diff --git a/src/vs/workbench/contrib/chat/common/chatModel.ts b/src/vs/workbench/contrib/chat/common/chatModel.ts index 26c82c87dd2..11eefe47dea 100644 --- a/src/vs/workbench/contrib/chat/common/chatModel.ts +++ b/src/vs/workbench/contrib/chat/common/chatModel.ts @@ -23,10 +23,21 @@ export interface IChatRequestModel { readonly response: IChatResponseModel | undefined; } +export type ResponsePart = + | string + | IMarkdownString + | { treeData: IChatResponseProgressFileTreeData } + | { + placeholder: string; + resolvedContent?: Promise< + string | IMarkdownString | { treeData: IChatResponseProgressFileTreeData } + >; + }; + export interface IResponse { readonly value: (IMarkdownString | IPlaceholderMarkdownString | IChatResponseProgressFileTreeData)[]; onDidChangeValue: Event; - updateContent(responsePart: string | IMarkdownString | { treeData: IChatResponseProgressFileTreeData } | { placeholder: string; resolvedContent?: Promise }, quiet?: boolean): void; + updateContent(responsePart: ResponsePart, quiet?: boolean): void; asString(): string; } @@ -93,7 +104,10 @@ export interface IPlaceholderMarkdownString extends IMarkdownString { isPlaceholder: boolean; } -type ResponsePart = { string: IMarkdownString; isPlaceholder?: boolean } | { treeData: IChatResponseProgressFileTreeData; isPlaceholder?: undefined }; +type InternalResponsePart = + | { string: IMarkdownString; isPlaceholder?: boolean } + | { treeData: IChatResponseProgressFileTreeData; isPlaceholder?: undefined }; + export class Response implements IResponse { private _onDidChangeValue = new Emitter(); public get onDidChangeValue() { @@ -101,7 +115,7 @@ export class Response implements IResponse { } // responseParts internally tracks all the response parts, including strings which are currently resolving, so that they can be updated when they do resolve - private _responseParts: ResponsePart[]; + private _responseParts: InternalResponsePart[]; // responseData externally presents the response parts with consolidated contiguous strings (including strings which were previously resolving) private _responseData: (IMarkdownString | IPlaceholderMarkdownString | IChatResponseProgressFileTreeData)[]; // responseRepr externally presents the response parts with consolidated contiguous strings (excluding tree data) @@ -126,7 +140,7 @@ export class Response implements IResponse { return this._responseRepr; } - updateContent(responsePart: string | IMarkdownString | { treeData: IChatResponseProgressFileTreeData } | { placeholder: string; resolvedContent?: Promise }, quiet?: boolean): void { + updateContent(responsePart: ResponsePart, quiet?: boolean): void { if (typeof responsePart === 'string' || isMarkdownString(responsePart)) { const responsePartLength = this._responseParts.length - 1; const lastResponsePart = this._responseParts[responsePartLength]; @@ -154,6 +168,9 @@ export class Response implements IResponse { if (typeof content === 'string') { this._responseParts[responsePosition] = { string: new MarkdownString(content), isPlaceholder: true }; this._updateRepr(quiet); + } else if ('value' in content) { + this._responseParts[responsePosition] = { string: content, isPlaceholder: true }; + this._updateRepr(quiet); } else if (content.treeData) { this._responseParts[responsePosition] = { treeData: content.treeData }; this._updateRepr(quiet); @@ -257,7 +274,7 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel this._id = 'response_' + ChatResponseModel.nextId++; } - updateContent(responsePart: string | IMarkdownString | { treeData: IChatResponseProgressFileTreeData } | { placeholder: string; resolvedContent?: Promise }, quiet?: boolean) { + updateContent(responsePart: ResponsePart, quiet?: boolean) { this._response.updateContent(responsePart, quiet); }