@mastra/schema-compat 1.0.0-beta.8 → 1.1.0-alpha.0

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 (73) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/dist/_types/@internal_ai-v6/dist/index.d.ts +11769 -0
  3. package/dist/chunk-5WRI5ZAA.js +29 -0
  4. package/dist/{chunk-EGRHWZRV.js.map → chunk-5WRI5ZAA.js.map} +1 -1
  5. package/dist/{chunk-7UW726BK.js → chunk-BXZCXMXO.js} +2 -2
  6. package/dist/chunk-BXZCXMXO.js.map +1 -0
  7. package/dist/chunk-DAVEUCUM.cjs +6784 -0
  8. package/dist/chunk-DAVEUCUM.cjs.map +1 -0
  9. package/dist/chunk-DGOXVQNP.js +6774 -0
  10. package/dist/chunk-DGOXVQNP.js.map +1 -0
  11. package/dist/chunk-DZUJEN5N.cjs +32 -0
  12. package/dist/{chunk-NKIQRCOM.cjs.map → chunk-DZUJEN5N.cjs.map} +1 -1
  13. package/dist/{chunk-ZXNJQOPF.cjs → chunk-VC7YNDY2.cjs} +2 -2
  14. package/dist/chunk-VC7YNDY2.cjs.map +1 -0
  15. package/dist/index.cjs +553 -95
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +554 -96
  19. package/dist/index.js.map +1 -1
  20. package/dist/json-schema/utils.d.ts +53 -0
  21. package/dist/json-schema/utils.d.ts.map +1 -0
  22. package/dist/provider-compats/anthropic.d.ts +5 -4
  23. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  24. package/dist/provider-compats/deepseek.d.ts +3 -0
  25. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  26. package/dist/provider-compats/google.d.ts +3 -0
  27. package/dist/provider-compats/google.d.ts.map +1 -1
  28. package/dist/provider-compats/meta.d.ts +3 -0
  29. package/dist/provider-compats/meta.d.ts.map +1 -1
  30. package/dist/provider-compats/openai-reasoning.d.ts +5 -4
  31. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  32. package/dist/provider-compats/openai.d.ts +4 -2
  33. package/dist/provider-compats/openai.d.ts.map +1 -1
  34. package/dist/schema-compatibility-v3.d.ts +13 -1
  35. package/dist/schema-compatibility-v3.d.ts.map +1 -1
  36. package/dist/schema-compatibility-v4.d.ts +9 -1
  37. package/dist/schema-compatibility-v4.d.ts.map +1 -1
  38. package/dist/schema-compatibility.d.ts +78 -149
  39. package/dist/schema-compatibility.d.ts.map +1 -1
  40. package/dist/schema.cjs +20 -0
  41. package/dist/schema.cjs.map +1 -0
  42. package/dist/schema.d.ts +4 -0
  43. package/dist/schema.d.ts.map +1 -0
  44. package/dist/schema.js +3 -0
  45. package/dist/schema.js.map +1 -0
  46. package/dist/schema.types.d.ts +17 -0
  47. package/dist/schema.types.d.ts.map +1 -0
  48. package/dist/standard-schema/adapters/ai-sdk.d.ts +85 -0
  49. package/dist/standard-schema/adapters/ai-sdk.d.ts.map +1 -0
  50. package/dist/standard-schema/adapters/json-schema.d.ts +100 -0
  51. package/dist/standard-schema/adapters/json-schema.d.ts.map +1 -0
  52. package/dist/standard-schema/adapters/zod-v3.d.ts +32 -0
  53. package/dist/standard-schema/adapters/zod-v3.d.ts.map +1 -0
  54. package/dist/standard-schema/standard-schema.d.ts +107 -0
  55. package/dist/standard-schema/standard-schema.d.ts.map +1 -0
  56. package/dist/standard-schema/standard-schema.types.d.ts +24 -0
  57. package/dist/standard-schema/standard-schema.types.d.ts.map +1 -0
  58. package/dist/utils.d.ts +1 -1
  59. package/dist/zod-to-json.cjs +2 -2
  60. package/dist/zod-to-json.d.ts +1 -3
  61. package/dist/zod-to-json.d.ts.map +1 -1
  62. package/dist/zod-to-json.js +1 -1
  63. package/dist/zodTypes.d.ts +66 -0
  64. package/dist/zodTypes.d.ts.map +1 -1
  65. package/package.json +22 -6
  66. package/dist/chunk-7UW726BK.js.map +0 -1
  67. package/dist/chunk-EGRHWZRV.js +0 -3
  68. package/dist/chunk-NKIQRCOM.cjs +0 -4
  69. package/dist/chunk-ZXNJQOPF.cjs.map +0 -1
  70. package/dist/utils-test-suite.d.ts +0 -2
  71. package/dist/utils-test-suite.d.ts.map +0 -1
  72. package/dist/zod-to-json-test-suite.d.ts +0 -6
  73. package/dist/zod-to-json-test-suite.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkZXNJQOPF_cjs = require('./chunk-ZXNJQOPF.cjs');
3
+ var chunkDAVEUCUM_cjs = require('./chunk-DAVEUCUM.cjs');
4
+ var chunkVC7YNDY2_cjs = require('./chunk-VC7YNDY2.cjs');
5
+ var chunkDZUJEN5N_cjs = require('./chunk-DZUJEN5N.cjs');
4
6
  var zod = require('zod');
5
7
  var zodFromJsonSchema = require('zod-from-json-schema');
6
8
  var zodFromJsonSchemaV3 = require('zod-from-json-schema-v3');
@@ -24,7 +26,7 @@ var __copyProps = (to, from, except, desc) => {
24
26
  }
25
27
  return to;
26
28
  };
27
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
30
  // If the importer is in node compatibility mode or this is not an ESM
29
31
  // file that has been converted to a CommonJS file using a Babel-
30
32
  // compatible transform (i.e. "__esModule" has not been set), then set
@@ -33,7 +35,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
35
  mod
34
36
  ));
35
37
  var require_secure_json_parse = __commonJS({
36
- "../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports, module) {
38
+ "../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports$1, module) {
37
39
  var hasBuffer = typeof Buffer !== "undefined";
38
40
  var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
39
41
  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*:/;
@@ -268,7 +270,7 @@ var customAlphabet = (alphabet, defaultSize = 21) => {
268
270
  return id;
269
271
  };
270
272
  };
271
- var import_secure_json_parse = __toESM(require_secure_json_parse());
273
+ var import_secure_json_parse = __toESM2(require_secure_json_parse());
272
274
  function convertAsyncIteratorToReadableStream(iterator) {
273
275
  return new ReadableStream({
274
276
  /**
@@ -3568,7 +3570,7 @@ function trimStartOfStream() {
3568
3570
 
3569
3571
  // src/utils.ts
3570
3572
  function convertZodSchemaToAISDKSchema(zodSchema2, target = "jsonSchema7") {
3571
- const jsonSchemaToUse = chunkZXNJQOPF_cjs.zodToJsonSchema(zodSchema2, target);
3573
+ const jsonSchemaToUse = chunkVC7YNDY2_cjs.zodToJsonSchema(zodSchema2, target);
3572
3574
  return jsonSchema(jsonSchemaToUse, {
3573
3575
  validate: (value) => {
3574
3576
  const result = zodSchema2.safeParse(value);
@@ -3615,7 +3617,7 @@ function applyCompatLayer({
3615
3617
  }
3616
3618
  }
3617
3619
  if (mode === "jsonSchema") {
3618
- return chunkZXNJQOPF_cjs.zodToJsonSchema(zodSchema2, "jsonSchema7");
3620
+ return chunkVC7YNDY2_cjs.zodToJsonSchema(zodSchema2, "jsonSchema7");
3619
3621
  } else {
3620
3622
  return convertZodSchemaToAISDKSchema(zodSchema2);
3621
3623
  }
@@ -3691,6 +3693,12 @@ var SchemaCompatLayer = class {
3691
3693
  isNull(v) {
3692
3694
  return v instanceof zod.ZodNull;
3693
3695
  }
3696
+ /**
3697
+ * Type guard for nullable Zod types
3698
+ */
3699
+ isNullable(v) {
3700
+ return v instanceof zod.ZodNullable;
3701
+ }
3694
3702
  /**
3695
3703
  * Type guard for array Zod types
3696
3704
  */
@@ -4022,6 +4030,20 @@ var SchemaCompatLayer = class {
4022
4030
  return value;
4023
4031
  }
4024
4032
  }
4033
+ /**
4034
+ * Default handler for Zod nullable types. Processes the inner type and maintains nullability.
4035
+ *
4036
+ * @param value - The Zod nullable to process
4037
+ * @param handleTypes - Types that should be processed vs passed through
4038
+ * @returns The processed Zod nullable
4039
+ */
4040
+ defaultZodNullableHandler(value, handleTypes = SUPPORTED_ZOD_TYPES) {
4041
+ if (handleTypes.includes(value._def.innerType._def.typeName)) {
4042
+ return this.processZodType(value._def.innerType).nullable();
4043
+ } else {
4044
+ return value;
4045
+ }
4046
+ }
4025
4047
  /**
4026
4048
  * Processes a Zod object schema and converts it to an AI SDK Schema.
4027
4049
  *
@@ -4192,16 +4214,16 @@ var SchemaCompatLayer2 = class {
4192
4214
  let result = v4.z.object(processedShape);
4193
4215
  if (value._zod.def.catchall instanceof v4.z.ZodNever) {
4194
4216
  result = v4.z.strictObject(processedShape);
4195
- }
4196
- if (value._zod.def.catchall && !(value._zod.def.catchall instanceof v4.z.ZodNever)) {
4217
+ } else if (value._zod.def.catchall instanceof v4.z.ZodUnknown) {
4218
+ if (options.passthrough) {
4219
+ result = v4.z.looseObject(processedShape);
4220
+ }
4221
+ } else if (value._zod.def.catchall) {
4197
4222
  result = result.catchall(value._zod.def.catchall);
4198
4223
  }
4199
4224
  if (value.description) {
4200
4225
  result = result.describe(value.description);
4201
4226
  }
4202
- if (options.passthrough && value._zod.def.catchall instanceof v4.z.ZodUnknown) {
4203
- result = v4.z.looseObject(processedShape);
4204
- }
4205
4227
  return result;
4206
4228
  }
4207
4229
  /**
@@ -4460,6 +4482,20 @@ var SchemaCompatLayer2 = class {
4460
4482
  return value;
4461
4483
  }
4462
4484
  }
4485
+ /**
4486
+ * Default handler for Zod nullable types. Processes the inner type and maintains nullability.
4487
+ *
4488
+ * @param value - The Zod nullable to process
4489
+ * @param handleTypes - Types that should be processed vs passed through
4490
+ * @returns The processed Zod nullable
4491
+ */
4492
+ defaultZodNullableHandler(value, handleTypes = SUPPORTED_ZOD_TYPES2) {
4493
+ if (handleTypes.includes(value.constructor.name)) {
4494
+ return this.processZodType(value._zod.def.innerType).nullable();
4495
+ } else {
4496
+ return value;
4497
+ }
4498
+ }
4463
4499
  /**
4464
4500
  * Processes a Zod object schema and converts it to an AI SDK Schema.
4465
4501
  *
@@ -4481,6 +4517,43 @@ var SchemaCompatLayer2 = class {
4481
4517
  }
4482
4518
  };
4483
4519
 
4520
+ // src/schema-compatibility.ts
4521
+ var import_json_schema_traverse = chunkDZUJEN5N_cjs.__toESM(chunkDAVEUCUM_cjs.require_json_schema_traverse(), 1);
4522
+
4523
+ // src/json-schema/utils.ts
4524
+ function hasType(schema, type) {
4525
+ if (schema.type === type) return true;
4526
+ if (Array.isArray(schema.type) && schema.type.includes(type)) return true;
4527
+ return false;
4528
+ }
4529
+ function isObjectSchema(schema) {
4530
+ return hasType(schema, "object") || schema.properties !== void 0;
4531
+ }
4532
+ function isArraySchema(schema) {
4533
+ return hasType(schema, "array") || schema.items !== void 0;
4534
+ }
4535
+ function isStringSchema(schema) {
4536
+ return hasType(schema, "string");
4537
+ }
4538
+ function isNumberSchema(schema) {
4539
+ return hasType(schema, "number") || hasType(schema, "integer");
4540
+ }
4541
+ function isAnyOfSchema(schema) {
4542
+ return Array.isArray(schema.anyOf) && schema.anyOf.length > 0;
4543
+ }
4544
+ function isOneOfSchema(schema) {
4545
+ return Array.isArray(schema.oneOf) && schema.oneOf.length > 0;
4546
+ }
4547
+ function isUnionSchema(schema) {
4548
+ return isAnyOfSchema(schema) || isOneOfSchema(schema);
4549
+ }
4550
+ function isOptionalSchema(propertyName, parentSchema) {
4551
+ if (!parentSchema.required || !Array.isArray(parentSchema.required)) {
4552
+ return true;
4553
+ }
4554
+ return !parentSchema.required.includes(propertyName);
4555
+ }
4556
+
4484
4557
  // src/schema-compatibility.ts
4485
4558
  var SchemaCompatLayer3 = class {
4486
4559
  model;
@@ -4504,8 +4577,8 @@ var SchemaCompatLayer3 = class {
4504
4577
  getModel() {
4505
4578
  return this.model;
4506
4579
  }
4507
- getUnsupportedZodTypes(v) {
4508
- if ("_zod" in v) {
4580
+ getUnsupportedZodTypes(value) {
4581
+ if ("_zod" in value) {
4509
4582
  return this.v4Layer.getUnsupportedZodTypes();
4510
4583
  } else {
4511
4584
  return this.v3Layer.getUnsupportedZodTypes();
@@ -4532,6 +4605,13 @@ var SchemaCompatLayer3 = class {
4532
4605
  return this.v3Layer.isNull(v);
4533
4606
  }
4534
4607
  }
4608
+ isNullable(v) {
4609
+ if ("_zod" in v) {
4610
+ return this.v4Layer.isNullable(v);
4611
+ } else {
4612
+ return this.v3Layer.isNullable(v);
4613
+ }
4614
+ }
4535
4615
  isArr(v) {
4536
4616
  if ("_zod" in v) {
4537
4617
  return this.v4Layer.isArr(v);
@@ -4574,6 +4654,10 @@ var SchemaCompatLayer3 = class {
4574
4654
  return this.v3Layer.isDefault(v);
4575
4655
  }
4576
4656
  }
4657
+ preProcessJSONNode(_schema, _parentSchema) {
4658
+ }
4659
+ postProcessJSONNode(_schema, _parentSchema) {
4660
+ }
4577
4661
  defaultZodObjectHandler(value, options = { passthrough: true }) {
4578
4662
  if ("_zod" in value) {
4579
4663
  return this.v4Layer.defaultZodObjectHandler(value, options);
@@ -4581,31 +4665,12 @@ var SchemaCompatLayer3 = class {
4581
4665
  return this.v3Layer.defaultZodObjectHandler(value, options);
4582
4666
  }
4583
4667
  }
4584
- /**
4585
- * Merges validation constraints into a parameter description.
4586
- *
4587
- * This helper method converts validation constraints that may not be supported
4588
- * by a provider into human-readable descriptions.
4589
- *
4590
- * @param description - The existing parameter description
4591
- * @param constraints - The validation constraints to merge
4592
- * @returns The updated description with constraints, or undefined if no constraints
4593
- */
4594
4668
  mergeParameterDescription(description, constraints) {
4595
4669
  return this.v3Layer.mergeParameterDescription(description, constraints);
4596
4670
  }
4597
- /**
4598
- * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
4599
- *
4600
- * @param value - The Zod type to check
4601
- * @param throwOnTypes - Array of type names to throw errors for
4602
- * @returns The original value if not in the throw list
4603
- * @throws Error if the type is in the unsupported list
4604
- */
4605
4671
  defaultUnsupportedZodTypeHandler(value, throwOnTypes) {
4606
4672
  if ("_zod" in value) {
4607
4673
  return this.v4Layer.defaultUnsupportedZodTypeHandler(
4608
- // @ts-expect-error - fix later
4609
4674
  value,
4610
4675
  throwOnTypes ?? UNSUPPORTED_ZOD_TYPES2
4611
4676
  );
@@ -4652,65 +4717,285 @@ var SchemaCompatLayer3 = class {
4652
4717
  }
4653
4718
  }
4654
4719
  defaultZodOptionalHandler(value, handleTypes) {
4720
+ if (!handleTypes) {
4721
+ handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"];
4722
+ }
4723
+ let innerTypeName;
4655
4724
  if ("_zod" in value) {
4656
- return this.v4Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES2);
4725
+ const innerType = value._zod?.def?.innerType;
4726
+ const v4Type = innerType?._zod?.def?.type;
4727
+ if (!v4Type) {
4728
+ return value;
4729
+ }
4730
+ innerTypeName = "Zod" + v4Type.charAt(0).toUpperCase() + v4Type.slice(1);
4731
+ } else {
4732
+ innerTypeName = value._def.innerType._def.typeName;
4733
+ }
4734
+ if (handleTypes.includes(innerTypeName)) {
4735
+ if ("_zod" in value) {
4736
+ const innerType = value._zod?.def?.innerType;
4737
+ if (!innerType) {
4738
+ return value;
4739
+ }
4740
+ return this.processZodType(innerType).optional();
4741
+ } else {
4742
+ return this.processZodType(value._def.innerType).optional();
4743
+ }
4657
4744
  } else {
4658
- return this.v3Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES);
4745
+ return value;
4746
+ }
4747
+ }
4748
+ defaultZodNullableHandler(value, handleTypes) {
4749
+ if ("_zod" in value) {
4750
+ return this.v4Layer.defaultZodNullableHandler(
4751
+ value,
4752
+ handleTypes ?? SUPPORTED_ZOD_TYPES2
4753
+ );
4754
+ } else {
4755
+ return this.v3Layer.defaultZodNullableHandler(
4756
+ value,
4757
+ handleTypes ?? SUPPORTED_ZOD_TYPES
4758
+ );
4659
4759
  }
4660
4760
  }
4661
- /**
4662
- * Processes a Zod object schema and converts it to an AI SDK Schema.
4663
- *
4664
- * @param zodSchema - The Zod object schema to process
4665
- * @returns An AI SDK Schema with provider-specific compatibility applied
4666
- */
4667
4761
  processToAISDKSchema(zodSchema2) {
4668
4762
  const processedSchema = this.processZodType(zodSchema2);
4669
4763
  return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
4670
4764
  }
4765
+ processToJSONSchema(zodSchema2, io = "input") {
4766
+ const standardSchema = chunkDAVEUCUM_cjs.toStandardSchema(zodSchema2);
4767
+ return chunkDAVEUCUM_cjs.standardSchemaToJSONSchema(standardSchema, {
4768
+ target: "draft-07",
4769
+ io
4770
+ // Use input mode so fields with defaults are optional
4771
+ });
4772
+ }
4773
+ // ==========================================
4774
+ // JSON Schema Default Handlers
4775
+ // ==========================================
4671
4776
  /**
4672
- * Processes a Zod object schema and converts it to a JSON Schema.
4777
+ * Default handler for JSON Schema objects.
4778
+ * Processes object schemas with properties and required fields.
4779
+ */
4780
+ defaultObjectHandler(schema) {
4781
+ if (schema.properties && schema.additionalProperties === void 0) {
4782
+ schema.additionalProperties = false;
4783
+ }
4784
+ return schema;
4785
+ }
4786
+ /**
4787
+ * Default handler for JSON Schema arrays.
4788
+ * Converts array constraints (minItems, maxItems) to description text.
4789
+ */
4790
+ defaultArrayHandler(schema) {
4791
+ let constraints = [];
4792
+ const minItems = schema.minItems;
4793
+ const maxItems = schema.maxItems;
4794
+ if (minItems !== void 0 && maxItems !== void 0 && minItems === maxItems) {
4795
+ constraints = [`exact length ${minItems}`];
4796
+ delete schema.minItems;
4797
+ delete schema.maxItems;
4798
+ } else {
4799
+ if (minItems !== void 0) {
4800
+ constraints.push(`minimum length ${minItems}`);
4801
+ delete schema.minItems;
4802
+ }
4803
+ if (maxItems !== void 0) {
4804
+ constraints.push(`maximum length ${maxItems}`);
4805
+ delete schema.maxItems;
4806
+ }
4807
+ }
4808
+ if (constraints.length) {
4809
+ schema.description = this.mergeParameterDescription(schema.description, constraints);
4810
+ }
4811
+ return schema;
4812
+ }
4813
+ /**
4814
+ * Default handler for JSON Schema strings.
4815
+ * Converts string constraints (minLength, maxLength, pattern, format) to description text.
4816
+ */
4817
+ defaultStringHandler(schema) {
4818
+ const constraints = [];
4819
+ if (schema.minLength !== void 0) {
4820
+ constraints.push(`minimum length ${schema.minLength}`);
4821
+ delete schema.minLength;
4822
+ }
4823
+ if (schema.maxLength !== void 0) {
4824
+ constraints.push(`maximum length ${schema.maxLength}`);
4825
+ delete schema.maxLength;
4826
+ }
4827
+ if (schema.pattern !== void 0) {
4828
+ delete schema.pattern;
4829
+ }
4830
+ if (schema.format !== void 0) {
4831
+ const formatMap = {
4832
+ email: "a valid email",
4833
+ uri: "a valid url",
4834
+ url: "a valid url",
4835
+ uuid: "a valid uuid",
4836
+ "date-time": "a valid date-time",
4837
+ date: "a valid date",
4838
+ time: "a valid time"
4839
+ };
4840
+ const formatText = formatMap[schema.format] || `format: ${schema.format}`;
4841
+ constraints.push(formatText);
4842
+ delete schema.format;
4843
+ }
4844
+ if (constraints.length) {
4845
+ schema.description = this.mergeParameterDescription(schema.description, constraints);
4846
+ }
4847
+ return schema;
4848
+ }
4849
+ /**
4850
+ * Default handler for JSON Schema numbers/integers.
4851
+ * Converts number constraints (minimum, maximum, multipleOf, exclusiveMinimum, exclusiveMaximum) to description text.
4852
+ */
4853
+ defaultNumberHandler(schema) {
4854
+ const constraints = [];
4855
+ if (schema.minimum !== void 0) {
4856
+ if (schema.minimum !== Number.MIN_SAFE_INTEGER) {
4857
+ constraints.push(`greater than or equal to ${schema.minimum}`);
4858
+ }
4859
+ delete schema.minimum;
4860
+ }
4861
+ if (schema.maximum !== void 0) {
4862
+ if (schema.maximum !== Number.MAX_SAFE_INTEGER) {
4863
+ constraints.push(`lower than or equal to ${schema.maximum}`);
4864
+ }
4865
+ delete schema.maximum;
4866
+ }
4867
+ if (schema.exclusiveMinimum !== void 0) {
4868
+ constraints.push(`greater than ${schema.exclusiveMinimum}`);
4869
+ delete schema.exclusiveMinimum;
4870
+ }
4871
+ if (schema.exclusiveMaximum !== void 0) {
4872
+ constraints.push(`lower than ${schema.exclusiveMaximum}`);
4873
+ delete schema.exclusiveMaximum;
4874
+ }
4875
+ if (schema.multipleOf !== void 0) {
4876
+ constraints.push(`multiple of ${schema.multipleOf}`);
4877
+ delete schema.multipleOf;
4878
+ }
4879
+ if (constraints.length) {
4880
+ schema.description = this.mergeParameterDescription(schema.description, constraints);
4881
+ }
4882
+ return schema;
4883
+ }
4884
+ /**
4885
+ * Default handler for JSON Schema unions (anyOf/oneOf).
4886
+ * Processes union schemas and can convert anyOf patterns to type arrays for simple primitives.
4887
+ */
4888
+ defaultUnionHandler(schema) {
4889
+ if (schema.anyOf && Array.isArray(schema.anyOf)) {
4890
+ const allSimplePrimitives = schema.anyOf.every((s) => {
4891
+ if (typeof s !== "object" || s === null) return false;
4892
+ const keys = Object.keys(s);
4893
+ return keys.length === 1 && keys[0] === "type" && typeof s.type === "string";
4894
+ });
4895
+ if (allSimplePrimitives) {
4896
+ const types = schema.anyOf.map((s) => s.type);
4897
+ delete schema.anyOf;
4898
+ schema.type = types;
4899
+ }
4900
+ }
4901
+ return schema;
4902
+ }
4903
+ /**
4904
+ * Default handler for JSON Schema nullable types.
4905
+ * Ensures nullable types are represented correctly.
4906
+ */
4907
+ defaultNullableHandler(schema) {
4908
+ return this.defaultUnionHandler(schema);
4909
+ }
4910
+ /**
4911
+ * Default handler for JSON Schema dates (string with date/date-time format).
4912
+ * Converts date formats to string type with format constraint in description.
4913
+ */
4914
+ defaultDateHandler(schema) {
4915
+ if (schema.format === "date" || schema.format === "date-time") {
4916
+ const format = schema.format;
4917
+ delete schema.format;
4918
+ schema.description = this.mergeParameterDescription(schema.description, [`format: ${format}`]);
4919
+ }
4920
+ return schema;
4921
+ }
4922
+ /**
4923
+ * Default handler for empty JSON schemas.
4924
+ * Converts empty {} schemas to a union of primitive types.
4925
+ */
4926
+ defaultEmptySchemaHandler(schema) {
4927
+ if (Object.keys(schema).length === 0) {
4928
+ schema.type = ["string", "number", "boolean", "null"];
4929
+ }
4930
+ return schema;
4931
+ }
4932
+ /**
4933
+ * Default handler for unsupported JSON Schema features.
4934
+ * Can be used to strip or convert unsupported keywords.
4935
+ */
4936
+ defaultUnsupportedHandler(schema, unsupportedKeywords = []) {
4937
+ for (const keyword of unsupportedKeywords) {
4938
+ if (keyword in schema) {
4939
+ delete schema[keyword];
4940
+ }
4941
+ }
4942
+ return schema;
4943
+ }
4944
+ // ==========================================
4945
+ // JSON Schema Type Checkers (delegating to json-schema/utils)
4946
+ // ==========================================
4947
+ isObjectSchema(schema) {
4948
+ return isObjectSchema(schema);
4949
+ }
4950
+ isArraySchema(schema) {
4951
+ return isArraySchema(schema);
4952
+ }
4953
+ isStringSchema(schema) {
4954
+ return isStringSchema(schema);
4955
+ }
4956
+ isNumberSchema(schema) {
4957
+ return isNumberSchema(schema);
4958
+ }
4959
+ isUnionSchema(schema) {
4960
+ return isUnionSchema(schema);
4961
+ }
4962
+ /**
4963
+ * Checks if a property is optional within a parent object schema.
4964
+ * A property is optional if it's not in the parent's `required` array.
4965
+ * @param propertyName - The name of the property to check
4966
+ * @param parentSchema - The parent object schema containing the property
4967
+ */
4968
+ isOptionalProperty(propertyName, parentSchema) {
4969
+ return isOptionalSchema(propertyName, parentSchema);
4970
+ }
4971
+ /**
4972
+ * Converts a Zod schema to JSON Schema using the standard-schema interface
4973
+ * and applies pre/post processing via traverse.
4673
4974
  *
4674
- * @param zodSchema - The Zod object schema to process
4675
- * @returns A JSONSchema7 object with provider-specific compatibility applied
4975
+ * Uses 'input' io mode so that fields with defaults are optional (appropriate for tool parameters).
4676
4976
  */
4677
- processToJSONSchema(zodSchema2) {
4678
- return this.processToAISDKSchema(zodSchema2).jsonSchema;
4977
+ toJSONSchema(zodSchema2) {
4978
+ const target = "draft-07";
4979
+ const standardSchema = chunkDAVEUCUM_cjs.toStandardSchema(zodSchema2);
4980
+ const jsonSchema2 = chunkDAVEUCUM_cjs.standardSchemaToJSONSchema(standardSchema, {
4981
+ target,
4982
+ io: "input"
4983
+ // Use input mode so fields with defaults are optional
4984
+ });
4985
+ (0, import_json_schema_traverse.default)(jsonSchema2, {
4986
+ cb: {
4987
+ pre: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {
4988
+ this.preProcessJSONNode(schema, parentSchema);
4989
+ },
4990
+ post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {
4991
+ this.postProcessJSONNode(schema, parentSchema);
4992
+ }
4993
+ }
4994
+ });
4995
+ return jsonSchema2;
4679
4996
  }
4680
4997
  };
4681
4998
 
4682
- // src/zodTypes.ts
4683
- function isOptional2(z11) {
4684
- return (v) => v instanceof z11["ZodOptional"];
4685
- }
4686
- function isObj2(z11) {
4687
- return (v) => v instanceof z11["ZodObject"];
4688
- }
4689
- function isNull(z11) {
4690
- return (v) => v instanceof z11["ZodNull"];
4691
- }
4692
- function isArr2(z11) {
4693
- return (v) => v instanceof z11["ZodArray"];
4694
- }
4695
- function isUnion2(z11) {
4696
- return (v) => v instanceof z11["ZodUnion"];
4697
- }
4698
- function isString2(z11) {
4699
- return (v) => v instanceof z11["ZodString"];
4700
- }
4701
- function isNumber2(z11) {
4702
- return (v) => v instanceof z11["ZodNumber"];
4703
- }
4704
- function isDate(z11) {
4705
- return (v) => v instanceof z11["ZodDate"];
4706
- }
4707
- function isDefault(z11) {
4708
- return (v) => v instanceof z11["ZodDefault"];
4709
- }
4710
- function isNullable(z11) {
4711
- return (v) => v instanceof z11["ZodNullable"];
4712
- }
4713
-
4714
4999
  // src/provider-compats/anthropic.ts
4715
5000
  var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
4716
5001
  constructor(model) {
@@ -4723,37 +5008,82 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
4723
5008
  return this.getModel().modelId.includes("claude");
4724
5009
  }
4725
5010
  processZodType(value) {
4726
- if (isOptional2(zod.z)(value)) {
4727
- const handleTypes = [
4728
- "ZodObject",
4729
- "ZodArray",
4730
- "ZodUnion",
4731
- "ZodNever",
4732
- "ZodUndefined",
4733
- "ZodTuple"
4734
- ];
5011
+ if (this.isOptional(value)) {
5012
+ const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined", "ZodTuple"];
4735
5013
  if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
4736
5014
  return this.defaultZodOptionalHandler(value, handleTypes);
4737
- } else if (isObj2(zod.z)(value)) {
5015
+ } else if (this.isObj(value)) {
4738
5016
  return this.defaultZodObjectHandler(value);
4739
- } else if (isArr2(zod.z)(value)) {
5017
+ } else if (this.isArr(value)) {
4740
5018
  return this.defaultZodArrayHandler(value, []);
4741
- } else if (isUnion2(zod.z)(value)) {
5019
+ } else if (this.isUnion(value)) {
4742
5020
  return this.defaultZodUnionHandler(value);
4743
- } else if (isString2(zod.z)(value)) {
5021
+ } else if (this.isString(value)) {
4744
5022
  if (this.getModel().modelId.includes("claude-3.5-haiku")) {
4745
5023
  return this.defaultZodStringHandler(value, ["max", "min"]);
4746
5024
  } else {
4747
5025
  return value;
4748
5026
  }
4749
5027
  }
4750
- return this.defaultUnsupportedZodTypeHandler(value, [
4751
- "ZodNever",
4752
- "ZodTuple",
4753
- "ZodUndefined"
4754
- ]);
5028
+ return this.defaultUnsupportedZodTypeHandler(value);
5029
+ }
5030
+ preProcessJSONNode(schema, _parentSchema) {
5031
+ if (isObjectSchema(schema)) {
5032
+ this.defaultObjectHandler(schema);
5033
+ } else if (isArraySchema(schema)) {
5034
+ this.defaultArrayHandler(schema);
5035
+ } else if (isStringSchema(schema)) {
5036
+ if (this.getModel().modelId.includes("claude-3.5-haiku")) {
5037
+ this.defaultStringHandler(schema);
5038
+ }
5039
+ }
5040
+ }
5041
+ postProcessJSONNode(schema) {
5042
+ if (isUnionSchema(schema)) {
5043
+ this.defaultUnionHandler(schema);
5044
+ }
5045
+ if (isObjectSchema(schema)) {
5046
+ if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
5047
+ schema.additionalProperties = true;
5048
+ }
5049
+ if ("propertyNames" in schema) {
5050
+ delete schema.propertyNames;
5051
+ }
5052
+ }
4755
5053
  }
4756
5054
  };
5055
+ function isOptional2(z10) {
5056
+ return (v) => v instanceof z10["ZodOptional"];
5057
+ }
5058
+ function isObj2(z10) {
5059
+ return (v) => v instanceof z10["ZodObject"];
5060
+ }
5061
+ function isNull(z10) {
5062
+ return (v) => v instanceof z10["ZodNull"];
5063
+ }
5064
+ function isArr2(z10) {
5065
+ return (v) => v instanceof z10["ZodArray"];
5066
+ }
5067
+ function isUnion2(z10) {
5068
+ return (v) => v instanceof z10["ZodUnion"];
5069
+ }
5070
+ function isString2(z10) {
5071
+ return (v) => v instanceof z10["ZodString"];
5072
+ }
5073
+ function isNumber2(z10) {
5074
+ return (v) => v instanceof z10["ZodNumber"];
5075
+ }
5076
+ function isDate(z10) {
5077
+ return (v) => v instanceof z10["ZodDate"];
5078
+ }
5079
+ function isDefault(z10) {
5080
+ return (v) => v instanceof z10["ZodDefault"];
5081
+ }
5082
+ function isNullable(z10) {
5083
+ return (v) => v instanceof z10["ZodNullable"];
5084
+ }
5085
+
5086
+ // src/provider-compats/deepseek.ts
4757
5087
  var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
4758
5088
  constructor(model) {
4759
5089
  super(model);
@@ -4778,6 +5108,28 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
4778
5108
  }
4779
5109
  return value;
4780
5110
  }
5111
+ preProcessJSONNode(schema, _parentSchema) {
5112
+ if (isObjectSchema(schema)) {
5113
+ this.defaultObjectHandler(schema);
5114
+ } else if (isArraySchema(schema)) {
5115
+ this.defaultArrayHandler(schema);
5116
+ } else if (isStringSchema(schema)) {
5117
+ this.defaultStringHandler(schema);
5118
+ }
5119
+ }
5120
+ postProcessJSONNode(schema, _parentSchema) {
5121
+ if (isUnionSchema(schema)) {
5122
+ this.defaultUnionHandler(schema);
5123
+ }
5124
+ if (isObjectSchema(schema)) {
5125
+ if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
5126
+ schema.additionalProperties = true;
5127
+ }
5128
+ if ("propertyNames" in schema) {
5129
+ delete schema.propertyNames;
5130
+ }
5131
+ }
5132
+ }
4781
5133
  };
4782
5134
  var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
4783
5135
  constructor(model) {
@@ -4807,6 +5159,30 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
4807
5159
  }
4808
5160
  return this.defaultUnsupportedZodTypeHandler(value);
4809
5161
  }
5162
+ preProcessJSONNode(schema, _parentSchema) {
5163
+ if (isObjectSchema(schema)) {
5164
+ this.defaultObjectHandler(schema);
5165
+ } else if (isArraySchema(schema)) {
5166
+ this.defaultArrayHandler(schema);
5167
+ } else if (isStringSchema(schema)) {
5168
+ this.defaultStringHandler(schema);
5169
+ } else if (isNumberSchema(schema)) {
5170
+ this.defaultNumberHandler(schema);
5171
+ }
5172
+ }
5173
+ postProcessJSONNode(schema, _parentSchema) {
5174
+ if (isUnionSchema(schema)) {
5175
+ this.defaultUnionHandler(schema);
5176
+ }
5177
+ if (isObjectSchema(schema)) {
5178
+ if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
5179
+ schema.additionalProperties = true;
5180
+ }
5181
+ if ("propertyNames" in schema) {
5182
+ delete schema.propertyNames;
5183
+ }
5184
+ }
5185
+ }
4810
5186
  };
4811
5187
  var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
4812
5188
  constructor(model) {
@@ -4834,6 +5210,30 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
4834
5210
  }
4835
5211
  return value;
4836
5212
  }
5213
+ preProcessJSONNode(schema, _parentSchema) {
5214
+ if (isObjectSchema(schema)) {
5215
+ this.defaultObjectHandler(schema);
5216
+ } else if (isArraySchema(schema)) {
5217
+ this.defaultArrayHandler(schema);
5218
+ } else if (isStringSchema(schema)) {
5219
+ this.defaultStringHandler(schema);
5220
+ } else if (isNumberSchema(schema)) {
5221
+ this.defaultNumberHandler(schema);
5222
+ }
5223
+ }
5224
+ postProcessJSONNode(schema, _parentSchema) {
5225
+ if (isUnionSchema(schema)) {
5226
+ this.defaultUnionHandler(schema);
5227
+ }
5228
+ if (isObjectSchema(schema)) {
5229
+ if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
5230
+ schema.additionalProperties = true;
5231
+ }
5232
+ if ("propertyNames" in schema) {
5233
+ delete schema.propertyNames;
5234
+ }
5235
+ }
5236
+ }
4837
5237
  };
4838
5238
  var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
4839
5239
  constructor(model) {
@@ -4915,6 +5315,40 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
4915
5315
  const jsonSchema2 = super.processToJSONSchema(zodSchema2);
4916
5316
  return this.fixAdditionalProperties(jsonSchema2);
4917
5317
  }
5318
+ preProcessJSONNode(schema, _parentSchema) {
5319
+ if (isObjectSchema(schema)) {
5320
+ this.defaultObjectHandler(schema);
5321
+ } else if (isArraySchema(schema)) {
5322
+ this.defaultArrayHandler(schema);
5323
+ } else if (isStringSchema(schema)) {
5324
+ const model = this.getModel();
5325
+ if (model.modelId.includes("gpt-4o-mini")) {
5326
+ if (schema.format === "emoji") {
5327
+ delete schema.format;
5328
+ }
5329
+ if (schema.pattern) {
5330
+ delete schema.pattern;
5331
+ }
5332
+ } else {
5333
+ if (schema.format === "emoji") {
5334
+ delete schema.format;
5335
+ }
5336
+ }
5337
+ }
5338
+ }
5339
+ postProcessJSONNode(schema) {
5340
+ if (isUnionSchema(schema)) {
5341
+ this.defaultUnionHandler(schema);
5342
+ }
5343
+ if (isObjectSchema(schema)) {
5344
+ if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
5345
+ schema.additionalProperties = true;
5346
+ }
5347
+ if ("propertyNames" in schema) {
5348
+ delete schema.propertyNames;
5349
+ }
5350
+ }
5351
+ }
4918
5352
  /**
4919
5353
  * Recursively fixes additionalProperties: {} to additionalProperties: true.
4920
5354
  * OpenAI requires additionalProperties to be either:
@@ -5028,6 +5462,30 @@ Argument was an "any" type, but you (the LLM) do not support "any", so it was ca
5028
5462
  }
5029
5463
  return this.defaultUnsupportedZodTypeHandler(value);
5030
5464
  }
5465
+ preProcessJSONNode(schema, _parentSchema) {
5466
+ if (isObjectSchema(schema)) {
5467
+ this.defaultObjectHandler(schema);
5468
+ } else if (isArraySchema(schema)) {
5469
+ this.defaultArrayHandler(schema);
5470
+ } else if (isNumberSchema(schema)) {
5471
+ this.defaultNumberHandler(schema);
5472
+ } else if (isStringSchema(schema)) {
5473
+ this.defaultStringHandler(schema);
5474
+ }
5475
+ }
5476
+ postProcessJSONNode(schema) {
5477
+ if (isUnionSchema(schema)) {
5478
+ this.defaultUnionHandler(schema);
5479
+ }
5480
+ if (isObjectSchema(schema)) {
5481
+ if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
5482
+ schema.additionalProperties = false;
5483
+ }
5484
+ if ("propertyNames" in schema) {
5485
+ delete schema.propertyNames;
5486
+ }
5487
+ }
5488
+ }
5031
5489
  };
5032
5490
 
5033
5491
  exports.ALL_ARRAY_CHECKS = ALL_ARRAY_CHECKS;