@@ -479,6 +479,77 @@ describe("TriggerChatTransport", function () {
479479 ) ;
480480 } ) ;
481481
482+ it ( "combines path prefixes with run and stream URL encoding" , async function ( ) {
483+ let observedTriggerPath : string | undefined ;
484+ let observedStreamPath : string | undefined ;
485+
486+ const server = await startServer ( function ( req , res ) {
487+ if ( req . method === "POST" ) {
488+ observedTriggerPath = req . url ?? "" ;
489+ }
490+
491+ if ( req . method === "GET" ) {
492+ observedStreamPath = req . url ?? "" ;
493+ }
494+
495+ if ( req . method === "POST" && req . url === "/prefixed/api/v1/tasks/chat-task/trigger" ) {
496+ res . writeHead ( 200 , {
497+ "content-type" : "application/json" ,
498+ "x-trigger-jwt" : "pk_run_prefixed_encoded" ,
499+ } ) ;
500+ res . end ( JSON . stringify ( { id : "run/with space" } ) ) ;
501+ return ;
502+ }
503+
504+ if (
505+ req . method === "GET" &&
506+ req . url ===
507+ "/prefixed/realtime/v1/streams/run%2Fwith%20space/chat%2Fspecial%20stream"
508+ ) {
509+ res . writeHead ( 200 , {
510+ "content-type" : "text/event-stream" ,
511+ } ) ;
512+ writeSSE (
513+ res ,
514+ "1-0" ,
515+ JSON . stringify ( { type : "text-start" , id : "prefixed_encoded_1" } )
516+ ) ;
517+ writeSSE (
518+ res ,
519+ "2-0" ,
520+ JSON . stringify ( { type : "text-end" , id : "prefixed_encoded_1" } )
521+ ) ;
522+ res . end ( ) ;
523+ return ;
524+ }
525+
526+ res . writeHead ( 404 ) ;
527+ res . end ( ) ;
528+ } ) ;
529+
530+ const transport = new TriggerChatTransport ( {
531+ task : "chat-task" ,
532+ accessToken : "pk_trigger" ,
533+ baseURL : `${ server . url } /prefixed///` ,
534+ stream : "chat/special stream" ,
535+ } ) ;
536+
537+ const stream = await transport . sendMessages ( {
538+ trigger : "submit-message" ,
539+ chatId : "chat-prefixed-encoded" ,
540+ messageId : undefined ,
541+ messages : [ ] ,
542+ abortSignal : undefined ,
543+ } ) ;
544+
545+ const chunks = await readChunks ( stream ) ;
546+ expect ( chunks ) . toHaveLength ( 2 ) ;
547+ expect ( observedTriggerPath ) . toBe ( "/prefixed/api/v1/tasks/chat-task/trigger" ) ;
548+ expect ( observedStreamPath ) . toBe (
549+ "/prefixed/realtime/v1/streams/run%2Fwith%20space/chat%2Fspecial%20stream"
550+ ) ;
551+ } ) ;
552+
482553 it ( "uses defined stream object id when provided" , async function ( ) {
483554 let observedStreamPath : string | undefined ;
484555
0 commit comments