@mastra/schema-compat 1.2.9 → 1.2.10-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.
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { convertJsonSchemaToZod } from 'zod-from-json-schema';
10
10
  import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from 'zod-from-json-schema-v3';
11
11
  import { ZodOptional as ZodOptional$1, ZodObject as ZodObject$1, ZodNull as ZodNull$1, ZodNullable as ZodNullable$1, ZodArray as ZodArray$1, ZodUnion as ZodUnion$1, ZodString as ZodString$1, ZodNumber as ZodNumber$1, ZodDate as ZodDate$1, ZodDefault as ZodDefault$1, ZodIntersection as ZodIntersection$1, z as z$2 } from 'zod/v4';
12
12
 
13
- // ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
13
+ // ../_vendored/ai_v4/dist/chunk-HB6FLTHO.js
14
14
  var __create = Object.create;
15
15
  var __defProp = Object.defineProperty;
16
16
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5905,56 +5905,62 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
5905
5905
  return schema;
5906
5906
  }
5907
5907
  };
5908
- function fixNullableUnionTypes(schema) {
5908
+ function fixAISDKNullableUnionTypes(schema) {
5909
5909
  if (typeof schema !== "object" || schema === null) {
5910
5910
  return schema;
5911
5911
  }
5912
5912
  const result = { ...schema };
5913
5913
  if (Array.isArray(result.type)) {
5914
5914
  const nonNullTypes = result.type.filter((t) => t !== "null");
5915
- if (nonNullTypes.length < result.type.length) {
5915
+ if (nonNullTypes.length === 1) {
5916
+ result.type = nonNullTypes[0];
5916
5917
  result.nullable = true;
5917
- if (nonNullTypes.length === 1) {
5918
- result.type = nonNullTypes[0];
5919
- } else if (nonNullTypes.length > 1) {
5920
- result.type = nonNullTypes;
5921
- } else {
5922
- delete result.type;
5923
- }
5918
+ } else {
5919
+ delete result.type;
5920
+ delete result.nullable;
5924
5921
  }
5925
5922
  }
5926
- if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {
5923
+ if (Array.isArray(result.enum) && result.enum.some((value) => typeof value !== "string")) {
5924
+ delete result.enum;
5925
+ }
5926
+ if ("const" in result && typeof result.const !== "string") {
5927
+ delete result.const;
5928
+ }
5929
+ if (result.anyOf && Array.isArray(result.anyOf)) {
5927
5930
  const nullSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type === "null");
5928
- const otherSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type !== "null");
5929
- if (nullSchema && otherSchema && typeof otherSchema === "object") {
5931
+ const nonNullSchemas = result.anyOf.filter((s) => !(typeof s === "object" && s !== null && s.type === "null"));
5932
+ if (nullSchema) {
5930
5933
  const { anyOf: _, ...rest } = result;
5931
- const fixedOther = fixNullableUnionTypes(otherSchema);
5932
- return { ...rest, ...fixedOther, nullable: true };
5934
+ if (nonNullSchemas.length === 1 && typeof nonNullSchemas[0] === "object" && nonNullSchemas[0] !== null) {
5935
+ const fixedOther = fixAISDKNullableUnionTypes(nonNullSchemas[0]);
5936
+ return fixedOther.type ? { ...rest, ...fixedOther, nullable: true } : { ...rest, ...fixedOther };
5937
+ }
5938
+ return rest;
5933
5939
  }
5934
5940
  }
5935
5941
  if (result.properties && typeof result.properties === "object") {
5936
5942
  result.properties = Object.fromEntries(
5937
- Object.entries(result.properties).map(([key, value]) => [key, fixNullableUnionTypes(value)])
5943
+ Object.entries(result.properties).map(([key, value]) => [key, fixAISDKNullableUnionTypes(value)])
5938
5944
  );
5939
5945
  }
5940
5946
  if (result.items) {
5941
5947
  if (Array.isArray(result.items)) {
5942
- result.items = result.items.map((item) => fixNullableUnionTypes(item));
5948
+ result.items = result.items.map((item) => fixAISDKNullableUnionTypes(item));
5943
5949
  } else {
5944
- result.items = fixNullableUnionTypes(result.items);
5950
+ result.items = fixAISDKNullableUnionTypes(result.items);
5945
5951
  }
5946
5952
  }
5947
5953
  if (result.additionalProperties && typeof result.additionalProperties === "object") {
5948
- result.additionalProperties = fixNullableUnionTypes(result.additionalProperties);
5954
+ result.additionalProperties = fixAISDKNullableUnionTypes(result.additionalProperties);
5949
5955
  }
5950
5956
  if (result.anyOf && Array.isArray(result.anyOf)) {
5951
- result.anyOf = result.anyOf.map((s) => fixNullableUnionTypes(s));
5957
+ result.anyOf = result.anyOf.map((s) => fixAISDKNullableUnionTypes(s));
5952
5958
  }
5953
5959
  if (result.oneOf && Array.isArray(result.oneOf)) {
5954
- result.oneOf = result.oneOf.map((s) => fixNullableUnionTypes(s));
5960
+ result.oneOf = result.oneOf.map((s) => fixAISDKNullableUnionTypes(s));
5955
5961
  }
5956
5962
  if (result.allOf && Array.isArray(result.allOf)) {
5957
- result.allOf = result.allOf.map((s) => fixNullableUnionTypes(s));
5963
+ result.allOf = result.allOf.map((s) => fixAISDKNullableUnionTypes(s));
5958
5964
  }
5959
5965
  if (result.anyOf && Array.isArray(result.anyOf)) {
5960
5966
  if (result.description) {
@@ -6007,15 +6013,13 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
6007
6013
  }
6008
6014
  return this.defaultUnsupportedZodTypeHandler(value);
6009
6015
  }
6010
- // public processToJSONSchema(zodSchema: PublicSchema<any>, io?: 'input' | 'output'): JSONSchema7 {
6011
- // const result = super.processToJSONSchema(zodSchema, io);
6012
- // // Fix union type arrays that Gemini doesn't support
6013
- // return fixNullableUnionTypes(result as Record<string, any>) as JSONSchema7;
6014
- // }
6016
+ processToJSONSchema(schema, io) {
6017
+ return super.processToJSONSchema(schema, io);
6018
+ }
6015
6019
  processToAISDKSchema(zodSchema2) {
6016
6020
  const compat = this.processToCompatSchema(zodSchema2);
6017
6021
  const transformedJsonSchema = standardSchemaToJSONSchema(compat);
6018
- const fixedJsonSchema = fixNullableUnionTypes(transformedJsonSchema);
6022
+ const fixedJsonSchema = fixAISDKNullableUnionTypes(transformedJsonSchema);
6019
6023
  return jsonSchema(fixedJsonSchema, {
6020
6024
  validate: (value) => {
6021
6025
  const transformed = this.#traverse(value, fixedJsonSchema);