@mastra/schema-compat 1.2.6-alpha.0 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/{chunk-IKQO7EW7.js → chunk-N4QSZBUR.js} +4 -2
- package/dist/chunk-N4QSZBUR.js.map +1 -0
- package/dist/{chunk-M46NFEVC.js → chunk-OA5IWMRF.js} +3 -3
- package/dist/{chunk-M46NFEVC.js.map → chunk-OA5IWMRF.js.map} +1 -1
- package/dist/{chunk-XQ27VZMH.cjs → chunk-UOL7NZ5L.cjs} +5 -5
- package/dist/{chunk-XQ27VZMH.cjs.map → chunk-UOL7NZ5L.cjs.map} +1 -1
- package/dist/{chunk-FKB2Z36H.cjs → chunk-YIDCYW4I.cjs} +4 -2
- package/dist/chunk-YIDCYW4I.cjs.map +1 -0
- package/dist/index.cjs +22 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/schema.cjs +7 -7
- package/dist/schema.js +1 -1
- package/dist/standard-schema/adapters/zod-v3.cjs +2 -2
- package/dist/standard-schema/adapters/zod-v3.d.ts.map +1 -1
- package/dist/standard-schema/adapters/zod-v3.js +1 -1
- package/package.json +6 -6
- package/dist/chunk-FKB2Z36H.cjs.map +0 -1
- package/dist/chunk-IKQO7EW7.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
+
## 1.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix(schema-compat): map Mastra draft target names to Zod v4 format ([#14401](https://github.com/mastra-ai/mastra/pull/14401))
|
|
8
|
+
|
|
9
|
+
Zod v4's `z.toJSONSchema()` expects `"draft-7"` / `"draft-4"` while
|
|
10
|
+
Mastra uses `"draft-07"` / `"draft-04"`. The mismatch caused repeated
|
|
11
|
+
`Invalid target: draft-07` console warnings and suppressed the `$schema`
|
|
12
|
+
field in generated JSON Schemas.
|
|
13
|
+
|
|
14
|
+
Adds `ZOD_V4_TARGET_MAP` in the zod-v4 adapter to translate target names
|
|
15
|
+
before calling `z.toJSONSchema()`. `"draft-2020-12"` is unchanged as both
|
|
16
|
+
sides already agree on that name.
|
|
17
|
+
|
|
18
|
+
Fixes `#14399`
|
|
19
|
+
|
|
20
|
+
- Add support for `draft-2020-12` and `draft-04` JSON Schema targets in the Zod v3 adapter, and fix the `toJSONSchema` target mapping to properly translate all `zod-to-json-schema` target names (like `openApi3`) to standard-schema target names. Fixes "Unsupported JSON Schema target" errors when serializing tool schemas. ([#14471](https://github.com/mastra-ai/mastra/pull/14471))
|
|
21
|
+
|
|
22
|
+
## 1.2.6-alpha.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Add support for `draft-2020-12` and `draft-04` JSON Schema targets in the Zod v3 adapter, and fix the `toJSONSchema` target mapping to properly translate all `zod-to-json-schema` target names (like `openApi3`) to standard-schema target names. Fixes "Unsupported JSON Schema target" errors when serializing tool schemas. ([#14471](https://github.com/mastra-ai/mastra/pull/14471))
|
|
27
|
+
|
|
3
28
|
## 1.2.6-alpha.0
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -5,7 +5,9 @@ import zodToJsonSchemaOriginal from 'zod-to-json-schema';
|
|
|
5
5
|
// src/standard-schema/adapters/zod-v3.ts
|
|
6
6
|
var import_json_schema_traverse = __toESM(require_json_schema_traverse(), 1);
|
|
7
7
|
var TARGET_MAP = {
|
|
8
|
+
"draft-04": "jsonSchema7",
|
|
8
9
|
"draft-07": "jsonSchema7",
|
|
10
|
+
"draft-2020-12": "jsonSchema2019-09",
|
|
9
11
|
"openapi-3.0": "openApi3"
|
|
10
12
|
};
|
|
11
13
|
function convertToJsonSchema(zodSchema, options) {
|
|
@@ -58,5 +60,5 @@ function toStandardSchema(zodSchema) {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export { toStandardSchema };
|
|
61
|
-
//# sourceMappingURL=chunk-
|
|
62
|
-
//# sourceMappingURL=chunk-
|
|
63
|
+
//# sourceMappingURL=chunk-N4QSZBUR.js.map
|
|
64
|
+
//# sourceMappingURL=chunk-N4QSZBUR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/standard-schema/adapters/zod-v3.ts"],"names":["traverse"],"mappings":";;;;;AACA,IAAA,2BAAA,GAAqB,OAAA,CAAA,4BAAA,EAAA,EAAA,CAAA,CAAA;AAYrB,IAAM,UAAA,GAAoD;AAAA,EACxD,UAAA,EAAY,aAAA;AAAA,EACZ,UAAA,EAAY,aAAA;AAAA,EACZ,eAAA,EAAiB,mBAAA;AAAA,EACjB,aAAA,EAAe;AACjB,CAAA;AAYA,SAAS,mBAAA,CACP,WACA,OAAA,EACyB;AACzB,EAAA,MAAM,MAAA,GAAS,UAAA,CAAW,OAAA,CAAQ,MAAM,CAAA;AAExC,EAAA,IAAI,CAAC,MAAA,EAAQ;AAEX,IAAA,MAAM,gBAAA,GAAmB,MAAA,CAAO,IAAA,CAAK,UAAU,CAAA;AAC/C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,oCAAoC,OAAA,CAAQ,MAAM,6BAAkC,gBAAA,CAAiB,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KACjH;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAAa,wBAAwB,SAAA,EAAW;AAAA,IACpD,YAAA,EAAc,MAAA;AAAA,IACd;AAAA,GACD,CAAA;AAED,EAAA,IAAA,2BAAA,CAAAA,SAAS,UAAA,EAAY;AAAA,IACnB,EAAA,EAAI;AAAA,MACF,KAAK,CAAA,MAAA,KAAU;AACb,QAAA,IAAI,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,MAAA,CAAO,WAAW,OAAA,EAAS;AACzD,UAAA,MAAA,CAAO,OAAA,GAAU,CAAA,uGAAA,CAAA;AAAA,QACnB;AAAA,MACF;AAAA;AAAA;AAAA;AAAA;AAIF,GACD,CAAA;AAED,EAAA,OAAO,UAAA;AACT;AA8BO,SAAS,iBAAoB,SAAA,EAAwE;AAE1G,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA;AAGvC,EAAA,MAAM,gBAAA,GAAmB,UAAU,WAAW,CAAA;AAG9C,EAAA,MAAM,mBAAA,GAAsD;AAAA,IAC1D,KAAA,EAAO,CAAC,OAAA,KAAmE;AACzE,MAAA,OAAO,mBAAA,CAAoB,WAAW,OAAO,CAAA;AAAA,IAC/C,CAAA;AAAA,IACA,MAAA,EAAQ,CAAC,OAAA,KAAmE;AAG1E,MAAA,OAAO,mBAAA,CAAoB,WAAW,OAAO,CAAA;AAAA,IAC/C;AAAA,GACF;AAGA,EAAA,MAAA,CAAO,cAAA,CAAe,SAAS,WAAA,EAAa;AAAA,IAC1C,KAAA,EAAO;AAAA,MACL,GAAG,gBAAA;AAAA,MACH,UAAA,EAAY;AAAA,KACd;AAAA,IACA,QAAA,EAAU,KAAA;AAAA,IACV,UAAA,EAAY,IAAA;AAAA,IACZ,YAAA,EAAc;AAAA,GACf,CAAA;AAED,EAAA,OAAO,OAAA;AACT","file":"chunk-N4QSZBUR.js","sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport traverse from 'json-schema-traverse';\n// Use zod/v3 types for v3 compatibility (v4's v3-compat layer)\nimport type { ZodType, ZodTypeDef } from 'zod/v3';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\nimport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n ZodToJsonSchemaTarget,\n} from '../standard-schema.types';\n/**\n * Target mapping from Standard Schema targets to zod-to-json-schema targets.\n */\nconst TARGET_MAP: Record<string, ZodToJsonSchemaTarget> = {\n 'draft-04': 'jsonSchema7',\n 'draft-07': 'jsonSchema7',\n 'draft-2020-12': 'jsonSchema2019-09',\n 'openapi-3.0': 'openApi3',\n};\n\n/**\n * Converts a Zod schema to JSON Schema using the specified target format.\n *\n * @param zodSchema - The Zod schema to convert\n * @param options - Standard Schema JSON options including the target format\n * @returns The JSON Schema representation\n * @throws Error if the target format is not supported\n *\n * @internal\n */\nfunction convertToJsonSchema<T extends ZodType<any, ZodTypeDef, any>>(\n zodSchema: T,\n options: StandardJSONSchemaV1.Options,\n): Record<string, unknown> {\n const target = TARGET_MAP[options.target];\n\n if (!target) {\n // For unknown targets, try to use jsonSchema7 as fallback or throw\n const supportedTargets = Object.keys(TARGET_MAP);\n throw new Error(\n `Unsupported JSON Schema target: \"${options.target}\". ` + `Supported targets are: ${supportedTargets.join(', ')}`,\n );\n }\n\n const jsonSchema = zodToJsonSchemaOriginal(zodSchema, {\n $refStrategy: 'none',\n target,\n });\n\n traverse(jsonSchema, {\n cb: {\n pre: schema => {\n if (schema.type === 'string' && schema.format === 'email') {\n schema.pattern = `^(?!\\\\.)(?!.*\\\\.\\\\.)([A-Za-z0-9_'+\\\\-\\\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\\\-]*\\\\.)+[A-Za-z]{2,}$`;\n }\n },\n // post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n // this.postProcessJSONNode(schema, parentSchema);\n // },\n },\n });\n\n return jsonSchema as Record<string, unknown>;\n}\n\n/**\n * Wraps a Zod v3 schema to implement the full @standard-schema/spec interface.\n *\n * While Zod v3 natively implements `StandardSchemaV1` (validation), it does not\n * implement `StandardJSONSchemaV1` (JSON Schema conversion). This adapter adds\n * the `jsonSchema` property to provide JSON Schema conversion capabilities.\n *\n * @typeParam T - The Zod schema type\n *\n * @example\n * ```typescript\n * import { z } from 'zod';\n * import { toStandardSchema } from '@mastra/schema-compat/adapters/zod-v3';\n *\n * const userSchema = z.object({\n * name: z.string(),\n * age: z.number().min(0),\n * });\n *\n * const standardSchema = toStandardSchema(userSchema);\n *\n * // Use validation (from StandardSchemaV1)\n * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });\n *\n * // Get JSON Schema (from StandardJSONSchemaV1)\n * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n * ```\n */\nexport function toStandardSchema<T>(zodSchema: ZodType<T, ZodTypeDef, T>): T & StandardSchemaWithJSON<T, T> {\n // Create a wrapper object that includes the jsonSchema converter\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON<T, T>;\n\n // Get the existing ~standard property from Zod\n const existingStandard = zodSchema['~standard'] as StandardSchemaV1.Props<T, T>;\n\n // Create the JSON Schema converter\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options);\n },\n output: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n // For Zod schemas, input and output JSON Schema are typically the same\n // unless using transforms, which would need special handling\n return convertToJsonSchema(zodSchema, options);\n },\n };\n\n // Define the enhanced ~standard property\n Object.defineProperty(wrapper, '~standard', {\n value: {\n ...existingStandard,\n jsonSchema: jsonSchemaConverter,\n } satisfies StandardSchemaWithJSONProps<T, T>,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toStandardSchema as toStandardSchema$1 } from './chunk-23HDOZLF.js';
|
|
2
2
|
import { toStandardSchema as toStandardSchema$2 } from './chunk-QDRBTCDV.js';
|
|
3
|
-
import { toStandardSchema } from './chunk-
|
|
3
|
+
import { toStandardSchema } from './chunk-N4QSZBUR.js';
|
|
4
4
|
import z3 from 'zod/v3';
|
|
5
5
|
import { createRequire } from 'module';
|
|
6
6
|
|
|
@@ -202,5 +202,5 @@ function standardSchemaToJSONSchema(schema, options = {}) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema5 as toStandardSchema };
|
|
205
|
-
//# sourceMappingURL=chunk-
|
|
206
|
-
//# sourceMappingURL=chunk-
|
|
205
|
+
//# sourceMappingURL=chunk-OA5IWMRF.js.map
|
|
206
|
+
//# sourceMappingURL=chunk-OA5IWMRF.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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,eAAe,eAAA,EAAgB;AACrC,EAAA,IAAI,CAAC,YAAA,EAAc;AACjB,IAAA,MAAM,IAAI,MAAM,qEAAqE,CAAA;AAAA,EACvF;AAEA,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,WAAW,iBAAiB,CAAA;AAClD;AAKA,IAAI,aAAA,GAA0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AA,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-M46NFEVC.js","sourcesContent":["import { createRequire } from 'node:module';\nimport type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\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 toJSONSchema = getToJSONSchema();\n if (!toJSONSchema) {\n throw new Error('z.toJSONSchema is not available. Ensure zod >= 3.25.0 is installed.');\n }\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, jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Cached reference to z.toJSONSchema.\n */\nlet _toJSONSchema: ((schema: unknown, options?: unknown) => unknown) | null = null;\nlet _toJSONSchemaResolved = false;\n\nlet __require: ReturnType<typeof createRequire>;\n\nfunction getRequire(): ReturnType<typeof createRequire> {\n if (!__require) {\n __require = createRequire(import.meta.url);\n }\n return __require;\n}\nfunction pickToJSONSchema(mod: unknown): ((schema: unknown, options?: unknown) => unknown) | null {\n const candidate = mod as {\n toJSONSchema?: unknown;\n z?: { toJSONSchema?: unknown };\n default?: { toJSONSchema?: unknown; z?: { toJSONSchema?: unknown } };\n };\n\n const picks = [\n candidate?.toJSONSchema,\n candidate?.z?.toJSONSchema,\n candidate?.default?.toJSONSchema,\n candidate?.default?.z?.toJSONSchema,\n ];\n\n const toJSONSchema = picks.find(fn => typeof fn === 'function');\n return (toJSONSchema as ((schema: unknown, options?: unknown) => unknown) | undefined) ?? null;\n}\n\nfunction resolveToJSONSchema(\n loadModule: (moduleName: 'zod/v4' | 'zod') => unknown,\n): ((schema: unknown, options?: unknown) => unknown) | null {\n for (const moduleName of ['zod/v4', 'zod'] as const) {\n try {\n const zodModule = loadModule(moduleName);\n const toJSONSchema = pickToJSONSchema(zodModule);\n if (toJSONSchema) {\n return toJSONSchema;\n }\n } catch {\n // Try next module path.\n }\n }\n\n return null;\n}\n\nfunction getToJSONSchema(): ((schema: unknown, options?: unknown) => unknown) | null {\n if (_toJSONSchemaResolved) {\n return _toJSONSchema;\n }\n\n _toJSONSchema = resolveToJSONSchema(moduleName => getRequire()(moduleName));\n _toJSONSchemaResolved = true;\n return _toJSONSchema;\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 { type?: string; _zod?: { def?: { type?: string } }; optional?: () => unknown };\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 // Convert z.date() to JSON Schema string with date-time format\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\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"]}
|
|
1
|
+
{"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,eAAe,eAAA,EAAgB;AACrC,EAAA,IAAI,CAAC,YAAA,EAAc;AACjB,IAAA,MAAM,IAAI,MAAM,qEAAqE,CAAA;AAAA,EACvF;AAEA,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,O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AA,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-OA5IWMRF.js","sourcesContent":["import { createRequire } from 'node:module';\nimport type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\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 toJSONSchema = getToJSONSchema();\n if (!toJSONSchema) {\n throw new Error('z.toJSONSchema is not available. Ensure zod >= 3.25.0 is installed.');\n }\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, jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Cached reference to z.toJSONSchema.\n */\nlet _toJSONSchema: ((schema: unknown, options?: unknown) => unknown) | null = null;\nlet _toJSONSchemaResolved = false;\n\nlet __require: ReturnType<typeof createRequire>;\n\nfunction getRequire(): ReturnType<typeof createRequire> {\n if (!__require) {\n __require = createRequire(import.meta.url);\n }\n return __require;\n}\nfunction pickToJSONSchema(mod: unknown): ((schema: unknown, options?: unknown) => unknown) | null {\n const candidate = mod as {\n toJSONSchema?: unknown;\n z?: { toJSONSchema?: unknown };\n default?: { toJSONSchema?: unknown; z?: { toJSONSchema?: unknown } };\n };\n\n const picks = [\n candidate?.toJSONSchema,\n candidate?.z?.toJSONSchema,\n candidate?.default?.toJSONSchema,\n candidate?.default?.z?.toJSONSchema,\n ];\n\n const toJSONSchema = picks.find(fn => typeof fn === 'function');\n return (toJSONSchema as ((schema: unknown, options?: unknown) => unknown) | undefined) ?? null;\n}\n\nfunction resolveToJSONSchema(\n loadModule: (moduleName: 'zod/v4' | 'zod') => unknown,\n): ((schema: unknown, options?: unknown) => unknown) | null {\n for (const moduleName of ['zod/v4', 'zod'] as const) {\n try {\n const zodModule = loadModule(moduleName);\n const toJSONSchema = pickToJSONSchema(zodModule);\n if (toJSONSchema) {\n return toJSONSchema;\n }\n } catch {\n // Try next module path.\n }\n }\n\n return null;\n}\n\nfunction getToJSONSchema(): ((schema: unknown, options?: unknown) => unknown) | null {\n if (_toJSONSchemaResolved) {\n return _toJSONSchema;\n }\n\n _toJSONSchema = resolveToJSONSchema(moduleName => getRequire()(moduleName));\n _toJSONSchemaResolved = true;\n return _toJSONSchema;\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 { type?: string; _zod?: { def?: { type?: string } }; optional?: () => unknown };\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 // Convert z.date() to JSON Schema string with date-time format\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkFS3P4V5M_cjs = require('./chunk-FS3P4V5M.cjs');
|
|
4
4
|
var chunkROFMEFEF_cjs = require('./chunk-ROFMEFEF.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkYIDCYW4I_cjs = require('./chunk-YIDCYW4I.cjs');
|
|
6
6
|
var z3 = require('zod/v3');
|
|
7
7
|
var module$1 = require('module');
|
|
8
8
|
|
|
@@ -38,7 +38,7 @@ var _toJSONSchemaResolved = false;
|
|
|
38
38
|
var __require;
|
|
39
39
|
function getRequire() {
|
|
40
40
|
if (!__require) {
|
|
41
|
-
__require = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
41
|
+
__require = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-UOL7NZ5L.cjs', document.baseURI).href)));
|
|
42
42
|
}
|
|
43
43
|
return __require;
|
|
44
44
|
}
|
|
@@ -149,7 +149,7 @@ function toStandardSchema5(schema) {
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
if (isZodV3(schema)) {
|
|
152
|
-
return
|
|
152
|
+
return chunkYIDCYW4I_cjs.toStandardSchema(schema);
|
|
153
153
|
}
|
|
154
154
|
if (isVercelSchema(schema)) {
|
|
155
155
|
return chunkFS3P4V5M_cjs.toStandardSchema(schema);
|
|
@@ -214,5 +214,5 @@ exports.isStandardSchema = isStandardSchema;
|
|
|
214
214
|
exports.isStandardSchemaWithJSON = isStandardSchemaWithJSON;
|
|
215
215
|
exports.standardSchemaToJSONSchema = standardSchemaToJSONSchema;
|
|
216
216
|
exports.toStandardSchema = toStandardSchema5;
|
|
217
|
-
//# sourceMappingURL=chunk-
|
|
218
|
-
//# sourceMappingURL=chunk-
|
|
217
|
+
//# sourceMappingURL=chunk-UOL7NZ5L.cjs.map
|
|
218
|
+
//# sourceMappingURL=chunk-UOL7NZ5L.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"names":["createRequire","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,eAAe,eAAA,EAAgB;AACrC,EAAA,IAAI,CAAC,YAAA,EAAc;AACjB,IAAA,MAAM,IAAI,MAAM,qEAAqE,CAAA;AAAA,EACvF;AAEA,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,C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IAAK,oBAAA,CAAqB,KAAK,CAAA;AAC9D;AA4BO,SAAS,0BAAA,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-XQ27VZMH.cjs","sourcesContent":["import { createRequire } from 'node:module';\nimport type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\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 toJSONSchema = getToJSONSchema();\n if (!toJSONSchema) {\n throw new Error('z.toJSONSchema is not available. Ensure zod >= 3.25.0 is installed.');\n }\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, jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Cached reference to z.toJSONSchema.\n */\nlet _toJSONSchema: ((schema: unknown, options?: unknown) => unknown) | null = null;\nlet _toJSONSchemaResolved = false;\n\nlet __require: ReturnType<typeof createRequire>;\n\nfunction getRequire(): ReturnType<typeof createRequire> {\n if (!__require) {\n __require = createRequire(import.meta.url);\n }\n return __require;\n}\nfunction pickToJSONSchema(mod: unknown): ((schema: unknown, options?: unknown) => unknown) | null {\n const candidate = mod as {\n toJSONSchema?: unknown;\n z?: { toJSONSchema?: unknown };\n default?: { toJSONSchema?: unknown; z?: { toJSONSchema?: unknown } };\n };\n\n const picks = [\n candidate?.toJSONSchema,\n candidate?.z?.toJSONSchema,\n candidate?.default?.toJSONSchema,\n candidate?.default?.z?.toJSONSchema,\n ];\n\n const toJSONSchema = picks.find(fn => typeof fn === 'function');\n return (toJSONSchema as ((schema: unknown, options?: unknown) => unknown) | undefined) ?? null;\n}\n\nfunction resolveToJSONSchema(\n loadModule: (moduleName: 'zod/v4' | 'zod') => unknown,\n): ((schema: unknown, options?: unknown) => unknown) | null {\n for (const moduleName of ['zod/v4', 'zod'] as const) {\n try {\n const zodModule = loadModule(moduleName);\n const toJSONSchema = pickToJSONSchema(zodModule);\n if (toJSONSchema) {\n return toJSONSchema;\n }\n } catch {\n // Try next module path.\n }\n }\n\n return null;\n}\n\nfunction getToJSONSchema(): ((schema: unknown, options?: unknown) => unknown) | null {\n if (_toJSONSchemaResolved) {\n return _toJSONSchema;\n }\n\n _toJSONSchema = resolveToJSONSchema(moduleName => getRequire()(moduleName));\n _toJSONSchemaResolved = true;\n return _toJSONSchema;\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 { type?: string; _zod?: { def?: { type?: string } }; optional?: () => unknown };\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 // Convert z.date() to JSON Schema string with date-time format\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/standard-schema/adapters/zod-v4.ts","../src/standard-schema/standard-schema.ts"],"names":["createRequire","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,eAAe,eAAA,EAAgB;AACrC,EAAA,IAAI,CAAC,YAAA,EAAc;AACjB,IAAA,MAAM,IAAI,MAAM,qEAAqE,CAAA;AAAA,EACvF;AAEA,EAAA,MAAM,SAAS,iBAAA,CAAkB,GAAA,CAAI,QAAQ,MAAM,CAAA,GAAI,QAA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A;AACxF;AAmBO,SAAS,yBAAyB,KAAA,EAAiD;AACxF,EAAA,OAAO,gBAAA,CAAiB,KAAK,CAAA,IAAK,oBAAA,CAAqB,KAAK,CAAA;AAC9D;AA4BO,SAAS,0BAAA,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-UOL7NZ5L.cjs","sourcesContent":["import { createRequire } from 'node:module';\nimport type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\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 toJSONSchema = getToJSONSchema();\n if (!toJSONSchema) {\n throw new Error('z.toJSONSchema is not available. Ensure zod >= 3.25.0 is installed.');\n }\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, jsonSchemaOptions) as Record<string, unknown>;\n}\n\n/**\n * Cached reference to z.toJSONSchema.\n */\nlet _toJSONSchema: ((schema: unknown, options?: unknown) => unknown) | null = null;\nlet _toJSONSchemaResolved = false;\n\nlet __require: ReturnType<typeof createRequire>;\n\nfunction getRequire(): ReturnType<typeof createRequire> {\n if (!__require) {\n __require = createRequire(import.meta.url);\n }\n return __require;\n}\nfunction pickToJSONSchema(mod: unknown): ((schema: unknown, options?: unknown) => unknown) | null {\n const candidate = mod as {\n toJSONSchema?: unknown;\n z?: { toJSONSchema?: unknown };\n default?: { toJSONSchema?: unknown; z?: { toJSONSchema?: unknown } };\n };\n\n const picks = [\n candidate?.toJSONSchema,\n candidate?.z?.toJSONSchema,\n candidate?.default?.toJSONSchema,\n candidate?.default?.z?.toJSONSchema,\n ];\n\n const toJSONSchema = picks.find(fn => typeof fn === 'function');\n return (toJSONSchema as ((schema: unknown, options?: unknown) => unknown) | undefined) ?? null;\n}\n\nfunction resolveToJSONSchema(\n loadModule: (moduleName: 'zod/v4' | 'zod') => unknown,\n): ((schema: unknown, options?: unknown) => unknown) | null {\n for (const moduleName of ['zod/v4', 'zod'] as const) {\n try {\n const zodModule = loadModule(moduleName);\n const toJSONSchema = pickToJSONSchema(zodModule);\n if (toJSONSchema) {\n return toJSONSchema;\n }\n } catch {\n // Try next module path.\n }\n }\n\n return null;\n}\n\nfunction getToJSONSchema(): ((schema: unknown, options?: unknown) => unknown) | null {\n if (_toJSONSchemaResolved) {\n return _toJSONSchema;\n }\n\n _toJSONSchema = resolveToJSONSchema(moduleName => getRequire()(moduleName));\n _toJSONSchemaResolved = true;\n return _toJSONSchema;\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 { type?: string; _zod?: { def?: { type?: string } }; optional?: () => unknown };\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 // Convert z.date() to JSON Schema string with date-time format\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\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"]}
|
|
@@ -11,7 +11,9 @@ var zodToJsonSchemaOriginal__default = /*#__PURE__*/_interopDefault(zodToJsonSch
|
|
|
11
11
|
// src/standard-schema/adapters/zod-v3.ts
|
|
12
12
|
var import_json_schema_traverse = chunkDZUJEN5N_cjs.__toESM(chunk3MLZICLP_cjs.require_json_schema_traverse(), 1);
|
|
13
13
|
var TARGET_MAP = {
|
|
14
|
+
"draft-04": "jsonSchema7",
|
|
14
15
|
"draft-07": "jsonSchema7",
|
|
16
|
+
"draft-2020-12": "jsonSchema2019-09",
|
|
15
17
|
"openapi-3.0": "openApi3"
|
|
16
18
|
};
|
|
17
19
|
function convertToJsonSchema(zodSchema, options) {
|
|
@@ -64,5 +66,5 @@ function toStandardSchema(zodSchema) {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
exports.toStandardSchema = toStandardSchema;
|
|
67
|
-
//# sourceMappingURL=chunk-
|
|
68
|
-
//# sourceMappingURL=chunk-
|
|
69
|
+
//# sourceMappingURL=chunk-YIDCYW4I.cjs.map
|
|
70
|
+
//# sourceMappingURL=chunk-YIDCYW4I.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/standard-schema/adapters/zod-v3.ts"],"names":["__toESM","require_json_schema_traverse","zodToJsonSchemaOriginal","traverse"],"mappings":";;;;;;;;;;;AACA,IAAA,2BAAA,GAAqBA,yBAAA,CAAAC,8CAAA,EAAA,EAAA,CAAA,CAAA;AAYrB,IAAM,UAAA,GAAoD;AAAA,EACxD,UAAA,EAAY,aAAA;AAAA,EACZ,UAAA,EAAY,aAAA;AAAA,EACZ,eAAA,EAAiB,mBAAA;AAAA,EACjB,aAAA,EAAe;AACjB,CAAA;AAYA,SAAS,mBAAA,CACP,WACA,OAAA,EACyB;AACzB,EAAA,MAAM,MAAA,GAAS,UAAA,CAAW,OAAA,CAAQ,MAAM,CAAA;AAExC,EAAA,IAAI,CAAC,MAAA,EAAQ;AAEX,IAAA,MAAM,gBAAA,GAAmB,MAAA,CAAO,IAAA,CAAK,UAAU,CAAA;AAC/C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,oCAAoC,OAAA,CAAQ,MAAM,6BAAkC,gBAAA,CAAiB,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KACjH;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAAaC,yCAAwB,SAAA,EAAW;AAAA,IACpD,YAAA,EAAc,MAAA;AAAA,IACd;AAAA,GACD,CAAA;AAED,EAAA,IAAA,2BAAA,CAAAC,SAAS,UAAA,EAAY;AAAA,IACnB,EAAA,EAAI;AAAA,MACF,KAAK,CAAA,MAAA,KAAU;AACb,QAAA,IAAI,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,MAAA,CAAO,WAAW,OAAA,EAAS;AACzD,UAAA,MAAA,CAAO,OAAA,GAAU,CAAA,uGAAA,CAAA;AAAA,QACnB;AAAA,MACF;AAAA;AAAA;AAAA;AAAA;AAIF,GACD,CAAA;AAED,EAAA,OAAO,UAAA;AACT;AA8BO,SAAS,iBAAoB,SAAA,EAAwE;AAE1G,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA;AAGvC,EAAA,MAAM,gBAAA,GAAmB,UAAU,WAAW,CAAA;AAG9C,EAAA,MAAM,mBAAA,GAAsD;AAAA,IAC1D,KAAA,EAAO,CAAC,OAAA,KAAmE;AACzE,MAAA,OAAO,mBAAA,CAAoB,WAAW,OAAO,CAAA;AAAA,IAC/C,CAAA;AAAA,IACA,MAAA,EAAQ,CAAC,OAAA,KAAmE;AAG1E,MAAA,OAAO,mBAAA,CAAoB,WAAW,OAAO,CAAA;AAAA,IAC/C;AAAA,GACF;AAGA,EAAA,MAAA,CAAO,cAAA,CAAe,SAAS,WAAA,EAAa;AAAA,IAC1C,KAAA,EAAO;AAAA,MACL,GAAG,gBAAA;AAAA,MACH,UAAA,EAAY;AAAA,KACd;AAAA,IACA,QAAA,EAAU,KAAA;AAAA,IACV,UAAA,EAAY,IAAA;AAAA,IACZ,YAAA,EAAc;AAAA,GACf,CAAA;AAED,EAAA,OAAO,OAAA;AACT","file":"chunk-YIDCYW4I.cjs","sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport traverse from 'json-schema-traverse';\n// Use zod/v3 types for v3 compatibility (v4's v3-compat layer)\nimport type { ZodType, ZodTypeDef } from 'zod/v3';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\nimport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n ZodToJsonSchemaTarget,\n} from '../standard-schema.types';\n/**\n * Target mapping from Standard Schema targets to zod-to-json-schema targets.\n */\nconst TARGET_MAP: Record<string, ZodToJsonSchemaTarget> = {\n 'draft-04': 'jsonSchema7',\n 'draft-07': 'jsonSchema7',\n 'draft-2020-12': 'jsonSchema2019-09',\n 'openapi-3.0': 'openApi3',\n};\n\n/**\n * Converts a Zod schema to JSON Schema using the specified target format.\n *\n * @param zodSchema - The Zod schema to convert\n * @param options - Standard Schema JSON options including the target format\n * @returns The JSON Schema representation\n * @throws Error if the target format is not supported\n *\n * @internal\n */\nfunction convertToJsonSchema<T extends ZodType<any, ZodTypeDef, any>>(\n zodSchema: T,\n options: StandardJSONSchemaV1.Options,\n): Record<string, unknown> {\n const target = TARGET_MAP[options.target];\n\n if (!target) {\n // For unknown targets, try to use jsonSchema7 as fallback or throw\n const supportedTargets = Object.keys(TARGET_MAP);\n throw new Error(\n `Unsupported JSON Schema target: \"${options.target}\". ` + `Supported targets are: ${supportedTargets.join(', ')}`,\n );\n }\n\n const jsonSchema = zodToJsonSchemaOriginal(zodSchema, {\n $refStrategy: 'none',\n target,\n });\n\n traverse(jsonSchema, {\n cb: {\n pre: schema => {\n if (schema.type === 'string' && schema.format === 'email') {\n schema.pattern = `^(?!\\\\.)(?!.*\\\\.\\\\.)([A-Za-z0-9_'+\\\\-\\\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\\\-]*\\\\.)+[A-Za-z]{2,}$`;\n }\n },\n // post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n // this.postProcessJSONNode(schema, parentSchema);\n // },\n },\n });\n\n return jsonSchema as Record<string, unknown>;\n}\n\n/**\n * Wraps a Zod v3 schema to implement the full @standard-schema/spec interface.\n *\n * While Zod v3 natively implements `StandardSchemaV1` (validation), it does not\n * implement `StandardJSONSchemaV1` (JSON Schema conversion). This adapter adds\n * the `jsonSchema` property to provide JSON Schema conversion capabilities.\n *\n * @typeParam T - The Zod schema type\n *\n * @example\n * ```typescript\n * import { z } from 'zod';\n * import { toStandardSchema } from '@mastra/schema-compat/adapters/zod-v3';\n *\n * const userSchema = z.object({\n * name: z.string(),\n * age: z.number().min(0),\n * });\n *\n * const standardSchema = toStandardSchema(userSchema);\n *\n * // Use validation (from StandardSchemaV1)\n * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });\n *\n * // Get JSON Schema (from StandardJSONSchemaV1)\n * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n * ```\n */\nexport function toStandardSchema<T>(zodSchema: ZodType<T, ZodTypeDef, T>): T & StandardSchemaWithJSON<T, T> {\n // Create a wrapper object that includes the jsonSchema converter\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON<T, T>;\n\n // Get the existing ~standard property from Zod\n const existingStandard = zodSchema['~standard'] as StandardSchemaV1.Props<T, T>;\n\n // Create the JSON Schema converter\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options);\n },\n output: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n // For Zod schemas, input and output JSON Schema are typically the same\n // unless using transforms, which would need special handling\n return convertToJsonSchema(zodSchema, options);\n },\n };\n\n // Define the enhanced ~standard property\n Object.defineProperty(wrapper, '~standard', {\n value: {\n ...existingStandard,\n jsonSchema: jsonSchemaConverter,\n } satisfies StandardSchemaWithJSONProps<T, T>,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkUOL7NZ5L_cjs = require('./chunk-UOL7NZ5L.cjs');
|
|
4
4
|
var chunkUFJG5KPA_cjs = require('./chunk-UFJG5KPA.cjs');
|
|
5
5
|
var chunk3MLZICLP_cjs = require('./chunk-3MLZICLP.cjs');
|
|
6
6
|
var chunkDZUJEN5N_cjs = require('./chunk-DZUJEN5N.cjs');
|
|
@@ -3608,19 +3608,19 @@ function applyCompatLayer({
|
|
|
3608
3608
|
mode
|
|
3609
3609
|
}) {
|
|
3610
3610
|
if (mode === "jsonSchema") {
|
|
3611
|
-
const standardSchema =
|
|
3611
|
+
const standardSchema = chunkUOL7NZ5L_cjs.toStandardSchema(schema);
|
|
3612
3612
|
for (const compat of compatLayers) {
|
|
3613
3613
|
if (compat.shouldApply()) {
|
|
3614
3614
|
return compat.processToJSONSchema(standardSchema);
|
|
3615
3615
|
}
|
|
3616
3616
|
}
|
|
3617
|
-
return
|
|
3617
|
+
return chunkUOL7NZ5L_cjs.standardSchemaToJSONSchema(standardSchema);
|
|
3618
3618
|
} else {
|
|
3619
3619
|
let zodSchema2;
|
|
3620
3620
|
if (isZodType(schema)) {
|
|
3621
3621
|
zodSchema2 = schema;
|
|
3622
3622
|
} else {
|
|
3623
|
-
if (
|
|
3623
|
+
if (chunkUOL7NZ5L_cjs.isStandardSchemaWithJSON(schema)) {
|
|
3624
3624
|
throw new Error("StandardSchemaWithJSON is not supported for applyCompatLayer and aiSdkSchema mode");
|
|
3625
3625
|
}
|
|
3626
3626
|
zodSchema2 = convertSchemaToZod(schema);
|
|
@@ -4874,8 +4874,8 @@ var SchemaCompatLayer3 = class {
|
|
|
4874
4874
|
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
4875
4875
|
}
|
|
4876
4876
|
processToJSONSchema(zodSchema2, io = "input") {
|
|
4877
|
-
const standardSchema =
|
|
4878
|
-
const jsonSchema2 =
|
|
4877
|
+
const standardSchema = chunkUOL7NZ5L_cjs.toStandardSchema(zodSchema2);
|
|
4878
|
+
const jsonSchema2 = chunkUOL7NZ5L_cjs.standardSchemaToJSONSchema(standardSchema, {
|
|
4879
4879
|
target: "draft-07",
|
|
4880
4880
|
io
|
|
4881
4881
|
// Use input mode so fields with defaults are optional
|
|
@@ -5127,9 +5127,15 @@ var SchemaCompatLayer3 = class {
|
|
|
5127
5127
|
* Uses 'input' io mode so that fields with defaults are optional (appropriate for tool parameters).
|
|
5128
5128
|
*/
|
|
5129
5129
|
toJSONSchema(zodSchema2) {
|
|
5130
|
-
const
|
|
5131
|
-
|
|
5132
|
-
|
|
5130
|
+
const SCHEMA_TARGET_TO_STANDARD = {
|
|
5131
|
+
jsonSchema7: "draft-07",
|
|
5132
|
+
"jsonSchema2019-09": "draft-2020-12",
|
|
5133
|
+
openApi3: "openapi-3.0"
|
|
5134
|
+
};
|
|
5135
|
+
const schemaTarget = this.getSchemaTarget();
|
|
5136
|
+
const target = (schemaTarget && SCHEMA_TARGET_TO_STANDARD[schemaTarget]) ?? schemaTarget;
|
|
5137
|
+
const standardSchema = chunkUOL7NZ5L_cjs.toStandardSchema(zodSchema2);
|
|
5138
|
+
const jsonSchema2 = chunkUOL7NZ5L_cjs.standardSchemaToJSONSchema(standardSchema, {
|
|
5133
5139
|
target,
|
|
5134
5140
|
io: "input"
|
|
5135
5141
|
// Use input mode so fields with defaults are optional
|
|
@@ -5582,7 +5588,7 @@ function applyOpenAICompatTransforms(schema, modelInfo) {
|
|
|
5582
5588
|
return schema;
|
|
5583
5589
|
}
|
|
5584
5590
|
const processedZodSchema = compatLayer.processZodType(zodSchema2);
|
|
5585
|
-
return
|
|
5591
|
+
return chunkUOL7NZ5L_cjs.toStandardSchema(processedZodSchema);
|
|
5586
5592
|
}
|
|
5587
5593
|
function applyOpenAICompatToTools(tools, modelInfo) {
|
|
5588
5594
|
if (!tools) {
|
|
@@ -5906,27 +5912,27 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5906
5912
|
|
|
5907
5913
|
Object.defineProperty(exports, "JSON_SCHEMA_LIBRARY_OPTIONS", {
|
|
5908
5914
|
enumerable: true,
|
|
5909
|
-
get: function () { return
|
|
5915
|
+
get: function () { return chunkUOL7NZ5L_cjs.JSON_SCHEMA_LIBRARY_OPTIONS; }
|
|
5910
5916
|
});
|
|
5911
5917
|
Object.defineProperty(exports, "isStandardJSONSchema", {
|
|
5912
5918
|
enumerable: true,
|
|
5913
|
-
get: function () { return
|
|
5919
|
+
get: function () { return chunkUOL7NZ5L_cjs.isStandardJSONSchema; }
|
|
5914
5920
|
});
|
|
5915
5921
|
Object.defineProperty(exports, "isStandardSchema", {
|
|
5916
5922
|
enumerable: true,
|
|
5917
|
-
get: function () { return
|
|
5923
|
+
get: function () { return chunkUOL7NZ5L_cjs.isStandardSchema; }
|
|
5918
5924
|
});
|
|
5919
5925
|
Object.defineProperty(exports, "isStandardSchemaWithJSON", {
|
|
5920
5926
|
enumerable: true,
|
|
5921
|
-
get: function () { return
|
|
5927
|
+
get: function () { return chunkUOL7NZ5L_cjs.isStandardSchemaWithJSON; }
|
|
5922
5928
|
});
|
|
5923
5929
|
Object.defineProperty(exports, "standardSchemaToJSONSchema", {
|
|
5924
5930
|
enumerable: true,
|
|
5925
|
-
get: function () { return
|
|
5931
|
+
get: function () { return chunkUOL7NZ5L_cjs.standardSchemaToJSONSchema; }
|
|
5926
5932
|
});
|
|
5927
5933
|
Object.defineProperty(exports, "toStandardSchema", {
|
|
5928
5934
|
enumerable: true,
|
|
5929
|
-
get: function () { return
|
|
5935
|
+
get: function () { return chunkUOL7NZ5L_cjs.toStandardSchema; }
|
|
5930
5936
|
});
|
|
5931
5937
|
Object.defineProperty(exports, "ensureAllPropertiesRequired", {
|
|
5932
5938
|
enumerable: true,
|