@mastra/schema-compat 1.3.10-alpha.0 → 1.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.cjs");
2
2
  const require_zod_to_json = require("./zod-to-json.cjs");
3
3
  const require_standard_schema_adapters_ai_sdk = require("./standard-schema/adapters/ai-sdk.cjs");
4
- const require_json_schema = require("./json-schema-pcL1TeZs.cjs");
4
+ const require_json_schema = require("./json-schema-CEVTdogs.cjs");
5
5
  const require_standard_schema_adapters_zod_v3 = require("./standard-schema/adapters/zod-v3.cjs");
6
6
  let zod_v3 = require("zod/v3");
7
7
  zod_v3 = require_rolldown_runtime.__toESM(zod_v3, 1);
@@ -292,4 +292,4 @@ Object.defineProperty(exports, "toStandardSchema", {
292
292
  }
293
293
  });
294
294
 
295
- //# sourceMappingURL=schema-Cjk6OMG9.cjs.map
295
+ //# sourceMappingURL=schema-Bw7nQdgA.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-Cjk6OMG9.cjs","names":["toStandardSchema","z3","toStandardSchemaZodV4","toStandardSchemaZodV3","toStandardSchemaAiSdk","toStandardSchemaJsonSchema"],"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport { toJSONSchema } from 'zod/v4';\nimport { patchRecordSchemas } from '../../zod-to-json';\nimport type { StandardSchemaWithJSON, StandardSchemaWithJSONProps } from '../standard-schema.types';\n\n/**\n * Supported JSON Schema targets for z.toJSONSchema().\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n */\nconst SUPPORTED_TARGETS = new Set(['draft-07', 'draft-04', 'draft-2020-12']);\n\n/**\n * Maps Mastra's target names to Zod v4's expected format.\n * Zod v4's z.toJSONSchema() expects \"draft-7\" instead of \"draft-07\",\n * and \"draft-4\" instead of \"draft-04\".\n */\nconst ZOD_V4_TARGET_MAP: Record<string, string> = {\n 'draft-07': 'draft-7',\n 'draft-04': 'draft-4',\n};\n\n/**\n * Options for the Zod v4 adapter's JSON Schema conversion.\n */\nexport interface ZodV4AdapterOptions {\n unrepresentable?: 'any' | 'error';\n override?: (ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }) => undefined;\n}\n\n/**\n * Converts a Zod v4 schema to JSON Schema using z.toJSONSchema().\n *\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n *\n * @internal\n */\nfunction convertToJsonSchema(\n zodSchema: unknown,\n options: StandardJSONSchemaV1.Options,\n adapterOptions: ZodV4AdapterOptions,\n): Record<string, unknown> {\n // Work around a Zod v4 bug where `z.record(valueSchema)` puts the value\n // in `def.keyType` instead of `def.valueType`, which crashes\n // `toJSONSchema`'s `recordProcessor`. The legacy `zodToJsonSchema` entry\n // applies the same patch; this keeps the `applyCompatLayer` path in sync.\n // Idempotent — safe to call repeatedly.\n patchRecordSchemas(zodSchema);\n\n const target = SUPPORTED_TARGETS.has(options.target) ? options.target : 'draft-07';\n\n const jsonSchemaOptions: Record<string, unknown> = {\n target: ZOD_V4_TARGET_MAP[target] ?? target,\n };\n\n if (adapterOptions.unrepresentable) {\n jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;\n }\n\n // The override option works in real Zod v4 but is a no-op in 3.25 compat.\n if (adapterOptions.override) {\n jsonSchemaOptions.override = adapterOptions.override;\n }\n\n return toJSONSchema(zodSchema as Parameters<typeof toJSONSchema>[0], jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Wraps a Zod v4 schema to implement the full @standard-schema/spec interface.\n *\n * Zod v4 schemas (and Zod 3.25's v4 compat layer) implement `StandardSchemaV1`\n * (validation) but may not implement `StandardJSONSchemaV1` (JSON Schema conversion)\n * on the `~standard` property. This adapter adds the `jsonSchema` property using\n * `z.toJSONSchema()` to provide JSON Schema conversion capabilities.\n *\n * @param zodSchema - A Zod v4 schema (has `_zod` property)\n * @param adapterOptions - Options passed to z.toJSONSchema()\n * @returns The schema wrapped with StandardSchemaWithJSON support\n */\nexport function toStandardSchema<T>(\n zodSchema: T & { _zod: unknown; '~standard': StandardSchemaV1.Props },\n adapterOptions: ZodV4AdapterOptions = {},\n): T & StandardSchemaWithJSON {\n // Create a wrapper object that preserves the original schema's prototype chain\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON;\n\n // Get the existing ~standard property from Zod\n const existingStandard = (zodSchema as any)['~standard'] as StandardSchemaV1.Props;\n\n // Create the JSON Schema converter using z.toJSONSchema()\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n output: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n };\n\n // Define the enhanced ~standard property\n Object.defineProperty(wrapper, '~standard', {\n value: {\n ...existingStandard,\n jsonSchema: jsonSchemaConverter,\n } satisfies StandardSchemaWithJSONProps,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n","import type { Schema } from '@internal/ai-v6';\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchema7 } from 'json-schema';\nimport z3 from 'zod/v3';\nimport type { ZodType } from 'zod/v3';\nimport type { PublicSchema } from '../schema.types';\nimport { patchRecordSchemas } from '../zod-to-json';\nimport { toStandardSchema as toStandardSchemaAiSdk } from './adapters/ai-sdk';\nimport { toStandardSchema as toStandardSchemaJsonSchema } from './adapters/json-schema';\nimport { toStandardSchema as toStandardSchemaZodV3 } from './adapters/zod-v3';\nimport { toStandardSchema as toStandardSchemaZodV4 } from './adapters/zod-v4';\nimport type { StandardSchemaWithJSON } from './standard-schema.types';\n\n/**\n * Override function for JSON Schema conversion.\n * Handles types that Zod v4 cannot natively represent in JSON Schema:\n * - z.date() -> { type: 'string', format: 'date-time' }\n */\nfunction jsonSchemaOverride(ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }): undefined {\n const zodSchema = ctx.zodSchema as {\n type?: string;\n _def?: { typeName?: string };\n _zod?: { def?: { type?: string; coerce?: boolean } };\n optional?: () => unknown;\n };\n\n if (\n ctx.jsonSchema.type === 'object' &&\n ctx.jsonSchema.properties !== undefined &&\n !ctx.jsonSchema.additionalProperties\n ) {\n ctx.jsonSchema.additionalProperties = false;\n }\n\n if (zodSchema) {\n // Zod v4: zodSchema.type === 'date'\n // Zod v3: zodSchema._def.typeName === 'ZodDate'\n const isDateType = zodSchema?.type === 'date' || zodSchema?._def?.typeName === 'ZodDate';\n\n if (isDateType) {\n // Zod v4 dates need explicit JSON schema conversion (zod-to-json-schema doesn't handle them)\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n // Mark dates for #traverse: x-date=true means string→Date conversion needed.\n // z.coerce.date() handles its own coercion, so mark as false to prevent conversion.\n // Zod v3 has no coerce, so all v3 dates are strict (handled by preProcessJSONNode fallback).\n ctx.jsonSchema['x-date'] = !zodSchema._zod?.def?.coerce;\n // @ts-expect-error - catchall is a valid property for zod\n } else if (zodSchema?.type === 'object' && zodSchema._zod?.def?.catchall?.type === 'unknown') {\n ctx.jsonSchema.additionalProperties = true;\n }\n }\n\n return undefined;\n}\n/**\n * Library options for JSON Schema conversion.\n * - unrepresentable: 'any' allows z.custom() and other unrepresentable types to be converted to {}\n * instead of throwing \"Custom types cannot be represented in JSON Schema\"\n * - override: converts z.date() to { type: 'string', format: 'date-time' }\n */\nexport const JSON_SCHEMA_LIBRARY_OPTIONS = {\n unrepresentable: 'any' as const,\n override: jsonSchemaOverride,\n};\n\nexport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n InferInput,\n InferOutput,\n StandardSchemaIssue,\n} from './standard-schema.types';\n\nfunction isVercelSchema(schema: unknown): schema is Schema {\n return (\n typeof schema === 'object' &&\n schema !== null &&\n '_type' in schema &&\n 'jsonSchema' in schema &&\n typeof (schema as Schema).jsonSchema === 'object'\n );\n}\n\n/**\n * Check if a schema is Zod v4 (has _zod property which is v4-only)\n */\nfunction isZodV4(schema: unknown): boolean {\n return typeof schema === 'object' && schema !== null && '_zod' in schema;\n}\n\n/**\n * Check if a schema is Zod v3.\n *\n * Zod v3 can come from:\n * 1. The old standalone 'zod-v3' package\n * 2. The 'zod/v3' compat export from modern zod\n *\n * We detect Zod v3 by checking:\n * - Has ~standard.vendor === 'zod' (both v3 and v4 have this)\n * - Does NOT have ~standard.jsonSchema (only Zod v4 has native JSON Schema support)\n * - Does NOT have _zod property (only Zod v4 has this)\n *\n * Note: We can't use instanceof z3.ZodType because the old 'zod-v3' package\n * has a different prototype chain than 'zod/v3'.\n */\nfunction isZodV3(schema: unknown): schema is ZodType {\n if (schema === null || typeof schema !== 'object') {\n return false;\n }\n\n // Must not be Zod v4\n if (isZodV4(schema)) {\n return false;\n }\n\n // Check for ~standard with vendor 'zod' but no jsonSchema\n if ('~standard' in schema) {\n const std = (schema as any)['~standard'];\n if (typeof std === 'object' && std !== null && std.vendor === 'zod' && !('jsonSchema' in std)) {\n return true;\n }\n }\n\n // Fallback: check instanceof for zod/v3 compat export\n return schema instanceof z3.ZodType;\n}\n\nexport function toStandardSchema<T = unknown>(schema: PublicSchema<T>): StandardSchemaWithJSON<T> {\n // Work around a Zod v4 (< 4.4.0) bug where single-arg `z.record(valueSchema)`\n // puts the value in `def.keyType` and leaves `def.valueType` undefined, which\n // crashes `toJSONSchema`'s recordProcessor. This must run BEFORE the\n // StandardSchemaWithJSON short-circuit below: Zod >= 4.2 natively exposes\n // `~standard.jsonSchema`, so those schemas are returned as-is and never go\n // through our Zod v4 adapter. Patching mutates the defs in place, so Zod's\n // native converter picks up the fix too. Idempotent — safe to call repeatedly.\n if (isZodV4(schema)) {\n patchRecordSchemas(schema);\n }\n\n // First check: if already StandardSchemaWithJSON, return as-is\n // This handles ArkType, Zod v4 (when it has jsonSchema), and pre-wrapped schemas\n if (isStandardSchemaWithJSON(schema)) {\n return schema;\n }\n\n // Check for Zod v4 schemas without ~standard.jsonSchema\n // This handles both real Zod v4 and Zod 3.25's v4 compat layer where\n // ~standard.jsonSchema is not present on the schema object\n if (isZodV4(schema)) {\n return toStandardSchemaZodV4(schema as any, {\n unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,\n override: JSON_SCHEMA_LIBRARY_OPTIONS.override,\n });\n }\n\n // Check for Zod v3 schemas (need wrapping to add JSON Schema support)\n // Important: Must use isZodV3() not instanceof z3.ZodType because\n // Zod v4 schemas are also instanceof z3.ZodType due to prototype compatibility\n if (isZodV3(schema)) {\n return toStandardSchemaZodV3(schema as ZodType);\n }\n\n // Check for AI SDK Schema objects (Vercel's jsonSchema wrapper)\n if (isVercelSchema(schema)) {\n return toStandardSchemaAiSdk(schema as Schema<T>);\n }\n\n // At this point, assume it's a plain JSON Schema object\n // JSON Schema objects are plain objects with properties like 'type', 'properties', etc.\n if (schema === null || (typeof schema !== 'object' && typeof schema !== 'function')) {\n throw new Error(`Unsupported schema type: ${typeof schema}`);\n }\n\n // If it's a function that's not StandardSchemaWithJSON, it's not supported\n if (typeof schema === 'function') {\n throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);\n }\n\n return toStandardSchemaJsonSchema(schema as JSONSchema7);\n}\n\n/**\n * Type guard to check if a value implements the StandardSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardSchema } from '@mastra/schema-compat';\n *\n * if (isStandardSchema(someValue)) {\n * const result = someValue['~standard'].validate(input);\n * }\n * ```\n */\nexport function isStandardSchema(value: unknown): value is StandardSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n return (\n typeof std === 'object' &&\n std !== null &&\n 'version' in std &&\n std.version === 1 &&\n 'vendor' in std &&\n 'validate' in std &&\n typeof std.validate === 'function'\n );\n}\n\n/**\n * Type guard to check if a value implements the StandardJSONSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardJSONSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardJSONSchema } from '@mastra/schema-compat';\n *\n * if (isStandardJSONSchema(someValue)) {\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardJSONSchema(value: unknown): value is StandardJSONSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n if (typeof std !== 'object' || std === null) {\n return false;\n }\n if (!('version' in std) || std.version !== 1 || !('vendor' in std)) {\n return false;\n }\n if (!('jsonSchema' in std) || typeof std.jsonSchema !== 'object') {\n return false;\n }\n return typeof std.jsonSchema.input === 'function' && typeof std.jsonSchema.output === 'function';\n}\n\n/**\n * Type guard to check if a value implements both StandardSchemaV1 and StandardJSONSchemaV1.\n *\n * @param value - The value to check\n * @returns True if the value implements both interfaces\n *\n * @example\n * ```typescript\n * import { isStandardSchemaWithJSON } from '@mastra/schema-compat';\n *\n * if (isStandardSchemaWithJSON(someValue)) {\n * // Can use both validation and JSON Schema conversion\n * const result = someValue['~standard'].validate(input);\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardSchemaWithJSON(value: unknown): value is StandardSchemaWithJSON {\n return isStandardSchema(value) && isStandardJSONSchema(value);\n}\n\n/**\n * Converts a StandardSchemaWithJSON to a JSON Schema.\n *\n * @param schema - The StandardSchemaWithJSON schema to convert\n * @param options - Conversion options\n * @param options.target - The JSON Schema target version (default: 'draft-07')\n * @param options.io - Whether to use input or output schema (default: 'output')\n * - 'input': Use for tool parameters, function arguments, request bodies\n * - 'output': Use for return types, response bodies\n * @returns The JSON Schema representation\n *\n * @example\n * ```typescript\n * import { standardSchemaToJSONSchema, toStandardSchema } from '@mastra/schema-compat';\n * import { z } from 'zod';\n *\n * const zodSchema = z.object({ name: z.string() });\n * const standardSchema = toStandardSchema(zodSchema);\n *\n * // For output types (default)\n * const outputSchema = standardSchemaToJSONSchema(standardSchema);\n *\n * // For input types (tool parameters)\n * const inputSchema = standardSchemaToJSONSchema(standardSchema, { io: 'input' });\n * ```\n */\nexport function standardSchemaToJSONSchema(\n schema: StandardSchemaWithJSON,\n options: {\n target?: StandardJSONSchemaV1.Target;\n io?: 'input' | 'output';\n override?: (typeof JSON_SCHEMA_LIBRARY_OPTIONS)['override'];\n } = {},\n): JSONSchema7 {\n const { target = 'draft-07', io = 'output', override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;\n const jsonSchemaFn = schema['~standard'].jsonSchema[io];\n let jsonSchema = jsonSchemaFn({\n target,\n libraryOptions: {\n ...JSON_SCHEMA_LIBRARY_OPTIONS,\n override,\n },\n }) as JSONSchema7;\n\n // make sure only jsonSchema is left, no standard schema metadata\n jsonSchema = JSON.parse(JSON.stringify(jsonSchema));\n\n return jsonSchema;\n}\n"],"mappings":";;;;;;;;;;;;;AASA,MAAM,oCAAoB,IAAI,IAAI;CAAC;CAAY;CAAY;AAAe,CAAC;;;;;;AAO3E,MAAM,oBAA4C;CAChD,YAAY;CACZ,YAAY;AACd;;;;;;;;AAiBA,SAAS,oBACP,WACA,SACA,gBACyB;CAMzB,oBAAA,mBAAmB,SAAS;CAE5B,MAAM,SAAS,kBAAkB,IAAI,QAAQ,MAAM,IAAI,QAAQ,SAAS;CAExE,MAAM,oBAA6C,EACjD,QAAQ,kBAAkB,WAAW,OACvC;CAEA,IAAI,eAAe,iBACjB,kBAAkB,kBAAkB,eAAe;CAIrD,IAAI,eAAe,UACjB,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OAA+C;CAElF,IAAI,UAAU,QAAS,OAAO,UAAU,YAAY,OAAO,UAAU,YACnE,OAAO;CAET,IAAI,EAAE,eAAe,QACnB,OAAO;CAET,MAAM,MAAO,MAAc;CAC3B,IAAI,OAAO,QAAQ,YAAY,QAAQ,MACrC,OAAO;CAET,IAAI,EAAE,aAAa,QAAQ,IAAI,YAAY,KAAK,EAAE,YAAY,MAC5D,OAAO;CAET,IAAI,EAAE,gBAAgB,QAAQ,OAAO,IAAI,eAAe,UACtD,OAAO;CAET,OAAO,OAAO,IAAI,WAAW,UAAU,cAAc,OAAO,IAAI,WAAW,WAAW;AACxF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,yBAAyB,OAAiD;CACxF,OAAO,iBAAiB,KAAK,KAAK,qBAAqB,KAAK;AAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,2BACd,QACA,UAII,CAAC,GACQ;CACb,MAAM,EAAE,SAAS,YAAY,KAAK,UAAU,WAAW,4BAA4B,aAAa;CAChG,MAAM,eAAe,OAAO,YAAY,CAAC,WAAW;CACpD,IAAI,aAAa,aAAa;EAC5B;EACA,gBAAgB;GACd,GAAG;GACH;EACF;CACF,CAAC;CAGD,aAAa,KAAK,MAAM,KAAK,UAAU,UAAU,CAAC;CAElD,OAAO;AACT"}
1
+ {"version":3,"file":"schema-Bw7nQdgA.cjs","names":["toStandardSchema","z3","toStandardSchemaZodV4","toStandardSchemaZodV3","toStandardSchemaAiSdk","toStandardSchemaJsonSchema"],"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport { toJSONSchema } from 'zod/v4';\nimport { patchRecordSchemas } from '../../zod-to-json';\nimport type { StandardSchemaWithJSON, StandardSchemaWithJSONProps } from '../standard-schema.types';\n\n/**\n * Supported JSON Schema targets for z.toJSONSchema().\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n */\nconst SUPPORTED_TARGETS = new Set(['draft-07', 'draft-04', 'draft-2020-12']);\n\n/**\n * Maps Mastra's target names to Zod v4's expected format.\n * Zod v4's z.toJSONSchema() expects \"draft-7\" instead of \"draft-07\",\n * and \"draft-4\" instead of \"draft-04\".\n */\nconst ZOD_V4_TARGET_MAP: Record<string, string> = {\n 'draft-07': 'draft-7',\n 'draft-04': 'draft-4',\n};\n\n/**\n * Options for the Zod v4 adapter's JSON Schema conversion.\n */\nexport interface ZodV4AdapterOptions {\n unrepresentable?: 'any' | 'error';\n override?: (ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }) => undefined;\n}\n\n/**\n * Converts a Zod v4 schema to JSON Schema using z.toJSONSchema().\n *\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n *\n * @internal\n */\nfunction convertToJsonSchema(\n zodSchema: unknown,\n options: StandardJSONSchemaV1.Options,\n adapterOptions: ZodV4AdapterOptions,\n): Record<string, unknown> {\n // Work around a Zod v4 bug where `z.record(valueSchema)` puts the value\n // in `def.keyType` instead of `def.valueType`, which crashes\n // `toJSONSchema`'s `recordProcessor`. The legacy `zodToJsonSchema` entry\n // applies the same patch; this keeps the `applyCompatLayer` path in sync.\n // Idempotent — safe to call repeatedly.\n patchRecordSchemas(zodSchema);\n\n const target = SUPPORTED_TARGETS.has(options.target) ? options.target : 'draft-07';\n\n const jsonSchemaOptions: Record<string, unknown> = {\n target: ZOD_V4_TARGET_MAP[target] ?? target,\n };\n\n if (adapterOptions.unrepresentable) {\n jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;\n }\n\n // The override option works in real Zod v4 but is a no-op in 3.25 compat.\n if (adapterOptions.override) {\n jsonSchemaOptions.override = adapterOptions.override;\n }\n\n return toJSONSchema(zodSchema as Parameters<typeof toJSONSchema>[0], jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Wraps a Zod v4 schema to implement the full @standard-schema/spec interface.\n *\n * Zod v4 schemas (and Zod 3.25's v4 compat layer) implement `StandardSchemaV1`\n * (validation) but may not implement `StandardJSONSchemaV1` (JSON Schema conversion)\n * on the `~standard` property. This adapter adds the `jsonSchema` property using\n * `z.toJSONSchema()` to provide JSON Schema conversion capabilities.\n *\n * @param zodSchema - A Zod v4 schema (has `_zod` property)\n * @param adapterOptions - Options passed to z.toJSONSchema()\n * @returns The schema wrapped with StandardSchemaWithJSON support\n */\nexport function toStandardSchema<T>(\n zodSchema: T & { _zod: unknown; '~standard': StandardSchemaV1.Props },\n adapterOptions: ZodV4AdapterOptions = {},\n): T & StandardSchemaWithJSON {\n // Create a wrapper object that preserves the original schema's prototype chain\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON;\n\n // Get the existing ~standard property from Zod\n const existingStandard = (zodSchema as any)['~standard'] as StandardSchemaV1.Props;\n\n // Create the JSON Schema converter using z.toJSONSchema()\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n output: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n };\n\n // Define the enhanced ~standard property\n Object.defineProperty(wrapper, '~standard', {\n value: {\n ...existingStandard,\n jsonSchema: jsonSchemaConverter,\n } satisfies StandardSchemaWithJSONProps,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n","import type { Schema } from '@internal/ai-v6';\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchema7 } from 'json-schema';\nimport z3 from 'zod/v3';\nimport type { ZodType } from 'zod/v3';\nimport type { PublicSchema } from '../schema.types';\nimport { patchRecordSchemas } from '../zod-to-json';\nimport { toStandardSchema as toStandardSchemaAiSdk } from './adapters/ai-sdk';\nimport { toStandardSchema as toStandardSchemaJsonSchema } from './adapters/json-schema';\nimport { toStandardSchema as toStandardSchemaZodV3 } from './adapters/zod-v3';\nimport { toStandardSchema as toStandardSchemaZodV4 } from './adapters/zod-v4';\nimport type { StandardSchemaWithJSON } from './standard-schema.types';\n\n/**\n * Override function for JSON Schema conversion.\n * Handles types that Zod v4 cannot natively represent in JSON Schema:\n * - z.date() -> { type: 'string', format: 'date-time' }\n */\nfunction jsonSchemaOverride(ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }): undefined {\n const zodSchema = ctx.zodSchema as {\n type?: string;\n _def?: { typeName?: string };\n _zod?: { def?: { type?: string; coerce?: boolean } };\n optional?: () => unknown;\n };\n\n if (\n ctx.jsonSchema.type === 'object' &&\n ctx.jsonSchema.properties !== undefined &&\n !ctx.jsonSchema.additionalProperties\n ) {\n ctx.jsonSchema.additionalProperties = false;\n }\n\n if (zodSchema) {\n // Zod v4: zodSchema.type === 'date'\n // Zod v3: zodSchema._def.typeName === 'ZodDate'\n const isDateType = zodSchema?.type === 'date' || zodSchema?._def?.typeName === 'ZodDate';\n\n if (isDateType) {\n // Zod v4 dates need explicit JSON schema conversion (zod-to-json-schema doesn't handle them)\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n // Mark dates for #traverse: x-date=true means string→Date conversion needed.\n // z.coerce.date() handles its own coercion, so mark as false to prevent conversion.\n // Zod v3 has no coerce, so all v3 dates are strict (handled by preProcessJSONNode fallback).\n ctx.jsonSchema['x-date'] = !zodSchema._zod?.def?.coerce;\n // @ts-expect-error - catchall is a valid property for zod\n } else if (zodSchema?.type === 'object' && zodSchema._zod?.def?.catchall?.type === 'unknown') {\n ctx.jsonSchema.additionalProperties = true;\n }\n }\n\n return undefined;\n}\n/**\n * Library options for JSON Schema conversion.\n * - unrepresentable: 'any' allows z.custom() and other unrepresentable types to be converted to {}\n * instead of throwing \"Custom types cannot be represented in JSON Schema\"\n * - override: converts z.date() to { type: 'string', format: 'date-time' }\n */\nexport const JSON_SCHEMA_LIBRARY_OPTIONS = {\n unrepresentable: 'any' as const,\n override: jsonSchemaOverride,\n};\n\nexport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n InferInput,\n InferOutput,\n StandardSchemaIssue,\n} from './standard-schema.types';\n\nfunction isVercelSchema(schema: unknown): schema is Schema {\n return (\n typeof schema === 'object' &&\n schema !== null &&\n '_type' in schema &&\n 'jsonSchema' in schema &&\n typeof (schema as Schema).jsonSchema === 'object'\n );\n}\n\n/**\n * Check if a schema is Zod v4 (has _zod property which is v4-only)\n */\nfunction isZodV4(schema: unknown): boolean {\n return typeof schema === 'object' && schema !== null && '_zod' in schema;\n}\n\n/**\n * Check if a schema is Zod v3.\n *\n * Zod v3 can come from:\n * 1. The old standalone 'zod-v3' package\n * 2. The 'zod/v3' compat export from modern zod\n *\n * We detect Zod v3 by checking:\n * - Has ~standard.vendor === 'zod' (both v3 and v4 have this)\n * - Does NOT have ~standard.jsonSchema (only Zod v4 has native JSON Schema support)\n * - Does NOT have _zod property (only Zod v4 has this)\n *\n * Note: We can't use instanceof z3.ZodType because the old 'zod-v3' package\n * has a different prototype chain than 'zod/v3'.\n */\nfunction isZodV3(schema: unknown): schema is ZodType {\n if (schema === null || typeof schema !== 'object') {\n return false;\n }\n\n // Must not be Zod v4\n if (isZodV4(schema)) {\n return false;\n }\n\n // Check for ~standard with vendor 'zod' but no jsonSchema\n if ('~standard' in schema) {\n const std = (schema as any)['~standard'];\n if (typeof std === 'object' && std !== null && std.vendor === 'zod' && !('jsonSchema' in std)) {\n return true;\n }\n }\n\n // Fallback: check instanceof for zod/v3 compat export\n return schema instanceof z3.ZodType;\n}\n\nexport function toStandardSchema<T = unknown>(schema: PublicSchema<T>): StandardSchemaWithJSON<T> {\n // Work around a Zod v4 (< 4.4.0) bug where single-arg `z.record(valueSchema)`\n // puts the value in `def.keyType` and leaves `def.valueType` undefined, which\n // crashes `toJSONSchema`'s recordProcessor. This must run BEFORE the\n // StandardSchemaWithJSON short-circuit below: Zod >= 4.2 natively exposes\n // `~standard.jsonSchema`, so those schemas are returned as-is and never go\n // through our Zod v4 adapter. Patching mutates the defs in place, so Zod's\n // native converter picks up the fix too. Idempotent — safe to call repeatedly.\n if (isZodV4(schema)) {\n patchRecordSchemas(schema);\n }\n\n // First check: if already StandardSchemaWithJSON, return as-is\n // This handles ArkType, Zod v4 (when it has jsonSchema), and pre-wrapped schemas\n if (isStandardSchemaWithJSON(schema)) {\n return schema;\n }\n\n // Check for Zod v4 schemas without ~standard.jsonSchema\n // This handles both real Zod v4 and Zod 3.25's v4 compat layer where\n // ~standard.jsonSchema is not present on the schema object\n if (isZodV4(schema)) {\n return toStandardSchemaZodV4(schema as any, {\n unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,\n override: JSON_SCHEMA_LIBRARY_OPTIONS.override,\n });\n }\n\n // Check for Zod v3 schemas (need wrapping to add JSON Schema support)\n // Important: Must use isZodV3() not instanceof z3.ZodType because\n // Zod v4 schemas are also instanceof z3.ZodType due to prototype compatibility\n if (isZodV3(schema)) {\n return toStandardSchemaZodV3(schema as ZodType);\n }\n\n // Check for AI SDK Schema objects (Vercel's jsonSchema wrapper)\n if (isVercelSchema(schema)) {\n return toStandardSchemaAiSdk(schema);\n }\n\n // At this point, assume it's a plain JSON Schema object\n // JSON Schema objects are plain objects with properties like 'type', 'properties', etc.\n if (schema === null || (typeof schema !== 'object' && typeof schema !== 'function')) {\n throw new Error(`Unsupported schema type: ${typeof schema}`);\n }\n\n // If it's a function that's not StandardSchemaWithJSON, it's not supported\n if (typeof schema === 'function') {\n throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);\n }\n\n return toStandardSchemaJsonSchema(schema as JSONSchema7);\n}\n\n/**\n * Type guard to check if a value implements the StandardSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardSchema } from '@mastra/schema-compat';\n *\n * if (isStandardSchema(someValue)) {\n * const result = someValue['~standard'].validate(input);\n * }\n * ```\n */\nexport function isStandardSchema(value: unknown): value is StandardSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n return (\n typeof std === 'object' &&\n std !== null &&\n 'version' in std &&\n std.version === 1 &&\n 'vendor' in std &&\n 'validate' in std &&\n typeof std.validate === 'function'\n );\n}\n\n/**\n * Type guard to check if a value implements the StandardJSONSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardJSONSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardJSONSchema } from '@mastra/schema-compat';\n *\n * if (isStandardJSONSchema(someValue)) {\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardJSONSchema(value: unknown): value is StandardJSONSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n if (typeof std !== 'object' || std === null) {\n return false;\n }\n if (!('version' in std) || std.version !== 1 || !('vendor' in std)) {\n return false;\n }\n if (!('jsonSchema' in std) || typeof std.jsonSchema !== 'object') {\n return false;\n }\n return typeof std.jsonSchema.input === 'function' && typeof std.jsonSchema.output === 'function';\n}\n\n/**\n * Type guard to check if a value implements both StandardSchemaV1 and StandardJSONSchemaV1.\n *\n * @param value - The value to check\n * @returns True if the value implements both interfaces\n *\n * @example\n * ```typescript\n * import { isStandardSchemaWithJSON } from '@mastra/schema-compat';\n *\n * if (isStandardSchemaWithJSON(someValue)) {\n * // Can use both validation and JSON Schema conversion\n * const result = someValue['~standard'].validate(input);\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardSchemaWithJSON(value: unknown): value is StandardSchemaWithJSON {\n return isStandardSchema(value) && isStandardJSONSchema(value);\n}\n\n/**\n * Converts a StandardSchemaWithJSON to a JSON Schema.\n *\n * @param schema - The StandardSchemaWithJSON schema to convert\n * @param options - Conversion options\n * @param options.target - The JSON Schema target version (default: 'draft-07')\n * @param options.io - Whether to use input or output schema (default: 'output')\n * - 'input': Use for tool parameters, function arguments, request bodies\n * - 'output': Use for return types, response bodies\n * @returns The JSON Schema representation\n *\n * @example\n * ```typescript\n * import { standardSchemaToJSONSchema, toStandardSchema } from '@mastra/schema-compat';\n * import { z } from 'zod';\n *\n * const zodSchema = z.object({ name: z.string() });\n * const standardSchema = toStandardSchema(zodSchema);\n *\n * // For output types (default)\n * const outputSchema = standardSchemaToJSONSchema(standardSchema);\n *\n * // For input types (tool parameters)\n * const inputSchema = standardSchemaToJSONSchema(standardSchema, { io: 'input' });\n * ```\n */\nexport function standardSchemaToJSONSchema(\n schema: StandardSchemaWithJSON,\n options: {\n target?: StandardJSONSchemaV1.Target;\n io?: 'input' | 'output';\n override?: (typeof JSON_SCHEMA_LIBRARY_OPTIONS)['override'];\n } = {},\n): JSONSchema7 {\n const { target = 'draft-07', io = 'output', override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;\n const jsonSchemaFn = schema['~standard'].jsonSchema[io];\n let jsonSchema = jsonSchemaFn({\n target,\n libraryOptions: {\n ...JSON_SCHEMA_LIBRARY_OPTIONS,\n override,\n },\n }) as JSONSchema7;\n\n // make sure only jsonSchema is left, no standard schema metadata\n jsonSchema = JSON.parse(JSON.stringify(jsonSchema));\n\n return jsonSchema;\n}\n"],"mappings":";;;;;;;;;;;;;AASA,MAAM,oCAAoB,IAAI,IAAI;CAAC;CAAY;CAAY;AAAe,CAAC;;;;;;AAO3E,MAAM,oBAA4C;CAChD,YAAY;CACZ,YAAY;AACd;;;;;;;;AAiBA,SAAS,oBACP,WACA,SACA,gBACyB;CAMzB,oBAAA,mBAAmB,SAAS;CAE5B,MAAM,SAAS,kBAAkB,IAAI,QAAQ,MAAM,IA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,QAAQ,YACf,QAAQ,QACR,aAAa,OACb,IAAI,YAAY,KAChB,YAAY,OACZ,cAAc,OACd,OAAO,IAAI,aAAa;AAE5B;;;;;;;;;;;;;;;;AAiBA,SAAgB,qBAAqB,OAA+C;CAElF,IAAI,UAAU,QAAS,OAAO,UAAU,YAAY,OAAO,UAAU,YACnE,OAAO;CAET,IAAI,EAAE,eAAe,QACnB,OAAO;CAET,MAAM,MAAO,MAAc;CAC3B,IAAI,OAAO,QAAQ,YAAY,QAAQ,MACrC,OAAO;CAET,IAAI,EAAE,aAAa,QAAQ,IAAI,YAAY,KAAK,EAAE,YAAY,MAC5D,OAAO;CAET,IAAI,EAAE,gBAAgB,QAAQ,OAAO,IAAI,eAAe,UACtD,OAAO;CAET,OAAO,OAAO,IAAI,WAAW,UAAU,cAAc,OAAO,IAAI,WAAW,WAAW;AACxF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,yBAAyB,OAAiD;CACxF,OAAO,iBAAiB,KAAK,KAAK,qBAAqB,KAAK;AAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,2BACd,QACA,UAII,CAAC,GACQ;CACb,MAAM,EAAE,SAAS,YAAY,KAAK,UAAU,WAAW,4BAA4B,aAAa;CAChG,MAAM,eAAe,OAAO,YAAY,CAAC,WAAW;CACpD,IAAI,aAAa,aAAa;EAC5B;EACA,gBAAgB;GACd,GAAG;GACH;EACF;CACF,CAAC;CAGD,aAAa,KAAK,MAAM,KAAK,UAAU,UAAU,CAAC;CAElD,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { patchRecordSchemas } from "./zod-to-json.js";
2
2
  import { toStandardSchema as toStandardSchema$2 } from "./standard-schema/adapters/ai-sdk.js";
3
- import { n as toStandardSchema$3 } from "./json-schema-BstKYbJi.js";
3
+ import { n as toStandardSchema$3 } from "./json-schema-BKit3LVN.js";
4
4
  import { toStandardSchema as toStandardSchema$4 } from "./standard-schema/adapters/zod-v3.js";
5
5
  import z3 from "zod/v3";
6
6
  import { toJSONSchema } from "zod/v4";
@@ -255,4 +255,4 @@ function standardSchemaToJSONSchema(schema, options = {}) {
255
255
  //#endregion
256
256
  export { standardSchemaToJSONSchema as a, isStandardSchemaWithJSON as i, isStandardJSONSchema as n, toStandardSchema as o, isStandardSchema as r, JSON_SCHEMA_LIBRARY_OPTIONS as t };
257
257
 
258
- //# sourceMappingURL=schema-Bv9OdW1f.js.map
258
+ //# sourceMappingURL=schema-D_ikovK6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-Bv9OdW1f.js","names":["toStandardSchema","toStandardSchemaZodV4","toStandardSchemaZodV3","toStandardSchemaAiSdk","toStandardSchemaJsonSchema"],"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport { toJSONSchema } from 'zod/v4';\nimport { patchRecordSchemas } from '../../zod-to-json';\nimport type { StandardSchemaWithJSON, StandardSchemaWithJSONProps } from '../standard-schema.types';\n\n/**\n * Supported JSON Schema targets for z.toJSONSchema().\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n */\nconst SUPPORTED_TARGETS = new Set(['draft-07', 'draft-04', 'draft-2020-12']);\n\n/**\n * Maps Mastra's target names to Zod v4's expected format.\n * Zod v4's z.toJSONSchema() expects \"draft-7\" instead of \"draft-07\",\n * and \"draft-4\" instead of \"draft-04\".\n */\nconst ZOD_V4_TARGET_MAP: Record<string, string> = {\n 'draft-07': 'draft-7',\n 'draft-04': 'draft-4',\n};\n\n/**\n * Options for the Zod v4 adapter's JSON Schema conversion.\n */\nexport interface ZodV4AdapterOptions {\n unrepresentable?: 'any' | 'error';\n override?: (ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }) => undefined;\n}\n\n/**\n * Converts a Zod v4 schema to JSON Schema using z.toJSONSchema().\n *\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n *\n * @internal\n */\nfunction convertToJsonSchema(\n zodSchema: unknown,\n options: StandardJSONSchemaV1.Options,\n adapterOptions: ZodV4AdapterOptions,\n): Record<string, unknown> {\n // Work around a Zod v4 bug where `z.record(valueSchema)` puts the value\n // in `def.keyType` instead of `def.valueType`, which crashes\n // `toJSONSchema`'s `recordProcessor`. The legacy `zodToJsonSchema` entry\n // applies the same patch; this keeps the `applyCompatLayer` path in sync.\n // Idempotent — safe to call repeatedly.\n patchRecordSchemas(zodSchema);\n\n const target = SUPPORTED_TARGETS.has(options.target) ? options.target : 'draft-07';\n\n const jsonSchemaOptions: Record<string, unknown> = {\n target: ZOD_V4_TARGET_MAP[target] ?? target,\n };\n\n if (adapterOptions.unrepresentable) {\n jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;\n }\n\n // The override option works in real Zod v4 but is a no-op in 3.25 compat.\n if (adapterOptions.override) {\n jsonSchemaOptions.override = adapterOptions.override;\n }\n\n return toJSONSchema(zodSchema as Parameters<typeof toJSONSchema>[0], jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Wraps a Zod v4 schema to implement the full @standard-schema/spec interface.\n *\n * Zod v4 schemas (and Zod 3.25's v4 compat layer) implement `StandardSchemaV1`\n * (validation) but may not implement `StandardJSONSchemaV1` (JSON Schema conversion)\n * on the `~standard` property. This adapter adds the `jsonSchema` property using\n * `z.toJSONSchema()` to provide JSON Schema conversion capabilities.\n *\n * @param zodSchema - A Zod v4 schema (has `_zod` property)\n * @param adapterOptions - Options passed to z.toJSONSchema()\n * @returns The schema wrapped with StandardSchemaWithJSON support\n */\nexport function toStandardSchema<T>(\n zodSchema: T & { _zod: unknown; '~standard': StandardSchemaV1.Props },\n adapterOptions: ZodV4AdapterOptions = {},\n): T & StandardSchemaWithJSON {\n // Create a wrapper object that preserves the original schema's prototype chain\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON;\n\n // Get the existing ~standard property from Zod\n const existingStandard = (zodSchema as any)['~standard'] as StandardSchemaV1.Props;\n\n // Create the JSON Schema converter using z.toJSONSchema()\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n output: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n };\n\n // Define the enhanced ~standard property\n Object.defineProperty(wrapper, '~standard', {\n value: {\n ...existingStandard,\n jsonSchema: jsonSchemaConverter,\n } satisfies StandardSchemaWithJSONProps,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n","import type { Schema } from '@internal/ai-v6';\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchema7 } from 'json-schema';\nimport z3 from 'zod/v3';\nimport type { ZodType } from 'zod/v3';\nimport type { PublicSchema } from '../schema.types';\nimport { patchRecordSchemas } from '../zod-to-json';\nimport { toStandardSchema as toStandardSchemaAiSdk } from './adapters/ai-sdk';\nimport { toStandardSchema as toStandardSchemaJsonSchema } from './adapters/json-schema';\nimport { toStandardSchema as toStandardSchemaZodV3 } from './adapters/zod-v3';\nimport { toStandardSchema as toStandardSchemaZodV4 } from './adapters/zod-v4';\nimport type { StandardSchemaWithJSON } from './standard-schema.types';\n\n/**\n * Override function for JSON Schema conversion.\n * Handles types that Zod v4 cannot natively represent in JSON Schema:\n * - z.date() -> { type: 'string', format: 'date-time' }\n */\nfunction jsonSchemaOverride(ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }): undefined {\n const zodSchema = ctx.zodSchema as {\n type?: string;\n _def?: { typeName?: string };\n _zod?: { def?: { type?: string; coerce?: boolean } };\n optional?: () => unknown;\n };\n\n if (\n ctx.jsonSchema.type === 'object' &&\n ctx.jsonSchema.properties !== undefined &&\n !ctx.jsonSchema.additionalProperties\n ) {\n ctx.jsonSchema.additionalProperties = false;\n }\n\n if (zodSchema) {\n // Zod v4: zodSchema.type === 'date'\n // Zod v3: zodSchema._def.typeName === 'ZodDate'\n const isDateType = zodSchema?.type === 'date' || zodSchema?._def?.typeName === 'ZodDate';\n\n if (isDateType) {\n // Zod v4 dates need explicit JSON schema conversion (zod-to-json-schema doesn't handle them)\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n // Mark dates for #traverse: x-date=true means string→Date conversion needed.\n // z.coerce.date() handles its own coercion, so mark as false to prevent conversion.\n // Zod v3 has no coerce, so all v3 dates are strict (handled by preProcessJSONNode fallback).\n ctx.jsonSchema['x-date'] = !zodSchema._zod?.def?.coerce;\n // @ts-expect-error - catchall is a valid property for zod\n } else if (zodSchema?.type === 'object' && zodSchema._zod?.def?.catchall?.type === 'unknown') {\n ctx.jsonSchema.additionalProperties = true;\n }\n }\n\n return undefined;\n}\n/**\n * Library options for JSON Schema conversion.\n * - unrepresentable: 'any' allows z.custom() and other unrepresentable types to be converted to {}\n * instead of throwing \"Custom types cannot be represented in JSON Schema\"\n * - override: converts z.date() to { type: 'string', format: 'date-time' }\n */\nexport const JSON_SCHEMA_LIBRARY_OPTIONS = {\n unrepresentable: 'any' as const,\n override: jsonSchemaOverride,\n};\n\nexport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n InferInput,\n InferOutput,\n StandardSchemaIssue,\n} from './standard-schema.types';\n\nfunction isVercelSchema(schema: unknown): schema is Schema {\n return (\n typeof schema === 'object' &&\n schema !== null &&\n '_type' in schema &&\n 'jsonSchema' in schema &&\n typeof (schema as Schema).jsonSchema === 'object'\n );\n}\n\n/**\n * Check if a schema is Zod v4 (has _zod property which is v4-only)\n */\nfunction isZodV4(schema: unknown): boolean {\n return typeof schema === 'object' && schema !== null && '_zod' in schema;\n}\n\n/**\n * Check if a schema is Zod v3.\n *\n * Zod v3 can come from:\n * 1. The old standalone 'zod-v3' package\n * 2. The 'zod/v3' compat export from modern zod\n *\n * We detect Zod v3 by checking:\n * - Has ~standard.vendor === 'zod' (both v3 and v4 have this)\n * - Does NOT have ~standard.jsonSchema (only Zod v4 has native JSON Schema support)\n * - Does NOT have _zod property (only Zod v4 has this)\n *\n * Note: We can't use instanceof z3.ZodType because the old 'zod-v3' package\n * has a different prototype chain than 'zod/v3'.\n */\nfunction isZodV3(schema: unknown): schema is ZodType {\n if (schema === null || typeof schema !== 'object') {\n return false;\n }\n\n // Must not be Zod v4\n if (isZodV4(schema)) {\n return false;\n }\n\n // Check for ~standard with vendor 'zod' but no jsonSchema\n if ('~standard' in schema) {\n const std = (schema as any)['~standard'];\n if (typeof std === 'object' && std !== null && std.vendor === 'zod' && !('jsonSchema' in std)) {\n return true;\n }\n }\n\n // Fallback: check instanceof for zod/v3 compat export\n return schema instanceof z3.ZodType;\n}\n\nexport function toStandardSchema<T = unknown>(schema: PublicSchema<T>): StandardSchemaWithJSON<T> {\n // Work around a Zod v4 (< 4.4.0) bug where single-arg `z.record(valueSchema)`\n // puts the value in `def.keyType` and leaves `def.valueType` undefined, which\n // crashes `toJSONSchema`'s recordProcessor. This must run BEFORE the\n // StandardSchemaWithJSON short-circuit below: Zod >= 4.2 natively exposes\n // `~standard.jsonSchema`, so those schemas are returned as-is and never go\n // through our Zod v4 adapter. Patching mutates the defs in place, so Zod's\n // native converter picks up the fix too. Idempotent — safe to call repeatedly.\n if (isZodV4(schema)) {\n patchRecordSchemas(schema);\n }\n\n // First check: if already StandardSchemaWithJSON, return as-is\n // This handles ArkType, Zod v4 (when it has jsonSchema), and pre-wrapped schemas\n if (isStandardSchemaWithJSON(schema)) {\n return schema;\n }\n\n // Check for Zod v4 schemas without ~standard.jsonSchema\n // This handles both real Zod v4 and Zod 3.25's v4 compat layer where\n // ~standard.jsonSchema is not present on the schema object\n if (isZodV4(schema)) {\n return toStandardSchemaZodV4(schema as any, {\n unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,\n override: JSON_SCHEMA_LIBRARY_OPTIONS.override,\n });\n }\n\n // Check for Zod v3 schemas (need wrapping to add JSON Schema support)\n // Important: Must use isZodV3() not instanceof z3.ZodType because\n // Zod v4 schemas are also instanceof z3.ZodType due to prototype compatibility\n if (isZodV3(schema)) {\n return toStandardSchemaZodV3(schema as ZodType);\n }\n\n // Check for AI SDK Schema objects (Vercel's jsonSchema wrapper)\n if (isVercelSchema(schema)) {\n return toStandardSchemaAiSdk(schema as Schema<T>);\n }\n\n // At this point, assume it's a plain JSON Schema object\n // JSON Schema objects are plain objects with properties like 'type', 'properties', etc.\n if (schema === null || (typeof schema !== 'object' && typeof schema !== 'function')) {\n throw new Error(`Unsupported schema type: ${typeof schema}`);\n }\n\n // If it's a function that's not StandardSchemaWithJSON, it's not supported\n if (typeof schema === 'function') {\n throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);\n }\n\n return toStandardSchemaJsonSchema(schema as JSONSchema7);\n}\n\n/**\n * Type guard to check if a value implements the StandardSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardSchema } from '@mastra/schema-compat';\n *\n * if (isStandardSchema(someValue)) {\n * const result = someValue['~standard'].validate(input);\n * }\n * ```\n */\nexport function isStandardSchema(value: unknown): value is StandardSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n return (\n typeof std === 'object' &&\n std !== null &&\n 'version' in std &&\n std.version === 1 &&\n 'vendor' in std &&\n 'validate' in std &&\n typeof std.validate === 'function'\n );\n}\n\n/**\n * Type guard to check if a value implements the StandardJSONSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardJSONSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardJSONSchema } from '@mastra/schema-compat';\n *\n * if (isStandardJSONSchema(someValue)) {\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardJSONSchema(value: unknown): value is StandardJSONSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n if (typeof std !== 'object' || std === null) {\n return false;\n }\n if (!('version' in std) || std.version !== 1 || !('vendor' in std)) {\n return false;\n }\n if (!('jsonSchema' in std) || typeof std.jsonSchema !== 'object') {\n return false;\n }\n return typeof std.jsonSchema.input === 'function' && typeof std.jsonSchema.output === 'function';\n}\n\n/**\n * Type guard to check if a value implements both StandardSchemaV1 and StandardJSONSchemaV1.\n *\n * @param value - The value to check\n * @returns True if the value implements both interfaces\n *\n * @example\n * ```typescript\n * import { isStandardSchemaWithJSON } from '@mastra/schema-compat';\n *\n * if (isStandardSchemaWithJSON(someValue)) {\n * // Can use both validation and JSON Schema conversion\n * const result = someValue['~standard'].validate(input);\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardSchemaWithJSON(value: unknown): value is StandardSchemaWithJSON {\n return isStandardSchema(value) && isStandardJSONSchema(value);\n}\n\n/**\n * Converts a StandardSchemaWithJSON to a JSON Schema.\n *\n * @param schema - The StandardSchemaWithJSON schema to convert\n * @param options - Conversion options\n * @param options.target - The JSON Schema target version (default: 'draft-07')\n * @param options.io - Whether to use input or output schema (default: 'output')\n * - 'input': Use for tool parameters, function arguments, request bodies\n * - 'output': Use for return types, response bodies\n * @returns The JSON Schema representation\n *\n * @example\n * ```typescript\n * import { standardSchemaToJSONSchema, toStandardSchema } from '@mastra/schema-compat';\n * import { z } from 'zod';\n *\n * const zodSchema = z.object({ name: z.string() });\n * const standardSchema = toStandardSchema(zodSchema);\n *\n * // For output types (default)\n * const outputSchema = standardSchemaToJSONSchema(standardSchema);\n *\n * // For input types (tool parameters)\n * const inputSchema = standardSchemaToJSONSchema(standardSchema, { io: 'input' });\n * ```\n */\nexport function standardSchemaToJSONSchema(\n schema: StandardSchemaWithJSON,\n options: {\n target?: StandardJSONSchemaV1.Target;\n io?: 'input' | 'output';\n override?: (typeof JSON_SCHEMA_LIBRARY_OPTIONS)['override'];\n } = {},\n): JSONSchema7 {\n const { target = 'draft-07', io = 'output', override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;\n const jsonSchemaFn = schema['~standard'].jsonSchema[io];\n let jsonSchema = jsonSchemaFn({\n target,\n libraryOptions: {\n ...JSON_SCHEMA_LIBRARY_OPTIONS,\n override,\n },\n }) as JSONSchema7;\n\n // make sure only jsonSchema is left, no standard schema metadata\n jsonSchema = JSON.parse(JSON.stringify(jsonSchema));\n\n return jsonSchema;\n}\n"],"mappings":";;;;;;;;;;;AASA,MAAM,oCAAoB,IAAI,IAAI;CAAC;CAAY;CAAY;AAAe,CAAC;;;;;;AAO3E,MAAM,oBAA4C;CAChD,YAAY;CACZ,YAAY;AACd;;;;;;;;AAiBA,SAAS,oBACP,WACA,SACA,gBACyB;CAMzB,mBAAmB,SAAS;CAE5B,MAAM,SAAS,kBAAkB,IAAI,QAAQ,MAAM,IAAI,QAAQ,SAAS;CAExE,MAAM,oBAA6C,EACjD,QAAQ,kBAAkB,WAAW,OACvC;CAEA,IAAI,eAAe,iBACjB,kBAAkB,kBAAkB,eAAe;CAIrD,IAAI,eAAe,UACjB,kBAAkB,WAAW,eAAe;CAG9C,OAAO,aAAa,WAAiD,iBAAiB;AACxF;;;;;;;;;;;;;AAcA,SAAgBA,mBACd,WACA,iBAAsC,CAAC,GACX;CAE5B,MAAM,UAAU,OAAO,OAAO,SAAS;CAGvC,MAAM,mBAAoB,UAAkB;CAG5C,MAAM,sBAAsD;EAC1D,QAAQ,YAAmE;GACzE,OAAO,oBAAoB,WAAW,SAAS,cAAc;EAC/D;EACA,SAAS,YAAmE;GAC1E,OAAO,oBAAoB,WAAW,SAAS,cAAc;EAC/D;CACF;CAGA,OAAO,eAAe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B,yBAAyB,OAAiD;CACxF,OAAO,iBAAiB,KAAK,KAAK,qBAAqB,KAAK;AAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,2BACd,QACA,UAII,CAAC,GACQ;CACb,MAAM,EAAE,SAAS,YAAY,KAAK,UAAU,WAAW,4BAA4B,aAAa;CAChG,MAAM,eAAe,OAAO,YAAY,CAAC,WAAW;CACpD,IAAI,aAAa,aAAa;EAC5B;EACA,gBAAgB;GACd,GAAG;GACH;EACF;CACF,CAAC;CAGD,aAAa,KAAK,MAAM,KAAK,UAAU,UAAU,CAAC;CAElD,OAAO;AACT"}
1
+ {"version":3,"file":"schema-D_ikovK6.js","names":["toStandardSchema","toStandardSchemaZodV4","toStandardSchemaZodV3","toStandardSchemaAiSdk","toStandardSchemaJsonSchema"],"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport { toJSONSchema } from 'zod/v4';\nimport { patchRecordSchemas } from '../../zod-to-json';\nimport type { StandardSchemaWithJSON, StandardSchemaWithJSONProps } from '../standard-schema.types';\n\n/**\n * Supported JSON Schema targets for z.toJSONSchema().\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n */\nconst SUPPORTED_TARGETS = new Set(['draft-07', 'draft-04', 'draft-2020-12']);\n\n/**\n * Maps Mastra's target names to Zod v4's expected format.\n * Zod v4's z.toJSONSchema() expects \"draft-7\" instead of \"draft-07\",\n * and \"draft-4\" instead of \"draft-04\".\n */\nconst ZOD_V4_TARGET_MAP: Record<string, string> = {\n 'draft-07': 'draft-7',\n 'draft-04': 'draft-4',\n};\n\n/**\n * Options for the Zod v4 adapter's JSON Schema conversion.\n */\nexport interface ZodV4AdapterOptions {\n unrepresentable?: 'any' | 'error';\n override?: (ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }) => undefined;\n}\n\n/**\n * Converts a Zod v4 schema to JSON Schema using z.toJSONSchema().\n *\n * Works with both real Zod v4 and Zod 3.25's v4 compat layer.\n *\n * @internal\n */\nfunction convertToJsonSchema(\n zodSchema: unknown,\n options: StandardJSONSchemaV1.Options,\n adapterOptions: ZodV4AdapterOptions,\n): Record<string, unknown> {\n // Work around a Zod v4 bug where `z.record(valueSchema)` puts the value\n // in `def.keyType` instead of `def.valueType`, which crashes\n // `toJSONSchema`'s `recordProcessor`. The legacy `zodToJsonSchema` entry\n // applies the same patch; this keeps the `applyCompatLayer` path in sync.\n // Idempotent — safe to call repeatedly.\n patchRecordSchemas(zodSchema);\n\n const target = SUPPORTED_TARGETS.has(options.target) ? options.target : 'draft-07';\n\n const jsonSchemaOptions: Record<string, unknown> = {\n target: ZOD_V4_TARGET_MAP[target] ?? target,\n };\n\n if (adapterOptions.unrepresentable) {\n jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;\n }\n\n // The override option works in real Zod v4 but is a no-op in 3.25 compat.\n if (adapterOptions.override) {\n jsonSchemaOptions.override = adapterOptions.override;\n }\n\n return toJSONSchema(zodSchema as Parameters<typeof toJSONSchema>[0], jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Wraps a Zod v4 schema to implement the full @standard-schema/spec interface.\n *\n * Zod v4 schemas (and Zod 3.25's v4 compat layer) implement `StandardSchemaV1`\n * (validation) but may not implement `StandardJSONSchemaV1` (JSON Schema conversion)\n * on the `~standard` property. This adapter adds the `jsonSchema` property using\n * `z.toJSONSchema()` to provide JSON Schema conversion capabilities.\n *\n * @param zodSchema - A Zod v4 schema (has `_zod` property)\n * @param adapterOptions - Options passed to z.toJSONSchema()\n * @returns The schema wrapped with StandardSchemaWithJSON support\n */\nexport function toStandardSchema<T>(\n zodSchema: T & { _zod: unknown; '~standard': StandardSchemaV1.Props },\n adapterOptions: ZodV4AdapterOptions = {},\n): T & StandardSchemaWithJSON {\n // Create a wrapper object that preserves the original schema's prototype chain\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON;\n\n // Get the existing ~standard property from Zod\n const existingStandard = (zodSchema as any)['~standard'] as StandardSchemaV1.Props;\n\n // Create the JSON Schema converter using z.toJSONSchema()\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n output: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options, adapterOptions);\n },\n };\n\n // Define the enhanced ~standard property\n Object.defineProperty(wrapper, '~standard', {\n value: {\n ...existingStandard,\n jsonSchema: jsonSchemaConverter,\n } satisfies StandardSchemaWithJSONProps,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n","import type { Schema } from '@internal/ai-v6';\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchema7 } from 'json-schema';\nimport z3 from 'zod/v3';\nimport type { ZodType } from 'zod/v3';\nimport type { PublicSchema } from '../schema.types';\nimport { patchRecordSchemas } from '../zod-to-json';\nimport { toStandardSchema as toStandardSchemaAiSdk } from './adapters/ai-sdk';\nimport { toStandardSchema as toStandardSchemaJsonSchema } from './adapters/json-schema';\nimport { toStandardSchema as toStandardSchemaZodV3 } from './adapters/zod-v3';\nimport { toStandardSchema as toStandardSchemaZodV4 } from './adapters/zod-v4';\nimport type { StandardSchemaWithJSON } from './standard-schema.types';\n\n/**\n * Override function for JSON Schema conversion.\n * Handles types that Zod v4 cannot natively represent in JSON Schema:\n * - z.date() -> { type: 'string', format: 'date-time' }\n */\nfunction jsonSchemaOverride(ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }): undefined {\n const zodSchema = ctx.zodSchema as {\n type?: string;\n _def?: { typeName?: string };\n _zod?: { def?: { type?: string; coerce?: boolean } };\n optional?: () => unknown;\n };\n\n if (\n ctx.jsonSchema.type === 'object' &&\n ctx.jsonSchema.properties !== undefined &&\n !ctx.jsonSchema.additionalProperties\n ) {\n ctx.jsonSchema.additionalProperties = false;\n }\n\n if (zodSchema) {\n // Zod v4: zodSchema.type === 'date'\n // Zod v3: zodSchema._def.typeName === 'ZodDate'\n const isDateType = zodSchema?.type === 'date' || zodSchema?._def?.typeName === 'ZodDate';\n\n if (isDateType) {\n // Zod v4 dates need explicit JSON schema conversion (zod-to-json-schema doesn't handle them)\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n // Mark dates for #traverse: x-date=true means string→Date conversion needed.\n // z.coerce.date() handles its own coercion, so mark as false to prevent conversion.\n // Zod v3 has no coerce, so all v3 dates are strict (handled by preProcessJSONNode fallback).\n ctx.jsonSchema['x-date'] = !zodSchema._zod?.def?.coerce;\n // @ts-expect-error - catchall is a valid property for zod\n } else if (zodSchema?.type === 'object' && zodSchema._zod?.def?.catchall?.type === 'unknown') {\n ctx.jsonSchema.additionalProperties = true;\n }\n }\n\n return undefined;\n}\n/**\n * Library options for JSON Schema conversion.\n * - unrepresentable: 'any' allows z.custom() and other unrepresentable types to be converted to {}\n * instead of throwing \"Custom types cannot be represented in JSON Schema\"\n * - override: converts z.date() to { type: 'string', format: 'date-time' }\n */\nexport const JSON_SCHEMA_LIBRARY_OPTIONS = {\n unrepresentable: 'any' as const,\n override: jsonSchemaOverride,\n};\n\nexport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n InferInput,\n InferOutput,\n StandardSchemaIssue,\n} from './standard-schema.types';\n\nfunction isVercelSchema(schema: unknown): schema is Schema {\n return (\n typeof schema === 'object' &&\n schema !== null &&\n '_type' in schema &&\n 'jsonSchema' in schema &&\n typeof (schema as Schema).jsonSchema === 'object'\n );\n}\n\n/**\n * Check if a schema is Zod v4 (has _zod property which is v4-only)\n */\nfunction isZodV4(schema: unknown): boolean {\n return typeof schema === 'object' && schema !== null && '_zod' in schema;\n}\n\n/**\n * Check if a schema is Zod v3.\n *\n * Zod v3 can come from:\n * 1. The old standalone 'zod-v3' package\n * 2. The 'zod/v3' compat export from modern zod\n *\n * We detect Zod v3 by checking:\n * - Has ~standard.vendor === 'zod' (both v3 and v4 have this)\n * - Does NOT have ~standard.jsonSchema (only Zod v4 has native JSON Schema support)\n * - Does NOT have _zod property (only Zod v4 has this)\n *\n * Note: We can't use instanceof z3.ZodType because the old 'zod-v3' package\n * has a different prototype chain than 'zod/v3'.\n */\nfunction isZodV3(schema: unknown): schema is ZodType {\n if (schema === null || typeof schema !== 'object') {\n return false;\n }\n\n // Must not be Zod v4\n if (isZodV4(schema)) {\n return false;\n }\n\n // Check for ~standard with vendor 'zod' but no jsonSchema\n if ('~standard' in schema) {\n const std = (schema as any)['~standard'];\n if (typeof std === 'object' && std !== null && std.vendor === 'zod' && !('jsonSchema' in std)) {\n return true;\n }\n }\n\n // Fallback: check instanceof for zod/v3 compat export\n return schema instanceof z3.ZodType;\n}\n\nexport function toStandardSchema<T = unknown>(schema: PublicSchema<T>): StandardSchemaWithJSON<T> {\n // Work around a Zod v4 (< 4.4.0) bug where single-arg `z.record(valueSchema)`\n // puts the value in `def.keyType` and leaves `def.valueType` undefined, which\n // crashes `toJSONSchema`'s recordProcessor. This must run BEFORE the\n // StandardSchemaWithJSON short-circuit below: Zod >= 4.2 natively exposes\n // `~standard.jsonSchema`, so those schemas are returned as-is and never go\n // through our Zod v4 adapter. Patching mutates the defs in place, so Zod's\n // native converter picks up the fix too. Idempotent — safe to call repeatedly.\n if (isZodV4(schema)) {\n patchRecordSchemas(schema);\n }\n\n // First check: if already StandardSchemaWithJSON, return as-is\n // This handles ArkType, Zod v4 (when it has jsonSchema), and pre-wrapped schemas\n if (isStandardSchemaWithJSON(schema)) {\n return schema;\n }\n\n // Check for Zod v4 schemas without ~standard.jsonSchema\n // This handles both real Zod v4 and Zod 3.25's v4 compat layer where\n // ~standard.jsonSchema is not present on the schema object\n if (isZodV4(schema)) {\n return toStandardSchemaZodV4(schema as any, {\n unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,\n override: JSON_SCHEMA_LIBRARY_OPTIONS.override,\n });\n }\n\n // Check for Zod v3 schemas (need wrapping to add JSON Schema support)\n // Important: Must use isZodV3() not instanceof z3.ZodType because\n // Zod v4 schemas are also instanceof z3.ZodType due to prototype compatibility\n if (isZodV3(schema)) {\n return toStandardSchemaZodV3(schema as ZodType);\n }\n\n // Check for AI SDK Schema objects (Vercel's jsonSchema wrapper)\n if (isVercelSchema(schema)) {\n return toStandardSchemaAiSdk(schema);\n }\n\n // At this point, assume it's a plain JSON Schema object\n // JSON Schema objects are plain objects with properties like 'type', 'properties', etc.\n if (schema === null || (typeof schema !== 'object' && typeof schema !== 'function')) {\n throw new Error(`Unsupported schema type: ${typeof schema}`);\n }\n\n // If it's a function that's not StandardSchemaWithJSON, it's not supported\n if (typeof schema === 'function') {\n throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);\n }\n\n return toStandardSchemaJsonSchema(schema as JSONSchema7);\n}\n\n/**\n * Type guard to check if a value implements the StandardSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardSchema } from '@mastra/schema-compat';\n *\n * if (isStandardSchema(someValue)) {\n * const result = someValue['~standard'].validate(input);\n * }\n * ```\n */\nexport function isStandardSchema(value: unknown): value is StandardSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n return (\n typeof std === 'object' &&\n std !== null &&\n 'version' in std &&\n std.version === 1 &&\n 'vendor' in std &&\n 'validate' in std &&\n typeof std.validate === 'function'\n );\n}\n\n/**\n * Type guard to check if a value implements the StandardJSONSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardJSONSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardJSONSchema } from '@mastra/schema-compat';\n *\n * if (isStandardJSONSchema(someValue)) {\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardJSONSchema(value: unknown): value is StandardJSONSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n if (typeof std !== 'object' || std === null) {\n return false;\n }\n if (!('version' in std) || std.version !== 1 || !('vendor' in std)) {\n return false;\n }\n if (!('jsonSchema' in std) || typeof std.jsonSchema !== 'object') {\n return false;\n }\n return typeof std.jsonSchema.input === 'function' && typeof std.jsonSchema.output === 'function';\n}\n\n/**\n * Type guard to check if a value implements both StandardSchemaV1 and StandardJSONSchemaV1.\n *\n * @param value - The value to check\n * @returns True if the value implements both interfaces\n *\n * @example\n * ```typescript\n * import { isStandardSchemaWithJSON } from '@mastra/schema-compat';\n *\n * if (isStandardSchemaWithJSON(someValue)) {\n * // Can use both validation and JSON Schema conversion\n * const result = someValue['~standard'].validate(input);\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardSchemaWithJSON(value: unknown): value is StandardSchemaWithJSON {\n return isStandardSchema(value) && isStandardJSONSchema(value);\n}\n\n/**\n * Converts a StandardSchemaWithJSON to a JSON Schema.\n *\n * @param schema - The StandardSchemaWithJSON schema to convert\n * @param options - Conversion options\n * @param options.target - The JSON Schema target version (default: 'draft-07')\n * @param options.io - Whether to use input or output schema (default: 'output')\n * - 'input': Use for tool parameters, function arguments, request bodies\n * - 'output': Use for return types, response bodies\n * @returns The JSON Schema representation\n *\n * @example\n * ```typescript\n * import { standardSchemaToJSONSchema, toStandardSchema } from '@mastra/schema-compat';\n * import { z } from 'zod';\n *\n * const zodSchema = z.object({ name: z.string() });\n * const standardSchema = toStandardSchema(zodSchema);\n *\n * // For output types (default)\n * const outputSchema = standardSchemaToJSONSchema(standardSchema);\n *\n * // For input types (tool parameters)\n * const inputSchema = standardSchemaToJSONSchema(standardSchema, { io: 'input' });\n * ```\n */\nexport function standardSchemaToJSONSchema(\n schema: StandardSchemaWithJSON,\n options: {\n target?: StandardJSONSchemaV1.Target;\n io?: 'input' | 'output';\n override?: (typeof JSON_SCHEMA_LIBRARY_OPTIONS)['override'];\n } = {},\n): JSONSchema7 {\n const { target = 'draft-07', io = 'output', override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;\n const jsonSchemaFn = schema['~standard'].jsonSchema[io];\n let jsonSchema = jsonSchemaFn({\n target,\n libraryOptions: {\n ...JSON_SCHEMA_LIBRARY_OPTIONS,\n override,\n },\n }) as JSONSchema7;\n\n // make sure only jsonSchema is left, no standard schema metadata\n jsonSchema = JSON.parse(JSON.stringify(jsonSchema));\n\n return jsonSchema;\n}\n"],"mappings":";;;;;;;;;;;AASA,MAAM,oCAAoB,IAAI,IAAI;CAAC;CAAY;CAAY;AAAe,CAAC;;;;;;AAO3E,MAAM,oBAA4C;CAChD,YAAY;CACZ,YAAY;AACd;;;;;;;;AAiBA,SAAS,oBACP,WACA,SACA,gBACyB;CAMzB,mBAAmB,SAAS;CAE5B,MAAM,SAAS,kBAAkB,IAAI,QAAQ,MAAM,IAAI,QAAQ,SAAS;CAExE,MAAM,oBAA6C,EACjD,QAAQ,kBAAkB,WAAW,OACvC;CAEA,IAAI,eAAe,iBACjB,kBAAkB,kBAAkB,eAAe;CAIrD,IAAI,eAAe,UACjB,kBAAkB,WAAW,eAAe;CAG9C,OAAO,aAAa,WAAiD,iBAAiB;AACxF;;;;;;;;;;;;;AAcA,SAAgBA,mBACd,WACA,iBAAsC,CAAC,GACX;CAE5B,MAAM,UAAU,OAAO,OAAO,SAAS;CAGvC,MAAM,mBAAoB,UAAkB;CAG5C,MAAM,sBAAsD;EAC1D,QAAQ,YAAmE;GACzE,OAAO,oBAAoB,WAAW,SAAS,cAAc;EAC/D;EACA,SAAS,YAAmE;GA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c,OAAO,IAAI,WAAW,WAAW;AACxF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,yBAAyB,OAAiD;CACxF,OAAO,iBAAiB,KAAK,KAAK,qBAAqB,KAAK;AAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,2BACd,QACA,UAII,CAAC,GACQ;CACb,MAAM,EAAE,SAAS,YAAY,KAAK,UAAU,WAAW,4BAA4B,aAAa;CAChG,MAAM,eAAe,OAAO,YAAY,CAAC,WAAW;CACpD,IAAI,aAAa,aAAa;EAC5B;EACA,gBAAgB;GACd,GAAG;GACH;EACF;CACF,CAAC;CAGD,aAAa,KAAK,MAAM,KAAK,UAAU,UAAU,CAAC;CAElD,OAAO;AACT"}
package/dist/schema.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_schema = require("./schema-Cjk6OMG9.cjs");
2
+ const require_schema = require("./schema-Bw7nQdgA.cjs");
3
3
  exports.JSON_SCHEMA_LIBRARY_OPTIONS = require_schema.JSON_SCHEMA_LIBRARY_OPTIONS;
4
4
  exports.isStandardJSONSchema = require_schema.isStandardJSONSchema;
5
5
  exports.isStandardSchema = require_schema.isStandardSchema;
package/dist/schema.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as standardSchemaToJSONSchema, i as isStandardSchemaWithJSON, n as isStandardJSONSchema, o as toStandardSchema, r as isStandardSchema, t as JSON_SCHEMA_LIBRARY_OPTIONS } from "./schema-Bv9OdW1f.js";
1
+ import { a as standardSchemaToJSONSchema, i as isStandardSchemaWithJSON, n as isStandardJSONSchema, o as toStandardSchema, r as isStandardSchema, t as JSON_SCHEMA_LIBRARY_OPTIONS } from "./schema-D_ikovK6.js";
2
2
  export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema };
@@ -17,7 +17,25 @@ export type ZodDefault = z4.ZodDefault<any> | z3.ZodDefault<any>;
17
17
  export type AISdkSchemaLike<Output = unknown> = {
18
18
  _type: Output;
19
19
  };
20
- export type PublicSchema<Output = unknown, Input = Output> = z4.ZodType<Output, Input> | z3.Schema<Output, z3.ZodTypeDef, Input> | SchemaV4<Output> | SchemaV5<Output> | SchemaV6<Output> | JSONSchema7 | StandardSchemaWithJSON<Input, Output> | AISdkSchemaLike<Output>;
20
+ /**
21
+ * A shallow structural boundary for Zod schemas.
22
+ *
23
+ * Using the full Zod v3 and v4 types in `PublicSchema` forces TypeScript to
24
+ * deeply compare both type trees whenever a concrete schema is inferred. The
25
+ * properties below are shared by supported Zod versions and mirror the shape
26
+ * checked by the runtime Zod guard.
27
+ */
28
+ type StructuralZodSchema<Output = unknown, Input = Output> = {
29
+ readonly _output: Output;
30
+ readonly _input: Input;
31
+ parse(data: unknown): Output;
32
+ safeParse(data: unknown): unknown;
33
+ } & ({
34
+ readonly _def: unknown;
35
+ } | {
36
+ readonly _zod: unknown;
37
+ });
38
+ export type PublicSchema<Output = unknown, Input = Output> = StructuralZodSchema<Output, Input> | SchemaV4<Output> | SchemaV5<Output> | SchemaV6<Output> | JSONSchema7 | StandardSchemaWithJSON<Input, Output> | AISdkSchemaLike<Output>;
21
39
  export type InferPublicSchema<T extends PublicSchema> = T extends {
22
40
  _output: infer Output;
23
41
  } ? Output : T extends {
@@ -29,4 +47,5 @@ export type InferPublicSchema<T extends PublicSchema> = T extends {
29
47
  };
30
48
  };
31
49
  } ? O : T extends PublicSchema<infer Output> ? Output : never;
50
+ export {};
32
51
  //# sourceMappingURL=schema.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.types.d.ts","sourceRoot":"","sources":["../src/schema.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAA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C,MAAM,MAAM,CAAC,GAClC,MAAM,GACN,KAAK,CAAC"}
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_json_schema = require("../../json-schema-pcL1TeZs.cjs");
2
+ const require_json_schema = require("../../json-schema-CEVTdogs.cjs");
3
3
  exports.JsonSchemaWrapper = require_json_schema.JsonSchemaWrapper;
4
4
  exports.toStandardSchema = require_json_schema.toStandardSchema;
@@ -1,2 +1,2 @@
1
- import { n as toStandardSchema, t as JsonSchemaWrapper } from "../../json-schema-BstKYbJi.js";
1
+ import { n as toStandardSchema, t as JsonSchemaWrapper } from "../../json-schema-BKit3LVN.js";
2
2
  export { JsonSchemaWrapper, toStandardSchema };
@@ -1 +1 @@
1
- {"version":3,"file":"zod-to-json.cjs","names":["zV4","zodToJsonSchemaOriginal"],"sources":["../src/zod-to-json.ts"],"sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport type { ZodSchema as ZodSchemaV3 } from 'zod/v3';\nimport { z as zV4 } from 'zod/v4';\nimport type { Targets } from 'zod-to-json-schema';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\n\n// Symbol to mark schemas as already patched (for idempotency)\nconst PATCHED = Symbol('__mastra_patched__');\n\n/**\n * Recursively patch Zod v4 record schemas that are missing valueType.\n * This fixes a bug in Zod v4 where z.record(valueSchema) doesn't set def.valueType.\n * The single-arg form should set valueType but instead only sets keyType.\n *\n * Idempotent — marks patched schemas with a Symbol so repeat calls no-op.\n *\n * @internal Exported so the Zod v4 standard-schema adapter can apply the\n * same patch before its native `toJSONSchema` call (the legacy `zodToJsonSchema`\n * entry already calls it; the `applyCompatLayer` path otherwise wouldn't).\n * Not part of the public API.\n */\nexport function patchRecordSchemas(schema: any): any {\n if (!schema || typeof schema !== 'object') return schema;\n\n // Skip if already patched (idempotency check)\n if ((schema as any)[PATCHED]) return schema;\n (schema as any)[PATCHED] = true;\n\n // Check the _zod.def location (v4 structure)\n const def = schema._zod?.def;\n\n // Fix record schemas with missing valueType\n if (def?.type === 'record' && def.keyType && !def.valueType) {\n // The bug: z.record(valueSchema) puts the value in keyType instead of valueType\n // Fix: move it to valueType and set keyType to string (the default)\n def.valueType = def.keyType;\n def.keyType = zV4.string();\n }\n\n // Recursively patch nested schemas\n if (!def) return schema;\n\n if (def.type === 'object' && def.shape) {\n const shape = typeof def.shape === 'function' ? def.shape() : def.shape;\n for (const key of Object.keys(shape)) {\n patchRecordSchemas(shape[key]);\n }\n }\n\n if (def.type === 'array' && def.element) {\n patchRecordSchemas(def.element);\n }\n\n if (def.type === 'union' && def.options) {\n def.options.forEach(patchRecordSchemas);\n }\n\n if (def.type === 'record') {\n if (def.keyType) patchRecordSchemas(def.keyType);\n if (def.valueType) patchRecordSchemas(def.valueType);\n }\n\n // Handle intersection types\n if (def.type === 'intersection') {\n if (def.left) patchRecordSchemas(def.left);\n if (def.right) patchRecordSchemas(def.right);\n }\n\n // Handle lazy types - patch the schema returned by the getter\n if (def.type === 'lazy') {\n // For lazy schemas, we need to patch the schema when it's accessed\n // Store the original getter and wrap it\n if (def.getter && typeof def.getter === 'function') {\n const originalGetter = def.getter;\n def.getter = function () {\n const innerSchema = originalGetter();\n if (innerSchema) {\n patchRecordSchemas(innerSchema);\n }\n return innerSchema;\n };\n }\n }\n\n // Handle wrapper types that have innerType\n // This covers: optional, nullable, default, catch, nullish, and any other wrappers\n if (def.innerType) {\n patchRecordSchemas(def.innerType);\n }\n\n return schema;\n}\n\n/**\n * Recursively fixes anyOf patterns that some providers (like OpenAI) don't accept.\n * Converts anyOf: [{type: X}, {type: \"null\"}] to type: [X, \"null\"]\n * Also fixes empty {} property schemas by converting to a union of primitive types.\n */\nfunction fixAnyOfNullable(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n // Fix anyOf pattern: [{type: X}, {type: \"null\"}] or [{type: \"null\"}, {type: X}]\n if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {\n const nullSchema = result.anyOf.find((s: any) => typeof s === 'object' && s !== null && s.type === 'null');\n const otherSchema = result.anyOf.find((s: any) => typeof s === 'object' && s !== null && s.type !== 'null');\n\n if (nullSchema && otherSchema && typeof otherSchema === 'object' && otherSchema.type) {\n // Convert anyOf to type array format\n // Normalize sibling fields (like properties/items) before returning\n const { anyOf, ...rest } = result;\n const fixedRest = fixAnyOfNullable(rest as JSONSchema7);\n const fixedOther = fixAnyOfNullable(otherSchema as JSONSchema7);\n return {\n ...fixedRest,\n ...fixedOther,\n type: (Array.isArray(fixedOther.type)\n ? [...fixedOther.type, 'null']\n : [fixedOther.type, 'null']) as JSONSchema7['type'],\n };\n }\n }\n\n // Fix empty property schemas {} - OpenAI requires a type key\n if (result.properties && typeof result.properties === 'object' && !Array.isArray(result.properties)) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => {\n const propSchema = value as JSONSchema7;\n\n // If property is an empty object {}, convert to allow primitive types\n // Note: We exclude 'object' (requires additionalProperties) and 'array' (requires items) for OpenAI\n if (\n typeof propSchema === 'object' &&\n propSchema !== null &&\n !Array.isArray(propSchema) &&\n Object.keys(propSchema).length === 0\n ) {\n return [key, { type: ['string', 'number', 'boolean', 'null'] as JSONSchema7['type'] }];\n }\n\n // Recursively fix nested schemas\n return [key, fixAnyOfNullable(propSchema)];\n }),\n );\n }\n\n // Recursively fix items in arrays\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => fixAnyOfNullable(item as JSONSchema7));\n } else {\n result.items = fixAnyOfNullable(result.items as JSONSchema7);\n }\n }\n\n // Recursively fix anyOf/oneOf/allOf schemas\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n\n return result;\n}\n\n/**\n * Apply a strict-mode pass to every schema hoisted into `$defs`/`definitions`.\n * zod-to-json-schema (v3 path, `$refStrategy: 'relative'`) lifts reused subschemas into\n * these definition maps and references them via `$ref`, so the referenced schemas must be\n * processed with the same pass as inline nodes or their unsupported keywords leak through.\n */\nfunction applyToDefinitions(result: JSONSchema7, fn: (schema: JSONSchema7) => JSONSchema7): void {\n for (const defKey of ['$defs', 'definitions'] as const) {\n const defs = (result as Record<string, unknown>)[defKey];\n if (defs && typeof defs === 'object' && !Array.isArray(defs)) {\n (result as Record<string, unknown>)[defKey] = Object.fromEntries(\n Object.entries(defs as Record<string, unknown>).map(([key, value]) => [\n key,\n typeof value === 'object' && value !== null ? fn(value as JSONSchema7) : value,\n ]),\n );\n }\n }\n}\n\n/**\n * Recursively ensures all properties in an object schema are included in the `required` array.\n * OpenAI's strict structured output mode requires every key in `properties` to also appear in `required`.\n *\n * @param schema - The JSON Schema to process\n * @returns A new schema with all properties marked as required\n */\nexport function ensureAllPropertiesRequired(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n if (result.type === 'object' && result.properties) {\n result.required = Object.keys(result.properties);\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value as JSONSchema7)]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => ensureAllPropertiesRequired(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = ensureAllPropertiesRequired(result.items as JSONSchema7);\n }\n }\n\n if (result.additionalProperties && typeof result.additionalProperties === 'object') {\n result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties as JSONSchema7);\n }\n\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n\n applyToDefinitions(result, ensureAllPropertiesRequired);\n\n return result;\n}\n\n/**\n * Prepare a JSON Schema for OpenAI strict mode by ensuring all object properties\n * are required and all objects have additionalProperties: false.\n */\nexport function prepareJsonSchemaForOpenAIStrictMode(schema: JSONSchema7): JSONSchema7 {\n const withRequired = ensureAllPropertiesRequired(schema);\n const withoutAdditional = ensureAdditionalPropertiesFalse(withRequired);\n return stripUnsupportedStrictModeKeywords(withoutAdditional);\n}\n\n// Keywords OpenAI Structured Outputs strict mode rejects and that carry no natural-language\n// intent worth preserving. They are removed silently.\n// @see https://platform.openai.com/docs/guides/structured-outputs#supported-schemas\nconst STRICT_MODE_DROPPED_KEYWORDS = [\n 'contains',\n 'minContains',\n 'maxContains',\n 'minProperties',\n 'maxProperties',\n 'patternProperties',\n 'unevaluatedItems',\n 'unevaluatedProperties',\n // Conditional/dependency keywords: unsupported by OpenAI strict mode with no\n // useful structural mapping, so they are dropped.\n 'not',\n 'if',\n 'then',\n 'else',\n 'dependentRequired',\n 'dependentSchemas',\n] as const;\n\nfunction isDeepEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (Array.isArray(a) || Array.isArray(b)) {\n return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => isDeepEqual(v, b[i]));\n }\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) return false;\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n return (\n keysA.length === keysB.length &&\n keysA.every(\n k => Object.hasOwn(b, k) && isDeepEqual((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]),\n )\n );\n}\n\n/**\n * Merge `allOf` subschemas into the containing node. OpenAI strict mode rejects `allOf`\n * (only `anyOf` composition is supported), so the intersection is flattened into a single\n * node. Every keyword from every branch is hoisted so nothing (e.g. `enum`, `const`,\n * `items`, `anyOf`) is silently discarded:\n *\n * - `properties` are unioned; a property present in more than one branch must be identical.\n * - `required` is unioned. `additionalProperties: false` wins. Descriptions are concatenated.\n * - Any other keyword must either be absent from the target or deep-equal to the branch value.\n *\n * Intersections that cannot be represented this way (conflicting property schemas, types,\n * enums, nested `anyOf`, ...) are rejected with an error instead of producing a schema that\n * accepts values the original would have rejected. This mirrors the tool-path behaviour in\n * SchemaCompatLayer (\"Cannot flatten intersections with overlapping keys\").\n */\nfunction mergeAllOfSubschemas(target: JSONSchema7 & Record<string, unknown>, subschemas: JSONSchema7[]): void {\n const mergedProps: Record<string, JSONSchema7> = { ...((target.properties as Record<string, JSONSchema7>) ?? {}) };\n const requiredSet = new Set<string>(Array.isArray(target.required) ? target.required : []);\n const descriptions: string[] =\n typeof target.description === 'string' && target.description ? [target.description] : [];\n\n for (const sub of subschemas) {\n if (!sub || typeof sub !== 'object') {\n continue;\n }\n for (const [key, value] of Object.entries(sub as Record<string, unknown>)) {\n switch (key) {\n case 'properties': {\n for (const [propName, propSchema] of Object.entries(value as Record<string, JSONSchema7>)) {\n if (propName in mergedProps && !isDeepEqual(mergedProps[propName], propSchema)) {\n throw new Error(\n `Cannot flatten allOf for OpenAI strict mode: property \"${propName}\" is defined differently in multiple branches`,\n );\n }\n mergedProps[propName] = propSchema;\n }\n break;\n }\n case 'required': {\n if (Array.isArray(value)) {\n for (const name of value) {\n requiredSet.add(name);\n }\n }\n break;\n }\n case 'additionalProperties': {\n if (value === false) {\n target.additionalProperties = false;\n }\n break;\n }\n case 'description': {\n if (typeof value === 'string' && value) {\n descriptions.push(value);\n }\n break;\n }\n default: {\n if (target[key] === undefined) {\n target[key] = value;\n } else if (!isDeepEqual(target[key], value)) {\n throw new Error(`Cannot flatten allOf for OpenAI strict mode: conflicting \"${key}\" values across branches`);\n }\n }\n }\n }\n }\n\n if (Object.keys(mergedProps).length) {\n target.properties = mergedProps;\n }\n if (requiredSet.size) {\n target.required = [...requiredSet];\n }\n if (descriptions.length) {\n target.description = descriptions.join(' ');\n }\n}\n\n/**\n * Merge constraint phrases into a schema node's description.\n * Mirrors SchemaCompatLayer.mergeParameterDescription phrasing so the strict-mode\n * output path degrades identically to the tool path.\n */\nfunction appendConstraintsToDescription(description: string | undefined, constraints: string[]): string | undefined {\n if (constraints.length === 0) {\n return description;\n }\n const suffix = constraints.join(', ');\n return description ? `${description} (${suffix})` : suffix;\n}\n\n/**\n * Recursively remove JSON Schema validation keywords that OpenAI strict mode rejects.\n * Constraints with useful intent (length/number/pattern/format/uniqueness bounds) are folded\n * into the node's `description` — matching how the tool-path SchemaCompatLayer degrades them\n * in schema-compatibility.ts — while purely structural unsupported keywords are dropped.\n */\nfunction stripUnsupportedStrictModeKeywords(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema } as JSONSchema7 & Record<string, unknown>;\n const constraints: string[] = [];\n\n // Array bounds\n const { minItems, maxItems } = result;\n if (minItems !== undefined && maxItems !== undefined && minItems === maxItems) {\n constraints.push(`exact length ${minItems}`);\n } else {\n if (minItems !== undefined) {\n constraints.push(`minimum length ${minItems}`);\n }\n if (maxItems !== undefined) {\n constraints.push(`maximum length ${maxItems}`);\n }\n }\n delete result.minItems;\n delete result.maxItems;\n\n if (result.uniqueItems === true) {\n constraints.push('all items must be unique');\n }\n delete result.uniqueItems;\n\n // String bounds\n if (result.minLength !== undefined) {\n constraints.push(`minimum length ${result.minLength}`);\n delete result.minLength;\n }\n if (result.maxLength !== undefined) {\n constraints.push(`maximum length ${result.maxLength}`);\n delete result.maxLength;\n }\n if (result.format !== undefined) {\n constraints.push(`a valid ${result.format}`);\n delete result.format;\n }\n if (result.pattern !== undefined) {\n constraints.push(`input must match this regex ${result.pattern}`);\n delete result.pattern;\n }\n\n // Number bounds\n if (result.minimum !== undefined) {\n if (result.minimum !== Number.MIN_SAFE_INTEGER) {\n constraints.push(`greater than or equal to ${result.minimum}`);\n }\n delete result.minimum;\n }\n if (result.maximum !== undefined) {\n if (result.maximum !== Number.MAX_SAFE_INTEGER) {\n constraints.push(`lower than or equal to ${result.maximum}`);\n }\n delete result.maximum;\n }\n if (result.exclusiveMinimum !== undefined) {\n constraints.push(`greater than ${result.exclusiveMinimum}`);\n delete result.exclusiveMinimum;\n }\n if (result.exclusiveMaximum !== undefined) {\n constraints.push(`lower than ${result.exclusiveMaximum}`);\n delete result.exclusiveMaximum;\n }\n if (result.multipleOf !== undefined) {\n constraints.push(`multiple of ${result.multipleOf}`);\n delete result.multipleOf;\n }\n\n // Structural unsupported keywords with no useful natural-language mapping\n for (const keyword of STRICT_MODE_DROPPED_KEYWORDS) {\n delete result[keyword];\n }\n\n if (constraints.length) {\n result.description = appendConstraintsToDescription(result.description, constraints);\n }\n\n if (result.properties) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [\n key,\n stripUnsupportedStrictModeKeywords(value as JSONSchema7),\n ]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => stripUnsupportedStrictModeKeywords(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = stripUnsupportedStrictModeKeywords(result.items as JSONSchema7);\n }\n }\n\n if (result.additionalProperties && typeof result.additionalProperties === 'object') {\n result.additionalProperties = stripUnsupportedStrictModeKeywords(result.additionalProperties as JSONSchema7);\n }\n\n // anyOf is the only composition keyword OpenAI strict mode supports; keep it, strip its branches.\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => stripUnsupportedStrictModeKeywords(s as JSONSchema7));\n }\n\n // oneOf is unsupported; anyOf is the documented replacement, so convert it.\n // When both are present the schema is a conjunction (value must satisfy both lists);\n // concatenating the branches would turn that into a union, so reject instead.\n if (result.oneOf && Array.isArray(result.oneOf)) {\n if (Array.isArray(result.anyOf)) {\n throw new Error(\n 'Cannot convert schema for OpenAI strict mode: \"oneOf\" and \"anyOf\" on the same node cannot be merged without changing semantics',\n );\n }\n result.anyOf = result.oneOf.map(s => stripUnsupportedStrictModeKeywords(s as JSONSchema7));\n delete result.oneOf;\n }\n\n // allOf is unsupported; flatten the intersection into the containing node.\n if (result.allOf && Array.isArray(result.allOf)) {\n const merged = result.allOf.map(s => stripUnsupportedStrictModeKeywords(s as JSONSchema7));\n delete result.allOf;\n mergeAllOfSubschemas(result, merged);\n }\n\n applyToDefinitions(result, stripUnsupportedStrictModeKeywords);\n\n return result;\n}\n\nfunction ensureAdditionalPropertiesFalse(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n if (result.type === 'object' || result.properties) {\n result.additionalProperties = false;\n }\n\n if (result.properties) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [\n key,\n ensureAdditionalPropertiesFalse(value as JSONSchema7),\n ]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => ensureAdditionalPropertiesFalse(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = ensureAdditionalPropertiesFalse(result.items as JSONSchema7);\n }\n }\n\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n\n applyToDefinitions(result, ensureAdditionalPropertiesFalse);\n\n return result;\n}\n\n// export function zotToJsonSchema(zodSchema: ZodSchemaV3 | ZodSchemaV4, target: Targets = 'jsonSchema7', strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative'): JSONSchema7 {\n// const target = 'draft-07' as StandardJSONSchemaV1.Target;\n// const standardSchema = toStandardSchema(zodSchema);\n// const jsonSchema = standardSchemaToJSONSchema(standardSchema, {\n// target,\n// });\n\n// traverse(jsonSchema, {\n// cb: {\n// pre: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n// this.preProcessJSONNode(schema, parentSchema);\n// },\n// post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n// this.postProcessJSONNode(schema, parentSchema);\n// },\n// },\n// });\n\n// }\n\nexport function zodToJsonSchema(\n zodSchema: any,\n target: Targets = 'jsonSchema7',\n strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative',\n): JSONSchema7 {\n // Route based on whether the schema is v4 (has _zod) or v3 (only has _def).\n // We use zV4.toJSONSchema (imported from 'zod/v4') for v4 schemas, since the\n // default 'zod' import may resolve to v3 depending on the environment.\n // Without this check, v3 schemas passed to v4's toJSONSchema would throw\n // \"Cannot read properties of undefined (reading 'def')\".\n if (zodSchema?._zod) {\n // Zod v4 path - patch record schemas before converting\n patchRecordSchemas(zodSchema);\n\n const jsonSchema = zV4.toJSONSchema(zodSchema, {\n unrepresentable: 'any',\n io: 'input',\n override: (ctx: any) => {\n // Handle both Zod v4 structures: _def directly or nested in _zod\n const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;\n // Check for date type using both possible property names\n if (def && (def.typeName === 'ZodDate' || def.type === 'date')) {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n // Add additionalProperties: false for object types to match Zod v3 behavior\n // This is required for OpenAI strict mode function calling\n if (def && (def.typeName === 'ZodObject' || def.type === 'object')) {\n ctx.jsonSchema.additionalProperties = false;\n }\n },\n }) as JSONSchema7;\n\n // Fix anyOf patterns for nullable fields - required for OpenAI compatibility\n return fixAnyOfNullable(jsonSchema);\n } else {\n // Zod v3 path - use the original converter\n return zodToJsonSchemaOriginal(zodSchema as ZodSchemaV3, {\n $refStrategy: strategy,\n target,\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BAAmB,QAAQ,+BAA+B;CAE1D,OAAO;AACT;AAsBA,SAAgB,gBACd,WACA,SAAkB,eAClB,WAAkD,YACrC;CAMb,IAAI,WAAW,MAAM;EAEnB,mBAAmB,SAAS;EAsB5B,OAAO,iBApBYA,OAAAA,EAAI,aAAa,WAAW;GAC7C,iBAAiB;GACjB,IAAI;GACJ,WAAW,QAAa;IAEtB,MAAM,MAAM,IAAI,WAAW,QAAQ,IAAI,WAAW,MAAM;IAExD,IAAI,QAAQ,IAAI,aAAa,aAAa,IAAI,SAAS,SAAS;KAC9D,IAAI,WAAW,OAAO;KACtB,IAAI,WAAW,SAAS;IAC1B;IAGA,IAAI,QAAQ,IAAI,aAAa,eAAe,IAAI,SAAS,WACvD,IAAI,WAAW,uBAAuB;GAE1C;EACF,CAGiC,CAAC;CACpC,OAEE,OAAOC,YAAAA,YAAwB,WAA0B;EACvD,cAAc;EACd;CACF,CAAC;AAEL"}
1
+ {"version":3,"file":"zod-to-json.cjs","names":["zV4","zodToJsonSchemaOriginal"],"sources":["../src/zod-to-json.ts"],"sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport type { ZodSchema as ZodSchemaV3 } from 'zod/v3';\nimport { z as zV4 } from 'zod/v4';\nimport type { Targets } from 'zod-to-json-schema';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\n\n// Symbol to mark schemas as already patched (for idempotency)\nconst PATCHED = Symbol('__mastra_patched__');\n\n/**\n * Recursively patch Zod v4 record schemas that are missing valueType.\n * This fixes a bug in Zod v4 where z.record(valueSchema) doesn't set def.valueType.\n * The single-arg form should set valueType but instead only sets keyType.\n *\n * Idempotent — marks patched schemas with a Symbol so repeat calls no-op.\n *\n * @internal Exported so the Zod v4 standard-schema adapter can apply the\n * same patch before its native `toJSONSchema` call (the legacy `zodToJsonSchema`\n * entry already calls it; the `applyCompatLayer` path otherwise wouldn't).\n * Not part of the public API.\n */\nexport function patchRecordSchemas(schema: any): any {\n if (!schema || typeof schema !== 'object') return schema;\n\n // Skip if already patched (idempotency check)\n if ((schema as any)[PATCHED]) return schema;\n (schema as any)[PATCHED] = true;\n\n // Check the _zod.def location (v4 structure)\n const def = schema._zod?.def;\n\n // Fix record schemas with missing valueType\n if (def?.type === 'record' && def.keyType && !def.valueType) {\n // The bug: z.record(valueSchema) puts the value in keyType instead of valueType\n // Fix: move it to valueType and set keyType to string (the default)\n def.valueType = def.keyType;\n def.keyType = zV4.string();\n }\n\n // Recursively patch nested schemas\n if (!def) return schema;\n\n if (def.type === 'object' && def.shape) {\n const shape = typeof def.shape === 'function' ? def.shape() : def.shape;\n for (const key of Object.keys(shape)) {\n patchRecordSchemas(shape[key]);\n }\n }\n\n if (def.type === 'array' && def.element) {\n patchRecordSchemas(def.element);\n }\n\n if (def.type === 'union' && def.options) {\n def.options.forEach(patchRecordSchemas);\n }\n\n if (def.type === 'record') {\n if (def.keyType) patchRecordSchemas(def.keyType);\n if (def.valueType) patchRecordSchemas(def.valueType);\n }\n\n // Handle intersection types\n if (def.type === 'intersection') {\n if (def.left) patchRecordSchemas(def.left);\n if (def.right) patchRecordSchemas(def.right);\n }\n\n // Handle lazy types - patch the schema returned by the getter\n if (def.type === 'lazy') {\n // For lazy schemas, we need to patch the schema when it's accessed\n // Store the original getter and wrap it\n if (def.getter && typeof def.getter === 'function') {\n const originalGetter = def.getter;\n def.getter = function () {\n const innerSchema = originalGetter();\n if (innerSchema) {\n patchRecordSchemas(innerSchema);\n }\n return innerSchema;\n };\n }\n }\n\n // Handle wrapper types that have innerType\n // This covers: optional, nullable, default, catch, nullish, and any other wrappers\n if (def.innerType) {\n patchRecordSchemas(def.innerType);\n }\n\n return schema;\n}\n\n/**\n * Recursively fixes anyOf patterns that some providers (like OpenAI) don't accept.\n * Converts anyOf: [{type: X}, {type: \"null\"}] to type: [X, \"null\"]\n * Also fixes empty {} property schemas by converting to a union of primitive types.\n */\nfunction fixAnyOfNullable(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n // Fix anyOf pattern: [{type: X}, {type: \"null\"}] or [{type: \"null\"}, {type: X}]\n if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {\n const nullSchema = result.anyOf.find((s: any) => typeof s === 'object' && s !== null && s.type === 'null');\n const otherSchema = result.anyOf.find((s: any) => typeof s === 'object' && s !== null && s.type !== 'null');\n\n if (nullSchema && otherSchema && typeof otherSchema === 'object' && otherSchema.type) {\n // Convert anyOf to type array format\n // Normalize sibling fields (like properties/items) before returning\n const { anyOf, ...rest } = result;\n const fixedRest = fixAnyOfNullable(rest as JSONSchema7);\n const fixedOther = fixAnyOfNullable(otherSchema);\n return {\n ...fixedRest,\n ...fixedOther,\n type: (Array.isArray(fixedOther.type)\n ? [...fixedOther.type, 'null']\n : [fixedOther.type, 'null']) as JSONSchema7['type'],\n };\n }\n }\n\n // Fix empty property schemas {} - OpenAI requires a type key\n if (result.properties && typeof result.properties === 'object' && !Array.isArray(result.properties)) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => {\n const propSchema = value as JSONSchema7;\n\n // If property is an empty object {}, convert to allow primitive types\n // Note: We exclude 'object' (requires additionalProperties) and 'array' (requires items) for OpenAI\n if (\n typeof propSchema === 'object' &&\n propSchema !== null &&\n !Array.isArray(propSchema) &&\n Object.keys(propSchema).length === 0\n ) {\n return [key, { type: ['string', 'number', 'boolean', 'null'] as JSONSchema7['type'] }];\n }\n\n // Recursively fix nested schemas\n return [key, fixAnyOfNullable(propSchema)];\n }),\n );\n }\n\n // Recursively fix items in arrays\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => fixAnyOfNullable(item as JSONSchema7));\n } else {\n result.items = fixAnyOfNullable(result.items as JSONSchema7);\n }\n }\n\n // Recursively fix anyOf/oneOf/allOf schemas\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n\n return result;\n}\n\n/**\n * Apply a strict-mode pass to every schema hoisted into `$defs`/`definitions`.\n * zod-to-json-schema (v3 path, `$refStrategy: 'relative'`) lifts reused subschemas into\n * these definition maps and references them via `$ref`, so the referenced schemas must be\n * processed with the same pass as inline nodes or their unsupported keywords leak through.\n */\nfunction applyToDefinitions(result: JSONSchema7, fn: (schema: JSONSchema7) => JSONSchema7): void {\n for (const defKey of ['$defs', 'definitions'] as const) {\n const defs = (result as Record<string, unknown>)[defKey];\n if (defs && typeof defs === 'object' && !Array.isArray(defs)) {\n (result as Record<string, unknown>)[defKey] = Object.fromEntries(\n Object.entries(defs as Record<string, unknown>).map(([key, value]) => [\n key,\n typeof value === 'object' && value !== null ? fn(value as JSONSchema7) : value,\n ]),\n );\n }\n }\n}\n\n/**\n * Recursively ensures all properties in an object schema are included in the `required` array.\n * OpenAI's strict structured output mode requires every key in `properties` to also appear in `required`.\n *\n * @param schema - The JSON Schema to process\n * @returns A new schema with all properties marked as required\n */\nexport function ensureAllPropertiesRequired(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n if (result.type === 'object' && result.properties) {\n result.required = Object.keys(result.properties);\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value as JSONSchema7)]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => ensureAllPropertiesRequired(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = ensureAllPropertiesRequired(result.items);\n }\n }\n\n if (result.additionalProperties && typeof result.additionalProperties === 'object') {\n result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties);\n }\n\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n\n applyToDefinitions(result, ensureAllPropertiesRequired);\n\n return result;\n}\n\n/**\n * Prepare a JSON Schema for OpenAI strict mode by ensuring all object properties\n * are required and all objects have additionalProperties: false.\n */\nexport function prepareJsonSchemaForOpenAIStrictMode(schema: JSONSchema7): JSONSchema7 {\n const withRequired = ensureAllPropertiesRequired(schema);\n const withoutAdditional = ensureAdditionalPropertiesFalse(withRequired);\n return stripUnsupportedStrictModeKeywords(withoutAdditional);\n}\n\n// Keywords OpenAI Structured Outputs strict mode rejects and that carry no natural-language\n// intent worth preserving. They are removed silently.\n// @see https://platform.openai.com/docs/guides/structured-outputs#supported-schemas\nconst STRICT_MODE_DROPPED_KEYWORDS = [\n 'contains',\n 'minContains',\n 'maxContains',\n 'minProperties',\n 'maxProperties',\n 'patternProperties',\n 'unevaluatedItems',\n 'unevaluatedProperties',\n // Conditional/dependency keywords: unsupported by OpenAI strict mode with no\n // useful structural mapping, so they are dropped.\n 'not',\n 'if',\n 'then',\n 'else',\n 'dependentRequired',\n 'dependentSchemas',\n] as const;\n\nfunction isDeepEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (Array.isArray(a) || Array.isArray(b)) {\n return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => isDeepEqual(v, b[i]));\n }\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) return false;\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n return (\n keysA.length === keysB.length &&\n keysA.every(\n k => Object.hasOwn(b, k) && isDeepEqual((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]),\n )\n );\n}\n\n/**\n * Merge `allOf` subschemas into the containing node. OpenAI strict mode rejects `allOf`\n * (only `anyOf` composition is supported), so the intersection is flattened into a single\n * node. Every keyword from every branch is hoisted so nothing (e.g. `enum`, `const`,\n * `items`, `anyOf`) is silently discarded:\n *\n * - `properties` are unioned; a property present in more than one branch must be identical.\n * - `required` is unioned. `additionalProperties: false` wins. Descriptions are concatenated.\n * - Any other keyword must either be absent from the target or deep-equal to the branch value.\n *\n * Intersections that cannot be represented this way (conflicting property schemas, types,\n * enums, nested `anyOf`, ...) are rejected with an error instead of producing a schema that\n * accepts values the original would have rejected. This mirrors the tool-path behaviour in\n * SchemaCompatLayer (\"Cannot flatten intersections with overlapping keys\").\n */\nfunction mergeAllOfSubschemas(target: JSONSchema7 & Record<string, unknown>, subschemas: JSONSchema7[]): void {\n const mergedProps: Record<string, JSONSchema7> = { ...((target.properties as Record<string, JSONSchema7>) ?? {}) };\n const requiredSet = new Set<string>(Array.isArray(target.required) ? target.required : []);\n const descriptions: string[] =\n typeof target.description === 'string' && target.description ? [target.description] : [];\n\n for (const sub of subschemas) {\n if (!sub || typeof sub !== 'object') {\n continue;\n }\n for (const [key, value] of Object.entries(sub as Record<string, unknown>)) {\n switch (key) {\n case 'properties': {\n for (const [propName, propSchema] of Object.entries(value as Record<string, JSONSchema7>)) {\n if (propName in mergedProps && !isDeepEqual(mergedProps[propName], propSchema)) {\n throw new Error(\n `Cannot flatten allOf for OpenAI strict mode: property \"${propName}\" is defined differently in multiple branches`,\n );\n }\n mergedProps[propName] = propSchema;\n }\n break;\n }\n case 'required': {\n if (Array.isArray(value)) {\n for (const name of value) {\n requiredSet.add(name);\n }\n }\n break;\n }\n case 'additionalProperties': {\n if (value === false) {\n target.additionalProperties = false;\n }\n break;\n }\n case 'description': {\n if (typeof value === 'string' && value) {\n descriptions.push(value);\n }\n break;\n }\n default: {\n if (target[key] === undefined) {\n target[key] = value;\n } else if (!isDeepEqual(target[key], value)) {\n throw new Error(`Cannot flatten allOf for OpenAI strict mode: conflicting \"${key}\" values across branches`);\n }\n }\n }\n }\n }\n\n if (Object.keys(mergedProps).length) {\n target.properties = mergedProps;\n }\n if (requiredSet.size) {\n target.required = [...requiredSet];\n }\n if (descriptions.length) {\n target.description = descriptions.join(' ');\n }\n}\n\n/**\n * Merge constraint phrases into a schema node's description.\n * Mirrors SchemaCompatLayer.mergeParameterDescription phrasing so the strict-mode\n * output path degrades identically to the tool path.\n */\nfunction appendConstraintsToDescription(description: string | undefined, constraints: string[]): string | undefined {\n if (constraints.length === 0) {\n return description;\n }\n const suffix = constraints.join(', ');\n return description ? `${description} (${suffix})` : suffix;\n}\n\n/**\n * Recursively remove JSON Schema validation keywords that OpenAI strict mode rejects.\n * Constraints with useful intent (length/number/pattern/format/uniqueness bounds) are folded\n * into the node's `description` — matching how the tool-path SchemaCompatLayer degrades them\n * in schema-compatibility.ts — while purely structural unsupported keywords are dropped.\n */\nfunction stripUnsupportedStrictModeKeywords(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema } as JSONSchema7 & Record<string, unknown>;\n const constraints: string[] = [];\n\n // Array bounds\n const { minItems, maxItems } = result;\n if (minItems !== undefined && maxItems !== undefined && minItems === maxItems) {\n constraints.push(`exact length ${minItems}`);\n } else {\n if (minItems !== undefined) {\n constraints.push(`minimum length ${minItems}`);\n }\n if (maxItems !== undefined) {\n constraints.push(`maximum length ${maxItems}`);\n }\n }\n delete result.minItems;\n delete result.maxItems;\n\n if (result.uniqueItems === true) {\n constraints.push('all items must be unique');\n }\n delete result.uniqueItems;\n\n // String bounds\n if (result.minLength !== undefined) {\n constraints.push(`minimum length ${result.minLength}`);\n delete result.minLength;\n }\n if (result.maxLength !== undefined) {\n constraints.push(`maximum length ${result.maxLength}`);\n delete result.maxLength;\n }\n if (result.format !== undefined) {\n constraints.push(`a valid ${result.format}`);\n delete result.format;\n }\n if (result.pattern !== undefined) {\n constraints.push(`input must match this regex ${result.pattern}`);\n delete result.pattern;\n }\n\n // Number bounds\n if (result.minimum !== undefined) {\n if (result.minimum !== Number.MIN_SAFE_INTEGER) {\n constraints.push(`greater than or equal to ${result.minimum}`);\n }\n delete result.minimum;\n }\n if (result.maximum !== undefined) {\n if (result.maximum !== Number.MAX_SAFE_INTEGER) {\n constraints.push(`lower than or equal to ${result.maximum}`);\n }\n delete result.maximum;\n }\n if (result.exclusiveMinimum !== undefined) {\n constraints.push(`greater than ${result.exclusiveMinimum}`);\n delete result.exclusiveMinimum;\n }\n if (result.exclusiveMaximum !== undefined) {\n constraints.push(`lower than ${result.exclusiveMaximum}`);\n delete result.exclusiveMaximum;\n }\n if (result.multipleOf !== undefined) {\n constraints.push(`multiple of ${result.multipleOf}`);\n delete result.multipleOf;\n }\n\n // Structural unsupported keywords with no useful natural-language mapping\n for (const keyword of STRICT_MODE_DROPPED_KEYWORDS) {\n delete result[keyword];\n }\n\n if (constraints.length) {\n result.description = appendConstraintsToDescription(result.description, constraints);\n }\n\n if (result.properties) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [\n key,\n stripUnsupportedStrictModeKeywords(value as JSONSchema7),\n ]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => stripUnsupportedStrictModeKeywords(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = stripUnsupportedStrictModeKeywords(result.items as JSONSchema7);\n }\n }\n\n if (result.additionalProperties && typeof result.additionalProperties === 'object') {\n result.additionalProperties = stripUnsupportedStrictModeKeywords(result.additionalProperties as JSONSchema7);\n }\n\n // anyOf is the only composition keyword OpenAI strict mode supports; keep it, strip its branches.\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => stripUnsupportedStrictModeKeywords(s as JSONSchema7));\n }\n\n // oneOf is unsupported; anyOf is the documented replacement, so convert it.\n // When both are present the schema is a conjunction (value must satisfy both lists);\n // concatenating the branches would turn that into a union, so reject instead.\n if (result.oneOf && Array.isArray(result.oneOf)) {\n if (Array.isArray(result.anyOf)) {\n throw new Error(\n 'Cannot convert schema for OpenAI strict mode: \"oneOf\" and \"anyOf\" on the same node cannot be merged without changing semantics',\n );\n }\n result.anyOf = result.oneOf.map(s => stripUnsupportedStrictModeKeywords(s as JSONSchema7));\n delete result.oneOf;\n }\n\n // allOf is unsupported; flatten the intersection into the containing node.\n if (result.allOf && Array.isArray(result.allOf)) {\n const merged = result.allOf.map(s => stripUnsupportedStrictModeKeywords(s as JSONSchema7));\n delete result.allOf;\n mergeAllOfSubschemas(result, merged);\n }\n\n applyToDefinitions(result, stripUnsupportedStrictModeKeywords);\n\n return result;\n}\n\nfunction ensureAdditionalPropertiesFalse(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n if (result.type === 'object' || result.properties) {\n result.additionalProperties = false;\n }\n\n if (result.properties) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [\n key,\n ensureAdditionalPropertiesFalse(value as JSONSchema7),\n ]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => ensureAdditionalPropertiesFalse(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = ensureAdditionalPropertiesFalse(result.items);\n }\n }\n\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n\n applyToDefinitions(result, ensureAdditionalPropertiesFalse);\n\n return result;\n}\n\n// export function zotToJsonSchema(zodSchema: ZodSchemaV3 | ZodSchemaV4, target: Targets = 'jsonSchema7', strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative'): JSONSchema7 {\n// const target = 'draft-07' as StandardJSONSchemaV1.Target;\n// const standardSchema = toStandardSchema(zodSchema);\n// const jsonSchema = standardSchemaToJSONSchema(standardSchema, {\n// target,\n// });\n\n// traverse(jsonSchema, {\n// cb: {\n// pre: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n// this.preProcessJSONNode(schema, parentSchema);\n// },\n// post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n// this.postProcessJSONNode(schema, parentSchema);\n// },\n// },\n// });\n\n// }\n\nexport function zodToJsonSchema(\n zodSchema: any,\n target: Targets = 'jsonSchema7',\n strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative',\n): JSONSchema7 {\n // Route based on whether the schema is v4 (has _zod) or v3 (only has _def).\n // We use zV4.toJSONSchema (imported from 'zod/v4') for v4 schemas, since the\n // default 'zod' import may resolve to v3 depending on the environment.\n // Without this check, v3 schemas passed to v4's toJSONSchema would throw\n // \"Cannot read properties of undefined (reading 'def')\".\n if (zodSchema?._zod) {\n // Zod v4 path - patch record schemas before converting\n patchRecordSchemas(zodSchema);\n\n const jsonSchema = zV4.toJSONSchema(zodSchema, {\n unrepresentable: 'any',\n io: 'input',\n override: (ctx: any) => {\n // Handle both Zod v4 structures: _def directly or nested in _zod\n const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;\n // Check for date type using both possible property names\n if (def && (def.typeName === 'ZodDate' || def.type === 'date')) {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n // Add additionalProperties: false for object types to match Zod v3 behavior\n // This is required for OpenAI strict mode function calling\n if (def && (def.typeName === 'ZodObject' || def.type === 'object')) {\n ctx.jsonSchema.additionalProperties = false;\n }\n },\n }) as JSONSchema7;\n\n // Fix anyOf patterns for nullable fields - required for OpenAI compatibility\n return fixAnyOfNullable(jsonSchema);\n } else {\n // Zod v3 path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