@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.
Files changed (48) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-PAQ6AHHC.mjs → chunk-5V6B3OXS.mjs} +2 -2
  3. package/dist/{chunk-PAQ6AHHC.mjs.map → chunk-5V6B3OXS.mjs.map} +1 -1
  4. package/dist/{chunk-YNQMTL2P.mjs → chunk-SCACOKQX.mjs} +38 -8
  5. package/dist/chunk-SCACOKQX.mjs.map +1 -0
  6. package/dist/{chunk-MTD2RJDJ.mjs → chunk-ZYA32QXZ.mjs} +44 -29
  7. package/dist/chunk-ZYA32QXZ.mjs.map +1 -0
  8. package/dist/client/CopilotRuntimeClient.js +1 -1
  9. package/dist/client/CopilotRuntimeClient.js.map +1 -1
  10. package/dist/client/CopilotRuntimeClient.mjs +1 -1
  11. package/dist/client/index.js +1 -1
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/client/index.mjs +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +82 -36
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +5 -3
  18. package/dist/message-conversion/agui-to-gql.js +37 -7
  19. package/dist/message-conversion/agui-to-gql.js.map +1 -1
  20. package/dist/message-conversion/agui-to-gql.mjs +2 -2
  21. package/dist/message-conversion/agui-to-gql.test.js +529 -7
  22. package/dist/message-conversion/agui-to-gql.test.js.map +1 -1
  23. package/dist/message-conversion/agui-to-gql.test.mjs +494 -2
  24. package/dist/message-conversion/agui-to-gql.test.mjs.map +1 -1
  25. package/dist/message-conversion/gql-to-agui.d.ts +3 -2
  26. package/dist/message-conversion/gql-to-agui.js +44 -28
  27. package/dist/message-conversion/gql-to-agui.js.map +1 -1
  28. package/dist/message-conversion/gql-to-agui.mjs +4 -2
  29. package/dist/message-conversion/gql-to-agui.test.js +622 -28
  30. package/dist/message-conversion/gql-to-agui.test.js.map +1 -1
  31. package/dist/message-conversion/gql-to-agui.test.mjs +583 -2
  32. package/dist/message-conversion/gql-to-agui.test.mjs.map +1 -1
  33. package/dist/message-conversion/index.d.ts +1 -1
  34. package/dist/message-conversion/index.js +81 -35
  35. package/dist/message-conversion/index.js.map +1 -1
  36. package/dist/message-conversion/index.mjs +5 -3
  37. package/dist/message-conversion/roundtrip-conversion.test.js +250 -35
  38. package/dist/message-conversion/roundtrip-conversion.test.js.map +1 -1
  39. package/dist/message-conversion/roundtrip-conversion.test.mjs +174 -3
  40. package/dist/message-conversion/roundtrip-conversion.test.mjs.map +1 -1
  41. package/package.json +3 -3
  42. package/src/message-conversion/agui-to-gql.test.ts +566 -0
  43. package/src/message-conversion/agui-to-gql.ts +56 -9
  44. package/src/message-conversion/gql-to-agui.test.ts +663 -0
  45. package/src/message-conversion/gql-to-agui.ts +62 -35
  46. package/src/message-conversion/roundtrip-conversion.test.ts +228 -0
  47. package/dist/chunk-MTD2RJDJ.mjs.map +0 -1
  48. package/dist/chunk-YNQMTL2P.mjs.map +0 -1
@@ -637,4 +637,570 @@ describe("agui-to-gql", () => {
637
637
  expect(result.role).toBe(gql.Role.User);
638
638
  });
639
639
  });
640
+
641
+ describe("Wild Card Actions", () => {
642
+ test("should preserve render function for specific action", () => {
643
+ const mockRender = () => "Specific Action Render";
644
+ const aguiMessage: agui.Message = {
645
+ id: "assistant-1",
646
+ role: "assistant",
647
+ content: "I'll execute a function",
648
+ toolCalls: [
649
+ {
650
+ id: "tool-call-1",
651
+ type: "function",
652
+ function: {
653
+ name: "specificAction",
654
+ arguments: JSON.stringify({ param: "value" }),
655
+ },
656
+ },
657
+ ],
658
+ generativeUI: mockRender,
659
+ };
660
+
661
+ const actions: Record<string, any> = {
662
+ specificAction: { name: "specificAction" },
663
+ };
664
+
665
+ const result = aguiToGQL(aguiMessage, actions);
666
+
667
+ expect(result).toHaveLength(2);
668
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
669
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
670
+ expect(actions.specificAction.render).toBe(mockRender);
671
+ });
672
+
673
+ test("should preserve render function for wild card action", () => {
674
+ const mockRender = () => "Wild Card Action Render";
675
+ const aguiMessage: agui.Message = {
676
+ id: "assistant-2",
677
+ role: "assistant",
678
+ content: "I'll execute an unknown function",
679
+ toolCalls: [
680
+ {
681
+ id: "tool-call-2",
682
+ type: "function",
683
+ function: {
684
+ name: "unknownAction",
685
+ arguments: JSON.stringify({ param: "value" }),
686
+ },
687
+ },
688
+ ],
689
+ generativeUI: mockRender,
690
+ };
691
+
692
+ const actions: Record<string, any> = {
693
+ "*": { name: "*" },
694
+ };
695
+
696
+ const result = aguiToGQL(aguiMessage, actions);
697
+
698
+ expect(result).toHaveLength(2);
699
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
700
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
701
+ expect(actions["*"].render).toBe(mockRender);
702
+ });
703
+
704
+ test("should prioritize specific action over wild card action", () => {
705
+ const mockRender = () => "Prioritized Render";
706
+ const aguiMessage: agui.Message = {
707
+ id: "assistant-3",
708
+ role: "assistant",
709
+ content: "I'll execute a function",
710
+ toolCalls: [
711
+ {
712
+ id: "tool-call-3",
713
+ type: "function",
714
+ function: {
715
+ name: "specificAction",
716
+ arguments: JSON.stringify({ param: "value" }),
717
+ },
718
+ },
719
+ ],
720
+ generativeUI: mockRender,
721
+ };
722
+
723
+ const actions: Record<string, any> = {
724
+ specificAction: { name: "specificAction" },
725
+ "*": { name: "*" },
726
+ };
727
+
728
+ const result = aguiToGQL(aguiMessage, actions);
729
+
730
+ expect(result).toHaveLength(2);
731
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
732
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
733
+ expect(actions.specificAction.render).toBe(mockRender);
734
+ expect(actions["*"].render).toBeUndefined();
735
+ });
736
+
737
+ test("should not preserve render function when no matching action", () => {
738
+ const mockRender = () => "Unmatched Render";
739
+ const aguiMessage: agui.Message = {
740
+ id: "assistant-4",
741
+ role: "assistant",
742
+ content: "I'll execute an unmatched function",
743
+ toolCalls: [
744
+ {
745
+ id: "tool-call-4",
746
+ type: "function",
747
+ function: {
748
+ name: "unmatchedAction",
749
+ arguments: JSON.stringify({ param: "value" }),
750
+ },
751
+ },
752
+ ],
753
+ generativeUI: mockRender,
754
+ };
755
+
756
+ const actions: Record<string, any> = {
757
+ otherAction: { name: "otherAction" },
758
+ };
759
+
760
+ const result = aguiToGQL(aguiMessage, actions);
761
+
762
+ expect(result).toHaveLength(2);
763
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
764
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
765
+ expect(actions.otherAction.render).toBeUndefined();
766
+ });
767
+
768
+ test("should handle multiple tool calls with wild card action", () => {
769
+ const mockRender = () => "Wild Card Render";
770
+ const aguiMessage: agui.Message = {
771
+ id: "assistant-5",
772
+ role: "assistant",
773
+ content: "I'll execute multiple functions",
774
+ toolCalls: [
775
+ {
776
+ id: "tool-call-5",
777
+ type: "function",
778
+ function: {
779
+ name: "firstFunction",
780
+ arguments: JSON.stringify({ param: "value1" }),
781
+ },
782
+ },
783
+ {
784
+ id: "tool-call-6",
785
+ type: "function",
786
+ function: {
787
+ name: "secondFunction",
788
+ arguments: JSON.stringify({ param: "value2" }),
789
+ },
790
+ },
791
+ ],
792
+ generativeUI: mockRender,
793
+ };
794
+
795
+ const actions: Record<string, any> = {
796
+ "*": { name: "*" },
797
+ };
798
+
799
+ const result = aguiToGQL(aguiMessage, actions);
800
+
801
+ expect(result).toHaveLength(3);
802
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
803
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
804
+ expect(result[2]).toBeInstanceOf(gql.ActionExecutionMessage);
805
+ expect(actions["*"].render).toBe(mockRender);
806
+ });
807
+
808
+ test("should handle mixed specific and wild card actions", () => {
809
+ const mockRender = () => "Mixed Render";
810
+ const aguiMessage: agui.Message = {
811
+ id: "assistant-6",
812
+ role: "assistant",
813
+ content: "I'll execute mixed functions",
814
+ toolCalls: [
815
+ {
816
+ id: "tool-call-7",
817
+ type: "function",
818
+ function: {
819
+ name: "specificAction",
820
+ arguments: JSON.stringify({ param: "value1" }),
821
+ },
822
+ },
823
+ {
824
+ id: "tool-call-8",
825
+ type: "function",
826
+ function: {
827
+ name: "unknownAction",
828
+ arguments: JSON.stringify({ param: "value2" }),
829
+ },
830
+ },
831
+ ],
832
+ generativeUI: mockRender,
833
+ };
834
+
835
+ const actions: Record<string, any> = {
836
+ specificAction: { name: "specificAction" },
837
+ "*": { name: "*" },
838
+ };
839
+
840
+ const result = aguiToGQL(aguiMessage, actions);
841
+
842
+ expect(result).toHaveLength(3);
843
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
844
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
845
+ expect(result[2]).toBeInstanceOf(gql.ActionExecutionMessage);
846
+ expect(actions.specificAction.render).toBe(mockRender);
847
+ // The wild card action should get the render function for the second tool call
848
+ expect(actions["*"].render).toBe(mockRender);
849
+ });
850
+
851
+ test("should handle no actions provided", () => {
852
+ const mockRender = () => "No Actions Render";
853
+ const aguiMessage: agui.Message = {
854
+ id: "assistant-7",
855
+ role: "assistant",
856
+ content: "I'll execute a function",
857
+ toolCalls: [
858
+ {
859
+ id: "tool-call-9",
860
+ type: "function",
861
+ function: {
862
+ name: "anyAction",
863
+ arguments: JSON.stringify({ param: "value" }),
864
+ },
865
+ },
866
+ ],
867
+ generativeUI: mockRender,
868
+ };
869
+
870
+ const result = aguiToGQL(aguiMessage);
871
+
872
+ expect(result).toHaveLength(2);
873
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
874
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
875
+ });
876
+
877
+ test("should handle empty actions object", () => {
878
+ const mockRender = () => "Empty Actions Render";
879
+ const aguiMessage: agui.Message = {
880
+ id: "assistant-8",
881
+ role: "assistant",
882
+ content: "I'll execute a function",
883
+ toolCalls: [
884
+ {
885
+ id: "tool-call-10",
886
+ type: "function",
887
+ function: {
888
+ name: "anyAction",
889
+ arguments: JSON.stringify({ param: "value" }),
890
+ },
891
+ },
892
+ ],
893
+ generativeUI: mockRender,
894
+ };
895
+
896
+ const actions: Record<string, any> = {};
897
+
898
+ const result = aguiToGQL(aguiMessage, actions);
899
+
900
+ expect(result).toHaveLength(2);
901
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
902
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
903
+ });
904
+
905
+ test("should handle actions with null render functions", () => {
906
+ const mockRender = () => "Null Render Test";
907
+ const aguiMessage: agui.Message = {
908
+ id: "assistant-9",
909
+ role: "assistant",
910
+ content: "I'll execute a function",
911
+ toolCalls: [
912
+ {
913
+ id: "tool-call-11",
914
+ type: "function",
915
+ function: {
916
+ name: "specificAction",
917
+ arguments: JSON.stringify({ param: "value" }),
918
+ },
919
+ },
920
+ ],
921
+ generativeUI: mockRender,
922
+ };
923
+
924
+ const actions: Record<string, any> = {
925
+ specificAction: { name: "specificAction", render: null },
926
+ "*": { name: "*", render: null },
927
+ };
928
+
929
+ const result = aguiToGQL(aguiMessage, actions);
930
+
931
+ expect(result).toHaveLength(2);
932
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
933
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
934
+ // The render function should still be assigned even if the action had null render
935
+ expect(actions.specificAction.render).toBe(mockRender);
936
+ });
937
+
938
+ test("should handle actions with undefined render functions", () => {
939
+ const mockRender = () => "Undefined Render Test";
940
+ const aguiMessage: agui.Message = {
941
+ id: "assistant-10",
942
+ role: "assistant",
943
+ content: "I'll execute a function",
944
+ toolCalls: [
945
+ {
946
+ id: "tool-call-12",
947
+ type: "function",
948
+ function: {
949
+ name: "wildcardAction",
950
+ arguments: JSON.stringify({ param: "value" }),
951
+ },
952
+ },
953
+ ],
954
+ generativeUI: mockRender,
955
+ };
956
+
957
+ const actions: Record<string, any> = {
958
+ "*": { name: "*", render: undefined },
959
+ };
960
+
961
+ const result = aguiToGQL(aguiMessage, actions);
962
+
963
+ expect(result).toHaveLength(2);
964
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
965
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
966
+ // The render function should still be assigned even if the action had undefined render
967
+ expect(actions["*"].render).toBe(mockRender);
968
+ });
969
+
970
+ test("should handle tool calls with malformed arguments", () => {
971
+ const mockRender = () => "Malformed Args Test";
972
+ const aguiMessage: agui.Message = {
973
+ id: "assistant-11",
974
+ role: "assistant",
975
+ content: "I'll execute a function",
976
+ toolCalls: [
977
+ {
978
+ id: "tool-call-13",
979
+ type: "function",
980
+ function: {
981
+ name: "wildcardAction",
982
+ arguments: "invalid json {", // Malformed JSON
983
+ },
984
+ },
985
+ ],
986
+ generativeUI: mockRender,
987
+ };
988
+
989
+ const actions: Record<string, any> = {
990
+ "*": { name: "*" },
991
+ };
992
+
993
+ const result = aguiToGQL(aguiMessage, actions);
994
+
995
+ expect(result).toHaveLength(2);
996
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
997
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
998
+ expect(actions["*"].render).toBe(mockRender);
999
+ });
1000
+
1001
+ test("should handle tool calls with empty arguments string", () => {
1002
+ const mockRender = () => "Empty Args Test";
1003
+ const aguiMessage: agui.Message = {
1004
+ id: "assistant-12",
1005
+ role: "assistant",
1006
+ content: "I'll execute a function",
1007
+ toolCalls: [
1008
+ {
1009
+ id: "tool-call-14",
1010
+ type: "function",
1011
+ function: {
1012
+ name: "wildcardAction",
1013
+ arguments: "",
1014
+ },
1015
+ },
1016
+ ],
1017
+ generativeUI: mockRender,
1018
+ };
1019
+
1020
+ const actions: Record<string, any> = {
1021
+ "*": { name: "*" },
1022
+ };
1023
+
1024
+ const result = aguiToGQL(aguiMessage, actions);
1025
+
1026
+ expect(result).toHaveLength(2);
1027
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
1028
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
1029
+ expect(actions["*"].render).toBe(mockRender);
1030
+ });
1031
+
1032
+ test("should handle multiple wild card actions in same object", () => {
1033
+ const mockRender = () => "Multiple Wildcards Test";
1034
+ const aguiMessage: agui.Message = {
1035
+ id: "assistant-13",
1036
+ role: "assistant",
1037
+ content: "I'll execute a function",
1038
+ toolCalls: [
1039
+ {
1040
+ id: "tool-call-15",
1041
+ type: "function",
1042
+ function: {
1043
+ name: "unknownAction",
1044
+ arguments: JSON.stringify({ param: "value" }),
1045
+ },
1046
+ },
1047
+ ],
1048
+ generativeUI: mockRender,
1049
+ };
1050
+
1051
+ const actions: Record<string, any> = {
1052
+ wildcard1: { name: "*" },
1053
+ wildcard2: { name: "*" },
1054
+ };
1055
+
1056
+ const result = aguiToGQL(aguiMessage, actions);
1057
+
1058
+ expect(result).toHaveLength(2);
1059
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
1060
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
1061
+ // Should assign to the first wild card action found
1062
+ expect(actions.wildcard1.render).toBe(mockRender);
1063
+ expect(actions.wildcard2.render).toBeUndefined();
1064
+ });
1065
+
1066
+ test("should handle tool calls with object arguments (backward compatibility)", () => {
1067
+ const mockRender = () => "Object Args Test";
1068
+ const aguiMessage: agui.Message = {
1069
+ id: "assistant-14",
1070
+ role: "assistant",
1071
+ content: "I'll execute a function",
1072
+ toolCalls: [
1073
+ {
1074
+ id: "tool-call-16",
1075
+ type: "function",
1076
+ function: {
1077
+ name: "objectArgsAction",
1078
+ arguments: { param: "value" } as any, // Object instead of string
1079
+ },
1080
+ },
1081
+ ],
1082
+ generativeUI: mockRender,
1083
+ };
1084
+
1085
+ const actions: Record<string, any> = {
1086
+ "*": { name: "*" },
1087
+ };
1088
+
1089
+ const result = aguiToGQL(aguiMessage, actions);
1090
+
1091
+ expect(result).toHaveLength(2);
1092
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
1093
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
1094
+ expect((result[1] as any).arguments).toEqual({ param: "value" });
1095
+ expect(actions["*"].render).toBe(mockRender);
1096
+ });
1097
+
1098
+ test("should handle tool calls with null/undefined arguments", () => {
1099
+ const mockRender = () => "Null Args Test";
1100
+ const aguiMessage: agui.Message = {
1101
+ id: "assistant-15",
1102
+ role: "assistant",
1103
+ content: "I'll execute a function",
1104
+ toolCalls: [
1105
+ {
1106
+ id: "tool-call-17",
1107
+ type: "function",
1108
+ function: {
1109
+ name: "nullArgsAction",
1110
+ arguments: null as any,
1111
+ },
1112
+ },
1113
+ ],
1114
+ generativeUI: mockRender,
1115
+ };
1116
+
1117
+ const actions: Record<string, any> = {
1118
+ "*": { name: "*" },
1119
+ };
1120
+
1121
+ const result = aguiToGQL(aguiMessage, actions);
1122
+
1123
+ expect(result).toHaveLength(2);
1124
+ expect(result[0]).toBeInstanceOf(gql.TextMessage);
1125
+ expect(result[1]).toBeInstanceOf(gql.ActionExecutionMessage);
1126
+ expect((result[1] as any).arguments).toEqual({});
1127
+ expect(actions["*"].render).toBe(mockRender);
1128
+ });
1129
+
1130
+ test("should handle tool result messages with object content", () => {
1131
+ const aguiMessage: agui.Message = {
1132
+ id: "tool-result-1",
1133
+ role: "tool",
1134
+ content: { status: "success", data: { value: 42 } } as any,
1135
+ toolCallId: "tool-call-1",
1136
+ toolName: "testAction",
1137
+ };
1138
+
1139
+ const toolCallNames = { "tool-call-1": "testAction" };
1140
+ const result = aguiToGQL(aguiMessage);
1141
+
1142
+ expect(result).toHaveLength(1);
1143
+ expect(result[0]).toBeInstanceOf(gql.ResultMessage);
1144
+ expect((result[0] as any).result).toBe('{"status":"success","data":{"value":42}}');
1145
+ expect((result[0] as any).actionExecutionId).toBe("tool-call-1");
1146
+ expect((result[0] as any).actionName).toBe("testAction");
1147
+ });
1148
+
1149
+ test("should handle tool result messages with non-string content types", () => {
1150
+ const aguiMessage: agui.Message = {
1151
+ id: "tool-result-2",
1152
+ role: "tool",
1153
+ content: 42 as any,
1154
+ toolCallId: "tool-call-2",
1155
+ toolName: "numberAction",
1156
+ };
1157
+
1158
+ const result = aguiToGQL(aguiMessage);
1159
+
1160
+ expect(result).toHaveLength(1);
1161
+ expect(result[0]).toBeInstanceOf(gql.ResultMessage);
1162
+ expect((result[0] as any).result).toBe("42");
1163
+ expect((result[0] as any).actionExecutionId).toBe("tool-call-2");
1164
+ expect((result[0] as any).actionName).toBe("numberAction");
1165
+ });
1166
+
1167
+ test("should handle tool result messages with circular reference content", () => {
1168
+ const circularObj: any = { status: "success" };
1169
+ circularObj.self = circularObj;
1170
+
1171
+ const aguiMessage: agui.Message = {
1172
+ id: "tool-result-3",
1173
+ role: "tool",
1174
+ content: circularObj as any,
1175
+ toolCallId: "tool-call-3",
1176
+ toolName: "circularAction",
1177
+ };
1178
+
1179
+ const result = aguiToGQL(aguiMessage);
1180
+
1181
+ expect(result).toHaveLength(1);
1182
+ expect(result[0]).toBeInstanceOf(gql.ResultMessage);
1183
+ expect((result[0] as any).result).toBe("[object Object]"); // Should fallback to String conversion
1184
+ expect((result[0] as any).actionExecutionId).toBe("tool-call-3");
1185
+ expect((result[0] as any).actionName).toBe("circularAction");
1186
+ });
1187
+
1188
+ test("should handle tool result messages with boolean content", () => {
1189
+ const aguiMessage: agui.Message = {
1190
+ id: "tool-result-4",
1191
+ role: "tool",
1192
+ content: true as any,
1193
+ toolCallId: "tool-call-4",
1194
+ toolName: "booleanAction",
1195
+ };
1196
+
1197
+ const result = aguiToGQL(aguiMessage);
1198
+
1199
+ expect(result).toHaveLength(1);
1200
+ expect(result[0]).toBeInstanceOf(gql.ResultMessage);
1201
+ expect((result[0] as any).result).toBe("true");
1202
+ expect((result[0] as any).actionExecutionId).toBe("tool-call-4");
1203
+ expect((result[0] as any).actionName).toBe("booleanAction");
1204
+ });
1205
+ });
640
1206
  });
@@ -86,8 +86,17 @@ export function aguiToGQL(
86
86
  // Preserve render function in actions context
87
87
  if ("generativeUI" in message && message.generativeUI && actions) {
88
88
  const actionName = toolCall.function.name;
89
- if (actions[actionName]) {
90
- actions[actionName].render = message.generativeUI;
89
+ // Check for specific action first, then wild card action
90
+ const specificAction = Object.values(actions).find(
91
+ (action: any) => action.name === actionName,
92
+ );
93
+ const wildcardAction = Object.values(actions).find((action: any) => action.name === "*");
94
+
95
+ // Assign render function to the matching action (specific takes priority)
96
+ if (specificAction) {
97
+ specificAction.render = message.generativeUI;
98
+ } else if (wildcardAction) {
99
+ wildcardAction.render = message.generativeUI;
91
100
  }
92
101
  }
93
102
  gqlMessages.push(actionExecMsg);
@@ -154,13 +163,31 @@ export function aguiToolCallToGQLActionExecution(
154
163
  throw new Error(`Unsupported tool call type: ${toolCall.type}`);
155
164
  }
156
165
 
157
- // Parse arguments with error handling
166
+ // Handle arguments - they should be a JSON string in AGUI format,
167
+ // but we need to convert them to an object for GQL format
158
168
  let argumentsObj: any;
159
- try {
160
- argumentsObj = JSON.parse(toolCall.function.arguments);
161
- } catch (error) {
162
- console.warn(`Failed to parse tool call arguments for ${toolCall.function.name}:`, error);
163
- // Provide fallback empty object to prevent application crash
169
+
170
+ if (typeof toolCall.function.arguments === "string") {
171
+ // Expected case: arguments is a JSON string
172
+ try {
173
+ argumentsObj = JSON.parse(toolCall.function.arguments);
174
+ } catch (error) {
175
+ console.warn(`Failed to parse tool call arguments for ${toolCall.function.name}:`, error);
176
+ // Provide fallback empty object to prevent application crash
177
+ argumentsObj = {};
178
+ }
179
+ } else if (
180
+ typeof toolCall.function.arguments === "object" &&
181
+ toolCall.function.arguments !== null
182
+ ) {
183
+ // Backward compatibility: arguments is already an object
184
+ argumentsObj = toolCall.function.arguments;
185
+ } else {
186
+ // Fallback for undefined, null, or other types
187
+ console.warn(
188
+ `Invalid tool call arguments type for ${toolCall.function.name}:`,
189
+ typeof toolCall.function.arguments,
190
+ );
164
191
  argumentsObj = {};
165
192
  }
166
193
 
@@ -187,9 +214,29 @@ export function aguiToolMessageToGQLResultMessage(
187
214
 
188
215
  const actionName = toolCallNames[message.toolCallId] || "unknown";
189
216
 
217
+ // Handle result content - it could be a string or an object that needs serialization
218
+ let resultContent: string;
219
+ const messageContent = message.content || "";
220
+
221
+ if (typeof messageContent === "string") {
222
+ // Expected case: content is already a string
223
+ resultContent = messageContent;
224
+ } else if (typeof messageContent === "object" && messageContent !== null) {
225
+ // Handle case where content is an object that needs to be serialized
226
+ try {
227
+ resultContent = JSON.stringify(messageContent);
228
+ } catch (error) {
229
+ console.warn(`Failed to stringify tool result for ${actionName}:`, error);
230
+ resultContent = String(messageContent);
231
+ }
232
+ } else {
233
+ // Handle other types (number, boolean, etc.)
234
+ resultContent = String(messageContent);
235
+ }
236
+
190
237
  return new gql.ResultMessage({
191
238
  id: message.id,
192
- result: message.content || "",
239
+ result: resultContent,
193
240
  actionExecutionId: message.toolCallId,
194
241
  actionName: message.toolName || actionName,
195
242
  });