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