@mastra/schema-compat 1.3.15 → 1.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +206 -873
- package/dist/_types/@internal_ai-v6/dist/index.d.ts +851 -1176
- package/dist/{esm-CWlHuVIx.js → esm-DA8owk0L.js} +60 -70
- package/dist/{esm-CWlHuVIx.js.map → esm-DA8owk0L.js.map} +1 -1
- package/dist/{esm-CkNCkZSB.cjs → esm-zrVJTTxY.cjs} +60 -70
- package/dist/{esm-CkNCkZSB.cjs.map → esm-zrVJTTxY.cjs.map} +1 -1
- package/dist/index.cjs +146 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +146 -153
- package/dist/index.js.map +1 -1
- package/dist/{json-schema-R8yfooPa.js → json-schema-DcMkkbbI.js} +55 -46
- package/dist/{json-schema-R8yfooPa.js.map → json-schema-DcMkkbbI.js.map} +1 -1
- package/dist/{json-schema-VSnKq6-P.cjs → json-schema-Dh7B27IP.cjs} +55 -46
- package/dist/{json-schema-VSnKq6-P.cjs.map → json-schema-Dh7B27IP.cjs.map} +1 -1
- package/dist/{json-schema-traverse-DbuWNYgg.cjs → json-schema-traverse-CKLDTw5l.cjs} +3 -3
- package/dist/{json-schema-traverse-DbuWNYgg.cjs.map → json-schema-traverse-CKLDTw5l.cjs.map} +1 -1
- package/dist/{json-schema-traverse-B35mHRM8.js → json-schema-traverse-Jrimn_T_.js} +3 -3
- package/dist/{json-schema-traverse-B35mHRM8.js.map → json-schema-traverse-Jrimn_T_.js.map} +1 -1
- package/dist/json-to-zod.cjs +84 -72
- package/dist/json-to-zod.cjs.map +1 -1
- package/dist/json-to-zod.js +84 -72
- package/dist/json-to-zod.js.map +1 -1
- package/dist/{schema-IhrnbMI3.cjs → schema-BXSe2bgB.cjs} +3 -3
- package/dist/schema-BXSe2bgB.cjs.map +1 -0
- package/dist/{schema-e0VHpMt0.js → schema-CzbEIyhE.js} +2 -2
- package/dist/{schema-e0VHpMt0.js.map → schema-CzbEIyhE.js.map} +1 -1
- package/dist/schema.cjs +1 -1
- package/dist/schema.js +1 -2
- package/dist/standard-schema/adapters/ai-sdk.cjs +1 -5
- package/dist/standard-schema/adapters/ai-sdk.cjs.map +1 -1
- package/dist/standard-schema/adapters/ai-sdk.js +1 -5
- package/dist/standard-schema/adapters/ai-sdk.js.map +1 -1
- package/dist/standard-schema/adapters/json-schema.cjs +1 -1
- package/dist/standard-schema/adapters/json-schema.js +1 -2
- package/dist/standard-schema/adapters/zod-v3.cjs +2 -2
- package/dist/standard-schema/adapters/zod-v3.js +2 -2
- package/dist/zod-to-json.cjs +5 -3
- package/dist/zod-to-json.cjs.map +1 -1
- package/dist/zod-to-json.js +5 -3
- package/dist/zod-to-json.js.map +1 -1
- package/package.json +14 -15
- package/dist/schema-IhrnbMI3.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_json_schema_traverse$1 = require("./json-schema-traverse-
|
|
2
|
+
const require_json_schema_traverse$1 = require("./json-schema-traverse-CKLDTw5l.cjs");
|
|
3
3
|
const require_zod_to_json = require("./zod-to-json.cjs");
|
|
4
|
-
const require_schema = require("./schema-
|
|
4
|
+
const require_schema = require("./schema-BXSe2bgB.cjs");
|
|
5
5
|
let zod_v3 = require("zod/v3");
|
|
6
6
|
let zod = require("zod");
|
|
7
7
|
let zod_from_json_schema = require("zod-from-json-schema");
|
|
@@ -261,7 +261,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
261
261
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
262
262
|
var __getProtoOf = Object.getPrototypeOf;
|
|
263
263
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
264
|
-
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
264
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
265
265
|
var __copyProps = (to, from, except, desc) => {
|
|
266
266
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
267
267
|
key = keys[i];
|
|
@@ -272,7 +272,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
272
272
|
}
|
|
273
273
|
return to;
|
|
274
274
|
};
|
|
275
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
|
|
275
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp$1(target, "default", {
|
|
276
276
|
value: mod,
|
|
277
277
|
enumerable: true
|
|
278
278
|
}) : target, mod));
|
|
@@ -577,24 +577,24 @@ function parseBigintDef(def, refs) {
|
|
|
577
577
|
if (!def.checks) return res;
|
|
578
578
|
for (const check of def.checks) switch (check.kind) {
|
|
579
579
|
case "min":
|
|
580
|
-
if (refs.target === "jsonSchema7")
|
|
581
|
-
|
|
582
|
-
|
|
580
|
+
if (refs.target === "jsonSchema7") {
|
|
581
|
+
if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
582
|
+
else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
583
|
+
} else {
|
|
583
584
|
if (!check.inclusive) res.exclusiveMinimum = true;
|
|
584
585
|
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
585
586
|
}
|
|
586
587
|
break;
|
|
587
588
|
case "max":
|
|
588
|
-
if (refs.target === "jsonSchema7")
|
|
589
|
-
|
|
590
|
-
|
|
589
|
+
if (refs.target === "jsonSchema7") {
|
|
590
|
+
if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
591
|
+
else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
592
|
+
} else {
|
|
591
593
|
if (!check.inclusive) res.exclusiveMaximum = true;
|
|
592
594
|
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
593
595
|
}
|
|
594
596
|
break;
|
|
595
|
-
case "multipleOf":
|
|
596
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
597
|
-
break;
|
|
597
|
+
case "multipleOf": setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
598
598
|
}
|
|
599
599
|
return res;
|
|
600
600
|
}
|
|
@@ -633,9 +633,7 @@ const integerDateParser = (def, refs) => {
|
|
|
633
633
|
case "min":
|
|
634
634
|
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
635
635
|
break;
|
|
636
|
-
case "max":
|
|
637
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
638
|
-
break;
|
|
636
|
+
case "max": setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
639
637
|
}
|
|
640
638
|
return res;
|
|
641
639
|
};
|
|
@@ -775,9 +773,7 @@ function parseStringDef(def, refs) {
|
|
|
775
773
|
case "format:idn-email":
|
|
776
774
|
addFormat(res, "idn-email", check.message, refs);
|
|
777
775
|
break;
|
|
778
|
-
case "pattern:zod":
|
|
779
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
780
|
-
break;
|
|
776
|
+
case "pattern:zod": addPattern(res, zodPatterns.email, check.message, refs);
|
|
781
777
|
}
|
|
782
778
|
break;
|
|
783
779
|
case "url":
|
|
@@ -848,16 +844,10 @@ function parseStringDef(def, refs) {
|
|
|
848
844
|
case "contentEncoding:base64":
|
|
849
845
|
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
850
846
|
break;
|
|
851
|
-
case "pattern:zod":
|
|
852
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
853
|
-
break;
|
|
847
|
+
case "pattern:zod": addPattern(res, zodPatterns.base64, check.message, refs);
|
|
854
848
|
}
|
|
855
849
|
break;
|
|
856
850
|
case "nanoid": addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
857
|
-
case "toLowerCase":
|
|
858
|
-
case "toUpperCase":
|
|
859
|
-
case "trim": break;
|
|
860
|
-
default:
|
|
861
851
|
}
|
|
862
852
|
return res;
|
|
863
853
|
}
|
|
@@ -1173,24 +1163,24 @@ function parseNumberDef(def, refs) {
|
|
|
1173
1163
|
addErrorMessage(res, "type", check.message, refs);
|
|
1174
1164
|
break;
|
|
1175
1165
|
case "min":
|
|
1176
|
-
if (refs.target === "jsonSchema7")
|
|
1177
|
-
|
|
1178
|
-
|
|
1166
|
+
if (refs.target === "jsonSchema7") {
|
|
1167
|
+
if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1168
|
+
else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
1169
|
+
} else {
|
|
1179
1170
|
if (!check.inclusive) res.exclusiveMinimum = true;
|
|
1180
1171
|
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1181
1172
|
}
|
|
1182
1173
|
break;
|
|
1183
1174
|
case "max":
|
|
1184
|
-
if (refs.target === "jsonSchema7")
|
|
1185
|
-
|
|
1186
|
-
|
|
1175
|
+
if (refs.target === "jsonSchema7") {
|
|
1176
|
+
if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1177
|
+
else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
1178
|
+
} else {
|
|
1187
1179
|
if (!check.inclusive) res.exclusiveMaximum = true;
|
|
1188
1180
|
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1189
1181
|
}
|
|
1190
1182
|
break;
|
|
1191
|
-
case "multipleOf":
|
|
1192
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1193
|
-
break;
|
|
1183
|
+
case "multipleOf": setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1194
1184
|
}
|
|
1195
1185
|
return res;
|
|
1196
1186
|
}
|
|
@@ -1609,7 +1599,6 @@ function fixJson(input) {
|
|
|
1609
1599
|
stack.pop();
|
|
1610
1600
|
stack.push(swapState);
|
|
1611
1601
|
stack.push("INSIDE_ARRAY_START");
|
|
1612
|
-
break;
|
|
1613
1602
|
}
|
|
1614
1603
|
}
|
|
1615
1604
|
function processAfterObjectValue(char, i) {
|
|
@@ -1621,7 +1610,6 @@ function fixJson(input) {
|
|
|
1621
1610
|
case "}":
|
|
1622
1611
|
lastValidIndex = i;
|
|
1623
1612
|
stack.pop();
|
|
1624
|
-
break;
|
|
1625
1613
|
}
|
|
1626
1614
|
}
|
|
1627
1615
|
function processAfterArrayValue(char, i) {
|
|
@@ -1633,7 +1621,6 @@ function fixJson(input) {
|
|
|
1633
1621
|
case "]":
|
|
1634
1622
|
lastValidIndex = i;
|
|
1635
1623
|
stack.pop();
|
|
1636
|
-
break;
|
|
1637
1624
|
}
|
|
1638
1625
|
}
|
|
1639
1626
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -1651,7 +1638,6 @@ function fixJson(input) {
|
|
|
1651
1638
|
case "}":
|
|
1652
1639
|
lastValidIndex = i;
|
|
1653
1640
|
stack.pop();
|
|
1654
|
-
break;
|
|
1655
1641
|
}
|
|
1656
1642
|
break;
|
|
1657
1643
|
case "INSIDE_OBJECT_AFTER_COMMA":
|
|
@@ -1659,7 +1645,6 @@ function fixJson(input) {
|
|
|
1659
1645
|
case "\"":
|
|
1660
1646
|
stack.pop();
|
|
1661
1647
|
stack.push("INSIDE_OBJECT_KEY");
|
|
1662
|
-
break;
|
|
1663
1648
|
}
|
|
1664
1649
|
break;
|
|
1665
1650
|
case "INSIDE_OBJECT_KEY":
|
|
@@ -1667,7 +1652,6 @@ function fixJson(input) {
|
|
|
1667
1652
|
case "\"":
|
|
1668
1653
|
stack.pop();
|
|
1669
1654
|
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
1670
|
-
break;
|
|
1671
1655
|
}
|
|
1672
1656
|
break;
|
|
1673
1657
|
case "INSIDE_OBJECT_AFTER_KEY":
|
|
@@ -1675,7 +1659,6 @@ function fixJson(input) {
|
|
|
1675
1659
|
case ":":
|
|
1676
1660
|
stack.pop();
|
|
1677
1661
|
stack.push("INSIDE_OBJECT_BEFORE_VALUE");
|
|
1678
|
-
break;
|
|
1679
1662
|
}
|
|
1680
1663
|
break;
|
|
1681
1664
|
case "INSIDE_OBJECT_BEFORE_VALUE":
|
|
@@ -1705,7 +1688,6 @@ function fixJson(input) {
|
|
|
1705
1688
|
default:
|
|
1706
1689
|
lastValidIndex = i;
|
|
1707
1690
|
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
1708
|
-
break;
|
|
1709
1691
|
}
|
|
1710
1692
|
break;
|
|
1711
1693
|
case "INSIDE_ARRAY_AFTER_VALUE":
|
|
@@ -1718,9 +1700,7 @@ function fixJson(input) {
|
|
|
1718
1700
|
lastValidIndex = i;
|
|
1719
1701
|
stack.pop();
|
|
1720
1702
|
break;
|
|
1721
|
-
default:
|
|
1722
|
-
lastValidIndex = i;
|
|
1723
|
-
break;
|
|
1703
|
+
default: lastValidIndex = i;
|
|
1724
1704
|
}
|
|
1725
1705
|
break;
|
|
1726
1706
|
case "INSIDE_ARRAY_AFTER_COMMA":
|
|
@@ -1761,9 +1741,7 @@ function fixJson(input) {
|
|
|
1761
1741
|
stack.pop();
|
|
1762
1742
|
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") processAfterArrayValue(char, i);
|
|
1763
1743
|
break;
|
|
1764
|
-
default:
|
|
1765
|
-
stack.pop();
|
|
1766
|
-
break;
|
|
1744
|
+
default: stack.pop();
|
|
1767
1745
|
}
|
|
1768
1746
|
break;
|
|
1769
1747
|
case "INSIDE_LITERAL": {
|
|
@@ -3508,7 +3486,10 @@ function convertSchemaToZod(schema) {
|
|
|
3508
3486
|
function applyCompatLayer({ schema, compatLayers, mode }) {
|
|
3509
3487
|
if (mode === "jsonSchema") {
|
|
3510
3488
|
const standardSchema = require_schema.toStandardSchema(schema);
|
|
3511
|
-
for (const compat of compatLayers) if (compat.shouldApply())
|
|
3489
|
+
for (const compat of compatLayers) if (compat.shouldApply()) {
|
|
3490
|
+
const compatSchema = compat.processToCompatSchema(standardSchema);
|
|
3491
|
+
return require_schema.standardSchemaToJSONSchema(compatSchema);
|
|
3492
|
+
}
|
|
3512
3493
|
return require_schema.standardSchemaToJSONSchema(standardSchema);
|
|
3513
3494
|
} else {
|
|
3514
3495
|
let zodSchema;
|
|
@@ -3803,12 +3784,18 @@ var SchemaCompatLayer$1 = class {
|
|
|
3803
3784
|
const processedType = this.processZodType(zodArrayDef.type);
|
|
3804
3785
|
let result = zod_v3.z.array(processedType);
|
|
3805
3786
|
const constraints = [];
|
|
3806
|
-
if (zodArrayDef.minLength?.value !== void 0)
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
if (zodArrayDef.
|
|
3811
|
-
|
|
3787
|
+
if (zodArrayDef.minLength?.value !== void 0) {
|
|
3788
|
+
if (handleChecks.includes("min")) constraints.push(`minimum length ${zodArrayDef.minLength.value}`);
|
|
3789
|
+
else result = result.min(zodArrayDef.minLength.value);
|
|
3790
|
+
}
|
|
3791
|
+
if (zodArrayDef.maxLength?.value !== void 0) {
|
|
3792
|
+
if (handleChecks.includes("max")) constraints.push(`maximum length ${zodArrayDef.maxLength.value}`);
|
|
3793
|
+
else result = result.max(zodArrayDef.maxLength.value);
|
|
3794
|
+
}
|
|
3795
|
+
if (zodArrayDef.exactLength?.value !== void 0) {
|
|
3796
|
+
if (handleChecks.includes("length")) constraints.push(`exact length ${zodArrayDef.exactLength.value}`);
|
|
3797
|
+
else result = result.length(zodArrayDef.exactLength.value);
|
|
3798
|
+
}
|
|
3812
3799
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
3813
3800
|
if (description) result = result.describe(description);
|
|
3814
3801
|
return result;
|
|
@@ -3838,23 +3825,23 @@ var SchemaCompatLayer$1 = class {
|
|
|
3838
3825
|
const constraints = [];
|
|
3839
3826
|
const checks = value._def.checks || [];
|
|
3840
3827
|
const newChecks = [];
|
|
3841
|
-
for (const check of checks) if ("kind" in check)
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
constraints.push(`${check.kind}imum length ${check.value}`);
|
|
3855
|
-
|
|
3828
|
+
for (const check of checks) if ("kind" in check) {
|
|
3829
|
+
if (handleChecks.includes(check.kind)) switch (check.kind) {
|
|
3830
|
+
case "regex":
|
|
3831
|
+
constraints.push(`input must match this regex ${check.regex.source}`);
|
|
3832
|
+
break;
|
|
3833
|
+
case "emoji":
|
|
3834
|
+
case "email":
|
|
3835
|
+
case "url":
|
|
3836
|
+
case "uuid":
|
|
3837
|
+
case "cuid":
|
|
3838
|
+
constraints.push(`a valid ${check.kind}`);
|
|
3839
|
+
break;
|
|
3840
|
+
case "min":
|
|
3841
|
+
case "max": constraints.push(`${check.kind}imum length ${check.value}`);
|
|
3842
|
+
}
|
|
3843
|
+
else newChecks.push(check);
|
|
3856
3844
|
}
|
|
3857
|
-
else newChecks.push(check);
|
|
3858
3845
|
let result = zod_v3.z.string();
|
|
3859
3846
|
for (const check of newChecks) result = result._addCheck(check);
|
|
3860
3847
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
@@ -3872,20 +3859,20 @@ var SchemaCompatLayer$1 = class {
|
|
|
3872
3859
|
const constraints = [];
|
|
3873
3860
|
const checks = value._def.checks || [];
|
|
3874
3861
|
const newChecks = [];
|
|
3875
|
-
for (const check of checks) if ("kind" in check)
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
constraints.push(`multiple of ${check.value}`);
|
|
3886
|
-
|
|
3862
|
+
for (const check of checks) if ("kind" in check) {
|
|
3863
|
+
if (handleChecks.includes(check.kind)) switch (check.kind) {
|
|
3864
|
+
case "min":
|
|
3865
|
+
if (check.inclusive) constraints.push(`greater than or equal to ${check.value}`);
|
|
3866
|
+
else constraints.push(`greater than ${check.value}`);
|
|
3867
|
+
break;
|
|
3868
|
+
case "max":
|
|
3869
|
+
if (check.inclusive) constraints.push(`lower than or equal to ${check.value}`);
|
|
3870
|
+
else constraints.push(`lower than ${check.value}`);
|
|
3871
|
+
break;
|
|
3872
|
+
case "multipleOf": constraints.push(`multiple of ${check.value}`);
|
|
3873
|
+
}
|
|
3874
|
+
else newChecks.push(check);
|
|
3887
3875
|
}
|
|
3888
|
-
else newChecks.push(check);
|
|
3889
3876
|
let result = zod_v3.z.number();
|
|
3890
3877
|
for (const check of newChecks) switch (check.kind) {
|
|
3891
3878
|
case "int":
|
|
@@ -4276,12 +4263,18 @@ var SchemaCompatLayer$2 = class {
|
|
|
4276
4263
|
let result = zod_v4.z.array(processedType);
|
|
4277
4264
|
const constraints = [];
|
|
4278
4265
|
if (zodArrayDef.checks) for (const check of zodArrayDef.checks) {
|
|
4279
|
-
if (check._zod.def.check === "min_length")
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
if (check._zod.def.check === "
|
|
4284
|
-
|
|
4266
|
+
if (check._zod.def.check === "min_length") {
|
|
4267
|
+
if (handleChecks.includes("min")) constraints.push(`minimum length ${check._zod.def.minimum}`);
|
|
4268
|
+
else result = result.min(check._zod.def.minimum);
|
|
4269
|
+
}
|
|
4270
|
+
if (check._zod.def.check === "max_length") {
|
|
4271
|
+
if (handleChecks.includes("max")) constraints.push(`maximum length ${check._zod.def.maximum}`);
|
|
4272
|
+
else result = result.max(check._zod.def.maximum);
|
|
4273
|
+
}
|
|
4274
|
+
if (check._zod.def.check === "length_equals") {
|
|
4275
|
+
if (handleChecks.includes("length")) constraints.push(`exact length ${check._zod.def.length}`);
|
|
4276
|
+
else result = result.length(check._zod.def.length);
|
|
4277
|
+
}
|
|
4285
4278
|
}
|
|
4286
4279
|
const metaDescription = value.meta()?.description;
|
|
4287
4280
|
const legacyDescription = value.description;
|
|
@@ -4321,23 +4314,19 @@ var SchemaCompatLayer$2 = class {
|
|
|
4321
4314
|
case "max_length":
|
|
4322
4315
|
constraints.push(`maximum length ${check._zod.def.maximum}`);
|
|
4323
4316
|
break;
|
|
4324
|
-
case "string_format":
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
newChecks.push(check);
|
|
4338
|
-
break;
|
|
4339
|
-
}
|
|
4340
|
-
break;
|
|
4317
|
+
case "string_format": switch (check._zod.def.format) {
|
|
4318
|
+
case "email":
|
|
4319
|
+
case "url":
|
|
4320
|
+
case "emoji":
|
|
4321
|
+
case "uuid":
|
|
4322
|
+
case "cuid":
|
|
4323
|
+
constraints.push(`a valid ${check._zod.def.format}`);
|
|
4324
|
+
break;
|
|
4325
|
+
case "regex":
|
|
4326
|
+
constraints.push(`input must match this regex ${check._zod.def.pattern}`);
|
|
4327
|
+
break;
|
|
4328
|
+
default: newChecks.push(check);
|
|
4329
|
+
}
|
|
4341
4330
|
}
|
|
4342
4331
|
else newChecks.push(check);
|
|
4343
4332
|
let result = zod_v4.z.string();
|
|
@@ -4368,18 +4357,14 @@ var SchemaCompatLayer$2 = class {
|
|
|
4368
4357
|
if (check._zod.def.inclusive) constraints.push(`lower than or equal to ${check._zod.def.value}`);
|
|
4369
4358
|
else constraints.push(`lower than ${check._zod.def.value}`);
|
|
4370
4359
|
break;
|
|
4371
|
-
case "multiple_of":
|
|
4372
|
-
constraints.push(`multiple of ${check._zod.def.value}`);
|
|
4373
|
-
break;
|
|
4360
|
+
case "multiple_of": constraints.push(`multiple of ${check._zod.def.value}`);
|
|
4374
4361
|
}
|
|
4375
4362
|
else newChecks.push(check);
|
|
4376
4363
|
let result = zod_v4.z.number();
|
|
4377
4364
|
for (const check of newChecks) switch (check._zod.def.check) {
|
|
4378
4365
|
case "number_format":
|
|
4379
4366
|
switch (check._zod.def.format) {
|
|
4380
|
-
case "safeint":
|
|
4381
|
-
result = result.int();
|
|
4382
|
-
break;
|
|
4367
|
+
case "safeint": result = result.int();
|
|
4383
4368
|
}
|
|
4384
4369
|
break;
|
|
4385
4370
|
default: result = result.check(check);
|
|
@@ -4672,12 +4657,13 @@ var SchemaCompatLayer = class {
|
|
|
4672
4657
|
if (!v4Type) return value;
|
|
4673
4658
|
innerTypeName = "Zod" + v4Type.charAt(0).toUpperCase() + v4Type.slice(1);
|
|
4674
4659
|
} else innerTypeName = value._def.innerType._def.typeName;
|
|
4675
|
-
if (handleTypes.includes(innerTypeName))
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4660
|
+
if (handleTypes.includes(innerTypeName)) {
|
|
4661
|
+
if ("_zod" in value) {
|
|
4662
|
+
const innerType = value._zod?.def?.innerType;
|
|
4663
|
+
if (!innerType) return value;
|
|
4664
|
+
return this.processZodType(innerType).optional();
|
|
4665
|
+
} else return this.processZodType(value._def.innerType).optional();
|
|
4666
|
+
} else return value;
|
|
4681
4667
|
}
|
|
4682
4668
|
defaultZodNullableHandler(value, handleTypes) {
|
|
4683
4669
|
if ("_zod" in value) return this.v4Layer.defaultZodNullableHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES$2);
|
|
@@ -4700,7 +4686,8 @@ var SchemaCompatLayer = class {
|
|
|
4700
4686
|
* @returns
|
|
4701
4687
|
*/
|
|
4702
4688
|
processToJSONSchema(schema, io = "input") {
|
|
4703
|
-
const
|
|
4689
|
+
const standardSchema = require_schema.toStandardSchema(schema);
|
|
4690
|
+
const jsonSchema = require_schema.standardSchemaToJSONSchema(standardSchema, {
|
|
4704
4691
|
target: "draft-07",
|
|
4705
4692
|
io
|
|
4706
4693
|
});
|
|
@@ -4788,7 +4775,6 @@ var SchemaCompatLayer = class {
|
|
|
4788
4775
|
constraints.push(`a valid ${schema.format}`);
|
|
4789
4776
|
delete schema.pattern;
|
|
4790
4777
|
delete schema.format;
|
|
4791
|
-
break;
|
|
4792
4778
|
}
|
|
4793
4779
|
if (constraints.length === 0 && schema.pattern !== void 0) {
|
|
4794
4780
|
constraints.push(`input must match this regex ${schema.pattern}`);
|
|
@@ -4943,7 +4929,8 @@ var SchemaCompatLayer = class {
|
|
|
4943
4929
|
};
|
|
4944
4930
|
const schemaTarget = this.getSchemaTarget();
|
|
4945
4931
|
const target = (schemaTarget && SCHEMA_TARGET_TO_STANDARD[schemaTarget]) ?? schemaTarget;
|
|
4946
|
-
const
|
|
4932
|
+
const standardSchema = require_schema.toStandardSchema(zodSchema);
|
|
4933
|
+
const jsonSchema = require_schema.standardSchemaToJSONSchema(standardSchema, {
|
|
4947
4934
|
target,
|
|
4948
4935
|
io: "input"
|
|
4949
4936
|
});
|
|
@@ -5217,7 +5204,8 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
5217
5204
|
* which causes OpenAI strict mode to reject tool schemas missing additionalProperties: false.
|
|
5218
5205
|
*/
|
|
5219
5206
|
processToAISDKSchema(zodSchema) {
|
|
5220
|
-
const
|
|
5207
|
+
const compat = this.processToCompatSchema(zodSchema);
|
|
5208
|
+
const transformedJsonSchema = require_schema.standardSchemaToJSONSchema(compat);
|
|
5221
5209
|
return jsonSchema(transformedJsonSchema, { validate: (value) => {
|
|
5222
5210
|
const transformed = this.#traverse(value, transformedJsonSchema);
|
|
5223
5211
|
const result = zodSchema.safeParse(transformed);
|
|
@@ -5394,14 +5382,16 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
5394
5382
|
prop.anyOf = [propSchema, { type: "null" }];
|
|
5395
5383
|
}
|
|
5396
5384
|
} else if (prop.type === void 0 && Array.isArray(prop.anyOf)) {
|
|
5397
|
-
if (!prop.anyOf.some((branch) => typeof branch !== "boolean" && branch.type === "null"))
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5385
|
+
if (!prop.anyOf.some((branch) => typeof branch !== "boolean" && branch.type === "null")) {
|
|
5386
|
+
if (genericConstraintKeywords.some((keyword) => keyword in prop)) {
|
|
5387
|
+
const branch = { anyOf: prop.anyOf };
|
|
5388
|
+
for (const keyword of genericConstraintKeywords) if (keyword in prop) {
|
|
5389
|
+
branch[keyword] = prop[keyword];
|
|
5390
|
+
delete prop[keyword];
|
|
5391
|
+
}
|
|
5392
|
+
prop.anyOf = [branch, { type: "null" }];
|
|
5393
|
+
} else prop.anyOf = [...prop.anyOf, { type: "null" }];
|
|
5394
|
+
}
|
|
5405
5395
|
}
|
|
5406
5396
|
}
|
|
5407
5397
|
}
|
|
@@ -5560,7 +5550,8 @@ function applyOpenAICompatTransforms(schema, modelInfo) {
|
|
|
5560
5550
|
const reasoningLayer = new OpenAIReasoningSchemaCompatLayer(modelInfo);
|
|
5561
5551
|
const compatLayer = reasoningLayer.isReasoningModel() ? reasoningLayer : new OpenAISchemaCompatLayer(modelInfo);
|
|
5562
5552
|
if (!compatLayer.shouldApply()) return schema;
|
|
5563
|
-
|
|
5553
|
+
const processedZodSchema = compatLayer.processZodType(zodSchema);
|
|
5554
|
+
return require_schema.toStandardSchema(processedZodSchema);
|
|
5564
5555
|
}
|
|
5565
5556
|
/**
|
|
5566
5557
|
* Applies OpenAI compat transforms to all tools in a toolset.
|
|
@@ -5648,9 +5639,10 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
5648
5639
|
} else if (this.isObj(value)) return this.defaultZodObjectHandler(value);
|
|
5649
5640
|
else if (this.isArr(value)) return this.defaultZodArrayHandler(value, []);
|
|
5650
5641
|
else if (this.isUnion(value)) return this.defaultZodUnionHandler(value);
|
|
5651
|
-
else if (this.isString(value))
|
|
5652
|
-
|
|
5653
|
-
|
|
5642
|
+
else if (this.isString(value)) {
|
|
5643
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
5644
|
+
else return value;
|
|
5645
|
+
} else if (isNull(zod.z)(value)) return zod.z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5654
5646
|
else if (isIntersection(zod.z)(value)) return this.defaultZodIntersectionHandler(value);
|
|
5655
5647
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
5656
5648
|
}
|
|
@@ -5815,12 +5807,10 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
5815
5807
|
case "promise":
|
|
5816
5808
|
replace("innerType");
|
|
5817
5809
|
break;
|
|
5818
|
-
case "lazy":
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
};
|
|
5823
|
-
break;
|
|
5810
|
+
case "lazy": nextDef = {
|
|
5811
|
+
...def,
|
|
5812
|
+
getter: () => strip(def.getter())
|
|
5813
|
+
};
|
|
5824
5814
|
}
|
|
5825
5815
|
if (nextDef === def) {
|
|
5826
5816
|
schemas.set(value, value);
|
|
@@ -5934,12 +5924,10 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
5934
5924
|
replace("in");
|
|
5935
5925
|
replace("out");
|
|
5936
5926
|
break;
|
|
5937
|
-
case "ZodLazy":
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
};
|
|
5942
|
-
break;
|
|
5927
|
+
case "ZodLazy": nextDef = {
|
|
5928
|
+
...def,
|
|
5929
|
+
getter: () => strip(def.getter())
|
|
5930
|
+
};
|
|
5943
5931
|
}
|
|
5944
5932
|
if (nextDef === def) {
|
|
5945
5933
|
schemas.set(value, value);
|
|
@@ -5989,7 +5977,8 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
5989
5977
|
return value;
|
|
5990
5978
|
}
|
|
5991
5979
|
processToAISDKSchema(zodSchema) {
|
|
5992
|
-
const
|
|
5980
|
+
const compat = this.processToCompatSchema(zodSchema);
|
|
5981
|
+
const transformedJsonSchema = require_schema.standardSchemaToJSONSchema(compat);
|
|
5993
5982
|
return jsonSchema(transformedJsonSchema, { validate: (value) => {
|
|
5994
5983
|
const transformed = this.#traverse(value, transformedJsonSchema);
|
|
5995
5984
|
const result = zodSchema.safeParse(transformed);
|
|
@@ -6091,8 +6080,10 @@ function fixAISDKNullableUnionTypes(schema) {
|
|
|
6091
6080
|
}
|
|
6092
6081
|
}
|
|
6093
6082
|
if (result.properties && typeof result.properties === "object") result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, fixAISDKNullableUnionTypes(value)]));
|
|
6094
|
-
if (result.items)
|
|
6095
|
-
|
|
6083
|
+
if (result.items) {
|
|
6084
|
+
if (Array.isArray(result.items)) result.items = result.items.map((item) => fixAISDKNullableUnionTypes(item));
|
|
6085
|
+
else result.items = fixAISDKNullableUnionTypes(result.items);
|
|
6086
|
+
}
|
|
6096
6087
|
if (result.additionalProperties && typeof result.additionalProperties === "object") result.additionalProperties = fixAISDKNullableUnionTypes(result.additionalProperties);
|
|
6097
6088
|
if (result.anyOf && Array.isArray(result.anyOf)) result.anyOf = result.anyOf.map((s) => fixAISDKNullableUnionTypes(s));
|
|
6098
6089
|
if (result.oneOf && Array.isArray(result.oneOf)) result.oneOf = result.oneOf.map((s) => fixAISDKNullableUnionTypes(s));
|
|
@@ -6180,7 +6171,8 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
6180
6171
|
return result;
|
|
6181
6172
|
}
|
|
6182
6173
|
processToAISDKSchema(zodSchema) {
|
|
6183
|
-
const
|
|
6174
|
+
const compat = this.processToCompatSchema(zodSchema);
|
|
6175
|
+
const fixedJsonSchema = fixAISDKNullableUnionTypes(require_schema.standardSchemaToJSONSchema(compat));
|
|
6184
6176
|
return jsonSchema(fixedJsonSchema, { validate: (value) => {
|
|
6185
6177
|
const transformed = this.#traverse(value, fixedJsonSchema);
|
|
6186
6178
|
const result = zodSchema.safeParse(transformed);
|
|
@@ -6340,7 +6332,8 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
6340
6332
|
return value;
|
|
6341
6333
|
}
|
|
6342
6334
|
processToAISDKSchema(zodSchema) {
|
|
6343
|
-
const
|
|
6335
|
+
const compat = this.processToCompatSchema(zodSchema);
|
|
6336
|
+
const transformedJsonSchema = require_schema.standardSchemaToJSONSchema(compat);
|
|
6344
6337
|
return jsonSchema(transformedJsonSchema, { validate: (value) => {
|
|
6345
6338
|
const transformed = this.#traverse(value, transformedJsonSchema);
|
|
6346
6339
|
const result = zodSchema.safeParse(transformed);
|