@@ -680,6 +680,77 @@ describe("TriggerChatTransport", function () {
680680 ) ;
681681 } ) ;
682682
683+ it ( "combines trimmed baseURL path prefixes with run and stream URL encoding" , async function ( ) {
684+ let observedTriggerPath : string | undefined ;
685+ let observedStreamPath : string | undefined ;
686+
687+ const server = await startServer ( function ( req , res ) {
688+ if ( req . method === "POST" ) {
689+ observedTriggerPath = req . url ?? "" ;
690+ }
691+
692+ if ( req . method === "GET" ) {
693+ observedStreamPath = req . url ?? "" ;
694+ }
695+
696+ if ( req . method === "POST" && req . url === "/trimmed-prefixed/api/v1/tasks/chat-task/trigger" ) {
697+ res . writeHead ( 200 , {
698+ "content-type" : "application/json" ,
699+ "x-trigger-jwt" : "pk_run_trimmed_prefixed_encoded" ,
700+ } ) ;
701+ res . end ( JSON . stringify ( { id : "run/with space trim" } ) ) ;
702+ return ;
703+ }
704+
705+ if (
706+ req . method === "GET" &&
707+ req . url ===
708+ "/trimmed-prefixed/realtime/v1/streams/run%2Fwith%20space%20trim/chat%2Fspecial%20stream"
709+ ) {
710+ res . writeHead ( 200 , {
711+ "content-type" : "text/event-stream" ,
712+ } ) ;
713+ writeSSE (
714+ res ,
715+ "1-0" ,
716+ JSON . stringify ( { type : "text-start" , id : "trimmed_prefixed_encoded_1" } )
717+ ) ;
718+ writeSSE (
719+ res ,
720+ "2-0" ,
721+ JSON . stringify ( { type : "text-end" , id : "trimmed_prefixed_encoded_1" } )
722+ ) ;
723+ res . end ( ) ;
724+ return ;
725+ }
726+
727+ res . writeHead ( 404 ) ;
728+ res . end ( ) ;
729+ } ) ;
730+
731+ const transport = new TriggerChatTransport ( {
732+ task : "chat-task" ,
733+ accessToken : "pk_trigger" ,
734+ baseURL : ` ${ server . url } /trimmed-prefixed/// ` ,
735+ stream : "chat/special stream" ,
736+ } ) ;
737+
738+ const stream = await transport . sendMessages ( {
739+ trigger : "submit-message" ,
740+ chatId : "chat-trimmed-prefixed-encoded" ,
741+ messageId : undefined ,
742+ messages : [ ] ,
743+ abortSignal : undefined ,
744+ } ) ;
745+
746+ const chunks = await readChunks ( stream ) ;
747+ expect ( chunks ) . toHaveLength ( 2 ) ;
748+ expect ( observedTriggerPath ) . toBe ( "/trimmed-prefixed/api/v1/tasks/chat-task/trigger" ) ;
749+ expect ( observedStreamPath ) . toBe (
750+ "/trimmed-prefixed/realtime/v1/streams/run%2Fwith%20space%20trim/chat%2Fspecial%20stream"
751+ ) ;
752+ } ) ;
753+
683754 it ( "uses defined stream object id when provided" , async function ( ) {
684755 let observedStreamPath : string | undefined ;
685756
0 commit comments