@copilotkit/runtime-client-gql 1.10.0 → 1.10.1-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 +10 -0
- package/dist/{chunk-YNQMTL2P.mjs → chunk-7OSRQ2O3.mjs} +9 -3
- package/dist/chunk-7OSRQ2O3.mjs.map +1 -0
- package/dist/{chunk-PAQ6AHHC.mjs → chunk-AES3X7TL.mjs} +2 -2
- package/dist/{chunk-PAQ6AHHC.mjs.map → chunk-AES3X7TL.mjs.map} +1 -1
- package/dist/{chunk-MTD2RJDJ.mjs → chunk-IGXWE4TX.mjs} +32 -29
- package/dist/chunk-IGXWE4TX.mjs.map +1 -0
- package/dist/client/CopilotRuntimeClient.js +1 -1
- package/dist/client/CopilotRuntimeClient.js.map +1 -1
- package/dist/client/CopilotRuntimeClient.mjs +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +41 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -3
- package/dist/message-conversion/agui-to-gql.js +8 -2
- package/dist/message-conversion/agui-to-gql.js.map +1 -1
- package/dist/message-conversion/agui-to-gql.mjs +2 -2
- package/dist/message-conversion/agui-to-gql.test.js +380 -2
- package/dist/message-conversion/agui-to-gql.test.js.map +1 -1
- package/dist/message-conversion/agui-to-gql.test.mjs +374 -2
- package/dist/message-conversion/agui-to-gql.test.mjs.map +1 -1
- package/dist/message-conversion/gql-to-agui.d.ts +3 -2
- package/dist/message-conversion/gql-to-agui.js +32 -28
- package/dist/message-conversion/gql-to-agui.js.map +1 -1
- package/dist/message-conversion/gql-to-agui.mjs +4 -2
- package/dist/message-conversion/gql-to-agui.test.js +496 -28
- package/dist/message-conversion/gql-to-agui.test.js.map +1 -1
- package/dist/message-conversion/gql-to-agui.test.mjs +469 -2
- package/dist/message-conversion/gql-to-agui.test.mjs.map +1 -1
- package/dist/message-conversion/index.d.ts +1 -1
- package/dist/message-conversion/index.js +40 -30
- package/dist/message-conversion/index.js.map +1 -1
- package/dist/message-conversion/index.mjs +5 -3
- package/dist/message-conversion/roundtrip-conversion.test.js +132 -30
- package/dist/message-conversion/roundtrip-conversion.test.js.map +1 -1
- package/dist/message-conversion/roundtrip-conversion.test.mjs +97 -3
- package/dist/message-conversion/roundtrip-conversion.test.mjs.map +1 -1
- package/package.json +3 -3
- package/src/message-conversion/agui-to-gql.test.ts +426 -0
- package/src/message-conversion/agui-to-gql.ts +11 -2
- package/src/message-conversion/gql-to-agui.test.ts +524 -0
- package/src/message-conversion/gql-to-agui.ts +45 -36
- package/src/message-conversion/roundtrip-conversion.test.ts +122 -0
- package/dist/chunk-MTD2RJDJ.mjs.map +0 -1
- package/dist/chunk-YNQMTL2P.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
aguiToGQL
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-7OSRQ2O3.mjs";
|
|
4
4
|
import {
|
|
5
5
|
gqlToAGUI
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-IGXWE4TX.mjs";
|
|
7
7
|
import {
|
|
8
8
|
describe,
|
|
9
9
|
globalExpect,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
vi
|
|
12
12
|
} from "../chunk-2R7M2FWR.mjs";
|
|
13
13
|
import "../chunk-7ECCT6PK.mjs";
|
|
14
|
-
import "../chunk-
|
|
14
|
+
import "../chunk-AES3X7TL.mjs";
|
|
15
15
|
import "../chunk-X2UAP3QY.mjs";
|
|
16
16
|
import "../chunk-HEODM5TW.mjs";
|
|
17
17
|
import "../chunk-4KTMZMM2.mjs";
|
|
@@ -215,5 +215,99 @@ describe("roundtrip message conversion", () => {
|
|
|
215
215
|
globalExpect(aguiUserMsgs2[0].image.format).toBe("png");
|
|
216
216
|
globalExpect(aguiUserMsgs2[0].image.bytes).toBe("userbase64data");
|
|
217
217
|
});
|
|
218
|
+
test("wild card action roundtrip conversion", () => {
|
|
219
|
+
const mockRender = vi.fn((props) => `Wildcard rendered: ${props.args.test}`);
|
|
220
|
+
const aguiMsg = {
|
|
221
|
+
id: "assistant-wildcard-1",
|
|
222
|
+
role: "assistant",
|
|
223
|
+
content: "Running wild card action",
|
|
224
|
+
toolCalls: [
|
|
225
|
+
{
|
|
226
|
+
id: "tool-call-wildcard-1",
|
|
227
|
+
type: "function",
|
|
228
|
+
function: {
|
|
229
|
+
name: "unknownAction",
|
|
230
|
+
arguments: JSON.stringify({ test: "wildcard-value" })
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
generativeUI: mockRender
|
|
235
|
+
};
|
|
236
|
+
const actions = {
|
|
237
|
+
"*": { name: "*" }
|
|
238
|
+
};
|
|
239
|
+
const gqlMsgs = aguiToGQL(aguiMsg, actions);
|
|
240
|
+
const aguiMsgs2 = gqlToAGUI(gqlMsgs, actions);
|
|
241
|
+
globalExpect(typeof actions["*"].render).toBe("function");
|
|
242
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
243
|
+
globalExpect(aguiMsgs2).toHaveLength(2);
|
|
244
|
+
globalExpect(aguiMsgs2[0].role).toBe("assistant");
|
|
245
|
+
globalExpect(aguiMsgs2[1].role).toBe("assistant");
|
|
246
|
+
if ("toolCalls" in aguiMsgs2[1]) {
|
|
247
|
+
globalExpect(aguiMsgs2[1].toolCalls[0].function.name).toBe("unknownAction");
|
|
248
|
+
globalExpect(aguiMsgs2[1].toolCalls[0].function.arguments).toBe(
|
|
249
|
+
'{"test":"wildcard-value"}'
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
test("wild card action with specific action priority roundtrip", () => {
|
|
254
|
+
const mockRender = vi.fn((props) => `Specific action rendered: ${props.args.test}`);
|
|
255
|
+
const aguiMsg = {
|
|
256
|
+
id: "assistant-priority-1",
|
|
257
|
+
role: "assistant",
|
|
258
|
+
content: "Running specific action",
|
|
259
|
+
toolCalls: [
|
|
260
|
+
{
|
|
261
|
+
id: "tool-call-priority-1",
|
|
262
|
+
type: "function",
|
|
263
|
+
function: {
|
|
264
|
+
name: "specificAction",
|
|
265
|
+
arguments: JSON.stringify({ test: "specific-value" })
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
],
|
|
269
|
+
generativeUI: mockRender
|
|
270
|
+
};
|
|
271
|
+
const actions = {
|
|
272
|
+
specificAction: { name: "specificAction" },
|
|
273
|
+
"*": { name: "*" }
|
|
274
|
+
};
|
|
275
|
+
const gqlMsgs = aguiToGQL(aguiMsg, actions);
|
|
276
|
+
const aguiMsgs2 = gqlToAGUI(gqlMsgs, actions);
|
|
277
|
+
globalExpect(typeof actions.specificAction.render).toBe("function");
|
|
278
|
+
globalExpect(actions.specificAction.render).toBe(mockRender);
|
|
279
|
+
globalExpect(actions["*"].render).toBeUndefined();
|
|
280
|
+
globalExpect(aguiMsgs2).toHaveLength(2);
|
|
281
|
+
globalExpect(aguiMsgs2[0].role).toBe("assistant");
|
|
282
|
+
globalExpect(aguiMsgs2[1].role).toBe("assistant");
|
|
283
|
+
if ("toolCalls" in aguiMsgs2[1]) {
|
|
284
|
+
globalExpect(aguiMsgs2[1].toolCalls[0].function.name).toBe("specificAction");
|
|
285
|
+
globalExpect(aguiMsgs2[1].toolCalls[0].function.arguments).toBe(
|
|
286
|
+
'{"test":"specific-value"}'
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
test("wild card action GQL -> AGUI -> GQL roundtrip", () => {
|
|
291
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
292
|
+
id: "wildcard-action-1",
|
|
293
|
+
name: "unknownAction",
|
|
294
|
+
arguments: { test: "wildcard-gql-value" },
|
|
295
|
+
parentMessageId: "assistant-1"
|
|
296
|
+
});
|
|
297
|
+
const actions = {
|
|
298
|
+
"*": {
|
|
299
|
+
name: "*",
|
|
300
|
+
render: vi.fn((props) => `GQL wildcard rendered: ${props.args.test}`)
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const aguiMsgs = gqlToAGUI([actionExecMsg], actions);
|
|
304
|
+
const gqlMsgs2 = aguiToGQL(aguiMsgs, actions);
|
|
305
|
+
globalExpect(gqlMsgs2).toHaveLength(2);
|
|
306
|
+
globalExpect(gqlMsgs2[0].id).toBe("wildcard-action-1");
|
|
307
|
+
globalExpect(gqlMsgs2[0].role).toBe(Role.Assistant);
|
|
308
|
+
globalExpect(gqlMsgs2[1].id).toBe("wildcard-action-1");
|
|
309
|
+
globalExpect(gqlMsgs2[1].name).toBe("unknownAction");
|
|
310
|
+
globalExpect(gqlMsgs2[1].arguments).toEqual({ test: "wildcard-gql-value" });
|
|
311
|
+
});
|
|
218
312
|
});
|
|
219
313
|
//# sourceMappingURL=roundtrip-conversion.test.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/message-conversion/roundtrip-conversion.test.ts"],"sourcesContent":["import { describe, test, expect, vi } from \"vitest\";\nimport * as gql from \"../client\";\nimport agui from \"@copilotkit/shared\";\nimport { aguiToGQL } from \"./agui-to-gql\";\nimport { gqlToAGUI } from \"./gql-to-agui\";\n\n// Helper to strip functions for deep equality\nfunction stripFunctions(obj: any): any {\n if (typeof obj === \"function\") return undefined;\n if (Array.isArray(obj)) return obj.map(stripFunctions);\n if (obj && typeof obj === \"object\") {\n const out: any = {};\n for (const k in obj) {\n if (typeof obj[k] !== \"function\") {\n out[k] = stripFunctions(obj[k]);\n }\n }\n return out;\n }\n return obj;\n}\n\ndescribe(\"roundtrip message conversion\", () => {\n test(\"text message AGUI -> GQL -> AGUI\", () => {\n const aguiMsg: agui.Message = {\n id: \"user-1\",\n role: \"user\",\n content: \"Hello!\",\n };\n const gqlMsgs = aguiToGQL(aguiMsg);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs);\n expect(stripFunctions(aguiMsgs2[0])).toEqual(stripFunctions(aguiMsg));\n });\n\n test(\"text message GQL -> AGUI -> GQL\", () => {\n const gqlMsg = new gql.TextMessage({\n id: \"assistant-1\",\n content: \"Hi!\",\n role: gql.Role.Assistant,\n });\n const aguiMsgs = gqlToAGUI(gqlMsg);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n // Should be equivalent in content, id, and role\n expect(gqlMsgs2[0].id).toBe(gqlMsg.id);\n expect((gqlMsgs2[0] as any).content).toBe(gqlMsg.content);\n expect((gqlMsgs2[0] as any).role).toBe(gqlMsg.role);\n });\n\n test(\"tool message AGUI -> GQL -> AGUI\", () => {\n const aguiMsg: agui.Message = {\n id: \"tool-1\",\n role: \"tool\",\n content: \"Tool result\",\n toolCallId: \"tool-call-1\",\n toolName: \"testAction\",\n };\n const gqlMsgs = aguiToGQL(aguiMsg);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs);\n expect(stripFunctions(aguiMsgs2[0])).toEqual(stripFunctions(aguiMsg));\n });\n\n test(\"tool message GQL -> AGUI -> GQL\", () => {\n const gqlMsg = new gql.ResultMessage({\n id: \"tool-1\",\n result: \"Tool result\",\n actionExecutionId: \"tool-call-1\",\n actionName: \"testAction\",\n });\n const aguiMsgs = gqlToAGUI(gqlMsg);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n expect(gqlMsgs2[0].id).toBe(gqlMsg.id);\n expect((gqlMsgs2[0] as any).result).toBe(gqlMsg.result);\n expect((gqlMsgs2[0] as any).actionExecutionId).toBe(gqlMsg.actionExecutionId);\n });\n\n test(\"action execution AGUI -> GQL -> AGUI\", () => {\n const aguiMsg: agui.Message = {\n id: \"assistant-1\",\n role: \"assistant\",\n content: \"Running action\",\n toolCalls: [\n {\n id: \"tool-call-1\",\n type: \"function\",\n function: {\n name: \"doSomething\",\n arguments: JSON.stringify({ foo: \"bar\" }),\n },\n },\n ],\n };\n const gqlMsgs = aguiToGQL(aguiMsg);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs);\n // Should have an assistant message and an action execution message\n expect(aguiMsgs2[0].role).toBe(\"assistant\");\n expect(aguiMsgs2[1].role).toBe(\"assistant\");\n // Only check toolCalls if present\n if (\"toolCalls\" in aguiMsgs2[1]) {\n expect((aguiMsgs2[1] as any).toolCalls[0].function.name).toBe(\"doSomething\");\n }\n });\n\n test(\"action execution GQL -> AGUI -> GQL\", () => {\n const actionExecMsg = new gql.ActionExecutionMessage({\n id: \"tool-call-1\",\n name: \"doSomething\",\n arguments: { foo: \"bar\" },\n parentMessageId: \"assistant-1\",\n });\n const aguiMsgs = gqlToAGUI([actionExecMsg]);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n // The ActionExecutionMessage is at index 1, not index 0\n expect(gqlMsgs2[1].id).toBe(\"tool-call-1\");\n // The name should be extracted from the toolCall function name\n expect((gqlMsgs2[1] as any).name).toBe(\"doSomething\");\n expect((gqlMsgs2[1] as any).arguments).toEqual({ foo: \"bar\" });\n });\n\n test(\"agent state GQL -> AGUI -> GQL\", () => {\n const agentStateMsg = new gql.AgentStateMessage({\n id: \"agent-state-1\",\n agentName: \"testAgent\",\n state: { status: \"running\" },\n role: gql.Role.Assistant,\n });\n const aguiMsgs = gqlToAGUI([agentStateMsg]);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n expect(gqlMsgs2[0].id).toBe(\"agent-state-1\");\n // The agentName should be preserved in the roundtrip\n expect((gqlMsgs2[0] as any).agentName).toBe(\"testAgent\");\n });\n\n test(\"action execution with render function roundtrip\", () => {\n const mockRender = vi.fn();\n const aguiMsg: agui.Message = {\n id: \"assistant-1\",\n role: \"assistant\",\n content: \"Running action\",\n toolCalls: [\n {\n id: \"tool-call-1\",\n type: \"function\",\n function: {\n name: \"doSomething\",\n arguments: JSON.stringify({ foo: \"bar\" }),\n },\n },\n ],\n generativeUI: mockRender,\n };\n const actions: Record<string, any> = { doSomething: { name: \"doSomething\" } };\n const gqlMsgs = aguiToGQL(aguiMsg, actions);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs, actions);\n // The render function should be preserved in actions context\n expect(typeof actions.doSomething.render).toBe(\"function\");\n // The roundtripped message should have the same tool call\n if (\"toolCalls\" in aguiMsgs2[1]) {\n expect((aguiMsgs2[1] as any).toolCalls[0].function.name).toBe(\"doSomething\");\n }\n });\n\n test(\"image message GQL -> AGUI -> GQL\", () => {\n const gqlMsg = new gql.ImageMessage({\n id: \"img-1\",\n format: \"jpeg\",\n bytes: \"somebase64string\",\n role: gql.Role.User,\n });\n const aguiMsgs = gqlToAGUI(gqlMsg);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n expect(gqlMsgs2[0].id).toBe(gqlMsg.id);\n expect((gqlMsgs2[0] as any).format).toBe(gqlMsg.format);\n expect((gqlMsgs2[0] as any).bytes).toBe(gqlMsg.bytes);\n expect((gqlMsgs2[0] as any).role).toBe(gqlMsg.role);\n });\n\n test(\"image message AGUI -> GQL -> AGUI (assistant and user)\", () => {\n // Assistant image message\n const aguiAssistantImageMsg: agui.Message = {\n id: \"img-assistant-1\",\n role: \"assistant\",\n image: {\n format: \"jpeg\",\n bytes: \"assistantbase64data\",\n },\n content: \"\", // required for type\n };\n const gqlAssistantMsgs = aguiToGQL(aguiAssistantImageMsg);\n const aguiAssistantMsgs2 = gqlToAGUI(gqlAssistantMsgs);\n expect(aguiAssistantMsgs2[0].id).toBe(aguiAssistantImageMsg.id);\n expect(aguiAssistantMsgs2[0].role).toBe(\"assistant\");\n expect((aguiAssistantMsgs2[0] as any).image.format).toBe(\"jpeg\");\n expect((aguiAssistantMsgs2[0] as any).image.bytes).toBe(\"assistantbase64data\");\n\n // User image message\n const aguiUserImageMsg: agui.Message = {\n id: \"img-user-1\",\n role: \"user\",\n image: {\n format: \"png\",\n bytes: \"userbase64data\",\n },\n content: \"\", // required for type\n };\n const gqlUserMsgs = aguiToGQL(aguiUserImageMsg);\n const aguiUserMsgs2 = gqlToAGUI(gqlUserMsgs);\n expect(aguiUserMsgs2[0].id).toBe(aguiUserImageMsg.id);\n expect(aguiUserMsgs2[0].role).toBe(\"user\");\n expect((aguiUserMsgs2[0] as any).image.format).toBe(\"png\");\n expect((aguiUserMsgs2[0] as any).image.bytes).toBe(\"userbase64data\");\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,eAAe,KAAe;AACrC,MAAI,OAAO,QAAQ;AAAY,WAAO;AACtC,MAAI,MAAM,QAAQ,GAAG;AAAG,WAAO,IAAI,IAAI,cAAc;AACrD,MAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,UAAM,MAAW,CAAC;AAClB,eAAW,KAAK,KAAK;AACnB,UAAI,OAAO,IAAI,CAAC,MAAM,YAAY;AAChC,YAAI,CAAC,IAAI,eAAe,IAAI,CAAC,CAAC;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,SAAS,gCAAgC,MAAM;AAC7C,OAAK,oCAAoC,MAAM;AAC7C,UAAM,UAAwB;AAAA,MAC5B,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AACA,UAAM,UAAU,UAAU,OAAO;AACjC,UAAM,YAAY,UAAU,OAAO;AACnC,iBAAO,eAAe,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,eAAe,OAAO,CAAC;AAAA,EACtE,CAAC;AAED,OAAK,mCAAmC,MAAM;AAC5C,UAAM,SAAS,IAAQ,YAAY;AAAA,MACjC,IAAI;AAAA,MACJ,SAAS;AAAA,MACT,MAAU,KAAK;AAAA,IACjB,CAAC;AACD,UAAM,WAAW,UAAU,MAAM;AACjC,UAAM,WAAW,UAAU,QAAQ;AAEnC,iBAAO,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,EAAE;AACrC,iBAAQ,SAAS,CAAC,EAAU,OAAO,EAAE,KAAK,OAAO,OAAO;AACxD,iBAAQ,SAAS,CAAC,EAAU,IAAI,EAAE,KAAK,OAAO,IAAI;AAAA,EACpD,CAAC;AAED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AW;AACnD,iBAAQ,mBAAmB,CAAC,EAAU,MAAM,MAAM,EAAE,KAAK,MAAM;AAC/D,iBAAQ,mBAAmB,CAAC,EAAU,MAAM,KAAK,EAAE,KAAK,qBAAqB;AAG7E,UAAM,mBAAiC;AAAA,MACrC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,QACL,QAAQ;AAAA,QACR,OAAO;AAAA,MACT;AAAA,MACA,SAAS;AAAA;AAAA,IACX;AACA,UAAM,cAAc,UAAU,gBAAgB;AAC9C,UAAM,gBAAgB,UAAU,WAAW;AAC3C,iBAAO,cAAc,CAAC,EAAE,EAAE,EAAE,KAAK,iBAAiB,EAAE;AACpD,iBAAO,cAAc,CAAC,EAAE,IAAI,EAAE,KAAK,MAAM;AACzC,iBAAQ,cAAc,CAAC,EAAU,MAAM,MAAM,EAAE,KAAK,KAAK;AACzD,iBAAQ,cAAc,CAAC,EAAU,MAAM,KAAK,EAAE,KAAK,gBAAgB;AAAA,EACrE,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/message-conversion/roundtrip-conversion.test.ts"],"sourcesContent":["import { describe, test, expect, vi } from \"vitest\";\nimport * as gql from \"../client\";\nimport agui from \"@copilotkit/shared\";\nimport { aguiToGQL } from \"./agui-to-gql\";\nimport { gqlToAGUI } from \"./gql-to-agui\";\n\n// Helper to strip functions for deep equality\nfunction stripFunctions(obj: any): any {\n if (typeof obj === \"function\") return undefined;\n if (Array.isArray(obj)) return obj.map(stripFunctions);\n if (obj && typeof obj === \"object\") {\n const out: any = {};\n for (const k in obj) {\n if (typeof obj[k] !== \"function\") {\n out[k] = stripFunctions(obj[k]);\n }\n }\n return out;\n }\n return obj;\n}\n\ndescribe(\"roundtrip message conversion\", () => {\n test(\"text message AGUI -> GQL -> AGUI\", () => {\n const aguiMsg: agui.Message = {\n id: \"user-1\",\n role: \"user\",\n content: \"Hello!\",\n };\n const gqlMsgs = aguiToGQL(aguiMsg);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs);\n expect(stripFunctions(aguiMsgs2[0])).toEqual(stripFunctions(aguiMsg));\n });\n\n test(\"text message GQL -> AGUI -> GQL\", () => {\n const gqlMsg = new gql.TextMessage({\n id: \"assistant-1\",\n content: \"Hi!\",\n role: gql.Role.Assistant,\n });\n const aguiMsgs = gqlToAGUI(gqlMsg);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n // Should be equivalent in content, id, and role\n expect(gqlMsgs2[0].id).toBe(gqlMsg.id);\n expect((gqlMsgs2[0] as any).content).toBe(gqlMsg.content);\n expect((gqlMsgs2[0] as any).role).toBe(gqlMsg.role);\n });\n\n test(\"tool message AGUI -> GQL -> AGUI\", () => {\n const aguiMsg: agui.Message = {\n id: \"tool-1\",\n role: \"tool\",\n content: \"Tool result\",\n toolCallId: \"tool-call-1\",\n toolName: \"testAction\",\n };\n const gqlMsgs = aguiToGQL(aguiMsg);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs);\n expect(stripFunctions(aguiMsgs2[0])).toEqual(stripFunctions(aguiMsg));\n });\n\n test(\"tool message GQL -> AGUI -> GQL\", () => {\n const gqlMsg = new gql.ResultMessage({\n id: \"tool-1\",\n result: \"Tool result\",\n actionExecutionId: \"tool-call-1\",\n actionName: \"testAction\",\n });\n const aguiMsgs = gqlToAGUI(gqlMsg);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n expect(gqlMsgs2[0].id).toBe(gqlMsg.id);\n expect((gqlMsgs2[0] as any).result).toBe(gqlMsg.result);\n expect((gqlMsgs2[0] as any).actionExecutionId).toBe(gqlMsg.actionExecutionId);\n });\n\n test(\"action execution AGUI -> GQL -> AGUI\", () => {\n const aguiMsg: agui.Message = {\n id: \"assistant-1\",\n role: \"assistant\",\n content: \"Running action\",\n toolCalls: [\n {\n id: \"tool-call-1\",\n type: \"function\",\n function: {\n name: \"doSomething\",\n arguments: JSON.stringify({ foo: \"bar\" }),\n },\n },\n ],\n };\n const gqlMsgs = aguiToGQL(aguiMsg);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs);\n // Should have an assistant message and an action execution message\n expect(aguiMsgs2[0].role).toBe(\"assistant\");\n expect(aguiMsgs2[1].role).toBe(\"assistant\");\n // Only check toolCalls if present\n if (\"toolCalls\" in aguiMsgs2[1]) {\n expect((aguiMsgs2[1] as any).toolCalls[0].function.name).toBe(\"doSomething\");\n }\n });\n\n test(\"action execution GQL -> AGUI -> GQL\", () => {\n const actionExecMsg = new gql.ActionExecutionMessage({\n id: \"tool-call-1\",\n name: \"doSomething\",\n arguments: { foo: \"bar\" },\n parentMessageId: \"assistant-1\",\n });\n const aguiMsgs = gqlToAGUI([actionExecMsg]);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n // The ActionExecutionMessage is at index 1, not index 0\n expect(gqlMsgs2[1].id).toBe(\"tool-call-1\");\n // The name should be extracted from the toolCall function name\n expect((gqlMsgs2[1] as any).name).toBe(\"doSomething\");\n expect((gqlMsgs2[1] as any).arguments).toEqual({ foo: \"bar\" });\n });\n\n test(\"agent state GQL -> AGUI -> GQL\", () => {\n const agentStateMsg = new gql.AgentStateMessage({\n id: \"agent-state-1\",\n agentName: \"testAgent\",\n state: { status: \"running\" },\n role: gql.Role.Assistant,\n });\n const aguiMsgs = gqlToAGUI([agentStateMsg]);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n expect(gqlMsgs2[0].id).toBe(\"agent-state-1\");\n // The agentName should be preserved in the roundtrip\n expect((gqlMsgs2[0] as any).agentName).toBe(\"testAgent\");\n });\n\n test(\"action execution with render function roundtrip\", () => {\n const mockRender = vi.fn();\n const aguiMsg: agui.Message = {\n id: \"assistant-1\",\n role: \"assistant\",\n content: \"Running action\",\n toolCalls: [\n {\n id: \"tool-call-1\",\n type: \"function\",\n function: {\n name: \"doSomething\",\n arguments: JSON.stringify({ foo: \"bar\" }),\n },\n },\n ],\n generativeUI: mockRender,\n };\n const actions: Record<string, any> = { doSomething: { name: \"doSomething\" } };\n const gqlMsgs = aguiToGQL(aguiMsg, actions);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs, actions);\n // The render function should be preserved in actions context\n expect(typeof actions.doSomething.render).toBe(\"function\");\n // The roundtripped message should have the same tool call\n if (\"toolCalls\" in aguiMsgs2[1]) {\n expect((aguiMsgs2[1] as any).toolCalls[0].function.name).toBe(\"doSomething\");\n }\n });\n\n test(\"image message GQL -> AGUI -> GQL\", () => {\n const gqlMsg = new gql.ImageMessage({\n id: \"img-1\",\n format: \"jpeg\",\n bytes: \"somebase64string\",\n role: gql.Role.User,\n });\n const aguiMsgs = gqlToAGUI(gqlMsg);\n const gqlMsgs2 = aguiToGQL(aguiMsgs);\n expect(gqlMsgs2[0].id).toBe(gqlMsg.id);\n expect((gqlMsgs2[0] as any).format).toBe(gqlMsg.format);\n expect((gqlMsgs2[0] as any).bytes).toBe(gqlMsg.bytes);\n expect((gqlMsgs2[0] as any).role).toBe(gqlMsg.role);\n });\n\n test(\"image message AGUI -> GQL -> AGUI (assistant and user)\", () => {\n // Assistant image message\n const aguiAssistantImageMsg: agui.Message = {\n id: \"img-assistant-1\",\n role: \"assistant\",\n image: {\n format: \"jpeg\",\n bytes: \"assistantbase64data\",\n },\n content: \"\", // required for type\n };\n const gqlAssistantMsgs = aguiToGQL(aguiAssistantImageMsg);\n const aguiAssistantMsgs2 = gqlToAGUI(gqlAssistantMsgs);\n expect(aguiAssistantMsgs2[0].id).toBe(aguiAssistantImageMsg.id);\n expect(aguiAssistantMsgs2[0].role).toBe(\"assistant\");\n expect((aguiAssistantMsgs2[0] as any).image.format).toBe(\"jpeg\");\n expect((aguiAssistantMsgs2[0] as any).image.bytes).toBe(\"assistantbase64data\");\n\n // User image message\n const aguiUserImageMsg: agui.Message = {\n id: \"img-user-1\",\n role: \"user\",\n image: {\n format: \"png\",\n bytes: \"userbase64data\",\n },\n content: \"\", // required for type\n };\n const gqlUserMsgs = aguiToGQL(aguiUserImageMsg);\n const aguiUserMsgs2 = gqlToAGUI(gqlUserMsgs);\n expect(aguiUserMsgs2[0].id).toBe(aguiUserImageMsg.id);\n expect(aguiUserMsgs2[0].role).toBe(\"user\");\n expect((aguiUserMsgs2[0] as any).image.format).toBe(\"png\");\n expect((aguiUserMsgs2[0] as any).image.bytes).toBe(\"userbase64data\");\n });\n\n test(\"wild card action roundtrip conversion\", () => {\n const mockRender = vi.fn((props) => `Wildcard rendered: ${props.args.test}`);\n const aguiMsg: agui.Message = {\n id: \"assistant-wildcard-1\",\n role: \"assistant\",\n content: \"Running wild card action\",\n toolCalls: [\n {\n id: \"tool-call-wildcard-1\",\n type: \"function\",\n function: {\n name: \"unknownAction\",\n arguments: JSON.stringify({ test: \"wildcard-value\" }),\n },\n },\n ],\n generativeUI: mockRender,\n };\n\n const actions: Record<string, any> = {\n \"*\": { name: \"*\" },\n };\n\n // AGUI -> GQL -> AGUI roundtrip\n const gqlMsgs = aguiToGQL(aguiMsg, actions);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs, actions);\n\n // Verify the wild card action preserved the render function\n expect(typeof actions[\"*\"].render).toBe(\"function\");\n expect(actions[\"*\"].render).toBe(mockRender);\n\n // Verify the roundtripped message structure\n expect(aguiMsgs2).toHaveLength(2);\n expect(aguiMsgs2[0].role).toBe(\"assistant\");\n expect(aguiMsgs2[1].role).toBe(\"assistant\");\n\n // Check that the tool call is preserved\n if (\"toolCalls\" in aguiMsgs2[1]) {\n expect((aguiMsgs2[1] as any).toolCalls[0].function.name).toBe(\"unknownAction\");\n expect((aguiMsgs2[1] as any).toolCalls[0].function.arguments).toBe(\n '{\"test\":\"wildcard-value\"}',\n );\n }\n });\n\n test(\"wild card action with specific action priority roundtrip\", () => {\n const mockRender = vi.fn((props) => `Specific action rendered: ${props.args.test}`);\n const aguiMsg: agui.Message = {\n id: \"assistant-priority-1\",\n role: \"assistant\",\n content: \"Running specific action\",\n toolCalls: [\n {\n id: \"tool-call-priority-1\",\n type: \"function\",\n function: {\n name: \"specificAction\",\n arguments: JSON.stringify({ test: \"specific-value\" }),\n },\n },\n ],\n generativeUI: mockRender,\n };\n\n const actions: Record<string, any> = {\n specificAction: { name: \"specificAction\" },\n \"*\": { name: \"*\" },\n };\n\n // AGUI -> GQL -> AGUI roundtrip\n const gqlMsgs = aguiToGQL(aguiMsg, actions);\n const aguiMsgs2 = gqlToAGUI(gqlMsgs, actions);\n\n // Verify the specific action preserved the render function (not wild card)\n expect(typeof actions.specificAction.render).toBe(\"function\");\n expect(actions.specificAction.render).toBe(mockRender);\n expect(actions[\"*\"].render).toBeUndefined();\n\n // Verify the roundtripped message structure\n expect(aguiMsgs2).toHaveLength(2);\n expect(aguiMsgs2[0].role).toBe(\"assistant\");\n expect(aguiMsgs2[1].role).toBe(\"assistant\");\n\n // Check that the tool call is preserved\n if (\"toolCalls\" in aguiMsgs2[1]) {\n expect((aguiMsgs2[1] as any).toolCalls[0].function.name).toBe(\"specificAction\");\n expect((aguiMsgs2[1] as any).toolCalls[0].function.arguments).toBe(\n '{\"test\":\"specific-value\"}',\n );\n }\n });\n\n test(\"wild card action GQL -> AGUI -> GQL roundtrip\", () => {\n const actionExecMsg = new gql.ActionExecutionMessage({\n id: \"wildcard-action-1\",\n name: \"unknownAction\",\n arguments: { test: \"wildcard-gql-value\" },\n parentMessageId: \"assistant-1\",\n });\n\n const actions: Record<string, any> = {\n \"*\": {\n name: \"*\",\n render: vi.fn((props) => `GQL wildcard rendered: ${props.args.test}`),\n },\n };\n\n // GQL -> AGUI -> GQL roundtrip\n const aguiMsgs = gqlToAGUI([actionExecMsg], actions);\n const gqlMsgs2 = aguiToGQL(aguiMsgs, actions);\n\n // When converting ActionExecutionMessage to AGUI and back, we get:\n // 1. A TextMessage (assistant message with toolCalls)\n // 2. An ActionExecutionMessage (the tool call itself)\n expect(gqlMsgs2).toHaveLength(2);\n expect(gqlMsgs2[0].id).toBe(\"wildcard-action-1\");\n expect((gqlMsgs2[0] as any).role).toBe(gql.Role.Assistant);\n expect(gqlMsgs2[1].id).toBe(\"wildcard-action-1\");\n expect((gqlMsgs2[1] as any).name).toBe(\"unknownAction\");\n expect((gqlMsgs2[1] as any).arguments).toEqual({ test: \"wildcard-gql-value\" });\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,eAAe,KAAe;AACrC,MAAI,OAAO,QAAQ;AAAY,WAAO;AACtC,MAAI,MAAM,QAAQ,GAAG;AAAG,WAAO,IAAI,IAAI,cAAc;AACrD,MAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,UAAM,MAAW,CAAC;AAClB,eAAW,KAAK,KAAK;AACnB,UAAI,OAAO,IAAI,CAAC,MAAM,YAAY;AAChC,YAAI,CAAC,IAAI,eAAe,IAAI,CAAC,CAAC;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,SAAS,gCAAgC,MAAM;AAC7C,OAAK,oCAAoC,MAAM;AAC7C,UAAM,UAAwB;AAAA,MAC5B,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AACA,UAAM,UAAU,UAAU,OAAO;AACjC,UAAM,YAAY,UAAU,OAAO;AACnC,iBAAO,eAAe,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,eAAe,OAAO,CAAC;AAAA,EACtE,CAAC;AAED,OAAK,mCAAmC,MAAM;AAC5C,UAAM,SAAS,IAAQ,YAAY;AAAA,MACjC,IAAI;AAAA,MACJ,SAAS;AAAA,MACT,MAAU,KAAK;AAAA,IACjB,CAAC;AACD,UAAM,WAAW,UAAU,MAAM;AACjC,UAAM,WAAW,UAAU,QAAQ;AAEnC,iBAAO,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,EAAE;AACrC,iBAAQ,SAAS,CAAC,EAAU,OAAO,EAAE,KAAK,OAAO,OAAO;AACxD,iBAAQ,SAAS,CAAC,EAAU,IAAI,EAAE,KAAK,OAAO,IAAI;AAAA,EACpD,CAAC;AAED,OAAK,oCAAoC,MAAM;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-next.0",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"tsup": "^6.7.0",
|
|
46
46
|
"typescript": "^5.4.5",
|
|
47
47
|
"vitest": "^3.1.3",
|
|
48
|
-
"@copilotkit/runtime": "1.10.0"
|
|
48
|
+
"@copilotkit/runtime": "1.10.1-next.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@urql/core": "^5.0.3",
|
|
52
52
|
"untruncate-json": "^0.0.1",
|
|
53
53
|
"urql": "^4.1.0",
|
|
54
|
-
"@copilotkit/shared": "1.10.0"
|
|
54
|
+
"@copilotkit/shared": "1.10.1-next.0"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"copilotkit",
|
|
@@ -637,4 +637,430 @@ describe("agui-to-gql", () => {
|
|
|
637
637
|
expect(result.role).toBe(gql.Role.User);
|
|
638
638
|
});
|
|
639
639
|
});
|
|
640
|
+
|
|
641
|
+
describe("Wild Card Actions", () => {
|
|
642
|
+
test("should preserve render function for specific action", () => {
|
|
643
|
+
const mockRender = () => "Specific Action Render";
|
|
644
|
+
const aguiMessage: agui.Message = {
|
|
645
|
+
id: "assistant-1",
|
|
646
|
+
role: "assistant",
|
|
647
|
+
content: "I'll execute a function",
|
|
648
|
+
toolCalls: [
|
|
649
|
+
{
|
|
650
|
+
id: "tool-call-1",
|
|
651
|
+
type: "function",
|
|
652
|
+
function: {
|
|
653
|
+
name: "specificAction",
|
|
654
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
],
|
|
658
|
+
generativeUI: mockRender,
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
const actions: Record<string, any> = {
|
|
662
|
+
specificAction: { name: "specificAction" },
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
666
|
+
|
|
667
|
+
expect(result).toHaveLength(2);
|
|
668
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
669
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
670
|
+
expect(actions.specificAction.render).toBe(mockRender);
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
test("should preserve render function for wild card action", () => {
|
|
674
|
+
const mockRender = () => "Wild Card Action Render";
|
|
675
|
+
const aguiMessage: agui.Message = {
|
|
676
|
+
id: "assistant-2",
|
|
677
|
+
role: "assistant",
|
|
678
|
+
content: "I'll execute an unknown function",
|
|
679
|
+
toolCalls: [
|
|
680
|
+
{
|
|
681
|
+
id: "tool-call-2",
|
|
682
|
+
type: "function",
|
|
683
|
+
function: {
|
|
684
|
+
name: "unknownAction",
|
|
685
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
],
|
|
689
|
+
generativeUI: mockRender,
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
const actions: Record<string, any> = {
|
|
693
|
+
"*": { name: "*" },
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
697
|
+
|
|
698
|
+
expect(result).toHaveLength(2);
|
|
699
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
700
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
701
|
+
expect(actions["*"].render).toBe(mockRender);
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
test("should prioritize specific action over wild card action", () => {
|
|
705
|
+
const mockRender = () => "Prioritized Render";
|
|
706
|
+
const aguiMessage: agui.Message = {
|
|
707
|
+
id: "assistant-3",
|
|
708
|
+
role: "assistant",
|
|
709
|
+
content: "I'll execute a function",
|
|
710
|
+
toolCalls: [
|
|
711
|
+
{
|
|
712
|
+
id: "tool-call-3",
|
|
713
|
+
type: "function",
|
|
714
|
+
function: {
|
|
715
|
+
name: "specificAction",
|
|
716
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
717
|
+
},
|
|
718
|
+
},
|
|
719
|
+
],
|
|
720
|
+
generativeUI: mockRender,
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
const actions: Record<string, any> = {
|
|
724
|
+
specificAction: { name: "specificAction" },
|
|
725
|
+
"*": { name: "*" },
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
729
|
+
|
|
730
|
+
expect(result).toHaveLength(2);
|
|
731
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
732
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
733
|
+
expect(actions.specificAction.render).toBe(mockRender);
|
|
734
|
+
expect(actions["*"].render).toBeUndefined();
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
test("should not preserve render function when no matching action", () => {
|
|
738
|
+
const mockRender = () => "Unmatched Render";
|
|
739
|
+
const aguiMessage: agui.Message = {
|
|
740
|
+
id: "assistant-4",
|
|
741
|
+
role: "assistant",
|
|
742
|
+
content: "I'll execute an unmatched function",
|
|
743
|
+
toolCalls: [
|
|
744
|
+
{
|
|
745
|
+
id: "tool-call-4",
|
|
746
|
+
type: "function",
|
|
747
|
+
function: {
|
|
748
|
+
name: "unmatchedAction",
|
|
749
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
750
|
+
},
|
|
751
|
+
},
|
|
752
|
+
],
|
|
753
|
+
generativeUI: mockRender,
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
const actions: Record<string, any> = {
|
|
757
|
+
otherAction: { name: "otherAction" },
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
761
|
+
|
|
762
|
+
expect(result).toHaveLength(2);
|
|
763
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
764
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
765
|
+
expect(actions.otherAction.render).toBeUndefined();
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
test("should handle multiple tool calls with wild card action", () => {
|
|
769
|
+
const mockRender = () => "Wild Card Render";
|
|
770
|
+
const aguiMessage: agui.Message = {
|
|
771
|
+
id: "assistant-5",
|
|
772
|
+
role: "assistant",
|
|
773
|
+
content: "I'll execute multiple functions",
|
|
774
|
+
toolCalls: [
|
|
775
|
+
{
|
|
776
|
+
id: "tool-call-5",
|
|
777
|
+
type: "function",
|
|
778
|
+
function: {
|
|
779
|
+
name: "firstFunction",
|
|
780
|
+
arguments: JSON.stringify({ param: "value1" }),
|
|
781
|
+
},
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
id: "tool-call-6",
|
|
785
|
+
type: "function",
|
|
786
|
+
function: {
|
|
787
|
+
name: "secondFunction",
|
|
788
|
+
arguments: JSON.stringify({ param: "value2" }),
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
],
|
|
792
|
+
generativeUI: mockRender,
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
const actions: Record<string, any> = {
|
|
796
|
+
"*": { name: "*" },
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
800
|
+
|
|
801
|
+
expect(result).toHaveLength(3);
|
|
802
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
803
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
804
|
+
expect(result[2]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
805
|
+
expect(actions["*"].render).toBe(mockRender);
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
test("should handle mixed specific and wild card actions", () => {
|
|
809
|
+
const mockRender = () => "Mixed Render";
|
|
810
|
+
const aguiMessage: agui.Message = {
|
|
811
|
+
id: "assistant-6",
|
|
812
|
+
role: "assistant",
|
|
813
|
+
content: "I'll execute mixed functions",
|
|
814
|
+
toolCalls: [
|
|
815
|
+
{
|
|
816
|
+
id: "tool-call-7",
|
|
817
|
+
type: "function",
|
|
818
|
+
function: {
|
|
819
|
+
name: "specificAction",
|
|
820
|
+
arguments: JSON.stringify({ param: "value1" }),
|
|
821
|
+
},
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
id: "tool-call-8",
|
|
825
|
+
type: "function",
|
|
826
|
+
function: {
|
|
827
|
+
name: "unknownAction",
|
|
828
|
+
arguments: JSON.stringify({ param: "value2" }),
|
|
829
|
+
},
|
|
830
|
+
},
|
|
831
|
+
],
|
|
832
|
+
generativeUI: mockRender,
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
const actions: Record<string, any> = {
|
|
836
|
+
specificAction: { name: "specificAction" },
|
|
837
|
+
"*": { name: "*" },
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
841
|
+
|
|
842
|
+
expect(result).toHaveLength(3);
|
|
843
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
844
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
845
|
+
expect(result[2]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
846
|
+
expect(actions.specificAction.render).toBe(mockRender);
|
|
847
|
+
// The wild card action should get the render function for the second tool call
|
|
848
|
+
expect(actions["*"].render).toBe(mockRender);
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
test("should handle no actions provided", () => {
|
|
852
|
+
const mockRender = () => "No Actions Render";
|
|
853
|
+
const aguiMessage: agui.Message = {
|
|
854
|
+
id: "assistant-7",
|
|
855
|
+
role: "assistant",
|
|
856
|
+
content: "I'll execute a function",
|
|
857
|
+
toolCalls: [
|
|
858
|
+
{
|
|
859
|
+
id: "tool-call-9",
|
|
860
|
+
type: "function",
|
|
861
|
+
function: {
|
|
862
|
+
name: "anyAction",
|
|
863
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
864
|
+
},
|
|
865
|
+
},
|
|
866
|
+
],
|
|
867
|
+
generativeUI: mockRender,
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
const result = aguiToGQL(aguiMessage);
|
|
871
|
+
|
|
872
|
+
expect(result).toHaveLength(2);
|
|
873
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
874
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
test("should handle empty actions object", () => {
|
|
878
|
+
const mockRender = () => "Empty Actions Render";
|
|
879
|
+
const aguiMessage: agui.Message = {
|
|
880
|
+
id: "assistant-8",
|
|
881
|
+
role: "assistant",
|
|
882
|
+
content: "I'll execute a function",
|
|
883
|
+
toolCalls: [
|
|
884
|
+
{
|
|
885
|
+
id: "tool-call-10",
|
|
886
|
+
type: "function",
|
|
887
|
+
function: {
|
|
888
|
+
name: "anyAction",
|
|
889
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
890
|
+
},
|
|
891
|
+
},
|
|
892
|
+
],
|
|
893
|
+
generativeUI: mockRender,
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
const actions: Record<string, any> = {};
|
|
897
|
+
|
|
898
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
899
|
+
|
|
900
|
+
expect(result).toHaveLength(2);
|
|
901
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
902
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
test("should handle actions with null render functions", () => {
|
|
906
|
+
const mockRender = () => "Null Render Test";
|
|
907
|
+
const aguiMessage: agui.Message = {
|
|
908
|
+
id: "assistant-9",
|
|
909
|
+
role: "assistant",
|
|
910
|
+
content: "I'll execute a function",
|
|
911
|
+
toolCalls: [
|
|
912
|
+
{
|
|
913
|
+
id: "tool-call-11",
|
|
914
|
+
type: "function",
|
|
915
|
+
function: {
|
|
916
|
+
name: "specificAction",
|
|
917
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
918
|
+
},
|
|
919
|
+
},
|
|
920
|
+
],
|
|
921
|
+
generativeUI: mockRender,
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
const actions: Record<string, any> = {
|
|
925
|
+
specificAction: { name: "specificAction", render: null },
|
|
926
|
+
"*": { name: "*", render: null },
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
930
|
+
|
|
931
|
+
expect(result).toHaveLength(2);
|
|
932
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
933
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
934
|
+
// The render function should still be assigned even if the action had null render
|
|
935
|
+
expect(actions.specificAction.render).toBe(mockRender);
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
test("should handle actions with undefined render functions", () => {
|
|
939
|
+
const mockRender = () => "Undefined Render Test";
|
|
940
|
+
const aguiMessage: agui.Message = {
|
|
941
|
+
id: "assistant-10",
|
|
942
|
+
role: "assistant",
|
|
943
|
+
content: "I'll execute a function",
|
|
944
|
+
toolCalls: [
|
|
945
|
+
{
|
|
946
|
+
id: "tool-call-12",
|
|
947
|
+
type: "function",
|
|
948
|
+
function: {
|
|
949
|
+
name: "wildcardAction",
|
|
950
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
951
|
+
},
|
|
952
|
+
},
|
|
953
|
+
],
|
|
954
|
+
generativeUI: mockRender,
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
const actions: Record<string, any> = {
|
|
958
|
+
"*": { name: "*", render: undefined },
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
962
|
+
|
|
963
|
+
expect(result).toHaveLength(2);
|
|
964
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
965
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
966
|
+
// The render function should still be assigned even if the action had undefined render
|
|
967
|
+
expect(actions["*"].render).toBe(mockRender);
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
test("should handle tool calls with malformed arguments", () => {
|
|
971
|
+
const mockRender = () => "Malformed Args Test";
|
|
972
|
+
const aguiMessage: agui.Message = {
|
|
973
|
+
id: "assistant-11",
|
|
974
|
+
role: "assistant",
|
|
975
|
+
content: "I'll execute a function",
|
|
976
|
+
toolCalls: [
|
|
977
|
+
{
|
|
978
|
+
id: "tool-call-13",
|
|
979
|
+
type: "function",
|
|
980
|
+
function: {
|
|
981
|
+
name: "wildcardAction",
|
|
982
|
+
arguments: "invalid json {", // Malformed JSON
|
|
983
|
+
},
|
|
984
|
+
},
|
|
985
|
+
],
|
|
986
|
+
generativeUI: mockRender,
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
const actions: Record<string, any> = {
|
|
990
|
+
"*": { name: "*" },
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
994
|
+
|
|
995
|
+
expect(result).toHaveLength(2);
|
|
996
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
997
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
998
|
+
expect(actions["*"].render).toBe(mockRender);
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
test("should handle tool calls with empty arguments string", () => {
|
|
1002
|
+
const mockRender = () => "Empty Args Test";
|
|
1003
|
+
const aguiMessage: agui.Message = {
|
|
1004
|
+
id: "assistant-12",
|
|
1005
|
+
role: "assistant",
|
|
1006
|
+
content: "I'll execute a function",
|
|
1007
|
+
toolCalls: [
|
|
1008
|
+
{
|
|
1009
|
+
id: "tool-call-14",
|
|
1010
|
+
type: "function",
|
|
1011
|
+
function: {
|
|
1012
|
+
name: "wildcardAction",
|
|
1013
|
+
arguments: "",
|
|
1014
|
+
},
|
|
1015
|
+
},
|
|
1016
|
+
],
|
|
1017
|
+
generativeUI: mockRender,
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
const actions: Record<string, any> = {
|
|
1021
|
+
"*": { name: "*" },
|
|
1022
|
+
};
|
|
1023
|
+
|
|
1024
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
1025
|
+
|
|
1026
|
+
expect(result).toHaveLength(2);
|
|
1027
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
1028
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
1029
|
+
expect(actions["*"].render).toBe(mockRender);
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
test("should handle multiple wild card actions in same object", () => {
|
|
1033
|
+
const mockRender = () => "Multiple Wildcards Test";
|
|
1034
|
+
const aguiMessage: agui.Message = {
|
|
1035
|
+
id: "assistant-13",
|
|
1036
|
+
role: "assistant",
|
|
1037
|
+
content: "I'll execute a function",
|
|
1038
|
+
toolCalls: [
|
|
1039
|
+
{
|
|
1040
|
+
id: "tool-call-15",
|
|
1041
|
+
type: "function",
|
|
1042
|
+
function: {
|
|
1043
|
+
name: "unknownAction",
|
|
1044
|
+
arguments: JSON.stringify({ param: "value" }),
|
|
1045
|
+
},
|
|
1046
|
+
},
|
|
1047
|
+
],
|
|
1048
|
+
generativeUI: mockRender,
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
const actions: Record<string, any> = {
|
|
1052
|
+
wildcard1: { name: "*" },
|
|
1053
|
+
wildcard2: { name: "*" },
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
1057
|
+
|
|
1058
|
+
expect(result).toHaveLength(2);
|
|
1059
|
+
expect(result[0]).toBeInstanceOf(gql.TextMessage);
|
|
1060
|
+
expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
|
|
1061
|
+
// Should assign to the first wild card action found
|
|
1062
|
+
expect(actions.wildcard1.render).toBe(mockRender);
|
|
1063
|
+
expect(actions.wildcard2.render).toBeUndefined();
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
640
1066
|
});
|
|
@@ -86,8 +86,17 @@ export function aguiToGQL(
|
|
|
86
86
|
// Preserve render function in actions context
|
|
87
87
|
if ("generativeUI" in message && message.generativeUI && actions) {
|
|
88
88
|
const actionName = toolCall.function.name;
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
// Check for specific action first, then wild card action
|
|
90
|
+
const specificAction = Object.values(actions).find(
|
|
91
|
+
(action: any) => action.name === actionName,
|
|
92
|
+
);
|
|
93
|
+
const wildcardAction = Object.values(actions).find((action: any) => action.name === "*");
|
|
94
|
+
|
|
95
|
+
// Assign render function to the matching action (specific takes priority)
|
|
96
|
+
if (specificAction) {
|
|
97
|
+
specificAction.render = message.generativeUI;
|
|
98
|
+
} else if (wildcardAction) {
|
|
99
|
+
wildcardAction.render = message.generativeUI;
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
gqlMessages.push(actionExecMsg);
|