@@ -403,6 +403,76 @@ describe("TriggerChatTransport", function () {
403403 expect ( observedStreamPath ) . toBe ( "/custom-base/realtime/v1/streams/run_path_prefix/chat-stream" ) ;
404404 } ) ;
405405
406+ it ( "supports trailing slashes on baseURL path prefixes" , async function ( ) {
407+ let observedTriggerPath : string | undefined ;
408+ let observedStreamPath : string | undefined ;
409+
410+ const server = await startServer ( function ( req , res ) {
411+ if ( req . method === "POST" ) {
412+ observedTriggerPath = req . url ?? "" ;
413+ }
414+
415+ if ( req . method === "GET" ) {
416+ observedStreamPath = req . url ?? "" ;
417+ }
418+
419+ if ( req . method === "POST" && req . url === "/custom-prefix/api/v1/tasks/chat-task/trigger" ) {
420+ res . writeHead ( 200 , {
421+ "content-type" : "application/json" ,
422+ "x-trigger-jwt" : "pk_run_path_prefix_trailing" ,
423+ } ) ;
424+ res . end ( JSON . stringify ( { id : "run_path_prefix_trailing" } ) ) ;
425+ return ;
426+ }
427+
428+ if (
429+ req . method === "GET" &&
430+ req . url === "/custom-prefix/realtime/v1/streams/run_path_prefix_trailing/chat-stream"
431+ ) {
432+ res . writeHead ( 200 , {
433+ "content-type" : "text/event-stream" ,
434+ } ) ;
435+ writeSSE (
436+ res ,
437+ "1-0" ,
438+ JSON . stringify ( { type : "text-start" , id : "path_prefix_trailing_1" } )
439+ ) ;
440+ writeSSE (
441+ res ,
442+ "2-0" ,
443+ JSON . stringify ( { type : "text-end" , id : "path_prefix_trailing_1" } )
444+ ) ;
445+ res . end ( ) ;
446+ return ;
447+ }
448+
449+ res . writeHead ( 404 ) ;
450+ res . end ( ) ;
451+ } ) ;
452+
453+ const transport = new TriggerChatTransport ( {
454+ task : "chat-task" ,
455+ accessToken : "pk_trigger" ,
456+ baseURL : `${ server . url } /custom-prefix///` ,
457+ stream : "chat-stream" ,
458+ } ) ;
459+
460+ const stream = await transport . sendMessages ( {
461+ trigger : "submit-message" ,
462+ chatId : "chat-path-prefix-trailing" ,
463+ messageId : undefined ,
464+ messages : [ ] ,
465+ abortSignal : undefined ,
466+ } ) ;
467+
468+ const chunks = await readChunks ( stream ) ;
469+ expect ( chunks ) . toHaveLength ( 2 ) ;
470+ expect ( observedTriggerPath ) . toBe ( "/custom-prefix/api/v1/tasks/chat-task/trigger" ) ;
471+ expect ( observedStreamPath ) . toBe (
472+ "/custom-prefix/realtime/v1/streams/run_path_prefix_trailing/chat-stream"
473+ ) ;
474+ } ) ;
475+
406476 it ( "uses defined stream object id when provided" , async function ( ) {
407477 let observedStreamPath : string | undefined ;
408478
0 commit comments