From 43c707b4e8232c32cd663c3d570704fbeaf6492b Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Wed, 7 May 2025 16:31:43 -0700 Subject: Continue to work through 429/500s. - The root of this issue was actually a genai SDK bug that was fixed here: https://critique.corp.google.com/cl/753255997 - Upgrade to latest genai SDK for latest bug fixes (including the above) - Removed specific 429 handling for uncaught rejections. Fixes https://b.corp.google.com/issues/413760164 --- packages/server/src/core/client.ts | 49 +++++++++++++++----------------------- 1 file changed, 19 insertions(+), 30 deletions(-) (limited to 'packages/server/src') diff --git a/packages/server/src/core/client.ts b/packages/server/src/core/client.ts index 29712db5..904e944c 100644 --- a/packages/server/src/core/client.ts +++ b/packages/server/src/core/client.ts @@ -133,39 +133,28 @@ export class GeminiClient { ): AsyncGenerator { let turns = 0; const availableTools = this.config.getToolRegistry().getAllTools(); - try { - while (turns < this.MAX_TURNS) { - turns++; - const turn = new Turn(chat, availableTools); - const resultStream = turn.run(request, signal); - for await (const event of resultStream) { - yield event; - } - - const confirmations = turn.getConfirmationDetails(); - if (confirmations.length > 0) { - break; - } - - // What do we do when we have both function responses and confirmations? - const fnResponses = turn.getFunctionResponses(); - if (fnResponses.length === 0) { - break; // user's turn to respond - } - request = fnResponses; + while (turns < this.MAX_TURNS) { + turns++; + const turn = new Turn(chat, availableTools); + const resultStream = turn.run(request, signal); + for await (const event of resultStream) { + yield event; } - if (turns >= this.MAX_TURNS) { - console.warn( - 'sendMessageStream: Reached maximum tool call turns limit.', - ); + + const confirmations = turn.getConfirmationDetails(); + if (confirmations.length > 0) { + break; } - } catch (error: unknown) { - if (error instanceof Error && error.name === 'AbortError') { - console.log('Gemini stream request aborted by user.'); - throw error; + + // What do we do when we have both function responses and confirmations? + const fnResponses = turn.getFunctionResponses(); + if (fnResponses.length === 0) { + break; // user's turn to respond } - console.error(`Error during Gemini stream or tool interaction:`, error); - throw error; + request = fnResponses; + } + if (turns >= this.MAX_TURNS) { + console.warn('sendMessageStream: Reached maximum tool call turns limit.'); } } -- cgit v1.2.3