@ai-sdk/provider-utils 4.0.0-beta.11 → 4.0.0-beta.12
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 +6 -0
- package/dist/index.d.mts +14 -15
- package/dist/index.d.ts +14 -15
- package/dist/index.js +87 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -2
package/dist/index.mjs
CHANGED
@@ -194,7 +194,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
194
194
|
}
|
195
195
|
|
196
196
|
// src/version.ts
|
197
|
-
var VERSION = true ? "4.0.0-beta.
|
197
|
+
var VERSION = true ? "4.0.0-beta.12" : "0.0.0-test";
|
198
198
|
|
199
199
|
// src/get-from-api.ts
|
200
200
|
var getOriginalFetch = () => globalThis.fetch;
|
@@ -495,9 +495,9 @@ function lazyValidator(createValidator) {
|
|
495
495
|
function asValidator(value) {
|
496
496
|
return isValidator(value) ? value : typeof value === "function" ? value() : standardSchemaValidator(value);
|
497
497
|
}
|
498
|
-
function standardSchemaValidator(
|
498
|
+
function standardSchemaValidator(standardSchema2) {
|
499
499
|
return validator(async (value) => {
|
500
|
-
const result = await
|
500
|
+
const result = await standardSchema2["~standard"].validate(value);
|
501
501
|
return result.issues == null ? { success: true, value: result.value } : {
|
502
502
|
success: false,
|
503
503
|
error: new TypeValidationError({
|
@@ -993,9 +993,20 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
993
993
|
};
|
994
994
|
};
|
995
995
|
|
996
|
-
// src/
|
996
|
+
// src/schema.ts
|
997
|
+
import { TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
|
997
998
|
import * as z4 from "zod/v4";
|
998
999
|
|
1000
|
+
// src/valibot-to-json-schema/valibot-to-json-schema.ts
|
1001
|
+
var valibotToJsonSchema = async (schema) => {
|
1002
|
+
try {
|
1003
|
+
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
1004
|
+
return toJsonSchema(schema);
|
1005
|
+
} catch (e) {
|
1006
|
+
throw new Error(`Failed to import @valibot/to-json-schema`);
|
1007
|
+
}
|
1008
|
+
};
|
1009
|
+
|
999
1010
|
// src/zod-to-json-schema/get-relative-path.ts
|
1000
1011
|
var getRelativePath = (pathA, pathB) => {
|
1001
1012
|
let i = 0;
|
@@ -2179,7 +2190,78 @@ var zodToJsonSchema = (schema, options) => {
|
|
2179
2190
|
// src/zod-to-json-schema/index.ts
|
2180
2191
|
var zod_to_json_schema_default = zodToJsonSchema;
|
2181
2192
|
|
2182
|
-
// src/
|
2193
|
+
// src/schema.ts
|
2194
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
2195
|
+
function lazySchema(createSchema) {
|
2196
|
+
let schema;
|
2197
|
+
return () => {
|
2198
|
+
if (schema == null) {
|
2199
|
+
schema = createSchema();
|
2200
|
+
}
|
2201
|
+
return schema;
|
2202
|
+
};
|
2203
|
+
}
|
2204
|
+
function jsonSchema(jsonSchema2, {
|
2205
|
+
validate
|
2206
|
+
} = {}) {
|
2207
|
+
return {
|
2208
|
+
[schemaSymbol]: true,
|
2209
|
+
_type: void 0,
|
2210
|
+
// should never be used directly
|
2211
|
+
[validatorSymbol]: true,
|
2212
|
+
get jsonSchema() {
|
2213
|
+
if (typeof jsonSchema2 === "function") {
|
2214
|
+
jsonSchema2 = jsonSchema2();
|
2215
|
+
}
|
2216
|
+
return jsonSchema2;
|
2217
|
+
},
|
2218
|
+
validate
|
2219
|
+
};
|
2220
|
+
}
|
2221
|
+
function isSchema(value) {
|
2222
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
2223
|
+
}
|
2224
|
+
function asSchema(schema) {
|
2225
|
+
return schema == null ? jsonSchema({
|
2226
|
+
properties: {},
|
2227
|
+
additionalProperties: false
|
2228
|
+
}) : isSchema(schema) ? schema : typeof schema === "function" ? schema() : standardSchema(schema);
|
2229
|
+
}
|
2230
|
+
function standardSchema(standardSchema2) {
|
2231
|
+
const vendor = standardSchema2["~standard"].vendor;
|
2232
|
+
switch (vendor) {
|
2233
|
+
case "zod": {
|
2234
|
+
return zodSchema(
|
2235
|
+
standardSchema2
|
2236
|
+
);
|
2237
|
+
}
|
2238
|
+
case "valibot": {
|
2239
|
+
return standardSchemaWithJsonSchemaResolver(
|
2240
|
+
standardSchema2,
|
2241
|
+
valibotToJsonSchema
|
2242
|
+
);
|
2243
|
+
}
|
2244
|
+
default: {
|
2245
|
+
return standardSchemaWithJsonSchemaResolver(standardSchema2, () => {
|
2246
|
+
throw new Error(`Unsupported standard schema vendor: ${vendor}`);
|
2247
|
+
});
|
2248
|
+
}
|
2249
|
+
}
|
2250
|
+
}
|
2251
|
+
function standardSchemaWithJsonSchemaResolver(standardSchema2, jsonSchemaResolver) {
|
2252
|
+
return jsonSchema(jsonSchemaResolver(standardSchema2), {
|
2253
|
+
validate: async (value) => {
|
2254
|
+
const result = await standardSchema2["~standard"].validate(value);
|
2255
|
+
return "value" in result ? { success: true, value: result.value } : {
|
2256
|
+
success: false,
|
2257
|
+
error: new TypeValidationError4({
|
2258
|
+
value,
|
2259
|
+
cause: result.issues
|
2260
|
+
})
|
2261
|
+
};
|
2262
|
+
}
|
2263
|
+
});
|
2264
|
+
}
|
2183
2265
|
function zod3Schema(zodSchema2, options) {
|
2184
2266
|
var _a;
|
2185
2267
|
const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
|
@@ -2225,44 +2307,6 @@ function zodSchema(zodSchema2, options) {
|
|
2225
2307
|
}
|
2226
2308
|
}
|
2227
2309
|
|
2228
|
-
// src/schema.ts
|
2229
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
2230
|
-
function lazySchema(createSchema) {
|
2231
|
-
let schema;
|
2232
|
-
return () => {
|
2233
|
-
if (schema == null) {
|
2234
|
-
schema = createSchema();
|
2235
|
-
}
|
2236
|
-
return schema;
|
2237
|
-
};
|
2238
|
-
}
|
2239
|
-
function jsonSchema(jsonSchema2, {
|
2240
|
-
validate
|
2241
|
-
} = {}) {
|
2242
|
-
return {
|
2243
|
-
[schemaSymbol]: true,
|
2244
|
-
_type: void 0,
|
2245
|
-
// should never be used directly
|
2246
|
-
[validatorSymbol]: true,
|
2247
|
-
get jsonSchema() {
|
2248
|
-
if (typeof jsonSchema2 === "function") {
|
2249
|
-
jsonSchema2 = jsonSchema2();
|
2250
|
-
}
|
2251
|
-
return jsonSchema2;
|
2252
|
-
},
|
2253
|
-
validate
|
2254
|
-
};
|
2255
|
-
}
|
2256
|
-
function isSchema(value) {
|
2257
|
-
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
2258
|
-
}
|
2259
|
-
function asSchema(schema) {
|
2260
|
-
return schema == null ? jsonSchema({
|
2261
|
-
properties: {},
|
2262
|
-
additionalProperties: false
|
2263
|
-
}) : isSchema(schema) ? schema : typeof schema === "function" ? schema() : zodSchema(schema);
|
2264
|
-
}
|
2265
|
-
|
2266
2310
|
// src/uint8-utils.ts
|
2267
2311
|
var { btoa, atob } = globalThis;
|
2268
2312
|
function convertBase64ToUint8Array(base64String) {
|