@@ -653,6 +653,76 @@ describe("TriggerChatTransport", function () {
653653 } ) . toThrowError ( "baseURL must use http or https protocol" ) ;
654654 } ) ;
655655
656+ it ( "accepts uppercase http protocol in baseURL" , async function ( ) {
657+ let observedTriggerPath : string | undefined ;
658+ let observedStreamPath : string | undefined ;
659+
660+ const server = await startServer ( function ( req , res ) {
661+ if ( req . method === "POST" ) {
662+ observedTriggerPath = req . url ?? "" ;
663+ }
664+
665+ if ( req . method === "GET" ) {
666+ observedStreamPath = req . url ?? "" ;
667+ }
668+
669+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
670+ res . writeHead ( 200 , {
671+ "content-type" : "application/json" ,
672+ "x-trigger-jwt" : "pk_run_uppercase_protocol" ,
673+ } ) ;
674+ res . end ( JSON . stringify ( { id : "run_uppercase_protocol" } ) ) ;
675+ return ;
676+ }
677+
678+ if (
679+ req . method === "GET" &&
680+ req . url === "/realtime/v1/streams/run_uppercase_protocol/chat-stream"
681+ ) {
682+ res . writeHead ( 200 , {
683+ "content-type" : "text/event-stream" ,
684+ } ) ;
685+ writeSSE (
686+ res ,
687+ "1-0" ,
688+ JSON . stringify ( { type : "text-start" , id : "uppercase_protocol_1" } )
689+ ) ;
690+ writeSSE (
691+ res ,
692+ "2-0" ,
693+ JSON . stringify ( { type : "text-end" , id : "uppercase_protocol_1" } )
694+ ) ;
695+ res . end ( ) ;
696+ return ;
697+ }
698+
699+ res . writeHead ( 404 ) ;
700+ res . end ( ) ;
701+ } ) ;
702+
703+ const uppercasedProtocolBaseUrl = server . url . replace ( / ^ h t t p : \/ \/ / , "HTTP://" ) ;
704+
705+ const transport = new TriggerChatTransport ( {
706+ task : "chat-task" ,
707+ accessToken : "pk_trigger" ,
708+ baseURL : uppercasedProtocolBaseUrl ,
709+ stream : "chat-stream" ,
710+ } ) ;
711+
712+ const stream = await transport . sendMessages ( {
713+ trigger : "submit-message" ,
714+ chatId : "chat-uppercase-protocol" ,
715+ messageId : undefined ,
716+ messages : [ ] ,
717+ abortSignal : undefined ,
718+ } ) ;
719+
720+ const chunks = await readChunks ( stream ) ;
721+ expect ( chunks ) . toHaveLength ( 2 ) ;
722+ expect ( observedTriggerPath ) . toBe ( "/api/v1/tasks/chat-task/trigger" ) ;
723+ expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_uppercase_protocol/chat-stream" ) ;
724+ } ) ;
725+
656726 it ( "combines path prefixes with run and stream URL encoding" , async function ( ) {
657727 let observedTriggerPath : string | undefined ;
658728 let observedStreamPath : string | undefined ;
0 commit comments