@@ -160,6 +160,7 @@ const convertAssistantMessage = (
160160 signature : msg . signature ,
161161 } satisfies Anthropic . ThinkingBlockParam )
162162 : undefined ,
163+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
163164 ...( ( convertStandardMessage ( msg ) ?. content || [ ] ) as any ) ,
164165 ...( msg . tool_calls || [ ] ) . map (
165166 ( tool ) =>
@@ -305,7 +306,7 @@ const completerFactory = (
305306 const httpAgent = await resolveHttpProxyAgent ( ) ;
306307 const messagesApi = await resolver ( trace , cfg , httpAgent , fetch ) ;
307308 dbg ( "caching" , caching ) ;
308- trace . itemValue ( `caching` , caching ) ;
309+ trace ? .itemValue ( `caching` , caching ) ;
309310
310311 let numTokens = 0 ;
311312 let chatResp = "" ;
@@ -363,8 +364,8 @@ const completerFactory = (
363364 }
364365
365366 dbgMessages ( `messages: %O` , messages ) ;
366- trace . detailsFenced ( "✉️ body" , mreq , "json" ) ;
367- trace . appendContent ( "\n" ) ;
367+ trace ? .detailsFenced ( "✉️ body" , mreq , "json" ) ;
368+ trace ? .appendContent ( "\n" ) ;
368369
369370 try {
370371 const stream = messagesApi . stream ( { ...mreq , ...headers } ) ;
@@ -399,17 +400,17 @@ const completerFactory = (
399400 break ;
400401 case "thinking_delta" :
401402 reasoningContent = chunk . delta . thinking ;
402- trace . appendToken ( reasoningContent ) ;
403+ trace ? .appendToken ( reasoningContent ) ;
403404 reasoningChatResp += reasoningContent ;
404- trace . appendToken ( chunkContent ) ;
405+ trace ? .appendToken ( chunkContent ) ;
405406 break ;
406407 case "text_delta" :
407408 if ( ! chunk . delta . text ) dbg ( `empty text_delta` , chunk ) ;
408409 else {
409410 chunkContent = chunk . delta . text ;
410411 numTokens += approximateTokens ( chunkContent , { encoder } ) ;
411412 chatResp += chunkContent ;
412- trace . appendToken ( chunkContent ) ;
413+ trace ? .appendToken ( chunkContent ) ;
413414 }
414415 break ;
415416
@@ -448,13 +449,13 @@ const completerFactory = (
448449 } catch ( e ) {
449450 finishReason = "fail" ;
450451 logError ( e ) ;
451- trace . error ( "error while processing event" , serializeError ( e ) ) ;
452+ trace ? .error ( "error while processing event" , serializeError ( e ) ) ;
452453 }
453454
454- trace . appendContent ( "\n\n" ) ;
455- trace . itemValue ( `🏁 finish reason` , finishReason ) ;
455+ trace ? .appendContent ( "\n\n" ) ;
456+ trace ? .itemValue ( `🏁 finish reason` , finishReason ) ;
456457 if ( usage ?. total_tokens ) {
457- trace . itemValue (
458+ trace ? .itemValue (
458459 `🪙 tokens` ,
459460 `${ usage . total_tokens } total, ${ usage . prompt_tokens } prompt, ${ usage . completion_tokens } completion` ,
460461 ) ;
@@ -472,7 +473,7 @@ const completerFactory = (
472473 return completion ;
473474} ;
474475
475- const listModels : ListModelsFunction = async ( cfg , options ) => {
476+ const listModels : ListModelsFunction = async ( cfg ) => {
476477 try {
477478 const anthropic = new Anthropic ( {
478479 baseURL : cfg . base ,
@@ -507,9 +508,10 @@ export const AnthropicModel = Object.freeze<LanguageModel>({
507508 fetch,
508509 fetchOptions : {
509510 dispatcher : httpAgent ,
511+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
510512 } as RequestInit as any ,
511513 } ) ;
512- if ( anthropic . baseURL ) trace . itemValue ( `url` , `[${ anthropic . baseURL } ](${ anthropic . baseURL } )` ) ;
514+ if ( anthropic . baseURL ) trace ? .itemValue ( `url` , `[${ anthropic . baseURL } ](${ anthropic . baseURL } )` ) ;
513515 const messagesApi = anthropic . beta . messages ;
514516 return messagesApi ;
515517 } ) ,
@@ -524,9 +526,10 @@ export const AnthropicBedrockModel = Object.freeze<LanguageModel>({
524526 fetch,
525527 fetchOptions : {
526528 dispatcher : httpAgent ,
529+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
527530 } as RequestInit as any ,
528531 } ) ;
529- if ( anthropic . baseURL ) trace . itemValue ( `url` , `[${ anthropic . baseURL } ](${ anthropic . baseURL } )` ) ;
532+ if ( anthropic . baseURL ) trace ? .itemValue ( `url` , `[${ anthropic . baseURL } ](${ anthropic . baseURL } )` ) ;
530533 return anthropic . beta . messages ;
531534 } ) ,
532535 id : MODEL_PROVIDER_ANTHROPIC_BEDROCK ,
0 commit comments