@copilotkit/runtime-client-gql 1.9.3-next.4 → 1.10.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/chunk-2R7M2FWR.mjs +17765 -0
- package/dist/chunk-2R7M2FWR.mjs.map +1 -0
- package/dist/chunk-CA4VMP2C.mjs +1 -0
- package/dist/chunk-CA4VMP2C.mjs.map +1 -0
- package/dist/chunk-DELDZXUX.mjs +31 -0
- package/dist/chunk-DELDZXUX.mjs.map +1 -0
- package/dist/chunk-MTD2RJDJ.mjs +187 -0
- package/dist/chunk-MTD2RJDJ.mjs.map +1 -0
- package/dist/{chunk-MCVCTWSF.mjs → chunk-UQACSQNW.mjs} +5 -5
- package/dist/{chunk-MCVCTWSF.mjs.map → chunk-UQACSQNW.mjs.map} +1 -1
- package/dist/chunk-YNQMTL2P.mjs +191 -0
- package/dist/chunk-YNQMTL2P.mjs.map +1 -0
- package/dist/client/CopilotRuntimeClient.js +1 -1
- package/dist/client/CopilotRuntimeClient.js.map +1 -1
- package/dist/client/CopilotRuntimeClient.mjs +3 -2
- package/dist/client/conversion.mjs +1 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +5 -4
- package/dist/client/types.mjs +1 -0
- package/dist/graphql/@generated/fragment-masking.mjs +1 -0
- package/dist/graphql/@generated/gql.mjs +1 -0
- package/dist/graphql/@generated/graphql.mjs +1 -0
- package/dist/graphql/@generated/index.mjs +5 -4
- package/dist/graphql/definitions/mutations.mjs +1 -0
- package/dist/graphql/definitions/queries.mjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +370 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -4
- package/dist/magic-string.es-O42ACB6H.mjs +1373 -0
- package/dist/magic-string.es-O42ACB6H.mjs.map +1 -0
- package/dist/message-conversion/agui-to-gql.d.ts +13 -0
- package/dist/message-conversion/agui-to-gql.js +293 -0
- package/dist/message-conversion/agui-to-gql.js.map +1 -0
- package/dist/message-conversion/agui-to-gql.mjs +26 -0
- package/dist/message-conversion/agui-to-gql.mjs.map +1 -0
- package/dist/message-conversion/agui-to-gql.test.d.ts +2 -0
- package/dist/message-conversion/agui-to-gql.test.js +19958 -0
- package/dist/message-conversion/agui-to-gql.test.js.map +1 -0
- package/dist/message-conversion/agui-to-gql.test.mjs +565 -0
- package/dist/message-conversion/agui-to-gql.test.mjs.map +1 -0
- package/dist/message-conversion/gql-to-agui.d.ts +11 -0
- package/dist/message-conversion/gql-to-agui.js +227 -0
- package/dist/message-conversion/gql-to-agui.js.map +1 -0
- package/dist/message-conversion/gql-to-agui.mjs +22 -0
- package/dist/message-conversion/gql-to-agui.mjs.map +1 -0
- package/dist/message-conversion/gql-to-agui.test.d.ts +2 -0
- package/dist/message-conversion/gql-to-agui.test.js +20134 -0
- package/dist/message-conversion/gql-to-agui.test.js.map +1 -0
- package/dist/message-conversion/gql-to-agui.test.mjs +737 -0
- package/dist/message-conversion/gql-to-agui.test.mjs.map +1 -0
- package/dist/message-conversion/index.d.ts +6 -0
- package/dist/message-conversion/index.js +477 -0
- package/dist/message-conversion/index.js.map +1 -0
- package/dist/message-conversion/index.mjs +37 -0
- package/dist/message-conversion/index.mjs.map +1 -0
- package/dist/message-conversion/roundtrip-conversion.test.d.ts +2 -0
- package/dist/message-conversion/roundtrip-conversion.test.js +19768 -0
- package/dist/message-conversion/roundtrip-conversion.test.js.map +1 -0
- package/dist/message-conversion/roundtrip-conversion.test.mjs +219 -0
- package/dist/message-conversion/roundtrip-conversion.test.mjs.map +1 -0
- package/package.json +7 -5
- package/src/index.ts +1 -0
- package/src/message-conversion/agui-to-gql.test.ts +640 -0
- package/src/message-conversion/agui-to-gql.ts +255 -0
- package/src/message-conversion/gql-to-agui.test.ts +844 -0
- package/src/message-conversion/gql-to-agui.ts +237 -0
- package/src/message-conversion/index.ts +2 -0
- package/src/message-conversion/roundtrip-conversion.test.ts +212 -0
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
import {
|
|
2
|
+
gqlImageMessageToAGUIMessage,
|
|
3
|
+
gqlResultMessageToAGUIMessage,
|
|
4
|
+
gqlTextMessageToAGUIMessage,
|
|
5
|
+
gqlToAGUI
|
|
6
|
+
} from "../chunk-MTD2RJDJ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
describe,
|
|
9
|
+
globalExpect,
|
|
10
|
+
test,
|
|
11
|
+
vi
|
|
12
|
+
} from "../chunk-2R7M2FWR.mjs";
|
|
13
|
+
import "../chunk-7ECCT6PK.mjs";
|
|
14
|
+
import "../chunk-UQACSQNW.mjs";
|
|
15
|
+
import "../chunk-X2UAP3QY.mjs";
|
|
16
|
+
import "../chunk-HEODM5TW.mjs";
|
|
17
|
+
import "../chunk-4KTMZMM2.mjs";
|
|
18
|
+
import "../chunk-P2AUSQOK.mjs";
|
|
19
|
+
import {
|
|
20
|
+
ActionExecutionMessage,
|
|
21
|
+
AgentStateMessage,
|
|
22
|
+
ImageMessage,
|
|
23
|
+
ResultMessage,
|
|
24
|
+
Role,
|
|
25
|
+
TextMessage
|
|
26
|
+
} from "../chunk-ROUIRR4B.mjs";
|
|
27
|
+
import "../chunk-WM3ARNBD.mjs";
|
|
28
|
+
import "../chunk-DELDZXUX.mjs";
|
|
29
|
+
|
|
30
|
+
// src/message-conversion/gql-to-agui.test.ts
|
|
31
|
+
describe("message-conversion", () => {
|
|
32
|
+
describe("gqlTextMessageToAGUIMessage", () => {
|
|
33
|
+
test("should convert developer message", () => {
|
|
34
|
+
const gqlMessage = new TextMessage({
|
|
35
|
+
id: "dev-message-id",
|
|
36
|
+
content: "Hello from developer",
|
|
37
|
+
role: Role.Developer
|
|
38
|
+
});
|
|
39
|
+
const result = gqlTextMessageToAGUIMessage(gqlMessage);
|
|
40
|
+
globalExpect(result).toEqual({
|
|
41
|
+
id: "dev-message-id",
|
|
42
|
+
role: "developer",
|
|
43
|
+
content: "Hello from developer"
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
test("should convert system message", () => {
|
|
47
|
+
const gqlMessage = new TextMessage({
|
|
48
|
+
id: "system-message-id",
|
|
49
|
+
content: "System instruction",
|
|
50
|
+
role: Role.System
|
|
51
|
+
});
|
|
52
|
+
const result = gqlTextMessageToAGUIMessage(gqlMessage);
|
|
53
|
+
globalExpect(result).toEqual({
|
|
54
|
+
id: "system-message-id",
|
|
55
|
+
role: "system",
|
|
56
|
+
content: "System instruction"
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
test("should convert assistant message", () => {
|
|
60
|
+
const gqlMessage = new TextMessage({
|
|
61
|
+
id: "assistant-message-id",
|
|
62
|
+
content: "Assistant response",
|
|
63
|
+
role: Role.Assistant
|
|
64
|
+
});
|
|
65
|
+
const result = gqlTextMessageToAGUIMessage(gqlMessage);
|
|
66
|
+
globalExpect(result).toEqual({
|
|
67
|
+
id: "assistant-message-id",
|
|
68
|
+
role: "assistant",
|
|
69
|
+
content: "Assistant response"
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
test("should throw error for unknown role", () => {
|
|
73
|
+
const gqlMessage = new TextMessage({
|
|
74
|
+
id: "unknown-message-id",
|
|
75
|
+
content: "Unknown message",
|
|
76
|
+
role: "unknown"
|
|
77
|
+
});
|
|
78
|
+
globalExpect(() => gqlTextMessageToAGUIMessage(gqlMessage)).toThrow("Unknown message role");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("gqlResultMessageToAGUIMessage", () => {
|
|
82
|
+
test("should convert result message to tool message", () => {
|
|
83
|
+
const gqlMessage = new ResultMessage({
|
|
84
|
+
id: "result-id",
|
|
85
|
+
result: "Function result data",
|
|
86
|
+
actionExecutionId: "action-exec-123",
|
|
87
|
+
actionName: "testAction"
|
|
88
|
+
});
|
|
89
|
+
const result = gqlResultMessageToAGUIMessage(gqlMessage);
|
|
90
|
+
globalExpect(result).toEqual({
|
|
91
|
+
id: "result-id",
|
|
92
|
+
role: "tool",
|
|
93
|
+
content: "Function result data",
|
|
94
|
+
toolCallId: "action-exec-123",
|
|
95
|
+
toolName: "testAction"
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe("gqlToAGUI", () => {
|
|
100
|
+
test("should convert an array of text messages", () => {
|
|
101
|
+
const gqlMessages = [
|
|
102
|
+
new TextMessage({
|
|
103
|
+
id: "dev-1",
|
|
104
|
+
content: "Hello",
|
|
105
|
+
role: Role.Developer
|
|
106
|
+
}),
|
|
107
|
+
new TextMessage({
|
|
108
|
+
id: "assistant-1",
|
|
109
|
+
content: "Hi there",
|
|
110
|
+
role: Role.Assistant
|
|
111
|
+
})
|
|
112
|
+
];
|
|
113
|
+
const result = gqlToAGUI(gqlMessages);
|
|
114
|
+
globalExpect(result).toHaveLength(2);
|
|
115
|
+
globalExpect(result[0]).toEqual({
|
|
116
|
+
id: "dev-1",
|
|
117
|
+
role: "developer",
|
|
118
|
+
content: "Hello"
|
|
119
|
+
});
|
|
120
|
+
globalExpect(result[1]).toEqual({
|
|
121
|
+
id: "assistant-1",
|
|
122
|
+
role: "assistant",
|
|
123
|
+
content: "Hi there"
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
test("should handle agent state messages", () => {
|
|
127
|
+
const gqlMessages = [new AgentStateMessage({ id: "agent-state-1" })];
|
|
128
|
+
const result = gqlToAGUI(gqlMessages);
|
|
129
|
+
globalExpect(result).toHaveLength(1);
|
|
130
|
+
globalExpect(result[0]).toEqual({
|
|
131
|
+
id: "agent-state-1",
|
|
132
|
+
role: "assistant"
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
test("should handle a mix of message types", () => {
|
|
136
|
+
const gqlMessages = [
|
|
137
|
+
new TextMessage({
|
|
138
|
+
id: "dev-1",
|
|
139
|
+
content: "Run action",
|
|
140
|
+
role: Role.Developer
|
|
141
|
+
}),
|
|
142
|
+
new TextMessage({
|
|
143
|
+
id: "assistant-1",
|
|
144
|
+
content: "I'll run the action",
|
|
145
|
+
role: Role.Assistant
|
|
146
|
+
}),
|
|
147
|
+
new ResultMessage({
|
|
148
|
+
id: "result-1",
|
|
149
|
+
result: "Action result",
|
|
150
|
+
actionExecutionId: "action-exec-1",
|
|
151
|
+
actionName: "testAction"
|
|
152
|
+
})
|
|
153
|
+
];
|
|
154
|
+
const result = gqlToAGUI(gqlMessages);
|
|
155
|
+
globalExpect(result).toHaveLength(3);
|
|
156
|
+
globalExpect(result[0]).toEqual({
|
|
157
|
+
id: "dev-1",
|
|
158
|
+
role: "developer",
|
|
159
|
+
content: "Run action"
|
|
160
|
+
});
|
|
161
|
+
globalExpect(result[1]).toEqual({
|
|
162
|
+
id: "assistant-1",
|
|
163
|
+
role: "assistant",
|
|
164
|
+
content: "I'll run the action"
|
|
165
|
+
});
|
|
166
|
+
globalExpect(result[2]).toEqual({
|
|
167
|
+
id: "result-1",
|
|
168
|
+
role: "tool",
|
|
169
|
+
content: "Action result",
|
|
170
|
+
toolCallId: "action-exec-1",
|
|
171
|
+
toolName: "testAction"
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
test("should handle action execution messages with parent messages", () => {
|
|
175
|
+
const assistantMsg = new TextMessage({
|
|
176
|
+
id: "assistant-1",
|
|
177
|
+
content: "I'll execute an action",
|
|
178
|
+
role: Role.Assistant
|
|
179
|
+
});
|
|
180
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
181
|
+
id: "action-1",
|
|
182
|
+
name: "testAction",
|
|
183
|
+
arguments: { param: "value" },
|
|
184
|
+
parentMessageId: "assistant-1"
|
|
185
|
+
});
|
|
186
|
+
const result = gqlToAGUI([assistantMsg, actionExecMsg]);
|
|
187
|
+
globalExpect(result).toHaveLength(2);
|
|
188
|
+
globalExpect(result[0]).toEqual({
|
|
189
|
+
id: "assistant-1",
|
|
190
|
+
role: "assistant",
|
|
191
|
+
content: "I'll execute an action"
|
|
192
|
+
});
|
|
193
|
+
globalExpect(result[1]).toEqual({
|
|
194
|
+
id: "action-1",
|
|
195
|
+
role: "assistant",
|
|
196
|
+
name: "testAction",
|
|
197
|
+
toolCalls: [
|
|
198
|
+
{
|
|
199
|
+
id: "action-1",
|
|
200
|
+
function: {
|
|
201
|
+
name: "testAction",
|
|
202
|
+
arguments: JSON.stringify({ param: "value" })
|
|
203
|
+
},
|
|
204
|
+
type: "function"
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
test("should handle multiple action execution messages for the same parent", () => {
|
|
210
|
+
const assistantMsg = new TextMessage({
|
|
211
|
+
id: "assistant-1",
|
|
212
|
+
content: "I'll execute multiple actions",
|
|
213
|
+
role: Role.Assistant
|
|
214
|
+
});
|
|
215
|
+
const action1 = new ActionExecutionMessage({
|
|
216
|
+
id: "action-1",
|
|
217
|
+
name: "firstAction",
|
|
218
|
+
arguments: { param: "value1" },
|
|
219
|
+
parentMessageId: "assistant-1"
|
|
220
|
+
});
|
|
221
|
+
const action2 = new ActionExecutionMessage({
|
|
222
|
+
id: "action-2",
|
|
223
|
+
name: "secondAction",
|
|
224
|
+
arguments: { param: "value2" },
|
|
225
|
+
parentMessageId: "assistant-1"
|
|
226
|
+
});
|
|
227
|
+
const result = gqlToAGUI([assistantMsg, action1, action2]);
|
|
228
|
+
globalExpect(result).toHaveLength(3);
|
|
229
|
+
globalExpect(result[0]).toEqual({
|
|
230
|
+
id: "assistant-1",
|
|
231
|
+
role: "assistant",
|
|
232
|
+
content: "I'll execute multiple actions"
|
|
233
|
+
});
|
|
234
|
+
globalExpect(result[1]).toEqual({
|
|
235
|
+
id: "action-1",
|
|
236
|
+
role: "assistant",
|
|
237
|
+
name: "firstAction",
|
|
238
|
+
toolCalls: [
|
|
239
|
+
{
|
|
240
|
+
id: "action-1",
|
|
241
|
+
function: {
|
|
242
|
+
name: "firstAction",
|
|
243
|
+
arguments: JSON.stringify({ param: "value1" })
|
|
244
|
+
},
|
|
245
|
+
type: "function"
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
});
|
|
249
|
+
globalExpect(result[2]).toEqual({
|
|
250
|
+
id: "action-2",
|
|
251
|
+
role: "assistant",
|
|
252
|
+
name: "secondAction",
|
|
253
|
+
toolCalls: [
|
|
254
|
+
{
|
|
255
|
+
id: "action-2",
|
|
256
|
+
function: {
|
|
257
|
+
name: "secondAction",
|
|
258
|
+
arguments: JSON.stringify({ param: "value2" })
|
|
259
|
+
},
|
|
260
|
+
type: "function"
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
test("should not add toolCalls to non-assistant messages", () => {
|
|
266
|
+
const developerMsg = new TextMessage({
|
|
267
|
+
id: "dev-1",
|
|
268
|
+
content: "Developer message",
|
|
269
|
+
role: Role.Developer
|
|
270
|
+
});
|
|
271
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
272
|
+
id: "action-1",
|
|
273
|
+
name: "testAction",
|
|
274
|
+
arguments: { param: "value" },
|
|
275
|
+
parentMessageId: "dev-1"
|
|
276
|
+
// This should be ignored since parent is not assistant
|
|
277
|
+
});
|
|
278
|
+
const result = gqlToAGUI([developerMsg, actionExecMsg]);
|
|
279
|
+
globalExpect(result).toHaveLength(2);
|
|
280
|
+
globalExpect(result[0]).toEqual({
|
|
281
|
+
id: "dev-1",
|
|
282
|
+
role: "developer",
|
|
283
|
+
content: "Developer message"
|
|
284
|
+
});
|
|
285
|
+
globalExpect(result[1]).toEqual({
|
|
286
|
+
id: "action-1",
|
|
287
|
+
role: "assistant",
|
|
288
|
+
name: "testAction",
|
|
289
|
+
toolCalls: [
|
|
290
|
+
{
|
|
291
|
+
id: "action-1",
|
|
292
|
+
function: {
|
|
293
|
+
name: "testAction",
|
|
294
|
+
arguments: JSON.stringify({ param: "value" })
|
|
295
|
+
},
|
|
296
|
+
type: "function"
|
|
297
|
+
}
|
|
298
|
+
]
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
test("should handle action execution messages without actions context", () => {
|
|
302
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
303
|
+
id: "action-1",
|
|
304
|
+
name: "testAction",
|
|
305
|
+
arguments: { param: "value" }
|
|
306
|
+
});
|
|
307
|
+
const result = gqlToAGUI([actionExecMsg]);
|
|
308
|
+
globalExpect(result).toHaveLength(1);
|
|
309
|
+
globalExpect(result[0]).toEqual({
|
|
310
|
+
id: "action-1",
|
|
311
|
+
role: "assistant",
|
|
312
|
+
name: "testAction",
|
|
313
|
+
toolCalls: [
|
|
314
|
+
{
|
|
315
|
+
id: "action-1",
|
|
316
|
+
function: {
|
|
317
|
+
name: "testAction",
|
|
318
|
+
arguments: JSON.stringify({ param: "value" })
|
|
319
|
+
},
|
|
320
|
+
type: "function"
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
});
|
|
324
|
+
globalExpect(result[0]).not.toHaveProperty("render");
|
|
325
|
+
globalExpect(result[0]).not.toHaveProperty("renderAndWaitForResponse");
|
|
326
|
+
});
|
|
327
|
+
test("should handle action execution messages with actions context and render functions", () => {
|
|
328
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
329
|
+
id: "action-1",
|
|
330
|
+
name: "testAction",
|
|
331
|
+
arguments: { param: "value" },
|
|
332
|
+
status: { code: "Pending" /* Pending */ }
|
|
333
|
+
});
|
|
334
|
+
const mockRender = vi.fn();
|
|
335
|
+
const mockRenderAndWaitForResponse = (props) => "Test Render With Response";
|
|
336
|
+
const actions = {
|
|
337
|
+
testAction: {
|
|
338
|
+
name: "testAction",
|
|
339
|
+
render: mockRender,
|
|
340
|
+
renderAndWaitForResponse: mockRenderAndWaitForResponse
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const result = gqlToAGUI([actionExecMsg], actions);
|
|
344
|
+
globalExpect(result).toHaveLength(1);
|
|
345
|
+
globalExpect(result[0]).toMatchObject({
|
|
346
|
+
id: "action-1",
|
|
347
|
+
role: "assistant",
|
|
348
|
+
name: "testAction",
|
|
349
|
+
content: "",
|
|
350
|
+
toolCalls: [
|
|
351
|
+
{
|
|
352
|
+
id: "action-1",
|
|
353
|
+
function: {
|
|
354
|
+
name: "testAction",
|
|
355
|
+
arguments: JSON.stringify({ param: "value" })
|
|
356
|
+
},
|
|
357
|
+
type: "function"
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
});
|
|
361
|
+
globalExpect(result[0]).toHaveProperty("generativeUI");
|
|
362
|
+
globalExpect(typeof result[0].generativeUI).toBe("function");
|
|
363
|
+
});
|
|
364
|
+
test("should provide correct status in generativeUI function props", () => {
|
|
365
|
+
var _a, _b;
|
|
366
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
367
|
+
id: "action-1",
|
|
368
|
+
name: "testAction",
|
|
369
|
+
arguments: { param: "value" },
|
|
370
|
+
status: { code: "Pending" /* Pending */ }
|
|
371
|
+
});
|
|
372
|
+
const mockRender = vi.fn();
|
|
373
|
+
const actions = {
|
|
374
|
+
testAction: {
|
|
375
|
+
name: "testAction",
|
|
376
|
+
render: mockRender
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const result = gqlToAGUI([actionExecMsg], actions);
|
|
380
|
+
(_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a);
|
|
381
|
+
globalExpect(mockRender).toHaveBeenCalledWith({
|
|
382
|
+
status: "inProgress",
|
|
383
|
+
args: { param: "value" },
|
|
384
|
+
result: void 0,
|
|
385
|
+
respond: globalExpect.any(Function),
|
|
386
|
+
messageId: "action-1"
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
test("should provide executing status when not pending", () => {
|
|
390
|
+
var _a, _b;
|
|
391
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
392
|
+
id: "action-1",
|
|
393
|
+
name: "testAction",
|
|
394
|
+
arguments: { param: "value" },
|
|
395
|
+
status: { code: "Success" /* Success */ }
|
|
396
|
+
});
|
|
397
|
+
const mockRender = vi.fn();
|
|
398
|
+
const actions = {
|
|
399
|
+
testAction: {
|
|
400
|
+
name: "testAction",
|
|
401
|
+
render: mockRender
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const result = gqlToAGUI([actionExecMsg], actions);
|
|
405
|
+
(_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a);
|
|
406
|
+
globalExpect(mockRender).toHaveBeenCalledWith({
|
|
407
|
+
status: "executing",
|
|
408
|
+
args: { param: "value" },
|
|
409
|
+
result: void 0,
|
|
410
|
+
respond: globalExpect.any(Function),
|
|
411
|
+
messageId: "action-1"
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
test("should provide complete status when result is available", () => {
|
|
415
|
+
var _a;
|
|
416
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
417
|
+
id: "action-1",
|
|
418
|
+
name: "testAction",
|
|
419
|
+
arguments: { param: "value" },
|
|
420
|
+
status: { code: "Success" /* Success */ }
|
|
421
|
+
});
|
|
422
|
+
const resultMsg = new ResultMessage({
|
|
423
|
+
id: "result-1",
|
|
424
|
+
result: "Action completed successfully",
|
|
425
|
+
actionExecutionId: "action-1",
|
|
426
|
+
actionName: "testAction"
|
|
427
|
+
});
|
|
428
|
+
const mockRender = vi.fn();
|
|
429
|
+
const actions = {
|
|
430
|
+
testAction: {
|
|
431
|
+
name: "testAction",
|
|
432
|
+
render: mockRender
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
const result = gqlToAGUI([actionExecMsg, resultMsg], actions);
|
|
436
|
+
const actionMessage = result.find((msg) => msg.role === "assistant" && "toolCalls" in msg);
|
|
437
|
+
(_a = actionMessage == null ? void 0 : actionMessage.generativeUI) == null ? void 0 : _a.call(actionMessage);
|
|
438
|
+
globalExpect(mockRender).toHaveBeenCalledWith({
|
|
439
|
+
status: "complete",
|
|
440
|
+
args: { param: "value" },
|
|
441
|
+
result: "Action completed successfully",
|
|
442
|
+
respond: globalExpect.any(Function),
|
|
443
|
+
messageId: "action-1"
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
test("should handle generativeUI function props override", () => {
|
|
447
|
+
var _a, _b;
|
|
448
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
449
|
+
id: "action-1",
|
|
450
|
+
name: "testAction",
|
|
451
|
+
arguments: { param: "value" },
|
|
452
|
+
status: { code: "Pending" /* Pending */ }
|
|
453
|
+
});
|
|
454
|
+
const mockRender = vi.fn();
|
|
455
|
+
const actions = {
|
|
456
|
+
testAction: {
|
|
457
|
+
name: "testAction",
|
|
458
|
+
render: mockRender
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
const result = gqlToAGUI([actionExecMsg], actions);
|
|
462
|
+
(_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a, {
|
|
463
|
+
status: "custom",
|
|
464
|
+
customProp: "test",
|
|
465
|
+
respond: () => "custom respond"
|
|
466
|
+
});
|
|
467
|
+
globalExpect(mockRender).toHaveBeenCalledWith({
|
|
468
|
+
status: "custom",
|
|
469
|
+
args: { param: "value" },
|
|
470
|
+
result: void 0,
|
|
471
|
+
respond: globalExpect.any(Function),
|
|
472
|
+
customProp: "test",
|
|
473
|
+
messageId: "action-1"
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
test("should handle missing render functions gracefully", () => {
|
|
477
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
478
|
+
id: "action-1",
|
|
479
|
+
name: "testAction",
|
|
480
|
+
arguments: { param: "value" }
|
|
481
|
+
});
|
|
482
|
+
const actions = {
|
|
483
|
+
testAction: {
|
|
484
|
+
name: "testAction"
|
|
485
|
+
// No render functions provided
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const result = gqlToAGUI([actionExecMsg], actions);
|
|
489
|
+
globalExpect(result[0]).toMatchObject({
|
|
490
|
+
id: "action-1",
|
|
491
|
+
role: "assistant",
|
|
492
|
+
name: "testAction",
|
|
493
|
+
content: "",
|
|
494
|
+
toolCalls: [
|
|
495
|
+
{
|
|
496
|
+
id: "action-1",
|
|
497
|
+
function: {
|
|
498
|
+
name: "testAction",
|
|
499
|
+
arguments: JSON.stringify({ param: "value" })
|
|
500
|
+
},
|
|
501
|
+
type: "function"
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
});
|
|
505
|
+
globalExpect(result[0].generativeUI).toBeUndefined();
|
|
506
|
+
});
|
|
507
|
+
test("should handle action not found in actions context", () => {
|
|
508
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
509
|
+
id: "action-1",
|
|
510
|
+
name: "unknownAction",
|
|
511
|
+
arguments: { param: "value" }
|
|
512
|
+
});
|
|
513
|
+
const actions = {
|
|
514
|
+
testAction: {
|
|
515
|
+
name: "testAction",
|
|
516
|
+
render: () => "Test"
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
const result = gqlToAGUI([actionExecMsg], actions);
|
|
520
|
+
globalExpect(result).toHaveLength(1);
|
|
521
|
+
globalExpect(result[0]).toEqual({
|
|
522
|
+
id: "action-1",
|
|
523
|
+
role: "assistant",
|
|
524
|
+
name: "unknownAction",
|
|
525
|
+
toolCalls: [
|
|
526
|
+
{
|
|
527
|
+
id: "action-1",
|
|
528
|
+
function: {
|
|
529
|
+
name: "unknownAction",
|
|
530
|
+
arguments: JSON.stringify({ param: "value" })
|
|
531
|
+
},
|
|
532
|
+
type: "function"
|
|
533
|
+
}
|
|
534
|
+
]
|
|
535
|
+
});
|
|
536
|
+
globalExpect(result[0]).not.toHaveProperty("generativeUI");
|
|
537
|
+
});
|
|
538
|
+
test("should handle agent state messages with coAgentStateRenders", () => {
|
|
539
|
+
var _a, _b;
|
|
540
|
+
const agentStateMsg = new AgentStateMessage({
|
|
541
|
+
id: "agent-state-1",
|
|
542
|
+
agentName: "testAgent",
|
|
543
|
+
state: { status: "running", data: "test data" },
|
|
544
|
+
role: Role.Assistant
|
|
545
|
+
});
|
|
546
|
+
const mockRender = vi.fn();
|
|
547
|
+
const coAgentStateRenders = {
|
|
548
|
+
testAgent: {
|
|
549
|
+
name: "testAgent",
|
|
550
|
+
render: mockRender
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
const result = gqlToAGUI([agentStateMsg], void 0, coAgentStateRenders);
|
|
554
|
+
globalExpect(result).toHaveLength(1);
|
|
555
|
+
globalExpect(result[0]).toEqual({
|
|
556
|
+
id: "agent-state-1",
|
|
557
|
+
role: "assistant",
|
|
558
|
+
agentName: "testAgent",
|
|
559
|
+
state: { status: "running", data: "test data" },
|
|
560
|
+
generativeUI: globalExpect.any(Function)
|
|
561
|
+
});
|
|
562
|
+
globalExpect(result[0]).toHaveProperty("generativeUI");
|
|
563
|
+
globalExpect(typeof result[0].generativeUI).toBe("function");
|
|
564
|
+
(_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a);
|
|
565
|
+
globalExpect(mockRender).toHaveBeenCalledWith({
|
|
566
|
+
state: { status: "running", data: "test data" }
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
test("should handle agent state messages without coAgentStateRenders", () => {
|
|
570
|
+
const agentStateMsg = new AgentStateMessage({
|
|
571
|
+
id: "agent-state-1",
|
|
572
|
+
agentName: "testAgent",
|
|
573
|
+
state: { status: "running", data: "test data" },
|
|
574
|
+
role: Role.Assistant
|
|
575
|
+
});
|
|
576
|
+
const result = gqlToAGUI([agentStateMsg]);
|
|
577
|
+
globalExpect(result).toHaveLength(1);
|
|
578
|
+
globalExpect(result[0]).toEqual({
|
|
579
|
+
id: "agent-state-1",
|
|
580
|
+
role: "assistant",
|
|
581
|
+
agentName: "testAgent",
|
|
582
|
+
state: { status: "running", data: "test data" }
|
|
583
|
+
});
|
|
584
|
+
globalExpect(result[0]).not.toHaveProperty("generativeUI");
|
|
585
|
+
});
|
|
586
|
+
test("should handle agent state messages with agent not found in coAgentStateRenders", () => {
|
|
587
|
+
const agentStateMsg = new AgentStateMessage({
|
|
588
|
+
id: "agent-state-1",
|
|
589
|
+
agentName: "unknownAgent",
|
|
590
|
+
state: { status: "running", data: "test data" },
|
|
591
|
+
role: Role.Assistant
|
|
592
|
+
});
|
|
593
|
+
const coAgentStateRenders = {
|
|
594
|
+
testAgent: {
|
|
595
|
+
name: "testAgent",
|
|
596
|
+
render: () => "Test"
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
const result = gqlToAGUI([agentStateMsg], void 0, coAgentStateRenders);
|
|
600
|
+
globalExpect(result).toHaveLength(1);
|
|
601
|
+
globalExpect(result[0]).toEqual({
|
|
602
|
+
id: "agent-state-1",
|
|
603
|
+
role: "assistant",
|
|
604
|
+
agentName: "unknownAgent",
|
|
605
|
+
state: { status: "running", data: "test data" }
|
|
606
|
+
});
|
|
607
|
+
globalExpect(result[0]).not.toHaveProperty("generativeUI");
|
|
608
|
+
});
|
|
609
|
+
test("should handle user role messages", () => {
|
|
610
|
+
const userMsg = new TextMessage({
|
|
611
|
+
id: "user-1",
|
|
612
|
+
content: "Hello from user",
|
|
613
|
+
role: Role.User
|
|
614
|
+
});
|
|
615
|
+
const result = gqlToAGUI([userMsg]);
|
|
616
|
+
globalExpect(result).toHaveLength(1);
|
|
617
|
+
globalExpect(result[0]).toEqual({
|
|
618
|
+
id: "user-1",
|
|
619
|
+
role: "user",
|
|
620
|
+
content: "Hello from user"
|
|
621
|
+
});
|
|
622
|
+
});
|
|
623
|
+
test("should handle mixed message types including agent state messages", () => {
|
|
624
|
+
const textMsg = new TextMessage({
|
|
625
|
+
id: "text-1",
|
|
626
|
+
content: "Hello",
|
|
627
|
+
role: Role.Assistant
|
|
628
|
+
});
|
|
629
|
+
const agentStateMsg = new AgentStateMessage({
|
|
630
|
+
id: "agent-state-1",
|
|
631
|
+
agentName: "testAgent",
|
|
632
|
+
state: { status: "running" },
|
|
633
|
+
role: Role.Assistant
|
|
634
|
+
});
|
|
635
|
+
const mockRender = vi.fn();
|
|
636
|
+
const coAgentStateRenders = {
|
|
637
|
+
testAgent: {
|
|
638
|
+
name: "testAgent",
|
|
639
|
+
render: mockRender
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
const result = gqlToAGUI([textMsg, agentStateMsg], void 0, coAgentStateRenders);
|
|
643
|
+
globalExpect(result).toHaveLength(2);
|
|
644
|
+
globalExpect(result[0]).toEqual({
|
|
645
|
+
id: "text-1",
|
|
646
|
+
role: "assistant",
|
|
647
|
+
content: "Hello"
|
|
648
|
+
});
|
|
649
|
+
globalExpect(result[1]).toMatchObject({
|
|
650
|
+
id: "agent-state-1",
|
|
651
|
+
role: "assistant",
|
|
652
|
+
agentName: "testAgent",
|
|
653
|
+
state: { status: "running" },
|
|
654
|
+
generativeUI: globalExpect.any(Function)
|
|
655
|
+
});
|
|
656
|
+
globalExpect(result[1]).toHaveProperty("generativeUI");
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
describe("gqlImageMessageToAGUIMessage", () => {
|
|
660
|
+
test("should throw error for invalid image format", () => {
|
|
661
|
+
const invalidImageMsg = new ImageMessage({
|
|
662
|
+
id: "img-1",
|
|
663
|
+
format: "bmp",
|
|
664
|
+
// not in VALID_IMAGE_FORMATS
|
|
665
|
+
bytes: "somebase64string",
|
|
666
|
+
role: Role.User
|
|
667
|
+
});
|
|
668
|
+
globalExpect(() => gqlImageMessageToAGUIMessage(invalidImageMsg)).toThrow("Invalid image format");
|
|
669
|
+
});
|
|
670
|
+
test("should throw error for empty image bytes", () => {
|
|
671
|
+
const invalidImageMsg = new ImageMessage({
|
|
672
|
+
id: "img-2",
|
|
673
|
+
format: "jpeg",
|
|
674
|
+
bytes: "",
|
|
675
|
+
role: Role.User
|
|
676
|
+
});
|
|
677
|
+
globalExpect(() => gqlImageMessageToAGUIMessage(invalidImageMsg)).toThrow(
|
|
678
|
+
"Image bytes must be a non-empty string"
|
|
679
|
+
);
|
|
680
|
+
});
|
|
681
|
+
test("should convert valid image message", () => {
|
|
682
|
+
const validImageMsg = new ImageMessage({
|
|
683
|
+
id: "img-3",
|
|
684
|
+
format: "jpeg",
|
|
685
|
+
bytes: "somebase64string",
|
|
686
|
+
role: Role.User
|
|
687
|
+
});
|
|
688
|
+
const result = gqlImageMessageToAGUIMessage(validImageMsg);
|
|
689
|
+
globalExpect(result).toMatchObject({
|
|
690
|
+
id: "img-3",
|
|
691
|
+
role: "user",
|
|
692
|
+
content: "",
|
|
693
|
+
image: {
|
|
694
|
+
format: "jpeg",
|
|
695
|
+
bytes: "somebase64string"
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
test("should convert valid user image message", () => {
|
|
700
|
+
const validImageMsg = new ImageMessage({
|
|
701
|
+
id: "img-user-1",
|
|
702
|
+
format: "jpeg",
|
|
703
|
+
bytes: "userbase64string",
|
|
704
|
+
role: Role.User
|
|
705
|
+
});
|
|
706
|
+
const result = gqlImageMessageToAGUIMessage(validImageMsg);
|
|
707
|
+
globalExpect(result).toMatchObject({
|
|
708
|
+
id: "img-user-1",
|
|
709
|
+
role: "user",
|
|
710
|
+
content: "",
|
|
711
|
+
image: {
|
|
712
|
+
format: "jpeg",
|
|
713
|
+
bytes: "userbase64string"
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
test("should convert valid assistant image message", () => {
|
|
718
|
+
const validImageMsg = new ImageMessage({
|
|
719
|
+
id: "img-assistant-1",
|
|
720
|
+
format: "png",
|
|
721
|
+
bytes: "assistantbase64string",
|
|
722
|
+
role: Role.Assistant
|
|
723
|
+
});
|
|
724
|
+
const result = gqlImageMessageToAGUIMessage(validImageMsg);
|
|
725
|
+
globalExpect(result).toMatchObject({
|
|
726
|
+
id: "img-assistant-1",
|
|
727
|
+
role: "assistant",
|
|
728
|
+
content: "",
|
|
729
|
+
image: {
|
|
730
|
+
format: "png",
|
|
731
|
+
bytes: "assistantbase64string"
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
});
|
|
737
|
+
//# sourceMappingURL=gql-to-agui.test.mjs.map
|