@ai-sdk/provider-utils 5.0.0-beta.3 → 5.0.0-beta.30

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 (110) hide show
  1. package/CHANGELOG.md +284 -0
  2. package/dist/index.d.ts +1339 -813
  3. package/dist/index.js +837 -288
  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 -13
  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 +3 -3
  12. package/src/convert-inline-file-data-to-uint8-array.ts +30 -0
  13. package/src/create-tool-name-mapping.ts +6 -22
  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 +42 -12
  20. package/src/inject-json-instruction.ts +6 -6
  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 +108 -0
  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-defined-tool-factory.ts +129 -0
  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 +5 -3
  79. package/src/types/content-part.ts +102 -24
  80. package/src/types/context.ts +4 -0
  81. package/src/types/executable-tool.ts +17 -0
  82. package/src/types/execute-tool.ts +29 -9
  83. package/src/types/file-data.ts +48 -0
  84. package/src/types/index.ts +26 -11
  85. package/src/types/infer-tool-context.ts +12 -0
  86. package/src/types/infer-tool-input.ts +7 -0
  87. package/src/types/infer-tool-output.ts +7 -0
  88. package/src/types/infer-tool-set-context.ts +15 -0
  89. package/src/types/model-message.ts +4 -4
  90. package/src/types/never-optional.ts +7 -0
  91. package/src/types/provider-options.ts +2 -2
  92. package/src/types/provider-reference.ts +10 -0
  93. package/src/types/sensitive-context.ts +9 -0
  94. package/src/types/system-model-message.ts +1 -1
  95. package/src/types/tool-approval-request.ts +7 -0
  96. package/src/types/tool-execute-function.ts +50 -0
  97. package/src/types/tool-model-message.ts +3 -3
  98. package/src/types/tool-needs-approval-function.ts +39 -0
  99. package/src/types/tool-set.ts +22 -0
  100. package/src/types/tool.ts +251 -222
  101. package/src/types/user-model-message.ts +2 -2
  102. package/src/validate-download-url.ts +7 -2
  103. package/src/validate-types.ts +5 -3
  104. package/dist/index.d.mts +0 -1458
  105. package/dist/index.mjs +0 -2759
  106. package/dist/index.mjs.map +0 -1
  107. package/dist/test/index.d.mts +0 -17
  108. package/dist/test/index.mjs +0 -77
  109. package/dist/test/index.mjs.map +0 -1
  110. package/src/provider-tool-factory.ts +0 -125
package/dist/index.d.ts CHANGED
@@ -1,10 +1,22 @@
1
- import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions, 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,748 +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, resolveProviderToolName, }: {
45
- /**
46
- * Tools that were passed to the language model.
47
- */
48
- tools: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderTool> | undefined;
49
- /**
50
- * Maps the provider tool ids to the provider tool names.
51
- */
52
- providerToolNames: Record<`${string}.${string}`, string>;
53
- /**
54
- * Optional resolver for provider tool names that cannot be represented as
55
- * static id -> name mappings (e.g. dynamic provider names).
56
- */
57
- resolveProviderToolName?: (tool: LanguageModelV3ProviderTool) => string | undefined;
58
- }): ToolNameMapping;
59
-
60
- /**
61
- * Creates a Promise that resolves after a specified delay
62
- * @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
63
- * @param signal - Optional AbortSignal to cancel the delay
64
- * @returns A Promise that resolves after the specified delay
65
- * @throws {DOMException} When the signal is aborted
32
+ * Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
66
33
  */
67
- declare function delay(delayInMs?: number | null, options?: {
68
- abortSignal?: AbortSignal;
69
- }): Promise<void>;
34
+ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
70
35
 
71
36
  /**
72
- * Delayed promise. It is only constructed once the value is accessed.
73
- * This is useful to avoid unhandled promise rejections when the promise is created
74
- * 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`.
75
41
  */
76
- declare class DelayedPromise<T> {
77
- private status;
78
- private _promise;
79
- private _resolve;
80
- private _reject;
81
- get promise(): Promise<T>;
82
- resolve(value: T): void;
83
- reject(error: unknown): void;
84
- isResolved(): boolean;
85
- isRejected(): boolean;
86
- isPending(): boolean;
42
+ interface FileDataData {
43
+ type: 'data';
44
+ data: DataContent;
87
45
  }
88
-
89
46
  /**
90
- * Extracts the headers from a response object and returns them as a key-value object.
91
- *
92
- * @param response - The response object to extract headers from.
93
- * @returns The headers as a key-value object.
47
+ * File data variant containing a URL that points to the file.
94
48
  */
95
- declare function extractResponseHeaders(response: Response): {
96
- [k: string]: string;
97
- };
98
-
49
+ type FileDataUrl = SharedV4FileDataUrl;
99
50
  /**
100
- * Convert an ImageModelV3File to a URL or data URI string.
101
- *
102
- * If the file is a URL, it returns the URL as-is.
103
- * If the file is base64 data, it returns a data URI with the base64 data.
104
- * 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 }`).
105
52
  */
106
- declare function convertImageModelFileToDataUri(file: ImageModelV3File): string;
107
-
53
+ type FileDataReference = SharedV4FileDataReference;
108
54
  /**
109
- * Converts an input object to FormData for multipart/form-data requests.
110
- *
111
- * Handles the following cases:
112
- * - `null` or `undefined` values are skipped
113
- * - Arrays with a single element are appended as a single value
114
- * - Arrays with multiple elements are appended with `[]` suffix (e.g., `image[]`)
115
- * unless `useArrayBrackets` is set to `false`
116
- * - All other values are appended directly
117
- *
118
- * @param input - The input object to convert. Use a generic type for type validation.
119
- * @param options - Optional configuration object.
120
- * @param options.useArrayBrackets - Whether to add `[]` suffix for multi-element arrays.
121
- * Defaults to `true`. Set to `false` for APIs that expect repeated keys without brackets.
122
- * @returns A FormData object containing the input values.
123
- *
124
- * @example
125
- * ```ts
126
- * type MyInput = {
127
- * model: string;
128
- * prompt: string;
129
- * images: Blob[];
130
- * };
131
- *
132
- * const formData = convertToFormData<MyInput>({
133
- * model: 'gpt-image-1',
134
- * prompt: 'A cat',
135
- * images: [blob1, blob2],
136
- * });
137
- * ```
55
+ * File data variant containing inline text content (e.g. an inline text
56
+ * document).
138
57
  */
139
- declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
140
- useArrayBrackets?: boolean;
141
- }): FormData;
142
-
58
+ type FileDataText = SharedV4FileDataText;
143
59
  /**
144
- * Download a file from a URL and return it as a Blob.
145
- *
146
- * @param url - The URL to download from.
147
- * @param options - Optional settings for the download.
148
- * @param options.maxBytes - Maximum allowed download size in bytes. Defaults to 100 MiB.
149
- * @param options.abortSignal - An optional abort signal to cancel the download.
150
- * @returns A Promise that resolves to the downloaded Blob.
60
+ * File data as a tagged discriminated union:
151
61
  *
152
- * @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).
153
67
  */
154
- declare function downloadBlob(url: string, options?: {
155
- maxBytes?: number;
156
- abortSignal?: AbortSignal;
157
- }): Promise<Blob>;
158
-
159
- declare const symbol: unique symbol;
160
- declare class DownloadError extends AISDKError {
161
- private readonly [symbol];
162
- readonly url: string;
163
- readonly statusCode?: number;
164
- readonly statusText?: string;
165
- constructor({ url, statusCode, statusText, cause, message, }: {
166
- url: string;
167
- statusCode?: number;
168
- statusText?: string;
169
- message?: string;
170
- cause?: unknown;
171
- });
172
- static isInstance(error: unknown): error is DownloadError;
173
- }
68
+ type FileData = FileDataData | FileDataUrl | FileDataReference | FileDataText;
174
69
 
175
70
  /**
176
- * Default maximum download size: 2 GiB.
177
- *
178
- * `fetch().arrayBuffer()` has ~2x peak memory overhead (undici buffers the
179
- * body internally, then creates the JS ArrayBuffer), so very large downloads
180
- * risk exceeding the default V8 heap limit on 64-bit systems and terminating
181
- * the process with an out-of-memory error.
71
+ * Additional provider-specific options.
182
72
  *
183
- * Setting this limit converts an unrecoverable OOM crash into a catchable
184
- * `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.
185
75
  */
186
- declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
76
+ type ProviderOptions = SharedV4ProviderOptions;
77
+
187
78
  /**
188
- * Reads a fetch Response body with a size limit to prevent memory exhaustion.
189
- *
190
- * Checks the Content-Length header for early rejection, then reads the body
191
- * incrementally via ReadableStream and aborts with a DownloadError when the
192
- * limit is exceeded.
79
+ * A mapping of provider names to provider-specific file identifiers.
193
80
  *
194
- * @param response - The fetch Response to read.
195
- * @param url - The URL being downloaded (used in error messages).
196
- * @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
197
- * @returns A Uint8Array containing the response body.
198
- * @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.
199
84
  */
200
- declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
201
- response: Response;
202
- url: string;
203
- maxBytes?: number;
204
- }): Promise<Uint8Array>;
85
+ type ProviderReference = SharedV4ProviderReference;
205
86
 
206
87
  /**
207
- * Fetch function type (standardizes the version of fetch used).
88
+ * Text content part of a prompt. It contains a string of text.
208
89
  */
209
- type FetchFunction = typeof globalThis.fetch;
210
-
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
+ }
211
103
  /**
212
- * Creates an ID generator.
213
- * The total length of the ID is the sum of the prefix, separator, and random part length.
214
- * Not cryptographically secure.
104
+ * Image content part of a prompt. It contains an image.
215
105
  *
216
- * @param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
217
- * @param prefix - The prefix of the ID to generate. Optional.
218
- * @param separator - The separator between the prefix and the random part of the ID. Default: '-'.
219
- * @param size - The size of the random part of the ID to generate. Default: 16.
220
- */
221
- declare const createIdGenerator: ({ prefix, size, alphabet, separator, }?: {
222
- prefix?: string;
223
- separator?: string;
224
- size?: number;
225
- alphabet?: string;
226
- }) => IdGenerator;
227
- /**
228
- * A function that generates an ID.
229
- */
230
- type IdGenerator = () => string;
231
- /**
232
- * Generates a 16-character random string to use for IDs.
233
- * Not cryptographically secure.
106
+ * @deprecated Use `FilePart` with `mediaType: 'image'` instead:
107
+ * `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
234
108
  */
235
- declare const generateId: IdGenerator;
236
-
237
- declare function getErrorMessage(error: unknown | undefined): string;
238
-
239
- /**
240
- * Used to mark schemas so we can support both Zod and custom schemas.
241
- */
242
- declare const schemaSymbol: unique symbol;
243
- type ValidationResult<OBJECT> = {
244
- success: true;
245
- value: OBJECT;
246
- } | {
247
- success: false;
248
- error: Error;
249
- };
250
- type Schema<OBJECT = unknown> = {
109
+ interface ImagePart {
110
+ type: 'image';
251
111
  /**
252
- * 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`
253
117
  */
254
- [schemaSymbol]: true;
118
+ image: DataContent | URL | ProviderReference;
255
119
  /**
256
- * 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
257
123
  */
258
- _type: OBJECT;
124
+ mediaType?: string;
259
125
  /**
260
- * Optional. Validates that the structure of a value matches this schema,
261
- * 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.
262
129
  */
263
- 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';
264
137
  /**
265
- * 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)
266
146
  */
267
- readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
268
- };
269
- /**
270
- * Creates a schema with deferred creation.
271
- * This is important to reduce the startup time of the library
272
- * and to avoid initializing unused validators.
273
- *
274
- * @param createValidator A function that creates a schema.
275
- * @returns A function that returns a schema.
276
- */
277
- declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
278
- type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
279
- type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | z4.core.$ZodType<SCHEMA, any>;
280
- type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & StandardJSONSchemaV1<unknown, SCHEMA>;
281
- type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
282
- 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;
283
- /**
284
- * Create a schema using a JSON Schema.
285
- *
286
- * @param jsonSchema The JSON Schema for the schema.
287
- * @param options.validate Optional. A validation function for the schema.
288
- */
289
- declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
290
- validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
291
- }): Schema<OBJECT>;
292
- declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
293
- declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
147
+ data: FileData | DataContent | URL | ProviderReference;
294
148
  /**
295
- * Enables support for references in the schema.
296
- * This is required for recursive schemas, e.g. with `z.lazy`.
297
- * However, not all language models and providers support such references.
298
- * Defaults to `false`.
149
+ * Optional filename of the file.
299
150
  */
300
- useReferences?: boolean;
301
- }): Schema<OBJECT>;
302
-
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
+ }
303
172
  /**
304
- * Parses a JSON string into an unknown object.
305
- *
306
- * @param text - The JSON string to parse.
307
- * @returns {JSONValue} - The parsed JSON object.
173
+ * Reasoning content part of a prompt. It contains a reasoning.
308
174
  */
309
- declare function parseJSON(options: {
175
+ interface ReasoningPart {
176
+ type: 'reasoning';
177
+ /**
178
+ * The reasoning text.
179
+ */
310
180
  text: string;
311
- schema?: undefined;
312
- }): 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
+ }
313
188
  /**
314
- * Parses a JSON string into a strongly-typed object using the provided schema.
315
- *
316
- * @template T - The type of the object to parse the JSON into.
317
- * @param {string} text - The JSON string to parse.
318
- * @param {Validator<T>} schema - The schema to use for parsing the JSON.
319
- * @returns {Promise<T>} - The parsed object.
189
+ * Custom content part of a prompt. It contains no standardized payload beyond
190
+ * provider-specific options.
320
191
  */
321
- declare function parseJSON<T>(options: {
322
- text: string;
323
- schema: FlexibleSchema<T>;
324
- }): Promise<T>;
325
- type ParseResult<T> = {
326
- success: true;
327
- value: T;
328
- rawValue: unknown;
329
- } | {
330
- success: false;
331
- error: JSONParseError | TypeValidationError;
332
- rawValue: unknown;
333
- };
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
+ }
334
205
  /**
335
- * Safely parses a JSON string and returns the result as an object of type `unknown`.
336
- *
337
- * @param text - The JSON string to parse.
338
- * @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.
339
207
  */
340
- declare function safeParseJSON(options: {
341
- text: string;
342
- schema?: undefined;
343
- }): 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
+ }
344
239
  /**
345
- * Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
346
- *
347
- * @template T - The type of the object to parse the JSON into.
348
- * @param {string} text - The JSON string to parse.
349
- * @param {Validator<T>} schema - The schema to use for parsing the JSON.
350
- * @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).
351
241
  */
352
- declare function safeParseJSON<T>(options: {
353
- text: string;
354
- schema: FlexibleSchema<T>;
355
- }): Promise<ParseResult<T>>;
356
- declare function isParsableJson(input: string): boolean;
357
-
358
- type ResponseHandler<RETURN_TYPE> = (options: {
359
- url: string;
360
- requestBodyValues: unknown;
361
- response: Response;
362
- }) => PromiseLike<{
363
- value: RETURN_TYPE;
364
- rawValue?: unknown;
365
- responseHeaders?: Record<string, string>;
366
- }>;
367
- declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
368
- errorSchema: FlexibleSchema<T>;
369
- errorToMessage: (error: T) => string;
370
- isRetryable?: (response: Response, error?: T) => boolean;
371
- }) => ResponseHandler<APICallError>;
372
- declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
373
- declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
374
- declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
375
- declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
376
-
377
- declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
378
- url: string;
379
- headers?: Record<string, string | undefined>;
380
- failedResponseHandler: ResponseHandler<Error>;
381
- successfulResponseHandler: ResponseHandler<T>;
382
- abortSignal?: AbortSignal;
383
- fetch?: FetchFunction;
384
- }) => Promise<{
385
- value: T;
386
- rawValue?: unknown;
387
- responseHeaders?: Record<string, string>;
388
- }>;
389
-
390
- declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
391
-
392
- declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
393
- messages: LanguageModelV3Prompt;
394
- schema?: JSONSchema7;
395
- schemaPrefix?: string;
396
- schemaSuffix?: string;
397
- }): LanguageModelV3Prompt;
398
-
399
- declare function isAbortError(error: unknown): error is Error;
400
-
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
+ }
401
267
  /**
402
- * Type guard that checks whether a value is not `null` or `undefined`.
403
- *
404
- * @template T - The type of the value to check.
405
- * @param value - The value to check.
406
- * @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.
407
269
  */
408
- declare function isNonNullable<T>(value: T | undefined | null): value is NonNullable<T>;
409
-
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
+ }
410
291
  /**
411
- * Checks if the given URL is supported natively by the model.
412
- *
413
- * @param mediaType - The media type of the URL. Case-sensitive.
414
- * @param url - The URL to check.
415
- * @param supportedUrls - A record where keys are case-sensitive media types (or '*')
416
- * and values are arrays of RegExp patterns for URLs.
417
- *
418
- * @returns `true` if the URL matches a pattern under the specific media type
419
- * or the wildcard '*', `false` otherwise.
292
+ * Output of a tool result.
420
293
  */
421
- declare function isUrlSupported({ mediaType, url, supportedUrls, }: {
422
- mediaType: string;
423
- url: string;
424
- supportedUrls: Record<string, RegExp[]>;
425
- }): boolean;
426
-
427
- declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
428
- apiKey: string | undefined;
429
- environmentVariableName: string;
430
- apiKeyParameterName?: string;
431
- description: string;
432
- }): string;
433
-
434
- /**
435
- * Loads an optional `string` setting from the environment or a parameter.
436
- *
437
- * @param settingValue - The setting value.
438
- * @param environmentVariableName - The environment variable name.
439
- * @returns The setting value.
440
- */
441
- declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
442
- settingValue: string | undefined;
443
- environmentVariableName: string;
444
- }): string | undefined;
445
-
446
- /**
447
- * Loads a `string` setting from the environment or a parameter.
448
- *
449
- * @param settingValue - The setting value.
450
- * @param environmentVariableName - The environment variable name.
451
- * @param settingName - The setting name.
452
- * @param description - The description of the setting.
453
- * @returns The setting value.
454
- */
455
- declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
456
- settingValue: string | undefined;
457
- environmentVariableName: string;
458
- settingName: string;
459
- description: string;
460
- }): string;
461
-
462
- type MaybePromiseLike<T> = T | PromiseLike<T>;
463
-
464
- /**
465
- * Maps a media type to its corresponding file extension.
466
- * It was originally introduced to set a filename for audio file uploads
467
- * in https://github.com/vercel/ai/pull/8159.
468
- *
469
- * @param mediaType The media type to map.
470
- * @returns The corresponding file extension
471
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
472
- */
473
- declare function mediaTypeToExtension(mediaType: string): string;
474
-
475
- /**
476
- * Normalizes different header inputs into a plain record with lower-case keys.
477
- * Entries with `undefined` or `null` values are removed.
478
- *
479
- * @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
480
- * @returns A record containing the normalized header entries.
481
- */
482
- declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
483
-
484
- /**
485
- * Parses a JSON event stream into a stream of parsed JSON objects.
486
- */
487
- declare function parseJsonEventStream<T>({ stream, schema, }: {
488
- stream: ReadableStream<Uint8Array>;
489
- schema: FlexibleSchema<T>;
490
- }): ReadableStream<ParseResult<T>>;
491
-
492
- declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
493
- provider: string;
494
- providerOptions: Record<string, unknown> | undefined;
495
- schema: FlexibleSchema<OPTIONS>;
496
- }): Promise<OPTIONS | undefined>;
497
-
498
- declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
499
- url: string;
500
- headers?: Record<string, string | undefined>;
501
- body: unknown;
502
- failedResponseHandler: ResponseHandler<APICallError>;
503
- successfulResponseHandler: ResponseHandler<T>;
504
- abortSignal?: AbortSignal;
505
- fetch?: FetchFunction;
506
- }) => Promise<{
507
- value: T;
508
- rawValue?: unknown;
509
- responseHeaders?: Record<string, string>;
510
- }>;
511
- declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
512
- url: string;
513
- headers?: Record<string, string | undefined>;
514
- formData: FormData;
515
- failedResponseHandler: ResponseHandler<APICallError>;
516
- successfulResponseHandler: ResponseHandler<T>;
517
- abortSignal?: AbortSignal;
518
- fetch?: FetchFunction;
519
- }) => Promise<{
520
- value: T;
521
- rawValue?: unknown;
522
- responseHeaders?: Record<string, string>;
523
- }>;
524
- declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
525
- url: string;
526
- headers?: Record<string, string | undefined>;
527
- body: {
528
- content: string | FormData | Uint8Array;
529
- values: unknown;
530
- };
531
- failedResponseHandler: ResponseHandler<Error>;
532
- successfulResponseHandler: ResponseHandler<T>;
533
- abortSignal?: AbortSignal;
534
- fetch?: FetchFunction;
535
- }) => Promise<{
536
- value: T;
537
- rawValue?: unknown;
538
- responseHeaders?: Record<string, string>;
539
- }>;
540
-
541
- /**
542
- * Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
543
- */
544
- type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
545
-
546
- /**
547
- * Additional provider-specific options.
548
- *
549
- * They are passed through to the provider from the AI SDK and enable
550
- * provider-specific functionality that can be fully encapsulated in the provider.
551
- */
552
- type ProviderOptions = SharedV3ProviderOptions;
553
-
554
- /**
555
- * Text content part of a prompt. It contains a string of text.
556
- */
557
- interface TextPart {
558
- type: 'text';
294
+ type ToolResultOutput = {
559
295
  /**
560
- * The text content.
296
+ * Text tool output that should be directly sent to the API.
561
297
  */
562
- text: string;
298
+ type: 'text';
299
+ value: string;
563
300
  /**
564
- * Additional provider-specific metadata. They are passed through
565
- * to the provider from the AI SDK and enable provider-specific
566
- * functionality that can be fully encapsulated in the provider.
301
+ * Provider-specific options.
567
302
  */
568
303
  providerOptions?: ProviderOptions;
569
- }
570
- /**
571
- * Image content part of a prompt. It contains an image.
572
- */
573
- interface ImagePart {
574
- type: 'image';
575
- /**
576
- * Image data. Can either be:
577
- *
578
- * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
579
- * - URL: a URL that points to the image
580
- */
581
- image: DataContent | URL;
582
- /**
583
- * Optional IANA media type of the image.
584
- *
585
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
586
- */
587
- mediaType?: string;
304
+ } | {
305
+ type: 'json';
306
+ value: JSONValue;
588
307
  /**
589
- * Additional provider-specific metadata. They are passed through
590
- * to the provider from the AI SDK and enable provider-specific
591
- * functionality that can be fully encapsulated in the provider.
308
+ * Provider-specific options.
592
309
  */
593
310
  providerOptions?: ProviderOptions;
594
- }
595
- /**
596
- * File content part of a prompt. It contains a file.
597
- */
598
- interface FilePart {
599
- type: 'file';
600
- /**
601
- * File data. Can either be:
602
- *
603
- * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
604
- * - URL: a URL that points to the image
605
- */
606
- data: DataContent | URL;
607
- /**
608
- * Optional filename of the file.
609
- */
610
- filename?: string;
611
- /**
612
- * IANA media type of the file.
613
- *
614
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
615
- */
616
- mediaType: string;
311
+ } | {
617
312
  /**
618
- * Additional provider-specific metadata. They are passed through
619
- * to the provider from the AI SDK and enable provider-specific
620
- * functionality that can be fully encapsulated in the provider.
313
+ * Type when the user has denied the execution of the tool call.
621
314
  */
622
- providerOptions?: ProviderOptions;
623
- }
624
- /**
625
- * Reasoning content part of a prompt. It contains a reasoning.
626
- */
627
- interface ReasoningPart {
628
- type: 'reasoning';
315
+ type: 'execution-denied';
629
316
  /**
630
- * The reasoning text.
317
+ * Optional reason for the execution denial.
631
318
  */
632
- text: string;
319
+ reason?: string;
633
320
  /**
634
- * Additional provider-specific metadata. They are passed through
635
- * to the provider from the AI SDK and enable provider-specific
636
- * functionality that can be fully encapsulated in the provider.
321
+ * Provider-specific options.
637
322
  */
638
323
  providerOptions?: ProviderOptions;
639
- }
640
- /**
641
- * Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
642
- */
643
- interface ReasoningFilePart {
644
- type: 'reasoning-file';
645
- /**
646
- * File data. Can either be:
647
- *
648
- * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
649
- * - URL: a URL that points to the file
650
- */
651
- data: DataContent | URL;
652
- /**
653
- * IANA media type of the file.
654
- *
655
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
656
- */
657
- mediaType: string;
324
+ } | {
325
+ type: 'error-text';
326
+ value: string;
658
327
  /**
659
- * Additional provider-specific metadata. They are passed through
660
- * to the provider from the AI SDK and enable provider-specific
661
- * functionality that can be fully encapsulated in the provider.
328
+ * Provider-specific options.
662
329
  */
663
330
  providerOptions?: ProviderOptions;
664
- }
665
- /**
666
- * Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
667
- */
668
- interface ToolCallPart {
669
- type: 'tool-call';
670
- /**
671
- * ID of the tool call. This ID is used to match the tool call with the tool result.
672
- */
673
- toolCallId: string;
674
- /**
675
- * Name of the tool that is being called.
676
- */
677
- toolName: string;
678
- /**
679
- * Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
680
- */
681
- input: unknown;
331
+ } | {
332
+ type: 'error-json';
333
+ value: JSONValue;
682
334
  /**
683
- * Additional provider-specific metadata. They are passed through
684
- * to the provider from the AI SDK and enable provider-specific
685
- * functionality that can be fully encapsulated in the provider.
686
- */
687
- providerOptions?: ProviderOptions;
688
- /**
689
- * Whether the tool call was executed by the provider.
690
- */
691
- providerExecuted?: boolean;
692
- }
693
- /**
694
- * Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
695
- */
696
- interface ToolResultPart {
697
- type: 'tool-result';
698
- /**
699
- * ID of the tool call that this result is associated with.
700
- */
701
- toolCallId: string;
702
- /**
703
- * Name of the tool that generated this result.
704
- */
705
- toolName: string;
706
- /**
707
- * Result of the tool call. This is a JSON-serializable object.
708
- */
709
- output: ToolResultOutput;
710
- /**
711
- * Additional provider-specific metadata. They are passed through
712
- * to the provider from the AI SDK and enable provider-specific
713
- * functionality that can be fully encapsulated in the provider.
714
- */
715
- providerOptions?: ProviderOptions;
716
- }
717
- /**
718
- * Output of a tool result.
719
- */
720
- type ToolResultOutput = {
721
- /**
722
- * Text tool output that should be directly sent to the API.
723
- */
724
- type: 'text';
725
- value: string;
726
- /**
727
- * Provider-specific options.
728
- */
729
- providerOptions?: ProviderOptions;
730
- } | {
731
- type: 'json';
732
- value: JSONValue;
733
- /**
734
- * Provider-specific options.
735
- */
736
- providerOptions?: ProviderOptions;
737
- } | {
738
- /**
739
- * Type when the user has denied the execution of the tool call.
740
- */
741
- type: 'execution-denied';
742
- /**
743
- * Optional reason for the execution denial.
744
- */
745
- reason?: string;
746
- /**
747
- * Provider-specific options.
748
- */
749
- providerOptions?: ProviderOptions;
750
- } | {
751
- type: 'error-text';
752
- value: string;
753
- /**
754
- * Provider-specific options.
755
- */
756
- providerOptions?: ProviderOptions;
757
- } | {
758
- type: 'error-json';
759
- value: JSONValue;
760
- /**
761
- * Provider-specific options.
335
+ * Provider-specific options.
762
336
  */
763
337
  providerOptions?: ProviderOptions;
764
338
  } | {
@@ -773,13 +347,6 @@ type ToolResultOutput = {
773
347
  * Provider-specific options.
774
348
  */
775
349
  providerOptions?: ProviderOptions;
776
- } | {
777
- /**
778
- * @deprecated Use image-data or file-data instead.
779
- */
780
- type: 'media';
781
- data: string;
782
- mediaType: string;
783
350
  } | {
784
351
  type: 'file-data';
785
352
  /**
@@ -805,11 +372,19 @@ type ToolResultOutput = {
805
372
  * URL of the file.
806
373
  */
807
374
  url: string;
375
+ /**
376
+ * IANA media type.
377
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
378
+ */
379
+ mediaType?: string;
808
380
  /**
809
381
  * Provider-specific options.
810
382
  */
811
383
  providerOptions?: ProviderOptions;
812
384
  } | {
385
+ /**
386
+ * @deprecated Use file-reference instead.
387
+ */
813
388
  type: 'file-id';
814
389
  /**
815
390
  * ID of the file.
@@ -824,9 +399,20 @@ type ToolResultOutput = {
824
399
  * Provider-specific options.
825
400
  */
826
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;
827
413
  } | {
828
414
  /**
829
- * Images that are referenced using base64 encoded data.
415
+ * @deprecated Use file-data instead.
830
416
  */
831
417
  type: 'image-data';
832
418
  /**
@@ -844,7 +430,7 @@ type ToolResultOutput = {
844
430
  providerOptions?: ProviderOptions;
845
431
  } | {
846
432
  /**
847
- * Images that are referenced using a URL.
433
+ * @deprecated Use file-url instead.
848
434
  */
849
435
  type: 'image-url';
850
436
  /**
@@ -857,7 +443,7 @@ type ToolResultOutput = {
857
443
  providerOptions?: ProviderOptions;
858
444
  } | {
859
445
  /**
860
- * Images that are referenced using a provider file id.
446
+ * @deprecated Use file-reference instead.
861
447
  */
862
448
  type: 'image-file-id';
863
449
  /**
@@ -873,6 +459,20 @@ type ToolResultOutput = {
873
459
  * Provider-specific options.
874
460
  */
875
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;
876
476
  } | {
877
477
  /**
878
478
  * Custom content part. This can be used to implement
@@ -886,6 +486,630 @@ type ToolResultOutput = {
886
486
  }>;
887
487
  };
888
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
+
889
1113
  /**
890
1114
  * Tool approval request prompt part.
891
1115
  */
@@ -899,6 +1123,12 @@ type ToolApprovalRequest = {
899
1123
  * ID of the tool call that the approval request is for.
900
1124
  */
901
1125
  toolCallId: string;
1126
+ /**
1127
+ * Flag indicating whether the tool was automatically approved or denied.
1128
+ *
1129
+ * @default false
1130
+ */
1131
+ isAutomatic?: boolean;
902
1132
  };
903
1133
 
904
1134
  /**
@@ -918,7 +1148,7 @@ type AssistantModelMessage = {
918
1148
  * Content of an assistant message.
919
1149
  * It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
920
1150
  */
921
- type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
1151
+ type AssistantContent = string | Array<TextPart | CustomPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
922
1152
 
923
1153
  /**
924
1154
  * A system message. It can contain system information.
@@ -1005,9 +1235,9 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
1005
1235
  type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
1006
1236
 
1007
1237
  /**
1008
- * Additional options that are sent into each tool call.
1238
+ * Additional options that are sent into each tool execution.
1009
1239
  */
1010
- interface ToolExecutionOptions {
1240
+ interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
1011
1241
  /**
1012
1242
  * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
1013
1243
  */
@@ -1022,7 +1252,8 @@ interface ToolExecutionOptions {
1022
1252
  */
1023
1253
  abortSignal?: AbortSignal;
1024
1254
  /**
1025
- * 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.
1026
1257
  *
1027
1258
  * Treat the context object as immutable inside tools.
1028
1259
  * Mutating the context object can lead to race conditions and unexpected results
@@ -1030,15 +1261,20 @@ interface ToolExecutionOptions {
1030
1261
  *
1031
1262
  * If you need to mutate the context, analyze the tool calls and results
1032
1263
  * in `prepareStep` and update it there.
1033
- *
1034
- * Experimental (can break in patch releases).
1035
1264
  */
1036
- experimental_context?: unknown;
1265
+ context: CONTEXT;
1037
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
+
1038
1272
  /**
1039
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.
1040
1276
  */
1041
- type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
1277
+ type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: {
1042
1278
  /**
1043
1279
  * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
1044
1280
  */
@@ -1049,15 +1285,29 @@ type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
1049
1285
  */
1050
1286
  messages: ModelMessage[];
1051
1287
  /**
1052
- * 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.
1053
1294
  *
1054
- * 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.
1055
1297
  */
1056
- experimental_context?: unknown;
1298
+ context: CONTEXT;
1057
1299
  }) => boolean | PromiseLike<boolean>;
1058
- type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolExecutionOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
1059
- type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
1060
- type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
1300
+
1301
+ /**
1302
+ * Helper type to determine the outputSchema and execute function properties of a tool.
1303
+ */
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>;
1061
1311
  /**
1062
1312
  * An async function that is called with the arguments from the tool call and produces a result.
1063
1313
  * If not provided, the tool will not be executed automatically.
@@ -1065,25 +1315,20 @@ type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
1065
1315
  * @args is the input of the tool call.
1066
1316
  * @options.abortSignal is a signal that can be used to abort the tool call.
1067
1317
  */
1068
- execute: ToolExecuteFunction<INPUT, OUTPUT>;
1069
- outputSchema?: FlexibleSchema<OUTPUT>;
1318
+ execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
1070
1319
  } | {
1320
+ /**
1321
+ * The schema of the output that the tool produces.
1322
+ *
1323
+ * Required when no execute function is provided.
1324
+ */
1071
1325
  outputSchema: FlexibleSchema<OUTPUT>;
1072
1326
  execute?: never;
1073
1327
  }>;
1074
1328
  /**
1075
- * A tool contains the description and the schema of the input that the tool expects.
1076
- * This enables the language model to generate the input.
1077
- *
1078
- * 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.
1079
1330
  */
1080
- type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any> = {
1081
- /**
1082
- * An optional description of what the tool does.
1083
- * Will be used by the language model to decide whether to use the tool.
1084
- * Not used for provider-defined tools.
1085
- */
1086
- description?: string;
1331
+ type BaseTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = {
1087
1332
  /**
1088
1333
  * An optional title of the tool.
1089
1334
  */
@@ -1094,6 +1339,16 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1094
1339
  * functionality that can be fully encapsulated in the provider.
1095
1340
  */
1096
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;
1097
1352
  /**
1098
1353
  * The schema of the input that the tool expects.
1099
1354
  * The language model will use this to generate the input.
@@ -1103,48 +1358,49 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1103
1358
  */
1104
1359
  inputSchema: FlexibleSchema<INPUT>;
1105
1360
  /**
1106
- * An optional list of input examples that show the language
1107
- * model what the input should look like.
1361
+ * An optional schema describing the context that the tool expects.
1362
+ *
1363
+ * The context is passed to execute function as part of the execution options.
1108
1364
  */
1109
- inputExamples?: Array<{
1110
- input: NoInfer<INPUT>;
1111
- }>;
1365
+ contextSchema?: FlexibleSchema<CONTEXT>;
1112
1366
  /**
1113
- * Whether the tool needs approval before it can be executed.
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.
1114
1369
  */
1115
- needsApproval?: boolean | ToolNeedsApprovalFunction<[INPUT] extends [never] ? unknown : INPUT>;
1370
+ sensitiveContext?: SensitiveContext<CONTEXT>;
1116
1371
  /**
1117
- * Strict mode setting for the tool.
1372
+ * Whether the tool needs approval before it can be executed.
1118
1373
  *
1119
- * Providers that support strict mode will use this setting to determine
1120
- * how the input should be generated. Strict mode will always produce
1121
- * valid inputs, but it might limit what input schemas are supported.
1374
+ * @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
1122
1375
  */
1123
- strict?: boolean;
1376
+ needsApproval?: boolean | ToolNeedsApprovalFunction<[
1377
+ INPUT
1378
+ ] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
1124
1379
  /**
1125
1380
  * Optional function that is called when the argument streaming starts.
1126
1381
  * Only called when the tool is used in a streaming context.
1127
1382
  */
1128
- onInputStart?: (options: ToolExecutionOptions) => void | PromiseLike<void>;
1383
+ onInputStart?: (options: ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
1129
1384
  /**
1130
1385
  * Optional function that is called when an argument streaming delta is available.
1131
1386
  * Only called when the tool is used in a streaming context.
1132
1387
  */
1133
1388
  onInputDelta?: (options: {
1134
1389
  inputTextDelta: string;
1135
- } & ToolExecutionOptions) => void | PromiseLike<void>;
1390
+ } & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
1136
1391
  /**
1137
1392
  * Optional function that is called when a tool call can be started,
1138
1393
  * even if the execute function is not provided.
1139
1394
  */
1140
1395
  onInputAvailable?: (options: {
1141
1396
  input: [INPUT] extends [never] ? unknown : INPUT;
1142
- } & ToolExecutionOptions) => void | PromiseLike<void>;
1143
- } & ToolOutputProperties<INPUT, OUTPUT> & {
1397
+ } & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
1144
1398
  /**
1145
1399
  * Optional conversion function that maps the tool result to an output that can be used by the language model.
1146
1400
  *
1147
1401
  * If not provided, the tool result will be sent as a JSON object.
1402
+ *
1403
+ * This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
1148
1404
  */
1149
1405
  toModelOutput?: (options: {
1150
1406
  /**
@@ -1160,21 +1416,53 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1160
1416
  */
1161
1417
  output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
1162
1418
  }) => ToolResultOutput | PromiseLike<ToolResultOutput>;
1163
- } & ({
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> & {
1164
1424
  /**
1165
- * 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.
1166
1427
  */
1167
- type?: undefined | 'function';
1168
- } | {
1428
+ description?: string;
1169
1429
  /**
1170
- * Tool that is defined at runtime (e.g. an MCP tool).
1171
- * 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.
1172
1435
  */
1173
- type: 'dynamic';
1174
- } | {
1436
+ strict?: boolean;
1175
1437
  /**
1176
- * 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.
1177
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> & {
1178
1466
  type: 'provider';
1179
1467
  /**
1180
1468
  * The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
@@ -1184,6 +1472,30 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1184
1472
  * The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
1185
1473
  */
1186
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;
1187
1499
  /**
1188
1500
  * Whether this provider-executed tool supports deferred results.
1189
1501
  *
@@ -1198,79 +1510,68 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1198
1510
  * @default false
1199
1511
  */
1200
1512
  supportsDeferredResults?: boolean;
1201
- });
1202
- /**
1203
- * Infer the input type of a tool.
1204
- */
1205
- type InferToolInput<TOOL extends Tool> = TOOL extends Tool<infer INPUT, any> ? INPUT : never;
1513
+ };
1206
1514
  /**
1207
- * Infer the output type of a tool.
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.
1208
1520
  */
1209
- type InferToolOutput<TOOL extends Tool> = TOOL extends Tool<any, infer OUTPUT> ? OUTPUT : never;
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>;
1210
1522
  /**
1211
- * 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.
1212
1526
  */
1213
- declare function tool<INPUT, OUTPUT>(tool: Tool<INPUT, OUTPUT>): Tool<INPUT, OUTPUT>;
1214
- declare function tool<INPUT>(tool: Tool<INPUT, never>): Tool<INPUT, never>;
1215
- declare function tool<OUTPUT>(tool: Tool<never, OUTPUT>): Tool<never, OUTPUT>;
1216
- declare function tool(tool: Tool<never, never>): Tool<never, never>;
1527
+ declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
1528
+ declare function tool<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
1529
+ declare function tool<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
1530
+ declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
1217
1531
  /**
1218
- * Defines a dynamic tool.
1532
+ * Define a dynamic tool.
1219
1533
  */
1220
- declare function dynamicTool(tool: {
1221
- description?: string;
1222
- title?: string;
1223
- providerOptions?: ProviderOptions;
1224
- inputSchema: FlexibleSchema<unknown>;
1225
- execute: ToolExecuteFunction<unknown, unknown>;
1226
- /**
1227
- * Optional conversion function that maps the tool result to an output that can be used by the language model.
1228
- *
1229
- * If not provided, the tool result will be sent as a JSON object.
1230
- */
1231
- toModelOutput?: (options: {
1232
- /**
1233
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
1234
- */
1235
- toolCallId: string;
1236
- /**
1237
- * The input of the tool call.
1238
- */
1239
- input: unknown;
1240
- /**
1241
- * The output of the tool call.
1242
- */
1243
- output: unknown;
1244
- }) => ToolResultOutput | PromiseLike<ToolResultOutput>;
1245
- /**
1246
- * Whether the tool needs approval before it can be executed.
1247
- */
1248
- needsApproval?: boolean | ToolNeedsApprovalFunction<unknown>;
1249
- }): Tool<unknown, unknown> & {
1250
- type: 'dynamic';
1251
- };
1534
+ declare function dynamicTool(tool: Omit<DynamicTool<unknown, unknown, Context>, 'type'>): DynamicTool<unknown, unknown, Context>;
1252
1535
 
1253
- type ProviderToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options: ARGS & {
1254
- execute?: ToolExecuteFunction<INPUT, OUTPUT>;
1255
- needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
1256
- toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
1257
- onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
1258
- onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
1259
- onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
1260
- }) => Tool<INPUT, OUTPUT>;
1261
- declare function createProviderToolFactory<INPUT, ARGS extends object>({ id, inputSchema, }: {
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 & {
1541
+ execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
1542
+ needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
1543
+ toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
1544
+ onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
1545
+ onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
1546
+ onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
1547
+ }) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
1548
+ declare function createProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
1262
1549
  id: `${string}.${string}`;
1263
1550
  inputSchema: FlexibleSchema<INPUT>;
1264
- }): ProviderToolFactory<INPUT, ARGS>;
1265
- type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & {
1266
- execute?: ToolExecuteFunction<INPUT, OUTPUT>;
1267
- needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
1268
- toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
1269
- onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
1270
- onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
1271
- onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
1272
- }) => Tool<INPUT, OUTPUT>;
1273
- declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
1551
+ }): ProviderDefinedToolFactory<INPUT, ARGS, CONTEXT>;
1552
+ type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
1553
+ execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
1554
+ needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
1555
+ toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
1556
+ onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
1557
+ onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
1558
+ onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
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, }: {
1274
1575
  id: `${string}.${string}`;
1275
1576
  inputSchema: FlexibleSchema<INPUT>;
1276
1577
  outputSchema: FlexibleSchema<OUTPUT>;
@@ -1285,7 +1586,38 @@ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS e
1285
1586
  * @default false
1286
1587
  */
1287
1588
  supportsDeferredResults?: boolean;
1288
- }): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS>;
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>;
1289
1621
 
1290
1622
  /**
1291
1623
  * Removes entries from a record where the value is null or undefined.
@@ -1294,6 +1626,21 @@ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS e
1294
1626
  */
1295
1627
  declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
1296
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
+ */
1297
1644
  type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
1298
1645
  /**
1299
1646
  * Resolves a value that could be a raw value, a Promise, a function returning a value,
@@ -1301,6 +1648,134 @@ type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
1301
1648
  */
1302
1649
  declare function resolve<T>(value: Resolvable<T>): Promise<T>;
1303
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
+
1304
1779
  /**
1305
1780
  * Strips file extension segments from a filename.
1306
1781
  *
@@ -1379,18 +1854,74 @@ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, strin
1379
1854
 
1380
1855
  declare function withoutTrailingSlash(url: string | undefined): string | undefined;
1381
1856
 
1382
- declare function executeTool<INPUT, OUTPUT>({ execute, input, options, }: {
1383
- execute: ToolExecuteFunction<INPUT, OUTPUT>;
1384
- input: INPUT;
1385
- options: ToolExecutionOptions;
1857
+ /**
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.
1885
+ *
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 }`.
1889
+ * - If the tool returns a direct value or Promise, a single `{ type: "final", output }` is yielded.
1890
+ *
1891
+ * @param params.tool The tool whose `execute` function should be invoked.
1892
+ * @param params.input The input value to pass to the tool.
1893
+ * @param params.options Additional options for tool execution.
1894
+ * @yields A preliminary output for each streamed value, followed by a final output, or a single final
1895
+ * output for non-streaming tools.
1896
+ */
1897
+ declare function executeTool<TOOL extends Tool>({ tool, input, options, }: {
1898
+ tool: ExecutableTool<TOOL>;
1899
+ input: InferToolInput<TOOL>;
1900
+ options: ToolExecutionOptions<InferToolContext<TOOL>>;
1386
1901
  }): AsyncGenerator<{
1387
1902
  type: 'preliminary';
1388
- output: OUTPUT;
1903
+ output: InferToolOutput<TOOL>;
1389
1904
  } | {
1390
1905
  type: 'final';
1391
- output: OUTPUT;
1906
+ output: InferToolOutput<TOOL>;
1392
1907
  }>;
1393
1908
 
1909
+ /**
1910
+ * A mapping of tool names to tool definitions.
1911
+ */
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'>>;
1913
+
1914
+ /**
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.
1920
+ */
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
+ };
1924
+
1394
1925
  /**
1395
1926
  * Typed tool call that is returned by generateText and streamText.
1396
1927
  * It contains the tool call ID, the tool name, and the tool arguments.
@@ -1450,9 +1981,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1450
1981
  dynamic?: boolean;
1451
1982
  }
1452
1983
 
1453
- /**
1454
- * @deprecated Use ToolExecutionOptions instead.
1455
- */
1456
- type ToolCallOptions = ToolExecutionOptions;
1457
-
1458
- export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, 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 ToolCallOptions, 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, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, 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 };