diff options
| author | Taylor Mullen <[email protected]> | 2025-05-27 23:40:25 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-05-27 23:46:37 -0700 |
| commit | f2f2ecf9d83224778e5fc38cfcc4a1edddf9f7d4 (patch) | |
| tree | 6ad7ce8c34f16016c67c208a5182a016739b2c07 /packages/server/src/core/turn.test.ts | |
| parent | bfeaac844186153698d3a7079b41214bbf1e4371 (diff) | |
feat: Allow cancellation of in-progress Gemini requests and pre-execution checks
- Implements cancellation for Gemini requests while they are actively being processed by the model.
- Extends cancellation support to the logic within tools. This allows users to cancel operations during the phase where the system is determining if a tool execution requires user confirmation, which can include potentially long-running pre-flight checks or LLM-based corrections.
- Underlying LLM calls for edit corrections (within and ) and next speaker checks can now also be cancelled.
- Previously, cancellation of the main request was not possible until text started streaming, and pre-execution checks were not cancellable.
- This change leverages the updated SDK's ability to accept an abort token and threads s throughout the request, tool execution, and pre-execution check lifecycle.
Fixes https://github.com/google-gemini/gemini-cli/issues/531
Diffstat (limited to 'packages/server/src/core/turn.test.ts')
| -rw-r--r-- | packages/server/src/core/turn.test.ts | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/packages/server/src/core/turn.test.ts b/packages/server/src/core/turn.test.ts index 44bb983f..8fb3a4c1 100644 --- a/packages/server/src/core/turn.test.ts +++ b/packages/server/src/core/turn.test.ts @@ -85,11 +85,17 @@ describe('Turn', () => { const events = []; const reqParts: Part[] = [{ text: 'Hi' }]; - for await (const event of turn.run(reqParts)) { + for await (const event of turn.run( + reqParts, + new AbortController().signal, + )) { events.push(event); } - expect(mockSendMessageStream).toHaveBeenCalledWith({ message: reqParts }); + expect(mockSendMessageStream).toHaveBeenCalledWith({ + message: reqParts, + config: { abortSignal: expect.any(AbortSignal) }, + }); expect(events).toEqual([ { type: GeminiEventType.Content, value: 'Hello' }, { type: GeminiEventType.Content, value: ' world' }, @@ -110,7 +116,10 @@ describe('Turn', () => { const events = []; const reqParts: Part[] = [{ text: 'Use tools' }]; - for await (const event of turn.run(reqParts)) { + for await (const event of turn.run( + reqParts, + new AbortController().signal, + )) { events.push(event); } @@ -179,7 +188,10 @@ describe('Turn', () => { mockGetHistory.mockReturnValue(historyContent); const events = []; - for await (const event of turn.run(reqParts)) { + for await (const event of turn.run( + reqParts, + new AbortController().signal, + )) { events.push(event); } @@ -210,7 +222,10 @@ describe('Turn', () => { const events = []; const reqParts: Part[] = [{ text: 'Test undefined tool parts' }]; - for await (const event of turn.run(reqParts)) { + for await (const event of turn.run( + reqParts, + new AbortController().signal, + )) { events.push(event); } @@ -261,7 +276,7 @@ describe('Turn', () => { })(); mockSendMessageStream.mockResolvedValue(mockResponseStream); const reqParts: Part[] = [{ text: 'Hi' }]; - for await (const _ of turn.run(reqParts)) { + for await (const _ of turn.run(reqParts, new AbortController().signal)) { // consume stream } expect(turn.getDebugResponses()).toEqual([resp1, resp2]); |
