@ai-sdk/provider-utils 4.0.0-beta.10 → 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 +13 -0
- package/dist/index.d.mts +68 -47
- package/dist/index.d.ts +68 -47
- package/dist/index.js +155 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# @ai-sdk/provider-utils
|
2
2
|
|
3
|
+
## 4.0.0-beta.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 7e32fea: feat(ai): valibot support
|
8
|
+
|
9
|
+
## 4.0.0-beta.11
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 95f65c2: chore: use import \* from zod/v4
|
14
|
+
- 95f65c2: chore: load zod schemas lazily
|
15
|
+
|
3
16
|
## 4.0.0-beta.10
|
4
17
|
|
5
18
|
### Major Changes
|
package/dist/index.d.mts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONSchema7, SharedV3ProviderOptions, LanguageModelV3ToolResultOutput, LanguageModelV3ToolResultPart } from '@ai-sdk/provider';
|
2
2
|
import * as z4 from 'zod/v4';
|
3
|
-
import { ZodType
|
4
|
-
import * as z3 from 'zod/v3';
|
3
|
+
import { ZodType } from 'zod/v4';
|
5
4
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
6
5
|
export * from '@standard-schema/spec';
|
6
|
+
import * as z3 from 'zod/v3';
|
7
7
|
export { EventSourceMessage, EventSourceParserStream } from 'eventsource-parser/stream';
|
8
8
|
|
9
9
|
declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
|
@@ -43,20 +43,6 @@ declare function extractResponseHeaders(response: Response): {
|
|
43
43
|
*/
|
44
44
|
type FetchFunction = typeof globalThis.fetch;
|
45
45
|
|
46
|
-
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Appends suffix parts to the `user-agent` header.
|
50
|
-
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
51
|
-
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
52
|
-
* Automatically removes undefined entries from the headers.
|
53
|
-
*
|
54
|
-
* @param headers - The original headers.
|
55
|
-
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
56
|
-
* @returns The new headers with the `user-agent` header set or updated.
|
57
|
-
*/
|
58
|
-
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
59
|
-
|
60
46
|
/**
|
61
47
|
Creates an ID generator.
|
62
48
|
The total length of the ID is the sum of the prefix, separator, and random part length.
|
@@ -114,7 +100,19 @@ type Validator<OBJECT = unknown> = {
|
|
114
100
|
*/
|
115
101
|
declare function validator<OBJECT>(validate?: undefined | ((value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>)): Validator<OBJECT>;
|
116
102
|
declare function isValidator(value: unknown): value is Validator;
|
117
|
-
|
103
|
+
/**
|
104
|
+
* Creates a validator with deferred creation.
|
105
|
+
* This is important to reduce the startup time of the library
|
106
|
+
* and to avoid initializing unused validators.
|
107
|
+
*
|
108
|
+
* @param createValidator A function that creates a validator.
|
109
|
+
* @returns A function that returns a validator.
|
110
|
+
*/
|
111
|
+
declare function lazyValidator<OBJECT>(createValidator: () => Validator<OBJECT>): LazyValidator<OBJECT>;
|
112
|
+
type LazyValidator<OBJECT> = () => Validator<OBJECT>;
|
113
|
+
type FlexibleValidator<OBJECT> = Validator<OBJECT> | LazyValidator<OBJECT> | StandardSchemaV1<unknown, OBJECT>;
|
114
|
+
type InferValidator<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazyValidator<infer T> ? T : SCHEMA extends Validator<infer T> ? T : never;
|
115
|
+
declare function asValidator<OBJECT>(value: FlexibleValidator<OBJECT>): Validator<OBJECT>;
|
118
116
|
declare function standardSchemaValidator<OBJECT>(standardSchema: StandardSchemaV1<unknown, OBJECT>): Validator<OBJECT>;
|
119
117
|
|
120
118
|
/**
|
@@ -137,7 +135,7 @@ declare function parseJSON(options: {
|
|
137
135
|
*/
|
138
136
|
declare function parseJSON<T>(options: {
|
139
137
|
text: string;
|
140
|
-
schema:
|
138
|
+
schema: FlexibleValidator<T>;
|
141
139
|
}): Promise<T>;
|
142
140
|
type ParseResult<T> = {
|
143
141
|
success: true;
|
@@ -168,7 +166,7 @@ declare function safeParseJSON(options: {
|
|
168
166
|
*/
|
169
167
|
declare function safeParseJSON<T>(options: {
|
170
168
|
text: string;
|
171
|
-
schema:
|
169
|
+
schema: FlexibleValidator<T>;
|
172
170
|
}): Promise<ParseResult<T>>;
|
173
171
|
declare function isParsableJson(input: string): boolean;
|
174
172
|
|
@@ -182,13 +180,13 @@ type ResponseHandler<RETURN_TYPE> = (options: {
|
|
182
180
|
responseHeaders?: Record<string, string>;
|
183
181
|
}>;
|
184
182
|
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
185
|
-
errorSchema:
|
183
|
+
errorSchema: FlexibleValidator<T>;
|
186
184
|
errorToMessage: (error: T) => string;
|
187
185
|
isRetryable?: (response: Response, error?: T) => boolean;
|
188
186
|
}) => ResponseHandler<APICallError>;
|
189
|
-
declare const createEventSourceResponseHandler: <T>(chunkSchema:
|
187
|
+
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleValidator<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
190
188
|
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
191
|
-
declare const createJsonResponseHandler: <T>(responseSchema:
|
189
|
+
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleValidator<T>) => ResponseHandler<T>;
|
192
190
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
193
191
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
194
192
|
|
@@ -205,6 +203,8 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
|
|
205
203
|
responseHeaders?: Record<string, string>;
|
206
204
|
}>;
|
207
205
|
|
206
|
+
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
207
|
+
|
208
208
|
declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
|
209
209
|
messages: LanguageModelV3Prompt;
|
210
210
|
schema?: JSONSchema7;
|
@@ -282,14 +282,14 @@ declare function mediaTypeToExtension(mediaType: string): string;
|
|
282
282
|
*/
|
283
283
|
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
284
284
|
stream: ReadableStream<Uint8Array>;
|
285
|
-
schema:
|
285
|
+
schema: FlexibleValidator<T>;
|
286
286
|
}): ReadableStream<ParseResult<T>>;
|
287
287
|
|
288
|
-
declare function parseProviderOptions<
|
288
|
+
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
289
289
|
provider: string;
|
290
290
|
providerOptions: Record<string, unknown> | undefined;
|
291
|
-
schema:
|
292
|
-
}): Promise<
|
291
|
+
schema: FlexibleValidator<OPTIONS>;
|
292
|
+
}): Promise<OPTIONS | undefined>;
|
293
293
|
|
294
294
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
295
295
|
url: string;
|
@@ -350,20 +350,39 @@ 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
|
-
|
356
|
-
|
355
|
+
/**
|
356
|
+
* Creates a schema with deferred creation.
|
357
|
+
* This is important to reduce the startup time of the library
|
358
|
+
* and to avoid initializing unused validators.
|
359
|
+
*
|
360
|
+
* @param createValidator A function that creates a schema.
|
361
|
+
* @returns A function that returns a schema.
|
362
|
+
*/
|
363
|
+
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
364
|
+
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
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;
|
357
367
|
/**
|
358
368
|
* Create a schema using a JSON Schema.
|
359
369
|
*
|
360
370
|
* @param jsonSchema The JSON Schema for the schema.
|
361
371
|
* @param options.validate Optional. A validation function for the schema.
|
362
372
|
*/
|
363
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, { validate, }?: {
|
373
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
364
374
|
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
365
375
|
}): Schema<OBJECT>;
|
366
|
-
declare function asSchema<OBJECT>(schema:
|
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>;
|
367
386
|
|
368
387
|
/**
|
369
388
|
Additional provider-specific options.
|
@@ -833,7 +852,7 @@ declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT,
|
|
833
852
|
*/
|
834
853
|
declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
|
835
854
|
|
836
|
-
type Resolvable<T> = T |
|
855
|
+
type Resolvable<T> = T | PromiseLike<T> | (() => T) | (() => PromiseLike<T>);
|
837
856
|
/**
|
838
857
|
* Resolves a value that could be a raw value, a Promise, a function returning a value,
|
839
858
|
* or a function returning a Promise.
|
@@ -855,7 +874,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
|
|
855
874
|
*/
|
856
875
|
declare function validateTypes<OBJECT>({ value, schema, }: {
|
857
876
|
value: unknown;
|
858
|
-
schema:
|
877
|
+
schema: FlexibleValidator<OBJECT>;
|
859
878
|
}): Promise<OBJECT>;
|
860
879
|
/**
|
861
880
|
* Safely validates the types of an unknown object using a schema and
|
@@ -868,7 +887,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
|
|
868
887
|
*/
|
869
888
|
declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
870
889
|
value: unknown;
|
871
|
-
schema:
|
890
|
+
schema: FlexibleValidator<OBJECT>;
|
872
891
|
}): Promise<{
|
873
892
|
success: true;
|
874
893
|
value: OBJECT;
|
@@ -879,17 +898,21 @@ declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
|
879
898
|
rawValue: unknown;
|
880
899
|
}>;
|
881
900
|
|
882
|
-
declare
|
901
|
+
declare const VERSION: string;
|
883
902
|
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
903
|
+
/**
|
904
|
+
* Appends suffix parts to the `user-agent` header.
|
905
|
+
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
906
|
+
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
907
|
+
* Automatically removes undefined entries from the headers.
|
908
|
+
*
|
909
|
+
* @param headers - The original headers.
|
910
|
+
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
911
|
+
* @returns The new headers with the `user-agent` header set or updated.
|
912
|
+
*/
|
913
|
+
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
914
|
+
|
915
|
+
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
893
916
|
|
894
917
|
declare function executeTool<INPUT, OUTPUT>({ execute, input, options, }: {
|
895
918
|
execute: ToolExecuteFunction<INPUT, OUTPUT>;
|
@@ -962,6 +985,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
962
985
|
dynamic?: boolean;
|
963
986
|
}
|
964
987
|
|
965
|
-
|
966
|
-
|
967
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
988
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONSchema7, SharedV3ProviderOptions, LanguageModelV3ToolResultOutput, LanguageModelV3ToolResultPart } from '@ai-sdk/provider';
|
2
2
|
import * as z4 from 'zod/v4';
|
3
|
-
import { ZodType
|
4
|
-
import * as z3 from 'zod/v3';
|
3
|
+
import { ZodType } from 'zod/v4';
|
5
4
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
6
5
|
export * from '@standard-schema/spec';
|
6
|
+
import * as z3 from 'zod/v3';
|
7
7
|
export { EventSourceMessage, EventSourceParserStream } from 'eventsource-parser/stream';
|
8
8
|
|
9
9
|
declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
|
@@ -43,20 +43,6 @@ declare function extractResponseHeaders(response: Response): {
|
|
43
43
|
*/
|
44
44
|
type FetchFunction = typeof globalThis.fetch;
|
45
45
|
|
46
|
-
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Appends suffix parts to the `user-agent` header.
|
50
|
-
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
51
|
-
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
52
|
-
* Automatically removes undefined entries from the headers.
|
53
|
-
*
|
54
|
-
* @param headers - The original headers.
|
55
|
-
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
56
|
-
* @returns The new headers with the `user-agent` header set or updated.
|
57
|
-
*/
|
58
|
-
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
59
|
-
|
60
46
|
/**
|
61
47
|
Creates an ID generator.
|
62
48
|
The total length of the ID is the sum of the prefix, separator, and random part length.
|
@@ -114,7 +100,19 @@ type Validator<OBJECT = unknown> = {
|
|
114
100
|
*/
|
115
101
|
declare function validator<OBJECT>(validate?: undefined | ((value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>)): Validator<OBJECT>;
|
116
102
|
declare function isValidator(value: unknown): value is Validator;
|
117
|
-
|
103
|
+
/**
|
104
|
+
* Creates a validator with deferred creation.
|
105
|
+
* This is important to reduce the startup time of the library
|
106
|
+
* and to avoid initializing unused validators.
|
107
|
+
*
|
108
|
+
* @param createValidator A function that creates a validator.
|
109
|
+
* @returns A function that returns a validator.
|
110
|
+
*/
|
111
|
+
declare function lazyValidator<OBJECT>(createValidator: () => Validator<OBJECT>): LazyValidator<OBJECT>;
|
112
|
+
type LazyValidator<OBJECT> = () => Validator<OBJECT>;
|
113
|
+
type FlexibleValidator<OBJECT> = Validator<OBJECT> | LazyValidator<OBJECT> | StandardSchemaV1<unknown, OBJECT>;
|
114
|
+
type InferValidator<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazyValidator<infer T> ? T : SCHEMA extends Validator<infer T> ? T : never;
|
115
|
+
declare function asValidator<OBJECT>(value: FlexibleValidator<OBJECT>): Validator<OBJECT>;
|
118
116
|
declare function standardSchemaValidator<OBJECT>(standardSchema: StandardSchemaV1<unknown, OBJECT>): Validator<OBJECT>;
|
119
117
|
|
120
118
|
/**
|
@@ -137,7 +135,7 @@ declare function parseJSON(options: {
|
|
137
135
|
*/
|
138
136
|
declare function parseJSON<T>(options: {
|
139
137
|
text: string;
|
140
|
-
schema:
|
138
|
+
schema: FlexibleValidator<T>;
|
141
139
|
}): Promise<T>;
|
142
140
|
type ParseResult<T> = {
|
143
141
|
success: true;
|
@@ -168,7 +166,7 @@ declare function safeParseJSON(options: {
|
|
168
166
|
*/
|
169
167
|
declare function safeParseJSON<T>(options: {
|
170
168
|
text: string;
|
171
|
-
schema:
|
169
|
+
schema: FlexibleValidator<T>;
|
172
170
|
}): Promise<ParseResult<T>>;
|
173
171
|
declare function isParsableJson(input: string): boolean;
|
174
172
|
|
@@ -182,13 +180,13 @@ type ResponseHandler<RETURN_TYPE> = (options: {
|
|
182
180
|
responseHeaders?: Record<string, string>;
|
183
181
|
}>;
|
184
182
|
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
185
|
-
errorSchema:
|
183
|
+
errorSchema: FlexibleValidator<T>;
|
186
184
|
errorToMessage: (error: T) => string;
|
187
185
|
isRetryable?: (response: Response, error?: T) => boolean;
|
188
186
|
}) => ResponseHandler<APICallError>;
|
189
|
-
declare const createEventSourceResponseHandler: <T>(chunkSchema:
|
187
|
+
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleValidator<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
190
188
|
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
191
|
-
declare const createJsonResponseHandler: <T>(responseSchema:
|
189
|
+
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleValidator<T>) => ResponseHandler<T>;
|
192
190
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
193
191
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
194
192
|
|
@@ -205,6 +203,8 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
|
|
205
203
|
responseHeaders?: Record<string, string>;
|
206
204
|
}>;
|
207
205
|
|
206
|
+
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
207
|
+
|
208
208
|
declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
|
209
209
|
messages: LanguageModelV3Prompt;
|
210
210
|
schema?: JSONSchema7;
|
@@ -282,14 +282,14 @@ declare function mediaTypeToExtension(mediaType: string): string;
|
|
282
282
|
*/
|
283
283
|
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
284
284
|
stream: ReadableStream<Uint8Array>;
|
285
|
-
schema:
|
285
|
+
schema: FlexibleValidator<T>;
|
286
286
|
}): ReadableStream<ParseResult<T>>;
|
287
287
|
|
288
|
-
declare function parseProviderOptions<
|
288
|
+
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
289
289
|
provider: string;
|
290
290
|
providerOptions: Record<string, unknown> | undefined;
|
291
|
-
schema:
|
292
|
-
}): Promise<
|
291
|
+
schema: FlexibleValidator<OPTIONS>;
|
292
|
+
}): Promise<OPTIONS | undefined>;
|
293
293
|
|
294
294
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
295
295
|
url: string;
|
@@ -350,20 +350,39 @@ 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
|
-
|
356
|
-
|
355
|
+
/**
|
356
|
+
* Creates a schema with deferred creation.
|
357
|
+
* This is important to reduce the startup time of the library
|
358
|
+
* and to avoid initializing unused validators.
|
359
|
+
*
|
360
|
+
* @param createValidator A function that creates a schema.
|
361
|
+
* @returns A function that returns a schema.
|
362
|
+
*/
|
363
|
+
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
364
|
+
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
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;
|
357
367
|
/**
|
358
368
|
* Create a schema using a JSON Schema.
|
359
369
|
*
|
360
370
|
* @param jsonSchema The JSON Schema for the schema.
|
361
371
|
* @param options.validate Optional. A validation function for the schema.
|
362
372
|
*/
|
363
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, { validate, }?: {
|
373
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
364
374
|
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
365
375
|
}): Schema<OBJECT>;
|
366
|
-
declare function asSchema<OBJECT>(schema:
|
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>;
|
367
386
|
|
368
387
|
/**
|
369
388
|
Additional provider-specific options.
|
@@ -833,7 +852,7 @@ declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT,
|
|
833
852
|
*/
|
834
853
|
declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
|
835
854
|
|
836
|
-
type Resolvable<T> = T |
|
855
|
+
type Resolvable<T> = T | PromiseLike<T> | (() => T) | (() => PromiseLike<T>);
|
837
856
|
/**
|
838
857
|
* Resolves a value that could be a raw value, a Promise, a function returning a value,
|
839
858
|
* or a function returning a Promise.
|
@@ -855,7 +874,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
|
|
855
874
|
*/
|
856
875
|
declare function validateTypes<OBJECT>({ value, schema, }: {
|
857
876
|
value: unknown;
|
858
|
-
schema:
|
877
|
+
schema: FlexibleValidator<OBJECT>;
|
859
878
|
}): Promise<OBJECT>;
|
860
879
|
/**
|
861
880
|
* Safely validates the types of an unknown object using a schema and
|
@@ -868,7 +887,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
|
|
868
887
|
*/
|
869
888
|
declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
870
889
|
value: unknown;
|
871
|
-
schema:
|
890
|
+
schema: FlexibleValidator<OBJECT>;
|
872
891
|
}): Promise<{
|
873
892
|
success: true;
|
874
893
|
value: OBJECT;
|
@@ -879,17 +898,21 @@ declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
|
879
898
|
rawValue: unknown;
|
880
899
|
}>;
|
881
900
|
|
882
|
-
declare
|
901
|
+
declare const VERSION: string;
|
883
902
|
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
903
|
+
/**
|
904
|
+
* Appends suffix parts to the `user-agent` header.
|
905
|
+
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
906
|
+
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
907
|
+
* Automatically removes undefined entries from the headers.
|
908
|
+
*
|
909
|
+
* @param headers - The original headers.
|
910
|
+
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
911
|
+
* @returns The new headers with the `user-agent` header set or updated.
|
912
|
+
*/
|
913
|
+
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
914
|
+
|
915
|
+
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
893
916
|
|
894
917
|
declare function executeTool<INPUT, OUTPUT>({ execute, input, options, }: {
|
895
918
|
execute: ToolExecuteFunction<INPUT, OUTPUT>;
|
@@ -962,6 +985,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
962
985
|
dynamic?: boolean;
|
963
986
|
}
|
964
987
|
|
965
|
-
|
966
|
-
|
967
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
988
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|