File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -728,6 +728,23 @@ describe('Gemini Client (client.ts)', () => {
728728 ) ;
729729 } ) ;
730730
731+ it ( 'yields UserCancelled when processTurn throws AbortError' , async ( ) => {
732+ const abortError = new Error ( 'Aborted' ) ;
733+ abortError . name = 'AbortError' ;
734+ vi . spyOn ( client [ 'loopDetector' ] , 'turnStarted' ) . mockRejectedValueOnce (
735+ abortError ,
736+ ) ;
737+
738+ const stream = client . sendMessageStream (
739+ [ { text : 'Hi' } ] ,
740+ new AbortController ( ) . signal ,
741+ 'prompt-id-abort-error' ,
742+ ) ;
743+ const events = await fromAsync ( stream ) ;
744+
745+ expect ( events ) . toEqual ( [ { type : GeminiEventType . UserCancelled } ] ) ;
746+ } ) ;
747+
731748 it . each ( [
732749 {
733750 compressionStatus :
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ import {
3434 type RetryAvailabilityContext ,
3535} from '../utils/retry.js' ;
3636import type { ValidationRequiredError } from '../utils/googleQuotaErrors.js' ;
37- import { getErrorMessage } from '../utils/errors.js' ;
37+ import { getErrorMessage , isAbortError } from '../utils/errors.js' ;
3838import { tokenLimit } from './tokenLimits.js' ;
3939import type {
4040 ChatRecordingService ,
@@ -957,6 +957,12 @@ export class GeminiClient {
957957 ) ;
958958 }
959959 }
960+ } catch ( error ) {
961+ if ( signal ?. aborted || isAbortError ( error ) ) {
962+ yield { type : GeminiEventType . UserCancelled } ;
963+ return turn ;
964+ }
965+ throw error ;
960966 } finally {
961967 const hookState = this . hookStateMap . get ( prompt_id ) ;
962968 if ( hookState ) {
You can’t perform that action at this time.
0 commit comments