@ai-sdk/provider-utils 5.0.51 → 5.0.53
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 +18 -0
- package/dist/experimental-evaluation/index.d.ts +23 -22
- package/dist/experimental-evaluation/index.d.ts.map +1 -0
- package/dist/experimental-evaluation/index.js +1216 -1506
- package/dist/experimental-evaluation/index.js.map +1 -1
- package/dist/index.d.ts +1749 -1644
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4363 -4716
- package/dist/index.js.map +1 -1
- package/dist/test/index.d.ts +24 -17
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +48 -73
- package/dist/test/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/is-valid-hostname-part.ts +12 -0
- package/src/transcription-stream-envelope.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { AISDKError, APICallError, Experimental_BatchV4Status, Experimental_TranscriptionModelV4StreamPart, ImageModelV4File, JSONObject, JSONParseError, JSONSchema7, JSONValue, LanguageModelV4CallOptions, LanguageModelV4FilePart, LanguageModelV4FunctionTool, LanguageModelV4Prompt, LanguageModelV4ProviderTool, LanguageModelV4ResponseMetadata, LanguageModelV4StreamPart, LanguageModelV4Usage, SharedV4FileDataReference, SharedV4FileDataText, SharedV4FileDataUrl, SharedV4ProviderMetadata, SharedV4ProviderOptions, SharedV4ProviderReference, SharedV4Warning, TypeValidationContext, TypeValidationError, getErrorMessage } from "@ai-sdk/provider";
|
|
2
|
+
import { $ZodType } from "zod/v4/core";
|
|
3
|
+
import { EventSourceMessage, EventSourceParserStream } from "eventsource-parser/stream";
|
|
4
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
5
|
+
import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
import * as z3 from "zod/v3";
|
|
7
|
+
export type * from "@standard-schema/spec";
|
|
8
|
+
//#region src/as-array.d.ts
|
|
10
9
|
/**
|
|
11
10
|
* A value that can be provided either as a single item, an array of items,
|
|
12
11
|
* or be left undefined.
|
|
@@ -15,36 +14,38 @@ type Arrayable<T> = T | T[] | undefined;
|
|
|
15
14
|
/**
|
|
16
15
|
* Normalizes a possibly undefined or non-array value into an array.
|
|
17
16
|
*/
|
|
18
|
-
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
export declare function asArray<T>(value: Arrayable<T>): T[];
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/combine-headers.d.ts
|
|
20
|
+
export declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/websocket.d.ts
|
|
22
23
|
type WebSocketLike = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
readyState: number;
|
|
25
|
+
/** Bytes queued by `send` but not yet transmitted (native + `ws`). */
|
|
26
|
+
readonly bufferedAmount?: number;
|
|
27
|
+
send(data: string | Uint8Array | ArrayBuffer): void;
|
|
28
|
+
close(code?: number, reason?: string): void;
|
|
29
|
+
onopen: ((event: unknown) => void) | null;
|
|
30
|
+
onmessage: ((event: {
|
|
31
|
+
data: unknown;
|
|
32
|
+
}) => void) | null;
|
|
33
|
+
onerror: ((event: unknown) => void) | null;
|
|
34
|
+
onclose: ((event: unknown) => void) | null;
|
|
34
35
|
};
|
|
35
36
|
type WebSocketConstructor = new (url: string | URL, protocols?: string | string[], options?: {
|
|
36
|
-
|
|
37
|
+
headers?: Record<string, string | undefined>;
|
|
37
38
|
}) => WebSocketLike;
|
|
38
|
-
declare function getWebSocketConstructor(webSocket: WebSocketConstructor | undefined): WebSocketConstructor;
|
|
39
|
+
export declare function getWebSocketConstructor(webSocket: WebSocketConstructor | undefined): WebSocketConstructor;
|
|
39
40
|
/**
|
|
40
41
|
* Converts an http(s) URL to the corresponding ws(s) URL.
|
|
41
42
|
*/
|
|
42
|
-
declare function toWebSocketUrl(url: string | URL): URL;
|
|
43
|
+
export declare function toWebSocketUrl(url: string | URL): URL;
|
|
43
44
|
/**
|
|
44
45
|
* Reads WebSocket message data as text, handling string, binary,
|
|
45
46
|
* and Blob payloads.
|
|
46
47
|
*/
|
|
47
|
-
declare function readWebSocketMessageText(data: unknown): Promise<string>;
|
|
48
|
+
export declare function readWebSocketMessageText(data: unknown): Promise<string>;
|
|
48
49
|
/**
|
|
49
50
|
* Waits until the socket's send buffer drains below `highWaterMark` bytes.
|
|
50
51
|
* No-op for implementations that do not expose `bufferedAmount`. There is no
|
|
@@ -52,20 +53,21 @@ declare function readWebSocketMessageText(data: unknown): Promise<string>;
|
|
|
52
53
|
* longer open or the signal aborts — `bufferedAmount` never drains on a
|
|
53
54
|
* closed socket, so waiting on would poll forever.
|
|
54
55
|
*/
|
|
55
|
-
declare function waitForWebSocketBufferDrain(socket: WebSocketLike, { highWaterMark, pollIntervalMs, abortSignal
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
export declare function waitForWebSocketBufferDrain(socket: WebSocketLike, { highWaterMark, pollIntervalMs, abortSignal }?: {
|
|
57
|
+
highWaterMark?: number;
|
|
58
|
+
pollIntervalMs?: number;
|
|
59
|
+
abortSignal?: AbortSignal;
|
|
59
60
|
}): Promise<void>;
|
|
60
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/connect-to-websocket.d.ts
|
|
61
63
|
interface WebSocketConnection {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
/** Undefined when the constructor threw or the signal was already aborted. */
|
|
65
|
+
socket: WebSocketLike | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Unregisters the abort listener and closes the socket. Never throws.
|
|
68
|
+
* Handlers stay attached; callers guard their own terminal state.
|
|
69
|
+
*/
|
|
70
|
+
close: (code?: number) => void;
|
|
69
71
|
}
|
|
70
72
|
/**
|
|
71
73
|
* Opens a WebSocket for a provider model, owning the transport-generic layer
|
|
@@ -73,30 +75,31 @@ interface WebSocketConnection {
|
|
|
73
75
|
* abort wiring, and message decoding. Callers own the URL, the auth channel
|
|
74
76
|
* (subprotocols vs headers), and the wire protocol.
|
|
75
77
|
*/
|
|
76
|
-
declare function connectToWebSocket({ url, protocols, headers, webSocket, abortSignal, onOpen, onMessageText, onProcessingError, onSocketError, onClose, onAbort
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
78
|
+
export declare function connectToWebSocket({ url, protocols, headers, webSocket, abortSignal, onOpen, onMessageText, onProcessingError, onSocketError, onClose, onAbort }: {
|
|
79
|
+
url: string | URL;
|
|
80
|
+
protocols?: string | string[];
|
|
81
|
+
headers?: Record<string, string | undefined>;
|
|
82
|
+
webSocket?: WebSocketConstructor;
|
|
83
|
+
abortSignal?: AbortSignal;
|
|
84
|
+
onOpen?: (socket: WebSocketLike) => void;
|
|
85
|
+
/** One decoded message. Throws and rejections go to `onProcessingError`. */
|
|
86
|
+
onMessageText: (text: string) => void | PromiseLike<void>;
|
|
87
|
+
/** Constructor throws and message decoding/processing failures. */
|
|
88
|
+
onProcessingError: (error: unknown) => void;
|
|
89
|
+
onSocketError?: () => void;
|
|
90
|
+
/**
|
|
91
|
+
* Receives the close code and reason when the transport provides them
|
|
92
|
+
* (native `CloseEvent` / `ws` close event).
|
|
93
|
+
*/
|
|
94
|
+
onClose?: (info: {
|
|
95
|
+
code?: number;
|
|
96
|
+
reason?: string;
|
|
97
|
+
}) => void;
|
|
98
|
+
/** Also called (without opening a socket) when the signal is already aborted. */
|
|
99
|
+
onAbort?: (reason: unknown) => void;
|
|
98
100
|
}): WebSocketConnection;
|
|
99
|
-
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/convert-async-iterator-to-readable-stream.d.ts
|
|
100
103
|
/**
|
|
101
104
|
* Converts an AsyncIterator to a ReadableStream.
|
|
102
105
|
*
|
|
@@ -104,13 +107,15 @@ declare function connectToWebSocket({ url, protocols, headers, webSocket, abortS
|
|
|
104
107
|
* @param { <T>} iterator - The AsyncIterator to convert.
|
|
105
108
|
* @returns {ReadableStream<T>} - A ReadableStream that provides the same data as the AsyncIterator.
|
|
106
109
|
*/
|
|
107
|
-
declare function convertAsyncIteratorToReadableStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
108
|
-
|
|
110
|
+
export declare function convertAsyncIteratorToReadableStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/types/data-content.d.ts
|
|
109
113
|
/**
|
|
110
114
|
* Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
|
111
115
|
*/
|
|
112
116
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
113
|
-
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/types/file-data.d.ts
|
|
114
119
|
/**
|
|
115
120
|
* File data variant containing raw bytes (`Uint8Array`, `ArrayBuffer`, or
|
|
116
121
|
* `Buffer`) or a base64-encoded string.
|
|
@@ -118,8 +123,8 @@ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
|
118
123
|
* This is slightly more permissive than `SharedV4FileDataData`.
|
|
119
124
|
*/
|
|
120
125
|
interface FileDataData {
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
type: 'data';
|
|
127
|
+
data: DataContent;
|
|
123
128
|
}
|
|
124
129
|
/**
|
|
125
130
|
* File data variant containing a URL that points to the file.
|
|
@@ -144,7 +149,8 @@ type FileDataText = SharedV4FileDataText;
|
|
|
144
149
|
* - `{ type: 'text', text }`: inline text content (e.g. an inline text document).
|
|
145
150
|
*/
|
|
146
151
|
type FileData = FileDataData | FileDataUrl | FileDataReference | FileDataText;
|
|
147
|
-
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/types/provider-options.d.ts
|
|
148
154
|
/**
|
|
149
155
|
* Additional provider-specific options.
|
|
150
156
|
*
|
|
@@ -152,7 +158,8 @@ type FileData = FileDataData | FileDataUrl | FileDataReference | FileDataText;
|
|
|
152
158
|
* provider-specific functionality that can be fully encapsulated in the provider.
|
|
153
159
|
*/
|
|
154
160
|
type ProviderOptions = SharedV4ProviderOptions;
|
|
155
|
-
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/types/provider-reference.d.ts
|
|
156
163
|
/**
|
|
157
164
|
* A mapping of provider names to provider-specific file identifiers.
|
|
158
165
|
*
|
|
@@ -161,22 +168,23 @@ type ProviderOptions = SharedV4ProviderOptions;
|
|
|
161
168
|
* identifier for the same logical file.
|
|
162
169
|
*/
|
|
163
170
|
type ProviderReference = SharedV4ProviderReference;
|
|
164
|
-
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/types/content-part.d.ts
|
|
165
173
|
/**
|
|
166
174
|
* Text content part of a prompt. It contains a string of text.
|
|
167
175
|
*/
|
|
168
176
|
interface TextPart {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
type: 'text';
|
|
178
|
+
/**
|
|
179
|
+
* The text content.
|
|
180
|
+
*/
|
|
181
|
+
text: string;
|
|
182
|
+
/**
|
|
183
|
+
* Additional provider-specific metadata. They are passed through
|
|
184
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
185
|
+
* functionality that can be fully encapsulated in the provider.
|
|
186
|
+
*/
|
|
187
|
+
providerOptions?: ProviderOptions;
|
|
180
188
|
}
|
|
181
189
|
/**
|
|
182
190
|
* Image content part of a prompt. It contains an image.
|
|
@@ -185,48 +193,260 @@ interface TextPart {
|
|
|
185
193
|
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
186
194
|
*/
|
|
187
195
|
interface ImagePart {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
196
|
+
type: 'image';
|
|
197
|
+
/**
|
|
198
|
+
* Image data. Can either be:
|
|
199
|
+
*
|
|
200
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
201
|
+
* - URL: a URL that points to the image
|
|
202
|
+
* - ProviderReference: a provider reference from `uploadFile`
|
|
203
|
+
*/
|
|
204
|
+
image: DataContent | URL | ProviderReference;
|
|
205
|
+
/**
|
|
206
|
+
* Optional IANA media type of the image.
|
|
207
|
+
*
|
|
208
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
209
|
+
*/
|
|
210
|
+
mediaType?: string;
|
|
211
|
+
/**
|
|
212
|
+
* Additional provider-specific metadata. They are passed through
|
|
213
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
214
|
+
* functionality that can be fully encapsulated in the provider.
|
|
215
|
+
*/
|
|
216
|
+
providerOptions?: ProviderOptions;
|
|
209
217
|
}
|
|
210
218
|
/**
|
|
211
219
|
* File content part of a prompt. It contains a file.
|
|
212
220
|
*/
|
|
213
221
|
interface FilePart {
|
|
222
|
+
type: 'file';
|
|
223
|
+
/**
|
|
224
|
+
* File data. Either a tagged shape or a bare shorthand:
|
|
225
|
+
*
|
|
226
|
+
* - `{ type: 'data', data }` or bare `DataContent`: raw bytes
|
|
227
|
+
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
228
|
+
* - `{ type: 'url', url }` or bare `URL`: a URL that points to the file
|
|
229
|
+
* - `{ type: 'reference', reference }` or bare `ProviderReference`:
|
|
230
|
+
* a provider reference from `uploadFile`
|
|
231
|
+
* - `{ type: 'text', text }`: inline text content (tagged only)
|
|
232
|
+
*/
|
|
233
|
+
data: FileData | DataContent | URL | ProviderReference;
|
|
234
|
+
/**
|
|
235
|
+
* Optional filename of the file.
|
|
236
|
+
*/
|
|
237
|
+
filename?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
|
|
240
|
+
* the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
|
|
241
|
+
*
|
|
242
|
+
* `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
|
|
243
|
+
* top-level segment alone (e.g. `image`). Providers can use the helpers in
|
|
244
|
+
* `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
|
|
245
|
+
* `detectMediaType`) to resolve the field according to their API
|
|
246
|
+
* requirements.
|
|
247
|
+
*
|
|
248
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
249
|
+
*/
|
|
250
|
+
mediaType: string;
|
|
251
|
+
/**
|
|
252
|
+
* Additional provider-specific metadata. They are passed through
|
|
253
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
254
|
+
* functionality that can be fully encapsulated in the provider.
|
|
255
|
+
*/
|
|
256
|
+
providerOptions?: ProviderOptions;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Reasoning content part of a prompt. It contains a reasoning.
|
|
260
|
+
*/
|
|
261
|
+
interface ReasoningPart {
|
|
262
|
+
type: 'reasoning';
|
|
263
|
+
/**
|
|
264
|
+
* The reasoning text.
|
|
265
|
+
*/
|
|
266
|
+
text: string;
|
|
267
|
+
/**
|
|
268
|
+
* Additional provider-specific metadata. They are passed through
|
|
269
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
270
|
+
* functionality that can be fully encapsulated in the provider.
|
|
271
|
+
*/
|
|
272
|
+
providerOptions?: ProviderOptions;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Custom content part of a prompt. It contains no standardized payload beyond
|
|
276
|
+
* provider-specific options.
|
|
277
|
+
*/
|
|
278
|
+
interface CustomPart {
|
|
279
|
+
type: 'custom';
|
|
280
|
+
/**
|
|
281
|
+
* The kind of custom content, in the format `{provider}.{provider-type}`.
|
|
282
|
+
*/
|
|
283
|
+
kind: `${string}.${string}`;
|
|
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
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
|
|
293
|
+
*/
|
|
294
|
+
interface ReasoningFilePart {
|
|
295
|
+
type: 'reasoning-file';
|
|
296
|
+
/**
|
|
297
|
+
* Reasoning file data.
|
|
298
|
+
*
|
|
299
|
+
* Reasoning files originate from a model's reasoning output and are always
|
|
300
|
+
* raw bytes or a fetchable URL. Unlike `FilePart.data`, the `reference` and
|
|
301
|
+
* `text` shapes are not supported here: provider references describe files
|
|
302
|
+
* uploaded by the user (not produced as model output), and reasoning text is
|
|
303
|
+
* carried by `ReasoningPart` rather than as a file.
|
|
304
|
+
*
|
|
305
|
+
* Either a tagged shape or a bare shorthand:
|
|
306
|
+
*
|
|
307
|
+
* - `{ type: 'data', data }` or bare `DataContent`: raw bytes
|
|
308
|
+
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
309
|
+
* - `{ type: 'url', url }` or bare `URL`: a URL that points to the file
|
|
310
|
+
*/
|
|
311
|
+
data: FileDataData | FileDataUrl | DataContent | URL;
|
|
312
|
+
/**
|
|
313
|
+
* IANA media type of the file.
|
|
314
|
+
*
|
|
315
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
316
|
+
*/
|
|
317
|
+
mediaType: string;
|
|
318
|
+
/**
|
|
319
|
+
* Additional provider-specific metadata. They are passed through
|
|
320
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
321
|
+
* functionality that can be fully encapsulated in the provider.
|
|
322
|
+
*/
|
|
323
|
+
providerOptions?: ProviderOptions;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
327
|
+
*/
|
|
328
|
+
interface ToolCallPart {
|
|
329
|
+
type: 'tool-call';
|
|
330
|
+
/**
|
|
331
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
332
|
+
*/
|
|
333
|
+
toolCallId: string;
|
|
334
|
+
/**
|
|
335
|
+
* Name of the tool that is being called.
|
|
336
|
+
*/
|
|
337
|
+
toolName: string;
|
|
338
|
+
/**
|
|
339
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
340
|
+
*/
|
|
341
|
+
input: unknown;
|
|
342
|
+
/**
|
|
343
|
+
* Additional provider-specific metadata. They are passed through
|
|
344
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
345
|
+
* functionality that can be fully encapsulated in the provider.
|
|
346
|
+
*/
|
|
347
|
+
providerOptions?: ProviderOptions;
|
|
348
|
+
/**
|
|
349
|
+
* Whether the tool call was executed by the provider.
|
|
350
|
+
*/
|
|
351
|
+
providerExecuted?: boolean;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
|
355
|
+
*/
|
|
356
|
+
interface ToolResultPart {
|
|
357
|
+
type: 'tool-result';
|
|
358
|
+
/**
|
|
359
|
+
* ID of the tool call that this result is associated with.
|
|
360
|
+
*/
|
|
361
|
+
toolCallId: string;
|
|
362
|
+
/**
|
|
363
|
+
* Name of the tool that generated this result.
|
|
364
|
+
*/
|
|
365
|
+
toolName: string;
|
|
366
|
+
/**
|
|
367
|
+
* Result of the tool call. This is a JSON-serializable object.
|
|
368
|
+
*/
|
|
369
|
+
output: ToolResultOutput;
|
|
370
|
+
/**
|
|
371
|
+
* Additional provider-specific metadata. They are passed through
|
|
372
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
373
|
+
* functionality that can be fully encapsulated in the provider.
|
|
374
|
+
*/
|
|
375
|
+
providerOptions?: ProviderOptions;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Output of a tool result.
|
|
379
|
+
*/
|
|
380
|
+
type ToolResultOutput = {
|
|
381
|
+
/**
|
|
382
|
+
* Text tool output that should be directly sent to the API.
|
|
383
|
+
*/
|
|
384
|
+
type: 'text';
|
|
385
|
+
value: string;
|
|
386
|
+
/**
|
|
387
|
+
* Provider-specific options.
|
|
388
|
+
*/
|
|
389
|
+
providerOptions?: ProviderOptions;
|
|
390
|
+
} | {
|
|
391
|
+
type: 'json';
|
|
392
|
+
value: JSONValue;
|
|
393
|
+
/**
|
|
394
|
+
* Provider-specific options.
|
|
395
|
+
*/
|
|
396
|
+
providerOptions?: ProviderOptions;
|
|
397
|
+
} | {
|
|
398
|
+
/**
|
|
399
|
+
* Type when the user has denied the execution of the tool call.
|
|
400
|
+
*/
|
|
401
|
+
type: 'execution-denied';
|
|
402
|
+
/**
|
|
403
|
+
* Optional reason for the execution denial.
|
|
404
|
+
*/
|
|
405
|
+
reason?: string;
|
|
406
|
+
/**
|
|
407
|
+
* Provider-specific options.
|
|
408
|
+
*/
|
|
409
|
+
providerOptions?: ProviderOptions;
|
|
410
|
+
} | {
|
|
411
|
+
type: 'error-text';
|
|
412
|
+
value: string;
|
|
413
|
+
/**
|
|
414
|
+
* Provider-specific options.
|
|
415
|
+
*/
|
|
416
|
+
providerOptions?: ProviderOptions;
|
|
417
|
+
} | {
|
|
418
|
+
type: 'error-json';
|
|
419
|
+
value: JSONValue;
|
|
420
|
+
/**
|
|
421
|
+
* Provider-specific options.
|
|
422
|
+
*/
|
|
423
|
+
providerOptions?: ProviderOptions;
|
|
424
|
+
} | {
|
|
425
|
+
type: 'content';
|
|
426
|
+
value: Array<{
|
|
427
|
+
type: 'text';
|
|
428
|
+
/**
|
|
429
|
+
* Text content.
|
|
430
|
+
*/
|
|
431
|
+
text: string;
|
|
432
|
+
/**
|
|
433
|
+
* Provider-specific options.
|
|
434
|
+
*/
|
|
435
|
+
providerOptions?: ProviderOptions;
|
|
436
|
+
} | {
|
|
214
437
|
type: 'file';
|
|
215
438
|
/**
|
|
216
|
-
* File data
|
|
439
|
+
* File data as a tagged discriminated union:
|
|
217
440
|
*
|
|
218
|
-
* - `{ type: 'data', data }
|
|
441
|
+
* - `{ type: 'data', data }`: raw bytes
|
|
219
442
|
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
220
|
-
* - `{ type: 'url', url }
|
|
221
|
-
* - `{ type: 'reference', reference }
|
|
222
|
-
*
|
|
223
|
-
* - `{ type: 'text', text }`: inline text content (
|
|
224
|
-
|
|
225
|
-
data: FileData | DataContent | URL | ProviderReference;
|
|
226
|
-
/**
|
|
227
|
-
* Optional filename of the file.
|
|
443
|
+
* - `{ type: 'url', url }`: a URL that points to the file
|
|
444
|
+
* - `{ type: 'reference', reference }`: a provider reference
|
|
445
|
+
* from `uploadFile`
|
|
446
|
+
* - `{ type: 'text', text }`: inline text content (e.g. an inline
|
|
447
|
+
* text document)
|
|
228
448
|
*/
|
|
229
|
-
|
|
449
|
+
data: FileData;
|
|
230
450
|
/**
|
|
231
451
|
* Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
|
|
232
452
|
* the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
|
|
@@ -241,389 +461,178 @@ interface FilePart {
|
|
|
241
461
|
*/
|
|
242
462
|
mediaType: string;
|
|
243
463
|
/**
|
|
244
|
-
*
|
|
245
|
-
|
|
246
|
-
|
|
464
|
+
* Optional filename of the file.
|
|
465
|
+
*/
|
|
466
|
+
filename?: string;
|
|
467
|
+
/**
|
|
468
|
+
* Provider-specific options.
|
|
247
469
|
*/
|
|
248
470
|
providerOptions?: ProviderOptions;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Reasoning content part of a prompt. It contains a reasoning.
|
|
252
|
-
*/
|
|
253
|
-
interface ReasoningPart {
|
|
254
|
-
type: 'reasoning';
|
|
471
|
+
} | {
|
|
255
472
|
/**
|
|
256
|
-
*
|
|
473
|
+
* @deprecated Use 'file' with mediaType + tagged data instead:
|
|
474
|
+
* `{ type: 'file', mediaType, data: { type: 'data', data } }`.
|
|
257
475
|
*/
|
|
258
|
-
|
|
476
|
+
type: 'file-data';
|
|
259
477
|
/**
|
|
260
|
-
*
|
|
261
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
262
|
-
* functionality that can be fully encapsulated in the provider.
|
|
478
|
+
* Base-64 encoded media data.
|
|
263
479
|
*/
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Custom content part of a prompt. It contains no standardized payload beyond
|
|
268
|
-
* provider-specific options.
|
|
269
|
-
*/
|
|
270
|
-
interface CustomPart {
|
|
271
|
-
type: 'custom';
|
|
480
|
+
data: string;
|
|
272
481
|
/**
|
|
273
|
-
*
|
|
482
|
+
* IANA media type.
|
|
483
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
274
484
|
*/
|
|
275
|
-
|
|
485
|
+
mediaType: string;
|
|
276
486
|
/**
|
|
277
|
-
*
|
|
278
|
-
|
|
279
|
-
|
|
487
|
+
* Optional filename of the file.
|
|
488
|
+
*/
|
|
489
|
+
filename?: string;
|
|
490
|
+
/**
|
|
491
|
+
* Provider-specific options.
|
|
280
492
|
*/
|
|
281
493
|
providerOptions?: ProviderOptions;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
|
|
285
|
-
*/
|
|
286
|
-
interface ReasoningFilePart {
|
|
287
|
-
type: 'reasoning-file';
|
|
494
|
+
} | {
|
|
288
495
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* Reasoning files originate from a model's reasoning output and are always
|
|
292
|
-
* raw bytes or a fetchable URL. Unlike `FilePart.data`, the `reference` and
|
|
293
|
-
* `text` shapes are not supported here: provider references describe files
|
|
294
|
-
* uploaded by the user (not produced as model output), and reasoning text is
|
|
295
|
-
* carried by `ReasoningPart` rather than as a file.
|
|
296
|
-
*
|
|
297
|
-
* Either a tagged shape or a bare shorthand:
|
|
298
|
-
*
|
|
299
|
-
* - `{ type: 'data', data }` or bare `DataContent`: raw bytes
|
|
300
|
-
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
301
|
-
* - `{ type: 'url', url }` or bare `URL`: a URL that points to the file
|
|
496
|
+
* @deprecated Use 'file' with mediaType and tagged data instead:
|
|
497
|
+
* `{ type: 'file', mediaType, data: { type: 'url', url: new URL(url) } }`.
|
|
302
498
|
*/
|
|
303
|
-
|
|
499
|
+
type: 'file-url';
|
|
304
500
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
501
|
+
* URL of the file.
|
|
308
502
|
*/
|
|
309
|
-
|
|
503
|
+
url: string;
|
|
310
504
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* functionality that can be fully encapsulated in the provider.
|
|
505
|
+
* IANA media type.
|
|
506
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
314
507
|
*/
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
319
|
-
*/
|
|
320
|
-
interface ToolCallPart {
|
|
321
|
-
type: 'tool-call';
|
|
508
|
+
mediaType?: string;
|
|
322
509
|
/**
|
|
323
|
-
*
|
|
510
|
+
* Provider-specific options.
|
|
324
511
|
*/
|
|
325
|
-
|
|
512
|
+
providerOptions?: ProviderOptions;
|
|
513
|
+
} | {
|
|
326
514
|
/**
|
|
327
|
-
*
|
|
515
|
+
* @deprecated Use 'file' with tagged data instead:
|
|
516
|
+
* `{ type: 'file', mediaType, data: { type: 'reference', reference } }`.
|
|
328
517
|
*/
|
|
329
|
-
|
|
518
|
+
type: 'file-id';
|
|
330
519
|
/**
|
|
331
|
-
*
|
|
520
|
+
* ID of the file.
|
|
521
|
+
*
|
|
522
|
+
* If you use multiple providers, you need to
|
|
523
|
+
* specify the provider specific ids using
|
|
524
|
+
* the Record option. The key is the provider
|
|
525
|
+
* name, e.g. 'openai' or 'anthropic'.
|
|
332
526
|
*/
|
|
333
|
-
|
|
527
|
+
fileId: string | Record<string, string>;
|
|
334
528
|
/**
|
|
335
|
-
*
|
|
336
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
337
|
-
* functionality that can be fully encapsulated in the provider.
|
|
529
|
+
* Provider-specific options.
|
|
338
530
|
*/
|
|
339
531
|
providerOptions?: ProviderOptions;
|
|
532
|
+
} | {
|
|
340
533
|
/**
|
|
341
|
-
*
|
|
534
|
+
* @deprecated Use 'file' with tagged data instead:
|
|
535
|
+
* `{ type: 'file', mediaType, data: { type: 'reference', reference } }`.
|
|
342
536
|
*/
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
|
347
|
-
*/
|
|
348
|
-
interface ToolResultPart {
|
|
349
|
-
type: 'tool-result';
|
|
537
|
+
type: 'file-reference';
|
|
350
538
|
/**
|
|
351
|
-
*
|
|
539
|
+
* Provider-specific references for the file.
|
|
540
|
+
* The key is the provider name, e.g. 'openai' or 'anthropic'.
|
|
352
541
|
*/
|
|
353
|
-
|
|
542
|
+
providerReference: ProviderReference;
|
|
354
543
|
/**
|
|
355
|
-
*
|
|
544
|
+
* Provider-specific options.
|
|
356
545
|
*/
|
|
357
|
-
|
|
546
|
+
providerOptions?: ProviderOptions;
|
|
547
|
+
} | {
|
|
358
548
|
/**
|
|
359
|
-
*
|
|
549
|
+
* @deprecated Use 'file' with mediaType (e.g. 'image' or a specific
|
|
550
|
+
* `image/*` subtype) and tagged data instead:
|
|
551
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
360
552
|
*/
|
|
361
|
-
|
|
553
|
+
type: 'image-data';
|
|
362
554
|
/**
|
|
363
|
-
*
|
|
364
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
365
|
-
* functionality that can be fully encapsulated in the provider.
|
|
555
|
+
* Base-64 encoded image data.
|
|
366
556
|
*/
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Output of a tool result.
|
|
371
|
-
*/
|
|
372
|
-
type ToolResultOutput = {
|
|
557
|
+
data: string;
|
|
373
558
|
/**
|
|
374
|
-
*
|
|
559
|
+
* IANA media type.
|
|
560
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
375
561
|
*/
|
|
376
|
-
|
|
377
|
-
value: string;
|
|
562
|
+
mediaType: string;
|
|
378
563
|
/**
|
|
379
564
|
* Provider-specific options.
|
|
380
565
|
*/
|
|
381
566
|
providerOptions?: ProviderOptions;
|
|
382
|
-
} | {
|
|
383
|
-
|
|
384
|
-
|
|
567
|
+
} | {
|
|
568
|
+
/**
|
|
569
|
+
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
570
|
+
* `image/*` subtype) and tagged data instead:
|
|
571
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'url', url: new URL(url) } }`.
|
|
572
|
+
*/
|
|
573
|
+
type: 'image-url';
|
|
574
|
+
/**
|
|
575
|
+
* URL of the image.
|
|
576
|
+
*/
|
|
577
|
+
url: string;
|
|
385
578
|
/**
|
|
386
579
|
* Provider-specific options.
|
|
387
580
|
*/
|
|
388
581
|
providerOptions?: ProviderOptions;
|
|
389
|
-
} | {
|
|
582
|
+
} | {
|
|
390
583
|
/**
|
|
391
|
-
*
|
|
584
|
+
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
585
|
+
* `image/*` subtype) and tagged data instead:
|
|
586
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'reference', reference } }`.
|
|
392
587
|
*/
|
|
393
|
-
type: '
|
|
588
|
+
type: 'image-file-id';
|
|
394
589
|
/**
|
|
395
|
-
*
|
|
590
|
+
* Image that is referenced using a provider file id.
|
|
591
|
+
*
|
|
592
|
+
* If you use multiple providers, you need to
|
|
593
|
+
* specify the provider specific ids using
|
|
594
|
+
* the Record option. The key is the provider
|
|
595
|
+
* name, e.g. 'openai' or 'anthropic'.
|
|
396
596
|
*/
|
|
397
|
-
|
|
597
|
+
fileId: string | Record<string, string>;
|
|
398
598
|
/**
|
|
399
599
|
* Provider-specific options.
|
|
400
600
|
*/
|
|
401
601
|
providerOptions?: ProviderOptions;
|
|
402
|
-
} | {
|
|
403
|
-
|
|
404
|
-
|
|
602
|
+
} | {
|
|
603
|
+
/**
|
|
604
|
+
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
605
|
+
* `image/*` subtype) and tagged data instead:
|
|
606
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'reference', reference } }`.
|
|
607
|
+
*/
|
|
608
|
+
type: 'image-file-reference';
|
|
609
|
+
/**
|
|
610
|
+
* Provider-specific references for the image file.
|
|
611
|
+
* The key is the provider name, e.g. 'openai' or 'anthropic'.
|
|
612
|
+
*/
|
|
613
|
+
providerReference: ProviderReference;
|
|
405
614
|
/**
|
|
406
615
|
* Provider-specific options.
|
|
407
616
|
*/
|
|
408
617
|
providerOptions?: ProviderOptions;
|
|
409
|
-
} | {
|
|
410
|
-
|
|
411
|
-
|
|
618
|
+
} | {
|
|
619
|
+
/**
|
|
620
|
+
* Custom content part. This can be used to implement
|
|
621
|
+
* provider-specific content parts.
|
|
622
|
+
*/
|
|
623
|
+
type: 'custom';
|
|
412
624
|
/**
|
|
413
625
|
* Provider-specific options.
|
|
414
626
|
*/
|
|
415
627
|
providerOptions?: ProviderOptions;
|
|
416
|
-
}
|
|
417
|
-
type: 'content';
|
|
418
|
-
value: Array<{
|
|
419
|
-
type: 'text';
|
|
420
|
-
/**
|
|
421
|
-
* Text content.
|
|
422
|
-
*/
|
|
423
|
-
text: string;
|
|
424
|
-
/**
|
|
425
|
-
* Provider-specific options.
|
|
426
|
-
*/
|
|
427
|
-
providerOptions?: ProviderOptions;
|
|
428
|
-
} | {
|
|
429
|
-
type: 'file';
|
|
430
|
-
/**
|
|
431
|
-
* File data as a tagged discriminated union:
|
|
432
|
-
*
|
|
433
|
-
* - `{ type: 'data', data }`: raw bytes
|
|
434
|
-
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
435
|
-
* - `{ type: 'url', url }`: a URL that points to the file
|
|
436
|
-
* - `{ type: 'reference', reference }`: a provider reference
|
|
437
|
-
* from `uploadFile`
|
|
438
|
-
* - `{ type: 'text', text }`: inline text content (e.g. an inline
|
|
439
|
-
* text document)
|
|
440
|
-
*/
|
|
441
|
-
data: FileData;
|
|
442
|
-
/**
|
|
443
|
-
* Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
|
|
444
|
-
* the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
|
|
445
|
-
*
|
|
446
|
-
* `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
|
|
447
|
-
* top-level segment alone (e.g. `image`). Providers can use the helpers in
|
|
448
|
-
* `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
|
|
449
|
-
* `detectMediaType`) to resolve the field according to their API
|
|
450
|
-
* requirements.
|
|
451
|
-
*
|
|
452
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
453
|
-
*/
|
|
454
|
-
mediaType: string;
|
|
455
|
-
/**
|
|
456
|
-
* Optional filename of the file.
|
|
457
|
-
*/
|
|
458
|
-
filename?: string;
|
|
459
|
-
/**
|
|
460
|
-
* Provider-specific options.
|
|
461
|
-
*/
|
|
462
|
-
providerOptions?: ProviderOptions;
|
|
463
|
-
} | {
|
|
464
|
-
/**
|
|
465
|
-
* @deprecated Use 'file' with mediaType + tagged data instead:
|
|
466
|
-
* `{ type: 'file', mediaType, data: { type: 'data', data } }`.
|
|
467
|
-
*/
|
|
468
|
-
type: 'file-data';
|
|
469
|
-
/**
|
|
470
|
-
* Base-64 encoded media data.
|
|
471
|
-
*/
|
|
472
|
-
data: string;
|
|
473
|
-
/**
|
|
474
|
-
* IANA media type.
|
|
475
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
476
|
-
*/
|
|
477
|
-
mediaType: string;
|
|
478
|
-
/**
|
|
479
|
-
* Optional filename of the file.
|
|
480
|
-
*/
|
|
481
|
-
filename?: string;
|
|
482
|
-
/**
|
|
483
|
-
* Provider-specific options.
|
|
484
|
-
*/
|
|
485
|
-
providerOptions?: ProviderOptions;
|
|
486
|
-
} | {
|
|
487
|
-
/**
|
|
488
|
-
* @deprecated Use 'file' with mediaType and tagged data instead:
|
|
489
|
-
* `{ type: 'file', mediaType, data: { type: 'url', url: new URL(url) } }`.
|
|
490
|
-
*/
|
|
491
|
-
type: 'file-url';
|
|
492
|
-
/**
|
|
493
|
-
* URL of the file.
|
|
494
|
-
*/
|
|
495
|
-
url: string;
|
|
496
|
-
/**
|
|
497
|
-
* IANA media type.
|
|
498
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
499
|
-
*/
|
|
500
|
-
mediaType?: string;
|
|
501
|
-
/**
|
|
502
|
-
* Provider-specific options.
|
|
503
|
-
*/
|
|
504
|
-
providerOptions?: ProviderOptions;
|
|
505
|
-
} | {
|
|
506
|
-
/**
|
|
507
|
-
* @deprecated Use 'file' with tagged data instead:
|
|
508
|
-
* `{ type: 'file', mediaType, data: { type: 'reference', reference } }`.
|
|
509
|
-
*/
|
|
510
|
-
type: 'file-id';
|
|
511
|
-
/**
|
|
512
|
-
* ID of the file.
|
|
513
|
-
*
|
|
514
|
-
* If you use multiple providers, you need to
|
|
515
|
-
* specify the provider specific ids using
|
|
516
|
-
* the Record option. The key is the provider
|
|
517
|
-
* name, e.g. 'openai' or 'anthropic'.
|
|
518
|
-
*/
|
|
519
|
-
fileId: string | Record<string, string>;
|
|
520
|
-
/**
|
|
521
|
-
* Provider-specific options.
|
|
522
|
-
*/
|
|
523
|
-
providerOptions?: ProviderOptions;
|
|
524
|
-
} | {
|
|
525
|
-
/**
|
|
526
|
-
* @deprecated Use 'file' with tagged data instead:
|
|
527
|
-
* `{ type: 'file', mediaType, data: { type: 'reference', reference } }`.
|
|
528
|
-
*/
|
|
529
|
-
type: 'file-reference';
|
|
530
|
-
/**
|
|
531
|
-
* Provider-specific references for the file.
|
|
532
|
-
* The key is the provider name, e.g. 'openai' or 'anthropic'.
|
|
533
|
-
*/
|
|
534
|
-
providerReference: ProviderReference;
|
|
535
|
-
/**
|
|
536
|
-
* Provider-specific options.
|
|
537
|
-
*/
|
|
538
|
-
providerOptions?: ProviderOptions;
|
|
539
|
-
} | {
|
|
540
|
-
/**
|
|
541
|
-
* @deprecated Use 'file' with mediaType (e.g. 'image' or a specific
|
|
542
|
-
* `image/*` subtype) and tagged data instead:
|
|
543
|
-
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
544
|
-
*/
|
|
545
|
-
type: 'image-data';
|
|
546
|
-
/**
|
|
547
|
-
* Base-64 encoded image data.
|
|
548
|
-
*/
|
|
549
|
-
data: string;
|
|
550
|
-
/**
|
|
551
|
-
* IANA media type.
|
|
552
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
553
|
-
*/
|
|
554
|
-
mediaType: string;
|
|
555
|
-
/**
|
|
556
|
-
* Provider-specific options.
|
|
557
|
-
*/
|
|
558
|
-
providerOptions?: ProviderOptions;
|
|
559
|
-
} | {
|
|
560
|
-
/**
|
|
561
|
-
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
562
|
-
* `image/*` subtype) and tagged data instead:
|
|
563
|
-
* `{ type: 'file', mediaType: 'image', data: { type: 'url', url: new URL(url) } }`.
|
|
564
|
-
*/
|
|
565
|
-
type: 'image-url';
|
|
566
|
-
/**
|
|
567
|
-
* URL of the image.
|
|
568
|
-
*/
|
|
569
|
-
url: string;
|
|
570
|
-
/**
|
|
571
|
-
* Provider-specific options.
|
|
572
|
-
*/
|
|
573
|
-
providerOptions?: ProviderOptions;
|
|
574
|
-
} | {
|
|
575
|
-
/**
|
|
576
|
-
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
577
|
-
* `image/*` subtype) and tagged data instead:
|
|
578
|
-
* `{ type: 'file', mediaType: 'image', data: { type: 'reference', reference } }`.
|
|
579
|
-
*/
|
|
580
|
-
type: 'image-file-id';
|
|
581
|
-
/**
|
|
582
|
-
* Image that is referenced using a provider file id.
|
|
583
|
-
*
|
|
584
|
-
* If you use multiple providers, you need to
|
|
585
|
-
* specify the provider specific ids using
|
|
586
|
-
* the Record option. The key is the provider
|
|
587
|
-
* name, e.g. 'openai' or 'anthropic'.
|
|
588
|
-
*/
|
|
589
|
-
fileId: string | Record<string, string>;
|
|
590
|
-
/**
|
|
591
|
-
* Provider-specific options.
|
|
592
|
-
*/
|
|
593
|
-
providerOptions?: ProviderOptions;
|
|
594
|
-
} | {
|
|
595
|
-
/**
|
|
596
|
-
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
597
|
-
* `image/*` subtype) and tagged data instead:
|
|
598
|
-
* `{ type: 'file', mediaType: 'image', data: { type: 'reference', reference } }`.
|
|
599
|
-
*/
|
|
600
|
-
type: 'image-file-reference';
|
|
601
|
-
/**
|
|
602
|
-
* Provider-specific references for the image file.
|
|
603
|
-
* The key is the provider name, e.g. 'openai' or 'anthropic'.
|
|
604
|
-
*/
|
|
605
|
-
providerReference: ProviderReference;
|
|
606
|
-
/**
|
|
607
|
-
* Provider-specific options.
|
|
608
|
-
*/
|
|
609
|
-
providerOptions?: ProviderOptions;
|
|
610
|
-
} | {
|
|
611
|
-
/**
|
|
612
|
-
* Custom content part. This can be used to implement
|
|
613
|
-
* provider-specific content parts.
|
|
614
|
-
*/
|
|
615
|
-
type: 'custom';
|
|
616
|
-
/**
|
|
617
|
-
* Provider-specific options.
|
|
618
|
-
*/
|
|
619
|
-
providerOptions?: ProviderOptions;
|
|
620
|
-
}>;
|
|
628
|
+
}>;
|
|
621
629
|
};
|
|
622
|
-
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region src/convert-inline-file-data-to-uint8-array.d.ts
|
|
623
632
|
type InlineFileData = Extract<FilePart['data'], {
|
|
624
|
-
|
|
633
|
+
type: 'data';
|
|
625
634
|
} | {
|
|
626
|
-
|
|
635
|
+
type: 'text';
|
|
627
636
|
}>;
|
|
628
637
|
/**
|
|
629
638
|
* Converts inline file data (a tagged `data` or `text` shape) into raw bytes.
|
|
@@ -636,11 +645,12 @@ type InlineFileData = Extract<FilePart['data'], {
|
|
|
636
645
|
* `{ type: 'stream' }` data is rejected: providers without streaming upload
|
|
637
646
|
* support funnel here and surface a clear `UnsupportedFunctionalityError`.
|
|
638
647
|
*/
|
|
639
|
-
declare function convertInlineFileDataToUint8Array(data: InlineFileData | {
|
|
640
|
-
|
|
641
|
-
|
|
648
|
+
export declare function convertInlineFileDataToUint8Array(data: InlineFileData | {
|
|
649
|
+
type: 'stream';
|
|
650
|
+
stream: ReadableStream<Uint8Array>;
|
|
642
651
|
}): Uint8Array;
|
|
643
|
-
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region src/convert-image-model-file-to-data-uri.d.ts
|
|
644
654
|
/**
|
|
645
655
|
* Convert an ImageModelV4File to a URL or data URI string.
|
|
646
656
|
*
|
|
@@ -648,8 +658,9 @@ declare function convertInlineFileDataToUint8Array(data: InlineFileData | {
|
|
|
648
658
|
* If the file is base64 data, it returns a data URI with the base64 data.
|
|
649
659
|
* If the file is a Uint8Array, it converts it to base64 and returns a data URI.
|
|
650
660
|
*/
|
|
651
|
-
declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
|
|
652
|
-
|
|
661
|
+
export declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/convert-to-form-data.d.ts
|
|
653
664
|
/**
|
|
654
665
|
* Converts an input object to FormData for multipart/form-data requests.
|
|
655
666
|
*
|
|
@@ -681,83 +692,88 @@ declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
|
|
|
681
692
|
* });
|
|
682
693
|
* ```
|
|
683
694
|
*/
|
|
684
|
-
declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
|
|
685
|
-
|
|
695
|
+
export declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
|
|
696
|
+
useArrayBrackets?: boolean;
|
|
686
697
|
}): FormData;
|
|
687
|
-
|
|
698
|
+
//#endregion
|
|
699
|
+
//#region src/create-language-model-response-metadata.d.ts
|
|
688
700
|
/**
|
|
689
701
|
* Converts common provider response fields into language model response
|
|
690
702
|
* metadata.
|
|
691
703
|
*/
|
|
692
|
-
declare function createLanguageModelResponseMetadata({ id, model, created
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
704
|
+
export declare function createLanguageModelResponseMetadata({ id, model, created }: {
|
|
705
|
+
id?: string | null;
|
|
706
|
+
model?: string | null;
|
|
707
|
+
created?: number | null;
|
|
696
708
|
}): LanguageModelV4ResponseMetadata;
|
|
697
|
-
|
|
709
|
+
//#endregion
|
|
710
|
+
//#region src/create-null-language-model-usage.d.ts
|
|
698
711
|
/**
|
|
699
712
|
* Creates an empty language model usage result for unavailable usage data.
|
|
700
713
|
*/
|
|
701
|
-
declare function createNullLanguageModelUsage(): LanguageModelV4Usage;
|
|
702
|
-
|
|
714
|
+
export declare function createNullLanguageModelUsage(): LanguageModelV4Usage;
|
|
715
|
+
//#endregion
|
|
716
|
+
//#region src/create-tool-name-mapping.d.ts
|
|
703
717
|
/**
|
|
704
718
|
* Interface for mapping between custom tool names and provider tool names.
|
|
705
719
|
*/
|
|
706
720
|
interface ToolNameMapping {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
721
|
+
/**
|
|
722
|
+
* Maps a custom tool name (used by the client) to the provider's tool name.
|
|
723
|
+
* If the custom tool name does not have a mapping, returns the input name.
|
|
724
|
+
*
|
|
725
|
+
* @param customToolName - The custom name of the tool defined by the client.
|
|
726
|
+
* @returns The corresponding provider tool name, or the input name if not mapped.
|
|
727
|
+
*/
|
|
728
|
+
toProviderToolName: (customToolName: string) => string;
|
|
729
|
+
/**
|
|
730
|
+
* Maps a provider tool name to the custom tool name used by the client.
|
|
731
|
+
* If the provider tool name does not have a mapping, returns the input name.
|
|
732
|
+
*
|
|
733
|
+
* @param providerToolName - The name of the tool as understood by the provider.
|
|
734
|
+
* @returns The corresponding custom tool name, or the input name if not mapped.
|
|
735
|
+
*/
|
|
736
|
+
toCustomToolName: (providerToolName: string) => string;
|
|
723
737
|
}
|
|
724
738
|
/**
|
|
725
739
|
* @param tools - Tools that were passed to the language model.
|
|
726
740
|
* @param providerToolNames - Maps the provider tool ids to the provider tool names.
|
|
727
741
|
*/
|
|
728
|
-
declare function createToolNameMapping({ tools, providerToolNames
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
742
|
+
export declare function createToolNameMapping({ tools, providerToolNames }: {
|
|
743
|
+
/**
|
|
744
|
+
* Tools that were passed to the language model.
|
|
745
|
+
*/
|
|
746
|
+
tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
|
|
747
|
+
/**
|
|
748
|
+
* Maps the provider tool ids to the provider tool names.
|
|
749
|
+
*/
|
|
750
|
+
providerToolNames: Record<`${string}.${string}`, string>;
|
|
737
751
|
}): ToolNameMapping;
|
|
738
|
-
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/create-provider-stream-error.d.ts
|
|
739
754
|
type ProviderStreamError = {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
755
|
+
readonly message: string;
|
|
756
|
+
readonly type?: string;
|
|
757
|
+
readonly code?: string | number;
|
|
758
|
+
readonly statusCode?: number;
|
|
759
|
+
readonly isRetryable?: boolean;
|
|
760
|
+
readonly data: unknown;
|
|
746
761
|
};
|
|
747
762
|
/**
|
|
748
763
|
* Adds provider-owned status and retry metadata to a stream error payload
|
|
749
764
|
* without requiring provider packages to depend on AI SDK Core.
|
|
750
765
|
*/
|
|
751
|
-
declare function createProviderStreamError({ message, type, code, statusCode, isRetryable, data
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
766
|
+
export declare function createProviderStreamError({ message, type, code, statusCode, isRetryable, data }: {
|
|
767
|
+
message: string;
|
|
768
|
+
type?: string;
|
|
769
|
+
code?: string | number;
|
|
770
|
+
statusCode?: number;
|
|
771
|
+
isRetryable?: boolean;
|
|
772
|
+
data: unknown;
|
|
758
773
|
}): ProviderStreamError;
|
|
759
|
-
declare function isProviderStreamError(error: unknown): error is ProviderStreamError;
|
|
760
|
-
|
|
774
|
+
export declare function isProviderStreamError(error: unknown): error is ProviderStreamError;
|
|
775
|
+
//#endregion
|
|
776
|
+
//#region src/delay.d.ts
|
|
761
777
|
/**
|
|
762
778
|
* Creates a Promise that resolves after a specified delay
|
|
763
779
|
* @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
|
|
@@ -765,62 +781,65 @@ declare function isProviderStreamError(error: unknown): error is ProviderStreamE
|
|
|
765
781
|
* @returns A Promise that resolves after the specified delay
|
|
766
782
|
* @throws {DOMException} When the signal is aborted
|
|
767
783
|
*/
|
|
768
|
-
declare function delay(delayInMs?: number | null, options?: {
|
|
769
|
-
|
|
784
|
+
export declare function delay(delayInMs?: number | null, options?: {
|
|
785
|
+
abortSignal?: AbortSignal;
|
|
770
786
|
}): Promise<void>;
|
|
771
|
-
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region src/delayed-promise.d.ts
|
|
772
789
|
/**
|
|
773
790
|
* Delayed promise. It is only constructed once the value is accessed.
|
|
774
791
|
* This is useful to avoid unhandled promise rejections when the promise is created
|
|
775
792
|
* but not accessed.
|
|
776
793
|
*/
|
|
777
|
-
declare class DelayedPromise<T> {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
794
|
+
export declare class DelayedPromise<T> {
|
|
795
|
+
private status;
|
|
796
|
+
private _promise;
|
|
797
|
+
private _resolve;
|
|
798
|
+
private _reject;
|
|
799
|
+
get promise(): Promise<T>;
|
|
800
|
+
resolve(value: T): void;
|
|
801
|
+
reject(error: unknown): void;
|
|
802
|
+
isResolved(): boolean;
|
|
803
|
+
isRejected(): boolean;
|
|
804
|
+
isPending(): boolean;
|
|
788
805
|
}
|
|
789
|
-
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region src/fetch-function.d.ts
|
|
790
808
|
/**
|
|
791
809
|
* Fetch function type (standardizes the version of fetch used).
|
|
792
810
|
*/
|
|
793
|
-
type FetchFunction = typeof globalThis.fetch;
|
|
794
|
-
|
|
811
|
+
export type FetchFunction = typeof globalThis.fetch;
|
|
812
|
+
//#endregion
|
|
813
|
+
//#region src/schema.d.ts
|
|
795
814
|
/**
|
|
796
815
|
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
797
816
|
*/
|
|
798
817
|
declare const schemaSymbol: unique symbol;
|
|
799
818
|
type ValidationResult<OBJECT> = {
|
|
800
|
-
|
|
801
|
-
|
|
819
|
+
success: true;
|
|
820
|
+
value: OBJECT;
|
|
802
821
|
} | {
|
|
803
|
-
|
|
804
|
-
|
|
822
|
+
success: false;
|
|
823
|
+
error: Error;
|
|
805
824
|
};
|
|
806
825
|
type Schema<OBJECT = unknown> = {
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
826
|
+
/**
|
|
827
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
828
|
+
*/
|
|
829
|
+
[schemaSymbol]: true;
|
|
830
|
+
/**
|
|
831
|
+
* Schema type for inference.
|
|
832
|
+
*/
|
|
833
|
+
_type: OBJECT;
|
|
834
|
+
/**
|
|
835
|
+
* Optional. Validates that the structure of a value matches this schema,
|
|
836
|
+
* and returns a typed version of the value if it does.
|
|
837
|
+
*/
|
|
838
|
+
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
839
|
+
/**
|
|
840
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
|
841
|
+
*/
|
|
842
|
+
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
|
824
843
|
};
|
|
825
844
|
/**
|
|
826
845
|
* Creates a schema with deferred creation.
|
|
@@ -830,13 +849,13 @@ type Schema<OBJECT = unknown> = {
|
|
|
830
849
|
* @param createValidator A function that creates a schema.
|
|
831
850
|
* @returns A function that returns a schema.
|
|
832
851
|
*/
|
|
833
|
-
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
|
852
|
+
export declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
|
834
853
|
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
|
835
854
|
type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | $ZodType<SCHEMA, any>;
|
|
836
855
|
type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
856
|
+
readonly '~standard': StandardSchemaV1.Props<unknown, SCHEMA> & {
|
|
857
|
+
readonly jsonSchema?: StandardJSONSchemaV1.Converter;
|
|
858
|
+
};
|
|
840
859
|
};
|
|
841
860
|
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
|
|
842
861
|
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;
|
|
@@ -846,29 +865,30 @@ type InferSchema<SCHEMA> = SCHEMA extends ZodSchema<infer T> ? T : SCHEMA extend
|
|
|
846
865
|
* @param jsonSchema The JSON Schema for the schema.
|
|
847
866
|
* @param options.validate Optional. A validation function for the schema.
|
|
848
867
|
*/
|
|
849
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate
|
|
850
|
-
|
|
868
|
+
export declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate }?: {
|
|
869
|
+
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
851
870
|
}): Schema<OBJECT>;
|
|
852
|
-
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
853
|
-
declare function zodSchema<OBJECT>(zodSchema: $ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
871
|
+
export declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
872
|
+
export declare function zodSchema<OBJECT>(zodSchema: $ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
|
873
|
+
/**
|
|
874
|
+
* Enables support for references in the schema.
|
|
875
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
|
876
|
+
* However, not all language models and providers support such references.
|
|
877
|
+
* Defaults to `false`.
|
|
878
|
+
*/
|
|
879
|
+
useReferences?: boolean;
|
|
861
880
|
}): Schema<OBJECT>;
|
|
862
|
-
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region src/parse-json.d.ts
|
|
863
883
|
/**
|
|
864
884
|
* Parses a JSON string into an unknown object.
|
|
865
885
|
*
|
|
866
886
|
* @param text - The JSON string to parse.
|
|
867
887
|
* @returns {JSONValue} - The parsed JSON object.
|
|
868
888
|
*/
|
|
869
|
-
declare function parseJSON(options: {
|
|
870
|
-
|
|
871
|
-
|
|
889
|
+
export declare function parseJSON(options: {
|
|
890
|
+
text: string;
|
|
891
|
+
schema?: undefined;
|
|
872
892
|
}): Promise<JSONValue>;
|
|
873
893
|
/**
|
|
874
894
|
* Parses a JSON string into a strongly-typed object using the provided schema.
|
|
@@ -878,18 +898,18 @@ declare function parseJSON(options: {
|
|
|
878
898
|
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
879
899
|
* @returns {Promise<T>} - The parsed object.
|
|
880
900
|
*/
|
|
881
|
-
declare function parseJSON<T>(options: {
|
|
882
|
-
|
|
883
|
-
|
|
901
|
+
export declare function parseJSON<T>(options: {
|
|
902
|
+
text: string;
|
|
903
|
+
schema: FlexibleSchema<T>;
|
|
884
904
|
}): Promise<T>;
|
|
885
|
-
type ParseResult<T> = {
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
905
|
+
export type ParseResult<T> = {
|
|
906
|
+
success: true;
|
|
907
|
+
value: T;
|
|
908
|
+
rawValue: unknown;
|
|
889
909
|
} | {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
910
|
+
success: false;
|
|
911
|
+
error: JSONParseError | TypeValidationError;
|
|
912
|
+
rawValue: unknown;
|
|
893
913
|
};
|
|
894
914
|
/**
|
|
895
915
|
* Safely parses a JSON string and returns the result as an object of type `unknown`.
|
|
@@ -897,9 +917,9 @@ type ParseResult<T> = {
|
|
|
897
917
|
* @param text - The JSON string to parse.
|
|
898
918
|
* @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
|
|
899
919
|
*/
|
|
900
|
-
declare function safeParseJSON(options: {
|
|
901
|
-
|
|
902
|
-
|
|
920
|
+
export declare function safeParseJSON(options: {
|
|
921
|
+
text: string;
|
|
922
|
+
schema?: undefined;
|
|
903
923
|
}): Promise<ParseResult<JSONValue>>;
|
|
904
924
|
/**
|
|
905
925
|
* Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
|
|
@@ -909,56 +929,59 @@ declare function safeParseJSON(options: {
|
|
|
909
929
|
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
910
930
|
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
911
931
|
*/
|
|
912
|
-
declare function safeParseJSON<T>(options: {
|
|
913
|
-
|
|
914
|
-
|
|
932
|
+
export declare function safeParseJSON<T>(options: {
|
|
933
|
+
text: string;
|
|
934
|
+
schema: FlexibleSchema<T>;
|
|
915
935
|
}): Promise<ParseResult<T>>;
|
|
916
|
-
declare function isParsableJson(input: string): boolean;
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
936
|
+
export declare function isParsableJson(input: string): boolean;
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/response-handler.d.ts
|
|
939
|
+
export type ResponseHandler<RETURN_TYPE> = (options: {
|
|
940
|
+
url: string;
|
|
941
|
+
requestBodyValues: unknown;
|
|
942
|
+
response: Response;
|
|
922
943
|
}) => PromiseLike<{
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
944
|
+
value: RETURN_TYPE;
|
|
945
|
+
rawValue?: unknown;
|
|
946
|
+
responseHeaders?: Record<string, string>;
|
|
926
947
|
}>;
|
|
927
|
-
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
948
|
+
export declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable }: {
|
|
949
|
+
errorSchema: FlexibleSchema<T>;
|
|
950
|
+
errorToMessage: (error: T) => string;
|
|
951
|
+
isRetryable?: (response: Response, error?: T) => boolean;
|
|
931
952
|
}) => ResponseHandler<APICallError>;
|
|
932
|
-
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
933
|
-
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
934
|
-
declare const createJsonLinesResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<AsyncGenerator<T>>;
|
|
935
|
-
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
953
|
+
export declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
954
|
+
export declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
955
|
+
export declare const createJsonLinesResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<AsyncGenerator<T>>;
|
|
956
|
+
export declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
936
957
|
/**
|
|
937
958
|
* Passes the response body through as a `ReadableStream<Uint8Array>` without
|
|
938
959
|
* buffering it (unlike `createBinaryResponseHandler`). The consumer is
|
|
939
960
|
* responsible for draining or cancelling the stream.
|
|
940
961
|
*/
|
|
941
|
-
declare const createBinaryStreamResponseHandler: () => ResponseHandler<ReadableStream<Uint8Array>>;
|
|
942
|
-
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
943
|
-
|
|
962
|
+
export declare const createBinaryStreamResponseHandler: () => ResponseHandler<ReadableStream<Uint8Array>>;
|
|
963
|
+
export declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
964
|
+
//#endregion
|
|
965
|
+
//#region src/delete-from-api.d.ts
|
|
944
966
|
/**
|
|
945
967
|
* Sends a DELETE request. For URLs built from developer-configured endpoints
|
|
946
968
|
* only — there is no untrusted-URL validation path (use `getFromApi` with
|
|
947
969
|
* `validateUrl` for response-supplied URLs).
|
|
948
970
|
*/
|
|
949
|
-
declare const deleteFromApi: <T>({ url, headers, failedResponseHandler, successfulResponseHandler, abortSignal, fetch
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
971
|
+
export declare const deleteFromApi: <T>({ url, headers, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }: {
|
|
972
|
+
url: string;
|
|
973
|
+
headers?: Record<string, string | undefined>;
|
|
974
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
975
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
976
|
+
abortSignal?: AbortSignal;
|
|
977
|
+
fetch?: FetchFunction;
|
|
956
978
|
}) => Promise<{
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
979
|
+
value: T;
|
|
980
|
+
rawValue?: unknown;
|
|
981
|
+
responseHeaders?: Record<string, string>;
|
|
960
982
|
}>;
|
|
961
|
-
|
|
983
|
+
//#endregion
|
|
984
|
+
//#region src/detect-media-type.d.ts
|
|
962
985
|
/**
|
|
963
986
|
* Detect the IANA media type of a file from its raw bytes or base64 string.
|
|
964
987
|
*
|
|
@@ -969,9 +992,9 @@ declare const deleteFromApi: <T>({ url, headers, failedResponseHandler, successf
|
|
|
969
992
|
* segment are considered. Returns `undefined` for unsupported segments
|
|
970
993
|
* (e.g. `"text"`) or when no signature matches.
|
|
971
994
|
*/
|
|
972
|
-
declare function detectMediaType({ data, topLevelType
|
|
973
|
-
|
|
974
|
-
|
|
995
|
+
export declare function detectMediaType({ data, topLevelType }: {
|
|
996
|
+
data: Uint8Array | string;
|
|
997
|
+
topLevelType?: string;
|
|
975
998
|
}): string | undefined;
|
|
976
999
|
/**
|
|
977
1000
|
* Returns the top-level segment of a media type (the portion before `/`).
|
|
@@ -984,7 +1007,7 @@ declare function detectMediaType({ data, topLevelType, }: {
|
|
|
984
1007
|
* - `""` -> `""`
|
|
985
1008
|
* - `"/"` -> `""`
|
|
986
1009
|
*/
|
|
987
|
-
declare function getTopLevelMediaType(mediaType: string): string;
|
|
1010
|
+
export declare function getTopLevelMediaType(mediaType: string): string;
|
|
988
1011
|
/**
|
|
989
1012
|
* Returns `true` only when the given media type has a non-empty, non-wildcard
|
|
990
1013
|
* subtype (i.e. matches the form `type/subtype`, and `subtype` is not `*`).
|
|
@@ -997,8 +1020,9 @@ declare function getTopLevelMediaType(mediaType: string): string;
|
|
|
997
1020
|
* - `""` -> `false`
|
|
998
1021
|
* - `"/"` -> `false`
|
|
999
1022
|
*/
|
|
1000
|
-
declare function isFullMediaType(mediaType: string): boolean;
|
|
1001
|
-
|
|
1023
|
+
export declare function isFullMediaType(mediaType: string): boolean;
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region src/download-blob.d.ts
|
|
1002
1026
|
/**
|
|
1003
1027
|
* Download a file from a URL and return it as a Blob.
|
|
1004
1028
|
*
|
|
@@ -1010,27 +1034,29 @@ declare function isFullMediaType(mediaType: string): boolean;
|
|
|
1010
1034
|
*
|
|
1011
1035
|
* @throws DownloadError if the download fails or exceeds maxBytes.
|
|
1012
1036
|
*/
|
|
1013
|
-
declare function downloadBlob(url: string, options?: {
|
|
1014
|
-
|
|
1015
|
-
|
|
1037
|
+
export declare function downloadBlob(url: string, options?: {
|
|
1038
|
+
maxBytes?: number;
|
|
1039
|
+
abortSignal?: AbortSignal;
|
|
1016
1040
|
}): Promise<Blob>;
|
|
1017
|
-
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/download-error.d.ts
|
|
1018
1043
|
declare const symbol$1: unique symbol;
|
|
1019
|
-
declare class DownloadError extends AISDKError {
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1044
|
+
export declare class DownloadError extends AISDKError {
|
|
1045
|
+
private readonly [symbol$1];
|
|
1046
|
+
readonly url: string;
|
|
1047
|
+
readonly statusCode?: number;
|
|
1048
|
+
readonly statusText?: string;
|
|
1049
|
+
constructor({ url, statusCode, statusText, cause, message }: {
|
|
1050
|
+
url: string;
|
|
1051
|
+
statusCode?: number;
|
|
1052
|
+
statusText?: string;
|
|
1053
|
+
message?: string;
|
|
1054
|
+
cause?: unknown;
|
|
1055
|
+
});
|
|
1056
|
+
static isInstance(error: unknown): error is DownloadError;
|
|
1032
1057
|
}
|
|
1033
|
-
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region src/embedding-model-capabilities.d.ts
|
|
1034
1060
|
/**
|
|
1035
1061
|
* Symbol for exposing the UTF-8 input byte budget of an embedding model.
|
|
1036
1062
|
*
|
|
@@ -1047,12 +1073,13 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
|
1047
1073
|
*/
|
|
1048
1074
|
declare const EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER: unique symbol;
|
|
1049
1075
|
type EmbeddingModelProviderOptionsTransformer = (options: {
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1076
|
+
providerOptions: SharedV4ProviderOptions | undefined;
|
|
1077
|
+
values: Array<string>;
|
|
1078
|
+
startIndex: number;
|
|
1079
|
+
endIndex: number;
|
|
1054
1080
|
}) => SharedV4ProviderOptions | undefined | PromiseLike<SharedV4ProviderOptions | undefined>;
|
|
1055
|
-
|
|
1081
|
+
//#endregion
|
|
1082
|
+
//#region src/fetch-with-validated-redirects.d.ts
|
|
1056
1083
|
/**
|
|
1057
1084
|
* Fetches one validated URL without following redirects.
|
|
1058
1085
|
*
|
|
@@ -1061,16 +1088,16 @@ type EmbeddingModelProviderOptionsTransformer = (options: {
|
|
|
1061
1088
|
* Redirects are rejected by default. Callers using `redirect: 'manual'` must
|
|
1062
1089
|
* validate the Location target before issuing another request.
|
|
1063
1090
|
*/
|
|
1064
|
-
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1091
|
+
export declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect }: {
|
|
1092
|
+
url: string | URL;
|
|
1093
|
+
init?: RequestInit;
|
|
1094
|
+
fetch?: FetchFunction;
|
|
1095
|
+
/**
|
|
1096
|
+
* A developer-configured origin that may legitimately resolve to a private
|
|
1097
|
+
* address. This must never be derived from untrusted response data.
|
|
1098
|
+
*/
|
|
1099
|
+
trustedOrigin?: string;
|
|
1100
|
+
redirect?: 'error' | 'manual';
|
|
1074
1101
|
}): Promise<Response>;
|
|
1075
1102
|
/**
|
|
1076
1103
|
* Fetches a URL while enforcing the download guard on every hop.
|
|
@@ -1119,19 +1146,20 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
|
|
|
1119
1146
|
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
1120
1147
|
* a redirect cannot be validated on a non-browser runtime.
|
|
1121
1148
|
*/
|
|
1122
|
-
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1149
|
+
export declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin }: {
|
|
1150
|
+
url: string;
|
|
1151
|
+
headers?: HeadersInit;
|
|
1152
|
+
abortSignal?: AbortSignal;
|
|
1153
|
+
maxRedirects?: number;
|
|
1154
|
+
fetch?: FetchFunction;
|
|
1155
|
+
/**
|
|
1156
|
+
* A developer-configured origin (e.g. the provider's `baseURL`) whose hops
|
|
1157
|
+
* skip target validation. Must never be derived from response data.
|
|
1158
|
+
*/
|
|
1159
|
+
trustedOrigin?: string;
|
|
1133
1160
|
}): Promise<Response>;
|
|
1134
|
-
|
|
1161
|
+
//#endregion
|
|
1162
|
+
//#region src/extract-lines.d.ts
|
|
1135
1163
|
/**
|
|
1136
1164
|
* Extracts a 1-based inclusive line range from `text`, auto-detecting the
|
|
1137
1165
|
* file's line ending (`\r\n`, `\n`, or `\r`, in that priority).
|
|
@@ -1141,22 +1169,24 @@ declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRed
|
|
|
1141
1169
|
* cleanly. When neither `startLine` nor `endLine` is provided, the input is
|
|
1142
1170
|
* returned unchanged. `endLine` past EOF clamps to the last line.
|
|
1143
1171
|
*/
|
|
1144
|
-
declare function extractLines({ text, startLine, endLine
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1172
|
+
export declare function extractLines({ text, startLine, endLine }: {
|
|
1173
|
+
text: string;
|
|
1174
|
+
startLine?: number;
|
|
1175
|
+
endLine?: number;
|
|
1148
1176
|
}): string;
|
|
1149
|
-
|
|
1177
|
+
//#endregion
|
|
1178
|
+
//#region src/extract-response-headers.d.ts
|
|
1150
1179
|
/**
|
|
1151
1180
|
* Extracts the headers from a response object and returns them as a key-value object.
|
|
1152
1181
|
*
|
|
1153
1182
|
* @param response - The response object to extract headers from.
|
|
1154
1183
|
* @returns The headers as a key-value object.
|
|
1155
1184
|
*/
|
|
1156
|
-
declare function extractResponseHeaders(response: Response): {
|
|
1157
|
-
|
|
1185
|
+
export declare function extractResponseHeaders(response: Response): {
|
|
1186
|
+
[k: string]: string;
|
|
1158
1187
|
};
|
|
1159
|
-
|
|
1188
|
+
//#endregion
|
|
1189
|
+
//#region src/fetch-untrusted-url.d.ts
|
|
1160
1190
|
/**
|
|
1161
1191
|
* Fetches an untrusted URL with first-hop credential isolation and validated
|
|
1162
1192
|
* redirects. Uses the URL validation, DNS-pinned Node.js transport, redirect
|
|
@@ -1176,30 +1206,32 @@ declare function extractResponseHeaders(response: Response): {
|
|
|
1176
1206
|
* This is an opt-in alternative to `fetchWithValidatedRedirects`, whose
|
|
1177
1207
|
* existing first-hop header behavior is preserved for compatibility.
|
|
1178
1208
|
*/
|
|
1179
|
-
declare function fetchUntrustedUrl({ headers, credentialedOrigin, untrustedFirstHopHeaders, ...options }: Parameters<typeof fetchWithValidatedRedirects>[0] & {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1209
|
+
export declare function fetchUntrustedUrl({ headers, credentialedOrigin, untrustedFirstHopHeaders, ...options }: Parameters<typeof fetchWithValidatedRedirects>[0] & {
|
|
1210
|
+
/**
|
|
1211
|
+
* The developer-configured origin allowed to receive arbitrary caller
|
|
1212
|
+
* headers on the first hop. Defaults to `trustedOrigin` when omitted.
|
|
1213
|
+
* An explicit value takes precedence over `trustedOrigin` and does not
|
|
1214
|
+
* exempt the URL from validation.
|
|
1215
|
+
*/
|
|
1216
|
+
credentialedOrigin?: string;
|
|
1217
|
+
/**
|
|
1218
|
+
* Additional sanitized header names safe to disclose to an untrusted first
|
|
1219
|
+
* hop. Use only for non-credential protocol metadata. Credentials require
|
|
1220
|
+
* a matching `credentialedOrigin` instead. Names are case-insensitive.
|
|
1221
|
+
*/
|
|
1222
|
+
untrustedFirstHopHeaders?: readonly string[];
|
|
1193
1223
|
}): Promise<Response>;
|
|
1194
|
-
|
|
1224
|
+
//#endregion
|
|
1225
|
+
//#region src/filter-nullable.d.ts
|
|
1195
1226
|
/**
|
|
1196
1227
|
* Filters `null` and `undefined` values out of a list of values.
|
|
1197
1228
|
*
|
|
1198
1229
|
* @param values - The values to filter.
|
|
1199
1230
|
* @returns A new array containing only non-nullish values.
|
|
1200
1231
|
*/
|
|
1201
|
-
declare function filterNullable<T>(...values: Array<T | undefined | null>): Array<T>;
|
|
1202
|
-
|
|
1232
|
+
export declare function filterNullable<T>(...values: Array<T | undefined | null>): Array<T>;
|
|
1233
|
+
//#endregion
|
|
1234
|
+
//#region src/generate-id.d.ts
|
|
1203
1235
|
/**
|
|
1204
1236
|
* Creates an ID generator.
|
|
1205
1237
|
* The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
@@ -1210,11 +1242,11 @@ declare function filterNullable<T>(...values: Array<T | undefined | null>): Arra
|
|
|
1210
1242
|
* @param separator - The separator between the prefix and the random part of the ID. Default: '-'.
|
|
1211
1243
|
* @param size - The size of the random part of the ID to generate. Default: 16.
|
|
1212
1244
|
*/
|
|
1213
|
-
declare const createIdGenerator: ({ prefix, size, alphabet, separator
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1245
|
+
export declare const createIdGenerator: ({ prefix, size, alphabet, separator }?: {
|
|
1246
|
+
prefix?: string;
|
|
1247
|
+
separator?: string;
|
|
1248
|
+
size?: number;
|
|
1249
|
+
alphabet?: string;
|
|
1218
1250
|
}) => IdGenerator;
|
|
1219
1251
|
/**
|
|
1220
1252
|
* A function that generates an ID.
|
|
@@ -1224,72 +1256,78 @@ type IdGenerator = () => string;
|
|
|
1224
1256
|
* Generates a 16-character random string to use for IDs.
|
|
1225
1257
|
* Not cryptographically secure.
|
|
1226
1258
|
*/
|
|
1227
|
-
declare const generateId: IdGenerator;
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1259
|
+
export declare const generateId: IdGenerator;
|
|
1260
|
+
//#endregion
|
|
1261
|
+
//#region src/get-from-api.d.ts
|
|
1262
|
+
export declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }: {
|
|
1263
|
+
url: string;
|
|
1264
|
+
headers?: Record<string, string | undefined>;
|
|
1265
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
1266
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1267
|
+
abortSignal?: AbortSignal;
|
|
1268
|
+
fetch?: FetchFunction;
|
|
1269
|
+
/**
|
|
1270
|
+
* Set `true` when `url` is untrusted (e.g. taken from a provider response
|
|
1271
|
+
* body): it is routed through {@link fetchWithValidatedRedirects}, which
|
|
1272
|
+
* rejects private/loopback/link-local targets and re-validates redirect
|
|
1273
|
+
* hops; blocked URLs throw `DownloadError`. Set `false` only for URLs built
|
|
1274
|
+
* from a developer-configured endpoint.
|
|
1275
|
+
*
|
|
1276
|
+
* Optional for backwards compatibility with existing callers; omitting it
|
|
1277
|
+
* behaves like `false` (no validation). Provider code in this repository
|
|
1278
|
+
* must always pass it explicitly so every call site makes a visible trust
|
|
1279
|
+
* decision — see `contributing/secure-url-handling.md`.
|
|
1280
|
+
*/
|
|
1281
|
+
validateUrl?: boolean;
|
|
1282
|
+
/**
|
|
1283
|
+
* When set, `headers` are sent only if `url` is same-origin with this origin
|
|
1284
|
+
* (the user-agent suffix is always kept). Pass the provider's configured
|
|
1285
|
+
* base URL alongside `validateUrl: true` so credentials never ride a request
|
|
1286
|
+
* to a response-supplied host on a different origin (e.g. a CDN). Redirects
|
|
1287
|
+
* that later cross origin drop all caller headers regardless (see
|
|
1288
|
+
* {@link fetchWithValidatedRedirects}).
|
|
1289
|
+
*/
|
|
1290
|
+
credentialedOrigin?: string;
|
|
1291
|
+
/**
|
|
1292
|
+
* A developer-configured origin (e.g. the provider's `baseURL`) that is
|
|
1293
|
+
* exempt from URL validation when `validateUrl` is `true`. A response URL
|
|
1294
|
+
* (or redirect hop) that is same-origin with it is fetched without target
|
|
1295
|
+
* validation — it points at exactly the host a config-derived
|
|
1296
|
+
* `validateUrl: false` request would fetch anyway, so blocking it would
|
|
1297
|
+
* only break legitimate self-hosted / localhost deployments whose response
|
|
1298
|
+
* URLs point back at the configured host. Hops on any other origin are
|
|
1299
|
+
* still validated. Must never be derived from response data.
|
|
1300
|
+
*/
|
|
1301
|
+
trustedOrigin?: string;
|
|
1269
1302
|
}) => Promise<{
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1303
|
+
value: T;
|
|
1304
|
+
rawValue?: unknown;
|
|
1305
|
+
responseHeaders?: Record<string, string>;
|
|
1273
1306
|
}>;
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1307
|
+
//#endregion
|
|
1308
|
+
//#region src/get-runtime-environment-user-agent.d.ts
|
|
1309
|
+
export declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
|
1310
|
+
//#endregion
|
|
1311
|
+
//#region src/has-required-key.d.ts
|
|
1277
1312
|
/**
|
|
1278
1313
|
* Checks if an object has required keys.
|
|
1279
1314
|
* @param OBJECT - The object to check.
|
|
1280
1315
|
* @returns True if the object has required keys, false otherwise.
|
|
1281
1316
|
*/
|
|
1282
1317
|
type HasRequiredKey<OBJECT> = {} extends OBJECT ? false : true;
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1318
|
+
//#endregion
|
|
1319
|
+
//#region src/inject-json-instruction.d.ts
|
|
1320
|
+
export declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix }: {
|
|
1321
|
+
messages: LanguageModelV4Prompt;
|
|
1322
|
+
schema?: JSONSchema7;
|
|
1323
|
+
schemaPrefix?: string;
|
|
1324
|
+
schemaSuffix?: string;
|
|
1289
1325
|
}): LanguageModelV4Prompt;
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1326
|
+
//#endregion
|
|
1327
|
+
//#region src/is-abort-error.d.ts
|
|
1328
|
+
export declare function isAbortError(error: unknown): error is Error;
|
|
1329
|
+
//#endregion
|
|
1330
|
+
//#region src/is-browser-runtime.d.ts
|
|
1293
1331
|
/**
|
|
1294
1332
|
* Returns `true` when running in a browser.
|
|
1295
1333
|
*
|
|
@@ -1298,16 +1336,18 @@ declare function isAbortError(error: unknown): error is Error;
|
|
|
1298
1336
|
* so the SDK has a single, consistent definition of "browser". Server runtimes
|
|
1299
1337
|
* (Node.js, Deno, Bun, edge/workers) do not define `window`.
|
|
1300
1338
|
*/
|
|
1301
|
-
declare function isBrowserRuntime(globalThisAny?: any): boolean;
|
|
1302
|
-
|
|
1339
|
+
export declare function isBrowserRuntime(globalThisAny?: any): boolean;
|
|
1340
|
+
//#endregion
|
|
1341
|
+
//#region src/is-buffer.d.ts
|
|
1303
1342
|
/**
|
|
1304
1343
|
* Type-guard for Node.js `Buffer` instances.
|
|
1305
1344
|
*
|
|
1306
1345
|
* Uses optional chaining on `globalThis.Buffer` so it returns `false` in
|
|
1307
1346
|
* runtimes where `Buffer` is not available (e.g. CloudFlare Workers).
|
|
1308
1347
|
*/
|
|
1309
|
-
declare function isBuffer(value: unknown): value is Buffer;
|
|
1310
|
-
|
|
1348
|
+
export declare function isBuffer(value: unknown): value is Buffer;
|
|
1349
|
+
//#endregion
|
|
1350
|
+
//#region src/is-same-origin.d.ts
|
|
1311
1351
|
/**
|
|
1312
1352
|
* Returns true when `url` has the same origin (scheme + host + port) as
|
|
1313
1353
|
* `baseUrl`.
|
|
@@ -1320,8 +1360,9 @@ declare function isBuffer(value: unknown): value is Buffer;
|
|
|
1320
1360
|
*
|
|
1321
1361
|
* Returns false if either value is not a valid absolute URL (fail-closed).
|
|
1322
1362
|
*/
|
|
1323
|
-
declare function isSameOrigin(url: string, baseUrl: string): boolean;
|
|
1324
|
-
|
|
1363
|
+
export declare function isSameOrigin(url: string, baseUrl: string): boolean;
|
|
1364
|
+
//#endregion
|
|
1365
|
+
//#region src/is-non-nullable.d.ts
|
|
1325
1366
|
/**
|
|
1326
1367
|
* Type guard that checks whether a value is not `null` or `undefined`.
|
|
1327
1368
|
*
|
|
@@ -1329,20 +1370,23 @@ declare function isSameOrigin(url: string, baseUrl: string): boolean;
|
|
|
1329
1370
|
* @param value - The value to check.
|
|
1330
1371
|
* @returns `true` if the value is neither `null` nor `undefined`, otherwise `false`.
|
|
1331
1372
|
*/
|
|
1332
|
-
declare function isNonNullable<T>(value: T | undefined | null): value is NonNullable<T>;
|
|
1333
|
-
|
|
1373
|
+
export declare function isNonNullable<T>(value: T | undefined | null): value is NonNullable<T>;
|
|
1374
|
+
//#endregion
|
|
1375
|
+
//#region src/is-provider-reference.d.ts
|
|
1334
1376
|
/**
|
|
1335
1377
|
* Checks whether a value is a provider reference (a mapping of provider names
|
|
1336
1378
|
* to provider-specific identifiers) as opposed to raw bytes, a URL, or a
|
|
1337
1379
|
* tagged `{ type: ... }` object.
|
|
1338
1380
|
*/
|
|
1339
|
-
declare function isProviderReference(data: unknown): data is SharedV4ProviderReference;
|
|
1340
|
-
|
|
1381
|
+
export declare function isProviderReference(data: unknown): data is SharedV4ProviderReference;
|
|
1382
|
+
//#endregion
|
|
1383
|
+
//#region src/is-record.d.ts
|
|
1341
1384
|
/**
|
|
1342
1385
|
* Checks whether a value is a non-null, non-array object.
|
|
1343
1386
|
*/
|
|
1344
|
-
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
1345
|
-
|
|
1387
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
1388
|
+
//#endregion
|
|
1389
|
+
//#region src/is-url-supported.d.ts
|
|
1346
1390
|
/**
|
|
1347
1391
|
* Checks if the given URL is supported natively by the model.
|
|
1348
1392
|
*
|
|
@@ -1356,19 +1400,32 @@ declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
|
1356
1400
|
* @returns `true` if the URL matches a pattern under the specific media type
|
|
1357
1401
|
* or the wildcard '*', `false` otherwise.
|
|
1358
1402
|
*/
|
|
1359
|
-
declare function isUrlSupported({ mediaType, url, supportedUrls
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1403
|
+
export declare function isUrlSupported({ mediaType, url, supportedUrls }: {
|
|
1404
|
+
mediaType: string;
|
|
1405
|
+
url: string;
|
|
1406
|
+
supportedUrls: Record<string, RegExp[]>;
|
|
1363
1407
|
}): boolean;
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region src/is-valid-hostname-part.d.ts
|
|
1410
|
+
/**
|
|
1411
|
+
* Checks whether a value is a valid ASCII hostname part: 1–63 letters, digits,
|
|
1412
|
+
* or hyphens, without a leading or trailing hyphen.
|
|
1413
|
+
*
|
|
1414
|
+
* Use this before inserting a resource name, region, or location into a
|
|
1415
|
+
* generated hostname. Rejects values such as `evil.example.com/#` and
|
|
1416
|
+
* `user@localhost:8080/#` that could change the request destination.
|
|
1417
|
+
*/
|
|
1418
|
+
export declare function isValidHostnamePart(value: string): boolean;
|
|
1419
|
+
//#endregion
|
|
1420
|
+
//#region src/load-api-key.d.ts
|
|
1421
|
+
export declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description }: {
|
|
1422
|
+
apiKey: string | undefined;
|
|
1423
|
+
environmentVariableName: string;
|
|
1424
|
+
apiKeyParameterName?: string;
|
|
1425
|
+
description: string;
|
|
1370
1426
|
}): string;
|
|
1371
|
-
|
|
1427
|
+
//#endregion
|
|
1428
|
+
//#region src/load-optional-setting.d.ts
|
|
1372
1429
|
/**
|
|
1373
1430
|
* Loads an optional `string` setting from the environment or a parameter.
|
|
1374
1431
|
*
|
|
@@ -1376,11 +1433,12 @@ declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterNa
|
|
|
1376
1433
|
* @param environmentVariableName - The environment variable name.
|
|
1377
1434
|
* @returns The setting value.
|
|
1378
1435
|
*/
|
|
1379
|
-
declare function loadOptionalSetting({ settingValue, environmentVariableName
|
|
1380
|
-
|
|
1381
|
-
|
|
1436
|
+
export declare function loadOptionalSetting({ settingValue, environmentVariableName }: {
|
|
1437
|
+
settingValue: string | undefined;
|
|
1438
|
+
environmentVariableName: string;
|
|
1382
1439
|
}): string | undefined;
|
|
1383
|
-
|
|
1440
|
+
//#endregion
|
|
1441
|
+
//#region src/load-setting.d.ts
|
|
1384
1442
|
/**
|
|
1385
1443
|
* Loads a `string` setting from the environment or a parameter.
|
|
1386
1444
|
*
|
|
@@ -1390,15 +1448,16 @@ declare function loadOptionalSetting({ settingValue, environmentVariableName, }:
|
|
|
1390
1448
|
* @param description - The description of the setting.
|
|
1391
1449
|
* @returns The setting value.
|
|
1392
1450
|
*/
|
|
1393
|
-
declare function loadSetting({ settingValue, environmentVariableName, settingName, description
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1451
|
+
export declare function loadSetting({ settingValue, environmentVariableName, settingName, description }: {
|
|
1452
|
+
settingValue: string | undefined;
|
|
1453
|
+
environmentVariableName: string;
|
|
1454
|
+
settingName: string;
|
|
1455
|
+
description: string;
|
|
1398
1456
|
}): string;
|
|
1399
|
-
|
|
1457
|
+
//#endregion
|
|
1458
|
+
//#region src/map-reasoning-to-provider.d.ts
|
|
1400
1459
|
type ReasoningLevel = Exclude<LanguageModelV4CallOptions['reasoning'], 'none' | 'provider-default' | undefined>;
|
|
1401
|
-
declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
|
|
1460
|
+
export declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
|
|
1402
1461
|
/**
|
|
1403
1462
|
* Maps a top-level reasoning level to a provider-specific effort string using
|
|
1404
1463
|
* the given effort map. Pushes a compatibility warning if the reasoning level
|
|
@@ -1408,10 +1467,10 @@ declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reason
|
|
|
1408
1467
|
* @returns The mapped effort string, or `undefined` if the level is not
|
|
1409
1468
|
* supported.
|
|
1410
1469
|
*/
|
|
1411
|
-
declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1470
|
+
export declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings }: {
|
|
1471
|
+
reasoning: ReasoningLevel;
|
|
1472
|
+
effortMap: Partial<Record<ReasoningLevel, T>>;
|
|
1473
|
+
warnings: SharedV4Warning[];
|
|
1415
1474
|
}): T | undefined;
|
|
1416
1475
|
/**
|
|
1417
1476
|
* Maps a top-level reasoning level to an absolute token budget by multiplying
|
|
@@ -1423,20 +1482,22 @@ declare function mapReasoningToProviderEffort<T extends string>({ reasoning, eff
|
|
|
1423
1482
|
* @returns The computed token budget, or `undefined` if the level is not
|
|
1424
1483
|
* supported.
|
|
1425
1484
|
*/
|
|
1426
|
-
declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1485
|
+
export declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings }: {
|
|
1486
|
+
reasoning: ReasoningLevel;
|
|
1487
|
+
maxOutputTokens: number;
|
|
1488
|
+
maxReasoningBudget: number;
|
|
1489
|
+
minReasoningBudget?: number;
|
|
1490
|
+
budgetPercentages?: Partial<Record<ReasoningLevel, number>>;
|
|
1491
|
+
warnings: SharedV4Warning[];
|
|
1433
1492
|
}): number | undefined;
|
|
1434
|
-
|
|
1493
|
+
//#endregion
|
|
1494
|
+
//#region src/maybe-promise-like.d.ts
|
|
1435
1495
|
/**
|
|
1436
1496
|
* A value that can be provided either synchronously or as a promise-like.
|
|
1437
1497
|
*/
|
|
1438
1498
|
type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
1439
|
-
|
|
1499
|
+
//#endregion
|
|
1500
|
+
//#region src/media-type-to-extension.d.ts
|
|
1440
1501
|
/**
|
|
1441
1502
|
* Maps a media type to its corresponding file extension.
|
|
1442
1503
|
* It was originally introduced to set a filename for audio file uploads
|
|
@@ -1446,8 +1507,9 @@ type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
|
1446
1507
|
* @returns The corresponding file extension
|
|
1447
1508
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
|
|
1448
1509
|
*/
|
|
1449
|
-
declare function mediaTypeToExtension(mediaType: string): string;
|
|
1450
|
-
|
|
1510
|
+
export declare function mediaTypeToExtension(mediaType: string): string;
|
|
1511
|
+
//#endregion
|
|
1512
|
+
//#region src/normalize-headers.d.ts
|
|
1451
1513
|
/**
|
|
1452
1514
|
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
1453
1515
|
* Entries with `undefined` or `null` values are removed.
|
|
@@ -1455,51 +1517,55 @@ declare function mediaTypeToExtension(mediaType: string): string;
|
|
|
1455
1517
|
* @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
|
|
1456
1518
|
* @returns A record containing the normalized header entries.
|
|
1457
1519
|
*/
|
|
1458
|
-
declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
|
|
1459
|
-
|
|
1520
|
+
export declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
|
|
1521
|
+
//#endregion
|
|
1522
|
+
//#region src/normalize-batch-request-counts.d.ts
|
|
1460
1523
|
/**
|
|
1461
1524
|
* Normalizes complete batch request counts.
|
|
1462
1525
|
*
|
|
1463
1526
|
* Returns `undefined` when any count is missing, is not a non-negative safe
|
|
1464
1527
|
* integer, or when the item counts do not add up to the total.
|
|
1465
1528
|
*/
|
|
1466
|
-
declare function normalizeBatchRequestCounts({ total, pending, completed, failed
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1529
|
+
export declare function normalizeBatchRequestCounts({ total, pending, completed, failed }: {
|
|
1530
|
+
total: number | null | undefined;
|
|
1531
|
+
pending: number | null | undefined;
|
|
1532
|
+
completed: number | null | undefined;
|
|
1533
|
+
failed: number | null | undefined;
|
|
1471
1534
|
}): Experimental_BatchV4Status['requestCounts'] | undefined;
|
|
1472
|
-
|
|
1535
|
+
//#endregion
|
|
1536
|
+
//#region src/parse-json-event-stream.d.ts
|
|
1473
1537
|
/**
|
|
1474
1538
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
1475
1539
|
*/
|
|
1476
|
-
declare function parseJsonEventStream<T>({ stream, schema
|
|
1477
|
-
|
|
1478
|
-
|
|
1540
|
+
export declare function parseJsonEventStream<T>({ stream, schema }: {
|
|
1541
|
+
stream: ReadableStream<Uint8Array>;
|
|
1542
|
+
schema: FlexibleSchema<T>;
|
|
1479
1543
|
}): ReadableStream<ParseResult<T>>;
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1544
|
+
//#endregion
|
|
1545
|
+
//#region src/parse-provider-options.d.ts
|
|
1546
|
+
export declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema }: {
|
|
1547
|
+
provider: string;
|
|
1548
|
+
providerOptions: Record<string, unknown> | undefined;
|
|
1549
|
+
schema: FlexibleSchema<OPTIONS>;
|
|
1485
1550
|
}): Promise<OPTIONS | undefined>;
|
|
1486
|
-
|
|
1551
|
+
//#endregion
|
|
1552
|
+
//#region src/post-multipart-stream-to-api.d.ts
|
|
1487
1553
|
/**
|
|
1488
1554
|
* A part of a streaming multipart/form-data request body.
|
|
1489
1555
|
*
|
|
1490
1556
|
* Parts are emitted in array order, which providers may depend on
|
|
1491
1557
|
* (e.g. xAI requires expiry fields to precede the file part).
|
|
1492
1558
|
*/
|
|
1493
|
-
type MultipartStreamPart = {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1559
|
+
export type MultipartStreamPart = {
|
|
1560
|
+
type: 'field';
|
|
1561
|
+
name: string;
|
|
1562
|
+
value: string;
|
|
1497
1563
|
} | {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1564
|
+
type: 'file';
|
|
1565
|
+
name: string;
|
|
1566
|
+
filename?: string;
|
|
1567
|
+
mediaType?: string;
|
|
1568
|
+
content: ReadableStream<Uint8Array> | Uint8Array;
|
|
1503
1569
|
};
|
|
1504
1570
|
/**
|
|
1505
1571
|
* POSTs a multipart/form-data body as a request stream, so file parts backed
|
|
@@ -1509,137 +1575,144 @@ type MultipartStreamPart = {
|
|
|
1509
1575
|
* (`duplex: 'half'`). Callers with fully buffered payloads can keep using
|
|
1510
1576
|
* `postFormDataToApi`.
|
|
1511
1577
|
*/
|
|
1512
|
-
declare const postMultipartStreamToApi: <T>({ url, headers, parts, failedResponseHandler, successfulResponseHandler, abortSignal, fetch
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1578
|
+
export declare const postMultipartStreamToApi: <T>({ url, headers, parts, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }: {
|
|
1579
|
+
url: string;
|
|
1580
|
+
headers?: Record<string, string | undefined>;
|
|
1581
|
+
parts: Array<MultipartStreamPart>;
|
|
1582
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
1583
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1584
|
+
abortSignal?: AbortSignal;
|
|
1585
|
+
fetch?: FetchFunction;
|
|
1520
1586
|
}) => Promise<{
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1587
|
+
value: T;
|
|
1588
|
+
rawValue?: unknown;
|
|
1589
|
+
responseHeaders?: Record<string, string>;
|
|
1524
1590
|
}>;
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1591
|
+
//#endregion
|
|
1592
|
+
//#region src/post-to-api.d.ts
|
|
1593
|
+
export declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }: {
|
|
1594
|
+
url: string;
|
|
1595
|
+
headers?: Record<string, string | undefined>;
|
|
1596
|
+
body: unknown;
|
|
1597
|
+
failedResponseHandler: ResponseHandler<APICallError>;
|
|
1598
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1599
|
+
abortSignal?: AbortSignal;
|
|
1600
|
+
fetch?: FetchFunction;
|
|
1534
1601
|
}) => Promise<{
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1602
|
+
value: T;
|
|
1603
|
+
rawValue?: unknown;
|
|
1604
|
+
responseHeaders?: Record<string, string>;
|
|
1538
1605
|
}>;
|
|
1539
|
-
declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1606
|
+
export declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }: {
|
|
1607
|
+
url: string;
|
|
1608
|
+
headers?: Record<string, string | undefined>;
|
|
1609
|
+
formData: FormData;
|
|
1610
|
+
failedResponseHandler: ResponseHandler<APICallError>;
|
|
1611
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1612
|
+
abortSignal?: AbortSignal;
|
|
1613
|
+
fetch?: FetchFunction;
|
|
1547
1614
|
}) => Promise<{
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1615
|
+
value: T;
|
|
1616
|
+
rawValue?: unknown;
|
|
1617
|
+
responseHeaders?: Record<string, string>;
|
|
1551
1618
|
}>;
|
|
1552
|
-
declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1619
|
+
export declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch }: {
|
|
1620
|
+
url: string;
|
|
1621
|
+
headers?: Record<string, string | undefined>;
|
|
1622
|
+
body: {
|
|
1623
|
+
content: string | FormData | Uint8Array | Blob;
|
|
1624
|
+
values: unknown;
|
|
1625
|
+
};
|
|
1626
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
1627
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1628
|
+
abortSignal?: AbortSignal;
|
|
1629
|
+
fetch?: FetchFunction;
|
|
1563
1630
|
}) => Promise<{
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1631
|
+
value: T;
|
|
1632
|
+
rawValue?: unknown;
|
|
1633
|
+
responseHeaders?: Record<string, string>;
|
|
1567
1634
|
}>;
|
|
1568
|
-
|
|
1635
|
+
//#endregion
|
|
1636
|
+
//#region src/types/context.d.ts
|
|
1569
1637
|
/**
|
|
1570
1638
|
* A context object that is passed into tool execution.
|
|
1571
1639
|
*/
|
|
1572
1640
|
type Context = Record<string, unknown>;
|
|
1573
|
-
|
|
1641
|
+
//#endregion
|
|
1642
|
+
//#region src/types/executable-tool.d.ts
|
|
1574
1643
|
/**
|
|
1575
1644
|
* A tool that is guaranteed to expose an execute function.
|
|
1576
1645
|
*/
|
|
1577
1646
|
type ExecutableTool<TOOL extends Tool = Tool> = TOOL & {
|
|
1578
|
-
|
|
1647
|
+
execute: NonNullable<TOOL['execute']>;
|
|
1579
1648
|
};
|
|
1580
1649
|
/**
|
|
1581
1650
|
* Checks whether a tool exposes an execute function.
|
|
1582
1651
|
*/
|
|
1583
|
-
declare function isExecutableTool<TOOL extends Tool>(tool: TOOL | undefined): tool is ExecutableTool<TOOL>;
|
|
1584
|
-
|
|
1652
|
+
export declare function isExecutableTool<TOOL extends Tool>(tool: TOOL | undefined): tool is ExecutableTool<TOOL>;
|
|
1653
|
+
//#endregion
|
|
1654
|
+
//#region src/types/never-optional.d.ts
|
|
1585
1655
|
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
1586
|
-
|
|
1656
|
+
//#endregion
|
|
1657
|
+
//#region src/types/tool-approval-request.d.ts
|
|
1587
1658
|
/**
|
|
1588
1659
|
* Tool approval request prompt part.
|
|
1589
1660
|
*/
|
|
1590
1661
|
type ToolApprovalRequest = {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1662
|
+
type: 'tool-approval-request';
|
|
1663
|
+
/**
|
|
1664
|
+
* ID of the tool approval.
|
|
1665
|
+
*/
|
|
1666
|
+
approvalId: string;
|
|
1667
|
+
/**
|
|
1668
|
+
* ID of the tool call that the approval request is for.
|
|
1669
|
+
*/
|
|
1670
|
+
toolCallId: string;
|
|
1671
|
+
/**
|
|
1672
|
+
* Reason why the tool call requires approval.
|
|
1673
|
+
*/
|
|
1674
|
+
reason?: string;
|
|
1675
|
+
/**
|
|
1676
|
+
* Flag indicating whether the tool was automatically approved or denied.
|
|
1677
|
+
*
|
|
1678
|
+
* @default false
|
|
1679
|
+
*/
|
|
1680
|
+
isAutomatic?: boolean;
|
|
1681
|
+
/**
|
|
1682
|
+
* HMAC-SHA256 signature binding this approval to its tool call.
|
|
1683
|
+
* Present only when `experimental_toolApprovalSecret` is configured.
|
|
1684
|
+
*/
|
|
1685
|
+
signature?: string;
|
|
1686
|
+
/**
|
|
1687
|
+
* Tool input before input schema validation and transformation.
|
|
1688
|
+
*
|
|
1689
|
+
* This is included when it differs from the validated tool input so that
|
|
1690
|
+
* approved tool calls can be safely revalidated before execution.
|
|
1691
|
+
*/
|
|
1692
|
+
inputSchemaInput?: unknown;
|
|
1622
1693
|
};
|
|
1623
|
-
|
|
1694
|
+
//#endregion
|
|
1695
|
+
//#region src/types/assistant-model-message.d.ts
|
|
1624
1696
|
/**
|
|
1625
1697
|
* An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
|
1626
1698
|
*/
|
|
1627
1699
|
type AssistantModelMessage = {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1700
|
+
role: 'assistant';
|
|
1701
|
+
content: AssistantContent;
|
|
1702
|
+
/**
|
|
1703
|
+
* Additional provider-specific metadata. They are passed through
|
|
1704
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1705
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1706
|
+
*/
|
|
1707
|
+
providerOptions?: ProviderOptions;
|
|
1636
1708
|
};
|
|
1637
1709
|
/**
|
|
1638
1710
|
* Content of an assistant message.
|
|
1639
1711
|
* It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
|
1640
1712
|
*/
|
|
1641
1713
|
type AssistantContent = string | Array<TextPart | CustomPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
|
1642
|
-
|
|
1714
|
+
//#endregion
|
|
1715
|
+
//#region src/types/system-model-message.d.ts
|
|
1643
1716
|
/**
|
|
1644
1717
|
* A system message. It can contain system information.
|
|
1645
1718
|
*
|
|
@@ -1648,496 +1721,502 @@ type AssistantContent = string | Array<TextPart | CustomPart | FilePart | Reason
|
|
|
1648
1721
|
* and because not all providers support several system messages.
|
|
1649
1722
|
*/
|
|
1650
1723
|
type SystemModelMessage = {
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1724
|
+
role: 'system';
|
|
1725
|
+
content: string;
|
|
1726
|
+
/**
|
|
1727
|
+
* Additional provider-specific metadata. They are passed through
|
|
1728
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1729
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1730
|
+
*/
|
|
1731
|
+
providerOptions?: ProviderOptions;
|
|
1659
1732
|
};
|
|
1660
|
-
|
|
1733
|
+
//#endregion
|
|
1734
|
+
//#region src/types/tool-approval-response.d.ts
|
|
1661
1735
|
/**
|
|
1662
1736
|
* Tool approval response prompt part.
|
|
1663
1737
|
*/
|
|
1664
1738
|
type ToolApprovalResponse = {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1739
|
+
type: 'tool-approval-response';
|
|
1740
|
+
/**
|
|
1741
|
+
* ID of the tool approval.
|
|
1742
|
+
*/
|
|
1743
|
+
approvalId: string;
|
|
1744
|
+
/**
|
|
1745
|
+
* Flag indicating whether the approval was granted or denied.
|
|
1746
|
+
*/
|
|
1747
|
+
approved: boolean;
|
|
1748
|
+
/**
|
|
1749
|
+
* Optional reason for the approval or denial.
|
|
1750
|
+
*/
|
|
1751
|
+
reason?: string;
|
|
1752
|
+
/**
|
|
1753
|
+
* Flag indicating whether the tool call is provider-executed.
|
|
1754
|
+
* Only provider-executed tool approval responses should be sent to the model.
|
|
1755
|
+
*/
|
|
1756
|
+
providerExecuted?: boolean;
|
|
1683
1757
|
};
|
|
1684
|
-
|
|
1758
|
+
//#endregion
|
|
1759
|
+
//#region src/types/tool-model-message.d.ts
|
|
1685
1760
|
/**
|
|
1686
1761
|
* A tool message. It contains the result of one or more tool calls.
|
|
1687
1762
|
*/
|
|
1688
1763
|
type ToolModelMessage = {
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1764
|
+
role: 'tool';
|
|
1765
|
+
content: ToolContent;
|
|
1766
|
+
/**
|
|
1767
|
+
* Additional provider-specific metadata. They are passed through
|
|
1768
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1769
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1770
|
+
*/
|
|
1771
|
+
providerOptions?: ProviderOptions;
|
|
1697
1772
|
};
|
|
1698
1773
|
/**
|
|
1699
1774
|
* Content of a tool message. It is an array of tool result parts.
|
|
1700
1775
|
*/
|
|
1701
1776
|
type ToolContent = Array<ToolResultPart | ToolApprovalResponse>;
|
|
1702
|
-
|
|
1777
|
+
//#endregion
|
|
1778
|
+
//#region src/types/user-model-message.d.ts
|
|
1703
1779
|
/**
|
|
1704
1780
|
* A user message. It can contain text or a combination of text and images.
|
|
1705
1781
|
*/
|
|
1706
1782
|
type UserModelMessage = {
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1783
|
+
role: 'user';
|
|
1784
|
+
content: UserContent;
|
|
1785
|
+
/**
|
|
1786
|
+
* Additional provider-specific metadata. They are passed through
|
|
1787
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1788
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1789
|
+
*/
|
|
1790
|
+
providerOptions?: ProviderOptions;
|
|
1715
1791
|
};
|
|
1716
1792
|
/**
|
|
1717
1793
|
* Content of a user message. It can be a string or an array of text and image parts.
|
|
1718
1794
|
*/
|
|
1719
1795
|
type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
|
1720
|
-
|
|
1796
|
+
//#endregion
|
|
1797
|
+
//#region src/types/model-message.d.ts
|
|
1721
1798
|
/**
|
|
1722
1799
|
* A message that can be used in the `messages` field of a prompt.
|
|
1723
1800
|
* It can be a user message, an assistant message, or a tool message.
|
|
1724
1801
|
*/
|
|
1725
1802
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
1726
|
-
|
|
1803
|
+
//#endregion
|
|
1804
|
+
//#region src/types/sandbox.d.ts
|
|
1727
1805
|
/**
|
|
1728
1806
|
* Options for executing a command in the sandbox via `run` or `spawn`.
|
|
1729
1807
|
*/
|
|
1730
1808
|
type SandboxProcessOptions = {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1809
|
+
/**
|
|
1810
|
+
* Command to execute in the sandbox.
|
|
1811
|
+
*/
|
|
1812
|
+
command: string;
|
|
1813
|
+
/**
|
|
1814
|
+
* Working directory to execute the command in.
|
|
1815
|
+
*/
|
|
1816
|
+
workingDirectory?: string;
|
|
1817
|
+
/**
|
|
1818
|
+
* Environment variables to set for this command. Merged with the
|
|
1819
|
+
* sandbox's default environment; values here take precedence.
|
|
1820
|
+
* Supporting environment variables as an option is preferable from a
|
|
1821
|
+
* security perspective, e.g. to avoid them leaking in logs.
|
|
1822
|
+
*/
|
|
1823
|
+
env?: Record<string, string>;
|
|
1824
|
+
/**
|
|
1825
|
+
* Signal that can be used to abort the command. When aborted, the running
|
|
1826
|
+
* process is killed; for `spawn`, `wait()` rejects with the abort reason.
|
|
1827
|
+
*/
|
|
1828
|
+
abortSignal?: AbortSignal;
|
|
1751
1829
|
};
|
|
1752
1830
|
/**
|
|
1753
1831
|
* Options for reading a file from the sandbox.
|
|
1754
1832
|
*/
|
|
1755
1833
|
type ReadFileOptions = {
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1834
|
+
/**
|
|
1835
|
+
* Path of the file to read.
|
|
1836
|
+
*/
|
|
1837
|
+
path: string;
|
|
1838
|
+
/**
|
|
1839
|
+
* Signal that can be used to abort the read.
|
|
1840
|
+
*/
|
|
1841
|
+
abortSignal?: AbortSignal;
|
|
1764
1842
|
};
|
|
1765
1843
|
/**
|
|
1766
1844
|
* Options for writing a file to the sandbox. `CONTENT` is the payload written
|
|
1767
1845
|
* to the file: a byte stream, raw bytes, or a string.
|
|
1768
1846
|
*/
|
|
1769
1847
|
type WriteFileOptions<CONTENT> = {
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1848
|
+
/**
|
|
1849
|
+
* Path of the file to write.
|
|
1850
|
+
*/
|
|
1851
|
+
path: string;
|
|
1852
|
+
/**
|
|
1853
|
+
* Content to write to the file.
|
|
1854
|
+
*/
|
|
1855
|
+
content: CONTENT;
|
|
1856
|
+
/**
|
|
1857
|
+
* Signal that can be used to abort the write.
|
|
1858
|
+
*/
|
|
1859
|
+
abortSignal?: AbortSignal;
|
|
1782
1860
|
};
|
|
1783
1861
|
/**
|
|
1784
1862
|
* Sandbox session that can execute commands and read/write files.
|
|
1785
1863
|
*/
|
|
1786
1864
|
type SandboxSession = {
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1865
|
+
/**
|
|
1866
|
+
* Description of the sandbox environment that can be added to the agent's instructions
|
|
1867
|
+
* so that the agent knows about relevant details such as the root directory, exposed
|
|
1868
|
+
* ports, the public hostname, etc.
|
|
1869
|
+
*/
|
|
1870
|
+
readonly description: string;
|
|
1871
|
+
/**
|
|
1872
|
+
* Read one file from the sandbox as a stream of bytes. Resolves to `null`
|
|
1873
|
+
* when the file does not exist.
|
|
1874
|
+
*
|
|
1875
|
+
* Relative path handling is implementation-defined. This is the lowest-level
|
|
1876
|
+
* read primitive; prefer `readBinaryFile` or `readTextFile` unless you need
|
|
1877
|
+
* to stream bytes.
|
|
1878
|
+
*/
|
|
1879
|
+
readonly readFile: (options: ReadFileOptions) => PromiseLike<ReadableStream<Uint8Array> | null>;
|
|
1880
|
+
/**
|
|
1881
|
+
* Read one file from the sandbox as raw bytes. Resolves to `null` when the
|
|
1882
|
+
* file does not exist.
|
|
1883
|
+
*/
|
|
1884
|
+
readonly readBinaryFile: (options: ReadFileOptions) => PromiseLike<Uint8Array | null>;
|
|
1885
|
+
/**
|
|
1886
|
+
* Read one text file from the sandbox, decoded using the requested encoding.
|
|
1887
|
+
* Resolves to `null` when the file does not exist.
|
|
1888
|
+
*
|
|
1889
|
+
* Line ranges are 1-based and inclusive. When `endLine` is past EOF the read
|
|
1890
|
+
* returns through EOF without error.
|
|
1891
|
+
*/
|
|
1892
|
+
readonly readTextFile: (options: ReadFileOptions & {
|
|
1893
|
+
/**
|
|
1894
|
+
* Text encoding used to decode the file bytes. Defaults to `"utf-8"`.
|
|
1895
|
+
*/
|
|
1896
|
+
encoding?: string;
|
|
1897
|
+
/**
|
|
1898
|
+
* 1-based inclusive start line. Defaults to 1.
|
|
1805
1899
|
*/
|
|
1806
|
-
|
|
1900
|
+
startLine?: number;
|
|
1807
1901
|
/**
|
|
1808
|
-
*
|
|
1809
|
-
* Resolves to `null` when the file does not exist.
|
|
1810
|
-
*
|
|
1811
|
-
* Line ranges are 1-based and inclusive. When `endLine` is past EOF the read
|
|
1902
|
+
* 1-based inclusive end line. When past the file's line count, the read
|
|
1812
1903
|
* returns through EOF without error.
|
|
1813
1904
|
*/
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
*
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
/**
|
|
1866
|
-
* Exit code returned by the command.
|
|
1867
|
-
*/
|
|
1868
|
-
exitCode: number;
|
|
1869
|
-
/**
|
|
1870
|
-
* Standard output produced by the command.
|
|
1871
|
-
*/
|
|
1872
|
-
stdout: string;
|
|
1873
|
-
/**
|
|
1874
|
-
* Standard error produced by the command.
|
|
1875
|
-
*/
|
|
1876
|
-
stderr: string;
|
|
1877
|
-
}>;
|
|
1905
|
+
endLine?: number;
|
|
1906
|
+
}) => PromiseLike<string | null>;
|
|
1907
|
+
/**
|
|
1908
|
+
* Write one file to the sandbox from a stream of bytes. Creates parent
|
|
1909
|
+
* directories recursively and overwrites any existing file.
|
|
1910
|
+
*
|
|
1911
|
+
* This is the lowest-level write primitive; prefer `writeBinaryFile` or
|
|
1912
|
+
* `writeTextFile` when the full content is already materialized in memory.
|
|
1913
|
+
*/
|
|
1914
|
+
readonly writeFile: (options: WriteFileOptions<ReadableStream<Uint8Array>>) => PromiseLike<void>;
|
|
1915
|
+
/**
|
|
1916
|
+
* Write one file to the sandbox from raw bytes. Creates parent directories
|
|
1917
|
+
* recursively and overwrites any existing file.
|
|
1918
|
+
*/
|
|
1919
|
+
readonly writeBinaryFile: (options: WriteFileOptions<Uint8Array>) => PromiseLike<void>;
|
|
1920
|
+
/**
|
|
1921
|
+
* Write one file to the sandbox from a string, encoded using the requested
|
|
1922
|
+
* encoding. Creates parent directories recursively and overwrites any
|
|
1923
|
+
* existing file.
|
|
1924
|
+
*/
|
|
1925
|
+
readonly writeTextFile: (options: WriteFileOptions<string> & {
|
|
1926
|
+
/**
|
|
1927
|
+
* Text encoding used to encode the string to bytes. Defaults to `"utf-8"`.
|
|
1928
|
+
*/
|
|
1929
|
+
encoding?: string;
|
|
1930
|
+
}) => PromiseLike<void>;
|
|
1931
|
+
/**
|
|
1932
|
+
* Spawn a long-running process in the sandbox. Returns immediately with a
|
|
1933
|
+
* handle that streams stdout/stderr, can be waited on, and can be killed.
|
|
1934
|
+
*
|
|
1935
|
+
* `run` is conceptually a thin wrapper over this primitive: spawn,
|
|
1936
|
+
* collect both streams to strings, await `wait()`, return the result.
|
|
1937
|
+
*/
|
|
1938
|
+
readonly spawn: (options: SandboxProcessOptions) => PromiseLike<SandboxProcess>;
|
|
1939
|
+
/**
|
|
1940
|
+
* Run a command in the sandbox.
|
|
1941
|
+
*/
|
|
1942
|
+
readonly run: (options: SandboxProcessOptions) => PromiseLike<{
|
|
1943
|
+
/**
|
|
1944
|
+
* Exit code returned by the command.
|
|
1945
|
+
*/
|
|
1946
|
+
exitCode: number;
|
|
1947
|
+
/**
|
|
1948
|
+
* Standard output produced by the command.
|
|
1949
|
+
*/
|
|
1950
|
+
stdout: string;
|
|
1951
|
+
/**
|
|
1952
|
+
* Standard error produced by the command.
|
|
1953
|
+
*/
|
|
1954
|
+
stderr: string;
|
|
1955
|
+
}>;
|
|
1878
1956
|
};
|
|
1879
1957
|
/**
|
|
1880
1958
|
* Handle to a long-running process started via `SandboxSession.spawn`.
|
|
1881
1959
|
*/
|
|
1882
1960
|
type SandboxProcess = {
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1961
|
+
/**
|
|
1962
|
+
* Process identifier, if the sandbox implementation exposes one.
|
|
1963
|
+
*/
|
|
1964
|
+
readonly pid?: number;
|
|
1965
|
+
/**
|
|
1966
|
+
* Stream of bytes written by the process to standard output.
|
|
1967
|
+
*/
|
|
1968
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
1969
|
+
/**
|
|
1970
|
+
* Stream of bytes written by the process to standard error.
|
|
1971
|
+
*/
|
|
1972
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
1973
|
+
/**
|
|
1974
|
+
* Resolve when the process exits, yielding its exit code.
|
|
1975
|
+
*/
|
|
1976
|
+
wait(): PromiseLike<{
|
|
1977
|
+
exitCode: number;
|
|
1978
|
+
}>;
|
|
1979
|
+
/**
|
|
1980
|
+
* Terminate the process. Idempotent.
|
|
1981
|
+
*/
|
|
1982
|
+
kill(): PromiseLike<void>;
|
|
1905
1983
|
};
|
|
1906
|
-
|
|
1984
|
+
//#endregion
|
|
1985
|
+
//#region src/types/tool-execute-function.d.ts
|
|
1907
1986
|
/**
|
|
1908
1987
|
* Additional options that are sent into each tool execution.
|
|
1909
1988
|
*/
|
|
1910
1989
|
interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1990
|
+
/**
|
|
1991
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1992
|
+
*/
|
|
1993
|
+
toolCallId: string;
|
|
1994
|
+
/**
|
|
1995
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
|
1996
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
|
1997
|
+
*/
|
|
1998
|
+
messages: ModelMessage[];
|
|
1999
|
+
/**
|
|
2000
|
+
* An optional abort signal that indicates that the overall operation should be aborted.
|
|
2001
|
+
*/
|
|
2002
|
+
abortSignal?: AbortSignal;
|
|
2003
|
+
/**
|
|
2004
|
+
* Tool context as defined by the tool's context schema.
|
|
2005
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
2006
|
+
*
|
|
2007
|
+
* Treat the context object as immutable inside tools.
|
|
2008
|
+
* Mutating the context object can lead to race conditions and unexpected results
|
|
2009
|
+
* when tools are called in parallel.
|
|
2010
|
+
*
|
|
2011
|
+
* If you need to mutate the context, analyze the tool calls and results
|
|
2012
|
+
* in `prepareStep` and update it there.
|
|
2013
|
+
*/
|
|
2014
|
+
context: CONTEXT;
|
|
2015
|
+
/**
|
|
2016
|
+
* The sandbox environment that the tool is operating in.
|
|
2017
|
+
*/
|
|
2018
|
+
experimental_sandbox?: SandboxSession;
|
|
1940
2019
|
}
|
|
1941
2020
|
/**
|
|
1942
2021
|
* Function that executes the tool and returns either a single result or a stream of results.
|
|
1943
2022
|
*/
|
|
1944
2023
|
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1945
|
-
|
|
2024
|
+
//#endregion
|
|
2025
|
+
//#region src/types/tool-needs-approval-function.d.ts
|
|
1946
2026
|
/**
|
|
1947
2027
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1948
2028
|
*
|
|
1949
2029
|
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
1950
2030
|
*/
|
|
1951
2031
|
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: {
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
2032
|
+
/**
|
|
2033
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
2034
|
+
*/
|
|
2035
|
+
toolCallId: string;
|
|
2036
|
+
/**
|
|
2037
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
|
2038
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
|
2039
|
+
*/
|
|
2040
|
+
messages: ModelMessage[];
|
|
2041
|
+
/**
|
|
2042
|
+
* Tool context as defined by the tool's context schema.
|
|
2043
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
2044
|
+
*
|
|
2045
|
+
* Treat the context object as immutable inside tools.
|
|
2046
|
+
* Mutating the context object can lead to race conditions and unexpected results
|
|
2047
|
+
* when tools are called in parallel.
|
|
2048
|
+
*
|
|
2049
|
+
* If you need to mutate the context, analyze the tool calls and results
|
|
2050
|
+
* in `prepareStep` and update it there.
|
|
2051
|
+
*/
|
|
2052
|
+
context: CONTEXT;
|
|
1973
2053
|
}) => boolean | PromiseLike<boolean>;
|
|
1974
|
-
|
|
2054
|
+
//#endregion
|
|
2055
|
+
//#region src/types/tool.d.ts
|
|
1975
2056
|
/**
|
|
1976
2057
|
* Helper type to determine the outputSchema and execute function properties of a tool.
|
|
1977
2058
|
*/
|
|
1978
2059
|
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = NeverOptional<OUTPUT, {
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2060
|
+
/**
|
|
2061
|
+
* The optional schema of the output that the tool produces.
|
|
2062
|
+
*
|
|
2063
|
+
* If not provided, the output shape will be inferred from the execute function.
|
|
2064
|
+
*/
|
|
2065
|
+
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
2066
|
+
/**
|
|
2067
|
+
* An async function that is called with the arguments from the tool call and produces a result.
|
|
2068
|
+
* If not provided, the tool will not be executed automatically.
|
|
2069
|
+
*
|
|
2070
|
+
* @args is the input of the tool call.
|
|
2071
|
+
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
2072
|
+
*/
|
|
2073
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1993
2074
|
} | {
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2075
|
+
/**
|
|
2076
|
+
* The schema of the output that the tool produces.
|
|
2077
|
+
*
|
|
2078
|
+
* Required when no execute function is provided.
|
|
2079
|
+
*/
|
|
2080
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
2081
|
+
execute?: never;
|
|
2001
2082
|
}>;
|
|
2002
2083
|
/**
|
|
2003
2084
|
* Common properties shared by all tool kinds.
|
|
2004
2085
|
*/
|
|
2005
2086
|
type BaseTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = {
|
|
2087
|
+
/**
|
|
2088
|
+
* Defer exposing this tool until it is discovered by `toolSearch`.
|
|
2089
|
+
* Supports direct calls and local callers that announce tools in conversation
|
|
2090
|
+
* messages (code mode with `toolDiscovery: 'conversation'`). Discovered tools
|
|
2091
|
+
* become available on the next model step.
|
|
2092
|
+
*/
|
|
2093
|
+
deferLoading?: boolean;
|
|
2094
|
+
/**
|
|
2095
|
+
* An optional title of the tool.
|
|
2096
|
+
*
|
|
2097
|
+
* @deprecated Use `providerMetadata` for source-specific tool display metadata.
|
|
2098
|
+
*/
|
|
2099
|
+
title?: string;
|
|
2100
|
+
/**
|
|
2101
|
+
* Additional provider-specific metadata. They are passed through
|
|
2102
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
2103
|
+
* functionality that can be fully encapsulated in the provider.
|
|
2104
|
+
*/
|
|
2105
|
+
providerOptions?: ProviderOptions;
|
|
2106
|
+
/**
|
|
2107
|
+
* Optional metadata about the tool itself (e.g. its source).
|
|
2108
|
+
*
|
|
2109
|
+
* Unlike `providerOptions`, this metadata is not sent to the language
|
|
2110
|
+
* model. Instead, it is propagated onto the resulting tool call's
|
|
2111
|
+
* `toolMetadata` so consumers can read it from tool call / result parts
|
|
2112
|
+
* and UI message parts. This is useful for sources of dynamic tools (e.g.
|
|
2113
|
+
* an MCP server) to identify themselves.
|
|
2114
|
+
*/
|
|
2115
|
+
metadata?: JSONObject;
|
|
2116
|
+
/**
|
|
2117
|
+
* The schema of the input that the tool expects.
|
|
2118
|
+
* The language model will use this to generate the input.
|
|
2119
|
+
* It is also used to validate the output of the language model.
|
|
2120
|
+
*
|
|
2121
|
+
* You can use descriptions on the schema properties to make the input understandable for the language model.
|
|
2122
|
+
*/
|
|
2123
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
2124
|
+
/**
|
|
2125
|
+
* An optional schema describing the context that the tool expects.
|
|
2126
|
+
*
|
|
2127
|
+
* The context is passed to execute function as part of the execution options.
|
|
2128
|
+
*/
|
|
2129
|
+
contextSchema?: FlexibleSchema<CONTEXT>;
|
|
2130
|
+
/**
|
|
2131
|
+
* Whether the tool needs approval before it can be executed.
|
|
2132
|
+
*
|
|
2133
|
+
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
2134
|
+
*/
|
|
2135
|
+
needsApproval?: boolean | ToolNeedsApprovalFunction<[INPUT] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
|
|
2136
|
+
/**
|
|
2137
|
+
* Optional function that is called when the model starts generating the tool input.
|
|
2138
|
+
* In non-streaming contexts, it is called immediately before `onInputAvailable`.
|
|
2139
|
+
*/
|
|
2140
|
+
onInputStart?: (options: ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
2141
|
+
/**
|
|
2142
|
+
* Optional function that is called when an argument streaming delta is available.
|
|
2143
|
+
* Only called when the tool is used in a streaming context.
|
|
2144
|
+
*/
|
|
2145
|
+
onInputDelta?: (options: {
|
|
2146
|
+
inputTextDelta: string;
|
|
2147
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
2148
|
+
/**
|
|
2149
|
+
* Optional function that is called when a tool call can be started,
|
|
2150
|
+
* even if the execute function is not provided.
|
|
2151
|
+
*/
|
|
2152
|
+
onInputAvailable?: (options: {
|
|
2153
|
+
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
2154
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
2155
|
+
/**
|
|
2156
|
+
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
2157
|
+
*
|
|
2158
|
+
* If not provided, the tool result will be sent as a JSON object.
|
|
2159
|
+
*
|
|
2160
|
+
* This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
|
|
2161
|
+
*/
|
|
2162
|
+
toModelOutput?: (options: {
|
|
2006
2163
|
/**
|
|
2007
|
-
*
|
|
2008
|
-
* Supports direct calls and local callers that announce tools in conversation
|
|
2009
|
-
* messages (code mode with `toolDiscovery: 'conversation'`). Discovered tools
|
|
2010
|
-
* become available on the next model step.
|
|
2011
|
-
*/
|
|
2012
|
-
deferLoading?: boolean;
|
|
2013
|
-
/**
|
|
2014
|
-
* An optional title of the tool.
|
|
2015
|
-
*
|
|
2016
|
-
* @deprecated Use `providerMetadata` for source-specific tool display metadata.
|
|
2017
|
-
*/
|
|
2018
|
-
title?: string;
|
|
2019
|
-
/**
|
|
2020
|
-
* Additional provider-specific metadata. They are passed through
|
|
2021
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
2022
|
-
* functionality that can be fully encapsulated in the provider.
|
|
2023
|
-
*/
|
|
2024
|
-
providerOptions?: ProviderOptions;
|
|
2025
|
-
/**
|
|
2026
|
-
* Optional metadata about the tool itself (e.g. its source).
|
|
2027
|
-
*
|
|
2028
|
-
* Unlike `providerOptions`, this metadata is not sent to the language
|
|
2029
|
-
* model. Instead, it is propagated onto the resulting tool call's
|
|
2030
|
-
* `toolMetadata` so consumers can read it from tool call / result parts
|
|
2031
|
-
* and UI message parts. This is useful for sources of dynamic tools (e.g.
|
|
2032
|
-
* an MCP server) to identify themselves.
|
|
2033
|
-
*/
|
|
2034
|
-
metadata?: JSONObject;
|
|
2035
|
-
/**
|
|
2036
|
-
* The schema of the input that the tool expects.
|
|
2037
|
-
* The language model will use this to generate the input.
|
|
2038
|
-
* It is also used to validate the output of the language model.
|
|
2039
|
-
*
|
|
2040
|
-
* You can use descriptions on the schema properties to make the input understandable for the language model.
|
|
2041
|
-
*/
|
|
2042
|
-
inputSchema: FlexibleSchema<INPUT>;
|
|
2043
|
-
/**
|
|
2044
|
-
* An optional schema describing the context that the tool expects.
|
|
2045
|
-
*
|
|
2046
|
-
* The context is passed to execute function as part of the execution options.
|
|
2047
|
-
*/
|
|
2048
|
-
contextSchema?: FlexibleSchema<CONTEXT>;
|
|
2049
|
-
/**
|
|
2050
|
-
* Whether the tool needs approval before it can be executed.
|
|
2051
|
-
*
|
|
2052
|
-
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
2053
|
-
*/
|
|
2054
|
-
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
2055
|
-
INPUT
|
|
2056
|
-
] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
|
|
2057
|
-
/**
|
|
2058
|
-
* Optional function that is called when the model starts generating the tool input.
|
|
2059
|
-
* In non-streaming contexts, it is called immediately before `onInputAvailable`.
|
|
2060
|
-
*/
|
|
2061
|
-
onInputStart?: (options: ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
2062
|
-
/**
|
|
2063
|
-
* Optional function that is called when an argument streaming delta is available.
|
|
2064
|
-
* Only called when the tool is used in a streaming context.
|
|
2164
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
2065
2165
|
*/
|
|
2066
|
-
|
|
2067
|
-
inputTextDelta: string;
|
|
2068
|
-
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
2166
|
+
toolCallId: string;
|
|
2069
2167
|
/**
|
|
2070
|
-
*
|
|
2071
|
-
* even if the execute function is not provided.
|
|
2168
|
+
* The input of the tool call.
|
|
2072
2169
|
*/
|
|
2073
|
-
|
|
2074
|
-
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
2075
|
-
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
2170
|
+
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
2076
2171
|
/**
|
|
2077
|
-
*
|
|
2078
|
-
*
|
|
2079
|
-
* If not provided, the tool result will be sent as a JSON object.
|
|
2080
|
-
*
|
|
2081
|
-
* This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
|
|
2172
|
+
* The output of the tool call.
|
|
2082
2173
|
*/
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
2086
|
-
*/
|
|
2087
|
-
toolCallId: string;
|
|
2088
|
-
/**
|
|
2089
|
-
* The input of the tool call.
|
|
2090
|
-
*/
|
|
2091
|
-
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
2092
|
-
/**
|
|
2093
|
-
* The output of the tool call.
|
|
2094
|
-
*/
|
|
2095
|
-
output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
|
|
2096
|
-
}) => ToolResultOutput | PromiseLike<ToolResultOutput>;
|
|
2174
|
+
output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
|
|
2175
|
+
}) => ToolResultOutput | PromiseLike<ToolResultOutput>;
|
|
2097
2176
|
} & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>>;
|
|
2098
2177
|
/**
|
|
2099
2178
|
* Common properties shared by function-style tools.
|
|
2100
2179
|
*/
|
|
2101
2180
|
type BaseFunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2181
|
+
/**
|
|
2182
|
+
* Optional description of what the tool does.
|
|
2183
|
+
*
|
|
2184
|
+
* Included in the tool definition sent to the language model so it can
|
|
2185
|
+
* decide when and how to call the tool.
|
|
2186
|
+
*
|
|
2187
|
+
* Provide a string for a fixed description, or a function that returns a
|
|
2188
|
+
* string from the current `context` (and optional `experimental_sandbox`) when the
|
|
2189
|
+
* description should vary per call.
|
|
2190
|
+
*/
|
|
2191
|
+
description?: string | ((options: {
|
|
2192
|
+
context: NoInfer<CONTEXT>;
|
|
2193
|
+
experimental_sandbox?: SandboxSession;
|
|
2194
|
+
}) => string);
|
|
2195
|
+
/**
|
|
2196
|
+
* Strict mode setting for the tool.
|
|
2197
|
+
*
|
|
2198
|
+
* Providers that support strict mode will use this setting to determine
|
|
2199
|
+
* how the input should be generated. Strict mode will always produce
|
|
2200
|
+
* valid inputs, but it might limit what input schemas are supported.
|
|
2201
|
+
*/
|
|
2202
|
+
strict?: boolean;
|
|
2203
|
+
/**
|
|
2204
|
+
* An optional list of input examples that show the language
|
|
2205
|
+
* model what the input should look like.
|
|
2206
|
+
*/
|
|
2207
|
+
inputExamples?: Array<{
|
|
2208
|
+
input: NoInfer<INPUT>;
|
|
2209
|
+
}>;
|
|
2210
|
+
id?: never;
|
|
2211
|
+
isProviderExecuted?: never;
|
|
2212
|
+
args?: never;
|
|
2213
|
+
supportsDeferredResults?: never;
|
|
2135
2214
|
};
|
|
2136
2215
|
/**
|
|
2137
2216
|
* Tool with user-defined input and output schemas that is executed by the AI SDK.
|
|
2138
2217
|
*/
|
|
2139
2218
|
type FunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
|
|
2140
|
-
|
|
2219
|
+
type?: undefined | 'function';
|
|
2141
2220
|
};
|
|
2142
2221
|
/**
|
|
2143
2222
|
* Tool that is defined at runtime.
|
|
@@ -2146,24 +2225,24 @@ type FunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extend
|
|
|
2146
2225
|
* For example, MCP tools that are not known at development time.
|
|
2147
2226
|
*/
|
|
2148
2227
|
type DynamicTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
|
|
2149
|
-
|
|
2228
|
+
type: 'dynamic';
|
|
2150
2229
|
};
|
|
2151
2230
|
/**
|
|
2152
2231
|
* Common properties shared by provider tools.
|
|
2153
2232
|
*/
|
|
2154
2233
|
type BaseProviderTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2234
|
+
type: 'provider';
|
|
2235
|
+
/**
|
|
2236
|
+
* The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
|
|
2237
|
+
*/
|
|
2238
|
+
id: `${string}.${string}`;
|
|
2239
|
+
/**
|
|
2240
|
+
* The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
|
2241
|
+
*/
|
|
2242
|
+
args: Record<string, unknown>;
|
|
2243
|
+
description?: never;
|
|
2244
|
+
strict?: never;
|
|
2245
|
+
inputExamples?: never;
|
|
2167
2246
|
};
|
|
2168
2247
|
/**
|
|
2169
2248
|
* Tool with provider-defined input and output schemas that is executed by the
|
|
@@ -2172,11 +2251,11 @@ type BaseProviderTool<INPUT extends JSONValue | unknown | never = any, OUTPUT ex
|
|
|
2172
2251
|
* For example, shell tools that are executed in a local shell, but have provider-defined input and output schemas.
|
|
2173
2252
|
*/
|
|
2174
2253
|
type ProviderDefinedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2254
|
+
/**
|
|
2255
|
+
* Flag that indicates whether the tool is executed by the provider.
|
|
2256
|
+
*/
|
|
2257
|
+
isProviderExecuted: false;
|
|
2258
|
+
supportsDeferredResults?: never;
|
|
2180
2259
|
};
|
|
2181
2260
|
/**
|
|
2182
2261
|
* Tool with provider-defined input and output schemas that is executed by the
|
|
@@ -2185,24 +2264,24 @@ type ProviderDefinedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT
|
|
|
2185
2264
|
* For example, web search tools and code execution tools that are executed by the provider itself.
|
|
2186
2265
|
*/
|
|
2187
2266
|
type ProviderExecutedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2267
|
+
/**
|
|
2268
|
+
* Flag that indicates whether the tool is executed by the provider.
|
|
2269
|
+
*/
|
|
2270
|
+
isProviderExecuted: true;
|
|
2271
|
+
/**
|
|
2272
|
+
* Whether this provider-executed tool supports deferred results.
|
|
2273
|
+
*
|
|
2274
|
+
* When true, the tool result may not be returned in the same turn as the
|
|
2275
|
+
* tool call (e.g., when using programmatic tool calling where a server tool
|
|
2276
|
+
* triggers a client-executed tool, and the server tool's result is deferred
|
|
2277
|
+
* until the client tool is resolved).
|
|
2278
|
+
*
|
|
2279
|
+
* This flag allows the AI SDK to handle tool results that arrive without
|
|
2280
|
+
* a matching tool call in the current response.
|
|
2281
|
+
*
|
|
2282
|
+
* @default false
|
|
2283
|
+
*/
|
|
2284
|
+
supportsDeferredResults?: boolean;
|
|
2206
2285
|
};
|
|
2207
2286
|
/**
|
|
2208
2287
|
* A tool can either be user-defined or provider-defined.
|
|
@@ -2221,73 +2300,76 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
2221
2300
|
* `ExecutableTool<Tool<...>>` so that `.execute` is non-nullable without
|
|
2222
2301
|
* needing `isExecutableTool` or a `!` assertion at the call site.
|
|
2223
2302
|
*/
|
|
2224
|
-
declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT> & {
|
|
2225
|
-
|
|
2303
|
+
declare function tool$1<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT> & {
|
|
2304
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
2226
2305
|
}): ExecutableTool<Tool<INPUT, OUTPUT, CONTEXT>>;
|
|
2227
|
-
declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
|
|
2228
|
-
declare function tool<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
|
|
2229
|
-
declare function tool<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
|
|
2230
|
-
declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
|
|
2306
|
+
declare function tool$1<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
|
|
2307
|
+
declare function tool$1<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
|
|
2308
|
+
declare function tool$1<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
|
|
2309
|
+
declare function tool$1<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
|
|
2231
2310
|
/**
|
|
2232
2311
|
* Define a dynamic tool.
|
|
2233
2312
|
*/
|
|
2234
|
-
declare function dynamicTool(tool: Omit<DynamicTool<unknown, unknown, Context>, 'type'>): DynamicTool<unknown, unknown, Context>;
|
|
2235
|
-
|
|
2313
|
+
export declare function dynamicTool(tool: Omit<DynamicTool<unknown, unknown, Context>, 'type'>): DynamicTool<unknown, unknown, Context>;
|
|
2314
|
+
//#endregion
|
|
2315
|
+
//#region src/provider-defined-tool-factory.d.ts
|
|
2236
2316
|
/**
|
|
2237
2317
|
* A provider-defined tool is a tool for which the provider defines the input
|
|
2238
2318
|
* and output schemas, but does not execute the tool.
|
|
2239
2319
|
*/
|
|
2240
2320
|
type ProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}> = <OUTPUT>(options: ARGS & {
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2321
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
2322
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
2323
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
2324
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
2325
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
2326
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
2247
2327
|
}) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
|
|
2248
|
-
declare function createProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema
|
|
2249
|
-
|
|
2250
|
-
|
|
2328
|
+
export declare function createProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema }: {
|
|
2329
|
+
id: `${string}.${string}`;
|
|
2330
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
2251
2331
|
}): ProviderDefinedToolFactory<INPUT, ARGS, CONTEXT>;
|
|
2252
2332
|
type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2333
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
2334
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
2335
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
2336
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
2337
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
2338
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
2259
2339
|
}) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
|
|
2260
|
-
declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2340
|
+
export declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema }: {
|
|
2341
|
+
id: `${string}.${string}`;
|
|
2342
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
2343
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
2264
2344
|
}): ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
2265
|
-
|
|
2345
|
+
//#endregion
|
|
2346
|
+
//#region src/provider-executed-tool-factory.d.ts
|
|
2266
2347
|
/**
|
|
2267
2348
|
* A provider-executed tool is a tool for which the provider executes the tool.
|
|
2268
2349
|
*/
|
|
2269
2350
|
type ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2351
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
2352
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
2353
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
2273
2354
|
}) => ProviderExecutedTool<INPUT, OUTPUT, CONTEXT>;
|
|
2274
|
-
declare function createProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2355
|
+
export declare function createProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults }: {
|
|
2356
|
+
id: `${string}.${string}`;
|
|
2357
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
2358
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
2359
|
+
/**
|
|
2360
|
+
* Whether this provider-executed tool supports deferred results.
|
|
2361
|
+
*
|
|
2362
|
+
* When true, the tool result may not be returned in the same turn as the
|
|
2363
|
+
* tool call (e.g., when using programmatic tool calling where a server tool
|
|
2364
|
+
* triggers a client-executed tool, and the server tool's result is deferred
|
|
2365
|
+
* until the client tool is resolved).
|
|
2366
|
+
*
|
|
2367
|
+
* @default false
|
|
2368
|
+
*/
|
|
2369
|
+
supportsDeferredResults?: boolean;
|
|
2289
2370
|
}): ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
2290
|
-
|
|
2371
|
+
//#endregion
|
|
2372
|
+
//#region src/cancel-response-body.d.ts
|
|
2291
2373
|
/**
|
|
2292
2374
|
* Cancels a response body to release the underlying connection.
|
|
2293
2375
|
*
|
|
@@ -2300,8 +2382,9 @@ declare function createProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends o
|
|
|
2300
2382
|
* Errors thrown while cancelling are ignored: the body may already be locked,
|
|
2301
2383
|
* disturbed, or absent, none of which should mask the original rejection.
|
|
2302
2384
|
*/
|
|
2303
|
-
declare function cancelResponseBody(response: Response): Promise<void>;
|
|
2304
|
-
|
|
2385
|
+
export declare function cancelResponseBody(response: Response): Promise<void>;
|
|
2386
|
+
//#endregion
|
|
2387
|
+
//#region src/read-response-with-size-limit.d.ts
|
|
2305
2388
|
/**
|
|
2306
2389
|
* Default maximum download size: 2 GiB.
|
|
2307
2390
|
*
|
|
@@ -2313,7 +2396,7 @@ declare function cancelResponseBody(response: Response): Promise<void>;
|
|
|
2313
2396
|
* Setting this limit converts an unrecoverable OOM crash into a catchable
|
|
2314
2397
|
* `DownloadError`.
|
|
2315
2398
|
*/
|
|
2316
|
-
declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
|
|
2399
|
+
export declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
|
|
2317
2400
|
/**
|
|
2318
2401
|
* Reads a fetch Response body with a size limit to prevent memory exhaustion.
|
|
2319
2402
|
*
|
|
@@ -2327,19 +2410,21 @@ declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
|
|
|
2327
2410
|
* @returns A Uint8Array containing the response body.
|
|
2328
2411
|
* @throws DownloadError if the response exceeds maxBytes.
|
|
2329
2412
|
*/
|
|
2330
|
-
declare function readResponseWithSizeLimit({ response, url, maxBytes
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2413
|
+
export declare function readResponseWithSizeLimit({ response, url, maxBytes }: {
|
|
2414
|
+
response: Response;
|
|
2415
|
+
url: string;
|
|
2416
|
+
maxBytes?: number;
|
|
2334
2417
|
}): Promise<Uint8Array>;
|
|
2335
|
-
|
|
2418
|
+
//#endregion
|
|
2419
|
+
//#region src/remove-undefined-entries.d.ts
|
|
2336
2420
|
/**
|
|
2337
2421
|
* Removes entries from a record where the value is null or undefined.
|
|
2338
2422
|
* @param record - The input object whose entries may be null or undefined.
|
|
2339
2423
|
* @returns A new object containing only entries with non-null and non-undefined values.
|
|
2340
2424
|
*/
|
|
2341
|
-
declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
|
|
2342
|
-
|
|
2425
|
+
export declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
|
|
2426
|
+
//#endregion
|
|
2427
|
+
//#region src/resolve.d.ts
|
|
2343
2428
|
/**
|
|
2344
2429
|
* A value or a lazy provider of a value, each of which may be synchronous or asynchronous.
|
|
2345
2430
|
*
|
|
@@ -2355,13 +2440,14 @@ declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>
|
|
|
2355
2440
|
* a {@link T} that happens to be a function—callers should wrap function values if disambiguation
|
|
2356
2441
|
* is required.
|
|
2357
2442
|
*/
|
|
2358
|
-
type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
|
|
2443
|
+
export type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
|
|
2359
2444
|
/**
|
|
2360
2445
|
* Resolves a value that could be a raw value, a Promise, a function returning a value,
|
|
2361
2446
|
* or a function returning a Promise.
|
|
2362
2447
|
*/
|
|
2363
|
-
declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
|
2364
|
-
|
|
2448
|
+
export declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
|
2449
|
+
//#endregion
|
|
2450
|
+
//#region src/resolve-full-media-type.d.ts
|
|
2365
2451
|
/**
|
|
2366
2452
|
* Resolves a file part's media type to a full `type/subtype` form required by
|
|
2367
2453
|
* providers whose API demands the full IANA media type.
|
|
@@ -2374,45 +2460,48 @@ declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
|
|
2374
2460
|
* - When neither applies (e.g. top-level-only with a URL source, or bytes that
|
|
2375
2461
|
* cannot be detected), an `UnsupportedFunctionalityError` is thrown.
|
|
2376
2462
|
*/
|
|
2377
|
-
declare function resolveFullMediaType({ part
|
|
2378
|
-
|
|
2463
|
+
export declare function resolveFullMediaType({ part }: {
|
|
2464
|
+
part: LanguageModelV4FilePart;
|
|
2379
2465
|
}): string;
|
|
2380
|
-
|
|
2466
|
+
//#endregion
|
|
2467
|
+
//#region src/resolve-provider-reference.d.ts
|
|
2381
2468
|
/**
|
|
2382
2469
|
* Resolves a provider reference to the provider-specific identifier for the
|
|
2383
2470
|
* given provider. Throws `NoSuchProviderReferenceError` if the provider is not
|
|
2384
2471
|
* found in the reference mapping.
|
|
2385
2472
|
*/
|
|
2386
|
-
declare function resolveProviderReference({ reference, provider
|
|
2387
|
-
|
|
2388
|
-
|
|
2473
|
+
export declare function resolveProviderReference({ reference, provider }: {
|
|
2474
|
+
reference: SharedV4ProviderReference;
|
|
2475
|
+
provider: string;
|
|
2389
2476
|
}): string;
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
type
|
|
2393
|
-
type
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2477
|
+
//#endregion
|
|
2478
|
+
//#region src/retry-with-exponential-backoff.d.ts
|
|
2479
|
+
export type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
|
|
2480
|
+
export type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable';
|
|
2481
|
+
export type RetryErrorFactory = ({ message, reason, errors }: {
|
|
2482
|
+
message: string;
|
|
2483
|
+
reason: RetryErrorReason;
|
|
2484
|
+
errors: Array<unknown>;
|
|
2397
2485
|
}) => unknown;
|
|
2398
|
-
type RetryDelayProvider = ({ error, exponentialBackoffDelay
|
|
2399
|
-
|
|
2400
|
-
|
|
2486
|
+
export type RetryDelayProvider = ({ error, exponentialBackoffDelay }: {
|
|
2487
|
+
error: unknown;
|
|
2488
|
+
exponentialBackoffDelay: number;
|
|
2401
2489
|
}) => number;
|
|
2402
|
-
type ShouldRetryFunction = (error: unknown) => boolean | Promise<boolean>;
|
|
2490
|
+
export type ShouldRetryFunction = (error: unknown) => boolean | Promise<boolean>;
|
|
2403
2491
|
/**
|
|
2404
2492
|
* Retries a failed operation with exponential backoff.
|
|
2405
2493
|
*/
|
|
2406
|
-
declare const retryWithExponentialBackoff: ({ maxRetries, initialDelayInMs, backoffFactor, abortSignal, shouldRetry, getDelayInMs, createRetryError
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2494
|
+
export declare const retryWithExponentialBackoff: ({ maxRetries, initialDelayInMs, backoffFactor, abortSignal, shouldRetry, getDelayInMs, createRetryError }: {
|
|
2495
|
+
maxRetries?: number;
|
|
2496
|
+
initialDelayInMs?: number;
|
|
2497
|
+
backoffFactor?: number;
|
|
2498
|
+
abortSignal?: AbortSignal;
|
|
2499
|
+
shouldRetry: ShouldRetryFunction;
|
|
2500
|
+
getDelayInMs?: RetryDelayProvider;
|
|
2501
|
+
createRetryError?: RetryErrorFactory;
|
|
2414
2502
|
}) => RetryFunction;
|
|
2415
|
-
|
|
2503
|
+
//#endregion
|
|
2504
|
+
//#region src/serialize-model-options.d.ts
|
|
2416
2505
|
/**
|
|
2417
2506
|
* Serializes a model instance for workflow step boundaries.
|
|
2418
2507
|
* Returns the `modelId` plus the JSON-serializable config properties.
|
|
@@ -2433,67 +2522,70 @@ declare const retryWithExponentialBackoff: ({ maxRetries, initialDelayInMs, back
|
|
|
2433
2522
|
* }
|
|
2434
2523
|
* ```
|
|
2435
2524
|
*/
|
|
2436
|
-
declare function serializeModelOptions<CONFIG extends {
|
|
2437
|
-
|
|
2525
|
+
export declare function serializeModelOptions<CONFIG extends {
|
|
2526
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
2438
2527
|
}>(options: {
|
|
2439
|
-
|
|
2440
|
-
|
|
2528
|
+
modelId: string;
|
|
2529
|
+
config: CONFIG;
|
|
2441
2530
|
}): {
|
|
2442
|
-
|
|
2443
|
-
|
|
2531
|
+
modelId: string;
|
|
2532
|
+
config: JSONObject;
|
|
2444
2533
|
};
|
|
2445
|
-
|
|
2534
|
+
//#endregion
|
|
2535
|
+
//#region src/serialization-error.d.ts
|
|
2446
2536
|
declare const symbol: unique symbol;
|
|
2447
|
-
declare class SerializationError extends AISDKError {
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2537
|
+
export declare class SerializationError extends AISDKError {
|
|
2538
|
+
private readonly [symbol];
|
|
2539
|
+
constructor({ message, cause }?: {
|
|
2540
|
+
message?: string;
|
|
2541
|
+
cause?: unknown;
|
|
2542
|
+
});
|
|
2543
|
+
static isInstance(error: unknown): error is SerializationError;
|
|
2454
2544
|
}
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2545
|
+
//#endregion
|
|
2546
|
+
//#region src/secure-json-parse.d.ts
|
|
2547
|
+
export declare function secureJsonParse(text: string): any;
|
|
2548
|
+
//#endregion
|
|
2549
|
+
//#region src/streaming-tool-call-tracker.d.ts
|
|
2458
2550
|
/**
|
|
2459
2551
|
* Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
|
|
2460
2552
|
*/
|
|
2461
2553
|
interface StreamingToolCallDelta {
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2554
|
+
index?: number | null;
|
|
2555
|
+
id?: string | null;
|
|
2556
|
+
type?: string | null;
|
|
2557
|
+
function?: {
|
|
2558
|
+
name?: string | null;
|
|
2559
|
+
arguments?: string | null;
|
|
2560
|
+
} | null;
|
|
2469
2561
|
}
|
|
2470
2562
|
interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2563
|
+
/**
|
|
2564
|
+
* ID generator function for tool call IDs.
|
|
2565
|
+
* Blank or repeated outputs are converted to usable unique IDs.
|
|
2566
|
+
* Defaults to the standard generateId.
|
|
2567
|
+
*/
|
|
2568
|
+
generateId?: () => string;
|
|
2569
|
+
/**
|
|
2570
|
+
* How to validate the `type` field on new tool call deltas.
|
|
2571
|
+
* - `'none'`: no validation (default)
|
|
2572
|
+
* - `'if-present'`: throw if type is present and not `'function'`
|
|
2573
|
+
* - `'required'`: throw if type is not exactly `'function'`
|
|
2574
|
+
*/
|
|
2575
|
+
typeValidation?: 'none' | 'if-present' | 'required';
|
|
2576
|
+
/**
|
|
2577
|
+
* Extract provider-specific metadata from a tool call delta.
|
|
2578
|
+
* Called once when a new tool call is detected.
|
|
2579
|
+
* The returned metadata is stored on the tool call and passed to
|
|
2580
|
+
* `buildToolCallProviderMetadata` when the tool call is finalized.
|
|
2581
|
+
*/
|
|
2582
|
+
extractMetadata?: (delta: DELTA) => SharedV4ProviderMetadata | undefined;
|
|
2583
|
+
/**
|
|
2584
|
+
* Build the `providerMetadata` object for a `tool-call` event.
|
|
2585
|
+
* Receives the metadata previously extracted via `extractMetadata`.
|
|
2586
|
+
* If `undefined` is returned, no `providerMetadata` is included in the event.
|
|
2587
|
+
*/
|
|
2588
|
+
buildToolCallProviderMetadata?: (metadata: SharedV4ProviderMetadata | undefined) => SharedV4ProviderMetadata | undefined;
|
|
2497
2589
|
}
|
|
2498
2590
|
type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV4StreamPart>, 'enqueue'>;
|
|
2499
2591
|
/**
|
|
@@ -2505,54 +2597,55 @@ type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<
|
|
|
2505
2597
|
* Used by openai, openai-compatible, groq, deepseek, alibaba, mistral, and
|
|
2506
2598
|
* moonshotai providers.
|
|
2507
2599
|
*/
|
|
2508
|
-
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2600
|
+
export declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
2601
|
+
private toolCalls;
|
|
2602
|
+
private toolCallsById;
|
|
2603
|
+
private toolCallsByIndex;
|
|
2604
|
+
private usedToolCallIds;
|
|
2605
|
+
private nextGeneratedIdSuffixes;
|
|
2606
|
+
private readonly controller;
|
|
2607
|
+
private readonly _generateId;
|
|
2608
|
+
private readonly typeValidation;
|
|
2609
|
+
private readonly extractMetadata?;
|
|
2610
|
+
private readonly buildToolCallProviderMetadata?;
|
|
2611
|
+
constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
|
|
2612
|
+
/**
|
|
2613
|
+
* Process a tool call delta from a streaming response chunk.
|
|
2614
|
+
* Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
|
|
2615
|
+
* events as appropriate.
|
|
2616
|
+
*/
|
|
2617
|
+
processDelta(toolCallDelta: DELTA): void;
|
|
2618
|
+
/**
|
|
2619
|
+
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
2620
|
+
* flush handler to ensure all tool calls are properly completed.
|
|
2621
|
+
*/
|
|
2622
|
+
flush(): void;
|
|
2623
|
+
/**
|
|
2624
|
+
* Correlation precedence for streamed deltas:
|
|
2625
|
+
*
|
|
2626
|
+
* | ID evidence | index/name evidence | start evidence | resolution |
|
|
2627
|
+
* | --- | --- | --- | --- |
|
|
2628
|
+
* | known | matching | any | matching call, new call, or ambiguity |
|
|
2629
|
+
* | known | conflicting | named | new call |
|
|
2630
|
+
* | unseen | matching | structured start | new call |
|
|
2631
|
+
* | unseen | matching | continuation | matching call or ambiguity |
|
|
2632
|
+
* | absent | matching | any | matching call, new call, or ambiguity |
|
|
2633
|
+
* | absent | absent | named | new call |
|
|
2634
|
+
* | absent | absent | unnamed | sole unfinished call, new call, or ambiguity |
|
|
2635
|
+
*/
|
|
2636
|
+
private resolveToolCall;
|
|
2637
|
+
private filterToolCallsByName;
|
|
2638
|
+
private resolveMatchingToolCall;
|
|
2639
|
+
private processNewToolCall;
|
|
2640
|
+
private associateWireId;
|
|
2641
|
+
private associateIndex;
|
|
2642
|
+
private createToolCallId;
|
|
2643
|
+
private getNonBlankString;
|
|
2644
|
+
private processExistingToolCall;
|
|
2645
|
+
private finishToolCall;
|
|
2554
2646
|
}
|
|
2555
|
-
|
|
2647
|
+
//#endregion
|
|
2648
|
+
//#region src/strip-file-extension.d.ts
|
|
2556
2649
|
/**
|
|
2557
2650
|
* Strips file extension segments from a filename.
|
|
2558
2651
|
*
|
|
@@ -2561,8 +2654,9 @@ declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = St
|
|
|
2561
2654
|
* - "archive.tar.gz" -> "archive"
|
|
2562
2655
|
* - "filename" -> "filename"
|
|
2563
2656
|
*/
|
|
2564
|
-
declare function stripFileExtension(filename: string): string;
|
|
2565
|
-
|
|
2657
|
+
export declare function stripFileExtension(filename: string): string;
|
|
2658
|
+
//#endregion
|
|
2659
|
+
//#region src/transcription-stream-envelope.d.ts
|
|
2566
2660
|
/**
|
|
2567
2661
|
* Experimental transcription-stream WebSocket envelope (v1): the standard
|
|
2568
2662
|
* serialization of `TranscriptionModelV4.doStream` over a WebSocket. Clients
|
|
@@ -2608,30 +2702,30 @@ declare const TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE = "transcription-stream
|
|
|
2608
2702
|
* The client's session start frame. Optional keys are omitted when undefined.
|
|
2609
2703
|
*/
|
|
2610
2704
|
type TranscriptionStreamStartFrame = {
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2705
|
+
type: typeof TRANSCRIPTION_STREAM_START_FRAME_TYPE;
|
|
2706
|
+
/** Audio format of the binary audio frames, e.g. `{ type: 'audio/pcm', rate: 16000 }`. */
|
|
2707
|
+
inputAudioFormat: {
|
|
2708
|
+
type: string;
|
|
2709
|
+
rate?: number;
|
|
2710
|
+
};
|
|
2711
|
+
/** Provider-specific options, passed through verbatim. */
|
|
2712
|
+
providerOptions?: Record<string, JSONObject>;
|
|
2713
|
+
/** When true, the server should include `raw` parts in the stream. */
|
|
2714
|
+
includeRawChunks?: boolean;
|
|
2621
2715
|
};
|
|
2622
2716
|
/** Server-side classification of a client TEXT frame. */
|
|
2623
2717
|
type TranscriptionStreamClientFrame = {
|
|
2624
|
-
|
|
2625
|
-
|
|
2718
|
+
type: 'start';
|
|
2719
|
+
frame: TranscriptionStreamStartFrame;
|
|
2626
2720
|
} | {
|
|
2627
|
-
|
|
2721
|
+
type: 'audio-done';
|
|
2628
2722
|
} | {
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2723
|
+
/** Malformed JSON or a recognized frame with an invalid shape. */
|
|
2724
|
+
type: 'invalid';
|
|
2725
|
+
message: string;
|
|
2632
2726
|
} | {
|
|
2633
|
-
|
|
2634
|
-
|
|
2727
|
+
/** Unrecognized frame type; ignore for forward compatibility. */
|
|
2728
|
+
type: 'unknown';
|
|
2635
2729
|
};
|
|
2636
2730
|
/**
|
|
2637
2731
|
* Server-side: parse a client TEXT frame. Validates envelope shape only and
|
|
@@ -2658,13 +2752,16 @@ declare function serializeTranscriptionStreamPart(part: Experimental_Transcripti
|
|
|
2658
2752
|
* Revives `response-metadata.timestamp` to a `Date`.
|
|
2659
2753
|
*/
|
|
2660
2754
|
declare function parseTranscriptionStreamPart(text: string): Experimental_TranscriptionModelV4StreamPart | undefined;
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
declare function
|
|
2664
|
-
declare function
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2755
|
+
//#endregion
|
|
2756
|
+
//#region src/uint8-utils.d.ts
|
|
2757
|
+
export declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
2758
|
+
export declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
2759
|
+
export declare function convertToBase64(value: string | Uint8Array): string;
|
|
2760
|
+
//#endregion
|
|
2761
|
+
//#region src/validate-base-url.d.ts
|
|
2762
|
+
export declare function validateBaseURL(baseURL: string | undefined): string | undefined;
|
|
2763
|
+
//#endregion
|
|
2764
|
+
//#region src/validate-download-url.d.ts
|
|
2668
2765
|
/**
|
|
2669
2766
|
* Validates that a URL is safe to download from, blocking private/internal addresses
|
|
2670
2767
|
* to prevent SSRF attacks.
|
|
@@ -2675,8 +2772,9 @@ declare function validateBaseURL(baseURL: string | undefined): string | undefine
|
|
|
2675
2772
|
* @param url - The URL string to validate.
|
|
2676
2773
|
* @throws DownloadError if the URL is unsafe.
|
|
2677
2774
|
*/
|
|
2678
|
-
declare function validateDownloadUrl(url: string): void;
|
|
2679
|
-
|
|
2775
|
+
export declare function validateDownloadUrl(url: string): void;
|
|
2776
|
+
//#endregion
|
|
2777
|
+
//#region src/validate-types.d.ts
|
|
2680
2778
|
/**
|
|
2681
2779
|
* Validates the types of an unknown object using a schema and
|
|
2682
2780
|
* return a strongly-typed object.
|
|
@@ -2687,10 +2785,10 @@ declare function validateDownloadUrl(url: string): void;
|
|
|
2687
2785
|
* @param {TypeValidationContext} options.context - Optional context about what is being validated.
|
|
2688
2786
|
* @returns {Promise<T>} - The typed object.
|
|
2689
2787
|
*/
|
|
2690
|
-
declare function validateTypes<OBJECT>({ value, schema, context
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2788
|
+
export declare function validateTypes<OBJECT>({ value, schema, context }: {
|
|
2789
|
+
value: unknown;
|
|
2790
|
+
schema: FlexibleSchema<OBJECT>;
|
|
2791
|
+
context?: TypeValidationContext;
|
|
2694
2792
|
}): Promise<OBJECT>;
|
|
2695
2793
|
/**
|
|
2696
2794
|
* Safely validates the types of an unknown object using a schema and
|
|
@@ -2702,22 +2800,24 @@ declare function validateTypes<OBJECT>({ value, schema, context, }: {
|
|
|
2702
2800
|
* @param {TypeValidationContext} options.context - Optional context about what is being validated.
|
|
2703
2801
|
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
2704
2802
|
*/
|
|
2705
|
-
declare function safeValidateTypes<OBJECT>({ value, schema, context
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2803
|
+
export declare function safeValidateTypes<OBJECT>({ value, schema, context }: {
|
|
2804
|
+
value: unknown;
|
|
2805
|
+
schema: FlexibleSchema<OBJECT>;
|
|
2806
|
+
context?: TypeValidationContext;
|
|
2709
2807
|
}): Promise<{
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2808
|
+
success: true;
|
|
2809
|
+
value: OBJECT;
|
|
2810
|
+
rawValue: unknown;
|
|
2713
2811
|
} | {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2812
|
+
success: false;
|
|
2813
|
+
error: TypeValidationError;
|
|
2814
|
+
rawValue: unknown;
|
|
2717
2815
|
}>;
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2816
|
+
//#endregion
|
|
2817
|
+
//#region src/version.d.ts
|
|
2818
|
+
export declare const VERSION: string;
|
|
2819
|
+
//#endregion
|
|
2820
|
+
//#region src/with-user-agent-suffix.d.ts
|
|
2721
2821
|
/**
|
|
2722
2822
|
* Appends suffix parts to the `user-agent` header.
|
|
2723
2823
|
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
|
@@ -2728,10 +2828,12 @@ declare const VERSION: string;
|
|
|
2728
2828
|
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
|
2729
2829
|
* @returns The new headers with the `user-agent` header set or updated.
|
|
2730
2830
|
*/
|
|
2731
|
-
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2831
|
+
export declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
|
2832
|
+
//#endregion
|
|
2833
|
+
//#region src/without-trailing-slash.d.ts
|
|
2834
|
+
export declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
|
2835
|
+
//#endregion
|
|
2836
|
+
//#region src/types/infer-tool-context.d.ts
|
|
2735
2837
|
/**
|
|
2736
2838
|
* Detects the `any` type so untyped tools can be treated as having no explicit
|
|
2737
2839
|
* context type.
|
|
@@ -2751,17 +2853,20 @@ type IsUntypedContext<CONTEXT> = IsAny<CONTEXT> extends true ? true : unknown ex
|
|
|
2751
2853
|
* Infer the context type of a tool.
|
|
2752
2854
|
*/
|
|
2753
2855
|
type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? IsUntypedContext<CONTEXT> extends true ? never : CONTEXT : never;
|
|
2754
|
-
|
|
2856
|
+
//#endregion
|
|
2857
|
+
//#region src/types/infer-tool-input.d.ts
|
|
2755
2858
|
/**
|
|
2756
2859
|
* Infer the input type of a tool.
|
|
2757
2860
|
*/
|
|
2758
2861
|
type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer INPUT, any, any> ? INPUT : never;
|
|
2759
|
-
|
|
2862
|
+
//#endregion
|
|
2863
|
+
//#region src/types/infer-tool-output.d.ts
|
|
2760
2864
|
/**
|
|
2761
2865
|
* Infer the output type of a tool.
|
|
2762
2866
|
*/
|
|
2763
2867
|
type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
|
|
2764
|
-
|
|
2868
|
+
//#endregion
|
|
2869
|
+
//#region src/types/execute-tool.d.ts
|
|
2765
2870
|
/**
|
|
2766
2871
|
* Executes a tool function and normalizes its results into a stream of outputs.
|
|
2767
2872
|
*
|
|
@@ -2776,44 +2881,40 @@ type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any,
|
|
|
2776
2881
|
* @yields A preliminary output for each streamed value, followed by a final output, or a single final
|
|
2777
2882
|
* output for non-streaming tools.
|
|
2778
2883
|
*/
|
|
2779
|
-
declare function executeTool<TOOL extends Tool>({ tool, input, options
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2884
|
+
export declare function executeTool<TOOL extends Tool>({ tool, input, options }: {
|
|
2885
|
+
tool: ExecutableTool<TOOL>;
|
|
2886
|
+
input: InferToolInput<TOOL>;
|
|
2887
|
+
options: ToolExecutionOptions<InferToolContext<TOOL>>;
|
|
2783
2888
|
}): AsyncGenerator<{
|
|
2784
|
-
|
|
2785
|
-
|
|
2889
|
+
type: 'preliminary';
|
|
2890
|
+
output: InferToolOutput<TOOL>;
|
|
2786
2891
|
} | {
|
|
2787
|
-
|
|
2788
|
-
|
|
2892
|
+
type: 'final';
|
|
2893
|
+
output: InferToolOutput<TOOL>;
|
|
2789
2894
|
}>;
|
|
2790
|
-
|
|
2895
|
+
//#endregion
|
|
2896
|
+
//#region src/types/tool-set.d.ts
|
|
2791
2897
|
/**
|
|
2792
2898
|
* A mapping of tool names to tool definitions.
|
|
2793
2899
|
*/
|
|
2794
2900
|
type ToolSet = Record<string, (Tool<never, never, any> | Tool<any, any, any> | Tool<any, never, any> | Tool<never, any, any>) & Pick<Tool<any, any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
|
|
2795
|
-
|
|
2901
|
+
//#endregion
|
|
2902
|
+
//#region src/types/infer-tool-set-context.d.ts
|
|
2796
2903
|
/**
|
|
2797
2904
|
* Builds the required portion of the tool context map for tools whose context
|
|
2798
2905
|
* type does not include `undefined`.
|
|
2799
2906
|
*/
|
|
2800
|
-
type RequiredToolSetContext<TOOLS extends ToolSet> = {
|
|
2801
|
-
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
2802
|
-
};
|
|
2907
|
+
type RequiredToolSetContext<TOOLS extends ToolSet> = { [K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>; };
|
|
2803
2908
|
/**
|
|
2804
2909
|
* Builds the optional portion of the tool context map for tools whose context
|
|
2805
2910
|
* object itself may be `undefined`.
|
|
2806
2911
|
*/
|
|
2807
|
-
type OptionalToolSetContext<TOOLS extends ToolSet> = {
|
|
2808
|
-
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? K : never]?: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
2809
|
-
};
|
|
2912
|
+
type OptionalToolSetContext<TOOLS extends ToolSet> = { [K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? K : never]?: InferToolContext<NoInfer<TOOLS[K]>>; };
|
|
2810
2913
|
/**
|
|
2811
2914
|
* Flattens intersected mapped types so type equality assertions and editor
|
|
2812
2915
|
* hovers show the resulting object shape.
|
|
2813
2916
|
*/
|
|
2814
|
-
type Normalize<OBJECT> = {
|
|
2815
|
-
[KEY in keyof OBJECT]: OBJECT[KEY];
|
|
2816
|
-
};
|
|
2917
|
+
type Normalize<OBJECT> = { [KEY in keyof OBJECT]: OBJECT[KEY]; };
|
|
2817
2918
|
/**
|
|
2818
2919
|
* Infer the context type for a tool set.
|
|
2819
2920
|
*
|
|
@@ -2823,85 +2924,89 @@ type Normalize<OBJECT> = {
|
|
|
2823
2924
|
* `undefined` are represented as optional properties.
|
|
2824
2925
|
*/
|
|
2825
2926
|
type InferToolSetContext<TOOLS extends ToolSet> = Normalize<RequiredToolSetContext<TOOLS> & OptionalToolSetContext<TOOLS>>;
|
|
2826
|
-
|
|
2927
|
+
//#endregion
|
|
2928
|
+
//#region src/types/tool-call.d.ts
|
|
2827
2929
|
/**
|
|
2828
2930
|
* Typed tool call that is returned by generateText and streamText.
|
|
2829
2931
|
* It contains the tool call ID, the tool name, and the tool arguments.
|
|
2830
2932
|
*/
|
|
2831
2933
|
interface ToolCall<NAME extends string, INPUT> {
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2934
|
+
/**
|
|
2935
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
2936
|
+
*/
|
|
2937
|
+
toolCallId: string;
|
|
2938
|
+
/**
|
|
2939
|
+
* Name of the tool that is being called.
|
|
2940
|
+
*/
|
|
2941
|
+
toolName: NAME;
|
|
2942
|
+
/**
|
|
2943
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
2944
|
+
*/
|
|
2945
|
+
input: INPUT;
|
|
2946
|
+
/**
|
|
2947
|
+
* Whether the tool call will be executed by the provider.
|
|
2948
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
|
2949
|
+
*/
|
|
2950
|
+
providerExecuted?: boolean;
|
|
2951
|
+
/**
|
|
2952
|
+
* Whether the tool is dynamic.
|
|
2953
|
+
*/
|
|
2954
|
+
dynamic?: boolean;
|
|
2853
2955
|
}
|
|
2854
|
-
|
|
2956
|
+
//#endregion
|
|
2957
|
+
//#region src/types/tool-caller.d.ts
|
|
2855
2958
|
type ToolCallerDefinition = {
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2959
|
+
type: 'local';
|
|
2960
|
+
bind: (tools: ToolSet) => Tool;
|
|
2961
|
+
/**
|
|
2962
|
+
* Creates a provider-agnostic user message that describes the tools
|
|
2963
|
+
* available through this caller. When present, the unbound caller tool
|
|
2964
|
+
* remains model-visible so its definition stays stable, while the
|
|
2965
|
+
* returned message is added to the conversation when its content has
|
|
2966
|
+
* not already been announced.
|
|
2967
|
+
*/
|
|
2968
|
+
prepareModelMessage?: (tools: ToolSet) => string | undefined;
|
|
2866
2969
|
} | {
|
|
2867
|
-
|
|
2868
|
-
|
|
2970
|
+
type: 'provider';
|
|
2971
|
+
prepareProviderOptions: (providerOptions: ProviderOptions | undefined) => ProviderOptions;
|
|
2869
2972
|
};
|
|
2870
2973
|
type ToolCallerTool<TOOL extends Tool = Tool> = TOOL & {
|
|
2871
|
-
|
|
2974
|
+
readonly experimental_toolCaller: ToolCallerDefinition;
|
|
2872
2975
|
};
|
|
2873
2976
|
declare function toolCaller<TOOL extends Tool>(tool: TOOL, definition: ToolCallerDefinition): ToolCallerTool<TOOL>;
|
|
2874
2977
|
declare function getToolCaller(tool: Tool | undefined): ToolCallerDefinition | undefined;
|
|
2875
|
-
|
|
2978
|
+
//#endregion
|
|
2979
|
+
//#region src/types/tool-result.d.ts
|
|
2876
2980
|
/**
|
|
2877
2981
|
* Typed tool result that is returned by `generateText` and `streamText`.
|
|
2878
2982
|
* It contains the tool call ID, the tool name, the tool arguments, and the tool result.
|
|
2879
2983
|
*/
|
|
2880
2984
|
interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2985
|
+
/**
|
|
2986
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
2987
|
+
*/
|
|
2988
|
+
toolCallId: string;
|
|
2989
|
+
/**
|
|
2990
|
+
* Name of the tool that was called.
|
|
2991
|
+
*/
|
|
2992
|
+
toolName: NAME;
|
|
2993
|
+
/**
|
|
2994
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
2995
|
+
*/
|
|
2996
|
+
input: INPUT;
|
|
2997
|
+
/**
|
|
2998
|
+
* Result of the tool call. This is the result of the tool's execution.
|
|
2999
|
+
*/
|
|
3000
|
+
output: OUTPUT;
|
|
3001
|
+
/**
|
|
3002
|
+
* Whether the tool result has been executed by the provider.
|
|
3003
|
+
*/
|
|
3004
|
+
providerExecuted?: boolean;
|
|
3005
|
+
/**
|
|
3006
|
+
* Whether the tool is dynamic.
|
|
3007
|
+
*/
|
|
3008
|
+
dynamic?: boolean;
|
|
2905
3009
|
}
|
|
2906
|
-
|
|
2907
|
-
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart,
|
|
3010
|
+
//#endregion
|
|
3011
|
+
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, type DataContent, type DynamicTool, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE, TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE, type EmbeddingModelProviderOptionsTransformer, type EventSourceMessage, EventSourceParserStream, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, type TranscriptionStreamClientFrame as Experimental_TranscriptionStreamClientFrame, type TranscriptionStreamStartFrame as Experimental_TranscriptionStreamStartFrame, 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 ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ProviderStreamError, type ReasoningFilePart, type ReasoningPart, type Schema, type StreamingToolCallDelta, 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, type ValidationResult, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, type WebSocketConnection, type WebSocketConstructor, type WebSocketLike, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, getErrorMessage, tool$1 as tool };
|
|
3012
|
+
//# sourceMappingURL=index.d.ts.map
|