@mastra/schema-compat 1.1.3 → 1.2.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/CHANGELOG.md +68 -0
- package/LICENSE.md +15 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7562 -0
- package/dist/_types/@internal_ai-v6/dist/index.d.ts +449 -343
- package/dist/chunk-23HDOZLF.js +105 -0
- package/dist/chunk-23HDOZLF.js.map +1 -0
- package/dist/chunk-3MLZICLP.cjs +94 -0
- package/dist/chunk-3MLZICLP.cjs.map +1 -0
- package/dist/chunk-3QMIGINL.cjs +123 -0
- package/dist/chunk-3QMIGINL.cjs.map +1 -0
- package/dist/{chunk-4EY4LZB2.js → chunk-7ZCSAPV3.js} +76 -3
- package/dist/chunk-7ZCSAPV3.js.map +1 -0
- package/dist/chunk-FKB2Z36H.cjs +68 -0
- package/dist/chunk-FKB2Z36H.cjs.map +1 -0
- package/dist/chunk-FS3P4V5M.cjs +108 -0
- package/dist/chunk-FS3P4V5M.cjs.map +1 -0
- package/dist/chunk-I2YUBGXM.js +112 -0
- package/dist/chunk-I2YUBGXM.js.map +1 -0
- package/dist/chunk-IKQO7EW7.js +62 -0
- package/dist/chunk-IKQO7EW7.js.map +1 -0
- package/dist/chunk-K7I3YXWP.js +92 -0
- package/dist/chunk-K7I3YXWP.js.map +1 -0
- package/dist/{chunk-DGOXVQNP.js → chunk-QDRBTCDV.js} +158 -479
- package/dist/chunk-QDRBTCDV.js.map +1 -0
- package/dist/{chunk-DAVEUCUM.cjs → chunk-ROFMEFEF.cjs} +160 -488
- package/dist/chunk-ROFMEFEF.cjs.map +1 -0
- package/dist/{chunk-BOGGUXB5.cjs → chunk-UFJG5KPA.cjs} +77 -2
- package/dist/chunk-UFJG5KPA.cjs.map +1 -0
- package/dist/index.cjs +626 -337
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +580 -325
- package/dist/index.js.map +1 -1
- package/dist/json-schema/utils.d.ts +8 -0
- package/dist/json-schema/utils.d.ts.map +1 -1
- package/dist/null-to-undefined.d.ts +24 -0
- package/dist/null-to-undefined.d.ts.map +1 -0
- package/dist/provider-compats/google.d.ts +3 -0
- package/dist/provider-compats/google.d.ts.map +1 -1
- package/dist/provider-compats/openai-reasoning.d.ts +5 -5
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
- package/dist/provider-compats/openai.d.ts +8 -0
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/dist/schema-compatibility-v3.d.ts +2 -2
- package/dist/schema-compatibility-v3.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts +2 -1
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/schema.cjs +16 -4
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -1
- package/dist/schema.types.d.ts +4 -2
- package/dist/schema.types.d.ts.map +1 -1
- package/dist/standard-schema/adapters/ai-sdk.cjs +16 -0
- package/dist/standard-schema/adapters/ai-sdk.cjs.map +1 -0
- package/dist/standard-schema/adapters/ai-sdk.js +3 -0
- package/dist/standard-schema/adapters/ai-sdk.js.map +1 -0
- package/dist/standard-schema/adapters/json-schema.cjs +16 -0
- package/dist/standard-schema/adapters/json-schema.cjs.map +1 -0
- package/dist/standard-schema/adapters/json-schema.d.ts.map +1 -1
- package/dist/standard-schema/adapters/json-schema.js +3 -0
- package/dist/standard-schema/adapters/json-schema.js.map +1 -0
- package/dist/standard-schema/adapters/zod-v3.cjs +12 -0
- package/dist/standard-schema/adapters/zod-v3.cjs.map +1 -0
- package/dist/standard-schema/adapters/zod-v3.js +3 -0
- package/dist/standard-schema/adapters/zod-v3.js.map +1 -0
- package/dist/standard-schema/standard-schema.d.ts.map +1 -1
- package/dist/standard-schema-compat.d.ts +74 -0
- package/dist/standard-schema-compat.d.ts.map +1 -0
- package/dist/utils.d.ts +3 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod-to-json.cjs +10 -2
- package/dist/zod-to-json.d.ts +13 -0
- package/dist/zod-to-json.d.ts.map +1 -1
- package/dist/zod-to-json.js +1 -1
- package/package.json +41 -10
- package/dist/chunk-4EY4LZB2.js.map +0 -1
- package/dist/chunk-BOGGUXB5.cjs.map +0 -1
- package/dist/chunk-DAVEUCUM.cjs.map +0 -1
- package/dist/chunk-DGOXVQNP.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk3QMIGINL_cjs = require('./chunk-3QMIGINL.cjs');
|
|
4
|
+
var chunkUFJG5KPA_cjs = require('./chunk-UFJG5KPA.cjs');
|
|
5
|
+
var chunk3MLZICLP_cjs = require('./chunk-3MLZICLP.cjs');
|
|
5
6
|
var chunkDZUJEN5N_cjs = require('./chunk-DZUJEN5N.cjs');
|
|
7
|
+
var v3 = require('zod/v3');
|
|
6
8
|
var zod = require('zod');
|
|
7
9
|
var zodFromJsonSchema = require('zod-from-json-schema');
|
|
8
10
|
var zodFromJsonSchemaV3 = require('zod-from-json-schema-v3');
|
|
9
|
-
var v3 = require('zod/v3');
|
|
10
11
|
var v4 = require('zod/v4');
|
|
11
12
|
|
|
12
13
|
// ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
|
|
@@ -3571,7 +3572,7 @@ function trimStartOfStream() {
|
|
|
3571
3572
|
|
|
3572
3573
|
// src/utils.ts
|
|
3573
3574
|
function convertZodSchemaToAISDKSchema(zodSchema2, target = "jsonSchema7") {
|
|
3574
|
-
const jsonSchemaToUse =
|
|
3575
|
+
const jsonSchemaToUse = chunkUFJG5KPA_cjs.zodToJsonSchema(zodSchema2, target);
|
|
3575
3576
|
return jsonSchema(jsonSchemaToUse, {
|
|
3576
3577
|
validate: (value) => {
|
|
3577
3578
|
const result = zodSchema2.safeParse(value);
|
|
@@ -3606,20 +3607,29 @@ function applyCompatLayer({
|
|
|
3606
3607
|
compatLayers,
|
|
3607
3608
|
mode
|
|
3608
3609
|
}) {
|
|
3609
|
-
let zodSchema2;
|
|
3610
|
-
if (!isZodType(schema)) {
|
|
3611
|
-
zodSchema2 = convertSchemaToZod(schema);
|
|
3612
|
-
} else {
|
|
3613
|
-
zodSchema2 = schema;
|
|
3614
|
-
}
|
|
3615
|
-
for (const compat of compatLayers) {
|
|
3616
|
-
if (compat.shouldApply()) {
|
|
3617
|
-
return mode === "jsonSchema" ? compat.processToJSONSchema(zodSchema2) : compat.processToAISDKSchema(zodSchema2);
|
|
3618
|
-
}
|
|
3619
|
-
}
|
|
3620
3610
|
if (mode === "jsonSchema") {
|
|
3621
|
-
|
|
3611
|
+
const standardSchema = chunk3QMIGINL_cjs.toStandardSchema(schema);
|
|
3612
|
+
for (const compat of compatLayers) {
|
|
3613
|
+
if (compat.shouldApply()) {
|
|
3614
|
+
return compat.processToJSONSchema(standardSchema);
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
return chunk3QMIGINL_cjs.standardSchemaToJSONSchema(standardSchema);
|
|
3622
3618
|
} else {
|
|
3619
|
+
let zodSchema2;
|
|
3620
|
+
if (isZodType(schema)) {
|
|
3621
|
+
zodSchema2 = schema;
|
|
3622
|
+
} else {
|
|
3623
|
+
if (chunk3QMIGINL_cjs.isStandardSchemaWithJSON(schema)) {
|
|
3624
|
+
throw new Error("StandardSchemaWithJSON is not supported for applyCompatLayer and aiSdkSchema mode");
|
|
3625
|
+
}
|
|
3626
|
+
zodSchema2 = convertSchemaToZod(schema);
|
|
3627
|
+
}
|
|
3628
|
+
for (const compat of compatLayers) {
|
|
3629
|
+
if (compat.shouldApply()) {
|
|
3630
|
+
return compat.processToAISDKSchema(zodSchema2);
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3623
3633
|
return convertZodSchemaToAISDKSchema(zodSchema2);
|
|
3624
3634
|
}
|
|
3625
3635
|
}
|
|
@@ -3634,12 +3644,12 @@ var ALL_NUMBER_CHECKS = [
|
|
|
3634
3644
|
"multipleOf"
|
|
3635
3645
|
];
|
|
3636
3646
|
var ALL_ARRAY_CHECKS = ["min", "max", "length"];
|
|
3637
|
-
var isOptional = (v) => v instanceof
|
|
3638
|
-
var isObj = (v) => v instanceof
|
|
3639
|
-
var isArr = (v) => v instanceof
|
|
3640
|
-
var isUnion = (v) => v instanceof
|
|
3641
|
-
var isString = (v) => v instanceof
|
|
3642
|
-
var isNumber = (v) => v instanceof
|
|
3647
|
+
var isOptional = (v) => v instanceof v3.ZodOptional;
|
|
3648
|
+
var isObj = (v) => v instanceof v3.ZodObject;
|
|
3649
|
+
var isArr = (v) => v instanceof v3.ZodArray;
|
|
3650
|
+
var isUnion = (v) => v instanceof v3.ZodUnion;
|
|
3651
|
+
var isString = (v) => v instanceof v3.ZodString;
|
|
3652
|
+
var isNumber = (v) => v instanceof v3.ZodNumber;
|
|
3643
3653
|
var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
3644
3654
|
var SUPPORTED_ZOD_TYPES = [
|
|
3645
3655
|
"ZodObject",
|
|
@@ -3680,61 +3690,61 @@ var SchemaCompatLayer = class {
|
|
|
3680
3690
|
* Type guard for optional Zod types
|
|
3681
3691
|
*/
|
|
3682
3692
|
isOptional(v) {
|
|
3683
|
-
return v instanceof
|
|
3693
|
+
return v instanceof v3.ZodOptional;
|
|
3684
3694
|
}
|
|
3685
3695
|
/**
|
|
3686
3696
|
* Type guard for object Zod types
|
|
3687
3697
|
*/
|
|
3688
3698
|
isObj(v) {
|
|
3689
|
-
return v instanceof
|
|
3699
|
+
return v instanceof v3.ZodObject;
|
|
3690
3700
|
}
|
|
3691
3701
|
/**
|
|
3692
3702
|
* Type guard for null Zod types
|
|
3693
3703
|
*/
|
|
3694
3704
|
isNull(v) {
|
|
3695
|
-
return v instanceof
|
|
3705
|
+
return v instanceof v3.ZodNull;
|
|
3696
3706
|
}
|
|
3697
3707
|
/**
|
|
3698
3708
|
* Type guard for nullable Zod types
|
|
3699
3709
|
*/
|
|
3700
3710
|
isNullable(v) {
|
|
3701
|
-
return v instanceof
|
|
3711
|
+
return v instanceof v3.ZodNullable;
|
|
3702
3712
|
}
|
|
3703
3713
|
/**
|
|
3704
3714
|
* Type guard for array Zod types
|
|
3705
3715
|
*/
|
|
3706
3716
|
isArr(v) {
|
|
3707
|
-
return v instanceof
|
|
3717
|
+
return v instanceof v3.ZodArray;
|
|
3708
3718
|
}
|
|
3709
3719
|
/**
|
|
3710
3720
|
* Type guard for union Zod types
|
|
3711
3721
|
*/
|
|
3712
3722
|
isUnion(v) {
|
|
3713
|
-
return v instanceof
|
|
3723
|
+
return v instanceof v3.ZodUnion;
|
|
3714
3724
|
}
|
|
3715
3725
|
/**
|
|
3716
3726
|
* Type guard for string Zod types
|
|
3717
3727
|
*/
|
|
3718
3728
|
isString(v) {
|
|
3719
|
-
return v instanceof
|
|
3729
|
+
return v instanceof v3.ZodString;
|
|
3720
3730
|
}
|
|
3721
3731
|
/**
|
|
3722
3732
|
* Type guard for number Zod types
|
|
3723
3733
|
*/
|
|
3724
3734
|
isNumber(v) {
|
|
3725
|
-
return v instanceof
|
|
3735
|
+
return v instanceof v3.ZodNumber;
|
|
3726
3736
|
}
|
|
3727
3737
|
/**
|
|
3728
3738
|
* Type guard for date Zod types
|
|
3729
3739
|
*/
|
|
3730
3740
|
isDate(v) {
|
|
3731
|
-
return v instanceof
|
|
3741
|
+
return v instanceof v3.ZodDate;
|
|
3732
3742
|
}
|
|
3733
3743
|
/**
|
|
3734
3744
|
* Type guard for default Zod types
|
|
3735
3745
|
*/
|
|
3736
3746
|
isDefault(v) {
|
|
3737
|
-
return v instanceof
|
|
3747
|
+
return v instanceof v3.ZodDefault;
|
|
3738
3748
|
}
|
|
3739
3749
|
/**
|
|
3740
3750
|
* Determines whether this compatibility layer should be applied for the current model.
|
|
@@ -3775,11 +3785,11 @@ var SchemaCompatLayer = class {
|
|
|
3775
3785
|
acc[key] = this.processZodType(propValue);
|
|
3776
3786
|
return acc;
|
|
3777
3787
|
}, {});
|
|
3778
|
-
let result =
|
|
3788
|
+
let result = v3.z.object(processedShape);
|
|
3779
3789
|
if (value._def.unknownKeys === "strict") {
|
|
3780
3790
|
result = result.strict();
|
|
3781
3791
|
}
|
|
3782
|
-
if (value._def.catchall && !(value._def.catchall instanceof
|
|
3792
|
+
if (value._def.catchall && !(value._def.catchall instanceof v3.z.ZodNever)) {
|
|
3783
3793
|
result = result.catchall(value._def.catchall);
|
|
3784
3794
|
}
|
|
3785
3795
|
if (value.description) {
|
|
@@ -3831,7 +3841,7 @@ var SchemaCompatLayer = class {
|
|
|
3831
3841
|
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
3832
3842
|
const zodArrayDef = value._def;
|
|
3833
3843
|
const processedType = this.processZodType(zodArrayDef.type);
|
|
3834
|
-
let result =
|
|
3844
|
+
let result = v3.z.array(processedType);
|
|
3835
3845
|
const constraints = [];
|
|
3836
3846
|
if (zodArrayDef.minLength?.value !== void 0) {
|
|
3837
3847
|
if (handleChecks.includes("min")) {
|
|
@@ -3870,7 +3880,7 @@ var SchemaCompatLayer = class {
|
|
|
3870
3880
|
defaultZodUnionHandler(value) {
|
|
3871
3881
|
const processedOptions = value._def.options.map((option) => this.processZodType(option));
|
|
3872
3882
|
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
3873
|
-
let result =
|
|
3883
|
+
let result = v3.z.union(processedOptions);
|
|
3874
3884
|
if (value.description) {
|
|
3875
3885
|
result = result.describe(value.description);
|
|
3876
3886
|
}
|
|
@@ -3914,7 +3924,7 @@ var SchemaCompatLayer = class {
|
|
|
3914
3924
|
}
|
|
3915
3925
|
}
|
|
3916
3926
|
}
|
|
3917
|
-
let result =
|
|
3927
|
+
let result = v3.z.string();
|
|
3918
3928
|
for (const check of newChecks) {
|
|
3919
3929
|
result = result._addCheck(check);
|
|
3920
3930
|
}
|
|
@@ -3963,7 +3973,7 @@ var SchemaCompatLayer = class {
|
|
|
3963
3973
|
}
|
|
3964
3974
|
}
|
|
3965
3975
|
}
|
|
3966
|
-
let result =
|
|
3976
|
+
let result = v3.z.number();
|
|
3967
3977
|
for (const check of newChecks) {
|
|
3968
3978
|
switch (check.kind) {
|
|
3969
3979
|
case "int":
|
|
@@ -4010,7 +4020,7 @@ var SchemaCompatLayer = class {
|
|
|
4010
4020
|
}
|
|
4011
4021
|
}
|
|
4012
4022
|
constraints.push(`Date format is date-time`);
|
|
4013
|
-
let result =
|
|
4023
|
+
let result = v3.z.string().describe("date-time");
|
|
4014
4024
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
4015
4025
|
if (description) {
|
|
4016
4026
|
result = result.describe(description);
|
|
@@ -4519,7 +4529,7 @@ var SchemaCompatLayer2 = class {
|
|
|
4519
4529
|
};
|
|
4520
4530
|
|
|
4521
4531
|
// src/schema-compatibility.ts
|
|
4522
|
-
var import_json_schema_traverse = chunkDZUJEN5N_cjs.__toESM(
|
|
4532
|
+
var import_json_schema_traverse = chunkDZUJEN5N_cjs.__toESM(chunk3MLZICLP_cjs.require_json_schema_traverse(), 1);
|
|
4523
4533
|
|
|
4524
4534
|
// src/json-schema/utils.ts
|
|
4525
4535
|
function hasType(schema, type) {
|
|
@@ -4546,7 +4556,10 @@ function isOneOfSchema(schema) {
|
|
|
4546
4556
|
return Array.isArray(schema.oneOf) && schema.oneOf.length > 0;
|
|
4547
4557
|
}
|
|
4548
4558
|
function isUnionSchema(schema) {
|
|
4549
|
-
return isAnyOfSchema(schema) || isOneOfSchema(schema);
|
|
4559
|
+
return isAnyOfSchema(schema) || isOneOfSchema(schema) || Array.isArray(schema.type);
|
|
4560
|
+
}
|
|
4561
|
+
function isEnumSchema(schema) {
|
|
4562
|
+
return Array.isArray(schema.enum) && schema.enum.length > 0;
|
|
4550
4563
|
}
|
|
4551
4564
|
function isOptionalSchema(propertyName, parentSchema) {
|
|
4552
4565
|
if (!parentSchema.required || !Array.isArray(parentSchema.required)) {
|
|
@@ -4764,12 +4777,23 @@ var SchemaCompatLayer3 = class {
|
|
|
4764
4777
|
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
4765
4778
|
}
|
|
4766
4779
|
processToJSONSchema(zodSchema2, io = "input") {
|
|
4767
|
-
const standardSchema =
|
|
4768
|
-
|
|
4780
|
+
const standardSchema = chunk3QMIGINL_cjs.toStandardSchema(zodSchema2);
|
|
4781
|
+
const jsonSchema2 = chunk3QMIGINL_cjs.standardSchemaToJSONSchema(standardSchema, {
|
|
4769
4782
|
target: "draft-07",
|
|
4770
4783
|
io
|
|
4771
4784
|
// Use input mode so fields with defaults are optional
|
|
4772
4785
|
});
|
|
4786
|
+
(0, import_json_schema_traverse.default)(jsonSchema2, {
|
|
4787
|
+
cb: {
|
|
4788
|
+
pre: (schema) => {
|
|
4789
|
+
this.preProcessJSONNode(schema);
|
|
4790
|
+
},
|
|
4791
|
+
post: (schema) => {
|
|
4792
|
+
this.postProcessJSONNode(schema);
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
});
|
|
4796
|
+
return jsonSchema2;
|
|
4773
4797
|
}
|
|
4774
4798
|
// ==========================================
|
|
4775
4799
|
// JSON Schema Default Handlers
|
|
@@ -4825,22 +4849,23 @@ var SchemaCompatLayer3 = class {
|
|
|
4825
4849
|
constraints.push(`maximum length ${schema.maxLength}`);
|
|
4826
4850
|
delete schema.maxLength;
|
|
4827
4851
|
}
|
|
4828
|
-
|
|
4829
|
-
|
|
4852
|
+
switch (schema.format) {
|
|
4853
|
+
case "email":
|
|
4854
|
+
case "emoji":
|
|
4855
|
+
case "uri":
|
|
4856
|
+
case "uuid":
|
|
4857
|
+
case "date-time":
|
|
4858
|
+
case "date":
|
|
4859
|
+
case "time": {
|
|
4860
|
+
constraints.push(`a valid ${schema.format}`);
|
|
4861
|
+
delete schema.pattern;
|
|
4862
|
+
delete schema.format;
|
|
4863
|
+
break;
|
|
4864
|
+
}
|
|
4830
4865
|
}
|
|
4831
|
-
if (schema.
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
uri: "a valid url",
|
|
4835
|
-
url: "a valid url",
|
|
4836
|
-
uuid: "a valid uuid",
|
|
4837
|
-
"date-time": "a valid date-time",
|
|
4838
|
-
date: "a valid date",
|
|
4839
|
-
time: "a valid time"
|
|
4840
|
-
};
|
|
4841
|
-
const formatText = formatMap[schema.format] || `format: ${schema.format}`;
|
|
4842
|
-
constraints.push(formatText);
|
|
4843
|
-
delete schema.format;
|
|
4866
|
+
if (constraints.length === 0 && schema.pattern !== void 0) {
|
|
4867
|
+
constraints.push(`input must match this regex ${schema.pattern}`);
|
|
4868
|
+
delete schema.pattern;
|
|
4844
4869
|
}
|
|
4845
4870
|
if (constraints.length) {
|
|
4846
4871
|
schema.description = this.mergeParameterDescription(schema.description, constraints);
|
|
@@ -4887,16 +4912,17 @@ var SchemaCompatLayer3 = class {
|
|
|
4887
4912
|
* Processes union schemas and can convert anyOf patterns to type arrays for simple primitives.
|
|
4888
4913
|
*/
|
|
4889
4914
|
defaultUnionHandler(schema) {
|
|
4890
|
-
if (
|
|
4891
|
-
|
|
4892
|
-
if (typeof
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4915
|
+
if (Array.isArray(schema.anyOf)) {
|
|
4916
|
+
schema.anyOf = schema.anyOf.map((subSchema) => {
|
|
4917
|
+
if (typeof subSchema !== "object" || subSchema === null) {
|
|
4918
|
+
return false;
|
|
4919
|
+
}
|
|
4920
|
+
this.preProcessJSONNode(subSchema);
|
|
4921
|
+
this.postProcessJSONNode(subSchema);
|
|
4922
|
+
return subSchema;
|
|
4923
|
+
}).filter(Boolean);
|
|
4924
|
+
if (schema.anyOf.length === 1) {
|
|
4925
|
+
schema = schema.anyOf[0];
|
|
4900
4926
|
}
|
|
4901
4927
|
}
|
|
4902
4928
|
return schema;
|
|
@@ -4976,26 +5002,81 @@ var SchemaCompatLayer3 = class {
|
|
|
4976
5002
|
* Uses 'input' io mode so that fields with defaults are optional (appropriate for tool parameters).
|
|
4977
5003
|
*/
|
|
4978
5004
|
toJSONSchema(zodSchema2) {
|
|
4979
|
-
const target = "draft-07";
|
|
4980
|
-
const standardSchema =
|
|
4981
|
-
const jsonSchema2 =
|
|
5005
|
+
const target = this.getSchemaTarget() === "jsonSchema7" ? "draft-07" : this.getSchemaTarget();
|
|
5006
|
+
const standardSchema = chunk3QMIGINL_cjs.toStandardSchema(zodSchema2);
|
|
5007
|
+
const jsonSchema2 = chunk3QMIGINL_cjs.standardSchemaToJSONSchema(standardSchema, {
|
|
4982
5008
|
target,
|
|
4983
5009
|
io: "input"
|
|
4984
5010
|
// Use input mode so fields with defaults are optional
|
|
4985
5011
|
});
|
|
4986
5012
|
(0, import_json_schema_traverse.default)(jsonSchema2, {
|
|
4987
5013
|
cb: {
|
|
4988
|
-
pre: (schema
|
|
4989
|
-
this.preProcessJSONNode(schema
|
|
5014
|
+
pre: (schema) => {
|
|
5015
|
+
this.preProcessJSONNode(schema);
|
|
4990
5016
|
},
|
|
4991
|
-
post: (schema
|
|
4992
|
-
this.postProcessJSONNode(schema
|
|
5017
|
+
post: (schema) => {
|
|
5018
|
+
this.postProcessJSONNode(schema);
|
|
4993
5019
|
}
|
|
4994
5020
|
}
|
|
4995
5021
|
});
|
|
4996
5022
|
return jsonSchema2;
|
|
4997
5023
|
}
|
|
4998
5024
|
};
|
|
5025
|
+
|
|
5026
|
+
// src/null-to-undefined.ts
|
|
5027
|
+
function transformNullToUndefined(value, jsonSchema2) {
|
|
5028
|
+
if (value === null || value === void 0) {
|
|
5029
|
+
return value;
|
|
5030
|
+
}
|
|
5031
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
5032
|
+
if (Array.isArray(value) && jsonSchema2.items && typeof jsonSchema2.items === "object") {
|
|
5033
|
+
return value.map((item) => transformNullToUndefined(item, jsonSchema2.items));
|
|
5034
|
+
}
|
|
5035
|
+
return value;
|
|
5036
|
+
}
|
|
5037
|
+
const properties = jsonSchema2.properties;
|
|
5038
|
+
if (!properties) {
|
|
5039
|
+
return value;
|
|
5040
|
+
}
|
|
5041
|
+
const required = jsonSchema2.required || [];
|
|
5042
|
+
const result = {};
|
|
5043
|
+
for (const [key, val] of Object.entries(value)) {
|
|
5044
|
+
if (val === null && !required.includes(key)) {
|
|
5045
|
+
result[key] = void 0;
|
|
5046
|
+
} else if (val !== null && typeof val === "object" && properties[key]) {
|
|
5047
|
+
result[key] = transformNullToUndefined(val, properties[key]);
|
|
5048
|
+
} else {
|
|
5049
|
+
result[key] = val;
|
|
5050
|
+
}
|
|
5051
|
+
}
|
|
5052
|
+
return result;
|
|
5053
|
+
}
|
|
5054
|
+
function wrapSchemaWithNullTransform(schema) {
|
|
5055
|
+
let jsonSchema2;
|
|
5056
|
+
try {
|
|
5057
|
+
jsonSchema2 = schema["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
5058
|
+
} catch {
|
|
5059
|
+
}
|
|
5060
|
+
if (!jsonSchema2) {
|
|
5061
|
+
return schema;
|
|
5062
|
+
}
|
|
5063
|
+
const innerProps = schema["~standard"];
|
|
5064
|
+
return {
|
|
5065
|
+
"~standard": {
|
|
5066
|
+
version: innerProps.version,
|
|
5067
|
+
vendor: innerProps.vendor,
|
|
5068
|
+
types: innerProps.types,
|
|
5069
|
+
validate: (value, options) => {
|
|
5070
|
+
const transformed = transformNullToUndefined(value, jsonSchema2);
|
|
5071
|
+
return innerProps.validate(transformed, options);
|
|
5072
|
+
},
|
|
5073
|
+
jsonSchema: innerProps.jsonSchema
|
|
5074
|
+
}
|
|
5075
|
+
};
|
|
5076
|
+
}
|
|
5077
|
+
|
|
5078
|
+
// src/provider-compats/openai.ts
|
|
5079
|
+
var import_json_schema_traverse2 = chunkDZUJEN5N_cjs.__toESM(chunk3MLZICLP_cjs.require_json_schema_traverse(), 1);
|
|
4999
5080
|
function isOptional2(z11) {
|
|
5000
5081
|
return (v) => v instanceof z11["ZodOptional"];
|
|
5001
5082
|
}
|
|
@@ -5027,38 +5108,121 @@ function isNullable(z11) {
|
|
|
5027
5108
|
return (v) => v instanceof z11["ZodNullable"];
|
|
5028
5109
|
}
|
|
5029
5110
|
|
|
5030
|
-
// src/provider-compats/
|
|
5031
|
-
var
|
|
5111
|
+
// src/provider-compats/openai.ts
|
|
5112
|
+
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5032
5113
|
constructor(model) {
|
|
5033
5114
|
super(model);
|
|
5034
5115
|
}
|
|
5035
5116
|
getSchemaTarget() {
|
|
5036
|
-
return
|
|
5117
|
+
return `jsonSchema7`;
|
|
5118
|
+
}
|
|
5119
|
+
isReasoningModel() {
|
|
5120
|
+
const modelId = this.getModel().modelId;
|
|
5121
|
+
if (!modelId) return false;
|
|
5122
|
+
return modelId.includes(`o3`) || modelId.includes(`o4`) || modelId.includes(`o1`);
|
|
5037
5123
|
}
|
|
5038
5124
|
shouldApply() {
|
|
5039
|
-
|
|
5125
|
+
const model = this.getModel();
|
|
5126
|
+
if (!this.isReasoningModel() && (model.provider.includes(`openai`) || model.modelId?.includes(`openai`) || model.provider.includes(`groq`))) {
|
|
5127
|
+
return true;
|
|
5128
|
+
}
|
|
5129
|
+
return false;
|
|
5040
5130
|
}
|
|
5041
5131
|
processZodType(value) {
|
|
5042
|
-
if (
|
|
5043
|
-
const
|
|
5044
|
-
if (
|
|
5045
|
-
|
|
5046
|
-
|
|
5132
|
+
if (isOptional2(zod.z)(value)) {
|
|
5133
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5134
|
+
if (innerType) {
|
|
5135
|
+
if (isNullable(zod.z)(innerType)) {
|
|
5136
|
+
const processed = this.processZodType(innerType);
|
|
5137
|
+
return processed.transform((val) => val === null ? void 0 : val);
|
|
5138
|
+
}
|
|
5139
|
+
const processedInner = this.processZodType(innerType);
|
|
5140
|
+
return processedInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5141
|
+
}
|
|
5142
|
+
return value;
|
|
5143
|
+
} else if (isNullable(zod.z)(value)) {
|
|
5144
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5145
|
+
if (innerType) {
|
|
5146
|
+
if (isOptional2(zod.z)(innerType)) {
|
|
5147
|
+
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
5148
|
+
if (innerInnerType) {
|
|
5149
|
+
const processedInnerInner = this.processZodType(innerInnerType);
|
|
5150
|
+
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
const processedInner = this.processZodType(innerType);
|
|
5154
|
+
return processedInner.nullable();
|
|
5155
|
+
}
|
|
5156
|
+
return value;
|
|
5157
|
+
} else if (isDefault(zod.z)(value)) {
|
|
5158
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5159
|
+
const defaultValue = "_def" in value ? value._def.defaultValue : value._zod?.def?.defaultValue;
|
|
5160
|
+
if (innerType) {
|
|
5161
|
+
const processedInner = this.processZodType(innerType);
|
|
5162
|
+
return processedInner.nullable().transform((val) => {
|
|
5163
|
+
if (val === null) {
|
|
5164
|
+
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
5165
|
+
}
|
|
5166
|
+
return val;
|
|
5167
|
+
});
|
|
5168
|
+
}
|
|
5169
|
+
return value;
|
|
5170
|
+
} else if (isObj2(zod.z)(value)) {
|
|
5047
5171
|
return this.defaultZodObjectHandler(value);
|
|
5048
|
-
} else if (
|
|
5049
|
-
return this.defaultZodArrayHandler(value, []);
|
|
5050
|
-
} else if (this.isUnion(value)) {
|
|
5172
|
+
} else if (isUnion2(zod.z)(value)) {
|
|
5051
5173
|
return this.defaultZodUnionHandler(value);
|
|
5052
|
-
} else if (
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5174
|
+
} else if (isArr2(zod.z)(value)) {
|
|
5175
|
+
return this.defaultZodArrayHandler(value);
|
|
5176
|
+
} else if (isString2(zod.z)(value)) {
|
|
5177
|
+
const model = this.getModel();
|
|
5178
|
+
const checks = ["emoji"];
|
|
5179
|
+
if (model.modelId?.includes("gpt-4o-mini")) {
|
|
5180
|
+
return this.defaultZodStringHandler(value, ["emoji", "regex"]);
|
|
5057
5181
|
}
|
|
5058
|
-
|
|
5059
|
-
return zod.z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5182
|
+
return this.defaultZodStringHandler(value, checks);
|
|
5060
5183
|
}
|
|
5061
|
-
return this.defaultUnsupportedZodTypeHandler(value
|
|
5184
|
+
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
5185
|
+
"ZodNever",
|
|
5186
|
+
"ZodUndefined",
|
|
5187
|
+
"ZodTuple"
|
|
5188
|
+
]);
|
|
5189
|
+
}
|
|
5190
|
+
/**
|
|
5191
|
+
* Override to fix additionalProperties: {} which OpenAI doesn't support.
|
|
5192
|
+
* Converts empty object {} to true to preserve passthrough intent.
|
|
5193
|
+
*/
|
|
5194
|
+
processToJSONSchema(zodSchema2) {
|
|
5195
|
+
const jsonSchema2 = super.processToJSONSchema(zodSchema2);
|
|
5196
|
+
const fixedSchema = this.fixAdditionalProperties(jsonSchema2);
|
|
5197
|
+
return chunkUFJG5KPA_cjs.ensureAllPropertiesRequired(fixedSchema);
|
|
5198
|
+
}
|
|
5199
|
+
/**
|
|
5200
|
+
* Override to apply the same JSON Schema fixes (additionalProperties, required fields)
|
|
5201
|
+
* that processToJSONSchema applies. The base implementation skips JSON Schema traversal,
|
|
5202
|
+
* which causes OpenAI strict mode to reject tool schemas missing additionalProperties: false.
|
|
5203
|
+
*/
|
|
5204
|
+
processToAISDKSchema(zodSchema2) {
|
|
5205
|
+
const jsonSchemaResult = chunkUFJG5KPA_cjs.zodToJsonSchema(zodSchema2, this.getSchemaTarget());
|
|
5206
|
+
const originalJsonSchema = JSON.parse(JSON.stringify(jsonSchemaResult));
|
|
5207
|
+
(0, import_json_schema_traverse2.default)(jsonSchemaResult, {
|
|
5208
|
+
cb: {
|
|
5209
|
+
pre: (schema) => {
|
|
5210
|
+
this.preProcessJSONNode(schema);
|
|
5211
|
+
},
|
|
5212
|
+
post: (schema) => {
|
|
5213
|
+
this.postProcessJSONNode(schema);
|
|
5214
|
+
}
|
|
5215
|
+
}
|
|
5216
|
+
});
|
|
5217
|
+
const fixedSchema = this.fixAdditionalProperties(jsonSchemaResult);
|
|
5218
|
+
const finalSchema = chunkUFJG5KPA_cjs.ensureAllPropertiesRequired(fixedSchema);
|
|
5219
|
+
return jsonSchema(finalSchema, {
|
|
5220
|
+
validate: (value) => {
|
|
5221
|
+
const transformed = transformNullToUndefined(value, originalJsonSchema);
|
|
5222
|
+
const result = zodSchema2.safeParse(transformed);
|
|
5223
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
5224
|
+
}
|
|
5225
|
+
});
|
|
5062
5226
|
}
|
|
5063
5227
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5064
5228
|
if (isObjectSchema(schema)) {
|
|
@@ -5066,112 +5230,282 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5066
5230
|
} else if (isArraySchema(schema)) {
|
|
5067
5231
|
this.defaultArrayHandler(schema);
|
|
5068
5232
|
} else if (isStringSchema(schema)) {
|
|
5069
|
-
|
|
5070
|
-
|
|
5233
|
+
const model = this.getModel();
|
|
5234
|
+
if (model.modelId?.includes("gpt-4o-mini")) {
|
|
5235
|
+
if (schema.format === "emoji") {
|
|
5236
|
+
delete schema.format;
|
|
5237
|
+
}
|
|
5238
|
+
if (schema.pattern) {
|
|
5239
|
+
delete schema.pattern;
|
|
5240
|
+
}
|
|
5071
5241
|
}
|
|
5242
|
+
this.defaultStringHandler(schema);
|
|
5072
5243
|
}
|
|
5073
5244
|
}
|
|
5074
5245
|
postProcessJSONNode(schema) {
|
|
5075
5246
|
if (isUnionSchema(schema)) {
|
|
5076
5247
|
this.defaultUnionHandler(schema);
|
|
5077
5248
|
}
|
|
5249
|
+
if (schema.type === void 0 && !schema.anyOf) {
|
|
5250
|
+
let subSchema = {};
|
|
5251
|
+
for (const key of Object.keys(schema)) {
|
|
5252
|
+
subSchema[key] = schema[key];
|
|
5253
|
+
delete schema[key];
|
|
5254
|
+
}
|
|
5255
|
+
schema.anyOf = [
|
|
5256
|
+
subSchema,
|
|
5257
|
+
{
|
|
5258
|
+
type: "null"
|
|
5259
|
+
}
|
|
5260
|
+
];
|
|
5261
|
+
}
|
|
5262
|
+
if (schema.type === "object" && schema.additionalProperties === void 0) {
|
|
5263
|
+
schema.additionalProperties = false;
|
|
5264
|
+
}
|
|
5078
5265
|
if (isObjectSchema(schema)) {
|
|
5079
|
-
|
|
5080
|
-
|
|
5266
|
+
const keys = Object.keys(schema.properties || {});
|
|
5267
|
+
if (keys.length) {
|
|
5268
|
+
for (const key of keys) {
|
|
5269
|
+
if (!schema.required?.includes(key) && schema.properties?.[key]?.type) {
|
|
5270
|
+
const prop = schema.properties[key];
|
|
5271
|
+
const subSchema = {};
|
|
5272
|
+
for (const propKey of Object.keys(prop)) {
|
|
5273
|
+
if (propKey !== "anyOf") {
|
|
5274
|
+
subSchema[propKey] = prop[propKey];
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
prop.anyOf = [subSchema, { type: "null" }];
|
|
5278
|
+
for (const propKey of Object.keys(subSchema)) {
|
|
5279
|
+
delete prop[propKey];
|
|
5280
|
+
}
|
|
5281
|
+
}
|
|
5282
|
+
}
|
|
5283
|
+
schema.required = keys;
|
|
5081
5284
|
}
|
|
5082
5285
|
if ("propertyNames" in schema) {
|
|
5083
5286
|
delete schema.propertyNames;
|
|
5084
5287
|
}
|
|
5085
5288
|
}
|
|
5086
5289
|
}
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
processZodType(value) {
|
|
5099
|
-
if (isOptional2(zod.z)(value)) {
|
|
5100
|
-
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
5101
|
-
} else if (isObj2(zod.z)(value)) {
|
|
5102
|
-
return this.defaultZodObjectHandler(value);
|
|
5103
|
-
} else if (isArr2(zod.z)(value)) {
|
|
5104
|
-
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
5105
|
-
} else if (isUnion2(zod.z)(value)) {
|
|
5106
|
-
return this.defaultZodUnionHandler(value);
|
|
5107
|
-
} else if (isString2(zod.z)(value)) {
|
|
5108
|
-
return this.defaultZodStringHandler(value);
|
|
5290
|
+
/**
|
|
5291
|
+
* Recursively fixes additionalProperties: {} to additionalProperties: true.
|
|
5292
|
+
* OpenAI requires additionalProperties to be either:
|
|
5293
|
+
* - false (no additional properties allowed)
|
|
5294
|
+
* - true (any additional properties allowed)
|
|
5295
|
+
* - an object with a "type" key (typed additional properties)
|
|
5296
|
+
* An empty object {} is NOT valid.
|
|
5297
|
+
*/
|
|
5298
|
+
fixAdditionalProperties(schema) {
|
|
5299
|
+
if (typeof schema !== "object" || schema === null) {
|
|
5300
|
+
return schema;
|
|
5109
5301
|
}
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
if (isObjectSchema(schema)) {
|
|
5114
|
-
this.defaultObjectHandler(schema);
|
|
5115
|
-
} else if (isArraySchema(schema)) {
|
|
5116
|
-
this.defaultArrayHandler(schema);
|
|
5117
|
-
} else if (isStringSchema(schema)) {
|
|
5118
|
-
this.defaultStringHandler(schema);
|
|
5302
|
+
const result = { ...schema };
|
|
5303
|
+
if (result.additionalProperties !== void 0 && typeof result.additionalProperties === "object" && result.additionalProperties !== null && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length === 0) {
|
|
5304
|
+
result.additionalProperties = true;
|
|
5119
5305
|
}
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5306
|
+
if (result.properties) {
|
|
5307
|
+
result.properties = Object.fromEntries(
|
|
5308
|
+
Object.entries(result.properties).map(([key, value]) => [
|
|
5309
|
+
key,
|
|
5310
|
+
this.fixAdditionalProperties(value)
|
|
5311
|
+
])
|
|
5312
|
+
);
|
|
5124
5313
|
}
|
|
5125
|
-
if (
|
|
5126
|
-
if (
|
|
5127
|
-
|
|
5128
|
-
}
|
|
5129
|
-
|
|
5130
|
-
delete schema.propertyNames;
|
|
5314
|
+
if (result.items) {
|
|
5315
|
+
if (Array.isArray(result.items)) {
|
|
5316
|
+
result.items = result.items.map((item) => this.fixAdditionalProperties(item));
|
|
5317
|
+
} else {
|
|
5318
|
+
result.items = this.fixAdditionalProperties(result.items);
|
|
5131
5319
|
}
|
|
5132
5320
|
}
|
|
5321
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length > 0) {
|
|
5322
|
+
result.additionalProperties = this.fixAdditionalProperties(result.additionalProperties);
|
|
5323
|
+
}
|
|
5324
|
+
return result;
|
|
5133
5325
|
}
|
|
5134
5326
|
};
|
|
5135
|
-
var
|
|
5136
|
-
constructor(model) {
|
|
5137
|
-
super(model);
|
|
5138
|
-
}
|
|
5327
|
+
var OpenAIReasoningSchemaCompatLayer = class extends OpenAISchemaCompatLayer {
|
|
5139
5328
|
getSchemaTarget() {
|
|
5140
|
-
return
|
|
5329
|
+
return `openApi3`;
|
|
5141
5330
|
}
|
|
5142
5331
|
shouldApply() {
|
|
5143
|
-
|
|
5332
|
+
const model = this.getModel();
|
|
5333
|
+
if (this.isReasoningModel() && (model.provider.includes(`openai`) || model.modelId?.includes(`openai`))) {
|
|
5334
|
+
return true;
|
|
5335
|
+
}
|
|
5336
|
+
return false;
|
|
5144
5337
|
}
|
|
5145
5338
|
processZodType(value) {
|
|
5146
5339
|
if (isOptional2(zod.z)(value)) {
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5340
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5341
|
+
if (innerType) {
|
|
5342
|
+
if (isNullable(zod.z)(innerType)) {
|
|
5343
|
+
const processed = this.processZodType(innerType);
|
|
5344
|
+
return processed.transform((val) => val === null ? void 0 : val);
|
|
5345
|
+
}
|
|
5346
|
+
const processedInner = this.processZodType(innerType);
|
|
5347
|
+
return processedInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5348
|
+
}
|
|
5349
|
+
return value;
|
|
5350
|
+
} else if (isNullable(zod.z)(value)) {
|
|
5351
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5352
|
+
if (innerType && isOptional2(zod.z)(innerType)) {
|
|
5353
|
+
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
5354
|
+
if (innerInnerType) {
|
|
5355
|
+
const processedInnerInner = this.processZodType(innerInnerType);
|
|
5356
|
+
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
if (innerType) {
|
|
5360
|
+
const processedInner = this.processZodType(innerType);
|
|
5361
|
+
return processedInner.nullable();
|
|
5362
|
+
}
|
|
5363
|
+
return value;
|
|
5150
5364
|
} else if (isObj2(zod.z)(value)) {
|
|
5151
|
-
return this.defaultZodObjectHandler(value);
|
|
5365
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
5152
5366
|
} else if (isArr2(zod.z)(value)) {
|
|
5153
|
-
return this.defaultZodArrayHandler(value
|
|
5367
|
+
return this.defaultZodArrayHandler(value);
|
|
5154
5368
|
} else if (isUnion2(zod.z)(value)) {
|
|
5155
5369
|
return this.defaultZodUnionHandler(value);
|
|
5156
|
-
} else if (
|
|
5157
|
-
|
|
5370
|
+
} else if (isDefault(zod.z)(value)) {
|
|
5371
|
+
const defaultDef = value._def;
|
|
5372
|
+
const innerType = defaultDef.innerType;
|
|
5373
|
+
const defaultValue = typeof defaultDef.defaultValue === "function" ? defaultDef.defaultValue() : defaultDef.defaultValue;
|
|
5374
|
+
const constraints = [];
|
|
5375
|
+
if (defaultValue !== void 0) {
|
|
5376
|
+
constraints.push(`the default value is ${defaultValue}`);
|
|
5377
|
+
}
|
|
5378
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
5379
|
+
let result = this.processZodType(innerType);
|
|
5380
|
+
if (description) {
|
|
5381
|
+
result = result.describe(description);
|
|
5382
|
+
}
|
|
5383
|
+
return result;
|
|
5158
5384
|
} else if (isNumber2(zod.z)(value)) {
|
|
5159
5385
|
return this.defaultZodNumberHandler(value);
|
|
5386
|
+
} else if (isString2(zod.z)(value)) {
|
|
5387
|
+
return this.defaultZodStringHandler(value);
|
|
5388
|
+
} else if (isDate(zod.z)(value)) {
|
|
5389
|
+
return this.defaultZodDateHandler(value);
|
|
5390
|
+
} else if (isNull(zod.z)(value)) {
|
|
5391
|
+
return zod.z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5392
|
+
} else if (value.constructor.name === "ZodAny") {
|
|
5393
|
+
return zod.z.string().describe(
|
|
5394
|
+
(value.description ?? "") + `
|
|
5395
|
+
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
5396
|
+
);
|
|
5160
5397
|
}
|
|
5161
5398
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5162
5399
|
}
|
|
5400
|
+
processToJSONSchema(zodSchema2) {
|
|
5401
|
+
const jsonSchema2 = super.processToJSONSchema(zodSchema2);
|
|
5402
|
+
return chunkUFJG5KPA_cjs.ensureAllPropertiesRequired(jsonSchema2);
|
|
5403
|
+
}
|
|
5163
5404
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5164
5405
|
if (isObjectSchema(schema)) {
|
|
5165
5406
|
this.defaultObjectHandler(schema);
|
|
5166
5407
|
} else if (isArraySchema(schema)) {
|
|
5167
5408
|
this.defaultArrayHandler(schema);
|
|
5168
|
-
} else if (isStringSchema(schema)) {
|
|
5169
|
-
this.defaultStringHandler(schema);
|
|
5170
5409
|
} else if (isNumberSchema(schema)) {
|
|
5171
5410
|
this.defaultNumberHandler(schema);
|
|
5411
|
+
} else if (isStringSchema(schema)) {
|
|
5412
|
+
this.defaultStringHandler(schema);
|
|
5172
5413
|
}
|
|
5173
5414
|
}
|
|
5174
|
-
postProcessJSONNode(schema
|
|
5415
|
+
postProcessJSONNode(schema) {
|
|
5416
|
+
super.postProcessJSONNode(schema);
|
|
5417
|
+
if (schema.type === "object" && schema.properties !== void 0) {
|
|
5418
|
+
schema.additionalProperties = false;
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
};
|
|
5422
|
+
|
|
5423
|
+
// src/standard-schema-compat.ts
|
|
5424
|
+
function extractZodSchema(schema) {
|
|
5425
|
+
if (!isZodType(schema)) {
|
|
5426
|
+
return null;
|
|
5427
|
+
}
|
|
5428
|
+
return schema;
|
|
5429
|
+
}
|
|
5430
|
+
function applyOpenAICompatTransforms(schema, modelInfo) {
|
|
5431
|
+
const isOpenAI = modelInfo.provider?.includes("openai") || modelInfo.modelId?.includes("openai");
|
|
5432
|
+
if (!isOpenAI) {
|
|
5433
|
+
return schema;
|
|
5434
|
+
}
|
|
5435
|
+
const zodSchema2 = extractZodSchema(schema);
|
|
5436
|
+
if (!zodSchema2) {
|
|
5437
|
+
return schema;
|
|
5438
|
+
}
|
|
5439
|
+
const isReasoningModel = /^o[1-5]/.test(modelInfo.modelId);
|
|
5440
|
+
const compatLayer = isReasoningModel ? new OpenAIReasoningSchemaCompatLayer(modelInfo) : new OpenAISchemaCompatLayer(modelInfo);
|
|
5441
|
+
if (!compatLayer.shouldApply()) {
|
|
5442
|
+
return schema;
|
|
5443
|
+
}
|
|
5444
|
+
const processedZodSchema = compatLayer.processZodType(zodSchema2);
|
|
5445
|
+
return chunk3QMIGINL_cjs.toStandardSchema(processedZodSchema);
|
|
5446
|
+
}
|
|
5447
|
+
function applyOpenAICompatToTools(tools, modelInfo) {
|
|
5448
|
+
if (!tools) {
|
|
5449
|
+
return tools;
|
|
5450
|
+
}
|
|
5451
|
+
const transformedTools = {};
|
|
5452
|
+
for (const [name17, tool] of Object.entries(tools)) {
|
|
5453
|
+
if (tool.inputSchema) {
|
|
5454
|
+
const processedSchema = applyOpenAICompatTransforms(tool.inputSchema, modelInfo);
|
|
5455
|
+
transformedTools[name17] = {
|
|
5456
|
+
...tool,
|
|
5457
|
+
inputSchema: processedSchema
|
|
5458
|
+
};
|
|
5459
|
+
} else {
|
|
5460
|
+
transformedTools[name17] = tool;
|
|
5461
|
+
}
|
|
5462
|
+
}
|
|
5463
|
+
return transformedTools;
|
|
5464
|
+
}
|
|
5465
|
+
var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5466
|
+
constructor(model) {
|
|
5467
|
+
super(model);
|
|
5468
|
+
}
|
|
5469
|
+
getSchemaTarget() {
|
|
5470
|
+
return "jsonSchema7";
|
|
5471
|
+
}
|
|
5472
|
+
shouldApply() {
|
|
5473
|
+
return this.getModel().modelId.includes("claude");
|
|
5474
|
+
}
|
|
5475
|
+
processZodType(value) {
|
|
5476
|
+
if (this.isOptional(value)) {
|
|
5477
|
+
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined", "ZodTuple"];
|
|
5478
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
5479
|
+
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
5480
|
+
} else if (this.isObj(value)) {
|
|
5481
|
+
return this.defaultZodObjectHandler(value);
|
|
5482
|
+
} else if (this.isArr(value)) {
|
|
5483
|
+
return this.defaultZodArrayHandler(value, []);
|
|
5484
|
+
} else if (this.isUnion(value)) {
|
|
5485
|
+
return this.defaultZodUnionHandler(value);
|
|
5486
|
+
} else if (this.isString(value)) {
|
|
5487
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
5488
|
+
return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
5489
|
+
} else {
|
|
5490
|
+
return value;
|
|
5491
|
+
}
|
|
5492
|
+
} else if (isNull(zod.z)(value)) {
|
|
5493
|
+
return zod.z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5494
|
+
}
|
|
5495
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5496
|
+
}
|
|
5497
|
+
preProcessJSONNode(schema, _parentSchema) {
|
|
5498
|
+
if (isObjectSchema(schema)) {
|
|
5499
|
+
this.defaultObjectHandler(schema);
|
|
5500
|
+
} else if (isArraySchema(schema)) {
|
|
5501
|
+
this.defaultArrayHandler(schema);
|
|
5502
|
+
} else if (isStringSchema(schema)) {
|
|
5503
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
5504
|
+
this.defaultStringHandler(schema);
|
|
5505
|
+
}
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
postProcessJSONNode(schema) {
|
|
5175
5509
|
if (isUnionSchema(schema)) {
|
|
5176
5510
|
this.defaultUnionHandler(schema);
|
|
5177
5511
|
}
|
|
@@ -5185,7 +5519,7 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5185
5519
|
}
|
|
5186
5520
|
}
|
|
5187
5521
|
};
|
|
5188
|
-
var
|
|
5522
|
+
var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5189
5523
|
constructor(model) {
|
|
5190
5524
|
super(model);
|
|
5191
5525
|
}
|
|
@@ -5193,7 +5527,7 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5193
5527
|
return "jsonSchema7";
|
|
5194
5528
|
}
|
|
5195
5529
|
shouldApply() {
|
|
5196
|
-
return this.getModel().modelId.includes("
|
|
5530
|
+
return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
|
|
5197
5531
|
}
|
|
5198
5532
|
processZodType(value) {
|
|
5199
5533
|
if (isOptional2(zod.z)(value)) {
|
|
@@ -5204,8 +5538,6 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5204
5538
|
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
5205
5539
|
} else if (isUnion2(zod.z)(value)) {
|
|
5206
5540
|
return this.defaultZodUnionHandler(value);
|
|
5207
|
-
} else if (isNumber2(zod.z)(value)) {
|
|
5208
|
-
return this.defaultZodNumberHandler(value);
|
|
5209
5541
|
} else if (isString2(zod.z)(value)) {
|
|
5210
5542
|
return this.defaultZodStringHandler(value);
|
|
5211
5543
|
}
|
|
@@ -5218,8 +5550,6 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5218
5550
|
this.defaultArrayHandler(schema);
|
|
5219
5551
|
} else if (isStringSchema(schema)) {
|
|
5220
5552
|
this.defaultStringHandler(schema);
|
|
5221
|
-
} else if (isNumberSchema(schema)) {
|
|
5222
|
-
this.defaultNumberHandler(schema);
|
|
5223
5553
|
}
|
|
5224
5554
|
}
|
|
5225
5555
|
postProcessJSONNode(schema, _parentSchema) {
|
|
@@ -5236,85 +5566,104 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5236
5566
|
}
|
|
5237
5567
|
}
|
|
5238
5568
|
};
|
|
5239
|
-
|
|
5569
|
+
function fixNullableUnionTypes(schema) {
|
|
5570
|
+
if (typeof schema !== "object" || schema === null) {
|
|
5571
|
+
return schema;
|
|
5572
|
+
}
|
|
5573
|
+
const result = { ...schema };
|
|
5574
|
+
if (Array.isArray(result.type)) {
|
|
5575
|
+
const nonNullTypes = result.type.filter((t) => t !== "null");
|
|
5576
|
+
if (nonNullTypes.length < result.type.length) {
|
|
5577
|
+
result.nullable = true;
|
|
5578
|
+
if (nonNullTypes.length === 1) {
|
|
5579
|
+
result.type = nonNullTypes[0];
|
|
5580
|
+
} else if (nonNullTypes.length > 1) {
|
|
5581
|
+
result.type = nonNullTypes;
|
|
5582
|
+
} else {
|
|
5583
|
+
delete result.type;
|
|
5584
|
+
}
|
|
5585
|
+
}
|
|
5586
|
+
}
|
|
5587
|
+
if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {
|
|
5588
|
+
const nullSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type === "null");
|
|
5589
|
+
const otherSchema = result.anyOf.find((s) => typeof s === "object" && s !== null && s.type !== "null");
|
|
5590
|
+
if (nullSchema && otherSchema && typeof otherSchema === "object") {
|
|
5591
|
+
const { anyOf: _, ...rest } = result;
|
|
5592
|
+
const fixedOther = fixNullableUnionTypes(otherSchema);
|
|
5593
|
+
return { ...rest, ...fixedOther, nullable: true };
|
|
5594
|
+
}
|
|
5595
|
+
}
|
|
5596
|
+
if (result.properties && typeof result.properties === "object") {
|
|
5597
|
+
result.properties = Object.fromEntries(
|
|
5598
|
+
Object.entries(result.properties).map(([key, value]) => [key, fixNullableUnionTypes(value)])
|
|
5599
|
+
);
|
|
5600
|
+
}
|
|
5601
|
+
if (result.items) {
|
|
5602
|
+
if (Array.isArray(result.items)) {
|
|
5603
|
+
result.items = result.items.map((item) => fixNullableUnionTypes(item));
|
|
5604
|
+
} else {
|
|
5605
|
+
result.items = fixNullableUnionTypes(result.items);
|
|
5606
|
+
}
|
|
5607
|
+
}
|
|
5608
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object") {
|
|
5609
|
+
result.additionalProperties = fixNullableUnionTypes(result.additionalProperties);
|
|
5610
|
+
}
|
|
5611
|
+
if (result.anyOf && Array.isArray(result.anyOf)) {
|
|
5612
|
+
result.anyOf = result.anyOf.map((s) => fixNullableUnionTypes(s));
|
|
5613
|
+
}
|
|
5614
|
+
if (result.oneOf && Array.isArray(result.oneOf)) {
|
|
5615
|
+
result.oneOf = result.oneOf.map((s) => fixNullableUnionTypes(s));
|
|
5616
|
+
}
|
|
5617
|
+
if (result.allOf && Array.isArray(result.allOf)) {
|
|
5618
|
+
result.allOf = result.allOf.map((s) => fixNullableUnionTypes(s));
|
|
5619
|
+
}
|
|
5620
|
+
return result;
|
|
5621
|
+
}
|
|
5622
|
+
var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5240
5623
|
constructor(model) {
|
|
5241
5624
|
super(model);
|
|
5242
5625
|
}
|
|
5243
5626
|
getSchemaTarget() {
|
|
5244
|
-
return
|
|
5627
|
+
return "jsonSchema7";
|
|
5245
5628
|
}
|
|
5246
5629
|
shouldApply() {
|
|
5247
|
-
|
|
5248
|
-
return true;
|
|
5249
|
-
}
|
|
5250
|
-
return false;
|
|
5630
|
+
return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
|
|
5251
5631
|
}
|
|
5252
5632
|
processZodType(value) {
|
|
5253
5633
|
if (isOptional2(zod.z)(value)) {
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
}
|
|
5263
|
-
return value;
|
|
5634
|
+
return this.defaultZodOptionalHandler(value, [
|
|
5635
|
+
"ZodObject",
|
|
5636
|
+
"ZodArray",
|
|
5637
|
+
"ZodUnion",
|
|
5638
|
+
"ZodString",
|
|
5639
|
+
"ZodNumber",
|
|
5640
|
+
"ZodNullable"
|
|
5641
|
+
]);
|
|
5264
5642
|
} else if (isNullable(zod.z)(value)) {
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
5269
|
-
if (innerInnerType) {
|
|
5270
|
-
const processedInnerInner = this.processZodType(innerInnerType);
|
|
5271
|
-
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5272
|
-
}
|
|
5273
|
-
}
|
|
5274
|
-
const processedInner = this.processZodType(innerType);
|
|
5275
|
-
return processedInner.nullable();
|
|
5276
|
-
}
|
|
5277
|
-
return value;
|
|
5278
|
-
} else if (isDefault(zod.z)(value)) {
|
|
5279
|
-
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5280
|
-
const defaultValue = "_def" in value ? value._def.defaultValue : value._zod?.def?.defaultValue;
|
|
5281
|
-
if (innerType) {
|
|
5282
|
-
const processedInner = this.processZodType(innerType);
|
|
5283
|
-
return processedInner.nullable().transform((val) => {
|
|
5284
|
-
if (val === null) {
|
|
5285
|
-
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
5286
|
-
}
|
|
5287
|
-
return val;
|
|
5288
|
-
});
|
|
5289
|
-
}
|
|
5290
|
-
return value;
|
|
5643
|
+
return this.defaultZodNullableHandler(value);
|
|
5644
|
+
} else if (isNull(zod.z)(value)) {
|
|
5645
|
+
return zod.z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5291
5646
|
} else if (isObj2(zod.z)(value)) {
|
|
5292
5647
|
return this.defaultZodObjectHandler(value);
|
|
5648
|
+
} else if (isArr2(zod.z)(value)) {
|
|
5649
|
+
return this.defaultZodArrayHandler(value, []);
|
|
5293
5650
|
} else if (isUnion2(zod.z)(value)) {
|
|
5294
5651
|
return this.defaultZodUnionHandler(value);
|
|
5295
|
-
} else if (isArr2(zod.z)(value)) {
|
|
5296
|
-
return this.defaultZodArrayHandler(value);
|
|
5297
5652
|
} else if (isString2(zod.z)(value)) {
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
return this.defaultZodStringHandler(value, ["emoji", "regex"]);
|
|
5302
|
-
}
|
|
5303
|
-
return this.defaultZodStringHandler(value, checks);
|
|
5653
|
+
return this.defaultZodStringHandler(value);
|
|
5654
|
+
} else if (isNumber2(zod.z)(value)) {
|
|
5655
|
+
return this.defaultZodNumberHandler(value);
|
|
5304
5656
|
}
|
|
5305
|
-
return this.defaultUnsupportedZodTypeHandler(value
|
|
5306
|
-
"ZodNever",
|
|
5307
|
-
"ZodUndefined",
|
|
5308
|
-
"ZodTuple"
|
|
5309
|
-
]);
|
|
5657
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5310
5658
|
}
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
const
|
|
5317
|
-
|
|
5659
|
+
processToJSONSchema(zodSchema2, io = "input") {
|
|
5660
|
+
const result = super.processToJSONSchema(zodSchema2, io);
|
|
5661
|
+
return fixNullableUnionTypes(result);
|
|
5662
|
+
}
|
|
5663
|
+
processToAISDKSchema(zodSchema2) {
|
|
5664
|
+
const result = super.processToAISDKSchema(zodSchema2);
|
|
5665
|
+
const fixedJsonSchema = fixNullableUnionTypes(result.jsonSchema);
|
|
5666
|
+
return { ...result, jsonSchema: fixedJsonSchema };
|
|
5318
5667
|
}
|
|
5319
5668
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5320
5669
|
if (isObjectSchema(schema)) {
|
|
@@ -5322,22 +5671,14 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5322
5671
|
} else if (isArraySchema(schema)) {
|
|
5323
5672
|
this.defaultArrayHandler(schema);
|
|
5324
5673
|
} else if (isStringSchema(schema)) {
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
if (schema.pattern) {
|
|
5331
|
-
delete schema.pattern;
|
|
5332
|
-
}
|
|
5333
|
-
} else {
|
|
5334
|
-
if (schema.format === "emoji") {
|
|
5335
|
-
delete schema.format;
|
|
5336
|
-
}
|
|
5337
|
-
}
|
|
5674
|
+
this.defaultStringHandler(schema);
|
|
5675
|
+
} else if (isNumberSchema(schema)) {
|
|
5676
|
+
this.defaultNumberHandler(schema);
|
|
5677
|
+
} else if (isEnumSchema(schema)) {
|
|
5678
|
+
schema.type = "string";
|
|
5338
5679
|
}
|
|
5339
5680
|
}
|
|
5340
|
-
postProcessJSONNode(schema) {
|
|
5681
|
+
postProcessJSONNode(schema, _parentSchema) {
|
|
5341
5682
|
if (isUnionSchema(schema)) {
|
|
5342
5683
|
this.defaultUnionHandler(schema);
|
|
5343
5684
|
}
|
|
@@ -5350,139 +5691,51 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5350
5691
|
}
|
|
5351
5692
|
}
|
|
5352
5693
|
}
|
|
5353
|
-
/**
|
|
5354
|
-
* Recursively fixes additionalProperties: {} to additionalProperties: true.
|
|
5355
|
-
* OpenAI requires additionalProperties to be either:
|
|
5356
|
-
* - false (no additional properties allowed)
|
|
5357
|
-
* - true (any additional properties allowed)
|
|
5358
|
-
* - an object with a "type" key (typed additional properties)
|
|
5359
|
-
* An empty object {} is NOT valid.
|
|
5360
|
-
*/
|
|
5361
|
-
fixAdditionalProperties(schema) {
|
|
5362
|
-
if (typeof schema !== "object" || schema === null) {
|
|
5363
|
-
return schema;
|
|
5364
|
-
}
|
|
5365
|
-
const result = { ...schema };
|
|
5366
|
-
if (result.additionalProperties !== void 0 && typeof result.additionalProperties === "object" && result.additionalProperties !== null && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length === 0) {
|
|
5367
|
-
result.additionalProperties = true;
|
|
5368
|
-
}
|
|
5369
|
-
if (result.properties) {
|
|
5370
|
-
result.properties = Object.fromEntries(
|
|
5371
|
-
Object.entries(result.properties).map(([key, value]) => [
|
|
5372
|
-
key,
|
|
5373
|
-
this.fixAdditionalProperties(value)
|
|
5374
|
-
])
|
|
5375
|
-
);
|
|
5376
|
-
}
|
|
5377
|
-
if (result.items) {
|
|
5378
|
-
if (Array.isArray(result.items)) {
|
|
5379
|
-
result.items = result.items.map((item) => this.fixAdditionalProperties(item));
|
|
5380
|
-
} else {
|
|
5381
|
-
result.items = this.fixAdditionalProperties(result.items);
|
|
5382
|
-
}
|
|
5383
|
-
}
|
|
5384
|
-
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length > 0) {
|
|
5385
|
-
result.additionalProperties = this.fixAdditionalProperties(result.additionalProperties);
|
|
5386
|
-
}
|
|
5387
|
-
return result;
|
|
5388
|
-
}
|
|
5389
5694
|
};
|
|
5390
|
-
var
|
|
5695
|
+
var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5391
5696
|
constructor(model) {
|
|
5392
5697
|
super(model);
|
|
5393
5698
|
}
|
|
5394
5699
|
getSchemaTarget() {
|
|
5395
|
-
return
|
|
5396
|
-
}
|
|
5397
|
-
isReasoningModel() {
|
|
5398
|
-
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`) || this.getModel().modelId.includes(`o1`);
|
|
5700
|
+
return "jsonSchema7";
|
|
5399
5701
|
}
|
|
5400
5702
|
shouldApply() {
|
|
5401
|
-
|
|
5402
|
-
return true;
|
|
5403
|
-
}
|
|
5404
|
-
return false;
|
|
5703
|
+
return this.getModel().modelId.includes("meta");
|
|
5405
5704
|
}
|
|
5406
5705
|
processZodType(value) {
|
|
5407
5706
|
if (isOptional2(zod.z)(value)) {
|
|
5408
|
-
|
|
5409
|
-
if (innerType) {
|
|
5410
|
-
if (isNullable(zod.z)(innerType)) {
|
|
5411
|
-
const processed = this.processZodType(innerType);
|
|
5412
|
-
return processed.transform((val) => val === null ? void 0 : val);
|
|
5413
|
-
}
|
|
5414
|
-
const processedInner = this.processZodType(innerType);
|
|
5415
|
-
return processedInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5416
|
-
}
|
|
5417
|
-
return value;
|
|
5418
|
-
} else if (isNullable(zod.z)(value)) {
|
|
5419
|
-
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5420
|
-
if (innerType && isOptional2(zod.z)(innerType)) {
|
|
5421
|
-
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
5422
|
-
if (innerInnerType) {
|
|
5423
|
-
const processedInnerInner = this.processZodType(innerInnerType);
|
|
5424
|
-
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5425
|
-
}
|
|
5426
|
-
}
|
|
5427
|
-
if (innerType) {
|
|
5428
|
-
const processedInner = this.processZodType(innerType);
|
|
5429
|
-
return processedInner.nullable();
|
|
5430
|
-
}
|
|
5431
|
-
return value;
|
|
5707
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
5432
5708
|
} else if (isObj2(zod.z)(value)) {
|
|
5433
|
-
return this.defaultZodObjectHandler(value
|
|
5709
|
+
return this.defaultZodObjectHandler(value);
|
|
5434
5710
|
} else if (isArr2(zod.z)(value)) {
|
|
5435
|
-
return this.defaultZodArrayHandler(value);
|
|
5711
|
+
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
5436
5712
|
} else if (isUnion2(zod.z)(value)) {
|
|
5437
5713
|
return this.defaultZodUnionHandler(value);
|
|
5438
|
-
} else if (isDefault(zod.z)(value)) {
|
|
5439
|
-
const defaultDef = value._def;
|
|
5440
|
-
const innerType = defaultDef.innerType;
|
|
5441
|
-
const defaultValue = typeof defaultDef.defaultValue === "function" ? defaultDef.defaultValue() : defaultDef.defaultValue;
|
|
5442
|
-
const constraints = [];
|
|
5443
|
-
if (defaultValue !== void 0) {
|
|
5444
|
-
constraints.push(`the default value is ${defaultValue}`);
|
|
5445
|
-
}
|
|
5446
|
-
const description = this.mergeParameterDescription(value.description, constraints);
|
|
5447
|
-
let result = this.processZodType(innerType);
|
|
5448
|
-
if (description) {
|
|
5449
|
-
result = result.describe(description);
|
|
5450
|
-
}
|
|
5451
|
-
return result;
|
|
5452
5714
|
} else if (isNumber2(zod.z)(value)) {
|
|
5453
5715
|
return this.defaultZodNumberHandler(value);
|
|
5454
5716
|
} else if (isString2(zod.z)(value)) {
|
|
5455
5717
|
return this.defaultZodStringHandler(value);
|
|
5456
|
-
} else if (isDate(zod.z)(value)) {
|
|
5457
|
-
return this.defaultZodDateHandler(value);
|
|
5458
|
-
} else if (isNull(zod.z)(value)) {
|
|
5459
|
-
return zod.z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5460
|
-
} else if (value.constructor.name === "ZodAny") {
|
|
5461
|
-
return zod.z.string().describe(
|
|
5462
|
-
(value.description ?? "") + `
|
|
5463
|
-
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
5464
|
-
);
|
|
5465
5718
|
}
|
|
5466
|
-
return
|
|
5719
|
+
return value;
|
|
5467
5720
|
}
|
|
5468
5721
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5469
5722
|
if (isObjectSchema(schema)) {
|
|
5470
5723
|
this.defaultObjectHandler(schema);
|
|
5471
5724
|
} else if (isArraySchema(schema)) {
|
|
5472
5725
|
this.defaultArrayHandler(schema);
|
|
5473
|
-
} else if (isNumberSchema(schema)) {
|
|
5474
|
-
this.defaultNumberHandler(schema);
|
|
5475
5726
|
} else if (isStringSchema(schema)) {
|
|
5476
5727
|
this.defaultStringHandler(schema);
|
|
5728
|
+
} else if (isNumberSchema(schema)) {
|
|
5729
|
+
this.defaultNumberHandler(schema);
|
|
5477
5730
|
}
|
|
5478
5731
|
}
|
|
5479
|
-
postProcessJSONNode(schema) {
|
|
5732
|
+
postProcessJSONNode(schema, _parentSchema) {
|
|
5480
5733
|
if (isUnionSchema(schema)) {
|
|
5481
5734
|
this.defaultUnionHandler(schema);
|
|
5482
5735
|
}
|
|
5483
5736
|
if (isObjectSchema(schema)) {
|
|
5484
5737
|
if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
|
|
5485
|
-
schema.additionalProperties =
|
|
5738
|
+
schema.additionalProperties = true;
|
|
5486
5739
|
}
|
|
5487
5740
|
if ("propertyNames" in schema) {
|
|
5488
5741
|
delete schema.propertyNames;
|
|
@@ -5491,6 +5744,38 @@ Argument was an "any" type, but you (the LLM) do not support "any", so it was ca
|
|
|
5491
5744
|
}
|
|
5492
5745
|
};
|
|
5493
5746
|
|
|
5747
|
+
Object.defineProperty(exports, "JSON_SCHEMA_LIBRARY_OPTIONS", {
|
|
5748
|
+
enumerable: true,
|
|
5749
|
+
get: function () { return chunk3QMIGINL_cjs.JSON_SCHEMA_LIBRARY_OPTIONS; }
|
|
5750
|
+
});
|
|
5751
|
+
Object.defineProperty(exports, "isStandardJSONSchema", {
|
|
5752
|
+
enumerable: true,
|
|
5753
|
+
get: function () { return chunk3QMIGINL_cjs.isStandardJSONSchema; }
|
|
5754
|
+
});
|
|
5755
|
+
Object.defineProperty(exports, "isStandardSchema", {
|
|
5756
|
+
enumerable: true,
|
|
5757
|
+
get: function () { return chunk3QMIGINL_cjs.isStandardSchema; }
|
|
5758
|
+
});
|
|
5759
|
+
Object.defineProperty(exports, "isStandardSchemaWithJSON", {
|
|
5760
|
+
enumerable: true,
|
|
5761
|
+
get: function () { return chunk3QMIGINL_cjs.isStandardSchemaWithJSON; }
|
|
5762
|
+
});
|
|
5763
|
+
Object.defineProperty(exports, "standardSchemaToJSONSchema", {
|
|
5764
|
+
enumerable: true,
|
|
5765
|
+
get: function () { return chunk3QMIGINL_cjs.standardSchemaToJSONSchema; }
|
|
5766
|
+
});
|
|
5767
|
+
Object.defineProperty(exports, "toStandardSchema", {
|
|
5768
|
+
enumerable: true,
|
|
5769
|
+
get: function () { return chunk3QMIGINL_cjs.toStandardSchema; }
|
|
5770
|
+
});
|
|
5771
|
+
Object.defineProperty(exports, "ensureAllPropertiesRequired", {
|
|
5772
|
+
enumerable: true,
|
|
5773
|
+
get: function () { return chunkUFJG5KPA_cjs.ensureAllPropertiesRequired; }
|
|
5774
|
+
});
|
|
5775
|
+
Object.defineProperty(exports, "prepareJsonSchemaForOpenAIStrictMode", {
|
|
5776
|
+
enumerable: true,
|
|
5777
|
+
get: function () { return chunkUFJG5KPA_cjs.prepareJsonSchemaForOpenAIStrictMode; }
|
|
5778
|
+
});
|
|
5494
5779
|
exports.ALL_ARRAY_CHECKS = ALL_ARRAY_CHECKS;
|
|
5495
5780
|
exports.ALL_NUMBER_CHECKS = ALL_NUMBER_CHECKS;
|
|
5496
5781
|
exports.ALL_STRING_CHECKS = ALL_STRING_CHECKS;
|
|
@@ -5507,8 +5792,11 @@ exports.SchemaCompatLayerV3 = SchemaCompatLayer;
|
|
|
5507
5792
|
exports.SchemaCompatLayerV4 = SchemaCompatLayer2;
|
|
5508
5793
|
exports.UNSUPPORTED_ZOD_TYPES = UNSUPPORTED_ZOD_TYPES;
|
|
5509
5794
|
exports.applyCompatLayer = applyCompatLayer;
|
|
5795
|
+
exports.applyOpenAICompatToTools = applyOpenAICompatToTools;
|
|
5796
|
+
exports.applyOpenAICompatTransforms = applyOpenAICompatTransforms;
|
|
5510
5797
|
exports.convertSchemaToZod = convertSchemaToZod;
|
|
5511
5798
|
exports.convertZodSchemaToAISDKSchema = convertZodSchemaToAISDKSchema;
|
|
5799
|
+
exports.extractZodSchema = extractZodSchema;
|
|
5512
5800
|
exports.isArr = isArr;
|
|
5513
5801
|
exports.isNumber = isNumber;
|
|
5514
5802
|
exports.isObj = isObj;
|
|
@@ -5517,5 +5805,6 @@ exports.isString = isString;
|
|
|
5517
5805
|
exports.isUnion = isUnion;
|
|
5518
5806
|
exports.isZodType = isZodType;
|
|
5519
5807
|
exports.jsonSchema = jsonSchema;
|
|
5808
|
+
exports.wrapSchemaWithNullTransform = wrapSchemaWithNullTransform;
|
|
5520
5809
|
//# sourceMappingURL=index.cjs.map
|
|
5521
5810
|
//# sourceMappingURL=index.cjs.map
|