From bea6e1ff1b4e4f8bcd87953a5fe4e649a9ea035c Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Tue, 11 Mar 2025 12:27:03 -0700 Subject: [PATCH] Add id to chat request (#243239) * Add id to chat request * Support proposed api check * Do some casting --- src/vs/workbench/api/common/extHostChatAgents2.ts | 6 ++++-- src/vs/workbench/api/common/extHostTypeConverters.ts | 10 +++++++++- .../vscode.proposed.chatParticipantPrivate.d.ts | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/api/common/extHostChatAgents2.ts b/src/vs/workbench/api/common/extHostChatAgents2.ts index b95655d118a..1c7afac413a 100644 --- a/src/vs/workbench/api/common/extHostChatAgents2.ts +++ b/src/vs/workbench/api/common/extHostChatAgents2.ts @@ -404,7 +404,8 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS const { request, location, history } = await this._createRequest(requestDto, context, detector.extension); const model = await this.getModelForRequest(request, detector.extension); - const extRequest = typeConvert.ChatAgentRequest.to(request, location, model, this.getDiagnosticsWhenEnabled(detector.extension)); + const includeInteractionId = isProposedApiEnabled(detector.extension, 'chatParticipantPrivate'); + const extRequest = typeConvert.ChatAgentRequest.to(includeInteractionId ? request : { ...request, requestId: '' }, location, model, this.getDiagnosticsWhenEnabled(detector.extension)); return detector.provider.provideParticipantDetection( extRequest, @@ -488,7 +489,8 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS stream = new ChatAgentResponseStream(agent.extension, request, this._proxy, this._commands.converter, sessionDisposables); const model = await this.getModelForRequest(request, agent.extension); - const extRequest = typeConvert.ChatAgentRequest.to(request, location, model, this.getDiagnosticsWhenEnabled(agent.extension)); + const includeInteractionId = isProposedApiEnabled(agent.extension, 'chatParticipantPrivate'); + const extRequest = typeConvert.ChatAgentRequest.to(includeInteractionId ? request : { ...request, requestId: '' }, location, model, this.getDiagnosticsWhenEnabled(agent.extension)); inFlightRequest = { requestId: requestDto.requestId, extRequest }; this._inFlightRequests.add(inFlightRequest); diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 8f4a1d6533d..5e96a687c55 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -2768,7 +2768,7 @@ export namespace ChatAgentRequest { export function to(request: IChatAgentRequest, location2: vscode.ChatRequestEditorData | vscode.ChatRequestNotebookData | undefined, model: vscode.LanguageModelChat, diagnostics: readonly [vscode.Uri, readonly vscode.Diagnostic[]][]): vscode.ChatRequest { const toolReferences = request.variables.variables.filter(v => v.isTool); const variableReferences = request.variables.variables.filter(v => !v.isTool); - return { + const requestWithoutId = { prompt: request.message, command: request.command, attempt: request.attempt ?? 0, @@ -2783,6 +2783,14 @@ export namespace ChatAgentRequest { toolInvocationToken: Object.freeze({ sessionId: request.sessionId }) as never, model }; + if (request.requestId) { + return { + ...requestWithoutId, + id: request.requestId + }; + } + // This cast is done to allow sending the stabl version of ChatRequest which does not have an id property + return requestWithoutId as unknown as vscode.ChatRequest; } } diff --git a/src/vscode-dts/vscode.proposed.chatParticipantPrivate.d.ts b/src/vscode-dts/vscode.proposed.chatParticipantPrivate.d.ts index 1391558150a..6a60318a241 100644 --- a/src/vscode-dts/vscode.proposed.chatParticipantPrivate.d.ts +++ b/src/vscode-dts/vscode.proposed.chatParticipantPrivate.d.ts @@ -50,6 +50,10 @@ declare module 'vscode' { } export interface ChatRequest { + /** + * The id of the chat request. Used to identity an interaction with any of the chat surfaces. + */ + readonly id: string; /** * The attempt number of the request. The first request has attempt number 0. */