@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
|
@@ -18989,45 +18989,59 @@ function gqlToAGUI(messages, actions, coAgentStateRenders) {
|
|
|
18989
18989
|
return aguiMessages;
|
|
18990
18990
|
}
|
|
18991
18991
|
function gqlActionExecutionMessageToAGUIMessage(message, actions, actionResults) {
|
|
18992
|
-
|
|
18993
|
-
|
|
18994
|
-
|
|
18995
|
-
if (!originalRender)
|
|
18996
|
-
return void 0;
|
|
18997
|
-
return (props) => {
|
|
18998
|
-
var _a3;
|
|
18999
|
-
const actionResult = actionResults == null ? void 0 : actionResults.get(message.id);
|
|
19000
|
-
let status = "inProgress";
|
|
19001
|
-
if (actionResult !== void 0) {
|
|
19002
|
-
status = "complete";
|
|
19003
|
-
} else if (((_a3 = message.status) == null ? void 0 : _a3.code) !== "Pending" /* Pending */) {
|
|
19004
|
-
status = "executing";
|
|
19005
|
-
}
|
|
19006
|
-
const renderProps = {
|
|
19007
|
-
status: (props == null ? void 0 : props.status) || status,
|
|
19008
|
-
args: message.arguments || {},
|
|
19009
|
-
result: (props == null ? void 0 : props.result) || actionResult || void 0,
|
|
19010
|
-
respond: (props == null ? void 0 : props.respond) || (() => {
|
|
19011
|
-
}),
|
|
19012
|
-
messageId: message.id,
|
|
19013
|
-
...props
|
|
19014
|
-
};
|
|
19015
|
-
return originalRender(renderProps);
|
|
19016
|
-
};
|
|
19017
|
-
};
|
|
18992
|
+
const hasSpecificAction = actions && Object.values(actions).some((action2) => action2.name === message.name);
|
|
18993
|
+
const hasWildcardAction = actions && Object.values(actions).some((action2) => action2.name === "*");
|
|
18994
|
+
if (!actions || !hasSpecificAction && !hasWildcardAction) {
|
|
19018
18995
|
return {
|
|
19019
18996
|
id: message.id,
|
|
19020
18997
|
role: "assistant",
|
|
19021
|
-
content: "",
|
|
19022
18998
|
toolCalls: [actionExecutionMessageToAGUIMessage(message)],
|
|
19023
|
-
generativeUI: createRenderWrapper(action.render),
|
|
19024
18999
|
name: message.name
|
|
19025
19000
|
};
|
|
19026
19001
|
}
|
|
19002
|
+
const action = Object.values(actions).find((action2) => action2.name === message.name) || Object.values(actions).find((action2) => action2.name === "*");
|
|
19003
|
+
const createRenderWrapper = (originalRender) => {
|
|
19004
|
+
if (!originalRender)
|
|
19005
|
+
return void 0;
|
|
19006
|
+
return (props) => {
|
|
19007
|
+
var _a3;
|
|
19008
|
+
let actionResult = actionResults == null ? void 0 : actionResults.get(message.id);
|
|
19009
|
+
let status = "inProgress";
|
|
19010
|
+
if (actionResult !== void 0) {
|
|
19011
|
+
status = "complete";
|
|
19012
|
+
} else if (((_a3 = message.status) == null ? void 0 : _a3.code) !== "Pending" /* Pending */) {
|
|
19013
|
+
status = "executing";
|
|
19014
|
+
}
|
|
19015
|
+
if (typeof (props == null ? void 0 : props.result) === "string") {
|
|
19016
|
+
try {
|
|
19017
|
+
props.result = JSON.parse(props.result);
|
|
19018
|
+
} catch (e) {
|
|
19019
|
+
}
|
|
19020
|
+
}
|
|
19021
|
+
if (typeof actionResult === "string") {
|
|
19022
|
+
try {
|
|
19023
|
+
actionResult = JSON.parse(actionResult);
|
|
19024
|
+
} catch (e) {
|
|
19025
|
+
}
|
|
19026
|
+
}
|
|
19027
|
+
const renderProps = {
|
|
19028
|
+
status: (props == null ? void 0 : props.status) || status,
|
|
19029
|
+
args: message.arguments || {},
|
|
19030
|
+
result: (props == null ? void 0 : props.result) || actionResult || void 0,
|
|
19031
|
+
respond: (props == null ? void 0 : props.respond) || (() => {
|
|
19032
|
+
}),
|
|
19033
|
+
messageId: message.id,
|
|
19034
|
+
...props
|
|
19035
|
+
};
|
|
19036
|
+
return originalRender(renderProps);
|
|
19037
|
+
};
|
|
19038
|
+
};
|
|
19027
19039
|
return {
|
|
19028
19040
|
id: message.id,
|
|
19029
19041
|
role: "assistant",
|
|
19042
|
+
content: "",
|
|
19030
19043
|
toolCalls: [actionExecutionMessageToAGUIMessage(message)],
|
|
19044
|
+
generativeUI: createRenderWrapper(action.render),
|
|
19031
19045
|
name: message.name
|
|
19032
19046
|
};
|
|
19033
19047
|
}
|
|
@@ -19839,6 +19853,586 @@ describe("message-conversion", () => {
|
|
|
19839
19853
|
});
|
|
19840
19854
|
});
|
|
19841
19855
|
});
|
|
19856
|
+
describe("Wild Card Actions", () => {
|
|
19857
|
+
test3("should handle action execution with specific action", () => {
|
|
19858
|
+
const actions = {
|
|
19859
|
+
testAction: {
|
|
19860
|
+
name: "testAction",
|
|
19861
|
+
render: vi.fn((props) => `Rendered: ${props.args.test}`)
|
|
19862
|
+
}
|
|
19863
|
+
};
|
|
19864
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
19865
|
+
id: "action-1",
|
|
19866
|
+
name: "testAction",
|
|
19867
|
+
arguments: { test: "value" },
|
|
19868
|
+
parentMessageId: "parent-1"
|
|
19869
|
+
});
|
|
19870
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
19871
|
+
globalExpect(result).toMatchObject({
|
|
19872
|
+
id: "action-1",
|
|
19873
|
+
role: "assistant",
|
|
19874
|
+
content: "",
|
|
19875
|
+
toolCalls: [
|
|
19876
|
+
{
|
|
19877
|
+
id: "action-1",
|
|
19878
|
+
function: {
|
|
19879
|
+
name: "testAction",
|
|
19880
|
+
arguments: '{"test":"value"}'
|
|
19881
|
+
},
|
|
19882
|
+
type: "function"
|
|
19883
|
+
}
|
|
19884
|
+
],
|
|
19885
|
+
generativeUI: globalExpect.any(Function),
|
|
19886
|
+
name: "testAction"
|
|
19887
|
+
});
|
|
19888
|
+
});
|
|
19889
|
+
test3("should handle action execution with wild card action", () => {
|
|
19890
|
+
const actions = {
|
|
19891
|
+
"*": {
|
|
19892
|
+
name: "*",
|
|
19893
|
+
render: vi.fn((props) => `Wildcard rendered: ${props.args.test}`)
|
|
19894
|
+
}
|
|
19895
|
+
};
|
|
19896
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
19897
|
+
id: "action-2",
|
|
19898
|
+
name: "unknownAction",
|
|
19899
|
+
arguments: { test: "wildcard-value" },
|
|
19900
|
+
parentMessageId: "parent-2"
|
|
19901
|
+
});
|
|
19902
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
19903
|
+
globalExpect(result).toMatchObject({
|
|
19904
|
+
id: "action-2",
|
|
19905
|
+
role: "assistant",
|
|
19906
|
+
content: "",
|
|
19907
|
+
toolCalls: [
|
|
19908
|
+
{
|
|
19909
|
+
id: "action-2",
|
|
19910
|
+
function: {
|
|
19911
|
+
name: "unknownAction",
|
|
19912
|
+
arguments: '{"test":"wildcard-value"}'
|
|
19913
|
+
},
|
|
19914
|
+
type: "function"
|
|
19915
|
+
}
|
|
19916
|
+
],
|
|
19917
|
+
generativeUI: globalExpect.any(Function),
|
|
19918
|
+
name: "unknownAction"
|
|
19919
|
+
});
|
|
19920
|
+
});
|
|
19921
|
+
test3("should prioritize specific action over wild card action", () => {
|
|
19922
|
+
const actions = {
|
|
19923
|
+
specificAction: {
|
|
19924
|
+
name: "specificAction",
|
|
19925
|
+
render: vi.fn((props) => "Specific action rendered")
|
|
19926
|
+
},
|
|
19927
|
+
"*": {
|
|
19928
|
+
name: "*",
|
|
19929
|
+
render: vi.fn((props) => "Wildcard action rendered")
|
|
19930
|
+
}
|
|
19931
|
+
};
|
|
19932
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
19933
|
+
id: "action-3",
|
|
19934
|
+
name: "specificAction",
|
|
19935
|
+
arguments: { test: "value" },
|
|
19936
|
+
parentMessageId: "parent-3"
|
|
19937
|
+
});
|
|
19938
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
19939
|
+
globalExpect(result).toMatchObject({
|
|
19940
|
+
id: "action-3",
|
|
19941
|
+
role: "assistant",
|
|
19942
|
+
content: "",
|
|
19943
|
+
toolCalls: [
|
|
19944
|
+
{
|
|
19945
|
+
id: "action-3",
|
|
19946
|
+
function: {
|
|
19947
|
+
name: "specificAction",
|
|
19948
|
+
arguments: '{"test":"value"}'
|
|
19949
|
+
},
|
|
19950
|
+
type: "function"
|
|
19951
|
+
}
|
|
19952
|
+
],
|
|
19953
|
+
generativeUI: globalExpect.any(Function),
|
|
19954
|
+
name: "specificAction"
|
|
19955
|
+
});
|
|
19956
|
+
});
|
|
19957
|
+
test3("should handle action execution without any matching actions", () => {
|
|
19958
|
+
const actions = {
|
|
19959
|
+
otherAction: {
|
|
19960
|
+
name: "otherAction",
|
|
19961
|
+
render: vi.fn()
|
|
19962
|
+
}
|
|
19963
|
+
};
|
|
19964
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
19965
|
+
id: "action-4",
|
|
19966
|
+
name: "unmatchedAction",
|
|
19967
|
+
arguments: { test: "value" },
|
|
19968
|
+
parentMessageId: "parent-4"
|
|
19969
|
+
});
|
|
19970
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
19971
|
+
globalExpect(result).toMatchObject({
|
|
19972
|
+
id: "action-4",
|
|
19973
|
+
role: "assistant",
|
|
19974
|
+
toolCalls: [
|
|
19975
|
+
{
|
|
19976
|
+
id: "action-4",
|
|
19977
|
+
function: {
|
|
19978
|
+
name: "unmatchedAction",
|
|
19979
|
+
arguments: '{"test":"value"}'
|
|
19980
|
+
},
|
|
19981
|
+
type: "function"
|
|
19982
|
+
}
|
|
19983
|
+
],
|
|
19984
|
+
name: "unmatchedAction"
|
|
19985
|
+
});
|
|
19986
|
+
globalExpect(result).not.toHaveProperty("generativeUI");
|
|
19987
|
+
});
|
|
19988
|
+
test3("should handle action execution with no actions provided", () => {
|
|
19989
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
19990
|
+
id: "action-5",
|
|
19991
|
+
name: "anyAction",
|
|
19992
|
+
arguments: { test: "value" },
|
|
19993
|
+
parentMessageId: "parent-5"
|
|
19994
|
+
});
|
|
19995
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
|
|
19996
|
+
globalExpect(result).toMatchObject({
|
|
19997
|
+
id: "action-5",
|
|
19998
|
+
role: "assistant",
|
|
19999
|
+
toolCalls: [
|
|
20000
|
+
{
|
|
20001
|
+
id: "action-5",
|
|
20002
|
+
function: {
|
|
20003
|
+
name: "anyAction",
|
|
20004
|
+
arguments: '{"test":"value"}'
|
|
20005
|
+
},
|
|
20006
|
+
type: "function"
|
|
20007
|
+
}
|
|
20008
|
+
],
|
|
20009
|
+
name: "anyAction"
|
|
20010
|
+
});
|
|
20011
|
+
globalExpect(result).not.toHaveProperty("generativeUI");
|
|
20012
|
+
});
|
|
20013
|
+
test3("should handle action execution with completed result", () => {
|
|
20014
|
+
const actions = {
|
|
20015
|
+
"*": {
|
|
20016
|
+
name: "*",
|
|
20017
|
+
render: vi.fn((props) => `Result: ${props.result}`)
|
|
20018
|
+
}
|
|
20019
|
+
};
|
|
20020
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20021
|
+
id: "action-6",
|
|
20022
|
+
name: "testAction",
|
|
20023
|
+
arguments: { test: "value" },
|
|
20024
|
+
parentMessageId: "parent-6"
|
|
20025
|
+
});
|
|
20026
|
+
const actionResults = /* @__PURE__ */ new Map([["action-6", "completed result"]]);
|
|
20027
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
20028
|
+
globalExpect(result).toMatchObject({
|
|
20029
|
+
id: "action-6",
|
|
20030
|
+
role: "assistant",
|
|
20031
|
+
content: "",
|
|
20032
|
+
toolCalls: [
|
|
20033
|
+
{
|
|
20034
|
+
id: "action-6",
|
|
20035
|
+
function: {
|
|
20036
|
+
name: "testAction",
|
|
20037
|
+
arguments: '{"test":"value"}'
|
|
20038
|
+
},
|
|
20039
|
+
type: "function"
|
|
20040
|
+
}
|
|
20041
|
+
],
|
|
20042
|
+
generativeUI: globalExpect.any(Function),
|
|
20043
|
+
name: "testAction"
|
|
20044
|
+
});
|
|
20045
|
+
});
|
|
20046
|
+
test3("should handle action execution with executing status", () => {
|
|
20047
|
+
const actions = {
|
|
20048
|
+
"*": {
|
|
20049
|
+
name: "*",
|
|
20050
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
20051
|
+
}
|
|
20052
|
+
};
|
|
20053
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20054
|
+
id: "action-7",
|
|
20055
|
+
name: "testAction",
|
|
20056
|
+
arguments: { test: "value" },
|
|
20057
|
+
parentMessageId: "parent-7",
|
|
20058
|
+
status: { code: "Success" /* Success */ }
|
|
20059
|
+
});
|
|
20060
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20061
|
+
globalExpect(result).toMatchObject({
|
|
20062
|
+
id: "action-7",
|
|
20063
|
+
role: "assistant",
|
|
20064
|
+
content: "",
|
|
20065
|
+
toolCalls: [
|
|
20066
|
+
{
|
|
20067
|
+
id: "action-7",
|
|
20068
|
+
function: {
|
|
20069
|
+
name: "testAction",
|
|
20070
|
+
arguments: '{"test":"value"}'
|
|
20071
|
+
},
|
|
20072
|
+
type: "function"
|
|
20073
|
+
}
|
|
20074
|
+
],
|
|
20075
|
+
generativeUI: globalExpect.any(Function),
|
|
20076
|
+
name: "testAction"
|
|
20077
|
+
});
|
|
20078
|
+
});
|
|
20079
|
+
test3("should handle action execution with pending status", () => {
|
|
20080
|
+
const actions = {
|
|
20081
|
+
"*": {
|
|
20082
|
+
name: "*",
|
|
20083
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
20084
|
+
}
|
|
20085
|
+
};
|
|
20086
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20087
|
+
id: "action-8",
|
|
20088
|
+
name: "testAction",
|
|
20089
|
+
arguments: { test: "value" },
|
|
20090
|
+
parentMessageId: "parent-8",
|
|
20091
|
+
status: { code: "Pending" /* Pending */ }
|
|
20092
|
+
});
|
|
20093
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20094
|
+
globalExpect(result).toMatchObject({
|
|
20095
|
+
id: "action-8",
|
|
20096
|
+
role: "assistant",
|
|
20097
|
+
content: "",
|
|
20098
|
+
toolCalls: [
|
|
20099
|
+
{
|
|
20100
|
+
id: "action-8",
|
|
20101
|
+
function: {
|
|
20102
|
+
name: "testAction",
|
|
20103
|
+
arguments: '{"test":"value"}'
|
|
20104
|
+
},
|
|
20105
|
+
type: "function"
|
|
20106
|
+
}
|
|
20107
|
+
],
|
|
20108
|
+
generativeUI: globalExpect.any(Function),
|
|
20109
|
+
name: "testAction"
|
|
20110
|
+
});
|
|
20111
|
+
});
|
|
20112
|
+
test3("should handle action execution with failed status", () => {
|
|
20113
|
+
const actions = {
|
|
20114
|
+
"*": {
|
|
20115
|
+
name: "*",
|
|
20116
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
20117
|
+
}
|
|
20118
|
+
};
|
|
20119
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20120
|
+
id: "action-9",
|
|
20121
|
+
name: "testAction",
|
|
20122
|
+
arguments: { test: "value" },
|
|
20123
|
+
parentMessageId: "parent-9",
|
|
20124
|
+
status: { code: "Failed" /* Failed */ }
|
|
20125
|
+
});
|
|
20126
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20127
|
+
globalExpect(result).toMatchObject({
|
|
20128
|
+
id: "action-9",
|
|
20129
|
+
role: "assistant",
|
|
20130
|
+
content: "",
|
|
20131
|
+
toolCalls: [
|
|
20132
|
+
{
|
|
20133
|
+
id: "action-9",
|
|
20134
|
+
function: {
|
|
20135
|
+
name: "testAction",
|
|
20136
|
+
arguments: '{"test":"value"}'
|
|
20137
|
+
},
|
|
20138
|
+
type: "function"
|
|
20139
|
+
}
|
|
20140
|
+
],
|
|
20141
|
+
generativeUI: globalExpect.any(Function),
|
|
20142
|
+
name: "testAction"
|
|
20143
|
+
});
|
|
20144
|
+
});
|
|
20145
|
+
test3("should handle action execution with undefined status", () => {
|
|
20146
|
+
const actions = {
|
|
20147
|
+
"*": {
|
|
20148
|
+
name: "*",
|
|
20149
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
20150
|
+
}
|
|
20151
|
+
};
|
|
20152
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20153
|
+
id: "action-10",
|
|
20154
|
+
name: "testAction",
|
|
20155
|
+
arguments: { test: "value" },
|
|
20156
|
+
parentMessageId: "parent-10"
|
|
20157
|
+
// No status field
|
|
20158
|
+
});
|
|
20159
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20160
|
+
globalExpect(result).toMatchObject({
|
|
20161
|
+
id: "action-10",
|
|
20162
|
+
role: "assistant",
|
|
20163
|
+
content: "",
|
|
20164
|
+
toolCalls: [
|
|
20165
|
+
{
|
|
20166
|
+
id: "action-10",
|
|
20167
|
+
function: {
|
|
20168
|
+
name: "testAction",
|
|
20169
|
+
arguments: '{"test":"value"}'
|
|
20170
|
+
},
|
|
20171
|
+
type: "function"
|
|
20172
|
+
}
|
|
20173
|
+
],
|
|
20174
|
+
generativeUI: globalExpect.any(Function),
|
|
20175
|
+
name: "testAction"
|
|
20176
|
+
});
|
|
20177
|
+
});
|
|
20178
|
+
test3("should handle action execution with empty arguments", () => {
|
|
20179
|
+
const actions = {
|
|
20180
|
+
"*": {
|
|
20181
|
+
name: "*",
|
|
20182
|
+
render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`)
|
|
20183
|
+
}
|
|
20184
|
+
};
|
|
20185
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20186
|
+
id: "action-11",
|
|
20187
|
+
name: "testAction",
|
|
20188
|
+
arguments: {},
|
|
20189
|
+
parentMessageId: "parent-11"
|
|
20190
|
+
});
|
|
20191
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20192
|
+
globalExpect(result).toMatchObject({
|
|
20193
|
+
id: "action-11",
|
|
20194
|
+
role: "assistant",
|
|
20195
|
+
content: "",
|
|
20196
|
+
toolCalls: [
|
|
20197
|
+
{
|
|
20198
|
+
id: "action-11",
|
|
20199
|
+
function: {
|
|
20200
|
+
name: "testAction",
|
|
20201
|
+
arguments: "{}"
|
|
20202
|
+
},
|
|
20203
|
+
type: "function"
|
|
20204
|
+
}
|
|
20205
|
+
],
|
|
20206
|
+
generativeUI: globalExpect.any(Function),
|
|
20207
|
+
name: "testAction"
|
|
20208
|
+
});
|
|
20209
|
+
});
|
|
20210
|
+
test3("should handle action execution with null arguments", () => {
|
|
20211
|
+
const actions = {
|
|
20212
|
+
"*": {
|
|
20213
|
+
name: "*",
|
|
20214
|
+
render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`)
|
|
20215
|
+
}
|
|
20216
|
+
};
|
|
20217
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20218
|
+
id: "action-12",
|
|
20219
|
+
name: "testAction",
|
|
20220
|
+
arguments: null,
|
|
20221
|
+
parentMessageId: "parent-12"
|
|
20222
|
+
});
|
|
20223
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20224
|
+
globalExpect(result).toMatchObject({
|
|
20225
|
+
id: "action-12",
|
|
20226
|
+
role: "assistant",
|
|
20227
|
+
content: "",
|
|
20228
|
+
toolCalls: [
|
|
20229
|
+
{
|
|
20230
|
+
id: "action-12",
|
|
20231
|
+
function: {
|
|
20232
|
+
name: "testAction",
|
|
20233
|
+
arguments: "null"
|
|
20234
|
+
},
|
|
20235
|
+
type: "function"
|
|
20236
|
+
}
|
|
20237
|
+
],
|
|
20238
|
+
generativeUI: globalExpect.any(Function),
|
|
20239
|
+
name: "testAction"
|
|
20240
|
+
});
|
|
20241
|
+
});
|
|
20242
|
+
test3("should handle action execution with complex nested arguments", () => {
|
|
20243
|
+
const actions = {
|
|
20244
|
+
"*": {
|
|
20245
|
+
name: "*",
|
|
20246
|
+
render: vi.fn((props) => `Complex: ${JSON.stringify(props.args)}`)
|
|
20247
|
+
}
|
|
20248
|
+
};
|
|
20249
|
+
const complexArgs = {
|
|
20250
|
+
nested: {
|
|
20251
|
+
array: [1, 2, 3],
|
|
20252
|
+
object: { key: "value" },
|
|
20253
|
+
nullValue: null,
|
|
20254
|
+
undefinedValue: void 0
|
|
20255
|
+
},
|
|
20256
|
+
string: "test",
|
|
20257
|
+
number: 42,
|
|
20258
|
+
boolean: true
|
|
20259
|
+
};
|
|
20260
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20261
|
+
id: "action-13",
|
|
20262
|
+
name: "testAction",
|
|
20263
|
+
arguments: complexArgs,
|
|
20264
|
+
parentMessageId: "parent-13"
|
|
20265
|
+
});
|
|
20266
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20267
|
+
globalExpect(result).toMatchObject({
|
|
20268
|
+
id: "action-13",
|
|
20269
|
+
role: "assistant",
|
|
20270
|
+
content: "",
|
|
20271
|
+
toolCalls: [
|
|
20272
|
+
{
|
|
20273
|
+
id: "action-13",
|
|
20274
|
+
function: {
|
|
20275
|
+
name: "testAction",
|
|
20276
|
+
arguments: JSON.stringify(complexArgs)
|
|
20277
|
+
},
|
|
20278
|
+
type: "function"
|
|
20279
|
+
}
|
|
20280
|
+
],
|
|
20281
|
+
generativeUI: globalExpect.any(Function),
|
|
20282
|
+
name: "testAction"
|
|
20283
|
+
});
|
|
20284
|
+
});
|
|
20285
|
+
test3("should handle multiple wild card actions (should use first one)", () => {
|
|
20286
|
+
const actions = {
|
|
20287
|
+
wildcard1: {
|
|
20288
|
+
name: "*",
|
|
20289
|
+
render: vi.fn((props) => "First wildcard")
|
|
20290
|
+
},
|
|
20291
|
+
wildcard2: {
|
|
20292
|
+
name: "*",
|
|
20293
|
+
render: vi.fn((props) => "Second wildcard")
|
|
20294
|
+
}
|
|
20295
|
+
};
|
|
20296
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20297
|
+
id: "action-14",
|
|
20298
|
+
name: "unknownAction",
|
|
20299
|
+
arguments: { test: "value" },
|
|
20300
|
+
parentMessageId: "parent-14"
|
|
20301
|
+
});
|
|
20302
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
20303
|
+
globalExpect(result).toMatchObject({
|
|
20304
|
+
id: "action-14",
|
|
20305
|
+
role: "assistant",
|
|
20306
|
+
content: "",
|
|
20307
|
+
toolCalls: [
|
|
20308
|
+
{
|
|
20309
|
+
id: "action-14",
|
|
20310
|
+
function: {
|
|
20311
|
+
name: "unknownAction",
|
|
20312
|
+
arguments: '{"test":"value"}'
|
|
20313
|
+
},
|
|
20314
|
+
type: "function"
|
|
20315
|
+
}
|
|
20316
|
+
],
|
|
20317
|
+
generativeUI: globalExpect.any(Function),
|
|
20318
|
+
name: "unknownAction"
|
|
20319
|
+
});
|
|
20320
|
+
});
|
|
20321
|
+
test3("should parse string results in generativeUI props", () => {
|
|
20322
|
+
const actions = {
|
|
20323
|
+
"*": {
|
|
20324
|
+
name: "*",
|
|
20325
|
+
render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
|
|
20326
|
+
}
|
|
20327
|
+
};
|
|
20328
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20329
|
+
id: "action-string-result",
|
|
20330
|
+
name: "stringResultAction",
|
|
20331
|
+
arguments: { test: "value" },
|
|
20332
|
+
parentMessageId: "parent-string"
|
|
20333
|
+
});
|
|
20334
|
+
const actionResults = /* @__PURE__ */ new Map();
|
|
20335
|
+
actionResults.set("action-string-result", '{"parsed": true, "value": 42}');
|
|
20336
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
20337
|
+
globalExpect(result.generativeUI).toBeDefined();
|
|
20338
|
+
const renderResult = result.generativeUI({
|
|
20339
|
+
result: '{"from": "props", "data": "test"}'
|
|
20340
|
+
});
|
|
20341
|
+
globalExpect(actions["*"].render).toHaveBeenCalledWith(
|
|
20342
|
+
globalExpect.objectContaining({
|
|
20343
|
+
result: { from: "props", data: "test" },
|
|
20344
|
+
// Should be parsed from string
|
|
20345
|
+
args: { test: "value" },
|
|
20346
|
+
status: "complete",
|
|
20347
|
+
messageId: "action-string-result"
|
|
20348
|
+
})
|
|
20349
|
+
);
|
|
20350
|
+
});
|
|
20351
|
+
test3("should handle malformed JSON strings gracefully in results", () => {
|
|
20352
|
+
const actions = {
|
|
20353
|
+
"*": {
|
|
20354
|
+
name: "*",
|
|
20355
|
+
render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
|
|
20356
|
+
}
|
|
20357
|
+
};
|
|
20358
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20359
|
+
id: "action-malformed",
|
|
20360
|
+
name: "malformedAction",
|
|
20361
|
+
arguments: { test: "value" },
|
|
20362
|
+
parentMessageId: "parent-malformed"
|
|
20363
|
+
});
|
|
20364
|
+
const actionResults = /* @__PURE__ */ new Map();
|
|
20365
|
+
actionResults.set("action-malformed", "invalid json {");
|
|
20366
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
20367
|
+
globalExpect(result.generativeUI).toBeDefined();
|
|
20368
|
+
const renderResult = result.generativeUI({
|
|
20369
|
+
result: "invalid json {"
|
|
20370
|
+
});
|
|
20371
|
+
globalExpect(actions["*"].render).toHaveBeenCalledWith(
|
|
20372
|
+
globalExpect.objectContaining({
|
|
20373
|
+
result: "invalid json {",
|
|
20374
|
+
// Should remain as string due to parse error
|
|
20375
|
+
args: { test: "value" },
|
|
20376
|
+
status: "complete",
|
|
20377
|
+
messageId: "action-malformed"
|
|
20378
|
+
})
|
|
20379
|
+
);
|
|
20380
|
+
});
|
|
20381
|
+
test3("should handle non-string results without parsing", () => {
|
|
20382
|
+
const actions = {
|
|
20383
|
+
"*": {
|
|
20384
|
+
name: "*",
|
|
20385
|
+
render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
|
|
20386
|
+
}
|
|
20387
|
+
};
|
|
20388
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20389
|
+
id: "action-object-result",
|
|
20390
|
+
name: "objectResultAction",
|
|
20391
|
+
arguments: { test: "value" },
|
|
20392
|
+
parentMessageId: "parent-object"
|
|
20393
|
+
});
|
|
20394
|
+
const actionResults = /* @__PURE__ */ new Map();
|
|
20395
|
+
actionResults.set("action-object-result", '{"already": "parsed"}');
|
|
20396
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
20397
|
+
globalExpect(result.generativeUI).toBeDefined();
|
|
20398
|
+
const renderResult = result.generativeUI({
|
|
20399
|
+
result: { from: "props", data: "object" }
|
|
20400
|
+
});
|
|
20401
|
+
globalExpect(actions["*"].render).toHaveBeenCalledWith(
|
|
20402
|
+
globalExpect.objectContaining({
|
|
20403
|
+
result: { from: "props", data: "object" },
|
|
20404
|
+
// Should remain as object
|
|
20405
|
+
args: { test: "value" },
|
|
20406
|
+
status: "complete",
|
|
20407
|
+
messageId: "action-object-result"
|
|
20408
|
+
})
|
|
20409
|
+
);
|
|
20410
|
+
});
|
|
20411
|
+
test3("should handle action execution arguments correctly with simplified conversion", () => {
|
|
20412
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
20413
|
+
id: "action-simplified",
|
|
20414
|
+
name: "simplifiedAction",
|
|
20415
|
+
arguments: { complex: { nested: "value" }, array: [1, 2, 3] },
|
|
20416
|
+
parentMessageId: "parent-simplified"
|
|
20417
|
+
});
|
|
20418
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
|
|
20419
|
+
globalExpect(result).toMatchObject({
|
|
20420
|
+
id: "action-simplified",
|
|
20421
|
+
role: "assistant",
|
|
20422
|
+
toolCalls: [
|
|
20423
|
+
{
|
|
20424
|
+
id: "action-simplified",
|
|
20425
|
+
function: {
|
|
20426
|
+
name: "simplifiedAction",
|
|
20427
|
+
arguments: '{"complex":{"nested":"value"},"array":[1,2,3]}'
|
|
20428
|
+
},
|
|
20429
|
+
type: "function"
|
|
20430
|
+
}
|
|
20431
|
+
],
|
|
20432
|
+
name: "simplifiedAction"
|
|
20433
|
+
});
|
|
20434
|
+
});
|
|
20435
|
+
});
|
|
19842
20436
|
});
|
|
19843
20437
|
/*! Bundled license information:
|
|
19844
20438
|
|