@ai-sdk/provider-utils 3.0.10 → 3.0.11
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 +7 -0
- package/dist/index.d.mts +58 -36
- package/dist/index.d.ts +58 -36
- package/dist/index.js +90 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -65
- package/dist/index.mjs.map +1 -1
- package/dist/test/index.js +2 -4
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +2 -4
- package/dist/test/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import {
|
1
|
+
import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } 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: LanguageModelV2Prompt;
|
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;
|
@@ -352,18 +352,28 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
|
352
352
|
*/
|
353
353
|
readonly jsonSchema: 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> = z4.core.$ZodType<SCHEMA, any> | z3.Schema<SCHEMA, z3.ZodTypeDef, any> | Schema<SCHEMA> | LazySchema<SCHEMA>;
|
366
|
+
type InferSchema<SCHEMA> = SCHEMA extends z3.Schema ? z3.infer<SCHEMA> : SCHEMA extends z4.core.$ZodType ? z4.infer<SCHEMA> : 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 | (() => 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>;
|
367
377
|
|
368
378
|
/**
|
369
379
|
Additional provider-specific options.
|
@@ -799,7 +809,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
|
|
799
809
|
*/
|
800
810
|
declare function validateTypes<OBJECT>({ value, schema, }: {
|
801
811
|
value: unknown;
|
802
|
-
schema:
|
812
|
+
schema: FlexibleValidator<OBJECT>;
|
803
813
|
}): Promise<OBJECT>;
|
804
814
|
/**
|
805
815
|
* Safely validates the types of an unknown object using a schema and
|
@@ -812,7 +822,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
|
|
812
822
|
*/
|
813
823
|
declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
814
824
|
value: unknown;
|
815
|
-
schema:
|
825
|
+
schema: FlexibleValidator<OBJECT>;
|
816
826
|
}): Promise<{
|
817
827
|
success: true;
|
818
828
|
value: OBJECT;
|
@@ -823,6 +833,20 @@ declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
|
823
833
|
rawValue: unknown;
|
824
834
|
}>;
|
825
835
|
|
836
|
+
declare const VERSION: string;
|
837
|
+
|
838
|
+
/**
|
839
|
+
* Appends suffix parts to the `user-agent` header.
|
840
|
+
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
841
|
+
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
842
|
+
* Automatically removes undefined entries from the headers.
|
843
|
+
*
|
844
|
+
* @param headers - The original headers.
|
845
|
+
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
846
|
+
* @returns The new headers with the `user-agent` header set or updated.
|
847
|
+
*/
|
848
|
+
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
849
|
+
|
826
850
|
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
827
851
|
|
828
852
|
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
@@ -906,6 +930,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
906
930
|
dynamic?: boolean;
|
907
931
|
}
|
908
932
|
|
909
|
-
|
910
|
-
|
911
|
-
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 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 };
|
933
|
+
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 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
|
-
import {
|
1
|
+
import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } 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: LanguageModelV2Prompt;
|
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;
|
@@ -352,18 +352,28 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
|
352
352
|
*/
|
353
353
|
readonly jsonSchema: 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> = z4.core.$ZodType<SCHEMA, any> | z3.Schema<SCHEMA, z3.ZodTypeDef, any> | Schema<SCHEMA> | LazySchema<SCHEMA>;
|
366
|
+
type InferSchema<SCHEMA> = SCHEMA extends z3.Schema ? z3.infer<SCHEMA> : SCHEMA extends z4.core.$ZodType ? z4.infer<SCHEMA> : 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 | (() => 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>;
|
367
377
|
|
368
378
|
/**
|
369
379
|
Additional provider-specific options.
|
@@ -799,7 +809,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
|
|
799
809
|
*/
|
800
810
|
declare function validateTypes<OBJECT>({ value, schema, }: {
|
801
811
|
value: unknown;
|
802
|
-
schema:
|
812
|
+
schema: FlexibleValidator<OBJECT>;
|
803
813
|
}): Promise<OBJECT>;
|
804
814
|
/**
|
805
815
|
* Safely validates the types of an unknown object using a schema and
|
@@ -812,7 +822,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
|
|
812
822
|
*/
|
813
823
|
declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
814
824
|
value: unknown;
|
815
|
-
schema:
|
825
|
+
schema: FlexibleValidator<OBJECT>;
|
816
826
|
}): Promise<{
|
817
827
|
success: true;
|
818
828
|
value: OBJECT;
|
@@ -823,6 +833,20 @@ declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
|
823
833
|
rawValue: unknown;
|
824
834
|
}>;
|
825
835
|
|
836
|
+
declare const VERSION: string;
|
837
|
+
|
838
|
+
/**
|
839
|
+
* Appends suffix parts to the `user-agent` header.
|
840
|
+
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
841
|
+
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
842
|
+
* Automatically removes undefined entries from the headers.
|
843
|
+
*
|
844
|
+
* @param headers - The original headers.
|
845
|
+
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
846
|
+
* @returns The new headers with the `user-agent` header set or updated.
|
847
|
+
*/
|
848
|
+
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
849
|
+
|
826
850
|
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
827
851
|
|
828
852
|
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
@@ -906,6 +930,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
906
930
|
dynamic?: boolean;
|
907
931
|
}
|
908
932
|
|
909
|
-
|
910
|
-
|
911
|
-
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 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 };
|
933
|
+
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 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 };
|