@mastra/schema-compat 0.0.0-ai-v5-20250801192614 → 0.0.0-allow-to-pass-a-mastra-url-instance-20251105224938

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 (67) hide show
  1. package/CHANGELOG.md +146 -2
  2. package/README.md +0 -4
  3. package/dist/chunk-5WM4A32G.cjs +83 -0
  4. package/dist/chunk-5WM4A32G.cjs.map +1 -0
  5. package/dist/chunk-U2HXWNAF.js +77 -0
  6. package/dist/chunk-U2HXWNAF.js.map +1 -0
  7. package/dist/index.cjs +4563 -280
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +12 -8
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +4561 -281
  12. package/dist/index.js.map +1 -1
  13. package/dist/json-schema.d.ts +4 -0
  14. package/dist/json-schema.d.ts.map +1 -0
  15. package/dist/provider-compats/anthropic.d.ts +7 -5
  16. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  17. package/dist/provider-compats/deepseek.d.ts +7 -5
  18. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  19. package/dist/provider-compats/google.d.ts +7 -5
  20. package/dist/provider-compats/google.d.ts.map +1 -1
  21. package/dist/provider-compats/meta.d.ts +7 -5
  22. package/dist/provider-compats/meta.d.ts.map +1 -1
  23. package/dist/provider-compats/openai-reasoning.d.ts +7 -5
  24. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  25. package/dist/provider-compats/openai.d.ts +7 -5
  26. package/dist/provider-compats/openai.d.ts.map +1 -1
  27. package/dist/schema-compatibility-v3.d.ts +287 -0
  28. package/dist/schema-compatibility-v3.d.ts.map +1 -0
  29. package/dist/schema-compatibility-v4.d.ts +278 -0
  30. package/dist/schema-compatibility-v4.d.ts.map +1 -0
  31. package/dist/schema-compatibility.d.ts +81 -166
  32. package/dist/schema-compatibility.d.ts.map +1 -1
  33. package/dist/types.d.ts +7 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/utils-test-suite.d.ts +2 -0
  36. package/dist/utils-test-suite.d.ts.map +1 -0
  37. package/dist/utils.d.ts +19 -7
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/zod-to-json-test-suite.d.ts +6 -0
  40. package/dist/zod-to-json-test-suite.d.ts.map +1 -0
  41. package/dist/zod-to-json.cjs +12 -0
  42. package/dist/zod-to-json.cjs.map +1 -0
  43. package/dist/zod-to-json.d.ts +6 -0
  44. package/dist/zod-to-json.d.ts.map +1 -0
  45. package/dist/zod-to-json.js +3 -0
  46. package/dist/zod-to-json.js.map +1 -0
  47. package/dist/zodTypes.d.ts +21 -0
  48. package/dist/zodTypes.d.ts.map +1 -0
  49. package/package.json +37 -10
  50. package/.turbo/turbo-build.log +0 -4
  51. package/eslint.config.js +0 -6
  52. package/src/index.ts +0 -39
  53. package/src/provider-compats/anthropic.ts +0 -43
  54. package/src/provider-compats/deepseek.ts +0 -35
  55. package/src/provider-compats/google.ts +0 -63
  56. package/src/provider-compats/meta.ts +0 -36
  57. package/src/provider-compats/openai-reasoning.ts +0 -88
  58. package/src/provider-compats/openai.ts +0 -56
  59. package/src/provider-compats.test.ts +0 -312
  60. package/src/schema-compatibility.test.ts +0 -479
  61. package/src/schema-compatibility.ts +0 -590
  62. package/src/utils.test.ts +0 -442
  63. package/src/utils.ts +0 -205
  64. package/tsconfig.build.json +0 -9
  65. package/tsconfig.json +0 -5
  66. package/tsup.config.ts +0 -22
  67. package/vitest.config.ts +0 -7
package/CHANGELOG.md CHANGED
@@ -1,10 +1,154 @@
1
1
  # @mastra/schema-compat
2
2
 
3
- ## 0.0.0-ai-v5-20250801192614
3
+ ## 0.0.0-allow-to-pass-a-mastra-url-instance-20251105224938
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
+ - Improved reliability of string field types in tool schema compatibility ([#9266](https://github.com/mastra-ai/mastra/pull/9266))
20
+
21
+ ## 0.11.4
22
+
23
+ ### Patch Changes
24
+
25
+ - Fixes an issue when the OpenAI reasoning schema compatibility layer was calling defaultValue() as a function, which works in Zod v3 but fails in Zod v4 where defaultValue is stored directly as a value. ([#8090](https://github.com/mastra-ai/mastra/pull/8090))
26
+
27
+ ## 0.11.4-alpha.0
28
+
29
+ ### Patch Changes
30
+
31
+ - Fixes an issue when the OpenAI reasoning schema compatibility layer was calling defaultValue() as a function, which works in Zod v3 but fails in Zod v4 where defaultValue is stored directly as a value. ([#8090](https://github.com/mastra-ai/mastra/pull/8090))
32
+
33
+ ## 0.11.3
34
+
35
+ ### Patch Changes
36
+
37
+ - Change SchemaCompat zodToJsonSchema ref strategy from none to relative, leading to less schema warnings and smaller converted schema sizes ([#7697](https://github.com/mastra-ai/mastra/pull/7697))
38
+
39
+ ## 0.11.3-alpha.0
40
+
41
+ ### Patch Changes
42
+
43
+ - Change SchemaCompat zodToJsonSchema ref strategy from none to relative, leading to less schema warnings and smaller converted schema sizes ([#7697](https://github.com/mastra-ai/mastra/pull/7697))
44
+
45
+ ## 0.11.2
46
+
47
+ ### Patch Changes
48
+
49
+ - ab48c97: dependencies updates:
50
+ - Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.24.5`, in `dependencies`)
51
+ - 637f323: Fix issue with some compilers and calling zod v4's toJSONSchema function
52
+ - de3cbc6: Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
53
+ - 45e4d39: Try fixing the `Attempted import error: 'z'.'toJSONSchema' is not exported from 'zod'` error by tricking the compiler
54
+
55
+ ## 0.11.2-alpha.3
56
+
57
+ ### Patch Changes
58
+
59
+ - [#7350](https://github.com/mastra-ai/mastra/pull/7350) [`45e4d39`](https://github.com/mastra-ai/mastra/commit/45e4d391a2a09fc70c48e4d60f505586ada1ba0e) Thanks [@LekoArts](https://github.com/LekoArts)! - Try fixing the `Attempted import error: 'z'.'toJSONSchema' is not exported from 'zod'` error by tricking the compiler
60
+
61
+ ## 0.11.2-alpha.2
62
+
63
+ ### Patch Changes
64
+
65
+ - [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
66
+
67
+ ## 0.11.2-alpha.1
68
+
69
+ ### Patch Changes
70
+
71
+ - [#5816](https://github.com/mastra-ai/mastra/pull/5816) [`ab48c97`](https://github.com/mastra-ai/mastra/commit/ab48c979098ea571faf998a55d3a00e7acd7a715) Thanks [@dane-ai-mastra](https://github.com/apps/dane-ai-mastra)! - dependencies updates:
72
+ - Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.24.5`, in `dependencies`)
73
+
74
+ ## 0.11.2-alpha.0
75
+
76
+ ### Patch Changes
77
+
78
+ - [#7121](https://github.com/mastra-ai/mastra/pull/7121) [`637f323`](https://github.com/mastra-ai/mastra/commit/637f32371d79a8f78c52c0d53411af0915fcec67) Thanks [@DanielSLew](https://github.com/DanielSLew)! - Fix issue with some compilers and calling zod v4's toJSONSchema function
79
+
80
+ ## 0.11.1
81
+
82
+ ### Patch Changes
83
+
84
+ - [`c6113ed`](https://github.com/mastra-ai/mastra/commit/c6113ed7f9df297e130d94436ceee310273d6430) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix peerdpes for @mastra/core
85
+
86
+ ## 0.11.0
87
+
88
+ ### Minor Changes
89
+
90
+ - [#7032](https://github.com/mastra-ai/mastra/pull/7032) [`1191ce9`](https://github.com/mastra-ai/mastra/commit/1191ce946b40ed291e7877a349f8388e3cff7e5c) Thanks [@wardpeet](https://github.com/wardpeet)! - Bump zod peerdep to 3.25.0 to support both v3/v4
91
+
92
+ ### Patch Changes
93
+
94
+ - [#7028](https://github.com/mastra-ai/mastra/pull/7028) [`da58ccc`](https://github.com/mastra-ai/mastra/commit/da58ccc1f2ac33da0cb97b00443fc6208b45bdec) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix exportsmap
95
+
96
+ - [#6982](https://github.com/mastra-ai/mastra/pull/6982) [`94e9f54`](https://github.com/mastra-ai/mastra/commit/94e9f547d66ef7cd01d9075ab53b5ca9a1cae100) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix AI peerdeps for NPM install
97
+
98
+ - [#6944](https://github.com/mastra-ai/mastra/pull/6944) [`a93f3ba`](https://github.com/mastra-ai/mastra/commit/a93f3ba05eef4cf17f876d61d29cf0841a9e70b7) Thanks [@wardpeet](https://github.com/wardpeet)! - Add support for zod v4
99
+
100
+ ## 0.11.0-alpha.2
4
101
 
5
102
  ### Minor Changes
6
103
 
7
- - 66858d4: AI SDK v5 beta
104
+ - [#7032](https://github.com/mastra-ai/mastra/pull/7032) [`1191ce9`](https://github.com/mastra-ai/mastra/commit/1191ce946b40ed291e7877a349f8388e3cff7e5c) Thanks [@wardpeet](https://github.com/wardpeet)! - Bump zod peerdep to 3.25.0 to support both v3/v4
105
+
106
+ ## 0.10.6-alpha.1
107
+
108
+ ### Patch Changes
109
+
110
+ - [#7028](https://github.com/mastra-ai/mastra/pull/7028) [`da58ccc`](https://github.com/mastra-ai/mastra/commit/da58ccc1f2ac33da0cb97b00443fc6208b45bdec) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix exportsmap
111
+
112
+ ## 0.10.6-alpha.0
113
+
114
+ ### Patch Changes
115
+
116
+ - [#6982](https://github.com/mastra-ai/mastra/pull/6982) [`94e9f54`](https://github.com/mastra-ai/mastra/commit/94e9f547d66ef7cd01d9075ab53b5ca9a1cae100) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix AI peerdeps for NPM install
117
+
118
+ - [#6944](https://github.com/mastra-ai/mastra/pull/6944) [`a93f3ba`](https://github.com/mastra-ai/mastra/commit/a93f3ba05eef4cf17f876d61d29cf0841a9e70b7) Thanks [@wardpeet](https://github.com/wardpeet)! - Add support for zod v4
119
+
120
+ ## 0.10.7
121
+
122
+ ### Patch Changes
123
+
124
+ - dd94a26: Dont rely on the full language model for schema compat
125
+ - 2fff911: Fix vnext working memory tool schema when model is incompatible with schema
126
+ - ae2eb63: Handle regex checks better, return description as a string rather than an object with pattern and flags.
127
+
128
+ ## 0.10.7-alpha.1
129
+
130
+ ### Patch Changes
131
+
132
+ - ae2eb63: Handle regex checks better, return description as a string rather than an object with pattern and flags.
133
+
134
+ ## 0.10.7-alpha.0
135
+
136
+ ### Patch Changes
137
+
138
+ - dd94a26: Dont rely on the full language model for schema compat
139
+ - 2fff911: Fix vnext working memory tool schema when model is incompatible with schema
140
+
141
+ ## 0.10.6
142
+
143
+ ### Patch Changes
144
+
145
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
146
+
147
+ ## 0.10.6-alpha.0
148
+
149
+ ### Patch Changes
150
+
151
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
8
152
 
9
153
  ## 0.10.5
10
154
 
package/README.md CHANGED
@@ -142,7 +142,3 @@ pnpm test
142
142
  # Run tests in watch mode
143
143
  pnpm test --watch
144
144
  ```
145
-
146
- ## License
147
-
148
- Elastic-2.0
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+ var zodToJsonSchemaOriginal = require('zod-to-json-schema');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var zodToJsonSchemaOriginal__default = /*#__PURE__*/_interopDefault(zodToJsonSchemaOriginal);
9
+
10
+ // src/zod-to-json.ts
11
+ var PATCHED = Symbol("__mastra_patched__");
12
+ function patchRecordSchemas(schema) {
13
+ if (!schema || typeof schema !== "object") return schema;
14
+ if (schema[PATCHED]) return schema;
15
+ schema[PATCHED] = true;
16
+ const def = schema._zod?.def;
17
+ if (def?.type === "record" && def.keyType && !def.valueType) {
18
+ def.valueType = def.keyType;
19
+ def.keyType = zod.z.string();
20
+ }
21
+ if (!def) return schema;
22
+ if (def.type === "object" && def.shape) {
23
+ const shape = typeof def.shape === "function" ? def.shape() : def.shape;
24
+ for (const key of Object.keys(shape)) {
25
+ patchRecordSchemas(shape[key]);
26
+ }
27
+ }
28
+ if (def.type === "array" && def.element) {
29
+ patchRecordSchemas(def.element);
30
+ }
31
+ if (def.type === "union" && def.options) {
32
+ def.options.forEach(patchRecordSchemas);
33
+ }
34
+ if (def.type === "record") {
35
+ if (def.keyType) patchRecordSchemas(def.keyType);
36
+ if (def.valueType) patchRecordSchemas(def.valueType);
37
+ }
38
+ if (def.type === "intersection") {
39
+ if (def.left) patchRecordSchemas(def.left);
40
+ if (def.right) patchRecordSchemas(def.right);
41
+ }
42
+ if (def.type === "lazy") {
43
+ if (def.getter && typeof def.getter === "function") {
44
+ const originalGetter = def.getter;
45
+ def.getter = function() {
46
+ const innerSchema = originalGetter();
47
+ if (innerSchema) {
48
+ patchRecordSchemas(innerSchema);
49
+ }
50
+ return innerSchema;
51
+ };
52
+ }
53
+ }
54
+ if (def.innerType) {
55
+ patchRecordSchemas(def.innerType);
56
+ }
57
+ return schema;
58
+ }
59
+ function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
60
+ const fn = "toJSONSchema";
61
+ if (fn in zod.z) {
62
+ patchRecordSchemas(zodSchema);
63
+ return zod.z[fn](zodSchema, {
64
+ unrepresentable: "any",
65
+ override: (ctx) => {
66
+ const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;
67
+ if (def && (def.typeName === "ZodDate" || def.type === "date")) {
68
+ ctx.jsonSchema.type = "string";
69
+ ctx.jsonSchema.format = "date-time";
70
+ }
71
+ }
72
+ });
73
+ } else {
74
+ return zodToJsonSchemaOriginal__default.default(zodSchema, {
75
+ $refStrategy: strategy,
76
+ target
77
+ });
78
+ }
79
+ }
80
+
81
+ exports.zodToJsonSchema = zodToJsonSchema;
82
+ //# sourceMappingURL=chunk-5WM4A32G.cjs.map
83
+ //# sourceMappingURL=chunk-5WM4A32G.cjs.map
@@ -0,0 +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,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,CA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MAAA,GAAA,CAAI,SAAS,WAAY;AACvB,QAAA,MAAM,cAAc,cAAA,EAAe;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,EAClD;AACA,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-5WM4A32G.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) {\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 }) as 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,77 @@
1
+ import { z } from 'zod';
2
+ import zodToJsonSchemaOriginal from 'zod-to-json-schema';
3
+
4
+ // src/zod-to-json.ts
5
+ var PATCHED = Symbol("__mastra_patched__");
6
+ function patchRecordSchemas(schema) {
7
+ if (!schema || typeof schema !== "object") return schema;
8
+ if (schema[PATCHED]) return schema;
9
+ schema[PATCHED] = true;
10
+ const def = schema._zod?.def;
11
+ if (def?.type === "record" && def.keyType && !def.valueType) {
12
+ def.valueType = def.keyType;
13
+ def.keyType = z.string();
14
+ }
15
+ if (!def) return schema;
16
+ if (def.type === "object" && def.shape) {
17
+ const shape = typeof def.shape === "function" ? def.shape() : def.shape;
18
+ for (const key of Object.keys(shape)) {
19
+ patchRecordSchemas(shape[key]);
20
+ }
21
+ }
22
+ if (def.type === "array" && def.element) {
23
+ patchRecordSchemas(def.element);
24
+ }
25
+ if (def.type === "union" && def.options) {
26
+ def.options.forEach(patchRecordSchemas);
27
+ }
28
+ if (def.type === "record") {
29
+ if (def.keyType) patchRecordSchemas(def.keyType);
30
+ if (def.valueType) patchRecordSchemas(def.valueType);
31
+ }
32
+ if (def.type === "intersection") {
33
+ if (def.left) patchRecordSchemas(def.left);
34
+ if (def.right) patchRecordSchemas(def.right);
35
+ }
36
+ if (def.type === "lazy") {
37
+ if (def.getter && typeof def.getter === "function") {
38
+ const originalGetter = def.getter;
39
+ def.getter = function() {
40
+ const innerSchema = originalGetter();
41
+ if (innerSchema) {
42
+ patchRecordSchemas(innerSchema);
43
+ }
44
+ return innerSchema;
45
+ };
46
+ }
47
+ }
48
+ if (def.innerType) {
49
+ patchRecordSchemas(def.innerType);
50
+ }
51
+ return schema;
52
+ }
53
+ function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
54
+ const fn = "toJSONSchema";
55
+ if (fn in z) {
56
+ patchRecordSchemas(zodSchema);
57
+ return z[fn](zodSchema, {
58
+ unrepresentable: "any",
59
+ override: (ctx) => {
60
+ const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;
61
+ if (def && (def.typeName === "ZodDate" || def.type === "date")) {
62
+ ctx.jsonSchema.type = "string";
63
+ ctx.jsonSchema.format = "date-time";
64
+ }
65
+ }
66
+ });
67
+ } else {
68
+ return zodToJsonSchemaOriginal(zodSchema, {
69
+ $refStrategy: strategy,
70
+ target
71
+ });
72
+ }
73
+ }
74
+
75
+ export { zodToJsonSchema };
76
+ //# sourceMappingURL=chunk-U2HXWNAF.js.map
77
+ //# sourceMappingURL=chunk-U2HXWNAF.js.map
@@ -0,0 +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,OAA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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-U2HXWNAF.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) {\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 }) as 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"]}