@mastra/schema-compat 0.0.0-fix-local-pkg-cwd-20251226155239 → 0.0.0-jail-fs-20260105160110
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 +53 -1
- package/dist/{chunk-3UNBRBSM.js → chunk-3RG3ZAXL.js} +3 -3
- package/dist/chunk-3RG3ZAXL.js.map +1 -0
- package/dist/{chunk-E3FJXGJD.cjs → chunk-MMU7PH2H.cjs} +3 -3
- package/dist/chunk-MMU7PH2H.cjs.map +1 -0
- package/dist/index.cjs +23 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod-to-json.cjs +2 -2
- package/dist/zod-to-json.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-3UNBRBSM.js.map +0 -1
- package/dist/chunk-E3FJXGJD.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-jail-fs-20260105160110
|
|
4
4
|
|
|
5
5
|
### Major Changes
|
|
6
6
|
|
|
@@ -18,8 +18,30 @@
|
|
|
18
18
|
|
|
19
19
|
- Embed AI types to fix peerdeps mismatches ([`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808))
|
|
20
20
|
|
|
21
|
+
- Fixed "Transforms cannot be represented in JSON Schema" error when using Zod v4 with structuredOutput ([#11466](https://github.com/mastra-ai/mastra/pull/11466))
|
|
22
|
+
|
|
23
|
+
When using schemas with `.optional()`, `.nullable()`, `.default()`, or `.nullish().default("")` patterns with `structuredOutput` and Zod v4, users would encounter an error because OpenAI schema compatibility layer adds transforms that Zod v4's native `toJSONSchema()` cannot handle.
|
|
24
|
+
|
|
25
|
+
The fix uses Mastra's transform-safe `zodToJsonSchema` function which gracefully handles transforms by using the `unrepresentable: 'any'` option.
|
|
26
|
+
|
|
27
|
+
Also exported `isZodType` utility from `@mastra/schema-compat` and updated it to detect both Zod v3 (`_def`) and Zod v4 (`_zod`) schemas.
|
|
28
|
+
|
|
21
29
|
- Improved reliability of string field types in tool schema compatibility ([#9266](https://github.com/mastra-ai/mastra/pull/9266))
|
|
22
30
|
|
|
31
|
+
- Fix OpenAI structured output compatibility for fields with `.default()` values ([#11434](https://github.com/mastra-ai/mastra/pull/11434))
|
|
32
|
+
|
|
33
|
+
When using Zod schemas with `.default()` fields (e.g., `z.number().default(1)`), OpenAI's structured output API was failing with errors like `Missing '<field>' in required`. This happened because `zod-to-json-schema` doesn't include fields with defaults in the `required` array, but OpenAI requires all properties to be required.
|
|
34
|
+
|
|
35
|
+
This fix converts `.default()` fields to `.nullable()` with a transform that returns the default value when `null` is received, ensuring compatibility with OpenAI's strict mode while preserving the original default value semantics.
|
|
36
|
+
|
|
37
|
+
- fix(schema-compat): handle undefined values in optional fields for OpenAI compat layers ([#11469](https://github.com/mastra-ai/mastra/pull/11469))
|
|
38
|
+
|
|
39
|
+
When a Zod schema has nested objects with `.partial()`, the optional fields would fail validation with "expected string, received undefined" errors. This occurred because the OpenAI schema compat layer converted `.optional()` to `.nullable()`, which only accepts `null` values, not `undefined`.
|
|
40
|
+
|
|
41
|
+
Changed `.nullable()` to `.nullish()` so that optional fields now accept both `null` (when explicitly provided by the LLM) and `undefined` (when fields are omitted entirely).
|
|
42
|
+
|
|
43
|
+
Fixes #11457
|
|
44
|
+
|
|
23
45
|
- Fix discriminatedUnion schema information lost when json schema is converted to zod ([#10500](https://github.com/mastra-ai/mastra/pull/10500))
|
|
24
46
|
|
|
25
47
|
- Fixed OpenAI schema compatibility when using `agent.generate()` or `agent.stream()` with `structuredOutput`. ([#10366](https://github.com/mastra-ai/mastra/pull/10366))
|
|
@@ -54,6 +76,36 @@
|
|
|
54
76
|
// Result: { name: 'John', age: undefined, deletedAt: null }
|
|
55
77
|
```
|
|
56
78
|
|
|
79
|
+
## 1.0.0-beta.5
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Fixed "Transforms cannot be represented in JSON Schema" error when using Zod v4 with structuredOutput ([#11466](https://github.com/mastra-ai/mastra/pull/11466))
|
|
84
|
+
|
|
85
|
+
When using schemas with `.optional()`, `.nullable()`, `.default()`, or `.nullish().default("")` patterns with `structuredOutput` and Zod v4, users would encounter an error because OpenAI schema compatibility layer adds transforms that Zod v4's native `toJSONSchema()` cannot handle.
|
|
86
|
+
|
|
87
|
+
The fix uses Mastra's transform-safe `zodToJsonSchema` function which gracefully handles transforms by using the `unrepresentable: 'any'` option.
|
|
88
|
+
|
|
89
|
+
Also exported `isZodType` utility from `@mastra/schema-compat` and updated it to detect both Zod v3 (`_def`) and Zod v4 (`_zod`) schemas.
|
|
90
|
+
|
|
91
|
+
- fix(schema-compat): handle undefined values in optional fields for OpenAI compat layers ([#11469](https://github.com/mastra-ai/mastra/pull/11469))
|
|
92
|
+
|
|
93
|
+
When a Zod schema has nested objects with `.partial()`, the optional fields would fail validation with "expected string, received undefined" errors. This occurred because the OpenAI schema compat layer converted `.optional()` to `.nullable()`, which only accepts `null` values, not `undefined`.
|
|
94
|
+
|
|
95
|
+
Changed `.nullable()` to `.nullish()` so that optional fields now accept both `null` (when explicitly provided by the LLM) and `undefined` (when fields are omitted entirely).
|
|
96
|
+
|
|
97
|
+
Fixes #11457
|
|
98
|
+
|
|
99
|
+
## 1.0.0-beta.4
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- Fix OpenAI structured output compatibility for fields with `.default()` values ([#11434](https://github.com/mastra-ai/mastra/pull/11434))
|
|
104
|
+
|
|
105
|
+
When using Zod schemas with `.default()` fields (e.g., `z.number().default(1)`), OpenAI's structured output API was failing with errors like `Missing '<field>' in required`. This happened because `zod-to-json-schema` doesn't include fields with defaults in the `required` array, but OpenAI requires all properties to be required.
|
|
106
|
+
|
|
107
|
+
This fix converts `.default()` fields to `.nullable()` with a transform that returns the default value when `null` is received, ensuring compatibility with OpenAI's strict mode while preserving the original default value semantics.
|
|
108
|
+
|
|
57
109
|
## 1.0.0-beta.3
|
|
58
110
|
|
|
59
111
|
### Patch Changes
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import zodToJsonSchemaOriginal from 'zod-to-json-schema';
|
|
3
3
|
|
|
4
4
|
// src/zod-to-json.ts
|
|
5
|
-
var PATCHED = Symbol("__mastra_patched__");
|
|
5
|
+
var PATCHED = /* @__PURE__ */ Symbol("__mastra_patched__");
|
|
6
6
|
function patchRecordSchemas(schema) {
|
|
7
7
|
if (!schema || typeof schema !== "object") return schema;
|
|
8
8
|
if (schema[PATCHED]) return schema;
|
|
@@ -73,5 +73,5 @@ function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
export { zodToJsonSchema };
|
|
76
|
-
//# sourceMappingURL=chunk-
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
76
|
+
//# sourceMappingURL=chunk-3RG3ZAXL.js.map
|
|
77
|
+
//# sourceMappingURL=chunk-3RG3ZAXL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/zod-to-json.ts"],"names":[],"mappings":";;;;AAQA,IAAM,OAAA,0BAAiB,oBAAoB,CAAA;AAO3C,SAAS,mBAAmB,MAAA,EAAkB;AAC5C,EAAA,IAAI,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,UAAU,OAAO,MAAA;AAGlD,EAAA,IAAK,MAAA,CAAe,OAAO,CAAA,EAAG,OAAO,MAAA;AACrC,EAAC,MAAA,CAAe,OAAO,CAAA,GAAI,IAAA;AAG3B,EAAA,MAAM,GAAA,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AW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH,CAAA,MAAO;AAEL,IAAA,OAAO,wBAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-3RG3ZAXL.js","sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport { z } from 'zod';\nimport type { ZodSchema as ZodSchemaV3 } from 'zod/v3';\nimport type { ZodType as ZodSchemaV4 } from 'zod/v4';\nimport type { Targets } from 'zod-to-json-schema';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\n\n// Symbol to mark schemas as already patched (for idempotency)\nconst PATCHED = Symbol('__mastra_patched__');\n\n/**\n * Recursively patch Zod v4 record schemas that are missing valueType.\n * This fixes a bug in Zod v4 where z.record(valueSchema) doesn't set def.valueType.\n * The single-arg form should set valueType but instead only sets keyType.\n */\nfunction patchRecordSchemas(schema: any): any {\n if (!schema || typeof schema !== 'object') return schema;\n\n // Skip if already patched (idempotency check)\n if ((schema as any)[PATCHED]) return schema;\n (schema as any)[PATCHED] = true;\n\n // Check the _zod.def location (v4 structure)\n const def = schema._zod?.def;\n\n // Fix record schemas with missing valueType\n if (def?.type === 'record' && def.keyType && !def.valueType) {\n // The bug: z.record(valueSchema) puts the value in keyType instead of valueType\n // Fix: move it to valueType and set keyType to string (the default)\n def.valueType = def.keyType;\n def.keyType = (z as any).string();\n }\n\n // Recursively patch nested schemas\n if (!def) return schema;\n\n if (def.type === 'object' && def.shape) {\n const shape = typeof def.shape === 'function' ? def.shape() : def.shape;\n for (const key of Object.keys(shape)) {\n patchRecordSchemas(shape[key]);\n }\n }\n\n if (def.type === 'array' && def.element) {\n patchRecordSchemas(def.element);\n }\n\n if (def.type === 'union' && def.options) {\n def.options.forEach(patchRecordSchemas);\n }\n\n if (def.type === 'record') {\n if (def.keyType) patchRecordSchemas(def.keyType);\n if (def.valueType) patchRecordSchemas(def.valueType);\n }\n\n // Handle intersection types\n if (def.type === 'intersection') {\n if (def.left) patchRecordSchemas(def.left);\n if (def.right) patchRecordSchemas(def.right);\n }\n\n // Handle lazy types - patch the schema returned by the getter\n if (def.type === 'lazy') {\n // For lazy schemas, we need to patch the schema when it's accessed\n // Store the original getter and wrap it\n if (def.getter && typeof def.getter === 'function') {\n const originalGetter = def.getter;\n def.getter = function () {\n const innerSchema = originalGetter();\n if (innerSchema) {\n patchRecordSchemas(innerSchema);\n }\n return innerSchema;\n };\n }\n }\n\n // Handle wrapper types that have innerType\n // This covers: optional, nullable, default, catch, nullish, and any other wrappers\n if (def.innerType) {\n patchRecordSchemas(def.innerType);\n }\n\n return schema;\n}\n\nexport function zodToJsonSchema(\n zodSchema: ZodSchemaV3 | ZodSchemaV4,\n target: Targets = 'jsonSchema7',\n strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative',\n): JSONSchema7 {\n const fn = 'toJSONSchema';\n\n if (fn in z) {\n // Zod v4 path - patch record schemas before converting\n patchRecordSchemas(zodSchema);\n\n return (z as any)[fn](zodSchema, {\n unrepresentable: 'any',\n override: (ctx: any) => {\n // Handle both Zod v4 structures: _def directly or nested in _zod\n const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;\n // Check for date type using both possible property names\n if (def && (def.typeName === 'ZodDate' || def.type === 'date')) {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n },\n }) satisfies JSONSchema7;\n } else {\n // Zod v3 path - use the original converter\n return zodToJsonSchemaOriginal(zodSchema as ZodSchemaV3, {\n $refStrategy: strategy,\n target,\n }) as JSONSchema7;\n }\n}\n"]}
|
|
@@ -8,7 +8,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
8
8
|
var zodToJsonSchemaOriginal__default = /*#__PURE__*/_interopDefault(zodToJsonSchemaOriginal);
|
|
9
9
|
|
|
10
10
|
// src/zod-to-json.ts
|
|
11
|
-
var PATCHED = Symbol("__mastra_patched__");
|
|
11
|
+
var PATCHED = /* @__PURE__ */ Symbol("__mastra_patched__");
|
|
12
12
|
function patchRecordSchemas(schema) {
|
|
13
13
|
if (!schema || typeof schema !== "object") return schema;
|
|
14
14
|
if (schema[PATCHED]) return schema;
|
|
@@ -79,5 +79,5 @@ function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
exports.zodToJsonSchema = zodToJsonSchema;
|
|
82
|
-
//# sourceMappingURL=chunk-
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
82
|
+
//# sourceMappingURL=chunk-MMU7PH2H.cjs.map
|
|
83
|
+
//# sourceMappingURL=chunk-MMU7PH2H.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["z","zodToJsonSchemaOriginal"],"mappings":";;;;;;;;;;AAQA,IAAM,OAAA,0BAAiB,oBAAoB,CAAA;AAO3C,SAAS,mBAAmB,MAAA,EAAkB;AAC5C,EAAA,IAAI,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,UAAU,OAAO,MAAA;AAGlD,EAAA,IAAK,MAAA,CAAe,OAAO,CAAA,EAAG,OAAO,MAAA;AACrC,EAAC,MAAA,CAAe,OAAO,CAAA,GAAI,IAAA;AAG3B,EAAA,MAAM,GAAA,GAAM,OAAO,IAAA,EAAM,GAAA;AAGzB,EAAA,IAAI,KAAK,IAAA,KAAS,QAAA,IAAY,IAAI,OAAA,IAAW,CAAC,IAAI,SAAA,EAAW;AAG3D,IAAA,GAAA,CAAI,YAAY,GAAA,CAAI,OAAA;AACpB,IAAA,GAAA,CAAI,OAAA,GAAWA,MAAU,MAAA,EAAO;AAAA,EAClC;AAGA,EAAA,IAAI,CAAC,KAAK,OAAO,MAAA;AAEjB,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,QAAA,IAAY,GAAA,CAAI,KAAA,EAAO;AACtC,IAAA,M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;AACnC,QAAA,IAAI,WAAA,EAAa;AACf,UAAA,kBAAA,CAAmB,WAAW,CAAA;AAAA,QAChC;AACA,QAAA,OAAO,WAAA;AAAA,MACT,CAAA;AAAA,IACF;AAAA,EACF;AAIA,EAAA,IAAI,IAAI,SAAA,EAAW;AACjB,IAAA,kBAAA,CAAmB,IAAI,SAAS,CAAA;AAAA,EAClC;AAEA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,eAAA,CACd,SAAA,EACA,MAAA,GAAkB,aAAA,EAClB,WAAkD,UAAA,EACrC;AACb,EAAA,MAAM,EAAA,GAAK,cAAA;AAEX,EAAA,IAAI,MAAMA,KAAA,EAAG;AAEX,IAAA,kBAAA,CAAmB,SAAS,CAAA;AAE5B,IAAA,OAAQA,KAAA,CAAU,EAAE,CAAA,CAAE,SAAA,EAAW;AAAA,MAC/B,eAAA,EAAiB,KAAA;AAAA,MACjB,QAAA,EAAU,CAAC,GAAA,KAAa;AAEtB,QAAA,MAAM,MAAM,GAAA,CAAI,SAAA,EAAW,IAAA,IAAQ,GAAA,CAAI,WAAW,IAAA,EAAM,GAAA;AAExD,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,SAAA,IAAa,GAAA,CAAI,SAAS,MAAA,CAAA,EAAS;AAC9D,UAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,UAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH,CAAA,MAAO;AAEL,IAAA,OAAOC,yCAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-MMU7PH2H.cjs","sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport { z } from 'zod';\nimport type { ZodSchema as ZodSchemaV3 } from 'zod/v3';\nimport type { ZodType as ZodSchemaV4 } from 'zod/v4';\nimport type { Targets } from 'zod-to-json-schema';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\n\n// Symbol to mark schemas as already patched (for idempotency)\nconst PATCHED = Symbol('__mastra_patched__');\n\n/**\n * Recursively patch Zod v4 record schemas that are missing valueType.\n * This fixes a bug in Zod v4 where z.record(valueSchema) doesn't set def.valueType.\n * The single-arg form should set valueType but instead only sets keyType.\n */\nfunction patchRecordSchemas(schema: any): any {\n if (!schema || typeof schema !== 'object') return schema;\n\n // Skip if already patched (idempotency check)\n if ((schema as any)[PATCHED]) return schema;\n (schema as any)[PATCHED] = true;\n\n // Check the _zod.def location (v4 structure)\n const def = schema._zod?.def;\n\n // Fix record schemas with missing valueType\n if (def?.type === 'record' && def.keyType && !def.valueType) {\n // The bug: z.record(valueSchema) puts the value in keyType instead of valueType\n // Fix: move it to valueType and set keyType to string (the default)\n def.valueType = def.keyType;\n def.keyType = (z as any).string();\n }\n\n // Recursively patch nested schemas\n if (!def) return schema;\n\n if (def.type === 'object' && def.shape) {\n const shape = typeof def.shape === 'function' ? def.shape() : def.shape;\n for (const key of Object.keys(shape)) {\n patchRecordSchemas(shape[key]);\n }\n }\n\n if (def.type === 'array' && def.element) {\n patchRecordSchemas(def.element);\n }\n\n if (def.type === 'union' && def.options) {\n def.options.forEach(patchRecordSchemas);\n }\n\n if (def.type === 'record') {\n if (def.keyType) patchRecordSchemas(def.keyType);\n if (def.valueType) patchRecordSchemas(def.valueType);\n }\n\n // Handle intersection types\n if (def.type === 'intersection') {\n if (def.left) patchRecordSchemas(def.left);\n if (def.right) patchRecordSchemas(def.right);\n }\n\n // Handle lazy types - patch the schema returned by the getter\n if (def.type === 'lazy') {\n // For lazy schemas, we need to patch the schema when it's accessed\n // Store the original getter and wrap it\n if (def.getter && typeof def.getter === 'function') {\n const originalGetter = def.getter;\n def.getter = function () {\n const innerSchema = originalGetter();\n if (innerSchema) {\n patchRecordSchemas(innerSchema);\n }\n return innerSchema;\n };\n }\n }\n\n // Handle wrapper types that have innerType\n // This covers: optional, nullable, default, catch, nullish, and any other wrappers\n if (def.innerType) {\n patchRecordSchemas(def.innerType);\n }\n\n return schema;\n}\n\nexport function zodToJsonSchema(\n zodSchema: ZodSchemaV3 | ZodSchemaV4,\n target: Targets = 'jsonSchema7',\n strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative',\n): JSONSchema7 {\n const fn = 'toJSONSchema';\n\n if (fn in z) {\n // Zod v4 path - patch record schemas before converting\n patchRecordSchemas(zodSchema);\n\n return (z as any)[fn](zodSchema, {\n unrepresentable: 'any',\n override: (ctx: any) => {\n // Handle both Zod v4 structures: _def directly or nested in _zod\n const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;\n // Check for date type using both possible property names\n if (def && (def.typeName === 'ZodDate' || def.type === 'date')) {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n },\n }) satisfies JSONSchema7;\n } else {\n // Zod v3 path - use the original converter\n return zodToJsonSchemaOriginal(zodSchema as ZodSchemaV3, {\n $refStrategy: strategy,\n target,\n }) as JSONSchema7;\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMMU7PH2H_cjs = require('./chunk-MMU7PH2H.cjs');
|
|
4
4
|
var zod = require('zod');
|
|
5
5
|
var zodFromJsonSchema = require('zod-from-json-schema');
|
|
6
6
|
var zodFromJsonSchemaV3 = require('zod-from-json-schema-v3');
|
|
7
7
|
var v4 = require('zod/v4');
|
|
8
8
|
|
|
9
|
-
// ../_vendored/ai_v4/dist/chunk-
|
|
9
|
+
// ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
|
|
10
10
|
var __create = Object.create;
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -315,7 +315,7 @@ var createIdGenerator = ({
|
|
|
315
315
|
return (size) => `${prefix}${separator}${generator(size)}`;
|
|
316
316
|
};
|
|
317
317
|
createIdGenerator();
|
|
318
|
-
var validatorSymbol = Symbol.for("vercel.ai.validator");
|
|
318
|
+
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
319
319
|
function validator(validate) {
|
|
320
320
|
return { [validatorSymbol]: true, validate };
|
|
321
321
|
}
|
|
@@ -373,7 +373,7 @@ function safeParseJSON({
|
|
|
373
373
|
};
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
376
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
377
377
|
var defaultOptions = {
|
|
378
378
|
name: void 0,
|
|
379
379
|
$refStrategy: "root",
|
|
@@ -2181,7 +2181,7 @@ function zodSchema(zodSchema2, options) {
|
|
|
2181
2181
|
}
|
|
2182
2182
|
);
|
|
2183
2183
|
}
|
|
2184
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
2184
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2185
2185
|
function jsonSchema(jsonSchema2, {
|
|
2186
2186
|
validate
|
|
2187
2187
|
} = {}) {
|
|
@@ -2268,7 +2268,7 @@ function _makeCompatibilityCheck(ownVersion) {
|
|
|
2268
2268
|
}
|
|
2269
2269
|
var isCompatible = _makeCompatibilityCheck(VERSION);
|
|
2270
2270
|
var major = VERSION.split(".")[0];
|
|
2271
|
-
var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
|
|
2271
|
+
var GLOBAL_OPENTELEMETRY_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major);
|
|
2272
2272
|
var _global = _globalThis;
|
|
2273
2273
|
function registerGlobal(type, instance, diag, allowOverride) {
|
|
2274
2274
|
var _a17;
|
|
@@ -3568,7 +3568,7 @@ function trimStartOfStream() {
|
|
|
3568
3568
|
|
|
3569
3569
|
// src/utils.ts
|
|
3570
3570
|
function convertZodSchemaToAISDKSchema(zodSchema2, target = "jsonSchema7") {
|
|
3571
|
-
const jsonSchemaToUse =
|
|
3571
|
+
const jsonSchemaToUse = chunkMMU7PH2H_cjs.zodToJsonSchema(zodSchema2, target);
|
|
3572
3572
|
return jsonSchema(jsonSchemaToUse, {
|
|
3573
3573
|
validate: (value) => {
|
|
3574
3574
|
const result = zodSchema2.safeParse(value);
|
|
@@ -3577,7 +3577,7 @@ function convertZodSchemaToAISDKSchema(zodSchema2, target = "jsonSchema7") {
|
|
|
3577
3577
|
});
|
|
3578
3578
|
}
|
|
3579
3579
|
function isZodType(value) {
|
|
3580
|
-
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
3580
|
+
return typeof value === "object" && value !== null && ("_def" in value || "_zod" in value) && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
3581
3581
|
}
|
|
3582
3582
|
function convertSchemaToZod(schema) {
|
|
3583
3583
|
if (isZodType(schema)) {
|
|
@@ -3615,7 +3615,7 @@ function applyCompatLayer({
|
|
|
3615
3615
|
}
|
|
3616
3616
|
}
|
|
3617
3617
|
if (mode === "jsonSchema") {
|
|
3618
|
-
return
|
|
3618
|
+
return chunkMMU7PH2H_cjs.zodToJsonSchema(zodSchema2, "jsonSchema7");
|
|
3619
3619
|
} else {
|
|
3620
3620
|
return convertZodSchemaToAISDKSchema(zodSchema2);
|
|
3621
3621
|
}
|
|
@@ -4874,6 +4874,19 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
4874
4874
|
return processedInner.nullable();
|
|
4875
4875
|
}
|
|
4876
4876
|
return value;
|
|
4877
|
+
} else if (isDefault(zod.z)(value)) {
|
|
4878
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
4879
|
+
const defaultValue = "_def" in value ? value._def.defaultValue : value._zod?.def?.defaultValue;
|
|
4880
|
+
if (innerType) {
|
|
4881
|
+
const processedInner = this.processZodType(innerType);
|
|
4882
|
+
return processedInner.nullable().transform((val) => {
|
|
4883
|
+
if (val === null) {
|
|
4884
|
+
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
4885
|
+
}
|
|
4886
|
+
return val;
|
|
4887
|
+
});
|
|
4888
|
+
}
|
|
4889
|
+
return value;
|
|
4877
4890
|
} else if (isObj2(zod.z)(value)) {
|
|
4878
4891
|
return this.defaultZodObjectHandler(value);
|
|
4879
4892
|
} else if (isUnion2(zod.z)(value)) {
|
|
@@ -4997,6 +5010,7 @@ exports.isObj = isObj;
|
|
|
4997
5010
|
exports.isOptional = isOptional;
|
|
4998
5011
|
exports.isString = isString;
|
|
4999
5012
|
exports.isUnion = isUnion;
|
|
5013
|
+
exports.isZodType = isZodType;
|
|
5000
5014
|
exports.jsonSchema = jsonSchema;
|
|
5001
5015
|
//# sourceMappingURL=index.cjs.map
|
|
5002
5016
|
//# sourceMappingURL=index.cjs.map
|