@@ -152,6 +152,68 @@ describe("TriggerChatTransport", function () {
152152 expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_encoded_stream/chat%2Fspecial%20stream" ) ;
153153 } ) ;
154154
155+ it ( "encodes run IDs in stream URL paths" , async function ( ) {
156+ let observedStreamPath : string | undefined ;
157+
158+ const server = await startServer ( function ( req , res ) {
159+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
160+ res . writeHead ( 200 , {
161+ "content-type" : "application/json" ,
162+ "x-trigger-jwt" : "pk_run_encoded_run_id" ,
163+ } ) ;
164+ res . end ( JSON . stringify ( { id : "run/with space" } ) ) ;
165+ return ;
166+ }
167+
168+ if ( req . method === "GET" ) {
169+ observedStreamPath = req . url ?? "" ;
170+ }
171+
172+ if (
173+ req . method === "GET" &&
174+ req . url === "/realtime/v1/streams/run%2Fwith%20space/chat-stream"
175+ ) {
176+ res . writeHead ( 200 , {
177+ "content-type" : "text/event-stream" ,
178+ } ) ;
179+ writeSSE (
180+ res ,
181+ "1-0" ,
182+ JSON . stringify ( { type : "text-start" , id : "encoded_run_1" } )
183+ ) ;
184+ writeSSE (
185+ res ,
186+ "2-0" ,
187+ JSON . stringify ( { type : "text-end" , id : "encoded_run_1" } )
188+ ) ;
189+ res . end ( ) ;
190+ return ;
191+ }
192+
193+ res . writeHead ( 404 ) ;
194+ res . end ( ) ;
195+ } ) ;
196+
197+ const transport = new TriggerChatTransport ( {
198+ task : "chat-task" ,
199+ accessToken : "pk_trigger" ,
200+ baseURL : server . url ,
201+ stream : "chat-stream" ,
202+ } ) ;
203+
204+ const stream = await transport . sendMessages ( {
205+ trigger : "submit-message" ,
206+ chatId : "chat-encoded-run-id" ,
207+ messageId : undefined ,
208+ messages : [ ] ,
209+ abortSignal : undefined ,
210+ } ) ;
211+
212+ const chunks = await readChunks ( stream ) ;
213+ expect ( chunks ) . toHaveLength ( 2 ) ;
214+ expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run%2Fwith%20space/chat-stream" ) ;
215+ } ) ;
216+
155217 it ( "uses defined stream object id when provided" , async function ( ) {
156218 let observedStreamPath : string | undefined ;
157219
0 commit comments