summaryrefslogtreecommitdiff
path: root/packages/server/src
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-05-09 22:47:18 -0700
committerN. Taylor Mullen <[email protected]>2025-05-09 22:49:32 -0700
commit090198a7d644f24c617bd35db6a287b930729280 (patch)
treebf50e9dfe773a5a42abb32e2fc99ebc51691e1fb /packages/server/src
parent28f9a2adfaab7f92db408575833189a64e2b65de (diff)
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
Diffstat (limited to 'packages/server/src')
-rw-r--r--packages/server/src/core/turn.ts13
1 files changed, 5 insertions, 8 deletions
diff --git a/packages/server/src/core/turn.ts b/packages/server/src/core/turn.ts
index ad461d74..7d8bf7b6 100644
--- a/packages/server/src/core/turn.ts
+++ b/packages/server/src/core/turn.ts
@@ -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;
}