(schema: Record<string, z.ZodType<any>>)
| 72 | * @returns Array of tool parameters |
| 73 | */ |
| 74 | export function zodToParameters(schema: Record<string, z.ZodType<any>>): ToolParameter[] { |
| 75 | const parameters: ToolParameter[] = []; |
| 76 | |
| 77 | for (const [key, zodType] of Object.entries(schema)) { |
| 78 | // Extract description from Zod schema |
| 79 | const description = zodType.description || ""; |
| 80 | |
| 81 | // Determine if required (Zod types are required by default unless optional) |
| 82 | const required = !(zodType instanceof z.ZodOptional); |
| 83 | |
| 84 | // Determine type from Zod type |
| 85 | let type = "string"; // default |
| 86 | if (zodType instanceof z.ZodString) { |
| 87 | type = "string"; |
| 88 | } else if (zodType instanceof z.ZodNumber) { |
| 89 | type = "number"; |
| 90 | } else if (zodType instanceof z.ZodBoolean) { |
| 91 | type = "boolean"; |
| 92 | } else if (zodType instanceof z.ZodArray) { |
| 93 | type = "array"; |
| 94 | } else if (zodType instanceof z.ZodObject) { |
| 95 | type = "object"; |
| 96 | } |
| 97 | |
| 98 | parameters.push({ |
| 99 | name: key, |
| 100 | type, |
| 101 | required, |
| 102 | description, |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | return parameters; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get execute_sql tool metadata for a specific source |
no outgoing calls
no test coverage detected