@copilotkit/runtime-client-gql 1.10.0 → 1.10.1-next.1
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 +20 -0
- package/dist/{chunk-PAQ6AHHC.mjs → chunk-5V6B3OXS.mjs} +2 -2
- package/dist/{chunk-PAQ6AHHC.mjs.map → chunk-5V6B3OXS.mjs.map} +1 -1
- package/dist/{chunk-YNQMTL2P.mjs → chunk-SCACOKQX.mjs} +38 -8
- package/dist/chunk-SCACOKQX.mjs.map +1 -0
- package/dist/{chunk-MTD2RJDJ.mjs → chunk-ZYA32QXZ.mjs} +44 -29
- package/dist/chunk-ZYA32QXZ.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 +82 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -3
- package/dist/message-conversion/agui-to-gql.js +37 -7
- 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 +529 -7
- package/dist/message-conversion/agui-to-gql.test.js.map +1 -1
- package/dist/message-conversion/agui-to-gql.test.mjs +494 -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 +44 -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 +622 -28
- package/dist/message-conversion/gql-to-agui.test.js.map +1 -1
- package/dist/message-conversion/gql-to-agui.test.mjs +583 -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 +81 -35
- 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 +250 -35
- package/dist/message-conversion/roundtrip-conversion.test.js.map +1 -1
- package/dist/message-conversion/roundtrip-conversion.test.mjs +174 -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 +566 -0
- package/src/message-conversion/agui-to-gql.ts +56 -9
- package/src/message-conversion/gql-to-agui.test.ts +663 -0
- package/src/message-conversion/gql-to-agui.ts +62 -35
- package/src/message-conversion/roundtrip-conversion.test.ts +228 -0
- package/dist/chunk-MTD2RJDJ.mjs.map +0 -1
- package/dist/chunk-YNQMTL2P.mjs.map +0 -1
|
@@ -19013,8 +19013,14 @@ function aguiToGQL(messages, actions, coAgentStateRenders) {
|
|
|
19013
19013
|
const actionExecMsg = aguiToolCallToGQLActionExecution(toolCall, message.id);
|
|
19014
19014
|
if ("generativeUI" in message && message.generativeUI && actions) {
|
|
19015
19015
|
const actionName = toolCall.function.name;
|
|
19016
|
-
|
|
19017
|
-
|
|
19016
|
+
const specificAction = Object.values(actions).find(
|
|
19017
|
+
(action) => action.name === actionName
|
|
19018
|
+
);
|
|
19019
|
+
const wildcardAction = Object.values(actions).find((action) => action.name === "*");
|
|
19020
|
+
if (specificAction) {
|
|
19021
|
+
specificAction.render = message.generativeUI;
|
|
19022
|
+
} else if (wildcardAction) {
|
|
19023
|
+
wildcardAction.render = message.generativeUI;
|
|
19018
19024
|
}
|
|
19019
19025
|
}
|
|
19020
19026
|
gqlMessages.push(actionExecMsg);
|
|
@@ -19060,10 +19066,20 @@ function aguiToolCallToGQLActionExecution(toolCall, parentMessageId) {
|
|
|
19060
19066
|
throw new Error(`Unsupported tool call type: ${toolCall.type}`);
|
|
19061
19067
|
}
|
|
19062
19068
|
let argumentsObj;
|
|
19063
|
-
|
|
19064
|
-
|
|
19065
|
-
|
|
19066
|
-
|
|
19069
|
+
if (typeof toolCall.function.arguments === "string") {
|
|
19070
|
+
try {
|
|
19071
|
+
argumentsObj = JSON.parse(toolCall.function.arguments);
|
|
19072
|
+
} catch (error) {
|
|
19073
|
+
console.warn(`Failed to parse tool call arguments for ${toolCall.function.name}:`, error);
|
|
19074
|
+
argumentsObj = {};
|
|
19075
|
+
}
|
|
19076
|
+
} else if (typeof toolCall.function.arguments === "object" && toolCall.function.arguments !== null) {
|
|
19077
|
+
argumentsObj = toolCall.function.arguments;
|
|
19078
|
+
} else {
|
|
19079
|
+
console.warn(
|
|
19080
|
+
`Invalid tool call arguments type for ${toolCall.function.name}:`,
|
|
19081
|
+
typeof toolCall.function.arguments
|
|
19082
|
+
);
|
|
19067
19083
|
argumentsObj = {};
|
|
19068
19084
|
}
|
|
19069
19085
|
return new ActionExecutionMessage({
|
|
@@ -19081,9 +19097,23 @@ function aguiToolMessageToGQLResultMessage(message, toolCallNames) {
|
|
|
19081
19097
|
throw new Error("Tool message must have a toolCallId");
|
|
19082
19098
|
}
|
|
19083
19099
|
const actionName = toolCallNames[message.toolCallId] || "unknown";
|
|
19100
|
+
let resultContent;
|
|
19101
|
+
const messageContent = message.content || "";
|
|
19102
|
+
if (typeof messageContent === "string") {
|
|
19103
|
+
resultContent = messageContent;
|
|
19104
|
+
} else if (typeof messageContent === "object" && messageContent !== null) {
|
|
19105
|
+
try {
|
|
19106
|
+
resultContent = JSON.stringify(messageContent);
|
|
19107
|
+
} catch (error) {
|
|
19108
|
+
console.warn(`Failed to stringify tool result for ${actionName}:`, error);
|
|
19109
|
+
resultContent = String(messageContent);
|
|
19110
|
+
}
|
|
19111
|
+
} else {
|
|
19112
|
+
resultContent = String(messageContent);
|
|
19113
|
+
}
|
|
19084
19114
|
return new ResultMessage({
|
|
19085
19115
|
id: message.id,
|
|
19086
|
-
result:
|
|
19116
|
+
result: resultContent,
|
|
19087
19117
|
actionExecutionId: message.toolCallId,
|
|
19088
19118
|
actionName: message.toolName || actionName
|
|
19089
19119
|
});
|
|
@@ -19663,6 +19693,498 @@ describe("agui-to-gql", () => {
|
|
|
19663
19693
|
globalExpect(result.role).toBe(Role.User);
|
|
19664
19694
|
});
|
|
19665
19695
|
});
|
|
19696
|
+
describe("Wild Card Actions", () => {
|
|
19697
|
+
test3("should preserve render function for specific action", () => {
|
|
19698
|
+
const mockRender = () => "Specific Action Render";
|
|
19699
|
+
const aguiMessage = {
|
|
19700
|
+
id: "assistant-1",
|
|
19701
|
+
role: "assistant",
|
|
19702
|
+
content: "I'll execute a function",
|
|
19703
|
+
toolCalls: [
|
|
19704
|
+
{
|
|
19705
|
+
id: "tool-call-1",
|
|
19706
|
+
type: "function",
|
|
19707
|
+
function: {
|
|
19708
|
+
name: "specificAction",
|
|
19709
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19710
|
+
}
|
|
19711
|
+
}
|
|
19712
|
+
],
|
|
19713
|
+
generativeUI: mockRender
|
|
19714
|
+
};
|
|
19715
|
+
const actions = {
|
|
19716
|
+
specificAction: { name: "specificAction" }
|
|
19717
|
+
};
|
|
19718
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19719
|
+
globalExpect(result).toHaveLength(2);
|
|
19720
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19721
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19722
|
+
globalExpect(actions.specificAction.render).toBe(mockRender);
|
|
19723
|
+
});
|
|
19724
|
+
test3("should preserve render function for wild card action", () => {
|
|
19725
|
+
const mockRender = () => "Wild Card Action Render";
|
|
19726
|
+
const aguiMessage = {
|
|
19727
|
+
id: "assistant-2",
|
|
19728
|
+
role: "assistant",
|
|
19729
|
+
content: "I'll execute an unknown function",
|
|
19730
|
+
toolCalls: [
|
|
19731
|
+
{
|
|
19732
|
+
id: "tool-call-2",
|
|
19733
|
+
type: "function",
|
|
19734
|
+
function: {
|
|
19735
|
+
name: "unknownAction",
|
|
19736
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19737
|
+
}
|
|
19738
|
+
}
|
|
19739
|
+
],
|
|
19740
|
+
generativeUI: mockRender
|
|
19741
|
+
};
|
|
19742
|
+
const actions = {
|
|
19743
|
+
"*": { name: "*" }
|
|
19744
|
+
};
|
|
19745
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19746
|
+
globalExpect(result).toHaveLength(2);
|
|
19747
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19748
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19749
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
19750
|
+
});
|
|
19751
|
+
test3("should prioritize specific action over wild card action", () => {
|
|
19752
|
+
const mockRender = () => "Prioritized Render";
|
|
19753
|
+
const aguiMessage = {
|
|
19754
|
+
id: "assistant-3",
|
|
19755
|
+
role: "assistant",
|
|
19756
|
+
content: "I'll execute a function",
|
|
19757
|
+
toolCalls: [
|
|
19758
|
+
{
|
|
19759
|
+
id: "tool-call-3",
|
|
19760
|
+
type: "function",
|
|
19761
|
+
function: {
|
|
19762
|
+
name: "specificAction",
|
|
19763
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19764
|
+
}
|
|
19765
|
+
}
|
|
19766
|
+
],
|
|
19767
|
+
generativeUI: mockRender
|
|
19768
|
+
};
|
|
19769
|
+
const actions = {
|
|
19770
|
+
specificAction: { name: "specificAction" },
|
|
19771
|
+
"*": { name: "*" }
|
|
19772
|
+
};
|
|
19773
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19774
|
+
globalExpect(result).toHaveLength(2);
|
|
19775
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19776
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19777
|
+
globalExpect(actions.specificAction.render).toBe(mockRender);
|
|
19778
|
+
globalExpect(actions["*"].render).toBeUndefined();
|
|
19779
|
+
});
|
|
19780
|
+
test3("should not preserve render function when no matching action", () => {
|
|
19781
|
+
const mockRender = () => "Unmatched Render";
|
|
19782
|
+
const aguiMessage = {
|
|
19783
|
+
id: "assistant-4",
|
|
19784
|
+
role: "assistant",
|
|
19785
|
+
content: "I'll execute an unmatched function",
|
|
19786
|
+
toolCalls: [
|
|
19787
|
+
{
|
|
19788
|
+
id: "tool-call-4",
|
|
19789
|
+
type: "function",
|
|
19790
|
+
function: {
|
|
19791
|
+
name: "unmatchedAction",
|
|
19792
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19793
|
+
}
|
|
19794
|
+
}
|
|
19795
|
+
],
|
|
19796
|
+
generativeUI: mockRender
|
|
19797
|
+
};
|
|
19798
|
+
const actions = {
|
|
19799
|
+
otherAction: { name: "otherAction" }
|
|
19800
|
+
};
|
|
19801
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19802
|
+
globalExpect(result).toHaveLength(2);
|
|
19803
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19804
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19805
|
+
globalExpect(actions.otherAction.render).toBeUndefined();
|
|
19806
|
+
});
|
|
19807
|
+
test3("should handle multiple tool calls with wild card action", () => {
|
|
19808
|
+
const mockRender = () => "Wild Card Render";
|
|
19809
|
+
const aguiMessage = {
|
|
19810
|
+
id: "assistant-5",
|
|
19811
|
+
role: "assistant",
|
|
19812
|
+
content: "I'll execute multiple functions",
|
|
19813
|
+
toolCalls: [
|
|
19814
|
+
{
|
|
19815
|
+
id: "tool-call-5",
|
|
19816
|
+
type: "function",
|
|
19817
|
+
function: {
|
|
19818
|
+
name: "firstFunction",
|
|
19819
|
+
arguments: JSON.stringify({ param: "value1" })
|
|
19820
|
+
}
|
|
19821
|
+
},
|
|
19822
|
+
{
|
|
19823
|
+
id: "tool-call-6",
|
|
19824
|
+
type: "function",
|
|
19825
|
+
function: {
|
|
19826
|
+
name: "secondFunction",
|
|
19827
|
+
arguments: JSON.stringify({ param: "value2" })
|
|
19828
|
+
}
|
|
19829
|
+
}
|
|
19830
|
+
],
|
|
19831
|
+
generativeUI: mockRender
|
|
19832
|
+
};
|
|
19833
|
+
const actions = {
|
|
19834
|
+
"*": { name: "*" }
|
|
19835
|
+
};
|
|
19836
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19837
|
+
globalExpect(result).toHaveLength(3);
|
|
19838
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19839
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19840
|
+
globalExpect(result[2]).toBeInstanceOf(ActionExecutionMessage);
|
|
19841
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
19842
|
+
});
|
|
19843
|
+
test3("should handle mixed specific and wild card actions", () => {
|
|
19844
|
+
const mockRender = () => "Mixed Render";
|
|
19845
|
+
const aguiMessage = {
|
|
19846
|
+
id: "assistant-6",
|
|
19847
|
+
role: "assistant",
|
|
19848
|
+
content: "I'll execute mixed functions",
|
|
19849
|
+
toolCalls: [
|
|
19850
|
+
{
|
|
19851
|
+
id: "tool-call-7",
|
|
19852
|
+
type: "function",
|
|
19853
|
+
function: {
|
|
19854
|
+
name: "specificAction",
|
|
19855
|
+
arguments: JSON.stringify({ param: "value1" })
|
|
19856
|
+
}
|
|
19857
|
+
},
|
|
19858
|
+
{
|
|
19859
|
+
id: "tool-call-8",
|
|
19860
|
+
type: "function",
|
|
19861
|
+
function: {
|
|
19862
|
+
name: "unknownAction",
|
|
19863
|
+
arguments: JSON.stringify({ param: "value2" })
|
|
19864
|
+
}
|
|
19865
|
+
}
|
|
19866
|
+
],
|
|
19867
|
+
generativeUI: mockRender
|
|
19868
|
+
};
|
|
19869
|
+
const actions = {
|
|
19870
|
+
specificAction: { name: "specificAction" },
|
|
19871
|
+
"*": { name: "*" }
|
|
19872
|
+
};
|
|
19873
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19874
|
+
globalExpect(result).toHaveLength(3);
|
|
19875
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19876
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19877
|
+
globalExpect(result[2]).toBeInstanceOf(ActionExecutionMessage);
|
|
19878
|
+
globalExpect(actions.specificAction.render).toBe(mockRender);
|
|
19879
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
19880
|
+
});
|
|
19881
|
+
test3("should handle no actions provided", () => {
|
|
19882
|
+
const mockRender = () => "No Actions Render";
|
|
19883
|
+
const aguiMessage = {
|
|
19884
|
+
id: "assistant-7",
|
|
19885
|
+
role: "assistant",
|
|
19886
|
+
content: "I'll execute a function",
|
|
19887
|
+
toolCalls: [
|
|
19888
|
+
{
|
|
19889
|
+
id: "tool-call-9",
|
|
19890
|
+
type: "function",
|
|
19891
|
+
function: {
|
|
19892
|
+
name: "anyAction",
|
|
19893
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19894
|
+
}
|
|
19895
|
+
}
|
|
19896
|
+
],
|
|
19897
|
+
generativeUI: mockRender
|
|
19898
|
+
};
|
|
19899
|
+
const result = aguiToGQL(aguiMessage);
|
|
19900
|
+
globalExpect(result).toHaveLength(2);
|
|
19901
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19902
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19903
|
+
});
|
|
19904
|
+
test3("should handle empty actions object", () => {
|
|
19905
|
+
const mockRender = () => "Empty Actions Render";
|
|
19906
|
+
const aguiMessage = {
|
|
19907
|
+
id: "assistant-8",
|
|
19908
|
+
role: "assistant",
|
|
19909
|
+
content: "I'll execute a function",
|
|
19910
|
+
toolCalls: [
|
|
19911
|
+
{
|
|
19912
|
+
id: "tool-call-10",
|
|
19913
|
+
type: "function",
|
|
19914
|
+
function: {
|
|
19915
|
+
name: "anyAction",
|
|
19916
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19917
|
+
}
|
|
19918
|
+
}
|
|
19919
|
+
],
|
|
19920
|
+
generativeUI: mockRender
|
|
19921
|
+
};
|
|
19922
|
+
const actions = {};
|
|
19923
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19924
|
+
globalExpect(result).toHaveLength(2);
|
|
19925
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19926
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19927
|
+
});
|
|
19928
|
+
test3("should handle actions with null render functions", () => {
|
|
19929
|
+
const mockRender = () => "Null Render Test";
|
|
19930
|
+
const aguiMessage = {
|
|
19931
|
+
id: "assistant-9",
|
|
19932
|
+
role: "assistant",
|
|
19933
|
+
content: "I'll execute a function",
|
|
19934
|
+
toolCalls: [
|
|
19935
|
+
{
|
|
19936
|
+
id: "tool-call-11",
|
|
19937
|
+
type: "function",
|
|
19938
|
+
function: {
|
|
19939
|
+
name: "specificAction",
|
|
19940
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19941
|
+
}
|
|
19942
|
+
}
|
|
19943
|
+
],
|
|
19944
|
+
generativeUI: mockRender
|
|
19945
|
+
};
|
|
19946
|
+
const actions = {
|
|
19947
|
+
specificAction: { name: "specificAction", render: null },
|
|
19948
|
+
"*": { name: "*", render: null }
|
|
19949
|
+
};
|
|
19950
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19951
|
+
globalExpect(result).toHaveLength(2);
|
|
19952
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19953
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19954
|
+
globalExpect(actions.specificAction.render).toBe(mockRender);
|
|
19955
|
+
});
|
|
19956
|
+
test3("should handle actions with undefined render functions", () => {
|
|
19957
|
+
const mockRender = () => "Undefined Render Test";
|
|
19958
|
+
const aguiMessage = {
|
|
19959
|
+
id: "assistant-10",
|
|
19960
|
+
role: "assistant",
|
|
19961
|
+
content: "I'll execute a function",
|
|
19962
|
+
toolCalls: [
|
|
19963
|
+
{
|
|
19964
|
+
id: "tool-call-12",
|
|
19965
|
+
type: "function",
|
|
19966
|
+
function: {
|
|
19967
|
+
name: "wildcardAction",
|
|
19968
|
+
arguments: JSON.stringify({ param: "value" })
|
|
19969
|
+
}
|
|
19970
|
+
}
|
|
19971
|
+
],
|
|
19972
|
+
generativeUI: mockRender
|
|
19973
|
+
};
|
|
19974
|
+
const actions = {
|
|
19975
|
+
"*": { name: "*", render: void 0 }
|
|
19976
|
+
};
|
|
19977
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
19978
|
+
globalExpect(result).toHaveLength(2);
|
|
19979
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
19980
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
19981
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
19982
|
+
});
|
|
19983
|
+
test3("should handle tool calls with malformed arguments", () => {
|
|
19984
|
+
const mockRender = () => "Malformed Args Test";
|
|
19985
|
+
const aguiMessage = {
|
|
19986
|
+
id: "assistant-11",
|
|
19987
|
+
role: "assistant",
|
|
19988
|
+
content: "I'll execute a function",
|
|
19989
|
+
toolCalls: [
|
|
19990
|
+
{
|
|
19991
|
+
id: "tool-call-13",
|
|
19992
|
+
type: "function",
|
|
19993
|
+
function: {
|
|
19994
|
+
name: "wildcardAction",
|
|
19995
|
+
arguments: "invalid json {"
|
|
19996
|
+
// Malformed JSON
|
|
19997
|
+
}
|
|
19998
|
+
}
|
|
19999
|
+
],
|
|
20000
|
+
generativeUI: mockRender
|
|
20001
|
+
};
|
|
20002
|
+
const actions = {
|
|
20003
|
+
"*": { name: "*" }
|
|
20004
|
+
};
|
|
20005
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
20006
|
+
globalExpect(result).toHaveLength(2);
|
|
20007
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
20008
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
20009
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
20010
|
+
});
|
|
20011
|
+
test3("should handle tool calls with empty arguments string", () => {
|
|
20012
|
+
const mockRender = () => "Empty Args Test";
|
|
20013
|
+
const aguiMessage = {
|
|
20014
|
+
id: "assistant-12",
|
|
20015
|
+
role: "assistant",
|
|
20016
|
+
content: "I'll execute a function",
|
|
20017
|
+
toolCalls: [
|
|
20018
|
+
{
|
|
20019
|
+
id: "tool-call-14",
|
|
20020
|
+
type: "function",
|
|
20021
|
+
function: {
|
|
20022
|
+
name: "wildcardAction",
|
|
20023
|
+
arguments: ""
|
|
20024
|
+
}
|
|
20025
|
+
}
|
|
20026
|
+
],
|
|
20027
|
+
generativeUI: mockRender
|
|
20028
|
+
};
|
|
20029
|
+
const actions = {
|
|
20030
|
+
"*": { name: "*" }
|
|
20031
|
+
};
|
|
20032
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
20033
|
+
globalExpect(result).toHaveLength(2);
|
|
20034
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
20035
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
20036
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
20037
|
+
});
|
|
20038
|
+
test3("should handle multiple wild card actions in same object", () => {
|
|
20039
|
+
const mockRender = () => "Multiple Wildcards Test";
|
|
20040
|
+
const aguiMessage = {
|
|
20041
|
+
id: "assistant-13",
|
|
20042
|
+
role: "assistant",
|
|
20043
|
+
content: "I'll execute a function",
|
|
20044
|
+
toolCalls: [
|
|
20045
|
+
{
|
|
20046
|
+
id: "tool-call-15",
|
|
20047
|
+
type: "function",
|
|
20048
|
+
function: {
|
|
20049
|
+
name: "unknownAction",
|
|
20050
|
+
arguments: JSON.stringify({ param: "value" })
|
|
20051
|
+
}
|
|
20052
|
+
}
|
|
20053
|
+
],
|
|
20054
|
+
generativeUI: mockRender
|
|
20055
|
+
};
|
|
20056
|
+
const actions = {
|
|
20057
|
+
wildcard1: { name: "*" },
|
|
20058
|
+
wildcard2: { name: "*" }
|
|
20059
|
+
};
|
|
20060
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
20061
|
+
globalExpect(result).toHaveLength(2);
|
|
20062
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
20063
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
20064
|
+
globalExpect(actions.wildcard1.render).toBe(mockRender);
|
|
20065
|
+
globalExpect(actions.wildcard2.render).toBeUndefined();
|
|
20066
|
+
});
|
|
20067
|
+
test3("should handle tool calls with object arguments (backward compatibility)", () => {
|
|
20068
|
+
const mockRender = () => "Object Args Test";
|
|
20069
|
+
const aguiMessage = {
|
|
20070
|
+
id: "assistant-14",
|
|
20071
|
+
role: "assistant",
|
|
20072
|
+
content: "I'll execute a function",
|
|
20073
|
+
toolCalls: [
|
|
20074
|
+
{
|
|
20075
|
+
id: "tool-call-16",
|
|
20076
|
+
type: "function",
|
|
20077
|
+
function: {
|
|
20078
|
+
name: "objectArgsAction",
|
|
20079
|
+
arguments: { param: "value" }
|
|
20080
|
+
// Object instead of string
|
|
20081
|
+
}
|
|
20082
|
+
}
|
|
20083
|
+
],
|
|
20084
|
+
generativeUI: mockRender
|
|
20085
|
+
};
|
|
20086
|
+
const actions = {
|
|
20087
|
+
"*": { name: "*" }
|
|
20088
|
+
};
|
|
20089
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
20090
|
+
globalExpect(result).toHaveLength(2);
|
|
20091
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
20092
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
20093
|
+
globalExpect(result[1].arguments).toEqual({ param: "value" });
|
|
20094
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
20095
|
+
});
|
|
20096
|
+
test3("should handle tool calls with null/undefined arguments", () => {
|
|
20097
|
+
const mockRender = () => "Null Args Test";
|
|
20098
|
+
const aguiMessage = {
|
|
20099
|
+
id: "assistant-15",
|
|
20100
|
+
role: "assistant",
|
|
20101
|
+
content: "I'll execute a function",
|
|
20102
|
+
toolCalls: [
|
|
20103
|
+
{
|
|
20104
|
+
id: "tool-call-17",
|
|
20105
|
+
type: "function",
|
|
20106
|
+
function: {
|
|
20107
|
+
name: "nullArgsAction",
|
|
20108
|
+
arguments: null
|
|
20109
|
+
}
|
|
20110
|
+
}
|
|
20111
|
+
],
|
|
20112
|
+
generativeUI: mockRender
|
|
20113
|
+
};
|
|
20114
|
+
const actions = {
|
|
20115
|
+
"*": { name: "*" }
|
|
20116
|
+
};
|
|
20117
|
+
const result = aguiToGQL(aguiMessage, actions);
|
|
20118
|
+
globalExpect(result).toHaveLength(2);
|
|
20119
|
+
globalExpect(result[0]).toBeInstanceOf(TextMessage);
|
|
20120
|
+
globalExpect(result[1]).toBeInstanceOf(ActionExecutionMessage);
|
|
20121
|
+
globalExpect(result[1].arguments).toEqual({});
|
|
20122
|
+
globalExpect(actions["*"].render).toBe(mockRender);
|
|
20123
|
+
});
|
|
20124
|
+
test3("should handle tool result messages with object content", () => {
|
|
20125
|
+
const aguiMessage = {
|
|
20126
|
+
id: "tool-result-1",
|
|
20127
|
+
role: "tool",
|
|
20128
|
+
content: { status: "success", data: { value: 42 } },
|
|
20129
|
+
toolCallId: "tool-call-1",
|
|
20130
|
+
toolName: "testAction"
|
|
20131
|
+
};
|
|
20132
|
+
const toolCallNames = { "tool-call-1": "testAction" };
|
|
20133
|
+
const result = aguiToGQL(aguiMessage);
|
|
20134
|
+
globalExpect(result).toHaveLength(1);
|
|
20135
|
+
globalExpect(result[0]).toBeInstanceOf(ResultMessage);
|
|
20136
|
+
globalExpect(result[0].result).toBe('{"status":"success","data":{"value":42}}');
|
|
20137
|
+
globalExpect(result[0].actionExecutionId).toBe("tool-call-1");
|
|
20138
|
+
globalExpect(result[0].actionName).toBe("testAction");
|
|
20139
|
+
});
|
|
20140
|
+
test3("should handle tool result messages with non-string content types", () => {
|
|
20141
|
+
const aguiMessage = {
|
|
20142
|
+
id: "tool-result-2",
|
|
20143
|
+
role: "tool",
|
|
20144
|
+
content: 42,
|
|
20145
|
+
toolCallId: "tool-call-2",
|
|
20146
|
+
toolName: "numberAction"
|
|
20147
|
+
};
|
|
20148
|
+
const result = aguiToGQL(aguiMessage);
|
|
20149
|
+
globalExpect(result).toHaveLength(1);
|
|
20150
|
+
globalExpect(result[0]).toBeInstanceOf(ResultMessage);
|
|
20151
|
+
globalExpect(result[0].result).toBe("42");
|
|
20152
|
+
globalExpect(result[0].actionExecutionId).toBe("tool-call-2");
|
|
20153
|
+
globalExpect(result[0].actionName).toBe("numberAction");
|
|
20154
|
+
});
|
|
20155
|
+
test3("should handle tool result messages with circular reference content", () => {
|
|
20156
|
+
const circularObj = { status: "success" };
|
|
20157
|
+
circularObj.self = circularObj;
|
|
20158
|
+
const aguiMessage = {
|
|
20159
|
+
id: "tool-result-3",
|
|
20160
|
+
role: "tool",
|
|
20161
|
+
content: circularObj,
|
|
20162
|
+
toolCallId: "tool-call-3",
|
|
20163
|
+
toolName: "circularAction"
|
|
20164
|
+
};
|
|
20165
|
+
const result = aguiToGQL(aguiMessage);
|
|
20166
|
+
globalExpect(result).toHaveLength(1);
|
|
20167
|
+
globalExpect(result[0]).toBeInstanceOf(ResultMessage);
|
|
20168
|
+
globalExpect(result[0].result).toBe("[object Object]");
|
|
20169
|
+
globalExpect(result[0].actionExecutionId).toBe("tool-call-3");
|
|
20170
|
+
globalExpect(result[0].actionName).toBe("circularAction");
|
|
20171
|
+
});
|
|
20172
|
+
test3("should handle tool result messages with boolean content", () => {
|
|
20173
|
+
const aguiMessage = {
|
|
20174
|
+
id: "tool-result-4",
|
|
20175
|
+
role: "tool",
|
|
20176
|
+
content: true,
|
|
20177
|
+
toolCallId: "tool-call-4",
|
|
20178
|
+
toolName: "booleanAction"
|
|
20179
|
+
};
|
|
20180
|
+
const result = aguiToGQL(aguiMessage);
|
|
20181
|
+
globalExpect(result).toHaveLength(1);
|
|
20182
|
+
globalExpect(result[0]).toBeInstanceOf(ResultMessage);
|
|
20183
|
+
globalExpect(result[0].result).toBe("true");
|
|
20184
|
+
globalExpect(result[0].actionExecutionId).toBe("tool-call-4");
|
|
20185
|
+
globalExpect(result[0].actionName).toBe("booleanAction");
|
|
20186
|
+
});
|
|
20187
|
+
});
|
|
19666
20188
|
});
|
|
19667
20189
|
/*! Bundled license information:
|
|
19668
20190
|
|