@copilotkit/shared 1.84.0 → 1.84.2-canary.1793807121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "1.84.0";
3
+ var version = "1.84.2-canary.1793807121";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.84.0";
2
+ var version = "1.84.2-canary.1793807121";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/shared",
3
- "version": "1.84.0",
3
+ "version": "1.84.2-canary.1793807121",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@ag-ui/a2ui-middleware": "0.0.10",
60
- "@ag-ui/client": "1.0.2",
60
+ "@ag-ui/client": "1.0.4-canary.1793805408.0",
61
61
  "@copilotkit/license-verifier": "~0.5.0",
62
62
  "@segment/analytics-node": "^2.1.2",
63
63
  "@standard-schema/spec": "^1.0.0",
@@ -70,7 +70,7 @@
70
70
  "zod-to-json-schema": "^3.23.5"
71
71
  },
72
72
  "devDependencies": {
73
- "@ag-ui/core": "1.0.2",
73
+ "@ag-ui/core": "1.0.4-canary.1793805408.0",
74
74
  "@types/clarinet": "^0.12.3",
75
75
  "@types/uuid": "^10.0.0",
76
76
  "@valibot/to-json-schema": "^1.5.0",
@@ -0,0 +1,403 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { z } from "zod";
3
+ import {
4
+ buildA2UICatalogContextValue,
5
+ extractA2UICatalogSchemas,
6
+ serializeA2UISchema,
7
+ } from "../a2ui-catalog-schema";
8
+ import type { A2UICatalogSchemaSource } from "../a2ui-catalog-schema";
9
+
10
+ function catalog(
11
+ components: Record<string, z.ZodTypeAny>,
12
+ extra: Partial<A2UICatalogSchemaSource> = {},
13
+ ): A2UICatalogSchemaSource {
14
+ return {
15
+ id: "copilotkit://test",
16
+ components: new Map(
17
+ Object.entries(components).map(([name, schema]) => [name, { schema }]),
18
+ ),
19
+ ...extra,
20
+ };
21
+ }
22
+
23
+ function props(
24
+ schema: ReturnType<typeof extractA2UICatalogSchemas>,
25
+ name: string,
26
+ ) {
27
+ const allOf = schema.components[name].allOf as {
28
+ properties: Record<string, Record<string, unknown>>;
29
+ }[];
30
+ return allOf[1].properties;
31
+ }
32
+
33
+ function commonTypes(schema: ReturnType<typeof extractA2UICatalogSchemas>) {
34
+ return schema["common_types.json"]?.$defs ?? {};
35
+ }
36
+
37
+ afterEach(() => {
38
+ vi.restoreAllMocks();
39
+ });
40
+
41
+ describe("extractA2UICatalogSchemas", () => {
42
+ it("replaces a REF marker with a bare $ref and stores its shape once", () => {
43
+ const action = () =>
44
+ z
45
+ .object({ event: z.object({ name: z.string() }) })
46
+ .describe("REF:common_types.json#/$defs/Action|Click action");
47
+ const schema = extractA2UICatalogSchemas(
48
+ catalog({
49
+ Button: z.object({
50
+ action: action(),
51
+ child: z
52
+ .string()
53
+ .describe("REF:common_types.json#/$defs/ComponentId"),
54
+ }),
55
+ Link: z.object({ action: action() }),
56
+ }),
57
+ );
58
+
59
+ expect(props(schema, "Button").action).toEqual({
60
+ $ref: "common_types.json#/$defs/Action",
61
+ description: "Click action",
62
+ });
63
+ expect(props(schema, "Link").action).toEqual(
64
+ props(schema, "Button").action,
65
+ );
66
+ expect(props(schema, "Button").child).toEqual({
67
+ $ref: "common_types.json#/$defs/ComponentId",
68
+ });
69
+ expect(commonTypes(schema)).toEqual({
70
+ Action: {
71
+ type: "object",
72
+ properties: {
73
+ event: {
74
+ type: "object",
75
+ properties: { name: { type: "string" } },
76
+ required: ["name"],
77
+ additionalProperties: false,
78
+ },
79
+ },
80
+ required: ["event"],
81
+ additionalProperties: false,
82
+ },
83
+ ComponentId: { type: "string" },
84
+ });
85
+ expect(JSON.stringify(schema)).not.toContain("REF:");
86
+ });
87
+
88
+ it("omits the common types block when nothing references one", () => {
89
+ const schema = extractA2UICatalogSchemas(
90
+ catalog({ Text: z.object({ text: z.string() }) }),
91
+ );
92
+
93
+ expect(schema).not.toHaveProperty(["common_types.json"]);
94
+ });
95
+
96
+ it("keeps a use whose shape differs from the stored type inline", () => {
97
+ const schema = extractA2UICatalogSchemas(
98
+ catalog({
99
+ Text: z.object({
100
+ text: z
101
+ .union([z.string(), z.object({ path: z.string() })])
102
+ .describe("REF:common_types.json#/$defs/DynamicString"),
103
+ }),
104
+ Badge: z.object({
105
+ label: z
106
+ .string()
107
+ .describe("REF:common_types.json#/$defs/DynamicString|Label"),
108
+ }),
109
+ }),
110
+ );
111
+
112
+ expect(props(schema, "Text").text).toEqual({
113
+ $ref: "common_types.json#/$defs/DynamicString",
114
+ });
115
+ expect(props(schema, "Badge").label).toEqual({
116
+ $ref: "common_types.json#/$defs/DynamicString",
117
+ description: "Label",
118
+ type: "string",
119
+ });
120
+ expect(commonTypes(schema).DynamicString).toMatchObject({
121
+ anyOf: [{ type: "string" }, { type: "object" }],
122
+ });
123
+ });
124
+
125
+ it("stores nested common types by bare $ref too", () => {
126
+ const dynamicString = z
127
+ .union([z.string(), z.object({ path: z.string() })])
128
+ .describe("REF:common_types.json#/$defs/DynamicString");
129
+ const schema = extractA2UICatalogSchemas(
130
+ catalog({
131
+ Card: z.object({
132
+ action: z
133
+ .object({ label: dynamicString })
134
+ .describe("REF:common_types.json#/$defs/Action"),
135
+ }),
136
+ }),
137
+ );
138
+
139
+ expect(props(schema, "Card").action).toEqual({
140
+ $ref: "common_types.json#/$defs/Action",
141
+ });
142
+ expect(commonTypes(schema).Action).toMatchObject({
143
+ properties: {
144
+ label: { $ref: "common_types.json#/$defs/DynamicString" },
145
+ },
146
+ });
147
+ expect(commonTypes(schema).DynamicString).toMatchObject({
148
+ anyOf: [{ type: "string" }, { properties: { path: { type: "string" } } }],
149
+ });
150
+ });
151
+
152
+ it("keeps the full description text after the first |", () => {
153
+ const schema = extractA2UICatalogSchemas(
154
+ catalog({
155
+ Badge: z.object({
156
+ status: z
157
+ .string()
158
+ .describe(
159
+ "REF:common_types.json#/$defs/DynamicString|Shown when status is 'open' | 'closed'",
160
+ ),
161
+ }),
162
+ }),
163
+ );
164
+
165
+ expect(props(schema, "Badge").status.description).toBe(
166
+ "Shown when status is 'open' | 'closed'",
167
+ );
168
+ });
169
+
170
+ it("does not rewrite or mutate literal default values", () => {
171
+ const fallback = { description: "REF:common_types.json#/$defs/Action|x" };
172
+ const schema = extractA2UICatalogSchemas(
173
+ catalog({
174
+ Widget: z.object({
175
+ meta: z.record(z.string(), z.string()).default(fallback),
176
+ }),
177
+ }),
178
+ );
179
+
180
+ expect(props(schema, "Widget").meta.default).toEqual({
181
+ description: "REF:common_types.json#/$defs/Action|x",
182
+ });
183
+ expect(fallback).toEqual({
184
+ description: "REF:common_types.json#/$defs/Action|x",
185
+ });
186
+ });
187
+
188
+ it("still resolves REF markers on a property named default", () => {
189
+ const schema = extractA2UICatalogSchemas(
190
+ catalog({
191
+ Picker: z.object({
192
+ default: z
193
+ .string()
194
+ .describe("REF:common_types.json#/$defs/ComponentId"),
195
+ }),
196
+ }),
197
+ );
198
+
199
+ expect(props(schema, "Picker").default.$ref).toBe(
200
+ "common_types.json#/$defs/ComponentId",
201
+ );
202
+ });
203
+
204
+ it("inlines reused schemas so no local $ref is left dangling", () => {
205
+ const label = z.string().describe("Label text");
206
+ const theme = z.object({
207
+ heading: z
208
+ .object({ font: label })
209
+ .describe("REF:common_types.json#/$defs/Typography"),
210
+ body: z.object({ font: label }),
211
+ });
212
+ const schema = extractA2UICatalogSchemas(
213
+ catalog(
214
+ {
215
+ Header: z.object({ title: label, subtitle: label }),
216
+ },
217
+ { themeSchema: theme },
218
+ ),
219
+ );
220
+
221
+ expect(JSON.stringify(schema)).not.toContain('"$ref":"#/');
222
+ expect(props(schema, "Header").subtitle).toEqual({
223
+ type: "string",
224
+ description: "Label text",
225
+ });
226
+ expect(schema.theme?.body).toMatchObject({
227
+ properties: { font: { type: "string" } },
228
+ });
229
+ expect(schema.theme?.heading).toEqual({
230
+ $ref: "common_types.json#/$defs/Typography",
231
+ });
232
+ expect(commonTypes(schema).Typography).toMatchObject({
233
+ properties: { font: { type: "string", description: "Label text" } },
234
+ });
235
+ });
236
+
237
+ it("turns a recursive reference into an any schema without warning", () => {
238
+ interface TreeNode {
239
+ label: string;
240
+ children?: TreeNode[];
241
+ }
242
+ const treeNode: z.ZodType<TreeNode> = z.lazy(() =>
243
+ z.object({ label: z.string(), children: z.array(treeNode).optional() }),
244
+ );
245
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
246
+
247
+ const schema = extractA2UICatalogSchemas(
248
+ catalog({ Tree: z.object({ root: treeNode }) }),
249
+ );
250
+
251
+ expect(props(schema, "Tree").root).toMatchObject({
252
+ type: "object",
253
+ properties: {
254
+ label: { type: "string" },
255
+ children: { type: "array", items: {} },
256
+ },
257
+ });
258
+ expect(warn).not.toHaveBeenCalled();
259
+ });
260
+
261
+ it("keeps a component named __proto__ as a regular entry", () => {
262
+ const schema = extractA2UICatalogSchemas({
263
+ id: "copilotkit://test",
264
+ components: new Map([
265
+ ["__proto__", { schema: z.object({ text: z.string() }) }],
266
+ ]),
267
+ });
268
+
269
+ expect(Object.keys(schema.components)).toEqual(["__proto__"]);
270
+ expect(JSON.parse(JSON.stringify(schema)).components).toHaveProperty(
271
+ "__proto__",
272
+ );
273
+ });
274
+
275
+ it("does not throw on default values structuredClone cannot copy", () => {
276
+ const schema = extractA2UICatalogSchemas(
277
+ catalog({
278
+ Widget: z.object({
279
+ meta: z
280
+ .object({ label: z.string() })
281
+ .passthrough()
282
+ .default({ label: "x", onClick: () => {} } as { label: string }),
283
+ }),
284
+ }),
285
+ );
286
+
287
+ expect(props(schema, "Widget").meta.default).toEqual({ label: "x" });
288
+ });
289
+
290
+ it("keeps a component's root description", () => {
291
+ const schema = extractA2UICatalogSchemas(
292
+ catalog({
293
+ FlightCard: z
294
+ .object({ airline: z.string() })
295
+ .describe("Shows one flight"),
296
+ }),
297
+ );
298
+
299
+ expect(schema.components.FlightCard.description).toBe("Shows one flight");
300
+ });
301
+
302
+ it("exports functions with REF-stripped root descriptions and no $schema", () => {
303
+ const schema = extractA2UICatalogSchemas(
304
+ catalog(
305
+ {},
306
+ {
307
+ functions: new Map([
308
+ [
309
+ "format",
310
+ {
311
+ name: "format",
312
+ returnType: "string",
313
+ schema: z
314
+ .object({ value: z.string() })
315
+ .describe(
316
+ "REF:common_types.json#/$defs/FunctionCall|Formats a value",
317
+ ),
318
+ },
319
+ ],
320
+ ]),
321
+ },
322
+ ),
323
+ );
324
+
325
+ expect(schema.functions).toEqual([
326
+ {
327
+ name: "format",
328
+ description: "Formats a value",
329
+ returnType: "string",
330
+ parameters: {
331
+ type: "object",
332
+ properties: { value: { type: "string" } },
333
+ required: ["value"],
334
+ additionalProperties: false,
335
+ },
336
+ },
337
+ ]);
338
+ });
339
+
340
+ it("tolerates catalog-shaped objects with non-Map or partial functions", () => {
341
+ const fn = {
342
+ name: "upper",
343
+ returnType: "string",
344
+ schema: z.object({ value: z.string() }),
345
+ };
346
+
347
+ for (const functions of [
348
+ undefined,
349
+ { upper: fn },
350
+ [fn, { name: "broken" }, null],
351
+ ]) {
352
+ const schema = extractA2UICatalogSchemas(
353
+ catalog({ Text: z.object({ text: z.string() }) }, { functions }),
354
+ );
355
+ expect(schema.functions?.map((f) => f.name)).toEqual(
356
+ functions ? ["upper"] : undefined,
357
+ );
358
+ }
359
+ });
360
+ });
361
+
362
+ describe("serializeA2UISchema", () => {
363
+ it("returns an independent copy on every call", () => {
364
+ const zodSchema = z.object({ name: z.string() });
365
+
366
+ const first = serializeA2UISchema(zodSchema);
367
+ (first.properties as Record<string, unknown>).name = "mutated";
368
+
369
+ expect(serializeA2UISchema(zodSchema)).toMatchObject({
370
+ properties: { name: { type: "string" } },
371
+ });
372
+ });
373
+ });
374
+
375
+ describe("buildA2UICatalogContextValue", () => {
376
+ it("describes custom components with the same REF handling as the schema", () => {
377
+ const value = buildA2UICatalogContextValue(
378
+ catalog({
379
+ Text: z.object({ text: z.string() }),
380
+ Card: z.object({
381
+ child: z
382
+ .string()
383
+ .describe("REF:common_types.json#/$defs/ComponentId|Card body"),
384
+ }),
385
+ }),
386
+ new Set(["Text", "Image"]),
387
+ );
388
+
389
+ expect(value).toContain(
390
+ " Custom catalog (does NOT include all basic components).",
391
+ );
392
+ expect(value).toContain(" - Card:");
393
+ expect(value).not.toContain(" - Text:");
394
+ expect(value).toContain('"$ref": "common_types.json#/$defs/ComponentId"');
395
+ expect(value).toContain('"description": "Card body"');
396
+ expect(value).toContain(
397
+ " Common types referenced above (common_types.json#/$defs):",
398
+ );
399
+ expect(value).toContain('"ComponentId": {');
400
+ expect(value).toContain('"type": "string"');
401
+ expect(value).not.toContain("REF:");
402
+ });
403
+ });