@@ -119,6 +119,7 @@ import type {
119119 StartWorkflowThreadInput ,
120120 StartWorkflowThreadResult ,
121121} from "@shared/contracts" ;
122+ import { parseGatewayHeadersBlock } from "../shared/gateway-headers.ts" ;
122123import {
123124 decideStreamSeq ,
124125 isControlTranscriptMessage ,
@@ -1099,6 +1100,16 @@ function applyGatewayAuthHeader(
10991100 return headers ;
11001101}
11011102
1103+ function applyGatewayCustomHeaders (
1104+ headers : Headers ,
1105+ gatewayHeaders : string | null | undefined ,
1106+ ) : Headers {
1107+ for ( const [ name , value ] of Object . entries ( parseGatewayHeadersBlock ( gatewayHeaders ) ) ) {
1108+ headers . set ( name , value ) ;
1109+ }
1110+ return headers ;
1111+ }
1112+
11021113function isLocalGatewayUrl ( gatewayUrl : string ) : boolean {
11031114 try {
11041115 const parsed = new URL ( normalizeGatewayUrl ( gatewayUrl ) ) ;
@@ -1323,7 +1334,10 @@ export async function streamThreadEvents(
13231334) : Promise < void > {
13241335 const afterSeq = Math . max ( 0 , Math . trunc ( options ?. afterSeq ?? 0 ) ) ;
13251336 const headers = applyGatewayAuthHeader (
1326- new Headers ( { Accept : "text/event-stream" } ) ,
1337+ applyGatewayCustomHeaders (
1338+ new Headers ( { Accept : "text/event-stream" } ) ,
1339+ settings . gatewayHeaders ,
1340+ ) ,
13271341 settings . gatewayAuthToken ,
13281342 ) ;
13291343 headers . set ( "Last-Event-ID" , String ( afterSeq ) ) ;
@@ -1548,7 +1562,7 @@ export async function requestJson<T>(
15481562 init ?: RequestInit ,
15491563) : Promise < T > {
15501564 const headers = applyGatewayAuthHeader (
1551- new Headers ( init ?. headers ) ,
1565+ applyGatewayCustomHeaders ( new Headers ( init ?. headers ) , settings . gatewayHeaders ) ,
15521566 settings . gatewayAuthToken ,
15531567 ) ;
15541568 headers . set ( "Accept" , "application/json" ) ;
@@ -1583,11 +1597,12 @@ export async function requestJson<T>(
15831597async function requestJsonFromGatewayUrl < T > (
15841598 gatewayUrl : string ,
15851599 gatewayAuthToken : string ,
1600+ gatewayHeaders : string | null | undefined ,
15861601 path : string ,
15871602 init ?: RequestInit ,
15881603) : Promise < T > {
15891604 const headers = applyGatewayAuthHeader (
1590- new Headers ( init ?. headers ) ,
1605+ applyGatewayCustomHeaders ( new Headers ( init ?. headers ) , gatewayHeaders ) ,
15911606 gatewayAuthToken ,
15921607 ) ;
15931608 headers . set ( "Accept" , "application/json" ) ;
@@ -2988,7 +3003,7 @@ export async function checkConnection(
29883003}
29893004
29903005export async function probeGateway (
2991- input : { gatewayUrl : string ; gatewayAuthToken : string } ,
3006+ input : { gatewayUrl : string ; gatewayAuthToken : string ; gatewayHeaders ?: string } ,
29923007) : Promise < GatewayProbeResult > {
29933008 const normalizedGatewayUrl = normalizeGatewayUrl ( input . gatewayUrl ) ;
29943009 const path = "/runtime" ;
@@ -3007,6 +3022,7 @@ export async function probeGateway(
30073022 const runtime = await requestJsonFromGatewayUrl < RuntimePayload > (
30083023 normalizedGatewayUrl ,
30093024 input . gatewayAuthToken ,
3025+ input . gatewayHeaders ,
30103026 path ,
30113027 {
30123028 signal : AbortSignal . timeout ( 5000 ) ,
0 commit comments