fix: add Zod v4 schema extraction support in Railway executor
- Import Zod v4's toJSONSchema from zod@4/json-schema - Add Strategy 3: Detect Zod v4 schemas via ._zod property - Convert Zod v4 schemas using native toJSONSchema function - Update error message to mention both Zod v4 and v3 support Fixes schema extraction for @tpmjs/emoji-magic and other Zod v4 tools 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
26421be4e6
commit
1c8b516db8
1 changed files with 19 additions and 3 deletions
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
// Import zod-to-json-schema for Zod v3 support
|
||||
import { zodToJsonSchema } from 'https://esm.sh/zod-to-json-schema@3.25.0';
|
||||
// Import Zod v4's JSON Schema converter (for packages using Zod v4)
|
||||
import { toJSONSchema as zodV4ToJsonSchema } from 'https://esm.sh/zod@4/json-schema';
|
||||
|
||||
// Cache TTL: 2 minutes
|
||||
const CACHE_TTL_MS = 2 * 60 * 1000;
|
||||
|
|
@ -406,7 +408,20 @@ async function loadAndDescribe(req: Request): Promise<Response> {
|
|||
rawJsonSchema = toolModule.inputSchema.jsonSchema;
|
||||
}
|
||||
|
||||
// Strategy 3: Try Zod v3 schema (detect via _def property and convert)
|
||||
// Strategy 3: Try Zod v4 schema (detect via _zod property - new in Zod v4)
|
||||
if (!rawJsonSchema && toolModule.inputSchema._zod) {
|
||||
console.log(
|
||||
`📋 Detected Zod v4 schema, converting with Zod v4 toJSONSchema for ${cacheKey}`
|
||||
);
|
||||
try {
|
||||
rawJsonSchema = zodV4ToJsonSchema(toolModule.inputSchema);
|
||||
console.log(`✅ Successfully converted Zod v4 schema for ${cacheKey}`);
|
||||
} catch (error) {
|
||||
console.warn(`⚠️ Zod v4 toJSONSchema conversion failed for ${cacheKey}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Strategy 4: Try Zod v3 schema (detect via _def property and convert)
|
||||
if (!rawJsonSchema && toolModule.inputSchema._def) {
|
||||
console.log(
|
||||
`📋 Detected Zod schema (v3), converting with zod-to-json-schema for ${cacheKey}`
|
||||
|
|
@ -436,11 +451,12 @@ async function loadAndDescribe(req: Request): Promise<Response> {
|
|||
return Response.json(
|
||||
{
|
||||
success: false,
|
||||
error: `Tool "${name}" has no valid inputSchema. Tools must use AI SDK jsonSchema(), Zod v4 toJSONSchema(), or Zod v3 schemas.`,
|
||||
error: `Tool "${name}" has no valid inputSchema. Tools must use AI SDK jsonSchema(), Zod v4 (._zod), or Zod v3 (._def) schemas.`,
|
||||
debug: {
|
||||
hasInputSchema: !!toolModule.inputSchema,
|
||||
availableMethods: toolModule.inputSchema ? Object.keys(toolModule.inputSchema) : [],
|
||||
hasZodDef: !!toolModule.inputSchema?._def,
|
||||
hasZodV4: !!toolModule.inputSchema?._zod,
|
||||
hasZodV3Def: !!toolModule.inputSchema?._def,
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue