@mastra/schema-compat 1.0.0-beta.4 → 1.0.0-beta.5
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 +20 -0
- package/dist/index.cjs +2 -1
- 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 +2 -2
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed "Transforms cannot be represented in JSON Schema" error when using Zod v4 with structuredOutput ([#11466](https://github.com/mastra-ai/mastra/pull/11466))
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
The fix uses Mastra's transform-safe `zodToJsonSchema` function which gracefully handles transforms by using the `unrepresentable: 'any'` option.
|
|
12
|
+
|
|
13
|
+
Also exported `isZodType` utility from `@mastra/schema-compat` and updated it to detect both Zod v3 (`_def`) and Zod v4 (`_zod`) schemas.
|
|
14
|
+
|
|
15
|
+
- fix(schema-compat): handle undefined values in optional fields for OpenAI compat layers ([#11469](https://github.com/mastra-ai/mastra/pull/11469))
|
|
16
|
+
|
|
17
|
+
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`.
|
|
18
|
+
|
|
19
|
+
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).
|
|
20
|
+
|
|
21
|
+
Fixes #11457
|
|
22
|
+
|
|
3
23
|
## 1.0.0-beta.4
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -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)) {
|
|
@@ -5010,6 +5010,7 @@ exports.isObj = isObj;
|
|
|
5010
5010
|
exports.isOptional = isOptional;
|
|
5011
5011
|
exports.isString = isString;
|
|
5012
5012
|
exports.isUnion = isUnion;
|
|
5013
|
+
exports.isZodType = isZodType;
|
|
5013
5014
|
exports.jsonSchema = jsonSchema;
|
|
5014
5015
|
//# sourceMappingURL=index.cjs.map
|
|
5015
5016
|
//# sourceMappingURL=index.cjs.map
|