@@ -76,7 +76,7 @@ describe("test", () => {
7676 expect ( jsonResponse . jsonrpc ) . toBe ( "2.0" ) ;
7777 expect ( jsonResponse . id ) . toBe ( "1" ) ;
7878 expect ( jsonResponse . result . tools ) . toBeDefined ( ) ;
79- expect ( jsonResponse . result . tools . length ) . toBe ( 1 ) ;
79+ expect ( jsonResponse . result . tools . length ) . toBe ( 2 ) ;
8080 expect ( jsonResponse . result . tools [ 0 ] ) . toEqual ( {
8181 name : "greet" ,
8282 description : "A simple greeting tool" ,
@@ -110,7 +110,7 @@ describe("test", () => {
110110 const sessionId = lines [ 1 ] . split ( "=" ) [ 1 ] ;
111111 expect ( sessionId ) . toBeDefined ( ) ;
112112
113- // send a message to the session to list the tools
113+ // send a message to the session to invoke the greet tool
114114 const toolsRequest = new Request (
115115 `http://example.com/sse/message?sessionId=${ sessionId } ` ,
116116 {
@@ -156,4 +156,66 @@ describe("test", () => {
156156 } ,
157157 } ) ;
158158 } ) ;
159+
160+ it ( "should pass props to the agent" , async ( ) => {
161+ const ctx = createExecutionContext ( ) ;
162+
163+ const request = new Request ( "http://example.com/sse" ) ;
164+ const sseStream = await worker . fetch ( request , env , ctx ) ;
165+
166+ const reader = sseStream . body ?. getReader ( ) ;
167+ let { done, value } = await reader ! . read ( ) ;
168+ const event = new TextDecoder ( ) . decode ( value ) ;
169+
170+ // parse the session id from the event
171+ const lines = event . split ( "\n" ) ;
172+ const sessionId = lines [ 1 ] . split ( "=" ) [ 1 ] ;
173+ expect ( sessionId ) . toBeDefined ( ) ;
174+
175+ // send a message to the session to invoke the getPropsTestValue tool
176+ const toolsRequest = new Request (
177+ `http://example.com/sse/message?sessionId=${ sessionId } ` ,
178+ {
179+ method : "POST" ,
180+ headers : {
181+ "Content-Type" : "application/json" ,
182+ } ,
183+ body : JSON . stringify ( {
184+ jsonrpc : "2.0" ,
185+ method : "tools/call" ,
186+ id : "2" ,
187+ params : {
188+ name : "getPropsTestValue" ,
189+ arguments : { } ,
190+ } ,
191+ } ) ,
192+ }
193+ ) ;
194+
195+ const toolsResponse = await worker . fetch ( toolsRequest , env , ctx ) ;
196+ expect ( toolsResponse . status ) . toBe ( 202 ) ;
197+ expect ( toolsResponse . headers . get ( "Content-Type" ) ) . toBe ( "text/event-stream" ) ;
198+ expect ( await toolsResponse . text ( ) ) . toBe ( "Accepted" ) ;
199+
200+ ( { done, value } = await reader ! . read ( ) ) ;
201+
202+ expect ( done ) . toBe ( false ) ;
203+ const toolsEvent = new TextDecoder ( ) . decode ( value ) ;
204+ const jsonResponse = JSON . parse (
205+ toolsEvent . split ( "\n" ) [ 1 ] . replace ( "data: " , "" )
206+ ) ;
207+
208+ expect ( jsonResponse ) . toEqual ( {
209+ jsonrpc : "2.0" ,
210+ id : "2" ,
211+ result : {
212+ content : [
213+ {
214+ type : "text" ,
215+ text : "123" ,
216+ } ,
217+ ] ,
218+ } ,
219+ } ) ;
220+ } ) ;
159221} ) ;
0 commit comments