ai 5.0.0-canary.1 → 5.0.0-canary.11
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 +146 -0
- package/dist/index.d.mts +1465 -727
- package/dist/index.d.ts +1465 -727
- package/dist/index.js +2802 -1263
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2692 -1190
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +732 -0
- package/dist/internal/index.d.ts +732 -0
- package/dist/internal/index.js +1490 -0
- package/dist/internal/index.js.map +1 -0
- package/{rsc/dist/rsc-server.mjs → dist/internal/index.mjs} +860 -1552
- package/dist/internal/index.mjs.map +1 -0
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.js +4 -4
- package/dist/mcp-stdio/index.js.map +1 -0
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.mjs +4 -4
- package/dist/mcp-stdio/index.mjs.map +1 -0
- package/{test/dist → dist/test}/index.d.mts +21 -23
- package/{test/dist → dist/test}/index.d.ts +21 -23
- package/{test/dist → dist/test}/index.js +31 -15
- package/dist/test/index.js.map +1 -0
- package/{test/dist → dist/test}/index.mjs +30 -14
- package/dist/test/index.mjs.map +1 -0
- package/package.json +28 -47
- package/mcp-stdio/create-child-process.test.ts +0 -92
- package/mcp-stdio/create-child-process.ts +0 -21
- package/mcp-stdio/dist/index.js.map +0 -1
- package/mcp-stdio/dist/index.mjs.map +0 -1
- package/mcp-stdio/get-environment.ts +0 -43
- package/mcp-stdio/index.ts +0 -4
- package/mcp-stdio/mcp-stdio-transport.test.ts +0 -262
- package/mcp-stdio/mcp-stdio-transport.ts +0 -157
- 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.d.mts +0 -748
- 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
- package/test/dist/index.js.map +0 -1
- package/test/dist/index.mjs.map +0 -1
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.mts +6 -6
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.ts +6 -6
package/dist/index.d.mts
CHANGED
@@ -1,14 +1,47 @@
|
|
1
|
-
import { IDGenerator } from '@ai-sdk/provider-utils';
|
2
|
-
export {
|
3
|
-
import {
|
4
|
-
export {
|
5
|
-
import { LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2LogProbs, LanguageModelV2CallWarning, LanguageModelV2Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV2ProviderMetadata, LanguageModelV2CallOptions, AISDKError, LanguageModelV2FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
6
|
-
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Prompt, LanguageModelV2StreamPart, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
1
|
+
import { ToolCall, ToolResult, FetchFunction, Validator, IDGenerator } from '@ai-sdk/provider-utils';
|
2
|
+
export { IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
|
3
|
+
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2LogProbs, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, TranscriptionModelV1, TranscriptionModelV1CallWarning, SpeechModelV1, SpeechModelV1CallWarning, JSONValue as JSONValue$1, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7 as JSONSchema7$1, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
4
|
+
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
7
5
|
import { ServerResponse } from 'node:http';
|
8
6
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
9
7
|
import { z } from 'zod';
|
8
|
+
import { JSONSchema7 } from 'json-schema';
|
10
9
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
11
10
|
|
11
|
+
/**
|
12
|
+
Embedding model that is used by the AI SDK Core functions.
|
13
|
+
*/
|
14
|
+
type EmbeddingModel<VALUE> = EmbeddingModelV2<VALUE>;
|
15
|
+
/**
|
16
|
+
Embedding.
|
17
|
+
*/
|
18
|
+
type Embedding = EmbeddingModelV2Embedding;
|
19
|
+
|
20
|
+
/**
|
21
|
+
Image model that is used by the AI SDK Core functions.
|
22
|
+
*/
|
23
|
+
type ImageModel = ImageModelV1;
|
24
|
+
/**
|
25
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
26
|
+
some settings might not be supported, which can lead to suboptimal results.
|
27
|
+
*/
|
28
|
+
type ImageGenerationWarning = ImageModelV1CallWarning;
|
29
|
+
|
30
|
+
type ImageModelResponseMetadata = {
|
31
|
+
/**
|
32
|
+
Timestamp for the start of the generated response.
|
33
|
+
*/
|
34
|
+
timestamp: Date;
|
35
|
+
/**
|
36
|
+
The ID of the response model that was used to generate the response.
|
37
|
+
*/
|
38
|
+
modelId: string;
|
39
|
+
/**
|
40
|
+
Response headers.
|
41
|
+
*/
|
42
|
+
headers?: Record<string, string>;
|
43
|
+
};
|
44
|
+
|
12
45
|
/**
|
13
46
|
Language model that is used by the AI SDK Core functions.
|
14
47
|
*/
|
@@ -50,132 +83,14 @@ Tool choice for the generation. It supports the following settings:
|
|
50
83
|
*/
|
51
84
|
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
52
85
|
type: 'tool';
|
53
|
-
toolName: keyof TOOLS
|
54
|
-
};
|
55
|
-
/**
|
56
|
-
* @deprecated Use `ToolChoice` instead.
|
57
|
-
*/
|
58
|
-
type CoreToolChoice<TOOLS extends Record<string, unknown>> = ToolChoice<TOOLS>;
|
59
|
-
|
60
|
-
interface DataStreamWriter {
|
61
|
-
/**
|
62
|
-
* Appends a data part to the stream.
|
63
|
-
*/
|
64
|
-
write(data: DataStreamString): void;
|
65
|
-
/**
|
66
|
-
* Appends a data part to the stream.
|
67
|
-
*/
|
68
|
-
writeData(value: JSONValue): void;
|
69
|
-
/**
|
70
|
-
* Appends a message annotation to the stream.
|
71
|
-
*/
|
72
|
-
writeMessageAnnotation(value: JSONValue): void;
|
73
|
-
/**
|
74
|
-
* Appends a source part to the stream.
|
75
|
-
*/
|
76
|
-
writeSource(source: Source): void;
|
77
|
-
/**
|
78
|
-
* Merges the contents of another stream to this stream.
|
79
|
-
*/
|
80
|
-
merge(stream: ReadableStream<DataStreamString>): void;
|
81
|
-
/**
|
82
|
-
* Error handler that is used by the data stream writer.
|
83
|
-
* This is intended for forwarding when merging streams
|
84
|
-
* to prevent duplicated error masking.
|
85
|
-
*/
|
86
|
-
onError: ((error: unknown) => string) | undefined;
|
87
|
-
}
|
88
|
-
|
89
|
-
declare function createDataStream({ execute, onError, }: {
|
90
|
-
execute: (dataStream: DataStreamWriter) => Promise<void> | void;
|
91
|
-
onError?: (error: unknown) => string;
|
92
|
-
}): ReadableStream<DataStreamString>;
|
93
|
-
|
94
|
-
declare function createDataStreamResponse({ status, statusText, headers, execute, onError, }: ResponseInit & {
|
95
|
-
execute: (dataStream: DataStreamWriter) => Promise<void> | void;
|
96
|
-
onError?: (error: unknown) => string;
|
97
|
-
}): Response;
|
98
|
-
|
99
|
-
declare function pipeDataStreamToResponse(response: ServerResponse, { status, statusText, headers, execute, onError, }: ResponseInit & {
|
100
|
-
execute: (writer: DataStreamWriter) => Promise<void> | void;
|
101
|
-
onError?: (error: unknown) => string;
|
102
|
-
}): void;
|
103
|
-
|
104
|
-
/**
|
105
|
-
* Telemetry configuration.
|
106
|
-
*/
|
107
|
-
type TelemetrySettings = {
|
108
|
-
/**
|
109
|
-
* Enable or disable telemetry. Disabled by default while experimental.
|
110
|
-
*/
|
111
|
-
isEnabled?: boolean;
|
112
|
-
/**
|
113
|
-
* Enable or disable input recording. Enabled by default.
|
114
|
-
*
|
115
|
-
* You might want to disable input recording to avoid recording sensitive
|
116
|
-
* information, to reduce data transfers, or to increase performance.
|
117
|
-
*/
|
118
|
-
recordInputs?: boolean;
|
119
|
-
/**
|
120
|
-
* Enable or disable output recording. Enabled by default.
|
121
|
-
*
|
122
|
-
* You might want to disable output recording to avoid recording sensitive
|
123
|
-
* information, to reduce data transfers, or to increase performance.
|
124
|
-
*/
|
125
|
-
recordOutputs?: boolean;
|
126
|
-
/**
|
127
|
-
* Identifier for this function. Used to group telemetry data by function.
|
128
|
-
*/
|
129
|
-
functionId?: string;
|
130
|
-
/**
|
131
|
-
* Additional information to include in the telemetry data.
|
132
|
-
*/
|
133
|
-
metadata?: Record<string, AttributeValue>;
|
134
|
-
/**
|
135
|
-
* A custom tracer to use for the telemetry data.
|
136
|
-
*/
|
137
|
-
tracer?: Tracer;
|
138
|
-
};
|
139
|
-
|
140
|
-
/**
|
141
|
-
Embedding model that is used by the AI SDK Core functions.
|
142
|
-
*/
|
143
|
-
type EmbeddingModel<VALUE> = EmbeddingModelV1<VALUE>;
|
144
|
-
/**
|
145
|
-
Embedding.
|
146
|
-
*/
|
147
|
-
type Embedding = EmbeddingModelV1Embedding;
|
148
|
-
|
149
|
-
/**
|
150
|
-
Image model that is used by the AI SDK Core functions.
|
151
|
-
*/
|
152
|
-
type ImageModel = ImageModelV1;
|
153
|
-
/**
|
154
|
-
Warning from the model provider for this call. The call will proceed, but e.g.
|
155
|
-
some settings might not be supported, which can lead to suboptimal results.
|
156
|
-
*/
|
157
|
-
type ImageGenerationWarning = ImageModelV1CallWarning;
|
158
|
-
|
159
|
-
type ImageModelResponseMetadata = {
|
160
|
-
/**
|
161
|
-
Timestamp for the start of the generated response.
|
162
|
-
*/
|
163
|
-
timestamp: Date;
|
164
|
-
/**
|
165
|
-
The ID of the response model that was used to generate the response.
|
166
|
-
*/
|
167
|
-
modelId: string;
|
168
|
-
/**
|
169
|
-
Response headers.
|
170
|
-
*/
|
171
|
-
headers?: Record<string, string>;
|
86
|
+
toolName: Extract<keyof TOOLS, string>;
|
172
87
|
};
|
173
88
|
|
174
89
|
type LanguageModelRequestMetadata = {
|
175
90
|
/**
|
176
|
-
|
91
|
+
Request HTTP body that was sent to the provider API.
|
177
92
|
*/
|
178
|
-
body?:
|
93
|
+
body?: unknown;
|
179
94
|
};
|
180
95
|
|
181
96
|
type LanguageModelResponseMetadata = {
|
@@ -240,40 +155,891 @@ Additional provider-specific metadata that is returned from the provider.
|
|
240
155
|
This is needed to enable provider-specific functionality that can be
|
241
156
|
fully encapsulated in the provider.
|
242
157
|
*/
|
243
|
-
type ProviderMetadata =
|
158
|
+
type ProviderMetadata = SharedV2ProviderMetadata;
|
244
159
|
/**
|
245
160
|
Additional provider-specific options.
|
246
161
|
|
247
|
-
They are passed through to the provider from the AI SDK and enable
|
248
|
-
provider-specific functionality that can be fully encapsulated in the provider.
|
249
|
-
*/
|
250
|
-
type ProviderOptions =
|
162
|
+
They are passed through to the provider from the AI SDK and enable
|
163
|
+
provider-specific functionality that can be fully encapsulated in the provider.
|
164
|
+
*/
|
165
|
+
type ProviderOptions = SharedV2ProviderOptions;
|
166
|
+
|
167
|
+
/**
|
168
|
+
Represents the number of tokens used in a prompt and completion.
|
169
|
+
*/
|
170
|
+
type LanguageModelUsage$1 = {
|
171
|
+
/**
|
172
|
+
The number of tokens used in the prompt.
|
173
|
+
*/
|
174
|
+
promptTokens: number;
|
175
|
+
/**
|
176
|
+
The number of tokens used in the completion.
|
177
|
+
*/
|
178
|
+
completionTokens: number;
|
179
|
+
/**
|
180
|
+
The total number of tokens used (promptTokens + completionTokens).
|
181
|
+
*/
|
182
|
+
totalTokens: number;
|
183
|
+
};
|
184
|
+
/**
|
185
|
+
Represents the number of tokens used in an embedding.
|
186
|
+
*/
|
187
|
+
type EmbeddingModelUsage = {
|
188
|
+
/**
|
189
|
+
The number of tokens used in the embedding.
|
190
|
+
*/
|
191
|
+
tokens: number;
|
192
|
+
};
|
193
|
+
|
194
|
+
/**
|
195
|
+
Represents the number of tokens used in a prompt and completion.
|
196
|
+
*/
|
197
|
+
type LanguageModelUsage = {
|
198
|
+
/**
|
199
|
+
The number of tokens used in the prompt.
|
200
|
+
*/
|
201
|
+
promptTokens: number;
|
202
|
+
/**
|
203
|
+
The number of tokens used in the completion.
|
204
|
+
*/
|
205
|
+
completionTokens: number;
|
206
|
+
/**
|
207
|
+
The total number of tokens used (promptTokens + completionTokens).
|
208
|
+
*/
|
209
|
+
totalTokens: number;
|
210
|
+
};
|
211
|
+
|
212
|
+
type IdGenerator = () => string;
|
213
|
+
/**
|
214
|
+
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
215
|
+
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
216
|
+
Once the call is complete, the invocation is a tool result.
|
217
|
+
|
218
|
+
The step is used to track how to map an assistant UI message with many tool invocations
|
219
|
+
back to a sequence of LLM assistant/tool result message pairs.
|
220
|
+
It is optional for backwards compatibility.
|
221
|
+
*/
|
222
|
+
type ToolInvocation = ({
|
223
|
+
state: 'partial-call';
|
224
|
+
step?: number;
|
225
|
+
} & ToolCall<string, any>) | ({
|
226
|
+
state: 'call';
|
227
|
+
step?: number;
|
228
|
+
} & ToolCall<string, any>) | ({
|
229
|
+
state: 'result';
|
230
|
+
step?: number;
|
231
|
+
} & ToolResult<string, any, any>);
|
232
|
+
/**
|
233
|
+
* An attachment that can be sent along with a message.
|
234
|
+
*/
|
235
|
+
interface Attachment {
|
236
|
+
/**
|
237
|
+
* The name of the attachment, usually the file name.
|
238
|
+
*/
|
239
|
+
name?: string;
|
240
|
+
/**
|
241
|
+
* A string indicating the [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
|
242
|
+
* By default, it's extracted from the pathname's extension.
|
243
|
+
*/
|
244
|
+
contentType?: string;
|
245
|
+
/**
|
246
|
+
* 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).
|
247
|
+
*/
|
248
|
+
url: string;
|
249
|
+
}
|
250
|
+
/**
|
251
|
+
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
252
|
+
*/
|
253
|
+
interface Message {
|
254
|
+
/**
|
255
|
+
A unique identifier for the message.
|
256
|
+
*/
|
257
|
+
id: string;
|
258
|
+
/**
|
259
|
+
The timestamp of the message.
|
260
|
+
*/
|
261
|
+
createdAt?: Date;
|
262
|
+
/**
|
263
|
+
Text content of the message. Use parts when possible.
|
264
|
+
*/
|
265
|
+
content: string;
|
266
|
+
/**
|
267
|
+
Reasoning for the message.
|
268
|
+
|
269
|
+
@deprecated Use `parts` instead.
|
270
|
+
*/
|
271
|
+
reasoning?: string;
|
272
|
+
/**
|
273
|
+
* Additional attachments to be sent along with the message.
|
274
|
+
*/
|
275
|
+
experimental_attachments?: Attachment[];
|
276
|
+
/**
|
277
|
+
The 'data' role is deprecated.
|
278
|
+
*/
|
279
|
+
role: 'system' | 'user' | 'assistant' | 'data';
|
280
|
+
/**
|
281
|
+
For data messages.
|
282
|
+
|
283
|
+
@deprecated Data messages will be removed.
|
284
|
+
*/
|
285
|
+
data?: JSONValue;
|
286
|
+
/**
|
287
|
+
* Additional message-specific information added on the server via StreamData
|
288
|
+
*/
|
289
|
+
annotations?: JSONValue[] | undefined;
|
290
|
+
/**
|
291
|
+
Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
|
292
|
+
that the assistant made as part of this message.
|
293
|
+
|
294
|
+
@deprecated Use `parts` instead.
|
295
|
+
*/
|
296
|
+
toolInvocations?: Array<ToolInvocation>;
|
297
|
+
/**
|
298
|
+
* The parts of the message. Use this for rendering the message in the UI.
|
299
|
+
*
|
300
|
+
* Assistant messages can have text, reasoning and tool invocation parts.
|
301
|
+
* User messages can have text parts.
|
302
|
+
*/
|
303
|
+
parts?: Array<TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart>;
|
304
|
+
}
|
305
|
+
type UIMessage = Message & {
|
306
|
+
/**
|
307
|
+
* The parts of the message. Use this for rendering the message in the UI.
|
308
|
+
*
|
309
|
+
* Assistant messages can have text, reasoning and tool invocation parts.
|
310
|
+
* User messages can have text parts.
|
311
|
+
*/
|
312
|
+
parts: Array<TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart>;
|
313
|
+
};
|
314
|
+
/**
|
315
|
+
* A text part of a message.
|
316
|
+
*/
|
317
|
+
type TextUIPart = {
|
318
|
+
type: 'text';
|
319
|
+
/**
|
320
|
+
* The text content.
|
321
|
+
*/
|
322
|
+
text: string;
|
323
|
+
};
|
324
|
+
/**
|
325
|
+
* A reasoning part of a message.
|
326
|
+
*/
|
327
|
+
type ReasoningUIPart = {
|
328
|
+
type: 'reasoning';
|
329
|
+
/**
|
330
|
+
* The reasoning text.
|
331
|
+
*/
|
332
|
+
reasoning: string;
|
333
|
+
details: Array<{
|
334
|
+
type: 'text';
|
335
|
+
text: string;
|
336
|
+
signature?: string;
|
337
|
+
} | {
|
338
|
+
type: 'redacted';
|
339
|
+
data: string;
|
340
|
+
}>;
|
341
|
+
};
|
342
|
+
/**
|
343
|
+
* A tool invocation part of a message.
|
344
|
+
*/
|
345
|
+
type ToolInvocationUIPart = {
|
346
|
+
type: 'tool-invocation';
|
347
|
+
/**
|
348
|
+
* The tool invocation.
|
349
|
+
*/
|
350
|
+
toolInvocation: ToolInvocation;
|
351
|
+
};
|
352
|
+
/**
|
353
|
+
* A source part of a message.
|
354
|
+
*/
|
355
|
+
type SourceUIPart = {
|
356
|
+
type: 'source';
|
357
|
+
/**
|
358
|
+
* The source.
|
359
|
+
*/
|
360
|
+
source: LanguageModelV2Source;
|
361
|
+
};
|
362
|
+
/**
|
363
|
+
* A file part of a message.
|
364
|
+
*/
|
365
|
+
type FileUIPart = {
|
366
|
+
type: 'file';
|
367
|
+
/**
|
368
|
+
* IANA media type of the file.
|
369
|
+
*
|
370
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
371
|
+
*/
|
372
|
+
mediaType: string;
|
373
|
+
/**
|
374
|
+
* The base64 encoded data.
|
375
|
+
*/
|
376
|
+
data: string;
|
377
|
+
};
|
378
|
+
/**
|
379
|
+
* A step boundary part of a message.
|
380
|
+
*/
|
381
|
+
type StepStartUIPart = {
|
382
|
+
type: 'step-start';
|
383
|
+
};
|
384
|
+
type CreateMessage = Omit<Message, 'id'> & {
|
385
|
+
id?: Message['id'];
|
386
|
+
};
|
387
|
+
type ChatRequest = {
|
388
|
+
/**
|
389
|
+
An optional object of headers to be passed to the API endpoint.
|
390
|
+
*/
|
391
|
+
headers?: Record<string, string> | Headers;
|
392
|
+
/**
|
393
|
+
An optional object to be passed to the API endpoint.
|
394
|
+
*/
|
395
|
+
body?: object;
|
396
|
+
/**
|
397
|
+
The messages of the chat.
|
398
|
+
*/
|
399
|
+
messages: Message[];
|
400
|
+
/**
|
401
|
+
Additional data to be sent to the server.
|
402
|
+
*/
|
403
|
+
data?: JSONValue;
|
404
|
+
};
|
405
|
+
type RequestOptions = {
|
406
|
+
/**
|
407
|
+
An optional object of headers to be passed to the API endpoint.
|
408
|
+
*/
|
409
|
+
headers?: Record<string, string> | Headers;
|
410
|
+
/**
|
411
|
+
An optional object to be passed to the API endpoint.
|
412
|
+
*/
|
413
|
+
body?: object;
|
414
|
+
};
|
415
|
+
type ChatRequestOptions = {
|
416
|
+
/**
|
417
|
+
Additional headers that should be to be passed to the API endpoint.
|
418
|
+
*/
|
419
|
+
headers?: Record<string, string> | Headers;
|
420
|
+
/**
|
421
|
+
Additional body JSON properties that should be sent to the API endpoint.
|
422
|
+
*/
|
423
|
+
body?: object;
|
424
|
+
/**
|
425
|
+
Additional data to be sent to the API endpoint.
|
426
|
+
*/
|
427
|
+
data?: JSONValue;
|
428
|
+
/**
|
429
|
+
* Additional files to be sent to the server.
|
430
|
+
*/
|
431
|
+
experimental_attachments?: FileList | Array<Attachment>;
|
432
|
+
/**
|
433
|
+
* Allow submitting an empty message. Defaults to `false`.
|
434
|
+
*/
|
435
|
+
allowEmptySubmit?: boolean;
|
436
|
+
};
|
437
|
+
type UseChatOptions = {
|
438
|
+
/**
|
439
|
+
Keeps the last message when an error happens. Defaults to `true`.
|
440
|
+
|
441
|
+
@deprecated This option will be removed in the next major release.
|
442
|
+
*/
|
443
|
+
keepLastMessageOnError?: boolean;
|
444
|
+
/**
|
445
|
+
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
446
|
+
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
447
|
+
*/
|
448
|
+
api?: string;
|
449
|
+
/**
|
450
|
+
* A unique identifier for the chat. If not provided, a random one will be
|
451
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
452
|
+
* have shared states across components.
|
453
|
+
*/
|
454
|
+
id?: string;
|
455
|
+
/**
|
456
|
+
* Initial messages of the chat. Useful to load an existing chat history.
|
457
|
+
*/
|
458
|
+
initialMessages?: Message[];
|
459
|
+
/**
|
460
|
+
* Initial input of the chat.
|
461
|
+
*/
|
462
|
+
initialInput?: string;
|
463
|
+
/**
|
464
|
+
Optional callback function that is invoked when a tool call is received.
|
465
|
+
Intended for automatic client-side tool execution.
|
466
|
+
|
467
|
+
You can optionally return a result for the tool call,
|
468
|
+
either synchronously or asynchronously.
|
469
|
+
*/
|
470
|
+
onToolCall?: ({ toolCall, }: {
|
471
|
+
toolCall: ToolCall<string, unknown>;
|
472
|
+
}) => void | Promise<unknown> | unknown;
|
473
|
+
/**
|
474
|
+
* Callback function to be called when the API response is received.
|
475
|
+
*/
|
476
|
+
onResponse?: (response: Response) => void | Promise<void>;
|
477
|
+
/**
|
478
|
+
* Optional callback function that is called when the assistant message is finished streaming.
|
479
|
+
*
|
480
|
+
* @param message The message that was streamed.
|
481
|
+
* @param options.usage The token usage of the message.
|
482
|
+
* @param options.finishReason The finish reason of the message.
|
483
|
+
*/
|
484
|
+
onFinish?: (message: Message, options: {
|
485
|
+
usage: LanguageModelUsage;
|
486
|
+
finishReason: LanguageModelV2FinishReason;
|
487
|
+
}) => void;
|
488
|
+
/**
|
489
|
+
* Callback function to be called when an error is encountered.
|
490
|
+
*/
|
491
|
+
onError?: (error: Error) => void;
|
492
|
+
/**
|
493
|
+
* A way to provide a function that is going to be used for ids for messages and the chat.
|
494
|
+
* If not provided the default AI SDK `generateId` is used.
|
495
|
+
*/
|
496
|
+
generateId?: IdGenerator;
|
497
|
+
/**
|
498
|
+
* The credentials mode to be used for the fetch request.
|
499
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
500
|
+
* Defaults to 'same-origin'.
|
501
|
+
*/
|
502
|
+
credentials?: RequestCredentials;
|
503
|
+
/**
|
504
|
+
* HTTP headers to be sent with the API request.
|
505
|
+
*/
|
506
|
+
headers?: Record<string, string> | Headers;
|
507
|
+
/**
|
508
|
+
* Extra body object to be sent with the API request.
|
509
|
+
* @example
|
510
|
+
* Send a `sessionId` to the API along with the messages.
|
511
|
+
* ```js
|
512
|
+
* useChat({
|
513
|
+
* body: {
|
514
|
+
* sessionId: '123',
|
515
|
+
* }
|
516
|
+
* })
|
517
|
+
* ```
|
518
|
+
*/
|
519
|
+
body?: object;
|
520
|
+
/**
|
521
|
+
* Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
|
522
|
+
* Defaults to `false`. When set to `true`, the API endpoint might need to
|
523
|
+
* handle the extra fields before forwarding the request to the AI service.
|
524
|
+
*/
|
525
|
+
sendExtraMessageFields?: boolean;
|
526
|
+
/**
|
527
|
+
Streaming protocol that is used. Defaults to `data`.
|
528
|
+
*/
|
529
|
+
streamProtocol?: 'data' | 'text';
|
530
|
+
/**
|
531
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
532
|
+
or to provide a custom fetch implementation for e.g. testing.
|
533
|
+
*/
|
534
|
+
fetch?: FetchFunction;
|
535
|
+
};
|
536
|
+
type UseCompletionOptions = {
|
537
|
+
/**
|
538
|
+
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
539
|
+
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
540
|
+
*/
|
541
|
+
api?: string;
|
542
|
+
/**
|
543
|
+
* An unique identifier for the chat. If not provided, a random one will be
|
544
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
545
|
+
* have shared states across components.
|
546
|
+
*/
|
547
|
+
id?: string;
|
548
|
+
/**
|
549
|
+
* Initial prompt input of the completion.
|
550
|
+
*/
|
551
|
+
initialInput?: string;
|
552
|
+
/**
|
553
|
+
* Initial completion result. Useful to load an existing history.
|
554
|
+
*/
|
555
|
+
initialCompletion?: string;
|
556
|
+
/**
|
557
|
+
* Callback function to be called when the API response is received.
|
558
|
+
*/
|
559
|
+
onResponse?: (response: Response) => void | Promise<void>;
|
560
|
+
/**
|
561
|
+
* Callback function to be called when the completion is finished streaming.
|
562
|
+
*/
|
563
|
+
onFinish?: (prompt: string, completion: string) => void;
|
564
|
+
/**
|
565
|
+
* Callback function to be called when an error is encountered.
|
566
|
+
*/
|
567
|
+
onError?: (error: Error) => void;
|
568
|
+
/**
|
569
|
+
* The credentials mode to be used for the fetch request.
|
570
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
571
|
+
* Defaults to 'same-origin'.
|
572
|
+
*/
|
573
|
+
credentials?: RequestCredentials;
|
574
|
+
/**
|
575
|
+
* HTTP headers to be sent with the API request.
|
576
|
+
*/
|
577
|
+
headers?: Record<string, string> | Headers;
|
578
|
+
/**
|
579
|
+
* Extra body object to be sent with the API request.
|
580
|
+
* @example
|
581
|
+
* Send a `sessionId` to the API along with the prompt.
|
582
|
+
* ```js
|
583
|
+
* useChat({
|
584
|
+
* body: {
|
585
|
+
* sessionId: '123',
|
586
|
+
* }
|
587
|
+
* })
|
588
|
+
* ```
|
589
|
+
*/
|
590
|
+
body?: object;
|
591
|
+
/**
|
592
|
+
Streaming protocol that is used. Defaults to `data`.
|
593
|
+
*/
|
594
|
+
streamProtocol?: 'data' | 'text';
|
595
|
+
/**
|
596
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
597
|
+
or to provide a custom fetch implementation for e.g. testing.
|
598
|
+
*/
|
599
|
+
fetch?: FetchFunction;
|
600
|
+
};
|
601
|
+
/**
|
602
|
+
A JSON value can be a string, number, boolean, object, array, or null.
|
603
|
+
JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
|
604
|
+
*/
|
605
|
+
type JSONValue = null | string | number | boolean | {
|
606
|
+
[value: string]: JSONValue;
|
607
|
+
} | Array<JSONValue>;
|
608
|
+
|
609
|
+
/**
|
610
|
+
Transcription model that is used by the AI SDK Core functions.
|
611
|
+
*/
|
612
|
+
type TranscriptionModel = TranscriptionModelV1;
|
613
|
+
/**
|
614
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
615
|
+
some settings might not be supported, which can lead to suboptimal results.
|
616
|
+
*/
|
617
|
+
type TranscriptionWarning = TranscriptionModelV1CallWarning;
|
618
|
+
|
619
|
+
type TranscriptionModelResponseMetadata = {
|
620
|
+
/**
|
621
|
+
Timestamp for the start of the generated response.
|
622
|
+
*/
|
623
|
+
timestamp: Date;
|
624
|
+
/**
|
625
|
+
The ID of the response model that was used to generate the response.
|
626
|
+
*/
|
627
|
+
modelId: string;
|
628
|
+
/**
|
629
|
+
Response headers.
|
630
|
+
*/
|
631
|
+
headers?: Record<string, string>;
|
632
|
+
};
|
633
|
+
|
634
|
+
/**
|
635
|
+
Speech model that is used by the AI SDK Core functions.
|
636
|
+
*/
|
637
|
+
type SpeechModel = SpeechModelV1;
|
638
|
+
/**
|
639
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
640
|
+
some settings might not be supported, which can lead to suboptimal results.
|
641
|
+
*/
|
642
|
+
type SpeechWarning = SpeechModelV1CallWarning;
|
643
|
+
|
644
|
+
type SpeechModelResponseMetadata = {
|
645
|
+
/**
|
646
|
+
Timestamp for the start of the generated response.
|
647
|
+
*/
|
648
|
+
timestamp: Date;
|
649
|
+
/**
|
650
|
+
The ID of the response model that was used to generate the response.
|
651
|
+
*/
|
652
|
+
modelId: string;
|
653
|
+
/**
|
654
|
+
Response headers.
|
655
|
+
*/
|
656
|
+
headers?: Record<string, string>;
|
657
|
+
/**
|
658
|
+
Response body.
|
659
|
+
*/
|
660
|
+
body?: unknown;
|
661
|
+
};
|
662
|
+
|
663
|
+
declare const getOriginalFetch$1: () => typeof fetch;
|
664
|
+
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController, restoreMessagesOnFailure, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, }: {
|
665
|
+
api: string;
|
666
|
+
body: Record<string, any>;
|
667
|
+
streamProtocol: 'data' | 'text' | undefined;
|
668
|
+
credentials: RequestCredentials | undefined;
|
669
|
+
headers: HeadersInit | undefined;
|
670
|
+
abortController: (() => AbortController | null) | undefined;
|
671
|
+
restoreMessagesOnFailure: () => void;
|
672
|
+
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
673
|
+
onUpdate: (options: {
|
674
|
+
message: UIMessage;
|
675
|
+
data: JSONValue[] | undefined;
|
676
|
+
replaceLastMessage: boolean;
|
677
|
+
}) => void;
|
678
|
+
onFinish: UseChatOptions['onFinish'];
|
679
|
+
onToolCall: UseChatOptions['onToolCall'];
|
680
|
+
generateId: IdGenerator;
|
681
|
+
fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
|
682
|
+
lastMessage: UIMessage | undefined;
|
683
|
+
}): Promise<void>;
|
684
|
+
|
685
|
+
declare const getOriginalFetch: () => typeof fetch;
|
686
|
+
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onResponse, onFinish, onError, onData, fetch, }: {
|
687
|
+
api: string;
|
688
|
+
prompt: string;
|
689
|
+
credentials: RequestCredentials | undefined;
|
690
|
+
headers: HeadersInit | undefined;
|
691
|
+
body: Record<string, any>;
|
692
|
+
streamProtocol: 'data' | 'text' | undefined;
|
693
|
+
setCompletion: (completion: string) => void;
|
694
|
+
setLoading: (loading: boolean) => void;
|
695
|
+
setError: (error: Error | undefined) => void;
|
696
|
+
setAbortController: (abortController: AbortController | null) => void;
|
697
|
+
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
698
|
+
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
699
|
+
onError: ((error: Error) => void) | undefined;
|
700
|
+
onData: ((data: JSONValue[]) => void) | undefined;
|
701
|
+
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
702
|
+
}): Promise<string | null | undefined>;
|
703
|
+
|
704
|
+
type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
|
705
|
+
interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
706
|
+
code: CODE;
|
707
|
+
name: NAME;
|
708
|
+
parse: (value: JSONValue) => {
|
709
|
+
type: NAME;
|
710
|
+
value: TYPE;
|
711
|
+
};
|
712
|
+
}
|
713
|
+
declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "args" | "toolName">>, DataStreamPart<"b", "tool_call_streaming_start", {
|
714
|
+
toolCallId: string;
|
715
|
+
toolName: string;
|
716
|
+
}>, DataStreamPart<"c", "tool_call_delta", {
|
717
|
+
toolCallId: string;
|
718
|
+
argsTextDelta: string;
|
719
|
+
}>, DataStreamPart<"d", "finish_message", {
|
720
|
+
finishReason: LanguageModelV2FinishReason;
|
721
|
+
usage?: {
|
722
|
+
promptTokens: number;
|
723
|
+
completionTokens: number;
|
724
|
+
};
|
725
|
+
}>, DataStreamPart<"e", "finish_step", {
|
726
|
+
isContinued: boolean;
|
727
|
+
finishReason: LanguageModelV2FinishReason;
|
728
|
+
usage?: {
|
729
|
+
promptTokens: number;
|
730
|
+
completionTokens: number;
|
731
|
+
};
|
732
|
+
}>, DataStreamPart<"f", "start_step", {
|
733
|
+
messageId: string;
|
734
|
+
}>, DataStreamPart<"g", "reasoning", string>, DataStreamPart<"h", "source", LanguageModelV2Source>, DataStreamPart<"i", "redacted_reasoning", {
|
735
|
+
data: string;
|
736
|
+
}>, DataStreamPart<"j", "reasoning_signature", {
|
737
|
+
signature: string;
|
738
|
+
}>, DataStreamPart<"k", "file", {
|
739
|
+
data: string;
|
740
|
+
mimeType: string;
|
741
|
+
}>];
|
742
|
+
type DataStreamParts = (typeof dataStreamParts)[number];
|
743
|
+
/**
|
744
|
+
* Maps the type of a stream part to its value type.
|
745
|
+
*/
|
746
|
+
type DataStreamPartValueType = {
|
747
|
+
[P in DataStreamParts as P['name']]: ReturnType<P['parse']>['value'];
|
748
|
+
};
|
749
|
+
type DataStreamPartType = ReturnType<DataStreamParts['parse']>;
|
750
|
+
/**
|
751
|
+
* The map of prefixes for data in the stream
|
752
|
+
*
|
753
|
+
* - 0: Text from the LLM response
|
754
|
+
* - 1: (OpenAI) function_call responses
|
755
|
+
* - 2: custom JSON added by the user using `Data`
|
756
|
+
* - 6: (OpenAI) tool_call responses
|
757
|
+
*
|
758
|
+
* Example:
|
759
|
+
* ```
|
760
|
+
* 0:Vercel
|
761
|
+
* 0:'s
|
762
|
+
* 0: AI
|
763
|
+
* 0: AI
|
764
|
+
* 0: SDK
|
765
|
+
* 0: is great
|
766
|
+
* 0:!
|
767
|
+
* 2: { "someJson": "value" }
|
768
|
+
* 1: {"function_call": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}
|
769
|
+
* 6: {"tool_call": {"id": "tool_0", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}}
|
770
|
+
*```
|
771
|
+
*/
|
772
|
+
declare const DataStreamStringPrefixes: { [K in DataStreamParts["name"]]: (typeof dataStreamParts)[number]["code"]; };
|
773
|
+
/**
|
774
|
+
Parses a stream part from a string.
|
775
|
+
|
776
|
+
@param line The string to parse.
|
777
|
+
@returns The parsed stream part.
|
778
|
+
@throws An error if the string cannot be parsed.
|
779
|
+
*/
|
780
|
+
declare const parseDataStreamPart: (line: string) => DataStreamPartType;
|
781
|
+
/**
|
782
|
+
Prepends a string with a prefix from the `StreamChunkPrefixes`, JSON-ifies it,
|
783
|
+
and appends a new line.
|
784
|
+
|
785
|
+
It ensures type-safety for the part type and value.
|
786
|
+
*/
|
787
|
+
declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
|
788
|
+
|
789
|
+
/**
|
790
|
+
* Converts a data URL of type text/* to a text string.
|
791
|
+
*/
|
792
|
+
declare function getTextFromDataUrl(dataUrl: string): string;
|
793
|
+
|
794
|
+
/**
|
795
|
+
Create a type from an object with all keys and nested keys set to optional.
|
796
|
+
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
797
|
+
It always recurses into arrays.
|
798
|
+
|
799
|
+
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
800
|
+
*/
|
801
|
+
type DeepPartial<T> = T extends z.ZodTypeAny ? DeepPartialInternal<z.infer<T>> : DeepPartialInternal<T>;
|
802
|
+
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
803
|
+
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
804
|
+
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
805
|
+
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
806
|
+
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
807
|
+
type PartialObject<ObjectType extends object> = {
|
808
|
+
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
809
|
+
};
|
810
|
+
|
811
|
+
declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
|
812
|
+
|
813
|
+
declare function fillMessageParts(messages: Message[]): UIMessage[];
|
814
|
+
|
815
|
+
declare function getMessageParts(message: Message | CreateMessage | UIMessage): (TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart)[];
|
816
|
+
|
817
|
+
/**
|
818
|
+
* Performs a deep-equal comparison of two parsed JSON objects.
|
819
|
+
*
|
820
|
+
* @param {any} obj1 - The first object to compare.
|
821
|
+
* @param {any} obj2 - The second object to compare.
|
822
|
+
* @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
|
823
|
+
*/
|
824
|
+
declare function isDeepEqualData(obj1: any, obj2: any): boolean;
|
825
|
+
|
826
|
+
declare function parsePartialJson(jsonText: string | undefined): {
|
827
|
+
value: JSONValue$1 | undefined;
|
828
|
+
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
829
|
+
};
|
830
|
+
|
831
|
+
declare function prepareAttachmentsForRequest(attachmentsFromOptions: FileList | Array<Attachment> | undefined): Promise<Attachment[]>;
|
832
|
+
|
833
|
+
declare function processDataStream({ stream, onTextPart, onReasoningPart, onReasoningSignaturePart, onRedactedReasoningPart, onSourcePart, onFilePart, onDataPart, onErrorPart, onToolCallStreamingStartPart, onToolCallDeltaPart, onToolCallPart, onToolResultPart, onMessageAnnotationsPart, onFinishMessagePart, onFinishStepPart, onStartStepPart, }: {
|
834
|
+
stream: ReadableStream<Uint8Array>;
|
835
|
+
onTextPart?: (streamPart: (DataStreamPartType & {
|
836
|
+
type: 'text';
|
837
|
+
})['value']) => Promise<void> | void;
|
838
|
+
onReasoningPart?: (streamPart: (DataStreamPartType & {
|
839
|
+
type: 'reasoning';
|
840
|
+
})['value']) => Promise<void> | void;
|
841
|
+
onReasoningSignaturePart?: (streamPart: (DataStreamPartType & {
|
842
|
+
type: 'reasoning_signature';
|
843
|
+
})['value']) => Promise<void> | void;
|
844
|
+
onRedactedReasoningPart?: (streamPart: (DataStreamPartType & {
|
845
|
+
type: 'redacted_reasoning';
|
846
|
+
})['value']) => Promise<void> | void;
|
847
|
+
onFilePart?: (streamPart: (DataStreamPartType & {
|
848
|
+
type: 'file';
|
849
|
+
})['value']) => Promise<void> | void;
|
850
|
+
onSourcePart?: (streamPart: (DataStreamPartType & {
|
851
|
+
type: 'source';
|
852
|
+
})['value']) => Promise<void> | void;
|
853
|
+
onDataPart?: (streamPart: (DataStreamPartType & {
|
854
|
+
type: 'data';
|
855
|
+
})['value']) => Promise<void> | void;
|
856
|
+
onErrorPart?: (streamPart: (DataStreamPartType & {
|
857
|
+
type: 'error';
|
858
|
+
})['value']) => Promise<void> | void;
|
859
|
+
onToolCallStreamingStartPart?: (streamPart: (DataStreamPartType & {
|
860
|
+
type: 'tool_call_streaming_start';
|
861
|
+
})['value']) => Promise<void> | void;
|
862
|
+
onToolCallDeltaPart?: (streamPart: (DataStreamPartType & {
|
863
|
+
type: 'tool_call_delta';
|
864
|
+
})['value']) => Promise<void> | void;
|
865
|
+
onToolCallPart?: (streamPart: (DataStreamPartType & {
|
866
|
+
type: 'tool_call';
|
867
|
+
})['value']) => Promise<void> | void;
|
868
|
+
onToolResultPart?: (streamPart: (DataStreamPartType & {
|
869
|
+
type: 'tool_result';
|
870
|
+
})['value']) => Promise<void> | void;
|
871
|
+
onMessageAnnotationsPart?: (streamPart: (DataStreamPartType & {
|
872
|
+
type: 'message_annotations';
|
873
|
+
})['value']) => Promise<void> | void;
|
874
|
+
onFinishMessagePart?: (streamPart: (DataStreamPartType & {
|
875
|
+
type: 'finish_message';
|
876
|
+
})['value']) => Promise<void> | void;
|
877
|
+
onFinishStepPart?: (streamPart: (DataStreamPartType & {
|
878
|
+
type: 'finish_step';
|
879
|
+
})['value']) => Promise<void> | void;
|
880
|
+
onStartStepPart?: (streamPart: (DataStreamPartType & {
|
881
|
+
type: 'start_step';
|
882
|
+
})['value']) => Promise<void> | void;
|
883
|
+
}): Promise<void>;
|
884
|
+
|
885
|
+
declare function processTextStream({ stream, onTextPart, }: {
|
886
|
+
stream: ReadableStream<Uint8Array>;
|
887
|
+
onTextPart: (chunk: string) => Promise<void> | void;
|
888
|
+
}): Promise<void>;
|
889
|
+
|
890
|
+
/**
|
891
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
892
|
+
*/
|
893
|
+
declare const schemaSymbol: unique symbol;
|
894
|
+
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
895
|
+
/**
|
896
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
897
|
+
*/
|
898
|
+
[schemaSymbol]: true;
|
899
|
+
/**
|
900
|
+
* Schema type for inference.
|
901
|
+
*/
|
902
|
+
_type: OBJECT;
|
903
|
+
/**
|
904
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
905
|
+
*/
|
906
|
+
readonly jsonSchema: JSONSchema7;
|
907
|
+
};
|
908
|
+
/**
|
909
|
+
* Create a schema using a JSON Schema.
|
910
|
+
*
|
911
|
+
* @param jsonSchema The JSON Schema for the schema.
|
912
|
+
* @param options.validate Optional. A validation function for the schema.
|
913
|
+
*/
|
914
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, { validate, }?: {
|
915
|
+
validate?: (value: unknown) => {
|
916
|
+
success: true;
|
917
|
+
value: OBJECT;
|
918
|
+
} | {
|
919
|
+
success: false;
|
920
|
+
error: Error;
|
921
|
+
};
|
922
|
+
}): Schema<OBJECT>;
|
923
|
+
declare function asSchema<OBJECT>(schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT> | undefined): Schema<OBJECT>;
|
924
|
+
|
925
|
+
declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
|
926
|
+
originalMaxToolInvocationStep: number | undefined;
|
927
|
+
originalMessageCount: number;
|
928
|
+
maxSteps: number;
|
929
|
+
messages: UIMessage[];
|
930
|
+
}): boolean;
|
931
|
+
/**
|
932
|
+
Check if the message is an assistant message with completed tool calls.
|
933
|
+
The last step of the message must have at least one tool invocation and
|
934
|
+
all tool invocations must have a result.
|
935
|
+
*/
|
936
|
+
declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
|
937
|
+
role: 'assistant';
|
938
|
+
};
|
939
|
+
|
940
|
+
/**
|
941
|
+
* Updates the result of a specific tool invocation in the last message of the given messages array.
|
942
|
+
*
|
943
|
+
* @param {object} params - The parameters object.
|
944
|
+
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
|
945
|
+
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
|
946
|
+
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
|
947
|
+
* @returns {void} This function does not return anything.
|
948
|
+
*/
|
949
|
+
declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
|
950
|
+
messages: UIMessage[];
|
951
|
+
toolCallId: string;
|
952
|
+
toolResult: unknown;
|
953
|
+
}): void;
|
954
|
+
|
955
|
+
declare function zodSchema<OBJECT>(zodSchema: z.Schema<OBJECT, z.ZodTypeDef, any>, options?: {
|
956
|
+
/**
|
957
|
+
* Enables support for references in the schema.
|
958
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
959
|
+
* However, not all language models and providers support such references.
|
960
|
+
* Defaults to `false`.
|
961
|
+
*/
|
962
|
+
useReferences?: boolean;
|
963
|
+
}): Schema<OBJECT>;
|
964
|
+
|
965
|
+
interface DataStreamWriter {
|
966
|
+
/**
|
967
|
+
* Appends a data part to the stream.
|
968
|
+
*/
|
969
|
+
write(data: DataStreamString): void;
|
970
|
+
/**
|
971
|
+
* Appends a data part to the stream.
|
972
|
+
*/
|
973
|
+
writeData(value: JSONValue$1): void;
|
974
|
+
/**
|
975
|
+
* Appends a message annotation to the stream.
|
976
|
+
*/
|
977
|
+
writeMessageAnnotation(value: JSONValue$1): void;
|
978
|
+
/**
|
979
|
+
* Appends a source part to the stream.
|
980
|
+
*/
|
981
|
+
writeSource(source: Source): void;
|
982
|
+
/**
|
983
|
+
* Merges the contents of another stream to this stream.
|
984
|
+
*/
|
985
|
+
merge(stream: ReadableStream<DataStreamString>): void;
|
986
|
+
/**
|
987
|
+
* Error handler that is used by the data stream writer.
|
988
|
+
* This is intended for forwarding when merging streams
|
989
|
+
* to prevent duplicated error masking.
|
990
|
+
*/
|
991
|
+
onError: ((error: unknown) => string) | undefined;
|
992
|
+
}
|
993
|
+
|
994
|
+
declare function createDataStream({ execute, onError, }: {
|
995
|
+
execute: (dataStream: DataStreamWriter) => Promise<void> | void;
|
996
|
+
onError?: (error: unknown) => string;
|
997
|
+
}): ReadableStream<DataStreamString>;
|
998
|
+
|
999
|
+
declare function createDataStreamResponse({ status, statusText, headers, execute, onError, }: ResponseInit & {
|
1000
|
+
execute: (dataStream: DataStreamWriter) => Promise<void> | void;
|
1001
|
+
onError?: (error: unknown) => string;
|
1002
|
+
}): Response;
|
1003
|
+
|
1004
|
+
declare function pipeDataStreamToResponse(response: ServerResponse, { status, statusText, headers, execute, onError, }: ResponseInit & {
|
1005
|
+
execute: (writer: DataStreamWriter) => Promise<void> | void;
|
1006
|
+
onError?: (error: unknown) => string;
|
1007
|
+
}): void;
|
251
1008
|
|
252
1009
|
/**
|
253
|
-
|
1010
|
+
* Telemetry configuration.
|
254
1011
|
*/
|
255
|
-
type
|
1012
|
+
type TelemetrySettings = {
|
256
1013
|
/**
|
257
|
-
|
1014
|
+
* Enable or disable telemetry. Disabled by default while experimental.
|
258
1015
|
*/
|
259
|
-
|
1016
|
+
isEnabled?: boolean;
|
260
1017
|
/**
|
261
|
-
|
262
|
-
|
263
|
-
|
1018
|
+
* Enable or disable input recording. Enabled by default.
|
1019
|
+
*
|
1020
|
+
* You might want to disable input recording to avoid recording sensitive
|
1021
|
+
* information, to reduce data transfers, or to increase performance.
|
1022
|
+
*/
|
1023
|
+
recordInputs?: boolean;
|
264
1024
|
/**
|
265
|
-
|
1025
|
+
* Enable or disable output recording. Enabled by default.
|
1026
|
+
*
|
1027
|
+
* You might want to disable output recording to avoid recording sensitive
|
1028
|
+
* information, to reduce data transfers, or to increase performance.
|
266
1029
|
*/
|
267
|
-
|
268
|
-
};
|
269
|
-
/**
|
270
|
-
Represents the number of tokens used in an embedding.
|
271
|
-
*/
|
272
|
-
type EmbeddingModelUsage = {
|
1030
|
+
recordOutputs?: boolean;
|
273
1031
|
/**
|
274
|
-
|
1032
|
+
* Identifier for this function. Used to group telemetry data by function.
|
275
1033
|
*/
|
276
|
-
|
1034
|
+
functionId?: string;
|
1035
|
+
/**
|
1036
|
+
* Additional information to include in the telemetry data.
|
1037
|
+
*/
|
1038
|
+
metadata?: Record<string, AttributeValue>;
|
1039
|
+
/**
|
1040
|
+
* A custom tracer to use for the telemetry data.
|
1041
|
+
*/
|
1042
|
+
tracer?: Tracer;
|
277
1043
|
};
|
278
1044
|
|
279
1045
|
/**
|
@@ -294,13 +1060,17 @@ interface EmbedResult<VALUE> {
|
|
294
1060
|
*/
|
295
1061
|
readonly usage: EmbeddingModelUsage;
|
296
1062
|
/**
|
297
|
-
Optional
|
1063
|
+
Optional response data.
|
298
1064
|
*/
|
299
|
-
readonly
|
1065
|
+
readonly response?: {
|
300
1066
|
/**
|
301
1067
|
Response headers.
|
302
1068
|
*/
|
303
1069
|
headers?: Record<string, string>;
|
1070
|
+
/**
|
1071
|
+
The response body.
|
1072
|
+
*/
|
1073
|
+
body?: unknown;
|
304
1074
|
};
|
305
1075
|
}
|
306
1076
|
|
@@ -316,7 +1086,7 @@ Embed a value using an embedding model. The type of the value is defined by the
|
|
316
1086
|
|
317
1087
|
@returns A result object that contains the embedding, the value, and additional information.
|
318
1088
|
*/
|
319
|
-
declare function embed<VALUE>({ model, value, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
1089
|
+
declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
320
1090
|
/**
|
321
1091
|
The embedding model to use.
|
322
1092
|
*/
|
@@ -340,6 +1110,12 @@ declare function embed<VALUE>({ model, value, maxRetries: maxRetriesArg, abortSi
|
|
340
1110
|
Only applicable for HTTP-based providers.
|
341
1111
|
*/
|
342
1112
|
headers?: Record<string, string>;
|
1113
|
+
/**
|
1114
|
+
Additional provider-specific options. They are passed through
|
1115
|
+
to the provider from the AI SDK and enable provider-specific
|
1116
|
+
functionality that can be fully encapsulated in the provider.
|
1117
|
+
*/
|
1118
|
+
providerOptions?: ProviderOptions;
|
343
1119
|
/**
|
344
1120
|
* Optional telemetry configuration (experimental).
|
345
1121
|
*/
|
@@ -363,6 +1139,19 @@ interface EmbedManyResult<VALUE> {
|
|
363
1139
|
The embedding token usage.
|
364
1140
|
*/
|
365
1141
|
readonly usage: EmbeddingModelUsage;
|
1142
|
+
/**
|
1143
|
+
Optional raw response data.
|
1144
|
+
*/
|
1145
|
+
readonly responses?: Array<{
|
1146
|
+
/**
|
1147
|
+
Response headers.
|
1148
|
+
*/
|
1149
|
+
headers?: Record<string, string>;
|
1150
|
+
/**
|
1151
|
+
The response body.
|
1152
|
+
*/
|
1153
|
+
body?: unknown;
|
1154
|
+
} | undefined>;
|
366
1155
|
}
|
367
1156
|
|
368
1157
|
/**
|
@@ -381,7 +1170,7 @@ has a limit on how many embeddings can be generated in a single call.
|
|
381
1170
|
|
382
1171
|
@returns A result object that contains the embeddings, the value, and additional information.
|
383
1172
|
*/
|
384
|
-
declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
1173
|
+
declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
385
1174
|
/**
|
386
1175
|
The embedding model to use.
|
387
1176
|
*/
|
@@ -409,22 +1198,29 @@ declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, ab
|
|
409
1198
|
* Optional telemetry configuration (experimental).
|
410
1199
|
*/
|
411
1200
|
experimental_telemetry?: TelemetrySettings;
|
1201
|
+
/**
|
1202
|
+
Additional provider-specific options. They are passed through
|
1203
|
+
to the provider from the AI SDK and enable provider-specific
|
1204
|
+
functionality that can be fully encapsulated in the provider.
|
1205
|
+
*/
|
1206
|
+
providerOptions?: ProviderOptions;
|
412
1207
|
}): Promise<EmbedManyResult<VALUE>>;
|
413
1208
|
|
414
1209
|
type CallSettings = {
|
415
1210
|
/**
|
416
1211
|
Maximum number of tokens to generate.
|
417
1212
|
*/
|
418
|
-
|
1213
|
+
maxOutputTokens?: number;
|
419
1214
|
/**
|
420
1215
|
Temperature setting. This is a number between 0 (almost no randomness) and
|
421
1216
|
1 (very random).
|
422
1217
|
|
423
1218
|
It is recommended to set either `temperature` or `topP`, but not both.
|
1219
|
+
Use `null` to use the provider's default temperature.
|
424
1220
|
|
425
1221
|
@default 0
|
426
1222
|
*/
|
427
|
-
temperature?: number;
|
1223
|
+
temperature?: number | null;
|
428
1224
|
/**
|
429
1225
|
Nucleus sampling. This is a number between 0 and 1.
|
430
1226
|
|
@@ -496,6 +1292,10 @@ type ToolResultContent = Array<{
|
|
496
1292
|
} | {
|
497
1293
|
type: 'image';
|
498
1294
|
data: string;
|
1295
|
+
mediaType?: string;
|
1296
|
+
/**
|
1297
|
+
* @deprecated Use `mediaType` instead.
|
1298
|
+
*/
|
499
1299
|
mimeType?: string;
|
500
1300
|
}>;
|
501
1301
|
|
@@ -514,10 +1314,6 @@ interface TextPart {
|
|
514
1314
|
functionality that can be fully encapsulated in the provider.
|
515
1315
|
*/
|
516
1316
|
providerOptions?: ProviderOptions;
|
517
|
-
/**
|
518
|
-
@deprecated Use `providerOptions` instead.
|
519
|
-
*/
|
520
|
-
experimental_providerMetadata?: ProviderMetadata;
|
521
1317
|
}
|
522
1318
|
/**
|
523
1319
|
Image content part of a prompt. It contains an image.
|
@@ -532,7 +1328,13 @@ interface ImagePart {
|
|
532
1328
|
*/
|
533
1329
|
image: DataContent | URL;
|
534
1330
|
/**
|
535
|
-
Optional
|
1331
|
+
Optional IANA media type of the image.
|
1332
|
+
|
1333
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1334
|
+
*/
|
1335
|
+
mediaType?: string;
|
1336
|
+
/**
|
1337
|
+
@deprecated Use `mediaType` instead.
|
536
1338
|
*/
|
537
1339
|
mimeType?: string;
|
538
1340
|
/**
|
@@ -541,10 +1343,6 @@ interface ImagePart {
|
|
541
1343
|
functionality that can be fully encapsulated in the provider.
|
542
1344
|
*/
|
543
1345
|
providerOptions?: ProviderOptions;
|
544
|
-
/**
|
545
|
-
@deprecated Use `providerOptions` instead.
|
546
|
-
*/
|
547
|
-
experimental_providerMetadata?: ProviderMetadata;
|
548
1346
|
}
|
549
1347
|
/**
|
550
1348
|
File content part of a prompt. It contains a file.
|
@@ -563,19 +1361,21 @@ interface FilePart {
|
|
563
1361
|
*/
|
564
1362
|
filename?: string;
|
565
1363
|
/**
|
566
|
-
|
1364
|
+
IANA media type of the file.
|
1365
|
+
|
1366
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
567
1367
|
*/
|
568
|
-
|
1368
|
+
mediaType: string;
|
1369
|
+
/**
|
1370
|
+
@deprecated Use `mediaType` instead.
|
1371
|
+
*/
|
1372
|
+
mimeType?: string;
|
569
1373
|
/**
|
570
1374
|
Additional provider-specific metadata. They are passed through
|
571
1375
|
to the provider from the AI SDK and enable provider-specific
|
572
1376
|
functionality that can be fully encapsulated in the provider.
|
573
1377
|
*/
|
574
1378
|
providerOptions?: ProviderOptions;
|
575
|
-
/**
|
576
|
-
@deprecated Use `providerOptions` instead.
|
577
|
-
*/
|
578
|
-
experimental_providerMetadata?: ProviderMetadata;
|
579
1379
|
}
|
580
1380
|
/**
|
581
1381
|
* Reasoning content part of a prompt. It contains a reasoning.
|
@@ -596,10 +1396,6 @@ interface ReasoningPart {
|
|
596
1396
|
functionality that can be fully encapsulated in the provider.
|
597
1397
|
*/
|
598
1398
|
providerOptions?: ProviderOptions;
|
599
|
-
/**
|
600
|
-
@deprecated Use `providerOptions` instead.
|
601
|
-
*/
|
602
|
-
experimental_providerMetadata?: ProviderMetadata;
|
603
1399
|
}
|
604
1400
|
/**
|
605
1401
|
Redacted reasoning content part of a prompt.
|
@@ -616,10 +1412,6 @@ interface RedactedReasoningPart {
|
|
616
1412
|
functionality that can be fully encapsulated in the provider.
|
617
1413
|
*/
|
618
1414
|
providerOptions?: ProviderOptions;
|
619
|
-
/**
|
620
|
-
@deprecated Use `providerOptions` instead.
|
621
|
-
*/
|
622
|
-
experimental_providerMetadata?: ProviderMetadata;
|
623
1415
|
}
|
624
1416
|
/**
|
625
1417
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
@@ -644,10 +1436,6 @@ interface ToolCallPart {
|
|
644
1436
|
functionality that can be fully encapsulated in the provider.
|
645
1437
|
*/
|
646
1438
|
providerOptions?: ProviderOptions;
|
647
|
-
/**
|
648
|
-
@deprecated Use `providerOptions` instead.
|
649
|
-
*/
|
650
|
-
experimental_providerMetadata?: ProviderMetadata;
|
651
1439
|
}
|
652
1440
|
/**
|
653
1441
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
@@ -680,10 +1468,6 @@ interface ToolResultPart {
|
|
680
1468
|
functionality that can be fully encapsulated in the provider.
|
681
1469
|
*/
|
682
1470
|
providerOptions?: ProviderOptions;
|
683
|
-
/**
|
684
|
-
@deprecated Use `providerOptions` instead.
|
685
|
-
*/
|
686
|
-
experimental_providerMetadata?: ProviderMetadata;
|
687
1471
|
}
|
688
1472
|
|
689
1473
|
/**
|
@@ -702,10 +1486,6 @@ type CoreSystemMessage = {
|
|
702
1486
|
functionality that can be fully encapsulated in the provider.
|
703
1487
|
*/
|
704
1488
|
providerOptions?: ProviderOptions;
|
705
|
-
/**
|
706
|
-
@deprecated Use `providerOptions` instead.
|
707
|
-
*/
|
708
|
-
experimental_providerMetadata?: ProviderMetadata;
|
709
1489
|
};
|
710
1490
|
declare const coreSystemMessageSchema: z.ZodType<CoreSystemMessage>;
|
711
1491
|
/**
|
@@ -720,10 +1500,6 @@ type CoreUserMessage = {
|
|
720
1500
|
functionality that can be fully encapsulated in the provider.
|
721
1501
|
*/
|
722
1502
|
providerOptions?: ProviderOptions;
|
723
|
-
/**
|
724
|
-
@deprecated Use `providerOptions` instead.
|
725
|
-
*/
|
726
|
-
experimental_providerMetadata?: ProviderMetadata;
|
727
1503
|
};
|
728
1504
|
declare const coreUserMessageSchema: z.ZodType<CoreUserMessage>;
|
729
1505
|
/**
|
@@ -742,10 +1518,6 @@ type CoreAssistantMessage = {
|
|
742
1518
|
functionality that can be fully encapsulated in the provider.
|
743
1519
|
*/
|
744
1520
|
providerOptions?: ProviderOptions;
|
745
|
-
/**
|
746
|
-
@deprecated Use `providerOptions` instead.
|
747
|
-
*/
|
748
|
-
experimental_providerMetadata?: ProviderMetadata;
|
749
1521
|
};
|
750
1522
|
declare const coreAssistantMessageSchema: z.ZodType<CoreAssistantMessage>;
|
751
1523
|
/**
|
@@ -765,10 +1537,6 @@ type CoreToolMessage = {
|
|
765
1537
|
functionality that can be fully encapsulated in the provider.
|
766
1538
|
*/
|
767
1539
|
providerOptions?: ProviderOptions;
|
768
|
-
/**
|
769
|
-
@deprecated Use `providerOptions` instead.
|
770
|
-
*/
|
771
|
-
experimental_providerMetadata?: ProviderMetadata;
|
772
1540
|
};
|
773
1541
|
declare const coreToolMessageSchema: z.ZodType<CoreToolMessage>;
|
774
1542
|
/**
|
@@ -814,12 +1582,14 @@ interface GeneratedFile {
|
|
814
1582
|
*/
|
815
1583
|
readonly uint8Array: Uint8Array;
|
816
1584
|
/**
|
817
|
-
|
1585
|
+
The IANA media type of the file.
|
1586
|
+
|
1587
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
818
1588
|
*/
|
819
|
-
readonly
|
1589
|
+
readonly mediaType: string;
|
820
1590
|
}
|
821
1591
|
|
822
|
-
type
|
1592
|
+
type Reasoning = {
|
823
1593
|
type: 'text';
|
824
1594
|
text: string;
|
825
1595
|
signature?: string;
|
@@ -828,133 +1598,6 @@ type ReasoningDetail = {
|
|
828
1598
|
data: string;
|
829
1599
|
};
|
830
1600
|
|
831
|
-
type ToolParameters = z.ZodTypeAny | Schema<any>;
|
832
|
-
type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
833
|
-
interface ToolExecutionOptions {
|
834
|
-
/**
|
835
|
-
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
836
|
-
*/
|
837
|
-
toolCallId: string;
|
838
|
-
/**
|
839
|
-
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
840
|
-
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
841
|
-
*/
|
842
|
-
messages: CoreMessage[];
|
843
|
-
/**
|
844
|
-
* An optional abort signal that indicates that the overall operation should be aborted.
|
845
|
-
*/
|
846
|
-
abortSignal?: AbortSignal;
|
847
|
-
}
|
848
|
-
/**
|
849
|
-
A tool contains the description and the schema of the input that the tool expects.
|
850
|
-
This enables the language model to generate the input.
|
851
|
-
|
852
|
-
The tool can also contain an optional execute function for the actual execution function of the tool.
|
853
|
-
*/
|
854
|
-
type Tool<PARAMETERS extends ToolParameters = any, RESULT = any> = {
|
855
|
-
/**
|
856
|
-
The schema of the input that the tool expects. The language model will use this to generate the input.
|
857
|
-
It is also used to validate the output of the language model.
|
858
|
-
Use descriptions to make the input understandable for the language model.
|
859
|
-
*/
|
860
|
-
parameters: PARAMETERS;
|
861
|
-
/**
|
862
|
-
An optional description of what the tool does.
|
863
|
-
Will be used by the language model to decide whether to use the tool.
|
864
|
-
Not used for provider-defined tools.
|
865
|
-
*/
|
866
|
-
description?: string;
|
867
|
-
/**
|
868
|
-
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
869
|
-
*/
|
870
|
-
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
871
|
-
/**
|
872
|
-
An async function that is called with the arguments from the tool call and produces a result.
|
873
|
-
If not provided, the tool will not be executed automatically.
|
874
|
-
|
875
|
-
@args is the input of the tool call.
|
876
|
-
@options.abortSignal is a signal that can be used to abort the tool call.
|
877
|
-
*/
|
878
|
-
execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
879
|
-
} & ({
|
880
|
-
/**
|
881
|
-
Function tool.
|
882
|
-
*/
|
883
|
-
type?: undefined | 'function';
|
884
|
-
} | {
|
885
|
-
/**
|
886
|
-
Provider-defined tool.
|
887
|
-
*/
|
888
|
-
type: 'provider-defined';
|
889
|
-
/**
|
890
|
-
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
891
|
-
*/
|
892
|
-
id: `${string}.${string}`;
|
893
|
-
/**
|
894
|
-
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
895
|
-
*/
|
896
|
-
args: Record<string, unknown>;
|
897
|
-
});
|
898
|
-
/**
|
899
|
-
* @deprecated Use `Tool` instead.
|
900
|
-
*/
|
901
|
-
type CoreTool<PARAMETERS extends ToolParameters = any, RESULT = any> = Tool<PARAMETERS, RESULT>;
|
902
|
-
/**
|
903
|
-
Helper function for inferring the execute args of a tool.
|
904
|
-
*/
|
905
|
-
declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
906
|
-
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
907
|
-
}): Tool<PARAMETERS, RESULT> & {
|
908
|
-
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
909
|
-
};
|
910
|
-
declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
911
|
-
execute?: undefined;
|
912
|
-
}): Tool<PARAMETERS, RESULT> & {
|
913
|
-
execute: undefined;
|
914
|
-
};
|
915
|
-
|
916
|
-
/**
|
917
|
-
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
918
|
-
|
919
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
920
|
-
|
921
|
-
@example
|
922
|
-
```
|
923
|
-
// data.json
|
924
|
-
{
|
925
|
-
'foo': 1,
|
926
|
-
'bar': 2,
|
927
|
-
'biz': 3
|
928
|
-
}
|
929
|
-
|
930
|
-
// main.ts
|
931
|
-
import type {ValueOf} from 'type-fest';
|
932
|
-
import data = require('./data.json');
|
933
|
-
|
934
|
-
export function getData(name: string): ValueOf<typeof data> {
|
935
|
-
return data[name];
|
936
|
-
}
|
937
|
-
|
938
|
-
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
939
|
-
return data[name];
|
940
|
-
}
|
941
|
-
|
942
|
-
// file.ts
|
943
|
-
import {getData, onlyBar} from './main';
|
944
|
-
|
945
|
-
getData('foo');
|
946
|
-
//=> 1
|
947
|
-
|
948
|
-
onlyBar('foo');
|
949
|
-
//=> TypeError ...
|
950
|
-
|
951
|
-
onlyBar('bar');
|
952
|
-
//=> 2
|
953
|
-
```
|
954
|
-
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
955
|
-
*/
|
956
|
-
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
957
|
-
|
958
1601
|
declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<{
|
959
1602
|
jsonrpc: z.ZodLiteral<"2.0">;
|
960
1603
|
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
@@ -1218,25 +1861,99 @@ type MCPTransportConfig = {
|
|
1218
1861
|
*/
|
1219
1862
|
url: string;
|
1220
1863
|
/**
|
1221
|
-
* Additional HTTP headers to be sent with requests.
|
1222
|
-
*/
|
1223
|
-
headers?: Record<string, string>;
|
1224
|
-
};
|
1864
|
+
* Additional HTTP headers to be sent with requests.
|
1865
|
+
*/
|
1866
|
+
headers?: Record<string, string>;
|
1867
|
+
};
|
1868
|
+
|
1869
|
+
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
1870
|
+
interface ToolExecutionOptions {
|
1871
|
+
/**
|
1872
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
1873
|
+
*/
|
1874
|
+
toolCallId: string;
|
1875
|
+
/**
|
1876
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
1877
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
1878
|
+
*/
|
1879
|
+
messages: CoreMessage[];
|
1880
|
+
/**
|
1881
|
+
* An optional abort signal that indicates that the overall operation should be aborted.
|
1882
|
+
*/
|
1883
|
+
abortSignal?: AbortSignal;
|
1884
|
+
}
|
1885
|
+
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
1886
|
+
/**
|
1887
|
+
A tool contains the description and the schema of the input that the tool expects.
|
1888
|
+
This enables the language model to generate the input.
|
1889
|
+
|
1890
|
+
The tool can also contain an optional execute function for the actual execution function of the tool.
|
1891
|
+
*/
|
1892
|
+
type Tool<PARAMETERS extends JSONValue$1 | unknown | never = any, RESULT = any> = {
|
1893
|
+
/**
|
1894
|
+
An optional description of what the tool does.
|
1895
|
+
Will be used by the language model to decide whether to use the tool.
|
1896
|
+
Not used for provider-defined tools.
|
1897
|
+
*/
|
1898
|
+
description?: string;
|
1899
|
+
} & NeverOptional<PARAMETERS, {
|
1900
|
+
/**
|
1901
|
+
The schema of the input that the tool expects. The language model will use this to generate the input.
|
1902
|
+
It is also used to validate the output of the language model.
|
1903
|
+
Use descriptions to make the input understandable for the language model.
|
1904
|
+
*/
|
1905
|
+
parameters: ToolParameters<PARAMETERS>;
|
1906
|
+
}> & NeverOptional<RESULT, {
|
1907
|
+
/**
|
1908
|
+
An async function that is called with the arguments from the tool call and produces a result.
|
1909
|
+
If not provided, the tool will not be executed automatically.
|
1910
|
+
|
1911
|
+
@args is the input of the tool call.
|
1912
|
+
@options.abortSignal is a signal that can be used to abort the tool call.
|
1913
|
+
*/
|
1914
|
+
execute: (args: [PARAMETERS] extends [never] ? undefined : PARAMETERS, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1915
|
+
/**
|
1916
|
+
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
1917
|
+
*/
|
1918
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
1919
|
+
}> & ({
|
1920
|
+
/**
|
1921
|
+
Function tool.
|
1922
|
+
*/
|
1923
|
+
type?: undefined | 'function';
|
1924
|
+
} | {
|
1925
|
+
/**
|
1926
|
+
Provider-defined tool.
|
1927
|
+
*/
|
1928
|
+
type: 'provider-defined';
|
1929
|
+
/**
|
1930
|
+
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
1931
|
+
*/
|
1932
|
+
id: `${string}.${string}`;
|
1933
|
+
/**
|
1934
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
1935
|
+
*/
|
1936
|
+
args: Record<string, unknown>;
|
1937
|
+
});
|
1938
|
+
/**
|
1939
|
+
Helper function for inferring the execute args of a tool.
|
1940
|
+
*/
|
1941
|
+
declare function tool(tool: Tool<never, never>): Tool<never, never>;
|
1942
|
+
declare function tool<PARAMETERS>(tool: Tool<PARAMETERS, never>): Tool<PARAMETERS, never>;
|
1943
|
+
declare function tool<RESULT>(tool: Tool<never, RESULT>): Tool<never, RESULT>;
|
1944
|
+
declare function tool<PARAMETERS, RESULT>(tool: Tool<PARAMETERS, RESULT>): Tool<PARAMETERS, RESULT>;
|
1945
|
+
type MappedTool<T extends Tool | JSONObject, RESULT extends any> = T extends Tool<infer P> ? Tool<P, RESULT> : T extends JSONObject ? Tool<T, RESULT> : never;
|
1225
1946
|
|
1226
1947
|
type ToolSchemas = Record<string, {
|
1227
|
-
parameters: ToolParameters
|
1948
|
+
parameters: ToolParameters<JSONObject | unknown>;
|
1228
1949
|
}> | 'automatic' | undefined;
|
1229
1950
|
type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
|
1230
|
-
parameters: ToolParameters
|
1951
|
+
parameters: ToolParameters<any>;
|
1231
1952
|
}> ? {
|
1232
|
-
[K in keyof TOOL_SCHEMAS]:
|
1233
|
-
|
1234
|
-
|
1235
|
-
}
|
1236
|
-
[k: string]: Tool<z.ZodUnknown, CallToolResult> & {
|
1237
|
-
execute: (args: unknown, options: ToolExecutionOptions) => PromiseLike<CallToolResult>;
|
1238
|
-
};
|
1239
|
-
};
|
1953
|
+
[K in keyof TOOL_SCHEMAS]: MappedTool<TOOL_SCHEMAS[K], CallToolResult> & Required<Pick<MappedTool<TOOL_SCHEMAS[K], CallToolResult>, 'execute'>>;
|
1954
|
+
} : McpToolSet<Record<string, {
|
1955
|
+
parameters: ToolParameters<unknown>;
|
1956
|
+
}>>;
|
1240
1957
|
declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
1241
1958
|
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1242
1959
|
}, {
|
@@ -2000,27 +2717,60 @@ declare class MCPClient {
|
|
2000
2717
|
private onResponse;
|
2001
2718
|
}
|
2002
2719
|
|
2003
|
-
|
2720
|
+
/**
|
2721
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
2722
|
+
|
2723
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
2724
|
+
|
2725
|
+
@example
|
2726
|
+
```
|
2727
|
+
// data.json
|
2728
|
+
{
|
2729
|
+
'foo': 1,
|
2730
|
+
'bar': 2,
|
2731
|
+
'biz': 3
|
2732
|
+
}
|
2733
|
+
|
2734
|
+
// main.ts
|
2735
|
+
import type {ValueOf} from 'type-fest';
|
2736
|
+
import data = require('./data.json');
|
2737
|
+
|
2738
|
+
export function getData(name: string): ValueOf<typeof data> {
|
2739
|
+
return data[name];
|
2740
|
+
}
|
2741
|
+
|
2742
|
+
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
2743
|
+
return data[name];
|
2744
|
+
}
|
2745
|
+
|
2746
|
+
// file.ts
|
2747
|
+
import {getData, onlyBar} from './main';
|
2748
|
+
|
2749
|
+
getData('foo');
|
2750
|
+
//=> 1
|
2751
|
+
|
2752
|
+
onlyBar('foo');
|
2753
|
+
//=> TypeError ...
|
2754
|
+
|
2755
|
+
onlyBar('bar');
|
2756
|
+
//=> 2
|
2757
|
+
```
|
2758
|
+
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
2759
|
+
*/
|
2760
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
2761
|
+
|
2762
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute'>>;
|
2004
2763
|
|
2005
2764
|
type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
2006
2765
|
[NAME in keyof TOOLS]: {
|
2007
2766
|
type: 'tool-call';
|
2008
2767
|
toolCallId: string;
|
2009
2768
|
toolName: NAME & string;
|
2010
|
-
args:
|
2769
|
+
args: TOOLS[NAME] extends Tool<infer PARAMETERS> ? PARAMETERS : never;
|
2011
2770
|
};
|
2012
2771
|
}>;
|
2013
|
-
/**
|
2014
|
-
* @deprecated Use `ToolCallUnion` instead.
|
2015
|
-
*/
|
2016
|
-
type CoreToolCallUnion<TOOLS extends ToolSet> = ToolCallUnion<ToolSet>;
|
2017
2772
|
type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
|
2018
2773
|
|
2019
|
-
type ToToolsWithExecute<TOOLS extends ToolSet> = {
|
2020
|
-
[K in keyof TOOLS as TOOLS[K] extends {
|
2021
|
-
execute: any;
|
2022
|
-
} ? K : never]: TOOLS[K];
|
2023
|
-
};
|
2024
2774
|
type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
|
2025
2775
|
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
2026
2776
|
};
|
@@ -2029,15 +2779,11 @@ type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
|
2029
2779
|
type: 'tool-result';
|
2030
2780
|
toolCallId: string;
|
2031
2781
|
toolName: NAME & string;
|
2032
|
-
args:
|
2782
|
+
args: TOOLS[NAME] extends Tool<infer P> ? P : never;
|
2033
2783
|
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
2034
2784
|
};
|
2035
2785
|
}>;
|
2036
|
-
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<
|
2037
|
-
/**
|
2038
|
-
* @deprecated Use `ToolResultUnion` instead.
|
2039
|
-
*/
|
2040
|
-
type CoreToolResultUnion<TOOLS extends ToolSet> = ToolResultUnion<TOOLS>;
|
2786
|
+
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<TOOLS>>;
|
2041
2787
|
type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
2042
2788
|
|
2043
2789
|
/**
|
@@ -2061,8 +2807,11 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
2061
2807
|
/**
|
2062
2808
|
The reasoning that was generated during the generation.
|
2063
2809
|
*/
|
2064
|
-
readonly reasoning:
|
2065
|
-
|
2810
|
+
readonly reasoning: Array<Reasoning>;
|
2811
|
+
/**
|
2812
|
+
The reasoning text that was generated during the generation.
|
2813
|
+
*/
|
2814
|
+
readonly reasoningText: string | undefined;
|
2066
2815
|
/**
|
2067
2816
|
The files that were generated during the generation.
|
2068
2817
|
*/
|
@@ -2086,7 +2835,7 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
2086
2835
|
/**
|
2087
2836
|
The token usage of the generated text.
|
2088
2837
|
*/
|
2089
|
-
readonly usage: LanguageModelUsage;
|
2838
|
+
readonly usage: LanguageModelUsage$1;
|
2090
2839
|
/**
|
2091
2840
|
Warnings from the model provider (e.g. unsupported settings).
|
2092
2841
|
*/
|
@@ -2122,10 +2871,6 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
2122
2871
|
*/
|
2123
2872
|
readonly providerMetadata: ProviderMetadata | undefined;
|
2124
2873
|
/**
|
2125
|
-
@deprecated Use `providerMetadata` instead.
|
2126
|
-
*/
|
2127
|
-
readonly experimental_providerMetadata: ProviderMetadata | undefined;
|
2128
|
-
/**
|
2129
2874
|
The type of step that this result is for. The first step is always
|
2130
2875
|
an "initial" step, and subsequent steps are either "continue" steps
|
2131
2876
|
or "tool-result" steps.
|
@@ -2147,19 +2892,19 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
|
2147
2892
|
*/
|
2148
2893
|
readonly text: string;
|
2149
2894
|
/**
|
2895
|
+
The full reasoning that the model has generated.
|
2896
|
+
*/
|
2897
|
+
readonly reasoning: Array<Reasoning>;
|
2898
|
+
/**
|
2150
2899
|
The reasoning text that the model has generated. Can be undefined if the model
|
2151
2900
|
has only generated text.
|
2152
2901
|
*/
|
2153
|
-
readonly
|
2902
|
+
readonly reasoningText: string | undefined;
|
2154
2903
|
/**
|
2155
2904
|
The files that were generated. Empty array if no files were generated.
|
2156
2905
|
*/
|
2157
2906
|
readonly files: Array<GeneratedFile>;
|
2158
2907
|
/**
|
2159
|
-
The full reasoning that the model has generated.
|
2160
|
-
*/
|
2161
|
-
readonly reasoningDetails: Array<ReasoningDetail>;
|
2162
|
-
/**
|
2163
2908
|
Sources that have been used as input to generate the response.
|
2164
2909
|
For multi-step generation, the sources are accumulated from all steps.
|
2165
2910
|
*/
|
@@ -2183,7 +2928,7 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
|
2183
2928
|
/**
|
2184
2929
|
The token usage of the generated text.
|
2185
2930
|
*/
|
2186
|
-
readonly usage: LanguageModelUsage;
|
2931
|
+
readonly usage: LanguageModelUsage$1;
|
2187
2932
|
/**
|
2188
2933
|
Warnings from the model provider (e.g. unsupported settings)
|
2189
2934
|
*/
|
@@ -2229,21 +2974,11 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
|
2229
2974
|
results that can be fully encapsulated in the provider.
|
2230
2975
|
*/
|
2231
2976
|
readonly providerMetadata: ProviderMetadata | undefined;
|
2232
|
-
/**
|
2233
|
-
@deprecated Use `providerMetadata` instead.
|
2234
|
-
*/
|
2235
|
-
readonly experimental_providerMetadata: ProviderMetadata | undefined;
|
2236
2977
|
}
|
2237
2978
|
|
2238
|
-
interface Output<OUTPUT, PARTIAL> {
|
2979
|
+
interface Output$1<OUTPUT, PARTIAL> {
|
2239
2980
|
readonly type: 'object' | 'text';
|
2240
|
-
|
2241
|
-
system: string | undefined;
|
2242
|
-
model: LanguageModel;
|
2243
|
-
}): string | undefined;
|
2244
|
-
responseFormat: (options: {
|
2245
|
-
model: LanguageModel;
|
2246
|
-
}) => LanguageModelV2CallOptions['responseFormat'];
|
2981
|
+
responseFormat: LanguageModelV2CallOptions['responseFormat'];
|
2247
2982
|
parsePartial(options: {
|
2248
2983
|
text: string;
|
2249
2984
|
}): {
|
@@ -2253,21 +2988,20 @@ interface Output<OUTPUT, PARTIAL> {
|
|
2253
2988
|
text: string;
|
2254
2989
|
}, context: {
|
2255
2990
|
response: LanguageModelResponseMetadata;
|
2256
|
-
usage: LanguageModelUsage;
|
2991
|
+
usage: LanguageModelUsage$1;
|
2257
2992
|
finishReason: FinishReason;
|
2258
2993
|
}): OUTPUT;
|
2259
2994
|
}
|
2260
|
-
declare const text: () => Output<string, string>;
|
2995
|
+
declare const text: () => Output$1<string, string>;
|
2261
2996
|
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
2262
2997
|
schema: z.Schema<OUTPUT, z.ZodTypeDef, any> | Schema<OUTPUT>;
|
2263
|
-
}) => Output<OUTPUT, DeepPartial<OUTPUT>>;
|
2998
|
+
}) => Output$1<OUTPUT, DeepPartial<OUTPUT>>;
|
2264
2999
|
|
2265
|
-
type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
|
2266
3000
|
declare const output_object: typeof object;
|
2267
3001
|
declare const output_text: typeof text;
|
2268
3002
|
declare namespace output {
|
2269
3003
|
export {
|
2270
|
-
|
3004
|
+
Output$1 as Output,
|
2271
3005
|
output_object as object,
|
2272
3006
|
output_text as text,
|
2273
3007
|
};
|
@@ -2352,13 +3086,13 @@ declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages:
|
|
2352
3086
|
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
2353
3087
|
system: string | undefined;
|
2354
3088
|
messages: CoreMessage[];
|
2355
|
-
toolCall:
|
3089
|
+
toolCall: LanguageModelV2ToolCall;
|
2356
3090
|
tools: TOOLS;
|
2357
3091
|
parameterSchema: (options: {
|
2358
3092
|
toolName: string;
|
2359
|
-
}) => JSONSchema7;
|
3093
|
+
}) => JSONSchema7$1;
|
2360
3094
|
error: NoSuchToolError | InvalidToolArgumentsError;
|
2361
|
-
}) => Promise<
|
3095
|
+
}) => Promise<LanguageModelV2ToolCall | null>;
|
2362
3096
|
|
2363
3097
|
/**
|
2364
3098
|
Callback that is set using the `onStepFinish` option.
|
@@ -2380,7 +3114,7 @@ This function does not stream the output. If you want to stream the output, use
|
|
2380
3114
|
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
2381
3115
|
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
2382
3116
|
|
2383
|
-
@param
|
3117
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
2384
3118
|
@param temperature - Temperature setting.
|
2385
3119
|
The value is passed through to the provider. The range depends on the provider and model.
|
2386
3120
|
It is recommended to set either `temperature` or `topP`, but not both.
|
@@ -2413,7 +3147,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
2413
3147
|
@returns
|
2414
3148
|
A result object that contains the generated text, the results of the tool calls, and additional information.
|
2415
3149
|
*/
|
2416
|
-
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry,
|
3150
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, providerOptions, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
|
2417
3151
|
/**
|
2418
3152
|
The language model to use.
|
2419
3153
|
*/
|
@@ -2455,10 +3189,6 @@ functionality that can be fully encapsulated in the provider.
|
|
2455
3189
|
*/
|
2456
3190
|
providerOptions?: ProviderOptions;
|
2457
3191
|
/**
|
2458
|
-
@deprecated Use `providerOptions` instead.
|
2459
|
-
*/
|
2460
|
-
experimental_providerMetadata?: ProviderMetadata;
|
2461
|
-
/**
|
2462
3192
|
Limits the tools that are available for the model to call without
|
2463
3193
|
changing the tool call and result types in the result.
|
2464
3194
|
*/
|
@@ -2466,7 +3196,7 @@ changing the tool call and result types in the result.
|
|
2466
3196
|
/**
|
2467
3197
|
Optional specification for parsing structured outputs from the LLM response.
|
2468
3198
|
*/
|
2469
|
-
experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
|
3199
|
+
experimental_output?: Output$1<OUTPUT, OUTPUT_PARTIAL>;
|
2470
3200
|
/**
|
2471
3201
|
A function that attempts to repair a tool call that failed to parse.
|
2472
3202
|
*/
|
@@ -2497,8 +3227,8 @@ declare class StreamData {
|
|
2497
3227
|
private warningTimeout;
|
2498
3228
|
constructor();
|
2499
3229
|
close(): Promise<void>;
|
2500
|
-
append(value: JSONValue
|
2501
|
-
appendMessageAnnotation(value: JSONValue
|
3230
|
+
append(value: JSONValue): void;
|
3231
|
+
appendMessageAnnotation(value: JSONValue): void;
|
2502
3232
|
}
|
2503
3233
|
|
2504
3234
|
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
@@ -2539,6 +3269,9 @@ type DataStreamOptions = {
|
|
2539
3269
|
*/
|
2540
3270
|
experimental_sendStart?: boolean;
|
2541
3271
|
};
|
3272
|
+
type ConsumeStreamOptions = {
|
3273
|
+
onError?: (error: unknown) => void;
|
3274
|
+
};
|
2542
3275
|
/**
|
2543
3276
|
A result object for accessing different stream types and additional information.
|
2544
3277
|
*/
|
@@ -2553,7 +3286,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
2553
3286
|
|
2554
3287
|
Resolved when the response is finished.
|
2555
3288
|
*/
|
2556
|
-
readonly usage: Promise<LanguageModelUsage>;
|
3289
|
+
readonly usage: Promise<LanguageModelUsage$1>;
|
2557
3290
|
/**
|
2558
3291
|
Sources that have been used as input to generate the response.
|
2559
3292
|
For multi-step generation, the sources are accumulated from all steps.
|
@@ -2580,27 +3313,23 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
2580
3313
|
*/
|
2581
3314
|
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
2582
3315
|
/**
|
2583
|
-
@deprecated Use `providerMetadata` instead.
|
2584
|
-
*/
|
2585
|
-
readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
|
2586
|
-
/**
|
2587
3316
|
The full text that has been generated by the last step.
|
2588
3317
|
|
2589
3318
|
Resolved when the response is finished.
|
2590
3319
|
*/
|
2591
3320
|
readonly text: Promise<string>;
|
2592
3321
|
/**
|
2593
|
-
The reasoning that has
|
3322
|
+
The full reasoning that the model has generated.
|
2594
3323
|
|
2595
3324
|
Resolved when the response is finished.
|
2596
|
-
|
2597
|
-
readonly reasoning: Promise<
|
3325
|
+
*/
|
3326
|
+
readonly reasoning: Promise<Array<Reasoning>>;
|
2598
3327
|
/**
|
2599
|
-
The
|
3328
|
+
The reasoning that has been generated by the last step.
|
2600
3329
|
|
2601
3330
|
Resolved when the response is finished.
|
2602
|
-
|
2603
|
-
readonly
|
3331
|
+
*/
|
3332
|
+
readonly reasoningText: Promise<string | undefined>;
|
2604
3333
|
/**
|
2605
3334
|
The tool calls that have been executed in the last step.
|
2606
3335
|
|
@@ -2659,8 +3388,10 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
2659
3388
|
This is useful to force the stream to finish.
|
2660
3389
|
It effectively removes the backpressure and allows the stream to finish,
|
2661
3390
|
triggering the `onFinish` callback and the promise resolution.
|
3391
|
+
|
3392
|
+
If an error occurs, it is passed to the optional `onError` callback.
|
2662
3393
|
*/
|
2663
|
-
consumeStream(): Promise<void>;
|
3394
|
+
consumeStream(options?: ConsumeStreamOptions): Promise<void>;
|
2664
3395
|
/**
|
2665
3396
|
Converts the result to a data stream.
|
2666
3397
|
|
@@ -2735,23 +3466,26 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
2735
3466
|
toTextStreamResponse(init?: ResponseInit): Response;
|
2736
3467
|
}
|
2737
3468
|
type TextStreamPart<TOOLS extends ToolSet> = {
|
2738
|
-
type: 'text
|
2739
|
-
|
3469
|
+
type: 'text';
|
3470
|
+
text: string;
|
2740
3471
|
} | {
|
2741
3472
|
type: 'reasoning';
|
2742
|
-
|
3473
|
+
reasoningType: 'text';
|
3474
|
+
text: string;
|
2743
3475
|
} | {
|
2744
|
-
type: 'reasoning
|
3476
|
+
type: 'reasoning';
|
3477
|
+
reasoningType: 'signature';
|
2745
3478
|
signature: string;
|
2746
3479
|
} | {
|
2747
|
-
type: '
|
3480
|
+
type: 'reasoning';
|
3481
|
+
reasoningType: 'redacted';
|
2748
3482
|
data: string;
|
2749
|
-
} | {
|
2750
|
-
type: 'source';
|
2751
|
-
source: Source;
|
2752
3483
|
} | ({
|
3484
|
+
type: 'source';
|
3485
|
+
} & Source) | {
|
2753
3486
|
type: 'file';
|
2754
|
-
|
3487
|
+
file: GeneratedFile;
|
3488
|
+
} | ({
|
2755
3489
|
type: 'tool-call';
|
2756
3490
|
} & ToolCallUnion<TOOLS>) | {
|
2757
3491
|
type: 'tool-call-streaming-start';
|
@@ -2776,23 +3510,15 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
2776
3510
|
request: LanguageModelRequestMetadata;
|
2777
3511
|
warnings: CallWarning[] | undefined;
|
2778
3512
|
response: LanguageModelResponseMetadata;
|
2779
|
-
usage: LanguageModelUsage;
|
3513
|
+
usage: LanguageModelUsage$1;
|
2780
3514
|
finishReason: FinishReason;
|
2781
3515
|
providerMetadata: ProviderMetadata | undefined;
|
2782
|
-
/**
|
2783
|
-
* @deprecated Use `providerMetadata` instead.
|
2784
|
-
*/
|
2785
|
-
experimental_providerMetadata?: ProviderMetadata;
|
2786
3516
|
isContinued: boolean;
|
2787
3517
|
} | {
|
2788
3518
|
type: 'finish';
|
2789
3519
|
finishReason: FinishReason;
|
2790
|
-
usage: LanguageModelUsage;
|
3520
|
+
usage: LanguageModelUsage$1;
|
2791
3521
|
providerMetadata: ProviderMetadata | undefined;
|
2792
|
-
/**
|
2793
|
-
* @deprecated Use `providerMetadata` instead.
|
2794
|
-
*/
|
2795
|
-
experimental_providerMetadata?: ProviderMetadata;
|
2796
3522
|
/**
|
2797
3523
|
* @deprecated will be moved into provider metadata
|
2798
3524
|
*/
|
@@ -2866,7 +3592,7 @@ Callback that is set using the `onChunk` option.
|
|
2866
3592
|
*/
|
2867
3593
|
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
2868
3594
|
chunk: Extract<TextStreamPart<TOOLS>, {
|
2869
|
-
type: 'text
|
3595
|
+
type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
|
2870
3596
|
}>;
|
2871
3597
|
}) => Promise<void> | void;
|
2872
3598
|
/**
|
@@ -2892,7 +3618,7 @@ This function streams the output. If you do not want to stream the output, use `
|
|
2892
3618
|
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
2893
3619
|
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
2894
3620
|
|
2895
|
-
@param
|
3621
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
2896
3622
|
@param temperature - Temperature setting.
|
2897
3623
|
The value is passed through to the provider. The range depends on the provider and model.
|
2898
3624
|
It is recommended to set either `temperature` or `topP`, but not both.
|
@@ -2929,7 +3655,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
2929
3655
|
@return
|
2930
3656
|
A result object for accessing different stream types and additional information.
|
2931
3657
|
*/
|
2932
|
-
declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry,
|
3658
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
2933
3659
|
/**
|
2934
3660
|
The language model to use.
|
2935
3661
|
*/
|
@@ -2971,10 +3697,6 @@ functionality that can be fully encapsulated in the provider.
|
|
2971
3697
|
*/
|
2972
3698
|
providerOptions?: ProviderOptions;
|
2973
3699
|
/**
|
2974
|
-
@deprecated Use `providerOptions` instead.
|
2975
|
-
*/
|
2976
|
-
experimental_providerMetadata?: ProviderMetadata;
|
2977
|
-
/**
|
2978
3700
|
Limits the tools that are available for the model to call without
|
2979
3701
|
changing the tool call and result types in the result.
|
2980
3702
|
*/
|
@@ -2982,7 +3704,7 @@ changing the tool call and result types in the result.
|
|
2982
3704
|
/**
|
2983
3705
|
Optional specification for parsing structured outputs from the LLM response.
|
2984
3706
|
*/
|
2985
|
-
experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
|
3707
|
+
experimental_output?: Output$1<OUTPUT, PARTIAL_OUTPUT>;
|
2986
3708
|
/**
|
2987
3709
|
A function that attempts to repair a tool call that failed to parse.
|
2988
3710
|
*/
|
@@ -3112,7 +3834,7 @@ declare function generateImage({ model, prompt, n, size, aspectRatio, seed, prov
|
|
3112
3834
|
}
|
3113
3835
|
```
|
3114
3836
|
*/
|
3115
|
-
providerOptions?: Record<string, Record<string, JSONValue>>;
|
3837
|
+
providerOptions?: Record<string, Record<string, JSONValue$1>>;
|
3116
3838
|
/**
|
3117
3839
|
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
3118
3840
|
|
@@ -3145,7 +3867,7 @@ interface GenerateObjectResult<OBJECT> {
|
|
3145
3867
|
/**
|
3146
3868
|
The token usage of the generated text.
|
3147
3869
|
*/
|
3148
|
-
readonly usage: LanguageModelUsage;
|
3870
|
+
readonly usage: LanguageModelUsage$1;
|
3149
3871
|
/**
|
3150
3872
|
Warnings from the model provider (e.g. unsupported settings).
|
3151
3873
|
*/
|
@@ -3177,186 +3899,54 @@ interface GenerateObjectResult<OBJECT> {
|
|
3177
3899
|
*/
|
3178
3900
|
readonly providerMetadata: ProviderMetadata | undefined;
|
3179
3901
|
/**
|
3180
|
-
|
3181
|
-
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
3185
|
-
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
A function that attempts to repair the raw output of the mode
|
3192
|
-
to enable JSON parsing.
|
3193
|
-
|
3194
|
-
Should return the repaired text or null if the text cannot be repaired.
|
3195
|
-
*/
|
3196
|
-
type RepairTextFunction = (options: {
|
3197
|
-
text: string;
|
3198
|
-
error: JSONParseError | TypeValidationError;
|
3199
|
-
}) => Promise<string | null>;
|
3200
|
-
/**
|
3201
|
-
Generate a structured, typed object for a given prompt and schema using a language model.
|
3202
|
-
|
3203
|
-
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
3204
|
-
|
3205
|
-
@returns
|
3206
|
-
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
3207
|
-
*/
|
3208
|
-
declare function generateObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3209
|
-
output?: 'object' | undefined;
|
3210
|
-
/**
|
3211
|
-
The language model to use.
|
3212
|
-
*/
|
3213
|
-
model: LanguageModel;
|
3214
|
-
/**
|
3215
|
-
The schema of the object that the model should generate.
|
3216
|
-
*/
|
3217
|
-
schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
|
3218
|
-
/**
|
3219
|
-
Optional name of the output that should be generated.
|
3220
|
-
Used by some providers for additional LLM guidance, e.g.
|
3221
|
-
via tool or schema name.
|
3222
|
-
*/
|
3223
|
-
schemaName?: string;
|
3224
|
-
/**
|
3225
|
-
Optional description of the output that should be generated.
|
3226
|
-
Used by some providers for additional LLM guidance, e.g.
|
3227
|
-
via tool or schema description.
|
3228
|
-
*/
|
3229
|
-
schemaDescription?: string;
|
3230
|
-
/**
|
3231
|
-
The mode to use for object generation.
|
3232
|
-
|
3233
|
-
The schema is converted into a JSON schema and used in one of the following ways
|
3234
|
-
|
3235
|
-
- 'auto': The provider will choose the best mode for the model.
|
3236
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3237
|
-
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3238
|
-
|
3239
|
-
Please note that most providers do not support all modes.
|
3240
|
-
|
3241
|
-
Default and recommended: 'auto' (best mode for the model).
|
3242
|
-
*/
|
3243
|
-
mode?: 'auto' | 'json' | 'tool';
|
3244
|
-
/**
|
3245
|
-
A function that attempts to repair the raw output of the mode
|
3246
|
-
to enable JSON parsing.
|
3247
|
-
*/
|
3248
|
-
experimental_repairText?: RepairTextFunction;
|
3249
|
-
/**
|
3250
|
-
Optional telemetry configuration (experimental).
|
3251
|
-
*/
|
3252
|
-
experimental_telemetry?: TelemetrySettings;
|
3253
|
-
/**
|
3254
|
-
Additional provider-specific options. They are passed through
|
3255
|
-
to the provider from the AI SDK and enable provider-specific
|
3256
|
-
functionality that can be fully encapsulated in the provider.
|
3257
|
-
*/
|
3258
|
-
providerOptions?: ProviderOptions;
|
3259
|
-
/**
|
3260
|
-
@deprecated Use `providerOptions` instead.
|
3261
|
-
*/
|
3262
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3263
|
-
/**
|
3264
|
-
* Internal. For test use only. May change without notice.
|
3265
|
-
*/
|
3266
|
-
_internal?: {
|
3267
|
-
generateId?: () => string;
|
3268
|
-
currentDate?: () => Date;
|
3269
|
-
};
|
3270
|
-
}): Promise<GenerateObjectResult<OBJECT>>;
|
3271
|
-
/**
|
3272
|
-
Generate an array with structured, typed elements for a given prompt and element schema using a language model.
|
3273
|
-
|
3274
|
-
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
3275
|
-
|
3276
|
-
@return
|
3277
|
-
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
3278
|
-
*/
|
3279
|
-
declare function generateObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3280
|
-
output: 'array';
|
3281
|
-
/**
|
3282
|
-
The language model to use.
|
3283
|
-
*/
|
3284
|
-
model: LanguageModel;
|
3285
|
-
/**
|
3286
|
-
The element schema of the array that the model should generate.
|
3287
|
-
*/
|
3288
|
-
schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
|
3289
|
-
/**
|
3290
|
-
Optional name of the array that should be generated.
|
3291
|
-
Used by some providers for additional LLM guidance, e.g.
|
3292
|
-
via tool or schema name.
|
3293
|
-
*/
|
3294
|
-
schemaName?: string;
|
3295
|
-
/**
|
3296
|
-
Optional description of the array that should be generated.
|
3297
|
-
Used by some providers for additional LLM guidance, e.g.
|
3298
|
-
via tool or schema description.
|
3299
|
-
*/
|
3300
|
-
schemaDescription?: string;
|
3301
|
-
/**
|
3302
|
-
The mode to use for object generation.
|
3303
|
-
|
3304
|
-
The schema is converted into a JSON schema and used in one of the following ways
|
3305
|
-
|
3306
|
-
- 'auto': The provider will choose the best mode for the model.
|
3307
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3308
|
-
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3309
|
-
|
3310
|
-
Please note that most providers do not support all modes.
|
3311
|
-
|
3312
|
-
Default and recommended: 'auto' (best mode for the model).
|
3313
|
-
*/
|
3314
|
-
mode?: 'auto' | 'json' | 'tool';
|
3315
|
-
/**
|
3316
|
-
A function that attempts to repair the raw output of the mode
|
3317
|
-
to enable JSON parsing.
|
3318
|
-
*/
|
3319
|
-
experimental_repairText?: RepairTextFunction;
|
3320
|
-
/**
|
3321
|
-
Optional telemetry configuration (experimental).
|
3322
|
-
*/
|
3323
|
-
experimental_telemetry?: TelemetrySettings;
|
3324
|
-
/**
|
3325
|
-
Additional provider-specific options. They are passed through
|
3326
|
-
to the provider from the AI SDK and enable provider-specific
|
3327
|
-
functionality that can be fully encapsulated in the provider.
|
3328
|
-
*/
|
3329
|
-
providerOptions?: ProviderOptions;
|
3330
|
-
/**
|
3331
|
-
@deprecated Use `providerOptions` instead.
|
3332
|
-
*/
|
3333
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3334
|
-
/**
|
3335
|
-
* Internal. For test use only. May change without notice.
|
3902
|
+
Converts the object to a JSON response.
|
3903
|
+
The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
|
3904
|
+
*/
|
3905
|
+
toJsonResponse(init?: ResponseInit): Response;
|
3906
|
+
}
|
3907
|
+
|
3908
|
+
/**
|
3909
|
+
A function that attempts to repair the raw output of the mode
|
3910
|
+
to enable JSON parsing.
|
3911
|
+
|
3912
|
+
Should return the repaired text or null if the text cannot be repaired.
|
3336
3913
|
*/
|
3337
|
-
|
3338
|
-
|
3339
|
-
|
3340
|
-
|
3341
|
-
}): Promise<GenerateObjectResult<Array<ELEMENT>>>;
|
3914
|
+
type RepairTextFunction = (options: {
|
3915
|
+
text: string;
|
3916
|
+
error: JSONParseError | TypeValidationError;
|
3917
|
+
}) => Promise<string | null>;
|
3342
3918
|
/**
|
3343
|
-
Generate a
|
3919
|
+
Generate a structured, typed object for a given prompt and schema using a language model.
|
3344
3920
|
|
3345
|
-
This function does not stream the output.
|
3921
|
+
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
3346
3922
|
|
3347
|
-
@
|
3348
|
-
A result object that contains the generated
|
3923
|
+
@returns
|
3924
|
+
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
3349
3925
|
*/
|
3350
|
-
declare function generateObject<
|
3926
|
+
declare function generateObject<TYPE extends SCHEMA extends z.Schema ? Output extends 'array' ? Array<z.infer<SCHEMA>> : z.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? Output extends 'array' ? Array<T> : T : never, SCHEMA extends z.Schema | Schema = z.Schema<JSONValue$1>, Output extends 'object' | 'array' | 'enum' | 'no-schema' = TYPE extends string ? 'enum' : 'object'>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (Output extends 'enum' ? {
|
3927
|
+
/**
|
3928
|
+
The enum values that the model should use.
|
3929
|
+
*/
|
3930
|
+
enum: Array<TYPE>;
|
3931
|
+
mode?: 'json';
|
3351
3932
|
output: 'enum';
|
3933
|
+
} : Output extends 'no-schema' ? {} : {
|
3352
3934
|
/**
|
3353
|
-
The
|
3354
|
-
|
3355
|
-
|
3935
|
+
The schema of the object that the model should generate.
|
3936
|
+
*/
|
3937
|
+
schema: SCHEMA;
|
3356
3938
|
/**
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3939
|
+
Optional name of the output that should be generated.
|
3940
|
+
Used by some providers for additional LLM guidance, e.g.
|
3941
|
+
via tool or schema name.
|
3942
|
+
*/
|
3943
|
+
schemaName?: string;
|
3944
|
+
/**
|
3945
|
+
Optional description of the output that should be generated.
|
3946
|
+
Used by some providers for additional LLM guidance, e.g.
|
3947
|
+
via tool or schema description.
|
3948
|
+
*/
|
3949
|
+
schemaDescription?: string;
|
3360
3950
|
/**
|
3361
3951
|
The mode to use for object generation.
|
3362
3952
|
|
@@ -3369,54 +3959,15 @@ The schema is converted into a JSON schema and used in one of the following ways
|
|
3369
3959
|
Please note that most providers do not support all modes.
|
3370
3960
|
|
3371
3961
|
Default and recommended: 'auto' (best mode for the model).
|
3372
|
-
|
3962
|
+
*/
|
3373
3963
|
mode?: 'auto' | 'json' | 'tool';
|
3374
|
-
|
3375
|
-
|
3376
|
-
to enable JSON parsing.
|
3377
|
-
*/
|
3378
|
-
experimental_repairText?: RepairTextFunction;
|
3379
|
-
/**
|
3380
|
-
Optional telemetry configuration (experimental).
|
3381
|
-
*/
|
3382
|
-
experimental_telemetry?: TelemetrySettings;
|
3383
|
-
/**
|
3384
|
-
Additional provider-specific options. They are passed through
|
3385
|
-
to the provider from the AI SDK and enable provider-specific
|
3386
|
-
functionality that can be fully encapsulated in the provider.
|
3387
|
-
*/
|
3388
|
-
providerOptions?: ProviderOptions;
|
3389
|
-
/**
|
3390
|
-
@deprecated Use `providerOptions` instead.
|
3391
|
-
*/
|
3392
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3393
|
-
/**
|
3394
|
-
* Internal. For test use only. May change without notice.
|
3395
|
-
*/
|
3396
|
-
_internal?: {
|
3397
|
-
generateId?: () => string;
|
3398
|
-
currentDate?: () => Date;
|
3399
|
-
};
|
3400
|
-
}): Promise<GenerateObjectResult<ENUM>>;
|
3401
|
-
/**
|
3402
|
-
Generate JSON with any schema for a given prompt using a language model.
|
3403
|
-
|
3404
|
-
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
3405
|
-
|
3406
|
-
@returns
|
3407
|
-
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
3408
|
-
*/
|
3409
|
-
declare function generateObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3410
|
-
output: 'no-schema';
|
3964
|
+
}) & {
|
3965
|
+
output?: Output;
|
3411
3966
|
/**
|
3412
3967
|
The language model to use.
|
3413
3968
|
*/
|
3414
3969
|
model: LanguageModel;
|
3415
3970
|
/**
|
3416
|
-
The mode to use for object generation. Must be "json" for no-schema output.
|
3417
|
-
*/
|
3418
|
-
mode?: 'json';
|
3419
|
-
/**
|
3420
3971
|
A function that attempts to repair the raw output of the mode
|
3421
3972
|
to enable JSON parsing.
|
3422
3973
|
*/
|
@@ -3432,17 +3983,13 @@ functionality that can be fully encapsulated in the provider.
|
|
3432
3983
|
*/
|
3433
3984
|
providerOptions?: ProviderOptions;
|
3434
3985
|
/**
|
3435
|
-
@deprecated Use `providerOptions` instead.
|
3436
|
-
*/
|
3437
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3438
|
-
/**
|
3439
3986
|
* Internal. For test use only. May change without notice.
|
3440
3987
|
*/
|
3441
3988
|
_internal?: {
|
3442
3989
|
generateId?: () => string;
|
3443
3990
|
currentDate?: () => Date;
|
3444
3991
|
};
|
3445
|
-
}): Promise<GenerateObjectResult<
|
3992
|
+
}): Promise<GenerateObjectResult<TYPE>>;
|
3446
3993
|
|
3447
3994
|
/**
|
3448
3995
|
The result of a `streamObject` call that contains the partial object stream and additional information.
|
@@ -3455,7 +4002,7 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
|
3455
4002
|
/**
|
3456
4003
|
The token usage of the generated response. Resolved when the response is finished.
|
3457
4004
|
*/
|
3458
|
-
readonly usage: Promise<LanguageModelUsage>;
|
4005
|
+
readonly usage: Promise<LanguageModelUsage$1>;
|
3459
4006
|
/**
|
3460
4007
|
Additional provider-specific metadata. They are passed through
|
3461
4008
|
from the provider to the AI SDK and enable provider-specific
|
@@ -3463,10 +4010,6 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
|
3463
4010
|
*/
|
3464
4011
|
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
3465
4012
|
/**
|
3466
|
-
@deprecated Use `providerMetadata` instead.
|
3467
|
-
*/
|
3468
|
-
readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
|
3469
|
-
/**
|
3470
4013
|
Additional request information from the last step.
|
3471
4014
|
*/
|
3472
4015
|
readonly request: Promise<LanguageModelRequestMetadata>;
|
@@ -3531,7 +4074,7 @@ type ObjectStreamPart<PARTIAL> = {
|
|
3531
4074
|
type: 'finish';
|
3532
4075
|
finishReason: FinishReason;
|
3533
4076
|
logprobs?: LogProbs;
|
3534
|
-
usage: LanguageModelUsage;
|
4077
|
+
usage: LanguageModelUsage$1;
|
3535
4078
|
response: LanguageModelResponseMetadata;
|
3536
4079
|
providerMetadata?: ProviderMetadata;
|
3537
4080
|
};
|
@@ -3553,7 +4096,7 @@ type StreamObjectOnFinishCallback<RESULT> = (event: {
|
|
3553
4096
|
/**
|
3554
4097
|
The token usage of the generated response.
|
3555
4098
|
*/
|
3556
|
-
usage: LanguageModelUsage;
|
4099
|
+
usage: LanguageModelUsage$1;
|
3557
4100
|
/**
|
3558
4101
|
The generated object. Can be undefined if the final object does not match the schema.
|
3559
4102
|
*/
|
@@ -3576,10 +4119,6 @@ type StreamObjectOnFinishCallback<RESULT> = (event: {
|
|
3576
4119
|
functionality that can be fully encapsulated in the provider.
|
3577
4120
|
*/
|
3578
4121
|
providerMetadata: ProviderMetadata | undefined;
|
3579
|
-
/**
|
3580
|
-
@deprecated Use `providerMetadata` instead.
|
3581
|
-
*/
|
3582
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3583
4122
|
}) => Promise<void> | void;
|
3584
4123
|
/**
|
3585
4124
|
Generate a structured, typed object for a given prompt and schema using a language model.
|
@@ -3636,10 +4175,6 @@ functionality that can be fully encapsulated in the provider.
|
|
3636
4175
|
*/
|
3637
4176
|
providerOptions?: ProviderOptions;
|
3638
4177
|
/**
|
3639
|
-
@deprecated Use `providerOptions` instead.
|
3640
|
-
*/
|
3641
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3642
|
-
/**
|
3643
4178
|
Callback that is invoked when an error occurs during streaming.
|
3644
4179
|
You can use it to log errors.
|
3645
4180
|
The stream processing will pause until the callback promise is resolved.
|
@@ -3713,10 +4248,6 @@ functionality that can be fully encapsulated in the provider.
|
|
3713
4248
|
*/
|
3714
4249
|
providerOptions?: ProviderOptions;
|
3715
4250
|
/**
|
3716
|
-
@deprecated Use `providerOptions` instead.
|
3717
|
-
*/
|
3718
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3719
|
-
/**
|
3720
4251
|
Callback that is invoked when an error occurs during streaming.
|
3721
4252
|
You can use it to log errors.
|
3722
4253
|
The stream processing will pause until the callback promise is resolved.
|
@@ -3764,10 +4295,6 @@ functionality that can be fully encapsulated in the provider.
|
|
3764
4295
|
*/
|
3765
4296
|
providerOptions?: ProviderOptions;
|
3766
4297
|
/**
|
3767
|
-
@deprecated Use `providerOptions` instead.
|
3768
|
-
*/
|
3769
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3770
|
-
/**
|
3771
4298
|
Callback that is invoked when an error occurs during streaming.
|
3772
4299
|
You can use it to log errors.
|
3773
4300
|
The stream processing will pause until the callback promise is resolved.
|
@@ -3776,7 +4303,7 @@ The stream processing will pause until the callback promise is resolved.
|
|
3776
4303
|
/**
|
3777
4304
|
Callback that is called when the LLM response and the final object validation are finished.
|
3778
4305
|
*/
|
3779
|
-
onFinish?: StreamObjectOnFinishCallback<JSONValue>;
|
4306
|
+
onFinish?: StreamObjectOnFinishCallback<JSONValue$1>;
|
3780
4307
|
/**
|
3781
4308
|
* Internal. For test use only. May change without notice.
|
3782
4309
|
*/
|
@@ -3785,14 +4312,236 @@ Callback that is called when the LLM response and the final object validation ar
|
|
3785
4312
|
currentDate?: () => Date;
|
3786
4313
|
now?: () => number;
|
3787
4314
|
};
|
3788
|
-
}): StreamObjectResult<JSONValue, JSONValue, never>;
|
4315
|
+
}): StreamObjectResult<JSONValue$1, JSONValue$1, never>;
|
4316
|
+
|
4317
|
+
/**
|
4318
|
+
* A generated audio file.
|
4319
|
+
*/
|
4320
|
+
interface GeneratedAudioFile extends GeneratedFile {
|
4321
|
+
/**
|
4322
|
+
* Audio format of the file (e.g., 'mp3', 'wav', etc.)
|
4323
|
+
*/
|
4324
|
+
readonly format: string;
|
4325
|
+
}
|
4326
|
+
|
4327
|
+
/**
|
4328
|
+
The result of a `generateSpeech` call.
|
4329
|
+
It contains the audio data and additional information.
|
4330
|
+
*/
|
4331
|
+
interface SpeechResult {
|
4332
|
+
/**
|
4333
|
+
* The audio data as a base64 encoded string or binary data.
|
4334
|
+
*/
|
4335
|
+
readonly audio: GeneratedAudioFile;
|
4336
|
+
/**
|
4337
|
+
Warnings for the call, e.g. unsupported settings.
|
4338
|
+
*/
|
4339
|
+
readonly warnings: Array<SpeechWarning>;
|
4340
|
+
/**
|
4341
|
+
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
4342
|
+
*/
|
4343
|
+
readonly responses: Array<SpeechModelResponseMetadata>;
|
4344
|
+
/**
|
4345
|
+
Provider metadata from the provider.
|
4346
|
+
*/
|
4347
|
+
readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
|
4348
|
+
}
|
4349
|
+
|
4350
|
+
/**
|
4351
|
+
Generates speech audio using a speech model.
|
4352
|
+
|
4353
|
+
@param model - The speech model to use.
|
4354
|
+
@param text - The text to convert to speech.
|
4355
|
+
@param voice - The voice to use for speech generation.
|
4356
|
+
@param outputFormat - The output format to use for speech generation e.g. "mp3", "wav", etc.
|
4357
|
+
@param instructions - Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
4358
|
+
@param speed - The speed of the speech generation.
|
4359
|
+
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
4360
|
+
as body parameters.
|
4361
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
4362
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
4363
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
4364
|
+
|
4365
|
+
@returns A result object that contains the generated audio data.
|
4366
|
+
*/
|
4367
|
+
declare function generateSpeech({ model, text, voice, outputFormat, instructions, speed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
4368
|
+
/**
|
4369
|
+
The speech model to use.
|
4370
|
+
*/
|
4371
|
+
model: SpeechModelV1;
|
4372
|
+
/**
|
4373
|
+
The text to convert to speech.
|
4374
|
+
*/
|
4375
|
+
text: string;
|
4376
|
+
/**
|
4377
|
+
The voice to use for speech generation.
|
4378
|
+
*/
|
4379
|
+
voice?: string;
|
4380
|
+
/**
|
4381
|
+
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
4382
|
+
*/
|
4383
|
+
outputFormat?: 'mp3' | 'wav' | (string & {});
|
4384
|
+
/**
|
4385
|
+
Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
4386
|
+
*/
|
4387
|
+
instructions?: string;
|
4388
|
+
/**
|
4389
|
+
The speed of the speech generation.
|
4390
|
+
*/
|
4391
|
+
speed?: number;
|
4392
|
+
/**
|
4393
|
+
Additional provider-specific options that are passed through to the provider
|
4394
|
+
as body parameters.
|
4395
|
+
|
4396
|
+
The outer record is keyed by the provider name, and the inner
|
4397
|
+
record is keyed by the provider-specific metadata key.
|
4398
|
+
```ts
|
4399
|
+
{
|
4400
|
+
"openai": {}
|
4401
|
+
}
|
4402
|
+
```
|
4403
|
+
*/
|
4404
|
+
providerOptions?: ProviderOptions;
|
4405
|
+
/**
|
4406
|
+
Maximum number of retries per speech model call. Set to 0 to disable retries.
|
4407
|
+
|
4408
|
+
@default 2
|
4409
|
+
*/
|
4410
|
+
maxRetries?: number;
|
4411
|
+
/**
|
4412
|
+
Abort signal.
|
4413
|
+
*/
|
4414
|
+
abortSignal?: AbortSignal;
|
4415
|
+
/**
|
4416
|
+
Additional headers to include in the request.
|
4417
|
+
Only applicable for HTTP-based providers.
|
4418
|
+
*/
|
4419
|
+
headers?: Record<string, string>;
|
4420
|
+
}): Promise<SpeechResult>;
|
4421
|
+
|
4422
|
+
/**
|
4423
|
+
The result of a `transcribe` call.
|
4424
|
+
It contains the transcript and additional information.
|
4425
|
+
*/
|
4426
|
+
interface TranscriptionResult {
|
4427
|
+
/**
|
4428
|
+
* The complete transcribed text from the audio.
|
4429
|
+
*/
|
4430
|
+
readonly text: string;
|
4431
|
+
/**
|
4432
|
+
* Array of transcript segments with timing information.
|
4433
|
+
* Each segment represents a portion of the transcribed text with start and end times.
|
4434
|
+
*/
|
4435
|
+
readonly segments: Array<{
|
4436
|
+
/**
|
4437
|
+
* The text content of this segment.
|
4438
|
+
*/
|
4439
|
+
readonly text: string;
|
4440
|
+
/**
|
4441
|
+
* The start time of this segment in seconds.
|
4442
|
+
*/
|
4443
|
+
readonly startSecond: number;
|
4444
|
+
/**
|
4445
|
+
* The end time of this segment in seconds.
|
4446
|
+
*/
|
4447
|
+
readonly endSecond: number;
|
4448
|
+
}>;
|
4449
|
+
/**
|
4450
|
+
* The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
|
4451
|
+
* May be undefined if the language couldn't be detected.
|
4452
|
+
*/
|
4453
|
+
readonly language: string | undefined;
|
4454
|
+
/**
|
4455
|
+
* The total duration of the audio file in seconds.
|
4456
|
+
* May be undefined if the duration couldn't be determined.
|
4457
|
+
*/
|
4458
|
+
readonly durationInSeconds: number | undefined;
|
4459
|
+
/**
|
4460
|
+
Warnings for the call, e.g. unsupported settings.
|
4461
|
+
*/
|
4462
|
+
readonly warnings: Array<TranscriptionWarning>;
|
4463
|
+
/**
|
4464
|
+
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
4465
|
+
*/
|
4466
|
+
readonly responses: Array<TranscriptionModelResponseMetadata>;
|
4467
|
+
/**
|
4468
|
+
Provider metadata from the provider.
|
4469
|
+
*/
|
4470
|
+
readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
|
4471
|
+
}
|
4472
|
+
|
4473
|
+
/**
|
4474
|
+
Generates transcripts using a transcription model.
|
4475
|
+
|
4476
|
+
@param model - The transcription model to use.
|
4477
|
+
@param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
|
4478
|
+
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
4479
|
+
as body parameters.
|
4480
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
4481
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
4482
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
4483
|
+
|
4484
|
+
@returns A result object that contains the generated transcript.
|
4485
|
+
*/
|
4486
|
+
declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
4487
|
+
/**
|
4488
|
+
The transcription model to use.
|
4489
|
+
*/
|
4490
|
+
model: TranscriptionModelV1;
|
4491
|
+
/**
|
4492
|
+
The audio data to transcribe.
|
4493
|
+
*/
|
4494
|
+
audio: DataContent | URL;
|
4495
|
+
/**
|
4496
|
+
Additional provider-specific options that are passed through to the provider
|
4497
|
+
as body parameters.
|
4498
|
+
|
4499
|
+
The outer record is keyed by the provider name, and the inner
|
4500
|
+
record is keyed by the provider-specific metadata key.
|
4501
|
+
```ts
|
4502
|
+
{
|
4503
|
+
"openai": {
|
4504
|
+
"temperature": 0
|
4505
|
+
}
|
4506
|
+
}
|
4507
|
+
```
|
4508
|
+
*/
|
4509
|
+
providerOptions?: ProviderOptions;
|
4510
|
+
/**
|
4511
|
+
Maximum number of retries per transcript model call. Set to 0 to disable retries.
|
4512
|
+
|
4513
|
+
@default 2
|
4514
|
+
*/
|
4515
|
+
maxRetries?: number;
|
4516
|
+
/**
|
4517
|
+
Abort signal.
|
4518
|
+
*/
|
4519
|
+
abortSignal?: AbortSignal;
|
4520
|
+
/**
|
4521
|
+
Additional headers to include in the request.
|
4522
|
+
Only applicable for HTTP-based providers.
|
4523
|
+
*/
|
4524
|
+
headers?: Record<string, string>;
|
4525
|
+
}): Promise<TranscriptionResult>;
|
3789
4526
|
|
3790
4527
|
/**
|
3791
4528
|
* Applies default settings for a language model.
|
3792
4529
|
*/
|
3793
4530
|
declare function defaultSettingsMiddleware({ settings, }: {
|
3794
|
-
settings: Partial<
|
3795
|
-
|
4531
|
+
settings: Partial<{
|
4532
|
+
maxOutputTokens?: LanguageModelV2CallOptions['maxOutputTokens'] | null;
|
4533
|
+
temperature?: LanguageModelV2CallOptions['temperature'] | null;
|
4534
|
+
stopSequences?: LanguageModelV2CallOptions['stopSequences'] | null;
|
4535
|
+
topP?: LanguageModelV2CallOptions['topP'] | null;
|
4536
|
+
topK?: LanguageModelV2CallOptions['topK'] | null;
|
4537
|
+
presencePenalty?: LanguageModelV2CallOptions['presencePenalty'] | null;
|
4538
|
+
frequencyPenalty?: LanguageModelV2CallOptions['frequencyPenalty'] | null;
|
4539
|
+
responseFormat?: LanguageModelV2CallOptions['responseFormat'] | null;
|
4540
|
+
seed?: LanguageModelV2CallOptions['seed'] | null;
|
4541
|
+
tools?: LanguageModelV2CallOptions['tools'] | null;
|
4542
|
+
toolChoice?: LanguageModelV2CallOptions['toolChoice'] | null;
|
4543
|
+
headers?: LanguageModelV2CallOptions['headers'];
|
4544
|
+
providerOptions?: LanguageModelV2CallOptions['providerOptions'];
|
3796
4545
|
}>;
|
3797
4546
|
}): LanguageModelV2Middleware;
|
3798
4547
|
|
@@ -3833,15 +4582,6 @@ declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, p
|
|
3833
4582
|
modelId?: string;
|
3834
4583
|
providerId?: string;
|
3835
4584
|
}) => LanguageModelV2;
|
3836
|
-
/**
|
3837
|
-
* @deprecated Use `wrapLanguageModel` instead.
|
3838
|
-
*/
|
3839
|
-
declare const experimental_wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
|
3840
|
-
model: LanguageModelV2;
|
3841
|
-
middleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
|
3842
|
-
modelId?: string;
|
3843
|
-
providerId?: string;
|
3844
|
-
}) => LanguageModelV2;
|
3845
4585
|
|
3846
4586
|
/**
|
3847
4587
|
* Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
|
@@ -3912,21 +4652,13 @@ declare const experimental_createProviderRegistry: typeof createProviderRegistry
|
|
3912
4652
|
*
|
3913
4653
|
* @param vector1 - The first vector.
|
3914
4654
|
* @param vector2 - The second vector.
|
3915
|
-
* @param options - Optional configuration.
|
3916
|
-
* @param options.throwErrorForEmptyVectors - If true, throws an error for empty vectors. Default: false.
|
3917
4655
|
*
|
3918
4656
|
* @returns The cosine similarity between vector1 and vector2.
|
3919
4657
|
* @returns 0 if either vector is the zero vector.
|
3920
4658
|
*
|
3921
|
-
* @throws {InvalidArgumentError} If throwErrorForEmptyVectors is true and vectors are empty.
|
3922
4659
|
* @throws {InvalidArgumentError} If the vectors do not have the same length.
|
3923
4660
|
*/
|
3924
|
-
declare function cosineSimilarity(vector1: number[], vector2: number[]
|
3925
|
-
/**
|
3926
|
-
* @deprecated will be removed in 5.0
|
3927
|
-
*/
|
3928
|
-
throwErrorForEmptyVectors?: boolean;
|
3929
|
-
}): number;
|
4661
|
+
declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
|
3930
4662
|
|
3931
4663
|
/**
|
3932
4664
|
* Creates a ReadableStream that emits the provided values with an optional delay between each value.
|
@@ -3960,23 +4692,29 @@ declare class InvalidArgumentError extends AISDKError {
|
|
3960
4692
|
}
|
3961
4693
|
|
3962
4694
|
type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
3963
|
-
type: '
|
3964
|
-
|
4695
|
+
type: 'stream-start';
|
4696
|
+
warnings: LanguageModelV2CallWarning[];
|
4697
|
+
} | {
|
4698
|
+
type: 'text';
|
4699
|
+
text: string;
|
3965
4700
|
} | {
|
3966
4701
|
type: 'reasoning';
|
3967
|
-
|
4702
|
+
reasoningType: 'text';
|
4703
|
+
text: string;
|
3968
4704
|
} | {
|
3969
|
-
type: 'reasoning
|
4705
|
+
type: 'reasoning';
|
4706
|
+
reasoningType: 'signature';
|
3970
4707
|
signature: string;
|
3971
4708
|
} | {
|
3972
|
-
type: '
|
4709
|
+
type: 'reasoning';
|
4710
|
+
reasoningType: 'redacted';
|
3973
4711
|
data: string;
|
3974
|
-
} |
|
4712
|
+
} | {
|
3975
4713
|
type: 'file';
|
3976
|
-
|
3977
|
-
type: 'source';
|
3978
|
-
source: Source;
|
4714
|
+
file: GeneratedFile;
|
3979
4715
|
} | ({
|
4716
|
+
type: 'source';
|
4717
|
+
} & Source) | ({
|
3980
4718
|
type: 'tool-call';
|
3981
4719
|
} & ToolCallUnion<TOOLS>) | {
|
3982
4720
|
type: 'tool-call-streaming-start';
|
@@ -3998,8 +4736,8 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
|
3998
4736
|
type: 'finish';
|
3999
4737
|
finishReason: FinishReason;
|
4000
4738
|
logprobs?: LogProbs;
|
4001
|
-
usage: LanguageModelUsage;
|
4002
|
-
|
4739
|
+
usage: LanguageModelUsage$1;
|
4740
|
+
providerMetadata?: ProviderMetadata;
|
4003
4741
|
} | {
|
4004
4742
|
type: 'error';
|
4005
4743
|
error: unknown;
|
@@ -4062,7 +4800,7 @@ declare class NoObjectGeneratedError extends AISDKError {
|
|
4062
4800
|
/**
|
4063
4801
|
The usage of the model.
|
4064
4802
|
*/
|
4065
|
-
readonly usage: LanguageModelUsage | undefined;
|
4803
|
+
readonly usage: LanguageModelUsage$1 | undefined;
|
4066
4804
|
/**
|
4067
4805
|
Reason why the model finished generating a response.
|
4068
4806
|
*/
|
@@ -4072,7 +4810,7 @@ declare class NoObjectGeneratedError extends AISDKError {
|
|
4072
4810
|
cause?: Error;
|
4073
4811
|
text?: string;
|
4074
4812
|
response: LanguageModelResponseMetadata;
|
4075
|
-
usage: LanguageModelUsage;
|
4813
|
+
usage: LanguageModelUsage$1;
|
4076
4814
|
finishReason: FinishReason;
|
4077
4815
|
});
|
4078
4816
|
static isInstance(error: unknown): error is NoObjectGeneratedError;
|
@@ -4106,11 +4844,11 @@ declare const symbol$6: unique symbol;
|
|
4106
4844
|
declare class ToolExecutionError extends AISDKError {
|
4107
4845
|
private readonly [symbol$6];
|
4108
4846
|
readonly toolName: string;
|
4109
|
-
readonly toolArgs: JSONValue;
|
4847
|
+
readonly toolArgs: JSONValue$1 | unknown;
|
4110
4848
|
readonly toolCallId: string;
|
4111
4849
|
constructor({ toolArgs, toolName, toolCallId, cause, message, }: {
|
4112
4850
|
message?: string;
|
4113
|
-
toolArgs: JSONValue;
|
4851
|
+
toolArgs: JSONValue$1 | unknown;
|
4114
4852
|
toolName: string;
|
4115
4853
|
toolCallId: string;
|
4116
4854
|
cause: unknown;
|
@@ -4249,7 +4987,7 @@ The following streams are supported:
|
|
4249
4987
|
- `LangChainAIMessageChunk` streams (LangChain `model.stream` output)
|
4250
4988
|
- `string` streams (LangChain `StringOutputParser` output)
|
4251
4989
|
*/
|
4252
|
-
declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array
|
4990
|
+
declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
4253
4991
|
declare function toDataStreamResponse$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, options?: {
|
4254
4992
|
init?: ResponseInit;
|
4255
4993
|
data?: StreamData;
|
@@ -4271,7 +5009,7 @@ declare namespace langchainAdapter {
|
|
4271
5009
|
type EngineResponse = {
|
4272
5010
|
delta: string;
|
4273
5011
|
};
|
4274
|
-
declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array
|
5012
|
+
declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
4275
5013
|
declare function toDataStreamResponse(stream: AsyncIterable<EngineResponse>, options?: {
|
4276
5014
|
init?: ResponseInit;
|
4277
5015
|
data?: StreamData;
|
@@ -4293,4 +5031,4 @@ declare namespace llamaindexAdapter {
|
|
4293
5031
|
};
|
4294
5032
|
}
|
4295
5033
|
|
4296
|
-
export { AssistantContent, CallWarning, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage,
|
5034
|
+
export { AssistantContent, Attachment, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamString, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, IdGenerator, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage$1 as LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MCPClientError, MCPTransport, Message, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RequestOptions, RetryError, Schema, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UseChatOptions, UseCompletionOptions, UserContent, appendClientMessage, appendResponseMessages, asSchema, callChatApi, callCompletionApi, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, fillMessageParts, formatDataStreamPart, generateObject, generateText, getMessageParts, getTextFromDataUrl, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, jsonSchema, parseDataStreamPart, parsePartialJson, pipeDataStreamToResponse, prepareAttachmentsForRequest, processDataStream, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, tool, updateToolCallResult, wrapLanguageModel, zodSchema };
|