@@ -212,17 +212,16 @@ function listSetupTokenProfiles(
212212 store : { profiles : Record < string , AuthProfileCredential > } ,
213213 normalizeProviderId : ( provider : string ) => string ,
214214) : Array < { id : string ; token : string } > {
215- return Object . entries ( store . profiles )
216- . filter ( ( [ , cred ] ) => {
217- if ( cred . type !== "token" ) {
218- return false ;
219- }
220- if ( normalizeProviderId ( cred . provider ) !== "anthropic" ) {
221- return false ;
222- }
223- return isSetupToken ( cred . token ?? "" ) ;
224- } )
225- . map ( ( [ id , cred ] ) => ( { id, token : cred . token ?? "" } ) ) ;
215+ return Object . entries ( store . profiles ) . flatMap ( ( [ id , cred ] ) => {
216+ if (
217+ cred . type !== "token" ||
218+ normalizeProviderId ( cred . provider ) !== "anthropic" ||
219+ ! isSetupToken ( cred . token ?? "" )
220+ ) {
221+ return [ ] ;
222+ }
223+ return [ { id, token : cred . token ?? "" } ] ;
224+ } ) ;
226225}
227226
228227function pickSetupTokenProfile ( candidates : Array < { id : string ; token : string } > ) : {
@@ -390,15 +389,16 @@ async function startAnthropicProxy(params: { port: number; upstreamBaseUrl: stri
390389 }
391390 headers . set ( key , Array . isArray ( value ) ? value . join ( ", " ) : value ) ;
392391 }
393- const upstreamRes = await fetch ( upstreamUrl , {
392+ const upstreamInit = {
394393 method,
395394 headers,
396395 body :
397396 method === "GET" || method === "HEAD" || requestBody . byteLength === 0
398397 ? undefined
399- : requestBody ,
398+ : Uint8Array . from ( requestBody ) ,
400399 duplex : "half" ,
401- } ) ;
400+ } as RequestInit & { duplex : "half" } ;
401+ const upstreamRes = await fetch ( upstreamUrl , upstreamInit ) ;
402402 const responseHeaders : Record < string , string > = { } ;
403403 for ( const [ key , value ] of upstreamRes . headers . entries ( ) ) {
404404 const lower = key . toLowerCase ( ) ;
@@ -926,19 +926,21 @@ async function runGatewayPrompt(prompt: string): Promise<PromptResult> {
926926 mode : "cli" ,
927927 } ) ;
928928 const text = extractPayloadText ( waitRes ) ;
929+ const waitStatus = typeof waitRes . status === "string" ? waitRes . status : undefined ;
930+ const waitError = typeof waitRes . error === "string" ? waitRes . error : undefined ;
929931 const logTail = await readLogTail ( logPath ) ;
930- const matched400 = matchesExtraUsage400 ( waitRes . error , logTail , JSON . stringify ( waitRes ) ) ;
932+ const matched400 = matchesExtraUsage400 ( waitError , logTail , JSON . stringify ( waitRes ) ) ;
931933 return {
932934 prompt,
933- ok : waitRes . status === "ok" && ! matched400 ,
935+ ok : waitStatus === "ok" && ! matched400 ,
934936 transport : "gateway" ,
935937 promptMode : GATEWAY_PROMPT_MODE ,
936- status : waitRes . status ,
938+ status : waitStatus ,
937939 text : text || undefined ,
938940 error :
939- waitRes . status === "ok"
941+ waitStatus === "ok"
940942 ? undefined
941- : redactForDevToolLog ( waitRes . error || logTail || "agent.wait failed" ) ,
943+ : redactForDevToolLog ( waitError || logTail || "agent.wait failed" ) ,
942944 matchedExtraUsage400 : matched400 ,
943945 capture : summarizeCapture ( proxy ?. getLastCapture ( ) , prompt ) ,
944946 ...promptProbeTmpResult ( tmpDir ) ,
0 commit comments