Skip to content

Commit 9b50d88

Browse files
authored
brianyin/ajs-309-support-zod-v4 (#792)
1 parent f54262c commit 9b50d88

File tree

13 files changed

+1304
-67
lines changed

13 files changed

+1304
-67
lines changed

.changeset/wild-hotels-battle.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@livekit/agents-plugins-test': patch
3+
'@livekit/agents': patch
4+
---
5+
6+
Support Zod V4 tool schema and backward competible to V3

agents/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"@types/node": "^22.5.5",
4343
"@types/ws": "^8.5.10",
4444
"tsup": "^8.4.0",
45-
"typescript": "^5.0.0"
45+
"typescript": "^5.0.0",
46+
"zod": "^3.25.76"
4647
},
4748
"dependencies": {
4849
"@ffmpeg-installer/ffmpeg": "^1.1.0",
@@ -62,10 +63,10 @@
6263
"sharp": "0.34.3",
6364
"uuid": "^11.1.0",
6465
"ws": "^8.16.0",
65-
"zod": "^3.23.8",
6666
"zod-to-json-schema": "^3.24.6"
6767
},
6868
"peerDependencies": {
69-
"@livekit/rtc-node": "^0.13.12"
69+
"@livekit/rtc-node": "^0.13.12",
70+
"zod": "^3.25.76 || ^4.1.8"
7071
}
7172
}
Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v3 schemas > should convert basic v3 object schema to JSON Schema 1`] = `
4+
{
5+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
6+
"additionalProperties": false,
7+
"properties": {
8+
"age": {
9+
"type": "number",
10+
},
11+
"name": {
12+
"type": "string",
13+
},
14+
},
15+
"required": [
16+
"name",
17+
"age",
18+
],
19+
"type": "object",
20+
}
21+
`;
22+
23+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v3 schemas > should handle v3 array schemas 1`] = `
24+
{
25+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
26+
"additionalProperties": false,
27+
"properties": {
28+
"tags": {
29+
"items": {
30+
"type": "string",
31+
},
32+
"type": "array",
33+
},
34+
},
35+
"required": [
36+
"tags",
37+
],
38+
"type": "object",
39+
}
40+
`;
41+
42+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v3 schemas > should handle v3 enum schemas 1`] = `
43+
{
44+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
45+
"additionalProperties": false,
46+
"properties": {
47+
"color": {
48+
"enum": [
49+
"red",
50+
"blue",
51+
"green",
52+
],
53+
"type": "string",
54+
},
55+
},
56+
"required": [
57+
"color",
58+
],
59+
"type": "object",
60+
}
61+
`;
62+
63+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v3 schemas > should handle v3 nested object schemas 1`] = `
64+
{
65+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
66+
"additionalProperties": false,
67+
"properties": {
68+
"user": {
69+
"additionalProperties": false,
70+
"properties": {
71+
"email": {
72+
"type": "string",
73+
},
74+
"name": {
75+
"type": "string",
76+
},
77+
},
78+
"required": [
79+
"name",
80+
"email",
81+
],
82+
"type": "object",
83+
},
84+
},
85+
"required": [
86+
"user",
87+
],
88+
"type": "object",
89+
}
90+
`;
91+
92+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v3 schemas > should handle v3 schemas with default values 1`] = `
93+
{
94+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
95+
"additionalProperties": false,
96+
"properties": {
97+
"active": {
98+
"anyOf": [
99+
{
100+
"default": true,
101+
"type": "boolean",
102+
},
103+
{
104+
"type": "null",
105+
},
106+
],
107+
},
108+
"name": {
109+
"type": "string",
110+
},
111+
"role": {
112+
"anyOf": [
113+
{
114+
"default": "user",
115+
"type": "string",
116+
},
117+
{
118+
"type": "null",
119+
},
120+
],
121+
},
122+
},
123+
"required": [
124+
"name",
125+
"role",
126+
"active",
127+
],
128+
"type": "object",
129+
}
130+
`;
131+
132+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v3 schemas > should handle v3 schemas with descriptions 1`] = `
133+
{
134+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
135+
"additionalProperties": false,
136+
"properties": {
137+
"location": {
138+
"description": "The location to search",
139+
"type": "string",
140+
},
141+
},
142+
"required": [
143+
"location",
144+
],
145+
"type": "object",
146+
}
147+
`;
148+
149+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v3 schemas > should handle v3 schemas with multiple optional fields 1`] = `
150+
{
151+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
152+
"additionalProperties": false,
153+
"properties": {
154+
"age": {
155+
"type": [
156+
"number",
157+
"null",
158+
],
159+
},
160+
"email": {
161+
"type": "string",
162+
},
163+
"id": {
164+
"type": "string",
165+
},
166+
"name": {
167+
"type": [
168+
"string",
169+
"null",
170+
],
171+
},
172+
},
173+
"required": [
174+
"id",
175+
"name",
176+
"age",
177+
"email",
178+
],
179+
"type": "object",
180+
}
181+
`;
182+
183+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v4 schemas > should convert basic v4 object schema to JSON Schema 1`] = `
184+
{
185+
"$schema": "http://json-schema.org/draft-07/schema#",
186+
"additionalProperties": false,
187+
"properties": {
188+
"age": {
189+
"type": "number",
190+
},
191+
"name": {
192+
"type": "string",
193+
},
194+
},
195+
"required": [
196+
"name",
197+
"age",
198+
],
199+
"type": "object",
200+
}
201+
`;
202+
203+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v4 schemas > should handle v4 array schemas 1`] = `
204+
{
205+
"$schema": "http://json-schema.org/draft-07/schema#",
206+
"additionalProperties": false,
207+
"properties": {
208+
"tags": {
209+
"items": {
210+
"type": "string",
211+
},
212+
"type": "array",
213+
},
214+
},
215+
"required": [
216+
"tags",
217+
],
218+
"type": "object",
219+
}
220+
`;
221+
222+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v4 schemas > should handle v4 enum schemas 1`] = `
223+
{
224+
"$schema": "http://json-schema.org/draft-07/schema#",
225+
"additionalProperties": false,
226+
"properties": {
227+
"color": {
228+
"enum": [
229+
"red",
230+
"blue",
231+
"green",
232+
],
233+
"type": "string",
234+
},
235+
},
236+
"required": [
237+
"color",
238+
],
239+
"type": "object",
240+
}
241+
`;
242+
243+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v4 schemas > should handle v4 nested object schemas 1`] = `
244+
{
245+
"$schema": "http://json-schema.org/draft-07/schema#",
246+
"additionalProperties": false,
247+
"properties": {
248+
"user": {
249+
"additionalProperties": false,
250+
"properties": {
251+
"email": {
252+
"type": "string",
253+
},
254+
"name": {
255+
"type": "string",
256+
},
257+
},
258+
"required": [
259+
"name",
260+
"email",
261+
],
262+
"type": "object",
263+
},
264+
},
265+
"required": [
266+
"user",
267+
],
268+
"type": "object",
269+
}
270+
`;
271+
272+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v4 schemas > should handle v4 schemas with default values 1`] = `
273+
{
274+
"$schema": "http://json-schema.org/draft-07/schema#",
275+
"additionalProperties": false,
276+
"properties": {
277+
"active": {
278+
"default": true,
279+
"type": "boolean",
280+
},
281+
"name": {
282+
"type": "string",
283+
},
284+
"role": {
285+
"default": "user",
286+
"type": "string",
287+
},
288+
},
289+
"required": [
290+
"name",
291+
"role",
292+
"active",
293+
],
294+
"type": "object",
295+
}
296+
`;
297+
298+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v4 schemas > should handle v4 schemas with multiple optional fields 1`] = `
299+
{
300+
"$schema": "http://json-schema.org/draft-07/schema#",
301+
"additionalProperties": false,
302+
"properties": {
303+
"age": {
304+
"type": "number",
305+
},
306+
"email": {
307+
"type": "string",
308+
},
309+
"id": {
310+
"type": "string",
311+
},
312+
"name": {
313+
"type": "string",
314+
},
315+
},
316+
"required": [
317+
"id",
318+
"email",
319+
],
320+
"type": "object",
321+
}
322+
`;
323+
324+
exports[`Zod Utils > zodSchemaToJsonSchema > Zod v4 schemas > should handle v4 schemas with optional fields 1`] = `
325+
{
326+
"$schema": "http://json-schema.org/draft-07/schema#",
327+
"additionalProperties": false,
328+
"properties": {
329+
"optional": {
330+
"type": "string",
331+
},
332+
"required": {
333+
"type": "string",
334+
},
335+
},
336+
"required": [
337+
"required",
338+
],
339+
"type": "object",
340+
}
341+
`;

0 commit comments

Comments
 (0)