@@ -35,23 +35,6 @@ class StreamingError extends Error {
3535type IncompleteResponse = Omit < Response , "incomplete_details" | "output_text" | "parallel_tool_calls" > ;
3636const SEQUENCE_NUMBER_PLACEHOLDER = - 1 ;
3737
38- // All headers are forwarded by default, except these ones.
39- const NOT_FORWARDED_HEADERS = new Set ( [
40- "accept" ,
41- "accept-encoding" ,
42- "authorization" ,
43- "connection" ,
44- "content-length" ,
45- "content-type" ,
46- "host" ,
47- "keep-alive" ,
48- "te" ,
49- "trailer" ,
50- "trailers" ,
51- "transfer-encoding" ,
52- "upgrade" ,
53- ] ) ;
54-
5538export const postCreateResponse = async (
5639 req : ValidatedRequest < CreateResponseParams > ,
5740 res : ExpressResponse
@@ -186,11 +169,6 @@ async function* innerRunStream(
186169 return ;
187170 }
188171
189- // Forward headers (except authorization handled separately)
190- const defaultHeaders = Object . fromEntries (
191- Object . entries ( req . headers ) . filter ( ( [ key ] ) => ! NOT_FORWARDED_HEADERS . has ( key . toLowerCase ( ) ) )
192- ) as Record < string , string > ;
193-
194172 // Return early if not supported param
195173 if ( req . body . reasoning ?. summary && req . body . reasoning ?. summary !== "auto" ) {
196174 throw new Error ( `Not implemented: only 'auto' summary is supported. Got '${ req . body . reasoning ?. summary } '` ) ;
@@ -451,7 +429,7 @@ async function* innerRunStream(
451429 do {
452430 previousMessageCount = currentMessageCount ;
453431
454- for await ( const event of handleOneTurnStream ( apiKey , payload , responseObject , mcpToolsMapping , defaultHeaders ) ) {
432+ for await ( const event of handleOneTurnStream ( apiKey , payload , responseObject , mcpToolsMapping ) ) {
455433 yield event ;
456434 }
457435
@@ -521,13 +499,11 @@ async function* handleOneTurnStream(
521499 apiKey : string | undefined ,
522500 payload : ChatCompletionCreateParamsStreaming ,
523501 responseObject : IncompleteResponse ,
524- mcpToolsMapping : Record < string , McpServerParams > ,
525- defaultHeaders : Record < string , string >
502+ mcpToolsMapping : Record < string , McpServerParams >
526503) : AsyncGenerator < PatchedResponseStreamEvent > {
527504 const client = new OpenAI ( {
528505 baseURL : process . env . OPENAI_BASE_URL ?? "https://router.huggingface.co/v1" ,
529506 apiKey : apiKey ,
530- defaultHeaders,
531507 } ) ;
532508 const stream = await client . chat . completions . create ( payload ) ;
533509 let previousInputTokens = responseObject . usage ?. input_tokens ?? 0 ;
0 commit comments