🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP →
Sign In

@mastra/schema-compat

Package Overview
Dependencies
Maintainers
7
Versions
293
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mastra/schema-compat - npm Package Compare versions

Comparing version
1.3.4-alpha.1
to
1.3.4-alpha.2
+208
dist/chunk-FJGZKUBH.cjs
'use strict';
var v4 = require('zod/v4');
var zodToJsonSchemaOriginal = require('zod-to-json-schema');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var zodToJsonSchemaOriginal__default = /*#__PURE__*/_interopDefault(zodToJsonSchemaOriginal);
// src/zod-to-json.ts
var PATCHED = /* @__PURE__ */ Symbol("__mastra_patched__");
function patchRecordSchemas(schema) {
if (!schema || typeof schema !== "object") return schema;
if (schema[PATCHED]) return schema;
schema[PATCHED] = true;
const def = schema._zod?.def;
if (def?.type === "record" && def.keyType && !def.valueType) {
def.valueType = def.keyType;
def.keyType = v4.z.string();
}
if (!def) return schema;
if (def.type === "object" && def.shape) {
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
for (const key of Object.keys(shape)) {
patchRecordSchemas(shape[key]);
}
}
if (def.type === "array" && def.element) {
patchRecordSchemas(def.element);
}
if (def.type === "union" && def.options) {
def.options.forEach(patchRecordSchemas);
}
if (def.type === "record") {
if (def.keyType) patchRecordSchemas(def.keyType);
if (def.valueType) patchRecordSchemas(def.valueType);
}
if (def.type === "intersection") {
if (def.left) patchRecordSchemas(def.left);
if (def.right) patchRecordSchemas(def.right);
}
if (def.type === "lazy") {
if (def.getter && typeof def.getter === "function") {
const originalGetter = def.getter;
def.getter = function() {
const innerSchema = originalGetter();
if (innerSchema) {
patchRecordSchemas(innerSchema);
}
return innerSchema;
};
}
}
if (def.innerType) {
patchRecordSchemas(def.innerType);
}
return schema;
}
function fixAnyOfNullable(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {
const nullSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type === "null");
const otherSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type !== "null");
if (nullSchema && otherSchema && typeof otherSchema === "object" && otherSchema.type) {
const { anyOf, ...rest } = result;
const fixedRest = fixAnyOfNullable(rest);
const fixedOther = fixAnyOfNullable(otherSchema);
return {
...fixedRest,
...fixedOther,
type: Array.isArray(fixedOther.type) ? [...fixedOther.type, "null"] : [fixedOther.type, "null"]
};
}
}
if (result.properties && typeof result.properties === "object" && !Array.isArray(result.properties)) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => {
const propSchema = value;
if (typeof propSchema === "object" && propSchema !== null && !Array.isArray(propSchema) && Object.keys(propSchema).length === 0) {
return [key, { type: ["string", "number", "boolean", "null"] }];
}
return [key, fixAnyOfNullable(propSchema)];
})
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => fixAnyOfNullable(item));
} else {
result.items = fixAnyOfNullable(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => fixAnyOfNullable(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => fixAnyOfNullable(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => fixAnyOfNullable(s));
}
return result;
}
function ensureAllPropertiesRequired(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" && result.properties) {
result.required = Object.keys(result.properties);
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value)])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAllPropertiesRequired(item));
} else if (typeof result.items === "object") {
result.items = ensureAllPropertiesRequired(result.items);
}
}
if (result.additionalProperties && typeof result.additionalProperties === "object") {
result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties);
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAllPropertiesRequired(s));
}
return result;
}
function prepareJsonSchemaForOpenAIStrictMode(schema) {
const withRequired = ensureAllPropertiesRequired(schema);
return ensureAdditionalPropertiesFalse(withRequired);
}
function ensureAdditionalPropertiesFalse(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" || result.properties) {
result.additionalProperties = false;
}
if (result.properties) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [
key,
ensureAdditionalPropertiesFalse(value)
])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAdditionalPropertiesFalse(item));
} else if (typeof result.items === "object") {
result.items = ensureAdditionalPropertiesFalse(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
return result;
}
function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
if (zodSchema?._zod) {
patchRecordSchemas(zodSchema);
const jsonSchema = v4.z.toJSONSchema(zodSchema, {
unrepresentable: "any",
io: "input",
override: (ctx) => {
const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;
if (def && (def.typeName === "ZodDate" || def.type === "date")) {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
if (def && (def.typeName === "ZodObject" || def.type === "object")) {
ctx.jsonSchema.additionalProperties = false;
}
}
});
return fixAnyOfNullable(jsonSchema);
} else {
return zodToJsonSchemaOriginal__default.default(zodSchema, {
$refStrategy: strategy,
target
});
}
}
exports.ensureAllPropertiesRequired = ensureAllPropertiesRequired;
exports.patchRecordSchemas = patchRecordSchemas;
exports.prepareJsonSchemaForOpenAIStrictMode = prepareJsonSchemaForOpenAIStrictMode;
exports.zodToJsonSchema = zodToJsonSchema;
//# sourceMappingURL=chunk-FJGZKUBH.cjs.map
//# sourceMappingURL=chunk-FJGZKUBH.cjs.map
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["zV4","zodToJsonSchemaOriginal"],"mappings":";;;;;;;;;;AAOA,IAAM,OAAA,0BAAiB,oBAAoB,CAAA;AAcpC,SAAS,mBAAmB,MAAA,EAAkB;AACnD,EAAA,IAAI,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,UAAU,OAAO,MAAA;AAGlD,EAAA,IAAK,MAAA,CAAe,OAAO,CAAA,EAAG,OAAO,MAAA;AACrC,EAAC,MAAA,CAAe,OAAO,CAAA,GAAI,IAAA;AAG3B,EAAA,MAAM,GAAA,GAAM,OAAO,IAAA,EAAM,GAAA;AAGzB,EAAA,IAAI,KAAK,IAAA,KAAS,QAAA,IAAY,IAAI,OAAA,IAAW,CAAC,IAAI,SAAA,EAAW;AAG3D,IAAA,GAAA,CAAI,YAAY,GAAA,CAAI,OAAA;AACpB,IAAA,GAAA,CAAI,OAAA,GAAUA,KAAI,MAAA,EAAO;AAAA,EAC3B;AAGA,EAAA,IAAI,CAAC,KAAK,OAAO,MAAA;AAEjB,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,QAAA,IAAY,GAAA,CAAI,KAAA,EAAO;AACtC,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAA,CAAI,KAAA,KAAU,aAAa,GAAA,CAAI,KAAA,KAAU,GAAA,CAAI,KAAA;AAClE,IAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK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AAI,QAAQ,GAAA,CAAI,QAAA,KAAa,WAAA,IAAe,GAAA,CAAI,SAAS,QAAA,CAAA,EAAW;AAClE,UAAA,GAAA,CAAI,WAAW,oBAAA,GAAuB,KAAA;AAAA,QACxC;AAAA,MACF;AAAA,KACD,CAAA;AAGD,IAAA,OAAO,iBAAiB,UAAU,CAAA;AAAA,EACpC,CAAA,MAAO;AAEL,IAAA,OAAOC,yCAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-FJGZKUBH.cjs","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 * 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 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 return ensureAdditionalPropertiesFalse(withRequired);\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 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,\n }) as JSONSchema7;\n }\n}\n"]}
import { z } from 'zod/v4';
import zodToJsonSchemaOriginal from 'zod-to-json-schema';
// src/zod-to-json.ts
var PATCHED = /* @__PURE__ */ Symbol("__mastra_patched__");
function patchRecordSchemas(schema) {
if (!schema || typeof schema !== "object") return schema;
if (schema[PATCHED]) return schema;
schema[PATCHED] = true;
const def = schema._zod?.def;
if (def?.type === "record" && def.keyType && !def.valueType) {
def.valueType = def.keyType;
def.keyType = z.string();
}
if (!def) return schema;
if (def.type === "object" && def.shape) {
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
for (const key of Object.keys(shape)) {
patchRecordSchemas(shape[key]);
}
}
if (def.type === "array" && def.element) {
patchRecordSchemas(def.element);
}
if (def.type === "union" && def.options) {
def.options.forEach(patchRecordSchemas);
}
if (def.type === "record") {
if (def.keyType) patchRecordSchemas(def.keyType);
if (def.valueType) patchRecordSchemas(def.valueType);
}
if (def.type === "intersection") {
if (def.left) patchRecordSchemas(def.left);
if (def.right) patchRecordSchemas(def.right);
}
if (def.type === "lazy") {
if (def.getter && typeof def.getter === "function") {
const originalGetter = def.getter;
def.getter = function() {
const innerSchema = originalGetter();
if (innerSchema) {
patchRecordSchemas(innerSchema);
}
return innerSchema;
};
}
}
if (def.innerType) {
patchRecordSchemas(def.innerType);
}
return schema;
}
function fixAnyOfNullable(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {
const nullSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type === "null");
const otherSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type !== "null");
if (nullSchema && otherSchema && typeof otherSchema === "object" && otherSchema.type) {
const { anyOf, ...rest } = result;
const fixedRest = fixAnyOfNullable(rest);
const fixedOther = fixAnyOfNullable(otherSchema);
return {
...fixedRest,
...fixedOther,
type: Array.isArray(fixedOther.type) ? [...fixedOther.type, "null"] : [fixedOther.type, "null"]
};
}
}
if (result.properties && typeof result.properties === "object" && !Array.isArray(result.properties)) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => {
const propSchema = value;
if (typeof propSchema === "object" && propSchema !== null && !Array.isArray(propSchema) && Object.keys(propSchema).length === 0) {
return [key, { type: ["string", "number", "boolean", "null"] }];
}
return [key, fixAnyOfNullable(propSchema)];
})
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => fixAnyOfNullable(item));
} else {
result.items = fixAnyOfNullable(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => fixAnyOfNullable(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => fixAnyOfNullable(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => fixAnyOfNullable(s));
}
return result;
}
function ensureAllPropertiesRequired(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" && result.properties) {
result.required = Object.keys(result.properties);
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value)])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAllPropertiesRequired(item));
} else if (typeof result.items === "object") {
result.items = ensureAllPropertiesRequired(result.items);
}
}
if (result.additionalProperties && typeof result.additionalProperties === "object") {
result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties);
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAllPropertiesRequired(s));
}
return result;
}
function prepareJsonSchemaForOpenAIStrictMode(schema) {
const withRequired = ensureAllPropertiesRequired(schema);
return ensureAdditionalPropertiesFalse(withRequired);
}
function ensureAdditionalPropertiesFalse(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" || result.properties) {
result.additionalProperties = false;
}
if (result.properties) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [
key,
ensureAdditionalPropertiesFalse(value)
])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAdditionalPropertiesFalse(item));
} else if (typeof result.items === "object") {
result.items = ensureAdditionalPropertiesFalse(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
return result;
}
function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
if (zodSchema?._zod) {
patchRecordSchemas(zodSchema);
const jsonSchema = z.toJSONSchema(zodSchema, {
unrepresentable: "any",
io: "input",
override: (ctx) => {
const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;
if (def && (def.typeName === "ZodDate" || def.type === "date")) {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
if (def && (def.typeName === "ZodObject" || def.type === "object")) {
ctx.jsonSchema.additionalProperties = false;
}
}
});
return fixAnyOfNullable(jsonSchema);
} else {
return zodToJsonSchemaOriginal(zodSchema, {
$refStrategy: strategy,
target
});
}
}
export { ensureAllPropertiesRequired, patchRecordSchemas, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema };
//# sourceMappingURL=chunk-QEM5W7OR.js.map
//# sourceMappingURL=chunk-QEM5W7OR.js.map
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["zV4"],"mappings":";;;;AAOA,IAAM,OAAA,0BAAiB,oBAAoB,CAAA;AAcpC,SAAS,mBAAmB,MAAA,EAAkB;AACnD,EAAA,IAAI,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,UAAU,OAAO,MAAA;AAGlD,EAAA,IAAK,MAAA,CAAe,OAAO,CAAA,EAAG,OAAO,MAAA;AACrC,EAAC,MAAA,CAAe,OAAO,CAAA,GAAI,IAAA;AAG3B,EAAA,MAAM,GAAA,GAAM,OAAO,IAAA,EAAM,GAAA;AAGzB,EAAA,IAAI,KAAK,IAAA,KAAS,QAAA,IAAY,IAAI,OAAA,IAAW,CAAC,IAAI,SAAA,EAAW;AAG3D,IAAA,GAAA,CAAI,YAAY,GAAA,CAAI,OAAA;AACpB,IAAA,GAAA,CAAI,OAAA,GAAUA,EAAI,MAAA,EAAO;AAAA,EAC3B;AAGA,EAAA,IAAI,CAAC,KAAK,OAAO,MAAA;AAEjB,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,QAAA,IAAY,GAAA,CAAI,KAAA,EAAO;AACtC,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAA,CAA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C9D,UAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,UAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAGA,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,WAAA,IAAe,GAAA,CAAI,SAAS,QAAA,CAAA,EAAW;AAClE,UAAA,GAAA,CAAI,WAAW,oBAAA,GAAuB,KAAA;AAAA,QACxC;AAAA,MACF;AAAA,KACD,CAAA;AAGD,IAAA,OAAO,iBAAiB,UAAU,CAAA;AAAA,EACpC,CAAA,MAAO;AAEL,IAAA,OAAO,wBAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-QEM5W7OR.js","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 * 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 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 return ensureAdditionalPropertiesFalse(withRequired);\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 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,\n }) as JSONSchema7;\n }\n}\n"]}
import { patchRecordSchemas } from './chunk-QEM5W7OR.js';
import { toStandardSchema as toStandardSchema$1 } from './chunk-23HDOZLF.js';
import { toStandardSchema as toStandardSchema$2 } from './chunk-RMMKMUYK.js';
import { toStandardSchema } from './chunk-QFEMCRFS.js';
import z3 from 'zod/v3';
import { toJSONSchema } from 'zod/v4';
var SUPPORTED_TARGETS = /* @__PURE__ */ new Set(["draft-07", "draft-04", "draft-2020-12"]);
var ZOD_V4_TARGET_MAP = {
"draft-07": "draft-7",
"draft-04": "draft-4"
};
function convertToJsonSchema(zodSchema, options, adapterOptions) {
patchRecordSchemas(zodSchema);
const target = SUPPORTED_TARGETS.has(options.target) ? options.target : "draft-07";
const jsonSchemaOptions = {
target: ZOD_V4_TARGET_MAP[target] ?? target
};
if (adapterOptions.unrepresentable) {
jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;
}
if (adapterOptions.override) {
jsonSchemaOptions.override = adapterOptions.override;
}
return toJSONSchema(zodSchema, jsonSchemaOptions);
}
function toStandardSchema4(zodSchema, adapterOptions = {}) {
const wrapper = Object.create(zodSchema);
const existingStandard = zodSchema["~standard"];
const jsonSchemaConverter = {
input: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
},
output: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
}
};
Object.defineProperty(wrapper, "~standard", {
value: {
...existingStandard,
jsonSchema: jsonSchemaConverter
},
writable: false,
enumerable: true,
configurable: false
});
return wrapper;
}
// src/standard-schema/standard-schema.ts
function jsonSchemaOverride(ctx) {
const zodSchema = ctx.zodSchema;
if (ctx.jsonSchema.type === "object" && ctx.jsonSchema.properties !== void 0 && !ctx.jsonSchema.additionalProperties) {
ctx.jsonSchema.additionalProperties = false;
}
if (zodSchema) {
const isDateType = zodSchema?.type === "date" || zodSchema?._def?.typeName === "ZodDate";
if (isDateType) {
if (zodSchema?.type === "date") {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
ctx.jsonSchema["x-date"] = !zodSchema._zod?.def?.coerce;
} else if (zodSchema?.type === "object" && zodSchema._zod?.def?.catchall?.type === "unknown") {
ctx.jsonSchema.additionalProperties = true;
}
}
return void 0;
}
var JSON_SCHEMA_LIBRARY_OPTIONS = {
unrepresentable: "any",
override: jsonSchemaOverride
};
function isVercelSchema(schema) {
return typeof schema === "object" && schema !== null && "_type" in schema && "jsonSchema" in schema && typeof schema.jsonSchema === "object";
}
function isZodV4(schema) {
return typeof schema === "object" && schema !== null && "_zod" in schema;
}
function isZodV3(schema) {
if (schema === null || typeof schema !== "object") {
return false;
}
if (isZodV4(schema)) {
return false;
}
if ("~standard" in schema) {
const std = schema["~standard"];
if (typeof std === "object" && std !== null && std.vendor === "zod" && !("jsonSchema" in std)) {
return true;
}
}
return schema instanceof z3.ZodType;
}
function toStandardSchema5(schema) {
if (isZodV4(schema)) {
patchRecordSchemas(schema);
}
if (isStandardSchemaWithJSON(schema)) {
return schema;
}
if (isZodV4(schema)) {
return toStandardSchema4(schema, {
unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,
override: JSON_SCHEMA_LIBRARY_OPTIONS.override
});
}
if (isZodV3(schema)) {
return toStandardSchema(schema);
}
if (isVercelSchema(schema)) {
return toStandardSchema$1(schema);
}
if (schema === null || typeof schema !== "object" && typeof schema !== "function") {
throw new Error(`Unsupported schema type: ${typeof schema}`);
}
if (typeof schema === "function") {
throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);
}
return toStandardSchema$2(schema);
}
function isStandardSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
return typeof std === "object" && std !== null && "version" in std && std.version === 1 && "vendor" in std && "validate" in std && typeof std.validate === "function";
}
function isStandardJSONSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
if (typeof std !== "object" || std === null) {
return false;
}
if (!("version" in std) || std.version !== 1 || !("vendor" in std)) {
return false;
}
if (!("jsonSchema" in std) || typeof std.jsonSchema !== "object") {
return false;
}
return typeof std.jsonSchema.input === "function" && typeof std.jsonSchema.output === "function";
}
function isStandardSchemaWithJSON(value) {
return isStandardSchema(value) && isStandardJSONSchema(value);
}
function standardSchemaToJSONSchema(schema, options = {}) {
const { target = "draft-07", io = "output", override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;
const jsonSchemaFn = schema["~standard"].jsonSchema[io];
let jsonSchema = jsonSchemaFn({
target,
libraryOptions: {
...JSON_SCHEMA_LIBRARY_OPTIONS,
override
}
});
jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
return jsonSchema;
}
export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema5 as toStandardSchema };
//# sourceMappingURL=chunk-VNIPWNNH.js.map
//# sourceMappingURL=chunk-VNIPWNNH.js.map
{"version":3,"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"names":["toStandardSchema"],"mappings":";;;;;;;AASA,IAAM,oCAAoB,IAAI,GAAA,CAAI,CAAC,UAAA,EAAY,UAAA,EAAY,eAAe,CAAC,CAAA;AAO3E,IAAM,iBAAA,GAA4C;AAAA,EAChD,UAAA,EAAY,SAAA;AAAA,EACZ,UAAA,EAAY;AACd,CAAA;AAiBA,SAAS,mBAAA,CACP,SAAA,EACA,OAAA,EACA,cAAA,EACyB;AAMzB,EAAA,kBAAA,CAAmB,SAAS,CAAA;AAE5B,EAAA,MAAM,SAAS,iBAAA,CAAkB,GAAA,CAAI,QAAQ,MAAM,CAAA,GAAI,QAAQ,MAAA,GAAS,UAAA;AAExE,EAAA,MAAM,iBAAA,GAA6C;AAAA,IACjD,MAAA,EAAQ,iBAAA,CAAkB,MAAM,CAAA,IAAK;AAAA,GACvC;AAEA,EAAA,IAAI,eAAe,eAAA,EAAiB;AAClC,IAAA,iBAAA,CAAkB,kBAAkB,cAAA,CAAe,eAAA;AAAA,EACrD;AAGA,EAAA,IAAI,eAAe,QAAA,EAAU;AAC3B,IAAA,iBAAA,CAAkB,WAAW,cAAA,CAAe,QAAA;AAAA,EAC9C;AAEA,EAAA,OAAO,YAAA,CAAa,WAAiD,iBAAiB,CAAA;AACxF;AAcO,SAASA,iBAAAA,CACd,SAAA,EACA,cAAA,GAAsC,EAAC,EACX;AAE5B,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA;AAGvC,EAAA,MAAM,gBAAA,GAAoB,UAAkB,WAAW,CAAA;AAGvD,EAAA,MAAM,mBAAA,GAAsD;AAAA,IAC1D,KAAA,EAAO,CAAC,OAAA,KAAmE;AACzE,MAAA,OAAO,mBAAA,C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AW,EAAE,CAAA;AACtD,EAAA,IAAI,aAAa,YAAA,CAAa;AAAA,IAC5B,MAAA;AAAA,IACA,cAAA,EAAgB;AAAA,MACd,GAAG,2BAAA;AAAA,MACH;AAAA;AACF,GACD,CAAA;AAGD,EAAA,UAAA,GAAa,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAA;AAElD,EAAA,OAAO,UAAA;AACT","file":"chunk-VNIPWNNH.js","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"]}
'use strict';
var chunkFJGZKUBH_cjs = require('./chunk-FJGZKUBH.cjs');
var chunkFS3P4V5M_cjs = require('./chunk-FS3P4V5M.cjs');
var chunk77T2HV4Q_cjs = require('./chunk-77T2HV4Q.cjs');
var chunkBQ3VTMIR_cjs = require('./chunk-BQ3VTMIR.cjs');
var z3 = require('zod/v3');
var v4 = require('zod/v4');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var z3__default = /*#__PURE__*/_interopDefault(z3);
var SUPPORTED_TARGETS = /* @__PURE__ */ new Set(["draft-07", "draft-04", "draft-2020-12"]);
var ZOD_V4_TARGET_MAP = {
"draft-07": "draft-7",
"draft-04": "draft-4"
};
function convertToJsonSchema(zodSchema, options, adapterOptions) {
chunkFJGZKUBH_cjs.patchRecordSchemas(zodSchema);
const target = SUPPORTED_TARGETS.has(options.target) ? options.target : "draft-07";
const jsonSchemaOptions = {
target: ZOD_V4_TARGET_MAP[target] ?? target
};
if (adapterOptions.unrepresentable) {
jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;
}
if (adapterOptions.override) {
jsonSchemaOptions.override = adapterOptions.override;
}
return v4.toJSONSchema(zodSchema, jsonSchemaOptions);
}
function toStandardSchema4(zodSchema, adapterOptions = {}) {
const wrapper = Object.create(zodSchema);
const existingStandard = zodSchema["~standard"];
const jsonSchemaConverter = {
input: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
},
output: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
}
};
Object.defineProperty(wrapper, "~standard", {
value: {
...existingStandard,
jsonSchema: jsonSchemaConverter
},
writable: false,
enumerable: true,
configurable: false
});
return wrapper;
}
// src/standard-schema/standard-schema.ts
function jsonSchemaOverride(ctx) {
const zodSchema = ctx.zodSchema;
if (ctx.jsonSchema.type === "object" && ctx.jsonSchema.properties !== void 0 && !ctx.jsonSchema.additionalProperties) {
ctx.jsonSchema.additionalProperties = false;
}
if (zodSchema) {
const isDateType = zodSchema?.type === "date" || zodSchema?._def?.typeName === "ZodDate";
if (isDateType) {
if (zodSchema?.type === "date") {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
ctx.jsonSchema["x-date"] = !zodSchema._zod?.def?.coerce;
} else if (zodSchema?.type === "object" && zodSchema._zod?.def?.catchall?.type === "unknown") {
ctx.jsonSchema.additionalProperties = true;
}
}
return void 0;
}
var JSON_SCHEMA_LIBRARY_OPTIONS = {
unrepresentable: "any",
override: jsonSchemaOverride
};
function isVercelSchema(schema) {
return typeof schema === "object" && schema !== null && "_type" in schema && "jsonSchema" in schema && typeof schema.jsonSchema === "object";
}
function isZodV4(schema) {
return typeof schema === "object" && schema !== null && "_zod" in schema;
}
function isZodV3(schema) {
if (schema === null || typeof schema !== "object") {
return false;
}
if (isZodV4(schema)) {
return false;
}
if ("~standard" in schema) {
const std = schema["~standard"];
if (typeof std === "object" && std !== null && std.vendor === "zod" && !("jsonSchema" in std)) {
return true;
}
}
return schema instanceof z3__default.default.ZodType;
}
function toStandardSchema5(schema) {
if (isZodV4(schema)) {
chunkFJGZKUBH_cjs.patchRecordSchemas(schema);
}
if (isStandardSchemaWithJSON(schema)) {
return schema;
}
if (isZodV4(schema)) {
return toStandardSchema4(schema, {
unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,
override: JSON_SCHEMA_LIBRARY_OPTIONS.override
});
}
if (isZodV3(schema)) {
return chunkBQ3VTMIR_cjs.toStandardSchema(schema);
}
if (isVercelSchema(schema)) {
return chunkFS3P4V5M_cjs.toStandardSchema(schema);
}
if (schema === null || typeof schema !== "object" && typeof schema !== "function") {
throw new Error(`Unsupported schema type: ${typeof schema}`);
}
if (typeof schema === "function") {
throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);
}
return chunk77T2HV4Q_cjs.toStandardSchema(schema);
}
function isStandardSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
return typeof std === "object" && std !== null && "version" in std && std.version === 1 && "vendor" in std && "validate" in std && typeof std.validate === "function";
}
function isStandardJSONSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
if (typeof std !== "object" || std === null) {
return false;
}
if (!("version" in std) || std.version !== 1 || !("vendor" in std)) {
return false;
}
if (!("jsonSchema" in std) || typeof std.jsonSchema !== "object") {
return false;
}
return typeof std.jsonSchema.input === "function" && typeof std.jsonSchema.output === "function";
}
function isStandardSchemaWithJSON(value) {
return isStandardSchema(value) && isStandardJSONSchema(value);
}
function standardSchemaToJSONSchema(schema, options = {}) {
const { target = "draft-07", io = "output", override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;
const jsonSchemaFn = schema["~standard"].jsonSchema[io];
let jsonSchema = jsonSchemaFn({
target,
libraryOptions: {
...JSON_SCHEMA_LIBRARY_OPTIONS,
override
}
});
jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
return jsonSchema;
}
exports.JSON_SCHEMA_LIBRARY_OPTIONS = JSON_SCHEMA_LIBRARY_OPTIONS;
exports.isStandardJSONSchema = isStandardJSONSchema;
exports.isStandardSchema = isStandardSchema;
exports.isStandardSchemaWithJSON = isStandardSchemaWithJSON;
exports.standardSchemaToJSONSchema = standardSchemaToJSONSchema;
exports.toStandardSchema = toStandardSchema5;
//# sourceMappingURL=chunk-ZTO66ALH.cjs.map
//# sourceMappingURL=chunk-ZTO66ALH.cjs.map
{"version":3,"sources":["../src/standard-schema/ad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A,MACd,GAAG,2BAAA;AAAA,MACH;AAAA;AACF,GACD,CAAA;AAGD,EAAA,UAAA,GAAa,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAA;AAElD,EAAA,OAAO,UAAA;AACT","file":"chunk-ZTO66ALH.cjs","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"]}
+10
-0
# @mastra/schema-compat
## 1.3.4-alpha.2
### Patch Changes
- Fixed a crash when converting Zod v4 schemas containing `z.record(...)` through `applyCompatLayer` with any provider compat layer attached (e.g. `GoogleSchemaCompatLayer`, `OpenAISchemaCompatLayer`). ([#17052](https://github.com/mastra-ai/mastra/pull/17052))
The record patch is now applied in `toStandardSchema` before the `StandardSchemaWithJSON` short-circuit, so it covers Zod >= 4.2 (which natively exposes `~standard.jsonSchema` and bypasses the Zod v4 adapter) as well as older Zod v4 versions that go through the adapter. Affects Zod 4.0.0–4.3.x; the underlying `z.record()` bug is fixed upstream in Zod 4.4.0.
Fixes [#17051](https://github.com/mastra-ai/mastra/issues/17051).
## 1.3.4-alpha.1

@@ -4,0 +14,0 @@

+7
-7
'use strict';
var chunkXVGNFEQ2_cjs = require('./chunk-XVGNFEQ2.cjs');
var chunkZTO66ALH_cjs = require('./chunk-ZTO66ALH.cjs');

@@ -9,25 +9,25 @@

enumerable: true,
get: function () { return chunkXVGNFEQ2_cjs.JSON_SCHEMA_LIBRARY_OPTIONS; }
get: function () { return chunkZTO66ALH_cjs.JSON_SCHEMA_LIBRARY_OPTIONS; }
});
Object.defineProperty(exports, "isStandardJSONSchema", {
enumerable: true,
get: function () { return chunkXVGNFEQ2_cjs.isStandardJSONSchema; }
get: function () { return chunkZTO66ALH_cjs.isStandardJSONSchema; }
});
Object.defineProperty(exports, "isStandardSchema", {
enumerable: true,
get: function () { return chunkXVGNFEQ2_cjs.isStandardSchema; }
get: function () { return chunkZTO66ALH_cjs.isStandardSchema; }
});
Object.defineProperty(exports, "isStandardSchemaWithJSON", {
enumerable: true,
get: function () { return chunkXVGNFEQ2_cjs.isStandardSchemaWithJSON; }
get: function () { return chunkZTO66ALH_cjs.isStandardSchemaWithJSON; }
});
Object.defineProperty(exports, "standardSchemaToJSONSchema", {
enumerable: true,
get: function () { return chunkXVGNFEQ2_cjs.standardSchemaToJSONSchema; }
get: function () { return chunkZTO66ALH_cjs.standardSchemaToJSONSchema; }
});
Object.defineProperty(exports, "toStandardSchema", {
enumerable: true,
get: function () { return chunkXVGNFEQ2_cjs.toStandardSchema; }
get: function () { return chunkZTO66ALH_cjs.toStandardSchema; }
});
//# sourceMappingURL=schema.cjs.map
//# sourceMappingURL=schema.cjs.map

@@ -1,3 +0,3 @@

export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema } from './chunk-UZUKSPJ6.js';
export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema } from './chunk-VNIPWNNH.js';
//# sourceMappingURL=schema.js.map
//# sourceMappingURL=schema.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"zod-v4.d.ts","sourceRoot":"","sources":["../../../src/standard-schema/adapters/zod-v4.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAEpF,OAAO,KAAK,EAAE,sBAAsB,EAA+B,MAAM,0BAA0B,CAAC;AAkBpG;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAAK,SAAS,CAAC;CAC5F;AAgCD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,SAAS,EAAE,CAAC,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAA;CAAE,EACrE,cAAc,GAAE,mBAAwB,GACvC,CAAC,GAAG,sBAAsB,CA6B5B"}
{"version":3,"file":"zod-v4.d.ts","sourceRoot":"","sources":["../../../src/standard-schema/adapters/zod-v4.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAGpF,OAAO,KAAK,EAAE,sBAAsB,EAA+B,MAAM,0BAA0B,CAAC;AAkBpG;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAAK,SAAS,CAAC;CAC5F;AAuCD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,SAAS,EAAE,CAAC,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAA;CAAE,EACrE,cAAc,GAAE,mBAAwB,GACvC,CAAC,GAAG,sBAAsB,CA6B5B"}

@@ -1,1 +0,1 @@

{"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../../src/standard-schema/standard-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAKpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEtE;;;;GAIG;AACH,iBAAS,kBAAkB,CAAC,GAAG,EAAE;IAA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LQOEEQF6_cjs = require('./chunk-LQOEEQF6.cjs');
var chunkFJGZKUBH_cjs = require('./chunk-FJGZKUBH.cjs');

@@ -9,13 +9,17 @@

enumerable: true,
get: function () { return chunkLQOEEQF6_cjs.ensureAllPropertiesRequired; }
get: function () { return chunkFJGZKUBH_cjs.ensureAllPropertiesRequired; }
});
Object.defineProperty(exports, "patchRecordSchemas", {
enumerable: true,
get: function () { return chunkFJGZKUBH_cjs.patchRecordSchemas; }
});
Object.defineProperty(exports, "prepareJsonSchemaForOpenAIStrictMode", {
enumerable: true,
get: function () { return chunkLQOEEQF6_cjs.prepareJsonSchemaForOpenAIStrictMode; }
get: function () { return chunkFJGZKUBH_cjs.prepareJsonSchemaForOpenAIStrictMode; }
});
Object.defineProperty(exports, "zodToJsonSchema", {
enumerable: true,
get: function () { return chunkLQOEEQF6_cjs.zodToJsonSchema; }
get: function () { return chunkFJGZKUBH_cjs.zodToJsonSchema; }
});
//# sourceMappingURL=zod-to-json.cjs.map
//# sourceMappingURL=zod-to-json.cjs.map
import type { JSONSchema7 } from './_types/@types_json-schema/index.d.ts';
import type { Targets } from 'zod-to-json-schema';
/**
* Recursively patch Zod v4 record schemas that are missing valueType.
* This fixes a bug in Zod v4 where z.record(valueSchema) doesn't set def.valueType.
* The single-arg form should set valueType but instead only sets keyType.
*
* Idempotent — marks patched schemas with a Symbol so repeat calls no-op.
*
* @internal Exported so the Zod v4 standard-schema adapter can apply the
* same patch before its native `toJSONSchema` call (the legacy `zodToJsonSchema`
* entry already calls it; the `applyCompatLayer` path otherwise wouldn't).
* Not part of the public API.
*/
export declare function patchRecordSchemas(schema: any): any;
/**
* Recursively ensures all properties in an object schema are included in the `required` array.

@@ -5,0 +18,0 @@ * OpenAI's strict structured output mode requires every key in `properties` to also appear in `required`.

@@ -1,1 +0,1 @@

{"version":3,"file":"zod-to-json.d.ts","sourceRoot":"","sources":["../src/zod-to-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAkKlD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAqC5E;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAGrF;AA+DD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,GAAG,EACd,MAAM,GAAE,OAAuB,EAC/B,QAAQ,GAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAuB,GAC3D,WAAW,CAsCb"}
{"version":3,"file":"zod-to-json.d.ts","sourceRoot":"","sources":["../src/zod-to-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAMlD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAsEnD;AAiFD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAqC5E;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAGrF;AA+DD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,GAAG,EACd,MAAM,GAAE,OAAuB,EAC/B,QAAQ,GAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAuB,GAC3D,WAAW,CAsCb"}

@@ -1,3 +0,3 @@

export { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema } from './chunk-ECLNT3TQ.js';
export { ensureAllPropertiesRequired, patchRecordSchemas, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema } from './chunk-QEM5W7OR.js';
//# sourceMappingURL=zod-to-json.js.map
//# sourceMappingURL=zod-to-json.js.map
{
"name": "@mastra/schema-compat",
"version": "1.3.4-alpha.1",
"version": "1.3.4-alpha.2",
"description": "Tool schema compatibility layer for Mastra.ai",

@@ -104,10 +104,10 @@ "type": "module",

"devDependencies": {
"@ai-sdk/anthropic": "^3.0.82",
"@ai-sdk/google": "^3.0.70",
"@ai-sdk/openai": "^3.0.63",
"@ai-sdk/anthropic": "^3.0.96",
"@ai-sdk/google": "^3.0.91",
"@ai-sdk/openai": "^3.0.84",
"@standard-schema/spec": "^1.1.0",
"@types/json-schema": "^7.0.15",
"@types/node": "22.19.21",
"@vitest/coverage-v8": "4.1.9",
"@vitest/ui": "4.1.9",
"@vitest/coverage-v8": "4.1.10",
"@vitest/ui": "4.1.10",
"ajv": "^8.20.0",

@@ -119,3 +119,3 @@ "arktype": "^2.2.0",

"typescript": "^6.0.3",
"vitest": "4.1.9",
"vitest": "4.1.10",
"zod": "^4.4.3",

@@ -126,6 +126,6 @@ "zod-v3": "npm:zod@^3.25.76",

"@internal/ai-v6": "0.0.60",
"@internal/llm-recorder": "0.0.49",
"@internal/lint": "0.0.113",
"@internal/test-utils": "0.0.49",
"@internal/lint": "0.0.113",
"@internal/types-builder": "0.0.88"
"@internal/types-builder": "0.0.88",
"@internal/llm-recorder": "0.0.49"
},

@@ -132,0 +132,0 @@ "homepage": "https://mastra.ai",

import { z } from 'zod/v4';
import zodToJsonSchemaOriginal from 'zod-to-json-schema';
// src/zod-to-json.ts
var PATCHED = /* @__PURE__ */ Symbol("__mastra_patched__");
function patchRecordSchemas(schema) {
if (!schema || typeof schema !== "object") return schema;
if (schema[PATCHED]) return schema;
schema[PATCHED] = true;
const def = schema._zod?.def;
if (def?.type === "record" && def.keyType && !def.valueType) {
def.valueType = def.keyType;
def.keyType = z.string();
}
if (!def) return schema;
if (def.type === "object" && def.shape) {
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
for (const key of Object.keys(shape)) {
patchRecordSchemas(shape[key]);
}
}
if (def.type === "array" && def.element) {
patchRecordSchemas(def.element);
}
if (def.type === "union" && def.options) {
def.options.forEach(patchRecordSchemas);
}
if (def.type === "record") {
if (def.keyType) patchRecordSchemas(def.keyType);
if (def.valueType) patchRecordSchemas(def.valueType);
}
if (def.type === "intersection") {
if (def.left) patchRecordSchemas(def.left);
if (def.right) patchRecordSchemas(def.right);
}
if (def.type === "lazy") {
if (def.getter && typeof def.getter === "function") {
const originalGetter = def.getter;
def.getter = function() {
const innerSchema = originalGetter();
if (innerSchema) {
patchRecordSchemas(innerSchema);
}
return innerSchema;
};
}
}
if (def.innerType) {
patchRecordSchemas(def.innerType);
}
return schema;
}
function fixAnyOfNullable(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {
const nullSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type === "null");
const otherSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type !== "null");
if (nullSchema && otherSchema && typeof otherSchema === "object" && otherSchema.type) {
const { anyOf, ...rest } = result;
const fixedRest = fixAnyOfNullable(rest);
const fixedOther = fixAnyOfNullable(otherSchema);
return {
...fixedRest,
...fixedOther,
type: Array.isArray(fixedOther.type) ? [...fixedOther.type, "null"] : [fixedOther.type, "null"]
};
}
}
if (result.properties && typeof result.properties === "object" && !Array.isArray(result.properties)) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => {
const propSchema = value;
if (typeof propSchema === "object" && propSchema !== null && !Array.isArray(propSchema) && Object.keys(propSchema).length === 0) {
return [key, { type: ["string", "number", "boolean", "null"] }];
}
return [key, fixAnyOfNullable(propSchema)];
})
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => fixAnyOfNullable(item));
} else {
result.items = fixAnyOfNullable(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => fixAnyOfNullable(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => fixAnyOfNullable(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => fixAnyOfNullable(s));
}
return result;
}
function ensureAllPropertiesRequired(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" && result.properties) {
result.required = Object.keys(result.properties);
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value)])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAllPropertiesRequired(item));
} else if (typeof result.items === "object") {
result.items = ensureAllPropertiesRequired(result.items);
}
}
if (result.additionalProperties && typeof result.additionalProperties === "object") {
result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties);
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAllPropertiesRequired(s));
}
return result;
}
function prepareJsonSchemaForOpenAIStrictMode(schema) {
const withRequired = ensureAllPropertiesRequired(schema);
return ensureAdditionalPropertiesFalse(withRequired);
}
function ensureAdditionalPropertiesFalse(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" || result.properties) {
result.additionalProperties = false;
}
if (result.properties) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [
key,
ensureAdditionalPropertiesFalse(value)
])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAdditionalPropertiesFalse(item));
} else if (typeof result.items === "object") {
result.items = ensureAdditionalPropertiesFalse(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
return result;
}
function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
if (zodSchema?._zod) {
patchRecordSchemas(zodSchema);
const jsonSchema = z.toJSONSchema(zodSchema, {
unrepresentable: "any",
io: "input",
override: (ctx) => {
const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;
if (def && (def.typeName === "ZodDate" || def.type === "date")) {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
if (def && (def.typeName === "ZodObject" || def.type === "object")) {
ctx.jsonSchema.additionalProperties = false;
}
}
});
return fixAnyOfNullable(jsonSchema);
} else {
return zodToJsonSchemaOriginal(zodSchema, {
$refStrategy: strategy,
target
});
}
}
export { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema };
//# sourceMappingURL=chunk-ECLNT3TQ.js.map
//# sourceMappingURL=chunk-ECLNT3TQ.js.map
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["zV4"],"mappings":";;;;AAOA,IAAM,OAAA,0BAAiB,oBAAoB,CAAA;AAO3C,SAAS,mBAAmB,MAAA,EAAkB;AAC5C,EAAA,IAAI,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,UAAU,OAAO,MAAA;AAGlD,EAAA,IAAK,MAAA,CAAe,OAAO,CAAA,EAAG,OAAO,MAAA;AACrC,EAAC,MAAA,CAAe,OAAO,CAAA,GAAI,IAAA;AAG3B,EAAA,MAAM,GAAA,GAAM,OAAO,IAAA,EAAM,GAAA;AAGzB,EAAA,IAAI,KAAK,IAAA,KAAS,QAAA,IAAY,IAAI,OAAA,IAAW,CAAC,IAAI,SAAA,EAAW;AAG3D,IAAA,GAAA,CAAI,YAAY,GAAA,CAAI,OAAA;AACpB,IAAA,GAAA,CAAI,OAAA,G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,KAAa;AAEtB,QAAA,MAAM,MAAM,GAAA,CAAI,SAAA,EAAW,IAAA,IAAQ,GAAA,CAAI,WAAW,IAAA,EAAM,GAAA;AAExD,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,SAAA,IAAa,GAAA,CAAI,SAAS,MAAA,CAAA,EAAS;AAC9D,UAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,UAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAGA,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,WAAA,IAAe,GAAA,CAAI,SAAS,QAAA,CAAA,EAAW;AAClE,UAAA,GAAA,CAAI,WAAW,oBAAA,GAAuB,KAAA;AAAA,QACxC;AAAA,MACF;AAAA,KACD,CAAA;AAGD,IAAA,OAAO,iBAAiB,UAAU,CAAA;AAAA,EACpC,CAAA,MAAO;AAEL,IAAA,OAAO,wBAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-ECLNT3TQ.js","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 */\nfunction 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 * 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 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 return ensureAdditionalPropertiesFalse(withRequired);\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 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,\n }) as JSONSchema7;\n }\n}\n"]}
'use strict';
var v4 = require('zod/v4');
var zodToJsonSchemaOriginal = require('zod-to-json-schema');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var zodToJsonSchemaOriginal__default = /*#__PURE__*/_interopDefault(zodToJsonSchemaOriginal);
// src/zod-to-json.ts
var PATCHED = /* @__PURE__ */ Symbol("__mastra_patched__");
function patchRecordSchemas(schema) {
if (!schema || typeof schema !== "object") return schema;
if (schema[PATCHED]) return schema;
schema[PATCHED] = true;
const def = schema._zod?.def;
if (def?.type === "record" && def.keyType && !def.valueType) {
def.valueType = def.keyType;
def.keyType = v4.z.string();
}
if (!def) return schema;
if (def.type === "object" && def.shape) {
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
for (const key of Object.keys(shape)) {
patchRecordSchemas(shape[key]);
}
}
if (def.type === "array" && def.element) {
patchRecordSchemas(def.element);
}
if (def.type === "union" && def.options) {
def.options.forEach(patchRecordSchemas);
}
if (def.type === "record") {
if (def.keyType) patchRecordSchemas(def.keyType);
if (def.valueType) patchRecordSchemas(def.valueType);
}
if (def.type === "intersection") {
if (def.left) patchRecordSchemas(def.left);
if (def.right) patchRecordSchemas(def.right);
}
if (def.type === "lazy") {
if (def.getter && typeof def.getter === "function") {
const originalGetter = def.getter;
def.getter = function() {
const innerSchema = originalGetter();
if (innerSchema) {
patchRecordSchemas(innerSchema);
}
return innerSchema;
};
}
}
if (def.innerType) {
patchRecordSchemas(def.innerType);
}
return schema;
}
function fixAnyOfNullable(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {
const nullSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type === "null");
const otherSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type !== "null");
if (nullSchema && otherSchema && typeof otherSchema === "object" && otherSchema.type) {
const { anyOf, ...rest } = result;
const fixedRest = fixAnyOfNullable(rest);
const fixedOther = fixAnyOfNullable(otherSchema);
return {
...fixedRest,
...fixedOther,
type: Array.isArray(fixedOther.type) ? [...fixedOther.type, "null"] : [fixedOther.type, "null"]
};
}
}
if (result.properties && typeof result.properties === "object" && !Array.isArray(result.properties)) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => {
const propSchema = value;
if (typeof propSchema === "object" && propSchema !== null && !Array.isArray(propSchema) && Object.keys(propSchema).length === 0) {
return [key, { type: ["string", "number", "boolean", "null"] }];
}
return [key, fixAnyOfNullable(propSchema)];
})
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => fixAnyOfNullable(item));
} else {
result.items = fixAnyOfNullable(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => fixAnyOfNullable(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => fixAnyOfNullable(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => fixAnyOfNullable(s));
}
return result;
}
function ensureAllPropertiesRequired(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" && result.properties) {
result.required = Object.keys(result.properties);
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value)])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAllPropertiesRequired(item));
} else if (typeof result.items === "object") {
result.items = ensureAllPropertiesRequired(result.items);
}
}
if (result.additionalProperties && typeof result.additionalProperties === "object") {
result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties);
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAllPropertiesRequired(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAllPropertiesRequired(s));
}
return result;
}
function prepareJsonSchemaForOpenAIStrictMode(schema) {
const withRequired = ensureAllPropertiesRequired(schema);
return ensureAdditionalPropertiesFalse(withRequired);
}
function ensureAdditionalPropertiesFalse(schema) {
if (typeof schema !== "object" || schema === null) {
return schema;
}
const result = { ...schema };
if (result.type === "object" || result.properties) {
result.additionalProperties = false;
}
if (result.properties) {
result.properties = Object.fromEntries(
Object.entries(result.properties).map(([key, value]) => [
key,
ensureAdditionalPropertiesFalse(value)
])
);
}
if (result.items) {
if (Array.isArray(result.items)) {
result.items = result.items.map((item) => ensureAdditionalPropertiesFalse(item));
} else if (typeof result.items === "object") {
result.items = ensureAdditionalPropertiesFalse(result.items);
}
}
if (result.anyOf && Array.isArray(result.anyOf)) {
result.anyOf = result.anyOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.oneOf && Array.isArray(result.oneOf)) {
result.oneOf = result.oneOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
if (result.allOf && Array.isArray(result.allOf)) {
result.allOf = result.allOf.map((s) => ensureAdditionalPropertiesFalse(s));
}
return result;
}
function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
if (zodSchema?._zod) {
patchRecordSchemas(zodSchema);
const jsonSchema = v4.z.toJSONSchema(zodSchema, {
unrepresentable: "any",
io: "input",
override: (ctx) => {
const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;
if (def && (def.typeName === "ZodDate" || def.type === "date")) {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
if (def && (def.typeName === "ZodObject" || def.type === "object")) {
ctx.jsonSchema.additionalProperties = false;
}
}
});
return fixAnyOfNullable(jsonSchema);
} else {
return zodToJsonSchemaOriginal__default.default(zodSchema, {
$refStrategy: strategy,
target
});
}
}
exports.ensureAllPropertiesRequired = ensureAllPropertiesRequired;
exports.prepareJsonSchemaForOpenAIStrictMode = prepareJsonSchemaForOpenAIStrictMode;
exports.zodToJsonSchema = zodToJsonSchema;
//# sourceMappingURL=chunk-LQOEEQF6.cjs.map
//# sourceMappingURL=chunk-LQOEEQF6.cjs.map
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["zV4","zodToJsonSchemaOriginal"],"mappings":";;;;;;;;;;AAOA,IAAM,OAAA,0BAAiB,oBAAoB,CAAA;AAO3C,SAAS,mBAAmB,MAAA,EAAkB;AAC5C,EAAA,IAAI,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,UAAU,OAAO,MAAA;AAGlD,EAAA,IAAK,MAAA,CAAe,OAAO,CAAA,EAAG,OAAO,MAAA;AACrC,EAAC,MAAA,CAAe,OAAO,CAAA,GAAI,IAAA;AAG3B,EAAA,MAAM,GAAA,GAAM,OAAO,IAAA,EAAM,GAAA;AAGzB,EAAA,IAAI,KAA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M,UAAA,GAAaA,IAAA,CAAI,YAAA,CAAa,SAAA,EAAW;AAAA,MAC7C,eAAA,EAAiB,KAAA;AAAA,MACjB,EAAA,EAAI,OAAA;AAAA,MACJ,QAAA,EAAU,CAAC,GAAA,KAAa;AAEtB,QAAA,MAAM,MAAM,GAAA,CAAI,SAAA,EAAW,IAAA,IAAQ,GAAA,CAAI,WAAW,IAAA,EAAM,GAAA;AAExD,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,SAAA,IAAa,GAAA,CAAI,SAAS,MAAA,CAAA,EAAS;AAC9D,UAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,UAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAGA,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,WAAA,IAAe,GAAA,CAAI,SAAS,QAAA,CAAA,EAAW;AAClE,UAAA,GAAA,CAAI,WAAW,oBAAA,GAAuB,KAAA;AAAA,QACxC;AAAA,MACF;AAAA,KACD,CAAA;AAGD,IAAA,OAAO,iBAAiB,UAAU,CAAA;AAAA,EACpC,CAAA,MAAO;AAEL,IAAA,OAAOC,yCAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-LQOEEQF6.cjs","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 */\nfunction 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 * 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 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 return ensureAdditionalPropertiesFalse(withRequired);\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 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,\n }) as JSONSchema7;\n }\n}\n"]}
import { toStandardSchema as toStandardSchema$1 } from './chunk-23HDOZLF.js';
import { toStandardSchema as toStandardSchema$2 } from './chunk-RMMKMUYK.js';
import { toStandardSchema } from './chunk-QFEMCRFS.js';
import z3 from 'zod/v3';
import { toJSONSchema } from 'zod/v4';
var SUPPORTED_TARGETS = /* @__PURE__ */ new Set(["draft-07", "draft-04", "draft-2020-12"]);
var ZOD_V4_TARGET_MAP = {
"draft-07": "draft-7",
"draft-04": "draft-4"
};
function convertToJsonSchema(zodSchema, options, adapterOptions) {
const target = SUPPORTED_TARGETS.has(options.target) ? options.target : "draft-07";
const jsonSchemaOptions = {
target: ZOD_V4_TARGET_MAP[target] ?? target
};
if (adapterOptions.unrepresentable) {
jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;
}
if (adapterOptions.override) {
jsonSchemaOptions.override = adapterOptions.override;
}
return toJSONSchema(zodSchema, jsonSchemaOptions);
}
function toStandardSchema4(zodSchema, adapterOptions = {}) {
const wrapper = Object.create(zodSchema);
const existingStandard = zodSchema["~standard"];
const jsonSchemaConverter = {
input: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
},
output: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
}
};
Object.defineProperty(wrapper, "~standard", {
value: {
...existingStandard,
jsonSchema: jsonSchemaConverter
},
writable: false,
enumerable: true,
configurable: false
});
return wrapper;
}
// src/standard-schema/standard-schema.ts
function jsonSchemaOverride(ctx) {
const zodSchema = ctx.zodSchema;
if (ctx.jsonSchema.type === "object" && ctx.jsonSchema.properties !== void 0 && !ctx.jsonSchema.additionalProperties) {
ctx.jsonSchema.additionalProperties = false;
}
if (zodSchema) {
const isDateType = zodSchema?.type === "date" || zodSchema?._def?.typeName === "ZodDate";
if (isDateType) {
if (zodSchema?.type === "date") {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
ctx.jsonSchema["x-date"] = !zodSchema._zod?.def?.coerce;
} else if (zodSchema?.type === "object" && zodSchema._zod?.def?.catchall?.type === "unknown") {
ctx.jsonSchema.additionalProperties = true;
}
}
return void 0;
}
var JSON_SCHEMA_LIBRARY_OPTIONS = {
unrepresentable: "any",
override: jsonSchemaOverride
};
function isVercelSchema(schema) {
return typeof schema === "object" && schema !== null && "_type" in schema && "jsonSchema" in schema && typeof schema.jsonSchema === "object";
}
function isZodV4(schema) {
return typeof schema === "object" && schema !== null && "_zod" in schema;
}
function isZodV3(schema) {
if (schema === null || typeof schema !== "object") {
return false;
}
if (isZodV4(schema)) {
return false;
}
if ("~standard" in schema) {
const std = schema["~standard"];
if (typeof std === "object" && std !== null && std.vendor === "zod" && !("jsonSchema" in std)) {
return true;
}
}
return schema instanceof z3.ZodType;
}
function toStandardSchema5(schema) {
if (isStandardSchemaWithJSON(schema)) {
return schema;
}
if (isZodV4(schema)) {
return toStandardSchema4(schema, {
unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,
override: JSON_SCHEMA_LIBRARY_OPTIONS.override
});
}
if (isZodV3(schema)) {
return toStandardSchema(schema);
}
if (isVercelSchema(schema)) {
return toStandardSchema$1(schema);
}
if (schema === null || typeof schema !== "object" && typeof schema !== "function") {
throw new Error(`Unsupported schema type: ${typeof schema}`);
}
if (typeof schema === "function") {
throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);
}
return toStandardSchema$2(schema);
}
function isStandardSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
return typeof std === "object" && std !== null && "version" in std && std.version === 1 && "vendor" in std && "validate" in std && typeof std.validate === "function";
}
function isStandardJSONSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
if (typeof std !== "object" || std === null) {
return false;
}
if (!("version" in std) || std.version !== 1 || !("vendor" in std)) {
return false;
}
if (!("jsonSchema" in std) || typeof std.jsonSchema !== "object") {
return false;
}
return typeof std.jsonSchema.input === "function" && typeof std.jsonSchema.output === "function";
}
function isStandardSchemaWithJSON(value) {
return isStandardSchema(value) && isStandardJSONSchema(value);
}
function standardSchemaToJSONSchema(schema, options = {}) {
const { target = "draft-07", io = "output", override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;
const jsonSchemaFn = schema["~standard"].jsonSchema[io];
let jsonSchema = jsonSchemaFn({
target,
libraryOptions: {
...JSON_SCHEMA_LIBRARY_OPTIONS,
override
}
});
jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
return jsonSchema;
}
export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema5 as toStandardSchema };
//# sourceMappingURL=chunk-UZUKSPJ6.js.map
//# sourceMappingURL=chunk-UZUKSPJ6.js.map
{"version":3,"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"names":["toStandardSchema"],"mappings":";;;;;;AAQA,IAAM,oCAAoB,IAAI,GAAA,CAAI,CAAC,UAAA,EAAY,UAAA,EAAY,eAAe,CAAC,CAAA;AAO3E,IAAM,iBAAA,GAA4C;AAAA,EAChD,UAAA,EAAY,SAAA;AAAA,EACZ,UAAA,EAAY;AACd,CAAA;AAiBA,SAAS,mBAAA,CACP,SAAA,EACA,OAAA,EACA,cAAA,EACyB;AACzB,EAAA,MAAM,SAAS,iBAAA,CAAkB,GAAA,CAAI,QAAQ,MAAM,CAAA,GAAI,QAAQ,MAAA,GAAS,UAAA;AAExE,EAAA,MAAM,iBAAA,GAA6C;AAAA,IACjD,MAAA,EAAQ,iBAAA,CAAkB,MAAM,CAAA,IAAK;AAAA,GACvC;AAEA,EAAA,IAAI,eAAe,eAAA,EAAiB;AAClC,IAAA,iBAAA,CAAkB,kBAAkB,cAAA,CAAe,eAAA;AAAA,EACrD;AAGA,EAAA,IAAI,eAAe,QAAA,EAAU;AAC3B,IAAA,iBAAA,CAAkB,WAAW,cAAA,CAAe,QAAA;AAAA,EAC9C;AAEA,EAAA,OAAO,YAAA,CAAa,WAAiD,iBAAiB,CAAA;AACxF;AAcO,SAASA,iBAAAA,CACd,SAAA,EACA,cAAA,GAAsC,EAAC,EACX;AAE5B,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA;AAGvC,EAAA,MAAM,gBAAA,GAAoB,UAAkB,WAAW,CAAA;AAGvD,EAAA,MAAM,mBAAA,GAAsD;AAAA,IAC1D,KAAA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Aa;AAAA,IAC5B,MAAA;AAAA,IACA,cAAA,EAAgB;AAAA,MACd,GAAG,2BAAA;AAAA,MACH;AAAA;AACF,GACD,CAAA;AAGD,EAAA,UAAA,GAAa,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAA;AAElD,EAAA,OAAO,UAAA;AACT","file":"chunk-UZUKSPJ6.js","sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport { toJSONSchema } from 'zod/v4';\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 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 { 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 // 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"]}
'use strict';
var chunkFS3P4V5M_cjs = require('./chunk-FS3P4V5M.cjs');
var chunk77T2HV4Q_cjs = require('./chunk-77T2HV4Q.cjs');
var chunkBQ3VTMIR_cjs = require('./chunk-BQ3VTMIR.cjs');
var z3 = require('zod/v3');
var v4 = require('zod/v4');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var z3__default = /*#__PURE__*/_interopDefault(z3);
var SUPPORTED_TARGETS = /* @__PURE__ */ new Set(["draft-07", "draft-04", "draft-2020-12"]);
var ZOD_V4_TARGET_MAP = {
"draft-07": "draft-7",
"draft-04": "draft-4"
};
function convertToJsonSchema(zodSchema, options, adapterOptions) {
const target = SUPPORTED_TARGETS.has(options.target) ? options.target : "draft-07";
const jsonSchemaOptions = {
target: ZOD_V4_TARGET_MAP[target] ?? target
};
if (adapterOptions.unrepresentable) {
jsonSchemaOptions.unrepresentable = adapterOptions.unrepresentable;
}
if (adapterOptions.override) {
jsonSchemaOptions.override = adapterOptions.override;
}
return v4.toJSONSchema(zodSchema, jsonSchemaOptions);
}
function toStandardSchema4(zodSchema, adapterOptions = {}) {
const wrapper = Object.create(zodSchema);
const existingStandard = zodSchema["~standard"];
const jsonSchemaConverter = {
input: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
},
output: (options) => {
return convertToJsonSchema(zodSchema, options, adapterOptions);
}
};
Object.defineProperty(wrapper, "~standard", {
value: {
...existingStandard,
jsonSchema: jsonSchemaConverter
},
writable: false,
enumerable: true,
configurable: false
});
return wrapper;
}
// src/standard-schema/standard-schema.ts
function jsonSchemaOverride(ctx) {
const zodSchema = ctx.zodSchema;
if (ctx.jsonSchema.type === "object" && ctx.jsonSchema.properties !== void 0 && !ctx.jsonSchema.additionalProperties) {
ctx.jsonSchema.additionalProperties = false;
}
if (zodSchema) {
const isDateType = zodSchema?.type === "date" || zodSchema?._def?.typeName === "ZodDate";
if (isDateType) {
if (zodSchema?.type === "date") {
ctx.jsonSchema.type = "string";
ctx.jsonSchema.format = "date-time";
}
ctx.jsonSchema["x-date"] = !zodSchema._zod?.def?.coerce;
} else if (zodSchema?.type === "object" && zodSchema._zod?.def?.catchall?.type === "unknown") {
ctx.jsonSchema.additionalProperties = true;
}
}
return void 0;
}
var JSON_SCHEMA_LIBRARY_OPTIONS = {
unrepresentable: "any",
override: jsonSchemaOverride
};
function isVercelSchema(schema) {
return typeof schema === "object" && schema !== null && "_type" in schema && "jsonSchema" in schema && typeof schema.jsonSchema === "object";
}
function isZodV4(schema) {
return typeof schema === "object" && schema !== null && "_zod" in schema;
}
function isZodV3(schema) {
if (schema === null || typeof schema !== "object") {
return false;
}
if (isZodV4(schema)) {
return false;
}
if ("~standard" in schema) {
const std = schema["~standard"];
if (typeof std === "object" && std !== null && std.vendor === "zod" && !("jsonSchema" in std)) {
return true;
}
}
return schema instanceof z3__default.default.ZodType;
}
function toStandardSchema5(schema) {
if (isStandardSchemaWithJSON(schema)) {
return schema;
}
if (isZodV4(schema)) {
return toStandardSchema4(schema, {
unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,
override: JSON_SCHEMA_LIBRARY_OPTIONS.override
});
}
if (isZodV3(schema)) {
return chunkBQ3VTMIR_cjs.toStandardSchema(schema);
}
if (isVercelSchema(schema)) {
return chunkFS3P4V5M_cjs.toStandardSchema(schema);
}
if (schema === null || typeof schema !== "object" && typeof schema !== "function") {
throw new Error(`Unsupported schema type: ${typeof schema}`);
}
if (typeof schema === "function") {
throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);
}
return chunk77T2HV4Q_cjs.toStandardSchema(schema);
}
function isStandardSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
return typeof std === "object" && std !== null && "version" in std && std.version === 1 && "vendor" in std && "validate" in std && typeof std.validate === "function";
}
function isStandardJSONSchema(value) {
if (value === null || typeof value !== "object" && typeof value !== "function") {
return false;
}
if (!("~standard" in value)) {
return false;
}
const std = value["~standard"];
if (typeof std !== "object" || std === null) {
return false;
}
if (!("version" in std) || std.version !== 1 || !("vendor" in std)) {
return false;
}
if (!("jsonSchema" in std) || typeof std.jsonSchema !== "object") {
return false;
}
return typeof std.jsonSchema.input === "function" && typeof std.jsonSchema.output === "function";
}
function isStandardSchemaWithJSON(value) {
return isStandardSchema(value) && isStandardJSONSchema(value);
}
function standardSchemaToJSONSchema(schema, options = {}) {
const { target = "draft-07", io = "output", override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;
const jsonSchemaFn = schema["~standard"].jsonSchema[io];
let jsonSchema = jsonSchemaFn({
target,
libraryOptions: {
...JSON_SCHEMA_LIBRARY_OPTIONS,
override
}
});
jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
return jsonSchema;
}
exports.JSON_SCHEMA_LIBRARY_OPTIONS = JSON_SCHEMA_LIBRARY_OPTIONS;
exports.isStandardJSONSchema = isStandardJSONSchema;
exports.isStandardSchema = isStandardSchema;
exports.isStandardSchemaWithJSON = isStandardSchemaWithJSON;
exports.standardSchemaToJSONSchema = standardSchemaToJSONSchema;
exports.toStandardSchema = toStandardSchema5;
//# sourceMappingURL=chunk-XVGNFEQ2.cjs.map
//# sourceMappingURL=chunk-XVGNFEQ2.cjs.map
{"version":3,"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"names":["toJSONSchema","toStandardSchema","z3"],"mappings":";;;;;;;;;;;;AAQA,IAAM,oCAAoB,IAAI,GAAA,CAAI,CAAC,UAAA,EAAY,UAAA,EAAY,eAAe,CAAC,CAAA;AAO3E,IAAM,iBAAA,GAA4C;AAAA,EAChD,UAAA,EAAY,SAAA;AAAA,EACZ,UAAA,EAAY;AACd,CAAA;AAiBA,SAAS,mBAAA,CACP,SAAA,EACA,OAAA,EACA,cAAA,EACyB;AACzB,EAAA,MAAM,SAAS,iBAAA,CAAkB,GAAA,CAAI,QAAQ,MAAM,CAAA,GAAI,QAAQ,MAAA,GAAS,UAAA;AAExE,EAAA,MAAM,iBAAA,GAA6C;AAAA,IACjD,MAAA,EAAQ,iBAAA,CAAkB,MAAM,CAAA,IAAK;AAAA,GACvC;AAEA,EAAA,IAAI,eAAe,eAAA,EAAiB;AAClC,IAAA,iBAAA,CAAkB,kBAAkB,cAAA,CAAe,eAAA;AAAA,EACrD;AAGA,EAAA,IAAI,eAAe,QAAA,EAAU;AAC3B,IAAA,iBAAA,CAAkB,WAAW,cAAA,CAAe,QAAA;AAAA,EAC9C;AAEA,EAAA,OAAOA,eAAA,CAAa,WAAiD,i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,CACd,MAAA,EACA,OAAA,GAII,EAAC,EACQ;AACb,EAAA,MAAM,EAAE,SAAS,UAAA,EAAY,EAAA,GAAK,UAAU,QAAA,GAAW,2BAAA,CAA4B,UAAS,GAAI,OAAA;AAChG,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,WAAW,CAAA,CAAE,WAAW,EAAE,CAAA;AACtD,EAAA,IAAI,aAAa,YAAA,CAAa;AAAA,IAC5B,MAAA;AAAA,IACA,cAAA,EAAgB;AAAA,MACd,GAAG,2BAAA;AAAA,MACH;AAAA;AACF,GACD,CAAA;AAGD,EAAA,UAAA,GAAa,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAA;AAElD,EAAA,OAAO,UAAA;AACT","file":"chunk-XVGNFEQ2.cjs","sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport { toJSONSchema } from 'zod/v4';\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 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 { 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 // 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"]}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display