@@ -273,6 +273,74 @@ describe("TriggerChatTransport", function () {
273273 expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_trailing_baseurl/chat-stream" ) ;
274274 } ) ;
275275
276+ it ( "supports baseURL path prefixes for trigger and stream routes" , async function ( ) {
277+ let observedTriggerPath : string | undefined ;
278+ let observedStreamPath : string | undefined ;
279+
280+ const server = await startServer ( function ( req , res ) {
281+ if ( req . method === "POST" ) {
282+ observedTriggerPath = req . url ?? "" ;
283+ }
284+
285+ if ( req . method === "GET" ) {
286+ observedStreamPath = req . url ?? "" ;
287+ }
288+
289+ if ( req . method === "POST" && req . url === "/custom-base/api/v1/tasks/chat-task/trigger" ) {
290+ res . writeHead ( 200 , {
291+ "content-type" : "application/json" ,
292+ "x-trigger-jwt" : "pk_run_path_prefix" ,
293+ } ) ;
294+ res . end ( JSON . stringify ( { id : "run_path_prefix" } ) ) ;
295+ return ;
296+ }
297+
298+ if (
299+ req . method === "GET" &&
300+ req . url === "/custom-base/realtime/v1/streams/run_path_prefix/chat-stream"
301+ ) {
302+ res . writeHead ( 200 , {
303+ "content-type" : "text/event-stream" ,
304+ } ) ;
305+ writeSSE (
306+ res ,
307+ "1-0" ,
308+ JSON . stringify ( { type : "text-start" , id : "path_prefix_1" } )
309+ ) ;
310+ writeSSE (
311+ res ,
312+ "2-0" ,
313+ JSON . stringify ( { type : "text-end" , id : "path_prefix_1" } )
314+ ) ;
315+ res . end ( ) ;
316+ return ;
317+ }
318+
319+ res . writeHead ( 404 ) ;
320+ res . end ( ) ;
321+ } ) ;
322+
323+ const transport = new TriggerChatTransport ( {
324+ task : "chat-task" ,
325+ accessToken : "pk_trigger" ,
326+ baseURL : `${ server . url } /custom-base` ,
327+ stream : "chat-stream" ,
328+ } ) ;
329+
330+ const stream = await transport . sendMessages ( {
331+ trigger : "submit-message" ,
332+ chatId : "chat-path-prefix" ,
333+ messageId : undefined ,
334+ messages : [ ] ,
335+ abortSignal : undefined ,
336+ } ) ;
337+
338+ const chunks = await readChunks ( stream ) ;
339+ expect ( chunks ) . toHaveLength ( 2 ) ;
340+ expect ( observedTriggerPath ) . toBe ( "/custom-base/api/v1/tasks/chat-task/trigger" ) ;
341+ expect ( observedStreamPath ) . toBe ( "/custom-base/realtime/v1/streams/run_path_prefix/chat-stream" ) ;
342+ } ) ;
343+
276344 it ( "uses defined stream object id when provided" , async function ( ) {
277345 let observedStreamPath : string | undefined ;
278346
0 commit comments