@mastra/schema-compat 0.11.8-alpha.0 → 0.11.8

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.
Files changed (2) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @mastra/schema-compat
2
2
 
3
+ ## 0.11.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed OpenAI schema compatibility when using `agent.generate()` or `agent.stream()` with `structuredOutput`. ([#10454](https://github.com/mastra-ai/mastra/pull/10454))
8
+
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
15
+
16
+ ## Example
17
+
18
+ ```typescript
19
+ const agent = new Agent({
20
+ name: 'data-extractor',
21
+ model: { provider: 'openai', modelId: 'gpt-4o' },
22
+ instructions: 'Extract user information',
23
+ });
24
+
25
+ const schema = z.object({
26
+ name: z.string(),
27
+ age: z.number().optional(),
28
+ deletedAt: z.date().nullable(),
29
+ });
30
+
31
+ // Schema is automatically transformed for OpenAI compatibility
32
+ const result = await agent.generate('Extract: John, deleted yesterday', {
33
+ structuredOutput: { schema },
34
+ });
35
+
36
+ // Result: { name: 'John', age: undefined, deletedAt: null }
37
+ ```
38
+
3
39
  ## 0.11.8-alpha.0
4
40
 
5
41
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/schema-compat",
3
- "version": "0.11.8-alpha.0",
3
+ "version": "0.11.8",
4
4
  "description": "Tool schema compatibility layer for Mastra.ai",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -60,8 +60,8 @@
60
60
  "typescript": "^5.8.3",
61
61
  "vitest": "^3.2.4",
62
62
  "zod": "^3.25.76",
63
- "@internal/lint": "0.0.63",
64
- "@internal/types-builder": "0.0.38"
63
+ "@internal/types-builder": "0.0.39",
64
+ "@internal/lint": "0.0.64"
65
65
  },
66
66
  "homepage": "https://mastra.ai",
67
67
  "repository": {