mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feat(core): Add infinite loop protection to client (#2793)
This commit is contained in:
@@ -219,7 +219,9 @@ export class GeminiClient {
|
||||
signal: AbortSignal,
|
||||
turns: number = this.MAX_TURNS,
|
||||
): AsyncGenerator<ServerGeminiStreamEvent, Turn> {
|
||||
if (!turns) {
|
||||
// Ensure turns never exceeds MAX_TURNS to prevent infinite loops
|
||||
const boundedTurns = Math.min(turns, this.MAX_TURNS);
|
||||
if (!boundedTurns) {
|
||||
return new Turn(this.getChat());
|
||||
}
|
||||
|
||||
@@ -242,7 +244,7 @@ export class GeminiClient {
|
||||
const nextRequest = [{ text: 'Please continue.' }];
|
||||
// This recursive call's events will be yielded out, but the final
|
||||
// turn object will be from the top-level call.
|
||||
yield* this.sendMessageStream(nextRequest, signal, turns - 1);
|
||||
yield* this.sendMessageStream(nextRequest, signal, boundedTurns - 1);
|
||||
}
|
||||
}
|
||||
return turn;
|
||||
|
||||
Reference in New Issue
Block a user