@@ -15,6 +15,7 @@ import {
15
15
GraphqlRequest ,
16
16
GraphqlRequestExecutor ,
17
17
} from './graphql_request_executor' ;
18
+ import { UserAgentProvider } from './user_agent_provider' ;
18
19
19
20
void describe ( 'Conversation turn response sender' , ( ) => {
20
21
const event : ConversationTurnEvent = {
@@ -37,7 +38,19 @@ void describe('Conversation turn response sender', () => {
37
38
} ;
38
39
39
40
void it ( 'sends response back to appsync' , async ( ) => {
40
- const graphqlRequestExecutor = new GraphqlRequestExecutor ( '' , '' , '' ) ;
41
+ const userAgentProvider = new UserAgentProvider (
42
+ { } as unknown as ConversationTurnEvent
43
+ ) ;
44
+ const userAgentProviderMock = mock . method (
45
+ userAgentProvider ,
46
+ 'getUserAgent' ,
47
+ ( ) => 'testUserAgent'
48
+ ) ;
49
+ const graphqlRequestExecutor = new GraphqlRequestExecutor (
50
+ '' ,
51
+ '' ,
52
+ userAgentProvider
53
+ ) ;
41
54
const executeGraphqlMock = mock . method (
42
55
graphqlRequestExecutor ,
43
56
'executeGraphql' ,
@@ -47,6 +60,7 @@ void describe('Conversation turn response sender', () => {
47
60
) ;
48
61
const sender = new ConversationTurnResponseSender (
49
62
event ,
63
+ userAgentProvider ,
50
64
graphqlRequestExecutor
51
65
) ;
52
66
const response : Array < ContentBlock > = [
@@ -57,7 +71,14 @@ void describe('Conversation turn response sender', () => {
57
71
] ;
58
72
await sender . sendResponse ( response ) ;
59
73
74
+ assert . strictEqual ( userAgentProviderMock . mock . calls . length , 1 ) ;
75
+ assert . deepStrictEqual ( userAgentProviderMock . mock . calls [ 0 ] . arguments [ 0 ] , {
76
+ 'turn-response-type' : 'single' ,
77
+ } ) ;
60
78
assert . strictEqual ( executeGraphqlMock . mock . calls . length , 1 ) ;
79
+ assert . deepStrictEqual ( executeGraphqlMock . mock . calls [ 0 ] . arguments [ 1 ] , {
80
+ userAgent : 'testUserAgent' ,
81
+ } ) ;
61
82
const request = executeGraphqlMock . mock . calls [ 0 ]
62
83
. arguments [ 0 ] as GraphqlRequest < MutationResponseInput > ;
63
84
assert . deepStrictEqual ( request , {
@@ -85,7 +106,15 @@ void describe('Conversation turn response sender', () => {
85
106
} ) ;
86
107
87
108
void it ( 'serializes tool use input to JSON' , async ( ) => {
88
- const graphqlRequestExecutor = new GraphqlRequestExecutor ( '' , '' , '' ) ;
109
+ const userAgentProvider = new UserAgentProvider (
110
+ { } as unknown as ConversationTurnEvent
111
+ ) ;
112
+ mock . method ( userAgentProvider , 'getUserAgent' , ( ) => '' ) ;
113
+ const graphqlRequestExecutor = new GraphqlRequestExecutor (
114
+ '' ,
115
+ '' ,
116
+ userAgentProvider
117
+ ) ;
89
118
const executeGraphqlMock = mock . method (
90
119
graphqlRequestExecutor ,
91
120
'executeGraphql' ,
@@ -95,6 +124,7 @@ void describe('Conversation turn response sender', () => {
95
124
) ;
96
125
const sender = new ConversationTurnResponseSender (
97
126
event ,
127
+ userAgentProvider ,
98
128
graphqlRequestExecutor
99
129
) ;
100
130
const toolUseBlock : ContentBlock . ToolUseMember = {
@@ -140,7 +170,19 @@ void describe('Conversation turn response sender', () => {
140
170
} ) ;
141
171
142
172
void it ( 'sends streaming response chunk back to appsync' , async ( ) => {
143
- const graphqlRequestExecutor = new GraphqlRequestExecutor ( '' , '' , '' ) ;
173
+ const userAgentProvider = new UserAgentProvider (
174
+ { } as unknown as ConversationTurnEvent
175
+ ) ;
176
+ const userAgentProviderMock = mock . method (
177
+ userAgentProvider ,
178
+ 'getUserAgent' ,
179
+ ( ) => 'testUserAgent'
180
+ ) ;
181
+ const graphqlRequestExecutor = new GraphqlRequestExecutor (
182
+ '' ,
183
+ '' ,
184
+ userAgentProvider
185
+ ) ;
144
186
const executeGraphqlMock = mock . method (
145
187
graphqlRequestExecutor ,
146
188
'executeGraphql' ,
@@ -150,6 +192,7 @@ void describe('Conversation turn response sender', () => {
150
192
) ;
151
193
const sender = new ConversationTurnResponseSender (
152
194
event ,
195
+ userAgentProvider ,
153
196
graphqlRequestExecutor
154
197
) ;
155
198
const chunk : StreamingResponseChunk = {
@@ -162,7 +205,14 @@ void describe('Conversation turn response sender', () => {
162
205
} ;
163
206
await sender . sendResponseChunk ( chunk ) ;
164
207
208
+ assert . strictEqual ( userAgentProviderMock . mock . calls . length , 1 ) ;
209
+ assert . deepStrictEqual ( userAgentProviderMock . mock . calls [ 0 ] . arguments [ 0 ] , {
210
+ 'turn-response-type' : 'streaming' ,
211
+ } ) ;
165
212
assert . strictEqual ( executeGraphqlMock . mock . calls . length , 1 ) ;
213
+ assert . deepStrictEqual ( executeGraphqlMock . mock . calls [ 0 ] . arguments [ 1 ] , {
214
+ userAgent : 'testUserAgent' ,
215
+ } ) ;
166
216
const request = executeGraphqlMock . mock . calls [ 0 ]
167
217
. arguments [ 0 ] as GraphqlRequest < MutationStreamingResponseInput > ;
168
218
assert . deepStrictEqual ( request , {
@@ -181,7 +231,15 @@ void describe('Conversation turn response sender', () => {
181
231
} ) ;
182
232
183
233
void it ( 'serializes tool use input to JSON when streaming' , async ( ) => {
184
- const graphqlRequestExecutor = new GraphqlRequestExecutor ( '' , '' , '' ) ;
234
+ const userAgentProvider = new UserAgentProvider (
235
+ { } as unknown as ConversationTurnEvent
236
+ ) ;
237
+ mock . method ( userAgentProvider , 'getUserAgent' , ( ) => '' ) ;
238
+ const graphqlRequestExecutor = new GraphqlRequestExecutor (
239
+ '' ,
240
+ '' ,
241
+ userAgentProvider
242
+ ) ;
185
243
const executeGraphqlMock = mock . method (
186
244
graphqlRequestExecutor ,
187
245
'executeGraphql' ,
@@ -191,6 +249,7 @@ void describe('Conversation turn response sender', () => {
191
249
) ;
192
250
const sender = new ConversationTurnResponseSender (
193
251
event ,
252
+ userAgentProvider ,
194
253
graphqlRequestExecutor
195
254
) ;
196
255
const toolUseBlock : ContentBlock . ToolUseMember = {
@@ -242,7 +301,19 @@ void describe('Conversation turn response sender', () => {
242
301
} ) ;
243
302
244
303
void it ( 'sends errors response back to appsync' , async ( ) => {
245
- const graphqlRequestExecutor = new GraphqlRequestExecutor ( '' , '' , '' ) ;
304
+ const userAgentProvider = new UserAgentProvider (
305
+ { } as unknown as ConversationTurnEvent
306
+ ) ;
307
+ const userAgentProviderMock = mock . method (
308
+ userAgentProvider ,
309
+ 'getUserAgent' ,
310
+ ( ) => 'testUserAgent'
311
+ ) ;
312
+ const graphqlRequestExecutor = new GraphqlRequestExecutor (
313
+ '' ,
314
+ '' ,
315
+ userAgentProvider
316
+ ) ;
246
317
const executeGraphqlMock = mock . method (
247
318
graphqlRequestExecutor ,
248
319
'executeGraphql' ,
@@ -252,6 +323,7 @@ void describe('Conversation turn response sender', () => {
252
323
) ;
253
324
const sender = new ConversationTurnResponseSender (
254
325
event ,
326
+ userAgentProvider ,
255
327
graphqlRequestExecutor
256
328
) ;
257
329
const errors : Array < ConversationTurnError > = [
@@ -266,6 +338,14 @@ void describe('Conversation turn response sender', () => {
266
338
] ;
267
339
await sender . sendErrors ( errors ) ;
268
340
341
+ assert . strictEqual ( userAgentProviderMock . mock . calls . length , 1 ) ;
342
+ assert . deepStrictEqual ( userAgentProviderMock . mock . calls [ 0 ] . arguments [ 0 ] , {
343
+ 'turn-response-type' : 'error' ,
344
+ } ) ;
345
+ assert . strictEqual ( executeGraphqlMock . mock . calls . length , 1 ) ;
346
+ assert . deepStrictEqual ( executeGraphqlMock . mock . calls [ 0 ] . arguments [ 1 ] , {
347
+ userAgent : 'testUserAgent' ,
348
+ } ) ;
269
349
assert . strictEqual ( executeGraphqlMock . mock . calls . length , 1 ) ;
270
350
const request = executeGraphqlMock . mock . calls [ 0 ]
271
351
. arguments [ 0 ] as GraphqlRequest < MutationResponseInput > ;
0 commit comments