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