@@ -544,6 +544,74 @@ describe("TriggerChatTransport", function () {
544544 expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_trimmed_baseurl/chat-stream" ) ;
545545 } ) ;
546546
547+ it ( "trims newline and tab whitespace around baseURL values" , async function ( ) {
548+ let observedTriggerPath : string | undefined ;
549+ let observedStreamPath : string | undefined ;
550+
551+ const server = await startServer ( function ( req , res ) {
552+ if ( req . method === "POST" ) {
553+ observedTriggerPath = req . url ?? "" ;
554+ }
555+
556+ if ( req . method === "GET" ) {
557+ observedStreamPath = req . url ?? "" ;
558+ }
559+
560+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
561+ res . writeHead ( 200 , {
562+ "content-type" : "application/json" ,
563+ "x-trigger-jwt" : "pk_run_trimmed_newline_tab_baseurl" ,
564+ } ) ;
565+ res . end ( JSON . stringify ( { id : "run_trimmed_newline_tab_baseurl" } ) ) ;
566+ return ;
567+ }
568+
569+ if (
570+ req . method === "GET" &&
571+ req . url === "/realtime/v1/streams/run_trimmed_newline_tab_baseurl/chat-stream"
572+ ) {
573+ res . writeHead ( 200 , {
574+ "content-type" : "text/event-stream" ,
575+ } ) ;
576+ writeSSE (
577+ res ,
578+ "1-0" ,
579+ JSON . stringify ( { type : "text-start" , id : "trimmed_newline_tab_baseurl_1" } )
580+ ) ;
581+ writeSSE (
582+ res ,
583+ "2-0" ,
584+ JSON . stringify ( { type : "text-end" , id : "trimmed_newline_tab_baseurl_1" } )
585+ ) ;
586+ res . end ( ) ;
587+ return ;
588+ }
589+
590+ res . writeHead ( 404 ) ;
591+ res . end ( ) ;
592+ } ) ;
593+
594+ const transport = new TriggerChatTransport ( {
595+ task : "chat-task" ,
596+ accessToken : "pk_trigger" ,
597+ baseURL : `\n\t${ server . url } /\t\n` ,
598+ stream : "chat-stream" ,
599+ } ) ;
600+
601+ const stream = await transport . sendMessages ( {
602+ trigger : "submit-message" ,
603+ chatId : "chat-trimmed-newline-tab-baseurl" ,
604+ messageId : undefined ,
605+ messages : [ ] ,
606+ abortSignal : undefined ,
607+ } ) ;
608+
609+ const chunks = await readChunks ( stream ) ;
610+ expect ( chunks ) . toHaveLength ( 2 ) ;
611+ expect ( observedTriggerPath ) . toBe ( "/api/v1/tasks/chat-task/trigger" ) ;
612+ expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_trimmed_newline_tab_baseurl/chat-stream" ) ;
613+ } ) ;
614+
547615 it ( "preserves baseURL path prefixes after trimming surrounding whitespace" , async function ( ) {
548616 let observedTriggerPath : string | undefined ;
549617 let observedStreamPath : string | undefined ;
0 commit comments