Replace Zod with TypeBox for schema validation
- Switch from Zod to TypeBox for tool parameter schemas - TypeBox schemas can be serialized/deserialized as JSON - Use AJV for runtime validation instead of Zod's parse - Add StringEnum helper for Google API compatibility (avoids anyOf/const patterns) - Export Type and Static from main package for convenience - Update all tests and documentation to reflect TypeBox usage
This commit is contained in:
17
packages/ai/test/enum-test.ts
Normal file
17
packages/ai/test/enum-test.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import { z } from "zod";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { StringEnum } from "../src/typebox-helpers.js";
|
||||
|
||||
// Zod version
|
||||
const zodSchema = z.object({
|
||||
operation: z.enum(["add", "subtract", "multiply", "divide"]),
|
||||
});
|
||||
|
||||
// TypeBox with our StringEnum helper
|
||||
const typeboxHelper = Type.Object({
|
||||
operation: StringEnum(["add", "subtract", "multiply", "divide"]),
|
||||
});
|
||||
|
||||
console.log("Zod:", JSON.stringify(zodToJsonSchema(zodSchema), null, 2));
|
||||
console.log("\nTypeBox.StringEnum:", JSON.stringify(typeboxHelper, null, 2));
|
||||
Reference in New Issue
Block a user