@ai-sdk/provider-utils 4.0.0-beta.11 → 4.0.0-beta.13

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/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.11" : "0.0.0-test";
197
+ var VERSION = true ? "4.0.0-beta.13" : "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(standardSchema) {
498
+ function standardSchemaValidator(standardSchema2) {
499
499
  return validator(async (value) => {
500
- const result = await standardSchema["~standard"].validate(value);
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,25 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
993
993
  };
994
994
  };
995
995
 
996
- // src/zod-schema.ts
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/to-json-schema/arktype-to-json-schema.ts
1001
+ var arktypeToJsonSchema = async (schema) => {
1002
+ return schema.toJsonSchema();
1003
+ };
1004
+
1005
+ // src/to-json-schema/valibot-to-json-schema.ts
1006
+ var valibotToJsonSchema = async (schema) => {
1007
+ try {
1008
+ const { toJsonSchema } = await import("@valibot/to-json-schema");
1009
+ return toJsonSchema(schema);
1010
+ } catch (e) {
1011
+ throw new Error(`Failed to import @valibot/to-json-schema`);
1012
+ }
1013
+ };
1014
+
999
1015
  // src/zod-to-json-schema/get-relative-path.ts
1000
1016
  var getRelativePath = (pathA, pathB) => {
1001
1017
  let i = 0;
@@ -2179,7 +2195,84 @@ var zodToJsonSchema = (schema, options) => {
2179
2195
  // src/zod-to-json-schema/index.ts
2180
2196
  var zod_to_json_schema_default = zodToJsonSchema;
2181
2197
 
2182
- // src/zod-schema.ts
2198
+ // src/schema.ts
2199
+ var schemaSymbol = Symbol.for("vercel.ai.schema");
2200
+ function lazySchema(createSchema) {
2201
+ let schema;
2202
+ return () => {
2203
+ if (schema == null) {
2204
+ schema = createSchema();
2205
+ }
2206
+ return schema;
2207
+ };
2208
+ }
2209
+ function jsonSchema(jsonSchema2, {
2210
+ validate
2211
+ } = {}) {
2212
+ return {
2213
+ [schemaSymbol]: true,
2214
+ _type: void 0,
2215
+ // should never be used directly
2216
+ [validatorSymbol]: true,
2217
+ get jsonSchema() {
2218
+ if (typeof jsonSchema2 === "function") {
2219
+ jsonSchema2 = jsonSchema2();
2220
+ }
2221
+ return jsonSchema2;
2222
+ },
2223
+ validate
2224
+ };
2225
+ }
2226
+ function isSchema(value) {
2227
+ return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
2228
+ }
2229
+ function asSchema(schema) {
2230
+ return schema == null ? jsonSchema({
2231
+ properties: {},
2232
+ additionalProperties: false
2233
+ }) : isSchema(schema) ? schema : "~standard" in schema ? standardSchema(schema) : schema();
2234
+ }
2235
+ function standardSchema(standardSchema2) {
2236
+ const vendor = standardSchema2["~standard"].vendor;
2237
+ switch (vendor) {
2238
+ case "zod": {
2239
+ return zodSchema(
2240
+ standardSchema2
2241
+ );
2242
+ }
2243
+ case "arktype": {
2244
+ return standardSchemaWithJsonSchemaResolver(
2245
+ standardSchema2,
2246
+ arktypeToJsonSchema
2247
+ );
2248
+ }
2249
+ case "valibot": {
2250
+ return standardSchemaWithJsonSchemaResolver(
2251
+ standardSchema2,
2252
+ valibotToJsonSchema
2253
+ );
2254
+ }
2255
+ default: {
2256
+ return standardSchemaWithJsonSchemaResolver(standardSchema2, () => {
2257
+ throw new Error(`Unsupported standard schema vendor: ${vendor}`);
2258
+ });
2259
+ }
2260
+ }
2261
+ }
2262
+ function standardSchemaWithJsonSchemaResolver(standardSchema2, jsonSchemaResolver) {
2263
+ return jsonSchema(jsonSchemaResolver(standardSchema2), {
2264
+ validate: async (value) => {
2265
+ const result = await standardSchema2["~standard"].validate(value);
2266
+ return "value" in result ? { success: true, value: result.value } : {
2267
+ success: false,
2268
+ error: new TypeValidationError4({
2269
+ value,
2270
+ cause: result.issues
2271
+ })
2272
+ };
2273
+ }
2274
+ });
2275
+ }
2183
2276
  function zod3Schema(zodSchema2, options) {
2184
2277
  var _a;
2185
2278
  const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
@@ -2225,44 +2318,6 @@ function zodSchema(zodSchema2, options) {
2225
2318
  }
2226
2319
  }
2227
2320
 
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
2321
  // src/uint8-utils.ts
2267
2322
  var { btoa, atob } = globalThis;
2268
2323
  function convertBase64ToUint8Array(base64String) {