@mastra/schema-compat 0.0.0-allow-to-pass-a-mastra-url-instance-20251105224938 → 0.0.0-bundle-studio-cloud-20251222034739
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 +103 -1
- package/dist/{chunk-U2HXWNAF.js → chunk-3UNBRBSM.js} +2 -2
- package/dist/{chunk-U2HXWNAF.js.map → chunk-3UNBRBSM.js.map} +1 -1
- package/dist/{chunk-5WM4A32G.cjs → chunk-E3FJXGJD.cjs} +2 -2
- package/dist/{chunk-5WM4A32G.cjs.map → chunk-E3FJXGJD.cjs.map} +1 -1
- package/dist/chunk-EGRHWZRV.js +3 -0
- package/dist/chunk-EGRHWZRV.js.map +1 -0
- package/dist/chunk-NKIQRCOM.cjs +4 -0
- package/dist/chunk-NKIQRCOM.cjs.map +1 -0
- package/dist/index.cjs +71 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -22
- package/dist/index.js.map +1 -1
- package/dist/json-schema.d.ts +2 -2
- package/dist/json-schema.d.ts.map +1 -1
- package/dist/json-to-zod.cjs +267 -0
- package/dist/json-to-zod.cjs.map +1 -0
- package/dist/json-to-zod.d.ts +4 -0
- package/dist/json-to-zod.d.ts.map +1 -0
- package/dist/json-to-zod.js +256 -0
- package/dist/json-to-zod.js.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 -5
- package/dist/schema-compatibility-v3.d.ts.map +1 -1
- package/dist/schema-compatibility-v4.d.ts +9 -5
- package/dist/schema-compatibility-v4.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts +2 -2
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils-test-suite.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod-to-json.cjs +2 -2
- package/dist/zod-to-json.d.ts.map +1 -1
- package/dist/zod-to-json.js +1 -1
- package/dist/zodTypes.d.ts +2 -0
- package/dist/zodTypes.d.ts.map +1 -1
- package/package.json +19 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,108 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-bundle-studio-cloud-20251222034739
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
|
|
8
|
+
|
|
9
|
+
- Mark as stable ([`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc))
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Fix Zod v4 toJSONSchema bug with z.record() single-argument form ([#9265](https://github.com/mastra-ai/mastra/pull/9265))
|
|
14
|
+
|
|
15
|
+
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.
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
- Embed AI types to fix peerdeps mismatches ([`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808))
|
|
20
|
+
|
|
21
|
+
- Improved reliability of string field types in tool schema compatibility ([#9266](https://github.com/mastra-ai/mastra/pull/9266))
|
|
22
|
+
|
|
23
|
+
- Fix discriminatedUnion schema information lost when json schema is converted to zod ([#10500](https://github.com/mastra-ai/mastra/pull/10500))
|
|
24
|
+
|
|
25
|
+
- Fixed OpenAI schema compatibility when using `agent.generate()` or `agent.stream()` with `structuredOutput`. ([#10366](https://github.com/mastra-ai/mastra/pull/10366))
|
|
26
|
+
|
|
27
|
+
**Changes**
|
|
28
|
+
- **Automatic transformation**: Zod schemas are now automatically transformed for OpenAI strict mode compatibility when using OpenAI models (including reasoning models like o1, o3, o4)
|
|
29
|
+
- **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
|
|
30
|
+
- **Preserves nullable fields**: Intentionally `.nullable()` fields remain unchanged
|
|
31
|
+
- **Deep transformation**: Handles `.optional()` fields at any nesting level (objects, arrays, unions, etc.)
|
|
32
|
+
- **JSON Schema objects**: Not transformed, only Zod schemas
|
|
33
|
+
|
|
34
|
+
**Example**
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const agent = new Agent({
|
|
38
|
+
name: 'data-extractor',
|
|
39
|
+
model: { provider: 'openai', modelId: 'gpt-4o' },
|
|
40
|
+
instructions: 'Extract user information',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const schema = z.object({
|
|
44
|
+
name: z.string(),
|
|
45
|
+
age: z.number().optional(),
|
|
46
|
+
deletedAt: z.date().nullable(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Schema is automatically transformed for OpenAI compatibility
|
|
50
|
+
const result = await agent.generate('Extract: John, deleted yesterday', {
|
|
51
|
+
structuredOutput: { schema },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Result: { name: 'John', age: undefined, deletedAt: null }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 1.0.0-beta.3
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- Embed AI types to fix peerdeps mismatches ([`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808))
|
|
62
|
+
|
|
63
|
+
## 1.0.0-beta.2
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- Fix discriminatedUnion schema information lost when json schema is converted to zod ([#10500](https://github.com/mastra-ai/mastra/pull/10500))
|
|
68
|
+
|
|
69
|
+
## 1.0.0-beta.1
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- Fixed OpenAI schema compatibility when using `agent.generate()` or `agent.stream()` with `structuredOutput`. ([#10366](https://github.com/mastra-ai/mastra/pull/10366))
|
|
74
|
+
|
|
75
|
+
## Changes
|
|
76
|
+
- **Automatic transformation**: Zod schemas are now automatically transformed for OpenAI strict mode compatibility when using OpenAI models (including reasoning models like o1, o3, o4)
|
|
77
|
+
- **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
|
|
78
|
+
- **Preserves nullable fields**: Intentionally `.nullable()` fields remain unchanged
|
|
79
|
+
- **Deep transformation**: Handles `.optional()` fields at any nesting level (objects, arrays, unions, etc.)
|
|
80
|
+
- **JSON Schema objects**: Not transformed, only Zod schemas
|
|
81
|
+
|
|
82
|
+
## Example
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const agent = new Agent({
|
|
86
|
+
name: 'data-extractor',
|
|
87
|
+
model: { provider: 'openai', modelId: 'gpt-4o' },
|
|
88
|
+
instructions: 'Extract user information',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const schema = z.object({
|
|
92
|
+
name: z.string(),
|
|
93
|
+
age: z.number().optional(),
|
|
94
|
+
deletedAt: z.date().nullable(),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Schema is automatically transformed for OpenAI compatibility
|
|
98
|
+
const result = await agent.generate('Extract: John, deleted yesterday', {
|
|
99
|
+
structuredOutput: { schema },
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Result: { name: 'John', age: undefined, deletedAt: null }
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 1.0.0-beta.0
|
|
4
106
|
|
|
5
107
|
### Major Changes
|
|
6
108
|
|
|
@@ -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-3UNBRBSM.js.map
|
|
77
|
+
//# sourceMappingURL=chunk-3UNBRBSM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/zod-to-json.ts"],"names":[],"mappings":";;;;AAQA,IAAM,OAAA,GAAU,OAAO,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,GAAW,EAAU,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,MAAM,KAAA,GAAQ,OAAO,GAAA,C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I,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,MAAM,CAAA,EAAG;AAEX,IAAA,kBAAA,CAAmB,SAAS,CAAA;AAE5B,IAAA,OAAQ,CAAA,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,OAAO,wBAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-3UNBRBSM.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"]}
|
|
@@ -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-E3FJXGJD.cjs.map
|
|
83
|
+
//# sourceMappingURL=chunk-E3FJXGJD.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["z","zodToJsonSchemaOriginal"],"mappings":";;;;;;;;;;AAQA,IAAM,OAAA,GAAU,OAAO,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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{ 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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-EGRHWZRV.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-NKIQRCOM.cjs"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkE3FJXGJD_cjs = require('./chunk-E3FJXGJD.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
|
-
// ../
|
|
9
|
+
// ../_vendored/ai_v4/dist/chunk-IHGBB4AL.js
|
|
10
10
|
var __create = Object.create;
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
14
|
var __getProtoOf = Object.getPrototypeOf;
|
|
15
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __commonJS = (cb, mod) => function
|
|
16
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
17
17
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
18
|
};
|
|
19
19
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -33,7 +33,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
mod
|
|
34
34
|
));
|
|
35
35
|
var require_secure_json_parse = __commonJS({
|
|
36
|
-
"
|
|
36
|
+
"../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports, module) {
|
|
37
37
|
var hasBuffer = typeof Buffer !== "undefined";
|
|
38
38
|
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
39
39
|
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
@@ -163,8 +163,8 @@ var _AISDKError = class _AISDKError2 extends Error {
|
|
|
163
163
|
static isInstance(error) {
|
|
164
164
|
return _AISDKError2.hasMarker(error, marker);
|
|
165
165
|
}
|
|
166
|
-
static hasMarker(error,
|
|
167
|
-
const markerSymbol = Symbol.for(
|
|
166
|
+
static hasMarker(error, marker152) {
|
|
167
|
+
const markerSymbol = Symbol.for(marker152);
|
|
168
168
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
169
169
|
}
|
|
170
170
|
};
|
|
@@ -2166,7 +2166,7 @@ function formatDataStreamPart(type, value) {
|
|
|
2166
2166
|
}
|
|
2167
2167
|
function zodSchema(zodSchema2, options) {
|
|
2168
2168
|
var _a17;
|
|
2169
|
-
const useReferences = (_a17 = void 0) != null ? _a17 : false;
|
|
2169
|
+
const useReferences = (_a17 = void 0 ) != null ? _a17 : false;
|
|
2170
2170
|
return jsonSchema(
|
|
2171
2171
|
esm_default(zodSchema2, {
|
|
2172
2172
|
$refStrategy: useReferences ? "root" : "none",
|
|
@@ -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 = chunkE3FJXGJD_cjs.zodToJsonSchema(zodSchema2, target);
|
|
3572
3572
|
return jsonSchema(jsonSchemaToUse, {
|
|
3573
3573
|
validate: (value) => {
|
|
3574
3574
|
const result = zodSchema2.safeParse(value);
|
|
@@ -3615,7 +3615,7 @@ function applyCompatLayer({
|
|
|
3615
3615
|
}
|
|
3616
3616
|
}
|
|
3617
3617
|
if (mode === "jsonSchema") {
|
|
3618
|
-
return
|
|
3618
|
+
return chunkE3FJXGJD_cjs.zodToJsonSchema(zodSchema2, "jsonSchema7");
|
|
3619
3619
|
} else {
|
|
3620
3620
|
return convertZodSchemaToAISDKSchema(zodSchema2);
|
|
3621
3621
|
}
|
|
@@ -3646,7 +3646,8 @@ var SUPPORTED_ZOD_TYPES = [
|
|
|
3646
3646
|
"ZodNumber",
|
|
3647
3647
|
"ZodDate",
|
|
3648
3648
|
"ZodAny",
|
|
3649
|
-
"ZodDefault"
|
|
3649
|
+
"ZodDefault",
|
|
3650
|
+
"ZodNullable"
|
|
3650
3651
|
];
|
|
3651
3652
|
var ALL_ZOD_TYPES = [...SUPPORTED_ZOD_TYPES, ...UNSUPPORTED_ZOD_TYPES];
|
|
3652
3653
|
var SchemaCompatLayer = class {
|
|
@@ -4063,7 +4064,8 @@ var SUPPORTED_ZOD_TYPES2 = [
|
|
|
4063
4064
|
"ZodNumber",
|
|
4064
4065
|
"ZodDate",
|
|
4065
4066
|
"ZodAny",
|
|
4066
|
-
"ZodDefault"
|
|
4067
|
+
"ZodDefault",
|
|
4068
|
+
"ZodNullable"
|
|
4067
4069
|
];
|
|
4068
4070
|
var SchemaCompatLayer2 = class {
|
|
4069
4071
|
model;
|
|
@@ -4106,6 +4108,12 @@ var SchemaCompatLayer2 = class {
|
|
|
4106
4108
|
isNull(v) {
|
|
4107
4109
|
return v instanceof v4.ZodNull;
|
|
4108
4110
|
}
|
|
4111
|
+
/**
|
|
4112
|
+
* Type guard for nullable Zod types
|
|
4113
|
+
*/
|
|
4114
|
+
isNullable(v) {
|
|
4115
|
+
return v instanceof v4.ZodNullable;
|
|
4116
|
+
}
|
|
4109
4117
|
/**
|
|
4110
4118
|
* Type guard for array Zod types
|
|
4111
4119
|
*/
|
|
@@ -4699,6 +4707,9 @@ function isDate(z11) {
|
|
|
4699
4707
|
function isDefault(z11) {
|
|
4700
4708
|
return (v) => v instanceof z11["ZodDefault"];
|
|
4701
4709
|
}
|
|
4710
|
+
function isNullable(z11) {
|
|
4711
|
+
return (v) => v instanceof z11["ZodNullable"];
|
|
4712
|
+
}
|
|
4702
4713
|
|
|
4703
4714
|
// src/provider-compats/anthropic.ts
|
|
4704
4715
|
var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
@@ -4839,15 +4850,30 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
4839
4850
|
}
|
|
4840
4851
|
processZodType(value) {
|
|
4841
4852
|
if (isOptional2(zod.z)(value)) {
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4853
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
4854
|
+
if (innerType) {
|
|
4855
|
+
if (isNullable(zod.z)(innerType)) {
|
|
4856
|
+
const processed = this.processZodType(innerType);
|
|
4857
|
+
return processed.transform((val) => val === null ? void 0 : val);
|
|
4858
|
+
}
|
|
4859
|
+
const processedInner = this.processZodType(innerType);
|
|
4860
|
+
return processedInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
4861
|
+
}
|
|
4862
|
+
return value;
|
|
4863
|
+
} else if (isNullable(zod.z)(value)) {
|
|
4864
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
4865
|
+
if (innerType) {
|
|
4866
|
+
if (isOptional2(zod.z)(innerType)) {
|
|
4867
|
+
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
4868
|
+
if (innerInnerType) {
|
|
4869
|
+
const processedInnerInner = this.processZodType(innerInnerType);
|
|
4870
|
+
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
const processedInner = this.processZodType(innerType);
|
|
4874
|
+
return processedInner.nullable();
|
|
4875
|
+
}
|
|
4876
|
+
return value;
|
|
4851
4877
|
} else if (isObj2(zod.z)(value)) {
|
|
4852
4878
|
return this.defaultZodObjectHandler(value);
|
|
4853
4879
|
} else if (isUnion2(zod.z)(value)) {
|
|
@@ -4880,15 +4906,37 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
4880
4906
|
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`) || this.getModel().modelId.includes(`o1`);
|
|
4881
4907
|
}
|
|
4882
4908
|
shouldApply() {
|
|
4883
|
-
if (
|
|
4909
|
+
if (this.isReasoningModel() && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
4884
4910
|
return true;
|
|
4885
4911
|
}
|
|
4886
4912
|
return false;
|
|
4887
4913
|
}
|
|
4888
4914
|
processZodType(value) {
|
|
4889
4915
|
if (isOptional2(zod.z)(value)) {
|
|
4890
|
-
const
|
|
4891
|
-
|
|
4916
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
4917
|
+
if (innerType) {
|
|
4918
|
+
if (isNullable(zod.z)(innerType)) {
|
|
4919
|
+
const processed = this.processZodType(innerType);
|
|
4920
|
+
return processed.transform((val) => val === null ? void 0 : val);
|
|
4921
|
+
}
|
|
4922
|
+
const processedInner = this.processZodType(innerType);
|
|
4923
|
+
return processedInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
4924
|
+
}
|
|
4925
|
+
return value;
|
|
4926
|
+
} else if (isNullable(zod.z)(value)) {
|
|
4927
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
4928
|
+
if (innerType && isOptional2(zod.z)(innerType)) {
|
|
4929
|
+
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
4930
|
+
if (innerInnerType) {
|
|
4931
|
+
const processedInnerInner = this.processZodType(innerInnerType);
|
|
4932
|
+
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4935
|
+
if (innerType) {
|
|
4936
|
+
const processedInner = this.processZodType(innerType);
|
|
4937
|
+
return processedInner.nullable();
|
|
4938
|
+
}
|
|
4939
|
+
return value;
|
|
4892
4940
|
} else if (isObj2(zod.z)(value)) {
|
|
4893
4941
|
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
4894
4942
|
} else if (isArr2(zod.z)(value)) {
|