Skip to content

Commit 5da1cda

Browse files
feat: support zod v4 & v3 (#2186)
Co-authored-by: Marcus Schiesser <mail@marcusschiesser.de>
1 parent 1285e38 commit 5da1cda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+731
-326
lines changed

.changeset/green-gorillas-hunt.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@llamaindex/core": patch
3+
"@llamaindex/tools": patch
4+
"@llamaindex/workflow": patch
5+
"@llamaindex/ollama": patch
6+
"@llamaindex/openai": patch
7+
"@llamaindex/vercel": patch
8+
---
9+
10+
feat: support zod v4 & v3

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jobs:
105105
run: |
106106
pnpm pack --pack-destination ${{ runner.temp }} -C packages/llamaindex
107107
pnpm pack --pack-destination ${{ runner.temp }} -C packages/workflow
108+
pnpm pack --pack-destination ${{ runner.temp }} -C packages/core
108109
- name: Install packed packages
109110
run: npm add ${{ runner.temp }}/*.tgz
110111
working-directory: e2e/npm
@@ -162,7 +163,7 @@ jobs:
162163
github_token: ${{ secrets.GITHUB_TOKEN }}
163164
directory: e2e/examples/vite-import-llamaindex
164165
skip_step: "install"
165-
build_script: build
166+
build_script: ci-build
166167
package_manager: pnpm
167168

168169
typecheck-examples:
@@ -203,7 +204,7 @@ jobs:
203204
fi
204205
done
205206
- name: Install
206-
run: npm add ${{ runner.temp }}/*.tgz
207+
run: npm add ${{ runner.temp }}/*.tgz --legacy-peer-deps
207208
working-directory: ${{ runner.temp }}/examples
208209
- name: Run Type Check
209210
run: npx tsc --project ./tsconfig.json

e2e/node/fixtures/tools.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export const getWeatherTool = FunctionTool.from(
4444
name: "getWeather",
4545
description: "Get the weather for a city",
4646
parameters: z.object({
47-
city: z.string({
48-
description: "The city to get the weather for",
49-
}),
47+
city: z.string().describe("The city to get the weather for"),
5048
}),
5149
},
5250
);

examples/agents/agent/blog-writer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ const saveFileTool = tool({
2020
description:
2121
"Save the written content into a file that can be downloaded by the user",
2222
parameters: z.object({
23-
content: z.string({
24-
description: "The content to save into a file",
25-
}),
23+
content: z.string().describe("The content to save into a file"),
2624
}),
2725
execute: ({ content }: { content: string }) => {
2826
const filePath = os.tmpdir() + "/report.md";

examples/agents/agent/large-toolcall.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ const userQuestion = "which are the best comedies after 2010?";
1717
description:
1818
"Execute python code in a Jupyter notebook cell and return any result, stdout, stderr, display_data, and error.",
1919
parameters: z.object({
20-
code: z.string({
21-
description: "The python code to execute in a single cell.",
22-
}),
20+
code: z.string().describe("The python code to execute in a single cell."),
2321
}),
2422
execute: ({ code }) => {
2523
console.log(

examples/agents/agent/multiple-agents.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ const temperatureConverterTool = tool({
2626
description: "Convert a temperature from Fahrenheit to Celsius",
2727
name: "fahrenheitToCelsius",
2828
parameters: z.object({
29-
temperature: z.number({
30-
description: "The temperature in Fahrenheit",
31-
}),
29+
temperature: z.number().describe("The temperature in Fahrenheit"),
3230
}),
3331
execute: ({ temperature }) => {
3432
return ((temperature - 32) * 5) / 9;
@@ -39,9 +37,7 @@ const temperatureFetcherTool = tool({
3937
description: "Fetch the temperature (in Fahrenheit) for a city",
4038
name: "fetchTemperature",
4139
parameters: z.object({
42-
city: z.string({
43-
description: "The city to fetch the temperature for",
44-
}),
40+
city: z.string().describe("The city to fetch the temperature for"),
4541
}),
4642
execute: ({ city }) => {
4743
const temperature = Math.floor(Math.random() * 58) + 32;

examples/agents/agent/with-anthropic.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ const weatherTool = tool({
1414
name: "weather",
1515
description: "Get the weather",
1616
parameters: z.object({
17-
location: z.string({
18-
description: "The location to get the weather for",
19-
}),
17+
location: z.string().describe("The location to get the weather for"),
2018
}),
2119
execute: ({ location }) => {
2220
return `The weather in ${location} is sunny`;
@@ -27,9 +25,7 @@ const inflationTool = tool({
2725
name: "inflation",
2826
description: "Get the inflation",
2927
parameters: z.object({
30-
location: z.string({
31-
description: "The location to get the inflation for",
32-
}),
28+
location: z.string().describe("The location to get the inflation for"),
3329
}),
3430
execute: ({ location }) => {
3531
return `The inflation in ${location} is 2%`;
@@ -41,9 +37,7 @@ const saveFileTool = tool({
4137
description:
4238
"Save the written content into a file that can be downloaded by the user",
4339
parameters: z.object({
44-
content: z.string({
45-
description: "The content to save into a file",
46-
}),
40+
content: z.string().describe("The content to save into a file"),
4741
}),
4842
execute: ({ content }) => {
4943
const filePath = "./report.md";

examples/agents/natural/joke.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ const writeJokeSchema = z.object({
1414
.describe("The topic to write a joke or describe the joke to improve."),
1515
writtenJoke: z.optional(z.string()).describe("The written joke."),
1616
retriedTimes: z
17-
.number()
18-
.default(0)
19-
.describe(
20-
"The retried times for writing the joke. Always increase this from the input retriedTimes.",
21-
),
17+
.optional(z.number().default(0))
18+
.describe("The retried times for writing the joke."),
2219
});
2320

2421
const critiqueSchema = z.object({

examples/deprecated/agents/large_toolcall_with_gpt4o.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ async function callLLM(init: { model: string }) {
2929
description:
3030
"Execute python code in a Jupyter notebook cell and return any result, stdout, stderr, display_data, and error.",
3131
parameters: z.object({
32-
code: z.string({
33-
description: "The python code to execute in a single cell.",
34-
}),
32+
code: z
33+
.string()
34+
.describe("The python code to execute in a single cell."),
3535
}),
3636
},
3737
);

examples/models/gemini/live/tool-call.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ const weatherTool = tool({
88
name: "weather",
99
description: "Get the weather",
1010
parameters: z.object({
11-
location: z.string({
12-
description: "The location to get the weather for",
13-
}),
11+
location: z.string().describe("The location to get the weather for"),
1412
}),
1513
execute: ({ location }) => {
1614
return `The weather in ${location} is rainy`;

0 commit comments

Comments
 (0)