ai 5.0.0-canary.3 → 5.0.0-canary.5
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 +30 -0
- package/dist/index.d.mts +1038 -178
- package/dist/index.d.ts +1038 -178
- package/dist/index.js +1839 -229
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1749 -178
- package/dist/index.mjs.map +1 -1
- package/{rsc/dist/rsc-server.d.mts → dist/internal/index.d.mts} +400 -366
- package/dist/internal/index.d.ts +782 -0
- package/dist/internal/index.js +1483 -0
- package/dist/internal/index.js.map +1 -0
- package/{rsc/dist/rsc-server.mjs → dist/internal/index.mjs} +1075 -1771
- package/dist/internal/index.mjs.map +1 -0
- package/mcp-stdio/dist/index.d.mts +6 -6
- package/mcp-stdio/dist/index.d.ts +6 -6
- package/mcp-stdio/dist/index.js +1 -1
- package/mcp-stdio/dist/index.js.map +1 -1
- package/mcp-stdio/dist/index.mjs +1 -1
- package/mcp-stdio/dist/index.mjs.map +1 -1
- package/mcp-stdio/get-environment.test.ts +13 -0
- package/mcp-stdio/get-environment.ts +1 -1
- package/package.json +14 -27
- package/rsc/dist/index.d.ts +0 -813
- package/rsc/dist/index.mjs +0 -18
- package/rsc/dist/rsc-client.d.mts +0 -1
- package/rsc/dist/rsc-client.mjs +0 -18
- package/rsc/dist/rsc-client.mjs.map +0 -1
- package/rsc/dist/rsc-server.mjs.map +0 -1
- package/rsc/dist/rsc-shared.d.mts +0 -101
- package/rsc/dist/rsc-shared.mjs +0 -308
- package/rsc/dist/rsc-shared.mjs.map +0 -1
@@ -0,0 +1,782 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { ToolCall, ToolResult, Validator } from '@ai-sdk/provider-utils';
|
3
|
+
import { JSONSchema7 } from 'json-schema';
|
4
|
+
import { LanguageModelV2ProviderMetadata, LanguageModelV2Source, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
|
5
|
+
|
6
|
+
/**
|
7
|
+
Tool choice for the generation. It supports the following settings:
|
8
|
+
|
9
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
10
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
11
|
+
- `none`: the model must not call tools
|
12
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
13
|
+
*/
|
14
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
15
|
+
type: 'tool';
|
16
|
+
toolName: keyof TOOLS;
|
17
|
+
};
|
18
|
+
|
19
|
+
/**
|
20
|
+
Additional provider-specific metadata that is returned from the provider.
|
21
|
+
|
22
|
+
This is needed to enable provider-specific functionality that can be
|
23
|
+
fully encapsulated in the provider.
|
24
|
+
*/
|
25
|
+
type ProviderMetadata = LanguageModelV2ProviderMetadata;
|
26
|
+
/**
|
27
|
+
Additional provider-specific options.
|
28
|
+
|
29
|
+
They are passed through to the provider from the AI SDK and enable
|
30
|
+
provider-specific functionality that can be fully encapsulated in the provider.
|
31
|
+
*/
|
32
|
+
type ProviderOptions = LanguageModelV2ProviderMetadata;
|
33
|
+
|
34
|
+
/**
|
35
|
+
Represents the number of tokens used in a prompt and completion.
|
36
|
+
*/
|
37
|
+
type LanguageModelUsage = {
|
38
|
+
/**
|
39
|
+
The number of tokens used in the prompt.
|
40
|
+
*/
|
41
|
+
promptTokens: number;
|
42
|
+
/**
|
43
|
+
The number of tokens used in the completion.
|
44
|
+
*/
|
45
|
+
completionTokens: number;
|
46
|
+
/**
|
47
|
+
The total number of tokens used (promptTokens + completionTokens).
|
48
|
+
*/
|
49
|
+
totalTokens: number;
|
50
|
+
};
|
51
|
+
declare function calculateLanguageModelUsage({ promptTokens, completionTokens, }: {
|
52
|
+
promptTokens: number;
|
53
|
+
completionTokens: number;
|
54
|
+
}): LanguageModelUsage;
|
55
|
+
|
56
|
+
/**
|
57
|
+
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
58
|
+
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
59
|
+
Once the call is complete, the invocation is a tool result.
|
60
|
+
|
61
|
+
The step is used to track how to map an assistant UI message with many tool invocations
|
62
|
+
back to a sequence of LLM assistant/tool result message pairs.
|
63
|
+
It is optional for backwards compatibility.
|
64
|
+
*/
|
65
|
+
type ToolInvocation = ({
|
66
|
+
state: 'partial-call';
|
67
|
+
step?: number;
|
68
|
+
} & ToolCall<string, any>) | ({
|
69
|
+
state: 'call';
|
70
|
+
step?: number;
|
71
|
+
} & ToolCall<string, any>) | ({
|
72
|
+
state: 'result';
|
73
|
+
step?: number;
|
74
|
+
} & ToolResult<string, any, any>);
|
75
|
+
/**
|
76
|
+
* An attachment that can be sent along with a message.
|
77
|
+
*/
|
78
|
+
interface Attachment {
|
79
|
+
/**
|
80
|
+
* The name of the attachment, usually the file name.
|
81
|
+
*/
|
82
|
+
name?: string;
|
83
|
+
/**
|
84
|
+
* A string indicating the [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
|
85
|
+
* By default, it's extracted from the pathname's extension.
|
86
|
+
*/
|
87
|
+
contentType?: string;
|
88
|
+
/**
|
89
|
+
* The URL of the attachment. It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
|
90
|
+
*/
|
91
|
+
url: string;
|
92
|
+
}
|
93
|
+
/**
|
94
|
+
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
95
|
+
*/
|
96
|
+
interface Message {
|
97
|
+
/**
|
98
|
+
A unique identifier for the message.
|
99
|
+
*/
|
100
|
+
id: string;
|
101
|
+
/**
|
102
|
+
The timestamp of the message.
|
103
|
+
*/
|
104
|
+
createdAt?: Date;
|
105
|
+
/**
|
106
|
+
Text content of the message. Use parts when possible.
|
107
|
+
*/
|
108
|
+
content: string;
|
109
|
+
/**
|
110
|
+
Reasoning for the message.
|
111
|
+
|
112
|
+
@deprecated Use `parts` instead.
|
113
|
+
*/
|
114
|
+
reasoning?: string;
|
115
|
+
/**
|
116
|
+
* Additional attachments to be sent along with the message.
|
117
|
+
*/
|
118
|
+
experimental_attachments?: Attachment[];
|
119
|
+
/**
|
120
|
+
The 'data' role is deprecated.
|
121
|
+
*/
|
122
|
+
role: 'system' | 'user' | 'assistant' | 'data';
|
123
|
+
/**
|
124
|
+
For data messages.
|
125
|
+
|
126
|
+
@deprecated Data messages will be removed.
|
127
|
+
*/
|
128
|
+
data?: JSONValue;
|
129
|
+
/**
|
130
|
+
* Additional message-specific information added on the server via StreamData
|
131
|
+
*/
|
132
|
+
annotations?: JSONValue[] | undefined;
|
133
|
+
/**
|
134
|
+
Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
|
135
|
+
that the assistant made as part of this message.
|
136
|
+
|
137
|
+
@deprecated Use `parts` instead.
|
138
|
+
*/
|
139
|
+
toolInvocations?: Array<ToolInvocation>;
|
140
|
+
/**
|
141
|
+
* The parts of the message. Use this for rendering the message in the UI.
|
142
|
+
*
|
143
|
+
* Assistant messages can have text, reasoning and tool invocation parts.
|
144
|
+
* User messages can have text parts.
|
145
|
+
*/
|
146
|
+
parts?: Array<TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart>;
|
147
|
+
}
|
148
|
+
/**
|
149
|
+
* A text part of a message.
|
150
|
+
*/
|
151
|
+
type TextUIPart = {
|
152
|
+
type: 'text';
|
153
|
+
/**
|
154
|
+
* The text content.
|
155
|
+
*/
|
156
|
+
text: string;
|
157
|
+
};
|
158
|
+
/**
|
159
|
+
* A reasoning part of a message.
|
160
|
+
*/
|
161
|
+
type ReasoningUIPart = {
|
162
|
+
type: 'reasoning';
|
163
|
+
/**
|
164
|
+
* The reasoning text.
|
165
|
+
*/
|
166
|
+
reasoning: string;
|
167
|
+
details: Array<{
|
168
|
+
type: 'text';
|
169
|
+
text: string;
|
170
|
+
signature?: string;
|
171
|
+
} | {
|
172
|
+
type: 'redacted';
|
173
|
+
data: string;
|
174
|
+
}>;
|
175
|
+
};
|
176
|
+
/**
|
177
|
+
* A tool invocation part of a message.
|
178
|
+
*/
|
179
|
+
type ToolInvocationUIPart = {
|
180
|
+
type: 'tool-invocation';
|
181
|
+
/**
|
182
|
+
* The tool invocation.
|
183
|
+
*/
|
184
|
+
toolInvocation: ToolInvocation;
|
185
|
+
};
|
186
|
+
/**
|
187
|
+
* A source part of a message.
|
188
|
+
*/
|
189
|
+
type SourceUIPart = {
|
190
|
+
type: 'source';
|
191
|
+
/**
|
192
|
+
* The source.
|
193
|
+
*/
|
194
|
+
source: LanguageModelV2Source;
|
195
|
+
};
|
196
|
+
/**
|
197
|
+
* A file part of a message.
|
198
|
+
*/
|
199
|
+
type FileUIPart = {
|
200
|
+
type: 'file';
|
201
|
+
/**
|
202
|
+
* IANA media type of the file.
|
203
|
+
*
|
204
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
205
|
+
*/
|
206
|
+
mediaType: string;
|
207
|
+
/**
|
208
|
+
* The base64 encoded data.
|
209
|
+
*/
|
210
|
+
data: string;
|
211
|
+
};
|
212
|
+
/**
|
213
|
+
* A step boundary part of a message.
|
214
|
+
*/
|
215
|
+
type StepStartUIPart = {
|
216
|
+
type: 'step-start';
|
217
|
+
};
|
218
|
+
/**
|
219
|
+
A JSON value can be a string, number, boolean, object, array, or null.
|
220
|
+
JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
|
221
|
+
*/
|
222
|
+
type JSONValue = null | string | number | boolean | {
|
223
|
+
[value: string]: JSONValue;
|
224
|
+
} | Array<JSONValue>;
|
225
|
+
|
226
|
+
/**
|
227
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
228
|
+
*/
|
229
|
+
declare const schemaSymbol: unique symbol;
|
230
|
+
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
231
|
+
/**
|
232
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
233
|
+
*/
|
234
|
+
[schemaSymbol]: true;
|
235
|
+
/**
|
236
|
+
* Schema type for inference.
|
237
|
+
*/
|
238
|
+
_type: OBJECT;
|
239
|
+
/**
|
240
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
241
|
+
*/
|
242
|
+
readonly jsonSchema: JSONSchema7;
|
243
|
+
};
|
244
|
+
|
245
|
+
type ToolResultContent = Array<{
|
246
|
+
type: 'text';
|
247
|
+
text: string;
|
248
|
+
} | {
|
249
|
+
type: 'image';
|
250
|
+
data: string;
|
251
|
+
mediaType?: string;
|
252
|
+
/**
|
253
|
+
* @deprecated Use `mediaType` instead.
|
254
|
+
*/
|
255
|
+
mimeType?: string;
|
256
|
+
}>;
|
257
|
+
|
258
|
+
/**
|
259
|
+
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
260
|
+
*/
|
261
|
+
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
262
|
+
|
263
|
+
/**
|
264
|
+
Text content part of a prompt. It contains a string of text.
|
265
|
+
*/
|
266
|
+
interface TextPart {
|
267
|
+
type: 'text';
|
268
|
+
/**
|
269
|
+
The text content.
|
270
|
+
*/
|
271
|
+
text: string;
|
272
|
+
/**
|
273
|
+
Additional provider-specific metadata. They are passed through
|
274
|
+
to the provider from the AI SDK and enable provider-specific
|
275
|
+
functionality that can be fully encapsulated in the provider.
|
276
|
+
*/
|
277
|
+
providerOptions?: ProviderOptions;
|
278
|
+
/**
|
279
|
+
@deprecated Use `providerOptions` instead.
|
280
|
+
*/
|
281
|
+
experimental_providerMetadata?: ProviderMetadata;
|
282
|
+
}
|
283
|
+
/**
|
284
|
+
Image content part of a prompt. It contains an image.
|
285
|
+
*/
|
286
|
+
interface ImagePart {
|
287
|
+
type: 'image';
|
288
|
+
/**
|
289
|
+
Image data. Can either be:
|
290
|
+
|
291
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
292
|
+
- URL: a URL that points to the image
|
293
|
+
*/
|
294
|
+
image: DataContent | URL;
|
295
|
+
/**
|
296
|
+
Optional IANA media type of the image.
|
297
|
+
|
298
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
299
|
+
*/
|
300
|
+
mediaType?: string;
|
301
|
+
/**
|
302
|
+
@deprecated Use `mediaType` instead.
|
303
|
+
*/
|
304
|
+
mimeType?: string;
|
305
|
+
/**
|
306
|
+
Additional provider-specific metadata. They are passed through
|
307
|
+
to the provider from the AI SDK and enable provider-specific
|
308
|
+
functionality that can be fully encapsulated in the provider.
|
309
|
+
*/
|
310
|
+
providerOptions?: ProviderOptions;
|
311
|
+
/**
|
312
|
+
@deprecated Use `providerOptions` instead.
|
313
|
+
*/
|
314
|
+
experimental_providerMetadata?: ProviderMetadata;
|
315
|
+
}
|
316
|
+
/**
|
317
|
+
File content part of a prompt. It contains a file.
|
318
|
+
*/
|
319
|
+
interface FilePart {
|
320
|
+
type: 'file';
|
321
|
+
/**
|
322
|
+
File data. Can either be:
|
323
|
+
|
324
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
325
|
+
- URL: a URL that points to the image
|
326
|
+
*/
|
327
|
+
data: DataContent | URL;
|
328
|
+
/**
|
329
|
+
Optional filename of the file.
|
330
|
+
*/
|
331
|
+
filename?: string;
|
332
|
+
/**
|
333
|
+
IANA media type of the file.
|
334
|
+
|
335
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
336
|
+
*/
|
337
|
+
mediaType: string;
|
338
|
+
/**
|
339
|
+
@deprecated Use `mediaType` instead.
|
340
|
+
*/
|
341
|
+
mimeType?: string;
|
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
|
+
@deprecated Use `providerOptions` instead.
|
350
|
+
*/
|
351
|
+
experimental_providerMetadata?: ProviderMetadata;
|
352
|
+
}
|
353
|
+
/**
|
354
|
+
* Reasoning content part of a prompt. It contains a reasoning.
|
355
|
+
*/
|
356
|
+
interface ReasoningPart {
|
357
|
+
type: 'reasoning';
|
358
|
+
/**
|
359
|
+
The reasoning text.
|
360
|
+
*/
|
361
|
+
text: string;
|
362
|
+
/**
|
363
|
+
An optional signature for verifying that the reasoning originated from the model.
|
364
|
+
*/
|
365
|
+
signature?: string;
|
366
|
+
/**
|
367
|
+
Additional provider-specific metadata. They are passed through
|
368
|
+
to the provider from the AI SDK and enable provider-specific
|
369
|
+
functionality that can be fully encapsulated in the provider.
|
370
|
+
*/
|
371
|
+
providerOptions?: ProviderOptions;
|
372
|
+
/**
|
373
|
+
@deprecated Use `providerOptions` instead.
|
374
|
+
*/
|
375
|
+
experimental_providerMetadata?: ProviderMetadata;
|
376
|
+
}
|
377
|
+
/**
|
378
|
+
Redacted reasoning content part of a prompt.
|
379
|
+
*/
|
380
|
+
interface RedactedReasoningPart {
|
381
|
+
type: 'redacted-reasoning';
|
382
|
+
/**
|
383
|
+
Redacted reasoning data.
|
384
|
+
*/
|
385
|
+
data: string;
|
386
|
+
/**
|
387
|
+
Additional provider-specific metadata. They are passed through
|
388
|
+
to the provider from the AI SDK and enable provider-specific
|
389
|
+
functionality that can be fully encapsulated in the provider.
|
390
|
+
*/
|
391
|
+
providerOptions?: ProviderOptions;
|
392
|
+
/**
|
393
|
+
@deprecated Use `providerOptions` instead.
|
394
|
+
*/
|
395
|
+
experimental_providerMetadata?: ProviderMetadata;
|
396
|
+
}
|
397
|
+
/**
|
398
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
399
|
+
*/
|
400
|
+
interface ToolCallPart {
|
401
|
+
type: 'tool-call';
|
402
|
+
/**
|
403
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
404
|
+
*/
|
405
|
+
toolCallId: string;
|
406
|
+
/**
|
407
|
+
Name of the tool that is being called.
|
408
|
+
*/
|
409
|
+
toolName: string;
|
410
|
+
/**
|
411
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
412
|
+
*/
|
413
|
+
args: unknown;
|
414
|
+
/**
|
415
|
+
Additional provider-specific metadata. They are passed through
|
416
|
+
to the provider from the AI SDK and enable provider-specific
|
417
|
+
functionality that can be fully encapsulated in the provider.
|
418
|
+
*/
|
419
|
+
providerOptions?: ProviderOptions;
|
420
|
+
/**
|
421
|
+
@deprecated Use `providerOptions` instead.
|
422
|
+
*/
|
423
|
+
experimental_providerMetadata?: ProviderMetadata;
|
424
|
+
}
|
425
|
+
/**
|
426
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
427
|
+
*/
|
428
|
+
interface ToolResultPart {
|
429
|
+
type: 'tool-result';
|
430
|
+
/**
|
431
|
+
ID of the tool call that this result is associated with.
|
432
|
+
*/
|
433
|
+
toolCallId: string;
|
434
|
+
/**
|
435
|
+
Name of the tool that generated this result.
|
436
|
+
*/
|
437
|
+
toolName: string;
|
438
|
+
/**
|
439
|
+
Result of the tool call. This is a JSON-serializable object.
|
440
|
+
*/
|
441
|
+
result: unknown;
|
442
|
+
/**
|
443
|
+
Multi-part content of the tool result. Only for tools that support multipart results.
|
444
|
+
*/
|
445
|
+
experimental_content?: ToolResultContent;
|
446
|
+
/**
|
447
|
+
Optional flag if the result is an error or an error message.
|
448
|
+
*/
|
449
|
+
isError?: boolean;
|
450
|
+
/**
|
451
|
+
Additional provider-specific metadata. They are passed through
|
452
|
+
to the provider from the AI SDK and enable provider-specific
|
453
|
+
functionality that can be fully encapsulated in the provider.
|
454
|
+
*/
|
455
|
+
providerOptions?: ProviderOptions;
|
456
|
+
/**
|
457
|
+
@deprecated Use `providerOptions` instead.
|
458
|
+
*/
|
459
|
+
experimental_providerMetadata?: ProviderMetadata;
|
460
|
+
}
|
461
|
+
|
462
|
+
/**
|
463
|
+
A system message. It can contain system information.
|
464
|
+
|
465
|
+
Note: using the "system" part of the prompt is strongly preferred
|
466
|
+
to increase the resilience against prompt injection attacks,
|
467
|
+
and because not all providers support several system messages.
|
468
|
+
*/
|
469
|
+
type CoreSystemMessage = {
|
470
|
+
role: 'system';
|
471
|
+
content: string;
|
472
|
+
/**
|
473
|
+
Additional provider-specific metadata. They are passed through
|
474
|
+
to the provider from the AI SDK and enable provider-specific
|
475
|
+
functionality that can be fully encapsulated in the provider.
|
476
|
+
*/
|
477
|
+
providerOptions?: ProviderOptions;
|
478
|
+
/**
|
479
|
+
@deprecated Use `providerOptions` instead.
|
480
|
+
*/
|
481
|
+
experimental_providerMetadata?: ProviderMetadata;
|
482
|
+
};
|
483
|
+
/**
|
484
|
+
A user message. It can contain text or a combination of text and images.
|
485
|
+
*/
|
486
|
+
type CoreUserMessage = {
|
487
|
+
role: 'user';
|
488
|
+
content: UserContent;
|
489
|
+
/**
|
490
|
+
Additional provider-specific metadata. They are passed through
|
491
|
+
to the provider from the AI SDK and enable provider-specific
|
492
|
+
functionality that can be fully encapsulated in the provider.
|
493
|
+
*/
|
494
|
+
providerOptions?: ProviderOptions;
|
495
|
+
/**
|
496
|
+
@deprecated Use `providerOptions` instead.
|
497
|
+
*/
|
498
|
+
experimental_providerMetadata?: ProviderMetadata;
|
499
|
+
};
|
500
|
+
/**
|
501
|
+
Content of a user message. It can be a string or an array of text and image parts.
|
502
|
+
*/
|
503
|
+
type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
504
|
+
/**
|
505
|
+
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
506
|
+
*/
|
507
|
+
type CoreAssistantMessage = {
|
508
|
+
role: 'assistant';
|
509
|
+
content: AssistantContent;
|
510
|
+
/**
|
511
|
+
Additional provider-specific metadata. They are passed through
|
512
|
+
to the provider from the AI SDK and enable provider-specific
|
513
|
+
functionality that can be fully encapsulated in the provider.
|
514
|
+
*/
|
515
|
+
providerOptions?: ProviderOptions;
|
516
|
+
/**
|
517
|
+
@deprecated Use `providerOptions` instead.
|
518
|
+
*/
|
519
|
+
experimental_providerMetadata?: ProviderMetadata;
|
520
|
+
};
|
521
|
+
/**
|
522
|
+
Content of an assistant message.
|
523
|
+
It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
524
|
+
*/
|
525
|
+
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | RedactedReasoningPart | ToolCallPart>;
|
526
|
+
/**
|
527
|
+
A tool message. It contains the result of one or more tool calls.
|
528
|
+
*/
|
529
|
+
type CoreToolMessage = {
|
530
|
+
role: 'tool';
|
531
|
+
content: ToolContent;
|
532
|
+
/**
|
533
|
+
Additional provider-specific metadata. They are passed through
|
534
|
+
to the provider from the AI SDK and enable provider-specific
|
535
|
+
functionality that can be fully encapsulated in the provider.
|
536
|
+
*/
|
537
|
+
providerOptions?: ProviderOptions;
|
538
|
+
/**
|
539
|
+
@deprecated Use `providerOptions` instead.
|
540
|
+
*/
|
541
|
+
experimental_providerMetadata?: ProviderMetadata;
|
542
|
+
};
|
543
|
+
/**
|
544
|
+
Content of a tool message. It is an array of tool result parts.
|
545
|
+
*/
|
546
|
+
type ToolContent = Array<ToolResultPart>;
|
547
|
+
/**
|
548
|
+
A message that can be used in the `messages` field of a prompt.
|
549
|
+
It can be a user message, an assistant message, or a tool message.
|
550
|
+
*/
|
551
|
+
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
552
|
+
|
553
|
+
type ToolParameters = z.ZodTypeAny | Schema<any>;
|
554
|
+
type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
555
|
+
interface ToolExecutionOptions {
|
556
|
+
/**
|
557
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
558
|
+
*/
|
559
|
+
toolCallId: string;
|
560
|
+
/**
|
561
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
562
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
563
|
+
*/
|
564
|
+
messages: CoreMessage[];
|
565
|
+
/**
|
566
|
+
* An optional abort signal that indicates that the overall operation should be aborted.
|
567
|
+
*/
|
568
|
+
abortSignal?: AbortSignal;
|
569
|
+
}
|
570
|
+
/**
|
571
|
+
A tool contains the description and the schema of the input that the tool expects.
|
572
|
+
This enables the language model to generate the input.
|
573
|
+
|
574
|
+
The tool can also contain an optional execute function for the actual execution function of the tool.
|
575
|
+
*/
|
576
|
+
type Tool<PARAMETERS extends ToolParameters = any, RESULT = any> = {
|
577
|
+
/**
|
578
|
+
The schema of the input that the tool expects. The language model will use this to generate the input.
|
579
|
+
It is also used to validate the output of the language model.
|
580
|
+
Use descriptions to make the input understandable for the language model.
|
581
|
+
*/
|
582
|
+
parameters: PARAMETERS;
|
583
|
+
/**
|
584
|
+
An optional description of what the tool does.
|
585
|
+
Will be used by the language model to decide whether to use the tool.
|
586
|
+
Not used for provider-defined tools.
|
587
|
+
*/
|
588
|
+
description?: string;
|
589
|
+
/**
|
590
|
+
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
591
|
+
*/
|
592
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
593
|
+
/**
|
594
|
+
An async function that is called with the arguments from the tool call and produces a result.
|
595
|
+
If not provided, the tool will not be executed automatically.
|
596
|
+
|
597
|
+
@args is the input of the tool call.
|
598
|
+
@options.abortSignal is a signal that can be used to abort the tool call.
|
599
|
+
*/
|
600
|
+
execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
601
|
+
} & ({
|
602
|
+
/**
|
603
|
+
Function tool.
|
604
|
+
*/
|
605
|
+
type?: undefined | 'function';
|
606
|
+
} | {
|
607
|
+
/**
|
608
|
+
Provider-defined tool.
|
609
|
+
*/
|
610
|
+
type: 'provider-defined';
|
611
|
+
/**
|
612
|
+
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
613
|
+
*/
|
614
|
+
id: `${string}.${string}`;
|
615
|
+
/**
|
616
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
617
|
+
*/
|
618
|
+
args: Record<string, unknown>;
|
619
|
+
});
|
620
|
+
|
621
|
+
type ToolSet = Record<string, Tool>;
|
622
|
+
|
623
|
+
/**
|
624
|
+
Prompt part of the AI function options.
|
625
|
+
It contains a system message, a simple text prompt, or a list of messages.
|
626
|
+
*/
|
627
|
+
type Prompt = {
|
628
|
+
/**
|
629
|
+
System message to include in the prompt. Can be used with `prompt` or `messages`.
|
630
|
+
*/
|
631
|
+
system?: string;
|
632
|
+
/**
|
633
|
+
A simple text prompt. You can either use `prompt` or `messages` but not both.
|
634
|
+
*/
|
635
|
+
prompt?: string;
|
636
|
+
/**
|
637
|
+
A list of messages. You can either use `prompt` or `messages` but not both.
|
638
|
+
*/
|
639
|
+
messages?: Array<CoreMessage> | Array<Omit<Message, 'id'>>;
|
640
|
+
};
|
641
|
+
|
642
|
+
type StandardizedPrompt = {
|
643
|
+
/**
|
644
|
+
* Original prompt type. This is forwarded to the providers and can be used
|
645
|
+
* to write send raw text to providers that support it.
|
646
|
+
*/
|
647
|
+
type: 'prompt' | 'messages';
|
648
|
+
/**
|
649
|
+
* System message.
|
650
|
+
*/
|
651
|
+
system?: string;
|
652
|
+
/**
|
653
|
+
* Messages.
|
654
|
+
*/
|
655
|
+
messages: CoreMessage[];
|
656
|
+
};
|
657
|
+
declare function standardizePrompt<TOOLS extends ToolSet>({ prompt, tools, }: {
|
658
|
+
prompt: Prompt;
|
659
|
+
tools: undefined | TOOLS;
|
660
|
+
}): StandardizedPrompt;
|
661
|
+
|
662
|
+
type CallSettings = {
|
663
|
+
/**
|
664
|
+
Maximum number of tokens to generate.
|
665
|
+
*/
|
666
|
+
maxTokens?: number;
|
667
|
+
/**
|
668
|
+
Temperature setting. This is a number between 0 (almost no randomness) and
|
669
|
+
1 (very random).
|
670
|
+
|
671
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
672
|
+
|
673
|
+
@default 0
|
674
|
+
*/
|
675
|
+
temperature?: number;
|
676
|
+
/**
|
677
|
+
Nucleus sampling. This is a number between 0 and 1.
|
678
|
+
|
679
|
+
E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
680
|
+
are considered.
|
681
|
+
|
682
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
683
|
+
*/
|
684
|
+
topP?: number;
|
685
|
+
/**
|
686
|
+
Only sample from the top K options for each subsequent token.
|
687
|
+
|
688
|
+
Used to remove "long tail" low probability responses.
|
689
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
690
|
+
*/
|
691
|
+
topK?: number;
|
692
|
+
/**
|
693
|
+
Presence penalty setting. It affects the likelihood of the model to
|
694
|
+
repeat information that is already in the prompt.
|
695
|
+
|
696
|
+
The presence penalty is a number between -1 (increase repetition)
|
697
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
698
|
+
*/
|
699
|
+
presencePenalty?: number;
|
700
|
+
/**
|
701
|
+
Frequency penalty setting. It affects the likelihood of the model
|
702
|
+
to repeatedly use the same words or phrases.
|
703
|
+
|
704
|
+
The frequency penalty is a number between -1 (increase repetition)
|
705
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
706
|
+
*/
|
707
|
+
frequencyPenalty?: number;
|
708
|
+
/**
|
709
|
+
Stop sequences.
|
710
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
711
|
+
Providers may have limits on the number of stop sequences.
|
712
|
+
*/
|
713
|
+
stopSequences?: string[];
|
714
|
+
/**
|
715
|
+
The seed (integer) to use for random sampling. If set and supported
|
716
|
+
by the model, calls will generate deterministic results.
|
717
|
+
*/
|
718
|
+
seed?: number;
|
719
|
+
/**
|
720
|
+
Maximum number of retries. Set to 0 to disable retries.
|
721
|
+
|
722
|
+
@default 2
|
723
|
+
*/
|
724
|
+
maxRetries?: number;
|
725
|
+
/**
|
726
|
+
Abort signal.
|
727
|
+
*/
|
728
|
+
abortSignal?: AbortSignal;
|
729
|
+
/**
|
730
|
+
Additional HTTP headers to be sent with the request.
|
731
|
+
Only applicable for HTTP-based providers.
|
732
|
+
*/
|
733
|
+
headers?: Record<string, string | undefined>;
|
734
|
+
};
|
735
|
+
|
736
|
+
declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolChoice, activeTools, }: {
|
737
|
+
tools: TOOLS | undefined;
|
738
|
+
toolChoice: ToolChoice<TOOLS> | undefined;
|
739
|
+
activeTools: Array<keyof TOOLS> | undefined;
|
740
|
+
}): {
|
741
|
+
tools: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool> | undefined;
|
742
|
+
toolChoice: LanguageModelV2ToolChoice | undefined;
|
743
|
+
};
|
744
|
+
|
745
|
+
type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
|
746
|
+
|
747
|
+
/**
|
748
|
+
* Validate and prepare retries.
|
749
|
+
*/
|
750
|
+
declare function prepareRetries({ maxRetries, }: {
|
751
|
+
maxRetries: number | undefined;
|
752
|
+
}): {
|
753
|
+
maxRetries: number;
|
754
|
+
retry: RetryFunction;
|
755
|
+
};
|
756
|
+
|
757
|
+
/**
|
758
|
+
* Validates call settings and sets default values.
|
759
|
+
*/
|
760
|
+
declare function prepareCallSettings({ maxTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, stopSequences, seed, }: Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>): Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>;
|
761
|
+
|
762
|
+
declare function download({ url }: {
|
763
|
+
url: URL;
|
764
|
+
}): Promise<{
|
765
|
+
data: Uint8Array;
|
766
|
+
mediaType: string | undefined;
|
767
|
+
}>;
|
768
|
+
|
769
|
+
declare function convertToLanguageModelPrompt({ prompt, modelSupportsImageUrls, modelSupportsUrl, downloadImplementation, }: {
|
770
|
+
prompt: StandardizedPrompt;
|
771
|
+
modelSupportsImageUrls: boolean | undefined;
|
772
|
+
modelSupportsUrl: undefined | ((url: URL) => boolean);
|
773
|
+
downloadImplementation?: typeof download;
|
774
|
+
}): Promise<LanguageModelV2Prompt>;
|
775
|
+
|
776
|
+
/**
|
777
|
+
* Warning time for notifying developers that a stream is hanging in dev mode
|
778
|
+
* using a console.warn.
|
779
|
+
*/
|
780
|
+
declare const HANGING_STREAM_WARNING_TIME_MS: number;
|
781
|
+
|
782
|
+
export { HANGING_STREAM_WARNING_TIME_MS, calculateLanguageModelUsage, convertToLanguageModelPrompt, prepareCallSettings, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };
|