@@ -138,14 +138,20 @@ const ANTHROPIC_SDK_NON_STREAMING_MAX_TOKENS = 21333
138138 */
139139async function createMessage (
140140 anthropic : Anthropic ,
141- payload : AnthropicPayload
141+ payload : AnthropicPayload ,
142+ abortSignal ?: AbortSignal
142143) : Promise < Anthropic . Messages . Message > {
144+ const options = abortSignal ? { signal : abortSignal } : undefined
143145 if ( payload . max_tokens > ANTHROPIC_SDK_NON_STREAMING_MAX_TOKENS && ! payload . stream ) {
144- const stream = anthropic . messages . stream ( payload as Anthropic . Messages . MessageStreamParams )
146+ const stream = anthropic . messages . stream (
147+ payload as Anthropic . Messages . MessageStreamParams ,
148+ options
149+ )
145150 return stream . finalMessage ( )
146151 }
147152 return anthropic . messages . create (
148- payload as Anthropic . Messages . MessageCreateParamsNonStreaming
153+ payload as Anthropic . Messages . MessageCreateParamsNonStreaming ,
154+ options
149155 ) as Promise < Anthropic . Messages . Message >
150156}
151157
@@ -367,10 +373,13 @@ export async function executeAnthropicProviderRequest(
367373 const providerStartTime = Date . now ( )
368374 const providerStartTimeISO = new Date ( providerStartTime ) . toISOString ( )
369375
370- const streamResponse = await anthropic . messages . create ( {
371- ...payload ,
372- stream : true ,
373- } as Anthropic . Messages . MessageCreateParamsStreaming )
376+ const streamResponse = await anthropic . messages . create (
377+ {
378+ ...payload ,
379+ stream : true ,
380+ } as Anthropic . Messages . MessageCreateParamsStreaming ,
381+ request . abortSignal ? { signal : request . abortSignal } : undefined
382+ )
374383
375384 const streamingResult = {
376385 stream : createReadableStreamFromAnthropicStream (
@@ -461,7 +470,7 @@ export async function executeAnthropicProviderRequest(
461470 const forcedTools = preparedTools ?. forcedTools || [ ]
462471 let usedForcedTools : string [ ] = [ ]
463472
464- let currentResponse = await createMessage ( anthropic , payload )
473+ let currentResponse = await createMessage ( anthropic , payload , request . abortSignal )
465474 const firstResponseTime = Date . now ( ) - initialCallTime
466475
467476 let content = ''
@@ -708,7 +717,7 @@ export async function executeAnthropicProviderRequest(
708717
709718 const nextModelStartTime = Date . now ( )
710719
711- currentResponse = await createMessage ( anthropic , nextPayload )
720+ currentResponse = await createMessage ( anthropic , nextPayload , request . abortSignal )
712721
713722 const nextCheckResult = checkForForcedToolUsage (
714723 currentResponse ,
@@ -758,7 +767,8 @@ export async function executeAnthropicProviderRequest(
758767 }
759768
760769 const streamResponse = await anthropic . messages . create (
761- streamingPayload as Anthropic . Messages . MessageCreateParamsStreaming
770+ streamingPayload as Anthropic . Messages . MessageCreateParamsStreaming ,
771+ request . abortSignal ? { signal : request . abortSignal } : undefined
762772 )
763773
764774 const streamingResult = {
@@ -860,7 +870,7 @@ export async function executeAnthropicProviderRequest(
860870 const forcedTools = preparedTools ?. forcedTools || [ ]
861871 let usedForcedTools : string [ ] = [ ]
862872
863- let currentResponse = await createMessage ( anthropic , payload )
873+ let currentResponse = await createMessage ( anthropic , payload , request . abortSignal )
864874 const firstResponseTime = Date . now ( ) - initialCallTime
865875
866876 let content = ''
@@ -1118,7 +1128,7 @@ export async function executeAnthropicProviderRequest(
11181128
11191129 const nextModelStartTime = Date . now ( )
11201130
1121- currentResponse = await createMessage ( anthropic , nextPayload )
1131+ currentResponse = await createMessage ( anthropic , nextPayload , request . abortSignal )
11221132
11231133 const nextCheckResult = checkForForcedToolUsage (
11241134 currentResponse ,
@@ -1182,7 +1192,8 @@ export async function executeAnthropicProviderRequest(
11821192 }
11831193
11841194 const streamResponse = await anthropic . messages . create (
1185- streamingPayload as Anthropic . Messages . MessageCreateParamsStreaming
1195+ streamingPayload as Anthropic . Messages . MessageCreateParamsStreaming ,
1196+ request . abortSignal ? { signal : request . abortSignal } : undefined
11861197 )
11871198
11881199 const streamingResult = {
0 commit comments