diff options
| author | Taylor Mullen <[email protected]> | 2025-05-12 00:04:21 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-05-12 00:06:20 -0700 |
| commit | df74594b8ff9d277f0358f89f7ef7bc568a7b8ec (patch) | |
| tree | 37bedec074804cc8b68f8004b0f7ce7b78f3ffb1 /packages/server/src | |
| parent | 8537aabba49543af5c96138285578e4e9d36a76f (diff) | |
When an error occurs stop processing.
Diffstat (limited to 'packages/server/src')
| -rw-r--r-- | packages/server/src/core/client.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/packages/server/src/core/client.ts b/packages/server/src/core/client.ts index 0b1e8ecf..fc6080ab 100644 --- a/packages/server/src/core/client.ts +++ b/packages/server/src/core/client.ts @@ -16,7 +16,7 @@ import { } from '@google/genai'; import process from 'node:process'; import { getFolderStructure } from '../utils/getFolderStructure.js'; -import { Turn, ServerGeminiStreamEvent } from './turn.js'; +import { Turn, ServerGeminiStreamEvent, GeminiEventType } from './turn.js'; import { Config } from '../config/config.js'; import { getCoreSystemPrompt } from './prompts.js'; import { ReadManyFilesTool } from '../tools/read-many-files.js'; @@ -156,7 +156,10 @@ export class GeminiClient { turns++; const turn = new Turn(chat, availableTools); const resultStream = turn.run(request, signal); + let seenError = false; for await (const event of resultStream) { + seenError = + seenError === false ? false : event.type === GeminiEventType.Error; yield event; } @@ -176,6 +179,11 @@ export class GeminiClient { } } request = fnResponses; + + if (seenError) { + // We saw an error, lets stop processing to prevent unexpected consequences. + break; + } } if (turns >= this.MAX_TURNS) { console.warn('sendMessageStream: Reached maximum tool call turns limit.'); |
