ai 5.0.0-canary.6 → 5.0.0-canary.7
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 +20 -0
- package/dist/index.d.mts +166 -446
- package/dist/index.d.ts +166 -446
- package/dist/index.js +283 -297
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +203 -217
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +259 -311
- package/dist/internal/index.d.ts +259 -311
- package/dist/internal/index.js +139 -155
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +129 -145
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +3 -3
@@ -1,246 +1,7 @@
|
|
1
|
+
import { LanguageModelV2ProviderMetadata, LanguageModelV2Usage, LanguageModelV2Source, JSONValue as JSONValue$1, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
|
1
2
|
import { z } from 'zod';
|
2
3
|
import { ToolCall, ToolResult, Validator } from '@ai-sdk/provider-utils';
|
3
4
|
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
5
|
|
245
6
|
type ToolResultContent = Array<{
|
246
7
|
type: 'text';
|
@@ -255,6 +16,14 @@ type ToolResultContent = Array<{
|
|
255
16
|
mimeType?: string;
|
256
17
|
}>;
|
257
18
|
|
19
|
+
/**
|
20
|
+
Additional provider-specific options.
|
21
|
+
|
22
|
+
They are passed through to the provider from the AI SDK and enable
|
23
|
+
provider-specific functionality that can be fully encapsulated in the provider.
|
24
|
+
*/
|
25
|
+
type ProviderOptions = LanguageModelV2ProviderMetadata;
|
26
|
+
|
258
27
|
/**
|
259
28
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
260
29
|
*/
|
@@ -275,10 +44,6 @@ interface TextPart {
|
|
275
44
|
functionality that can be fully encapsulated in the provider.
|
276
45
|
*/
|
277
46
|
providerOptions?: ProviderOptions;
|
278
|
-
/**
|
279
|
-
@deprecated Use `providerOptions` instead.
|
280
|
-
*/
|
281
|
-
experimental_providerMetadata?: ProviderMetadata;
|
282
47
|
}
|
283
48
|
/**
|
284
49
|
Image content part of a prompt. It contains an image.
|
@@ -308,10 +73,6 @@ interface ImagePart {
|
|
308
73
|
functionality that can be fully encapsulated in the provider.
|
309
74
|
*/
|
310
75
|
providerOptions?: ProviderOptions;
|
311
|
-
/**
|
312
|
-
@deprecated Use `providerOptions` instead.
|
313
|
-
*/
|
314
|
-
experimental_providerMetadata?: ProviderMetadata;
|
315
76
|
}
|
316
77
|
/**
|
317
78
|
File content part of a prompt. It contains a file.
|
@@ -345,10 +106,6 @@ interface FilePart {
|
|
345
106
|
functionality that can be fully encapsulated in the provider.
|
346
107
|
*/
|
347
108
|
providerOptions?: ProviderOptions;
|
348
|
-
/**
|
349
|
-
@deprecated Use `providerOptions` instead.
|
350
|
-
*/
|
351
|
-
experimental_providerMetadata?: ProviderMetadata;
|
352
109
|
}
|
353
110
|
/**
|
354
111
|
* Reasoning content part of a prompt. It contains a reasoning.
|
@@ -369,10 +126,6 @@ interface ReasoningPart {
|
|
369
126
|
functionality that can be fully encapsulated in the provider.
|
370
127
|
*/
|
371
128
|
providerOptions?: ProviderOptions;
|
372
|
-
/**
|
373
|
-
@deprecated Use `providerOptions` instead.
|
374
|
-
*/
|
375
|
-
experimental_providerMetadata?: ProviderMetadata;
|
376
129
|
}
|
377
130
|
/**
|
378
131
|
Redacted reasoning content part of a prompt.
|
@@ -389,10 +142,6 @@ interface RedactedReasoningPart {
|
|
389
142
|
functionality that can be fully encapsulated in the provider.
|
390
143
|
*/
|
391
144
|
providerOptions?: ProviderOptions;
|
392
|
-
/**
|
393
|
-
@deprecated Use `providerOptions` instead.
|
394
|
-
*/
|
395
|
-
experimental_providerMetadata?: ProviderMetadata;
|
396
145
|
}
|
397
146
|
/**
|
398
147
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
@@ -417,10 +166,6 @@ interface ToolCallPart {
|
|
417
166
|
functionality that can be fully encapsulated in the provider.
|
418
167
|
*/
|
419
168
|
providerOptions?: ProviderOptions;
|
420
|
-
/**
|
421
|
-
@deprecated Use `providerOptions` instead.
|
422
|
-
*/
|
423
|
-
experimental_providerMetadata?: ProviderMetadata;
|
424
169
|
}
|
425
170
|
/**
|
426
171
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
@@ -453,10 +198,6 @@ interface ToolResultPart {
|
|
453
198
|
functionality that can be fully encapsulated in the provider.
|
454
199
|
*/
|
455
200
|
providerOptions?: ProviderOptions;
|
456
|
-
/**
|
457
|
-
@deprecated Use `providerOptions` instead.
|
458
|
-
*/
|
459
|
-
experimental_providerMetadata?: ProviderMetadata;
|
460
201
|
}
|
461
202
|
|
462
203
|
/**
|
@@ -475,10 +216,6 @@ type CoreSystemMessage = {
|
|
475
216
|
functionality that can be fully encapsulated in the provider.
|
476
217
|
*/
|
477
218
|
providerOptions?: ProviderOptions;
|
478
|
-
/**
|
479
|
-
@deprecated Use `providerOptions` instead.
|
480
|
-
*/
|
481
|
-
experimental_providerMetadata?: ProviderMetadata;
|
482
219
|
};
|
483
220
|
/**
|
484
221
|
A user message. It can contain text or a combination of text and images.
|
@@ -492,10 +229,6 @@ type CoreUserMessage = {
|
|
492
229
|
functionality that can be fully encapsulated in the provider.
|
493
230
|
*/
|
494
231
|
providerOptions?: ProviderOptions;
|
495
|
-
/**
|
496
|
-
@deprecated Use `providerOptions` instead.
|
497
|
-
*/
|
498
|
-
experimental_providerMetadata?: ProviderMetadata;
|
499
232
|
};
|
500
233
|
/**
|
501
234
|
Content of a user message. It can be a string or an array of text and image parts.
|
@@ -513,10 +246,6 @@ type CoreAssistantMessage = {
|
|
513
246
|
functionality that can be fully encapsulated in the provider.
|
514
247
|
*/
|
515
248
|
providerOptions?: ProviderOptions;
|
516
|
-
/**
|
517
|
-
@deprecated Use `providerOptions` instead.
|
518
|
-
*/
|
519
|
-
experimental_providerMetadata?: ProviderMetadata;
|
520
249
|
};
|
521
250
|
/**
|
522
251
|
Content of an assistant message.
|
@@ -535,10 +264,6 @@ type CoreToolMessage = {
|
|
535
264
|
functionality that can be fully encapsulated in the provider.
|
536
265
|
*/
|
537
266
|
providerOptions?: ProviderOptions;
|
538
|
-
/**
|
539
|
-
@deprecated Use `providerOptions` instead.
|
540
|
-
*/
|
541
|
-
experimental_providerMetadata?: ProviderMetadata;
|
542
267
|
};
|
543
268
|
/**
|
544
269
|
Content of a tool message. It is an array of tool result parts.
|
@@ -550,8 +275,228 @@ It can be a user message, an assistant message, or a tool message.
|
|
550
275
|
*/
|
551
276
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
552
277
|
|
553
|
-
|
554
|
-
|
278
|
+
/**
|
279
|
+
Tool choice for the generation. It supports the following settings:
|
280
|
+
|
281
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
282
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
283
|
+
- `none`: the model must not call tools
|
284
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
285
|
+
*/
|
286
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
287
|
+
type: 'tool';
|
288
|
+
toolName: Extract<keyof TOOLS, string>;
|
289
|
+
};
|
290
|
+
|
291
|
+
/**
|
292
|
+
Represents the number of tokens used in a prompt and completion.
|
293
|
+
*/
|
294
|
+
type LanguageModelUsage = {
|
295
|
+
/**
|
296
|
+
The number of tokens used in the prompt.
|
297
|
+
*/
|
298
|
+
promptTokens: number;
|
299
|
+
/**
|
300
|
+
The number of tokens used in the completion.
|
301
|
+
*/
|
302
|
+
completionTokens: number;
|
303
|
+
/**
|
304
|
+
The total number of tokens used (promptTokens + completionTokens).
|
305
|
+
*/
|
306
|
+
totalTokens: number;
|
307
|
+
};
|
308
|
+
declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
|
309
|
+
|
310
|
+
/**
|
311
|
+
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
312
|
+
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
313
|
+
Once the call is complete, the invocation is a tool result.
|
314
|
+
|
315
|
+
The step is used to track how to map an assistant UI message with many tool invocations
|
316
|
+
back to a sequence of LLM assistant/tool result message pairs.
|
317
|
+
It is optional for backwards compatibility.
|
318
|
+
*/
|
319
|
+
type ToolInvocation = ({
|
320
|
+
state: 'partial-call';
|
321
|
+
step?: number;
|
322
|
+
} & ToolCall<string, any>) | ({
|
323
|
+
state: 'call';
|
324
|
+
step?: number;
|
325
|
+
} & ToolCall<string, any>) | ({
|
326
|
+
state: 'result';
|
327
|
+
step?: number;
|
328
|
+
} & ToolResult<string, any, any>);
|
329
|
+
/**
|
330
|
+
* An attachment that can be sent along with a message.
|
331
|
+
*/
|
332
|
+
interface Attachment {
|
333
|
+
/**
|
334
|
+
* The name of the attachment, usually the file name.
|
335
|
+
*/
|
336
|
+
name?: string;
|
337
|
+
/**
|
338
|
+
* A string indicating the [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
|
339
|
+
* By default, it's extracted from the pathname's extension.
|
340
|
+
*/
|
341
|
+
contentType?: string;
|
342
|
+
/**
|
343
|
+
* 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).
|
344
|
+
*/
|
345
|
+
url: string;
|
346
|
+
}
|
347
|
+
/**
|
348
|
+
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
349
|
+
*/
|
350
|
+
interface Message {
|
351
|
+
/**
|
352
|
+
A unique identifier for the message.
|
353
|
+
*/
|
354
|
+
id: string;
|
355
|
+
/**
|
356
|
+
The timestamp of the message.
|
357
|
+
*/
|
358
|
+
createdAt?: Date;
|
359
|
+
/**
|
360
|
+
Text content of the message. Use parts when possible.
|
361
|
+
*/
|
362
|
+
content: string;
|
363
|
+
/**
|
364
|
+
Reasoning for the message.
|
365
|
+
|
366
|
+
@deprecated Use `parts` instead.
|
367
|
+
*/
|
368
|
+
reasoning?: string;
|
369
|
+
/**
|
370
|
+
* Additional attachments to be sent along with the message.
|
371
|
+
*/
|
372
|
+
experimental_attachments?: Attachment[];
|
373
|
+
/**
|
374
|
+
The 'data' role is deprecated.
|
375
|
+
*/
|
376
|
+
role: 'system' | 'user' | 'assistant' | 'data';
|
377
|
+
/**
|
378
|
+
For data messages.
|
379
|
+
|
380
|
+
@deprecated Data messages will be removed.
|
381
|
+
*/
|
382
|
+
data?: JSONValue;
|
383
|
+
/**
|
384
|
+
* Additional message-specific information added on the server via StreamData
|
385
|
+
*/
|
386
|
+
annotations?: JSONValue[] | undefined;
|
387
|
+
/**
|
388
|
+
Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
|
389
|
+
that the assistant made as part of this message.
|
390
|
+
|
391
|
+
@deprecated Use `parts` instead.
|
392
|
+
*/
|
393
|
+
toolInvocations?: Array<ToolInvocation>;
|
394
|
+
/**
|
395
|
+
* The parts of the message. Use this for rendering the message in the UI.
|
396
|
+
*
|
397
|
+
* Assistant messages can have text, reasoning and tool invocation parts.
|
398
|
+
* User messages can have text parts.
|
399
|
+
*/
|
400
|
+
parts?: Array<TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart>;
|
401
|
+
}
|
402
|
+
/**
|
403
|
+
* A text part of a message.
|
404
|
+
*/
|
405
|
+
type TextUIPart = {
|
406
|
+
type: 'text';
|
407
|
+
/**
|
408
|
+
* The text content.
|
409
|
+
*/
|
410
|
+
text: string;
|
411
|
+
};
|
412
|
+
/**
|
413
|
+
* A reasoning part of a message.
|
414
|
+
*/
|
415
|
+
type ReasoningUIPart = {
|
416
|
+
type: 'reasoning';
|
417
|
+
/**
|
418
|
+
* The reasoning text.
|
419
|
+
*/
|
420
|
+
reasoning: string;
|
421
|
+
details: Array<{
|
422
|
+
type: 'text';
|
423
|
+
text: string;
|
424
|
+
signature?: string;
|
425
|
+
} | {
|
426
|
+
type: 'redacted';
|
427
|
+
data: string;
|
428
|
+
}>;
|
429
|
+
};
|
430
|
+
/**
|
431
|
+
* A tool invocation part of a message.
|
432
|
+
*/
|
433
|
+
type ToolInvocationUIPart = {
|
434
|
+
type: 'tool-invocation';
|
435
|
+
/**
|
436
|
+
* The tool invocation.
|
437
|
+
*/
|
438
|
+
toolInvocation: ToolInvocation;
|
439
|
+
};
|
440
|
+
/**
|
441
|
+
* A source part of a message.
|
442
|
+
*/
|
443
|
+
type SourceUIPart = {
|
444
|
+
type: 'source';
|
445
|
+
/**
|
446
|
+
* The source.
|
447
|
+
*/
|
448
|
+
source: LanguageModelV2Source;
|
449
|
+
};
|
450
|
+
/**
|
451
|
+
* A file part of a message.
|
452
|
+
*/
|
453
|
+
type FileUIPart = {
|
454
|
+
type: 'file';
|
455
|
+
/**
|
456
|
+
* IANA media type of the file.
|
457
|
+
*
|
458
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
459
|
+
*/
|
460
|
+
mediaType: string;
|
461
|
+
/**
|
462
|
+
* The base64 encoded data.
|
463
|
+
*/
|
464
|
+
data: string;
|
465
|
+
};
|
466
|
+
/**
|
467
|
+
* A step boundary part of a message.
|
468
|
+
*/
|
469
|
+
type StepStartUIPart = {
|
470
|
+
type: 'step-start';
|
471
|
+
};
|
472
|
+
/**
|
473
|
+
A JSON value can be a string, number, boolean, object, array, or null.
|
474
|
+
JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
|
475
|
+
*/
|
476
|
+
type JSONValue = null | string | number | boolean | {
|
477
|
+
[value: string]: JSONValue;
|
478
|
+
} | Array<JSONValue>;
|
479
|
+
|
480
|
+
/**
|
481
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
482
|
+
*/
|
483
|
+
declare const schemaSymbol: unique symbol;
|
484
|
+
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
485
|
+
/**
|
486
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
487
|
+
*/
|
488
|
+
[schemaSymbol]: true;
|
489
|
+
/**
|
490
|
+
* Schema type for inference.
|
491
|
+
*/
|
492
|
+
_type: OBJECT;
|
493
|
+
/**
|
494
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
495
|
+
*/
|
496
|
+
readonly jsonSchema: JSONSchema7;
|
497
|
+
};
|
498
|
+
|
499
|
+
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
555
500
|
interface ToolExecutionOptions {
|
556
501
|
/**
|
557
502
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
@@ -567,58 +512,61 @@ interface ToolExecutionOptions {
|
|
567
512
|
*/
|
568
513
|
abortSignal?: AbortSignal;
|
569
514
|
}
|
515
|
+
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
570
516
|
/**
|
571
517
|
A tool contains the description and the schema of the input that the tool expects.
|
572
518
|
This enables the language model to generate the input.
|
573
519
|
|
574
520
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
575
521
|
*/
|
576
|
-
type Tool<PARAMETERS extends
|
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;
|
522
|
+
type Tool<PARAMETERS extends JSONValue$1 | unknown | never = any, RESULT = any> = {
|
583
523
|
/**
|
584
524
|
An optional description of what the tool does.
|
585
525
|
Will be used by the language model to decide whether to use the tool.
|
586
526
|
Not used for provider-defined tools.
|
587
527
|
*/
|
588
528
|
description?: string;
|
529
|
+
} & NeverOptional<PARAMETERS, {
|
589
530
|
/**
|
590
|
-
|
591
|
-
|
592
|
-
|
531
|
+
The schema of the input that the tool expects. The language model will use this to generate the input.
|
532
|
+
It is also used to validate the output of the language model.
|
533
|
+
Use descriptions to make the input understandable for the language model.
|
534
|
+
*/
|
535
|
+
parameters: ToolParameters<PARAMETERS>;
|
536
|
+
}> & NeverOptional<RESULT, {
|
593
537
|
/**
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
execute
|
601
|
-
|
538
|
+
An async function that is called with the arguments from the tool call and produces a result.
|
539
|
+
If not provided, the tool will not be executed automatically.
|
540
|
+
|
541
|
+
@args is the input of the tool call.
|
542
|
+
@options.abortSignal is a signal that can be used to abort the tool call.
|
543
|
+
*/
|
544
|
+
execute: (args: [PARAMETERS] extends [never] ? undefined : PARAMETERS, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
545
|
+
/**
|
546
|
+
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
547
|
+
*/
|
548
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
549
|
+
}> & ({
|
602
550
|
/**
|
603
551
|
Function tool.
|
604
|
-
|
552
|
+
*/
|
605
553
|
type?: undefined | 'function';
|
606
554
|
} | {
|
607
555
|
/**
|
608
556
|
Provider-defined tool.
|
609
|
-
|
557
|
+
*/
|
610
558
|
type: 'provider-defined';
|
611
559
|
/**
|
612
560
|
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
613
|
-
|
561
|
+
*/
|
614
562
|
id: `${string}.${string}`;
|
615
563
|
/**
|
616
564
|
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
617
|
-
|
565
|
+
*/
|
618
566
|
args: Record<string, unknown>;
|
619
567
|
});
|
620
568
|
|
621
|
-
type ToolSet = Record<string, Tool
|
569
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute'>>;
|
622
570
|
|
623
571
|
/**
|
624
572
|
Prompt part of the AI function options.
|
@@ -663,7 +611,7 @@ type CallSettings = {
|
|
663
611
|
/**
|
664
612
|
Maximum number of tokens to generate.
|
665
613
|
*/
|
666
|
-
|
614
|
+
maxOutputTokens?: number;
|
667
615
|
/**
|
668
616
|
Temperature setting. This is a number between 0 (almost no randomness) and
|
669
617
|
1 (very random).
|
@@ -757,7 +705,7 @@ declare function prepareRetries({ maxRetries, }: {
|
|
757
705
|
/**
|
758
706
|
* Validates call settings and sets default values.
|
759
707
|
*/
|
760
|
-
declare function prepareCallSettings({
|
708
|
+
declare function prepareCallSettings({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, stopSequences, seed, }: Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>): Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>;
|
761
709
|
|
762
710
|
declare function download({ url }: {
|
763
711
|
url: URL;
|