Do some ReadableArray in chat model (#195030)

* Do some ReadableArray

* Update test
This commit is contained in:
Rob Lourens
2023-10-08 14:54:20 -07:00
committed by GitHub
parent ef9f5d7f6f
commit 658dbfb253
5 changed files with 22 additions and 12 deletions
@@ -593,7 +593,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
};
}
private renderContentReferencesListData(data: IChatContentReference[], element: IChatResponseViewModel, templateData: IChatListItemTemplate): { element: HTMLElement; dispose: () => void } {
private renderContentReferencesListData(data: ReadonlyArray<IChatContentReference>, element: IChatResponseViewModel, templateData: IChatListItemTemplate): { element: HTMLElement; dispose: () => void } {
const listDisposables = new DisposableStore();
const referencesLabel = data.length > 1 ?
localize('usedReferencesPlural', "Used {0} references", data.length) :
@@ -39,9 +39,9 @@ export type ResponsePart =
| IChatContentReference;
export interface IResponse {
readonly value: (IMarkdownString | IPlaceholderMarkdownString | IChatResponseProgressFileTreeData)[];
readonly value: ReadonlyArray<IMarkdownString | IPlaceholderMarkdownString | IChatResponseProgressFileTreeData>;
readonly usedContext: IUsedContext | undefined;
readonly contentReferences: IChatContentReference[];
readonly contentReferences: ReadonlyArray<IChatContentReference>;
onDidChangeValue: Event<void>;
updateContent(responsePart: ResponsePart, quiet?: boolean): void;
asString(): string;
@@ -133,7 +133,7 @@ export class Response implements IResponse {
return this._responseData;
}
constructor(value: IMarkdownString | (IMarkdownString | IChatResponseProgressFileTreeData)[]) {
constructor(value: IMarkdownString | ReadonlyArray<IMarkdownString | IChatResponseProgressFileTreeData>) {
this._responseData = Array.isArray(value) ? value : [value];
this._responseParts = Array.isArray(value) ? value.map((v) => ('value' in v ? { string: v } : { treeData: v })) : [{ string: value }];
this._responseRepr = this._responseParts.map((part) => {
@@ -269,8 +269,10 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
return this.agent?.metadata.icon ?? this.session.responderAvatarIconUri;
}
private _followups?: IChatFollowup[];
constructor(
_response: IMarkdownString | (IMarkdownString | IChatResponseProgressFileTreeData)[],
_response: IMarkdownString | ReadonlyArray<IMarkdownString | IChatResponseProgressFileTreeData>,
public readonly session: ChatModel,
public readonly agent: IChatAgentData | undefined,
private _isComplete: boolean = false,
@@ -278,9 +280,10 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
private _vote?: InteractiveSessionVoteDirection,
private _providerResponseId?: string,
private _errorDetails?: IChatResponseErrorDetails,
private _followups?: IChatFollowup[]
followups?: ReadonlyArray<IChatFollowup>
) {
super();
this._followups = followups ? [...followups] : undefined;
this._response = new Response(_response);
this._register(this._response.onDidChangeValue(() => this._onDidChange.fire()));
this._id = 'response_' + ChatResponseModel.nextId++;
@@ -350,15 +353,15 @@ export interface ISerializableChatAgentData {
export interface ISerializableChatRequestData {
providerRequestId: string | undefined;
message: string | IParsedChatRequest;
response: (IMarkdownString | IChatResponseProgressFileTreeData)[] | undefined;
response: ReadonlyArray<IMarkdownString | IChatResponseProgressFileTreeData> | undefined;
agent?: ISerializableChatAgentData;
responseErrorDetails: IChatResponseErrorDetails | undefined;
followups: IChatFollowup[] | undefined;
followups: ReadonlyArray<IChatFollowup> | undefined;
isCanceled: boolean | undefined;
vote: InteractiveSessionVoteDirection | undefined;
/** For backward compat: should be optional */
usedContext?: IUsedContext;
contentReferences?: IChatContentReference[];
contentReferences?: ReadonlyArray<IChatContentReference>;
}
export interface IExportableChatData {
@@ -540,6 +543,10 @@ export class ChatModel extends Disposable implements IChatModel {
if (raw.usedContext) { // @ulugbekna: if this's a new vscode sessions, doc versions are incorrect anyway?
request.response.updateContent(raw.usedContext);
}
if (raw.contentReferences) {
raw.contentReferences.forEach(r => request.response!.updateContent(r));
}
}
return request;
});
@@ -720,6 +727,7 @@ export class ChatModel extends Disposable implements IChatModel {
icon: r.response.agent.metadata.icon
} : undefined,
usedContext: r.response?.response.usedContext,
contentReferences: r.response?.response.contentReferences
};
}),
providerId: this.providerId,
@@ -223,7 +223,7 @@ export interface IChatDynamicRequest {
}
export interface IChatCompleteResponse {
message: string | (IMarkdownString | IChatResponseProgressFileTreeData)[];
message: string | ReadonlyArray<IMarkdownString | IChatResponseProgressFileTreeData>;
errorDetails?: IChatResponseErrorDetails;
followups?: IChatFollowup[];
}
@@ -60,7 +60,8 @@
}
]
}
] }
] },
contentReferences: [ ]
}
],
providerId: "ChatProviderWithUsedContext",
@@ -60,7 +60,8 @@
}
]
}
] }
] },
contentReferences: [ ]
}
],
providerId: "ChatProviderWithUsedContext",