Path: blob/main/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessionDescription.ts
13406 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { renderAsPlaintext } from '../../../../../base/browser/markdownRenderer.js';6import { IMarkdownString } from '../../../../../base/common/htmlContent.js';7import { localize } from '../../../../../nls.js';8import { IChatToolInvocation } from '../../common/chatService/chatService.js';9import { IChatModel } from '../../common/model/chatModel.js';1011export function getInProgressSessionDescription(chatModel: IChatModel): string | undefined {12const requests = chatModel.getRequests();13if (requests.length === 0) {14return undefined;15}1617// Get the last request to check its response status18const lastRequest = requests.at(-1);19const response = lastRequest?.response;20if (!response) {21return undefined;22}2324// If the response is complete, show Finished25if (response.isComplete) {26return undefined;27}2829// Get the response parts to find tool invocations and progress messages30const responseParts = response.response.value;31let description: string | IMarkdownString | undefined = '';3233for (let i = responseParts.length - 1; i >= 0; i--) {34const part = responseParts[i];35if (description) {36break;37}3839if (part.kind === 'confirmation' && typeof part.message === 'string') {40description = part.message;41} else if (part.kind === 'toolInvocation') {42const toolInvocation = part as IChatToolInvocation;43const state = toolInvocation.state.get();44description = toolInvocation.generatedTitle || toolInvocation.pastTenseMessage || toolInvocation.invocationMessage;45if (state.type === IChatToolInvocation.StateKind.WaitingForConfirmation) {46const confirmationTitle = state.confirmationMessages?.title;47const titleMessage = confirmationTitle && (typeof confirmationTitle === 'string'48? confirmationTitle49: confirmationTitle.value);50const descriptionValue = typeof description === 'string' ? description : description.value;51description = titleMessage ?? localize('chat.sessions.description.waitingForConfirmation', "Waiting for confirmation: {0}", descriptionValue);52}53} else if (part.kind === 'toolInvocationSerialized') {54description = part.invocationMessage;55} else if (part.kind === 'progressMessage') {56description = part.content;57} else if (part.kind === 'thinking') {58description = localize('chat.sessions.description.thinking', 'Thinking...');59}60}6162return description ? renderAsPlaintext(description, { useLinkFormatter: true }) : '';63}646566