@copilotkit/runtime-client-gql 1.51.4 → 1.51.5-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 (176) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/client/CopilotRuntimeClient.cjs +119 -0
  4. package/dist/client/CopilotRuntimeClient.cjs.map +1 -0
  5. package/dist/client/CopilotRuntimeClient.d.cts +44 -0
  6. package/dist/client/CopilotRuntimeClient.d.cts.map +1 -0
  7. package/dist/client/CopilotRuntimeClient.d.mts +44 -0
  8. package/dist/client/CopilotRuntimeClient.d.mts.map +1 -0
  9. package/dist/client/CopilotRuntimeClient.mjs +116 -10
  10. package/dist/client/CopilotRuntimeClient.mjs.map +1 -1
  11. package/dist/client/conversion.cjs +194 -0
  12. package/dist/client/conversion.cjs.map +1 -0
  13. package/dist/client/{conversion.d.ts → conversion.d.cts} +5 -4
  14. package/dist/client/conversion.d.cts.map +1 -0
  15. package/dist/client/conversion.d.mts +12 -0
  16. package/dist/client/conversion.d.mts.map +1 -0
  17. package/dist/client/conversion.mjs +187 -17
  18. package/dist/client/conversion.mjs.map +1 -1
  19. package/dist/client/index.d.cts +5 -0
  20. package/dist/client/index.d.mts +5 -0
  21. package/dist/client/types.cjs +86 -0
  22. package/dist/client/types.cjs.map +1 -0
  23. package/dist/client/types.d.cts +76 -0
  24. package/dist/client/types.d.cts.map +1 -0
  25. package/dist/client/types.d.mts +76 -0
  26. package/dist/client/types.d.mts.map +1 -0
  27. package/dist/client/types.mjs +76 -21
  28. package/dist/client/types.mjs.map +1 -1
  29. package/dist/graphql/@generated/gql.cjs +15 -0
  30. package/dist/graphql/@generated/gql.cjs.map +1 -0
  31. package/dist/graphql/@generated/gql.mjs +13 -7
  32. package/dist/graphql/@generated/gql.mjs.map +1 -1
  33. package/dist/graphql/@generated/graphql.cjs +1154 -0
  34. package/dist/graphql/@generated/graphql.cjs.map +1 -0
  35. package/dist/graphql/@generated/graphql.d.cts +642 -0
  36. package/dist/graphql/@generated/graphql.d.cts.map +1 -0
  37. package/dist/graphql/@generated/graphql.d.mts +642 -0
  38. package/dist/graphql/@generated/graphql.d.mts.map +1 -0
  39. package/dist/graphql/@generated/graphql.mjs +1142 -24
  40. package/dist/graphql/@generated/graphql.mjs.map +1 -1
  41. package/dist/{chunk-E5FOLXLN.mjs → graphql/definitions/mutations.cjs} +8 -11
  42. package/dist/graphql/definitions/mutations.cjs.map +1 -0
  43. package/dist/graphql/definitions/mutations.mjs +140 -9
  44. package/dist/graphql/definitions/mutations.mjs.map +1 -1
  45. package/dist/graphql/definitions/queries.cjs +35 -0
  46. package/dist/graphql/definitions/queries.cjs.map +1 -0
  47. package/dist/graphql/definitions/queries.mjs +33 -11
  48. package/dist/graphql/definitions/queries.mjs.map +1 -1
  49. package/dist/index.cjs +43 -0
  50. package/dist/index.d.cts +9 -0
  51. package/dist/index.d.mts +9 -0
  52. package/dist/index.mjs +8 -91
  53. package/dist/index.umd.js +2080 -2
  54. package/dist/index.umd.js.map +1 -1
  55. package/dist/message-conversion/agui-to-gql.cjs +162 -0
  56. package/dist/message-conversion/agui-to-gql.cjs.map +1 -0
  57. package/dist/message-conversion/{agui-to-gql.d.ts → agui-to-gql.d.cts} +6 -5
  58. package/dist/message-conversion/agui-to-gql.d.cts.map +1 -0
  59. package/dist/message-conversion/agui-to-gql.d.mts +14 -0
  60. package/dist/message-conversion/agui-to-gql.d.mts.map +1 -0
  61. package/dist/message-conversion/agui-to-gql.mjs +156 -25
  62. package/dist/message-conversion/agui-to-gql.mjs.map +1 -1
  63. package/dist/message-conversion/gql-to-agui.cjs +169 -0
  64. package/dist/message-conversion/gql-to-agui.cjs.map +1 -0
  65. package/dist/message-conversion/{gql-to-agui.d.ts → gql-to-agui.d.cts} +6 -5
  66. package/dist/message-conversion/gql-to-agui.d.cts.map +1 -0
  67. package/dist/message-conversion/gql-to-agui.d.mts +13 -0
  68. package/dist/message-conversion/gql-to-agui.d.mts.map +1 -0
  69. package/dist/message-conversion/gql-to-agui.mjs +164 -23
  70. package/dist/message-conversion/gql-to-agui.mjs.map +1 -1
  71. package/dist/message-conversion/index.d.cts +2 -0
  72. package/dist/message-conversion/index.d.mts +2 -0
  73. package/dist/package.cjs +12 -0
  74. package/dist/package.cjs.map +1 -0
  75. package/dist/package.mjs +6 -0
  76. package/dist/package.mjs.map +1 -0
  77. package/package.json +15 -15
  78. package/src/message-conversion/agui-to-gql.test.ts +70 -0
  79. package/src/message-conversion/agui-to-gql.ts +4 -0
  80. package/tsdown.config.ts +49 -0
  81. package/vitest.config.mjs +11 -0
  82. package/dist/chunk-2XWNDVTL.mjs +0 -176
  83. package/dist/chunk-2XWNDVTL.mjs.map +0 -1
  84. package/dist/chunk-7ECCT6PK.mjs +0 -1
  85. package/dist/chunk-7ECCT6PK.mjs.map +0 -1
  86. package/dist/chunk-A4INSSNE.mjs +0 -17722
  87. package/dist/chunk-A4INSSNE.mjs.map +0 -1
  88. package/dist/chunk-CA4VMP2C.mjs +0 -1
  89. package/dist/chunk-CA4VMP2C.mjs.map +0 -1
  90. package/dist/chunk-DELDZXUX.mjs +0 -31
  91. package/dist/chunk-DELDZXUX.mjs.map +0 -1
  92. package/dist/chunk-E5FOLXLN.mjs.map +0 -1
  93. package/dist/chunk-LTVE64IE.mjs +0 -241
  94. package/dist/chunk-LTVE64IE.mjs.map +0 -1
  95. package/dist/chunk-M4CK5HDR.mjs +0 -237
  96. package/dist/chunk-M4CK5HDR.mjs.map +0 -1
  97. package/dist/chunk-OBDQ5BWD.mjs +0 -63
  98. package/dist/chunk-OBDQ5BWD.mjs.map +0 -1
  99. package/dist/chunk-QUH7QWUA.mjs +0 -38
  100. package/dist/chunk-QUH7QWUA.mjs.map +0 -1
  101. package/dist/chunk-SDQPJXLL.mjs +0 -20
  102. package/dist/chunk-SDQPJXLL.mjs.map +0 -1
  103. package/dist/chunk-UOAPP5IN.mjs +0 -93
  104. package/dist/chunk-UOAPP5IN.mjs.map +0 -1
  105. package/dist/chunk-VIHKTLUA.mjs +0 -221
  106. package/dist/chunk-VIHKTLUA.mjs.map +0 -1
  107. package/dist/chunk-XZPL6QVK.mjs +0 -24
  108. package/dist/chunk-XZPL6QVK.mjs.map +0 -1
  109. package/dist/client/CopilotRuntimeClient.d.ts +0 -39
  110. package/dist/client/CopilotRuntimeClient.js +0 -366
  111. package/dist/client/CopilotRuntimeClient.js.map +0 -1
  112. package/dist/client/conversion.js +0 -339
  113. package/dist/client/conversion.js.map +0 -1
  114. package/dist/client/index.d.ts +0 -8
  115. package/dist/client/index.js +0 -711
  116. package/dist/client/index.js.map +0 -1
  117. package/dist/client/index.mjs +0 -43
  118. package/dist/client/index.mjs.map +0 -1
  119. package/dist/client/types.d.ts +0 -75
  120. package/dist/client/types.js +0 -132
  121. package/dist/client/types.js.map +0 -1
  122. package/dist/graphql/@generated/fragment-masking.d.ts +0 -22
  123. package/dist/graphql/@generated/fragment-masking.js +0 -50
  124. package/dist/graphql/@generated/fragment-masking.js.map +0 -1
  125. package/dist/graphql/@generated/fragment-masking.mjs +0 -12
  126. package/dist/graphql/@generated/fragment-masking.mjs.map +0 -1
  127. package/dist/graphql/@generated/gql.d.ts +0 -48
  128. package/dist/graphql/@generated/gql.js +0 -45
  129. package/dist/graphql/@generated/gql.js.map +0 -1
  130. package/dist/graphql/@generated/graphql.d.ts +0 -655
  131. package/dist/graphql/@generated/graphql.js +0 -96
  132. package/dist/graphql/@generated/graphql.js.map +0 -1
  133. package/dist/graphql/@generated/index.d.ts +0 -4
  134. package/dist/graphql/@generated/index.js +0 -69
  135. package/dist/graphql/@generated/index.js.map +0 -1
  136. package/dist/graphql/@generated/index.mjs +0 -17
  137. package/dist/graphql/@generated/index.mjs.map +0 -1
  138. package/dist/graphql/definitions/mutations.d.ts +0 -9
  139. package/dist/graphql/definitions/mutations.js +0 -181
  140. package/dist/graphql/definitions/mutations.js.map +0 -1
  141. package/dist/graphql/definitions/queries.d.ts +0 -11
  142. package/dist/graphql/definitions/queries.js +0 -76
  143. package/dist/graphql/definitions/queries.js.map +0 -1
  144. package/dist/index.d.ts +0 -11
  145. package/dist/index.js +0 -1222
  146. package/dist/index.js.map +0 -1
  147. package/dist/index.mjs.map +0 -1
  148. package/dist/magic-string.es-XBKSJO3K.mjs +0 -1389
  149. package/dist/magic-string.es-XBKSJO3K.mjs.map +0 -1
  150. package/dist/message-conversion/agui-to-gql.js +0 -344
  151. package/dist/message-conversion/agui-to-gql.js.map +0 -1
  152. package/dist/message-conversion/agui-to-gql.test.d.ts +0 -2
  153. package/dist/message-conversion/agui-to-gql.test.js +0 -20553
  154. package/dist/message-conversion/agui-to-gql.test.js.map +0 -1
  155. package/dist/message-conversion/agui-to-gql.test.mjs +0 -1137
  156. package/dist/message-conversion/agui-to-gql.test.mjs.map +0 -1
  157. package/dist/message-conversion/gql-to-agui.js +0 -262
  158. package/dist/message-conversion/gql-to-agui.js.map +0 -1
  159. package/dist/message-conversion/gql-to-agui.test.d.ts +0 -2
  160. package/dist/message-conversion/gql-to-agui.test.js +0 -20850
  161. package/dist/message-conversion/gql-to-agui.test.js.map +0 -1
  162. package/dist/message-conversion/gql-to-agui.test.mjs +0 -1447
  163. package/dist/message-conversion/gql-to-agui.test.mjs.map +0 -1
  164. package/dist/message-conversion/index.d.ts +0 -6
  165. package/dist/message-conversion/index.js +0 -563
  166. package/dist/message-conversion/index.js.map +0 -1
  167. package/dist/message-conversion/index.mjs +0 -39
  168. package/dist/message-conversion/index.mjs.map +0 -1
  169. package/dist/message-conversion/roundtrip-conversion.test.d.ts +0 -2
  170. package/dist/message-conversion/roundtrip-conversion.test.js +0 -20095
  171. package/dist/message-conversion/roundtrip-conversion.test.js.map +0 -1
  172. package/dist/message-conversion/roundtrip-conversion.test.mjs +0 -489
  173. package/dist/message-conversion/roundtrip-conversion.test.mjs.map +0 -1
  174. package/jest.config.js +0 -5
  175. package/rollup.config.mjs +0 -62
  176. package/tsup.config.ts +0 -12
@@ -1,1447 +0,0 @@
1
- import {
2
- gqlActionExecutionMessageToAGUIMessage,
3
- gqlImageMessageToAGUIMessage,
4
- gqlResultMessageToAGUIMessage,
5
- gqlTextMessageToAGUIMessage,
6
- gqlToAGUI
7
- } from "../chunk-VIHKTLUA.mjs";
8
- import {
9
- describe,
10
- globalExpect,
11
- test,
12
- vi
13
- } from "../chunk-A4INSSNE.mjs";
14
- import "../chunk-7ECCT6PK.mjs";
15
- import "../chunk-2XWNDVTL.mjs";
16
- import "../chunk-QUH7QWUA.mjs";
17
- import "../chunk-E5FOLXLN.mjs";
18
- import "../chunk-SDQPJXLL.mjs";
19
- import "../chunk-M4CK5HDR.mjs";
20
- import {
21
- ActionExecutionMessage,
22
- AgentStateMessage,
23
- ImageMessage,
24
- ResultMessage,
25
- Role,
26
- TextMessage
27
- } from "../chunk-UOAPP5IN.mjs";
28
- import "../chunk-OBDQ5BWD.mjs";
29
- import "../chunk-DELDZXUX.mjs";
30
-
31
- // src/message-conversion/gql-to-agui.test.ts
32
- describe("message-conversion", () => {
33
- describe("gqlTextMessageToAGUIMessage", () => {
34
- test("should convert developer message", () => {
35
- const gqlMessage = new TextMessage({
36
- id: "dev-message-id",
37
- content: "Hello from developer",
38
- role: Role.Developer
39
- });
40
- const result = gqlTextMessageToAGUIMessage(gqlMessage);
41
- globalExpect(result).toEqual({
42
- id: "dev-message-id",
43
- role: "developer",
44
- content: "Hello from developer"
45
- });
46
- });
47
- test("should convert system message", () => {
48
- const gqlMessage = new TextMessage({
49
- id: "system-message-id",
50
- content: "System instruction",
51
- role: Role.System
52
- });
53
- const result = gqlTextMessageToAGUIMessage(gqlMessage);
54
- globalExpect(result).toEqual({
55
- id: "system-message-id",
56
- role: "system",
57
- content: "System instruction"
58
- });
59
- });
60
- test("should convert assistant message", () => {
61
- const gqlMessage = new TextMessage({
62
- id: "assistant-message-id",
63
- content: "Assistant response",
64
- role: Role.Assistant
65
- });
66
- const result = gqlTextMessageToAGUIMessage(gqlMessage);
67
- globalExpect(result).toEqual({
68
- id: "assistant-message-id",
69
- role: "assistant",
70
- content: "Assistant response"
71
- });
72
- });
73
- test("should throw error for unknown role", () => {
74
- const gqlMessage = new TextMessage({
75
- id: "unknown-message-id",
76
- content: "Unknown message",
77
- role: "unknown"
78
- });
79
- globalExpect(() => gqlTextMessageToAGUIMessage(gqlMessage)).toThrow(
80
- "Unknown message role"
81
- );
82
- });
83
- });
84
- describe("gqlResultMessageToAGUIMessage", () => {
85
- test("should convert result message to tool message", () => {
86
- const gqlMessage = new ResultMessage({
87
- id: "result-id",
88
- result: "Function result data",
89
- actionExecutionId: "action-exec-123",
90
- actionName: "testAction"
91
- });
92
- const result = gqlResultMessageToAGUIMessage(gqlMessage);
93
- globalExpect(result).toEqual({
94
- id: "result-id",
95
- role: "tool",
96
- content: "Function result data",
97
- toolCallId: "action-exec-123",
98
- toolName: "testAction"
99
- });
100
- });
101
- });
102
- describe("gqlToAGUI", () => {
103
- test("should convert an array of text messages", () => {
104
- const gqlMessages = [
105
- new TextMessage({
106
- id: "dev-1",
107
- content: "Hello",
108
- role: Role.Developer
109
- }),
110
- new TextMessage({
111
- id: "assistant-1",
112
- content: "Hi there",
113
- role: Role.Assistant
114
- })
115
- ];
116
- const result = gqlToAGUI(gqlMessages);
117
- globalExpect(result).toHaveLength(2);
118
- globalExpect(result[0]).toEqual({
119
- id: "dev-1",
120
- role: "developer",
121
- content: "Hello"
122
- });
123
- globalExpect(result[1]).toEqual({
124
- id: "assistant-1",
125
- role: "assistant",
126
- content: "Hi there"
127
- });
128
- });
129
- test("should handle agent state messages", () => {
130
- const gqlMessages = [new AgentStateMessage({ id: "agent-state-1" })];
131
- const result = gqlToAGUI(gqlMessages);
132
- globalExpect(result).toHaveLength(1);
133
- globalExpect(result[0]).toEqual({
134
- id: "agent-state-1",
135
- role: "assistant"
136
- });
137
- });
138
- test("should handle a mix of message types", () => {
139
- const gqlMessages = [
140
- new TextMessage({
141
- id: "dev-1",
142
- content: "Run action",
143
- role: Role.Developer
144
- }),
145
- new TextMessage({
146
- id: "assistant-1",
147
- content: "I'll run the action",
148
- role: Role.Assistant
149
- }),
150
- new ResultMessage({
151
- id: "result-1",
152
- result: "Action result",
153
- actionExecutionId: "action-exec-1",
154
- actionName: "testAction"
155
- })
156
- ];
157
- const result = gqlToAGUI(gqlMessages);
158
- globalExpect(result).toHaveLength(3);
159
- globalExpect(result[0]).toEqual({
160
- id: "dev-1",
161
- role: "developer",
162
- content: "Run action"
163
- });
164
- globalExpect(result[1]).toEqual({
165
- id: "assistant-1",
166
- role: "assistant",
167
- content: "I'll run the action"
168
- });
169
- globalExpect(result[2]).toEqual({
170
- id: "result-1",
171
- role: "tool",
172
- content: "Action result",
173
- toolCallId: "action-exec-1",
174
- toolName: "testAction"
175
- });
176
- });
177
- test("should handle action execution messages with parent messages", () => {
178
- const assistantMsg = new TextMessage({
179
- id: "assistant-1",
180
- content: "I'll execute an action",
181
- role: Role.Assistant
182
- });
183
- const actionExecMsg = new ActionExecutionMessage({
184
- id: "action-1",
185
- name: "testAction",
186
- arguments: { param: "value" },
187
- parentMessageId: "assistant-1"
188
- });
189
- const result = gqlToAGUI([assistantMsg, actionExecMsg]);
190
- globalExpect(result).toHaveLength(2);
191
- globalExpect(result[0]).toEqual({
192
- id: "assistant-1",
193
- role: "assistant",
194
- content: "I'll execute an action"
195
- });
196
- globalExpect(result[1]).toEqual({
197
- id: "action-1",
198
- role: "assistant",
199
- name: "testAction",
200
- toolCalls: [
201
- {
202
- id: "action-1",
203
- function: {
204
- name: "testAction",
205
- arguments: JSON.stringify({ param: "value" })
206
- },
207
- type: "function"
208
- }
209
- ]
210
- });
211
- });
212
- test("should handle multiple action execution messages for the same parent", () => {
213
- const assistantMsg = new TextMessage({
214
- id: "assistant-1",
215
- content: "I'll execute multiple actions",
216
- role: Role.Assistant
217
- });
218
- const action1 = new ActionExecutionMessage({
219
- id: "action-1",
220
- name: "firstAction",
221
- arguments: { param: "value1" },
222
- parentMessageId: "assistant-1"
223
- });
224
- const action2 = new ActionExecutionMessage({
225
- id: "action-2",
226
- name: "secondAction",
227
- arguments: { param: "value2" },
228
- parentMessageId: "assistant-1"
229
- });
230
- const result = gqlToAGUI([assistantMsg, action1, action2]);
231
- globalExpect(result).toHaveLength(3);
232
- globalExpect(result[0]).toEqual({
233
- id: "assistant-1",
234
- role: "assistant",
235
- content: "I'll execute multiple actions"
236
- });
237
- globalExpect(result[1]).toEqual({
238
- id: "action-1",
239
- role: "assistant",
240
- name: "firstAction",
241
- toolCalls: [
242
- {
243
- id: "action-1",
244
- function: {
245
- name: "firstAction",
246
- arguments: JSON.stringify({ param: "value1" })
247
- },
248
- type: "function"
249
- }
250
- ]
251
- });
252
- globalExpect(result[2]).toEqual({
253
- id: "action-2",
254
- role: "assistant",
255
- name: "secondAction",
256
- toolCalls: [
257
- {
258
- id: "action-2",
259
- function: {
260
- name: "secondAction",
261
- arguments: JSON.stringify({ param: "value2" })
262
- },
263
- type: "function"
264
- }
265
- ]
266
- });
267
- });
268
- test("should not add toolCalls to non-assistant messages", () => {
269
- const developerMsg = new TextMessage({
270
- id: "dev-1",
271
- content: "Developer message",
272
- role: Role.Developer
273
- });
274
- const actionExecMsg = new ActionExecutionMessage({
275
- id: "action-1",
276
- name: "testAction",
277
- arguments: { param: "value" },
278
- parentMessageId: "dev-1"
279
- // This should be ignored since parent is not assistant
280
- });
281
- const result = gqlToAGUI([developerMsg, actionExecMsg]);
282
- globalExpect(result).toHaveLength(2);
283
- globalExpect(result[0]).toEqual({
284
- id: "dev-1",
285
- role: "developer",
286
- content: "Developer message"
287
- });
288
- globalExpect(result[1]).toEqual({
289
- id: "action-1",
290
- role: "assistant",
291
- name: "testAction",
292
- toolCalls: [
293
- {
294
- id: "action-1",
295
- function: {
296
- name: "testAction",
297
- arguments: JSON.stringify({ param: "value" })
298
- },
299
- type: "function"
300
- }
301
- ]
302
- });
303
- });
304
- test("should handle action execution messages without actions context", () => {
305
- const actionExecMsg = new ActionExecutionMessage({
306
- id: "action-1",
307
- name: "testAction",
308
- arguments: { param: "value" }
309
- });
310
- const result = gqlToAGUI([actionExecMsg]);
311
- globalExpect(result).toHaveLength(1);
312
- globalExpect(result[0]).toEqual({
313
- id: "action-1",
314
- role: "assistant",
315
- name: "testAction",
316
- toolCalls: [
317
- {
318
- id: "action-1",
319
- function: {
320
- name: "testAction",
321
- arguments: JSON.stringify({ param: "value" })
322
- },
323
- type: "function"
324
- }
325
- ]
326
- });
327
- globalExpect(result[0]).not.toHaveProperty("render");
328
- globalExpect(result[0]).not.toHaveProperty("renderAndWaitForResponse");
329
- });
330
- test("should handle action execution messages with actions context and render functions", () => {
331
- const actionExecMsg = new ActionExecutionMessage({
332
- id: "action-1",
333
- name: "testAction",
334
- arguments: { param: "value" },
335
- status: { code: "Pending" /* Pending */ }
336
- });
337
- const mockRender = vi.fn();
338
- const mockRenderAndWaitForResponse = (props) => "Test Render With Response";
339
- const actions = {
340
- testAction: {
341
- name: "testAction",
342
- render: mockRender,
343
- renderAndWaitForResponse: mockRenderAndWaitForResponse
344
- }
345
- };
346
- const result = gqlToAGUI([actionExecMsg], actions);
347
- globalExpect(result).toHaveLength(1);
348
- globalExpect(result[0]).toMatchObject({
349
- id: "action-1",
350
- role: "assistant",
351
- name: "testAction",
352
- content: "",
353
- toolCalls: [
354
- {
355
- id: "action-1",
356
- function: {
357
- name: "testAction",
358
- arguments: JSON.stringify({ param: "value" })
359
- },
360
- type: "function"
361
- }
362
- ]
363
- });
364
- globalExpect(result[0]).toHaveProperty("generativeUI");
365
- globalExpect(typeof result[0].generativeUI).toBe("function");
366
- });
367
- test("should provide correct status in generativeUI function props", () => {
368
- var _a, _b;
369
- const actionExecMsg = new ActionExecutionMessage({
370
- id: "action-1",
371
- name: "testAction",
372
- arguments: { param: "value" },
373
- status: { code: "Pending" /* Pending */ }
374
- });
375
- const mockRender = vi.fn();
376
- const actions = {
377
- testAction: {
378
- name: "testAction",
379
- render: mockRender
380
- }
381
- };
382
- const result = gqlToAGUI([actionExecMsg], actions);
383
- (_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a);
384
- globalExpect(mockRender).toHaveBeenCalledWith({
385
- status: "inProgress",
386
- args: { param: "value" },
387
- result: void 0,
388
- respond: globalExpect.any(Function),
389
- messageId: "action-1"
390
- // Regular actions should NOT have the name property
391
- });
392
- });
393
- test("should provide executing status when not pending", () => {
394
- var _a, _b;
395
- const actionExecMsg = new ActionExecutionMessage({
396
- id: "action-1",
397
- name: "testAction",
398
- arguments: { param: "value" },
399
- status: { code: "Success" /* Success */ }
400
- });
401
- const mockRender = vi.fn();
402
- const actions = {
403
- testAction: {
404
- name: "testAction",
405
- render: mockRender
406
- }
407
- };
408
- const result = gqlToAGUI([actionExecMsg], actions);
409
- (_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a);
410
- globalExpect(mockRender).toHaveBeenCalledWith({
411
- status: "executing",
412
- args: { param: "value" },
413
- result: void 0,
414
- respond: globalExpect.any(Function),
415
- messageId: "action-1"
416
- // Regular actions should NOT have the name property
417
- });
418
- });
419
- test("should provide complete status when result is available", () => {
420
- var _a;
421
- const actionExecMsg = new ActionExecutionMessage({
422
- id: "action-1",
423
- name: "testAction",
424
- arguments: { param: "value" },
425
- status: { code: "Success" /* Success */ }
426
- });
427
- const resultMsg = new ResultMessage({
428
- id: "result-1",
429
- result: "Action completed successfully",
430
- actionExecutionId: "action-1",
431
- actionName: "testAction"
432
- });
433
- const mockRender = vi.fn();
434
- const actions = {
435
- testAction: {
436
- name: "testAction",
437
- render: mockRender
438
- }
439
- };
440
- const result = gqlToAGUI([actionExecMsg, resultMsg], actions);
441
- const actionMessage = result.find(
442
- (msg) => msg.role === "assistant" && "toolCalls" in msg
443
- );
444
- (_a = actionMessage == null ? void 0 : actionMessage.generativeUI) == null ? void 0 : _a.call(actionMessage);
445
- globalExpect(mockRender).toHaveBeenCalledWith({
446
- status: "complete",
447
- args: { param: "value" },
448
- result: "Action completed successfully",
449
- respond: globalExpect.any(Function),
450
- messageId: "action-1"
451
- // Regular actions should NOT have the name property
452
- });
453
- });
454
- test("should handle generativeUI function props override", () => {
455
- var _a, _b;
456
- const actionExecMsg = new ActionExecutionMessage({
457
- id: "action-1",
458
- name: "testAction",
459
- arguments: { param: "value" },
460
- status: { code: "Pending" /* Pending */ }
461
- });
462
- const mockRender = vi.fn();
463
- const actions = {
464
- testAction: {
465
- name: "testAction",
466
- render: mockRender
467
- }
468
- };
469
- const result = gqlToAGUI([actionExecMsg], actions);
470
- (_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a, {
471
- status: "custom",
472
- customProp: "test",
473
- respond: () => "custom respond"
474
- });
475
- globalExpect(mockRender).toHaveBeenCalledWith({
476
- status: "custom",
477
- args: { param: "value" },
478
- result: void 0,
479
- respond: globalExpect.any(Function),
480
- customProp: "test",
481
- messageId: "action-1"
482
- // Regular actions should NOT have the name property
483
- });
484
- });
485
- test("should handle missing render functions gracefully", () => {
486
- const actionExecMsg = new ActionExecutionMessage({
487
- id: "action-1",
488
- name: "testAction",
489
- arguments: { param: "value" }
490
- });
491
- const actions = {
492
- testAction: {
493
- name: "testAction"
494
- // No render functions provided
495
- }
496
- };
497
- const result = gqlToAGUI([actionExecMsg], actions);
498
- globalExpect(result[0]).toMatchObject({
499
- id: "action-1",
500
- role: "assistant",
501
- name: "testAction",
502
- content: "",
503
- toolCalls: [
504
- {
505
- id: "action-1",
506
- function: {
507
- name: "testAction",
508
- arguments: JSON.stringify({ param: "value" })
509
- },
510
- type: "function"
511
- }
512
- ]
513
- });
514
- globalExpect(result[0].generativeUI).toBeUndefined();
515
- });
516
- test("should handle action not found in actions context", () => {
517
- const actionExecMsg = new ActionExecutionMessage({
518
- id: "action-1",
519
- name: "unknownAction",
520
- arguments: { param: "value" }
521
- });
522
- const actions = {
523
- testAction: {
524
- name: "testAction",
525
- render: () => "Test"
526
- }
527
- };
528
- const result = gqlToAGUI([actionExecMsg], actions);
529
- globalExpect(result).toHaveLength(1);
530
- globalExpect(result[0]).toEqual({
531
- id: "action-1",
532
- role: "assistant",
533
- name: "unknownAction",
534
- toolCalls: [
535
- {
536
- id: "action-1",
537
- function: {
538
- name: "unknownAction",
539
- arguments: JSON.stringify({ param: "value" })
540
- },
541
- type: "function"
542
- }
543
- ]
544
- });
545
- globalExpect(result[0]).not.toHaveProperty("generativeUI");
546
- });
547
- test("should handle agent state messages with coAgentStateRenders", () => {
548
- var _a, _b;
549
- const agentStateMsg = new AgentStateMessage({
550
- id: "agent-state-1",
551
- agentName: "testAgent",
552
- state: { status: "running", data: "test data" },
553
- role: Role.Assistant
554
- });
555
- const mockRender = vi.fn();
556
- const coAgentStateRenders = {
557
- testAgent: {
558
- name: "testAgent",
559
- render: mockRender
560
- }
561
- };
562
- const result = gqlToAGUI([agentStateMsg], void 0, coAgentStateRenders);
563
- globalExpect(result).toHaveLength(1);
564
- globalExpect(result[0]).toEqual({
565
- id: "agent-state-1",
566
- role: "assistant",
567
- agentName: "testAgent",
568
- state: { status: "running", data: "test data" },
569
- generativeUI: globalExpect.any(Function)
570
- });
571
- globalExpect(result[0]).toHaveProperty("generativeUI");
572
- globalExpect(typeof result[0].generativeUI).toBe("function");
573
- (_b = (_a = result[0]).generativeUI) == null ? void 0 : _b.call(_a);
574
- globalExpect(mockRender).toHaveBeenCalledWith({
575
- state: { status: "running", data: "test data" }
576
- });
577
- });
578
- test("should handle agent state messages without coAgentStateRenders", () => {
579
- const agentStateMsg = new AgentStateMessage({
580
- id: "agent-state-1",
581
- agentName: "testAgent",
582
- state: { status: "running", data: "test data" },
583
- role: Role.Assistant
584
- });
585
- const result = gqlToAGUI([agentStateMsg]);
586
- globalExpect(result).toHaveLength(1);
587
- globalExpect(result[0]).toEqual({
588
- id: "agent-state-1",
589
- role: "assistant",
590
- agentName: "testAgent",
591
- state: { status: "running", data: "test data" }
592
- });
593
- globalExpect(result[0]).not.toHaveProperty("generativeUI");
594
- });
595
- test("should handle agent state messages with agent not found in coAgentStateRenders", () => {
596
- const agentStateMsg = new AgentStateMessage({
597
- id: "agent-state-1",
598
- agentName: "unknownAgent",
599
- state: { status: "running", data: "test data" },
600
- role: Role.Assistant
601
- });
602
- const coAgentStateRenders = {
603
- testAgent: {
604
- name: "testAgent",
605
- render: () => "Test"
606
- }
607
- };
608
- const result = gqlToAGUI([agentStateMsg], void 0, coAgentStateRenders);
609
- globalExpect(result).toHaveLength(1);
610
- globalExpect(result[0]).toEqual({
611
- id: "agent-state-1",
612
- role: "assistant",
613
- agentName: "unknownAgent",
614
- state: { status: "running", data: "test data" }
615
- });
616
- globalExpect(result[0]).not.toHaveProperty("generativeUI");
617
- });
618
- test("should handle user role messages", () => {
619
- const userMsg = new TextMessage({
620
- id: "user-1",
621
- content: "Hello from user",
622
- role: Role.User
623
- });
624
- const result = gqlToAGUI([userMsg]);
625
- globalExpect(result).toHaveLength(1);
626
- globalExpect(result[0]).toEqual({
627
- id: "user-1",
628
- role: "user",
629
- content: "Hello from user"
630
- });
631
- });
632
- test("should handle mixed message types including agent state messages", () => {
633
- const textMsg = new TextMessage({
634
- id: "text-1",
635
- content: "Hello",
636
- role: Role.Assistant
637
- });
638
- const agentStateMsg = new AgentStateMessage({
639
- id: "agent-state-1",
640
- agentName: "testAgent",
641
- state: { status: "running" },
642
- role: Role.Assistant
643
- });
644
- const mockRender = vi.fn();
645
- const coAgentStateRenders = {
646
- testAgent: {
647
- name: "testAgent",
648
- render: mockRender
649
- }
650
- };
651
- const result = gqlToAGUI(
652
- [textMsg, agentStateMsg],
653
- void 0,
654
- coAgentStateRenders
655
- );
656
- globalExpect(result).toHaveLength(2);
657
- globalExpect(result[0]).toEqual({
658
- id: "text-1",
659
- role: "assistant",
660
- content: "Hello"
661
- });
662
- globalExpect(result[1]).toMatchObject({
663
- id: "agent-state-1",
664
- role: "assistant",
665
- agentName: "testAgent",
666
- state: { status: "running" },
667
- generativeUI: globalExpect.any(Function)
668
- });
669
- globalExpect(result[1]).toHaveProperty("generativeUI");
670
- });
671
- });
672
- describe("gqlImageMessageToAGUIMessage", () => {
673
- test("should throw error for invalid image format", () => {
674
- const invalidImageMsg = new ImageMessage({
675
- id: "img-1",
676
- format: "bmp",
677
- // not in VALID_IMAGE_FORMATS
678
- bytes: "somebase64string",
679
- role: Role.User
680
- });
681
- globalExpect(() => gqlImageMessageToAGUIMessage(invalidImageMsg)).toThrow(
682
- "Invalid image format"
683
- );
684
- });
685
- test("should throw error for empty image bytes", () => {
686
- const invalidImageMsg = new ImageMessage({
687
- id: "img-2",
688
- format: "jpeg",
689
- bytes: "",
690
- role: Role.User
691
- });
692
- globalExpect(() => gqlImageMessageToAGUIMessage(invalidImageMsg)).toThrow(
693
- "Image bytes must be a non-empty string"
694
- );
695
- });
696
- test("should convert valid image message", () => {
697
- const validImageMsg = new ImageMessage({
698
- id: "img-3",
699
- format: "jpeg",
700
- bytes: "somebase64string",
701
- role: Role.User
702
- });
703
- const result = gqlImageMessageToAGUIMessage(validImageMsg);
704
- globalExpect(result).toMatchObject({
705
- id: "img-3",
706
- role: "user",
707
- content: "",
708
- image: {
709
- format: "jpeg",
710
- bytes: "somebase64string"
711
- }
712
- });
713
- });
714
- test("should convert valid user image message", () => {
715
- const validImageMsg = new ImageMessage({
716
- id: "img-user-1",
717
- format: "jpeg",
718
- bytes: "userbase64string",
719
- role: Role.User
720
- });
721
- const result = gqlImageMessageToAGUIMessage(validImageMsg);
722
- globalExpect(result).toMatchObject({
723
- id: "img-user-1",
724
- role: "user",
725
- content: "",
726
- image: {
727
- format: "jpeg",
728
- bytes: "userbase64string"
729
- }
730
- });
731
- });
732
- test("should convert valid assistant image message", () => {
733
- const validImageMsg = new ImageMessage({
734
- id: "img-assistant-1",
735
- format: "png",
736
- bytes: "assistantbase64string",
737
- role: Role.Assistant
738
- });
739
- const result = gqlImageMessageToAGUIMessage(validImageMsg);
740
- globalExpect(result).toMatchObject({
741
- id: "img-assistant-1",
742
- role: "assistant",
743
- content: "",
744
- image: {
745
- format: "png",
746
- bytes: "assistantbase64string"
747
- }
748
- });
749
- });
750
- });
751
- describe("Wild Card Actions", () => {
752
- test("should handle action execution with specific action", () => {
753
- const actions = {
754
- testAction: {
755
- name: "testAction",
756
- render: vi.fn((props) => `Rendered: ${props.args.test}`)
757
- }
758
- };
759
- const actionExecMsg = new ActionExecutionMessage({
760
- id: "action-1",
761
- name: "testAction",
762
- arguments: { test: "value" },
763
- parentMessageId: "parent-1"
764
- });
765
- const result = gqlActionExecutionMessageToAGUIMessage(
766
- actionExecMsg,
767
- actions
768
- );
769
- globalExpect(result).toMatchObject({
770
- id: "action-1",
771
- role: "assistant",
772
- content: "",
773
- toolCalls: [
774
- {
775
- id: "action-1",
776
- function: {
777
- name: "testAction",
778
- arguments: '{"test":"value"}'
779
- },
780
- type: "function"
781
- }
782
- ],
783
- generativeUI: globalExpect.any(Function),
784
- name: "testAction"
785
- });
786
- });
787
- test("should handle action execution with wild card action", () => {
788
- const actions = {
789
- "*": {
790
- name: "*",
791
- render: vi.fn((props) => `Wildcard rendered: ${props.args.test}`)
792
- }
793
- };
794
- const actionExecMsg = new ActionExecutionMessage({
795
- id: "action-2",
796
- name: "unknownAction",
797
- arguments: { test: "wildcard-value" },
798
- parentMessageId: "parent-2"
799
- });
800
- const result = gqlActionExecutionMessageToAGUIMessage(
801
- actionExecMsg,
802
- actions
803
- );
804
- globalExpect(result).toMatchObject({
805
- id: "action-2",
806
- role: "assistant",
807
- content: "",
808
- toolCalls: [
809
- {
810
- id: "action-2",
811
- function: {
812
- name: "unknownAction",
813
- arguments: '{"test":"wildcard-value"}'
814
- },
815
- type: "function"
816
- }
817
- ],
818
- generativeUI: globalExpect.any(Function),
819
- name: "unknownAction"
820
- });
821
- });
822
- test("should pass tool name to wildcard action render function", () => {
823
- var _a;
824
- const mockRender = vi.fn(
825
- (props) => `Wildcard rendered: ${props.name} with args: ${JSON.stringify(props.args)}`
826
- );
827
- const actions = {
828
- "*": {
829
- name: "*",
830
- render: mockRender
831
- }
832
- };
833
- const actionExecMsg = new ActionExecutionMessage({
834
- id: "action-wildcard-name",
835
- name: "testTool",
836
- arguments: { param: "value" },
837
- parentMessageId: "parent-wildcard-name"
838
- });
839
- const result = gqlActionExecutionMessageToAGUIMessage(
840
- actionExecMsg,
841
- actions
842
- );
843
- (_a = result.generativeUI) == null ? void 0 : _a.call(result);
844
- globalExpect(mockRender).toHaveBeenCalledWith(
845
- globalExpect.objectContaining({
846
- name: "testTool",
847
- args: { param: "value" }
848
- })
849
- );
850
- });
851
- test("should pass tool name to regular action render function", () => {
852
- var _a;
853
- const mockRender = vi.fn(
854
- (props) => `Regular action rendered: ${JSON.stringify(props.args)}`
855
- );
856
- const actions = {
857
- testAction: {
858
- name: "testAction",
859
- render: mockRender
860
- }
861
- };
862
- const actionExecMsg = new ActionExecutionMessage({
863
- id: "action-regular-name",
864
- name: "testAction",
865
- arguments: { param: "value" },
866
- parentMessageId: "parent-regular-name"
867
- });
868
- const result = gqlActionExecutionMessageToAGUIMessage(
869
- actionExecMsg,
870
- actions
871
- );
872
- (_a = result.generativeUI) == null ? void 0 : _a.call(result);
873
- globalExpect(mockRender).toHaveBeenCalledWith(
874
- globalExpect.objectContaining({
875
- args: { param: "value" }
876
- // name property should NOT be present for regular actions
877
- })
878
- );
879
- const callArgs = mockRender.mock.calls[0][0];
880
- globalExpect(callArgs).not.toHaveProperty("name");
881
- });
882
- test("should prioritize specific action over wild card action", () => {
883
- const actions = {
884
- specificAction: {
885
- name: "specificAction",
886
- render: vi.fn((props) => "Specific action rendered")
887
- },
888
- "*": {
889
- name: "*",
890
- render: vi.fn((props) => "Wildcard action rendered")
891
- }
892
- };
893
- const actionExecMsg = new ActionExecutionMessage({
894
- id: "action-3",
895
- name: "specificAction",
896
- arguments: { test: "value" },
897
- parentMessageId: "parent-3"
898
- });
899
- const result = gqlActionExecutionMessageToAGUIMessage(
900
- actionExecMsg,
901
- actions
902
- );
903
- globalExpect(result).toMatchObject({
904
- id: "action-3",
905
- role: "assistant",
906
- content: "",
907
- toolCalls: [
908
- {
909
- id: "action-3",
910
- function: {
911
- name: "specificAction",
912
- arguments: '{"test":"value"}'
913
- },
914
- type: "function"
915
- }
916
- ],
917
- generativeUI: globalExpect.any(Function),
918
- name: "specificAction"
919
- });
920
- });
921
- test("should handle action execution without any matching actions", () => {
922
- const actions = {
923
- otherAction: {
924
- name: "otherAction",
925
- render: vi.fn()
926
- }
927
- };
928
- const actionExecMsg = new ActionExecutionMessage({
929
- id: "action-4",
930
- name: "unmatchedAction",
931
- arguments: { test: "value" },
932
- parentMessageId: "parent-4"
933
- });
934
- const result = gqlActionExecutionMessageToAGUIMessage(
935
- actionExecMsg,
936
- actions
937
- );
938
- globalExpect(result).toMatchObject({
939
- id: "action-4",
940
- role: "assistant",
941
- toolCalls: [
942
- {
943
- id: "action-4",
944
- function: {
945
- name: "unmatchedAction",
946
- arguments: '{"test":"value"}'
947
- },
948
- type: "function"
949
- }
950
- ],
951
- name: "unmatchedAction"
952
- });
953
- globalExpect(result).not.toHaveProperty("generativeUI");
954
- });
955
- test("should handle action execution with no actions provided", () => {
956
- const actionExecMsg = new ActionExecutionMessage({
957
- id: "action-5",
958
- name: "anyAction",
959
- arguments: { test: "value" },
960
- parentMessageId: "parent-5"
961
- });
962
- const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
963
- globalExpect(result).toMatchObject({
964
- id: "action-5",
965
- role: "assistant",
966
- toolCalls: [
967
- {
968
- id: "action-5",
969
- function: {
970
- name: "anyAction",
971
- arguments: '{"test":"value"}'
972
- },
973
- type: "function"
974
- }
975
- ],
976
- name: "anyAction"
977
- });
978
- globalExpect(result).not.toHaveProperty("generativeUI");
979
- });
980
- test("should handle action execution with completed result", () => {
981
- const actions = {
982
- "*": {
983
- name: "*",
984
- render: vi.fn((props) => `Result: ${props.result}`)
985
- }
986
- };
987
- const actionExecMsg = new ActionExecutionMessage({
988
- id: "action-6",
989
- name: "testAction",
990
- arguments: { test: "value" },
991
- parentMessageId: "parent-6"
992
- });
993
- const actionResults = /* @__PURE__ */ new Map([["action-6", "completed result"]]);
994
- const result = gqlActionExecutionMessageToAGUIMessage(
995
- actionExecMsg,
996
- actions,
997
- actionResults
998
- );
999
- globalExpect(result).toMatchObject({
1000
- id: "action-6",
1001
- role: "assistant",
1002
- content: "",
1003
- toolCalls: [
1004
- {
1005
- id: "action-6",
1006
- function: {
1007
- name: "testAction",
1008
- arguments: '{"test":"value"}'
1009
- },
1010
- type: "function"
1011
- }
1012
- ],
1013
- generativeUI: globalExpect.any(Function),
1014
- name: "testAction"
1015
- });
1016
- });
1017
- test("should handle action execution with executing status", () => {
1018
- const actions = {
1019
- "*": {
1020
- name: "*",
1021
- render: vi.fn((props) => `Status: ${props.status}`)
1022
- }
1023
- };
1024
- const actionExecMsg = new ActionExecutionMessage({
1025
- id: "action-7",
1026
- name: "testAction",
1027
- arguments: { test: "value" },
1028
- parentMessageId: "parent-7",
1029
- status: { code: "Success" /* Success */ }
1030
- });
1031
- const result = gqlActionExecutionMessageToAGUIMessage(
1032
- actionExecMsg,
1033
- actions
1034
- );
1035
- globalExpect(result).toMatchObject({
1036
- id: "action-7",
1037
- role: "assistant",
1038
- content: "",
1039
- toolCalls: [
1040
- {
1041
- id: "action-7",
1042
- function: {
1043
- name: "testAction",
1044
- arguments: '{"test":"value"}'
1045
- },
1046
- type: "function"
1047
- }
1048
- ],
1049
- generativeUI: globalExpect.any(Function),
1050
- name: "testAction"
1051
- });
1052
- });
1053
- test("should handle action execution with pending status", () => {
1054
- const actions = {
1055
- "*": {
1056
- name: "*",
1057
- render: vi.fn((props) => `Status: ${props.status}`)
1058
- }
1059
- };
1060
- const actionExecMsg = new ActionExecutionMessage({
1061
- id: "action-8",
1062
- name: "testAction",
1063
- arguments: { test: "value" },
1064
- parentMessageId: "parent-8",
1065
- status: { code: "Pending" /* Pending */ }
1066
- });
1067
- const result = gqlActionExecutionMessageToAGUIMessage(
1068
- actionExecMsg,
1069
- actions
1070
- );
1071
- globalExpect(result).toMatchObject({
1072
- id: "action-8",
1073
- role: "assistant",
1074
- content: "",
1075
- toolCalls: [
1076
- {
1077
- id: "action-8",
1078
- function: {
1079
- name: "testAction",
1080
- arguments: '{"test":"value"}'
1081
- },
1082
- type: "function"
1083
- }
1084
- ],
1085
- generativeUI: globalExpect.any(Function),
1086
- name: "testAction"
1087
- });
1088
- });
1089
- test("should handle action execution with failed status", () => {
1090
- const actions = {
1091
- "*": {
1092
- name: "*",
1093
- render: vi.fn((props) => `Status: ${props.status}`)
1094
- }
1095
- };
1096
- const actionExecMsg = new ActionExecutionMessage({
1097
- id: "action-9",
1098
- name: "testAction",
1099
- arguments: { test: "value" },
1100
- parentMessageId: "parent-9",
1101
- status: { code: "Failed" /* Failed */ }
1102
- });
1103
- const result = gqlActionExecutionMessageToAGUIMessage(
1104
- actionExecMsg,
1105
- actions
1106
- );
1107
- globalExpect(result).toMatchObject({
1108
- id: "action-9",
1109
- role: "assistant",
1110
- content: "",
1111
- toolCalls: [
1112
- {
1113
- id: "action-9",
1114
- function: {
1115
- name: "testAction",
1116
- arguments: '{"test":"value"}'
1117
- },
1118
- type: "function"
1119
- }
1120
- ],
1121
- generativeUI: globalExpect.any(Function),
1122
- name: "testAction"
1123
- });
1124
- });
1125
- test("should handle action execution with undefined status", () => {
1126
- const actions = {
1127
- "*": {
1128
- name: "*",
1129
- render: vi.fn((props) => `Status: ${props.status}`)
1130
- }
1131
- };
1132
- const actionExecMsg = new ActionExecutionMessage({
1133
- id: "action-10",
1134
- name: "testAction",
1135
- arguments: { test: "value" },
1136
- parentMessageId: "parent-10"
1137
- // No status field
1138
- });
1139
- const result = gqlActionExecutionMessageToAGUIMessage(
1140
- actionExecMsg,
1141
- actions
1142
- );
1143
- globalExpect(result).toMatchObject({
1144
- id: "action-10",
1145
- role: "assistant",
1146
- content: "",
1147
- toolCalls: [
1148
- {
1149
- id: "action-10",
1150
- function: {
1151
- name: "testAction",
1152
- arguments: '{"test":"value"}'
1153
- },
1154
- type: "function"
1155
- }
1156
- ],
1157
- generativeUI: globalExpect.any(Function),
1158
- name: "testAction"
1159
- });
1160
- });
1161
- test("should handle action execution with empty arguments", () => {
1162
- const actions = {
1163
- "*": {
1164
- name: "*",
1165
- render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`)
1166
- }
1167
- };
1168
- const actionExecMsg = new ActionExecutionMessage({
1169
- id: "action-11",
1170
- name: "testAction",
1171
- arguments: {},
1172
- parentMessageId: "parent-11"
1173
- });
1174
- const result = gqlActionExecutionMessageToAGUIMessage(
1175
- actionExecMsg,
1176
- actions
1177
- );
1178
- globalExpect(result).toMatchObject({
1179
- id: "action-11",
1180
- role: "assistant",
1181
- content: "",
1182
- toolCalls: [
1183
- {
1184
- id: "action-11",
1185
- function: {
1186
- name: "testAction",
1187
- arguments: "{}"
1188
- },
1189
- type: "function"
1190
- }
1191
- ],
1192
- generativeUI: globalExpect.any(Function),
1193
- name: "testAction"
1194
- });
1195
- });
1196
- test("should handle action execution with null arguments", () => {
1197
- const actions = {
1198
- "*": {
1199
- name: "*",
1200
- render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`)
1201
- }
1202
- };
1203
- const actionExecMsg = new ActionExecutionMessage({
1204
- id: "action-12",
1205
- name: "testAction",
1206
- arguments: null,
1207
- parentMessageId: "parent-12"
1208
- });
1209
- const result = gqlActionExecutionMessageToAGUIMessage(
1210
- actionExecMsg,
1211
- actions
1212
- );
1213
- globalExpect(result).toMatchObject({
1214
- id: "action-12",
1215
- role: "assistant",
1216
- content: "",
1217
- toolCalls: [
1218
- {
1219
- id: "action-12",
1220
- function: {
1221
- name: "testAction",
1222
- arguments: "null"
1223
- },
1224
- type: "function"
1225
- }
1226
- ],
1227
- generativeUI: globalExpect.any(Function),
1228
- name: "testAction"
1229
- });
1230
- });
1231
- test("should handle action execution with complex nested arguments", () => {
1232
- const actions = {
1233
- "*": {
1234
- name: "*",
1235
- render: vi.fn((props) => `Complex: ${JSON.stringify(props.args)}`)
1236
- }
1237
- };
1238
- const complexArgs = {
1239
- nested: {
1240
- array: [1, 2, 3],
1241
- object: { key: "value" },
1242
- nullValue: null,
1243
- undefinedValue: void 0
1244
- },
1245
- string: "test",
1246
- number: 42,
1247
- boolean: true
1248
- };
1249
- const actionExecMsg = new ActionExecutionMessage({
1250
- id: "action-13",
1251
- name: "testAction",
1252
- arguments: complexArgs,
1253
- parentMessageId: "parent-13"
1254
- });
1255
- const result = gqlActionExecutionMessageToAGUIMessage(
1256
- actionExecMsg,
1257
- actions
1258
- );
1259
- globalExpect(result).toMatchObject({
1260
- id: "action-13",
1261
- role: "assistant",
1262
- content: "",
1263
- toolCalls: [
1264
- {
1265
- id: "action-13",
1266
- function: {
1267
- name: "testAction",
1268
- arguments: JSON.stringify(complexArgs)
1269
- },
1270
- type: "function"
1271
- }
1272
- ],
1273
- generativeUI: globalExpect.any(Function),
1274
- name: "testAction"
1275
- });
1276
- });
1277
- test("should handle multiple wild card actions (should use first one)", () => {
1278
- const actions = {
1279
- wildcard1: {
1280
- name: "*",
1281
- render: vi.fn((props) => "First wildcard")
1282
- },
1283
- wildcard2: {
1284
- name: "*",
1285
- render: vi.fn((props) => "Second wildcard")
1286
- }
1287
- };
1288
- const actionExecMsg = new ActionExecutionMessage({
1289
- id: "action-14",
1290
- name: "unknownAction",
1291
- arguments: { test: "value" },
1292
- parentMessageId: "parent-14"
1293
- });
1294
- const result = gqlActionExecutionMessageToAGUIMessage(
1295
- actionExecMsg,
1296
- actions
1297
- );
1298
- globalExpect(result).toMatchObject({
1299
- id: "action-14",
1300
- role: "assistant",
1301
- content: "",
1302
- toolCalls: [
1303
- {
1304
- id: "action-14",
1305
- function: {
1306
- name: "unknownAction",
1307
- arguments: '{"test":"value"}'
1308
- },
1309
- type: "function"
1310
- }
1311
- ],
1312
- generativeUI: globalExpect.any(Function),
1313
- name: "unknownAction"
1314
- });
1315
- });
1316
- test("should parse string results in generativeUI props", () => {
1317
- const actions = {
1318
- "*": {
1319
- name: "*",
1320
- render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
1321
- }
1322
- };
1323
- const actionExecMsg = new ActionExecutionMessage({
1324
- id: "action-string-result",
1325
- name: "stringResultAction",
1326
- arguments: { test: "value" },
1327
- parentMessageId: "parent-string"
1328
- });
1329
- const actionResults = /* @__PURE__ */ new Map();
1330
- actionResults.set(
1331
- "action-string-result",
1332
- '{"parsed": true, "value": 42}'
1333
- );
1334
- const result = gqlActionExecutionMessageToAGUIMessage(
1335
- actionExecMsg,
1336
- actions,
1337
- actionResults
1338
- );
1339
- globalExpect(result.generativeUI).toBeDefined();
1340
- const renderResult = result.generativeUI({
1341
- result: '{"from": "props", "data": "test"}'
1342
- });
1343
- globalExpect(actions["*"].render).toHaveBeenCalledWith(
1344
- globalExpect.objectContaining({
1345
- result: { from: "props", data: "test" },
1346
- // Should be parsed from string
1347
- args: { test: "value" },
1348
- status: "complete",
1349
- messageId: "action-string-result"
1350
- })
1351
- );
1352
- });
1353
- test("should handle malformed JSON strings gracefully in results", () => {
1354
- const actions = {
1355
- "*": {
1356
- name: "*",
1357
- render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
1358
- }
1359
- };
1360
- const actionExecMsg = new ActionExecutionMessage({
1361
- id: "action-malformed",
1362
- name: "malformedAction",
1363
- arguments: { test: "value" },
1364
- parentMessageId: "parent-malformed"
1365
- });
1366
- const actionResults = /* @__PURE__ */ new Map();
1367
- actionResults.set("action-malformed", "invalid json {");
1368
- const result = gqlActionExecutionMessageToAGUIMessage(
1369
- actionExecMsg,
1370
- actions,
1371
- actionResults
1372
- );
1373
- globalExpect(result.generativeUI).toBeDefined();
1374
- const renderResult = result.generativeUI({
1375
- result: "invalid json {"
1376
- });
1377
- globalExpect(actions["*"].render).toHaveBeenCalledWith(
1378
- globalExpect.objectContaining({
1379
- result: "invalid json {",
1380
- // Should remain as string due to parse error
1381
- args: { test: "value" },
1382
- status: "complete",
1383
- messageId: "action-malformed"
1384
- })
1385
- );
1386
- });
1387
- test("should handle non-string results without parsing", () => {
1388
- const actions = {
1389
- "*": {
1390
- name: "*",
1391
- render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`)
1392
- }
1393
- };
1394
- const actionExecMsg = new ActionExecutionMessage({
1395
- id: "action-object-result",
1396
- name: "objectResultAction",
1397
- arguments: { test: "value" },
1398
- parentMessageId: "parent-object"
1399
- });
1400
- const actionResults = /* @__PURE__ */ new Map();
1401
- actionResults.set("action-object-result", '{"already": "parsed"}');
1402
- const result = gqlActionExecutionMessageToAGUIMessage(
1403
- actionExecMsg,
1404
- actions,
1405
- actionResults
1406
- );
1407
- globalExpect(result.generativeUI).toBeDefined();
1408
- const renderResult = result.generativeUI({
1409
- result: { from: "props", data: "object" }
1410
- });
1411
- globalExpect(actions["*"].render).toHaveBeenCalledWith(
1412
- globalExpect.objectContaining({
1413
- result: { from: "props", data: "object" },
1414
- // Should remain as object
1415
- args: { test: "value" },
1416
- status: "complete",
1417
- messageId: "action-object-result"
1418
- })
1419
- );
1420
- });
1421
- test("should handle action execution arguments correctly with simplified conversion", () => {
1422
- const actionExecMsg = new ActionExecutionMessage({
1423
- id: "action-simplified",
1424
- name: "simplifiedAction",
1425
- arguments: { complex: { nested: "value" }, array: [1, 2, 3] },
1426
- parentMessageId: "parent-simplified"
1427
- });
1428
- const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
1429
- globalExpect(result).toMatchObject({
1430
- id: "action-simplified",
1431
- role: "assistant",
1432
- toolCalls: [
1433
- {
1434
- id: "action-simplified",
1435
- function: {
1436
- name: "simplifiedAction",
1437
- arguments: '{"complex":{"nested":"value"},"array":[1,2,3]}'
1438
- },
1439
- type: "function"
1440
- }
1441
- ],
1442
- name: "simplifiedAction"
1443
- });
1444
- });
1445
- });
1446
- });
1447
- //# sourceMappingURL=gql-to-agui.test.mjs.map