@mastra/schema-compat 1.2.4 → 1.2.5
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 +12 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +33 -46
- package/dist/_types/@internal_ai-v6/dist/index.d.ts +677 -122
- package/dist/index.cjs +161 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +163 -3
- package/dist/index.js.map +1 -1
- package/dist/json-schema/utils.d.ts +6 -0
- package/dist/json-schema/utils.d.ts.map +1 -1
- package/dist/json-schema.d.ts +2 -2
- package/dist/provider-compats/anthropic.d.ts.map +1 -1
- package/dist/provider-compats/deepseek.d.ts.map +1 -1
- package/dist/provider-compats/google.d.ts.map +1 -1
- package/dist/provider-compats/meta.d.ts.map +1 -1
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/dist/schema-compatibility-v3.d.ts +16 -1
- package/dist/schema-compatibility-v3.d.ts.map +1 -1
- package/dist/schema-compatibility-v4.d.ts +15 -1
- package/dist/schema-compatibility-v4.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts +10 -0
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/zodTypes.d.ts +2 -0
- package/dist/zodTypes.d.ts.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -4,13 +4,13 @@ import { zodToJsonSchema, ensureAllPropertiesRequired } from './chunk-7ZCSAPV3.j
|
|
|
4
4
|
export { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode } from './chunk-7ZCSAPV3.js';
|
|
5
5
|
import { require_json_schema_traverse } from './chunk-K7I3YXWP.js';
|
|
6
6
|
import { __toESM } from './chunk-5WRI5ZAA.js';
|
|
7
|
-
import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodNull, ZodNullable, ZodDate, ZodDefault, z as z$1, ZodFirstPartyTypeKind } from 'zod/v3';
|
|
7
|
+
import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodNull, ZodNullable, ZodDate, ZodDefault, ZodIntersection, z as z$1, ZodFirstPartyTypeKind } from 'zod/v3';
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { convertJsonSchemaToZod } from 'zod-from-json-schema';
|
|
10
10
|
import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from 'zod-from-json-schema-v3';
|
|
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, z as z$2 } from 'zod/v4';
|
|
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-
|
|
13
|
+
// ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
|
|
14
14
|
var __create = Object.create;
|
|
15
15
|
var __defProp = Object.defineProperty;
|
|
16
16
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -3746,6 +3746,12 @@ var SchemaCompatLayer = class {
|
|
|
3746
3746
|
isDefault(v) {
|
|
3747
3747
|
return v instanceof ZodDefault;
|
|
3748
3748
|
}
|
|
3749
|
+
/**
|
|
3750
|
+
* Type guard for intersection Zod types
|
|
3751
|
+
*/
|
|
3752
|
+
isIntersection(v) {
|
|
3753
|
+
return v instanceof ZodIntersection;
|
|
3754
|
+
}
|
|
3749
3755
|
/**
|
|
3750
3756
|
* Determines whether this compatibility layer should be applied for the current model.
|
|
3751
3757
|
*
|
|
@@ -4055,6 +4061,36 @@ var SchemaCompatLayer = class {
|
|
|
4055
4061
|
return value;
|
|
4056
4062
|
}
|
|
4057
4063
|
}
|
|
4064
|
+
/**
|
|
4065
|
+
* Recursively collects leaf types from a ZodIntersection tree.
|
|
4066
|
+
*/
|
|
4067
|
+
collectIntersectionLeaves(value) {
|
|
4068
|
+
if (value instanceof ZodIntersection) {
|
|
4069
|
+
return [...this.collectIntersectionLeaves(value._def.left), ...this.collectIntersectionLeaves(value._def.right)];
|
|
4070
|
+
}
|
|
4071
|
+
return [value];
|
|
4072
|
+
}
|
|
4073
|
+
/**
|
|
4074
|
+
* Default handler for Zod intersection types.
|
|
4075
|
+
* Flattens the intersection tree and merges object shapes into a single z.object().
|
|
4076
|
+
* Falls back to z.any() for non-object intersections.
|
|
4077
|
+
*/
|
|
4078
|
+
defaultZodIntersectionHandler(value) {
|
|
4079
|
+
const leaves = this.collectIntersectionLeaves(value);
|
|
4080
|
+
const processed = leaves.map((leaf) => this.processZodType(leaf));
|
|
4081
|
+
if (processed.every((p) => p instanceof ZodObject)) {
|
|
4082
|
+
const mergedShape = {};
|
|
4083
|
+
for (const obj of processed) {
|
|
4084
|
+
Object.assign(mergedShape, obj.shape);
|
|
4085
|
+
}
|
|
4086
|
+
let result = z$1.object(mergedShape);
|
|
4087
|
+
if (value.description) {
|
|
4088
|
+
result = result.describe(value.description);
|
|
4089
|
+
}
|
|
4090
|
+
return result;
|
|
4091
|
+
}
|
|
4092
|
+
return z$1.any().describe(value.description || "intersection type");
|
|
4093
|
+
}
|
|
4058
4094
|
/**
|
|
4059
4095
|
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
4060
4096
|
*
|
|
@@ -4183,6 +4219,12 @@ var SchemaCompatLayer2 = class {
|
|
|
4183
4219
|
isDefault(v) {
|
|
4184
4220
|
return v instanceof ZodDefault$1;
|
|
4185
4221
|
}
|
|
4222
|
+
/**
|
|
4223
|
+
* Type guard for intersection Zod types
|
|
4224
|
+
*/
|
|
4225
|
+
isIntersection(v) {
|
|
4226
|
+
return v instanceof ZodIntersection$1;
|
|
4227
|
+
}
|
|
4186
4228
|
/**
|
|
4187
4229
|
* Determines whether this compatibility layer should be applied for the current model.
|
|
4188
4230
|
*
|
|
@@ -4507,6 +4549,44 @@ var SchemaCompatLayer2 = class {
|
|
|
4507
4549
|
return value;
|
|
4508
4550
|
}
|
|
4509
4551
|
}
|
|
4552
|
+
/**
|
|
4553
|
+
* Recursively collects leaf types from a ZodIntersection tree.
|
|
4554
|
+
*/
|
|
4555
|
+
collectIntersectionLeaves(value) {
|
|
4556
|
+
if (value instanceof ZodIntersection$1) {
|
|
4557
|
+
return [
|
|
4558
|
+
...this.collectIntersectionLeaves(value._zod.def.left),
|
|
4559
|
+
...this.collectIntersectionLeaves(value._zod.def.right)
|
|
4560
|
+
];
|
|
4561
|
+
}
|
|
4562
|
+
return [value];
|
|
4563
|
+
}
|
|
4564
|
+
/**
|
|
4565
|
+
* Default handler for Zod intersection types.
|
|
4566
|
+
* Flattens the intersection tree and merges object shapes into a single z.object().
|
|
4567
|
+
* Falls back to z.any() for non-object intersections.
|
|
4568
|
+
*/
|
|
4569
|
+
defaultZodIntersectionHandler(value) {
|
|
4570
|
+
const leaves = this.collectIntersectionLeaves(value);
|
|
4571
|
+
const processed = leaves.map((leaf) => this.processZodType(leaf));
|
|
4572
|
+
if (processed.every((p) => p instanceof ZodObject$1)) {
|
|
4573
|
+
const mergedShape = {};
|
|
4574
|
+
for (const obj of processed) {
|
|
4575
|
+
for (const [key, field] of Object.entries(obj.shape)) {
|
|
4576
|
+
if (key in mergedShape) {
|
|
4577
|
+
throw new Error("Cannot flatten intersections with overlapping keys");
|
|
4578
|
+
}
|
|
4579
|
+
mergedShape[key] = field;
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
let result = z$2.object(mergedShape);
|
|
4583
|
+
if (value.description) {
|
|
4584
|
+
result = result.describe(value.description);
|
|
4585
|
+
}
|
|
4586
|
+
return result;
|
|
4587
|
+
}
|
|
4588
|
+
return z$2.any().describe(value.description || "intersection type");
|
|
4589
|
+
}
|
|
4510
4590
|
/**
|
|
4511
4591
|
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
4512
4592
|
*
|
|
@@ -4561,6 +4641,9 @@ function isUnionSchema(schema) {
|
|
|
4561
4641
|
function isEnumSchema(schema) {
|
|
4562
4642
|
return Array.isArray(schema.enum) && schema.enum.length > 0;
|
|
4563
4643
|
}
|
|
4644
|
+
function isAllOfSchema(schema) {
|
|
4645
|
+
return Array.isArray(schema.allOf) && schema.allOf.length > 0;
|
|
4646
|
+
}
|
|
4564
4647
|
function isOptionalSchema(propertyName, parentSchema) {
|
|
4565
4648
|
if (!parentSchema.required || !Array.isArray(parentSchema.required)) {
|
|
4566
4649
|
return true;
|
|
@@ -4668,6 +4751,13 @@ var SchemaCompatLayer3 = class {
|
|
|
4668
4751
|
return this.v3Layer.isDefault(v);
|
|
4669
4752
|
}
|
|
4670
4753
|
}
|
|
4754
|
+
isIntersection(v) {
|
|
4755
|
+
if ("_zod" in v) {
|
|
4756
|
+
return this.v4Layer.isIntersection(v);
|
|
4757
|
+
} else {
|
|
4758
|
+
return this.v3Layer.isIntersection(v);
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4671
4761
|
preProcessJSONNode(_schema, _parentSchema) {
|
|
4672
4762
|
}
|
|
4673
4763
|
postProcessJSONNode(_schema, _parentSchema) {
|
|
@@ -4772,6 +4862,13 @@ var SchemaCompatLayer3 = class {
|
|
|
4772
4862
|
);
|
|
4773
4863
|
}
|
|
4774
4864
|
}
|
|
4865
|
+
defaultZodIntersectionHandler(value) {
|
|
4866
|
+
if ("_zod" in value) {
|
|
4867
|
+
return this.v4Layer.defaultZodIntersectionHandler(value);
|
|
4868
|
+
} else {
|
|
4869
|
+
return this.v3Layer.defaultZodIntersectionHandler(value);
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4775
4872
|
processToAISDKSchema(zodSchema2) {
|
|
4776
4873
|
const processedSchema = this.processZodType(zodSchema2);
|
|
4777
4874
|
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
@@ -4927,6 +5024,31 @@ var SchemaCompatLayer3 = class {
|
|
|
4927
5024
|
}
|
|
4928
5025
|
return schema;
|
|
4929
5026
|
}
|
|
5027
|
+
/**
|
|
5028
|
+
* Default handler for JSON Schema allOf (intersection) types.
|
|
5029
|
+
* Flattens allOf sub-schemas by merging properties and required arrays into a single object schema.
|
|
5030
|
+
*/
|
|
5031
|
+
defaultAllOfHandler(schema) {
|
|
5032
|
+
if (!schema.allOf || !Array.isArray(schema.allOf)) return schema;
|
|
5033
|
+
const mergedProperties = {};
|
|
5034
|
+
const mergedRequired = [];
|
|
5035
|
+
for (const subSchema of schema.allOf) {
|
|
5036
|
+
if (subSchema.properties) {
|
|
5037
|
+
Object.assign(mergedProperties, subSchema.properties);
|
|
5038
|
+
}
|
|
5039
|
+
if (Array.isArray(subSchema.required)) {
|
|
5040
|
+
mergedRequired.push(...subSchema.required);
|
|
5041
|
+
}
|
|
5042
|
+
}
|
|
5043
|
+
delete schema.allOf;
|
|
5044
|
+
schema.type = "object";
|
|
5045
|
+
schema.properties = mergedProperties;
|
|
5046
|
+
if (mergedRequired.length > 0) {
|
|
5047
|
+
schema.required = [...new Set(mergedRequired)];
|
|
5048
|
+
}
|
|
5049
|
+
schema.additionalProperties = false;
|
|
5050
|
+
return schema;
|
|
5051
|
+
}
|
|
4930
5052
|
/**
|
|
4931
5053
|
* Default handler for JSON Schema nullable types.
|
|
4932
5054
|
* Ensures nullable types are represented correctly.
|
|
@@ -4986,6 +5108,9 @@ var SchemaCompatLayer3 = class {
|
|
|
4986
5108
|
isUnionSchema(schema) {
|
|
4987
5109
|
return isUnionSchema(schema);
|
|
4988
5110
|
}
|
|
5111
|
+
isAllOfSchema(schema) {
|
|
5112
|
+
return isAllOfSchema(schema);
|
|
5113
|
+
}
|
|
4989
5114
|
/**
|
|
4990
5115
|
* Checks if a property is optional within a parent object schema.
|
|
4991
5116
|
* A property is optional if it's not in the parent's `required` array.
|
|
@@ -5107,6 +5232,9 @@ function isDefault(z11) {
|
|
|
5107
5232
|
function isNullable(z11) {
|
|
5108
5233
|
return (v) => v instanceof z11["ZodNullable"];
|
|
5109
5234
|
}
|
|
5235
|
+
function isIntersection(z11) {
|
|
5236
|
+
return (v) => v instanceof z11["ZodIntersection"];
|
|
5237
|
+
}
|
|
5110
5238
|
|
|
5111
5239
|
// src/provider-compats/openai.ts
|
|
5112
5240
|
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
@@ -5181,6 +5309,9 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5181
5309
|
}
|
|
5182
5310
|
return this.defaultZodStringHandler(value, checks);
|
|
5183
5311
|
}
|
|
5312
|
+
if (isIntersection(z)(value)) {
|
|
5313
|
+
return this.defaultZodIntersectionHandler(value);
|
|
5314
|
+
}
|
|
5184
5315
|
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
5185
5316
|
"ZodNever",
|
|
5186
5317
|
"ZodUndefined",
|
|
@@ -5225,6 +5356,9 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5225
5356
|
});
|
|
5226
5357
|
}
|
|
5227
5358
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5359
|
+
if (isAllOfSchema(schema)) {
|
|
5360
|
+
this.defaultAllOfHandler(schema);
|
|
5361
|
+
}
|
|
5228
5362
|
if (isObjectSchema(schema)) {
|
|
5229
5363
|
this.defaultObjectHandler(schema);
|
|
5230
5364
|
} else if (isArraySchema(schema)) {
|
|
@@ -5395,6 +5529,9 @@ var OpenAIReasoningSchemaCompatLayer = class extends OpenAISchemaCompatLayer {
|
|
|
5395
5529
|
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
5396
5530
|
);
|
|
5397
5531
|
}
|
|
5532
|
+
if (isIntersection(z)(value)) {
|
|
5533
|
+
return this.defaultZodIntersectionHandler(value);
|
|
5534
|
+
}
|
|
5398
5535
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5399
5536
|
}
|
|
5400
5537
|
processToJSONSchema(zodSchema2) {
|
|
@@ -5402,6 +5539,9 @@ Argument was an "any" type, but you (the LLM) do not support "any", so it was ca
|
|
|
5402
5539
|
return ensureAllPropertiesRequired(jsonSchema2);
|
|
5403
5540
|
}
|
|
5404
5541
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5542
|
+
if (isAllOfSchema(schema)) {
|
|
5543
|
+
this.defaultAllOfHandler(schema);
|
|
5544
|
+
}
|
|
5405
5545
|
if (isObjectSchema(schema)) {
|
|
5406
5546
|
this.defaultObjectHandler(schema);
|
|
5407
5547
|
} else if (isArraySchema(schema)) {
|
|
@@ -5491,10 +5631,15 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5491
5631
|
}
|
|
5492
5632
|
} else if (isNull(z)(value)) {
|
|
5493
5633
|
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5634
|
+
} else if (isIntersection(z)(value)) {
|
|
5635
|
+
return this.defaultZodIntersectionHandler(value);
|
|
5494
5636
|
}
|
|
5495
5637
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5496
5638
|
}
|
|
5497
5639
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5640
|
+
if (isAllOfSchema(schema)) {
|
|
5641
|
+
this.defaultAllOfHandler(schema);
|
|
5642
|
+
}
|
|
5498
5643
|
if (isObjectSchema(schema)) {
|
|
5499
5644
|
this.defaultObjectHandler(schema);
|
|
5500
5645
|
} else if (isArraySchema(schema)) {
|
|
@@ -5540,10 +5685,15 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5540
5685
|
return this.defaultZodUnionHandler(value);
|
|
5541
5686
|
} else if (isString2(z)(value)) {
|
|
5542
5687
|
return this.defaultZodStringHandler(value);
|
|
5688
|
+
} else if (isIntersection(z)(value)) {
|
|
5689
|
+
return this.defaultZodIntersectionHandler(value);
|
|
5543
5690
|
}
|
|
5544
5691
|
return value;
|
|
5545
5692
|
}
|
|
5546
5693
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5694
|
+
if (isAllOfSchema(schema)) {
|
|
5695
|
+
this.defaultAllOfHandler(schema);
|
|
5696
|
+
}
|
|
5547
5697
|
if (isObjectSchema(schema)) {
|
|
5548
5698
|
this.defaultObjectHandler(schema);
|
|
5549
5699
|
} else if (isArraySchema(schema)) {
|
|
@@ -5653,6 +5803,8 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5653
5803
|
return this.defaultZodStringHandler(value);
|
|
5654
5804
|
} else if (isNumber2(z)(value)) {
|
|
5655
5805
|
return this.defaultZodNumberHandler(value);
|
|
5806
|
+
} else if (isIntersection(z)(value)) {
|
|
5807
|
+
return this.defaultZodIntersectionHandler(value);
|
|
5656
5808
|
}
|
|
5657
5809
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5658
5810
|
}
|
|
@@ -5666,6 +5818,9 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5666
5818
|
return { ...result, jsonSchema: fixedJsonSchema };
|
|
5667
5819
|
}
|
|
5668
5820
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5821
|
+
if (isAllOfSchema(schema)) {
|
|
5822
|
+
this.defaultAllOfHandler(schema);
|
|
5823
|
+
}
|
|
5669
5824
|
if (isObjectSchema(schema)) {
|
|
5670
5825
|
this.defaultObjectHandler(schema);
|
|
5671
5826
|
} else if (isArraySchema(schema)) {
|
|
@@ -5715,10 +5870,15 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5715
5870
|
return this.defaultZodNumberHandler(value);
|
|
5716
5871
|
} else if (isString2(z)(value)) {
|
|
5717
5872
|
return this.defaultZodStringHandler(value);
|
|
5873
|
+
} else if (isIntersection(z)(value)) {
|
|
5874
|
+
return this.defaultZodIntersectionHandler(value);
|
|
5718
5875
|
}
|
|
5719
5876
|
return value;
|
|
5720
5877
|
}
|
|
5721
5878
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5879
|
+
if (isAllOfSchema(schema)) {
|
|
5880
|
+
this.defaultAllOfHandler(schema);
|
|
5881
|
+
}
|
|
5722
5882
|
if (isObjectSchema(schema)) {
|
|
5723
5883
|
this.defaultObjectHandler(schema);
|
|
5724
5884
|
} else if (isArraySchema(schema)) {
|