@copilotkit/shared 2.0.0-rc.1 → 2.0.0-rc.11

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 (220) hide show
  1. package/README.md +3 -14
  2. package/dist/a2ui-prompts.cjs +21 -62
  3. package/dist/a2ui-prompts.cjs.map +1 -1
  4. package/dist/a2ui-prompts.d.cts +8 -1
  5. package/dist/a2ui-prompts.d.cts.map +1 -1
  6. package/dist/a2ui-prompts.d.mts +8 -1
  7. package/dist/a2ui-prompts.d.mts.map +1 -1
  8. package/dist/a2ui-prompts.mjs +22 -62
  9. package/dist/a2ui-prompts.mjs.map +1 -1
  10. package/dist/generative-ui/basic-functions.cjs +1 -1
  11. package/dist/generative-ui/basic-functions.cjs.map +1 -1
  12. package/dist/generative-ui/basic-functions.mjs +1 -1
  13. package/dist/generative-ui/basic-functions.mjs.map +1 -1
  14. package/dist/generative-ui/compact-schema.cjs +187 -0
  15. package/dist/generative-ui/compact-schema.cjs.map +1 -0
  16. package/dist/generative-ui/compact-schema.d.cts +55 -0
  17. package/dist/generative-ui/compact-schema.d.cts.map +1 -0
  18. package/dist/generative-ui/compact-schema.d.mts +55 -0
  19. package/dist/generative-ui/compact-schema.d.mts.map +1 -0
  20. package/dist/generative-ui/compact-schema.mjs +185 -0
  21. package/dist/generative-ui/compact-schema.mjs.map +1 -0
  22. package/dist/generative-ui/prompt-spec.cjs +225 -0
  23. package/dist/generative-ui/prompt-spec.cjs.map +1 -0
  24. package/dist/generative-ui/prompt-spec.d.cts +94 -0
  25. package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
  26. package/dist/generative-ui/prompt-spec.d.mts +94 -0
  27. package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
  28. package/dist/generative-ui/prompt-spec.mjs +220 -0
  29. package/dist/generative-ui/prompt-spec.mjs.map +1 -0
  30. package/dist/generative-ui/prompt.cjs +10 -36
  31. package/dist/generative-ui/prompt.cjs.map +1 -1
  32. package/dist/generative-ui/prompt.d.cts +2 -1
  33. package/dist/generative-ui/prompt.d.cts.map +1 -1
  34. package/dist/generative-ui/prompt.d.mts +2 -1
  35. package/dist/generative-ui/prompt.d.mts.map +1 -1
  36. package/dist/generative-ui/prompt.mjs +12 -38
  37. package/dist/generative-ui/prompt.mjs.map +1 -1
  38. package/dist/generative-ui/schema-render.cjs +242 -0
  39. package/dist/generative-ui/schema-render.cjs.map +1 -0
  40. package/dist/generative-ui/schema-render.d.cts +44 -0
  41. package/dist/generative-ui/schema-render.d.cts.map +1 -0
  42. package/dist/generative-ui/schema-render.d.mts +44 -0
  43. package/dist/generative-ui/schema-render.d.mts.map +1 -0
  44. package/dist/generative-ui/schema-render.mjs +239 -0
  45. package/dist/generative-ui/schema-render.mjs.map +1 -0
  46. package/dist/index.cjs +17 -15
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.cts +10 -9
  49. package/dist/index.d.cts.map +1 -1
  50. package/dist/index.d.mts +10 -9
  51. package/dist/index.d.mts.map +1 -1
  52. package/dist/index.mjs +9 -7
  53. package/dist/index.mjs.map +1 -1
  54. package/dist/index.umd.js +808 -438
  55. package/dist/index.umd.js.map +1 -1
  56. package/dist/package.cjs +1 -1
  57. package/dist/package.mjs +1 -1
  58. package/dist/standard-schema.cjs +20 -7
  59. package/dist/standard-schema.cjs.map +1 -1
  60. package/dist/standard-schema.d.cts +15 -16
  61. package/dist/standard-schema.d.cts.map +1 -1
  62. package/dist/standard-schema.d.mts +15 -16
  63. package/dist/standard-schema.d.mts.map +1 -1
  64. package/dist/standard-schema.mjs +20 -8
  65. package/dist/standard-schema.mjs.map +1 -1
  66. package/dist/telemetry/lambda-client.cjs.map +1 -1
  67. package/dist/telemetry/lambda-client.d.cts.map +1 -1
  68. package/dist/telemetry/lambda-client.d.mts.map +1 -1
  69. package/dist/telemetry/lambda-client.mjs.map +1 -1
  70. package/dist/telemetry/telemetry-disabled.cjs +3 -6
  71. package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
  72. package/dist/telemetry/telemetry-disabled.d.cts +0 -5
  73. package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
  74. package/dist/telemetry/telemetry-disabled.d.mts +0 -5
  75. package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
  76. package/dist/telemetry/telemetry-disabled.mjs +4 -6
  77. package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
  78. package/dist/types/message.d.cts +1 -18
  79. package/dist/types/message.d.cts.map +1 -1
  80. package/dist/types/message.d.mts +1 -18
  81. package/dist/types/message.d.mts.map +1 -1
  82. package/dist/utils/errors.cjs +4 -42
  83. package/dist/utils/errors.cjs.map +1 -1
  84. package/dist/utils/errors.d.cts +16 -34
  85. package/dist/utils/errors.d.cts.map +1 -1
  86. package/dist/utils/errors.d.mts +16 -34
  87. package/dist/utils/errors.d.mts.map +1 -1
  88. package/dist/utils/errors.mjs +5 -41
  89. package/dist/utils/errors.mjs.map +1 -1
  90. package/dist/utils/index.cjs +1 -2
  91. package/dist/utils/index.cjs.map +1 -1
  92. package/dist/utils/index.d.cts +4 -5
  93. package/dist/utils/index.d.cts.map +1 -1
  94. package/dist/utils/index.d.mts +4 -5
  95. package/dist/utils/index.d.mts.map +1 -1
  96. package/dist/utils/index.mjs +4 -5
  97. package/dist/utils/index.mjs.map +1 -1
  98. package/dist/utils/json-schema.cjs +0 -79
  99. package/dist/utils/json-schema.cjs.map +1 -1
  100. package/dist/utils/json-schema.d.cts +1 -4
  101. package/dist/utils/json-schema.d.cts.map +1 -1
  102. package/dist/utils/json-schema.d.mts +1 -4
  103. package/dist/utils/json-schema.d.mts.map +1 -1
  104. package/dist/utils/json-schema.mjs +1 -78
  105. package/dist/utils/json-schema.mjs.map +1 -1
  106. package/dist/utils/process-env.cjs +14 -0
  107. package/dist/utils/process-env.cjs.map +1 -0
  108. package/dist/utils/process-env.d.cts +10 -0
  109. package/dist/utils/process-env.d.cts.map +1 -0
  110. package/dist/utils/process-env.d.mts +10 -0
  111. package/dist/utils/process-env.d.mts.map +1 -0
  112. package/dist/utils/process-env.mjs +13 -0
  113. package/dist/utils/process-env.mjs.map +1 -0
  114. package/dist/utils/random-id.cjs +13 -26
  115. package/dist/utils/random-id.cjs.map +1 -1
  116. package/dist/utils/random-id.d.cts +6 -3
  117. package/dist/utils/random-id.d.cts.map +1 -1
  118. package/dist/utils/random-id.d.mts +6 -3
  119. package/dist/utils/random-id.d.mts.map +1 -1
  120. package/dist/utils/random-id.mjs +14 -25
  121. package/dist/utils/random-id.mjs.map +1 -1
  122. package/package.json +7 -31
  123. package/src/__tests__/a2ui-prompts.test.ts +42 -9
  124. package/src/__tests__/fixtures/prompt-goldens.json +354 -0
  125. package/src/__tests__/prompt-spec.test.ts +191 -0
  126. package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
  127. package/src/__tests__/schema-render.test.ts +245 -0
  128. package/src/__tests__/standard-schema.test.ts +61 -101
  129. package/src/a2ui-prompts.ts +47 -96
  130. package/src/generative-ui/basic-functions.ts +1 -1
  131. package/src/generative-ui/compact-schema.ts +277 -0
  132. package/src/generative-ui/index.ts +3 -0
  133. package/src/generative-ui/prompt-spec.ts +335 -0
  134. package/src/generative-ui/prompt.ts +25 -75
  135. package/src/generative-ui/schema-render.ts +374 -0
  136. package/src/index.ts +3 -16
  137. package/src/standard-schema.ts +24 -27
  138. package/src/telemetry/lambda-client.ts +3 -2
  139. package/src/telemetry/telemetry-disabled.ts +7 -12
  140. package/src/types/message.ts +1 -19
  141. package/src/utils/__tests__/errors.test.ts +44 -0
  142. package/src/utils/__tests__/json-schema.test.ts +3 -479
  143. package/src/utils/__tests__/process-env.test.ts +22 -0
  144. package/src/utils/__tests__/random-id.test.ts +37 -0
  145. package/src/utils/errors.ts +27 -85
  146. package/src/utils/index.ts +1 -2
  147. package/src/utils/json-schema.ts +1 -152
  148. package/src/utils/process-env.ts +14 -0
  149. package/src/utils/random-id.ts +17 -37
  150. package/tsdown.config.ts +2 -19
  151. package/dist/event-transforms/index.cjs +0 -15
  152. package/dist/event-transforms/index.d.cts +0 -4
  153. package/dist/event-transforms/index.d.mts +0 -4
  154. package/dist/event-transforms/index.mjs +0 -5
  155. package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
  156. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
  157. package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
  158. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
  159. package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
  160. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
  161. package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
  162. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
  163. package/dist/event-transforms/recorded-events.cjs +0 -59
  164. package/dist/event-transforms/recorded-events.cjs.map +0 -1
  165. package/dist/event-transforms/recorded-events.d.cts +0 -23
  166. package/dist/event-transforms/recorded-events.d.cts.map +0 -1
  167. package/dist/event-transforms/recorded-events.d.mts +0 -23
  168. package/dist/event-transforms/recorded-events.d.mts.map +0 -1
  169. package/dist/event-transforms/recorded-events.mjs +0 -58
  170. package/dist/event-transforms/recorded-events.mjs.map +0 -1
  171. package/dist/telemetry/events.d.cts +0 -72
  172. package/dist/telemetry/events.d.cts.map +0 -1
  173. package/dist/telemetry/events.d.mts +0 -72
  174. package/dist/telemetry/events.d.mts.map +0 -1
  175. package/dist/telemetry/index.cjs +0 -18
  176. package/dist/telemetry/index.d.cts +0 -5
  177. package/dist/telemetry/index.d.mts +0 -5
  178. package/dist/telemetry/index.mjs +0 -6
  179. package/dist/telemetry/telemetry-client.cjs +0 -165
  180. package/dist/telemetry/telemetry-client.cjs.map +0 -1
  181. package/dist/telemetry/telemetry-client.d.cts +0 -87
  182. package/dist/telemetry/telemetry-client.d.cts.map +0 -1
  183. package/dist/telemetry/telemetry-client.d.mts +0 -87
  184. package/dist/telemetry/telemetry-client.d.mts.map +0 -1
  185. package/dist/telemetry/telemetry-client.mjs +0 -164
  186. package/dist/telemetry/telemetry-client.mjs.map +0 -1
  187. package/dist/telemetry/utils.cjs +0 -14
  188. package/dist/telemetry/utils.cjs.map +0 -1
  189. package/dist/telemetry/utils.mjs +0 -13
  190. package/dist/telemetry/utils.mjs.map +0 -1
  191. package/dist/utils/conditions.cjs +0 -32
  192. package/dist/utils/conditions.cjs.map +0 -1
  193. package/dist/utils/conditions.d.cts +0 -31
  194. package/dist/utils/conditions.d.cts.map +0 -1
  195. package/dist/utils/conditions.d.mts +0 -31
  196. package/dist/utils/conditions.d.mts.map +0 -1
  197. package/dist/utils/conditions.mjs +0 -31
  198. package/dist/utils/conditions.mjs.map +0 -1
  199. package/dist/utils/console-styling.cjs +0 -91
  200. package/dist/utils/console-styling.cjs.map +0 -1
  201. package/dist/utils/console-styling.d.cts +0 -65
  202. package/dist/utils/console-styling.d.cts.map +0 -1
  203. package/dist/utils/console-styling.d.mts +0 -65
  204. package/dist/utils/console-styling.d.mts.map +0 -1
  205. package/dist/utils/console-styling.mjs +0 -85
  206. package/dist/utils/console-styling.mjs.map +0 -1
  207. package/src/__tests__/zod-regression.test.ts +0 -319
  208. package/src/event-transforms/index.ts +0 -5
  209. package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
  210. package/src/event-transforms/recorded-events.test.ts +0 -166
  211. package/src/event-transforms/recorded-events.ts +0 -74
  212. package/src/telemetry/events.ts +0 -68
  213. package/src/telemetry/index.ts +0 -9
  214. package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
  215. package/src/telemetry/telemetry-client.test.ts +0 -798
  216. package/src/telemetry/telemetry-client.ts +0 -328
  217. package/src/telemetry/utils.ts +0 -15
  218. package/src/utils/__tests__/conditions.test.ts +0 -161
  219. package/src/utils/conditions.ts +0 -116
  220. package/src/utils/console-styling.ts +0 -126
@@ -0,0 +1,245 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { defaultGenerativeUIPromptSpec } from "../generative-ui/prompt-spec";
3
+ import type { GenerativeUISchemaSettings } from "../generative-ui/prompt-spec";
4
+ import {
5
+ applyDescriptionOverrides,
6
+ renderGenerativeUIComponentList,
7
+ renderGenerativeUISchema,
8
+ schemaCoverage,
9
+ } from "../generative-ui/schema-render";
10
+ import type { GenerativeUIManifest } from "../generative-ui/types";
11
+
12
+ const manifest: GenerativeUIManifest = {
13
+ catalogId: "test/schema@1",
14
+ components: {
15
+ Text: {
16
+ description: "Shows text",
17
+ props: {
18
+ type: "object",
19
+ properties: {
20
+ text: { type: "string", description: "The text" },
21
+ size: { enum: ["sm", "md"] },
22
+ },
23
+ required: ["text"],
24
+ },
25
+ },
26
+ Button: {
27
+ description: "A button",
28
+ props: { type: "object", properties: { label: { type: "string" } } },
29
+ events: { onClick: { description: "Action" } },
30
+ },
31
+ },
32
+ functions: {
33
+ formatCurrency: {
34
+ description: "Formats money",
35
+ parameters: { type: "object", description: "{value: number}" },
36
+ },
37
+ },
38
+ targets: [{ id: "chat", kind: "chat" }],
39
+ surfaces: {},
40
+ };
41
+
42
+ const settings = (
43
+ notation: GenerativeUISchemaSettings["notation"],
44
+ ): GenerativeUISchemaSettings => ({
45
+ notation,
46
+ propDescriptions: true,
47
+ commonProps: true,
48
+ });
49
+
50
+ describe("renderGenerativeUISchema", () => {
51
+ it("writes the lines schema that ships by default", () => {
52
+ expect(
53
+ renderGenerativeUISchema(
54
+ manifest,
55
+ defaultGenerativeUIPromptSpec().schema.markdown,
56
+ ),
57
+ ).toBe(renderGenerativeUISchema(manifest, settings("lines")));
58
+ });
59
+
60
+ it.each(["compact", "json-schema", "ts-signature", "lines"] as const)(
61
+ "covers every component and prop in %s notation",
62
+ (notation) => {
63
+ const text = renderGenerativeUISchema(manifest, settings(notation));
64
+ expect(schemaCoverage(manifest, text).missing).toEqual([]);
65
+ },
66
+ );
67
+
68
+ it("writes one signature line per component, with events", () => {
69
+ const text = renderGenerativeUISchema(manifest, settings("ts-signature"));
70
+ expect(text).toContain(
71
+ '- Text(text: string // The text, size?: "sm" | "md"): Shows text',
72
+ );
73
+ expect(text).toContain(" events: onClick(Action)");
74
+ expect(text).toContain("- formatCurrency{value: number}: Formats money");
75
+ });
76
+
77
+ it("separates a function name from parameters that are not an object", () => {
78
+ const withCalls: GenerativeUIManifest = {
79
+ ...manifest,
80
+ functions: {
81
+ clearCart: { parameters: { type: "object", properties: {} } },
82
+ setVolume: { parameters: { type: "number" } },
83
+ },
84
+ };
85
+ for (const notation of ["lines", "ts-signature"] as const) {
86
+ const text = renderGenerativeUISchema(withCalls, settings(notation));
87
+ expect(text).toContain("clearCart{}");
88
+ expect(text).toContain("setVolume(number)");
89
+ }
90
+ });
91
+
92
+ it("keeps the quotes of enum values that would read as a type or a number", () => {
93
+ const text = renderGenerativeUISchema(
94
+ {
95
+ ...manifest,
96
+ components: {
97
+ Icon: {
98
+ props: {
99
+ type: "object",
100
+ properties: {
101
+ size: { anyOf: [{ enum: ["sm", "md"] }, { type: "number" }] },
102
+ format: { enum: ["number", "currency"] },
103
+ level: { enum: ["1", "2"] },
104
+ tone: { enum: ["calm", "loud"] },
105
+ stringFlags: { enum: ["true", "false"] },
106
+ booleanFlags: { enum: [true, false] },
107
+ note: {
108
+ type: "string",
109
+ description: "First line\nIcon: not a component",
110
+ },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ },
116
+ settings("lines"),
117
+ );
118
+ expect(text).toContain(' size: "sm"|"md"|number');
119
+ expect(text).toContain(' format: "number"|"currency"');
120
+ expect(text).toContain(' level: "1"|"2"');
121
+ expect(text).toContain(" tone: calm|loud");
122
+ expect(text).toContain(' stringFlags: "true"|"false"');
123
+ expect(text).toContain(" booleanFlags: true|false");
124
+ expect(text).toContain(" note: string - First line Icon: not a component");
125
+ });
126
+
127
+ it("writes the status of a deleted or failed surface in signature notation", () => {
128
+ const text = renderGenerativeUISchema(
129
+ {
130
+ ...manifest,
131
+ surfaces: {
132
+ old: { target: "chat", status: "deleted" },
133
+ bad: { target: "chat", status: "failed" },
134
+ },
135
+ },
136
+ settings("ts-signature"),
137
+ );
138
+ expect(text).toContain("- old (target chat) status: deleted");
139
+ expect(text).toContain("- bad (target chat) status: failed");
140
+ });
141
+
142
+ it("writes lines: one line per prop, bare enums, required marked *, events as action props", () => {
143
+ const text = renderGenerativeUISchema(manifest, settings("lines"));
144
+ expect(text).toContain(
145
+ "Text: Shows text\n text*: string - The text\n size: sm|md",
146
+ );
147
+ expect(text).toContain(
148
+ "Button: A button\n label: string\n onClick: action - Action",
149
+ );
150
+ expect(text).toContain("formatCurrency{value: number}: Formats money");
151
+ expect(text).not.toContain('\\"');
152
+ });
153
+
154
+ it("writes slots as componentId and childList props in lines notation", () => {
155
+ const withSlots: GenerativeUIManifest = {
156
+ ...manifest,
157
+ components: {
158
+ Card: {
159
+ props: { type: "object", properties: {} },
160
+ slots: { child: "single", children: "multiple" },
161
+ },
162
+ },
163
+ };
164
+ const text = renderGenerativeUISchema(withSlots, settings("lines"));
165
+ expect(text).toContain("Card\n child: componentId\n children: childList");
166
+ expect(text).not.toContain("slots");
167
+ });
168
+
169
+ it("leaves the prop descriptions out on request", () => {
170
+ for (const notation of [
171
+ "compact",
172
+ "json-schema",
173
+ "ts-signature",
174
+ "lines",
175
+ ] as const) {
176
+ const text = renderGenerativeUISchema(manifest, {
177
+ ...settings(notation),
178
+ propDescriptions: false,
179
+ });
180
+ expect(text).not.toContain("The text");
181
+ expect(text).toContain("Shows text");
182
+ }
183
+ });
184
+ });
185
+
186
+ describe("renderGenerativeUIComponentList", () => {
187
+ it("writes each notation for the tool guide and covers the catalog", () => {
188
+ for (const notation of [
189
+ "compact",
190
+ "json-schema",
191
+ "ts-signature",
192
+ "lines",
193
+ ] as const) {
194
+ const text = renderGenerativeUIComponentList(
195
+ manifest.components,
196
+ settings(notation),
197
+ );
198
+ expect(schemaCoverage(manifest, text).missing).toEqual([]);
199
+ }
200
+ });
201
+ });
202
+
203
+ describe("applyDescriptionOverrides", () => {
204
+ it("replaces only the named descriptions and reports unknown keys", () => {
205
+ const { manifest: next, unknown } = applyDescriptionOverrides(manifest, {
206
+ Text: "Prose in a surface",
207
+ "Text.size": "How big",
208
+ Nope: "x",
209
+ "Text.nope": "y",
210
+ });
211
+ expect(next.components.Text.description).toBe("Prose in a surface");
212
+ expect(next.components.Text.props.properties).toMatchObject({
213
+ size: { description: "How big" },
214
+ text: { description: "The text" },
215
+ });
216
+ expect(next.components.Button).toEqual(manifest.components.Button);
217
+ expect(unknown).toEqual(["Nope", "Text.nope"]);
218
+ // The input is not changed.
219
+ expect(manifest.components.Text.description).toBe("Shows text");
220
+ });
221
+ });
222
+
223
+ describe("applyDescriptionOverrides with inherited keys", () => {
224
+ it("treats __proto__ as unknown and never touches Object.prototype", () => {
225
+ const { unknown } = applyDescriptionOverrides(manifest, {
226
+ __proto__: "polluted",
227
+ "Text.__proto__": "polluted",
228
+ "Text.constructor": "polluted",
229
+ } as Record<string, string>);
230
+ expect(({} as { description?: string }).description).toBeUndefined();
231
+ expect(unknown).toEqual(
232
+ expect.arrayContaining(["Text.__proto__", "Text.constructor"]),
233
+ );
234
+ });
235
+ });
236
+
237
+ describe("schemaCoverage", () => {
238
+ it("reports a prop that the text leaves out", () => {
239
+ const text = renderGenerativeUISchema(
240
+ manifest,
241
+ settings("ts-signature"),
242
+ ).replace("size", "");
243
+ expect(schemaCoverage(manifest, text).missing).toEqual(["Text.size"]);
244
+ });
245
+ });
@@ -3,26 +3,26 @@ import { z } from "zod";
3
3
  import * as v from "valibot";
4
4
  import { toStandardJsonSchema } from "@valibot/to-json-schema";
5
5
  import { type } from "arktype";
6
- import { zodToJsonSchema } from "zod-to-json-schema";
7
- import { schemaToJsonSchema } from "../standard-schema";
6
+ import { schemaToJsonSchema, ɵanySchema } from "../standard-schema";
8
7
  import type { StandardSchemaV1 } from "@standard-schema/spec";
9
8
 
10
9
  describe("schemaToJsonSchema", () => {
11
- describe("Zod schemas (via injected zodToJsonSchema)", () => {
10
+ describe("Zod 4 schemas (native ~standard.jsonSchema)", () => {
12
11
  it("converts a simple zod object schema", () => {
13
12
  const schema = z.object({
14
- name: z.string(),
13
+ name: z.string().describe("Full name"),
15
14
  age: z.number(),
16
15
  });
17
16
 
18
- const result = schemaToJsonSchema(schema, { zodToJsonSchema });
19
-
20
- expect(result).toHaveProperty("type", "object");
21
- expect(result).toHaveProperty("properties.name.type", "string");
22
- expect(result).toHaveProperty("properties.age.type", "number");
23
- expect(result).toHaveProperty("required");
24
- expect(result.required).toContain("name");
25
- expect(result.required).toContain("age");
17
+ expect(schemaToJsonSchema(schema)).toEqual({
18
+ $schema: "http://json-schema.org/draft-07/schema#",
19
+ type: "object",
20
+ properties: {
21
+ name: { type: "string", description: "Full name" },
22
+ age: { type: "number" },
23
+ },
24
+ required: ["name", "age"],
25
+ });
26
26
  });
27
27
 
28
28
  it("converts a zod schema with optional fields", () => {
@@ -31,12 +31,27 @@ describe("schemaToJsonSchema", () => {
31
31
  units: z.enum(["celsius", "fahrenheit"]).optional(),
32
32
  });
33
33
 
34
- const result = schemaToJsonSchema(schema, { zodToJsonSchema });
34
+ const result = schemaToJsonSchema(schema);
35
35
 
36
36
  expect(result).toHaveProperty("type", "object");
37
37
  expect(result).toHaveProperty("properties.city.type", "string");
38
- expect(result.required).toContain("city");
39
- expect(result.required).not.toContain("units");
38
+ expect(result).toHaveProperty("properties.units.enum", [
39
+ "celsius",
40
+ "fahrenheit",
41
+ ]);
42
+ expect(result.required).toEqual(["city"]);
43
+ });
44
+
45
+ it("describes the input side, so fields with defaults are optional", () => {
46
+ const schema = z.object({
47
+ query: z.string(),
48
+ page: z.number().default(1),
49
+ });
50
+
51
+ const result = schemaToJsonSchema(schema);
52
+
53
+ expect(result.required).toEqual(["query"]);
54
+ expect(result).toHaveProperty("properties.page.default", 1);
40
55
  });
41
56
 
42
57
  it("has vendor 'zod' on ~standard", () => {
@@ -131,10 +146,9 @@ describe("schemaToJsonSchema", () => {
131
146
  expect(result.required).toContain("age");
132
147
  });
133
148
 
134
- it("converts an arktype schema without needing zodToJsonSchema fallback", () => {
149
+ it("converts a single-field arktype schema", () => {
135
150
  const schema = type({ query: "string" });
136
151
 
137
- // No zodToJsonSchema option needed — arktype uses Standard JSON Schema V1 natively
138
152
  const result = schemaToJsonSchema(schema);
139
153
 
140
154
  expect(result).toHaveProperty("type", "object");
@@ -179,38 +193,9 @@ describe("schemaToJsonSchema", () => {
179
193
  $target: "draft-07",
180
194
  });
181
195
  });
182
-
183
- it("prefers ~standard.jsonSchema over zodToJsonSchema fallback", () => {
184
- const mockSchema = {
185
- "~standard": {
186
- version: 1,
187
- vendor: "zod",
188
- validate: (value: unknown) => ({ value }),
189
- jsonSchema: {
190
- input: () => ({
191
- type: "object",
192
- properties: { fromJsonSchema: { type: "boolean" } },
193
- }),
194
- },
195
- },
196
- };
197
-
198
- const zodFallback = () => ({
199
- type: "object",
200
- properties: { fromZodFallback: { type: "boolean" } },
201
- });
202
-
203
- const result = schemaToJsonSchema(mockSchema, {
204
- zodToJsonSchema: zodFallback,
205
- });
206
-
207
- // Should use ~standard.jsonSchema, not the zod fallback
208
- expect(result).toHaveProperty("properties.fromJsonSchema");
209
- expect(result).not.toHaveProperty("properties.fromZodFallback");
210
- });
211
196
  });
212
197
 
213
- describe("Zod v4 schemas (via toJSONSchema method)", () => {
198
+ describe("schemas exposing a toJSONSchema() method", () => {
214
199
  it("calls toJSONSchema() when the method exists on the schema", () => {
215
200
  const expectedOutput = {
216
201
  type: "object",
@@ -231,7 +216,7 @@ describe("schemaToJsonSchema", () => {
231
216
  expect(result).toEqual(expectedOutput);
232
217
  });
233
218
 
234
- it("uses toJSONSchema() even without zodToJsonSchema option", () => {
219
+ it("uses toJSONSchema() with no options", () => {
235
220
  const mockZod4Schema: StandardSchemaV1 = {
236
221
  "~standard": {
237
222
  version: 1,
@@ -249,32 +234,6 @@ describe("schemaToJsonSchema", () => {
249
234
  expect(result).toHaveProperty("properties.city.type", "string");
250
235
  });
251
236
 
252
- it("prefers toJSONSchema() over zodToJsonSchema fallback for Zod v4", () => {
253
- const mockZod4Schema: StandardSchemaV1 = {
254
- "~standard": {
255
- version: 1,
256
- vendor: "zod",
257
- validate: (value: unknown) => ({ value }),
258
- },
259
- toJSONSchema: () => ({
260
- type: "object",
261
- properties: { fromNative: { type: "boolean" } },
262
- }),
263
- } as any;
264
-
265
- const zodFallback = () => ({
266
- type: "object",
267
- properties: { fromFallback: { type: "boolean" } },
268
- });
269
-
270
- const result = schemaToJsonSchema(mockZod4Schema, {
271
- zodToJsonSchema: zodFallback,
272
- });
273
-
274
- expect(result).toHaveProperty("properties.fromNative");
275
- expect(result).not.toHaveProperty("properties.fromFallback");
276
- });
277
-
278
237
  it("prefers ~standard.jsonSchema over toJSONSchema()", () => {
279
238
  const mockSchema = {
280
239
  "~standard": {
@@ -303,7 +262,7 @@ describe("schemaToJsonSchema", () => {
303
262
  });
304
263
 
305
264
  describe("Error handling", () => {
306
- it("throws when schema has no jsonSchema support and no zodToJsonSchema", () => {
265
+ it("throws when schema has no jsonSchema support", () => {
307
266
  const mockSchema: StandardSchemaV1 = {
308
267
  "~standard": {
309
268
  version: 1,
@@ -318,42 +277,43 @@ describe("schemaToJsonSchema", () => {
318
277
  expect(() => schemaToJsonSchema(mockSchema)).toThrow(/unknown-lib/);
319
278
  });
320
279
 
321
- it("throws for non-zod vendor when zodToJsonSchema is not provided", () => {
322
- const mockSchema: StandardSchemaV1 = {
280
+ it("rejects a Zod 3 schema and names the supported Zod version", () => {
281
+ // Zod 3 implements Standard Schema validation only: no
282
+ // `~standard.jsonSchema` and no `toJSONSchema()` method.
283
+ const zod3Like: StandardSchemaV1 = {
323
284
  "~standard": {
324
285
  version: 1,
325
- vendor: "some-other-lib",
286
+ vendor: "zod",
326
287
  validate: (value: unknown) => ({ value }),
327
288
  },
328
289
  };
329
290
 
330
- expect(() => schemaToJsonSchema(mockSchema)).toThrow(
331
- /no zodToJsonSchema fallback/,
332
- );
291
+ expect(() => schemaToJsonSchema(zod3Like)).toThrow(/Zod 4\.2\+/);
333
292
  });
293
+ });
294
+ });
334
295
 
335
- it("uses zodToJsonSchema fallback for zod vendor schemas", () => {
336
- const mockZodSchema: StandardSchemaV1 = {
337
- "~standard": {
338
- version: 1,
339
- vendor: "zod",
340
- validate: (value: unknown) => ({ value }),
341
- },
342
- };
296
+ describe("ɵanySchema", () => {
297
+ it("identifies itself as a CopilotKit Standard Schema V1", () => {
298
+ expect(ɵanySchema["~standard"].version).toBe(1);
299
+ expect(ɵanySchema["~standard"].vendor).toBe("copilotkit");
300
+ });
343
301
 
344
- const fallback = () => ({
345
- type: "object",
346
- properties: { test: { type: "string" } },
347
- });
302
+ it("returns the value it was given, unchanged", async () => {
303
+ const args = { city: "Berlin", days: [1, 2] };
348
304
 
349
- const result = schemaToJsonSchema(mockZodSchema, {
350
- zodToJsonSchema: fallback,
351
- });
305
+ const result = await ɵanySchema["~standard"].validate(args);
352
306
 
353
- expect(result).toEqual({
354
- type: "object",
355
- properties: { test: { type: "string" } },
356
- });
357
- });
307
+ expect(result).toEqual({ value: { city: "Berlin", days: [1, 2] } });
358
308
  });
309
+
310
+ it.each([undefined, null, "", 0, false])(
311
+ "accepts %j without issues",
312
+ async (input) => {
313
+ const result = await ɵanySchema["~standard"].validate(input);
314
+
315
+ expect(result).toEqual({ value: input });
316
+ expect(result).not.toHaveProperty("issues");
317
+ },
318
+ );
359
319
  });