@@ -29,6 +29,64 @@ afterEach(async function () {
2929} ) ;
3030
3131describe ( "TriggerChatTransport" , function ( ) {
32+ it ( "uses default stream key when stream option is omitted" , async function ( ) {
33+ let observedStreamPath : string | undefined ;
34+
35+ const server = await startServer ( function ( req , res ) {
36+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
37+ res . writeHead ( 200 , {
38+ "content-type" : "application/json" ,
39+ "x-trigger-jwt" : "pk_run_default_stream" ,
40+ } ) ;
41+ res . end ( JSON . stringify ( { id : "run_default_stream" } ) ) ;
42+ return ;
43+ }
44+
45+ if ( req . method === "GET" ) {
46+ observedStreamPath = req . url ?? "" ;
47+ }
48+
49+ if ( req . method === "GET" && req . url === "/realtime/v1/streams/run_default_stream/default" ) {
50+ res . writeHead ( 200 , {
51+ "content-type" : "text/event-stream" ,
52+ } ) ;
53+ writeSSE (
54+ res ,
55+ "1-0" ,
56+ JSON . stringify ( { type : "text-start" , id : "default_1" } )
57+ ) ;
58+ writeSSE (
59+ res ,
60+ "2-0" ,
61+ JSON . stringify ( { type : "text-end" , id : "default_1" } )
62+ ) ;
63+ res . end ( ) ;
64+ return ;
65+ }
66+
67+ res . writeHead ( 404 ) ;
68+ res . end ( ) ;
69+ } ) ;
70+
71+ const transport = new TriggerChatTransport ( {
72+ task : "chat-task" ,
73+ accessToken : "pk_trigger" ,
74+ baseURL : server . url ,
75+ } ) ;
76+
77+ const stream = await transport . sendMessages ( {
78+ trigger : "submit-message" ,
79+ chatId : "chat-default-stream" ,
80+ messageId : undefined ,
81+ messages : [ ] ,
82+ abortSignal : undefined ,
83+ } ) ;
84+
85+ const chunks = await readChunks ( stream ) ;
86+ expect ( chunks ) . toHaveLength ( 2 ) ;
87+ expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_default_stream/default" ) ;
88+ } ) ;
89+
3290 it ( "triggers task and streams chunks with rich default payload" , async function ( ) {
3391 let receivedTriggerBody : Record < string , unknown > | undefined ;
3492
0 commit comments