Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessionDescription.ts
13406 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { renderAsPlaintext } from '../../../../../base/browser/markdownRenderer.js';
7
import { IMarkdownString } from '../../../../../base/common/htmlContent.js';
8
import { localize } from '../../../../../nls.js';
9
import { IChatToolInvocation } from '../../common/chatService/chatService.js';
10
import { IChatModel } from '../../common/model/chatModel.js';
11
12
export function getInProgressSessionDescription(chatModel: IChatModel): string | undefined {
13
const requests = chatModel.getRequests();
14
if (requests.length === 0) {
15
return undefined;
16
}
17
18
// Get the last request to check its response status
19
const lastRequest = requests.at(-1);
20
const response = lastRequest?.response;
21
if (!response) {
22
return undefined;
23
}
24
25
// If the response is complete, show Finished
26
if (response.isComplete) {
27
return undefined;
28
}
29
30
// Get the response parts to find tool invocations and progress messages
31
const responseParts = response.response.value;
32
let description: string | IMarkdownString | undefined = '';
33
34
for (let i = responseParts.length - 1; i >= 0; i--) {
35
const part = responseParts[i];
36
if (description) {
37
break;
38
}
39
40
if (part.kind === 'confirmation' && typeof part.message === 'string') {
41
description = part.message;
42
} else if (part.kind === 'toolInvocation') {
43
const toolInvocation = part as IChatToolInvocation;
44
const state = toolInvocation.state.get();
45
description = toolInvocation.generatedTitle || toolInvocation.pastTenseMessage || toolInvocation.invocationMessage;
46
if (state.type === IChatToolInvocation.StateKind.WaitingForConfirmation) {
47
const confirmationTitle = state.confirmationMessages?.title;
48
const titleMessage = confirmationTitle && (typeof confirmationTitle === 'string'
49
? confirmationTitle
50
: confirmationTitle.value);
51
const descriptionValue = typeof description === 'string' ? description : description.value;
52
description = titleMessage ?? localize('chat.sessions.description.waitingForConfirmation', "Waiting for confirmation: {0}", descriptionValue);
53
}
54
} else if (part.kind === 'toolInvocationSerialized') {
55
description = part.invocationMessage;
56
} else if (part.kind === 'progressMessage') {
57
description = part.content;
58
} else if (part.kind === 'thinking') {
59
description = localize('chat.sessions.description.thinking', 'Thinking...');
60
}
61
}
62
63
return description ? renderAsPlaintext(description, { useLinkFormatter: true }) : '';
64
}
65
66