Skip to content

Commit e8fd234

Browse files
committed
fix(examples): use jsonSchema() in vercel_ai_tool for AI SDK v5 compat
@ai-sdk/openai v2 drops Zod type info when converting to function parameters, sending type: "None" to OpenAI which rejects it. Switch to jsonSchema() which preserves the type: "object" wrapper correctly. Also remove unused zod import.
1 parent 0d3eb66 commit e8fd234

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

examples/vercel_ai_tool.mjs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
* automatically via `generateText` with `maxSteps`.
88
*
99
* Prerequisites:
10-
* npm install ai @ai-sdk/openai zod
10+
* npm install ai @ai-sdk/openai
1111
* export OPENAI_API_KEY=sk-...
1212
*
1313
* Run:
1414
* node examples/vercel_ai_tool.mjs
1515
*/
1616

17-
import { generateText, tool } from "ai";
17+
import { generateText, tool, jsonSchema } from "ai";
1818
import { openai } from "@ai-sdk/openai";
19-
import { z } from "zod";
2019
import { BashTool } from "@everruns/bashkit";
2120

2221
// ─── Setup ───────────────────────────────────────────────────────────
@@ -26,10 +25,17 @@ const bashTool = new BashTool({ username: "agent", hostname: "sandbox" });
2625
// Define bashkit as a Vercel AI SDK tool
2726
const bashkitTool = tool({
2827
description: bashTool.shortDescription,
29-
parameters: z.object({
30-
commands: z
31-
.string()
32-
.describe("Bash commands to execute in a sandboxed virtual environment"),
28+
parameters: jsonSchema({
29+
type: "object",
30+
properties: {
31+
commands: {
32+
type: "string",
33+
description:
34+
"Bash commands to execute in a sandboxed virtual environment",
35+
},
36+
},
37+
required: ["commands"],
38+
additionalProperties: false,
3339
}),
3440
execute: async ({ commands }) => {
3541
const result = bashTool.executeSync(commands);

0 commit comments

Comments
 (0)