@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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +14 -15
- package/dist/index.d.ts +14 -15
- package/dist/index.js +98 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -350,7 +350,7 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
|
350
350
|
/**
|
351
351
|
* The JSON Schema for the schema. It is passed to the providers.
|
352
352
|
*/
|
353
|
-
readonly jsonSchema: JSONSchema7
|
353
|
+
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
354
354
|
};
|
355
355
|
/**
|
356
356
|
* Creates a schema with deferred creation.
|
@@ -362,18 +362,27 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
|
362
362
|
*/
|
363
363
|
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
364
364
|
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
365
|
-
type FlexibleSchema<SCHEMA
|
366
|
-
type InferSchema<SCHEMA> = SCHEMA extends
|
365
|
+
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | StandardSchemaV1<unknown, SCHEMA>;
|
366
|
+
type InferSchema<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
367
367
|
/**
|
368
368
|
* Create a schema using a JSON Schema.
|
369
369
|
*
|
370
370
|
* @param jsonSchema The JSON Schema for the schema.
|
371
371
|
* @param options.validate Optional. A validation function for the schema.
|
372
372
|
*/
|
373
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | (() => JSONSchema7), { validate, }?: {
|
373
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
374
374
|
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
375
375
|
}): Schema<OBJECT>;
|
376
376
|
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
377
|
+
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
378
|
+
/**
|
379
|
+
* Enables support for references in the schema.
|
380
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
381
|
+
* However, not all language models and providers support such references.
|
382
|
+
* Defaults to `false`.
|
383
|
+
*/
|
384
|
+
useReferences?: boolean;
|
385
|
+
}): Schema<OBJECT>;
|
377
386
|
|
378
387
|
/**
|
379
388
|
Additional provider-specific options.
|
@@ -843,7 +852,7 @@ declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT,
|
|
843
852
|
*/
|
844
853
|
declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
|
845
854
|
|
846
|
-
type Resolvable<T> = T |
|
855
|
+
type Resolvable<T> = T | PromiseLike<T> | (() => T) | (() => PromiseLike<T>);
|
847
856
|
/**
|
848
857
|
* Resolves a value that could be a raw value, a Promise, a function returning a value,
|
849
858
|
* or a function returning a Promise.
|
@@ -905,16 +914,6 @@ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, strin
|
|
905
914
|
|
906
915
|
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
907
916
|
|
908
|
-
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
909
|
-
/**
|
910
|
-
* Enables support for references in the schema.
|
911
|
-
* This is required for recursive schemas, e.g. with `z.lazy`.
|
912
|
-
* However, not all language models and providers support such references.
|
913
|
-
* Defaults to `false`.
|
914
|
-
*/
|
915
|
-
useReferences?: boolean;
|
916
|
-
}): Schema<OBJECT>;
|
917
|
-
|
918
917
|
declare function executeTool<INPUT, OUTPUT>({ execute, input, options, }: {
|
919
918
|
execute: ToolExecuteFunction<INPUT, OUTPUT>;
|
920
919
|
input: INPUT;
|
package/dist/index.d.ts
CHANGED
@@ -350,7 +350,7 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
|
350
350
|
/**
|
351
351
|
* The JSON Schema for the schema. It is passed to the providers.
|
352
352
|
*/
|
353
|
-
readonly jsonSchema: JSONSchema7
|
353
|
+
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
354
354
|
};
|
355
355
|
/**
|
356
356
|
* Creates a schema with deferred creation.
|
@@ -362,18 +362,27 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
|
362
362
|
*/
|
363
363
|
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
364
364
|
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
365
|
-
type FlexibleSchema<SCHEMA
|
366
|
-
type InferSchema<SCHEMA> = SCHEMA extends
|
365
|
+
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | StandardSchemaV1<unknown, SCHEMA>;
|
366
|
+
type InferSchema<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
367
367
|
/**
|
368
368
|
* Create a schema using a JSON Schema.
|
369
369
|
*
|
370
370
|
* @param jsonSchema The JSON Schema for the schema.
|
371
371
|
* @param options.validate Optional. A validation function for the schema.
|
372
372
|
*/
|
373
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | (() => JSONSchema7), { validate, }?: {
|
373
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
374
374
|
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
375
375
|
}): Schema<OBJECT>;
|
376
376
|
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
377
|
+
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
378
|
+
/**
|
379
|
+
* Enables support for references in the schema.
|
380
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
381
|
+
* However, not all language models and providers support such references.
|
382
|
+
* Defaults to `false`.
|
383
|
+
*/
|
384
|
+
useReferences?: boolean;
|
385
|
+
}): Schema<OBJECT>;
|
377
386
|
|
378
387
|
/**
|
379
388
|
Additional provider-specific options.
|
@@ -843,7 +852,7 @@ declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT,
|
|
843
852
|
*/
|
844
853
|
declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
|
845
854
|
|
846
|
-
type Resolvable<T> = T |
|
855
|
+
type Resolvable<T> = T | PromiseLike<T> | (() => T) | (() => PromiseLike<T>);
|
847
856
|
/**
|
848
857
|
* Resolves a value that could be a raw value, a Promise, a function returning a value,
|
849
858
|
* or a function returning a Promise.
|
@@ -905,16 +914,6 @@ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, strin
|
|
905
914
|
|
906
915
|
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
907
916
|
|
908
|
-
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
909
|
-
/**
|
910
|
-
* Enables support for references in the schema.
|
911
|
-
* This is required for recursive schemas, e.g. with `z.lazy`.
|
912
|
-
* However, not all language models and providers support such references.
|
913
|
-
* Defaults to `false`.
|
914
|
-
*/
|
915
|
-
useReferences?: boolean;
|
916
|
-
}): Schema<OBJECT>;
|
917
|
-
|
918
917
|
declare function executeTool<INPUT, OUTPUT>({ execute, input, options, }: {
|
919
918
|
execute: ToolExecuteFunction<INPUT, OUTPUT>;
|
920
919
|
input: INPUT;
|
package/dist/index.js
CHANGED
@@ -285,7 +285,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
285
285
|
}
|
286
286
|
|
287
287
|
// src/version.ts
|
288
|
-
var VERSION = true ? "4.0.0-beta.
|
288
|
+
var VERSION = true ? "4.0.0-beta.13" : "0.0.0-test";
|
289
289
|
|
290
290
|
// src/get-from-api.ts
|
291
291
|
var getOriginalFetch = () => globalThis.fetch;
|
@@ -583,9 +583,9 @@ function lazyValidator(createValidator) {
|
|
583
583
|
function asValidator(value) {
|
584
584
|
return isValidator(value) ? value : typeof value === "function" ? value() : standardSchemaValidator(value);
|
585
585
|
}
|
586
|
-
function standardSchemaValidator(
|
586
|
+
function standardSchemaValidator(standardSchema2) {
|
587
587
|
return validator(async (value) => {
|
588
|
-
const result = await
|
588
|
+
const result = await standardSchema2["~standard"].validate(value);
|
589
589
|
return result.issues == null ? { success: true, value: result.value } : {
|
590
590
|
success: false,
|
591
591
|
error: new import_provider6.TypeValidationError({
|
@@ -1079,9 +1079,25 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
1079
1079
|
};
|
1080
1080
|
};
|
1081
1081
|
|
1082
|
-
// src/
|
1082
|
+
// src/schema.ts
|
1083
|
+
var import_provider12 = require("@ai-sdk/provider");
|
1083
1084
|
var z4 = __toESM(require("zod/v4"));
|
1084
1085
|
|
1086
|
+
// src/to-json-schema/arktype-to-json-schema.ts
|
1087
|
+
var arktypeToJsonSchema = async (schema) => {
|
1088
|
+
return schema.toJsonSchema();
|
1089
|
+
};
|
1090
|
+
|
1091
|
+
// src/to-json-schema/valibot-to-json-schema.ts
|
1092
|
+
var valibotToJsonSchema = async (schema) => {
|
1093
|
+
try {
|
1094
|
+
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
1095
|
+
return toJsonSchema(schema);
|
1096
|
+
} catch (e) {
|
1097
|
+
throw new Error(`Failed to import @valibot/to-json-schema`);
|
1098
|
+
}
|
1099
|
+
};
|
1100
|
+
|
1085
1101
|
// src/zod-to-json-schema/get-relative-path.ts
|
1086
1102
|
var getRelativePath = (pathA, pathB) => {
|
1087
1103
|
let i = 0;
|
@@ -2263,7 +2279,84 @@ var zodToJsonSchema = (schema, options) => {
|
|
2263
2279
|
// src/zod-to-json-schema/index.ts
|
2264
2280
|
var zod_to_json_schema_default = zodToJsonSchema;
|
2265
2281
|
|
2266
|
-
// src/
|
2282
|
+
// src/schema.ts
|
2283
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
2284
|
+
function lazySchema(createSchema) {
|
2285
|
+
let schema;
|
2286
|
+
return () => {
|
2287
|
+
if (schema == null) {
|
2288
|
+
schema = createSchema();
|
2289
|
+
}
|
2290
|
+
return schema;
|
2291
|
+
};
|
2292
|
+
}
|
2293
|
+
function jsonSchema(jsonSchema2, {
|
2294
|
+
validate
|
2295
|
+
} = {}) {
|
2296
|
+
return {
|
2297
|
+
[schemaSymbol]: true,
|
2298
|
+
_type: void 0,
|
2299
|
+
// should never be used directly
|
2300
|
+
[validatorSymbol]: true,
|
2301
|
+
get jsonSchema() {
|
2302
|
+
if (typeof jsonSchema2 === "function") {
|
2303
|
+
jsonSchema2 = jsonSchema2();
|
2304
|
+
}
|
2305
|
+
return jsonSchema2;
|
2306
|
+
},
|
2307
|
+
validate
|
2308
|
+
};
|
2309
|
+
}
|
2310
|
+
function isSchema(value) {
|
2311
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
2312
|
+
}
|
2313
|
+
function asSchema(schema) {
|
2314
|
+
return schema == null ? jsonSchema({
|
2315
|
+
properties: {},
|
2316
|
+
additionalProperties: false
|
2317
|
+
}) : isSchema(schema) ? schema : "~standard" in schema ? standardSchema(schema) : schema();
|
2318
|
+
}
|
2319
|
+
function standardSchema(standardSchema2) {
|
2320
|
+
const vendor = standardSchema2["~standard"].vendor;
|
2321
|
+
switch (vendor) {
|
2322
|
+
case "zod": {
|
2323
|
+
return zodSchema(
|
2324
|
+
standardSchema2
|
2325
|
+
);
|
2326
|
+
}
|
2327
|
+
case "arktype": {
|
2328
|
+
return standardSchemaWithJsonSchemaResolver(
|
2329
|
+
standardSchema2,
|
2330
|
+
arktypeToJsonSchema
|
2331
|
+
);
|
2332
|
+
}
|
2333
|
+
case "valibot": {
|
2334
|
+
return standardSchemaWithJsonSchemaResolver(
|
2335
|
+
standardSchema2,
|
2336
|
+
valibotToJsonSchema
|
2337
|
+
);
|
2338
|
+
}
|
2339
|
+
default: {
|
2340
|
+
return standardSchemaWithJsonSchemaResolver(standardSchema2, () => {
|
2341
|
+
throw new Error(`Unsupported standard schema vendor: ${vendor}`);
|
2342
|
+
});
|
2343
|
+
}
|
2344
|
+
}
|
2345
|
+
}
|
2346
|
+
function standardSchemaWithJsonSchemaResolver(standardSchema2, jsonSchemaResolver) {
|
2347
|
+
return jsonSchema(jsonSchemaResolver(standardSchema2), {
|
2348
|
+
validate: async (value) => {
|
2349
|
+
const result = await standardSchema2["~standard"].validate(value);
|
2350
|
+
return "value" in result ? { success: true, value: result.value } : {
|
2351
|
+
success: false,
|
2352
|
+
error: new import_provider12.TypeValidationError({
|
2353
|
+
value,
|
2354
|
+
cause: result.issues
|
2355
|
+
})
|
2356
|
+
};
|
2357
|
+
}
|
2358
|
+
});
|
2359
|
+
}
|
2267
2360
|
function zod3Schema(zodSchema2, options) {
|
2268
2361
|
var _a;
|
2269
2362
|
const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
|
@@ -2309,44 +2402,6 @@ function zodSchema(zodSchema2, options) {
|
|
2309
2402
|
}
|
2310
2403
|
}
|
2311
2404
|
|
2312
|
-
// src/schema.ts
|
2313
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
2314
|
-
function lazySchema(createSchema) {
|
2315
|
-
let schema;
|
2316
|
-
return () => {
|
2317
|
-
if (schema == null) {
|
2318
|
-
schema = createSchema();
|
2319
|
-
}
|
2320
|
-
return schema;
|
2321
|
-
};
|
2322
|
-
}
|
2323
|
-
function jsonSchema(jsonSchema2, {
|
2324
|
-
validate
|
2325
|
-
} = {}) {
|
2326
|
-
return {
|
2327
|
-
[schemaSymbol]: true,
|
2328
|
-
_type: void 0,
|
2329
|
-
// should never be used directly
|
2330
|
-
[validatorSymbol]: true,
|
2331
|
-
get jsonSchema() {
|
2332
|
-
if (typeof jsonSchema2 === "function") {
|
2333
|
-
jsonSchema2 = jsonSchema2();
|
2334
|
-
}
|
2335
|
-
return jsonSchema2;
|
2336
|
-
},
|
2337
|
-
validate
|
2338
|
-
};
|
2339
|
-
}
|
2340
|
-
function isSchema(value) {
|
2341
|
-
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
2342
|
-
}
|
2343
|
-
function asSchema(schema) {
|
2344
|
-
return schema == null ? jsonSchema({
|
2345
|
-
properties: {},
|
2346
|
-
additionalProperties: false
|
2347
|
-
}) : isSchema(schema) ? schema : typeof schema === "function" ? schema() : zodSchema(schema);
|
2348
|
-
}
|
2349
|
-
|
2350
2405
|
// src/uint8-utils.ts
|
2351
2406
|
var { btoa, atob } = globalThis;
|
2352
2407
|
function convertBase64ToUint8Array(base64String) {
|