@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
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
gqlTextMessageToAGUIMessage,
|
|
7
7
|
gqlResultMessageToAGUIMessage,
|
|
8
8
|
gqlImageMessageToAGUIMessage,
|
|
9
|
+
gqlActionExecutionMessageToAGUIMessage,
|
|
9
10
|
} from "./gql-to-agui";
|
|
10
11
|
|
|
11
12
|
describe("message-conversion", () => {
|
|
@@ -841,4 +842,527 @@ describe("message-conversion", () => {
|
|
|
841
842
|
});
|
|
842
843
|
});
|
|
843
844
|
});
|
|
845
|
+
|
|
846
|
+
describe("Wild Card Actions", () => {
|
|
847
|
+
test("should handle action execution with specific action", () => {
|
|
848
|
+
const actions = {
|
|
849
|
+
testAction: {
|
|
850
|
+
name: "testAction",
|
|
851
|
+
render: vi.fn((props) => `Rendered: ${props.args.test}`),
|
|
852
|
+
},
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
856
|
+
id: "action-1",
|
|
857
|
+
name: "testAction",
|
|
858
|
+
arguments: { test: "value" },
|
|
859
|
+
parentMessageId: "parent-1",
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
863
|
+
|
|
864
|
+
expect(result).toMatchObject({
|
|
865
|
+
id: "action-1",
|
|
866
|
+
role: "assistant",
|
|
867
|
+
content: "",
|
|
868
|
+
toolCalls: [
|
|
869
|
+
{
|
|
870
|
+
id: "action-1",
|
|
871
|
+
function: {
|
|
872
|
+
name: "testAction",
|
|
873
|
+
arguments: '{"test":"value"}',
|
|
874
|
+
},
|
|
875
|
+
type: "function",
|
|
876
|
+
},
|
|
877
|
+
],
|
|
878
|
+
generativeUI: expect.any(Function),
|
|
879
|
+
name: "testAction",
|
|
880
|
+
});
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
test("should handle action execution with wild card action", () => {
|
|
884
|
+
const actions = {
|
|
885
|
+
"*": {
|
|
886
|
+
name: "*",
|
|
887
|
+
render: vi.fn((props) => `Wildcard rendered: ${props.args.test}`),
|
|
888
|
+
},
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
892
|
+
id: "action-2",
|
|
893
|
+
name: "unknownAction",
|
|
894
|
+
arguments: { test: "wildcard-value" },
|
|
895
|
+
parentMessageId: "parent-2",
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
899
|
+
|
|
900
|
+
expect(result).toMatchObject({
|
|
901
|
+
id: "action-2",
|
|
902
|
+
role: "assistant",
|
|
903
|
+
content: "",
|
|
904
|
+
toolCalls: [
|
|
905
|
+
{
|
|
906
|
+
id: "action-2",
|
|
907
|
+
function: {
|
|
908
|
+
name: "unknownAction",
|
|
909
|
+
arguments: '{"test":"wildcard-value"}',
|
|
910
|
+
},
|
|
911
|
+
type: "function",
|
|
912
|
+
},
|
|
913
|
+
],
|
|
914
|
+
generativeUI: expect.any(Function),
|
|
915
|
+
name: "unknownAction",
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
test("should prioritize specific action over wild card action", () => {
|
|
920
|
+
const actions = {
|
|
921
|
+
specificAction: {
|
|
922
|
+
name: "specificAction",
|
|
923
|
+
render: vi.fn((props) => "Specific action rendered"),
|
|
924
|
+
},
|
|
925
|
+
"*": {
|
|
926
|
+
name: "*",
|
|
927
|
+
render: vi.fn((props) => "Wildcard action rendered"),
|
|
928
|
+
},
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
932
|
+
id: "action-3",
|
|
933
|
+
name: "specificAction",
|
|
934
|
+
arguments: { test: "value" },
|
|
935
|
+
parentMessageId: "parent-3",
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
939
|
+
|
|
940
|
+
expect(result).toMatchObject({
|
|
941
|
+
id: "action-3",
|
|
942
|
+
role: "assistant",
|
|
943
|
+
content: "",
|
|
944
|
+
toolCalls: [
|
|
945
|
+
{
|
|
946
|
+
id: "action-3",
|
|
947
|
+
function: {
|
|
948
|
+
name: "specificAction",
|
|
949
|
+
arguments: '{"test":"value"}',
|
|
950
|
+
},
|
|
951
|
+
type: "function",
|
|
952
|
+
},
|
|
953
|
+
],
|
|
954
|
+
generativeUI: expect.any(Function),
|
|
955
|
+
name: "specificAction",
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
test("should handle action execution without any matching actions", () => {
|
|
960
|
+
const actions = {
|
|
961
|
+
otherAction: {
|
|
962
|
+
name: "otherAction",
|
|
963
|
+
render: vi.fn(),
|
|
964
|
+
},
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
968
|
+
id: "action-4",
|
|
969
|
+
name: "unmatchedAction",
|
|
970
|
+
arguments: { test: "value" },
|
|
971
|
+
parentMessageId: "parent-4",
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
975
|
+
|
|
976
|
+
expect(result).toMatchObject({
|
|
977
|
+
id: "action-4",
|
|
978
|
+
role: "assistant",
|
|
979
|
+
toolCalls: [
|
|
980
|
+
{
|
|
981
|
+
id: "action-4",
|
|
982
|
+
function: {
|
|
983
|
+
name: "unmatchedAction",
|
|
984
|
+
arguments: '{"test":"value"}',
|
|
985
|
+
},
|
|
986
|
+
type: "function",
|
|
987
|
+
},
|
|
988
|
+
],
|
|
989
|
+
name: "unmatchedAction",
|
|
990
|
+
});
|
|
991
|
+
expect(result).not.toHaveProperty("generativeUI");
|
|
992
|
+
});
|
|
993
|
+
|
|
994
|
+
test("should handle action execution with no actions provided", () => {
|
|
995
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
996
|
+
id: "action-5",
|
|
997
|
+
name: "anyAction",
|
|
998
|
+
arguments: { test: "value" },
|
|
999
|
+
parentMessageId: "parent-5",
|
|
1000
|
+
});
|
|
1001
|
+
|
|
1002
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
|
|
1003
|
+
|
|
1004
|
+
expect(result).toMatchObject({
|
|
1005
|
+
id: "action-5",
|
|
1006
|
+
role: "assistant",
|
|
1007
|
+
toolCalls: [
|
|
1008
|
+
{
|
|
1009
|
+
id: "action-5",
|
|
1010
|
+
function: {
|
|
1011
|
+
name: "anyAction",
|
|
1012
|
+
arguments: '{"test":"value"}',
|
|
1013
|
+
},
|
|
1014
|
+
type: "function",
|
|
1015
|
+
},
|
|
1016
|
+
],
|
|
1017
|
+
name: "anyAction",
|
|
1018
|
+
});
|
|
1019
|
+
expect(result).not.toHaveProperty("generativeUI");
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
test("should handle action execution with completed result", () => {
|
|
1023
|
+
const actions = {
|
|
1024
|
+
"*": {
|
|
1025
|
+
name: "*",
|
|
1026
|
+
render: vi.fn((props) => `Result: ${props.result}`),
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1031
|
+
id: "action-6",
|
|
1032
|
+
name: "testAction",
|
|
1033
|
+
arguments: { test: "value" },
|
|
1034
|
+
parentMessageId: "parent-6",
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
const actionResults = new Map([["action-6", "completed result"]]);
|
|
1038
|
+
|
|
1039
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions, actionResults);
|
|
1040
|
+
|
|
1041
|
+
expect(result).toMatchObject({
|
|
1042
|
+
id: "action-6",
|
|
1043
|
+
role: "assistant",
|
|
1044
|
+
content: "",
|
|
1045
|
+
toolCalls: [
|
|
1046
|
+
{
|
|
1047
|
+
id: "action-6",
|
|
1048
|
+
function: {
|
|
1049
|
+
name: "testAction",
|
|
1050
|
+
arguments: '{"test":"value"}',
|
|
1051
|
+
},
|
|
1052
|
+
type: "function",
|
|
1053
|
+
},
|
|
1054
|
+
],
|
|
1055
|
+
generativeUI: expect.any(Function),
|
|
1056
|
+
name: "testAction",
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
test("should handle action execution with executing status", () => {
|
|
1061
|
+
const actions = {
|
|
1062
|
+
"*": {
|
|
1063
|
+
name: "*",
|
|
1064
|
+
render: vi.fn((props) => `Status: ${props.status}`),
|
|
1065
|
+
},
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1069
|
+
id: "action-7",
|
|
1070
|
+
name: "testAction",
|
|
1071
|
+
arguments: { test: "value" },
|
|
1072
|
+
parentMessageId: "parent-7",
|
|
1073
|
+
status: { code: MessageStatusCode.Success },
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1077
|
+
|
|
1078
|
+
expect(result).toMatchObject({
|
|
1079
|
+
id: "action-7",
|
|
1080
|
+
role: "assistant",
|
|
1081
|
+
content: "",
|
|
1082
|
+
toolCalls: [
|
|
1083
|
+
{
|
|
1084
|
+
id: "action-7",
|
|
1085
|
+
function: {
|
|
1086
|
+
name: "testAction",
|
|
1087
|
+
arguments: '{"test":"value"}',
|
|
1088
|
+
},
|
|
1089
|
+
type: "function",
|
|
1090
|
+
},
|
|
1091
|
+
],
|
|
1092
|
+
generativeUI: expect.any(Function),
|
|
1093
|
+
name: "testAction",
|
|
1094
|
+
});
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
test("should handle action execution with pending status", () => {
|
|
1098
|
+
const actions = {
|
|
1099
|
+
"*": {
|
|
1100
|
+
name: "*",
|
|
1101
|
+
render: vi.fn((props) => `Status: ${props.status}`),
|
|
1102
|
+
},
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1106
|
+
id: "action-8",
|
|
1107
|
+
name: "testAction",
|
|
1108
|
+
arguments: { test: "value" },
|
|
1109
|
+
parentMessageId: "parent-8",
|
|
1110
|
+
status: { code: MessageStatusCode.Pending },
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1114
|
+
|
|
1115
|
+
expect(result).toMatchObject({
|
|
1116
|
+
id: "action-8",
|
|
1117
|
+
role: "assistant",
|
|
1118
|
+
content: "",
|
|
1119
|
+
toolCalls: [
|
|
1120
|
+
{
|
|
1121
|
+
id: "action-8",
|
|
1122
|
+
function: {
|
|
1123
|
+
name: "testAction",
|
|
1124
|
+
arguments: '{"test":"value"}',
|
|
1125
|
+
},
|
|
1126
|
+
type: "function",
|
|
1127
|
+
},
|
|
1128
|
+
],
|
|
1129
|
+
generativeUI: expect.any(Function),
|
|
1130
|
+
name: "testAction",
|
|
1131
|
+
});
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
test("should handle action execution with failed status", () => {
|
|
1135
|
+
const actions = {
|
|
1136
|
+
"*": {
|
|
1137
|
+
name: "*",
|
|
1138
|
+
render: vi.fn((props) => `Status: ${props.status}`),
|
|
1139
|
+
},
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1143
|
+
id: "action-9",
|
|
1144
|
+
name: "testAction",
|
|
1145
|
+
arguments: { test: "value" },
|
|
1146
|
+
parentMessageId: "parent-9",
|
|
1147
|
+
status: { code: MessageStatusCode.Failed },
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1151
|
+
|
|
1152
|
+
expect(result).toMatchObject({
|
|
1153
|
+
id: "action-9",
|
|
1154
|
+
role: "assistant",
|
|
1155
|
+
content: "",
|
|
1156
|
+
toolCalls: [
|
|
1157
|
+
{
|
|
1158
|
+
id: "action-9",
|
|
1159
|
+
function: {
|
|
1160
|
+
name: "testAction",
|
|
1161
|
+
arguments: '{"test":"value"}',
|
|
1162
|
+
},
|
|
1163
|
+
type: "function",
|
|
1164
|
+
},
|
|
1165
|
+
],
|
|
1166
|
+
generativeUI: expect.any(Function),
|
|
1167
|
+
name: "testAction",
|
|
1168
|
+
});
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
test("should handle action execution with undefined status", () => {
|
|
1172
|
+
const actions = {
|
|
1173
|
+
"*": {
|
|
1174
|
+
name: "*",
|
|
1175
|
+
render: vi.fn((props) => `Status: ${props.status}`),
|
|
1176
|
+
},
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1180
|
+
id: "action-10",
|
|
1181
|
+
name: "testAction",
|
|
1182
|
+
arguments: { test: "value" },
|
|
1183
|
+
parentMessageId: "parent-10",
|
|
1184
|
+
// No status field
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1188
|
+
|
|
1189
|
+
expect(result).toMatchObject({
|
|
1190
|
+
id: "action-10",
|
|
1191
|
+
role: "assistant",
|
|
1192
|
+
content: "",
|
|
1193
|
+
toolCalls: [
|
|
1194
|
+
{
|
|
1195
|
+
id: "action-10",
|
|
1196
|
+
function: {
|
|
1197
|
+
name: "testAction",
|
|
1198
|
+
arguments: '{"test":"value"}',
|
|
1199
|
+
},
|
|
1200
|
+
type: "function",
|
|
1201
|
+
},
|
|
1202
|
+
],
|
|
1203
|
+
generativeUI: expect.any(Function),
|
|
1204
|
+
name: "testAction",
|
|
1205
|
+
});
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
test("should handle action execution with empty arguments", () => {
|
|
1209
|
+
const actions = {
|
|
1210
|
+
"*": {
|
|
1211
|
+
name: "*",
|
|
1212
|
+
render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`),
|
|
1213
|
+
},
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1217
|
+
id: "action-11",
|
|
1218
|
+
name: "testAction",
|
|
1219
|
+
arguments: {},
|
|
1220
|
+
parentMessageId: "parent-11",
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1224
|
+
|
|
1225
|
+
expect(result).toMatchObject({
|
|
1226
|
+
id: "action-11",
|
|
1227
|
+
role: "assistant",
|
|
1228
|
+
content: "",
|
|
1229
|
+
toolCalls: [
|
|
1230
|
+
{
|
|
1231
|
+
id: "action-11",
|
|
1232
|
+
function: {
|
|
1233
|
+
name: "testAction",
|
|
1234
|
+
arguments: "{}",
|
|
1235
|
+
},
|
|
1236
|
+
type: "function",
|
|
1237
|
+
},
|
|
1238
|
+
],
|
|
1239
|
+
generativeUI: expect.any(Function),
|
|
1240
|
+
name: "testAction",
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1243
|
+
|
|
1244
|
+
test("should handle action execution with null arguments", () => {
|
|
1245
|
+
const actions = {
|
|
1246
|
+
"*": {
|
|
1247
|
+
name: "*",
|
|
1248
|
+
render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`),
|
|
1249
|
+
},
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1253
|
+
id: "action-12",
|
|
1254
|
+
name: "testAction",
|
|
1255
|
+
arguments: null as any,
|
|
1256
|
+
parentMessageId: "parent-12",
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1260
|
+
|
|
1261
|
+
expect(result).toMatchObject({
|
|
1262
|
+
id: "action-12",
|
|
1263
|
+
role: "assistant",
|
|
1264
|
+
content: "",
|
|
1265
|
+
toolCalls: [
|
|
1266
|
+
{
|
|
1267
|
+
id: "action-12",
|
|
1268
|
+
function: {
|
|
1269
|
+
name: "testAction",
|
|
1270
|
+
arguments: "null",
|
|
1271
|
+
},
|
|
1272
|
+
type: "function",
|
|
1273
|
+
},
|
|
1274
|
+
],
|
|
1275
|
+
generativeUI: expect.any(Function),
|
|
1276
|
+
name: "testAction",
|
|
1277
|
+
});
|
|
1278
|
+
});
|
|
1279
|
+
|
|
1280
|
+
test("should handle action execution with complex nested arguments", () => {
|
|
1281
|
+
const actions = {
|
|
1282
|
+
"*": {
|
|
1283
|
+
name: "*",
|
|
1284
|
+
render: vi.fn((props) => `Complex: ${JSON.stringify(props.args)}`),
|
|
1285
|
+
},
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
const complexArgs = {
|
|
1289
|
+
nested: {
|
|
1290
|
+
array: [1, 2, 3],
|
|
1291
|
+
object: { key: "value" },
|
|
1292
|
+
nullValue: null,
|
|
1293
|
+
undefinedValue: undefined,
|
|
1294
|
+
},
|
|
1295
|
+
string: "test",
|
|
1296
|
+
number: 42,
|
|
1297
|
+
boolean: true,
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1301
|
+
id: "action-13",
|
|
1302
|
+
name: "testAction",
|
|
1303
|
+
arguments: complexArgs,
|
|
1304
|
+
parentMessageId: "parent-13",
|
|
1305
|
+
});
|
|
1306
|
+
|
|
1307
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1308
|
+
|
|
1309
|
+
expect(result).toMatchObject({
|
|
1310
|
+
id: "action-13",
|
|
1311
|
+
role: "assistant",
|
|
1312
|
+
content: "",
|
|
1313
|
+
toolCalls: [
|
|
1314
|
+
{
|
|
1315
|
+
id: "action-13",
|
|
1316
|
+
function: {
|
|
1317
|
+
name: "testAction",
|
|
1318
|
+
arguments: JSON.stringify(complexArgs),
|
|
1319
|
+
},
|
|
1320
|
+
type: "function",
|
|
1321
|
+
},
|
|
1322
|
+
],
|
|
1323
|
+
generativeUI: expect.any(Function),
|
|
1324
|
+
name: "testAction",
|
|
1325
|
+
});
|
|
1326
|
+
});
|
|
1327
|
+
|
|
1328
|
+
test("should handle multiple wild card actions (should use first one)", () => {
|
|
1329
|
+
const actions = {
|
|
1330
|
+
wildcard1: {
|
|
1331
|
+
name: "*",
|
|
1332
|
+
render: vi.fn((props) => "First wildcard"),
|
|
1333
|
+
},
|
|
1334
|
+
wildcard2: {
|
|
1335
|
+
name: "*",
|
|
1336
|
+
render: vi.fn((props) => "Second wildcard"),
|
|
1337
|
+
},
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1340
|
+
const actionExecMsg = new gql.ActionExecutionMessage({
|
|
1341
|
+
id: "action-14",
|
|
1342
|
+
name: "unknownAction",
|
|
1343
|
+
arguments: { test: "value" },
|
|
1344
|
+
parentMessageId: "parent-14",
|
|
1345
|
+
});
|
|
1346
|
+
|
|
1347
|
+
const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg, actions);
|
|
1348
|
+
|
|
1349
|
+
expect(result).toMatchObject({
|
|
1350
|
+
id: "action-14",
|
|
1351
|
+
role: "assistant",
|
|
1352
|
+
content: "",
|
|
1353
|
+
toolCalls: [
|
|
1354
|
+
{
|
|
1355
|
+
id: "action-14",
|
|
1356
|
+
function: {
|
|
1357
|
+
name: "unknownAction",
|
|
1358
|
+
arguments: '{"test":"value"}',
|
|
1359
|
+
},
|
|
1360
|
+
type: "function",
|
|
1361
|
+
},
|
|
1362
|
+
],
|
|
1363
|
+
generativeUI: expect.any(Function),
|
|
1364
|
+
name: "unknownAction",
|
|
1365
|
+
});
|
|
1366
|
+
});
|
|
1367
|
+
});
|
|
844
1368
|
});
|
|
@@ -51,59 +51,68 @@ export function gqlToAGUI(
|
|
|
51
51
|
return aguiMessages;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function gqlActionExecutionMessageToAGUIMessage(
|
|
54
|
+
export function gqlActionExecutionMessageToAGUIMessage(
|
|
55
55
|
message: gql.ActionExecutionMessage,
|
|
56
56
|
actions?: Record<string, any>,
|
|
57
57
|
actionResults?: Map<string, string>,
|
|
58
58
|
): agui.Message {
|
|
59
|
-
if
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!originalRender) return undefined;
|
|
65
|
-
|
|
66
|
-
return (props?: any) => {
|
|
67
|
-
// Determine the correct status based on the same logic as RenderActionExecutionMessage
|
|
68
|
-
const actionResult = actionResults?.get(message.id);
|
|
69
|
-
let status: "inProgress" | "executing" | "complete" = "inProgress";
|
|
70
|
-
|
|
71
|
-
if (actionResult !== undefined) {
|
|
72
|
-
status = "complete";
|
|
73
|
-
} else if (message.status?.code !== MessageStatusCode.Pending) {
|
|
74
|
-
status = "executing";
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Provide the full props structure that the render function expects
|
|
78
|
-
const renderProps = {
|
|
79
|
-
status: props?.status || status,
|
|
80
|
-
args: message.arguments || {},
|
|
81
|
-
result: props?.result || actionResult || undefined,
|
|
82
|
-
respond: props?.respond || (() => {}),
|
|
83
|
-
messageId: message.id,
|
|
84
|
-
...props,
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
return originalRender(renderProps);
|
|
88
|
-
};
|
|
89
|
-
};
|
|
59
|
+
// Check if we have actions and if there's a specific action or wild card action
|
|
60
|
+
const hasSpecificAction =
|
|
61
|
+
actions && Object.values(actions).some((action: any) => action.name === message.name);
|
|
62
|
+
const hasWildcardAction =
|
|
63
|
+
actions && Object.values(actions).some((action: any) => action.name === "*");
|
|
90
64
|
|
|
65
|
+
if (!actions || (!hasSpecificAction && !hasWildcardAction)) {
|
|
91
66
|
return {
|
|
92
67
|
id: message.id,
|
|
93
68
|
role: "assistant",
|
|
94
|
-
content: "",
|
|
95
69
|
toolCalls: [actionExecutionMessageToAGUIMessage(message)],
|
|
96
|
-
generativeUI: createRenderWrapper(action.render),
|
|
97
70
|
name: message.name,
|
|
98
|
-
}
|
|
71
|
+
};
|
|
99
72
|
}
|
|
100
73
|
|
|
74
|
+
// Find the specific action first, then fall back to wild card action
|
|
75
|
+
const action =
|
|
76
|
+
Object.values(actions).find((action: any) => action.name === message.name) ||
|
|
77
|
+
Object.values(actions).find((action: any) => action.name === "*");
|
|
78
|
+
|
|
79
|
+
// Create render function wrapper that provides proper props
|
|
80
|
+
const createRenderWrapper = (originalRender: any) => {
|
|
81
|
+
if (!originalRender) return undefined;
|
|
82
|
+
|
|
83
|
+
return (props?: any) => {
|
|
84
|
+
// Determine the correct status based on the same logic as RenderActionExecutionMessage
|
|
85
|
+
const actionResult = actionResults?.get(message.id);
|
|
86
|
+
let status: "inProgress" | "executing" | "complete" = "inProgress";
|
|
87
|
+
|
|
88
|
+
if (actionResult !== undefined) {
|
|
89
|
+
status = "complete";
|
|
90
|
+
} else if (message.status?.code !== MessageStatusCode.Pending) {
|
|
91
|
+
status = "executing";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Provide the full props structure that the render function expects
|
|
95
|
+
const renderProps = {
|
|
96
|
+
status: props?.status || status,
|
|
97
|
+
args: message.arguments || {},
|
|
98
|
+
result: props?.result || actionResult || undefined,
|
|
99
|
+
respond: props?.respond || (() => {}),
|
|
100
|
+
messageId: message.id,
|
|
101
|
+
...props,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return originalRender(renderProps);
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
101
108
|
return {
|
|
102
109
|
id: message.id,
|
|
103
110
|
role: "assistant",
|
|
111
|
+
content: "",
|
|
104
112
|
toolCalls: [actionExecutionMessageToAGUIMessage(message)],
|
|
113
|
+
generativeUI: createRenderWrapper(action.render),
|
|
105
114
|
name: message.name,
|
|
106
|
-
};
|
|
115
|
+
} as agui.AIMessage;
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
function gqlAgentStateMessageToAGUIMessage(
|