@copilotkit/vue 2.0.0-rc.8 → 2.0.0-rc.9

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 (51) hide show
  1. package/dist/hooks/use-copilot-action.d.ts.map +1 -1
  2. package/dist/hooks/use-frontend-tool.d.ts +1 -1
  3. package/dist/hooks/use-frontend-tool.d.ts.map +1 -1
  4. package/dist/hooks/zod-parameters.d.ts +14 -0
  5. package/dist/hooks/zod-parameters.d.ts.map +1 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.mjs +392 -290
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/use-render-activity-message-B59A4R48.js +18097 -0
  11. package/dist/use-render-activity-message-B59A4R48.js.map +1 -0
  12. package/dist/use-render-activity-message-u0OVXjd8.cjs +92 -0
  13. package/dist/use-render-activity-message-u0OVXjd8.cjs.map +1 -0
  14. package/dist/v2/components/OpenGenerativeUIRenderer.d.ts +13 -45
  15. package/dist/v2/components/OpenGenerativeUIRenderer.d.ts.map +1 -1
  16. package/dist/v2/components/a2ui/A2UICatalogContext.d.ts +1 -1
  17. package/dist/v2/components/a2ui/A2UICatalogContext.d.ts.map +1 -1
  18. package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts +13 -5
  19. package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts.map +1 -1
  20. package/dist/v2/components/a2ui.d.ts +3 -7
  21. package/dist/v2/components/a2ui.d.ts.map +1 -1
  22. package/dist/v2/index.cjs +1 -1
  23. package/dist/v2/index.mjs +173 -173
  24. package/dist/v2/lib/processPartialHtml.d.ts +1 -2
  25. package/dist/v2/lib/processPartialHtml.d.ts.map +1 -1
  26. package/dist/v2/providers/CopilotKitProvider.vue.d.ts +1 -1
  27. package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
  28. package/package.json +10 -10
  29. package/src/hooks/__tests__/zod-parameters.test.ts +520 -0
  30. package/src/hooks/use-copilot-action.ts +2 -1
  31. package/src/hooks/use-frontend-tool.ts +3 -6
  32. package/src/hooks/zod-parameters.ts +162 -0
  33. package/src/v2/components/A2UIMessageRenderer.ts +3 -3
  34. package/src/v2/components/OpenGenerativeUIRenderer.ts +51 -373
  35. package/src/v2/components/__tests__/A2UICatalogContext.test.ts +1 -1
  36. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.ts +55 -6
  37. package/src/v2/components/a2ui/A2UIBuiltInToolCallRenderer.ts +1 -1
  38. package/src/v2/components/a2ui/A2UICatalogContext.ts +10 -102
  39. package/src/v2/components/a2ui/A2UIRecoveryStates.ts +1 -1
  40. package/src/v2/components/a2ui.ts +1 -1
  41. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.ts +26 -9
  42. package/src/v2/hooks/__tests__/zod-regression.test.ts +1 -1
  43. package/src/v2/lib/processPartialHtml.ts +6 -21
  44. package/src/v2/providers/CopilotKitProvider.vue +26 -34
  45. package/src/v2/providers/__tests__/CopilotKitProvider.a2ui.test.ts +1 -1
  46. package/vite.config.ts +2 -2
  47. package/dist/use-render-activity-message-C5LCG9a9.js +0 -16451
  48. package/dist/use-render-activity-message-C5LCG9a9.js.map +0 -1
  49. package/dist/use-render-activity-message-CPzguixR.cjs +0 -74
  50. package/dist/use-render-activity-message-CPzguixR.cjs.map +0 -1
  51. package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -84
@@ -10,10 +10,10 @@ type __VLS_Slots = {} & {
10
10
  declare const __VLS_component: import("vue").DefineComponent<CopilotKitProviderProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CopilotKitProviderProps> & Readonly<{}>, {
11
11
  renderActivityMessages: VueActivityMessageRenderer<unknown>[];
12
12
  renderCustomMessages: import("..").VueCustomMessageRenderer[];
13
- properties: Record<string, unknown>;
14
13
  headers: CopilotKitHeadersSource;
15
14
  nonce: string;
16
15
  injectStyles: boolean;
16
+ properties: Record<string, unknown>;
17
17
  useSingleEndpoint: boolean;
18
18
  agents__unsafe_dev_only: Record<string, AbstractAgent>;
19
19
  selfManagedAgents: Record<string, AbstractAgent>;
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotKitProvider.vue.d.ts","sourceRoot":"","sources":["../../../src/v2/providers/CopilotKitProvider.vue"],"names":[],"mappings":"AAi7BA,OAAO,KAAK,EAAE,SAAS,EAAuB,MAAM,KAAK,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAGV,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAmC1B,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC1B,eAAe,EAGhB,MAAM,UAAU,CAAC;AAk4BlB,QAAA,IAAI,OAAO,IAAW,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAyB/C,QAAA,MAAM,eAAe;;;;;;;;;;;;;wBAn+BrB,CA50B4B;mBA40B5B,CA30BiB;;;;aA20BjB,CAp0BkD;eAo0BlD,CAp0B2E;wBAo0B3E,CAp0BuG;qBAo0BvG,CA3zB2B;gBA2zB3B,CAvzBM;;;+BAuzBN,CAryB6B;;;6EA+wD3B,CAAC;wBACkB,eAAe,CAAC,OAAO,eAAe,EAAE,WAAW,CAAC;AAAzE,wBAA0E;AAa1E,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"CopilotKitProvider.vue.d.ts","sourceRoot":"","sources":["../../../src/v2/providers/CopilotKitProvider.vue"],"names":[],"mappings":"AA06BA,OAAO,KAAK,EAAE,SAAS,EAAuB,MAAM,KAAK,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAGV,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAuC1B,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC1B,eAAe,EAGhB,MAAM,UAAU,CAAC;AAs3BlB,QAAA,IAAI,OAAO,IAAW,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAyB/C,QAAA,MAAM,eAAe;;;;;;;;;;;;;wBA39BrB,CAh0BoB;mBAg0BpB,CA/zBS;;;;aA+zBT,CAvzByC;eAuzBzC,CAvzBkE;wBAuzBlE,CAtzBiB;qBAszBjB,CArxBgC;gBAqxBhC,CA5wBuB;;;+BA4wBvB,CA3vBa;;;6EA6tDX,CAAC;wBACkB,eAAe,CAAC,OAAO,eAAe,EAAE,WAAW,CAAC;AAAzE,wBAA0E;AAa1E,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/vue",
3
- "version": "2.0.0-rc.8",
3
+ "version": "2.0.0-rc.9",
4
4
  "private": false,
5
5
  "description": "Vue 3 components and composables for CopilotKit",
6
6
  "keywords": [
@@ -61,15 +61,14 @@
61
61
  "@a2ui/web_core": "0.10.4",
62
62
  "@ag-ui/client": "1.0.2",
63
63
  "@ag-ui/core": "1.0.2",
64
- "@copilotkit/core": "2.0.0-rc.8",
65
- "@copilotkit/markdown-renderer": "2.0.0-rc.8",
66
- "@copilotkit/mcp-apps-renderer": "2.0.0-rc.8",
67
- "@copilotkit/shared": "2.0.0-rc.8",
68
- "@copilotkit/web-components": "2.0.0-rc.8",
69
- "@copilotkit/web-inspector": "2.0.0-rc.8",
70
- "@jetbrains/websandbox": "^1.1.3",
71
- "zod": "^3.25.75",
72
- "zod-to-json-schema": "^3.24.5"
64
+ "@copilotkit/a2ui-renderer": "2.0.0-rc.9",
65
+ "@copilotkit/core": "2.0.0-rc.9",
66
+ "@copilotkit/markdown-renderer": "2.0.0-rc.9",
67
+ "@copilotkit/mcp-apps-renderer": "2.0.0-rc.9",
68
+ "@copilotkit/shared": "2.0.0-rc.9",
69
+ "@copilotkit/web-components": "2.0.0-rc.9",
70
+ "@copilotkit/web-inspector": "2.0.0-rc.9",
71
+ "zod": "^4.2.0"
73
72
  },
74
73
  "devDependencies": {
75
74
  "@eslint/js": "^9.39.2",
@@ -93,6 +92,7 @@
93
92
  "vue": "^3.5.28",
94
93
  "vue-eslint-parser": "^10.4.0",
95
94
  "vue-tsc": "^2.1.10",
95
+ "zod-v3": "npm:zod@^3.25.76",
96
96
  "@copilotkit/typescript-config": "1.55.0-next.8"
97
97
  },
98
98
  "peerDependencies": {
@@ -0,0 +1,520 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+ import { z } from "zod";
3
+ import type { Parameter } from "@copilotkit/shared";
4
+ import {
5
+ convertJsonSchemaToZodSchema,
6
+ getZodParameters,
7
+ } from "../zod-parameters";
8
+
9
+ describe("convertJsonSchemaToZodSchema", () => {
10
+ it("should convert a simple JSON schema to a Zod schema", () => {
11
+ const jsonSchema = {
12
+ type: "object",
13
+ properties: {
14
+ name: { type: "string" },
15
+ age: { type: "number" },
16
+ },
17
+ required: ["name", "age"],
18
+ };
19
+
20
+ const expectedSchema = z.object({
21
+ name: z.string(),
22
+ age: z.number(),
23
+ });
24
+
25
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
26
+ const resultSchemaJson = z.toJSONSchema(result);
27
+ const expectedSchemaJson = z.toJSONSchema(expectedSchema);
28
+
29
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
30
+ });
31
+
32
+ it("should convert a JSON schema with nested objects to a Zod schema", () => {
33
+ const jsonSchema = {
34
+ type: "object",
35
+ properties: {
36
+ name: { type: "string" },
37
+ address: {
38
+ type: "object",
39
+ properties: {
40
+ street: { type: "string" },
41
+ city: { type: "string" },
42
+ },
43
+ required: ["street", "city"],
44
+ },
45
+ },
46
+ required: ["name", "address"],
47
+ };
48
+
49
+ const expectedSchema = z.object({
50
+ name: z.string(),
51
+ address: z.object({
52
+ street: z.string(),
53
+ city: z.string(),
54
+ }),
55
+ });
56
+
57
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
58
+ const resultSchemaJson = z.toJSONSchema(result);
59
+ const expectedSchemaJson = z.toJSONSchema(expectedSchema);
60
+
61
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
62
+ });
63
+
64
+ it("should convert a JSON schema with arrays to a Zod schema", () => {
65
+ const jsonSchema = {
66
+ type: "object",
67
+ properties: {
68
+ names: {
69
+ type: "array",
70
+ items: { type: "string" },
71
+ },
72
+ },
73
+ required: ["names"],
74
+ };
75
+
76
+ const expectedSchema = z.object({
77
+ names: z.array(z.string()),
78
+ });
79
+
80
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
81
+ const resultSchemaJson = z.toJSONSchema(result);
82
+ const expectedSchemaJson = z.toJSONSchema(expectedSchema);
83
+
84
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
85
+ });
86
+
87
+ it("should convert a JSON schema with optional properties to a Zod schema", () => {
88
+ const jsonSchema = {
89
+ type: "object",
90
+ properties: {
91
+ name: { type: "string" },
92
+ age: { type: "number", required: false },
93
+ },
94
+ };
95
+
96
+ const expectedSchema = z
97
+ .object({
98
+ name: z.string().optional(),
99
+ age: z.number().optional(),
100
+ })
101
+ .optional();
102
+
103
+ const result = convertJsonSchemaToZodSchema(jsonSchema, false);
104
+
105
+ const resultSchemaJson = z.toJSONSchema(result);
106
+ const expectedSchemaJson = z.toJSONSchema(expectedSchema);
107
+
108
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
109
+ });
110
+
111
+ it("should convert a JSON schema with different types to a Zod schema", () => {
112
+ const jsonSchema = {
113
+ type: "object",
114
+ properties: {
115
+ name: { type: "string" },
116
+ age: { type: "number" },
117
+ isAdmin: { type: "boolean" },
118
+ },
119
+ required: ["name", "age", "isAdmin"],
120
+ };
121
+
122
+ const expectedSchema = z.object({
123
+ name: z.string(),
124
+ age: z.number(),
125
+ isAdmin: z.boolean(),
126
+ });
127
+
128
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
129
+ const resultSchemaJson = z.toJSONSchema(result);
130
+ const expectedSchemaJson = z.toJSONSchema(expectedSchema);
131
+
132
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
133
+ });
134
+
135
+ it("should handle edge case where JSON schema has no properties", () => {
136
+ const jsonSchema = {
137
+ type: "object",
138
+ };
139
+
140
+ const expectedSchema = z.object({});
141
+
142
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
143
+ const resultSchemaJson = z.toJSONSchema(result);
144
+ const expectedSchemaJson = z.toJSONSchema(expectedSchema);
145
+
146
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
147
+ });
148
+
149
+ it("should preserve string enum constraints", () => {
150
+ const jsonSchema = {
151
+ type: "object",
152
+ properties: {
153
+ status: {
154
+ type: "string",
155
+ description: "The status",
156
+ enum: ["todo", "done"],
157
+ },
158
+ },
159
+ required: ["status"],
160
+ };
161
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
162
+ const statusSchema = (result as z.ZodObject<any>).shape.status;
163
+ expect(statusSchema).toBeInstanceOf(z.ZodEnum);
164
+ expect(statusSchema.options).toEqual(["todo", "done"]);
165
+ });
166
+
167
+ it("should handle null-union type ['string', 'null'] as nullable", () => {
168
+ const jsonSchema = {
169
+ type: "object",
170
+ properties: {
171
+ nickname: {
172
+ type: ["string", "null"],
173
+ description: "Optional nickname",
174
+ },
175
+ },
176
+ required: ["nickname"],
177
+ };
178
+
179
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
180
+ const shape = (result as z.ZodObject<any>).shape;
181
+
182
+ // The nickname field should accept both string and null
183
+ expect(shape.nickname.safeParse("hello").success).toBe(true);
184
+ expect(shape.nickname.safeParse(null).success).toBe(true);
185
+ expect(shape.nickname.safeParse(42).success).toBe(false);
186
+ });
187
+
188
+ it("should handle null-union type ['number', 'null'] as nullable number", () => {
189
+ const jsonSchema = {
190
+ type: "object",
191
+ properties: {
192
+ score: {
193
+ type: ["number", "null"],
194
+ },
195
+ },
196
+ required: ["score"],
197
+ };
198
+
199
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
200
+ const shape = (result as z.ZodObject<any>).shape;
201
+
202
+ expect(shape.score.safeParse(42).success).toBe(true);
203
+ expect(shape.score.safeParse(null).success).toBe(true);
204
+ expect(shape.score.safeParse("hello").success).toBe(false);
205
+ });
206
+
207
+ it("should handle edge case where JSON schema has no required properties", () => {
208
+ const jsonSchema = {
209
+ type: "object",
210
+ properties: {
211
+ name: { type: "string" },
212
+ age: { type: "number" },
213
+ },
214
+ };
215
+
216
+ const expectedSchema = z
217
+ .object({
218
+ name: z.string().optional(),
219
+ age: z.number().optional(),
220
+ })
221
+ .optional();
222
+
223
+ const result = convertJsonSchemaToZodSchema(jsonSchema, false);
224
+ const resultSchemaJson = z.toJSONSchema(result);
225
+ const expectedSchemaJson = z.toJSONSchema(expectedSchema);
226
+
227
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
228
+ });
229
+
230
+ it("should resolve non-circular $ref definitions correctly", () => {
231
+ const jsonSchema = {
232
+ type: "object",
233
+ properties: {
234
+ address: { $ref: "#/$defs/Address" },
235
+ },
236
+ required: ["address"],
237
+ $defs: {
238
+ Address: {
239
+ type: "object",
240
+ properties: {
241
+ street: { type: "string", description: "Street name" },
242
+ city: { type: "string", description: "City name" },
243
+ },
244
+ required: ["street", "city"],
245
+ description: "A postal address",
246
+ },
247
+ },
248
+ };
249
+
250
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
251
+ const resultJson = z.toJSONSchema(result);
252
+
253
+ const expectedSchema = z.object({
254
+ address: z
255
+ .object({
256
+ street: z.string().describe("Street name"),
257
+ city: z.string().describe("City name"),
258
+ })
259
+ .describe("A postal address"),
260
+ });
261
+ const expectedJson = z.toJSONSchema(expectedSchema);
262
+
263
+ expect(resultJson).toStrictEqual(expectedJson);
264
+ });
265
+
266
+ it("should handle circular $ref without crashing and return z.any()", () => {
267
+ // A schema where Node references itself — this would cause infinite
268
+ // recursion without cycle detection.
269
+ const jsonSchema = {
270
+ type: "object",
271
+ properties: {
272
+ root: { $ref: "#/$defs/Node" },
273
+ },
274
+ required: ["root"],
275
+ $defs: {
276
+ Node: {
277
+ type: "object",
278
+ properties: {
279
+ value: { type: "string", description: "Node value" },
280
+ child: { $ref: "#/$defs/Node" },
281
+ },
282
+ required: ["value"],
283
+ description: "A tree node",
284
+ },
285
+ },
286
+ };
287
+
288
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
289
+
290
+ // Must not throw or hang
291
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
292
+ expect(result).toBeDefined();
293
+
294
+ // The circular ref should have produced a console.warn
295
+ expect(warnSpy).toHaveBeenCalledWith(
296
+ expect.stringContaining("Circular $ref detected"),
297
+ );
298
+
299
+ // The top-level shape should still have a "root" key that is an object
300
+ const shape = (result as z.ZodObject<any>).shape;
301
+ expect(shape.root).toBeDefined();
302
+
303
+ // Inside root, "value" should be a string and "child" should be z.any()
304
+ // (child is optional since it's not in required[], so unwrap ZodOptional)
305
+ const rootShape = (shape.root as z.ZodObject<any>).shape;
306
+ expect(rootShape.value).toBeInstanceOf(z.ZodString);
307
+ const child = rootShape.child;
308
+ if (child instanceof z.ZodOptional) {
309
+ expect(child.unwrap()).toBeInstanceOf(z.ZodAny);
310
+ } else {
311
+ expect(child).toBeInstanceOf(z.ZodAny);
312
+ }
313
+
314
+ warnSpy.mockRestore();
315
+ });
316
+
317
+ it("should resolve the same $ref used by multiple sibling properties", () => {
318
+ // Two properties reference the same $def — the visited set must NOT
319
+ // mark the second usage as circular.
320
+ const jsonSchema = {
321
+ type: "object",
322
+ properties: {
323
+ billing: { $ref: "#/$defs/Address" },
324
+ shipping: { $ref: "#/$defs/Address" },
325
+ },
326
+ required: ["billing", "shipping"],
327
+ $defs: {
328
+ Address: {
329
+ type: "object",
330
+ properties: {
331
+ street: { type: "string", description: "Street" },
332
+ city: { type: "string", description: "City" },
333
+ },
334
+ required: ["street", "city"],
335
+ description: "An address",
336
+ },
337
+ },
338
+ };
339
+
340
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
341
+
342
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
343
+ const shape = (result as z.ZodObject<any>).shape;
344
+
345
+ // Both should be fully resolved objects, NOT z.any()
346
+ expect(shape.billing).toBeInstanceOf(z.ZodObject);
347
+ expect(shape.shipping).toBeInstanceOf(z.ZodObject);
348
+
349
+ // No circular-ref warning should have been emitted
350
+ expect(warnSpy).not.toHaveBeenCalled();
351
+
352
+ warnSpy.mockRestore();
353
+ });
354
+
355
+ it("should resolve a shared $ref used in different branches of a $ref chain", () => {
356
+ // Wrapper -> Container (via $ref) which has two children both using $ref to Leaf.
357
+ // Without set cloning, the second Leaf ref in Container would be wrongly flagged
358
+ // as circular because the first Leaf resolution already added it to the set.
359
+ const jsonSchema = {
360
+ type: "object",
361
+ properties: {
362
+ wrapper: { $ref: "#/$defs/Container" },
363
+ },
364
+ required: ["wrapper"],
365
+ $defs: {
366
+ Container: {
367
+ type: "object",
368
+ properties: {
369
+ first: { $ref: "#/$defs/Leaf" },
370
+ second: { $ref: "#/$defs/Leaf" },
371
+ },
372
+ required: ["first", "second"],
373
+ description: "A container with two leaves",
374
+ },
375
+ Leaf: {
376
+ type: "object",
377
+ properties: {
378
+ label: { type: "string", description: "Leaf label" },
379
+ },
380
+ required: ["label"],
381
+ description: "A leaf node",
382
+ },
383
+ },
384
+ };
385
+
386
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
387
+
388
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
389
+ const wrapperShape = (
390
+ (result as z.ZodObject<any>).shape.wrapper as z.ZodObject<any>
391
+ ).shape;
392
+
393
+ // Both first and second should be fully resolved Leaf objects
394
+ expect(wrapperShape.first).toBeInstanceOf(z.ZodObject);
395
+ expect(wrapperShape.second).toBeInstanceOf(z.ZodObject);
396
+
397
+ // No circular-ref warning should have been emitted
398
+ expect(warnSpy).not.toHaveBeenCalled();
399
+
400
+ warnSpy.mockRestore();
401
+ });
402
+
403
+ it("should handle anyOf with $ref variants", () => {
404
+ const jsonSchema = {
405
+ type: "object",
406
+ properties: {
407
+ pet: {
408
+ anyOf: [{ $ref: "#/$defs/Cat" }, { $ref: "#/$defs/Dog" }],
409
+ description: "A pet",
410
+ },
411
+ },
412
+ required: ["pet"],
413
+ $defs: {
414
+ Cat: {
415
+ type: "object",
416
+ properties: { meow: { type: "boolean" } },
417
+ required: ["meow"],
418
+ },
419
+ Dog: {
420
+ type: "object",
421
+ properties: { bark: { type: "boolean" } },
422
+ required: ["bark"],
423
+ },
424
+ },
425
+ };
426
+
427
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
428
+ expect(result).toBeDefined();
429
+
430
+ // Should produce a union inside the "pet" property
431
+ const petSchema = (result as z.ZodObject<any>).shape.pet;
432
+ expect(petSchema).toBeInstanceOf(z.ZodUnion);
433
+ });
434
+
435
+ it("should handle integer type as z.number()", () => {
436
+ const jsonSchema = {
437
+ type: "object",
438
+ properties: {
439
+ count: { type: "integer", description: "A count" },
440
+ },
441
+ required: ["count"],
442
+ };
443
+
444
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
445
+ const shape = (result as z.ZodObject<any>).shape;
446
+ expect(shape.count).toBeInstanceOf(z.ZodNumber);
447
+ });
448
+
449
+ it("should handle null type", () => {
450
+ const jsonSchema = {
451
+ type: "object",
452
+ properties: {
453
+ empty: { type: "null", description: "Always null" },
454
+ },
455
+ required: ["empty"],
456
+ };
457
+
458
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
459
+ const shape = (result as z.ZodObject<any>).shape;
460
+ expect(shape.empty).toBeInstanceOf(z.ZodNull);
461
+ });
462
+
463
+ it("should warn and return z.any() for unsupported schema types", () => {
464
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
465
+
466
+ const jsonSchema = { type: "custom_unsupported" };
467
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
468
+
469
+ expect(result).toBeInstanceOf(z.ZodAny);
470
+ expect(warnSpy).toHaveBeenCalledWith(
471
+ expect.stringContaining(
472
+ 'Unsupported JSON schema type "custom_unsupported"',
473
+ ),
474
+ );
475
+
476
+ warnSpy.mockRestore();
477
+ });
478
+ });
479
+
480
+ describe("getZodParameters", () => {
481
+ it("returns an empty object schema without parameters", () => {
482
+ expect(z.toJSONSchema(getZodParameters(undefined))).toStrictEqual(
483
+ z.toJSONSchema(z.object({})),
484
+ );
485
+ });
486
+
487
+ it("converts v1 parameters to a Zod object schema", () => {
488
+ const parameters: Parameter[] = [
489
+ { name: "name", type: "string", description: "User name" },
490
+ { name: "age", type: "number", required: false },
491
+ { name: "role", type: "string", enum: ["admin", "user"] },
492
+ {
493
+ name: "address",
494
+ type: "object",
495
+ attributes: [{ name: "city", type: "string" }],
496
+ },
497
+ { name: "tags", type: "string[]" },
498
+ ];
499
+
500
+ const schema = getZodParameters(parameters);
501
+
502
+ expect(
503
+ schema.safeParse({
504
+ name: "Ada",
505
+ role: "admin",
506
+ address: { city: "London" },
507
+ tags: ["a"],
508
+ }).success,
509
+ ).toBe(true);
510
+ expect(
511
+ schema.safeParse({
512
+ name: "Ada",
513
+ role: "owner",
514
+ address: { city: "London" },
515
+ tags: [],
516
+ }).success,
517
+ ).toBe(false);
518
+ expect(schema.safeParse({ role: "user" }).success).toBe(false);
519
+ });
520
+ });
@@ -7,7 +7,8 @@
7
7
  import type { WatchSource } from "vue";
8
8
  import type { WebMCPToolConfig } from "@copilotkit/core";
9
9
  import type { Parameter, MappedParameterTypes } from "@copilotkit/shared";
10
- import { getZodParameters, parseJson } from "@copilotkit/shared";
10
+ import { parseJson } from "@copilotkit/shared";
11
+ import { getZodParameters } from "./zod-parameters";
11
12
  import { useFrontendTool as useFrontendToolV2 } from "../v2/hooks/use-frontend-tool";
12
13
  import { useHumanInTheLoop as useHumanInTheLoopV2 } from "../v2/hooks/use-human-in-the-loop";
13
14
  import { useRenderTool as useRenderToolV2 } from "../v2/hooks/use-render-tool";
@@ -6,12 +6,9 @@
6
6
  */
7
7
  import type { WatchSource } from "vue";
8
8
  import type { WebMCPToolConfig } from "@copilotkit/core";
9
- import {
10
- type Parameter,
11
- type MappedParameterTypes,
12
- getZodParameters,
13
- parseJson,
14
- } from "@copilotkit/shared";
9
+ import { parseJson } from "@copilotkit/shared";
10
+ import type { Parameter, MappedParameterTypes } from "@copilotkit/shared";
11
+ import { getZodParameters } from "./zod-parameters";
15
12
  import { useFrontendTool as useFrontendToolV2 } from "../v2/hooks/use-frontend-tool";
16
13
  import type { VueFrontendTool } from "../v2/types";
17
14