mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
refactor(chatModel):
* create a separate type to represent a response part * rename existing `ResponsePart` to `InternalResponsePart` * fix? handle if response part's resolved value is a markdown string, which is allowed in the `IResponse` interface
This commit is contained in:
@@ -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<void>;
|
||||
updateContent(responsePart: string | IMarkdownString | { treeData: IChatResponseProgressFileTreeData } | { placeholder: string; resolvedContent?: Promise<string | IMarkdownString | { treeData: IChatResponseProgressFileTreeData }> }, 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<void>();
|
||||
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<string | { treeData: IChatResponseProgressFileTreeData }> }, 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<string | IMarkdownString | { treeData: IChatResponseProgressFileTreeData }> }, quiet?: boolean) {
|
||||
updateContent(responsePart: ResponsePart, quiet?: boolean) {
|
||||
this._response.updateContent(responsePart, quiet);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user