@mastra/schema-compat 0.11.7 → 1.0.0-beta.1
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 +32 -20
- package/dist/index.cjs +3664 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3665 -57
- package/dist/index.js.map +1 -1
- package/dist/json-schema.d.ts +4 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/dist/schema-compatibility-v3.d.ts +6 -6
- package/dist/schema-compatibility-v3.d.ts.map +1 -1
- package/dist/schema-compatibility-v4.d.ts +9 -6
- package/dist/schema-compatibility-v4.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts +2 -3
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils-test-suite.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/zodTypes.d.ts +2 -0
- package/dist/zodTypes.d.ts.map +1 -1
- package/package.json +10 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,46 +1,58 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 1.0.0-beta.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Fixed OpenAI schema compatibility when using `agent.generate()` or `agent.stream()` with `structuredOutput`. ([#10366](https://github.com/mastra-ai/mastra/pull/10366))
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Changes
|
|
10
|
+
- **Automatic transformation**: Zod schemas are now automatically transformed for OpenAI strict mode compatibility when using OpenAI models (including reasoning models like o1, o3, o4)
|
|
11
|
+
- **Optional field handling**: `.optional()` fields are converted to `.nullable()` with a transform that converts `null` → `undefined`, preserving optional semantics while satisfying OpenAI's strict mode requirements
|
|
12
|
+
- **Preserves nullable fields**: Intentionally `.nullable()` fields remain unchanged
|
|
13
|
+
- **Deep transformation**: Handles `.optional()` fields at any nesting level (objects, arrays, unions, etc.)
|
|
14
|
+
- **JSON Schema objects**: Not transformed, only Zod schemas
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
## Example
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
```typescript
|
|
19
|
+
const agent = new Agent({
|
|
20
|
+
name: 'data-extractor',
|
|
21
|
+
model: { provider: 'openai', modelId: 'gpt-4o' },
|
|
22
|
+
instructions: 'Extract user information',
|
|
23
|
+
});
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
const schema = z.object({
|
|
26
|
+
name: z.string(),
|
|
27
|
+
age: z.number().optional(),
|
|
28
|
+
deletedAt: z.date().nullable(),
|
|
29
|
+
});
|
|
16
30
|
|
|
17
|
-
|
|
31
|
+
// Schema is automatically transformed for OpenAI compatibility
|
|
32
|
+
const result = await agent.generate('Extract: John, deleted yesterday', {
|
|
33
|
+
structuredOutput: { schema },
|
|
34
|
+
});
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
// Result: { name: 'John', age: undefined, deletedAt: null }
|
|
37
|
+
```
|
|
20
38
|
|
|
21
|
-
|
|
39
|
+
## 1.0.0-beta.0
|
|
22
40
|
|
|
23
|
-
|
|
41
|
+
### Major Changes
|
|
24
42
|
|
|
25
|
-
-
|
|
43
|
+
- Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
|
|
26
44
|
|
|
27
|
-
|
|
45
|
+
- Mark as stable ([`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc))
|
|
28
46
|
|
|
29
47
|
### Patch Changes
|
|
30
48
|
|
|
31
|
-
- Fix Zod v4 toJSONSchema bug with z.record() single-argument form ([#
|
|
49
|
+
- Fix Zod v4 toJSONSchema bug with z.record() single-argument form ([#9265](https://github.com/mastra-ai/mastra/pull/9265))
|
|
32
50
|
|
|
33
51
|
Zod v4 has a bug in the single-argument form of `z.record(valueSchema)` where it incorrectly assigns the value schema to `keyType` instead of `valueType`, leaving `valueType` undefined. This causes `toJSONSchema()` to throw "Cannot read properties of undefined (reading '\_zod')" when processing schemas containing `z.record()` fields.
|
|
34
52
|
|
|
35
53
|
This fix patches affected schemas before conversion by detecting records with missing `valueType` and correctly assigning the schema to `valueType` while setting `keyType` to `z.string()` (the default). The patch recursively handles nested schemas including those wrapped in `.optional()`, `.nullable()`, arrays, unions, and objects.
|
|
36
54
|
|
|
37
|
-
- Improved reliability of string field types in tool schema compatibility ([#
|
|
38
|
-
|
|
39
|
-
## 0.11.5
|
|
40
|
-
|
|
41
|
-
### Patch Changes
|
|
42
|
-
|
|
43
|
-
- Fix peerdependencies ([`eb7c1c8`](https://github.com/mastra-ai/mastra/commit/eb7c1c8c592d8fb16dfd250e337d9cdc73c8d5de))
|
|
55
|
+
- Improved reliability of string field types in tool schema compatibility ([#9266](https://github.com/mastra-ai/mastra/pull/9266))
|
|
44
56
|
|
|
45
57
|
## 0.11.4
|
|
46
58
|
|