@mastra/schema-compat 1.3.17 → 1.3.18-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/dist/_types/{@internal_ai-sdk-v4 → @internal_ai-sdk-v4@0.0.95}/dist/index.d.ts +52 -13
- package/dist/_types/{@internal_ai-sdk-v5 → @internal_ai-sdk-v5@0.0.95}/dist/index.d.ts +145 -43
- package/dist/_types/{@internal_ai-v6 → @internal_ai-v6@0.0.95}/dist/index.d.ts +151 -31
- package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/resolve.d.ts +1 -1
- package/dist/_types/{ajv → ajv@8.20.0}/dist/types/index.d.ts +1 -1
- package/dist/index.cjs +67 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -2
- package/dist/index.js.map +1 -1
- package/dist/json-schema/utils.d.ts +1 -1
- package/dist/json-schema.d.ts +3 -3
- package/dist/provider-compats/anthropic.d.ts +2 -2
- package/dist/provider-compats/deepseek.d.ts +2 -2
- package/dist/provider-compats/google.d.ts +1 -1
- package/dist/provider-compats/google.d.ts.map +1 -1
- package/dist/provider-compats/meta.d.ts +2 -2
- package/dist/provider-compats/openai.d.ts +1 -1
- package/dist/schema.types.d.ts +4 -4
- package/dist/standard-schema/adapters/ai-sdk.d.ts +2 -2
- package/dist/standard-schema/adapters/json-schema.d.ts +2 -2
- package/dist/standard-schema/adapters/zod-v4.d.ts +1 -1
- package/dist/standard-schema/standard-schema.d.ts +2 -2
- package/dist/standard-schema/standard-schema.types.d.ts +1 -1
- package/dist/zod-to-json.d.ts +1 -1
- package/package.json +14 -14
- /package/dist/_types/{@internal_ai-sdk-v4 → @internal_ai-sdk-v4@0.0.95}/package.json +0 -0
- /package/dist/_types/{@internal_ai-sdk-v5 → @internal_ai-sdk-v5@0.0.95}/package.json +0 -0
- /package/dist/_types/{@internal_ai-v6 → @internal_ai-v6@0.0.95}/package.json +0 -0
- /package/dist/_types/{@standard-schema_spec → @standard-schema_spec@1.1.0}/dist/index.d.ts +0 -0
- /package/dist/_types/{@standard-schema_spec → @standard-schema_spec@1.1.0}/package.json +0 -0
- /package/dist/_types/{@types_json-schema → @types_json-schema@7.0.15}/index.d.ts +0 -0
- /package/dist/_types/{@types_json-schema → @types_json-schema@7.0.15}/package.json +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/ajv.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/codegen/code.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/codegen/index.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/codegen/scope.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/errors.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/index.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/ref_error.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/rules.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/util.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/validate/dataType.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/validate/index.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/compile/validate/subschema.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/core.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/runtime/validation_error.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/types/json-schema.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/types/jtd-schema.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/additionalItems.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/additionalProperties.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/anyOf.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/contains.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/dependencies.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/if.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/index.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/items2020.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/not.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/oneOf.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/applicator/propertyNames.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/discriminator/index.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/discriminator/types.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/errors.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/format/format.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/unevaluated/unevaluatedItems.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/unevaluated/unevaluatedProperties.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/const.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/dependentRequired.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/enum.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/index.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/limitNumber.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/multipleOf.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/pattern.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/required.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/dist/vocabularies/validation/uniqueItems.d.ts +0 -0
- /package/dist/_types/{ajv → ajv@8.20.0}/package.json +0 -0
- /package/dist/_types/{fast-uri → fast-uri@3.1.9}/package.json +0 -0
- /package/dist/_types/{fast-uri → fast-uri@3.1.9}/types/index.d.ts +0 -0
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-D0CId4oM.js";
|
|
2
|
-
import { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema as zodToJsonSchema$1 } from "./zod-to-json.js";
|
|
3
1
|
import { a as standardSchemaToJSONSchema, i as isStandardSchemaWithJSON, n as isStandardJSONSchema, o as toStandardSchema, r as isStandardSchema, t as JSON_SCHEMA_LIBRARY_OPTIONS } from "./schema-Bf12g7KC.js";
|
|
2
|
+
import { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema as zodToJsonSchema$1 } from "./zod-to-json.js";
|
|
3
|
+
import { r as __toESM$1, t as require_json_schema_traverse } from "./json-schema-traverse-D0CId4oM.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";
|
|
@@ -6080,6 +6080,63 @@ function fixAISDKNullableUnionTypes(schema) {
|
|
|
6080
6080
|
}
|
|
6081
6081
|
return result;
|
|
6082
6082
|
}
|
|
6083
|
+
function isNonEmptyString(value) {
|
|
6084
|
+
return typeof value === "string" && value !== "";
|
|
6085
|
+
}
|
|
6086
|
+
/**
|
|
6087
|
+
* The JSON Schema types of a set of literal values (all numbers count as one
|
|
6088
|
+
* `integer` or `number` type), or `undefined` when there are none or one is an
|
|
6089
|
+
* object or array.
|
|
6090
|
+
*/
|
|
6091
|
+
function inferLiteralTypes(values) {
|
|
6092
|
+
const numberType = values.every((value) => typeof value !== "number" || Number.isInteger(value)) ? "integer" : "number";
|
|
6093
|
+
const types = /* @__PURE__ */ new Set();
|
|
6094
|
+
for (const value of values) if (typeof value === "string" || typeof value === "boolean") types.add(typeof value);
|
|
6095
|
+
else if (typeof value === "number") types.add(numberType);
|
|
6096
|
+
else return;
|
|
6097
|
+
return types.size > 0 ? [...types] : void 0;
|
|
6098
|
+
}
|
|
6099
|
+
function appendDescription(description, note) {
|
|
6100
|
+
return typeof description === "string" && description !== "" ? `${description} ${note}` : note;
|
|
6101
|
+
}
|
|
6102
|
+
/** Nodes whose description got an allowed-values note from `toGeminiEnum`. */
|
|
6103
|
+
const nodesWithAllowedValuesNote = /* @__PURE__ */ new WeakSet();
|
|
6104
|
+
/**
|
|
6105
|
+
* Gemini's `Schema.enum` only accepts non-empty strings, so any other enum value
|
|
6106
|
+
* (numbers, booleans, `""`, `null`) makes the whole request fail with HTTP 400 (#29167).
|
|
6107
|
+
*
|
|
6108
|
+
* - A string enum on a string (or untyped) node is kept and gets `type: 'string'`;
|
|
6109
|
+
* a `null` among its values becomes `nullable: true`.
|
|
6110
|
+
* - Any other enum is dropped. The node keeps (or gets) a `type`, and the allowed
|
|
6111
|
+
* values move into `description` so the model still sees the constraint.
|
|
6112
|
+
*
|
|
6113
|
+
* Tool-call arguments are still validated against the original schema, so this
|
|
6114
|
+
* only changes what is sent to Gemini, not which inputs are accepted.
|
|
6115
|
+
*/
|
|
6116
|
+
function toGeminiEnum(s) {
|
|
6117
|
+
const values = s["enum"];
|
|
6118
|
+
if (!Array.isArray(values) || values.length === 0) return;
|
|
6119
|
+
const isStringNode = s["type"] === "string" || s["type"] === void 0 && s["anyOf"] === void 0;
|
|
6120
|
+
const hasNull = values.includes(null);
|
|
6121
|
+
const nonNull = values.filter((value) => value !== null);
|
|
6122
|
+
if (isStringNode && nonNull.length > 0 && nonNull.every(isNonEmptyString)) {
|
|
6123
|
+
s["enum"] = nonNull;
|
|
6124
|
+
s["type"] = "string";
|
|
6125
|
+
if (hasNull) s["nullable"] = true;
|
|
6126
|
+
return;
|
|
6127
|
+
}
|
|
6128
|
+
delete s["enum"];
|
|
6129
|
+
if (hasNull) s["nullable"] = true;
|
|
6130
|
+
if (s["type"] === void 0 && s["anyOf"] === void 0) {
|
|
6131
|
+
const types = inferLiteralTypes(nonNull);
|
|
6132
|
+
if (types?.length === 1) s["type"] = types[0];
|
|
6133
|
+
else if (types) s["anyOf"] = types.map((type) => ({ type }));
|
|
6134
|
+
}
|
|
6135
|
+
const formatted = values.map((value) => JSON.stringify(value));
|
|
6136
|
+
const note = formatted.length === 1 ? `Must be ${formatted[0]}.` : `Must be one of: ${formatted.join(", ")}.`;
|
|
6137
|
+
s["description"] = appendDescription(s["description"], note);
|
|
6138
|
+
nodesWithAllowedValuesNote.add(s);
|
|
6139
|
+
}
|
|
6083
6140
|
/**
|
|
6084
6141
|
* Inline `$ref` pointers one level and drop `definitions`/`$defs`.
|
|
6085
6142
|
* Gemini can't follow JSON Schema `$ref`s — they cause silent mis-fills.
|
|
@@ -6226,6 +6283,7 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
6226
6283
|
s["enum"] = [s["const"]];
|
|
6227
6284
|
delete s["const"];
|
|
6228
6285
|
}
|
|
6286
|
+
toGeminiEnum(s);
|
|
6229
6287
|
if (Array.isArray(s["items"])) {
|
|
6230
6288
|
s["items"] = { anyOf: s["items"] };
|
|
6231
6289
|
delete s["minItems"];
|
|
@@ -6237,8 +6295,15 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
6237
6295
|
const hasNull = variants.some((v) => v && typeof v === "object" && v["type"] === "null");
|
|
6238
6296
|
if (hasNull && nonNull.length === 1) {
|
|
6239
6297
|
const base = nonNull[0];
|
|
6298
|
+
const parentDescription = s["description"];
|
|
6299
|
+
const carriesNote = nodesWithAllowedValuesNote.has(s) || nodesWithAllowedValuesNote.has(base);
|
|
6240
6300
|
delete s["anyOf"];
|
|
6241
6301
|
Object.assign(s, base);
|
|
6302
|
+
if (carriesNote) {
|
|
6303
|
+
const baseDescription = base["description"];
|
|
6304
|
+
if (isNonEmptyString(parentDescription) && isNonEmptyString(baseDescription) && !baseDescription.startsWith(parentDescription)) s["description"] = appendDescription(parentDescription, baseDescription);
|
|
6305
|
+
nodesWithAllowedValuesNote.add(s);
|
|
6306
|
+
}
|
|
6242
6307
|
s["nullable"] = true;
|
|
6243
6308
|
} else if (hasNull && nonNull.length > 1) {
|
|
6244
6309
|
s["anyOf"] = nonNull;
|