mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 02:04:05 +00:00
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:
parent
f5ac1ef521
commit
e8370436d7
16 changed files with 196 additions and 121 deletions
|
|
@ -4,7 +4,6 @@ import type {
|
|||
MessageCreateParamsStreaming,
|
||||
MessageParam,
|
||||
} from "@anthropic-ai/sdk/resources/messages.js";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { AssistantMessageEventStream } from "../event-stream.js";
|
||||
import { calculateCost } from "../models.js";
|
||||
import type {
|
||||
|
|
@ -442,7 +441,7 @@ function convertTools(tools: Tool[]): Anthropic.Messages.Tool[] {
|
|||
if (!tools) return [];
|
||||
|
||||
return tools.map((tool) => {
|
||||
const jsonSchema = zodToJsonSchema(tool.parameters, { $refStrategy: "none" }) as any;
|
||||
const jsonSchema = tool.parameters as any; // TypeBox already generates JSON Schema
|
||||
|
||||
return {
|
||||
name: tool.name,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import {
|
|||
GoogleGenAI,
|
||||
type Part,
|
||||
} from "@google/genai";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { AssistantMessageEventStream } from "../event-stream.js";
|
||||
import { calculateCost } from "../models.js";
|
||||
import type {
|
||||
|
|
@ -394,7 +393,7 @@ function convertTools(tools: Tool[]): any[] | undefined {
|
|||
functionDeclarations: tools.map((tool) => ({
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
parameters: zodToJsonSchema(tool.parameters, { $refStrategy: "none" }),
|
||||
parameters: tool.parameters as any, // TypeBox already generates JSON Schema
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import type {
|
|||
ChatCompletionContentPartText,
|
||||
ChatCompletionMessageParam,
|
||||
} from "openai/resources/chat/completions.js";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { AssistantMessageEventStream } from "../event-stream.js";
|
||||
import { calculateCost } from "../models.js";
|
||||
import type {
|
||||
|
|
@ -396,7 +395,7 @@ function convertTools(tools: Tool[]): OpenAI.Chat.Completions.ChatCompletionTool
|
|||
function: {
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
parameters: zodToJsonSchema(tool.parameters, { $refStrategy: "none" }),
|
||||
parameters: tool.parameters as any, // TypeBox already generates JSON Schema
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import type {
|
|||
ResponseOutputMessage,
|
||||
ResponseReasoningItem,
|
||||
} from "openai/resources/responses/responses.js";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { AssistantMessageEventStream } from "../event-stream.js";
|
||||
import { calculateCost } from "../models.js";
|
||||
import type {
|
||||
|
|
@ -462,7 +461,7 @@ function convertTools(tools: Tool[]): OpenAITool[] {
|
|||
type: "function",
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
parameters: zodToJsonSchema(tool.parameters, { $refStrategy: "none" }),
|
||||
parameters: tool.parameters as any, // TypeBox already generates JSON Schema
|
||||
strict: null,
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue