Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import * as z4 from 'zod/v4'; |
| 2 | |
| 3 | import { jsonSchemaToZod as v4Convert, jsonSchemaToZodShape as v4ConvertShape } from '../../src/v4'; |
| 4 | import type { Builder, RuntimeSchema, SchemaKind } from './builders'; |
| 5 | |
| 6 | const V4_KINDS: Record<string, SchemaKind> = { |
| 7 | string: 'string', |
| 8 | number: 'number', |
| 9 | boolean: 'boolean', |
| 10 | null: 'null', |
| 11 | object: 'object', |
| 12 | array: 'array', |
| 13 | }; |
| 14 | |
| 15 | const asV4 = (schema: RuntimeSchema): z4.ZodType => schema as unknown as z4.ZodType; |
| 16 | |
| 17 | export const v4: Builder = { |
| 18 | name: 'zod-v4', |
| 19 | convert: (schema, options) => v4Convert(schema, options) as unknown as RuntimeSchema, |
| 20 | convertShape: (schema, options) => |
| 21 | v4ConvertShape(schema, options) as unknown as Record<string, RuntimeSchema>, |
| 22 | objectFromShape: shape => |
| 23 | z4.object(shape as unknown as Record<string, z4.ZodType>) as unknown as RuntimeSchema, |
| 24 | kind: schema => V4_KINDS[asV4(schema).def.type] ?? 'other', |
| 25 | shape: schema => (asV4(schema) as z4.ZodObject).shape as unknown as Record<string, RuntimeSchema>, |
| 26 | description: schema => asV4(schema).description, |
| 27 | toJsonSchema: schema => z4.toJSONSchema(asV4(schema), { io: 'input' }) as Record<string, unknown>, |
| 28 | }; |