@@ -479,6 +479,71 @@ describe("TriggerChatTransport", function () {
479479 ) ;
480480 } ) ;
481481
482+ it ( "trims surrounding whitespace from baseURL values" , 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 === "/api/v1/tasks/chat-task/trigger" ) {
496+ res . writeHead ( 200 , {
497+ "content-type" : "application/json" ,
498+ "x-trigger-jwt" : "pk_run_trimmed_baseurl" ,
499+ } ) ;
500+ res . end ( JSON . stringify ( { id : "run_trimmed_baseurl" } ) ) ;
501+ return ;
502+ }
503+
504+ if ( req . method === "GET" && req . url === "/realtime/v1/streams/run_trimmed_baseurl/chat-stream" ) {
505+ res . writeHead ( 200 , {
506+ "content-type" : "text/event-stream" ,
507+ } ) ;
508+ writeSSE (
509+ res ,
510+ "1-0" ,
511+ JSON . stringify ( { type : "text-start" , id : "trimmed_baseurl_1" } )
512+ ) ;
513+ writeSSE (
514+ res ,
515+ "2-0" ,
516+ JSON . stringify ( { type : "text-end" , id : "trimmed_baseurl_1" } )
517+ ) ;
518+ res . end ( ) ;
519+ return ;
520+ }
521+
522+ res . writeHead ( 404 ) ;
523+ res . end ( ) ;
524+ } ) ;
525+
526+ const transport = new TriggerChatTransport ( {
527+ task : "chat-task" ,
528+ accessToken : "pk_trigger" ,
529+ baseURL : ` ${ server . url } / ` ,
530+ stream : "chat-stream" ,
531+ } ) ;
532+
533+ const stream = await transport . sendMessages ( {
534+ trigger : "submit-message" ,
535+ chatId : "chat-trimmed-baseurl" ,
536+ messageId : undefined ,
537+ messages : [ ] ,
538+ abortSignal : undefined ,
539+ } ) ;
540+
541+ const chunks = await readChunks ( stream ) ;
542+ expect ( chunks ) . toHaveLength ( 2 ) ;
543+ expect ( observedTriggerPath ) . toBe ( "/api/v1/tasks/chat-task/trigger" ) ;
544+ expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_trimmed_baseurl/chat-stream" ) ;
545+ } ) ;
546+
482547 it ( "combines path prefixes with run and stream URL encoding" , async function ( ) {
483548 let observedTriggerPath : string | undefined ;
484549 let observedStreamPath : string | undefined ;
0 commit comments