Make cancel not explode.

- We were console.erroring, throwing and early aborting. Instead we now treat cancels like a normal user message and show an indicator in the UI

Fixes https://b.corp.google.com/issues/416515841
This commit is contained in:
Taylor Mullen
2025-05-09 22:47:18 -07:00
committed by N. Taylor Mullen
parent 28f9a2adfa
commit 090198a7d6
3 changed files with 18 additions and 11 deletions

View File

@@ -47,6 +47,7 @@ export enum GeminiEventType {
ToolCallRequest = 'tool_call_request',
ToolCallResponse = 'tool_call_response',
ToolCallConfirmation = 'tool_call_confirmation',
UserCancelled = 'user_cancelled',
}
export interface ToolCallRequestInfo {
@@ -74,7 +75,8 @@ export type ServerGeminiStreamEvent =
| {
type: GeminiEventType.ToolCallConfirmation;
value: ServerToolCallConfirmationDetails;
};
}
| { type: GeminiEventType.UserCancelled };
// A turn manages the agentic loop turn within the server context.
export class Turn {
@@ -108,7 +110,8 @@ export class Turn {
for await (const resp of responseStream) {
this.debugResponses.push(resp);
if (signal?.aborted) {
throw this.abortError();
yield { type: GeminiEventType.UserCancelled };
return;
}
const text = getResponseText(resp);
@@ -240,12 +243,6 @@ export class Turn {
};
}
private abortError(): Error {
const error = new Error('Request cancelled by user during stream.');
error.name = 'AbortError';
return error; // Return instead of throw, let caller handle
}
getConfirmationDetails(): ToolCallConfirmationDetails[] {
return this.confirmationDetails;
}