ai 6.0.0-beta.99 → 6.0.0
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 +823 -0
- package/README.md +17 -13
- package/dist/index.d.mts +924 -624
- package/dist/index.d.ts +924 -624
- package/dist/index.js +1394 -976
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1209 -785
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +103 -6
- package/dist/internal/index.d.ts +103 -6
- package/dist/internal/index.js +124 -107
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +97 -79
- package/dist/internal/index.mjs.map +1 -1
- package/dist/test/index.d.mts +19 -19
- package/dist/test/index.d.ts +19 -19
- package/dist/test/index.js +2 -2
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +2 -2
- package/dist/test/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import { GatewayModelId } from '@ai-sdk/gateway';
|
|
2
|
+
export { GatewayModelId, createGateway, gateway } from '@ai-sdk/gateway';
|
|
2
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
|
-
import { Tool, InferToolInput, InferToolOutput, FlexibleSchema, InferSchema, AssistantModelMessage, ToolModelMessage, ReasoningPart, ModelMessage,
|
|
4
|
-
export { AssistantContent, AssistantModelMessage, DataContent, FilePart, FlexibleSchema, IdGenerator, ImagePart, InferSchema, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, dynamicTool, generateId, jsonSchema, parseJsonEventStream, tool, zodSchema } from '@ai-sdk/provider-utils';
|
|
4
|
+
import { Tool, InferToolInput, InferToolOutput, FlexibleSchema, InferSchema, AssistantModelMessage, ToolModelMessage, ReasoningPart, SystemModelMessage, ModelMessage, ProviderOptions, UserModelMessage, IdGenerator, ToolCall, MaybePromiseLike, TextPart, FilePart, Resolvable, FetchFunction, DataContent } from '@ai-sdk/provider-utils';
|
|
5
|
+
export { AssistantContent, AssistantModelMessage, DataContent, DownloadError, FilePart, FlexibleSchema, IdGenerator, ImagePart, InferSchema, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolExecutionOptions, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, dynamicTool, generateId, jsonSchema, parseJsonEventStream, tool, zodSchema } from '@ai-sdk/provider-utils';
|
|
5
6
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
6
|
-
import { EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV3Embedding, ImageModelV3,
|
|
7
|
+
import { EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV3Embedding, EmbeddingModelV3Middleware, ImageModelV3, ImageModelV2, ImageModelV3ProviderMetadata, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV3, LanguageModelV2, SharedV3Warning, LanguageModelV3Source, LanguageModelV3Middleware, RerankingModelV3, SharedV3ProviderMetadata, SpeechModelV3, SpeechModelV2, TranscriptionModelV3, TranscriptionModelV2, JSONObject, ImageModelV3Usage, LanguageModelV3CallOptions, AISDKError, LanguageModelV3ToolCall, JSONSchema7, JSONParseError, TypeValidationError, EmbeddingModelV3CallOptions, ProviderV3, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
|
7
8
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
|
8
|
-
import { ServerResponse } from 'node:http';
|
|
9
9
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
|
10
|
+
import { ServerResponse } from 'node:http';
|
|
10
11
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
|
11
12
|
import { z } from 'zod/v4';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
Embedding model that is used by the AI SDK
|
|
15
|
+
Embedding model that is used by the AI SDK.
|
|
15
16
|
*/
|
|
16
|
-
type EmbeddingModel
|
|
17
|
+
type EmbeddingModel = string | EmbeddingModelV3 | EmbeddingModelV2<string>;
|
|
17
18
|
/**
|
|
18
19
|
Embedding.
|
|
19
20
|
*/
|
|
20
21
|
type Embedding = EmbeddingModelV3Embedding;
|
|
21
22
|
|
|
23
|
+
type EmbeddingModelMiddleware = EmbeddingModelV3Middleware;
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
|
-
Image model that is used by the AI SDK
|
|
24
|
-
*/
|
|
25
|
-
type ImageModel = ImageModelV3;
|
|
26
|
-
/**
|
|
27
|
-
Warning from the model provider for this call. The call will proceed, but e.g.
|
|
28
|
-
some settings might not be supported, which can lead to suboptimal results.
|
|
26
|
+
Image model that is used by the AI SDK.
|
|
29
27
|
*/
|
|
30
|
-
type
|
|
28
|
+
type ImageModel = string | ImageModelV3 | ImageModelV2;
|
|
31
29
|
/**
|
|
32
30
|
Metadata from the model provider for this call
|
|
33
31
|
*/
|
|
34
|
-
type ImageModelProviderMetadata = ImageModelV3ProviderMetadata;
|
|
32
|
+
type ImageModelProviderMetadata = ImageModelV3ProviderMetadata | ImageModelV2ProviderMetadata;
|
|
35
33
|
|
|
36
34
|
type ImageModelResponseMetadata = {
|
|
37
35
|
/**
|
|
@@ -50,10 +48,50 @@ type ImageModelResponseMetadata = {
|
|
|
50
48
|
|
|
51
49
|
type JSONValue = JSONValue$1;
|
|
52
50
|
|
|
51
|
+
declare global {
|
|
52
|
+
/**
|
|
53
|
+
* Global interface that can be augmented by third-party packages to register custom model IDs.
|
|
54
|
+
*
|
|
55
|
+
* You can register model IDs in two ways:
|
|
56
|
+
*
|
|
57
|
+
* 1. Register baesd on Model IDs from a provider package:
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { openai } from '@ai-sdk/openai';
|
|
61
|
+
* type OpenAIResponsesModelId = Parameters<typeof openai>[0];
|
|
62
|
+
*
|
|
63
|
+
* declare global {
|
|
64
|
+
* interface RegisteredProviderModels {
|
|
65
|
+
* openai: OpenAIResponsesModelId;
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* 2. Register individual model IDs directly as keys:
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* declare global {
|
|
74
|
+
* interface RegisteredProviderModels {
|
|
75
|
+
* 'my-provider:my-model': any;
|
|
76
|
+
* 'my-provider:another-model': any;
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
interface RegisteredProviderModels {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Global provider model ID type that defaults to GatewayModelId but can be augmented
|
|
86
|
+
* by third-party packages via declaration merging.
|
|
87
|
+
*/
|
|
88
|
+
type GlobalProviderModelId = [keyof RegisteredProviderModels] extends [
|
|
89
|
+
never
|
|
90
|
+
] ? GatewayModelId : keyof RegisteredProviderModels | RegisteredProviderModels[keyof RegisteredProviderModels];
|
|
53
91
|
/**
|
|
54
|
-
Language model that is used by the AI SDK
|
|
92
|
+
Language model that is used by the AI SDK.
|
|
55
93
|
*/
|
|
56
|
-
type LanguageModel =
|
|
94
|
+
type LanguageModel = GlobalProviderModelId | LanguageModelV3 | LanguageModelV2;
|
|
57
95
|
/**
|
|
58
96
|
Reason why a language model finished generating a response.
|
|
59
97
|
|
|
@@ -65,12 +103,12 @@ Can be one of the following:
|
|
|
65
103
|
- `error`: model stopped because of an error
|
|
66
104
|
- `other`: model stopped for other reasons
|
|
67
105
|
*/
|
|
68
|
-
type FinishReason =
|
|
106
|
+
type FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
|
|
69
107
|
/**
|
|
70
108
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
|
71
109
|
some settings might not be supported, which can lead to suboptimal results.
|
|
72
110
|
*/
|
|
73
|
-
type CallWarning =
|
|
111
|
+
type CallWarning = SharedV3Warning;
|
|
74
112
|
/**
|
|
75
113
|
A source that has been used as input to generate the response.
|
|
76
114
|
*/
|
|
@@ -90,8 +128,6 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
|
|
|
90
128
|
|
|
91
129
|
type LanguageModelMiddleware = LanguageModelV3Middleware;
|
|
92
130
|
|
|
93
|
-
type EmbeddingModelMiddleware = EmbeddingModelV3Middleware;
|
|
94
|
-
|
|
95
131
|
type LanguageModelRequestMetadata = {
|
|
96
132
|
/**
|
|
97
133
|
Request HTTP body that was sent to the provider API.
|
|
@@ -119,7 +155,7 @@ type LanguageModelResponseMetadata = {
|
|
|
119
155
|
};
|
|
120
156
|
|
|
121
157
|
/**
|
|
122
|
-
* Reranking model that is used by the AI SDK
|
|
158
|
+
* Reranking model that is used by the AI SDK.
|
|
123
159
|
*/
|
|
124
160
|
type RerankingModel = RerankingModelV3;
|
|
125
161
|
|
|
@@ -148,7 +184,7 @@ type Provider = {
|
|
|
148
184
|
|
|
149
185
|
@throws {NoSuchModelError} If no such model exists.
|
|
150
186
|
*/
|
|
151
|
-
|
|
187
|
+
embeddingModel(modelId: string): EmbeddingModel;
|
|
152
188
|
/**
|
|
153
189
|
Returns the image model with the given id.
|
|
154
190
|
The model id is then passed to the provider function to get the model.
|
|
@@ -180,14 +216,9 @@ fully encapsulated in the provider.
|
|
|
180
216
|
type ProviderMetadata = SharedV3ProviderMetadata;
|
|
181
217
|
|
|
182
218
|
/**
|
|
183
|
-
Speech model that is used by the AI SDK
|
|
219
|
+
Speech model that is used by the AI SDK.
|
|
184
220
|
*/
|
|
185
221
|
type SpeechModel = string | SpeechModelV3 | SpeechModelV2;
|
|
186
|
-
/**
|
|
187
|
-
Warning from the model provider for this call. The call will proceed, but e.g.
|
|
188
|
-
some settings might not be supported, which can lead to suboptimal results.
|
|
189
|
-
*/
|
|
190
|
-
type SpeechWarning = SpeechModelV3CallWarning;
|
|
191
222
|
|
|
192
223
|
type SpeechModelResponseMetadata = {
|
|
193
224
|
/**
|
|
@@ -209,14 +240,9 @@ type SpeechModelResponseMetadata = {
|
|
|
209
240
|
};
|
|
210
241
|
|
|
211
242
|
/**
|
|
212
|
-
Transcription model that is used by the AI SDK
|
|
243
|
+
Transcription model that is used by the AI SDK.
|
|
213
244
|
*/
|
|
214
245
|
type TranscriptionModel = string | TranscriptionModelV3 | TranscriptionModelV2;
|
|
215
|
-
/**
|
|
216
|
-
Warning from the model provider for this call. The call will proceed, but e.g.
|
|
217
|
-
some settings might not be supported, which can lead to suboptimal results.
|
|
218
|
-
*/
|
|
219
|
-
type TranscriptionWarning = TranscriptionModelV3CallWarning;
|
|
220
246
|
|
|
221
247
|
type TranscriptionModelResponseMetadata = {
|
|
222
248
|
/**
|
|
@@ -234,9 +260,67 @@ type TranscriptionModelResponseMetadata = {
|
|
|
234
260
|
};
|
|
235
261
|
|
|
236
262
|
/**
|
|
237
|
-
Represents the number of tokens used in a prompt and completion.
|
|
263
|
+
* Represents the number of tokens used in a prompt and completion.
|
|
238
264
|
*/
|
|
239
|
-
type LanguageModelUsage =
|
|
265
|
+
type LanguageModelUsage = {
|
|
266
|
+
/**
|
|
267
|
+
* The total number of input (prompt) tokens used.
|
|
268
|
+
*/
|
|
269
|
+
inputTokens: number | undefined;
|
|
270
|
+
/**
|
|
271
|
+
* Detailed information about the input tokens.
|
|
272
|
+
*/
|
|
273
|
+
inputTokenDetails: {
|
|
274
|
+
/**
|
|
275
|
+
* The number of non-cached input (prompt) tokens used.
|
|
276
|
+
*/
|
|
277
|
+
noCacheTokens: number | undefined;
|
|
278
|
+
/**
|
|
279
|
+
* The number of cached input (prompt) tokens read.
|
|
280
|
+
*/
|
|
281
|
+
cacheReadTokens: number | undefined;
|
|
282
|
+
/**
|
|
283
|
+
* The number of cached input (prompt) tokens written.
|
|
284
|
+
*/
|
|
285
|
+
cacheWriteTokens: number | undefined;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* The number of total output (completion) tokens used.
|
|
289
|
+
*/
|
|
290
|
+
outputTokens: number | undefined;
|
|
291
|
+
/**
|
|
292
|
+
* Detailed information about the output tokens.
|
|
293
|
+
*/
|
|
294
|
+
outputTokenDetails: {
|
|
295
|
+
/**
|
|
296
|
+
* The number of text tokens used.
|
|
297
|
+
*/
|
|
298
|
+
textTokens: number | undefined;
|
|
299
|
+
/**
|
|
300
|
+
* The number of reasoning tokens used.
|
|
301
|
+
*/
|
|
302
|
+
reasoningTokens: number | undefined;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* The total number of tokens used.
|
|
306
|
+
*/
|
|
307
|
+
totalTokens: number | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* @deprecated Use outputTokenDetails.reasoning instead.
|
|
310
|
+
*/
|
|
311
|
+
reasoningTokens?: number | undefined;
|
|
312
|
+
/**
|
|
313
|
+
* @deprecated Use inputTokenDetails.cacheRead instead.
|
|
314
|
+
*/
|
|
315
|
+
cachedInputTokens?: number | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* Raw usage information from the provider.
|
|
318
|
+
*
|
|
319
|
+
* This is the usage information in the shape that the provider returns.
|
|
320
|
+
* It can include additional information that is not part of the standard usage information.
|
|
321
|
+
*/
|
|
322
|
+
raw?: JSONObject;
|
|
323
|
+
};
|
|
240
324
|
/**
|
|
241
325
|
Represents the number of tokens used in an embedding.
|
|
242
326
|
*/
|
|
@@ -251,6 +335,12 @@ Usage information for an image model call.
|
|
|
251
335
|
*/
|
|
252
336
|
type ImageModelUsage = ImageModelV3Usage;
|
|
253
337
|
|
|
338
|
+
/**
|
|
339
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
|
340
|
+
some settings might not be supported, which can lead to suboptimal results.
|
|
341
|
+
*/
|
|
342
|
+
type Warning = SharedV3Warning;
|
|
343
|
+
|
|
254
344
|
/**
|
|
255
345
|
* A generated file.
|
|
256
346
|
*/
|
|
@@ -390,6 +480,7 @@ type StaticToolError<TOOLS extends ToolSet> = ValueOf<{
|
|
|
390
480
|
input: InferToolInput<TOOLS[NAME]>;
|
|
391
481
|
error: unknown;
|
|
392
482
|
providerExecuted?: boolean;
|
|
483
|
+
providerMetadata?: ProviderMetadata;
|
|
393
484
|
dynamic?: false | undefined;
|
|
394
485
|
title?: string;
|
|
395
486
|
};
|
|
@@ -401,6 +492,7 @@ type DynamicToolError = {
|
|
|
401
492
|
input: unknown;
|
|
402
493
|
error: unknown;
|
|
403
494
|
providerExecuted?: boolean;
|
|
495
|
+
providerMetadata?: ProviderMetadata;
|
|
404
496
|
dynamic: true;
|
|
405
497
|
title?: string;
|
|
406
498
|
};
|
|
@@ -414,6 +506,7 @@ type StaticToolResult<TOOLS extends ToolSet> = ValueOf<{
|
|
|
414
506
|
input: InferToolInput<TOOLS[NAME]>;
|
|
415
507
|
output: InferToolOutput<TOOLS[NAME]>;
|
|
416
508
|
providerExecuted?: boolean;
|
|
509
|
+
providerMetadata?: ProviderMetadata;
|
|
417
510
|
dynamic?: false | undefined;
|
|
418
511
|
preliminary?: boolean;
|
|
419
512
|
title?: string;
|
|
@@ -426,6 +519,7 @@ type DynamicToolResult = {
|
|
|
426
519
|
input: unknown;
|
|
427
520
|
output: unknown;
|
|
428
521
|
providerExecuted?: boolean;
|
|
522
|
+
providerMetadata?: ProviderMetadata;
|
|
429
523
|
dynamic: true;
|
|
430
524
|
preliminary?: boolean;
|
|
431
525
|
title?: string;
|
|
@@ -509,41 +603,91 @@ declare const text: () => Output<string, string>;
|
|
|
509
603
|
* When the model generates a text response, it will return an object that matches the schema.
|
|
510
604
|
*
|
|
511
605
|
* @param schema - The schema of the object to generate.
|
|
606
|
+
* @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
607
|
+
* @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
512
608
|
*
|
|
513
609
|
* @returns An output specification for generating objects with the specified schema.
|
|
514
610
|
*/
|
|
515
|
-
declare const object: <OBJECT>({ schema: inputSchema, }: {
|
|
611
|
+
declare const object: <OBJECT>({ schema: inputSchema, name, description, }: {
|
|
516
612
|
schema: FlexibleSchema<OBJECT>;
|
|
613
|
+
/**
|
|
614
|
+
* Optional name of the output that should be generated.
|
|
615
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
616
|
+
*/
|
|
617
|
+
name?: string;
|
|
618
|
+
/**
|
|
619
|
+
* Optional description of the output that should be generated.
|
|
620
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
621
|
+
*/
|
|
622
|
+
description?: string;
|
|
517
623
|
}) => Output<OBJECT, DeepPartial<OBJECT>>;
|
|
518
624
|
/**
|
|
519
625
|
* Output specification for array generation.
|
|
520
626
|
* When the model generates a text response, it will return an array of elements.
|
|
521
627
|
*
|
|
522
628
|
* @param element - The schema of the array elements to generate.
|
|
629
|
+
* @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
630
|
+
* @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
523
631
|
*
|
|
524
632
|
* @returns An output specification for generating an array of elements.
|
|
525
633
|
*/
|
|
526
|
-
declare const array: <ELEMENT>({ element: inputElementSchema, }: {
|
|
634
|
+
declare const array: <ELEMENT>({ element: inputElementSchema, name, description, }: {
|
|
527
635
|
element: FlexibleSchema<ELEMENT>;
|
|
636
|
+
/**
|
|
637
|
+
* Optional name of the output that should be generated.
|
|
638
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
639
|
+
*/
|
|
640
|
+
name?: string;
|
|
641
|
+
/**
|
|
642
|
+
* Optional description of the output that should be generated.
|
|
643
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
644
|
+
*/
|
|
645
|
+
description?: string;
|
|
528
646
|
}) => Output<Array<ELEMENT>, Array<ELEMENT>>;
|
|
529
647
|
/**
|
|
530
648
|
* Output specification for choice generation.
|
|
531
649
|
* When the model generates a text response, it will return a one of the choice options.
|
|
532
650
|
*
|
|
533
651
|
* @param options - The available choices.
|
|
652
|
+
* @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
653
|
+
* @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
534
654
|
*
|
|
535
655
|
* @returns An output specification for generating a choice.
|
|
536
656
|
*/
|
|
537
|
-
declare const choice: <CHOICE extends string>({ options: choiceOptions, }: {
|
|
657
|
+
declare const choice: <CHOICE extends string>({ options: choiceOptions, name, description, }: {
|
|
538
658
|
options: Array<CHOICE>;
|
|
659
|
+
/**
|
|
660
|
+
* Optional name of the output that should be generated.
|
|
661
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
662
|
+
*/
|
|
663
|
+
name?: string;
|
|
664
|
+
/**
|
|
665
|
+
* Optional description of the output that should be generated.
|
|
666
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
667
|
+
*/
|
|
668
|
+
description?: string;
|
|
539
669
|
}) => Output<CHOICE, CHOICE>;
|
|
540
670
|
/**
|
|
541
671
|
* Output specification for unstructured JSON generation.
|
|
542
672
|
* When the model generates a text response, it will return a JSON object.
|
|
543
673
|
*
|
|
674
|
+
* @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
675
|
+
* @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
676
|
+
*
|
|
544
677
|
* @returns An output specification for generating JSON.
|
|
545
678
|
*/
|
|
546
|
-
declare const json: (
|
|
679
|
+
declare const json: ({ name, description, }?: {
|
|
680
|
+
/**
|
|
681
|
+
* Optional name of the output that should be generated.
|
|
682
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
683
|
+
*/
|
|
684
|
+
name?: string;
|
|
685
|
+
/**
|
|
686
|
+
* Optional description of the output that should be generated.
|
|
687
|
+
* Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
688
|
+
*/
|
|
689
|
+
description?: string;
|
|
690
|
+
}) => Output<JSONValue$1, JSONValue$1>;
|
|
547
691
|
|
|
548
692
|
type output_Output<OUTPUT = any, PARTIAL = any> = Output<OUTPUT, PARTIAL>;
|
|
549
693
|
declare const output_array: typeof array;
|
|
@@ -630,10 +774,14 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
|
630
774
|
*/
|
|
631
775
|
readonly dynamicToolResults: Array<DynamicToolResult>;
|
|
632
776
|
/**
|
|
633
|
-
|
|
634
|
-
|
|
777
|
+
* The unified reason why the generation finished.
|
|
778
|
+
*/
|
|
635
779
|
readonly finishReason: FinishReason;
|
|
636
780
|
/**
|
|
781
|
+
* The raw reason why the generation finished (from the provider).
|
|
782
|
+
*/
|
|
783
|
+
readonly rawFinishReason: string | undefined;
|
|
784
|
+
/**
|
|
637
785
|
The token usage of the generated text.
|
|
638
786
|
*/
|
|
639
787
|
readonly usage: LanguageModelUsage;
|
|
@@ -724,10 +872,14 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
724
872
|
*/
|
|
725
873
|
readonly dynamicToolResults: Array<DynamicToolResult>;
|
|
726
874
|
/**
|
|
727
|
-
|
|
875
|
+
* The unified reason why the generation finished.
|
|
728
876
|
*/
|
|
729
877
|
readonly finishReason: FinishReason;
|
|
730
878
|
/**
|
|
879
|
+
* The raw reason why the generation finished (from the provider).
|
|
880
|
+
*/
|
|
881
|
+
readonly rawFinishReason: string | undefined;
|
|
882
|
+
/**
|
|
731
883
|
The token usage of the last step.
|
|
732
884
|
*/
|
|
733
885
|
readonly usage: LanguageModelUsage;
|
|
@@ -866,7 +1018,7 @@ type Prompt = {
|
|
|
866
1018
|
/**
|
|
867
1019
|
System message to include in the prompt. Can be used with `prompt` or `messages`.
|
|
868
1020
|
*/
|
|
869
|
-
system?: string
|
|
1021
|
+
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
870
1022
|
} & ({
|
|
871
1023
|
/**
|
|
872
1024
|
A prompt. It can be either a text prompt or a list of messages.
|
|
@@ -957,28 +1109,81 @@ type DownloadFunction = (options: Array<{
|
|
|
957
1109
|
} | null>>;
|
|
958
1110
|
|
|
959
1111
|
/**
|
|
960
|
-
Function that you can use to provide different settings for a step.
|
|
961
|
-
|
|
962
|
-
@param options - The options for the step.
|
|
963
|
-
@param options.steps - The steps that have been executed so far.
|
|
964
|
-
@param options.stepNumber - The number of the step that is being executed.
|
|
965
|
-
@param options.model - The model that is being used.
|
|
966
|
-
|
|
967
|
-
@
|
|
968
|
-
|
|
969
|
-
|
|
1112
|
+
* Function that you can use to provide different settings for a step.
|
|
1113
|
+
*
|
|
1114
|
+
* @param options - The options for the step.
|
|
1115
|
+
* @param options.steps - The steps that have been executed so far.
|
|
1116
|
+
* @param options.stepNumber - The number of the step that is being executed.
|
|
1117
|
+
* @param options.model - The model that is being used.
|
|
1118
|
+
* @param options.messages - The messages that will be sent to the model for the current step.
|
|
1119
|
+
* @param options.experimental_context - The context passed via the experimental_context setting (experimental).
|
|
1120
|
+
*
|
|
1121
|
+
* @returns An object that contains the settings for the step.
|
|
1122
|
+
* If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
1123
|
+
*/
|
|
970
1124
|
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
1125
|
+
/**
|
|
1126
|
+
* The steps that have been executed so far.
|
|
1127
|
+
*/
|
|
971
1128
|
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
|
1129
|
+
/**
|
|
1130
|
+
* The number of the step that is being executed.
|
|
1131
|
+
*/
|
|
972
1132
|
stepNumber: number;
|
|
1133
|
+
/**
|
|
1134
|
+
* The model instance that is being used for this step.
|
|
1135
|
+
*/
|
|
973
1136
|
model: LanguageModel;
|
|
1137
|
+
/**
|
|
1138
|
+
* The messages that will be sent to the model for the current step.
|
|
1139
|
+
*/
|
|
974
1140
|
messages: Array<ModelMessage>;
|
|
1141
|
+
/**
|
|
1142
|
+
* The context passed via the experimental_context setting (experimental).
|
|
1143
|
+
*/
|
|
1144
|
+
experimental_context: unknown;
|
|
975
1145
|
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
|
1146
|
+
/**
|
|
1147
|
+
* The result type returned by a {@link PrepareStepFunction},
|
|
1148
|
+
* allowing per-step overrides of model, tools, or messages.
|
|
1149
|
+
*/
|
|
976
1150
|
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
1151
|
+
/**
|
|
1152
|
+
* Optionally override which LanguageModel instance is used for this step.
|
|
1153
|
+
*/
|
|
977
1154
|
model?: LanguageModel;
|
|
1155
|
+
/**
|
|
1156
|
+
* Optionally set which tool the model must call, or provide tool call configuration
|
|
1157
|
+
* for this step.
|
|
1158
|
+
*/
|
|
978
1159
|
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
1160
|
+
/**
|
|
1161
|
+
* If provided, only these tools are enabled/available for this step.
|
|
1162
|
+
*/
|
|
979
1163
|
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
980
|
-
|
|
1164
|
+
/**
|
|
1165
|
+
* Optionally override the system message(s) sent to the model for this step.
|
|
1166
|
+
*/
|
|
1167
|
+
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
1168
|
+
/**
|
|
1169
|
+
* Optionally override the full set of messages sent to the model
|
|
1170
|
+
* for this step.
|
|
1171
|
+
*/
|
|
981
1172
|
messages?: Array<ModelMessage>;
|
|
1173
|
+
/**
|
|
1174
|
+
* Context that is passed into tool execution. Experimental.
|
|
1175
|
+
*
|
|
1176
|
+
* Changing the context will affect the context in this step
|
|
1177
|
+
* and all subsequent steps.
|
|
1178
|
+
*/
|
|
1179
|
+
experimental_context?: unknown;
|
|
1180
|
+
/**
|
|
1181
|
+
* Additional provider-specific options for this step.
|
|
1182
|
+
*
|
|
1183
|
+
* Can be used to pass provider-specific configuration such as
|
|
1184
|
+
* container IDs for Anthropic's code execution.
|
|
1185
|
+
*/
|
|
1186
|
+
providerOptions?: ProviderOptions;
|
|
982
1187
|
} | undefined;
|
|
983
1188
|
|
|
984
1189
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
@@ -987,9 +1192,9 @@ type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
|
987
1192
|
declare function stepCountIs(stepCount: number): StopCondition<any>;
|
|
988
1193
|
declare function hasToolCall(toolName: string): StopCondition<any>;
|
|
989
1194
|
|
|
990
|
-
declare const symbol$
|
|
1195
|
+
declare const symbol$c: unique symbol;
|
|
991
1196
|
declare class InvalidToolInputError extends AISDKError {
|
|
992
|
-
private readonly [symbol$
|
|
1197
|
+
private readonly [symbol$c];
|
|
993
1198
|
readonly toolName: string;
|
|
994
1199
|
readonly toolInput: string;
|
|
995
1200
|
constructor({ toolInput, toolName, cause, message, }: {
|
|
@@ -1001,9 +1206,9 @@ declare class InvalidToolInputError extends AISDKError {
|
|
|
1001
1206
|
static isInstance(error: unknown): error is InvalidToolInputError;
|
|
1002
1207
|
}
|
|
1003
1208
|
|
|
1004
|
-
declare const symbol$
|
|
1209
|
+
declare const symbol$b: unique symbol;
|
|
1005
1210
|
declare class NoSuchToolError extends AISDKError {
|
|
1006
|
-
private readonly [symbol$
|
|
1211
|
+
private readonly [symbol$b];
|
|
1007
1212
|
readonly toolName: string;
|
|
1008
1213
|
readonly availableTools: string[] | undefined;
|
|
1009
1214
|
constructor({ toolName, availableTools, message, }: {
|
|
@@ -1014,51 +1219,11 @@ declare class NoSuchToolError extends AISDKError {
|
|
|
1014
1219
|
static isInstance(error: unknown): error is NoSuchToolError;
|
|
1015
1220
|
}
|
|
1016
1221
|
|
|
1017
|
-
/**
|
|
1018
|
-
@deprecated Use `SystemModelMessage` instead.
|
|
1019
|
-
*/
|
|
1020
|
-
type CoreSystemMessage = SystemModelMessage;
|
|
1021
1222
|
declare const systemModelMessageSchema: z.ZodType<SystemModelMessage>;
|
|
1022
|
-
/**
|
|
1023
|
-
@deprecated Use `systemModelMessageSchema` instead.
|
|
1024
|
-
*/
|
|
1025
|
-
declare const coreSystemMessageSchema: z.ZodType<SystemModelMessage, unknown, z.core.$ZodTypeInternals<SystemModelMessage, unknown>>;
|
|
1026
|
-
/**
|
|
1027
|
-
@deprecated Use `UserModelMessage` instead.
|
|
1028
|
-
*/
|
|
1029
|
-
type CoreUserMessage = UserModelMessage;
|
|
1030
1223
|
declare const userModelMessageSchema: z.ZodType<UserModelMessage>;
|
|
1031
|
-
/**
|
|
1032
|
-
@deprecated Use `userModelMessageSchema` instead.
|
|
1033
|
-
*/
|
|
1034
|
-
declare const coreUserMessageSchema: z.ZodType<UserModelMessage, unknown, z.core.$ZodTypeInternals<UserModelMessage, unknown>>;
|
|
1035
|
-
/**
|
|
1036
|
-
@deprecated Use `AssistantModelMessage` instead.
|
|
1037
|
-
*/
|
|
1038
|
-
type CoreAssistantMessage = AssistantModelMessage;
|
|
1039
1224
|
declare const assistantModelMessageSchema: z.ZodType<AssistantModelMessage>;
|
|
1040
|
-
/**
|
|
1041
|
-
@deprecated Use `assistantModelMessageSchema` instead.
|
|
1042
|
-
*/
|
|
1043
|
-
declare const coreAssistantMessageSchema: z.ZodType<AssistantModelMessage, unknown, z.core.$ZodTypeInternals<AssistantModelMessage, unknown>>;
|
|
1044
|
-
/**
|
|
1045
|
-
@deprecated Use `ToolModelMessage` instead.
|
|
1046
|
-
*/
|
|
1047
|
-
type CoreToolMessage = ToolModelMessage;
|
|
1048
1225
|
declare const toolModelMessageSchema: z.ZodType<ToolModelMessage>;
|
|
1049
|
-
/**
|
|
1050
|
-
@deprecated Use `toolModelMessageSchema` instead.
|
|
1051
|
-
*/
|
|
1052
|
-
declare const coreToolMessageSchema: z.ZodType<ToolModelMessage, unknown, z.core.$ZodTypeInternals<ToolModelMessage, unknown>>;
|
|
1053
|
-
/**
|
|
1054
|
-
@deprecated Use `ModelMessage` instead.
|
|
1055
|
-
*/
|
|
1056
|
-
type CoreMessage = ModelMessage;
|
|
1057
1226
|
declare const modelMessageSchema: z.ZodType<ModelMessage>;
|
|
1058
|
-
/**
|
|
1059
|
-
@deprecated Use `modelMessageSchema` instead.
|
|
1060
|
-
*/
|
|
1061
|
-
declare const coreMessageSchema: z.ZodType<CoreMessage>;
|
|
1062
1227
|
|
|
1063
1228
|
/**
|
|
1064
1229
|
* A function that attempts to repair a tool call that failed to parse.
|
|
@@ -1074,7 +1239,7 @@ declare const coreMessageSchema: z.ZodType<CoreMessage>;
|
|
|
1074
1239
|
* @param options.error - The error that occurred while parsing the tool call.
|
|
1075
1240
|
*/
|
|
1076
1241
|
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
|
1077
|
-
system: string | undefined;
|
|
1242
|
+
system: string | SystemModelMessage | Array<SystemModelMessage> | undefined;
|
|
1078
1243
|
messages: ModelMessage[];
|
|
1079
1244
|
toolCall: LanguageModelV3ToolCall;
|
|
1080
1245
|
tools: TOOLS;
|
|
@@ -1097,13 +1262,21 @@ Callback that is set using the `onFinish` option.
|
|
|
1097
1262
|
*/
|
|
1098
1263
|
type GenerateTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
|
1099
1264
|
/**
|
|
1100
|
-
Details for all steps.
|
|
1101
|
-
|
|
1265
|
+
* Details for all steps.
|
|
1266
|
+
*/
|
|
1102
1267
|
readonly steps: StepResult<TOOLS>[];
|
|
1103
1268
|
/**
|
|
1104
|
-
Total usage for all steps. This is the sum of the usage of all steps.
|
|
1269
|
+
* Total usage for all steps. This is the sum of the usage of all steps.
|
|
1105
1270
|
*/
|
|
1106
1271
|
readonly totalUsage: LanguageModelUsage;
|
|
1272
|
+
/**
|
|
1273
|
+
* Context that is passed into tool execution.
|
|
1274
|
+
*
|
|
1275
|
+
* Experimental (can break in patch releases).
|
|
1276
|
+
*
|
|
1277
|
+
* @default undefined
|
|
1278
|
+
*/
|
|
1279
|
+
experimental_context: unknown;
|
|
1107
1280
|
}) => PromiseLike<void> | void;
|
|
1108
1281
|
/**
|
|
1109
1282
|
Generate a text and call tools for a given prompt using a language model.
|
|
@@ -1294,288 +1467,58 @@ declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _int
|
|
|
1294
1467
|
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
|
1295
1468
|
|
|
1296
1469
|
/**
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
@param stopStream - A function that stops the source stream.
|
|
1300
|
-
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
1470
|
+
* Tool output when the tool execution has been denied (for static tools).
|
|
1301
1471
|
*/
|
|
1302
|
-
type
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1472
|
+
type StaticToolOutputDenied<TOOLS extends ToolSet> = ValueOf<{
|
|
1473
|
+
[NAME in keyof TOOLS]: {
|
|
1474
|
+
type: 'tool-output-denied';
|
|
1475
|
+
toolCallId: string;
|
|
1476
|
+
toolName: NAME & string;
|
|
1477
|
+
providerExecuted?: boolean;
|
|
1478
|
+
dynamic?: false | undefined;
|
|
1479
|
+
};
|
|
1480
|
+
}>;
|
|
1306
1481
|
/**
|
|
1307
|
-
|
|
1482
|
+
* Tool output when the tool execution has been denied.
|
|
1483
|
+
*/
|
|
1484
|
+
type TypedToolOutputDenied<TOOLS extends ToolSet> = StaticToolOutputDenied<TOOLS>;
|
|
1308
1485
|
|
|
1309
|
-
|
|
1486
|
+
/**
|
|
1487
|
+
The data types that can be used in the UI message for the UI message data parts.
|
|
1310
1488
|
*/
|
|
1311
|
-
type
|
|
1312
|
-
|
|
1313
|
-
|
|
1489
|
+
type UIDataTypes = Record<string, unknown>;
|
|
1490
|
+
type UITool = {
|
|
1491
|
+
input: unknown;
|
|
1492
|
+
output: unknown | undefined;
|
|
1493
|
+
};
|
|
1314
1494
|
/**
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
@param stepResult - The result of the step.
|
|
1495
|
+
* Infer the input and output types of a tool so it can be used as a UI tool.
|
|
1318
1496
|
*/
|
|
1319
|
-
type
|
|
1497
|
+
type InferUITool<TOOL extends Tool> = {
|
|
1498
|
+
input: InferToolInput<TOOL>;
|
|
1499
|
+
output: InferToolOutput<TOOL>;
|
|
1500
|
+
};
|
|
1320
1501
|
/**
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
@param event - The event that is passed to the callback.
|
|
1502
|
+
* Infer the input and output types of a tool set so it can be used as a UI tool set.
|
|
1324
1503
|
*/
|
|
1325
|
-
type
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
}) => PromiseLike<void> | void;
|
|
1504
|
+
type InferUITools<TOOLS extends ToolSet> = {
|
|
1505
|
+
[NAME in keyof TOOLS & string]: InferUITool<TOOLS[NAME]>;
|
|
1506
|
+
};
|
|
1507
|
+
type UITools = Record<string, UITool>;
|
|
1330
1508
|
/**
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
@param event - The event that is passed to the callback.
|
|
1509
|
+
AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
|
1334
1510
|
*/
|
|
1335
|
-
|
|
1511
|
+
interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
|
|
1336
1512
|
/**
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1513
|
+
A unique identifier for the message.
|
|
1514
|
+
*/
|
|
1515
|
+
id: string;
|
|
1340
1516
|
/**
|
|
1341
|
-
|
|
1517
|
+
The role of the message.
|
|
1342
1518
|
*/
|
|
1343
|
-
|
|
1344
|
-
}) => PromiseLike<void> | void;
|
|
1345
|
-
/**
|
|
1346
|
-
Callback that is set using the `onAbort` option.
|
|
1347
|
-
|
|
1348
|
-
@param event - The event that is passed to the callback.
|
|
1349
|
-
*/
|
|
1350
|
-
type StreamTextOnAbortCallback<TOOLS extends ToolSet> = (event: {
|
|
1519
|
+
role: 'system' | 'user' | 'assistant';
|
|
1351
1520
|
/**
|
|
1352
|
-
|
|
1353
|
-
*/
|
|
1354
|
-
readonly steps: StepResult<TOOLS>[];
|
|
1355
|
-
}) => PromiseLike<void> | void;
|
|
1356
|
-
/**
|
|
1357
|
-
Generate a text and call tools for a given prompt using a language model.
|
|
1358
|
-
|
|
1359
|
-
This function streams the output. If you do not want to stream the output, use `generateText` instead.
|
|
1360
|
-
|
|
1361
|
-
@param model - The language model to use.
|
|
1362
|
-
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
1363
|
-
|
|
1364
|
-
@param system - A system message that will be part of the prompt.
|
|
1365
|
-
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
|
1366
|
-
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
|
1367
|
-
|
|
1368
|
-
@param maxOutputTokens - Maximum number of tokens to generate.
|
|
1369
|
-
@param temperature - Temperature setting.
|
|
1370
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1371
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
|
1372
|
-
@param topP - Nucleus sampling.
|
|
1373
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1374
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
|
1375
|
-
@param topK - Only sample from the top K options for each subsequent token.
|
|
1376
|
-
Used to remove "long tail" low probability responses.
|
|
1377
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
|
1378
|
-
@param presencePenalty - Presence penalty setting.
|
|
1379
|
-
It affects the likelihood of the model to repeat information that is already in the prompt.
|
|
1380
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1381
|
-
@param frequencyPenalty - Frequency penalty setting.
|
|
1382
|
-
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
|
1383
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1384
|
-
@param stopSequences - Stop sequences.
|
|
1385
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
|
1386
|
-
@param seed - The seed (integer) to use for random sampling.
|
|
1387
|
-
If set and supported by the model, calls will generate deterministic results.
|
|
1388
|
-
|
|
1389
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
1390
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
1391
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
1392
|
-
|
|
1393
|
-
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
|
1394
|
-
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
|
1395
|
-
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
1396
|
-
@param onFinish - Callback that is called when all steps are finished and the response is complete.
|
|
1397
|
-
|
|
1398
|
-
@return
|
|
1399
|
-
A result object for accessing different stream types and additional information.
|
|
1400
|
-
*/
|
|
1401
|
-
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
1402
|
-
/**
|
|
1403
|
-
The language model to use.
|
|
1404
|
-
*/
|
|
1405
|
-
model: LanguageModel;
|
|
1406
|
-
/**
|
|
1407
|
-
The tools that the model can call. The model needs to support calling tools.
|
|
1408
|
-
*/
|
|
1409
|
-
tools?: TOOLS;
|
|
1410
|
-
/**
|
|
1411
|
-
The tool choice strategy. Default: 'auto'.
|
|
1412
|
-
*/
|
|
1413
|
-
toolChoice?: ToolChoice<TOOLS>;
|
|
1414
|
-
/**
|
|
1415
|
-
Condition for stopping the generation when there are tool results in the last step.
|
|
1416
|
-
When the condition is an array, any of the conditions can be met to stop the generation.
|
|
1417
|
-
|
|
1418
|
-
@default stepCountIs(1)
|
|
1419
|
-
*/
|
|
1420
|
-
stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
|
|
1421
|
-
/**
|
|
1422
|
-
Optional telemetry configuration (experimental).
|
|
1423
|
-
*/
|
|
1424
|
-
experimental_telemetry?: TelemetrySettings;
|
|
1425
|
-
/**
|
|
1426
|
-
Additional provider-specific options. They are passed through
|
|
1427
|
-
to the provider from the AI SDK and enable provider-specific
|
|
1428
|
-
functionality that can be fully encapsulated in the provider.
|
|
1429
|
-
*/
|
|
1430
|
-
providerOptions?: ProviderOptions;
|
|
1431
|
-
/**
|
|
1432
|
-
* @deprecated Use `activeTools` instead.
|
|
1433
|
-
*/
|
|
1434
|
-
experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1435
|
-
/**
|
|
1436
|
-
Limits the tools that are available for the model to call without
|
|
1437
|
-
changing the tool call and result types in the result.
|
|
1438
|
-
*/
|
|
1439
|
-
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1440
|
-
/**
|
|
1441
|
-
Optional specification for parsing structured outputs from the LLM response.
|
|
1442
|
-
*/
|
|
1443
|
-
output?: OUTPUT;
|
|
1444
|
-
/**
|
|
1445
|
-
Optional specification for parsing structured outputs from the LLM response.
|
|
1446
|
-
|
|
1447
|
-
@deprecated Use `output` instead.
|
|
1448
|
-
*/
|
|
1449
|
-
experimental_output?: OUTPUT;
|
|
1450
|
-
/**
|
|
1451
|
-
Optional function that you can use to provide different settings for a step.
|
|
1452
|
-
|
|
1453
|
-
@param options - The options for the step.
|
|
1454
|
-
@param options.steps - The steps that have been executed so far.
|
|
1455
|
-
@param options.stepNumber - The number of the step that is being executed.
|
|
1456
|
-
@param options.model - The model that is being used.
|
|
1457
|
-
|
|
1458
|
-
@returns An object that contains the settings for the step.
|
|
1459
|
-
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
1460
|
-
*/
|
|
1461
|
-
prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
|
1462
|
-
/**
|
|
1463
|
-
A function that attempts to repair a tool call that failed to parse.
|
|
1464
|
-
*/
|
|
1465
|
-
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
|
1466
|
-
/**
|
|
1467
|
-
Optional stream transformations.
|
|
1468
|
-
They are applied in the order they are provided.
|
|
1469
|
-
The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
1470
|
-
*/
|
|
1471
|
-
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
1472
|
-
/**
|
|
1473
|
-
Custom download function to use for URLs.
|
|
1474
|
-
|
|
1475
|
-
By default, files are downloaded if the model does not support the URL for the given media type.
|
|
1476
|
-
*/
|
|
1477
|
-
experimental_download?: DownloadFunction | undefined;
|
|
1478
|
-
/**
|
|
1479
|
-
Whether to include raw chunks from the provider in the stream.
|
|
1480
|
-
When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
|
|
1481
|
-
This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
|
|
1482
|
-
Defaults to false.
|
|
1483
|
-
*/
|
|
1484
|
-
includeRawChunks?: boolean;
|
|
1485
|
-
/**
|
|
1486
|
-
Callback that is called for each chunk of the stream.
|
|
1487
|
-
The stream processing will pause until the callback promise is resolved.
|
|
1488
|
-
*/
|
|
1489
|
-
onChunk?: StreamTextOnChunkCallback<TOOLS>;
|
|
1490
|
-
/**
|
|
1491
|
-
Callback that is invoked when an error occurs during streaming.
|
|
1492
|
-
You can use it to log errors.
|
|
1493
|
-
The stream processing will pause until the callback promise is resolved.
|
|
1494
|
-
*/
|
|
1495
|
-
onError?: StreamTextOnErrorCallback;
|
|
1496
|
-
/**
|
|
1497
|
-
Callback that is called when the LLM response and all request tool executions
|
|
1498
|
-
(for tools that have an `execute` function) are finished.
|
|
1499
|
-
|
|
1500
|
-
The usage is the combined usage of all steps.
|
|
1501
|
-
*/
|
|
1502
|
-
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
|
1503
|
-
onAbort?: StreamTextOnAbortCallback<TOOLS>;
|
|
1504
|
-
/**
|
|
1505
|
-
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
1506
|
-
*/
|
|
1507
|
-
onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
|
|
1508
|
-
/**
|
|
1509
|
-
* Context that is passed into tool execution.
|
|
1510
|
-
*
|
|
1511
|
-
* Experimental (can break in patch releases).
|
|
1512
|
-
*
|
|
1513
|
-
* @default undefined
|
|
1514
|
-
*/
|
|
1515
|
-
experimental_context?: unknown;
|
|
1516
|
-
/**
|
|
1517
|
-
Internal. For test use only. May change without notice.
|
|
1518
|
-
*/
|
|
1519
|
-
_internal?: {
|
|
1520
|
-
now?: () => number;
|
|
1521
|
-
generateId?: IdGenerator;
|
|
1522
|
-
currentDate?: () => Date;
|
|
1523
|
-
};
|
|
1524
|
-
}): StreamTextResult<TOOLS, OUTPUT>;
|
|
1525
|
-
|
|
1526
|
-
/**
|
|
1527
|
-
* Tool output when the tool execution has been denied (for static tools).
|
|
1528
|
-
*/
|
|
1529
|
-
type StaticToolOutputDenied<TOOLS extends ToolSet> = ValueOf<{
|
|
1530
|
-
[NAME in keyof TOOLS]: {
|
|
1531
|
-
type: 'tool-output-denied';
|
|
1532
|
-
toolCallId: string;
|
|
1533
|
-
toolName: NAME & string;
|
|
1534
|
-
providerExecuted?: boolean;
|
|
1535
|
-
dynamic?: false | undefined;
|
|
1536
|
-
};
|
|
1537
|
-
}>;
|
|
1538
|
-
/**
|
|
1539
|
-
* Tool output when the tool execution has been denied.
|
|
1540
|
-
*/
|
|
1541
|
-
type TypedToolOutputDenied<TOOLS extends ToolSet> = StaticToolOutputDenied<TOOLS>;
|
|
1542
|
-
|
|
1543
|
-
/**
|
|
1544
|
-
The data types that can be used in the UI message for the UI message data parts.
|
|
1545
|
-
*/
|
|
1546
|
-
type UIDataTypes = Record<string, unknown>;
|
|
1547
|
-
type UITool = {
|
|
1548
|
-
input: unknown;
|
|
1549
|
-
output: unknown | undefined;
|
|
1550
|
-
};
|
|
1551
|
-
/**
|
|
1552
|
-
* Infer the input and output types of a tool so it can be used as a UI tool.
|
|
1553
|
-
*/
|
|
1554
|
-
type InferUITool<TOOL extends Tool> = {
|
|
1555
|
-
input: InferToolInput<TOOL>;
|
|
1556
|
-
output: InferToolOutput<TOOL>;
|
|
1557
|
-
};
|
|
1558
|
-
/**
|
|
1559
|
-
* Infer the input and output types of a tool set so it can be used as a UI tool set.
|
|
1560
|
-
*/
|
|
1561
|
-
type InferUITools<TOOLS extends ToolSet> = {
|
|
1562
|
-
[NAME in keyof TOOLS & string]: InferUITool<TOOLS[NAME]>;
|
|
1563
|
-
};
|
|
1564
|
-
type UITools = Record<string, UITool>;
|
|
1565
|
-
/**
|
|
1566
|
-
AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
|
1567
|
-
*/
|
|
1568
|
-
interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
|
|
1569
|
-
/**
|
|
1570
|
-
A unique identifier for the message.
|
|
1571
|
-
*/
|
|
1572
|
-
id: string;
|
|
1573
|
-
/**
|
|
1574
|
-
The role of the message.
|
|
1575
|
-
*/
|
|
1576
|
-
role: 'system' | 'user' | 'assistant';
|
|
1577
|
-
/**
|
|
1578
|
-
The metadata of the message.
|
|
1521
|
+
The metadata of the message.
|
|
1579
1522
|
*/
|
|
1580
1523
|
metadata?: METADATA;
|
|
1581
1524
|
/**
|
|
@@ -1879,10 +1822,41 @@ declare function isFileUIPart(part: UIMessagePart<UIDataTypes, UITools>): part i
|
|
|
1879
1822
|
* Type guard to check if a message part is a reasoning part.
|
|
1880
1823
|
*/
|
|
1881
1824
|
declare function isReasoningUIPart(part: UIMessagePart<UIDataTypes, UITools>): part is ReasoningUIPart;
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1825
|
+
/**
|
|
1826
|
+
* Check if a message part is a static tool part.
|
|
1827
|
+
*
|
|
1828
|
+
* Static tools are tools for which the types are known at development time.
|
|
1829
|
+
*/
|
|
1830
|
+
declare function isStaticToolUIPart<TOOLS extends UITools>(part: UIMessagePart<UIDataTypes, TOOLS>): part is ToolUIPart<TOOLS>;
|
|
1831
|
+
/**
|
|
1832
|
+
* Check if a message part is a tool part.
|
|
1833
|
+
*
|
|
1834
|
+
* Tool parts are either static or dynamic tools.
|
|
1835
|
+
*
|
|
1836
|
+
* Use `isStaticToolUIPart` or `isDynamicToolUIPart` to check the type of the tool.
|
|
1837
|
+
*/
|
|
1838
|
+
declare function isToolUIPart<TOOLS extends UITools>(part: UIMessagePart<UIDataTypes, TOOLS>): part is ToolUIPart<TOOLS> | DynamicToolUIPart;
|
|
1839
|
+
/**
|
|
1840
|
+
* @deprecated Use isToolUIPart instead.
|
|
1841
|
+
*/
|
|
1842
|
+
declare const isToolOrDynamicToolUIPart: typeof isToolUIPart;
|
|
1843
|
+
/**
|
|
1844
|
+
* Returns the name of the static tool.
|
|
1845
|
+
*
|
|
1846
|
+
* The possible values are the keys of the tool set.
|
|
1847
|
+
*/
|
|
1848
|
+
declare function getStaticToolName<TOOLS extends UITools>(part: ToolUIPart<TOOLS>): keyof TOOLS;
|
|
1849
|
+
/**
|
|
1850
|
+
* Returns the name of the tool (static or dynamic).
|
|
1851
|
+
*
|
|
1852
|
+
* This function will not restrict the name to the keys of the tool set.
|
|
1853
|
+
* If you need to restrict the name to the keys of the tool set, use `getStaticToolName` instead.
|
|
1854
|
+
*/
|
|
1855
|
+
declare function getToolName(part: ToolUIPart<UITools> | DynamicToolUIPart): string;
|
|
1856
|
+
/**
|
|
1857
|
+
* @deprecated Use getToolName instead.
|
|
1858
|
+
*/
|
|
1859
|
+
declare const getToolOrDynamicToolName: typeof getToolName;
|
|
1886
1860
|
type InferUIMessageMetadata<T extends UIMessage> = T extends UIMessage<infer METADATA> ? METADATA : unknown;
|
|
1887
1861
|
type InferUIMessageData<T extends UIMessage> = T extends UIMessage<unknown, infer DATA_TYPES> ? DATA_TYPES : UIDataTypes;
|
|
1888
1862
|
type InferUIMessageTools<T extends UIMessage> = T extends UIMessage<unknown, UIDataTypes, infer TOOLS> ? TOOLS : UITools;
|
|
@@ -2008,7 +1982,7 @@ declare const uiMessageChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
2008
1982
|
messageMetadata?: unknown;
|
|
2009
1983
|
} | {
|
|
2010
1984
|
type: "finish";
|
|
2011
|
-
finishReason?: "
|
|
1985
|
+
finishReason?: "length" | "error" | "stop" | "content-filter" | "tool-calls" | "other" | undefined;
|
|
2012
1986
|
messageMetadata?: unknown;
|
|
2013
1987
|
} | {
|
|
2014
1988
|
type: "abort";
|
|
@@ -2245,98 +2219,104 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2245
2219
|
|
|
2246
2220
|
Automatically consumes the stream.
|
|
2247
2221
|
*/
|
|
2248
|
-
readonly content:
|
|
2222
|
+
readonly content: PromiseLike<Array<ContentPart<TOOLS>>>;
|
|
2249
2223
|
/**
|
|
2250
2224
|
The full text that has been generated by the last step.
|
|
2251
2225
|
|
|
2252
2226
|
Automatically consumes the stream.
|
|
2253
2227
|
*/
|
|
2254
|
-
readonly text:
|
|
2228
|
+
readonly text: PromiseLike<string>;
|
|
2255
2229
|
/**
|
|
2256
2230
|
The full reasoning that the model has generated.
|
|
2257
2231
|
|
|
2258
2232
|
Automatically consumes the stream.
|
|
2259
2233
|
*/
|
|
2260
|
-
readonly reasoning:
|
|
2234
|
+
readonly reasoning: PromiseLike<Array<ReasoningOutput>>;
|
|
2261
2235
|
/**
|
|
2262
2236
|
The reasoning that has been generated by the last step.
|
|
2263
2237
|
|
|
2264
2238
|
Automatically consumes the stream.
|
|
2265
2239
|
*/
|
|
2266
|
-
readonly reasoningText:
|
|
2240
|
+
readonly reasoningText: PromiseLike<string | undefined>;
|
|
2267
2241
|
/**
|
|
2268
2242
|
Files that have been generated by the model in the last step.
|
|
2269
2243
|
|
|
2270
2244
|
Automatically consumes the stream.
|
|
2271
2245
|
*/
|
|
2272
|
-
readonly files:
|
|
2246
|
+
readonly files: PromiseLike<GeneratedFile[]>;
|
|
2273
2247
|
/**
|
|
2274
2248
|
Sources that have been used as references in the last step.
|
|
2275
2249
|
|
|
2276
2250
|
Automatically consumes the stream.
|
|
2277
2251
|
*/
|
|
2278
|
-
readonly sources:
|
|
2252
|
+
readonly sources: PromiseLike<Source[]>;
|
|
2279
2253
|
/**
|
|
2280
2254
|
The tool calls that have been executed in the last step.
|
|
2281
2255
|
|
|
2282
2256
|
Automatically consumes the stream.
|
|
2283
2257
|
*/
|
|
2284
|
-
readonly toolCalls:
|
|
2258
|
+
readonly toolCalls: PromiseLike<TypedToolCall<TOOLS>[]>;
|
|
2285
2259
|
/**
|
|
2286
2260
|
The static tool calls that have been executed in the last step.
|
|
2287
2261
|
|
|
2288
2262
|
Automatically consumes the stream.
|
|
2289
2263
|
*/
|
|
2290
|
-
readonly staticToolCalls:
|
|
2264
|
+
readonly staticToolCalls: PromiseLike<StaticToolCall<TOOLS>[]>;
|
|
2291
2265
|
/**
|
|
2292
2266
|
The dynamic tool calls that have been executed in the last step.
|
|
2293
2267
|
|
|
2294
2268
|
Automatically consumes the stream.
|
|
2295
2269
|
*/
|
|
2296
|
-
readonly dynamicToolCalls:
|
|
2270
|
+
readonly dynamicToolCalls: PromiseLike<DynamicToolCall[]>;
|
|
2297
2271
|
/**
|
|
2298
2272
|
The static tool results that have been generated in the last step.
|
|
2299
2273
|
|
|
2300
2274
|
Automatically consumes the stream.
|
|
2301
2275
|
*/
|
|
2302
|
-
readonly staticToolResults:
|
|
2276
|
+
readonly staticToolResults: PromiseLike<StaticToolResult<TOOLS>[]>;
|
|
2303
2277
|
/**
|
|
2304
2278
|
The dynamic tool results that have been generated in the last step.
|
|
2305
2279
|
|
|
2306
2280
|
Automatically consumes the stream.
|
|
2307
2281
|
*/
|
|
2308
|
-
readonly dynamicToolResults:
|
|
2282
|
+
readonly dynamicToolResults: PromiseLike<DynamicToolResult[]>;
|
|
2309
2283
|
/**
|
|
2310
2284
|
The tool results that have been generated in the last step.
|
|
2311
2285
|
|
|
2312
2286
|
Automatically consumes the stream.
|
|
2313
2287
|
*/
|
|
2314
|
-
readonly toolResults:
|
|
2288
|
+
readonly toolResults: PromiseLike<TypedToolResult<TOOLS>[]>;
|
|
2315
2289
|
/**
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
readonly finishReason:
|
|
2290
|
+
* The unified finish reason why the generation finished. Taken from the last step.
|
|
2291
|
+
*
|
|
2292
|
+
* Automatically consumes the stream.
|
|
2293
|
+
*/
|
|
2294
|
+
readonly finishReason: PromiseLike<FinishReason>;
|
|
2295
|
+
/**
|
|
2296
|
+
* The raw reason why the generation finished (from the provider). Taken from the last step.
|
|
2297
|
+
*
|
|
2298
|
+
* Automatically consumes the stream.
|
|
2299
|
+
*/
|
|
2300
|
+
readonly rawFinishReason: PromiseLike<string | undefined>;
|
|
2321
2301
|
/**
|
|
2322
2302
|
The token usage of the last step.
|
|
2323
2303
|
|
|
2324
2304
|
Automatically consumes the stream.
|
|
2325
2305
|
*/
|
|
2326
|
-
readonly usage:
|
|
2306
|
+
readonly usage: PromiseLike<LanguageModelUsage>;
|
|
2327
2307
|
/**
|
|
2328
2308
|
The total token usage of the generated response.
|
|
2329
2309
|
When there are multiple steps, the usage is the sum of all step usages.
|
|
2330
2310
|
|
|
2331
2311
|
Automatically consumes the stream.
|
|
2332
2312
|
*/
|
|
2333
|
-
readonly totalUsage:
|
|
2313
|
+
readonly totalUsage: PromiseLike<LanguageModelUsage>;
|
|
2334
2314
|
/**
|
|
2335
2315
|
Warnings from the model provider (e.g. unsupported settings) for the first step.
|
|
2336
2316
|
|
|
2337
2317
|
Automatically consumes the stream.
|
|
2338
2318
|
*/
|
|
2339
|
-
readonly warnings:
|
|
2319
|
+
readonly warnings: PromiseLike<CallWarning[] | undefined>;
|
|
2340
2320
|
/**
|
|
2341
2321
|
Details for all steps.
|
|
2342
2322
|
You can use this to get information about intermediate steps,
|
|
@@ -2344,19 +2324,19 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2344
2324
|
|
|
2345
2325
|
Automatically consumes the stream.
|
|
2346
2326
|
*/
|
|
2347
|
-
readonly steps:
|
|
2327
|
+
readonly steps: PromiseLike<Array<StepResult<TOOLS>>>;
|
|
2348
2328
|
/**
|
|
2349
2329
|
Additional request information from the last step.
|
|
2350
2330
|
|
|
2351
2331
|
Automatically consumes the stream.
|
|
2352
2332
|
*/
|
|
2353
|
-
readonly request:
|
|
2333
|
+
readonly request: PromiseLike<LanguageModelRequestMetadata>;
|
|
2354
2334
|
/**
|
|
2355
2335
|
Additional response information from the last step.
|
|
2356
2336
|
|
|
2357
2337
|
Automatically consumes the stream.
|
|
2358
2338
|
*/
|
|
2359
|
-
readonly response:
|
|
2339
|
+
readonly response: PromiseLike<LanguageModelResponseMetadata & {
|
|
2360
2340
|
/**
|
|
2361
2341
|
The response messages that were generated during the call. It consists of an assistant message,
|
|
2362
2342
|
potentially containing tool calls.
|
|
@@ -2372,7 +2352,7 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2372
2352
|
Metadata is passed through from the provider to the AI SDK and
|
|
2373
2353
|
enables provider-specific results that can be fully encapsulated in the provider.
|
|
2374
2354
|
*/
|
|
2375
|
-
readonly providerMetadata:
|
|
2355
|
+
readonly providerMetadata: PromiseLike<ProviderMetadata | undefined>;
|
|
2376
2356
|
/**
|
|
2377
2357
|
A text stream that returns only the generated text deltas. You can use it
|
|
2378
2358
|
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
|
@@ -2399,7 +2379,7 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2399
2379
|
/**
|
|
2400
2380
|
* The complete parsed output. It uses the `output` specification.
|
|
2401
2381
|
*/
|
|
2402
|
-
readonly output:
|
|
2382
|
+
readonly output: PromiseLike<InferCompleteOutput<OUTPUT>>;
|
|
2403
2383
|
/**
|
|
2404
2384
|
Consumes the stream without processing the parts.
|
|
2405
2385
|
This is useful to force the stream to finish.
|
|
@@ -2408,7 +2388,7 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2408
2388
|
|
|
2409
2389
|
If an error occurs, it is passed to the optional `onError` callback.
|
|
2410
2390
|
*/
|
|
2411
|
-
consumeStream(options?: ConsumeStreamOptions):
|
|
2391
|
+
consumeStream(options?: ConsumeStreamOptions): PromiseLike<void>;
|
|
2412
2392
|
/**
|
|
2413
2393
|
Converts the result to a UI message stream.
|
|
2414
2394
|
|
|
@@ -2416,114 +2396,357 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2416
2396
|
*/
|
|
2417
2397
|
toUIMessageStream<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamOptions<UI_MESSAGE>): AsyncIterableStream<InferUIMessageChunk<UI_MESSAGE>>;
|
|
2418
2398
|
/**
|
|
2419
|
-
*Writes UI message stream output to a Node.js response-like object.
|
|
2399
|
+
*Writes UI message stream output to a Node.js response-like object.
|
|
2400
|
+
*/
|
|
2401
|
+
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): void;
|
|
2402
|
+
/**
|
|
2403
|
+
Writes text delta output to a Node.js response-like object.
|
|
2404
|
+
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
|
2405
|
+
writes each text delta as a separate chunk.
|
|
2406
|
+
|
|
2407
|
+
@param response A Node.js response-like object (ServerResponse).
|
|
2408
|
+
@param init Optional headers, status code, and status text.
|
|
2409
|
+
*/
|
|
2410
|
+
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
|
|
2411
|
+
/**
|
|
2412
|
+
Converts the result to a streamed response object with a stream data part stream.
|
|
2413
|
+
|
|
2414
|
+
@return A response object.
|
|
2415
|
+
*/
|
|
2416
|
+
toUIMessageStreamResponse<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): Response;
|
|
2417
|
+
/**
|
|
2418
|
+
Creates a simple text stream response.
|
|
2419
|
+
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
|
2420
|
+
Non-text-delta events are ignored.
|
|
2421
|
+
@param init Optional headers, status code, and status text.
|
|
2422
|
+
*/
|
|
2423
|
+
toTextStreamResponse(init?: ResponseInit): Response;
|
|
2424
|
+
}
|
|
2425
|
+
type TextStreamPart<TOOLS extends ToolSet> = {
|
|
2426
|
+
type: 'text-start';
|
|
2427
|
+
id: string;
|
|
2428
|
+
providerMetadata?: ProviderMetadata;
|
|
2429
|
+
} | {
|
|
2430
|
+
type: 'text-end';
|
|
2431
|
+
id: string;
|
|
2432
|
+
providerMetadata?: ProviderMetadata;
|
|
2433
|
+
} | {
|
|
2434
|
+
type: 'text-delta';
|
|
2435
|
+
id: string;
|
|
2436
|
+
providerMetadata?: ProviderMetadata;
|
|
2437
|
+
text: string;
|
|
2438
|
+
} | {
|
|
2439
|
+
type: 'reasoning-start';
|
|
2440
|
+
id: string;
|
|
2441
|
+
providerMetadata?: ProviderMetadata;
|
|
2442
|
+
} | {
|
|
2443
|
+
type: 'reasoning-end';
|
|
2444
|
+
id: string;
|
|
2445
|
+
providerMetadata?: ProviderMetadata;
|
|
2446
|
+
} | {
|
|
2447
|
+
type: 'reasoning-delta';
|
|
2448
|
+
providerMetadata?: ProviderMetadata;
|
|
2449
|
+
id: string;
|
|
2450
|
+
text: string;
|
|
2451
|
+
} | {
|
|
2452
|
+
type: 'tool-input-start';
|
|
2453
|
+
id: string;
|
|
2454
|
+
toolName: string;
|
|
2455
|
+
providerMetadata?: ProviderMetadata;
|
|
2456
|
+
providerExecuted?: boolean;
|
|
2457
|
+
dynamic?: boolean;
|
|
2458
|
+
title?: string;
|
|
2459
|
+
} | {
|
|
2460
|
+
type: 'tool-input-end';
|
|
2461
|
+
id: string;
|
|
2462
|
+
providerMetadata?: ProviderMetadata;
|
|
2463
|
+
} | {
|
|
2464
|
+
type: 'tool-input-delta';
|
|
2465
|
+
id: string;
|
|
2466
|
+
delta: string;
|
|
2467
|
+
providerMetadata?: ProviderMetadata;
|
|
2468
|
+
} | ({
|
|
2469
|
+
type: 'source';
|
|
2470
|
+
} & Source) | {
|
|
2471
|
+
type: 'file';
|
|
2472
|
+
file: GeneratedFile;
|
|
2473
|
+
} | ({
|
|
2474
|
+
type: 'tool-call';
|
|
2475
|
+
} & TypedToolCall<TOOLS>) | ({
|
|
2476
|
+
type: 'tool-result';
|
|
2477
|
+
} & TypedToolResult<TOOLS>) | ({
|
|
2478
|
+
type: 'tool-error';
|
|
2479
|
+
} & TypedToolError<TOOLS>) | ({
|
|
2480
|
+
type: 'tool-output-denied';
|
|
2481
|
+
} & StaticToolOutputDenied<TOOLS>) | ToolApprovalRequestOutput<TOOLS> | {
|
|
2482
|
+
type: 'start-step';
|
|
2483
|
+
request: LanguageModelRequestMetadata;
|
|
2484
|
+
warnings: CallWarning[];
|
|
2485
|
+
} | {
|
|
2486
|
+
type: 'finish-step';
|
|
2487
|
+
response: LanguageModelResponseMetadata;
|
|
2488
|
+
usage: LanguageModelUsage;
|
|
2489
|
+
finishReason: FinishReason;
|
|
2490
|
+
rawFinishReason: string | undefined;
|
|
2491
|
+
providerMetadata: ProviderMetadata | undefined;
|
|
2492
|
+
} | {
|
|
2493
|
+
type: 'start';
|
|
2494
|
+
} | {
|
|
2495
|
+
type: 'finish';
|
|
2496
|
+
finishReason: FinishReason;
|
|
2497
|
+
rawFinishReason: string | undefined;
|
|
2498
|
+
totalUsage: LanguageModelUsage;
|
|
2499
|
+
} | {
|
|
2500
|
+
type: 'abort';
|
|
2501
|
+
} | {
|
|
2502
|
+
type: 'error';
|
|
2503
|
+
error: unknown;
|
|
2504
|
+
} | {
|
|
2505
|
+
type: 'raw';
|
|
2506
|
+
rawValue: unknown;
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2509
|
+
/**
|
|
2510
|
+
A transformation that is applied to the stream.
|
|
2511
|
+
|
|
2512
|
+
@param stopStream - A function that stops the source stream.
|
|
2513
|
+
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
2514
|
+
*/
|
|
2515
|
+
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
|
2516
|
+
tools: TOOLS;
|
|
2517
|
+
stopStream: () => void;
|
|
2518
|
+
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
|
2519
|
+
/**
|
|
2520
|
+
Callback that is set using the `onError` option.
|
|
2521
|
+
|
|
2522
|
+
@param event - The event that is passed to the callback.
|
|
2523
|
+
*/
|
|
2524
|
+
type StreamTextOnErrorCallback = (event: {
|
|
2525
|
+
error: unknown;
|
|
2526
|
+
}) => PromiseLike<void> | void;
|
|
2527
|
+
/**
|
|
2528
|
+
Callback that is set using the `onStepFinish` option.
|
|
2529
|
+
|
|
2530
|
+
@param stepResult - The result of the step.
|
|
2531
|
+
*/
|
|
2532
|
+
type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => PromiseLike<void> | void;
|
|
2533
|
+
/**
|
|
2534
|
+
Callback that is set using the `onChunk` option.
|
|
2535
|
+
|
|
2536
|
+
@param event - The event that is passed to the callback.
|
|
2537
|
+
*/
|
|
2538
|
+
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
|
2539
|
+
chunk: Extract<TextStreamPart<TOOLS>, {
|
|
2540
|
+
type: 'text-delta' | 'reasoning-delta' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
|
2541
|
+
}>;
|
|
2542
|
+
}) => PromiseLike<void> | void;
|
|
2543
|
+
/**
|
|
2544
|
+
Callback that is set using the `onFinish` option.
|
|
2545
|
+
|
|
2546
|
+
@param event - The event that is passed to the callback.
|
|
2547
|
+
*/
|
|
2548
|
+
type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
|
2549
|
+
/**
|
|
2550
|
+
* Details for all steps.
|
|
2551
|
+
*/
|
|
2552
|
+
readonly steps: StepResult<TOOLS>[];
|
|
2553
|
+
/**
|
|
2554
|
+
* Total usage for all steps. This is the sum of the usage of all steps.
|
|
2555
|
+
*/
|
|
2556
|
+
readonly totalUsage: LanguageModelUsage;
|
|
2557
|
+
/**
|
|
2558
|
+
* Context that is passed into tool execution.
|
|
2559
|
+
*
|
|
2560
|
+
* Experimental (can break in patch releases).
|
|
2561
|
+
*
|
|
2562
|
+
* @default undefined
|
|
2563
|
+
*/
|
|
2564
|
+
experimental_context: unknown;
|
|
2565
|
+
}) => PromiseLike<void> | void;
|
|
2566
|
+
/**
|
|
2567
|
+
Callback that is set using the `onAbort` option.
|
|
2568
|
+
|
|
2569
|
+
@param event - The event that is passed to the callback.
|
|
2570
|
+
*/
|
|
2571
|
+
type StreamTextOnAbortCallback<TOOLS extends ToolSet> = (event: {
|
|
2572
|
+
/**
|
|
2573
|
+
Details for all previously finished steps.
|
|
2574
|
+
*/
|
|
2575
|
+
readonly steps: StepResult<TOOLS>[];
|
|
2576
|
+
}) => PromiseLike<void> | void;
|
|
2577
|
+
/**
|
|
2578
|
+
Generate a text and call tools for a given prompt using a language model.
|
|
2579
|
+
|
|
2580
|
+
This function streams the output. If you do not want to stream the output, use `generateText` instead.
|
|
2581
|
+
|
|
2582
|
+
@param model - The language model to use.
|
|
2583
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
2584
|
+
|
|
2585
|
+
@param system - A system message that will be part of the prompt.
|
|
2586
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
|
2587
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
|
2588
|
+
|
|
2589
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
|
2590
|
+
@param temperature - Temperature setting.
|
|
2591
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2592
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
|
2593
|
+
@param topP - Nucleus sampling.
|
|
2594
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2595
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
|
2596
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
|
2597
|
+
Used to remove "long tail" low probability responses.
|
|
2598
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
|
2599
|
+
@param presencePenalty - Presence penalty setting.
|
|
2600
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
|
2601
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2602
|
+
@param frequencyPenalty - Frequency penalty setting.
|
|
2603
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
|
2604
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2605
|
+
@param stopSequences - Stop sequences.
|
|
2606
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
|
2607
|
+
@param seed - The seed (integer) to use for random sampling.
|
|
2608
|
+
If set and supported by the model, calls will generate deterministic results.
|
|
2609
|
+
|
|
2610
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
2611
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
2612
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
2613
|
+
|
|
2614
|
+
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
|
2615
|
+
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
|
2616
|
+
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
2617
|
+
@param onFinish - Callback that is called when all steps are finished and the response is complete.
|
|
2618
|
+
|
|
2619
|
+
@return
|
|
2620
|
+
A result object for accessing different stream types and additional information.
|
|
2621
|
+
*/
|
|
2622
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
2623
|
+
/**
|
|
2624
|
+
The language model to use.
|
|
2625
|
+
*/
|
|
2626
|
+
model: LanguageModel;
|
|
2627
|
+
/**
|
|
2628
|
+
The tools that the model can call. The model needs to support calling tools.
|
|
2629
|
+
*/
|
|
2630
|
+
tools?: TOOLS;
|
|
2631
|
+
/**
|
|
2632
|
+
The tool choice strategy. Default: 'auto'.
|
|
2633
|
+
*/
|
|
2634
|
+
toolChoice?: ToolChoice<TOOLS>;
|
|
2635
|
+
/**
|
|
2636
|
+
Condition for stopping the generation when there are tool results in the last step.
|
|
2637
|
+
When the condition is an array, any of the conditions can be met to stop the generation.
|
|
2638
|
+
|
|
2639
|
+
@default stepCountIs(1)
|
|
2640
|
+
*/
|
|
2641
|
+
stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
|
|
2642
|
+
/**
|
|
2643
|
+
Optional telemetry configuration (experimental).
|
|
2644
|
+
*/
|
|
2645
|
+
experimental_telemetry?: TelemetrySettings;
|
|
2646
|
+
/**
|
|
2647
|
+
Additional provider-specific options. They are passed through
|
|
2648
|
+
to the provider from the AI SDK and enable provider-specific
|
|
2649
|
+
functionality that can be fully encapsulated in the provider.
|
|
2650
|
+
*/
|
|
2651
|
+
providerOptions?: ProviderOptions;
|
|
2652
|
+
/**
|
|
2653
|
+
* @deprecated Use `activeTools` instead.
|
|
2654
|
+
*/
|
|
2655
|
+
experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
2656
|
+
/**
|
|
2657
|
+
Limits the tools that are available for the model to call without
|
|
2658
|
+
changing the tool call and result types in the result.
|
|
2659
|
+
*/
|
|
2660
|
+
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
2661
|
+
/**
|
|
2662
|
+
Optional specification for parsing structured outputs from the LLM response.
|
|
2663
|
+
*/
|
|
2664
|
+
output?: OUTPUT;
|
|
2665
|
+
/**
|
|
2666
|
+
Optional specification for parsing structured outputs from the LLM response.
|
|
2667
|
+
|
|
2668
|
+
@deprecated Use `output` instead.
|
|
2669
|
+
*/
|
|
2670
|
+
experimental_output?: OUTPUT;
|
|
2671
|
+
/**
|
|
2672
|
+
Optional function that you can use to provide different settings for a step.
|
|
2673
|
+
|
|
2674
|
+
@param options - The options for the step.
|
|
2675
|
+
@param options.steps - The steps that have been executed so far.
|
|
2676
|
+
@param options.stepNumber - The number of the step that is being executed.
|
|
2677
|
+
@param options.model - The model that is being used.
|
|
2678
|
+
|
|
2679
|
+
@returns An object that contains the settings for the step.
|
|
2680
|
+
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
2681
|
+
*/
|
|
2682
|
+
prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
|
2683
|
+
/**
|
|
2684
|
+
A function that attempts to repair a tool call that failed to parse.
|
|
2685
|
+
*/
|
|
2686
|
+
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
|
2687
|
+
/**
|
|
2688
|
+
Optional stream transformations.
|
|
2689
|
+
They are applied in the order they are provided.
|
|
2690
|
+
The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
2691
|
+
*/
|
|
2692
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
2693
|
+
/**
|
|
2694
|
+
Custom download function to use for URLs.
|
|
2695
|
+
|
|
2696
|
+
By default, files are downloaded if the model does not support the URL for the given media type.
|
|
2697
|
+
*/
|
|
2698
|
+
experimental_download?: DownloadFunction | undefined;
|
|
2699
|
+
/**
|
|
2700
|
+
Whether to include raw chunks from the provider in the stream.
|
|
2701
|
+
When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
|
|
2702
|
+
This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
|
|
2703
|
+
Defaults to false.
|
|
2704
|
+
*/
|
|
2705
|
+
includeRawChunks?: boolean;
|
|
2706
|
+
/**
|
|
2707
|
+
Callback that is called for each chunk of the stream.
|
|
2708
|
+
The stream processing will pause until the callback promise is resolved.
|
|
2709
|
+
*/
|
|
2710
|
+
onChunk?: StreamTextOnChunkCallback<TOOLS>;
|
|
2711
|
+
/**
|
|
2712
|
+
Callback that is invoked when an error occurs during streaming.
|
|
2713
|
+
You can use it to log errors.
|
|
2714
|
+
The stream processing will pause until the callback promise is resolved.
|
|
2715
|
+
*/
|
|
2716
|
+
onError?: StreamTextOnErrorCallback;
|
|
2717
|
+
/**
|
|
2718
|
+
Callback that is called when the LLM response and all request tool executions
|
|
2719
|
+
(for tools that have an `execute` function) are finished.
|
|
2720
|
+
|
|
2721
|
+
The usage is the combined usage of all steps.
|
|
2420
2722
|
*/
|
|
2421
|
-
|
|
2723
|
+
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
|
2724
|
+
onAbort?: StreamTextOnAbortCallback<TOOLS>;
|
|
2422
2725
|
/**
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
@param response A Node.js response-like object (ServerResponse).
|
|
2428
|
-
@param init Optional headers, status code, and status text.
|
|
2429
|
-
*/
|
|
2430
|
-
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
|
|
2726
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
2727
|
+
*/
|
|
2728
|
+
onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
|
|
2431
2729
|
/**
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2730
|
+
* Context that is passed into tool execution.
|
|
2731
|
+
*
|
|
2732
|
+
* Experimental (can break in patch releases).
|
|
2733
|
+
*
|
|
2734
|
+
* @default undefined
|
|
2735
|
+
*/
|
|
2736
|
+
experimental_context?: unknown;
|
|
2437
2737
|
/**
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
type: 'text-start';
|
|
2447
|
-
id: string;
|
|
2448
|
-
providerMetadata?: ProviderMetadata;
|
|
2449
|
-
} | {
|
|
2450
|
-
type: 'text-end';
|
|
2451
|
-
id: string;
|
|
2452
|
-
providerMetadata?: ProviderMetadata;
|
|
2453
|
-
} | {
|
|
2454
|
-
type: 'text-delta';
|
|
2455
|
-
id: string;
|
|
2456
|
-
providerMetadata?: ProviderMetadata;
|
|
2457
|
-
text: string;
|
|
2458
|
-
} | {
|
|
2459
|
-
type: 'reasoning-start';
|
|
2460
|
-
id: string;
|
|
2461
|
-
providerMetadata?: ProviderMetadata;
|
|
2462
|
-
} | {
|
|
2463
|
-
type: 'reasoning-end';
|
|
2464
|
-
id: string;
|
|
2465
|
-
providerMetadata?: ProviderMetadata;
|
|
2466
|
-
} | {
|
|
2467
|
-
type: 'reasoning-delta';
|
|
2468
|
-
providerMetadata?: ProviderMetadata;
|
|
2469
|
-
id: string;
|
|
2470
|
-
text: string;
|
|
2471
|
-
} | {
|
|
2472
|
-
type: 'tool-input-start';
|
|
2473
|
-
id: string;
|
|
2474
|
-
toolName: string;
|
|
2475
|
-
providerMetadata?: ProviderMetadata;
|
|
2476
|
-
providerExecuted?: boolean;
|
|
2477
|
-
dynamic?: boolean;
|
|
2478
|
-
title?: string;
|
|
2479
|
-
} | {
|
|
2480
|
-
type: 'tool-input-end';
|
|
2481
|
-
id: string;
|
|
2482
|
-
providerMetadata?: ProviderMetadata;
|
|
2483
|
-
} | {
|
|
2484
|
-
type: 'tool-input-delta';
|
|
2485
|
-
id: string;
|
|
2486
|
-
delta: string;
|
|
2487
|
-
providerMetadata?: ProviderMetadata;
|
|
2488
|
-
} | ({
|
|
2489
|
-
type: 'source';
|
|
2490
|
-
} & Source) | {
|
|
2491
|
-
type: 'file';
|
|
2492
|
-
file: GeneratedFile;
|
|
2493
|
-
} | ({
|
|
2494
|
-
type: 'tool-call';
|
|
2495
|
-
} & TypedToolCall<TOOLS>) | ({
|
|
2496
|
-
type: 'tool-result';
|
|
2497
|
-
} & TypedToolResult<TOOLS>) | ({
|
|
2498
|
-
type: 'tool-error';
|
|
2499
|
-
} & TypedToolError<TOOLS>) | ({
|
|
2500
|
-
type: 'tool-output-denied';
|
|
2501
|
-
} & StaticToolOutputDenied<TOOLS>) | ToolApprovalRequestOutput<TOOLS> | {
|
|
2502
|
-
type: 'start-step';
|
|
2503
|
-
request: LanguageModelRequestMetadata;
|
|
2504
|
-
warnings: CallWarning[];
|
|
2505
|
-
} | {
|
|
2506
|
-
type: 'finish-step';
|
|
2507
|
-
response: LanguageModelResponseMetadata;
|
|
2508
|
-
usage: LanguageModelUsage;
|
|
2509
|
-
finishReason: FinishReason;
|
|
2510
|
-
providerMetadata: ProviderMetadata | undefined;
|
|
2511
|
-
} | {
|
|
2512
|
-
type: 'start';
|
|
2513
|
-
} | {
|
|
2514
|
-
type: 'finish';
|
|
2515
|
-
finishReason: FinishReason;
|
|
2516
|
-
totalUsage: LanguageModelUsage;
|
|
2517
|
-
} | {
|
|
2518
|
-
type: 'abort';
|
|
2519
|
-
} | {
|
|
2520
|
-
type: 'error';
|
|
2521
|
-
error: unknown;
|
|
2522
|
-
} | {
|
|
2523
|
-
type: 'raw';
|
|
2524
|
-
rawValue: unknown;
|
|
2525
|
-
};
|
|
2738
|
+
Internal. For test use only. May change without notice.
|
|
2739
|
+
*/
|
|
2740
|
+
_internal?: {
|
|
2741
|
+
now?: () => number;
|
|
2742
|
+
generateId?: IdGenerator;
|
|
2743
|
+
currentDate?: () => Date;
|
|
2744
|
+
};
|
|
2745
|
+
}): StreamTextResult<TOOLS, OUTPUT>;
|
|
2526
2746
|
|
|
2747
|
+
/**
|
|
2748
|
+
* Parameters for calling an agent.
|
|
2749
|
+
*/
|
|
2527
2750
|
type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
|
|
2528
2751
|
options?: never;
|
|
2529
2752
|
} : {
|
|
@@ -2560,6 +2783,17 @@ type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
|
|
|
2560
2783
|
*/
|
|
2561
2784
|
abortSignal?: AbortSignal;
|
|
2562
2785
|
};
|
|
2786
|
+
/**
|
|
2787
|
+
* Parameters for streaming an output from an agent.
|
|
2788
|
+
*/
|
|
2789
|
+
type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS> & {
|
|
2790
|
+
/**
|
|
2791
|
+
* Optional stream transformations.
|
|
2792
|
+
* They are applied in the order they are provided.
|
|
2793
|
+
* The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
2794
|
+
*/
|
|
2795
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
2796
|
+
};
|
|
2563
2797
|
/**
|
|
2564
2798
|
* An Agent receives a prompt (text or messages) and generates or streams an output
|
|
2565
2799
|
* that consists of steps, tool calls, data parts, etc.
|
|
@@ -2588,7 +2822,7 @@ interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends
|
|
|
2588
2822
|
/**
|
|
2589
2823
|
* Streams an output from the agent (streaming).
|
|
2590
2824
|
*/
|
|
2591
|
-
stream(options:
|
|
2825
|
+
stream(options: AgentStreamParameters<CALL_OPTIONS, TOOLS>): PromiseLike<StreamTextResult<TOOLS, OUTPUT>>;
|
|
2592
2826
|
}
|
|
2593
2827
|
|
|
2594
2828
|
/**
|
|
@@ -2598,13 +2832,21 @@ Callback that is set using the `onFinish` option.
|
|
|
2598
2832
|
*/
|
|
2599
2833
|
type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: StepResult<TOOLS> & {
|
|
2600
2834
|
/**
|
|
2601
|
-
Details for all steps.
|
|
2602
|
-
|
|
2835
|
+
* Details for all steps.
|
|
2836
|
+
*/
|
|
2603
2837
|
readonly steps: StepResult<TOOLS>[];
|
|
2604
2838
|
/**
|
|
2605
|
-
Total usage for all steps. This is the sum of the usage of all steps.
|
|
2839
|
+
* Total usage for all steps. This is the sum of the usage of all steps.
|
|
2606
2840
|
*/
|
|
2607
2841
|
readonly totalUsage: LanguageModelUsage;
|
|
2842
|
+
/**
|
|
2843
|
+
* Context that is passed into tool calls.
|
|
2844
|
+
*
|
|
2845
|
+
* Experimental (can break in patch releases).
|
|
2846
|
+
*
|
|
2847
|
+
* @default undefined
|
|
2848
|
+
*/
|
|
2849
|
+
experimental_context?: unknown;
|
|
2608
2850
|
}) => PromiseLike<void> | void;
|
|
2609
2851
|
|
|
2610
2852
|
/**
|
|
@@ -2624,8 +2866,10 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
2624
2866
|
id?: string;
|
|
2625
2867
|
/**
|
|
2626
2868
|
* The instructions for the agent.
|
|
2869
|
+
*
|
|
2870
|
+
* It can be a string, or, if you need to pass additional provider options (e.g. for caching), a `SystemModelMessage`.
|
|
2627
2871
|
*/
|
|
2628
|
-
instructions?: string
|
|
2872
|
+
instructions?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
2629
2873
|
/**
|
|
2630
2874
|
The language model to use.
|
|
2631
2875
|
*/
|
|
@@ -2689,6 +2933,12 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
2689
2933
|
*/
|
|
2690
2934
|
experimental_context?: unknown;
|
|
2691
2935
|
/**
|
|
2936
|
+
Custom download function to use for URLs.
|
|
2937
|
+
|
|
2938
|
+
By default, files are downloaded if the model does not support the URL for the given media type.
|
|
2939
|
+
*/
|
|
2940
|
+
experimental_download?: DownloadFunction | undefined;
|
|
2941
|
+
/**
|
|
2692
2942
|
* The schema for the call options.
|
|
2693
2943
|
*/
|
|
2694
2944
|
callOptionsSchema?: FlexibleSchema<CALL_OPTIONS>;
|
|
@@ -2697,7 +2947,7 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
2697
2947
|
*
|
|
2698
2948
|
* You can use this to have templates based on call options.
|
|
2699
2949
|
*/
|
|
2700
|
-
prepareCall?: (options: AgentCallParameters<CALL_OPTIONS> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context'> & Omit<Prompt, 'system'>>;
|
|
2950
|
+
prepareCall?: (options: AgentCallParameters<CALL_OPTIONS> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
|
|
2701
2951
|
};
|
|
2702
2952
|
|
|
2703
2953
|
/**
|
|
@@ -2731,7 +2981,7 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
|
|
|
2731
2981
|
/**
|
|
2732
2982
|
* Streams an output from the agent (streaming).
|
|
2733
2983
|
*/
|
|
2734
|
-
stream({ abortSignal, ...options }:
|
|
2984
|
+
stream({ abortSignal, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
2735
2985
|
}
|
|
2736
2986
|
|
|
2737
2987
|
/**
|
|
@@ -2742,20 +2992,22 @@ type InferAgentTools<AGENT> = AGENT extends Agent<any, infer TOOLS, any> ? TOOLS
|
|
|
2742
2992
|
/**
|
|
2743
2993
|
* Infer the UI message type of an agent.
|
|
2744
2994
|
*/
|
|
2745
|
-
type InferAgentUIMessage<AGENT> = UIMessage<
|
|
2995
|
+
type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_METADATA, never, InferUITools<InferAgentTools<AGENT>>>;
|
|
2746
2996
|
|
|
2747
2997
|
/**
|
|
2748
2998
|
* Runs the agent and returns a response object with a UI message stream.
|
|
2749
2999
|
*
|
|
2750
3000
|
* @param agent - The agent to run.
|
|
2751
|
-
* @param
|
|
3001
|
+
* @param uiMessages - The input UI messages.
|
|
2752
3002
|
*
|
|
2753
3003
|
* @returns The response object.
|
|
2754
3004
|
*/
|
|
2755
3005
|
declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, consumeSseStream, ...options }: {
|
|
2756
3006
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
2757
|
-
|
|
3007
|
+
uiMessages: unknown[];
|
|
3008
|
+
abortSignal?: AbortSignal;
|
|
2758
3009
|
options?: CALL_OPTIONS;
|
|
3010
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
2759
3011
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<Response>;
|
|
2760
3012
|
|
|
2761
3013
|
declare const getOriginalFetch: () => typeof fetch;
|
|
@@ -3088,11 +3340,7 @@ declare function convertToModelMessages<UI_MESSAGE extends UIMessage>(messages:
|
|
|
3088
3340
|
tools?: ToolSet;
|
|
3089
3341
|
ignoreIncompleteToolCalls?: boolean;
|
|
3090
3342
|
convertDataPart?: (part: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => TextPart | FilePart | undefined;
|
|
3091
|
-
}): ModelMessage[]
|
|
3092
|
-
/**
|
|
3093
|
-
@deprecated Use `convertToModelMessages` instead.
|
|
3094
|
-
*/
|
|
3095
|
-
declare const convertToCoreMessages: typeof convertToModelMessages;
|
|
3343
|
+
}): Promise<ModelMessage[]>;
|
|
3096
3344
|
|
|
3097
3345
|
type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (options: {
|
|
3098
3346
|
id: string;
|
|
@@ -3420,38 +3668,45 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
3420
3668
|
* Runs the agent and stream the output as a UI message stream.
|
|
3421
3669
|
*
|
|
3422
3670
|
* @param agent - The agent to run.
|
|
3423
|
-
* @param
|
|
3671
|
+
* @param uiMessages - The input UI messages.
|
|
3672
|
+
* @param abortSignal - The abort signal. Optional.
|
|
3673
|
+
* @param options - The options for the agent.
|
|
3674
|
+
* @param experimental_transform - The stream transformations. Optional.
|
|
3424
3675
|
*
|
|
3425
3676
|
* @returns The UI message stream.
|
|
3426
3677
|
*/
|
|
3427
|
-
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent,
|
|
3678
|
+
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, experimental_transform, ...uiMessageStreamOptions }: {
|
|
3428
3679
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3429
|
-
|
|
3680
|
+
uiMessages: unknown[];
|
|
3681
|
+
abortSignal?: AbortSignal;
|
|
3430
3682
|
options?: CALL_OPTIONS;
|
|
3683
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3431
3684
|
} & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<AsyncIterableStream<InferUIMessageChunk<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>>>;
|
|
3432
3685
|
|
|
3433
3686
|
/**
|
|
3434
3687
|
* Pipes the agent UI message stream to a Node.js ServerResponse object.
|
|
3435
3688
|
*
|
|
3436
3689
|
* @param agent - The agent to run.
|
|
3437
|
-
* @param
|
|
3690
|
+
* @param uiMessages - The input UI messages.
|
|
3438
3691
|
*/
|
|
3439
3692
|
declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, consumeSseStream, ...options }: {
|
|
3440
3693
|
response: ServerResponse;
|
|
3441
3694
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3442
|
-
|
|
3695
|
+
uiMessages: unknown[];
|
|
3696
|
+
abortSignal?: AbortSignal;
|
|
3443
3697
|
options?: CALL_OPTIONS;
|
|
3698
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3444
3699
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<void>;
|
|
3445
3700
|
|
|
3446
3701
|
/**
|
|
3447
3702
|
The result of an `embed` call.
|
|
3448
3703
|
It contains the embedding, the value, and additional information.
|
|
3449
3704
|
*/
|
|
3450
|
-
interface EmbedResult
|
|
3705
|
+
interface EmbedResult {
|
|
3451
3706
|
/**
|
|
3452
3707
|
The value that was embedded.
|
|
3453
3708
|
*/
|
|
3454
|
-
readonly value:
|
|
3709
|
+
readonly value: string;
|
|
3455
3710
|
/**
|
|
3456
3711
|
The embedding of the value.
|
|
3457
3712
|
*/
|
|
@@ -3461,6 +3716,10 @@ interface EmbedResult<VALUE> {
|
|
|
3461
3716
|
*/
|
|
3462
3717
|
readonly usage: EmbeddingModelUsage;
|
|
3463
3718
|
/**
|
|
3719
|
+
Warnings for the call, e.g. unsupported settings.
|
|
3720
|
+
*/
|
|
3721
|
+
readonly warnings: Array<Warning>;
|
|
3722
|
+
/**
|
|
3464
3723
|
Optional provider-specific metadata.
|
|
3465
3724
|
*/
|
|
3466
3725
|
readonly providerMetadata?: ProviderMetadata;
|
|
@@ -3491,15 +3750,15 @@ Embed a value using an embedding model. The type of the value is defined by the
|
|
|
3491
3750
|
|
|
3492
3751
|
@returns A result object that contains the embedding, the value, and additional information.
|
|
3493
3752
|
*/
|
|
3494
|
-
declare function embed
|
|
3753
|
+
declare function embed({ model: modelArg, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
|
3495
3754
|
/**
|
|
3496
3755
|
The embedding model to use.
|
|
3497
3756
|
*/
|
|
3498
|
-
model: EmbeddingModel
|
|
3757
|
+
model: EmbeddingModel;
|
|
3499
3758
|
/**
|
|
3500
3759
|
The value that should be embedded.
|
|
3501
3760
|
*/
|
|
3502
|
-
value:
|
|
3761
|
+
value: string;
|
|
3503
3762
|
/**
|
|
3504
3763
|
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
|
3505
3764
|
|
|
@@ -3525,17 +3784,17 @@ declare function embed<VALUE = string>({ model: modelArg, value, providerOptions
|
|
|
3525
3784
|
* Optional telemetry configuration (experimental).
|
|
3526
3785
|
*/
|
|
3527
3786
|
experimental_telemetry?: TelemetrySettings;
|
|
3528
|
-
}): Promise<EmbedResult
|
|
3787
|
+
}): Promise<EmbedResult>;
|
|
3529
3788
|
|
|
3530
3789
|
/**
|
|
3531
3790
|
The result of a `embedMany` call.
|
|
3532
3791
|
It contains the embeddings, the values, and additional information.
|
|
3533
3792
|
*/
|
|
3534
|
-
interface EmbedManyResult
|
|
3793
|
+
interface EmbedManyResult {
|
|
3535
3794
|
/**
|
|
3536
3795
|
The values that were embedded.
|
|
3537
3796
|
*/
|
|
3538
|
-
readonly values: Array<
|
|
3797
|
+
readonly values: Array<string>;
|
|
3539
3798
|
/**
|
|
3540
3799
|
The embeddings. They are in the same order as the values.
|
|
3541
3800
|
*/
|
|
@@ -3545,6 +3804,10 @@ interface EmbedManyResult<VALUE> {
|
|
|
3545
3804
|
*/
|
|
3546
3805
|
readonly usage: EmbeddingModelUsage;
|
|
3547
3806
|
/**
|
|
3807
|
+
Warnings for the call, e.g. unsupported settings.
|
|
3808
|
+
*/
|
|
3809
|
+
readonly warnings: Array<Warning>;
|
|
3810
|
+
/**
|
|
3548
3811
|
Optional provider-specific metadata.
|
|
3549
3812
|
*/
|
|
3550
3813
|
readonly providerMetadata?: ProviderMetadata;
|
|
@@ -3579,15 +3842,15 @@ has a limit on how many embeddings can be generated in a single call.
|
|
|
3579
3842
|
|
|
3580
3843
|
@returns A result object that contains the embeddings, the value, and additional information.
|
|
3581
3844
|
*/
|
|
3582
|
-
declare function embedMany
|
|
3845
|
+
declare function embedMany({ model: modelArg, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
|
3583
3846
|
/**
|
|
3584
3847
|
The embedding model to use.
|
|
3585
3848
|
*/
|
|
3586
|
-
model: EmbeddingModel
|
|
3849
|
+
model: EmbeddingModel;
|
|
3587
3850
|
/**
|
|
3588
3851
|
The values that should be embedded.
|
|
3589
3852
|
*/
|
|
3590
|
-
values: Array<
|
|
3853
|
+
values: Array<string>;
|
|
3591
3854
|
/**
|
|
3592
3855
|
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
|
3593
3856
|
|
|
@@ -3619,11 +3882,11 @@ declare function embedMany<VALUE = string>({ model: modelArg, values, maxParalle
|
|
|
3619
3882
|
* @default Infinity
|
|
3620
3883
|
*/
|
|
3621
3884
|
maxParallelCalls?: number;
|
|
3622
|
-
}): Promise<EmbedManyResult
|
|
3885
|
+
}): Promise<EmbedManyResult>;
|
|
3623
3886
|
|
|
3624
|
-
declare const symbol$
|
|
3887
|
+
declare const symbol$a: unique symbol;
|
|
3625
3888
|
declare class InvalidArgumentError extends AISDKError {
|
|
3626
|
-
private readonly [symbol$
|
|
3889
|
+
private readonly [symbol$a];
|
|
3627
3890
|
readonly parameter: string;
|
|
3628
3891
|
readonly value: unknown;
|
|
3629
3892
|
constructor({ parameter, value, message, }: {
|
|
@@ -3692,7 +3955,7 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
|
|
3692
3955
|
file: GeneratedFile;
|
|
3693
3956
|
} | {
|
|
3694
3957
|
type: 'stream-start';
|
|
3695
|
-
warnings:
|
|
3958
|
+
warnings: SharedV3Warning[];
|
|
3696
3959
|
} | {
|
|
3697
3960
|
type: 'response-metadata';
|
|
3698
3961
|
id?: string;
|
|
@@ -3701,6 +3964,7 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
|
|
3701
3964
|
} | {
|
|
3702
3965
|
type: 'finish';
|
|
3703
3966
|
finishReason: FinishReason;
|
|
3967
|
+
rawFinishReason: string | undefined;
|
|
3704
3968
|
usage: LanguageModelUsage;
|
|
3705
3969
|
providerMetadata?: ProviderMetadata;
|
|
3706
3970
|
} | {
|
|
@@ -3711,9 +3975,9 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
|
|
3711
3975
|
rawValue: unknown;
|
|
3712
3976
|
};
|
|
3713
3977
|
|
|
3714
|
-
declare const symbol$
|
|
3978
|
+
declare const symbol$9: unique symbol;
|
|
3715
3979
|
declare class InvalidStreamPartError extends AISDKError {
|
|
3716
|
-
private readonly [symbol$
|
|
3980
|
+
private readonly [symbol$9];
|
|
3717
3981
|
readonly chunk: SingleRequestTextStreamPart<any>;
|
|
3718
3982
|
constructor({ chunk, message, }: {
|
|
3719
3983
|
chunk: SingleRequestTextStreamPart<any>;
|
|
@@ -3722,7 +3986,7 @@ declare class InvalidStreamPartError extends AISDKError {
|
|
|
3722
3986
|
static isInstance(error: unknown): error is InvalidStreamPartError;
|
|
3723
3987
|
}
|
|
3724
3988
|
|
|
3725
|
-
declare const symbol$
|
|
3989
|
+
declare const symbol$8: unique symbol;
|
|
3726
3990
|
/**
|
|
3727
3991
|
Thrown when no image could be generated. This can have multiple causes:
|
|
3728
3992
|
|
|
@@ -3730,7 +3994,7 @@ Thrown when no image could be generated. This can have multiple causes:
|
|
|
3730
3994
|
- The model generated a response that could not be parsed.
|
|
3731
3995
|
*/
|
|
3732
3996
|
declare class NoImageGeneratedError extends AISDKError {
|
|
3733
|
-
private readonly [symbol$
|
|
3997
|
+
private readonly [symbol$8];
|
|
3734
3998
|
/**
|
|
3735
3999
|
The response metadata for each call.
|
|
3736
4000
|
*/
|
|
@@ -3743,7 +4007,7 @@ declare class NoImageGeneratedError extends AISDKError {
|
|
|
3743
4007
|
static isInstance(error: unknown): error is NoImageGeneratedError;
|
|
3744
4008
|
}
|
|
3745
4009
|
|
|
3746
|
-
declare const symbol$
|
|
4010
|
+
declare const symbol$7: unique symbol;
|
|
3747
4011
|
/**
|
|
3748
4012
|
Thrown when no object could be generated. This can have several causes:
|
|
3749
4013
|
|
|
@@ -3756,7 +4020,7 @@ The error contains the following properties:
|
|
|
3756
4020
|
- `text`: The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
|
|
3757
4021
|
*/
|
|
3758
4022
|
declare class NoObjectGeneratedError extends AISDKError {
|
|
3759
|
-
private readonly [symbol$
|
|
4023
|
+
private readonly [symbol$7];
|
|
3760
4024
|
/**
|
|
3761
4025
|
The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
|
|
3762
4026
|
*/
|
|
@@ -3784,12 +4048,12 @@ declare class NoObjectGeneratedError extends AISDKError {
|
|
|
3784
4048
|
static isInstance(error: unknown): error is NoObjectGeneratedError;
|
|
3785
4049
|
}
|
|
3786
4050
|
|
|
3787
|
-
declare const symbol$
|
|
4051
|
+
declare const symbol$6: unique symbol;
|
|
3788
4052
|
/**
|
|
3789
4053
|
Thrown when no LLM output was generated, e.g. because of errors.
|
|
3790
4054
|
*/
|
|
3791
4055
|
declare class NoOutputGeneratedError extends AISDKError {
|
|
3792
|
-
private readonly [symbol$
|
|
4056
|
+
private readonly [symbol$6];
|
|
3793
4057
|
constructor({ message, cause, }?: {
|
|
3794
4058
|
message?: string;
|
|
3795
4059
|
cause?: Error;
|
|
@@ -3807,9 +4071,9 @@ declare class NoSpeechGeneratedError extends AISDKError {
|
|
|
3807
4071
|
});
|
|
3808
4072
|
}
|
|
3809
4073
|
|
|
3810
|
-
declare const symbol$
|
|
4074
|
+
declare const symbol$5: unique symbol;
|
|
3811
4075
|
declare class ToolCallRepairError extends AISDKError {
|
|
3812
|
-
private readonly [symbol$
|
|
4076
|
+
private readonly [symbol$5];
|
|
3813
4077
|
readonly originalError: NoSuchToolError | InvalidToolInputError;
|
|
3814
4078
|
constructor({ cause, originalError, message, }: {
|
|
3815
4079
|
message?: string;
|
|
@@ -3833,9 +4097,9 @@ declare class UnsupportedModelVersionError extends AISDKError {
|
|
|
3833
4097
|
});
|
|
3834
4098
|
}
|
|
3835
4099
|
|
|
3836
|
-
declare const symbol$
|
|
4100
|
+
declare const symbol$4: unique symbol;
|
|
3837
4101
|
declare class InvalidDataContentError extends AISDKError {
|
|
3838
|
-
private readonly [symbol$
|
|
4102
|
+
private readonly [symbol$4];
|
|
3839
4103
|
readonly content: unknown;
|
|
3840
4104
|
constructor({ content, cause, message, }: {
|
|
3841
4105
|
content: unknown;
|
|
@@ -3845,9 +4109,9 @@ declare class InvalidDataContentError extends AISDKError {
|
|
|
3845
4109
|
static isInstance(error: unknown): error is InvalidDataContentError;
|
|
3846
4110
|
}
|
|
3847
4111
|
|
|
3848
|
-
declare const symbol$
|
|
4112
|
+
declare const symbol$3: unique symbol;
|
|
3849
4113
|
declare class InvalidMessageRoleError extends AISDKError {
|
|
3850
|
-
private readonly [symbol$
|
|
4114
|
+
private readonly [symbol$3];
|
|
3851
4115
|
readonly role: string;
|
|
3852
4116
|
constructor({ role, message, }: {
|
|
3853
4117
|
role: string;
|
|
@@ -3856,9 +4120,9 @@ declare class InvalidMessageRoleError extends AISDKError {
|
|
|
3856
4120
|
static isInstance(error: unknown): error is InvalidMessageRoleError;
|
|
3857
4121
|
}
|
|
3858
4122
|
|
|
3859
|
-
declare const symbol$
|
|
4123
|
+
declare const symbol$2: unique symbol;
|
|
3860
4124
|
declare class MessageConversionError extends AISDKError {
|
|
3861
|
-
private readonly [symbol$
|
|
4125
|
+
private readonly [symbol$2];
|
|
3862
4126
|
readonly originalMessage: Omit<UIMessage, 'id'>;
|
|
3863
4127
|
constructor({ originalMessage, message, }: {
|
|
3864
4128
|
originalMessage: Omit<UIMessage, 'id'>;
|
|
@@ -3867,22 +4131,6 @@ declare class MessageConversionError extends AISDKError {
|
|
|
3867
4131
|
static isInstance(error: unknown): error is MessageConversionError;
|
|
3868
4132
|
}
|
|
3869
4133
|
|
|
3870
|
-
declare const symbol$2: unique symbol;
|
|
3871
|
-
declare class DownloadError extends AISDKError {
|
|
3872
|
-
private readonly [symbol$2];
|
|
3873
|
-
readonly url: string;
|
|
3874
|
-
readonly statusCode?: number;
|
|
3875
|
-
readonly statusText?: string;
|
|
3876
|
-
constructor({ url, statusCode, statusText, cause, message, }: {
|
|
3877
|
-
url: string;
|
|
3878
|
-
statusCode?: number;
|
|
3879
|
-
statusText?: string;
|
|
3880
|
-
message?: string;
|
|
3881
|
-
cause?: unknown;
|
|
3882
|
-
});
|
|
3883
|
-
static isInstance(error: unknown): error is DownloadError;
|
|
3884
|
-
}
|
|
3885
|
-
|
|
3886
4134
|
declare const symbol$1: unique symbol;
|
|
3887
4135
|
type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
|
|
3888
4136
|
declare class RetryError extends AISDKError {
|
|
@@ -3914,7 +4162,7 @@ interface GenerateImageResult {
|
|
|
3914
4162
|
/**
|
|
3915
4163
|
Warnings for the call, e.g. unsupported settings.
|
|
3916
4164
|
*/
|
|
3917
|
-
readonly warnings: Array<
|
|
4165
|
+
readonly warnings: Array<Warning>;
|
|
3918
4166
|
/**
|
|
3919
4167
|
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
|
3920
4168
|
*/
|
|
@@ -3930,6 +4178,11 @@ interface GenerateImageResult {
|
|
|
3930
4178
|
readonly usage: ImageModelUsage;
|
|
3931
4179
|
}
|
|
3932
4180
|
|
|
4181
|
+
type GenerateImagePrompt = string | {
|
|
4182
|
+
images: Array<DataContent>;
|
|
4183
|
+
text?: string;
|
|
4184
|
+
mask?: DataContent;
|
|
4185
|
+
};
|
|
3933
4186
|
/**
|
|
3934
4187
|
Generates images using an image model.
|
|
3935
4188
|
|
|
@@ -3947,15 +4200,15 @@ as body parameters.
|
|
|
3947
4200
|
|
|
3948
4201
|
@returns A result object that contains the generated images.
|
|
3949
4202
|
*/
|
|
3950
|
-
declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
|
4203
|
+
declare function generateImage({ model: modelArg, prompt: promptArg, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
|
3951
4204
|
/**
|
|
3952
4205
|
The image model to use.
|
|
3953
4206
|
*/
|
|
3954
|
-
model:
|
|
4207
|
+
model: ImageModel;
|
|
3955
4208
|
/**
|
|
3956
4209
|
The prompt that should be used to generate the image.
|
|
3957
4210
|
*/
|
|
3958
|
-
prompt:
|
|
4211
|
+
prompt: GenerateImagePrompt;
|
|
3959
4212
|
/**
|
|
3960
4213
|
Number of images to generate.
|
|
3961
4214
|
*/
|
|
@@ -4008,6 +4261,16 @@ declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspec
|
|
|
4008
4261
|
headers?: Record<string, string>;
|
|
4009
4262
|
}): Promise<GenerateImageResult>;
|
|
4010
4263
|
|
|
4264
|
+
/**
|
|
4265
|
+
* @deprecated Use `generateImage` instead.
|
|
4266
|
+
*/
|
|
4267
|
+
declare const experimental_generateImage: typeof generateImage;
|
|
4268
|
+
|
|
4269
|
+
/**
|
|
4270
|
+
* @deprecated Use `GenerateImageResult` instead.
|
|
4271
|
+
*/
|
|
4272
|
+
type Experimental_GenerateImageResult = GenerateImageResult;
|
|
4273
|
+
|
|
4011
4274
|
/**
|
|
4012
4275
|
The result of a `generateObject` call.
|
|
4013
4276
|
*/
|
|
@@ -4133,13 +4396,14 @@ functionality that can be fully encapsulated in the provider.
|
|
|
4133
4396
|
|
|
4134
4397
|
@returns
|
|
4135
4398
|
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
|
4399
|
+
|
|
4400
|
+
@deprecated Use `generateText` with an `output` setting instead.
|
|
4136
4401
|
*/
|
|
4137
4402
|
declare function generateObject<SCHEMA extends FlexibleSchema<unknown> = FlexibleSchema<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
|
4138
4403
|
/**
|
|
4139
4404
|
The enum values that the model should use.
|
|
4140
4405
|
*/
|
|
4141
4406
|
enum: Array<RESULT>;
|
|
4142
|
-
mode?: 'json';
|
|
4143
4407
|
output: 'enum';
|
|
4144
4408
|
} : OUTPUT extends 'no-schema' ? {} : {
|
|
4145
4409
|
/**
|
|
@@ -4158,20 +4422,6 @@ Used by some providers for additional LLM guidance, e.g.
|
|
|
4158
4422
|
via tool or schema description.
|
|
4159
4423
|
*/
|
|
4160
4424
|
schemaDescription?: string;
|
|
4161
|
-
/**
|
|
4162
|
-
The mode to use for object generation.
|
|
4163
|
-
|
|
4164
|
-
The schema is converted into a JSON schema and used in one of the following ways
|
|
4165
|
-
|
|
4166
|
-
- 'auto': The provider will choose the best mode for the model.
|
|
4167
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
|
4168
|
-
- '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.
|
|
4169
|
-
|
|
4170
|
-
Please note that most providers do not support all modes.
|
|
4171
|
-
|
|
4172
|
-
Default and recommended: 'auto' (best mode for the model).
|
|
4173
|
-
*/
|
|
4174
|
-
mode?: 'auto' | 'json' | 'tool';
|
|
4175
4425
|
}) & {
|
|
4176
4426
|
output?: OUTPUT;
|
|
4177
4427
|
/**
|
|
@@ -4477,13 +4727,14 @@ functionality that can be fully encapsulated in the provider.
|
|
|
4477
4727
|
|
|
4478
4728
|
@returns
|
|
4479
4729
|
A result object for accessing the partial object stream and additional information.
|
|
4730
|
+
|
|
4731
|
+
@deprecated Use `streamText` with an `output` setting instead.
|
|
4480
4732
|
*/
|
|
4481
4733
|
declare function streamObject<SCHEMA extends FlexibleSchema<unknown> = FlexibleSchema<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
|
4482
4734
|
/**
|
|
4483
4735
|
The enum values that the model should use.
|
|
4484
4736
|
*/
|
|
4485
4737
|
enum: Array<RESULT>;
|
|
4486
|
-
mode?: 'json';
|
|
4487
4738
|
output: 'enum';
|
|
4488
4739
|
} : OUTPUT extends 'no-schema' ? {} : {
|
|
4489
4740
|
/**
|
|
@@ -4502,20 +4753,6 @@ Used by some providers for additional LLM guidance, e.g.
|
|
|
4502
4753
|
via tool or schema description.
|
|
4503
4754
|
*/
|
|
4504
4755
|
schemaDescription?: string;
|
|
4505
|
-
/**
|
|
4506
|
-
The mode to use for object generation.
|
|
4507
|
-
|
|
4508
|
-
The schema is converted into a JSON schema and used in one of the following ways
|
|
4509
|
-
|
|
4510
|
-
- 'auto': The provider will choose the best mode for the model.
|
|
4511
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
|
4512
|
-
- '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.
|
|
4513
|
-
|
|
4514
|
-
Please note that most providers do not support all modes.
|
|
4515
|
-
|
|
4516
|
-
Default and recommended: 'auto' (best mode for the model).
|
|
4517
|
-
*/
|
|
4518
|
-
mode?: 'auto' | 'json' | 'tool';
|
|
4519
4756
|
}) & {
|
|
4520
4757
|
output?: OUTPUT;
|
|
4521
4758
|
/**
|
|
@@ -4585,7 +4822,7 @@ interface SpeechResult {
|
|
|
4585
4822
|
/**
|
|
4586
4823
|
Warnings for the call, e.g. unsupported settings.
|
|
4587
4824
|
*/
|
|
4588
|
-
readonly warnings: Array<
|
|
4825
|
+
readonly warnings: Array<Warning>;
|
|
4589
4826
|
/**
|
|
4590
4827
|
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
|
4591
4828
|
*/
|
|
@@ -4673,10 +4910,30 @@ declare function generateSpeech({ model, text, voice, outputFormat, instructions
|
|
|
4673
4910
|
headers?: Record<string, string>;
|
|
4674
4911
|
}): Promise<SpeechResult>;
|
|
4675
4912
|
|
|
4676
|
-
|
|
4913
|
+
/**
|
|
4914
|
+
* A function for logging warnings.
|
|
4915
|
+
*
|
|
4916
|
+
* You can assign it to the `AI_SDK_LOG_WARNINGS` global variable to use it as the default warning logger.
|
|
4917
|
+
*
|
|
4918
|
+
* @example
|
|
4919
|
+
* ```ts
|
|
4920
|
+
* globalThis.AI_SDK_LOG_WARNINGS = (options) => {
|
|
4921
|
+
* console.log('WARNINGS:', options.warnings, options.provider, options.model);
|
|
4922
|
+
* };
|
|
4923
|
+
* ```
|
|
4924
|
+
*/
|
|
4677
4925
|
type LogWarningsFunction = (options: {
|
|
4926
|
+
/**
|
|
4927
|
+
* The warnings returned by the model provider.
|
|
4928
|
+
*/
|
|
4678
4929
|
warnings: Warning[];
|
|
4930
|
+
/**
|
|
4931
|
+
* The provider id used for the call.
|
|
4932
|
+
*/
|
|
4679
4933
|
provider: string;
|
|
4934
|
+
/**
|
|
4935
|
+
* The model id used for the call.
|
|
4936
|
+
*/
|
|
4680
4937
|
model: string;
|
|
4681
4938
|
}) => void;
|
|
4682
4939
|
|
|
@@ -4685,8 +4942,8 @@ type LogWarningsFunction = (options: {
|
|
|
4685
4942
|
*/
|
|
4686
4943
|
declare function defaultEmbeddingSettingsMiddleware({ settings, }: {
|
|
4687
4944
|
settings: Partial<{
|
|
4688
|
-
headers?:
|
|
4689
|
-
providerOptions?:
|
|
4945
|
+
headers?: EmbeddingModelV3CallOptions['headers'];
|
|
4946
|
+
providerOptions?: EmbeddingModelV3CallOptions['providerOptions'];
|
|
4690
4947
|
}>;
|
|
4691
4948
|
}): EmbeddingModelMiddleware;
|
|
4692
4949
|
|
|
@@ -4730,6 +4987,49 @@ declare function extractReasoningMiddleware({ tagName, separator, startWithReaso
|
|
|
4730
4987
|
*/
|
|
4731
4988
|
declare function simulateStreamingMiddleware(): LanguageModelMiddleware;
|
|
4732
4989
|
|
|
4990
|
+
/**
|
|
4991
|
+
* Middleware that appends input examples to tool descriptions.
|
|
4992
|
+
*
|
|
4993
|
+
* This is useful for providers that don't natively support the `inputExamples`
|
|
4994
|
+
* property. The middleware serializes examples into the tool's description text.
|
|
4995
|
+
*
|
|
4996
|
+
* @param options - Configuration options for the middleware.
|
|
4997
|
+
* @param options.prefix - A prefix to prepend before the examples. Default: 'Input Examples:'
|
|
4998
|
+
* @param options.format - Optional custom formatter for each example.
|
|
4999
|
+
* Receives the example object and its index. Default: JSON.stringify(example.input)
|
|
5000
|
+
* @param options.remove - Whether to remove the inputExamples property
|
|
5001
|
+
* after adding them to the description. Default: true
|
|
5002
|
+
*
|
|
5003
|
+
* @example
|
|
5004
|
+
* ```ts
|
|
5005
|
+
* import { wrapLanguageModel, addToolInputExamplesMiddleware } from 'ai';
|
|
5006
|
+
*
|
|
5007
|
+
* const model = wrapLanguageModel({
|
|
5008
|
+
* model: yourModel,
|
|
5009
|
+
* middleware: addToolInputExamplesMiddleware(),
|
|
5010
|
+
* });
|
|
5011
|
+
* ```
|
|
5012
|
+
*/
|
|
5013
|
+
declare function addToolInputExamplesMiddleware({ prefix, format, remove, }?: {
|
|
5014
|
+
/**
|
|
5015
|
+
* A prefix to prepend before the examples.
|
|
5016
|
+
*/
|
|
5017
|
+
prefix?: string;
|
|
5018
|
+
/**
|
|
5019
|
+
* Optional custom formatter for each example.
|
|
5020
|
+
* Receives the example object and its index.
|
|
5021
|
+
* Default: JSON.stringify(example.input)
|
|
5022
|
+
*/
|
|
5023
|
+
format?: (example: {
|
|
5024
|
+
input: JSONObject;
|
|
5025
|
+
}, index: number) => string;
|
|
5026
|
+
/**
|
|
5027
|
+
* Whether to remove the inputExamples property after adding them to the description.
|
|
5028
|
+
* Default: true
|
|
5029
|
+
*/
|
|
5030
|
+
remove?: boolean;
|
|
5031
|
+
}): LanguageModelMiddleware;
|
|
5032
|
+
|
|
4733
5033
|
/**
|
|
4734
5034
|
* Wraps a LanguageModelV3 instance with middleware functionality.
|
|
4735
5035
|
* This function allows you to apply middleware to transform parameters,
|
|
@@ -4762,11 +5062,11 @@ declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, p
|
|
|
4762
5062
|
* @returns A new EmbeddingModelV3 instance with middleware applied.
|
|
4763
5063
|
*/
|
|
4764
5064
|
declare const wrapEmbeddingModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
|
|
4765
|
-
model: EmbeddingModelV3
|
|
5065
|
+
model: EmbeddingModelV3;
|
|
4766
5066
|
middleware: EmbeddingModelMiddleware | EmbeddingModelMiddleware[];
|
|
4767
5067
|
modelId?: string;
|
|
4768
5068
|
providerId?: string;
|
|
4769
|
-
}) => EmbeddingModelV3
|
|
5069
|
+
}) => EmbeddingModelV3;
|
|
4770
5070
|
|
|
4771
5071
|
/**
|
|
4772
5072
|
* Wraps a ProviderV3 instance with middleware functionality.
|
|
@@ -4789,19 +5089,19 @@ declare function wrapProvider({ provider, languageModelMiddleware, }: {
|
|
|
4789
5089
|
*
|
|
4790
5090
|
* @param {Object} options - The options for creating the custom provider.
|
|
4791
5091
|
* @param {Record<string, LanguageModel>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModel instances.
|
|
4792
|
-
* @param {Record<string, EmbeddingModel
|
|
5092
|
+
* @param {Record<string, EmbeddingModel>} [options.embeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModel instances.
|
|
4793
5093
|
* @param {Record<string, ImageModel>} [options.imageModels] - A record of image models, where keys are model IDs and values are ImageModel instances.
|
|
4794
5094
|
* @param {Record<string, TranscriptionModel>} [options.transcriptionModels] - A record of transcription models, where keys are model IDs and values are TranscriptionModel instances.
|
|
4795
5095
|
* @param {Record<string, SpeechModel>} [options.speechModels] - A record of speech models, where keys are model IDs and values are SpeechModel instances.
|
|
4796
|
-
* @param {Record<string, RerankingModel
|
|
5096
|
+
* @param {Record<string, RerankingModel>} [options.rerankingModels] - A record of reranking models, where keys are model IDs and values are RerankingModel instances.
|
|
4797
5097
|
* @param {Provider} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
|
|
4798
|
-
* @returns {Provider} A Provider object with languageModel,
|
|
5098
|
+
* @returns {Provider} A Provider object with languageModel, embeddingModel, imageModel, transcriptionModel, and speechModel methods.
|
|
4799
5099
|
*
|
|
4800
5100
|
* @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
|
|
4801
5101
|
*/
|
|
4802
|
-
declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModelV3>, EMBEDDING_MODELS extends Record<string, EmbeddingModelV3
|
|
5102
|
+
declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModelV3>, EMBEDDING_MODELS extends Record<string, EmbeddingModelV3>, IMAGE_MODELS extends Record<string, ImageModelV3>, TRANSCRIPTION_MODELS extends Record<string, TranscriptionModelV3>, SPEECH_MODELS extends Record<string, SpeechModelV3>, RERANKING_MODELS extends Record<string, RerankingModelV3>>({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels, fallbackProvider: fallbackProviderArg, }: {
|
|
4803
5103
|
languageModels?: LANGUAGE_MODELS;
|
|
4804
|
-
|
|
5104
|
+
embeddingModels?: EMBEDDING_MODELS;
|
|
4805
5105
|
imageModels?: IMAGE_MODELS;
|
|
4806
5106
|
transcriptionModels?: TRANSCRIPTION_MODELS;
|
|
4807
5107
|
speechModels?: SPEECH_MODELS;
|
|
@@ -4809,7 +5109,7 @@ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageM
|
|
|
4809
5109
|
fallbackProvider?: ProviderV3 | ProviderV2;
|
|
4810
5110
|
}): ProviderV3 & {
|
|
4811
5111
|
languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModelV3;
|
|
4812
|
-
|
|
5112
|
+
embeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModelV3;
|
|
4813
5113
|
imageModel(modelId: ExtractModelId<IMAGE_MODELS>): ImageModelV3;
|
|
4814
5114
|
transcriptionModel(modelId: ExtractModelId<TRANSCRIPTION_MODELS>): TranscriptionModelV3;
|
|
4815
5115
|
rerankingModel(modelId: ExtractModelId<RERANKING_MODELS>): RerankingModelV3;
|
|
@@ -4828,7 +5128,7 @@ declare class NoSuchProviderError extends NoSuchModelError {
|
|
|
4828
5128
|
readonly availableProviders: string[];
|
|
4829
5129
|
constructor({ modelId, modelType, providerId, availableProviders, message, }: {
|
|
4830
5130
|
modelId: string;
|
|
4831
|
-
modelType: 'languageModel' | '
|
|
5131
|
+
modelType: 'languageModel' | 'embeddingModel' | 'imageModel' | 'transcriptionModel' | 'speechModel' | 'rerankingModel';
|
|
4832
5132
|
providerId: string;
|
|
4833
5133
|
availableProviders: string[];
|
|
4834
5134
|
message?: string;
|
|
@@ -4840,8 +5140,8 @@ type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T :
|
|
|
4840
5140
|
interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV3> = Record<string, ProviderV3>, SEPARATOR extends string = ':'> {
|
|
4841
5141
|
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModelV3;
|
|
4842
5142
|
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModelV3;
|
|
4843
|
-
|
|
4844
|
-
|
|
5143
|
+
embeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['embeddingModel']>>[0]>}` : never): EmbeddingModelV3;
|
|
5144
|
+
embeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModelV3;
|
|
4845
5145
|
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModelV3;
|
|
4846
5146
|
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModelV3;
|
|
4847
5147
|
transcriptionModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['transcriptionModel']>>[0]>}` : never): TranscriptionModelV3;
|
|
@@ -5040,7 +5340,7 @@ interface TranscriptionResult {
|
|
|
5040
5340
|
/**
|
|
5041
5341
|
Warnings for the call, e.g. unsupported settings.
|
|
5042
5342
|
*/
|
|
5043
|
-
readonly warnings: Array<
|
|
5343
|
+
readonly warnings: Array<Warning>;
|
|
5044
5344
|
/**
|
|
5045
5345
|
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
|
5046
5346
|
*/
|
|
@@ -5125,4 +5425,4 @@ declare global {
|
|
|
5125
5425
|
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
5126
5426
|
}
|
|
5127
5427
|
|
|
5128
|
-
export { AbstractChat, Agent, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions,
|
|
5428
|
+
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolApprovalRequestOutput, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapLanguageModel, wrapProvider };
|