@mastra/schema-compat 0.0.0-fix-cloud-peer-deps-20250923194656 → 0.0.0-sidebar-window-undefined-fix-20251029233656

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 CHANGED
@@ -1,6 +1,18 @@
1
1
  # @mastra/schema-compat
2
2
 
3
- ## 0.0.0-fix-cloud-peer-deps-20250923194656
3
+ ## 0.0.0-sidebar-window-undefined-fix-20251029233656
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix Zod v4 toJSONSchema bug with z.record() single-argument form ([#9265](https://github.com/mastra-ai/mastra/pull/9265))
8
+
9
+ 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.
10
+
11
+ 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.
12
+
13
+ - Improved reliability of string field types in tool schema compatibility ([#9266](https://github.com/mastra-ai/mastra/pull/9266))
14
+
15
+ ## 0.11.4
4
16
 
5
17
  ### Patch Changes
6
18
 
@@ -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.zodToJsonSch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X,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,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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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"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk7YUR5KZ5_cjs = require('./chunk-7YUR5KZ5.cjs');
3
+ var chunk5WM4A32G_cjs = require('./chunk-5WM4A32G.cjs');
4
4
  var zod = require('zod');
5
5
  var ai = require('ai');
6
6
  var zodFromJsonSchema = require('zod-from-json-schema');
@@ -8,7 +8,7 @@ var zodFromJsonSchemaV3 = require('zod-from-json-schema-v3');
8
8
  var v4 = require('zod/v4');
9
9
 
10
10
  function convertZodSchemaToAISDKSchema(zodSchema, target = "jsonSchema7") {
11
- const jsonSchemaToUse = chunk7YUR5KZ5_cjs.zodToJsonSchema(zodSchema, target);
11
+ const jsonSchemaToUse = chunk5WM4A32G_cjs.zodToJsonSchema(zodSchema, target);
12
12
  return ai.jsonSchema(jsonSchemaToUse, {
13
13
  validate: (value) => {
14
14
  const result = zodSchema.safeParse(value);
@@ -55,7 +55,7 @@ function applyCompatLayer({
55
55
  }
56
56
  }
57
57
  if (mode === "jsonSchema") {
58
- return chunk7YUR5KZ5_cjs.zodToJsonSchema(zodSchema, "jsonSchema7");
58
+ return chunk5WM4A32G_cjs.zodToJsonSchema(zodSchema, "jsonSchema7");
59
59
  } else {
60
60
  return convertZodSchemaToAISDKSchema(zodSchema);
61
61
  }
@@ -231,8 +231,8 @@ var SchemaCompatLayer = class {
231
231
  * @returns The updated description with constraints, or undefined if no constraints
232
232
  */
233
233
  mergeParameterDescription(description, constraints) {
234
- if (Object.keys(constraints).length > 0) {
235
- return (description ? description + "\n" : "") + JSON.stringify(constraints);
234
+ if (constraints.length > 0) {
235
+ return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
236
236
  } else {
237
237
  return description;
238
238
  }
@@ -262,24 +262,24 @@ var SchemaCompatLayer = class {
262
262
  const zodArrayDef = value._def;
263
263
  const processedType = this.processZodType(zodArrayDef.type);
264
264
  let result = zod.z.array(processedType);
265
- const constraints = {};
265
+ const constraints = [];
266
266
  if (zodArrayDef.minLength?.value !== void 0) {
267
267
  if (handleChecks.includes("min")) {
268
- constraints.minLength = zodArrayDef.minLength.value;
268
+ constraints.push(`minimum length ${zodArrayDef.minLength.value}`);
269
269
  } else {
270
270
  result = result.min(zodArrayDef.minLength.value);
271
271
  }
272
272
  }
273
273
  if (zodArrayDef.maxLength?.value !== void 0) {
274
274
  if (handleChecks.includes("max")) {
275
- constraints.maxLength = zodArrayDef.maxLength.value;
275
+ constraints.push(`maximum length ${zodArrayDef.maxLength.value}`);
276
276
  } else {
277
277
  result = result.max(zodArrayDef.maxLength.value);
278
278
  }
279
279
  }
280
280
  if (zodArrayDef.exactLength?.value !== void 0) {
281
281
  if (handleChecks.includes("length")) {
282
- constraints.exactLength = zodArrayDef.exactLength.value;
282
+ constraints.push(`exact length ${zodArrayDef.exactLength.value}`);
283
283
  } else {
284
284
  result = result.length(zodArrayDef.exactLength.value);
285
285
  }
@@ -314,7 +314,7 @@ var SchemaCompatLayer = class {
314
314
  * @returns The processed Zod string
315
315
  */
316
316
  defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
317
- const constraints = {};
317
+ const constraints = [];
318
318
  const checks = value._def.checks || [];
319
319
  const newChecks = [];
320
320
  for (const check of checks) {
@@ -322,38 +322,20 @@ var SchemaCompatLayer = class {
322
322
  if (handleChecks.includes(check.kind)) {
323
323
  switch (check.kind) {
324
324
  case "regex": {
325
- constraints.regex = {
326
- pattern: check.regex.source,
327
- flags: check.regex.flags
328
- };
329
- break;
330
- }
331
- case "emoji": {
332
- constraints.emoji = true;
333
- break;
334
- }
335
- case "email": {
336
- constraints.email = true;
337
- break;
338
- }
339
- case "url": {
340
- constraints.url = true;
341
- break;
342
- }
343
- case "uuid": {
344
- constraints.uuid = true;
325
+ constraints.push(`input must match this regex ${check.regex.source}`);
345
326
  break;
346
327
  }
328
+ case "emoji":
329
+ case "email":
330
+ case "url":
331
+ case "uuid":
347
332
  case "cuid": {
348
- constraints.cuid = true;
349
- break;
350
- }
351
- case "min": {
352
- constraints.minLength = check.value;
333
+ constraints.push(`a valid ${check.kind}`);
353
334
  break;
354
335
  }
336
+ case "min":
355
337
  case "max": {
356
- constraints.maxLength = check.value;
338
+ constraints.push(`${check.kind}imum length ${check.value}`);
357
339
  break;
358
340
  }
359
341
  }
@@ -380,7 +362,7 @@ var SchemaCompatLayer = class {
380
362
  * @returns The processed Zod number
381
363
  */
382
364
  defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
383
- const constraints = {};
365
+ const constraints = [];
384
366
  const checks = value._def.checks || [];
385
367
  const newChecks = [];
386
368
  for (const check of checks) {
@@ -389,20 +371,20 @@ var SchemaCompatLayer = class {
389
371
  switch (check.kind) {
390
372
  case "min":
391
373
  if (check.inclusive) {
392
- constraints.gte = check.value;
374
+ constraints.push(`greater than or equal to ${check.value}`);
393
375
  } else {
394
- constraints.gt = check.value;
376
+ constraints.push(`greater than ${check.value}`);
395
377
  }
396
378
  break;
397
379
  case "max":
398
380
  if (check.inclusive) {
399
- constraints.lte = check.value;
381
+ constraints.push(`lower than or equal to ${check.value}`);
400
382
  } else {
401
- constraints.lt = check.value;
383
+ constraints.push(`lower than ${check.value}`);
402
384
  }
403
385
  break;
404
386
  case "multipleOf": {
405
- constraints.multipleOf = check.value;
387
+ constraints.push(`multiple of ${check.value}`);
406
388
  break;
407
389
  }
408
390
  }
@@ -437,7 +419,7 @@ var SchemaCompatLayer = class {
437
419
  * @returns A Zod string schema representing the date in ISO format
438
420
  */
439
421
  defaultZodDateHandler(value) {
440
- const constraints = {};
422
+ const constraints = [];
441
423
  const checks = value._def.checks || [];
442
424
  for (const check of checks) {
443
425
  if ("kind" in check) {
@@ -445,19 +427,19 @@ var SchemaCompatLayer = class {
445
427
  case "min":
446
428
  const minDate = new Date(check.value);
447
429
  if (!isNaN(minDate.getTime())) {
448
- constraints.minDate = minDate.toISOString();
430
+ constraints.push(`Date must be newer than ${minDate.toISOString()} (ISO)`);
449
431
  }
450
432
  break;
451
433
  case "max":
452
434
  const maxDate = new Date(check.value);
453
435
  if (!isNaN(maxDate.getTime())) {
454
- constraints.maxDate = maxDate.toISOString();
436
+ constraints.push(`Date must be older than ${maxDate.toISOString()} (ISO)`);
455
437
  }
456
438
  break;
457
439
  }
458
440
  }
459
441
  }
460
- constraints.dateFormat = "date-time";
442
+ constraints.push(`Date format is date-time`);
461
443
  let result = zod.z.string().describe("date-time");
462
444
  const description = this.mergeParameterDescription(value.description, constraints);
463
445
  if (description) {
@@ -665,8 +647,8 @@ var SchemaCompatLayer2 = class {
665
647
  * @returns The updated description with constraints, or undefined if no constraints
666
648
  */
667
649
  mergeParameterDescription(description, constraints) {
668
- if (Object.keys(constraints).length > 0) {
669
- return (description ? description + "\n" : "") + JSON.stringify(constraints);
650
+ if (constraints.length > 0) {
651
+ return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
670
652
  } else {
671
653
  return description;
672
654
  }
@@ -696,26 +678,26 @@ var SchemaCompatLayer2 = class {
696
678
  const zodArrayDef = value._zod.def;
697
679
  const processedType = this.processZodType(zodArrayDef.element);
698
680
  let result = v4.z.array(processedType);
699
- const constraints = {};
681
+ const constraints = [];
700
682
  if (zodArrayDef.checks) {
701
683
  for (const check of zodArrayDef.checks) {
702
684
  if (check._zod.def.check === "min_length") {
703
685
  if (handleChecks.includes("min")) {
704
- constraints.minLength = check._zod.def.minimum;
686
+ constraints.push(`minimum length ${check._zod.def.minimum}`);
705
687
  } else {
706
688
  result = result.min(check._zod.def.minimum);
707
689
  }
708
690
  }
709
691
  if (check._zod.def.check === "max_length") {
710
692
  if (handleChecks.includes("max")) {
711
- constraints.maxLength = check._zod.def.maximum;
693
+ constraints.push(`maximum length ${check._zod.def.maximum}`);
712
694
  } else {
713
695
  result = result.max(check._zod.def.maximum);
714
696
  }
715
697
  }
716
698
  if (check._zod.def.check === "length_equals") {
717
699
  if (handleChecks.includes("length")) {
718
- constraints.exactLength = check._zod.def.length;
700
+ constraints.push(`exact length ${check._zod.def.length}`);
719
701
  } else {
720
702
  result = result.length(check._zod.def.length);
721
703
  }
@@ -754,7 +736,7 @@ var SchemaCompatLayer2 = class {
754
736
  * @returns The processed Zod string
755
737
  */
756
738
  defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS2) {
757
- const constraints = {};
739
+ const constraints = [];
758
740
  const checks = value._zod.def.checks || [];
759
741
  const newChecks = [];
760
742
  if (checks) {
@@ -762,36 +744,23 @@ var SchemaCompatLayer2 = class {
762
744
  if (handleChecks.includes(check._zod.def.check)) {
763
745
  switch (check._zod.def.check) {
764
746
  case "min_length":
765
- constraints.minLength = check._zod.def.minimum;
747
+ constraints.push(`minimum length ${check._zod.def.minimum}`);
766
748
  break;
767
749
  case "max_length":
768
- constraints.maxLength = check._zod.def.maximum;
750
+ constraints.push(`maximum length ${check._zod.def.maximum}`);
769
751
  break;
770
752
  case "string_format":
771
753
  {
772
754
  switch (check._zod.def.format) {
773
755
  case "email":
774
- constraints.email = true;
775
- break;
776
756
  case "url":
777
- constraints.url = true;
778
- break;
779
757
  case "emoji":
780
- constraints.emoji = true;
781
- break;
782
758
  case "uuid":
783
- constraints.uuid = true;
784
- break;
785
759
  case "cuid":
786
- constraints.cuid = true;
760
+ constraints.push(`a valid ${check._zod.def.format}`);
787
761
  break;
788
762
  case "regex":
789
- constraints.regex = {
790
- // @ts-expect-error - fix later
791
- pattern: check._zod.def.pattern,
792
- // @ts-expect-error - fix later
793
- flags: check._zod.def.flags
794
- };
763
+ constraints.push(`input must match this regex ${check._zod.def.pattern}`);
795
764
  break;
796
765
  }
797
766
  }
@@ -822,7 +791,7 @@ var SchemaCompatLayer2 = class {
822
791
  * @returns The processed Zod number
823
792
  */
824
793
  defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS2) {
825
- const constraints = {};
794
+ const constraints = [];
826
795
  const checks = value._zod.def.checks || [];
827
796
  const newChecks = [];
828
797
  if (checks) {
@@ -831,20 +800,20 @@ var SchemaCompatLayer2 = class {
831
800
  switch (check._zod.def.check) {
832
801
  case "greater_than":
833
802
  if (check._zod.def.inclusive) {
834
- constraints.gte = check._zod.def.value;
803
+ constraints.push(`greater than or equal to ${check._zod.def.value}`);
835
804
  } else {
836
- constraints.gt = check._zod.def.value;
805
+ constraints.push(`greater than ${check._zod.def.value}`);
837
806
  }
838
807
  break;
839
808
  case "less_than":
840
809
  if (check._zod.def.inclusive) {
841
- constraints.lte = check._zod.def.value;
810
+ constraints.push(`lower than or equal to ${check._zod.def.value}`);
842
811
  } else {
843
- constraints.lt = check._zod.def.value;
812
+ constraints.push(`lower than ${check._zod.def.value}`);
844
813
  }
845
814
  break;
846
815
  case "multiple_of": {
847
- constraints.multipleOf = check._zod.def.value;
816
+ constraints.push(`multiple of ${check._zod.def.value}`);
848
817
  break;
849
818
  }
850
819
  }
@@ -881,7 +850,7 @@ var SchemaCompatLayer2 = class {
881
850
  * @returns A Zod string schema representing the date in ISO format
882
851
  */
883
852
  defaultZodDateHandler(value) {
884
- const constraints = {};
853
+ const constraints = [];
885
854
  const checks = value._zod.def.checks || [];
886
855
  if (checks) {
887
856
  for (const check of checks) {
@@ -889,19 +858,19 @@ var SchemaCompatLayer2 = class {
889
858
  case "less_than":
890
859
  const minDate = new Date(check._zod.def.value);
891
860
  if (!isNaN(minDate.getTime())) {
892
- constraints.minDate = minDate.toISOString();
861
+ constraints.push(`Date must be newer than ${minDate.toISOString()} (ISO)`);
893
862
  }
894
863
  break;
895
864
  case "greater_than":
896
865
  const maxDate = new Date(check._zod.def.value);
897
866
  if (!isNaN(maxDate.getTime())) {
898
- constraints.maxDate = maxDate.toISOString();
867
+ constraints.push(`Date must be older than ${maxDate.toISOString()} (ISO)`);
899
868
  }
900
869
  break;
901
870
  }
902
871
  }
903
872
  }
904
- constraints.dateFormat = "date-time";
873
+ constraints.push(`Date format is date-time`);
905
874
  let result = v4.z.string().describe("date-time");
906
875
  const description = this.mergeParameterDescription(value.description, constraints);
907
876
  if (description) {
@@ -1370,9 +1339,9 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
1370
1339
  const defaultDef = value._def;
1371
1340
  const innerType = defaultDef.innerType;
1372
1341
  const defaultValue = typeof defaultDef.defaultValue === "function" ? defaultDef.defaultValue() : defaultDef.defaultValue;
1373
- const constraints = {};
1342
+ const constraints = [];
1374
1343
  if (defaultValue !== void 0) {
1375
- constraints.defaultValue = defaultValue;
1344
+ constraints.push(`the default value is ${defaultValue}`);
1376
1345
  }
1377
1346
  const description = this.mergeParameterDescription(value.description, constraints);
1378
1347
  let result = this.processZodType(innerType);