@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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
gqlActionExecutionMessageToAGUIMessage,
|
|
2
3
|
gqlImageMessageToAGUIMessage,
|
|
3
4
|
gqlResultMessageToAGUIMessage,
|
|
4
5
|
gqlTextMessageToAGUIMessage,
|
|
5
6
|
gqlToAGUI
|
|
6
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-ZYA32QXZ.mjs";
|
|
7
8
|
import {
|
|
8
9
|
describe,
|
|
9
10
|
globalExpect,
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
vi
|
|
12
13
|
} from "../chunk-2R7M2FWR.mjs";
|
|
13
14
|
import "../chunk-7ECCT6PK.mjs";
|
|
14
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-5V6B3OXS.mjs";
|
|
15
16
|
import "../chunk-X2UAP3QY.mjs";
|
|
16
17
|
import "../chunk-HEODM5TW.mjs";
|
|
17
18
|
import "../chunk-4KTMZMM2.mjs";
|
|
@@ -733,5 +734,585 @@ describe("message-conversion", () => {
|
|
|
733
734
|
});
|
|
734
735
|
});
|
|
735
736
|
});
|
|
737
|
+
describe("Wild Card Actions", () => {
|
|
738
|
+
test("should handle action execution with specific action", () => {
|
|
739
|
+
const actions = {
|
|
740
|
+
testAction: {
|
|
741
|
+
name: "testAction",
|
|
742
|
+
render: vi.fn((props) => `Rendered: ${props.args.test}`)
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
746
|
+
id: "action-1",
|
|
747
|
+
name: "testAction",
|
|
748
|
+
arguments: { test: "value" },
|
|
749
|
+
parentMessageId: "parent-1"
|
|
750
|
+
});
|
|
751
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
752
|
+
globalExpect(result).toMatchObject({
|
|
753
|
+
id: "action-1",
|
|
754
|
+
role: "assistant",
|
|
755
|
+
content: "",
|
|
756
|
+
toolCalls: [
|
|
757
|
+
{
|
|
758
|
+
id: "action-1",
|
|
759
|
+
function: {
|
|
760
|
+
name: "testAction",
|
|
761
|
+
arguments: '{"test":"value"}'
|
|
762
|
+
},
|
|
763
|
+
type: "function"
|
|
764
|
+
}
|
|
765
|
+
],
|
|
766
|
+
generativeUI: globalExpect.any(Function),
|
|
767
|
+
name: "testAction"
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
test("should handle action execution with wild card action", () => {
|
|
771
|
+
const actions = {
|
|
772
|
+
"*": {
|
|
773
|
+
name: "*",
|
|
774
|
+
render: vi.fn((props) => `Wildcard rendered: ${props.args.test}`)
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
778
|
+
id: "action-2",
|
|
779
|
+
name: "unknownAction",
|
|
780
|
+
arguments: { test: "wildcard-value" },
|
|
781
|
+
parentMessageId: "parent-2"
|
|
782
|
+
});
|
|
783
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
784
|
+
globalExpect(result).toMatchObject({
|
|
785
|
+
id: "action-2",
|
|
786
|
+
role: "assistant",
|
|
787
|
+
content: "",
|
|
788
|
+
toolCalls: [
|
|
789
|
+
{
|
|
790
|
+
id: "action-2",
|
|
791
|
+
function: {
|
|
792
|
+
name: "unknownAction",
|
|
793
|
+
arguments: '{"test":"wildcard-value"}'
|
|
794
|
+
},
|
|
795
|
+
type: "function"
|
|
796
|
+
}
|
|
797
|
+
],
|
|
798
|
+
generativeUI: globalExpect.any(Function),
|
|
799
|
+
name: "unknownAction"
|
|
800
|
+
});
|
|
801
|
+
});
|
|
802
|
+
test("should prioritize specific action over wild card action", () => {
|
|
803
|
+
const actions = {
|
|
804
|
+
specificAction: {
|
|
805
|
+
name: "specificAction",
|
|
806
|
+
render: vi.fn((props) => "Specific action rendered")
|
|
807
|
+
},
|
|
808
|
+
"*": {
|
|
809
|
+
name: "*",
|
|
810
|
+
render: vi.fn((props) => "Wildcard action rendered")
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
814
|
+
id: "action-3",
|
|
815
|
+
name: "specificAction",
|
|
816
|
+
arguments: { test: "value" },
|
|
817
|
+
parentMessageId: "parent-3"
|
|
818
|
+
});
|
|
819
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
820
|
+
globalExpect(result).toMatchObject({
|
|
821
|
+
id: "action-3",
|
|
822
|
+
role: "assistant",
|
|
823
|
+
content: "",
|
|
824
|
+
toolCalls: [
|
|
825
|
+
{
|
|
826
|
+
id: "action-3",
|
|
827
|
+
function: {
|
|
828
|
+
name: "specificAction",
|
|
829
|
+
arguments: '{"test":"value"}'
|
|
830
|
+
},
|
|
831
|
+
type: "function"
|
|
832
|
+
}
|
|
833
|
+
],
|
|
834
|
+
generativeUI: globalExpect.any(Function),
|
|
835
|
+
name: "specificAction"
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
test("should handle action execution without any matching actions", () => {
|
|
839
|
+
const actions = {
|
|
840
|
+
otherAction: {
|
|
841
|
+
name: "otherAction",
|
|
842
|
+
render: vi.fn()
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
846
|
+
id: "action-4",
|
|
847
|
+
name: "unmatchedAction",
|
|
848
|
+
arguments: { test: "value" },
|
|
849
|
+
parentMessageId: "parent-4"
|
|
850
|
+
});
|
|
851
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
852
|
+
globalExpect(result).toMatchObject({
|
|
853
|
+
id: "action-4",
|
|
854
|
+
role: "assistant",
|
|
855
|
+
toolCalls: [
|
|
856
|
+
{
|
|
857
|
+
id: "action-4",
|
|
858
|
+
function: {
|
|
859
|
+
name: "unmatchedAction",
|
|
860
|
+
arguments: '{"test":"value"}'
|
|
861
|
+
},
|
|
862
|
+
type: "function"
|
|
863
|
+
}
|
|
864
|
+
],
|
|
865
|
+
name: "unmatchedAction"
|
|
866
|
+
});
|
|
867
|
+
globalExpect(result).not.toHaveProperty("generativeUI");
|
|
868
|
+
});
|
|
869
|
+
test("should handle action execution with no actions provided", () => {
|
|
870
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
871
|
+
id: "action-5",
|
|
872
|
+
name: "anyAction",
|
|
873
|
+
arguments: { test: "value" },
|
|
874
|
+
parentMessageId: "parent-5"
|
|
875
|
+
});
|
|
876
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
|
|
877
|
+
globalExpect(result).toMatchObject({
|
|
878
|
+
id: "action-5",
|
|
879
|
+
role: "assistant",
|
|
880
|
+
toolCalls: [
|
|
881
|
+
{
|
|
882
|
+
id: "action-5",
|
|
883
|
+
function: {
|
|
884
|
+
name: "anyAction",
|
|
885
|
+
arguments: '{"test":"value"}'
|
|
886
|
+
},
|
|
887
|
+
type: "function"
|
|
888
|
+
}
|
|
889
|
+
],
|
|
890
|
+
name: "anyAction"
|
|
891
|
+
});
|
|
892
|
+
globalExpect(result).not.toHaveProperty("generativeUI");
|
|
893
|
+
});
|
|
894
|
+
test("should handle action execution with completed result", () => {
|
|
895
|
+
const actions = {
|
|
896
|
+
"*": {
|
|
897
|
+
name: "*",
|
|
898
|
+
render: vi.fn((props) => `Result: ${props.result}`)
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
902
|
+
id: "action-6",
|
|
903
|
+
name: "testAction",
|
|
904
|
+
arguments: { test: "value" },
|
|
905
|
+
parentMessageId: "parent-6"
|
|
906
|
+
});
|
|
907
|
+
const actionResults = /* @__PURE__ */ new Map([["action-6", "completed result"]]);
|
|
908
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
909
|
+
globalExpect(result).toMatchObject({
|
|
910
|
+
id: "action-6",
|
|
911
|
+
role: "assistant",
|
|
912
|
+
content: "",
|
|
913
|
+
toolCalls: [
|
|
914
|
+
{
|
|
915
|
+
id: "action-6",
|
|
916
|
+
function: {
|
|
917
|
+
name: "testAction",
|
|
918
|
+
arguments: '{"test":"value"}'
|
|
919
|
+
},
|
|
920
|
+
type: "function"
|
|
921
|
+
}
|
|
922
|
+
],
|
|
923
|
+
generativeUI: globalExpect.any(Function),
|
|
924
|
+
name: "testAction"
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
test("should handle action execution with executing status", () => {
|
|
928
|
+
const actions = {
|
|
929
|
+
"*": {
|
|
930
|
+
name: "*",
|
|
931
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
935
|
+
id: "action-7",
|
|
936
|
+
name: "testAction",
|
|
937
|
+
arguments: { test: "value" },
|
|
938
|
+
parentMessageId: "parent-7",
|
|
939
|
+
status: { code: "Success" /* Success */ }
|
|
940
|
+
});
|
|
941
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
942
|
+
globalExpect(result).toMatchObject({
|
|
943
|
+
id: "action-7",
|
|
944
|
+
role: "assistant",
|
|
945
|
+
content: "",
|
|
946
|
+
toolCalls: [
|
|
947
|
+
{
|
|
948
|
+
id: "action-7",
|
|
949
|
+
function: {
|
|
950
|
+
name: "testAction",
|
|
951
|
+
arguments: '{"test":"value"}'
|
|
952
|
+
},
|
|
953
|
+
type: "function"
|
|
954
|
+
}
|
|
955
|
+
],
|
|
956
|
+
generativeUI: globalExpect.any(Function),
|
|
957
|
+
name: "testAction"
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
test("should handle action execution with pending status", () => {
|
|
961
|
+
const actions = {
|
|
962
|
+
"*": {
|
|
963
|
+
name: "*",
|
|
964
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
968
|
+
id: "action-8",
|
|
969
|
+
name: "testAction",
|
|
970
|
+
arguments: { test: "value" },
|
|
971
|
+
parentMessageId: "parent-8",
|
|
972
|
+
status: { code: "Pending" /* Pending */ }
|
|
973
|
+
});
|
|
974
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
975
|
+
globalExpect(result).toMatchObject({
|
|
976
|
+
id: "action-8",
|
|
977
|
+
role: "assistant",
|
|
978
|
+
content: "",
|
|
979
|
+
toolCalls: [
|
|
980
|
+
{
|
|
981
|
+
id: "action-8",
|
|
982
|
+
function: {
|
|
983
|
+
name: "testAction",
|
|
984
|
+
arguments: '{"test":"value"}'
|
|
985
|
+
},
|
|
986
|
+
type: "function"
|
|
987
|
+
}
|
|
988
|
+
],
|
|
989
|
+
generativeUI: globalExpect.any(Function),
|
|
990
|
+
name: "testAction"
|
|
991
|
+
});
|
|
992
|
+
});
|
|
993
|
+
test("should handle action execution with failed status", () => {
|
|
994
|
+
const actions = {
|
|
995
|
+
"*": {
|
|
996
|
+
name: "*",
|
|
997
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1001
|
+
id: "action-9",
|
|
1002
|
+
name: "testAction",
|
|
1003
|
+
arguments: { test: "value" },
|
|
1004
|
+
parentMessageId: "parent-9",
|
|
1005
|
+
status: { code: "Failed" /* Failed */ }
|
|
1006
|
+
});
|
|
1007
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1008
|
+
globalExpect(result).toMatchObject({
|
|
1009
|
+
id: "action-9",
|
|
1010
|
+
role: "assistant",
|
|
1011
|
+
content: "",
|
|
1012
|
+
toolCalls: [
|
|
1013
|
+
{
|
|
1014
|
+
id: "action-9",
|
|
1015
|
+
function: {
|
|
1016
|
+
name: "testAction",
|
|
1017
|
+
arguments: '{"test":"value"}'
|
|
1018
|
+
},
|
|
1019
|
+
type: "function"
|
|
1020
|
+
}
|
|
1021
|
+
],
|
|
1022
|
+
generativeUI: globalExpect.any(Function),
|
|
1023
|
+
name: "testAction"
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
test("should handle action execution with undefined status", () => {
|
|
1027
|
+
const actions = {
|
|
1028
|
+
"*": {
|
|
1029
|
+
name: "*",
|
|
1030
|
+
render: vi.fn((props) => `Status: ${props.status}`)
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1034
|
+
id: "action-10",
|
|
1035
|
+
name: "testAction",
|
|
1036
|
+
arguments: { test: "value" },
|
|
1037
|
+
parentMessageId: "parent-10"
|
|
1038
|
+
// No status field
|
|
1039
|
+
});
|
|
1040
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1041
|
+
globalExpect(result).toMatchObject({
|
|
1042
|
+
id: "action-10",
|
|
1043
|
+
role: "assistant",
|
|
1044
|
+
content: "",
|
|
1045
|
+
toolCalls: [
|
|
1046
|
+
{
|
|
1047
|
+
id: "action-10",
|
|
1048
|
+
function: {
|
|
1049
|
+
name: "testAction",
|
|
1050
|
+
arguments: '{"test":"value"}'
|
|
1051
|
+
},
|
|
1052
|
+
type: "function"
|
|
1053
|
+
}
|
|
1054
|
+
],
|
|
1055
|
+
generativeUI: globalExpect.any(Function),
|
|
1056
|
+
name: "testAction"
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
test("should handle action execution with empty arguments", () => {
|
|
1060
|
+
const actions = {
|
|
1061
|
+
"*": {
|
|
1062
|
+
name: "*",
|
|
1063
|
+
render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`)
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1067
|
+
id: "action-11",
|
|
1068
|
+
name: "testAction",
|
|
1069
|
+
arguments: {},
|
|
1070
|
+
parentMessageId: "parent-11"
|
|
1071
|
+
});
|
|
1072
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1073
|
+
globalExpect(result).toMatchObject({
|
|
1074
|
+
id: "action-11",
|
|
1075
|
+
role: "assistant",
|
|
1076
|
+
content: "",
|
|
1077
|
+
toolCalls: [
|
|
1078
|
+
{
|
|
1079
|
+
id: "action-11",
|
|
1080
|
+
function: {
|
|
1081
|
+
name: "testAction",
|
|
1082
|
+
arguments: "{}"
|
|
1083
|
+
},
|
|
1084
|
+
type: "function"
|
|
1085
|
+
}
|
|
1086
|
+
],
|
|
1087
|
+
generativeUI: globalExpect.any(Function),
|
|
1088
|
+
name: "testAction"
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
test("should handle action execution with null arguments", () => {
|
|
1092
|
+
const actions = {
|
|
1093
|
+
"*": {
|
|
1094
|
+
name: "*",
|
|
1095
|
+
render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`)
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1099
|
+
id: "action-12",
|
|
1100
|
+
name: "testAction",
|
|
1101
|
+
arguments: null,
|
|
1102
|
+
parentMessageId: "parent-12"
|
|
1103
|
+
});
|
|
1104
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1105
|
+
globalExpect(result).toMatchObject({
|
|
1106
|
+
id: "action-12",
|
|
1107
|
+
role: "assistant",
|
|
1108
|
+
content: "",
|
|
1109
|
+
toolCalls: [
|
|
1110
|
+
{
|
|
1111
|
+
id: "action-12",
|
|
1112
|
+
function: {
|
|
1113
|
+
name: "testAction",
|
|
1114
|
+
arguments: "null"
|
|
1115
|
+
},
|
|
1116
|
+
type: "function"
|
|
1117
|
+
}
|
|
1118
|
+
],
|
|
1119
|
+
generativeUI: globalExpect.any(Function),
|
|
1120
|
+
name: "testAction"
|
|
1121
|
+
});
|
|
1122
|
+
});
|
|
1123
|
+
test("should handle action execution with complex nested arguments", () => {
|
|
1124
|
+
const actions = {
|
|
1125
|
+
"*": {
|
|
1126
|
+
name: "*",
|
|
1127
|
+
render: vi.fn((props) => `Complex: ${JSON.stringify(props.args)}`)
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
const complexArgs = {
|
|
1131
|
+
nested: {
|
|
1132
|
+
array: [1, 2, 3],
|
|
1133
|
+
object: { key: "value" },
|
|
1134
|
+
nullValue: null,
|
|
1135
|
+
undefinedValue: void 0
|
|
1136
|
+
},
|
|
1137
|
+
string: "test",
|
|
1138
|
+
number: 42,
|
|
1139
|
+
boolean: true
|
|
1140
|
+
};
|
|
1141
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1142
|
+
id: "action-13",
|
|
1143
|
+
name: "testAction",
|
|
1144
|
+
arguments: complexArgs,
|
|
1145
|
+
parentMessageId: "parent-13"
|
|
1146
|
+
});
|
|
1147
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1148
|
+
globalExpect(result).toMatchObject({
|
|
1149
|
+
id: "action-13",
|
|
1150
|
+
role: "assistant",
|
|
1151
|
+
content: "",
|
|
1152
|
+
toolCalls: [
|
|
1153
|
+
{
|
|
1154
|
+
id: "action-13",
|
|
1155
|
+
function: {
|
|
1156
|
+
name: "testAction",
|
|
1157
|
+
arguments: JSON.stringify(complexArgs)
|
|
1158
|
+
},
|
|
1159
|
+
type: "function"
|
|
1160
|
+
}
|
|
1161
|
+
],
|
|
1162
|
+
generativeUI: globalExpect.any(Function),
|
|
1163
|
+
name: "testAction"
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
test("should handle multiple wild card actions (should use first one)", () => {
|
|
1167
|
+
const actions = {
|
|
1168
|
+
wildcard1: {
|
|
1169
|
+
name: "*",
|
|
1170
|
+
render: vi.fn((props) => "First wildcard")
|
|
1171
|
+
},
|
|
1172
|
+
wildcard2: {
|
|
1173
|
+
name: "*",
|
|
1174
|
+
render: vi.fn((props) => "Second wildcard")
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1178
|
+
id: "action-14",
|
|
1179
|
+
name: "unknownAction",
|
|
1180
|
+
arguments: { test: "value" },
|
|
1181
|
+
parentMessageId: "parent-14"
|
|
1182
|
+
});
|
|
1183
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1184
|
+
globalExpect(result).toMatchObject({
|
|
1185
|
+
id: "action-14",
|
|
1186
|
+
role: "assistant",
|
|
1187
|
+
content: "",
|
|
1188
|
+
toolCalls: [
|
|
1189
|
+
{
|
|
1190
|
+
id: "action-14",
|
|
1191
|
+
function: {
|
|
1192
|
+
name: "unknownAction",
|
|
1193
|
+
arguments: '{"test":"value"}'
|
|
1194
|
+
},
|
|
1195
|
+
type: "function"
|
|
1196
|
+
}
|
|
1197
|
+
],
|
|
1198
|
+
generativeUI: globalExpect.any(Function),
|
|
1199
|
+
name: "unknownAction"
|
|
1200
|
+
});
|
|
1201
|
+
});
|
|
1202
|
+
test("should parse string results in generativeUI props", () => {
|
|
1203
|
+
const actions = {
|
|
1204
|
+
"*": {
|
|
1205
|
+
name: "*",
|
|
1206
|
+
render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1210
|
+
id: "action-string-result",
|
|
1211
|
+
name: "stringResultAction",
|
|
1212
|
+
arguments: { test: "value" },
|
|
1213
|
+
parentMessageId: "parent-string"
|
|
1214
|
+
});
|
|
1215
|
+
const actionResults = /* @__PURE__ */ new Map();
|
|
1216
|
+
actionResults.set("action-string-result", '{"parsed": true, "value": 42}');
|
|
1217
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
1218
|
+
globalExpect(result.generativeUI).toBeDefined();
|
|
1219
|
+
const renderResult = result.generativeUI({
|
|
1220
|
+
result: '{"from": "props", "data": "test"}'
|
|
1221
|
+
});
|
|
1222
|
+
globalExpect(actions["*"].render).toHaveBeenCalledWith(
|
|
1223
|
+
globalExpect.objectContaining({
|
|
1224
|
+
result: { from: "props", data: "test" },
|
|
1225
|
+
// Should be parsed from string
|
|
1226
|
+
args: { test: "value" },
|
|
1227
|
+
status: "complete",
|
|
1228
|
+
messageId: "action-string-result"
|
|
1229
|
+
})
|
|
1230
|
+
);
|
|
1231
|
+
});
|
|
1232
|
+
test("should handle malformed JSON strings gracefully in results", () => {
|
|
1233
|
+
const actions = {
|
|
1234
|
+
"*": {
|
|
1235
|
+
name: "*",
|
|
1236
|
+
render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1240
|
+
id: "action-malformed",
|
|
1241
|
+
name: "malformedAction",
|
|
1242
|
+
arguments: { test: "value" },
|
|
1243
|
+
parentMessageId: "parent-malformed"
|
|
1244
|
+
});
|
|
1245
|
+
const actionResults = /* @__PURE__ */ new Map();
|
|
1246
|
+
actionResults.set("action-malformed", "invalid json {");
|
|
1247
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
1248
|
+
globalExpect(result.generativeUI).toBeDefined();
|
|
1249
|
+
const renderResult = result.generativeUI({
|
|
1250
|
+
result: "invalid json {"
|
|
1251
|
+
});
|
|
1252
|
+
globalExpect(actions["*"].render).toHaveBeenCalledWith(
|
|
1253
|
+
globalExpect.objectContaining({
|
|
1254
|
+
result: "invalid json {",
|
|
1255
|
+
// Should remain as string due to parse error
|
|
1256
|
+
args: { test: "value" },
|
|
1257
|
+
status: "complete",
|
|
1258
|
+
messageId: "action-malformed"
|
|
1259
|
+
})
|
|
1260
|
+
);
|
|
1261
|
+
});
|
|
1262
|
+
test("should handle non-string results without parsing", () => {
|
|
1263
|
+
const actions = {
|
|
1264
|
+
"*": {
|
|
1265
|
+
name: "*",
|
|
1266
|
+
render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1270
|
+
id: "action-object-result",
|
|
1271
|
+
name: "objectResultAction",
|
|
1272
|
+
arguments: { test: "value" },
|
|
1273
|
+
parentMessageId: "parent-object"
|
|
1274
|
+
});
|
|
1275
|
+
const actionResults = /* @__PURE__ */ new Map();
|
|
1276
|
+
actionResults.set("action-object-result", '{"already": "parsed"}');
|
|
1277
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
1278
|
+
globalExpect(result.generativeUI).toBeDefined();
|
|
1279
|
+
const renderResult = result.generativeUI({
|
|
1280
|
+
result: { from: "props", data: "object" }
|
|
1281
|
+
});
|
|
1282
|
+
globalExpect(actions["*"].render).toHaveBeenCalledWith(
|
|
1283
|
+
globalExpect.objectContaining({
|
|
1284
|
+
result: { from: "props", data: "object" },
|
|
1285
|
+
// Should remain as object
|
|
1286
|
+
args: { test: "value" },
|
|
1287
|
+
status: "complete",
|
|
1288
|
+
messageId: "action-object-result"
|
|
1289
|
+
})
|
|
1290
|
+
);
|
|
1291
|
+
});
|
|
1292
|
+
test("should handle action execution arguments correctly with simplified conversion", () => {
|
|
1293
|
+
const actionExecMsg = new ActionExecutionMessage({
|
|
1294
|
+
id: "action-simplified",
|
|
1295
|
+
name: "simplifiedAction",
|
|
1296
|
+
arguments: { complex: { nested: "value" }, array: [1, 2, 3] },
|
|
1297
|
+
parentMessageId: "parent-simplified"
|
|
1298
|
+
});
|
|
1299
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
|
|
1300
|
+
globalExpect(result).toMatchObject({
|
|
1301
|
+
id: "action-simplified",
|
|
1302
|
+
role: "assistant",
|
|
1303
|
+
toolCalls: [
|
|
1304
|
+
{
|
|
1305
|
+
id: "action-simplified",
|
|
1306
|
+
function: {
|
|
1307
|
+
name: "simplifiedAction",
|
|
1308
|
+
arguments: '{"complex":{"nested":"value"},"array":[1,2,3]}'
|
|
1309
|
+
},
|
|
1310
|
+
type: "function"
|
|
1311
|
+
}
|
|
1312
|
+
],
|
|
1313
|
+
name: "simplifiedAction"
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
});
|
|
736
1317
|
});
|
|
737
1318
|
//# sourceMappingURL=gql-to-agui.test.mjs.map
|