@@ -87,6 +87,68 @@ describe("TriggerChatTransport", function () {
8787 expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_default_stream/default" ) ;
8888 } ) ;
8989
90+ it ( "encodes stream key values in stream URL paths" , async function ( ) {
91+ let observedStreamPath : string | undefined ;
92+
93+ const server = await startServer ( function ( req , res ) {
94+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
95+ res . writeHead ( 200 , {
96+ "content-type" : "application/json" ,
97+ "x-trigger-jwt" : "pk_run_encoded_stream" ,
98+ } ) ;
99+ res . end ( JSON . stringify ( { id : "run_encoded_stream" } ) ) ;
100+ return ;
101+ }
102+
103+ if ( req . method === "GET" ) {
104+ observedStreamPath = req . url ?? "" ;
105+ }
106+
107+ if (
108+ req . method === "GET" &&
109+ req . url === "/realtime/v1/streams/run_encoded_stream/chat%2Fspecial%20stream"
110+ ) {
111+ res . writeHead ( 200 , {
112+ "content-type" : "text/event-stream" ,
113+ } ) ;
114+ writeSSE (
115+ res ,
116+ "1-0" ,
117+ JSON . stringify ( { type : "text-start" , id : "encoded_1" } )
118+ ) ;
119+ writeSSE (
120+ res ,
121+ "2-0" ,
122+ JSON . stringify ( { type : "text-end" , id : "encoded_1" } )
123+ ) ;
124+ res . end ( ) ;
125+ return ;
126+ }
127+
128+ res . writeHead ( 404 ) ;
129+ res . end ( ) ;
130+ } ) ;
131+
132+ const transport = new TriggerChatTransport ( {
133+ task : "chat-task" ,
134+ accessToken : "pk_trigger" ,
135+ baseURL : server . url ,
136+ stream : "chat/special stream" ,
137+ } ) ;
138+
139+ const stream = await transport . sendMessages ( {
140+ trigger : "submit-message" ,
141+ chatId : "chat-encoded-stream" ,
142+ messageId : undefined ,
143+ messages : [ ] ,
144+ abortSignal : undefined ,
145+ } ) ;
146+
147+ const chunks = await readChunks ( stream ) ;
148+ expect ( chunks ) . toHaveLength ( 2 ) ;
149+ expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_encoded_stream/chat%2Fspecial%20stream" ) ;
150+ } ) ;
151+
90152 it ( "triggers task and streams chunks with rich default payload" , async function ( ) {
91153 let receivedTriggerBody : Record < string , unknown > | undefined ;
92154
0 commit comments