@ai-sdk/provider-utils 4.0.0-beta.15 → 4.0.0-beta.16
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 +49 -81
- package/dist/index.d.ts +49 -81
- package/dist/index.js +1653 -1696
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1658 -1696
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt,
|
1
|
+
import { JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions, LanguageModelV3ToolResultOutput, LanguageModelV3ToolResultPart } from '@ai-sdk/provider';
|
2
2
|
import * as z4 from 'zod/v4';
|
3
3
|
import { ZodType } from 'zod/v4';
|
4
4
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
@@ -72,9 +72,9 @@ declare const generateId: IdGenerator;
|
|
72
72
|
declare function getErrorMessage(error: unknown | undefined): string;
|
73
73
|
|
74
74
|
/**
|
75
|
-
* Used to mark
|
75
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
76
76
|
*/
|
77
|
-
declare const
|
77
|
+
declare const schemaSymbol: unique symbol;
|
78
78
|
type ValidationResult<OBJECT> = {
|
79
79
|
success: true;
|
80
80
|
value: OBJECT;
|
@@ -82,38 +82,56 @@ type ValidationResult<OBJECT> = {
|
|
82
82
|
success: false;
|
83
83
|
error: Error;
|
84
84
|
};
|
85
|
-
type
|
85
|
+
type Schema<OBJECT = unknown> = {
|
86
86
|
/**
|
87
|
-
* Used to mark
|
87
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
88
88
|
*/
|
89
|
-
[
|
89
|
+
[schemaSymbol]: true;
|
90
|
+
/**
|
91
|
+
* Schema type for inference.
|
92
|
+
*/
|
93
|
+
_type: OBJECT;
|
90
94
|
/**
|
91
95
|
* Optional. Validates that the structure of a value matches this schema,
|
92
96
|
* and returns a typed version of the value if it does.
|
93
97
|
*/
|
94
98
|
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
99
|
+
/**
|
100
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
101
|
+
*/
|
102
|
+
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
95
103
|
};
|
96
104
|
/**
|
97
|
-
*
|
105
|
+
* Creates a schema with deferred creation.
|
106
|
+
* This is important to reduce the startup time of the library
|
107
|
+
* and to avoid initializing unused validators.
|
98
108
|
*
|
99
|
-
* @param
|
109
|
+
* @param createValidator A function that creates a schema.
|
110
|
+
* @returns A function that returns a schema.
|
100
111
|
*/
|
101
|
-
declare function
|
102
|
-
|
112
|
+
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
113
|
+
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
114
|
+
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | StandardSchemaV1<unknown, SCHEMA>;
|
115
|
+
type InferSchema<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
103
116
|
/**
|
104
|
-
*
|
105
|
-
* This is important to reduce the startup time of the library
|
106
|
-
* and to avoid initializing unused validators.
|
117
|
+
* Create a schema using a JSON Schema.
|
107
118
|
*
|
108
|
-
* @param
|
109
|
-
* @
|
119
|
+
* @param jsonSchema The JSON Schema for the schema.
|
120
|
+
* @param options.validate Optional. A validation function for the schema.
|
110
121
|
*/
|
111
|
-
declare function
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
declare function
|
116
|
-
|
122
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
123
|
+
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
124
|
+
}): Schema<OBJECT>;
|
125
|
+
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
126
|
+
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
127
|
+
/**
|
128
|
+
* Enables support for references in the schema.
|
129
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
130
|
+
* However, not all language models and providers support such references.
|
131
|
+
* Defaults to `false`.
|
132
|
+
*/
|
133
|
+
useReferences?: boolean;
|
134
|
+
}): Schema<OBJECT>;
|
117
135
|
|
118
136
|
/**
|
119
137
|
* Parses a JSON string into an unknown object.
|
@@ -135,7 +153,7 @@ declare function parseJSON(options: {
|
|
135
153
|
*/
|
136
154
|
declare function parseJSON<T>(options: {
|
137
155
|
text: string;
|
138
|
-
schema:
|
156
|
+
schema: FlexibleSchema<T>;
|
139
157
|
}): Promise<T>;
|
140
158
|
type ParseResult<T> = {
|
141
159
|
success: true;
|
@@ -166,7 +184,7 @@ declare function safeParseJSON(options: {
|
|
166
184
|
*/
|
167
185
|
declare function safeParseJSON<T>(options: {
|
168
186
|
text: string;
|
169
|
-
schema:
|
187
|
+
schema: FlexibleSchema<T>;
|
170
188
|
}): Promise<ParseResult<T>>;
|
171
189
|
declare function isParsableJson(input: string): boolean;
|
172
190
|
|
@@ -180,13 +198,13 @@ type ResponseHandler<RETURN_TYPE> = (options: {
|
|
180
198
|
responseHeaders?: Record<string, string>;
|
181
199
|
}>;
|
182
200
|
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
183
|
-
errorSchema:
|
201
|
+
errorSchema: FlexibleSchema<T>;
|
184
202
|
errorToMessage: (error: T) => string;
|
185
203
|
isRetryable?: (response: Response, error?: T) => boolean;
|
186
204
|
}) => ResponseHandler<APICallError>;
|
187
|
-
declare const createEventSourceResponseHandler: <T>(chunkSchema:
|
205
|
+
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
188
206
|
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
189
|
-
declare const createJsonResponseHandler: <T>(responseSchema:
|
207
|
+
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
190
208
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
191
209
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
192
210
|
|
@@ -282,13 +300,13 @@ declare function mediaTypeToExtension(mediaType: string): string;
|
|
282
300
|
*/
|
283
301
|
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
284
302
|
stream: ReadableStream<Uint8Array>;
|
285
|
-
schema:
|
303
|
+
schema: FlexibleSchema<T>;
|
286
304
|
}): ReadableStream<ParseResult<T>>;
|
287
305
|
|
288
306
|
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
289
307
|
provider: string;
|
290
308
|
providerOptions: Record<string, unknown> | undefined;
|
291
|
-
schema:
|
309
|
+
schema: FlexibleSchema<OPTIONS>;
|
292
310
|
}): Promise<OPTIONS | undefined>;
|
293
311
|
|
294
312
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
@@ -334,56 +352,6 @@ declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, fa
|
|
334
352
|
responseHeaders?: Record<string, string>;
|
335
353
|
}>;
|
336
354
|
|
337
|
-
/**
|
338
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
339
|
-
*/
|
340
|
-
declare const schemaSymbol: unique symbol;
|
341
|
-
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
342
|
-
/**
|
343
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
344
|
-
*/
|
345
|
-
[schemaSymbol]: true;
|
346
|
-
/**
|
347
|
-
* Schema type for inference.
|
348
|
-
*/
|
349
|
-
_type: OBJECT;
|
350
|
-
/**
|
351
|
-
* The JSON Schema for the schema. It is passed to the providers.
|
352
|
-
*/
|
353
|
-
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
354
|
-
};
|
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;
|
367
|
-
/**
|
368
|
-
* Create a schema using a JSON Schema.
|
369
|
-
*
|
370
|
-
* @param jsonSchema The JSON Schema for the schema.
|
371
|
-
* @param options.validate Optional. A validation function for the schema.
|
372
|
-
*/
|
373
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
374
|
-
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
375
|
-
}): Schema<OBJECT>;
|
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>;
|
386
|
-
|
387
355
|
/**
|
388
356
|
Additional provider-specific options.
|
389
357
|
|
@@ -874,7 +842,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
|
|
874
842
|
*/
|
875
843
|
declare function validateTypes<OBJECT>({ value, schema, }: {
|
876
844
|
value: unknown;
|
877
|
-
schema:
|
845
|
+
schema: FlexibleSchema<OBJECT>;
|
878
846
|
}): Promise<OBJECT>;
|
879
847
|
/**
|
880
848
|
* Safely validates the types of an unknown object using a schema and
|
@@ -887,7 +855,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
|
|
887
855
|
*/
|
888
856
|
declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
889
857
|
value: unknown;
|
890
|
-
schema:
|
858
|
+
schema: FlexibleSchema<OBJECT>;
|
891
859
|
}): Promise<{
|
892
860
|
success: true;
|
893
861
|
value: OBJECT;
|
@@ -985,4 +953,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
985
953
|
dynamic?: boolean;
|
986
954
|
}
|
987
955
|
|
988
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type
|
956
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, 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, asSchema, 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, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt,
|
1
|
+
import { JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions, LanguageModelV3ToolResultOutput, LanguageModelV3ToolResultPart } from '@ai-sdk/provider';
|
2
2
|
import * as z4 from 'zod/v4';
|
3
3
|
import { ZodType } from 'zod/v4';
|
4
4
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
@@ -72,9 +72,9 @@ declare const generateId: IdGenerator;
|
|
72
72
|
declare function getErrorMessage(error: unknown | undefined): string;
|
73
73
|
|
74
74
|
/**
|
75
|
-
* Used to mark
|
75
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
76
76
|
*/
|
77
|
-
declare const
|
77
|
+
declare const schemaSymbol: unique symbol;
|
78
78
|
type ValidationResult<OBJECT> = {
|
79
79
|
success: true;
|
80
80
|
value: OBJECT;
|
@@ -82,38 +82,56 @@ type ValidationResult<OBJECT> = {
|
|
82
82
|
success: false;
|
83
83
|
error: Error;
|
84
84
|
};
|
85
|
-
type
|
85
|
+
type Schema<OBJECT = unknown> = {
|
86
86
|
/**
|
87
|
-
* Used to mark
|
87
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
88
88
|
*/
|
89
|
-
[
|
89
|
+
[schemaSymbol]: true;
|
90
|
+
/**
|
91
|
+
* Schema type for inference.
|
92
|
+
*/
|
93
|
+
_type: OBJECT;
|
90
94
|
/**
|
91
95
|
* Optional. Validates that the structure of a value matches this schema,
|
92
96
|
* and returns a typed version of the value if it does.
|
93
97
|
*/
|
94
98
|
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
99
|
+
/**
|
100
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
101
|
+
*/
|
102
|
+
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
95
103
|
};
|
96
104
|
/**
|
97
|
-
*
|
105
|
+
* Creates a schema with deferred creation.
|
106
|
+
* This is important to reduce the startup time of the library
|
107
|
+
* and to avoid initializing unused validators.
|
98
108
|
*
|
99
|
-
* @param
|
109
|
+
* @param createValidator A function that creates a schema.
|
110
|
+
* @returns A function that returns a schema.
|
100
111
|
*/
|
101
|
-
declare function
|
102
|
-
|
112
|
+
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
113
|
+
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
114
|
+
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | StandardSchemaV1<unknown, SCHEMA>;
|
115
|
+
type InferSchema<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
103
116
|
/**
|
104
|
-
*
|
105
|
-
* This is important to reduce the startup time of the library
|
106
|
-
* and to avoid initializing unused validators.
|
117
|
+
* Create a schema using a JSON Schema.
|
107
118
|
*
|
108
|
-
* @param
|
109
|
-
* @
|
119
|
+
* @param jsonSchema The JSON Schema for the schema.
|
120
|
+
* @param options.validate Optional. A validation function for the schema.
|
110
121
|
*/
|
111
|
-
declare function
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
declare function
|
116
|
-
|
122
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
123
|
+
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
124
|
+
}): Schema<OBJECT>;
|
125
|
+
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
126
|
+
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
127
|
+
/**
|
128
|
+
* Enables support for references in the schema.
|
129
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
130
|
+
* However, not all language models and providers support such references.
|
131
|
+
* Defaults to `false`.
|
132
|
+
*/
|
133
|
+
useReferences?: boolean;
|
134
|
+
}): Schema<OBJECT>;
|
117
135
|
|
118
136
|
/**
|
119
137
|
* Parses a JSON string into an unknown object.
|
@@ -135,7 +153,7 @@ declare function parseJSON(options: {
|
|
135
153
|
*/
|
136
154
|
declare function parseJSON<T>(options: {
|
137
155
|
text: string;
|
138
|
-
schema:
|
156
|
+
schema: FlexibleSchema<T>;
|
139
157
|
}): Promise<T>;
|
140
158
|
type ParseResult<T> = {
|
141
159
|
success: true;
|
@@ -166,7 +184,7 @@ declare function safeParseJSON(options: {
|
|
166
184
|
*/
|
167
185
|
declare function safeParseJSON<T>(options: {
|
168
186
|
text: string;
|
169
|
-
schema:
|
187
|
+
schema: FlexibleSchema<T>;
|
170
188
|
}): Promise<ParseResult<T>>;
|
171
189
|
declare function isParsableJson(input: string): boolean;
|
172
190
|
|
@@ -180,13 +198,13 @@ type ResponseHandler<RETURN_TYPE> = (options: {
|
|
180
198
|
responseHeaders?: Record<string, string>;
|
181
199
|
}>;
|
182
200
|
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
183
|
-
errorSchema:
|
201
|
+
errorSchema: FlexibleSchema<T>;
|
184
202
|
errorToMessage: (error: T) => string;
|
185
203
|
isRetryable?: (response: Response, error?: T) => boolean;
|
186
204
|
}) => ResponseHandler<APICallError>;
|
187
|
-
declare const createEventSourceResponseHandler: <T>(chunkSchema:
|
205
|
+
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
188
206
|
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
189
|
-
declare const createJsonResponseHandler: <T>(responseSchema:
|
207
|
+
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
190
208
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
191
209
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
192
210
|
|
@@ -282,13 +300,13 @@ declare function mediaTypeToExtension(mediaType: string): string;
|
|
282
300
|
*/
|
283
301
|
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
284
302
|
stream: ReadableStream<Uint8Array>;
|
285
|
-
schema:
|
303
|
+
schema: FlexibleSchema<T>;
|
286
304
|
}): ReadableStream<ParseResult<T>>;
|
287
305
|
|
288
306
|
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
289
307
|
provider: string;
|
290
308
|
providerOptions: Record<string, unknown> | undefined;
|
291
|
-
schema:
|
309
|
+
schema: FlexibleSchema<OPTIONS>;
|
292
310
|
}): Promise<OPTIONS | undefined>;
|
293
311
|
|
294
312
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
@@ -334,56 +352,6 @@ declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, fa
|
|
334
352
|
responseHeaders?: Record<string, string>;
|
335
353
|
}>;
|
336
354
|
|
337
|
-
/**
|
338
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
339
|
-
*/
|
340
|
-
declare const schemaSymbol: unique symbol;
|
341
|
-
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
342
|
-
/**
|
343
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
344
|
-
*/
|
345
|
-
[schemaSymbol]: true;
|
346
|
-
/**
|
347
|
-
* Schema type for inference.
|
348
|
-
*/
|
349
|
-
_type: OBJECT;
|
350
|
-
/**
|
351
|
-
* The JSON Schema for the schema. It is passed to the providers.
|
352
|
-
*/
|
353
|
-
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
354
|
-
};
|
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;
|
367
|
-
/**
|
368
|
-
* Create a schema using a JSON Schema.
|
369
|
-
*
|
370
|
-
* @param jsonSchema The JSON Schema for the schema.
|
371
|
-
* @param options.validate Optional. A validation function for the schema.
|
372
|
-
*/
|
373
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
374
|
-
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
375
|
-
}): Schema<OBJECT>;
|
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>;
|
386
|
-
|
387
355
|
/**
|
388
356
|
Additional provider-specific options.
|
389
357
|
|
@@ -874,7 +842,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
|
|
874
842
|
*/
|
875
843
|
declare function validateTypes<OBJECT>({ value, schema, }: {
|
876
844
|
value: unknown;
|
877
|
-
schema:
|
845
|
+
schema: FlexibleSchema<OBJECT>;
|
878
846
|
}): Promise<OBJECT>;
|
879
847
|
/**
|
880
848
|
* Safely validates the types of an unknown object using a schema and
|
@@ -887,7 +855,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
|
|
887
855
|
*/
|
888
856
|
declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
889
857
|
value: unknown;
|
890
|
-
schema:
|
858
|
+
schema: FlexibleSchema<OBJECT>;
|
891
859
|
}): Promise<{
|
892
860
|
success: true;
|
893
861
|
value: OBJECT;
|
@@ -985,4 +953,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
985
953
|
dynamic?: boolean;
|
986
954
|
}
|
987
955
|
|
988
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type
|
956
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, 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, asSchema, 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, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|