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
@@ -1,244 +1,246 @@
|
|
1
|
-
import { LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2ProviderMetadata, LanguageModelV2 } from '@ai-sdk/provider';
|
2
|
-
import { ReactNode } from 'react';
|
3
1
|
import { z } from 'zod';
|
4
|
-
import {
|
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
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
type
|
16
|
-
|
17
|
-
type OnSetAIState<S> = ({ key, state, done, }: {
|
18
|
-
key: string | number | symbol | undefined;
|
19
|
-
state: S;
|
20
|
-
done: boolean;
|
21
|
-
}) => void | Promise<void>;
|
22
|
-
type OnGetUIState<S> = AIAction<void, S | undefined>;
|
23
|
-
type ValueOrUpdater<T> = T | ((current: T) => T);
|
24
|
-
type MutableAIState<AIState> = {
|
25
|
-
get: () => AIState;
|
26
|
-
update: (newState: ValueOrUpdater<AIState>) => void;
|
27
|
-
done: ((newState: AIState) => void) | (() => void);
|
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;
|
28
17
|
};
|
29
18
|
|
30
19
|
/**
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): Readonly<InferAIState<AI, any>[typeof key]>;
|
40
|
-
/**
|
41
|
-
* Get the mutable AI state. Note that you must call `.done()` when finishing
|
42
|
-
* updating the AI state.
|
43
|
-
*
|
44
|
-
* @example
|
45
|
-
* ```tsx
|
46
|
-
* const state = getMutableAIState()
|
47
|
-
* state.update({ ...state.get(), key: 'value' })
|
48
|
-
* state.update((currentState) => ({ ...currentState, key: 'value' }))
|
49
|
-
* state.done()
|
50
|
-
* ```
|
51
|
-
*
|
52
|
-
* @example
|
53
|
-
* ```tsx
|
54
|
-
* const state = getMutableAIState()
|
55
|
-
* state.done({ ...state.get(), key: 'value' }) // Done with a new state
|
56
|
-
* ```
|
57
|
-
*/
|
58
|
-
declare function getMutableAIState<AI extends AIProvider = any>(): MutableAIState<InferAIState<AI, any>>;
|
59
|
-
declare function getMutableAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): MutableAIState<InferAIState<AI, any>[typeof key]>;
|
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.
|
60
28
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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 = {
|
65
38
|
/**
|
66
|
-
|
67
|
-
* You can use this to persist the AI state to a database, or to send it to a
|
68
|
-
* logging service.
|
39
|
+
The number of tokens used in the prompt.
|
69
40
|
*/
|
70
|
-
|
41
|
+
promptTokens: number;
|
71
42
|
/**
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
*
|
78
|
-
* This function must be annotated with the `"use server"` directive.
|
79
|
-
*
|
80
|
-
* @example
|
81
|
-
* ```tsx
|
82
|
-
* onGetUIState: async () => {
|
83
|
-
* 'use server';
|
84
|
-
*
|
85
|
-
* const currentAIState = getAIState();
|
86
|
-
* const externalAIState = await loadAIStateFromDatabase();
|
87
|
-
*
|
88
|
-
* if (currentAIState === externalAIState) return undefined;
|
89
|
-
*
|
90
|
-
* // Update current AI state and return the new UI state
|
91
|
-
* const state = getMutableAIState()
|
92
|
-
* state.done(externalAIState)
|
93
|
-
*
|
94
|
-
* return <div>...</div>;
|
95
|
-
* }
|
96
|
-
* ```
|
43
|
+
The number of tokens used in the completion.
|
44
|
+
*/
|
45
|
+
completionTokens: number;
|
46
|
+
/**
|
47
|
+
The total number of tokens used (promptTokens + completionTokens).
|
97
48
|
*/
|
98
|
-
|
99
|
-
}
|
49
|
+
totalTokens: number;
|
50
|
+
};
|
51
|
+
declare function calculateLanguageModelUsage({ promptTokens, completionTokens, }: {
|
52
|
+
promptTokens: number;
|
53
|
+
completionTokens: number;
|
54
|
+
}): LanguageModelUsage;
|
100
55
|
|
101
|
-
|
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 {
|
102
79
|
/**
|
103
|
-
|
80
|
+
* The name of the attachment, usually the file name.
|
104
81
|
*/
|
105
|
-
|
82
|
+
name?: string;
|
106
83
|
/**
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
111
|
-
|
112
|
-
@default 0
|
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.
|
113
86
|
*/
|
114
|
-
|
87
|
+
contentType?: string;
|
115
88
|
/**
|
116
|
-
|
117
|
-
|
118
|
-
E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
119
|
-
are considered.
|
120
|
-
|
121
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
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).
|
122
90
|
*/
|
123
|
-
|
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 {
|
124
97
|
/**
|
125
|
-
|
126
|
-
|
127
|
-
Used to remove "long tail" low probability responses.
|
128
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
98
|
+
A unique identifier for the message.
|
129
99
|
*/
|
130
|
-
|
100
|
+
id: string;
|
131
101
|
/**
|
132
|
-
|
133
|
-
repeat information that is already in the prompt.
|
134
|
-
|
135
|
-
The presence penalty is a number between -1 (increase repetition)
|
136
|
-
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
102
|
+
The timestamp of the message.
|
137
103
|
*/
|
138
|
-
|
104
|
+
createdAt?: Date;
|
139
105
|
/**
|
140
|
-
|
141
|
-
|
106
|
+
Text content of the message. Use parts when possible.
|
107
|
+
*/
|
108
|
+
content: string;
|
109
|
+
/**
|
110
|
+
Reasoning for the message.
|
142
111
|
|
143
|
-
|
144
|
-
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
112
|
+
@deprecated Use `parts` instead.
|
145
113
|
*/
|
146
|
-
|
114
|
+
reasoning?: string;
|
147
115
|
/**
|
148
|
-
|
149
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
150
|
-
Providers may have limits on the number of stop sequences.
|
116
|
+
* Additional attachments to be sent along with the message.
|
151
117
|
*/
|
152
|
-
|
118
|
+
experimental_attachments?: Attachment[];
|
153
119
|
/**
|
154
|
-
The
|
155
|
-
by the model, calls will generate deterministic results.
|
120
|
+
The 'data' role is deprecated.
|
156
121
|
*/
|
157
|
-
|
122
|
+
role: 'system' | 'user' | 'assistant' | 'data';
|
158
123
|
/**
|
159
|
-
|
124
|
+
For data messages.
|
160
125
|
|
161
|
-
@
|
126
|
+
@deprecated Data messages will be removed.
|
162
127
|
*/
|
163
|
-
|
128
|
+
data?: JSONValue;
|
164
129
|
/**
|
165
|
-
|
130
|
+
* Additional message-specific information added on the server via StreamData
|
166
131
|
*/
|
167
|
-
|
132
|
+
annotations?: JSONValue[] | undefined;
|
168
133
|
/**
|
169
|
-
|
170
|
-
|
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.
|
171
138
|
*/
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
- `content-filter`: content filter violation stopped the model
|
182
|
-
- `tool-calls`: model triggered tool calls
|
183
|
-
- `error`: model stopped because of an error
|
184
|
-
- `other`: model stopped for other reasons
|
185
|
-
*/
|
186
|
-
type FinishReason = LanguageModelV2FinishReason;
|
187
|
-
/**
|
188
|
-
Warning from the model provider for this call. The call will proceed, but e.g.
|
189
|
-
some settings might not be supported, which can lead to suboptimal results.
|
190
|
-
*/
|
191
|
-
type CallWarning = LanguageModelV2CallWarning;
|
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
|
+
}
|
192
148
|
/**
|
193
|
-
|
194
|
-
|
195
|
-
- `auto` (default): the model can choose whether and which tools to call.
|
196
|
-
- `required`: the model must call a tool. It can choose which tool to call.
|
197
|
-
- `none`: the model must not call tools
|
198
|
-
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
149
|
+
* A text part of a message.
|
199
150
|
*/
|
200
|
-
type
|
201
|
-
type: '
|
202
|
-
|
151
|
+
type TextUIPart = {
|
152
|
+
type: 'text';
|
153
|
+
/**
|
154
|
+
* The text content.
|
155
|
+
*/
|
156
|
+
text: string;
|
203
157
|
};
|
204
|
-
|
205
158
|
/**
|
206
|
-
|
207
|
-
|
208
|
-
This is needed to enable provider-specific functionality that can be
|
209
|
-
fully encapsulated in the provider.
|
159
|
+
* A reasoning part of a message.
|
210
160
|
*/
|
211
|
-
type
|
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
|
+
};
|
212
176
|
/**
|
213
|
-
|
214
|
-
|
215
|
-
They are passed through to the provider from the AI SDK and enable
|
216
|
-
provider-specific functionality that can be fully encapsulated in the provider.
|
177
|
+
* A tool invocation part of a message.
|
217
178
|
*/
|
218
|
-
type
|
219
|
-
|
179
|
+
type ToolInvocationUIPart = {
|
180
|
+
type: 'tool-invocation';
|
181
|
+
/**
|
182
|
+
* The tool invocation.
|
183
|
+
*/
|
184
|
+
toolInvocation: ToolInvocation;
|
185
|
+
};
|
220
186
|
/**
|
221
|
-
|
187
|
+
* A source part of a message.
|
222
188
|
*/
|
223
|
-
type
|
189
|
+
type SourceUIPart = {
|
190
|
+
type: 'source';
|
224
191
|
/**
|
225
|
-
|
192
|
+
* The source.
|
226
193
|
*/
|
227
|
-
|
194
|
+
source: LanguageModelV2Source;
|
195
|
+
};
|
196
|
+
/**
|
197
|
+
* A file part of a message.
|
198
|
+
*/
|
199
|
+
type FileUIPart = {
|
200
|
+
type: 'file';
|
228
201
|
/**
|
229
|
-
|
230
|
-
|
231
|
-
|
202
|
+
* IANA media type of the file.
|
203
|
+
*
|
204
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
205
|
+
*/
|
206
|
+
mediaType: string;
|
232
207
|
/**
|
233
|
-
|
208
|
+
* The base64 encoded data.
|
234
209
|
*/
|
235
|
-
|
210
|
+
data: string;
|
211
|
+
};
|
212
|
+
/**
|
213
|
+
* A step boundary part of a message.
|
214
|
+
*/
|
215
|
+
type StepStartUIPart = {
|
216
|
+
type: 'step-start';
|
236
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>;
|
237
225
|
|
238
226
|
/**
|
239
|
-
|
227
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
240
228
|
*/
|
241
|
-
|
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
|
+
};
|
242
244
|
|
243
245
|
type ToolResultContent = Array<{
|
244
246
|
type: 'text';
|
@@ -246,9 +248,18 @@ type ToolResultContent = Array<{
|
|
246
248
|
} | {
|
247
249
|
type: 'image';
|
248
250
|
data: string;
|
251
|
+
mediaType?: string;
|
252
|
+
/**
|
253
|
+
* @deprecated Use `mediaType` instead.
|
254
|
+
*/
|
249
255
|
mimeType?: string;
|
250
256
|
}>;
|
251
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
|
+
|
252
263
|
/**
|
253
264
|
Text content part of a prompt. It contains a string of text.
|
254
265
|
*/
|
@@ -282,7 +293,13 @@ interface ImagePart {
|
|
282
293
|
*/
|
283
294
|
image: DataContent | URL;
|
284
295
|
/**
|
285
|
-
Optional
|
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.
|
286
303
|
*/
|
287
304
|
mimeType?: string;
|
288
305
|
/**
|
@@ -313,9 +330,15 @@ interface FilePart {
|
|
313
330
|
*/
|
314
331
|
filename?: string;
|
315
332
|
/**
|
316
|
-
|
333
|
+
IANA media type of the file.
|
334
|
+
|
335
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
317
336
|
*/
|
318
|
-
|
337
|
+
mediaType: string;
|
338
|
+
/**
|
339
|
+
@deprecated Use `mediaType` instead.
|
340
|
+
*/
|
341
|
+
mimeType?: string;
|
319
342
|
/**
|
320
343
|
Additional provider-specific metadata. They are passed through
|
321
344
|
to the provider from the AI SDK and enable provider-specific
|
@@ -527,6 +550,76 @@ It can be a user message, an assistant message, or a tool message.
|
|
527
550
|
*/
|
528
551
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
529
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
|
+
|
530
623
|
/**
|
531
624
|
Prompt part of the AI function options.
|
532
625
|
It contains a system message, a simple text prompt, or a list of messages.
|
@@ -546,203 +639,144 @@ type Prompt = {
|
|
546
639
|
messages?: Array<CoreMessage> | Array<Omit<Message, 'id'>>;
|
547
640
|
};
|
548
641
|
|
549
|
-
type
|
550
|
-
type Renderer<T extends Array<any>> = (...args: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
|
551
|
-
type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
|
552
|
-
description?: string;
|
553
|
-
parameters: PARAMETERS;
|
554
|
-
generate?: Renderer<[
|
555
|
-
z.infer<PARAMETERS>,
|
556
|
-
{
|
557
|
-
toolName: string;
|
558
|
-
toolCallId: string;
|
559
|
-
}
|
560
|
-
]>;
|
561
|
-
};
|
562
|
-
type RenderText = Renderer<[
|
563
|
-
{
|
564
|
-
/**
|
565
|
-
* The full text content from the model so far.
|
566
|
-
*/
|
567
|
-
content: string;
|
568
|
-
/**
|
569
|
-
* The new appended text content from the model since the last `text` call.
|
570
|
-
*/
|
571
|
-
delta: string;
|
572
|
-
/**
|
573
|
-
* Whether the model is done generating text.
|
574
|
-
* If `true`, the `content` will be the final output and this call will be the last.
|
575
|
-
*/
|
576
|
-
done: boolean;
|
577
|
-
}
|
578
|
-
]>;
|
579
|
-
type RenderResult = {
|
580
|
-
value: ReactNode;
|
581
|
-
} & Awaited<ReturnType<LanguageModelV2['doStream']>>;
|
582
|
-
/**
|
583
|
-
* `streamUI` is a helper function to create a streamable UI from LLMs.
|
584
|
-
*/
|
585
|
-
declare function streamUI<TOOLS extends {
|
586
|
-
[name: string]: z.ZodTypeAny;
|
587
|
-
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, initial, text, experimental_providerMetadata, providerOptions, onFinish, ...settings }: CallSettings & Prompt & {
|
588
|
-
/**
|
589
|
-
* The language model to use.
|
590
|
-
*/
|
591
|
-
model: LanguageModelV2;
|
592
|
-
/**
|
593
|
-
* The tools that the model can call. The model needs to support calling tools.
|
594
|
-
*/
|
595
|
-
tools?: {
|
596
|
-
[name in keyof TOOLS]: RenderTool<TOOLS[name]>;
|
597
|
-
};
|
598
|
-
/**
|
599
|
-
* The tool choice strategy. Default: 'auto'.
|
600
|
-
*/
|
601
|
-
toolChoice?: ToolChoice<TOOLS>;
|
602
|
-
text?: RenderText;
|
603
|
-
initial?: ReactNode;
|
604
|
-
/**
|
605
|
-
Additional provider-specific options. They are passed through
|
606
|
-
to the provider from the AI SDK and enable provider-specific
|
607
|
-
functionality that can be fully encapsulated in the provider.
|
608
|
-
*/
|
609
|
-
providerOptions?: ProviderOptions;
|
642
|
+
type StandardizedPrompt = {
|
610
643
|
/**
|
611
|
-
|
612
|
-
|
613
|
-
|
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';
|
614
648
|
/**
|
615
|
-
*
|
616
|
-
*/
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
* The final ui node that was generated.
|
628
|
-
*/
|
629
|
-
value: ReactNode;
|
630
|
-
/**
|
631
|
-
* Warnings from the model provider (e.g. unsupported settings)
|
632
|
-
*/
|
633
|
-
warnings?: CallWarning[];
|
634
|
-
/**
|
635
|
-
* Optional raw response data.
|
636
|
-
*/
|
637
|
-
rawResponse?: {
|
638
|
-
/**
|
639
|
-
* Response headers.
|
640
|
-
*/
|
641
|
-
headers?: Record<string, string>;
|
642
|
-
};
|
643
|
-
}) => Promise<void> | void;
|
644
|
-
}): Promise<RenderResult>;
|
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;
|
645
661
|
|
646
|
-
type
|
662
|
+
type CallSettings = {
|
663
|
+
/**
|
664
|
+
Maximum number of tokens to generate.
|
665
|
+
*/
|
666
|
+
maxTokens?: number;
|
647
667
|
/**
|
648
|
-
|
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
|
649
674
|
*/
|
650
|
-
|
675
|
+
temperature?: number;
|
651
676
|
/**
|
652
|
-
|
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.
|
653
683
|
*/
|
654
|
-
|
684
|
+
topP?: number;
|
655
685
|
/**
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
* ```jsx
|
661
|
-
* const ui = createStreamableUI(<div>hello</div>)
|
662
|
-
* ui.append(<div>world</div>)
|
663
|
-
*
|
664
|
-
* // The UI node will be:
|
665
|
-
* // <>
|
666
|
-
* // <div>hello</div>
|
667
|
-
* // <div>world</div>
|
668
|
-
* // </>
|
669
|
-
* ```
|
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.
|
670
690
|
*/
|
671
|
-
|
691
|
+
topK?: number;
|
672
692
|
/**
|
673
|
-
|
674
|
-
|
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.
|
675
698
|
*/
|
676
|
-
|
699
|
+
presencePenalty?: number;
|
677
700
|
/**
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
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.
|
682
706
|
*/
|
683
|
-
|
684
|
-
};
|
685
|
-
/**
|
686
|
-
* Create a piece of changeable UI that can be streamed to the client.
|
687
|
-
* On the client side, it can be rendered as a normal React node.
|
688
|
-
*/
|
689
|
-
declare function createStreamableUI(initialValue?: React.ReactNode): StreamableUIWrapper;
|
690
|
-
|
691
|
-
declare const __internal_curr: unique symbol;
|
692
|
-
declare const __internal_error: unique symbol;
|
693
|
-
/**
|
694
|
-
* StreamableValue is a value that can be streamed over the network via AI Actions.
|
695
|
-
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
|
696
|
-
*/
|
697
|
-
type StreamableValue<T = any, E = any> = {
|
698
|
-
[__internal_curr]?: T;
|
699
|
-
[__internal_error]?: E;
|
700
|
-
};
|
701
|
-
|
702
|
-
/**
|
703
|
-
* Create a wrapped, changeable value that can be streamed to the client.
|
704
|
-
* On the client side, the value can be accessed via the readStreamableValue() API.
|
705
|
-
*/
|
706
|
-
declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): StreamableValueWrapper<T, E>;
|
707
|
-
type StreamableValueWrapper<T, E> = {
|
707
|
+
frequencyPenalty?: number;
|
708
708
|
/**
|
709
|
-
|
710
|
-
|
711
|
-
|
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
712
|
*/
|
713
|
-
|
713
|
+
stopSequences?: string[];
|
714
714
|
/**
|
715
|
-
|
715
|
+
The seed (integer) to use for random sampling. If set and supported
|
716
|
+
by the model, calls will generate deterministic results.
|
716
717
|
*/
|
717
|
-
|
718
|
+
seed?: number;
|
718
719
|
/**
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
* @example
|
723
|
-
* ```jsx
|
724
|
-
* const streamable = createStreamableValue('hello');
|
725
|
-
* streamable.append(' world');
|
726
|
-
*
|
727
|
-
* // The value will be 'hello world'
|
728
|
-
* ```
|
720
|
+
Maximum number of retries. Set to 0 to disable retries.
|
721
|
+
|
722
|
+
@default 2
|
729
723
|
*/
|
730
|
-
|
724
|
+
maxRetries?: number;
|
731
725
|
/**
|
732
|
-
|
733
|
-
* It will be thrown on the client side when consumed via
|
734
|
-
* `readStreamableValue` or `useStreamableValue`.
|
726
|
+
Abort signal.
|
735
727
|
*/
|
736
|
-
|
728
|
+
abortSignal?: AbortSignal;
|
737
729
|
/**
|
738
|
-
|
739
|
-
|
740
|
-
* Once called, the value cannot be updated or appended anymore.
|
741
|
-
*
|
742
|
-
* This method is always **required** to be called, otherwise the response
|
743
|
-
* will be stuck in a loading state.
|
730
|
+
Additional HTTP headers to be sent with the request.
|
731
|
+
Only applicable for HTTP-based providers.
|
744
732
|
*/
|
745
|
-
|
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;
|
746
755
|
};
|
747
756
|
|
748
|
-
|
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 };
|