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