@@ -910,6 +910,78 @@ describe("TriggerChatTransport", function () {
910910 expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_uppercase_protocol/chat-stream" ) ;
911911 } ) ;
912912
913+ it ( "supports whitespace-wrapped uppercase http protocol with path prefix" , async function ( ) {
914+ let observedTriggerPath : string | undefined ;
915+ let observedStreamPath : string | undefined ;
916+
917+ const server = await startServer ( function ( req , res ) {
918+ if ( req . method === "POST" ) {
919+ observedTriggerPath = req . url ?? "" ;
920+ }
921+
922+ if ( req . method === "GET" ) {
923+ observedStreamPath = req . url ?? "" ;
924+ }
925+
926+ if ( req . method === "POST" && req . url === "/uppercase-http-prefix/api/v1/tasks/chat-task/trigger" ) {
927+ res . writeHead ( 200 , {
928+ "content-type" : "application/json" ,
929+ "x-trigger-jwt" : "pk_run_uppercase_http_prefix" ,
930+ } ) ;
931+ res . end ( JSON . stringify ( { id : "run_uppercase_http_prefix" } ) ) ;
932+ return ;
933+ }
934+
935+ if (
936+ req . method === "GET" &&
937+ req . url === "/uppercase-http-prefix/realtime/v1/streams/run_uppercase_http_prefix/chat-stream"
938+ ) {
939+ res . writeHead ( 200 , {
940+ "content-type" : "text/event-stream" ,
941+ } ) ;
942+ writeSSE (
943+ res ,
944+ "1-0" ,
945+ JSON . stringify ( { type : "text-start" , id : "uppercase_http_prefix_1" } )
946+ ) ;
947+ writeSSE (
948+ res ,
949+ "2-0" ,
950+ JSON . stringify ( { type : "text-end" , id : "uppercase_http_prefix_1" } )
951+ ) ;
952+ res . end ( ) ;
953+ return ;
954+ }
955+
956+ res . writeHead ( 404 ) ;
957+ res . end ( ) ;
958+ } ) ;
959+
960+ const uppercaseHttpBaseUrl = server . url . replace ( / ^ h t t p : \/ \/ / , "HTTP://" ) ;
961+
962+ const transport = new TriggerChatTransport ( {
963+ task : "chat-task" ,
964+ accessToken : "pk_trigger" ,
965+ baseURL : ` ${ uppercaseHttpBaseUrl } /uppercase-http-prefix/// ` ,
966+ stream : "chat-stream" ,
967+ } ) ;
968+
969+ const stream = await transport . sendMessages ( {
970+ trigger : "submit-message" ,
971+ chatId : "chat-uppercase-http-prefix" ,
972+ messageId : undefined ,
973+ messages : [ ] ,
974+ abortSignal : undefined ,
975+ } ) ;
976+
977+ const chunks = await readChunks ( stream ) ;
978+ expect ( chunks ) . toHaveLength ( 2 ) ;
979+ expect ( observedTriggerPath ) . toBe ( "/uppercase-http-prefix/api/v1/tasks/chat-task/trigger" ) ;
980+ expect ( observedStreamPath ) . toBe (
981+ "/uppercase-http-prefix/realtime/v1/streams/run_uppercase_http_prefix/chat-stream"
982+ ) ;
983+ } ) ;
984+
913985 it ( "combines path prefixes with run and stream URL encoding" , async function ( ) {
914986 let observedTriggerPath : string | undefined ;
915987 let observedStreamPath : string | undefined ;
0 commit comments