@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/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.12" : "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,20 @@ 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/valibot-to-json-schema/valibot-to-json-schema.ts
|
1087
|
+
var valibotToJsonSchema = async (schema) => {
|
1088
|
+
try {
|
1089
|
+
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
1090
|
+
return toJsonSchema(schema);
|
1091
|
+
} catch (e) {
|
1092
|
+
throw new Error(`Failed to import @valibot/to-json-schema`);
|
1093
|
+
}
|
1094
|
+
};
|
1095
|
+
|
1085
1096
|
// src/zod-to-json-schema/get-relative-path.ts
|
1086
1097
|
var getRelativePath = (pathA, pathB) => {
|
1087
1098
|
let i = 0;
|
@@ -2263,7 +2274,78 @@ var zodToJsonSchema = (schema, options) => {
|
|
2263
2274
|
// src/zod-to-json-schema/index.ts
|
2264
2275
|
var zod_to_json_schema_default = zodToJsonSchema;
|
2265
2276
|
|
2266
|
-
// src/
|
2277
|
+
// src/schema.ts
|
2278
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
2279
|
+
function lazySchema(createSchema) {
|
2280
|
+
let schema;
|
2281
|
+
return () => {
|
2282
|
+
if (schema == null) {
|
2283
|
+
schema = createSchema();
|
2284
|
+
}
|
2285
|
+
return schema;
|
2286
|
+
};
|
2287
|
+
}
|
2288
|
+
function jsonSchema(jsonSchema2, {
|
2289
|
+
validate
|
2290
|
+
} = {}) {
|
2291
|
+
return {
|
2292
|
+
[schemaSymbol]: true,
|
2293
|
+
_type: void 0,
|
2294
|
+
// should never be used directly
|
2295
|
+
[validatorSymbol]: true,
|
2296
|
+
get jsonSchema() {
|
2297
|
+
if (typeof jsonSchema2 === "function") {
|
2298
|
+
jsonSchema2 = jsonSchema2();
|
2299
|
+
}
|
2300
|
+
return jsonSchema2;
|
2301
|
+
},
|
2302
|
+
validate
|
2303
|
+
};
|
2304
|
+
}
|
2305
|
+
function isSchema(value) {
|
2306
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
2307
|
+
}
|
2308
|
+
function asSchema(schema) {
|
2309
|
+
return schema == null ? jsonSchema({
|
2310
|
+
properties: {},
|
2311
|
+
additionalProperties: false
|
2312
|
+
}) : isSchema(schema) ? schema : typeof schema === "function" ? schema() : standardSchema(schema);
|
2313
|
+
}
|
2314
|
+
function standardSchema(standardSchema2) {
|
2315
|
+
const vendor = standardSchema2["~standard"].vendor;
|
2316
|
+
switch (vendor) {
|
2317
|
+
case "zod": {
|
2318
|
+
return zodSchema(
|
2319
|
+
standardSchema2
|
2320
|
+
);
|
2321
|
+
}
|
2322
|
+
case "valibot": {
|
2323
|
+
return standardSchemaWithJsonSchemaResolver(
|
2324
|
+
standardSchema2,
|
2325
|
+
valibotToJsonSchema
|
2326
|
+
);
|
2327
|
+
}
|
2328
|
+
default: {
|
2329
|
+
return standardSchemaWithJsonSchemaResolver(standardSchema2, () => {
|
2330
|
+
throw new Error(`Unsupported standard schema vendor: ${vendor}`);
|
2331
|
+
});
|
2332
|
+
}
|
2333
|
+
}
|
2334
|
+
}
|
2335
|
+
function standardSchemaWithJsonSchemaResolver(standardSchema2, jsonSchemaResolver) {
|
2336
|
+
return jsonSchema(jsonSchemaResolver(standardSchema2), {
|
2337
|
+
validate: async (value) => {
|
2338
|
+
const result = await standardSchema2["~standard"].validate(value);
|
2339
|
+
return "value" in result ? { success: true, value: result.value } : {
|
2340
|
+
success: false,
|
2341
|
+
error: new import_provider12.TypeValidationError({
|
2342
|
+
value,
|
2343
|
+
cause: result.issues
|
2344
|
+
})
|
2345
|
+
};
|
2346
|
+
}
|
2347
|
+
});
|
2348
|
+
}
|
2267
2349
|
function zod3Schema(zodSchema2, options) {
|
2268
2350
|
var _a;
|
2269
2351
|
const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
|
@@ -2309,44 +2391,6 @@ function zodSchema(zodSchema2, options) {
|
|
2309
2391
|
}
|
2310
2392
|
}
|
2311
2393
|
|
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
2394
|
// src/uint8-utils.ts
|
2351
2395
|
var { btoa, atob } = globalThis;
|
2352
2396
|
function convertBase64ToUint8Array(base64String) {
|