@ai-sdk/provider-utils 5.0.0-beta.8 → 5.0.0-canary.31

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/dist/index.d.ts +1299 -862
  3. package/dist/index.js +813 -325
  4. package/dist/index.js.map +1 -1
  5. package/dist/test/index.d.ts +2 -1
  6. package/dist/test/index.js +18 -37
  7. package/dist/test/index.js.map +1 -1
  8. package/package.json +13 -11
  9. package/src/add-additional-properties-to-json-schema.ts +1 -1
  10. package/src/as-array.ts +12 -0
  11. package/src/convert-image-model-file-to-data-uri.ts +1 -1
  12. package/src/convert-inline-file-data-to-uint8-array.ts +30 -0
  13. package/src/create-tool-name-mapping.ts +1 -1
  14. package/src/detect-media-type.ts +312 -0
  15. package/src/filter-nullable.ts +11 -0
  16. package/src/get-error-message.ts +1 -15
  17. package/src/get-from-api.ts +2 -2
  18. package/src/has-required-key.ts +6 -0
  19. package/src/index.ts +39 -14
  20. package/src/inject-json-instruction.ts +1 -1
  21. package/src/is-buffer.ts +9 -0
  22. package/src/is-json-serializable.ts +29 -0
  23. package/src/is-provider-reference.ts +21 -0
  24. package/src/is-url-supported.ts +17 -2
  25. package/src/load-api-key.ts +1 -1
  26. package/src/load-setting.ts +1 -1
  27. package/src/map-reasoning-to-provider.ts +4 -1
  28. package/src/maybe-promise-like.ts +3 -0
  29. package/src/parse-json-event-stream.ts +3 -3
  30. package/src/parse-json.ts +3 -3
  31. package/src/parse-provider-options.ts +1 -1
  32. package/src/post-to-api.ts +4 -4
  33. package/src/{provider-tool-factory.ts → provider-defined-tool-factory.ts} +22 -29
  34. package/src/provider-executed-tool-factory.ts +69 -0
  35. package/src/resolve-full-media-type.ts +49 -0
  36. package/src/resolve-provider-reference.ts +26 -0
  37. package/src/resolve.ts +16 -1
  38. package/src/response-handler.ts +3 -3
  39. package/src/schema.ts +6 -3
  40. package/src/secure-json-parse.ts +1 -1
  41. package/src/serialize-model-options.ts +63 -0
  42. package/src/streaming-tool-call-tracker.ts +241 -0
  43. package/src/test/convert-response-stream-to-array.ts +1 -1
  44. package/src/test/is-node-version.ts +22 -1
  45. package/src/to-json-schema/zod3-to-json-schema/options.ts +3 -3
  46. package/src/to-json-schema/zod3-to-json-schema/parse-def.ts +3 -3
  47. package/src/to-json-schema/zod3-to-json-schema/parse-types.ts +22 -22
  48. package/src/to-json-schema/zod3-to-json-schema/parsers/array.ts +3 -3
  49. package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.ts +1 -1
  50. package/src/to-json-schema/zod3-to-json-schema/parsers/branded.ts +2 -2
  51. package/src/to-json-schema/zod3-to-json-schema/parsers/catch.ts +2 -2
  52. package/src/to-json-schema/zod3-to-json-schema/parsers/date.ts +4 -4
  53. package/src/to-json-schema/zod3-to-json-schema/parsers/default.ts +3 -3
  54. package/src/to-json-schema/zod3-to-json-schema/parsers/effects.ts +3 -3
  55. package/src/to-json-schema/zod3-to-json-schema/parsers/enum.ts +1 -1
  56. package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.ts +5 -5
  57. package/src/to-json-schema/zod3-to-json-schema/parsers/literal.ts +1 -1
  58. package/src/to-json-schema/zod3-to-json-schema/parsers/map.ts +4 -5
  59. package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.ts +1 -1
  60. package/src/to-json-schema/zod3-to-json-schema/parsers/never.ts +1 -2
  61. package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.ts +4 -4
  62. package/src/to-json-schema/zod3-to-json-schema/parsers/number.ts +1 -1
  63. package/src/to-json-schema/zod3-to-json-schema/parsers/object.ts +3 -3
  64. package/src/to-json-schema/zod3-to-json-schema/parsers/optional.ts +3 -3
  65. package/src/to-json-schema/zod3-to-json-schema/parsers/pipeline.ts +4 -4
  66. package/src/to-json-schema/zod3-to-json-schema/parsers/promise.ts +3 -3
  67. package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.ts +2 -2
  68. package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +9 -10
  69. package/src/to-json-schema/zod3-to-json-schema/parsers/set.ts +3 -3
  70. package/src/to-json-schema/zod3-to-json-schema/parsers/string.ts +2 -2
  71. package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.ts +3 -3
  72. package/src/to-json-schema/zod3-to-json-schema/parsers/undefined.ts +1 -2
  73. package/src/to-json-schema/zod3-to-json-schema/parsers/union.ts +3 -3
  74. package/src/to-json-schema/zod3-to-json-schema/parsers/unknown.ts +1 -2
  75. package/src/to-json-schema/zod3-to-json-schema/refs.ts +3 -3
  76. package/src/to-json-schema/zod3-to-json-schema/select-parser.ts +2 -2
  77. package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts +3 -3
  78. package/src/types/assistant-model-message.ts +3 -3
  79. package/src/types/content-part.ts +82 -24
  80. package/src/types/executable-tool.ts +17 -0
  81. package/src/types/execute-tool.ts +23 -23
  82. package/src/types/file-data.ts +48 -0
  83. package/src/types/index.ts +21 -3
  84. package/src/types/infer-tool-context.ts +7 -2
  85. package/src/types/infer-tool-set-context.ts +15 -0
  86. package/src/types/model-message.ts +4 -4
  87. package/src/types/never-optional.ts +7 -0
  88. package/src/types/provider-options.ts +1 -1
  89. package/src/types/provider-reference.ts +10 -0
  90. package/src/types/sensitive-context.ts +9 -0
  91. package/src/types/system-model-message.ts +1 -1
  92. package/src/types/tool-approval-request.ts +7 -0
  93. package/src/types/tool-execute-function.ts +50 -0
  94. package/src/types/tool-model-message.ts +3 -3
  95. package/src/types/tool-needs-approval-function.ts +39 -0
  96. package/src/types/tool-set.ts +22 -0
  97. package/src/types/tool.ts +230 -223
  98. package/src/types/user-model-message.ts +2 -2
  99. package/src/validate-types.ts +5 -3
  100. package/dist/index.d.mts +0 -1547
  101. package/dist/index.mjs +0 -2817
  102. package/dist/index.mjs.map +0 -1
  103. package/dist/test/index.d.mts +0 -17
  104. package/dist/test/index.mjs +0 -77
  105. package/dist/test/index.mjs.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,10 +1,22 @@
1
- import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
1
+ import { SharedV4FileDataUrl, SharedV4FileDataReference, SharedV4FileDataText, SharedV4ProviderOptions, SharedV4ProviderReference, JSONValue, ImageModelV4File, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderMetadata, LanguageModelV4FilePart, JSONObject, LanguageModelV4StreamPart, TypeValidationContext } from '@ai-sdk/provider';
2
+ export { getErrorMessage } from '@ai-sdk/provider';
2
3
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
4
  export * from '@standard-schema/spec';
4
5
  import * as z3 from 'zod/v3';
5
6
  import * as z4 from 'zod/v4';
7
+ export { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from '@workflow/serde';
6
8
  export { EventSourceMessage, EventSourceParserStream } from 'eventsource-parser/stream';
7
9
 
10
+ /**
11
+ * A value that can be provided either as a single item, an array of items,
12
+ * or be left undefined.
13
+ */
14
+ type Arrayable<T> = T | T[] | undefined;
15
+ /**
16
+ * Normalizes a possibly undefined or non-array value into an array.
17
+ */
18
+ declare function asArray<T>(value: Arrayable<T>): T[];
19
+
8
20
  declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
9
21
 
10
22
  /**
@@ -17,795 +29,310 @@ declare function combineHeaders(...headers: Array<Record<string, string | undefi
17
29
  declare function convertAsyncIteratorToReadableStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
18
30
 
19
31
  /**
20
- * Interface for mapping between custom tool names and provider tool names.
21
- */
22
- interface ToolNameMapping {
23
- /**
24
- * Maps a custom tool name (used by the client) to the provider's tool name.
25
- * If the custom tool name does not have a mapping, returns the input name.
26
- *
27
- * @param customToolName - The custom name of the tool defined by the client.
28
- * @returns The corresponding provider tool name, or the input name if not mapped.
29
- */
30
- toProviderToolName: (customToolName: string) => string;
31
- /**
32
- * Maps a provider tool name to the custom tool name used by the client.
33
- * If the provider tool name does not have a mapping, returns the input name.
34
- *
35
- * @param providerToolName - The name of the tool as understood by the provider.
36
- * @returns The corresponding custom tool name, or the input name if not mapped.
37
- */
38
- toCustomToolName: (providerToolName: string) => string;
39
- }
40
- /**
41
- * @param tools - Tools that were passed to the language model.
42
- * @param providerToolNames - Maps the provider tool ids to the provider tool names.
43
- */
44
- declare function createToolNameMapping({ tools, providerToolNames, }: {
45
- /**
46
- * Tools that were passed to the language model.
47
- */
48
- tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
49
- /**
50
- * Maps the provider tool ids to the provider tool names.
51
- */
52
- providerToolNames: Record<`${string}.${string}`, string>;
53
- }): ToolNameMapping;
54
-
55
- /**
56
- * Creates a Promise that resolves after a specified delay
57
- * @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
58
- * @param signal - Optional AbortSignal to cancel the delay
59
- * @returns A Promise that resolves after the specified delay
60
- * @throws {DOMException} When the signal is aborted
32
+ * Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
61
33
  */
62
- declare function delay(delayInMs?: number | null, options?: {
63
- abortSignal?: AbortSignal;
64
- }): Promise<void>;
34
+ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
65
35
 
66
36
  /**
67
- * Delayed promise. It is only constructed once the value is accessed.
68
- * This is useful to avoid unhandled promise rejections when the promise is created
69
- * but not accessed.
37
+ * File data variant containing raw bytes (`Uint8Array`, `ArrayBuffer`, or
38
+ * `Buffer`) or a base64-encoded string.
39
+ *
40
+ * This is slightly more permissive than `SharedV4FileDataData`.
70
41
  */
71
- declare class DelayedPromise<T> {
72
- private status;
73
- private _promise;
74
- private _resolve;
75
- private _reject;
76
- get promise(): Promise<T>;
77
- resolve(value: T): void;
78
- reject(error: unknown): void;
79
- isResolved(): boolean;
80
- isRejected(): boolean;
81
- isPending(): boolean;
42
+ interface FileDataData {
43
+ type: 'data';
44
+ data: DataContent;
82
45
  }
83
-
84
46
  /**
85
- * Extracts the headers from a response object and returns them as a key-value object.
86
- *
87
- * @param response - The response object to extract headers from.
88
- * @returns The headers as a key-value object.
47
+ * File data variant containing a URL that points to the file.
89
48
  */
90
- declare function extractResponseHeaders(response: Response): {
91
- [k: string]: string;
92
- };
93
-
49
+ type FileDataUrl = SharedV4FileDataUrl;
94
50
  /**
95
- * Convert an ImageModelV4File to a URL or data URI string.
96
- *
97
- * If the file is a URL, it returns the URL as-is.
98
- * If the file is base64 data, it returns a data URI with the base64 data.
99
- * If the file is a Uint8Array, it converts it to base64 and returns a data URI.
51
+ * File data variant containing a provider reference (`{ [provider]: id }`).
100
52
  */
101
- declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
102
-
53
+ type FileDataReference = SharedV4FileDataReference;
103
54
  /**
104
- * Converts an input object to FormData for multipart/form-data requests.
105
- *
106
- * Handles the following cases:
107
- * - `null` or `undefined` values are skipped
108
- * - Arrays with a single element are appended as a single value
109
- * - Arrays with multiple elements are appended with `[]` suffix (e.g., `image[]`)
110
- * unless `useArrayBrackets` is set to `false`
111
- * - All other values are appended directly
112
- *
113
- * @param input - The input object to convert. Use a generic type for type validation.
114
- * @param options - Optional configuration object.
115
- * @param options.useArrayBrackets - Whether to add `[]` suffix for multi-element arrays.
116
- * Defaults to `true`. Set to `false` for APIs that expect repeated keys without brackets.
117
- * @returns A FormData object containing the input values.
118
- *
119
- * @example
120
- * ```ts
121
- * type MyInput = {
122
- * model: string;
123
- * prompt: string;
124
- * images: Blob[];
125
- * };
126
- *
127
- * const formData = convertToFormData<MyInput>({
128
- * model: 'gpt-image-1',
129
- * prompt: 'A cat',
130
- * images: [blob1, blob2],
131
- * });
132
- * ```
55
+ * File data variant containing inline text content (e.g. an inline text
56
+ * document).
133
57
  */
134
- declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
135
- useArrayBrackets?: boolean;
136
- }): FormData;
137
-
58
+ type FileDataText = SharedV4FileDataText;
138
59
  /**
139
- * Download a file from a URL and return it as a Blob.
140
- *
141
- * @param url - The URL to download from.
142
- * @param options - Optional settings for the download.
143
- * @param options.maxBytes - Maximum allowed download size in bytes. Defaults to 100 MiB.
144
- * @param options.abortSignal - An optional abort signal to cancel the download.
145
- * @returns A Promise that resolves to the downloaded Blob.
60
+ * File data as a tagged discriminated union:
146
61
  *
147
- * @throws DownloadError if the download fails or exceeds maxBytes.
62
+ * - `{ type: 'data', data }`: raw bytes (`Uint8Array`, `ArrayBuffer`, or
63
+ * `Buffer`) or a base64-encoded string.
64
+ * - `{ type: 'url', url }`: a URL that points to the file.
65
+ * - `{ type: 'reference', reference }`: a provider reference (`{ [provider]: id }`).
66
+ * - `{ type: 'text', text }`: inline text content (e.g. an inline text document).
148
67
  */
149
- declare function downloadBlob(url: string, options?: {
150
- maxBytes?: number;
151
- abortSignal?: AbortSignal;
152
- }): Promise<Blob>;
153
-
154
- declare const symbol: unique symbol;
155
- declare class DownloadError extends AISDKError {
156
- private readonly [symbol];
157
- readonly url: string;
158
- readonly statusCode?: number;
159
- readonly statusText?: string;
160
- constructor({ url, statusCode, statusText, cause, message, }: {
161
- url: string;
162
- statusCode?: number;
163
- statusText?: string;
164
- message?: string;
165
- cause?: unknown;
166
- });
167
- static isInstance(error: unknown): error is DownloadError;
168
- }
68
+ type FileData = FileDataData | FileDataUrl | FileDataReference | FileDataText;
169
69
 
170
70
  /**
171
- * Default maximum download size: 2 GiB.
172
- *
173
- * `fetch().arrayBuffer()` has ~2x peak memory overhead (undici buffers the
174
- * body internally, then creates the JS ArrayBuffer), so very large downloads
175
- * risk exceeding the default V8 heap limit on 64-bit systems and terminating
176
- * the process with an out-of-memory error.
71
+ * Additional provider-specific options.
177
72
  *
178
- * Setting this limit converts an unrecoverable OOM crash into a catchable
179
- * `DownloadError`.
73
+ * They are passed through to the provider from the AI SDK and enable
74
+ * provider-specific functionality that can be fully encapsulated in the provider.
180
75
  */
181
- declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
76
+ type ProviderOptions = SharedV4ProviderOptions;
77
+
182
78
  /**
183
- * Reads a fetch Response body with a size limit to prevent memory exhaustion.
184
- *
185
- * Checks the Content-Length header for early rejection, then reads the body
186
- * incrementally via ReadableStream and aborts with a DownloadError when the
187
- * limit is exceeded.
79
+ * A mapping of provider names to provider-specific file identifiers.
188
80
  *
189
- * @param response - The fetch Response to read.
190
- * @param url - The URL being downloaded (used in error messages).
191
- * @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
192
- * @returns A Uint8Array containing the response body.
193
- * @throws DownloadError if the response exceeds maxBytes.
81
+ * Provider references allow files to be identified across different
82
+ * providers without re-uploading, by storing each provider's own
83
+ * identifier for the same logical file.
194
84
  */
195
- declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
196
- response: Response;
197
- url: string;
198
- maxBytes?: number;
199
- }): Promise<Uint8Array>;
85
+ type ProviderReference = SharedV4ProviderReference;
200
86
 
201
87
  /**
202
- * Fetch function type (standardizes the version of fetch used).
88
+ * Text content part of a prompt. It contains a string of text.
203
89
  */
204
- type FetchFunction = typeof globalThis.fetch;
205
-
90
+ interface TextPart {
91
+ type: 'text';
92
+ /**
93
+ * The text content.
94
+ */
95
+ text: string;
96
+ /**
97
+ * Additional provider-specific metadata. They are passed through
98
+ * to the provider from the AI SDK and enable provider-specific
99
+ * functionality that can be fully encapsulated in the provider.
100
+ */
101
+ providerOptions?: ProviderOptions;
102
+ }
206
103
  /**
207
- * Creates an ID generator.
208
- * The total length of the ID is the sum of the prefix, separator, and random part length.
209
- * Not cryptographically secure.
104
+ * Image content part of a prompt. It contains an image.
210
105
  *
211
- * @param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
212
- * @param prefix - The prefix of the ID to generate. Optional.
213
- * @param separator - The separator between the prefix and the random part of the ID. Default: '-'.
214
- * @param size - The size of the random part of the ID to generate. Default: 16.
215
- */
216
- declare const createIdGenerator: ({ prefix, size, alphabet, separator, }?: {
217
- prefix?: string;
218
- separator?: string;
219
- size?: number;
220
- alphabet?: string;
221
- }) => IdGenerator;
222
- /**
223
- * A function that generates an ID.
224
- */
225
- type IdGenerator = () => string;
226
- /**
227
- * Generates a 16-character random string to use for IDs.
228
- * Not cryptographically secure.
229
- */
230
- declare const generateId: IdGenerator;
231
-
232
- declare function getErrorMessage(error: unknown | undefined): string;
233
-
234
- /**
235
- * Used to mark schemas so we can support both Zod and custom schemas.
106
+ * @deprecated Use `FilePart` with `mediaType: 'image'` instead:
107
+ * `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
236
108
  */
237
- declare const schemaSymbol: unique symbol;
238
- type ValidationResult<OBJECT> = {
239
- success: true;
240
- value: OBJECT;
241
- } | {
242
- success: false;
243
- error: Error;
244
- };
245
- type Schema<OBJECT = unknown> = {
109
+ interface ImagePart {
110
+ type: 'image';
246
111
  /**
247
- * Used to mark schemas so we can support both Zod and custom schemas.
112
+ * Image data. Can either be:
113
+ *
114
+ * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
115
+ * - URL: a URL that points to the image
116
+ * - ProviderReference: a provider reference from `uploadFile`
248
117
  */
249
- [schemaSymbol]: true;
118
+ image: DataContent | URL | ProviderReference;
250
119
  /**
251
- * Schema type for inference.
120
+ * Optional IANA media type of the image.
121
+ *
122
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
252
123
  */
253
- _type: OBJECT;
124
+ mediaType?: string;
254
125
  /**
255
- * Optional. Validates that the structure of a value matches this schema,
256
- * and returns a typed version of the value if it does.
126
+ * Additional provider-specific metadata. They are passed through
127
+ * to the provider from the AI SDK and enable provider-specific
128
+ * functionality that can be fully encapsulated in the provider.
257
129
  */
258
- readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
130
+ providerOptions?: ProviderOptions;
131
+ }
132
+ /**
133
+ * File content part of a prompt. It contains a file.
134
+ */
135
+ interface FilePart {
136
+ type: 'file';
259
137
  /**
260
- * The JSON Schema for the schema. It is passed to the providers.
138
+ * File data. Either a tagged shape or a bare shorthand:
139
+ *
140
+ * - `{ type: 'data', data }` or bare `DataContent`: raw bytes
141
+ * (base64 string, Uint8Array, ArrayBuffer, Buffer)
142
+ * - `{ type: 'url', url }` or bare `URL`: a URL that points to the file
143
+ * - `{ type: 'reference', reference }` or bare `ProviderReference`:
144
+ * a provider reference from `uploadFile`
145
+ * - `{ type: 'text', text }`: inline text content (tagged only)
261
146
  */
262
- readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
263
- };
264
- /**
265
- * Creates a schema with deferred creation.
266
- * This is important to reduce the startup time of the library
267
- * and to avoid initializing unused validators.
268
- *
269
- * @param createValidator A function that creates a schema.
270
- * @returns A function that returns a schema.
271
- */
272
- declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
273
- type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
274
- type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | z4.core.$ZodType<SCHEMA, any>;
275
- type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & StandardJSONSchemaV1<unknown, SCHEMA>;
276
- type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
277
- type InferSchema<SCHEMA> = SCHEMA extends ZodSchema<infer T> ? T : SCHEMA extends StandardSchema<infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
278
- /**
279
- * Create a schema using a JSON Schema.
280
- *
281
- * @param jsonSchema The JSON Schema for the schema.
282
- * @param options.validate Optional. A validation function for the schema.
283
- */
284
- declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
285
- validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
286
- }): Schema<OBJECT>;
287
- declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
288
- declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
147
+ data: FileData | DataContent | URL | ProviderReference;
289
148
  /**
290
- * Enables support for references in the schema.
291
- * This is required for recursive schemas, e.g. with `z.lazy`.
292
- * However, not all language models and providers support such references.
293
- * Defaults to `false`.
149
+ * Optional filename of the file.
294
150
  */
295
- useReferences?: boolean;
296
- }): Schema<OBJECT>;
297
-
151
+ filename?: string;
152
+ /**
153
+ * Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
154
+ * the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
155
+ *
156
+ * `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
157
+ * top-level segment alone (e.g. `image`). Providers can use the helpers in
158
+ * `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
159
+ * `detectMediaType`) to resolve the field according to their API
160
+ * requirements.
161
+ *
162
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
163
+ */
164
+ mediaType: string;
165
+ /**
166
+ * Additional provider-specific metadata. They are passed through
167
+ * to the provider from the AI SDK and enable provider-specific
168
+ * functionality that can be fully encapsulated in the provider.
169
+ */
170
+ providerOptions?: ProviderOptions;
171
+ }
298
172
  /**
299
- * Parses a JSON string into an unknown object.
300
- *
301
- * @param text - The JSON string to parse.
302
- * @returns {JSONValue} - The parsed JSON object.
173
+ * Reasoning content part of a prompt. It contains a reasoning.
303
174
  */
304
- declare function parseJSON(options: {
175
+ interface ReasoningPart {
176
+ type: 'reasoning';
177
+ /**
178
+ * The reasoning text.
179
+ */
305
180
  text: string;
306
- schema?: undefined;
307
- }): Promise<JSONValue>;
181
+ /**
182
+ * Additional provider-specific metadata. They are passed through
183
+ * to the provider from the AI SDK and enable provider-specific
184
+ * functionality that can be fully encapsulated in the provider.
185
+ */
186
+ providerOptions?: ProviderOptions;
187
+ }
308
188
  /**
309
- * Parses a JSON string into a strongly-typed object using the provided schema.
310
- *
311
- * @template T - The type of the object to parse the JSON into.
312
- * @param {string} text - The JSON string to parse.
313
- * @param {Validator<T>} schema - The schema to use for parsing the JSON.
314
- * @returns {Promise<T>} - The parsed object.
189
+ * Custom content part of a prompt. It contains no standardized payload beyond
190
+ * provider-specific options.
315
191
  */
316
- declare function parseJSON<T>(options: {
317
- text: string;
318
- schema: FlexibleSchema<T>;
319
- }): Promise<T>;
320
- type ParseResult<T> = {
321
- success: true;
322
- value: T;
323
- rawValue: unknown;
324
- } | {
325
- success: false;
326
- error: JSONParseError | TypeValidationError;
327
- rawValue: unknown;
328
- };
192
+ interface CustomPart {
193
+ type: 'custom';
194
+ /**
195
+ * The kind of custom content, in the format `{provider}.{provider-type}`.
196
+ */
197
+ kind: `${string}.${string}`;
198
+ /**
199
+ * Additional provider-specific metadata. They are passed through
200
+ * to the provider from the AI SDK and enable provider-specific
201
+ * functionality that can be fully encapsulated in the provider.
202
+ */
203
+ providerOptions?: ProviderOptions;
204
+ }
329
205
  /**
330
- * Safely parses a JSON string and returns the result as an object of type `unknown`.
331
- *
332
- * @param text - The JSON string to parse.
333
- * @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
206
+ * Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
334
207
  */
335
- declare function safeParseJSON(options: {
336
- text: string;
337
- schema?: undefined;
338
- }): Promise<ParseResult<JSONValue>>;
208
+ interface ReasoningFilePart {
209
+ type: 'reasoning-file';
210
+ /**
211
+ * Reasoning file data.
212
+ *
213
+ * Reasoning files originate from a model's reasoning output and are always
214
+ * raw bytes or a fetchable URL. Unlike `FilePart.data`, the `reference` and
215
+ * `text` shapes are not supported here: provider references describe files
216
+ * uploaded by the user (not produced as model output), and reasoning text is
217
+ * carried by `ReasoningPart` rather than as a file.
218
+ *
219
+ * Either a tagged shape or a bare shorthand:
220
+ *
221
+ * - `{ type: 'data', data }` or bare `DataContent`: raw bytes
222
+ * (base64 string, Uint8Array, ArrayBuffer, Buffer)
223
+ * - `{ type: 'url', url }` or bare `URL`: a URL that points to the file
224
+ */
225
+ data: FileDataData | FileDataUrl | DataContent | URL;
226
+ /**
227
+ * IANA media type of the file.
228
+ *
229
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
230
+ */
231
+ mediaType: string;
232
+ /**
233
+ * Additional provider-specific metadata. They are passed through
234
+ * to the provider from the AI SDK and enable provider-specific
235
+ * functionality that can be fully encapsulated in the provider.
236
+ */
237
+ providerOptions?: ProviderOptions;
238
+ }
339
239
  /**
340
- * Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
341
- *
342
- * @template T - The type of the object to parse the JSON into.
343
- * @param {string} text - The JSON string to parse.
344
- * @param {Validator<T>} schema - The schema to use for parsing the JSON.
345
- * @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
240
+ * Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
346
241
  */
347
- declare function safeParseJSON<T>(options: {
348
- text: string;
349
- schema: FlexibleSchema<T>;
350
- }): Promise<ParseResult<T>>;
351
- declare function isParsableJson(input: string): boolean;
352
-
353
- type ResponseHandler<RETURN_TYPE> = (options: {
354
- url: string;
355
- requestBodyValues: unknown;
356
- response: Response;
357
- }) => PromiseLike<{
358
- value: RETURN_TYPE;
359
- rawValue?: unknown;
360
- responseHeaders?: Record<string, string>;
361
- }>;
362
- declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
363
- errorSchema: FlexibleSchema<T>;
364
- errorToMessage: (error: T) => string;
365
- isRetryable?: (response: Response, error?: T) => boolean;
366
- }) => ResponseHandler<APICallError>;
367
- declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
368
- declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
369
- declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
370
- declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
371
-
372
- declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
373
- url: string;
374
- headers?: Record<string, string | undefined>;
375
- failedResponseHandler: ResponseHandler<Error>;
376
- successfulResponseHandler: ResponseHandler<T>;
377
- abortSignal?: AbortSignal;
378
- fetch?: FetchFunction;
379
- }) => Promise<{
380
- value: T;
381
- rawValue?: unknown;
382
- responseHeaders?: Record<string, string>;
383
- }>;
384
-
385
- declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
386
-
387
- declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
388
- messages: LanguageModelV4Prompt;
389
- schema?: JSONSchema7;
390
- schemaPrefix?: string;
391
- schemaSuffix?: string;
392
- }): LanguageModelV4Prompt;
393
-
394
- declare function isAbortError(error: unknown): error is Error;
395
-
242
+ interface ToolCallPart {
243
+ type: 'tool-call';
244
+ /**
245
+ * ID of the tool call. This ID is used to match the tool call with the tool result.
246
+ */
247
+ toolCallId: string;
248
+ /**
249
+ * Name of the tool that is being called.
250
+ */
251
+ toolName: string;
252
+ /**
253
+ * Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
254
+ */
255
+ input: unknown;
256
+ /**
257
+ * Additional provider-specific metadata. They are passed through
258
+ * to the provider from the AI SDK and enable provider-specific
259
+ * functionality that can be fully encapsulated in the provider.
260
+ */
261
+ providerOptions?: ProviderOptions;
262
+ /**
263
+ * Whether the tool call was executed by the provider.
264
+ */
265
+ providerExecuted?: boolean;
266
+ }
396
267
  /**
397
- * Type guard that checks whether a value is not `null` or `undefined`.
398
- *
399
- * @template T - The type of the value to check.
400
- * @param value - The value to check.
401
- * @returns `true` if the value is neither `null` nor `undefined`, otherwise `false`.
268
+ * Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
402
269
  */
403
- declare function isNonNullable<T>(value: T | undefined | null): value is NonNullable<T>;
404
-
270
+ interface ToolResultPart {
271
+ type: 'tool-result';
272
+ /**
273
+ * ID of the tool call that this result is associated with.
274
+ */
275
+ toolCallId: string;
276
+ /**
277
+ * Name of the tool that generated this result.
278
+ */
279
+ toolName: string;
280
+ /**
281
+ * Result of the tool call. This is a JSON-serializable object.
282
+ */
283
+ output: ToolResultOutput;
284
+ /**
285
+ * Additional provider-specific metadata. They are passed through
286
+ * to the provider from the AI SDK and enable provider-specific
287
+ * functionality that can be fully encapsulated in the provider.
288
+ */
289
+ providerOptions?: ProviderOptions;
290
+ }
405
291
  /**
406
- * Checks if the given URL is supported natively by the model.
407
- *
408
- * @param mediaType - The media type of the URL. Case-sensitive.
409
- * @param url - The URL to check.
410
- * @param supportedUrls - A record where keys are case-sensitive media types (or '*')
411
- * and values are arrays of RegExp patterns for URLs.
412
- *
413
- * @returns `true` if the URL matches a pattern under the specific media type
414
- * or the wildcard '*', `false` otherwise.
292
+ * Output of a tool result.
415
293
  */
416
- declare function isUrlSupported({ mediaType, url, supportedUrls, }: {
417
- mediaType: string;
418
- url: string;
419
- supportedUrls: Record<string, RegExp[]>;
420
- }): boolean;
421
-
422
- declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
423
- apiKey: string | undefined;
424
- environmentVariableName: string;
425
- apiKeyParameterName?: string;
426
- description: string;
427
- }): string;
428
-
429
- type ReasoningLevel = Exclude<LanguageModelV4CallOptions['reasoning'], 'none' | 'provider-default' | undefined>;
430
- declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
431
- /**
432
- * Maps a top-level reasoning level to a provider-specific effort string using
433
- * the given effort map. Pushes a compatibility warning if the reasoning level
434
- * maps to a different string, or an unsupported warning if the level is not
435
- * present in the map.
436
- *
437
- * @returns The mapped effort string, or `undefined` if the level is not
438
- * supported.
439
- */
440
- declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings, }: {
441
- reasoning: ReasoningLevel;
442
- effortMap: Partial<Record<ReasoningLevel, T>>;
443
- warnings: SharedV4Warning[];
444
- }): T | undefined;
445
- /**
446
- * Maps a top-level reasoning level to an absolute token budget by multiplying
447
- * the model's max output tokens by a percentage from the budget percentages
448
- * map. The result is clamped between `minReasoningBudget` (default 1024) and
449
- * `maxReasoningBudget`. Pushes an unsupported warning if the level is not
450
- * present in the budget percentages map.
451
- *
452
- * @returns The computed token budget, or `undefined` if the level is not
453
- * supported.
454
- */
455
- declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings, }: {
456
- reasoning: ReasoningLevel;
457
- maxOutputTokens: number;
458
- maxReasoningBudget: number;
459
- minReasoningBudget?: number;
460
- budgetPercentages?: Partial<Record<ReasoningLevel, number>>;
461
- warnings: SharedV4Warning[];
462
- }): number | undefined;
463
-
464
- /**
465
- * Loads an optional `string` setting from the environment or a parameter.
466
- *
467
- * @param settingValue - The setting value.
468
- * @param environmentVariableName - The environment variable name.
469
- * @returns The setting value.
470
- */
471
- declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
472
- settingValue: string | undefined;
473
- environmentVariableName: string;
474
- }): string | undefined;
475
-
476
- /**
477
- * Loads a `string` setting from the environment or a parameter.
478
- *
479
- * @param settingValue - The setting value.
480
- * @param environmentVariableName - The environment variable name.
481
- * @param settingName - The setting name.
482
- * @param description - The description of the setting.
483
- * @returns The setting value.
484
- */
485
- declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
486
- settingValue: string | undefined;
487
- environmentVariableName: string;
488
- settingName: string;
489
- description: string;
490
- }): string;
491
-
492
- type MaybePromiseLike<T> = T | PromiseLike<T>;
493
-
494
- /**
495
- * Maps a media type to its corresponding file extension.
496
- * It was originally introduced to set a filename for audio file uploads
497
- * in https://github.com/vercel/ai/pull/8159.
498
- *
499
- * @param mediaType The media type to map.
500
- * @returns The corresponding file extension
501
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
502
- */
503
- declare function mediaTypeToExtension(mediaType: string): string;
504
-
505
- /**
506
- * Normalizes different header inputs into a plain record with lower-case keys.
507
- * Entries with `undefined` or `null` values are removed.
508
- *
509
- * @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
510
- * @returns A record containing the normalized header entries.
511
- */
512
- declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
513
-
514
- /**
515
- * Parses a JSON event stream into a stream of parsed JSON objects.
516
- */
517
- declare function parseJsonEventStream<T>({ stream, schema, }: {
518
- stream: ReadableStream<Uint8Array>;
519
- schema: FlexibleSchema<T>;
520
- }): ReadableStream<ParseResult<T>>;
521
-
522
- declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
523
- provider: string;
524
- providerOptions: Record<string, unknown> | undefined;
525
- schema: FlexibleSchema<OPTIONS>;
526
- }): Promise<OPTIONS | undefined>;
527
-
528
- declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
529
- url: string;
530
- headers?: Record<string, string | undefined>;
531
- body: unknown;
532
- failedResponseHandler: ResponseHandler<APICallError>;
533
- successfulResponseHandler: ResponseHandler<T>;
534
- abortSignal?: AbortSignal;
535
- fetch?: FetchFunction;
536
- }) => Promise<{
537
- value: T;
538
- rawValue?: unknown;
539
- responseHeaders?: Record<string, string>;
540
- }>;
541
- declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
542
- url: string;
543
- headers?: Record<string, string | undefined>;
544
- formData: FormData;
545
- failedResponseHandler: ResponseHandler<APICallError>;
546
- successfulResponseHandler: ResponseHandler<T>;
547
- abortSignal?: AbortSignal;
548
- fetch?: FetchFunction;
549
- }) => Promise<{
550
- value: T;
551
- rawValue?: unknown;
552
- responseHeaders?: Record<string, string>;
553
- }>;
554
- declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
555
- url: string;
556
- headers?: Record<string, string | undefined>;
557
- body: {
558
- content: string | FormData | Uint8Array;
559
- values: unknown;
560
- };
561
- failedResponseHandler: ResponseHandler<Error>;
562
- successfulResponseHandler: ResponseHandler<T>;
563
- abortSignal?: AbortSignal;
564
- fetch?: FetchFunction;
565
- }) => Promise<{
566
- value: T;
567
- rawValue?: unknown;
568
- responseHeaders?: Record<string, string>;
569
- }>;
570
-
571
- /**
572
- * Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
573
- */
574
- type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
575
-
576
- /**
577
- * Additional provider-specific options.
578
- *
579
- * They are passed through to the provider from the AI SDK and enable
580
- * provider-specific functionality that can be fully encapsulated in the provider.
581
- */
582
- type ProviderOptions = SharedV4ProviderOptions;
583
-
584
- /**
585
- * Text content part of a prompt. It contains a string of text.
586
- */
587
- interface TextPart {
588
- type: 'text';
294
+ type ToolResultOutput = {
589
295
  /**
590
- * The text content.
296
+ * Text tool output that should be directly sent to the API.
591
297
  */
592
- text: string;
298
+ type: 'text';
299
+ value: string;
593
300
  /**
594
- * Additional provider-specific metadata. They are passed through
595
- * to the provider from the AI SDK and enable provider-specific
596
- * functionality that can be fully encapsulated in the provider.
301
+ * Provider-specific options.
597
302
  */
598
303
  providerOptions?: ProviderOptions;
599
- }
600
- /**
601
- * Image content part of a prompt. It contains an image.
602
- */
603
- interface ImagePart {
604
- type: 'image';
605
- /**
606
- * Image data. Can either be:
607
- *
608
- * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
609
- * - URL: a URL that points to the image
610
- */
611
- image: DataContent | URL;
612
- /**
613
- * Optional IANA media type of the image.
614
- *
615
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
616
- */
617
- mediaType?: string;
304
+ } | {
305
+ type: 'json';
306
+ value: JSONValue;
618
307
  /**
619
- * Additional provider-specific metadata. They are passed through
620
- * to the provider from the AI SDK and enable provider-specific
621
- * functionality that can be fully encapsulated in the provider.
308
+ * Provider-specific options.
622
309
  */
623
310
  providerOptions?: ProviderOptions;
624
- }
625
- /**
626
- * File content part of a prompt. It contains a file.
627
- */
628
- interface FilePart {
629
- type: 'file';
630
- /**
631
- * File data. Can either be:
632
- *
633
- * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
634
- * - URL: a URL that points to the image
635
- */
636
- data: DataContent | URL;
311
+ } | {
637
312
  /**
638
- * Optional filename of the file.
313
+ * Type when the user has denied the execution of the tool call.
639
314
  */
640
- filename?: string;
315
+ type: 'execution-denied';
641
316
  /**
642
- * IANA media type of the file.
643
- *
644
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
317
+ * Optional reason for the execution denial.
645
318
  */
646
- mediaType: string;
319
+ reason?: string;
647
320
  /**
648
- * Additional provider-specific metadata. They are passed through
649
- * to the provider from the AI SDK and enable provider-specific
650
- * functionality that can be fully encapsulated in the provider.
321
+ * Provider-specific options.
651
322
  */
652
323
  providerOptions?: ProviderOptions;
653
- }
654
- /**
655
- * Reasoning content part of a prompt. It contains a reasoning.
656
- */
657
- interface ReasoningPart {
658
- type: 'reasoning';
324
+ } | {
325
+ type: 'error-text';
326
+ value: string;
659
327
  /**
660
- * The reasoning text.
328
+ * Provider-specific options.
661
329
  */
662
- text: string;
330
+ providerOptions?: ProviderOptions;
331
+ } | {
332
+ type: 'error-json';
333
+ value: JSONValue;
663
334
  /**
664
- * Additional provider-specific metadata. They are passed through
665
- * to the provider from the AI SDK and enable provider-specific
666
- * functionality that can be fully encapsulated in the provider.
667
- */
668
- providerOptions?: ProviderOptions;
669
- }
670
- /**
671
- * Custom content part of a prompt. It contains no standardized payload beyond
672
- * provider-specific options.
673
- */
674
- interface CustomPart {
675
- type: 'custom';
676
- /**
677
- * The kind of custom content, in the format `{provider}.{provider-type}`.
678
- */
679
- kind: `${string}.${string}`;
680
- /**
681
- * Additional provider-specific metadata. They are passed through
682
- * to the provider from the AI SDK and enable provider-specific
683
- * functionality that can be fully encapsulated in the provider.
684
- */
685
- providerOptions?: ProviderOptions;
686
- }
687
- /**
688
- * Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
689
- */
690
- interface ReasoningFilePart {
691
- type: 'reasoning-file';
692
- /**
693
- * File data. Can either be:
694
- *
695
- * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
696
- * - URL: a URL that points to the file
697
- */
698
- data: DataContent | URL;
699
- /**
700
- * IANA media type of the file.
701
- *
702
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
703
- */
704
- mediaType: string;
705
- /**
706
- * Additional provider-specific metadata. They are passed through
707
- * to the provider from the AI SDK and enable provider-specific
708
- * functionality that can be fully encapsulated in the provider.
709
- */
710
- providerOptions?: ProviderOptions;
711
- }
712
- /**
713
- * Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
714
- */
715
- interface ToolCallPart {
716
- type: 'tool-call';
717
- /**
718
- * ID of the tool call. This ID is used to match the tool call with the tool result.
719
- */
720
- toolCallId: string;
721
- /**
722
- * Name of the tool that is being called.
723
- */
724
- toolName: string;
725
- /**
726
- * Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
727
- */
728
- input: unknown;
729
- /**
730
- * Additional provider-specific metadata. They are passed through
731
- * to the provider from the AI SDK and enable provider-specific
732
- * functionality that can be fully encapsulated in the provider.
733
- */
734
- providerOptions?: ProviderOptions;
735
- /**
736
- * Whether the tool call was executed by the provider.
737
- */
738
- providerExecuted?: boolean;
739
- }
740
- /**
741
- * Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
742
- */
743
- interface ToolResultPart {
744
- type: 'tool-result';
745
- /**
746
- * ID of the tool call that this result is associated with.
747
- */
748
- toolCallId: string;
749
- /**
750
- * Name of the tool that generated this result.
751
- */
752
- toolName: string;
753
- /**
754
- * Result of the tool call. This is a JSON-serializable object.
755
- */
756
- output: ToolResultOutput;
757
- /**
758
- * Additional provider-specific metadata. They are passed through
759
- * to the provider from the AI SDK and enable provider-specific
760
- * functionality that can be fully encapsulated in the provider.
761
- */
762
- providerOptions?: ProviderOptions;
763
- }
764
- /**
765
- * Output of a tool result.
766
- */
767
- type ToolResultOutput = {
768
- /**
769
- * Text tool output that should be directly sent to the API.
770
- */
771
- type: 'text';
772
- value: string;
773
- /**
774
- * Provider-specific options.
775
- */
776
- providerOptions?: ProviderOptions;
777
- } | {
778
- type: 'json';
779
- value: JSONValue;
780
- /**
781
- * Provider-specific options.
782
- */
783
- providerOptions?: ProviderOptions;
784
- } | {
785
- /**
786
- * Type when the user has denied the execution of the tool call.
787
- */
788
- type: 'execution-denied';
789
- /**
790
- * Optional reason for the execution denial.
791
- */
792
- reason?: string;
793
- /**
794
- * Provider-specific options.
795
- */
796
- providerOptions?: ProviderOptions;
797
- } | {
798
- type: 'error-text';
799
- value: string;
800
- /**
801
- * Provider-specific options.
802
- */
803
- providerOptions?: ProviderOptions;
804
- } | {
805
- type: 'error-json';
806
- value: JSONValue;
807
- /**
808
- * Provider-specific options.
335
+ * Provider-specific options.
809
336
  */
810
337
  providerOptions?: ProviderOptions;
811
338
  } | {
@@ -820,13 +347,6 @@ type ToolResultOutput = {
820
347
  * Provider-specific options.
821
348
  */
822
349
  providerOptions?: ProviderOptions;
823
- } | {
824
- /**
825
- * @deprecated Use image-data or file-data instead.
826
- */
827
- type: 'media';
828
- data: string;
829
- mediaType: string;
830
350
  } | {
831
351
  type: 'file-data';
832
352
  /**
@@ -852,11 +372,19 @@ type ToolResultOutput = {
852
372
  * URL of the file.
853
373
  */
854
374
  url: string;
375
+ /**
376
+ * IANA media type.
377
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
378
+ */
379
+ mediaType?: string;
855
380
  /**
856
381
  * Provider-specific options.
857
382
  */
858
383
  providerOptions?: ProviderOptions;
859
384
  } | {
385
+ /**
386
+ * @deprecated Use file-reference instead.
387
+ */
860
388
  type: 'file-id';
861
389
  /**
862
390
  * ID of the file.
@@ -871,9 +399,20 @@ type ToolResultOutput = {
871
399
  * Provider-specific options.
872
400
  */
873
401
  providerOptions?: ProviderOptions;
402
+ } | {
403
+ type: 'file-reference';
404
+ /**
405
+ * Provider-specific references for the file.
406
+ * The key is the provider name, e.g. 'openai' or 'anthropic'.
407
+ */
408
+ providerReference: ProviderReference;
409
+ /**
410
+ * Provider-specific options.
411
+ */
412
+ providerOptions?: ProviderOptions;
874
413
  } | {
875
414
  /**
876
- * Images that are referenced using base64 encoded data.
415
+ * @deprecated Use file-data instead.
877
416
  */
878
417
  type: 'image-data';
879
418
  /**
@@ -891,7 +430,7 @@ type ToolResultOutput = {
891
430
  providerOptions?: ProviderOptions;
892
431
  } | {
893
432
  /**
894
- * Images that are referenced using a URL.
433
+ * @deprecated Use file-url instead.
895
434
  */
896
435
  type: 'image-url';
897
436
  /**
@@ -904,7 +443,7 @@ type ToolResultOutput = {
904
443
  providerOptions?: ProviderOptions;
905
444
  } | {
906
445
  /**
907
- * Images that are referenced using a provider file id.
446
+ * @deprecated Use file-reference instead.
908
447
  */
909
448
  type: 'image-file-id';
910
449
  /**
@@ -920,6 +459,20 @@ type ToolResultOutput = {
920
459
  * Provider-specific options.
921
460
  */
922
461
  providerOptions?: ProviderOptions;
462
+ } | {
463
+ /**
464
+ * @deprecated Use file-reference instead.
465
+ */
466
+ type: 'image-file-reference';
467
+ /**
468
+ * Provider-specific references for the image file.
469
+ * The key is the provider name, e.g. 'openai' or 'anthropic'.
470
+ */
471
+ providerReference: ProviderReference;
472
+ /**
473
+ * Provider-specific options.
474
+ */
475
+ providerOptions?: ProviderOptions;
923
476
  } | {
924
477
  /**
925
478
  * Custom content part. This can be used to implement
@@ -933,6 +486,630 @@ type ToolResultOutput = {
933
486
  }>;
934
487
  };
935
488
 
489
+ type InlineFileData = Extract<FilePart['data'], {
490
+ type: 'data';
491
+ } | {
492
+ type: 'text';
493
+ }>;
494
+ /**
495
+ * Converts inline file data (a tagged `data` or `text` shape) into raw bytes.
496
+ *
497
+ * - `{ type: 'text', text }` → UTF-8 encoded bytes
498
+ * - `{ type: 'data', data: Uint8Array | Buffer }` → returned as-is
499
+ * - `{ type: 'data', data: ArrayBuffer }` → wrapped in a `Uint8Array`
500
+ * - `{ type: 'data', data: string }` → decoded as base64
501
+ */
502
+ declare function convertInlineFileDataToUint8Array(data: InlineFileData): Uint8Array;
503
+
504
+ /**
505
+ * Convert an ImageModelV4File to a URL or data URI string.
506
+ *
507
+ * If the file is a URL, it returns the URL as-is.
508
+ * If the file is base64 data, it returns a data URI with the base64 data.
509
+ * If the file is a Uint8Array, it converts it to base64 and returns a data URI.
510
+ */
511
+ declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
512
+
513
+ /**
514
+ * Converts an input object to FormData for multipart/form-data requests.
515
+ *
516
+ * Handles the following cases:
517
+ * - `null` or `undefined` values are skipped
518
+ * - Arrays with a single element are appended as a single value
519
+ * - Arrays with multiple elements are appended with `[]` suffix (e.g., `image[]`)
520
+ * unless `useArrayBrackets` is set to `false`
521
+ * - All other values are appended directly
522
+ *
523
+ * @param input - The input object to convert. Use a generic type for type validation.
524
+ * @param options - Optional configuration object.
525
+ * @param options.useArrayBrackets - Whether to add `[]` suffix for multi-element arrays.
526
+ * Defaults to `true`. Set to `false` for APIs that expect repeated keys without brackets.
527
+ * @returns A FormData object containing the input values.
528
+ *
529
+ * @example
530
+ * ```ts
531
+ * type MyInput = {
532
+ * model: string;
533
+ * prompt: string;
534
+ * images: Blob[];
535
+ * };
536
+ *
537
+ * const formData = convertToFormData<MyInput>({
538
+ * model: 'gpt-image-1',
539
+ * prompt: 'A cat',
540
+ * images: [blob1, blob2],
541
+ * });
542
+ * ```
543
+ */
544
+ declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
545
+ useArrayBrackets?: boolean;
546
+ }): FormData;
547
+
548
+ /**
549
+ * Interface for mapping between custom tool names and provider tool names.
550
+ */
551
+ interface ToolNameMapping {
552
+ /**
553
+ * Maps a custom tool name (used by the client) to the provider's tool name.
554
+ * If the custom tool name does not have a mapping, returns the input name.
555
+ *
556
+ * @param customToolName - The custom name of the tool defined by the client.
557
+ * @returns The corresponding provider tool name, or the input name if not mapped.
558
+ */
559
+ toProviderToolName: (customToolName: string) => string;
560
+ /**
561
+ * Maps a provider tool name to the custom tool name used by the client.
562
+ * If the provider tool name does not have a mapping, returns the input name.
563
+ *
564
+ * @param providerToolName - The name of the tool as understood by the provider.
565
+ * @returns The corresponding custom tool name, or the input name if not mapped.
566
+ */
567
+ toCustomToolName: (providerToolName: string) => string;
568
+ }
569
+ /**
570
+ * @param tools - Tools that were passed to the language model.
571
+ * @param providerToolNames - Maps the provider tool ids to the provider tool names.
572
+ */
573
+ declare function createToolNameMapping({ tools, providerToolNames, }: {
574
+ /**
575
+ * Tools that were passed to the language model.
576
+ */
577
+ tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
578
+ /**
579
+ * Maps the provider tool ids to the provider tool names.
580
+ */
581
+ providerToolNames: Record<`${string}.${string}`, string>;
582
+ }): ToolNameMapping;
583
+
584
+ /**
585
+ * Creates a Promise that resolves after a specified delay
586
+ * @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
587
+ * @param signal - Optional AbortSignal to cancel the delay
588
+ * @returns A Promise that resolves after the specified delay
589
+ * @throws {DOMException} When the signal is aborted
590
+ */
591
+ declare function delay(delayInMs?: number | null, options?: {
592
+ abortSignal?: AbortSignal;
593
+ }): Promise<void>;
594
+
595
+ /**
596
+ * Delayed promise. It is only constructed once the value is accessed.
597
+ * This is useful to avoid unhandled promise rejections when the promise is created
598
+ * but not accessed.
599
+ */
600
+ declare class DelayedPromise<T> {
601
+ private status;
602
+ private _promise;
603
+ private _resolve;
604
+ private _reject;
605
+ get promise(): Promise<T>;
606
+ resolve(value: T): void;
607
+ reject(error: unknown): void;
608
+ isResolved(): boolean;
609
+ isRejected(): boolean;
610
+ isPending(): boolean;
611
+ }
612
+
613
+ /**
614
+ * Detect the IANA media type of a file from its raw bytes or base64 string.
615
+ *
616
+ * - When `topLevelType` is omitted, every known signature is considered
617
+ * (image, audio, video, and application). Returns `undefined` when the
618
+ * bytes do not match any known signature.
619
+ * - When `topLevelType` is provided, only signatures for that top-level
620
+ * segment are considered. Returns `undefined` for unsupported segments
621
+ * (e.g. `"text"`) or when no signature matches.
622
+ */
623
+ declare function detectMediaType({ data, topLevelType, }: {
624
+ data: Uint8Array | string;
625
+ topLevelType?: string;
626
+ }): string | undefined;
627
+ /**
628
+ * Returns the top-level segment of a media type (the portion before `/`).
629
+ *
630
+ * Examples:
631
+ * - `"image/png"` -> `"image"`
632
+ * - `"image/*"` -> `"image"`
633
+ * - `"image"` -> `"image"`
634
+ * - `"image/"` -> `"image"`
635
+ * - `""` -> `""`
636
+ * - `"/"` -> `""`
637
+ */
638
+ declare function getTopLevelMediaType(mediaType: string): string;
639
+ /**
640
+ * Returns `true` only when the given media type has a non-empty, non-wildcard
641
+ * subtype (i.e. matches the form `type/subtype`, and `subtype` is not `*`).
642
+ *
643
+ * Examples:
644
+ * - `"image/png"` -> `true`
645
+ * - `"image/*"` -> `false`
646
+ * - `"image"` -> `false`
647
+ * - `"image/"` -> `false`
648
+ * - `""` -> `false`
649
+ * - `"/"` -> `false`
650
+ */
651
+ declare function isFullMediaType(mediaType: string): boolean;
652
+
653
+ /**
654
+ * Download a file from a URL and return it as a Blob.
655
+ *
656
+ * @param url - The URL to download from.
657
+ * @param options - Optional settings for the download.
658
+ * @param options.maxBytes - Maximum allowed download size in bytes. Defaults to 100 MiB.
659
+ * @param options.abortSignal - An optional abort signal to cancel the download.
660
+ * @returns A Promise that resolves to the downloaded Blob.
661
+ *
662
+ * @throws DownloadError if the download fails or exceeds maxBytes.
663
+ */
664
+ declare function downloadBlob(url: string, options?: {
665
+ maxBytes?: number;
666
+ abortSignal?: AbortSignal;
667
+ }): Promise<Blob>;
668
+
669
+ declare const symbol: unique symbol;
670
+ declare class DownloadError extends AISDKError {
671
+ private readonly [symbol];
672
+ readonly url: string;
673
+ readonly statusCode?: number;
674
+ readonly statusText?: string;
675
+ constructor({ url, statusCode, statusText, cause, message, }: {
676
+ url: string;
677
+ statusCode?: number;
678
+ statusText?: string;
679
+ message?: string;
680
+ cause?: unknown;
681
+ });
682
+ static isInstance(error: unknown): error is DownloadError;
683
+ }
684
+
685
+ /**
686
+ * Extracts the headers from a response object and returns them as a key-value object.
687
+ *
688
+ * @param response - The response object to extract headers from.
689
+ * @returns The headers as a key-value object.
690
+ */
691
+ declare function extractResponseHeaders(response: Response): {
692
+ [k: string]: string;
693
+ };
694
+
695
+ /**
696
+ * Fetch function type (standardizes the version of fetch used).
697
+ */
698
+ type FetchFunction = typeof globalThis.fetch;
699
+
700
+ /**
701
+ * Filters `null` and `undefined` values out of a list of values.
702
+ *
703
+ * @param values - The values to filter.
704
+ * @returns A new array containing only non-nullish values.
705
+ */
706
+ declare function filterNullable<T>(...values: Array<T | undefined | null>): Array<T>;
707
+
708
+ /**
709
+ * Creates an ID generator.
710
+ * The total length of the ID is the sum of the prefix, separator, and random part length.
711
+ * Not cryptographically secure.
712
+ *
713
+ * @param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
714
+ * @param prefix - The prefix of the ID to generate. Optional.
715
+ * @param separator - The separator between the prefix and the random part of the ID. Default: '-'.
716
+ * @param size - The size of the random part of the ID to generate. Default: 16.
717
+ */
718
+ declare const createIdGenerator: ({ prefix, size, alphabet, separator, }?: {
719
+ prefix?: string;
720
+ separator?: string;
721
+ size?: number;
722
+ alphabet?: string;
723
+ }) => IdGenerator;
724
+ /**
725
+ * A function that generates an ID.
726
+ */
727
+ type IdGenerator = () => string;
728
+ /**
729
+ * Generates a 16-character random string to use for IDs.
730
+ * Not cryptographically secure.
731
+ */
732
+ declare const generateId: IdGenerator;
733
+
734
+ /**
735
+ * Used to mark schemas so we can support both Zod and custom schemas.
736
+ */
737
+ declare const schemaSymbol: unique symbol;
738
+ type ValidationResult<OBJECT> = {
739
+ success: true;
740
+ value: OBJECT;
741
+ } | {
742
+ success: false;
743
+ error: Error;
744
+ };
745
+ type Schema<OBJECT = unknown> = {
746
+ /**
747
+ * Used to mark schemas so we can support both Zod and custom schemas.
748
+ */
749
+ [schemaSymbol]: true;
750
+ /**
751
+ * Schema type for inference.
752
+ */
753
+ _type: OBJECT;
754
+ /**
755
+ * Optional. Validates that the structure of a value matches this schema,
756
+ * and returns a typed version of the value if it does.
757
+ */
758
+ readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
759
+ /**
760
+ * The JSON Schema for the schema. It is passed to the providers.
761
+ */
762
+ readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
763
+ };
764
+ /**
765
+ * Creates a schema with deferred creation.
766
+ * This is important to reduce the startup time of the library
767
+ * and to avoid initializing unused validators.
768
+ *
769
+ * @param createValidator A function that creates a schema.
770
+ * @returns A function that returns a schema.
771
+ */
772
+ declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
773
+ type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
774
+ type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | z4.core.$ZodType<SCHEMA, any>;
775
+ type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & StandardJSONSchemaV1<unknown, SCHEMA>;
776
+ type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
777
+ type InferSchema<SCHEMA> = SCHEMA extends ZodSchema<infer T> ? T : SCHEMA extends StandardSchema<infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
778
+ /**
779
+ * Create a schema using a JSON Schema.
780
+ *
781
+ * @param jsonSchema The JSON Schema for the schema.
782
+ * @param options.validate Optional. A validation function for the schema.
783
+ */
784
+ declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
785
+ validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
786
+ }): Schema<OBJECT>;
787
+ declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
788
+ declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
789
+ /**
790
+ * Enables support for references in the schema.
791
+ * This is required for recursive schemas, e.g. with `z.lazy`.
792
+ * However, not all language models and providers support such references.
793
+ * Defaults to `false`.
794
+ */
795
+ useReferences?: boolean;
796
+ }): Schema<OBJECT>;
797
+
798
+ /**
799
+ * Parses a JSON string into an unknown object.
800
+ *
801
+ * @param text - The JSON string to parse.
802
+ * @returns {JSONValue} - The parsed JSON object.
803
+ */
804
+ declare function parseJSON(options: {
805
+ text: string;
806
+ schema?: undefined;
807
+ }): Promise<JSONValue>;
808
+ /**
809
+ * Parses a JSON string into a strongly-typed object using the provided schema.
810
+ *
811
+ * @template T - The type of the object to parse the JSON into.
812
+ * @param {string} text - The JSON string to parse.
813
+ * @param {Validator<T>} schema - The schema to use for parsing the JSON.
814
+ * @returns {Promise<T>} - The parsed object.
815
+ */
816
+ declare function parseJSON<T>(options: {
817
+ text: string;
818
+ schema: FlexibleSchema<T>;
819
+ }): Promise<T>;
820
+ type ParseResult<T> = {
821
+ success: true;
822
+ value: T;
823
+ rawValue: unknown;
824
+ } | {
825
+ success: false;
826
+ error: JSONParseError | TypeValidationError;
827
+ rawValue: unknown;
828
+ };
829
+ /**
830
+ * Safely parses a JSON string and returns the result as an object of type `unknown`.
831
+ *
832
+ * @param text - The JSON string to parse.
833
+ * @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
834
+ */
835
+ declare function safeParseJSON(options: {
836
+ text: string;
837
+ schema?: undefined;
838
+ }): Promise<ParseResult<JSONValue>>;
839
+ /**
840
+ * Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
841
+ *
842
+ * @template T - The type of the object to parse the JSON into.
843
+ * @param {string} text - The JSON string to parse.
844
+ * @param {Validator<T>} schema - The schema to use for parsing the JSON.
845
+ * @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
846
+ */
847
+ declare function safeParseJSON<T>(options: {
848
+ text: string;
849
+ schema: FlexibleSchema<T>;
850
+ }): Promise<ParseResult<T>>;
851
+ declare function isParsableJson(input: string): boolean;
852
+
853
+ type ResponseHandler<RETURN_TYPE> = (options: {
854
+ url: string;
855
+ requestBodyValues: unknown;
856
+ response: Response;
857
+ }) => PromiseLike<{
858
+ value: RETURN_TYPE;
859
+ rawValue?: unknown;
860
+ responseHeaders?: Record<string, string>;
861
+ }>;
862
+ declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
863
+ errorSchema: FlexibleSchema<T>;
864
+ errorToMessage: (error: T) => string;
865
+ isRetryable?: (response: Response, error?: T) => boolean;
866
+ }) => ResponseHandler<APICallError>;
867
+ declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
868
+ declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
869
+ declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
870
+ declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
871
+
872
+ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
873
+ url: string;
874
+ headers?: Record<string, string | undefined>;
875
+ failedResponseHandler: ResponseHandler<Error>;
876
+ successfulResponseHandler: ResponseHandler<T>;
877
+ abortSignal?: AbortSignal;
878
+ fetch?: FetchFunction;
879
+ }) => Promise<{
880
+ value: T;
881
+ rawValue?: unknown;
882
+ responseHeaders?: Record<string, string>;
883
+ }>;
884
+
885
+ declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
886
+
887
+ /**
888
+ * Checks if an object has required keys.
889
+ * @param OBJECT - The object to check.
890
+ * @returns True if the object has required keys, false otherwise.
891
+ */
892
+ type HasRequiredKey<OBJECT> = {} extends OBJECT ? false : true;
893
+
894
+ declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
895
+ messages: LanguageModelV4Prompt;
896
+ schema?: JSONSchema7;
897
+ schemaPrefix?: string;
898
+ schemaSuffix?: string;
899
+ }): LanguageModelV4Prompt;
900
+
901
+ declare function isAbortError(error: unknown): error is Error;
902
+
903
+ /**
904
+ * Type-guard for Node.js `Buffer` instances.
905
+ *
906
+ * Uses optional chaining on `globalThis.Buffer` so it returns `false` in
907
+ * runtimes where `Buffer` is not available (e.g. CloudFlare Workers).
908
+ */
909
+ declare function isBuffer(value: unknown): value is Buffer;
910
+
911
+ /**
912
+ * Type guard that checks whether a value is not `null` or `undefined`.
913
+ *
914
+ * @template T - The type of the value to check.
915
+ * @param value - The value to check.
916
+ * @returns `true` if the value is neither `null` nor `undefined`, otherwise `false`.
917
+ */
918
+ declare function isNonNullable<T>(value: T | undefined | null): value is NonNullable<T>;
919
+
920
+ /**
921
+ * Checks whether a value is a provider reference (a mapping of provider names
922
+ * to provider-specific identifiers) as opposed to raw bytes, a URL, or a
923
+ * tagged `{ type: ... }` object.
924
+ */
925
+ declare function isProviderReference(data: unknown): data is SharedV4ProviderReference;
926
+
927
+ /**
928
+ * Checks if the given URL is supported natively by the model.
929
+ *
930
+ * @param mediaType - The media type of the URL. Case-sensitive. May be a full
931
+ * `type/subtype`, a wildcard `type/*`, or just the
932
+ * top-level segment (e.g. `image`).
933
+ * @param url - The URL to check.
934
+ * @param supportedUrls - A record where keys are case-sensitive media types (or '*')
935
+ * and values are arrays of RegExp patterns for URLs.
936
+ *
937
+ * @returns `true` if the URL matches a pattern under the specific media type
938
+ * or the wildcard '*', `false` otherwise.
939
+ */
940
+ declare function isUrlSupported({ mediaType, url, supportedUrls, }: {
941
+ mediaType: string;
942
+ url: string;
943
+ supportedUrls: Record<string, RegExp[]>;
944
+ }): boolean;
945
+
946
+ declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
947
+ apiKey: string | undefined;
948
+ environmentVariableName: string;
949
+ apiKeyParameterName?: string;
950
+ description: string;
951
+ }): string;
952
+
953
+ /**
954
+ * Loads an optional `string` setting from the environment or a parameter.
955
+ *
956
+ * @param settingValue - The setting value.
957
+ * @param environmentVariableName - The environment variable name.
958
+ * @returns The setting value.
959
+ */
960
+ declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
961
+ settingValue: string | undefined;
962
+ environmentVariableName: string;
963
+ }): string | undefined;
964
+
965
+ /**
966
+ * Loads a `string` setting from the environment or a parameter.
967
+ *
968
+ * @param settingValue - The setting value.
969
+ * @param environmentVariableName - The environment variable name.
970
+ * @param settingName - The setting name.
971
+ * @param description - The description of the setting.
972
+ * @returns The setting value.
973
+ */
974
+ declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
975
+ settingValue: string | undefined;
976
+ environmentVariableName: string;
977
+ settingName: string;
978
+ description: string;
979
+ }): string;
980
+
981
+ type ReasoningLevel = Exclude<LanguageModelV4CallOptions['reasoning'], 'none' | 'provider-default' | undefined>;
982
+ declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
983
+ /**
984
+ * Maps a top-level reasoning level to a provider-specific effort string using
985
+ * the given effort map. Pushes a compatibility warning if the reasoning level
986
+ * maps to a different string, or an unsupported warning if the level is not
987
+ * present in the map.
988
+ *
989
+ * @returns The mapped effort string, or `undefined` if the level is not
990
+ * supported.
991
+ */
992
+ declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings, }: {
993
+ reasoning: ReasoningLevel;
994
+ effortMap: Partial<Record<ReasoningLevel, T>>;
995
+ warnings: SharedV4Warning[];
996
+ }): T | undefined;
997
+ /**
998
+ * Maps a top-level reasoning level to an absolute token budget by multiplying
999
+ * the model's max output tokens by a percentage from the budget percentages
1000
+ * map. The result is clamped between `minReasoningBudget` (default 1024) and
1001
+ * `maxReasoningBudget`. Pushes an unsupported warning if the level is not
1002
+ * present in the budget percentages map.
1003
+ *
1004
+ * @returns The computed token budget, or `undefined` if the level is not
1005
+ * supported.
1006
+ */
1007
+ declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings, }: {
1008
+ reasoning: ReasoningLevel;
1009
+ maxOutputTokens: number;
1010
+ maxReasoningBudget: number;
1011
+ minReasoningBudget?: number;
1012
+ budgetPercentages?: Partial<Record<ReasoningLevel, number>>;
1013
+ warnings: SharedV4Warning[];
1014
+ }): number | undefined;
1015
+
1016
+ /**
1017
+ * A value that can be provided either synchronously or as a promise-like.
1018
+ */
1019
+ type MaybePromiseLike<T> = T | PromiseLike<T>;
1020
+
1021
+ /**
1022
+ * Maps a media type to its corresponding file extension.
1023
+ * It was originally introduced to set a filename for audio file uploads
1024
+ * in https://github.com/vercel/ai/pull/8159.
1025
+ *
1026
+ * @param mediaType The media type to map.
1027
+ * @returns The corresponding file extension
1028
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
1029
+ */
1030
+ declare function mediaTypeToExtension(mediaType: string): string;
1031
+
1032
+ /**
1033
+ * Normalizes different header inputs into a plain record with lower-case keys.
1034
+ * Entries with `undefined` or `null` values are removed.
1035
+ *
1036
+ * @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
1037
+ * @returns A record containing the normalized header entries.
1038
+ */
1039
+ declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
1040
+
1041
+ /**
1042
+ * Parses a JSON event stream into a stream of parsed JSON objects.
1043
+ */
1044
+ declare function parseJsonEventStream<T>({ stream, schema, }: {
1045
+ stream: ReadableStream<Uint8Array>;
1046
+ schema: FlexibleSchema<T>;
1047
+ }): ReadableStream<ParseResult<T>>;
1048
+
1049
+ declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
1050
+ provider: string;
1051
+ providerOptions: Record<string, unknown> | undefined;
1052
+ schema: FlexibleSchema<OPTIONS>;
1053
+ }): Promise<OPTIONS | undefined>;
1054
+
1055
+ declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
1056
+ url: string;
1057
+ headers?: Record<string, string | undefined>;
1058
+ body: unknown;
1059
+ failedResponseHandler: ResponseHandler<APICallError>;
1060
+ successfulResponseHandler: ResponseHandler<T>;
1061
+ abortSignal?: AbortSignal;
1062
+ fetch?: FetchFunction;
1063
+ }) => Promise<{
1064
+ value: T;
1065
+ rawValue?: unknown;
1066
+ responseHeaders?: Record<string, string>;
1067
+ }>;
1068
+ declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
1069
+ url: string;
1070
+ headers?: Record<string, string | undefined>;
1071
+ formData: FormData;
1072
+ failedResponseHandler: ResponseHandler<APICallError>;
1073
+ successfulResponseHandler: ResponseHandler<T>;
1074
+ abortSignal?: AbortSignal;
1075
+ fetch?: FetchFunction;
1076
+ }) => Promise<{
1077
+ value: T;
1078
+ rawValue?: unknown;
1079
+ responseHeaders?: Record<string, string>;
1080
+ }>;
1081
+ declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
1082
+ url: string;
1083
+ headers?: Record<string, string | undefined>;
1084
+ body: {
1085
+ content: string | FormData | Uint8Array;
1086
+ values: unknown;
1087
+ };
1088
+ failedResponseHandler: ResponseHandler<Error>;
1089
+ successfulResponseHandler: ResponseHandler<T>;
1090
+ abortSignal?: AbortSignal;
1091
+ fetch?: FetchFunction;
1092
+ }) => Promise<{
1093
+ value: T;
1094
+ rawValue?: unknown;
1095
+ responseHeaders?: Record<string, string>;
1096
+ }>;
1097
+
1098
+ /**
1099
+ * A context object that is passed into tool execution.
1100
+ */
1101
+ type Context = Record<string, unknown>;
1102
+
1103
+ type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
1104
+
1105
+ /**
1106
+ * Top-level context properties that contain sensitive data and should be
1107
+ * excluded from telemetry.
1108
+ */
1109
+ type SensitiveContext<CONTEXT extends Context | unknown | never> = {
1110
+ [KEY in keyof CONTEXT]?: boolean;
1111
+ } | undefined;
1112
+
936
1113
  /**
937
1114
  * Tool approval request prompt part.
938
1115
  */
@@ -946,6 +1123,12 @@ type ToolApprovalRequest = {
946
1123
  * ID of the tool call that the approval request is for.
947
1124
  */
948
1125
  toolCallId: string;
1126
+ /**
1127
+ * Flag indicating whether the tool was automatically approved or denied.
1128
+ *
1129
+ * @default false
1130
+ */
1131
+ isAutomatic?: boolean;
949
1132
  };
950
1133
 
951
1134
  /**
@@ -1051,15 +1234,10 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
1051
1234
  */
1052
1235
  type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
1053
1236
 
1054
- /**
1055
- * A context object that is passed into tool execution.
1056
- */
1057
- type Context = Record<string, unknown>;
1058
-
1059
1237
  /**
1060
1238
  * Additional options that are sent into each tool execution.
1061
1239
  */
1062
- interface ToolExecutionOptions<CONTEXT extends Context> {
1240
+ interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
1063
1241
  /**
1064
1242
  * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
1065
1243
  */
@@ -1074,7 +1252,8 @@ interface ToolExecutionOptions<CONTEXT extends Context> {
1074
1252
  */
1075
1253
  abortSignal?: AbortSignal;
1076
1254
  /**
1077
- * User-defined context.
1255
+ * Tool context as defined by the tool's context schema.
1256
+ * The tool context is specific to the tool and is passed to the tool execution.
1078
1257
  *
1079
1258
  * Treat the context object as immutable inside tools.
1080
1259
  * Mutating the context object can lead to race conditions and unexpected results
@@ -1082,15 +1261,20 @@ interface ToolExecutionOptions<CONTEXT extends Context> {
1082
1261
  *
1083
1262
  * If you need to mutate the context, analyze the tool calls and results
1084
1263
  * in `prepareStep` and update it there.
1085
- *
1086
- * Experimental (can break in patch releases).
1087
1264
  */
1088
- experimental_context: CONTEXT;
1265
+ context: CONTEXT;
1089
1266
  }
1267
+ /**
1268
+ * Function that executes the tool and returns either a single result or a stream of results.
1269
+ */
1270
+ type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
1271
+
1090
1272
  /**
1091
1273
  * Function that is called to determine if the tool needs approval before it can be executed.
1274
+ *
1275
+ * @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
1092
1276
  */
1093
- type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT, options: {
1277
+ type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: {
1094
1278
  /**
1095
1279
  * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
1096
1280
  */
@@ -1101,21 +1285,29 @@ type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT,
1101
1285
  */
1102
1286
  messages: ModelMessage[];
1103
1287
  /**
1104
- * Additional context.
1288
+ * Tool context as defined by the tool's context schema.
1289
+ * The tool context is specific to the tool and is passed to the tool execution.
1290
+ *
1291
+ * Treat the context object as immutable inside tools.
1292
+ * Mutating the context object can lead to race conditions and unexpected results
1293
+ * when tools are called in parallel.
1105
1294
  *
1106
- * Experimental (can break in patch releases).
1295
+ * If you need to mutate the context, analyze the tool calls and results
1296
+ * in `prepareStep` and update it there.
1107
1297
  */
1108
- experimental_context: CONTEXT;
1298
+ context: CONTEXT;
1109
1299
  }) => boolean | PromiseLike<boolean>;
1300
+
1110
1301
  /**
1111
- * Function that executes the tool and returns either a single result or a stream of results.
1112
- */
1113
- type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
1114
- type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
1115
- /**
1116
- * Helper type to determine the output properties of a tool.
1302
+ * Helper type to determine the outputSchema and execute function properties of a tool.
1117
1303
  */
1118
- type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptional<OUTPUT, {
1304
+ type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = NeverOptional<OUTPUT, {
1305
+ /**
1306
+ * The optional schema of the output that the tool produces.
1307
+ *
1308
+ * If not provided, the output shape will be inferred from the execute function.
1309
+ */
1310
+ outputSchema?: FlexibleSchema<OUTPUT>;
1119
1311
  /**
1120
1312
  * An async function that is called with the arguments from the tool call and produces a result.
1121
1313
  * If not provided, the tool will not be executed automatically.
@@ -1124,24 +1316,19 @@ type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptiona
1124
1316
  * @options.abortSignal is a signal that can be used to abort the tool call.
1125
1317
  */
1126
1318
  execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
1127
- outputSchema?: FlexibleSchema<OUTPUT>;
1128
1319
  } | {
1320
+ /**
1321
+ * The schema of the output that the tool produces.
1322
+ *
1323
+ * Required when no execute function is provided.
1324
+ */
1129
1325
  outputSchema: FlexibleSchema<OUTPUT>;
1130
1326
  execute?: never;
1131
1327
  }>;
1132
1328
  /**
1133
- * A tool contains the description and the schema of the input that the tool expects.
1134
- * This enables the language model to generate the input.
1135
- *
1136
- * The tool can also contain an optional execute function for the actual execution function of the tool.
1329
+ * Common properties shared by all tool kinds.
1137
1330
  */
1138
- type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context = Context> = {
1139
- /**
1140
- * An optional description of what the tool does.
1141
- * Will be used by the language model to decide whether to use the tool.
1142
- * Not used for provider-defined tools.
1143
- */
1144
- description?: string;
1331
+ type BaseTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = {
1145
1332
  /**
1146
1333
  * An optional title of the tool.
1147
1334
  */
@@ -1152,6 +1339,16 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1152
1339
  * functionality that can be fully encapsulated in the provider.
1153
1340
  */
1154
1341
  providerOptions?: ProviderOptions;
1342
+ /**
1343
+ * Optional metadata about the tool itself (e.g. its source).
1344
+ *
1345
+ * Unlike `providerOptions`, this metadata is not sent to the language
1346
+ * model. Instead, it is propagated onto the resulting tool call's
1347
+ * `providerMetadata` so consumers can read it from tool call / result
1348
+ * parts and UI message parts. This is useful for sources of dynamic
1349
+ * tools (e.g. an MCP server) to identify themselves.
1350
+ */
1351
+ providerMetadata?: SharedV4ProviderMetadata;
1155
1352
  /**
1156
1353
  * The schema of the input that the tool expects.
1157
1354
  * The language model will use this to generate the input.
@@ -1160,33 +1357,25 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1160
1357
  * You can use descriptions on the schema properties to make the input understandable for the language model.
1161
1358
  */
1162
1359
  inputSchema: FlexibleSchema<INPUT>;
1163
- /**
1164
- * An optional list of input examples that show the language
1165
- * model what the input should look like.
1166
- */
1167
- inputExamples?: Array<{
1168
- input: NoInfer<INPUT>;
1169
- }>;
1170
1360
  /**
1171
1361
  * An optional schema describing the context that the tool expects.
1172
1362
  *
1173
1363
  * The context is passed to execute function as part of the execution options.
1174
1364
  */
1175
1365
  contextSchema?: FlexibleSchema<CONTEXT>;
1366
+ /**
1367
+ * Marks top-level context properties that contain sensitive data and should be excluded from telemetry.
1368
+ * Properties marked as `true` are omitted from telemetry integrations.
1369
+ */
1370
+ sensitiveContext?: SensitiveContext<CONTEXT>;
1176
1371
  /**
1177
1372
  * Whether the tool needs approval before it can be executed.
1373
+ *
1374
+ * @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
1178
1375
  */
1179
1376
  needsApproval?: boolean | ToolNeedsApprovalFunction<[
1180
1377
  INPUT
1181
1378
  ] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
1182
- /**
1183
- * Strict mode setting for the tool.
1184
- *
1185
- * Providers that support strict mode will use this setting to determine
1186
- * how the input should be generated. Strict mode will always produce
1187
- * valid inputs, but it might limit what input schemas are supported.
1188
- */
1189
- strict?: boolean;
1190
1379
  /**
1191
1380
  * Optional function that is called when the argument streaming starts.
1192
1381
  * Only called when the tool is used in a streaming context.
@@ -1206,7 +1395,6 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1206
1395
  onInputAvailable?: (options: {
1207
1396
  input: [INPUT] extends [never] ? unknown : INPUT;
1208
1397
  } & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
1209
- } & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>> & {
1210
1398
  /**
1211
1399
  * Optional conversion function that maps the tool result to an output that can be used by the language model.
1212
1400
  *
@@ -1228,21 +1416,53 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1228
1416
  */
1229
1417
  output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
1230
1418
  }) => ToolResultOutput | PromiseLike<ToolResultOutput>;
1231
- } & ({
1419
+ } & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>>;
1420
+ /**
1421
+ * Common properties shared by function-style tools.
1422
+ */
1423
+ type BaseFunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
1232
1424
  /**
1233
- * Tool with user-defined input and output schemas.
1425
+ * An optional description of what the tool does.
1426
+ * Will be used by the language model to decide whether to use the tool.
1234
1427
  */
1235
- type?: undefined | 'function';
1236
- } | {
1428
+ description?: string;
1237
1429
  /**
1238
- * Tool that is defined at runtime (e.g. an MCP tool).
1239
- * The types of input and output are not known at development time.
1430
+ * Strict mode setting for the tool.
1431
+ *
1432
+ * Providers that support strict mode will use this setting to determine
1433
+ * how the input should be generated. Strict mode will always produce
1434
+ * valid inputs, but it might limit what input schemas are supported.
1240
1435
  */
1241
- type: 'dynamic';
1242
- } | {
1436
+ strict?: boolean;
1243
1437
  /**
1244
- * Tool with provider-defined input and output schemas.
1438
+ * An optional list of input examples that show the language
1439
+ * model what the input should look like.
1245
1440
  */
1441
+ inputExamples?: Array<{
1442
+ input: NoInfer<INPUT>;
1443
+ }>;
1444
+ id?: never;
1445
+ isProviderExecuted?: never;
1446
+ args?: never;
1447
+ supportsDeferredResults?: never;
1448
+ };
1449
+ /**
1450
+ * Tool with user-defined input and output schemas.
1451
+ */
1452
+ type FunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
1453
+ type?: undefined | 'function';
1454
+ };
1455
+ /**
1456
+ * Tool that is defined at runtime (e.g. an MCP tool).
1457
+ * The types of input and output are not known at development time.
1458
+ */
1459
+ type DynamicTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
1460
+ type: 'dynamic';
1461
+ };
1462
+ /**
1463
+ * Common properties shared by provider tools.
1464
+ */
1465
+ type BaseProviderTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
1246
1466
  type: 'provider';
1247
1467
  /**
1248
1468
  * The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
@@ -1252,6 +1472,30 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1252
1472
  * The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
1253
1473
  */
1254
1474
  args: Record<string, unknown>;
1475
+ description?: never;
1476
+ strict?: never;
1477
+ inputExamples?: never;
1478
+ };
1479
+ /**
1480
+ * Tool with provider-defined input and output schemas that is executed by the
1481
+ * user.
1482
+ */
1483
+ type ProviderDefinedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
1484
+ /**
1485
+ * Flag that indicates whether the tool is executed by the provider.
1486
+ */
1487
+ isProviderExecuted: false;
1488
+ supportsDeferredResults?: never;
1489
+ };
1490
+ /**
1491
+ * Tool with provider-defined input and output schemas that is executed by the
1492
+ * provider.
1493
+ */
1494
+ type ProviderExecutedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
1495
+ /**
1496
+ * Flag that indicates whether the tool is executed by the provider.
1497
+ */
1498
+ isProviderExecuted: true;
1255
1499
  /**
1256
1500
  * Whether this provider-executed tool supports deferred results.
1257
1501
  *
@@ -1266,71 +1510,68 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1266
1510
  * @default false
1267
1511
  */
1268
1512
  supportsDeferredResults?: boolean;
1269
- });
1513
+ };
1514
+ /**
1515
+ * A tool can either be user-defined or provider-defined.
1516
+ *
1517
+ * It contains the schemas and metadata needed for the language model to call
1518
+ * the tool and can include an execute function for tools that are executed by
1519
+ * the AI SDK.
1520
+ */
1521
+ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = FunctionTool<INPUT, OUTPUT, CONTEXT> | DynamicTool<INPUT, OUTPUT, CONTEXT> | ProviderDefinedTool<INPUT, OUTPUT, CONTEXT> | ProviderExecutedTool<INPUT, OUTPUT, CONTEXT>;
1270
1522
  /**
1271
- * Helper function for inferring the execute args of a tool.
1523
+ * Infer the tool type from a tool object.
1524
+ *
1525
+ * This is useful for type inference when working with tool objects.
1272
1526
  */
1273
1527
  declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
1274
1528
  declare function tool<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
1275
1529
  declare function tool<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
1276
1530
  declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
1277
1531
  /**
1278
- * Defines a dynamic tool.
1532
+ * Define a dynamic tool.
1279
1533
  */
1280
- declare function dynamicTool(tool: {
1281
- description?: string;
1282
- title?: string;
1283
- providerOptions?: ProviderOptions;
1284
- inputSchema: FlexibleSchema<unknown>;
1285
- execute: ToolExecuteFunction<unknown, unknown, Context>;
1286
- /**
1287
- * Optional conversion function that maps the tool result to an output that can be used by the language model.
1288
- *
1289
- * If not provided, the tool result will be sent as a JSON object.
1290
- */
1291
- toModelOutput?: (options: {
1292
- /**
1293
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
1294
- */
1295
- toolCallId: string;
1296
- /**
1297
- * The input of the tool call.
1298
- */
1299
- input: unknown;
1300
- /**
1301
- * The output of the tool call.
1302
- */
1303
- output: unknown;
1304
- }) => ToolResultOutput | PromiseLike<ToolResultOutput>;
1305
- /**
1306
- * Whether the tool needs approval before it can be executed.
1307
- */
1308
- needsApproval?: boolean | ToolNeedsApprovalFunction<unknown, Context>;
1309
- }): Tool<unknown, unknown, Context> & {
1310
- type: 'dynamic';
1311
- };
1534
+ declare function dynamicTool(tool: Omit<DynamicTool<unknown, unknown, Context>, 'type'>): DynamicTool<unknown, unknown, Context>;
1312
1535
 
1313
- type ProviderToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}> = <OUTPUT>(options: ARGS & {
1536
+ /**
1537
+ * A provider-defined tool is a tool for which the provider defines the input
1538
+ * and output schemas, but does not execute the tool.
1539
+ */
1540
+ type ProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}> = <OUTPUT>(options: ARGS & {
1314
1541
  execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
1315
1542
  needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
1316
1543
  toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
1317
1544
  onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
1318
1545
  onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
1319
1546
  onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
1320
- }) => Tool<INPUT, OUTPUT, CONTEXT>;
1321
- declare function createProviderToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
1547
+ }) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
1548
+ declare function createProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
1322
1549
  id: `${string}.${string}`;
1323
1550
  inputSchema: FlexibleSchema<INPUT>;
1324
- }): ProviderToolFactory<INPUT, ARGS, CONTEXT>;
1325
- type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
1551
+ }): ProviderDefinedToolFactory<INPUT, ARGS, CONTEXT>;
1552
+ type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
1326
1553
  execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
1327
1554
  needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
1328
1555
  toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
1329
1556
  onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
1330
1557
  onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
1331
1558
  onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
1332
- }) => Tool<INPUT, OUTPUT, CONTEXT>;
1333
- declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
1559
+ }) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
1560
+ declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, }: {
1561
+ id: `${string}.${string}`;
1562
+ inputSchema: FlexibleSchema<INPUT>;
1563
+ outputSchema: FlexibleSchema<OUTPUT>;
1564
+ }): ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS, CONTEXT>;
1565
+
1566
+ /**
1567
+ * A provider-executed tool is a tool for which the provider executes the tool.
1568
+ */
1569
+ type ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
1570
+ onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
1571
+ onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
1572
+ onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
1573
+ }) => ProviderExecutedTool<INPUT, OUTPUT, CONTEXT>;
1574
+ declare function createProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
1334
1575
  id: `${string}.${string}`;
1335
1576
  inputSchema: FlexibleSchema<INPUT>;
1336
1577
  outputSchema: FlexibleSchema<OUTPUT>;
@@ -1345,7 +1586,38 @@ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS e
1345
1586
  * @default false
1346
1587
  */
1347
1588
  supportsDeferredResults?: boolean;
1348
- }): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS, CONTEXT>;
1589
+ }): ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS, CONTEXT>;
1590
+
1591
+ /**
1592
+ * Default maximum download size: 2 GiB.
1593
+ *
1594
+ * `fetch().arrayBuffer()` has ~2x peak memory overhead (undici buffers the
1595
+ * body internally, then creates the JS ArrayBuffer), so very large downloads
1596
+ * risk exceeding the default V8 heap limit on 64-bit systems and terminating
1597
+ * the process with an out-of-memory error.
1598
+ *
1599
+ * Setting this limit converts an unrecoverable OOM crash into a catchable
1600
+ * `DownloadError`.
1601
+ */
1602
+ declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
1603
+ /**
1604
+ * Reads a fetch Response body with a size limit to prevent memory exhaustion.
1605
+ *
1606
+ * Checks the Content-Length header for early rejection, then reads the body
1607
+ * incrementally via ReadableStream and aborts with a DownloadError when the
1608
+ * limit is exceeded.
1609
+ *
1610
+ * @param response - The fetch Response to read.
1611
+ * @param url - The URL being downloaded (used in error messages).
1612
+ * @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
1613
+ * @returns A Uint8Array containing the response body.
1614
+ * @throws DownloadError if the response exceeds maxBytes.
1615
+ */
1616
+ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
1617
+ response: Response;
1618
+ url: string;
1619
+ maxBytes?: number;
1620
+ }): Promise<Uint8Array>;
1349
1621
 
1350
1622
  /**
1351
1623
  * Removes entries from a record where the value is null or undefined.
@@ -1354,6 +1626,21 @@ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS e
1354
1626
  */
1355
1627
  declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
1356
1628
 
1629
+ /**
1630
+ * A value or a lazy provider of a value, each of which may be synchronous or asynchronous.
1631
+ *
1632
+ * @template T The resolved type after {@link resolve} runs.
1633
+ *
1634
+ * One of:
1635
+ * - A plain value of type {@link T}
1636
+ * - A {@link PromiseLike} of {@link T} (e.g. a `Promise<T>`)
1637
+ * - A zero-argument function that returns a plain {@link T}
1638
+ * - A zero-argument function that returns a {@link PromiseLike} of {@link T}
1639
+ *
1640
+ * The function form is only invoked when passed to {@link resolve}; it is not distinguished from
1641
+ * a {@link T} that happens to be a function—callers should wrap function values if disambiguation
1642
+ * is required.
1643
+ */
1357
1644
  type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
1358
1645
  /**
1359
1646
  * Resolves a value that could be a raw value, a Promise, a function returning a value,
@@ -1361,6 +1648,134 @@ type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
1361
1648
  */
1362
1649
  declare function resolve<T>(value: Resolvable<T>): Promise<T>;
1363
1650
 
1651
+ /**
1652
+ * Resolves a file part's media type to a full `type/subtype` form required by
1653
+ * providers whose API demands the full IANA media type.
1654
+ *
1655
+ * - If `part.mediaType` is already a full media type (e.g. `image/png`), it is
1656
+ * returned as-is.
1657
+ * - Otherwise, when inline bytes are available (`part.data.type === 'data'`),
1658
+ * the subtype is sniffed from the bytes using the signature table that
1659
+ * corresponds to the top-level segment.
1660
+ * - When neither applies (e.g. top-level-only with a URL source, or bytes that
1661
+ * cannot be detected), an `UnsupportedFunctionalityError` is thrown.
1662
+ */
1663
+ declare function resolveFullMediaType({ part, }: {
1664
+ part: LanguageModelV4FilePart;
1665
+ }): string;
1666
+
1667
+ /**
1668
+ * Resolves a provider reference to the provider-specific identifier for the
1669
+ * given provider. Throws `NoSuchProviderReferenceError` if the provider is not
1670
+ * found in the reference mapping.
1671
+ */
1672
+ declare function resolveProviderReference({ reference, provider, }: {
1673
+ reference: SharedV4ProviderReference;
1674
+ provider: string;
1675
+ }): string;
1676
+
1677
+ /**
1678
+ * Serializes a model instance for workflow step boundaries.
1679
+ * Returns the `modelId` plus the JSON-serializable config properties.
1680
+ *
1681
+ * Non-serializable values are omitted. As a special case, a
1682
+ * function-valued `headers` property is resolved during serialization
1683
+ * and included if the returned value is JSON-serializable.
1684
+ *
1685
+ * Used as the body of `static [WORKFLOW_SERIALIZE]` in provider models.
1686
+ *
1687
+ * @example
1688
+ * ```ts
1689
+ * static [WORKFLOW_SERIALIZE](model: MyLanguageModel) {
1690
+ * return serializeModelOptions({
1691
+ * modelId: model.modelId,
1692
+ * config: model.config,
1693
+ * });
1694
+ * }
1695
+ * ```
1696
+ */
1697
+ declare function serializeModelOptions<CONFIG extends {
1698
+ headers?: Resolvable<Record<string, string | undefined>>;
1699
+ }>(options: {
1700
+ modelId: string;
1701
+ config: CONFIG;
1702
+ }): {
1703
+ modelId: string;
1704
+ config: JSONObject;
1705
+ };
1706
+
1707
+ /**
1708
+ * Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
1709
+ */
1710
+ interface StreamingToolCallDelta {
1711
+ index?: number | null;
1712
+ id?: string | null;
1713
+ type?: string | null;
1714
+ function?: {
1715
+ name?: string | null;
1716
+ arguments?: string | null;
1717
+ } | null;
1718
+ }
1719
+ interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
1720
+ /**
1721
+ * ID generator function for tool call IDs.
1722
+ * Defaults to the standard generateId.
1723
+ */
1724
+ generateId?: () => string;
1725
+ /**
1726
+ * How to validate the `type` field on new tool call deltas.
1727
+ * - `'none'`: no validation (default)
1728
+ * - `'if-present'`: throw if type is present and not `'function'`
1729
+ * - `'required'`: throw if type is not exactly `'function'`
1730
+ */
1731
+ typeValidation?: 'none' | 'if-present' | 'required';
1732
+ /**
1733
+ * Extract provider-specific metadata from a tool call delta.
1734
+ * Called once when a new tool call is detected.
1735
+ * The returned metadata is stored on the tool call and passed to
1736
+ * `buildToolCallProviderMetadata` when the tool call is finalized.
1737
+ */
1738
+ extractMetadata?: (delta: DELTA) => SharedV4ProviderMetadata | undefined;
1739
+ /**
1740
+ * Build the `providerMetadata` object for a `tool-call` event.
1741
+ * Receives the metadata previously extracted via `extractMetadata`.
1742
+ * If `undefined` is returned, no `providerMetadata` is included in the event.
1743
+ */
1744
+ buildToolCallProviderMetadata?: (metadata: SharedV4ProviderMetadata | undefined) => SharedV4ProviderMetadata | undefined;
1745
+ }
1746
+ type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV4StreamPart>, 'enqueue'>;
1747
+ /**
1748
+ * Tracks streaming tool call state across multiple deltas from an
1749
+ * OpenAI-compatible chat completion stream. Handles argument accumulation,
1750
+ * emits tool-input-start/delta/end and tool-call events, and finalizes
1751
+ * unfinished tool calls on flush.
1752
+ *
1753
+ * Used by openai, openai-compatible, groq, deepseek, and alibaba providers.
1754
+ */
1755
+ declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
1756
+ private toolCalls;
1757
+ private readonly controller;
1758
+ private readonly _generateId;
1759
+ private readonly typeValidation;
1760
+ private readonly extractMetadata?;
1761
+ private readonly buildToolCallProviderMetadata?;
1762
+ constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
1763
+ /**
1764
+ * Process a tool call delta from a streaming response chunk.
1765
+ * Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
1766
+ * events as appropriate.
1767
+ */
1768
+ processDelta(toolCallDelta: DELTA): void;
1769
+ /**
1770
+ * Finalize any unfinished tool calls. Should be called during the stream's
1771
+ * flush handler to ensure all tool calls are properly completed.
1772
+ */
1773
+ flush(): void;
1774
+ private processNewToolCall;
1775
+ private processExistingToolCall;
1776
+ private finishToolCall;
1777
+ }
1778
+
1364
1779
  /**
1365
1780
  * Strips file extension segments from a filename.
1366
1781
  *
@@ -1440,50 +1855,72 @@ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, strin
1440
1855
  declare function withoutTrailingSlash(url: string | undefined): string | undefined;
1441
1856
 
1442
1857
  /**
1443
- * Executes a tool function, supporting both synchronous and streaming/asynchronous results.
1444
- *
1445
- * This generator yields intermediate ("preliminary") outputs as they're produced, allowing callers
1446
- * to stream partial tool results before completion. When execution is finished, it yields a final output,
1447
- * ensuring all consumers receive a conclusive result.
1858
+ * A tool that is guaranteed to expose an execute function.
1859
+ */
1860
+ type ExecutableTool<TOOL extends Tool = Tool> = TOOL & {
1861
+ execute: NonNullable<TOOL['execute']>;
1862
+ };
1863
+ /**
1864
+ * Checks whether a tool exposes an execute function.
1865
+ */
1866
+ declare function isExecutableTool<TOOL extends Tool>(tool: TOOL | undefined): tool is ExecutableTool<TOOL>;
1867
+
1868
+ /**
1869
+ * Infer the context type of a tool.
1870
+ */
1871
+ type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? HasRequiredKey<CONTEXT> extends true ? CONTEXT : never : never;
1872
+
1873
+ /**
1874
+ * Infer the input type of a tool.
1875
+ */
1876
+ type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer INPUT, any, any> ? INPUT : never;
1877
+
1878
+ /**
1879
+ * Infer the output type of a tool.
1880
+ */
1881
+ type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
1882
+
1883
+ /**
1884
+ * Executes a tool function and normalizes its results into a stream of outputs.
1448
1885
  *
1449
- * - If the tool's `execute` function returns an `AsyncIterable`, all intermediate values are yielded
1450
- * as `{ type: "preliminary", output }` except the last, which is yielded as `{ type: "final", output }`.
1886
+ * - If the tool's `execute` function returns an `AsyncIterable`, each yielded value is emitted as
1887
+ * `{ type: "preliminary", output }`. After iteration completes, the last yielded value is emitted
1888
+ * again as `{ type: "final", output }`.
1451
1889
  * - If the tool returns a direct value or Promise, a single `{ type: "final", output }` is yielded.
1452
1890
  *
1453
- * @template INPUT Input type for the tool execution.
1454
- * @template OUTPUT Output type for the tool execution.
1455
- * @template CONTEXT Context object extension for execution (extends Context).
1456
- * @param params.execute The tool execute function.
1457
- * @param params.input Input value to pass to the execute function.
1891
+ * @param params.tool The tool whose `execute` function should be invoked.
1892
+ * @param params.input The input value to pass to the tool.
1458
1893
  * @param params.options Additional options for tool execution.
1459
- * @yields An object containing either a preliminary or final output from the tool.
1894
+ * @yields A preliminary output for each streamed value, followed by a final output, or a single final
1895
+ * output for non-streaming tools.
1460
1896
  */
1461
- declare function executeTool<INPUT, OUTPUT, CONTEXT extends Context>({ execute, input, options, }: {
1462
- execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
1463
- input: INPUT;
1464
- options: ToolExecutionOptions<NoInfer<CONTEXT>>;
1897
+ declare function executeTool<TOOL extends Tool>({ tool, input, options, }: {
1898
+ tool: ExecutableTool<TOOL>;
1899
+ input: InferToolInput<TOOL>;
1900
+ options: ToolExecutionOptions<InferToolContext<TOOL>>;
1465
1901
  }): AsyncGenerator<{
1466
1902
  type: 'preliminary';
1467
- output: OUTPUT;
1903
+ output: InferToolOutput<TOOL>;
1468
1904
  } | {
1469
1905
  type: 'final';
1470
- output: OUTPUT;
1906
+ output: InferToolOutput<TOOL>;
1471
1907
  }>;
1472
1908
 
1473
1909
  /**
1474
- * Infer the context type of a tool.
1475
- */
1476
- type InferToolContext<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, any, infer CONTEXT> ? CONTEXT : never;
1477
-
1478
- /**
1479
- * Infer the input type of a tool.
1910
+ * A mapping of tool names to tool definitions.
1480
1911
  */
1481
- type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer INPUT, any, any> ? INPUT : never;
1912
+ type ToolSet = Record<string, (Tool<never, never, any> | Tool<any, any, any> | Tool<any, never, any> | Tool<never, any, any>) & Pick<Tool<any, any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
1482
1913
 
1483
1914
  /**
1484
- * Infer the output type of a tool.
1915
+ * Infer the context type for a tool set.
1916
+ *
1917
+ * The inferred type maps each tool name to its required context type.
1918
+ *
1919
+ * Tools without required context properties are omitted from the result.
1485
1920
  */
1486
- type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
1921
+ type InferToolSetContext<TOOLS extends ToolSet> = {
1922
+ [K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>;
1923
+ };
1487
1924
 
1488
1925
  /**
1489
1926
  * Typed tool call that is returned by generateText and streamText.
@@ -1544,4 +1981,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1544
1981
  dynamic?: boolean;
1545
1982
  }
1546
1983
 
1547
- export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1984
+ export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, type ExecutableTool, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SensitiveContext, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asArray, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, injectJsonInstructionIntoMessages, isAbortError, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };