@@ -629,7 +629,7 @@ export async function loopAgentSteps(
629629 const system =
630630 agentTemplate . inheritParentSystemPrompt && parentSystemPrompt
631631 ? parentSystemPrompt
632- : ( await getAgentPrompt ( {
632+ : ( ( await getAgentPrompt ( {
633633 ...params ,
634634 agentTemplate,
635635 promptType : { type : 'systemPrompt' } ,
@@ -645,7 +645,7 @@ export async function loopAgentSteps(
645645 }
646646 return cachedAdditionalToolDefinitions
647647 } ,
648- } ) ) ?? ''
648+ } ) ) ?? '' )
649649
650650 // Build agent tools (agents as direct tool calls) for non-inherited tools
651651 const agentTools = useParentTools
@@ -674,8 +674,8 @@ export async function loopAgentSteps(
674674
675675 const hasUserMessage = Boolean (
676676 prompt ||
677- ( spawnParams && Object . keys ( spawnParams ) . length > 0 ) ||
678- ( content && content . length > 0 ) ,
677+ ( spawnParams && Object . keys ( spawnParams ) . length > 0 ) ||
678+ ( content && content . length > 0 ) ,
679679 )
680680
681681 const initialMessages = buildArray < Message > (
@@ -918,10 +918,14 @@ export async function loopAgentSteps(
918918 )
919919
920920 // Re-throw NetworkError and PaymentRequiredError to allow SDK retry wrapper to handle it
921- if (
922- error instanceof Error &&
923- ( error . name === 'NetworkError' || error . name === 'PaymentRequiredError' )
924- ) {
921+ if ( error instanceof Error && error . name === 'NetworkError' ) {
922+ throw error
923+ }
924+
925+ const isPaymentRequired =
926+ ( error as { statusCode ?: number } ) . statusCode === 402
927+
928+ if ( isPaymentRequired ) {
925929 throw error
926930 }
927931
0 commit comments