From c18d1b7ea603b1be0b75ccc3693ce60e904b0268 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Thu, 4 Dec 2025 09:49:39 +1000 Subject: [PATCH] feat: add Zod v3 schema support via zod-to-json-schema - Import zod-to-json-schema from esm.sh - Add Strategy 3: detect Zod schemas via _def property - Convert Zod v3/v4 schemas to JSON Schema - Update error message to mention Zod v3 support - Fixes firecrawl-aisdk tool schema extraction --- apps/railway-executor/server.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/railway-executor/server.ts b/apps/railway-executor/server.ts index 4ef0521..88b9322 100644 --- a/apps/railway-executor/server.ts +++ b/apps/railway-executor/server.ts @@ -3,6 +3,9 @@ * Uses Deno's native HTTP import support */ +// Import zod-to-json-schema for Zod v3 support +import { zodToJsonSchema } from 'https://esm.sh/zod-to-json-schema@3.25.0'; + // Cache for imported tool modules const moduleCache = new Map(); @@ -101,6 +104,17 @@ async function loadAndDescribe(req: Request): Promise { console.log(`📋 Using AI SDK jsonSchema.schema for ${cacheKey}`); rawJsonSchema = toolModule.inputSchema.schema; } + + // Strategy 3: 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}`); + try { + rawJsonSchema = zodToJsonSchema(toolModule.inputSchema); + console.log(`✅ Successfully converted Zod schema for ${cacheKey}`); + } catch (error) { + console.warn(`⚠️ zod-to-json-schema conversion failed for ${cacheKey}:`, error); + } + } } // If no schema found, fail with helpful error @@ -116,10 +130,11 @@ async function loadAndDescribe(req: Request): Promise { return Response.json( { success: false, - error: `Tool "${exportName}" has no valid inputSchema. Tools must use AI SDK jsonSchema() or Zod v4 with toJSONSchema().`, + error: `Tool "${exportName}" has no valid inputSchema. Tools must use AI SDK jsonSchema(), Zod v4 toJSONSchema(), or Zod v3 schemas.`, debug: { hasInputSchema: !!toolModule.inputSchema, availableMethods: toolModule.inputSchema ? Object.keys(toolModule.inputSchema) : [], + hasZodDef: !!toolModule.inputSchema?._def, }, }, { status: 400 }