@ai-sdk/provider-utils 5.0.0-beta.27 → 5.0.0-beta.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/index.d.ts +967 -843
- package/dist/index.js +340 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/add-additional-properties-to-json-schema.ts +1 -1
- package/src/convert-image-model-file-to-data-uri.ts +1 -1
- package/src/convert-inline-file-data-to-uint8-array.ts +30 -0
- package/src/create-tool-name-mapping.ts +1 -1
- package/src/detect-media-type.ts +312 -0
- package/src/get-from-api.ts +2 -2
- package/src/index.ts +8 -0
- package/src/inject-json-instruction.ts +1 -1
- package/src/is-buffer.ts +9 -0
- package/src/is-json-serializable.ts +1 -1
- package/src/is-provider-reference.ts +11 -8
- package/src/is-url-supported.ts +17 -2
- package/src/map-reasoning-to-provider.ts +4 -1
- package/src/parse-json-event-stream.ts +3 -3
- package/src/parse-json.ts +2 -2
- package/src/parse-provider-options.ts +1 -1
- package/src/post-to-api.ts +2 -2
- package/src/provider-defined-tool-factory.ts +10 -9
- package/src/provider-executed-tool-factory.ts +6 -7
- package/src/resolve-full-media-type.ts +49 -0
- package/src/resolve-provider-reference.ts +1 -2
- package/src/resolve.ts +1 -1
- package/src/response-handler.ts +2 -2
- package/src/schema.ts +6 -3
- package/src/serialize-model-options.ts +2 -2
- package/src/streaming-tool-call-tracker.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/options.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parse-def.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parse-types.ts +22 -22
- package/src/to-json-schema/zod3-to-json-schema/parsers/array.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/branded.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/catch.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/date.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/default.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/effects.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/enum.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.ts +4 -4
- package/src/to-json-schema/zod3-to-json-schema/parsers/literal.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/map.ts +4 -5
- package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/never.ts +1 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.ts +4 -4
- package/src/to-json-schema/zod3-to-json-schema/parsers/number.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/object.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/optional.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/pipeline.ts +4 -4
- package/src/to-json-schema/zod3-to-json-schema/parsers/promise.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +7 -8
- package/src/to-json-schema/zod3-to-json-schema/parsers/set.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/string.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/undefined.ts +1 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/union.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/unknown.ts +1 -2
- package/src/to-json-schema/zod3-to-json-schema/refs.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/select-parser.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts +3 -3
- package/src/types/assistant-model-message.ts +3 -3
- package/src/types/content-part.ts +37 -14
- package/src/types/executable-tool.ts +1 -1
- package/src/types/execute-tool.ts +6 -5
- package/src/types/file-data.ts +48 -0
- package/src/types/index.ts +16 -3
- package/src/types/infer-tool-context.ts +1 -1
- package/src/types/model-message.ts +4 -4
- package/src/types/never-optional.ts +7 -0
- package/src/types/provider-options.ts +1 -1
- package/src/types/provider-reference.ts +1 -1
- package/src/types/system-model-message.ts +1 -1
- package/src/types/tool-execute-function.ts +50 -0
- package/src/types/tool-model-message.ts +3 -3
- package/src/types/tool-needs-approval-function.ts +39 -0
- package/src/types/tool.ts +200 -271
- package/src/types/user-model-message.ts +2 -2
- package/src/validate-types.ts +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModelV4File, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError,
|
|
1
|
+
import { SharedV4FileDataUrl, SharedV4FileDataReference, SharedV4FileDataText, SharedV4ProviderOptions, SharedV4ProviderReference, JSONValue, ImageModelV4File, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, LanguageModelV4FilePart, JSONObject, LanguageModelV4StreamPart, SharedV4ProviderMetadata, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
export { getErrorMessage } from '@ai-sdk/provider';
|
|
3
3
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
4
4
|
export * from '@standard-schema/spec';
|
|
@@ -29,797 +29,310 @@ declare function combineHeaders(...headers: Array<Record<string, string | undefi
|
|
|
29
29
|
declare function convertAsyncIteratorToReadableStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* If the file is a URL, it returns the URL as-is.
|
|
35
|
-
* If the file is base64 data, it returns a data URI with the base64 data.
|
|
36
|
-
* If the file is a Uint8Array, it converts it to base64 and returns a data URI.
|
|
32
|
+
* Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
|
37
33
|
*/
|
|
38
|
-
|
|
34
|
+
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
39
35
|
|
|
40
36
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* Handles the following cases:
|
|
44
|
-
* - `null` or `undefined` values are skipped
|
|
45
|
-
* - Arrays with a single element are appended as a single value
|
|
46
|
-
* - Arrays with multiple elements are appended with `[]` suffix (e.g., `image[]`)
|
|
47
|
-
* unless `useArrayBrackets` is set to `false`
|
|
48
|
-
* - All other values are appended directly
|
|
37
|
+
* File data variant containing raw bytes (`Uint8Array`, `ArrayBuffer`, or
|
|
38
|
+
* `Buffer`) or a base64-encoded string.
|
|
49
39
|
*
|
|
50
|
-
*
|
|
51
|
-
* @param options - Optional configuration object.
|
|
52
|
-
* @param options.useArrayBrackets - Whether to add `[]` suffix for multi-element arrays.
|
|
53
|
-
* Defaults to `true`. Set to `false` for APIs that expect repeated keys without brackets.
|
|
54
|
-
* @returns A FormData object containing the input values.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* type MyInput = {
|
|
59
|
-
* model: string;
|
|
60
|
-
* prompt: string;
|
|
61
|
-
* images: Blob[];
|
|
62
|
-
* };
|
|
63
|
-
*
|
|
64
|
-
* const formData = convertToFormData<MyInput>({
|
|
65
|
-
* model: 'gpt-image-1',
|
|
66
|
-
* prompt: 'A cat',
|
|
67
|
-
* images: [blob1, blob2],
|
|
68
|
-
* });
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
|
|
72
|
-
useArrayBrackets?: boolean;
|
|
73
|
-
}): FormData;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Interface for mapping between custom tool names and provider tool names.
|
|
40
|
+
* This is slightly more permissive than `SharedV4FileDataData`.
|
|
77
41
|
*/
|
|
78
|
-
interface
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* If the custom tool name does not have a mapping, returns the input name.
|
|
82
|
-
*
|
|
83
|
-
* @param customToolName - The custom name of the tool defined by the client.
|
|
84
|
-
* @returns The corresponding provider tool name, or the input name if not mapped.
|
|
85
|
-
*/
|
|
86
|
-
toProviderToolName: (customToolName: string) => string;
|
|
87
|
-
/**
|
|
88
|
-
* Maps a provider tool name to the custom tool name used by the client.
|
|
89
|
-
* If the provider tool name does not have a mapping, returns the input name.
|
|
90
|
-
*
|
|
91
|
-
* @param providerToolName - The name of the tool as understood by the provider.
|
|
92
|
-
* @returns The corresponding custom tool name, or the input name if not mapped.
|
|
93
|
-
*/
|
|
94
|
-
toCustomToolName: (providerToolName: string) => string;
|
|
42
|
+
interface FileDataData {
|
|
43
|
+
type: 'data';
|
|
44
|
+
data: DataContent;
|
|
95
45
|
}
|
|
96
46
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param providerToolNames - Maps the provider tool ids to the provider tool names.
|
|
47
|
+
* File data variant containing a URL that points to the file.
|
|
99
48
|
*/
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Tools that were passed to the language model.
|
|
103
|
-
*/
|
|
104
|
-
tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
|
|
105
|
-
/**
|
|
106
|
-
* Maps the provider tool ids to the provider tool names.
|
|
107
|
-
*/
|
|
108
|
-
providerToolNames: Record<`${string}.${string}`, string>;
|
|
109
|
-
}): ToolNameMapping;
|
|
110
|
-
|
|
49
|
+
type FileDataUrl = SharedV4FileDataUrl;
|
|
111
50
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
|
|
114
|
-
* @param signal - Optional AbortSignal to cancel the delay
|
|
115
|
-
* @returns A Promise that resolves after the specified delay
|
|
116
|
-
* @throws {DOMException} When the signal is aborted
|
|
51
|
+
* File data variant containing a provider reference (`{ [provider]: id }`).
|
|
117
52
|
*/
|
|
118
|
-
|
|
119
|
-
abortSignal?: AbortSignal;
|
|
120
|
-
}): Promise<void>;
|
|
121
|
-
|
|
53
|
+
type FileDataReference = SharedV4FileDataReference;
|
|
122
54
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* but not accessed.
|
|
55
|
+
* File data variant containing inline text content (e.g. an inline text
|
|
56
|
+
* document).
|
|
126
57
|
*/
|
|
127
|
-
|
|
128
|
-
private status;
|
|
129
|
-
private _promise;
|
|
130
|
-
private _resolve;
|
|
131
|
-
private _reject;
|
|
132
|
-
get promise(): Promise<T>;
|
|
133
|
-
resolve(value: T): void;
|
|
134
|
-
reject(error: unknown): void;
|
|
135
|
-
isResolved(): boolean;
|
|
136
|
-
isRejected(): boolean;
|
|
137
|
-
isPending(): boolean;
|
|
138
|
-
}
|
|
139
|
-
|
|
58
|
+
type FileDataText = SharedV4FileDataText;
|
|
140
59
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @param url - The URL to download from.
|
|
144
|
-
* @param options - Optional settings for the download.
|
|
145
|
-
* @param options.maxBytes - Maximum allowed download size in bytes. Defaults to 100 MiB.
|
|
146
|
-
* @param options.abortSignal - An optional abort signal to cancel the download.
|
|
147
|
-
* @returns A Promise that resolves to the downloaded Blob.
|
|
60
|
+
* File data as a tagged discriminated union:
|
|
148
61
|
*
|
|
149
|
-
*
|
|
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).
|
|
150
67
|
*/
|
|
151
|
-
|
|
152
|
-
maxBytes?: number;
|
|
153
|
-
abortSignal?: AbortSignal;
|
|
154
|
-
}): Promise<Blob>;
|
|
155
|
-
|
|
156
|
-
declare const symbol: unique symbol;
|
|
157
|
-
declare class DownloadError extends AISDKError {
|
|
158
|
-
private readonly [symbol];
|
|
159
|
-
readonly url: string;
|
|
160
|
-
readonly statusCode?: number;
|
|
161
|
-
readonly statusText?: string;
|
|
162
|
-
constructor({ url, statusCode, statusText, cause, message, }: {
|
|
163
|
-
url: string;
|
|
164
|
-
statusCode?: number;
|
|
165
|
-
statusText?: string;
|
|
166
|
-
message?: string;
|
|
167
|
-
cause?: unknown;
|
|
168
|
-
});
|
|
169
|
-
static isInstance(error: unknown): error is DownloadError;
|
|
170
|
-
}
|
|
68
|
+
type FileData = FileDataData | FileDataUrl | FileDataReference | FileDataText;
|
|
171
69
|
|
|
172
70
|
/**
|
|
173
|
-
*
|
|
71
|
+
* Additional provider-specific options.
|
|
174
72
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*/
|
|
178
|
-
declare function extractResponseHeaders(response: Response): {
|
|
179
|
-
[k: string]: string;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Fetch function type (standardizes the version of fetch used).
|
|
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.
|
|
184
75
|
*/
|
|
185
|
-
type
|
|
76
|
+
type ProviderOptions = SharedV4ProviderOptions;
|
|
186
77
|
|
|
187
78
|
/**
|
|
188
|
-
*
|
|
79
|
+
* A mapping of provider names to provider-specific file identifiers.
|
|
189
80
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
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.
|
|
192
84
|
*/
|
|
193
|
-
|
|
85
|
+
type ProviderReference = SharedV4ProviderReference;
|
|
194
86
|
|
|
195
87
|
/**
|
|
196
|
-
*
|
|
197
|
-
* The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
198
|
-
* Not cryptographically secure.
|
|
199
|
-
*
|
|
200
|
-
* @param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
|
|
201
|
-
* @param prefix - The prefix of the ID to generate. Optional.
|
|
202
|
-
* @param separator - The separator between the prefix and the random part of the ID. Default: '-'.
|
|
203
|
-
* @param size - The size of the random part of the ID to generate. Default: 16.
|
|
204
|
-
*/
|
|
205
|
-
declare const createIdGenerator: ({ prefix, size, alphabet, separator, }?: {
|
|
206
|
-
prefix?: string;
|
|
207
|
-
separator?: string;
|
|
208
|
-
size?: number;
|
|
209
|
-
alphabet?: string;
|
|
210
|
-
}) => IdGenerator;
|
|
211
|
-
/**
|
|
212
|
-
* A function that generates an ID.
|
|
88
|
+
* Text content part of a prompt. It contains a string of text.
|
|
213
89
|
*/
|
|
214
|
-
|
|
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
|
+
}
|
|
215
103
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
104
|
+
* Image content part of a prompt. It contains an image.
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Use `FilePart` with `mediaType: 'image'` instead:
|
|
107
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
218
108
|
*/
|
|
219
|
-
|
|
220
|
-
|
|
109
|
+
interface ImagePart {
|
|
110
|
+
type: 'image';
|
|
111
|
+
/**
|
|
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`
|
|
117
|
+
*/
|
|
118
|
+
image: DataContent | URL | ProviderReference;
|
|
119
|
+
/**
|
|
120
|
+
* Optional IANA media type of the image.
|
|
121
|
+
*
|
|
122
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
123
|
+
*/
|
|
124
|
+
mediaType?: string;
|
|
125
|
+
/**
|
|
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.
|
|
129
|
+
*/
|
|
130
|
+
providerOptions?: ProviderOptions;
|
|
131
|
+
}
|
|
221
132
|
/**
|
|
222
|
-
*
|
|
133
|
+
* File content part of a prompt. It contains a file.
|
|
223
134
|
*/
|
|
224
|
-
|
|
225
|
-
type
|
|
226
|
-
success: true;
|
|
227
|
-
value: OBJECT;
|
|
228
|
-
} | {
|
|
229
|
-
success: false;
|
|
230
|
-
error: Error;
|
|
231
|
-
};
|
|
232
|
-
type Schema<OBJECT = unknown> = {
|
|
135
|
+
interface FilePart {
|
|
136
|
+
type: 'file';
|
|
233
137
|
/**
|
|
234
|
-
*
|
|
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)
|
|
235
146
|
*/
|
|
236
|
-
|
|
147
|
+
data: FileData | DataContent | URL | ProviderReference;
|
|
237
148
|
/**
|
|
238
|
-
*
|
|
149
|
+
* Optional filename of the file.
|
|
239
150
|
*/
|
|
240
|
-
|
|
151
|
+
filename?: string;
|
|
241
152
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
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
|
|
244
163
|
*/
|
|
245
|
-
|
|
164
|
+
mediaType: string;
|
|
246
165
|
/**
|
|
247
|
-
*
|
|
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.
|
|
248
169
|
*/
|
|
249
|
-
|
|
250
|
-
}
|
|
170
|
+
providerOptions?: ProviderOptions;
|
|
171
|
+
}
|
|
251
172
|
/**
|
|
252
|
-
*
|
|
253
|
-
* This is important to reduce the startup time of the library
|
|
254
|
-
* and to avoid initializing unused validators.
|
|
255
|
-
*
|
|
256
|
-
* @param createValidator A function that creates a schema.
|
|
257
|
-
* @returns A function that returns a schema.
|
|
173
|
+
* Reasoning content part of a prompt. It contains a reasoning.
|
|
258
174
|
*/
|
|
259
|
-
|
|
260
|
-
type
|
|
261
|
-
type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | z4.core.$ZodType<SCHEMA, any>;
|
|
262
|
-
type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & StandardJSONSchemaV1<unknown, SCHEMA>;
|
|
263
|
-
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
|
|
264
|
-
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;
|
|
265
|
-
/**
|
|
266
|
-
* Create a schema using a JSON Schema.
|
|
267
|
-
*
|
|
268
|
-
* @param jsonSchema The JSON Schema for the schema.
|
|
269
|
-
* @param options.validate Optional. A validation function for the schema.
|
|
270
|
-
*/
|
|
271
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
|
272
|
-
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
273
|
-
}): Schema<OBJECT>;
|
|
274
|
-
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
275
|
-
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
|
175
|
+
interface ReasoningPart {
|
|
176
|
+
type: 'reasoning';
|
|
276
177
|
/**
|
|
277
|
-
*
|
|
278
|
-
* This is required for recursive schemas, e.g. with `z.lazy`.
|
|
279
|
-
* However, not all language models and providers support such references.
|
|
280
|
-
* Defaults to `false`.
|
|
178
|
+
* The reasoning text.
|
|
281
179
|
*/
|
|
282
|
-
useReferences?: boolean;
|
|
283
|
-
}): Schema<OBJECT>;
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Parses a JSON string into an unknown object.
|
|
287
|
-
*
|
|
288
|
-
* @param text - The JSON string to parse.
|
|
289
|
-
* @returns {JSONValue} - The parsed JSON object.
|
|
290
|
-
*/
|
|
291
|
-
declare function parseJSON(options: {
|
|
292
|
-
text: string;
|
|
293
|
-
schema?: undefined;
|
|
294
|
-
}): Promise<JSONValue>;
|
|
295
|
-
/**
|
|
296
|
-
* Parses a JSON string into a strongly-typed object using the provided schema.
|
|
297
|
-
*
|
|
298
|
-
* @template T - The type of the object to parse the JSON into.
|
|
299
|
-
* @param {string} text - The JSON string to parse.
|
|
300
|
-
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
301
|
-
* @returns {Promise<T>} - The parsed object.
|
|
302
|
-
*/
|
|
303
|
-
declare function parseJSON<T>(options: {
|
|
304
|
-
text: string;
|
|
305
|
-
schema: FlexibleSchema<T>;
|
|
306
|
-
}): Promise<T>;
|
|
307
|
-
type ParseResult<T> = {
|
|
308
|
-
success: true;
|
|
309
|
-
value: T;
|
|
310
|
-
rawValue: unknown;
|
|
311
|
-
} | {
|
|
312
|
-
success: false;
|
|
313
|
-
error: JSONParseError | TypeValidationError;
|
|
314
|
-
rawValue: unknown;
|
|
315
|
-
};
|
|
316
|
-
/**
|
|
317
|
-
* Safely parses a JSON string and returns the result as an object of type `unknown`.
|
|
318
|
-
*
|
|
319
|
-
* @param text - The JSON string to parse.
|
|
320
|
-
* @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
|
|
321
|
-
*/
|
|
322
|
-
declare function safeParseJSON(options: {
|
|
323
|
-
text: string;
|
|
324
|
-
schema?: undefined;
|
|
325
|
-
}): Promise<ParseResult<JSONValue>>;
|
|
326
|
-
/**
|
|
327
|
-
* Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
|
|
328
|
-
*
|
|
329
|
-
* @template T - The type of the object to parse the JSON into.
|
|
330
|
-
* @param {string} text - The JSON string to parse.
|
|
331
|
-
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
332
|
-
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
333
|
-
*/
|
|
334
|
-
declare function safeParseJSON<T>(options: {
|
|
335
180
|
text: string;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
response: Response;
|
|
344
|
-
}) => PromiseLike<{
|
|
345
|
-
value: RETURN_TYPE;
|
|
346
|
-
rawValue?: unknown;
|
|
347
|
-
responseHeaders?: Record<string, string>;
|
|
348
|
-
}>;
|
|
349
|
-
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
|
350
|
-
errorSchema: FlexibleSchema<T>;
|
|
351
|
-
errorToMessage: (error: T) => string;
|
|
352
|
-
isRetryable?: (response: Response, error?: T) => boolean;
|
|
353
|
-
}) => ResponseHandler<APICallError>;
|
|
354
|
-
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
355
|
-
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
356
|
-
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
357
|
-
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
358
|
-
|
|
359
|
-
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
|
360
|
-
url: string;
|
|
361
|
-
headers?: Record<string, string | undefined>;
|
|
362
|
-
failedResponseHandler: ResponseHandler<Error>;
|
|
363
|
-
successfulResponseHandler: ResponseHandler<T>;
|
|
364
|
-
abortSignal?: AbortSignal;
|
|
365
|
-
fetch?: FetchFunction;
|
|
366
|
-
}) => Promise<{
|
|
367
|
-
value: T;
|
|
368
|
-
rawValue?: unknown;
|
|
369
|
-
responseHeaders?: Record<string, string>;
|
|
370
|
-
}>;
|
|
371
|
-
|
|
372
|
-
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
|
373
|
-
|
|
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
|
+
}
|
|
374
188
|
/**
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
* @returns True if the object has required keys, false otherwise.
|
|
189
|
+
* Custom content part of a prompt. It contains no standardized payload beyond
|
|
190
|
+
* provider-specific options.
|
|
378
191
|
*/
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
+
}
|
|
390
205
|
/**
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
* @template T - The type of the value to check.
|
|
394
|
-
* @param value - The value to check.
|
|
395
|
-
* @returns `true` if the value is neither `null` nor `undefined`, otherwise `false`.
|
|
206
|
+
* Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
|
|
396
207
|
*/
|
|
397
|
-
|
|
398
|
-
|
|
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
|
+
}
|
|
399
239
|
/**
|
|
400
|
-
*
|
|
401
|
-
* names to provider-specific identifiers) as opposed to raw bytes or a URL.
|
|
240
|
+
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
402
241
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
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
|
+
}
|
|
405
267
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* @param mediaType - The media type of the URL. Case-sensitive.
|
|
409
|
-
* @param url - The URL to check.
|
|
410
|
-
* @param supportedUrls - A record where keys are case-sensitive media types (or '*')
|
|
411
|
-
* and values are arrays of RegExp patterns for URLs.
|
|
412
|
-
*
|
|
413
|
-
* @returns `true` if the URL matches a pattern under the specific media type
|
|
414
|
-
* or the wildcard '*', `false` otherwise.
|
|
268
|
+
* Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
|
415
269
|
*/
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
+
}
|
|
429
291
|
/**
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
* @param settingValue - The setting value.
|
|
433
|
-
* @param environmentVariableName - The environment variable name.
|
|
434
|
-
* @returns The setting value.
|
|
292
|
+
* Output of a tool result.
|
|
435
293
|
*/
|
|
436
|
-
|
|
437
|
-
settingValue: string | undefined;
|
|
438
|
-
environmentVariableName: string;
|
|
439
|
-
}): string | undefined;
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Loads a `string` setting from the environment or a parameter.
|
|
443
|
-
*
|
|
444
|
-
* @param settingValue - The setting value.
|
|
445
|
-
* @param environmentVariableName - The environment variable name.
|
|
446
|
-
* @param settingName - The setting name.
|
|
447
|
-
* @param description - The description of the setting.
|
|
448
|
-
* @returns The setting value.
|
|
449
|
-
*/
|
|
450
|
-
declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
|
|
451
|
-
settingValue: string | undefined;
|
|
452
|
-
environmentVariableName: string;
|
|
453
|
-
settingName: string;
|
|
454
|
-
description: string;
|
|
455
|
-
}): string;
|
|
456
|
-
|
|
457
|
-
type ReasoningLevel = Exclude<LanguageModelV4CallOptions['reasoning'], 'none' | 'provider-default' | undefined>;
|
|
458
|
-
declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
|
|
459
|
-
/**
|
|
460
|
-
* Maps a top-level reasoning level to a provider-specific effort string using
|
|
461
|
-
* the given effort map. Pushes a compatibility warning if the reasoning level
|
|
462
|
-
* maps to a different string, or an unsupported warning if the level is not
|
|
463
|
-
* present in the map.
|
|
464
|
-
*
|
|
465
|
-
* @returns The mapped effort string, or `undefined` if the level is not
|
|
466
|
-
* supported.
|
|
467
|
-
*/
|
|
468
|
-
declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings, }: {
|
|
469
|
-
reasoning: ReasoningLevel;
|
|
470
|
-
effortMap: Partial<Record<ReasoningLevel, T>>;
|
|
471
|
-
warnings: SharedV4Warning[];
|
|
472
|
-
}): T | undefined;
|
|
473
|
-
/**
|
|
474
|
-
* Maps a top-level reasoning level to an absolute token budget by multiplying
|
|
475
|
-
* the model's max output tokens by a percentage from the budget percentages
|
|
476
|
-
* map. The result is clamped between `minReasoningBudget` (default 1024) and
|
|
477
|
-
* `maxReasoningBudget`. Pushes an unsupported warning if the level is not
|
|
478
|
-
* present in the budget percentages map.
|
|
479
|
-
*
|
|
480
|
-
* @returns The computed token budget, or `undefined` if the level is not
|
|
481
|
-
* supported.
|
|
482
|
-
*/
|
|
483
|
-
declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings, }: {
|
|
484
|
-
reasoning: ReasoningLevel;
|
|
485
|
-
maxOutputTokens: number;
|
|
486
|
-
maxReasoningBudget: number;
|
|
487
|
-
minReasoningBudget?: number;
|
|
488
|
-
budgetPercentages?: Partial<Record<ReasoningLevel, number>>;
|
|
489
|
-
warnings: SharedV4Warning[];
|
|
490
|
-
}): number | undefined;
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* A value that can be provided either synchronously or as a promise-like.
|
|
494
|
-
*/
|
|
495
|
-
type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* Maps a media type to its corresponding file extension.
|
|
499
|
-
* It was originally introduced to set a filename for audio file uploads
|
|
500
|
-
* in https://github.com/vercel/ai/pull/8159.
|
|
501
|
-
*
|
|
502
|
-
* @param mediaType The media type to map.
|
|
503
|
-
* @returns The corresponding file extension
|
|
504
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
|
|
505
|
-
*/
|
|
506
|
-
declare function mediaTypeToExtension(mediaType: string): string;
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
510
|
-
* Entries with `undefined` or `null` values are removed.
|
|
511
|
-
*
|
|
512
|
-
* @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
|
|
513
|
-
* @returns A record containing the normalized header entries.
|
|
514
|
-
*/
|
|
515
|
-
declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
519
|
-
*/
|
|
520
|
-
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
|
521
|
-
stream: ReadableStream<Uint8Array>;
|
|
522
|
-
schema: FlexibleSchema<T>;
|
|
523
|
-
}): ReadableStream<ParseResult<T>>;
|
|
524
|
-
|
|
525
|
-
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
|
526
|
-
provider: string;
|
|
527
|
-
providerOptions: Record<string, unknown> | undefined;
|
|
528
|
-
schema: FlexibleSchema<OPTIONS>;
|
|
529
|
-
}): Promise<OPTIONS | undefined>;
|
|
530
|
-
|
|
531
|
-
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
|
532
|
-
url: string;
|
|
533
|
-
headers?: Record<string, string | undefined>;
|
|
534
|
-
body: unknown;
|
|
535
|
-
failedResponseHandler: ResponseHandler<APICallError>;
|
|
536
|
-
successfulResponseHandler: ResponseHandler<T>;
|
|
537
|
-
abortSignal?: AbortSignal;
|
|
538
|
-
fetch?: FetchFunction;
|
|
539
|
-
}) => Promise<{
|
|
540
|
-
value: T;
|
|
541
|
-
rawValue?: unknown;
|
|
542
|
-
responseHeaders?: Record<string, string>;
|
|
543
|
-
}>;
|
|
544
|
-
declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
|
545
|
-
url: string;
|
|
546
|
-
headers?: Record<string, string | undefined>;
|
|
547
|
-
formData: FormData;
|
|
548
|
-
failedResponseHandler: ResponseHandler<APICallError>;
|
|
549
|
-
successfulResponseHandler: ResponseHandler<T>;
|
|
550
|
-
abortSignal?: AbortSignal;
|
|
551
|
-
fetch?: FetchFunction;
|
|
552
|
-
}) => Promise<{
|
|
553
|
-
value: T;
|
|
554
|
-
rawValue?: unknown;
|
|
555
|
-
responseHeaders?: Record<string, string>;
|
|
556
|
-
}>;
|
|
557
|
-
declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
|
558
|
-
url: string;
|
|
559
|
-
headers?: Record<string, string | undefined>;
|
|
560
|
-
body: {
|
|
561
|
-
content: string | FormData | Uint8Array;
|
|
562
|
-
values: unknown;
|
|
563
|
-
};
|
|
564
|
-
failedResponseHandler: ResponseHandler<Error>;
|
|
565
|
-
successfulResponseHandler: ResponseHandler<T>;
|
|
566
|
-
abortSignal?: AbortSignal;
|
|
567
|
-
fetch?: FetchFunction;
|
|
568
|
-
}) => Promise<{
|
|
569
|
-
value: T;
|
|
570
|
-
rawValue?: unknown;
|
|
571
|
-
responseHeaders?: Record<string, string>;
|
|
572
|
-
}>;
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
|
576
|
-
*/
|
|
577
|
-
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Additional provider-specific options.
|
|
581
|
-
*
|
|
582
|
-
* They are passed through to the provider from the AI SDK and enable
|
|
583
|
-
* provider-specific functionality that can be fully encapsulated in the provider.
|
|
584
|
-
*/
|
|
585
|
-
type ProviderOptions = SharedV4ProviderOptions;
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* A mapping of provider names to provider-specific file identifiers.
|
|
589
|
-
*
|
|
590
|
-
* Provider references allow files to be identified across different
|
|
591
|
-
* providers without re-uploading, by storing each provider's own
|
|
592
|
-
* identifier for the same logical file.
|
|
593
|
-
*/
|
|
594
|
-
type ProviderReference = SharedV4ProviderReference;
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Text content part of a prompt. It contains a string of text.
|
|
598
|
-
*/
|
|
599
|
-
interface TextPart {
|
|
600
|
-
type: 'text';
|
|
294
|
+
type ToolResultOutput = {
|
|
601
295
|
/**
|
|
602
|
-
*
|
|
296
|
+
* Text tool output that should be directly sent to the API.
|
|
603
297
|
*/
|
|
604
|
-
|
|
298
|
+
type: 'text';
|
|
299
|
+
value: string;
|
|
605
300
|
/**
|
|
606
|
-
*
|
|
607
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
608
|
-
* functionality that can be fully encapsulated in the provider.
|
|
301
|
+
* Provider-specific options.
|
|
609
302
|
*/
|
|
610
303
|
providerOptions?: ProviderOptions;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
*/
|
|
615
|
-
interface ImagePart {
|
|
616
|
-
type: 'image';
|
|
617
|
-
/**
|
|
618
|
-
* Image data. Can either be:
|
|
619
|
-
*
|
|
620
|
-
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
621
|
-
* - URL: a URL that points to the image
|
|
622
|
-
* - ProviderReference: a provider reference from `uploadFile`
|
|
623
|
-
*/
|
|
624
|
-
image: DataContent | URL | ProviderReference;
|
|
625
|
-
/**
|
|
626
|
-
* Optional IANA media type of the image.
|
|
627
|
-
*
|
|
628
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
629
|
-
*/
|
|
630
|
-
mediaType?: string;
|
|
304
|
+
} | {
|
|
305
|
+
type: 'json';
|
|
306
|
+
value: JSONValue;
|
|
631
307
|
/**
|
|
632
|
-
*
|
|
633
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
634
|
-
* functionality that can be fully encapsulated in the provider.
|
|
308
|
+
* Provider-specific options.
|
|
635
309
|
*/
|
|
636
310
|
providerOptions?: ProviderOptions;
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* File content part of a prompt. It contains a file.
|
|
640
|
-
*/
|
|
641
|
-
interface FilePart {
|
|
642
|
-
type: 'file';
|
|
643
|
-
/**
|
|
644
|
-
* File data. Can either be:
|
|
645
|
-
*
|
|
646
|
-
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
647
|
-
* - URL: a URL that points to the file
|
|
648
|
-
* - ProviderReference: a provider reference from `uploadFile`
|
|
649
|
-
*/
|
|
650
|
-
data: DataContent | URL | ProviderReference;
|
|
311
|
+
} | {
|
|
651
312
|
/**
|
|
652
|
-
*
|
|
313
|
+
* Type when the user has denied the execution of the tool call.
|
|
653
314
|
*/
|
|
654
|
-
|
|
315
|
+
type: 'execution-denied';
|
|
655
316
|
/**
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
317
|
+
* Optional reason for the execution denial.
|
|
659
318
|
*/
|
|
660
|
-
|
|
319
|
+
reason?: string;
|
|
661
320
|
/**
|
|
662
|
-
*
|
|
663
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
664
|
-
* functionality that can be fully encapsulated in the provider.
|
|
321
|
+
* Provider-specific options.
|
|
665
322
|
*/
|
|
666
323
|
providerOptions?: ProviderOptions;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
*/
|
|
671
|
-
interface ReasoningPart {
|
|
672
|
-
type: 'reasoning';
|
|
673
|
-
/**
|
|
674
|
-
* The reasoning text.
|
|
675
|
-
*/
|
|
676
|
-
text: string;
|
|
324
|
+
} | {
|
|
325
|
+
type: 'error-text';
|
|
326
|
+
value: string;
|
|
677
327
|
/**
|
|
678
|
-
*
|
|
679
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
680
|
-
* functionality that can be fully encapsulated in the provider.
|
|
328
|
+
* Provider-specific options.
|
|
681
329
|
*/
|
|
682
330
|
providerOptions?: ProviderOptions;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
* provider-specific options.
|
|
687
|
-
*/
|
|
688
|
-
interface CustomPart {
|
|
689
|
-
type: 'custom';
|
|
331
|
+
} | {
|
|
332
|
+
type: 'error-json';
|
|
333
|
+
value: JSONValue;
|
|
690
334
|
/**
|
|
691
|
-
*
|
|
692
|
-
*/
|
|
693
|
-
kind: `${string}.${string}`;
|
|
694
|
-
/**
|
|
695
|
-
* Additional provider-specific metadata. They are passed through
|
|
696
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
697
|
-
* functionality that can be fully encapsulated in the provider.
|
|
698
|
-
*/
|
|
699
|
-
providerOptions?: ProviderOptions;
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
|
|
703
|
-
*/
|
|
704
|
-
interface ReasoningFilePart {
|
|
705
|
-
type: 'reasoning-file';
|
|
706
|
-
/**
|
|
707
|
-
* File data. Can either be:
|
|
708
|
-
*
|
|
709
|
-
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
710
|
-
* - URL: a URL that points to the file
|
|
711
|
-
*/
|
|
712
|
-
data: DataContent | URL;
|
|
713
|
-
/**
|
|
714
|
-
* IANA media type of the file.
|
|
715
|
-
*
|
|
716
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
717
|
-
*/
|
|
718
|
-
mediaType: string;
|
|
719
|
-
/**
|
|
720
|
-
* Additional provider-specific metadata. They are passed through
|
|
721
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
722
|
-
* functionality that can be fully encapsulated in the provider.
|
|
723
|
-
*/
|
|
724
|
-
providerOptions?: ProviderOptions;
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
728
|
-
*/
|
|
729
|
-
interface ToolCallPart {
|
|
730
|
-
type: 'tool-call';
|
|
731
|
-
/**
|
|
732
|
-
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
733
|
-
*/
|
|
734
|
-
toolCallId: string;
|
|
735
|
-
/**
|
|
736
|
-
* Name of the tool that is being called.
|
|
737
|
-
*/
|
|
738
|
-
toolName: string;
|
|
739
|
-
/**
|
|
740
|
-
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
741
|
-
*/
|
|
742
|
-
input: unknown;
|
|
743
|
-
/**
|
|
744
|
-
* Additional provider-specific metadata. They are passed through
|
|
745
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
746
|
-
* functionality that can be fully encapsulated in the provider.
|
|
747
|
-
*/
|
|
748
|
-
providerOptions?: ProviderOptions;
|
|
749
|
-
/**
|
|
750
|
-
* Whether the tool call was executed by the provider.
|
|
751
|
-
*/
|
|
752
|
-
providerExecuted?: boolean;
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
|
756
|
-
*/
|
|
757
|
-
interface ToolResultPart {
|
|
758
|
-
type: 'tool-result';
|
|
759
|
-
/**
|
|
760
|
-
* ID of the tool call that this result is associated with.
|
|
761
|
-
*/
|
|
762
|
-
toolCallId: string;
|
|
763
|
-
/**
|
|
764
|
-
* Name of the tool that generated this result.
|
|
765
|
-
*/
|
|
766
|
-
toolName: string;
|
|
767
|
-
/**
|
|
768
|
-
* Result of the tool call. This is a JSON-serializable object.
|
|
769
|
-
*/
|
|
770
|
-
output: ToolResultOutput;
|
|
771
|
-
/**
|
|
772
|
-
* Additional provider-specific metadata. They are passed through
|
|
773
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
774
|
-
* functionality that can be fully encapsulated in the provider.
|
|
775
|
-
*/
|
|
776
|
-
providerOptions?: ProviderOptions;
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Output of a tool result.
|
|
780
|
-
*/
|
|
781
|
-
type ToolResultOutput = {
|
|
782
|
-
/**
|
|
783
|
-
* Text tool output that should be directly sent to the API.
|
|
784
|
-
*/
|
|
785
|
-
type: 'text';
|
|
786
|
-
value: string;
|
|
787
|
-
/**
|
|
788
|
-
* Provider-specific options.
|
|
789
|
-
*/
|
|
790
|
-
providerOptions?: ProviderOptions;
|
|
791
|
-
} | {
|
|
792
|
-
type: 'json';
|
|
793
|
-
value: JSONValue;
|
|
794
|
-
/**
|
|
795
|
-
* Provider-specific options.
|
|
796
|
-
*/
|
|
797
|
-
providerOptions?: ProviderOptions;
|
|
798
|
-
} | {
|
|
799
|
-
/**
|
|
800
|
-
* Type when the user has denied the execution of the tool call.
|
|
801
|
-
*/
|
|
802
|
-
type: 'execution-denied';
|
|
803
|
-
/**
|
|
804
|
-
* Optional reason for the execution denial.
|
|
805
|
-
*/
|
|
806
|
-
reason?: string;
|
|
807
|
-
/**
|
|
808
|
-
* Provider-specific options.
|
|
809
|
-
*/
|
|
810
|
-
providerOptions?: ProviderOptions;
|
|
811
|
-
} | {
|
|
812
|
-
type: 'error-text';
|
|
813
|
-
value: string;
|
|
814
|
-
/**
|
|
815
|
-
* Provider-specific options.
|
|
816
|
-
*/
|
|
817
|
-
providerOptions?: ProviderOptions;
|
|
818
|
-
} | {
|
|
819
|
-
type: 'error-json';
|
|
820
|
-
value: JSONValue;
|
|
821
|
-
/**
|
|
822
|
-
* Provider-specific options.
|
|
335
|
+
* Provider-specific options.
|
|
823
336
|
*/
|
|
824
337
|
providerOptions?: ProviderOptions;
|
|
825
338
|
} | {
|
|
@@ -973,11 +486,630 @@ type ToolResultOutput = {
|
|
|
973
486
|
}>;
|
|
974
487
|
};
|
|
975
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
|
+
|
|
976
1098
|
/**
|
|
977
1099
|
* A context object that is passed into tool execution.
|
|
978
1100
|
*/
|
|
979
1101
|
type Context = Record<string, unknown>;
|
|
980
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
|
+
|
|
981
1113
|
/**
|
|
982
1114
|
* Tool approval request prompt part.
|
|
983
1115
|
*/
|
|
@@ -1102,14 +1234,6 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
|
|
1102
1234
|
*/
|
|
1103
1235
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
1104
1236
|
|
|
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
|
-
|
|
1113
1237
|
/**
|
|
1114
1238
|
* Additional options that are sent into each tool execution.
|
|
1115
1239
|
*/
|
|
@@ -1140,6 +1264,11 @@ interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
|
|
|
1140
1264
|
*/
|
|
1141
1265
|
context: CONTEXT;
|
|
1142
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
|
+
|
|
1143
1272
|
/**
|
|
1144
1273
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1145
1274
|
*
|
|
@@ -1168,15 +1297,17 @@ type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never>
|
|
|
1168
1297
|
*/
|
|
1169
1298
|
context: CONTEXT;
|
|
1170
1299
|
}) => boolean | PromiseLike<boolean>;
|
|
1300
|
+
|
|
1171
1301
|
/**
|
|
1172
|
-
*
|
|
1173
|
-
*/
|
|
1174
|
-
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1175
|
-
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
1176
|
-
/**
|
|
1177
|
-
* Helper type to determine the output properties of a tool.
|
|
1302
|
+
* Helper type to determine the outputSchema and execute function properties of a tool.
|
|
1178
1303
|
*/
|
|
1179
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>;
|
|
1180
1311
|
/**
|
|
1181
1312
|
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1182
1313
|
* If not provided, the tool will not be executed automatically.
|
|
@@ -1185,30 +1316,19 @@ type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context | unknown | nev
|
|
|
1185
1316
|
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
1186
1317
|
*/
|
|
1187
1318
|
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1188
|
-
/**
|
|
1189
|
-
* The schema of the output that the tool produces.
|
|
1190
|
-
*/
|
|
1191
|
-
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
1192
1319
|
} | {
|
|
1193
1320
|
/**
|
|
1194
1321
|
* The schema of the output that the tool produces.
|
|
1322
|
+
*
|
|
1323
|
+
* Required when no execute function is provided.
|
|
1195
1324
|
*/
|
|
1196
1325
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
1197
1326
|
execute?: never;
|
|
1198
1327
|
}>;
|
|
1199
1328
|
/**
|
|
1200
|
-
*
|
|
1201
|
-
* This enables the language model to generate the input.
|
|
1202
|
-
*
|
|
1203
|
-
* 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.
|
|
1204
1330
|
*/
|
|
1205
|
-
type
|
|
1206
|
-
/**
|
|
1207
|
-
* An optional description of what the tool does.
|
|
1208
|
-
* Will be used by the language model to decide whether to use the tool.
|
|
1209
|
-
* Not used for provider-defined tools.
|
|
1210
|
-
*/
|
|
1211
|
-
description?: string;
|
|
1331
|
+
type BaseTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = {
|
|
1212
1332
|
/**
|
|
1213
1333
|
* An optional title of the tool.
|
|
1214
1334
|
*/
|
|
@@ -1227,13 +1347,6 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1227
1347
|
* You can use descriptions on the schema properties to make the input understandable for the language model.
|
|
1228
1348
|
*/
|
|
1229
1349
|
inputSchema: FlexibleSchema<INPUT>;
|
|
1230
|
-
/**
|
|
1231
|
-
* An optional list of input examples that show the language
|
|
1232
|
-
* model what the input should look like.
|
|
1233
|
-
*/
|
|
1234
|
-
inputExamples?: Array<{
|
|
1235
|
-
input: NoInfer<INPUT>;
|
|
1236
|
-
}>;
|
|
1237
1350
|
/**
|
|
1238
1351
|
* An optional schema describing the context that the tool expects.
|
|
1239
1352
|
*
|
|
@@ -1253,14 +1366,6 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1253
1366
|
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
1254
1367
|
INPUT
|
|
1255
1368
|
] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
|
|
1256
|
-
/**
|
|
1257
|
-
* Strict mode setting for the tool.
|
|
1258
|
-
*
|
|
1259
|
-
* Providers that support strict mode will use this setting to determine
|
|
1260
|
-
* how the input should be generated. Strict mode will always produce
|
|
1261
|
-
* valid inputs, but it might limit what input schemas are supported.
|
|
1262
|
-
*/
|
|
1263
|
-
strict?: boolean;
|
|
1264
1369
|
/**
|
|
1265
1370
|
* Optional function that is called when the argument streaming starts.
|
|
1266
1371
|
* Only called when the tool is used in a streaming context.
|
|
@@ -1280,7 +1385,6 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1280
1385
|
onInputAvailable?: (options: {
|
|
1281
1386
|
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
1282
1387
|
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1283
|
-
} & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>> & {
|
|
1284
1388
|
/**
|
|
1285
1389
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1286
1390
|
*
|
|
@@ -1302,34 +1406,86 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1302
1406
|
*/
|
|
1303
1407
|
output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
|
|
1304
1408
|
}) => ToolResultOutput | PromiseLike<ToolResultOutput>;
|
|
1305
|
-
} &
|
|
1409
|
+
} & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>>;
|
|
1410
|
+
/**
|
|
1411
|
+
* Common properties shared by function-style tools.
|
|
1412
|
+
*/
|
|
1413
|
+
type BaseFunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1306
1414
|
/**
|
|
1307
|
-
*
|
|
1415
|
+
* An optional description of what the tool does.
|
|
1416
|
+
* Will be used by the language model to decide whether to use the tool.
|
|
1308
1417
|
*/
|
|
1309
|
-
|
|
1310
|
-
} | {
|
|
1418
|
+
description?: string;
|
|
1311
1419
|
/**
|
|
1312
|
-
*
|
|
1313
|
-
*
|
|
1420
|
+
* Strict mode setting for the tool.
|
|
1421
|
+
*
|
|
1422
|
+
* Providers that support strict mode will use this setting to determine
|
|
1423
|
+
* how the input should be generated. Strict mode will always produce
|
|
1424
|
+
* valid inputs, but it might limit what input schemas are supported.
|
|
1314
1425
|
*/
|
|
1315
|
-
|
|
1316
|
-
} | {
|
|
1426
|
+
strict?: boolean;
|
|
1317
1427
|
/**
|
|
1318
|
-
*
|
|
1428
|
+
* An optional list of input examples that show the language
|
|
1429
|
+
* model what the input should look like.
|
|
1319
1430
|
*/
|
|
1431
|
+
inputExamples?: Array<{
|
|
1432
|
+
input: NoInfer<INPUT>;
|
|
1433
|
+
}>;
|
|
1434
|
+
id?: never;
|
|
1435
|
+
isProviderExecuted?: never;
|
|
1436
|
+
args?: never;
|
|
1437
|
+
supportsDeferredResults?: never;
|
|
1438
|
+
};
|
|
1439
|
+
/**
|
|
1440
|
+
* Tool with user-defined input and output schemas.
|
|
1441
|
+
*/
|
|
1442
|
+
type FunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1443
|
+
type?: undefined | 'function';
|
|
1444
|
+
};
|
|
1445
|
+
/**
|
|
1446
|
+
* Tool that is defined at runtime (e.g. an MCP tool).
|
|
1447
|
+
* The types of input and output are not known at development time.
|
|
1448
|
+
*/
|
|
1449
|
+
type DynamicTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1450
|
+
type: 'dynamic';
|
|
1451
|
+
};
|
|
1452
|
+
/**
|
|
1453
|
+
* Common properties shared by provider tools.
|
|
1454
|
+
*/
|
|
1455
|
+
type BaseProviderTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1320
1456
|
type: 'provider';
|
|
1321
1457
|
/**
|
|
1322
1458
|
* The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
|
|
1323
1459
|
*/
|
|
1324
1460
|
id: `${string}.${string}`;
|
|
1461
|
+
/**
|
|
1462
|
+
* The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
|
1463
|
+
*/
|
|
1464
|
+
args: Record<string, unknown>;
|
|
1465
|
+
description?: never;
|
|
1466
|
+
strict?: never;
|
|
1467
|
+
inputExamples?: never;
|
|
1468
|
+
};
|
|
1469
|
+
/**
|
|
1470
|
+
* Tool with provider-defined input and output schemas that is executed by the
|
|
1471
|
+
* user.
|
|
1472
|
+
*/
|
|
1473
|
+
type ProviderDefinedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1325
1474
|
/**
|
|
1326
1475
|
* Flag that indicates whether the tool is executed by the provider.
|
|
1327
1476
|
*/
|
|
1328
|
-
isProviderExecuted:
|
|
1477
|
+
isProviderExecuted: false;
|
|
1478
|
+
supportsDeferredResults?: never;
|
|
1479
|
+
};
|
|
1480
|
+
/**
|
|
1481
|
+
* Tool with provider-defined input and output schemas that is executed by the
|
|
1482
|
+
* provider.
|
|
1483
|
+
*/
|
|
1484
|
+
type ProviderExecutedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1329
1485
|
/**
|
|
1330
|
-
*
|
|
1486
|
+
* Flag that indicates whether the tool is executed by the provider.
|
|
1331
1487
|
*/
|
|
1332
|
-
|
|
1488
|
+
isProviderExecuted: true;
|
|
1333
1489
|
/**
|
|
1334
1490
|
* Whether this provider-executed tool supports deferred results.
|
|
1335
1491
|
*
|
|
@@ -1344,76 +1500,28 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1344
1500
|
* @default false
|
|
1345
1501
|
*/
|
|
1346
1502
|
supportsDeferredResults?: boolean;
|
|
1347
|
-
}
|
|
1503
|
+
};
|
|
1504
|
+
/**
|
|
1505
|
+
* A tool can either be user-defined or provider-defined.
|
|
1506
|
+
*
|
|
1507
|
+
* It contains the schemas and metadata needed for the language model to call
|
|
1508
|
+
* the tool and can include an execute function for tools that are executed by
|
|
1509
|
+
* the AI SDK.
|
|
1510
|
+
*/
|
|
1511
|
+
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>;
|
|
1348
1512
|
/**
|
|
1349
|
-
*
|
|
1513
|
+
* Infer the tool type from a tool object.
|
|
1514
|
+
*
|
|
1515
|
+
* This is useful for type inference when working with tool objects.
|
|
1350
1516
|
*/
|
|
1351
1517
|
declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1352
1518
|
declare function tool<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
|
|
1353
1519
|
declare function tool<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
|
|
1354
1520
|
declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
|
|
1355
1521
|
/**
|
|
1356
|
-
*
|
|
1522
|
+
* Define a dynamic tool.
|
|
1357
1523
|
*/
|
|
1358
|
-
declare function dynamicTool(tool:
|
|
1359
|
-
/**
|
|
1360
|
-
* An optional description of what the tool does.
|
|
1361
|
-
* Will be used by the language model to decide whether to use the tool.
|
|
1362
|
-
* Not used for provider-defined tools.
|
|
1363
|
-
*/
|
|
1364
|
-
description?: string;
|
|
1365
|
-
/**
|
|
1366
|
-
* An optional title of the tool.
|
|
1367
|
-
*/
|
|
1368
|
-
title?: string;
|
|
1369
|
-
/**
|
|
1370
|
-
* Additional provider-specific metadata. They are passed through
|
|
1371
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
1372
|
-
* functionality that can be fully encapsulated in the provider.
|
|
1373
|
-
*/
|
|
1374
|
-
providerOptions?: ProviderOptions;
|
|
1375
|
-
/**
|
|
1376
|
-
* The schema of the input that the tool expects.
|
|
1377
|
-
* The language model will use this to generate the input.
|
|
1378
|
-
* It is also used to validate the output of the language model.
|
|
1379
|
-
*
|
|
1380
|
-
* You can use descriptions on the schema properties to make the input understandable for the language model.
|
|
1381
|
-
*/
|
|
1382
|
-
inputSchema: FlexibleSchema<unknown>;
|
|
1383
|
-
/**
|
|
1384
|
-
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1385
|
-
* If not provided, the tool will not be executed automatically.
|
|
1386
|
-
*
|
|
1387
|
-
* @args is the input of the tool call.
|
|
1388
|
-
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
1389
|
-
*/
|
|
1390
|
-
execute: ToolExecuteFunction<unknown, unknown, Context>;
|
|
1391
|
-
/**
|
|
1392
|
-
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1393
|
-
*
|
|
1394
|
-
* If not provided, the tool result will be sent as a JSON object.
|
|
1395
|
-
*/
|
|
1396
|
-
toModelOutput?: (options: {
|
|
1397
|
-
/**
|
|
1398
|
-
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1399
|
-
*/
|
|
1400
|
-
toolCallId: string;
|
|
1401
|
-
/**
|
|
1402
|
-
* The input of the tool call.
|
|
1403
|
-
*/
|
|
1404
|
-
input: unknown;
|
|
1405
|
-
/**
|
|
1406
|
-
* The output of the tool call.
|
|
1407
|
-
*/
|
|
1408
|
-
output: unknown;
|
|
1409
|
-
}) => ToolResultOutput | PromiseLike<ToolResultOutput>;
|
|
1410
|
-
/**
|
|
1411
|
-
* Whether the tool needs approval before it can be executed.
|
|
1412
|
-
*/
|
|
1413
|
-
needsApproval?: boolean | ToolNeedsApprovalFunction<unknown, Context>;
|
|
1414
|
-
}): Tool<unknown, unknown, Context> & {
|
|
1415
|
-
type: 'dynamic';
|
|
1416
|
-
};
|
|
1524
|
+
declare function dynamicTool(tool: Omit<DynamicTool<unknown, unknown, Context>, 'type'>): DynamicTool<unknown, unknown, Context>;
|
|
1417
1525
|
|
|
1418
1526
|
/**
|
|
1419
1527
|
* A provider-defined tool is a tool for which the provider defines the input
|
|
@@ -1426,7 +1534,7 @@ type ProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Cont
|
|
|
1426
1534
|
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1427
1535
|
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1428
1536
|
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1429
|
-
}) =>
|
|
1537
|
+
}) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
|
|
1430
1538
|
declare function createProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
|
|
1431
1539
|
id: `${string}.${string}`;
|
|
1432
1540
|
inputSchema: FlexibleSchema<INPUT>;
|
|
@@ -1438,7 +1546,7 @@ type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends obje
|
|
|
1438
1546
|
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1439
1547
|
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1440
1548
|
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1441
|
-
}) =>
|
|
1549
|
+
}) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
|
|
1442
1550
|
declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, }: {
|
|
1443
1551
|
id: `${string}.${string}`;
|
|
1444
1552
|
inputSchema: FlexibleSchema<INPUT>;
|
|
@@ -1452,7 +1560,7 @@ type ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT ext
|
|
|
1452
1560
|
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1453
1561
|
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1454
1562
|
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1455
|
-
}) =>
|
|
1563
|
+
}) => ProviderExecutedTool<INPUT, OUTPUT, CONTEXT>;
|
|
1456
1564
|
declare function createProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
|
|
1457
1565
|
id: `${string}.${string}`;
|
|
1458
1566
|
inputSchema: FlexibleSchema<INPUT>;
|
|
@@ -1530,6 +1638,22 @@ type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
|
|
|
1530
1638
|
*/
|
|
1531
1639
|
declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
|
1532
1640
|
|
|
1641
|
+
/**
|
|
1642
|
+
* Resolves a file part's media type to a full `type/subtype` form required by
|
|
1643
|
+
* providers whose API demands the full IANA media type.
|
|
1644
|
+
*
|
|
1645
|
+
* - If `part.mediaType` is already a full media type (e.g. `image/png`), it is
|
|
1646
|
+
* returned as-is.
|
|
1647
|
+
* - Otherwise, when inline bytes are available (`part.data.type === 'data'`),
|
|
1648
|
+
* the subtype is sniffed from the bytes using the signature table that
|
|
1649
|
+
* corresponds to the top-level segment.
|
|
1650
|
+
* - When neither applies (e.g. top-level-only with a URL source, or bytes that
|
|
1651
|
+
* cannot be detected), an `UnsupportedFunctionalityError` is thrown.
|
|
1652
|
+
*/
|
|
1653
|
+
declare function resolveFullMediaType({ part, }: {
|
|
1654
|
+
part: LanguageModelV4FilePart;
|
|
1655
|
+
}): string;
|
|
1656
|
+
|
|
1533
1657
|
/**
|
|
1534
1658
|
* Resolves a provider reference to the provider-specific identifier for the
|
|
1535
1659
|
* given provider. Throws `NoSuchProviderReferenceError` if the provider is not
|
|
@@ -1847,4 +1971,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1847
1971
|
dynamic?: boolean;
|
|
1848
1972
|
}
|
|
1849
1973
|
|
|
1850
|
-
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type ExecutableTool, type FetchFunction, type FilePart, type FlexibleSchema, 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 ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, 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, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isExecutableTool, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1974
|
+
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 };
|