Add id to chat request (#243239)

* Add id to chat request

* Support proposed api check

* Do some casting
This commit is contained in:
Logan Ramos
2025-03-11 12:27:03 -07:00
committed by GitHub
parent 91c7debaf6
commit bea6e1ff1b
3 changed files with 17 additions and 3 deletions

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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.
*/