@mastra/schema-compat 1.1.3 → 1.2.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.
- package/CHANGELOG.md +34 -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.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { toStandardSchema, standardSchemaToJSONSchema, isStandardSchemaWithJSON } from './chunk-I2YUBGXM.js';
|
|
2
|
+
export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema } from './chunk-I2YUBGXM.js';
|
|
3
|
+
import { zodToJsonSchema, ensureAllPropertiesRequired } from './chunk-7ZCSAPV3.js';
|
|
4
|
+
export { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode } from './chunk-7ZCSAPV3.js';
|
|
5
|
+
import { require_json_schema_traverse } from './chunk-K7I3YXWP.js';
|
|
3
6
|
import { __toESM } from './chunk-5WRI5ZAA.js';
|
|
4
|
-
import {
|
|
7
|
+
import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodNull, ZodNullable, ZodDate, ZodDefault, z as z$1, ZodFirstPartyTypeKind } from 'zod/v3';
|
|
8
|
+
import { z } from 'zod';
|
|
5
9
|
import { convertJsonSchemaToZod } from 'zod-from-json-schema';
|
|
6
10
|
import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from 'zod-from-json-schema-v3';
|
|
7
|
-
import {
|
|
8
|
-
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$1 } 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, z as z$2 } from 'zod/v4';
|
|
9
12
|
|
|
10
13
|
// ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
|
|
11
14
|
var __create = Object.create;
|
|
@@ -3604,20 +3607,29 @@ function applyCompatLayer({
|
|
|
3604
3607
|
compatLayers,
|
|
3605
3608
|
mode
|
|
3606
3609
|
}) {
|
|
3607
|
-
let zodSchema2;
|
|
3608
|
-
if (!isZodType(schema)) {
|
|
3609
|
-
zodSchema2 = convertSchemaToZod(schema);
|
|
3610
|
-
} else {
|
|
3611
|
-
zodSchema2 = schema;
|
|
3612
|
-
}
|
|
3613
|
-
for (const compat of compatLayers) {
|
|
3614
|
-
if (compat.shouldApply()) {
|
|
3615
|
-
return mode === "jsonSchema" ? compat.processToJSONSchema(zodSchema2) : compat.processToAISDKSchema(zodSchema2);
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
3610
|
if (mode === "jsonSchema") {
|
|
3619
|
-
|
|
3611
|
+
const standardSchema = toStandardSchema(schema);
|
|
3612
|
+
for (const compat of compatLayers) {
|
|
3613
|
+
if (compat.shouldApply()) {
|
|
3614
|
+
return compat.processToJSONSchema(standardSchema);
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
return standardSchemaToJSONSchema(standardSchema);
|
|
3620
3618
|
} else {
|
|
3619
|
+
let zodSchema2;
|
|
3620
|
+
if (isZodType(schema)) {
|
|
3621
|
+
zodSchema2 = schema;
|
|
3622
|
+
} else {
|
|
3623
|
+
if (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
|
+
}
|
|
3621
3633
|
return convertZodSchemaToAISDKSchema(zodSchema2);
|
|
3622
3634
|
}
|
|
3623
3635
|
}
|
|
@@ -3773,11 +3785,11 @@ var SchemaCompatLayer = class {
|
|
|
3773
3785
|
acc[key] = this.processZodType(propValue);
|
|
3774
3786
|
return acc;
|
|
3775
3787
|
}, {});
|
|
3776
|
-
let result = z.object(processedShape);
|
|
3788
|
+
let result = z$1.object(processedShape);
|
|
3777
3789
|
if (value._def.unknownKeys === "strict") {
|
|
3778
3790
|
result = result.strict();
|
|
3779
3791
|
}
|
|
3780
|
-
if (value._def.catchall && !(value._def.catchall instanceof z.ZodNever)) {
|
|
3792
|
+
if (value._def.catchall && !(value._def.catchall instanceof z$1.ZodNever)) {
|
|
3781
3793
|
result = result.catchall(value._def.catchall);
|
|
3782
3794
|
}
|
|
3783
3795
|
if (value.description) {
|
|
@@ -3829,7 +3841,7 @@ var SchemaCompatLayer = class {
|
|
|
3829
3841
|
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
3830
3842
|
const zodArrayDef = value._def;
|
|
3831
3843
|
const processedType = this.processZodType(zodArrayDef.type);
|
|
3832
|
-
let result = z.array(processedType);
|
|
3844
|
+
let result = z$1.array(processedType);
|
|
3833
3845
|
const constraints = [];
|
|
3834
3846
|
if (zodArrayDef.minLength?.value !== void 0) {
|
|
3835
3847
|
if (handleChecks.includes("min")) {
|
|
@@ -3868,7 +3880,7 @@ var SchemaCompatLayer = class {
|
|
|
3868
3880
|
defaultZodUnionHandler(value) {
|
|
3869
3881
|
const processedOptions = value._def.options.map((option) => this.processZodType(option));
|
|
3870
3882
|
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
3871
|
-
let result = z.union(processedOptions);
|
|
3883
|
+
let result = z$1.union(processedOptions);
|
|
3872
3884
|
if (value.description) {
|
|
3873
3885
|
result = result.describe(value.description);
|
|
3874
3886
|
}
|
|
@@ -3912,7 +3924,7 @@ var SchemaCompatLayer = class {
|
|
|
3912
3924
|
}
|
|
3913
3925
|
}
|
|
3914
3926
|
}
|
|
3915
|
-
let result = z.string();
|
|
3927
|
+
let result = z$1.string();
|
|
3916
3928
|
for (const check of newChecks) {
|
|
3917
3929
|
result = result._addCheck(check);
|
|
3918
3930
|
}
|
|
@@ -3961,7 +3973,7 @@ var SchemaCompatLayer = class {
|
|
|
3961
3973
|
}
|
|
3962
3974
|
}
|
|
3963
3975
|
}
|
|
3964
|
-
let result = z.number();
|
|
3976
|
+
let result = z$1.number();
|
|
3965
3977
|
for (const check of newChecks) {
|
|
3966
3978
|
switch (check.kind) {
|
|
3967
3979
|
case "int":
|
|
@@ -4008,7 +4020,7 @@ var SchemaCompatLayer = class {
|
|
|
4008
4020
|
}
|
|
4009
4021
|
}
|
|
4010
4022
|
constraints.push(`Date format is date-time`);
|
|
4011
|
-
let result = z.string().describe("date-time");
|
|
4023
|
+
let result = z$1.string().describe("date-time");
|
|
4012
4024
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
4013
4025
|
if (description) {
|
|
4014
4026
|
result = result.describe(description);
|
|
@@ -4210,12 +4222,12 @@ var SchemaCompatLayer2 = class {
|
|
|
4210
4222
|
acc[key] = this.processZodType(propValue);
|
|
4211
4223
|
return acc;
|
|
4212
4224
|
}, {});
|
|
4213
|
-
let result = z$
|
|
4214
|
-
if (value._zod.def.catchall instanceof z$
|
|
4215
|
-
result = z$
|
|
4216
|
-
} else if (value._zod.def.catchall instanceof z$
|
|
4225
|
+
let result = z$2.object(processedShape);
|
|
4226
|
+
if (value._zod.def.catchall instanceof z$2.ZodNever) {
|
|
4227
|
+
result = z$2.strictObject(processedShape);
|
|
4228
|
+
} else if (value._zod.def.catchall instanceof z$2.ZodUnknown) {
|
|
4217
4229
|
if (options.passthrough) {
|
|
4218
|
-
result = z$
|
|
4230
|
+
result = z$2.looseObject(processedShape);
|
|
4219
4231
|
}
|
|
4220
4232
|
} else if (value._zod.def.catchall) {
|
|
4221
4233
|
result = result.catchall(value._zod.def.catchall);
|
|
@@ -4266,7 +4278,7 @@ var SchemaCompatLayer2 = class {
|
|
|
4266
4278
|
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS2) {
|
|
4267
4279
|
const zodArrayDef = value._zod.def;
|
|
4268
4280
|
const processedType = this.processZodType(zodArrayDef.element);
|
|
4269
|
-
let result = z$
|
|
4281
|
+
let result = z$2.array(processedType);
|
|
4270
4282
|
const constraints = [];
|
|
4271
4283
|
if (zodArrayDef.checks) {
|
|
4272
4284
|
for (const check of zodArrayDef.checks) {
|
|
@@ -4311,7 +4323,7 @@ var SchemaCompatLayer2 = class {
|
|
|
4311
4323
|
defaultZodUnionHandler(value) {
|
|
4312
4324
|
const processedOptions = value._zod.def.options.map((option) => this.processZodType(option));
|
|
4313
4325
|
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
4314
|
-
let result = z$
|
|
4326
|
+
let result = z$2.union(processedOptions);
|
|
4315
4327
|
if (value.description) {
|
|
4316
4328
|
result = result.describe(value.description);
|
|
4317
4329
|
}
|
|
@@ -4360,7 +4372,7 @@ var SchemaCompatLayer2 = class {
|
|
|
4360
4372
|
}
|
|
4361
4373
|
}
|
|
4362
4374
|
}
|
|
4363
|
-
let result = z$
|
|
4375
|
+
let result = z$2.string();
|
|
4364
4376
|
for (const check of newChecks) {
|
|
4365
4377
|
result = result.check(check);
|
|
4366
4378
|
}
|
|
@@ -4411,7 +4423,7 @@ var SchemaCompatLayer2 = class {
|
|
|
4411
4423
|
}
|
|
4412
4424
|
}
|
|
4413
4425
|
}
|
|
4414
|
-
let result = z$
|
|
4426
|
+
let result = z$2.number();
|
|
4415
4427
|
for (const check of newChecks) {
|
|
4416
4428
|
switch (check._zod.def.check) {
|
|
4417
4429
|
case "number_format": {
|
|
@@ -4460,7 +4472,7 @@ var SchemaCompatLayer2 = class {
|
|
|
4460
4472
|
}
|
|
4461
4473
|
}
|
|
4462
4474
|
constraints.push(`Date format is date-time`);
|
|
4463
|
-
let result = z$
|
|
4475
|
+
let result = z$2.string().describe("date-time");
|
|
4464
4476
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
4465
4477
|
if (description) {
|
|
4466
4478
|
result = result.describe(description);
|
|
@@ -4544,7 +4556,10 @@ function isOneOfSchema(schema) {
|
|
|
4544
4556
|
return Array.isArray(schema.oneOf) && schema.oneOf.length > 0;
|
|
4545
4557
|
}
|
|
4546
4558
|
function isUnionSchema(schema) {
|
|
4547
|
-
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;
|
|
4548
4563
|
}
|
|
4549
4564
|
function isOptionalSchema(propertyName, parentSchema) {
|
|
4550
4565
|
if (!parentSchema.required || !Array.isArray(parentSchema.required)) {
|
|
@@ -4763,11 +4778,22 @@ var SchemaCompatLayer3 = class {
|
|
|
4763
4778
|
}
|
|
4764
4779
|
processToJSONSchema(zodSchema2, io = "input") {
|
|
4765
4780
|
const standardSchema = toStandardSchema(zodSchema2);
|
|
4766
|
-
|
|
4781
|
+
const jsonSchema2 = standardSchemaToJSONSchema(standardSchema, {
|
|
4767
4782
|
target: "draft-07",
|
|
4768
4783
|
io
|
|
4769
4784
|
// Use input mode so fields with defaults are optional
|
|
4770
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;
|
|
4771
4797
|
}
|
|
4772
4798
|
// ==========================================
|
|
4773
4799
|
// JSON Schema Default Handlers
|
|
@@ -4823,22 +4849,23 @@ var SchemaCompatLayer3 = class {
|
|
|
4823
4849
|
constraints.push(`maximum length ${schema.maxLength}`);
|
|
4824
4850
|
delete schema.maxLength;
|
|
4825
4851
|
}
|
|
4826
|
-
|
|
4827
|
-
|
|
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
|
+
}
|
|
4828
4865
|
}
|
|
4829
|
-
if (schema.
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
uri: "a valid url",
|
|
4833
|
-
url: "a valid url",
|
|
4834
|
-
uuid: "a valid uuid",
|
|
4835
|
-
"date-time": "a valid date-time",
|
|
4836
|
-
date: "a valid date",
|
|
4837
|
-
time: "a valid time"
|
|
4838
|
-
};
|
|
4839
|
-
const formatText = formatMap[schema.format] || `format: ${schema.format}`;
|
|
4840
|
-
constraints.push(formatText);
|
|
4841
|
-
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;
|
|
4842
4869
|
}
|
|
4843
4870
|
if (constraints.length) {
|
|
4844
4871
|
schema.description = this.mergeParameterDescription(schema.description, constraints);
|
|
@@ -4885,16 +4912,17 @@ var SchemaCompatLayer3 = class {
|
|
|
4885
4912
|
* Processes union schemas and can convert anyOf patterns to type arrays for simple primitives.
|
|
4886
4913
|
*/
|
|
4887
4914
|
defaultUnionHandler(schema) {
|
|
4888
|
-
if (
|
|
4889
|
-
|
|
4890
|
-
if (typeof
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
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];
|
|
4898
4926
|
}
|
|
4899
4927
|
}
|
|
4900
4928
|
return schema;
|
|
@@ -4974,7 +5002,7 @@ var SchemaCompatLayer3 = class {
|
|
|
4974
5002
|
* Uses 'input' io mode so that fields with defaults are optional (appropriate for tool parameters).
|
|
4975
5003
|
*/
|
|
4976
5004
|
toJSONSchema(zodSchema2) {
|
|
4977
|
-
const target = "draft-07";
|
|
5005
|
+
const target = this.getSchemaTarget() === "jsonSchema7" ? "draft-07" : this.getSchemaTarget();
|
|
4978
5006
|
const standardSchema = toStandardSchema(zodSchema2);
|
|
4979
5007
|
const jsonSchema2 = standardSchemaToJSONSchema(standardSchema, {
|
|
4980
5008
|
target,
|
|
@@ -4983,17 +5011,72 @@ var SchemaCompatLayer3 = class {
|
|
|
4983
5011
|
});
|
|
4984
5012
|
(0, import_json_schema_traverse.default)(jsonSchema2, {
|
|
4985
5013
|
cb: {
|
|
4986
|
-
pre: (schema
|
|
4987
|
-
this.preProcessJSONNode(schema
|
|
5014
|
+
pre: (schema) => {
|
|
5015
|
+
this.preProcessJSONNode(schema);
|
|
4988
5016
|
},
|
|
4989
|
-
post: (schema
|
|
4990
|
-
this.postProcessJSONNode(schema
|
|
5017
|
+
post: (schema) => {
|
|
5018
|
+
this.postProcessJSONNode(schema);
|
|
4991
5019
|
}
|
|
4992
5020
|
}
|
|
4993
5021
|
});
|
|
4994
5022
|
return jsonSchema2;
|
|
4995
5023
|
}
|
|
4996
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 = __toESM(require_json_schema_traverse(), 1);
|
|
4997
5080
|
function isOptional2(z11) {
|
|
4998
5081
|
return (v) => v instanceof z11["ZodOptional"];
|
|
4999
5082
|
}
|
|
@@ -5025,38 +5108,121 @@ function isNullable(z11) {
|
|
|
5025
5108
|
return (v) => v instanceof z11["ZodNullable"];
|
|
5026
5109
|
}
|
|
5027
5110
|
|
|
5028
|
-
// src/provider-compats/
|
|
5029
|
-
var
|
|
5111
|
+
// src/provider-compats/openai.ts
|
|
5112
|
+
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5030
5113
|
constructor(model) {
|
|
5031
5114
|
super(model);
|
|
5032
5115
|
}
|
|
5033
5116
|
getSchemaTarget() {
|
|
5034
|
-
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`);
|
|
5035
5123
|
}
|
|
5036
5124
|
shouldApply() {
|
|
5037
|
-
|
|
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;
|
|
5038
5130
|
}
|
|
5039
5131
|
processZodType(value) {
|
|
5040
|
-
if (
|
|
5041
|
-
const
|
|
5042
|
-
if (
|
|
5043
|
-
|
|
5044
|
-
|
|
5132
|
+
if (isOptional2(z)(value)) {
|
|
5133
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5134
|
+
if (innerType) {
|
|
5135
|
+
if (isNullable(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(z)(value)) {
|
|
5144
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5145
|
+
if (innerType) {
|
|
5146
|
+
if (isOptional2(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(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(z)(value)) {
|
|
5045
5171
|
return this.defaultZodObjectHandler(value);
|
|
5046
|
-
} else if (
|
|
5047
|
-
return this.defaultZodArrayHandler(value, []);
|
|
5048
|
-
} else if (this.isUnion(value)) {
|
|
5172
|
+
} else if (isUnion2(z)(value)) {
|
|
5049
5173
|
return this.defaultZodUnionHandler(value);
|
|
5050
|
-
} else if (
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5174
|
+
} else if (isArr2(z)(value)) {
|
|
5175
|
+
return this.defaultZodArrayHandler(value);
|
|
5176
|
+
} else if (isString2(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"]);
|
|
5055
5181
|
}
|
|
5056
|
-
|
|
5057
|
-
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5182
|
+
return this.defaultZodStringHandler(value, checks);
|
|
5058
5183
|
}
|
|
5059
|
-
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 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 = 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 = 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
|
+
});
|
|
5060
5226
|
}
|
|
5061
5227
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5062
5228
|
if (isObjectSchema(schema)) {
|
|
@@ -5064,73 +5230,239 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5064
5230
|
} else if (isArraySchema(schema)) {
|
|
5065
5231
|
this.defaultArrayHandler(schema);
|
|
5066
5232
|
} else if (isStringSchema(schema)) {
|
|
5067
|
-
|
|
5068
|
-
|
|
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
|
+
}
|
|
5069
5241
|
}
|
|
5242
|
+
this.defaultStringHandler(schema);
|
|
5070
5243
|
}
|
|
5071
5244
|
}
|
|
5072
5245
|
postProcessJSONNode(schema) {
|
|
5073
5246
|
if (isUnionSchema(schema)) {
|
|
5074
5247
|
this.defaultUnionHandler(schema);
|
|
5075
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
|
+
}
|
|
5076
5265
|
if (isObjectSchema(schema)) {
|
|
5077
|
-
|
|
5078
|
-
|
|
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;
|
|
5079
5284
|
}
|
|
5080
5285
|
if ("propertyNames" in schema) {
|
|
5081
5286
|
delete schema.propertyNames;
|
|
5082
5287
|
}
|
|
5083
5288
|
}
|
|
5084
5289
|
}
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
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;
|
|
5301
|
+
}
|
|
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;
|
|
5305
|
+
}
|
|
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
|
+
);
|
|
5313
|
+
}
|
|
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);
|
|
5319
|
+
}
|
|
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;
|
|
5089
5325
|
}
|
|
5326
|
+
};
|
|
5327
|
+
var OpenAIReasoningSchemaCompatLayer = class extends OpenAISchemaCompatLayer {
|
|
5090
5328
|
getSchemaTarget() {
|
|
5091
|
-
return
|
|
5329
|
+
return `openApi3`;
|
|
5092
5330
|
}
|
|
5093
5331
|
shouldApply() {
|
|
5094
|
-
|
|
5332
|
+
const model = this.getModel();
|
|
5333
|
+
if (this.isReasoningModel() && (model.provider.includes(`openai`) || model.modelId?.includes(`openai`))) {
|
|
5334
|
+
return true;
|
|
5335
|
+
}
|
|
5336
|
+
return false;
|
|
5095
5337
|
}
|
|
5096
5338
|
processZodType(value) {
|
|
5097
5339
|
if (isOptional2(z)(value)) {
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
return this.defaultZodStringHandler(value);
|
|
5107
|
-
}
|
|
5108
|
-
return value;
|
|
5109
|
-
}
|
|
5110
|
-
preProcessJSONNode(schema, _parentSchema) {
|
|
5111
|
-
if (isObjectSchema(schema)) {
|
|
5112
|
-
this.defaultObjectHandler(schema);
|
|
5113
|
-
} else if (isArraySchema(schema)) {
|
|
5114
|
-
this.defaultArrayHandler(schema);
|
|
5115
|
-
} else if (isStringSchema(schema)) {
|
|
5116
|
-
this.defaultStringHandler(schema);
|
|
5117
|
-
}
|
|
5118
|
-
}
|
|
5119
|
-
postProcessJSONNode(schema, _parentSchema) {
|
|
5120
|
-
if (isUnionSchema(schema)) {
|
|
5121
|
-
this.defaultUnionHandler(schema);
|
|
5122
|
-
}
|
|
5123
|
-
if (isObjectSchema(schema)) {
|
|
5124
|
-
if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
|
|
5125
|
-
schema.additionalProperties = true;
|
|
5340
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5341
|
+
if (innerType) {
|
|
5342
|
+
if (isNullable(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);
|
|
5126
5348
|
}
|
|
5127
|
-
|
|
5128
|
-
|
|
5349
|
+
return value;
|
|
5350
|
+
} else if (isNullable(z)(value)) {
|
|
5351
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5352
|
+
if (innerType && isOptional2(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;
|
|
5364
|
+
} else if (isObj2(z)(value)) {
|
|
5365
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
5366
|
+
} else if (isArr2(z)(value)) {
|
|
5367
|
+
return this.defaultZodArrayHandler(value);
|
|
5368
|
+
} else if (isUnion2(z)(value)) {
|
|
5369
|
+
return this.defaultZodUnionHandler(value);
|
|
5370
|
+
} else if (isDefault(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);
|
|
5129
5382
|
}
|
|
5383
|
+
return result;
|
|
5384
|
+
} else if (isNumber2(z)(value)) {
|
|
5385
|
+
return this.defaultZodNumberHandler(value);
|
|
5386
|
+
} else if (isString2(z)(value)) {
|
|
5387
|
+
return this.defaultZodStringHandler(value);
|
|
5388
|
+
} else if (isDate(z)(value)) {
|
|
5389
|
+
return this.defaultZodDateHandler(value);
|
|
5390
|
+
} else if (isNull(z)(value)) {
|
|
5391
|
+
return 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 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
|
+
);
|
|
5397
|
+
}
|
|
5398
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5399
|
+
}
|
|
5400
|
+
processToJSONSchema(zodSchema2) {
|
|
5401
|
+
const jsonSchema2 = super.processToJSONSchema(zodSchema2);
|
|
5402
|
+
return ensureAllPropertiesRequired(jsonSchema2);
|
|
5403
|
+
}
|
|
5404
|
+
preProcessJSONNode(schema, _parentSchema) {
|
|
5405
|
+
if (isObjectSchema(schema)) {
|
|
5406
|
+
this.defaultObjectHandler(schema);
|
|
5407
|
+
} else if (isArraySchema(schema)) {
|
|
5408
|
+
this.defaultArrayHandler(schema);
|
|
5409
|
+
} else if (isNumberSchema(schema)) {
|
|
5410
|
+
this.defaultNumberHandler(schema);
|
|
5411
|
+
} else if (isStringSchema(schema)) {
|
|
5412
|
+
this.defaultStringHandler(schema);
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
postProcessJSONNode(schema) {
|
|
5416
|
+
super.postProcessJSONNode(schema);
|
|
5417
|
+
if (schema.type === "object" && schema.properties !== void 0) {
|
|
5418
|
+
schema.additionalProperties = false;
|
|
5130
5419
|
}
|
|
5131
5420
|
}
|
|
5132
5421
|
};
|
|
5133
|
-
|
|
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 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 {
|
|
5134
5466
|
constructor(model) {
|
|
5135
5467
|
super(model);
|
|
5136
5468
|
}
|
|
@@ -5138,23 +5470,27 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5138
5470
|
return "jsonSchema7";
|
|
5139
5471
|
}
|
|
5140
5472
|
shouldApply() {
|
|
5141
|
-
return this.getModel().
|
|
5473
|
+
return this.getModel().modelId.includes("claude");
|
|
5142
5474
|
}
|
|
5143
5475
|
processZodType(value) {
|
|
5144
|
-
if (
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
return
|
|
5148
|
-
} else if (
|
|
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)) {
|
|
5149
5481
|
return this.defaultZodObjectHandler(value);
|
|
5150
|
-
} else if (
|
|
5482
|
+
} else if (this.isArr(value)) {
|
|
5151
5483
|
return this.defaultZodArrayHandler(value, []);
|
|
5152
|
-
} else if (
|
|
5484
|
+
} else if (this.isUnion(value)) {
|
|
5153
5485
|
return this.defaultZodUnionHandler(value);
|
|
5154
|
-
} else if (
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
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(z)(value)) {
|
|
5493
|
+
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5158
5494
|
}
|
|
5159
5495
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5160
5496
|
}
|
|
@@ -5164,12 +5500,12 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5164
5500
|
} else if (isArraySchema(schema)) {
|
|
5165
5501
|
this.defaultArrayHandler(schema);
|
|
5166
5502
|
} else if (isStringSchema(schema)) {
|
|
5167
|
-
this.
|
|
5168
|
-
|
|
5169
|
-
|
|
5503
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
5504
|
+
this.defaultStringHandler(schema);
|
|
5505
|
+
}
|
|
5170
5506
|
}
|
|
5171
5507
|
}
|
|
5172
|
-
postProcessJSONNode(schema
|
|
5508
|
+
postProcessJSONNode(schema) {
|
|
5173
5509
|
if (isUnionSchema(schema)) {
|
|
5174
5510
|
this.defaultUnionHandler(schema);
|
|
5175
5511
|
}
|
|
@@ -5183,7 +5519,7 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5183
5519
|
}
|
|
5184
5520
|
}
|
|
5185
5521
|
};
|
|
5186
|
-
var
|
|
5522
|
+
var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5187
5523
|
constructor(model) {
|
|
5188
5524
|
super(model);
|
|
5189
5525
|
}
|
|
@@ -5191,7 +5527,7 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5191
5527
|
return "jsonSchema7";
|
|
5192
5528
|
}
|
|
5193
5529
|
shouldApply() {
|
|
5194
|
-
return this.getModel().modelId.includes("
|
|
5530
|
+
return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
|
|
5195
5531
|
}
|
|
5196
5532
|
processZodType(value) {
|
|
5197
5533
|
if (isOptional2(z)(value)) {
|
|
@@ -5202,8 +5538,6 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5202
5538
|
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
5203
5539
|
} else if (isUnion2(z)(value)) {
|
|
5204
5540
|
return this.defaultZodUnionHandler(value);
|
|
5205
|
-
} else if (isNumber2(z)(value)) {
|
|
5206
|
-
return this.defaultZodNumberHandler(value);
|
|
5207
5541
|
} else if (isString2(z)(value)) {
|
|
5208
5542
|
return this.defaultZodStringHandler(value);
|
|
5209
5543
|
}
|
|
@@ -5216,8 +5550,6 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5216
5550
|
this.defaultArrayHandler(schema);
|
|
5217
5551
|
} else if (isStringSchema(schema)) {
|
|
5218
5552
|
this.defaultStringHandler(schema);
|
|
5219
|
-
} else if (isNumberSchema(schema)) {
|
|
5220
|
-
this.defaultNumberHandler(schema);
|
|
5221
5553
|
}
|
|
5222
5554
|
}
|
|
5223
5555
|
postProcessJSONNode(schema, _parentSchema) {
|
|
@@ -5234,85 +5566,104 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5234
5566
|
}
|
|
5235
5567
|
}
|
|
5236
5568
|
};
|
|
5237
|
-
|
|
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 {
|
|
5238
5623
|
constructor(model) {
|
|
5239
5624
|
super(model);
|
|
5240
5625
|
}
|
|
5241
5626
|
getSchemaTarget() {
|
|
5242
|
-
return
|
|
5627
|
+
return "jsonSchema7";
|
|
5243
5628
|
}
|
|
5244
5629
|
shouldApply() {
|
|
5245
|
-
|
|
5246
|
-
return true;
|
|
5247
|
-
}
|
|
5248
|
-
return false;
|
|
5630
|
+
return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
|
|
5249
5631
|
}
|
|
5250
5632
|
processZodType(value) {
|
|
5251
5633
|
if (isOptional2(z)(value)) {
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
}
|
|
5261
|
-
return value;
|
|
5634
|
+
return this.defaultZodOptionalHandler(value, [
|
|
5635
|
+
"ZodObject",
|
|
5636
|
+
"ZodArray",
|
|
5637
|
+
"ZodUnion",
|
|
5638
|
+
"ZodString",
|
|
5639
|
+
"ZodNumber",
|
|
5640
|
+
"ZodNullable"
|
|
5641
|
+
]);
|
|
5262
5642
|
} else if (isNullable(z)(value)) {
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
5267
|
-
if (innerInnerType) {
|
|
5268
|
-
const processedInnerInner = this.processZodType(innerInnerType);
|
|
5269
|
-
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5270
|
-
}
|
|
5271
|
-
}
|
|
5272
|
-
const processedInner = this.processZodType(innerType);
|
|
5273
|
-
return processedInner.nullable();
|
|
5274
|
-
}
|
|
5275
|
-
return value;
|
|
5276
|
-
} else if (isDefault(z)(value)) {
|
|
5277
|
-
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5278
|
-
const defaultValue = "_def" in value ? value._def.defaultValue : value._zod?.def?.defaultValue;
|
|
5279
|
-
if (innerType) {
|
|
5280
|
-
const processedInner = this.processZodType(innerType);
|
|
5281
|
-
return processedInner.nullable().transform((val) => {
|
|
5282
|
-
if (val === null) {
|
|
5283
|
-
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
5284
|
-
}
|
|
5285
|
-
return val;
|
|
5286
|
-
});
|
|
5287
|
-
}
|
|
5288
|
-
return value;
|
|
5643
|
+
return this.defaultZodNullableHandler(value);
|
|
5644
|
+
} else if (isNull(z)(value)) {
|
|
5645
|
+
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5289
5646
|
} else if (isObj2(z)(value)) {
|
|
5290
5647
|
return this.defaultZodObjectHandler(value);
|
|
5648
|
+
} else if (isArr2(z)(value)) {
|
|
5649
|
+
return this.defaultZodArrayHandler(value, []);
|
|
5291
5650
|
} else if (isUnion2(z)(value)) {
|
|
5292
5651
|
return this.defaultZodUnionHandler(value);
|
|
5293
|
-
} else if (isArr2(z)(value)) {
|
|
5294
|
-
return this.defaultZodArrayHandler(value);
|
|
5295
5652
|
} else if (isString2(z)(value)) {
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
return this.defaultZodStringHandler(value, ["emoji", "regex"]);
|
|
5300
|
-
}
|
|
5301
|
-
return this.defaultZodStringHandler(value, checks);
|
|
5653
|
+
return this.defaultZodStringHandler(value);
|
|
5654
|
+
} else if (isNumber2(z)(value)) {
|
|
5655
|
+
return this.defaultZodNumberHandler(value);
|
|
5302
5656
|
}
|
|
5303
|
-
return this.defaultUnsupportedZodTypeHandler(value
|
|
5304
|
-
"ZodNever",
|
|
5305
|
-
"ZodUndefined",
|
|
5306
|
-
"ZodTuple"
|
|
5307
|
-
]);
|
|
5657
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5308
5658
|
}
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
const
|
|
5315
|
-
|
|
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 };
|
|
5316
5667
|
}
|
|
5317
5668
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5318
5669
|
if (isObjectSchema(schema)) {
|
|
@@ -5320,22 +5671,14 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5320
5671
|
} else if (isArraySchema(schema)) {
|
|
5321
5672
|
this.defaultArrayHandler(schema);
|
|
5322
5673
|
} else if (isStringSchema(schema)) {
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
if (schema.pattern) {
|
|
5329
|
-
delete schema.pattern;
|
|
5330
|
-
}
|
|
5331
|
-
} else {
|
|
5332
|
-
if (schema.format === "emoji") {
|
|
5333
|
-
delete schema.format;
|
|
5334
|
-
}
|
|
5335
|
-
}
|
|
5674
|
+
this.defaultStringHandler(schema);
|
|
5675
|
+
} else if (isNumberSchema(schema)) {
|
|
5676
|
+
this.defaultNumberHandler(schema);
|
|
5677
|
+
} else if (isEnumSchema(schema)) {
|
|
5678
|
+
schema.type = "string";
|
|
5336
5679
|
}
|
|
5337
5680
|
}
|
|
5338
|
-
postProcessJSONNode(schema) {
|
|
5681
|
+
postProcessJSONNode(schema, _parentSchema) {
|
|
5339
5682
|
if (isUnionSchema(schema)) {
|
|
5340
5683
|
this.defaultUnionHandler(schema);
|
|
5341
5684
|
}
|
|
@@ -5348,139 +5691,51 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
5348
5691
|
}
|
|
5349
5692
|
}
|
|
5350
5693
|
}
|
|
5351
|
-
/**
|
|
5352
|
-
* Recursively fixes additionalProperties: {} to additionalProperties: true.
|
|
5353
|
-
* OpenAI requires additionalProperties to be either:
|
|
5354
|
-
* - false (no additional properties allowed)
|
|
5355
|
-
* - true (any additional properties allowed)
|
|
5356
|
-
* - an object with a "type" key (typed additional properties)
|
|
5357
|
-
* An empty object {} is NOT valid.
|
|
5358
|
-
*/
|
|
5359
|
-
fixAdditionalProperties(schema) {
|
|
5360
|
-
if (typeof schema !== "object" || schema === null) {
|
|
5361
|
-
return schema;
|
|
5362
|
-
}
|
|
5363
|
-
const result = { ...schema };
|
|
5364
|
-
if (result.additionalProperties !== void 0 && typeof result.additionalProperties === "object" && result.additionalProperties !== null && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length === 0) {
|
|
5365
|
-
result.additionalProperties = true;
|
|
5366
|
-
}
|
|
5367
|
-
if (result.properties) {
|
|
5368
|
-
result.properties = Object.fromEntries(
|
|
5369
|
-
Object.entries(result.properties).map(([key, value]) => [
|
|
5370
|
-
key,
|
|
5371
|
-
this.fixAdditionalProperties(value)
|
|
5372
|
-
])
|
|
5373
|
-
);
|
|
5374
|
-
}
|
|
5375
|
-
if (result.items) {
|
|
5376
|
-
if (Array.isArray(result.items)) {
|
|
5377
|
-
result.items = result.items.map((item) => this.fixAdditionalProperties(item));
|
|
5378
|
-
} else {
|
|
5379
|
-
result.items = this.fixAdditionalProperties(result.items);
|
|
5380
|
-
}
|
|
5381
|
-
}
|
|
5382
|
-
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length > 0) {
|
|
5383
|
-
result.additionalProperties = this.fixAdditionalProperties(result.additionalProperties);
|
|
5384
|
-
}
|
|
5385
|
-
return result;
|
|
5386
|
-
}
|
|
5387
5694
|
};
|
|
5388
|
-
var
|
|
5695
|
+
var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
5389
5696
|
constructor(model) {
|
|
5390
5697
|
super(model);
|
|
5391
5698
|
}
|
|
5392
5699
|
getSchemaTarget() {
|
|
5393
|
-
return
|
|
5394
|
-
}
|
|
5395
|
-
isReasoningModel() {
|
|
5396
|
-
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`) || this.getModel().modelId.includes(`o1`);
|
|
5700
|
+
return "jsonSchema7";
|
|
5397
5701
|
}
|
|
5398
5702
|
shouldApply() {
|
|
5399
|
-
|
|
5400
|
-
return true;
|
|
5401
|
-
}
|
|
5402
|
-
return false;
|
|
5703
|
+
return this.getModel().modelId.includes("meta");
|
|
5403
5704
|
}
|
|
5404
5705
|
processZodType(value) {
|
|
5405
5706
|
if (isOptional2(z)(value)) {
|
|
5406
|
-
|
|
5407
|
-
if (innerType) {
|
|
5408
|
-
if (isNullable(z)(innerType)) {
|
|
5409
|
-
const processed = this.processZodType(innerType);
|
|
5410
|
-
return processed.transform((val) => val === null ? void 0 : val);
|
|
5411
|
-
}
|
|
5412
|
-
const processedInner = this.processZodType(innerType);
|
|
5413
|
-
return processedInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5414
|
-
}
|
|
5415
|
-
return value;
|
|
5416
|
-
} else if (isNullable(z)(value)) {
|
|
5417
|
-
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
5418
|
-
if (innerType && isOptional2(z)(innerType)) {
|
|
5419
|
-
const innerInnerType = "_def" in innerType ? innerType._def.innerType : innerType._zod?.def?.innerType;
|
|
5420
|
-
if (innerInnerType) {
|
|
5421
|
-
const processedInnerInner = this.processZodType(innerInnerType);
|
|
5422
|
-
return processedInnerInner.nullable().transform((val) => val === null ? void 0 : val);
|
|
5423
|
-
}
|
|
5424
|
-
}
|
|
5425
|
-
if (innerType) {
|
|
5426
|
-
const processedInner = this.processZodType(innerType);
|
|
5427
|
-
return processedInner.nullable();
|
|
5428
|
-
}
|
|
5429
|
-
return value;
|
|
5707
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
5430
5708
|
} else if (isObj2(z)(value)) {
|
|
5431
|
-
return this.defaultZodObjectHandler(value
|
|
5709
|
+
return this.defaultZodObjectHandler(value);
|
|
5432
5710
|
} else if (isArr2(z)(value)) {
|
|
5433
|
-
return this.defaultZodArrayHandler(value);
|
|
5711
|
+
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
5434
5712
|
} else if (isUnion2(z)(value)) {
|
|
5435
5713
|
return this.defaultZodUnionHandler(value);
|
|
5436
|
-
} else if (isDefault(z)(value)) {
|
|
5437
|
-
const defaultDef = value._def;
|
|
5438
|
-
const innerType = defaultDef.innerType;
|
|
5439
|
-
const defaultValue = typeof defaultDef.defaultValue === "function" ? defaultDef.defaultValue() : defaultDef.defaultValue;
|
|
5440
|
-
const constraints = [];
|
|
5441
|
-
if (defaultValue !== void 0) {
|
|
5442
|
-
constraints.push(`the default value is ${defaultValue}`);
|
|
5443
|
-
}
|
|
5444
|
-
const description = this.mergeParameterDescription(value.description, constraints);
|
|
5445
|
-
let result = this.processZodType(innerType);
|
|
5446
|
-
if (description) {
|
|
5447
|
-
result = result.describe(description);
|
|
5448
|
-
}
|
|
5449
|
-
return result;
|
|
5450
5714
|
} else if (isNumber2(z)(value)) {
|
|
5451
5715
|
return this.defaultZodNumberHandler(value);
|
|
5452
5716
|
} else if (isString2(z)(value)) {
|
|
5453
5717
|
return this.defaultZodStringHandler(value);
|
|
5454
|
-
} else if (isDate(z)(value)) {
|
|
5455
|
-
return this.defaultZodDateHandler(value);
|
|
5456
|
-
} else if (isNull(z)(value)) {
|
|
5457
|
-
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5458
|
-
} else if (value.constructor.name === "ZodAny") {
|
|
5459
|
-
return z.string().describe(
|
|
5460
|
-
(value.description ?? "") + `
|
|
5461
|
-
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
5462
|
-
);
|
|
5463
5718
|
}
|
|
5464
|
-
return
|
|
5719
|
+
return value;
|
|
5465
5720
|
}
|
|
5466
5721
|
preProcessJSONNode(schema, _parentSchema) {
|
|
5467
5722
|
if (isObjectSchema(schema)) {
|
|
5468
5723
|
this.defaultObjectHandler(schema);
|
|
5469
5724
|
} else if (isArraySchema(schema)) {
|
|
5470
5725
|
this.defaultArrayHandler(schema);
|
|
5471
|
-
} else if (isNumberSchema(schema)) {
|
|
5472
|
-
this.defaultNumberHandler(schema);
|
|
5473
5726
|
} else if (isStringSchema(schema)) {
|
|
5474
5727
|
this.defaultStringHandler(schema);
|
|
5728
|
+
} else if (isNumberSchema(schema)) {
|
|
5729
|
+
this.defaultNumberHandler(schema);
|
|
5475
5730
|
}
|
|
5476
5731
|
}
|
|
5477
|
-
postProcessJSONNode(schema) {
|
|
5732
|
+
postProcessJSONNode(schema, _parentSchema) {
|
|
5478
5733
|
if (isUnionSchema(schema)) {
|
|
5479
5734
|
this.defaultUnionHandler(schema);
|
|
5480
5735
|
}
|
|
5481
5736
|
if (isObjectSchema(schema)) {
|
|
5482
5737
|
if (schema.additionalProperties !== void 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && Object.keys(schema.additionalProperties).length === 0) {
|
|
5483
|
-
schema.additionalProperties =
|
|
5738
|
+
schema.additionalProperties = true;
|
|
5484
5739
|
}
|
|
5485
5740
|
if ("propertyNames" in schema) {
|
|
5486
5741
|
delete schema.propertyNames;
|
|
@@ -5489,6 +5744,6 @@ Argument was an "any" type, but you (the LLM) do not support "any", so it was ca
|
|
|
5489
5744
|
}
|
|
5490
5745
|
};
|
|
5491
5746
|
|
|
5492
|
-
export { ALL_ARRAY_CHECKS, ALL_NUMBER_CHECKS, ALL_STRING_CHECKS, ALL_ZOD_TYPES, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, GoogleSchemaCompatLayer, MetaSchemaCompatLayer, OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, SUPPORTED_ZOD_TYPES, SchemaCompatLayer3 as SchemaCompatLayer, SchemaCompatLayer as SchemaCompatLayerV3, SchemaCompatLayer2 as SchemaCompatLayerV4, UNSUPPORTED_ZOD_TYPES, applyCompatLayer, convertSchemaToZod, convertZodSchemaToAISDKSchema, isArr, isNumber, isObj, isOptional, isString, isUnion, isZodType, jsonSchema };
|
|
5747
|
+
export { ALL_ARRAY_CHECKS, ALL_NUMBER_CHECKS, ALL_STRING_CHECKS, ALL_ZOD_TYPES, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, GoogleSchemaCompatLayer, MetaSchemaCompatLayer, OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, SUPPORTED_ZOD_TYPES, SchemaCompatLayer3 as SchemaCompatLayer, SchemaCompatLayer as SchemaCompatLayerV3, SchemaCompatLayer2 as SchemaCompatLayerV4, UNSUPPORTED_ZOD_TYPES, applyCompatLayer, applyOpenAICompatToTools, applyOpenAICompatTransforms, convertSchemaToZod, convertZodSchemaToAISDKSchema, extractZodSchema, isArr, isNumber, isObj, isOptional, isString, isUnion, isZodType, jsonSchema, wrapSchemaWithNullTransform };
|
|
5493
5748
|
//# sourceMappingURL=index.js.map
|
|
5494
5749
|
//# sourceMappingURL=index.js.map
|