ai 7.0.122 → 7.0.123
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 +15 -0
- package/dist/index.d.ts +7418 -7268
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19263 -22545
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2044 -2004
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +3255 -3921
- package/dist/internal/index.js.map +1 -1
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/test/index.d.ts +294 -273
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +325 -469
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/03-prompts.mdx +3 -1
- package/docs/02-foundations/06-provider-options.mdx +1 -1
- package/docs/02-getting-started/06-nodejs.mdx +4 -4
- package/docs/02-getting-started/08-tanstack-start.mdx +1 -1
- package/docs/03-agents/05-configuring-call-options.mdx +1 -1
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +1 -1
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +3 -0
- package/docs/03-ai-sdk-core/17-mcp-apps.mdx +5 -5
- package/docs/03-ai-sdk-core/37-speech.mdx +1 -1
- package/docs/03-ai-sdk-core/42-batch.mdx +1 -1
- package/docs/03-ai-sdk-core/60-telemetry.mdx +2 -2
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +24 -0
- package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +12 -12
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +9 -7
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +2 -2
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +7 -9
- package/docs/04-ai-sdk-ui/05-completion.mdx +1 -1
- package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +2 -2
- package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +8 -7
- package/docs/05-ai-sdk-rsc/06-loading-state.mdx +19 -10
- package/docs/05-ai-sdk-rsc/08-error-handling.mdx +2 -0
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +4 -3
- package/docs/06-advanced/02-stopping-streams.mdx +2 -2
- package/docs/06-advanced/04-caching.mdx +9 -5
- package/docs/06-advanced/05-multiple-streamables.mdx +1 -1
- package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +16 -16
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/14-upload-file.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/14-upload-skill.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +1 -4
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +5 -4
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +3 -2
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +7 -0
- package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +7 -0
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +2 -2
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +2 -2
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +1 -1
- package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +4 -5
- package/docs/08-migration-guides/26-migration-guide-5-0.mdx +2 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +4 -4
- package/docs/08-migration-guides/38-migration-guide-3-2.mdx +1 -1
- package/docs/08-migration-guides/39-migration-guide-3-1.mdx +1 -1
- package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +8 -6
- package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +6 -6
- package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +1 -1
- package/package.json +17 -17
- package/src/agent/create-agent-ui-stream-response.ts +3 -0
- package/src/agent/pipe-agent-ui-stream-to-response.ts +3 -0
- package/src/generate-text/prune-messages.ts +1 -1
- package/src/middleware/extract-reasoning-middleware.ts +27 -11
- package/src/ui/convert-to-model-messages.ts +18 -6
- package/src/ui-message-stream/create-sse-stream-with-keep-alive.ts +89 -0
- package/src/ui-message-stream/create-ui-message-stream-response.ts +7 -1
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +7 -1
- package/src/ui-message-stream/ui-message-stream-response-init.ts +7 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,54 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Arrayable, AssistantModelMessage, AssistantModelMessage as AssistantModelMessage$1, Context, Experimental_SandboxSession, FlexibleSchema, HasRequiredKey, InferToolContext, InferToolInput, InferToolOutput, InferToolSetContext, MaybePromiseLike, ModelMessage, ModelMessage as ModelMessage$1, ProviderOptions, ReasoningFilePart, ReasoningPart, RetryFunction, ShouldRetryFunction, SystemModelMessage, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolExecutionOptions, ToolModelMessage, ToolModelMessage as ToolModelMessage$1, ToolResultOutput, ToolResultPart, ToolSet, convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { AISDKError, EmbeddingModelV4Embedding, Experimental_EvaluationModelV4CallOptions, Experimental_EvaluationModelV4Question, Experimental_EvaluationModelV4Result, JSONObject, JSONSchema7, LanguageModelV2, LanguageModelV3, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4FunctionTool, LanguageModelV4Prompt, LanguageModelV4ProviderTool, LanguageModelV4Source, LanguageModelV4ToolCall, LanguageModelV4ToolChoice, LanguageModelV4ToolResultOutput, LanguageModelV4Usage, ProviderV2, ProviderV3, ProviderV4, SharedV4ProviderMetadata, SharedV4Warning } from "@ai-sdk/provider";
|
|
3
|
+
import { array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, lazy, literal, looseObject, never, null as null$1, number, object, record, string, union, unknown } from "zod/v4";
|
|
4
|
+
import { GatewayModelId } from "@ai-sdk/gateway";
|
|
5
|
+
//#region src/types/embedding-model.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Embedding.
|
|
9
8
|
*/
|
|
10
9
|
type Embedding = EmbeddingModelV4Embedding;
|
|
11
|
-
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types/language-model.d.ts
|
|
12
12
|
declare global {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* Global interface that can be augmented by third-party packages to register custom model IDs.
|
|
15
|
+
*
|
|
16
|
+
* You can register model IDs in two ways:
|
|
17
|
+
*
|
|
18
|
+
* 1. Register based on Model IDs from a provider package:
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { openai } from '@ai-sdk/openai';
|
|
22
|
+
* type OpenAIResponsesModelId = Parameters<typeof openai>[0];
|
|
23
|
+
*
|
|
24
|
+
* declare global {
|
|
25
|
+
* interface RegisteredProviderModels {
|
|
26
|
+
* openai: OpenAIResponsesModelId;
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* 2. Register individual model IDs directly as keys:
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* declare global {
|
|
35
|
+
* interface RegisteredProviderModels {
|
|
36
|
+
* 'my-provider:my-model': any;
|
|
37
|
+
* 'my-provider:another-model': any;
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
interface RegisteredProviderModels {}
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
45
|
* Global provider model ID type that defaults to GatewayModelId but can be augmented
|
|
47
46
|
* by third-party packages via declaration merging.
|
|
48
47
|
*/
|
|
49
|
-
type GlobalProviderModelId = [keyof RegisteredProviderModels] extends [
|
|
50
|
-
never
|
|
51
|
-
] ? GatewayModelId : keyof RegisteredProviderModels | RegisteredProviderModels[keyof RegisteredProviderModels];
|
|
48
|
+
type GlobalProviderModelId = [keyof RegisteredProviderModels] extends [never] ? GatewayModelId : keyof RegisteredProviderModels | RegisteredProviderModels[keyof RegisteredProviderModels];
|
|
52
49
|
/**
|
|
53
50
|
* Language model that is used by the AI SDK.
|
|
54
51
|
*/
|
|
@@ -83,62 +80,66 @@ type Source = LanguageModelV4Source;
|
|
|
83
80
|
* - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
|
84
81
|
*/
|
|
85
82
|
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
type: 'tool';
|
|
84
|
+
toolName: Extract<keyof TOOLS, string>;
|
|
88
85
|
};
|
|
89
|
-
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/types/language-model-request-metadata.d.ts
|
|
90
88
|
/**
|
|
91
89
|
* Metadata for a language model request.
|
|
92
90
|
*/
|
|
93
91
|
type LanguageModelRequestMetadata = {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
|
|
92
|
+
/**
|
|
93
|
+
* The input messages that were sent to the model for this step.
|
|
94
|
+
*/
|
|
95
|
+
readonly messages?: Array<ModelMessage>;
|
|
96
|
+
/**
|
|
97
|
+
* Request HTTP body that was sent to the provider API.
|
|
98
|
+
*/
|
|
99
|
+
readonly body?: unknown;
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/generate-text/response-message.d.ts
|
|
104
103
|
/**
|
|
105
104
|
* A message that was generated during the generation process.
|
|
106
105
|
* It can be either an assistant message or a tool message.
|
|
107
106
|
*/
|
|
108
107
|
type ResponseMessage = AssistantModelMessage | ToolModelMessage;
|
|
109
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/types/language-model-response-metadata.d.ts
|
|
110
110
|
/**
|
|
111
111
|
* Metadata for a language model response.
|
|
112
112
|
*/
|
|
113
113
|
type LanguageModelResponseMetadata = {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
|
|
114
|
+
/**
|
|
115
|
+
* The response messages that were generated during the call.
|
|
116
|
+
* Response messages can be either assistant messages or tool messages.
|
|
117
|
+
* They contain a generated id.
|
|
118
|
+
*/
|
|
119
|
+
readonly messages: Array<ResponseMessage>;
|
|
120
|
+
/**
|
|
121
|
+
* ID for the generated response.
|
|
122
|
+
*/
|
|
123
|
+
readonly id: string;
|
|
124
|
+
/**
|
|
125
|
+
* Timestamp for the start of the generated response.
|
|
126
|
+
*/
|
|
127
|
+
readonly timestamp: Date;
|
|
128
|
+
/**
|
|
129
|
+
* The ID of the response model that was used to generate the response.
|
|
130
|
+
*/
|
|
131
|
+
readonly modelId: string;
|
|
132
|
+
/**
|
|
133
|
+
* Response headers (available only for providers that use HTTP requests).
|
|
134
|
+
*/
|
|
135
|
+
readonly headers?: Record<string, string>;
|
|
136
|
+
/**
|
|
137
|
+
* Response body (available only for providers that use HTTP requests).
|
|
138
|
+
*/
|
|
139
|
+
readonly body?: unknown;
|
|
140
|
+
};
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/types/provider-metadata.d.ts
|
|
142
143
|
/**
|
|
143
144
|
* Additional provider-specific metadata that is returned from the provider.
|
|
144
145
|
*
|
|
@@ -146,80 +147,83 @@ type LanguageModelResponseMetadata = {
|
|
|
146
147
|
* fully encapsulated in the provider.
|
|
147
148
|
*/
|
|
148
149
|
type ProviderMetadata = SharedV4ProviderMetadata;
|
|
149
|
-
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/types/usage.d.ts
|
|
150
152
|
/**
|
|
151
153
|
* Represents the number of tokens used in a prompt and completion.
|
|
152
154
|
*/
|
|
153
155
|
type LanguageModelUsage = {
|
|
156
|
+
/**
|
|
157
|
+
* The total number of input (prompt) tokens used.
|
|
158
|
+
*/
|
|
159
|
+
inputTokens: number | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Detailed information about the input tokens.
|
|
162
|
+
*/
|
|
163
|
+
inputTokenDetails: {
|
|
154
164
|
/**
|
|
155
|
-
* The
|
|
165
|
+
* The number of non-cached input (prompt) tokens used.
|
|
156
166
|
*/
|
|
157
|
-
|
|
167
|
+
noCacheTokens: number | undefined;
|
|
158
168
|
/**
|
|
159
|
-
*
|
|
169
|
+
* The number of cached input (prompt) tokens read.
|
|
160
170
|
*/
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* The number of non-cached input (prompt) tokens used.
|
|
164
|
-
*/
|
|
165
|
-
noCacheTokens: number | undefined;
|
|
166
|
-
/**
|
|
167
|
-
* The number of cached input (prompt) tokens read.
|
|
168
|
-
*/
|
|
169
|
-
cacheReadTokens: number | undefined;
|
|
170
|
-
/**
|
|
171
|
-
* The number of cached input (prompt) tokens written.
|
|
172
|
-
*/
|
|
173
|
-
cacheWriteTokens: number | undefined;
|
|
174
|
-
};
|
|
171
|
+
cacheReadTokens: number | undefined;
|
|
175
172
|
/**
|
|
176
|
-
* The number of
|
|
173
|
+
* The number of cached input (prompt) tokens written.
|
|
177
174
|
*/
|
|
178
|
-
|
|
175
|
+
cacheWriteTokens: number | undefined;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* The number of total output (completion) tokens used.
|
|
179
|
+
*/
|
|
180
|
+
outputTokens: number | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Detailed information about the output tokens.
|
|
183
|
+
*/
|
|
184
|
+
outputTokenDetails: {
|
|
179
185
|
/**
|
|
180
|
-
*
|
|
186
|
+
* The number of text tokens used.
|
|
181
187
|
*/
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* The number of text tokens used.
|
|
185
|
-
*/
|
|
186
|
-
textTokens: number | undefined;
|
|
187
|
-
/**
|
|
188
|
-
* The number of reasoning tokens used.
|
|
189
|
-
*/
|
|
190
|
-
reasoningTokens: number | undefined;
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* The total number of tokens used.
|
|
194
|
-
*/
|
|
195
|
-
totalTokens: number | undefined;
|
|
188
|
+
textTokens: number | undefined;
|
|
196
189
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* This is the usage information in the shape that the provider returns.
|
|
200
|
-
* It can include additional information that is not part of the standard usage information.
|
|
190
|
+
* The number of reasoning tokens used.
|
|
201
191
|
*/
|
|
202
|
-
|
|
192
|
+
reasoningTokens: number | undefined;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The total number of tokens used.
|
|
196
|
+
*/
|
|
197
|
+
totalTokens: number | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Raw usage information from the provider.
|
|
200
|
+
*
|
|
201
|
+
* This is the usage information in the shape that the provider returns.
|
|
202
|
+
* It can include additional information that is not part of the standard usage information.
|
|
203
|
+
*/
|
|
204
|
+
raw?: JSONObject;
|
|
203
205
|
};
|
|
204
206
|
/**
|
|
205
207
|
* Represents the number of tokens used in an embedding.
|
|
206
208
|
*/
|
|
207
209
|
type EmbeddingModelUsage = {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
/**
|
|
211
|
+
* The number of tokens used in the embedding.
|
|
212
|
+
*/
|
|
213
|
+
tokens: number;
|
|
212
214
|
};
|
|
213
|
-
declare function asLanguageModelUsage(usage: LanguageModelV4Usage): LanguageModelUsage;
|
|
214
|
-
declare function createNullLanguageModelUsage(): LanguageModelUsage;
|
|
215
|
-
declare function addLanguageModelUsage(usage1: LanguageModelUsage, usage2: LanguageModelUsage): LanguageModelUsage;
|
|
216
|
-
|
|
215
|
+
export declare function asLanguageModelUsage(usage: LanguageModelV4Usage): LanguageModelUsage;
|
|
216
|
+
export declare function createNullLanguageModelUsage(): LanguageModelUsage;
|
|
217
|
+
export declare function addLanguageModelUsage(usage1: LanguageModelUsage, usage2: LanguageModelUsage): LanguageModelUsage;
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/types/warning.d.ts
|
|
217
220
|
/**
|
|
218
221
|
* Warning from the model provider for this call. The call will proceed, but e.g.
|
|
219
222
|
* some settings might not be supported, which can lead to suboptimal results.
|
|
220
223
|
*/
|
|
221
224
|
type Warning = SharedV4Warning;
|
|
222
|
-
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/logger/log-warnings.d.ts
|
|
223
227
|
/**
|
|
224
228
|
* A function for logging warnings.
|
|
225
229
|
*
|
|
@@ -233,44 +237,45 @@ type Warning = SharedV4Warning;
|
|
|
233
237
|
* ```
|
|
234
238
|
*/
|
|
235
239
|
type LogWarningsFunction = (options: {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
/**
|
|
241
|
+
* The warnings returned by the model provider.
|
|
242
|
+
*/
|
|
243
|
+
warnings: Warning[];
|
|
244
|
+
/**
|
|
245
|
+
* The provider id used for the call, if scoped to a specific provider.
|
|
246
|
+
*/
|
|
247
|
+
provider?: string;
|
|
248
|
+
/**
|
|
249
|
+
* The model id used for the call, if scoped to a specific provider.
|
|
250
|
+
*/
|
|
251
|
+
model?: string;
|
|
248
252
|
}) => void;
|
|
249
|
-
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/embed/embed-events.d.ts
|
|
250
255
|
/**
|
|
251
256
|
* Event passed to the `onStart` callback for embed and embedMany operations.
|
|
252
257
|
*
|
|
253
258
|
* Called when the operation begins, before the embedding model is called.
|
|
254
259
|
*/
|
|
255
260
|
type EmbedStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
261
|
+
/** User-defined runtime context. */
|
|
262
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
263
|
+
/** Unique identifier for this embed call, used to correlate events. */
|
|
264
|
+
readonly callId: string;
|
|
265
|
+
/** Identifies the operation type (e.g. 'ai.embed' or 'ai.embedMany'). */
|
|
266
|
+
readonly operationId: string;
|
|
267
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
268
|
+
readonly provider: string;
|
|
269
|
+
/** The specific model identifier (e.g., 'text-embedding-3-small'). */
|
|
270
|
+
readonly modelId: string;
|
|
271
|
+
/** The value(s) being embedded. A string for embed, an array for embedMany. */
|
|
272
|
+
readonly value: string | Array<string>;
|
|
273
|
+
/** Maximum number of retries for failed requests. */
|
|
274
|
+
readonly maxRetries: number;
|
|
275
|
+
/** Additional HTTP headers sent with the request. */
|
|
276
|
+
readonly headers: Record<string, string | undefined> | undefined;
|
|
277
|
+
/** Additional provider-specific options. */
|
|
278
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
274
279
|
};
|
|
275
280
|
/**
|
|
276
281
|
* Event passed to the `onEnd` callback for embed and embedMany operations.
|
|
@@ -278,34 +283,34 @@ type EmbedStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
|
278
283
|
* Called when the operation completes, after the embedding model returns.
|
|
279
284
|
*/
|
|
280
285
|
type EmbedEndEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
286
|
+
/** User-defined runtime context. */
|
|
287
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
288
|
+
/** Unique identifier for this embed call, used to correlate events. */
|
|
289
|
+
readonly callId: string;
|
|
290
|
+
/** Identifies the operation type (e.g. 'ai.embed' or 'ai.embedMany'). */
|
|
291
|
+
readonly operationId: string;
|
|
292
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
293
|
+
readonly provider: string;
|
|
294
|
+
/** The specific model identifier (e.g., 'text-embedding-3-small'). */
|
|
295
|
+
readonly modelId: string;
|
|
296
|
+
/** The value(s) that were embedded. A string for embed, an array for embedMany. */
|
|
297
|
+
readonly value: string | Array<string>;
|
|
298
|
+
/** The resulting embedding(s). A single vector for embed, an array for embedMany. */
|
|
299
|
+
readonly embedding: Embedding | Array<Embedding>;
|
|
300
|
+
/** Token usage for the embedding operation. */
|
|
301
|
+
readonly usage: EmbeddingModelUsage;
|
|
302
|
+
/** Warnings from the embedding model, e.g. unsupported settings. */
|
|
303
|
+
readonly warnings: Array<Warning>;
|
|
304
|
+
/** Optional provider-specific metadata. */
|
|
305
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
|
306
|
+
/** Response data including headers and body. A single response for embed, an array for embedMany. */
|
|
307
|
+
readonly response: {
|
|
308
|
+
headers?: Record<string, string>;
|
|
309
|
+
body?: unknown;
|
|
310
|
+
} | Array<{
|
|
311
|
+
headers?: Record<string, string>;
|
|
312
|
+
body?: unknown;
|
|
313
|
+
} | undefined> | undefined;
|
|
309
314
|
};
|
|
310
315
|
/**
|
|
311
316
|
* Event fired when an individual embedding model call (inner operation doEmbed) begins.
|
|
@@ -314,18 +319,18 @@ type EmbedEndEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
|
314
319
|
* calls when values are chunked.
|
|
315
320
|
*/
|
|
316
321
|
type EmbeddingModelCallStartEvent = {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
322
|
+
/** Unique identifier for this embed call, used to correlate events. */
|
|
323
|
+
readonly callId: string;
|
|
324
|
+
/** Unique identifier for this individual doEmbed invocation, used to correlate start/finish within parallel chunks. */
|
|
325
|
+
readonly embedCallId: string;
|
|
326
|
+
/** Identifies the inner operation (e.g. 'ai.embed.doEmbed' or 'ai.embedMany.doEmbed'). */
|
|
327
|
+
readonly operationId: string;
|
|
328
|
+
/** The provider identifier. */
|
|
329
|
+
readonly provider: string;
|
|
330
|
+
/** The specific model identifier. */
|
|
331
|
+
readonly modelId: string;
|
|
332
|
+
/** The values being embedded in this particular model call. */
|
|
333
|
+
readonly values: Array<string>;
|
|
329
334
|
};
|
|
330
335
|
/**
|
|
331
336
|
* Event fired when an individual embedding model call (doEmbed) completes.
|
|
@@ -333,86 +338,86 @@ type EmbeddingModelCallStartEvent = {
|
|
|
333
338
|
* Contains the embeddings, usage, and any warnings from the model response.
|
|
334
339
|
*/
|
|
335
340
|
type EmbeddingModelCallEndEvent = {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
};
|
|
353
|
-
|
|
341
|
+
/** Unique identifier for this embed call, used to correlate events. */
|
|
342
|
+
readonly callId: string;
|
|
343
|
+
/** Unique identifier for this individual doEmbed invocation, used to correlate start/finish within parallel chunks. */
|
|
344
|
+
readonly embedCallId: string;
|
|
345
|
+
/** Identifies the inner operation (e.g. 'ai.embed.doEmbed' or 'ai.embedMany.doEmbed'). */
|
|
346
|
+
readonly operationId: string;
|
|
347
|
+
/** The provider identifier. */
|
|
348
|
+
readonly provider: string;
|
|
349
|
+
/** The specific model identifier. */
|
|
350
|
+
readonly modelId: string;
|
|
351
|
+
/** The values that were embedded in this particular model call. */
|
|
352
|
+
readonly values: Array<string>;
|
|
353
|
+
/** The resulting embeddings from the model call. */
|
|
354
|
+
readonly embeddings: Array<Embedding>;
|
|
355
|
+
/** Token usage for this model call. */
|
|
356
|
+
readonly usage: EmbeddingModelUsage;
|
|
357
|
+
};
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/evaluate/evaluation-result.d.ts
|
|
354
360
|
type EvaluationQuestion = Experimental_EvaluationModelV4Question;
|
|
355
361
|
type EvaluationAnswer<QUESTION extends EvaluationQuestion> = QUESTION extends {
|
|
356
|
-
|
|
357
|
-
|
|
362
|
+
type: 'choice';
|
|
363
|
+
criteria: infer CRITERIA;
|
|
358
364
|
} ? {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
365
|
+
type: 'choice';
|
|
366
|
+
choice: Extract<keyof CRITERIA, string>;
|
|
367
|
+
probabilities?: Record<Extract<keyof CRITERIA, string>, number>;
|
|
362
368
|
} : QUESTION extends {
|
|
363
|
-
|
|
369
|
+
type: 'score';
|
|
364
370
|
} ? {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
371
|
+
type: 'score';
|
|
372
|
+
score: number;
|
|
373
|
+
probabilities?: Record<string, number>;
|
|
368
374
|
} : {
|
|
369
|
-
|
|
370
|
-
|
|
375
|
+
type: 'boolean';
|
|
376
|
+
probability: number;
|
|
371
377
|
};
|
|
372
378
|
type EvaluationResult<QUESTIONS extends Record<string, EvaluationQuestion>> = {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
379
|
+
readonly answers: { [ID in keyof QUESTIONS]: EvaluationAnswer<QUESTIONS[ID]>; };
|
|
380
|
+
readonly usage: {
|
|
381
|
+
inputTokens: number | undefined;
|
|
382
|
+
outputTokens: number | undefined;
|
|
383
|
+
totalTokens: number | undefined;
|
|
384
|
+
};
|
|
385
|
+
readonly warnings: Experimental_EvaluationModelV4Result['warnings'];
|
|
386
|
+
readonly rounding: Experimental_EvaluationModelV4Result['rounding'];
|
|
387
|
+
readonly providerMetadata: Experimental_EvaluationModelV4Result['providerMetadata'];
|
|
388
|
+
readonly response: NonNullable<Experimental_EvaluationModelV4Result['response']> & {
|
|
389
|
+
timestamp: Date;
|
|
390
|
+
modelId: string;
|
|
391
|
+
};
|
|
392
|
+
};
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/evaluate/evaluate-events.d.ts
|
|
390
395
|
/**
|
|
391
396
|
* Event passed to the `onStart` callback for evaluation operations.
|
|
392
397
|
*
|
|
393
398
|
* Called when the operation begins, before the evaluation model is called.
|
|
394
399
|
*/
|
|
395
400
|
type EvaluateStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
401
|
+
/** User-defined runtime context. */
|
|
402
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
403
|
+
/** Unique identifier for this evaluation call, used to correlate events. */
|
|
404
|
+
readonly callId: string;
|
|
405
|
+
/** Identifies the operation type (`ai.evaluate`). */
|
|
406
|
+
readonly operationId: 'ai.evaluate';
|
|
407
|
+
/** The provider identifier. */
|
|
408
|
+
readonly provider: string;
|
|
409
|
+
/** The evaluation model identifier. */
|
|
410
|
+
readonly modelId: string;
|
|
411
|
+
/** The shared state being evaluated. */
|
|
412
|
+
readonly state: Experimental_EvaluationModelV4CallOptions['state'];
|
|
413
|
+
/** The questions being evaluated against the shared state. */
|
|
414
|
+
readonly questions: Readonly<Record<string, EvaluationQuestion>>;
|
|
415
|
+
/** Maximum number of retries for the evaluation model call. */
|
|
416
|
+
readonly maxRetries: number;
|
|
417
|
+
/** Additional HTTP headers sent with the request. */
|
|
418
|
+
readonly headers: Record<string, string> | undefined;
|
|
419
|
+
/** Additional provider-specific options. */
|
|
420
|
+
readonly providerOptions: ProviderOptions;
|
|
416
421
|
};
|
|
417
422
|
/**
|
|
418
423
|
* Event passed to the `onEnd` callback for evaluation operations.
|
|
@@ -420,18 +425,18 @@ type EvaluateStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
|
420
425
|
* Called when the operation completes successfully.
|
|
421
426
|
*/
|
|
422
427
|
type EvaluateEndEvent<RUNTIME_CONTEXT extends Context = Context> = EvaluateStartEvent<RUNTIME_CONTEXT> & {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
428
|
+
/** Exactly one typed answer per question ID. */
|
|
429
|
+
readonly answers: EvaluationResult<Record<string, EvaluationQuestion>>['answers'];
|
|
430
|
+
/** Token usage for the evaluation operation. */
|
|
431
|
+
readonly usage: EvaluationResult<Record<string, EvaluationQuestion>>['usage'];
|
|
432
|
+
/** Warnings from the evaluation model. */
|
|
433
|
+
readonly warnings: EvaluationResult<Record<string, EvaluationQuestion>>['warnings'];
|
|
434
|
+
/** Provider-declared decimal precision for probabilities and scores. */
|
|
435
|
+
readonly rounding: EvaluationResult<Record<string, EvaluationQuestion>>['rounding'];
|
|
436
|
+
/** Optional provider-specific metadata. */
|
|
437
|
+
readonly providerMetadata: EvaluationResult<Record<string, EvaluationQuestion>>['providerMetadata'];
|
|
438
|
+
/** Response metadata, including the resolved model ID and timestamp. */
|
|
439
|
+
readonly response: EvaluationResult<Record<string, EvaluationQuestion>>['response'];
|
|
435
440
|
};
|
|
436
441
|
/**
|
|
437
442
|
* Event fired when the evaluation model call begins.
|
|
@@ -439,18 +444,18 @@ type EvaluateEndEvent<RUNTIME_CONTEXT extends Context = Context> = EvaluateStart
|
|
|
439
444
|
* The logical model call includes any provider retries.
|
|
440
445
|
*/
|
|
441
446
|
type EvaluationModelCallStartEvent = {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
447
|
+
/** Unique identifier for the outer evaluation call. */
|
|
448
|
+
readonly callId: string;
|
|
449
|
+
/** Identifies the inner operation (`ai.evaluate.doEvaluate`). */
|
|
450
|
+
readonly operationId: 'ai.evaluate.doEvaluate';
|
|
451
|
+
/** The provider identifier. */
|
|
452
|
+
readonly provider: string;
|
|
453
|
+
/** The evaluation model identifier. */
|
|
454
|
+
readonly modelId: string;
|
|
455
|
+
/** The shared state being evaluated. */
|
|
456
|
+
readonly state: Experimental_EvaluationModelV4CallOptions['state'];
|
|
457
|
+
/** The questions being evaluated against the shared state. */
|
|
458
|
+
readonly questions: Readonly<Record<string, EvaluationQuestion>>;
|
|
454
459
|
};
|
|
455
460
|
/**
|
|
456
461
|
* Event fired after the evaluation model response has been validated.
|
|
@@ -458,89 +463,91 @@ type EvaluationModelCallStartEvent = {
|
|
|
458
463
|
* Contains the result of the logical model call, including any retries.
|
|
459
464
|
*/
|
|
460
465
|
type EvaluationModelCallEndEvent = EvaluationModelCallStartEvent & {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
};
|
|
474
|
-
|
|
466
|
+
/** Exactly one answer per question ID. */
|
|
467
|
+
readonly answers: Experimental_EvaluationModelV4Result['answers'];
|
|
468
|
+
/** Token usage reported by the evaluation model. */
|
|
469
|
+
readonly usage?: Experimental_EvaluationModelV4Result['usage'];
|
|
470
|
+
/** Warnings from the evaluation model. */
|
|
471
|
+
readonly warnings: Experimental_EvaluationModelV4Result['warnings'];
|
|
472
|
+
/** Provider-declared decimal precision for probabilities and scores. */
|
|
473
|
+
readonly rounding?: Experimental_EvaluationModelV4Result['rounding'];
|
|
474
|
+
/** Optional provider-specific metadata. */
|
|
475
|
+
readonly providerMetadata?: Experimental_EvaluationModelV4Result['providerMetadata'];
|
|
476
|
+
/** Optional raw response metadata from the provider. */
|
|
477
|
+
readonly response?: Experimental_EvaluationModelV4Result['response'];
|
|
478
|
+
};
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/prompt/language-model-call-options.d.ts
|
|
475
481
|
/**
|
|
476
482
|
* Model-facing generation controls. These settings influence how the model
|
|
477
483
|
* generates its response (token limits, sampling, penalties, stop sequences,
|
|
478
484
|
* seed, reasoning).
|
|
479
485
|
*/
|
|
480
486
|
type LanguageModelCallOptions = {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
};
|
|
543
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Maximum number of tokens to generate.
|
|
489
|
+
*/
|
|
490
|
+
maxOutputTokens?: number;
|
|
491
|
+
/**
|
|
492
|
+
* Temperature setting. The range depends on the provider and model.
|
|
493
|
+
*
|
|
494
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
|
495
|
+
*/
|
|
496
|
+
temperature?: number;
|
|
497
|
+
/**
|
|
498
|
+
* Nucleus sampling. This is a number between 0 and 1.
|
|
499
|
+
*
|
|
500
|
+
* E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
|
501
|
+
* are considered.
|
|
502
|
+
*
|
|
503
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
|
504
|
+
*/
|
|
505
|
+
topP?: number;
|
|
506
|
+
/**
|
|
507
|
+
* Only sample from the top K options for each subsequent token.
|
|
508
|
+
*
|
|
509
|
+
* Used to remove "long tail" low probability responses.
|
|
510
|
+
* Recommended for advanced use cases only. You usually only need to use temperature.
|
|
511
|
+
*/
|
|
512
|
+
topK?: number;
|
|
513
|
+
/**
|
|
514
|
+
* Presence penalty setting. It affects the likelihood of the model to
|
|
515
|
+
* repeat information that is already in the prompt.
|
|
516
|
+
*
|
|
517
|
+
* The presence penalty is a number between -1 (increase repetition)
|
|
518
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
|
519
|
+
*/
|
|
520
|
+
presencePenalty?: number;
|
|
521
|
+
/**
|
|
522
|
+
* Frequency penalty setting. It affects the likelihood of the model
|
|
523
|
+
* to repeatedly use the same words or phrases.
|
|
524
|
+
*
|
|
525
|
+
* The frequency penalty is a number between -1 (increase repetition)
|
|
526
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
|
527
|
+
*/
|
|
528
|
+
frequencyPenalty?: number;
|
|
529
|
+
/**
|
|
530
|
+
* Stop sequences.
|
|
531
|
+
* If set, the model will stop generating text when one of the stop sequences is generated.
|
|
532
|
+
* Providers may have limits on the number of stop sequences.
|
|
533
|
+
*/
|
|
534
|
+
stopSequences?: string[];
|
|
535
|
+
/**
|
|
536
|
+
* The seed (integer) to use for random sampling. If set and supported
|
|
537
|
+
* by the model, calls will generate deterministic results.
|
|
538
|
+
*/
|
|
539
|
+
seed?: number;
|
|
540
|
+
/**
|
|
541
|
+
* Reasoning effort level for the model. Controls how much reasoning
|
|
542
|
+
* the model performs before generating a response.
|
|
543
|
+
*
|
|
544
|
+
* Use `'provider-default'` to use the provider's default reasoning level.
|
|
545
|
+
* Use `'none'` to disable reasoning (if supported by the provider).
|
|
546
|
+
*/
|
|
547
|
+
reasoning?: LanguageModelV4CallOptions['reasoning'];
|
|
548
|
+
};
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/prompt/request-options.d.ts
|
|
544
551
|
/**
|
|
545
552
|
* Timeout configuration for API calls. Can be specified as:
|
|
546
553
|
* - A number representing milliseconds
|
|
@@ -552,14 +559,15 @@ type LanguageModelCallOptions = {
|
|
|
552
559
|
* - An object with `tools` property for per-tool timeout overrides using `{toolName}Ms` keys
|
|
553
560
|
*/
|
|
554
561
|
type TimeoutConfiguration<TOOLS extends ToolSet> = number | {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
562
|
+
totalMs?: number;
|
|
563
|
+
stepMs?: number;
|
|
564
|
+
firstChunkMs?: number;
|
|
565
|
+
chunkMs?: number;
|
|
566
|
+
toolMs?: number;
|
|
567
|
+
tools?: Partial<Record<`${keyof TOOLS & string}Ms`, number>>;
|
|
561
568
|
};
|
|
562
|
-
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/prompt/prompt.d.ts
|
|
563
571
|
/**
|
|
564
572
|
* Instructions to include in the prompt. Can be used with `prompt` or `messages`.
|
|
565
573
|
*/
|
|
@@ -569,53 +577,54 @@ type Instructions = string | SystemModelMessage | Array<SystemModelMessage>;
|
|
|
569
577
|
* It contains instructions, a simple text prompt, or a list of messages.
|
|
570
578
|
*/
|
|
571
579
|
type Prompt = {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
580
|
+
/**
|
|
581
|
+
* Instructions to include in the prompt. Can be used with `prompt` or `messages`.
|
|
582
|
+
*/
|
|
583
|
+
instructions?: Instructions;
|
|
584
|
+
/**
|
|
585
|
+
* Instructions to include in the prompt. Can be used with `prompt` or `messages`.
|
|
586
|
+
*
|
|
587
|
+
* @deprecated Use `instructions` instead.
|
|
588
|
+
*/
|
|
589
|
+
system?: Instructions;
|
|
590
|
+
/**
|
|
591
|
+
* Whether system messages are allowed in the `prompt` or `messages` fields.
|
|
592
|
+
*
|
|
593
|
+
* When disabled, system messages must be provided through the `instructions`
|
|
594
|
+
* option.
|
|
595
|
+
*
|
|
596
|
+
* @default false
|
|
597
|
+
*/
|
|
598
|
+
allowSystemInMessages?: boolean;
|
|
591
599
|
} & ({
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
600
|
+
/**
|
|
601
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
602
|
+
*
|
|
603
|
+
* You can either use `prompt` or `messages` but not both.
|
|
604
|
+
*/
|
|
605
|
+
prompt: string | Array<ModelMessage>;
|
|
606
|
+
/**
|
|
607
|
+
* A list of messages.
|
|
608
|
+
*
|
|
609
|
+
* You can either use `prompt` or `messages` but not both.
|
|
610
|
+
*/
|
|
611
|
+
messages?: never;
|
|
604
612
|
} | {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
613
|
+
/**
|
|
614
|
+
* A list of messages.
|
|
615
|
+
*
|
|
616
|
+
* You can either use `prompt` or `messages` but not both.
|
|
617
|
+
*/
|
|
618
|
+
messages: Array<ModelMessage>;
|
|
619
|
+
/**
|
|
620
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
621
|
+
*
|
|
622
|
+
* You can either use `prompt` or `messages` but not both.
|
|
623
|
+
*/
|
|
624
|
+
prompt?: never;
|
|
617
625
|
});
|
|
618
|
-
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region src/generate-object/structured-output-events.d.ts
|
|
619
628
|
/**
|
|
620
629
|
* Event passed to the `onStart` callback of
|
|
621
630
|
* `generateObject` and `streamObject`.
|
|
@@ -625,48 +634,48 @@ type Prompt = {
|
|
|
625
634
|
* @deprecated
|
|
626
635
|
*/
|
|
627
636
|
interface GenerateObjectStartEvent {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
637
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
638
|
+
readonly callId: string;
|
|
639
|
+
/** Identifies the operation type (e.g. `'ai.generateObject'` or `'ai.streamObject'`). */
|
|
640
|
+
readonly operationId: string;
|
|
641
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
642
|
+
readonly provider: string;
|
|
643
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
644
|
+
readonly modelId: string;
|
|
645
|
+
/** The system message(s) provided to the model. */
|
|
646
|
+
readonly system: Instructions | undefined;
|
|
647
|
+
/** The prompt string or array of messages if using the prompt option. */
|
|
648
|
+
readonly prompt: string | Array<ModelMessage> | undefined;
|
|
649
|
+
/** The messages array if using the messages option. */
|
|
650
|
+
readonly messages: Array<ModelMessage> | undefined;
|
|
651
|
+
/** Maximum number of tokens to generate. */
|
|
652
|
+
readonly maxOutputTokens: number | undefined;
|
|
653
|
+
/** Sampling temperature for generation. */
|
|
654
|
+
readonly temperature: number | undefined;
|
|
655
|
+
/** Top-p (nucleus) sampling parameter. */
|
|
656
|
+
readonly topP: number | undefined;
|
|
657
|
+
/** Top-k sampling parameter. */
|
|
658
|
+
readonly topK: number | undefined;
|
|
659
|
+
/** Presence penalty for generation. */
|
|
660
|
+
readonly presencePenalty: number | undefined;
|
|
661
|
+
/** Frequency penalty for generation. */
|
|
662
|
+
readonly frequencyPenalty: number | undefined;
|
|
663
|
+
/** Random seed for reproducible generation. */
|
|
664
|
+
readonly seed: number | undefined;
|
|
665
|
+
/** Maximum number of retries for failed requests. */
|
|
666
|
+
readonly maxRetries: number;
|
|
667
|
+
/** Additional HTTP headers sent with the request. */
|
|
668
|
+
readonly headers: Record<string, string | undefined> | undefined;
|
|
669
|
+
/** Additional provider-specific options. */
|
|
670
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
671
|
+
/** The output strategy type. */
|
|
672
|
+
readonly output: 'object' | 'array' | 'enum' | 'no-schema';
|
|
673
|
+
/** The JSON Schema used for object generation, if any. */
|
|
674
|
+
readonly schema: Record<string, unknown> | undefined;
|
|
675
|
+
/** Optional name of the schema. */
|
|
676
|
+
readonly schemaName: string | undefined;
|
|
677
|
+
/** Optional description of the schema. */
|
|
678
|
+
readonly schemaDescription: string | undefined;
|
|
670
679
|
}
|
|
671
680
|
/**
|
|
672
681
|
* Event passed to the `onStepStart` callback of
|
|
@@ -678,20 +687,20 @@ interface GenerateObjectStartEvent {
|
|
|
678
687
|
* @deprecated
|
|
679
688
|
*/
|
|
680
689
|
interface GenerateObjectStepStartEvent {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
690
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
691
|
+
readonly callId: string;
|
|
692
|
+
/** Zero-based index of the current step. Always `0` for object generation. */
|
|
693
|
+
readonly stepNumber: 0;
|
|
694
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
695
|
+
readonly provider: string;
|
|
696
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
697
|
+
readonly modelId: string;
|
|
698
|
+
/** Additional provider-specific options. */
|
|
699
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
700
|
+
/** Additional HTTP headers sent with the request. */
|
|
701
|
+
readonly headers: Record<string, string | undefined> | undefined;
|
|
702
|
+
/** The prompt messages in provider format (for telemetry). */
|
|
703
|
+
readonly promptMessages?: LanguageModelV4Prompt;
|
|
695
704
|
}
|
|
696
705
|
/**
|
|
697
706
|
* Event passed to the `onStepEnd` callback of
|
|
@@ -703,32 +712,32 @@ interface GenerateObjectStepStartEvent {
|
|
|
703
712
|
* @deprecated
|
|
704
713
|
*/
|
|
705
714
|
interface GenerateObjectStepEndEvent {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
715
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
716
|
+
readonly callId: string;
|
|
717
|
+
/** Zero-based index of the current step. Always `0` for object generation. */
|
|
718
|
+
readonly stepNumber: 0;
|
|
719
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
720
|
+
readonly provider: string;
|
|
721
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
722
|
+
readonly modelId: string;
|
|
723
|
+
/** The unified reason why the generation finished. */
|
|
724
|
+
readonly finishReason: FinishReason;
|
|
725
|
+
/** The token usage of the generated response. */
|
|
726
|
+
readonly usage: LanguageModelUsage;
|
|
727
|
+
/** The raw text output from the model (before JSON parsing). */
|
|
728
|
+
readonly objectText: string;
|
|
729
|
+
/** The reasoning generated by the model, if any. */
|
|
730
|
+
readonly reasoning: string | undefined;
|
|
731
|
+
/** Warnings from the model provider (e.g. unsupported settings). */
|
|
732
|
+
readonly warnings: CallWarning[] | undefined;
|
|
733
|
+
/** Additional request information. */
|
|
734
|
+
readonly request: Omit<LanguageModelRequestMetadata, 'messages'>;
|
|
735
|
+
/** Additional response information. */
|
|
736
|
+
readonly response: Omit<LanguageModelResponseMetadata, 'messages'>;
|
|
737
|
+
/** Additional provider-specific metadata. */
|
|
738
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
|
739
|
+
/** Milliseconds from the start of the stream to the first chunk (streaming only). */
|
|
740
|
+
readonly msToFirstChunk: number | undefined;
|
|
732
741
|
}
|
|
733
742
|
/**
|
|
734
743
|
* Event passed to the `onFinish` callback of
|
|
@@ -741,44 +750,45 @@ interface GenerateObjectStepEndEvent {
|
|
|
741
750
|
* @deprecated
|
|
742
751
|
*/
|
|
743
752
|
interface GenerateObjectEndEvent<RESULT> {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
753
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
754
|
+
readonly callId: string;
|
|
755
|
+
/**
|
|
756
|
+
* The generated object (typed according to the schema).
|
|
757
|
+
* Always defined for `generateObject`. May be `undefined` for `streamObject`
|
|
758
|
+
* when parsing or validation fails.
|
|
759
|
+
*/
|
|
760
|
+
readonly object: RESULT | undefined;
|
|
761
|
+
/**
|
|
762
|
+
* Error from parsing or schema validation, if any.
|
|
763
|
+
* Always `undefined` for `generateObject` (which throws instead).
|
|
764
|
+
*/
|
|
765
|
+
readonly error: unknown | undefined;
|
|
766
|
+
/** The reasoning generated by the model, if any. */
|
|
767
|
+
readonly reasoning: string | undefined;
|
|
768
|
+
/** The unified reason why the generation finished. */
|
|
769
|
+
readonly finishReason: FinishReason;
|
|
770
|
+
/** The token usage of the generated response. */
|
|
771
|
+
readonly usage: LanguageModelUsage;
|
|
772
|
+
/** Warnings from the model provider (e.g. unsupported settings). */
|
|
773
|
+
readonly warnings: CallWarning[] | undefined;
|
|
774
|
+
/** Additional request information. */
|
|
775
|
+
readonly request: Omit<LanguageModelRequestMetadata, 'messages'>;
|
|
776
|
+
/** Additional response information. */
|
|
777
|
+
readonly response: Omit<LanguageModelResponseMetadata, 'messages'>;
|
|
778
|
+
/** Additional provider-specific metadata. */
|
|
779
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
|
771
780
|
}
|
|
772
|
-
|
|
781
|
+
//#endregion
|
|
782
|
+
//#region src/prompt/standardize-prompt.d.ts
|
|
773
783
|
type StandardizedPrompt = {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
784
|
+
/**
|
|
785
|
+
* Instructions.
|
|
786
|
+
*/
|
|
787
|
+
instructions: Instructions | undefined;
|
|
788
|
+
/**
|
|
789
|
+
* Messages.
|
|
790
|
+
*/
|
|
791
|
+
messages: ModelMessage[];
|
|
782
792
|
};
|
|
783
793
|
/**
|
|
784
794
|
* Converts a prompt input into a standardized prompt with validated model
|
|
@@ -791,13 +801,15 @@ type StandardizedPrompt = {
|
|
|
791
801
|
* @returns The standardized prompt.
|
|
792
802
|
* @throws {InvalidPromptError} When the prompt is invalid.
|
|
793
803
|
*/
|
|
794
|
-
declare function standardizePrompt({ allowSystemInMessages, system, instructions, prompt, messages
|
|
795
|
-
|
|
804
|
+
export declare function standardizePrompt({ allowSystemInMessages, system, instructions, prompt, messages }: Prompt): Promise<StandardizedPrompt>;
|
|
805
|
+
//#endregion
|
|
806
|
+
//#region src/util/callback.d.ts
|
|
796
807
|
/**
|
|
797
808
|
* A callback function that can be used with `notify`.
|
|
798
809
|
*/
|
|
799
810
|
type Callback<EVENT> = (event: EVENT) => PromiseLike<void> | void;
|
|
800
|
-
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/generate-text/active-tools.d.ts
|
|
801
813
|
/**
|
|
802
814
|
* Tool names that are enabled for a generation step.
|
|
803
815
|
*
|
|
@@ -806,61 +818,59 @@ type Callback<EVENT> = (event: EVENT) => PromiseLike<void> | void;
|
|
|
806
818
|
* tool set.
|
|
807
819
|
*/
|
|
808
820
|
type ActiveTools<TOOLS extends ToolSet> = ReadonlyArray<keyof TOOLS & string> | undefined;
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
} | undefined;
|
|
813
|
-
type IncludedToolsContext<TOOLS extends ToolSet> = {
|
|
814
|
-
[TOOL_NAME in keyof NoInfer<InferToolSetContext<TOOLS>>]?: IncludedContext<NoInfer<InferToolSetContext<TOOLS>[TOOL_NAME]>>;
|
|
815
|
-
} | undefined;
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/telemetry/telemetry-options.d.ts
|
|
823
|
+
type IncludedContext<CONTEXT extends Context | unknown | never> = { [KEY in keyof NoInfer<CONTEXT>]?: boolean; } | undefined;
|
|
824
|
+
type IncludedToolsContext<TOOLS extends ToolSet> = { [TOOL_NAME in keyof NoInfer<InferToolSetContext<TOOLS>>]?: IncludedContext<NoInfer<InferToolSetContext<TOOLS>[TOOL_NAME]>>; } | undefined;
|
|
816
825
|
/**
|
|
817
826
|
* Telemetry configuration.
|
|
818
827
|
*/
|
|
819
828
|
type TelemetryOptions<RUNTIME_CONTEXT extends Context = Context, TOOLS extends ToolSet = ToolSet> = {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
};
|
|
863
|
-
|
|
829
|
+
/**
|
|
830
|
+
* Enable or disable telemetry. Enabled by default when a telemetry
|
|
831
|
+
* integration is registered. Set to `false` to opt out.
|
|
832
|
+
*/
|
|
833
|
+
isEnabled?: boolean;
|
|
834
|
+
/**
|
|
835
|
+
* Enable or disable input recording. Enabled by default.
|
|
836
|
+
*
|
|
837
|
+
* You might want to disable input recording to avoid recording sensitive
|
|
838
|
+
* information, to reduce data transfers, or to increase performance.
|
|
839
|
+
*/
|
|
840
|
+
recordInputs?: boolean;
|
|
841
|
+
/**
|
|
842
|
+
* Enable or disable output recording. Enabled by default.
|
|
843
|
+
*
|
|
844
|
+
* You might want to disable output recording to avoid recording sensitive
|
|
845
|
+
* information, to reduce data transfers, or to increase performance.
|
|
846
|
+
*/
|
|
847
|
+
recordOutputs?: boolean;
|
|
848
|
+
/**
|
|
849
|
+
* Identifier for this function. Used to group telemetry data by function.
|
|
850
|
+
*/
|
|
851
|
+
functionId?: string;
|
|
852
|
+
/**
|
|
853
|
+
* Top-level runtime context properties that should be included in telemetry.
|
|
854
|
+
* Runtime context properties are excluded unless they are explicitly set to `true`.
|
|
855
|
+
*/
|
|
856
|
+
includeRuntimeContext?: IncludedContext<RUNTIME_CONTEXT>;
|
|
857
|
+
/**
|
|
858
|
+
* Top-level tool context properties that should be included in telemetry,
|
|
859
|
+
* configured per tool.
|
|
860
|
+
*
|
|
861
|
+
* Tool context properties are excluded unless they are explicitly set to `true`.
|
|
862
|
+
*/
|
|
863
|
+
includeToolsContext?: IncludedToolsContext<TOOLS>;
|
|
864
|
+
/**
|
|
865
|
+
* Per-call telemetry integrations that receive lifecycle events during generation.
|
|
866
|
+
*
|
|
867
|
+
* When provided, these integrations will take precedence over the globally registered
|
|
868
|
+
* integrations for this call.
|
|
869
|
+
*/
|
|
870
|
+
integrations?: Arrayable<Telemetry>;
|
|
871
|
+
};
|
|
872
|
+
//#endregion
|
|
873
|
+
//#region src/util/download/download.d.ts
|
|
864
874
|
/**
|
|
865
875
|
* Download a file from a URL.
|
|
866
876
|
*
|
|
@@ -871,15 +881,16 @@ type TelemetryOptions<RUNTIME_CONTEXT extends Context = Context, TOOLS extends T
|
|
|
871
881
|
*
|
|
872
882
|
* @throws DownloadError if the download fails or exceeds maxBytes.
|
|
873
883
|
*/
|
|
874
|
-
declare const download: ({ url, maxBytes, abortSignal
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
884
|
+
declare const download$1: ({ url, maxBytes, abortSignal }: {
|
|
885
|
+
url: URL;
|
|
886
|
+
maxBytes?: number;
|
|
887
|
+
abortSignal?: AbortSignal;
|
|
878
888
|
}) => Promise<{
|
|
879
|
-
|
|
880
|
-
|
|
889
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
890
|
+
mediaType: string | undefined;
|
|
881
891
|
}>;
|
|
882
|
-
|
|
892
|
+
//#endregion
|
|
893
|
+
//#region src/util/download/download-function.d.ts
|
|
883
894
|
/**
|
|
884
895
|
* Experimental. Can change in patch versions without warning.
|
|
885
896
|
*
|
|
@@ -898,76 +909,79 @@ declare const download: ({ url, maxBytes, abortSignal, }: {
|
|
|
898
909
|
* For each object, the data should be null if the URL should be passed through as is.
|
|
899
910
|
*/
|
|
900
911
|
type DownloadFunction = (options: Array<{
|
|
901
|
-
|
|
902
|
-
|
|
912
|
+
url: URL;
|
|
913
|
+
isUrlSupportedByModel: boolean;
|
|
903
914
|
}>) => PromiseLike<Array<{
|
|
904
|
-
|
|
905
|
-
|
|
915
|
+
data: Uint8Array;
|
|
916
|
+
mediaType: string | undefined;
|
|
906
917
|
} | null>>;
|
|
907
918
|
/**
|
|
908
919
|
* Default download function.
|
|
909
920
|
* Downloads the file if it is not supported by the model.
|
|
910
921
|
*/
|
|
911
|
-
declare const createDefaultDownloadFunction: (download?: typeof download, abortSignal?: AbortSignal) => DownloadFunction;
|
|
912
|
-
|
|
922
|
+
export declare const createDefaultDownloadFunction: (download?: typeof download$1, abortSignal?: AbortSignal) => DownloadFunction;
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region src/generate-text/generated-file.d.ts
|
|
913
925
|
/**
|
|
914
926
|
* A generated file.
|
|
915
927
|
*/
|
|
916
928
|
interface GeneratedFile {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
929
|
+
/**
|
|
930
|
+
* File as a base64 encoded string.
|
|
931
|
+
*/
|
|
932
|
+
readonly base64: string;
|
|
933
|
+
/**
|
|
934
|
+
* File as a Uint8Array.
|
|
935
|
+
*/
|
|
936
|
+
readonly uint8Array: Uint8Array;
|
|
937
|
+
/**
|
|
938
|
+
* The IANA media type of the file.
|
|
939
|
+
*
|
|
940
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
941
|
+
*/
|
|
942
|
+
readonly mediaType: string;
|
|
943
|
+
/**
|
|
944
|
+
* Provider-specific metadata for this file.
|
|
945
|
+
*/
|
|
946
|
+
readonly providerMetadata?: Record<string, JSONObject>;
|
|
935
947
|
}
|
|
936
|
-
|
|
948
|
+
//#endregion
|
|
949
|
+
//#region src/generate-text/reasoning-output.d.ts
|
|
937
950
|
/**
|
|
938
951
|
* Reasoning output of a text generation. It contains a reasoning.
|
|
939
952
|
*/
|
|
940
953
|
interface ReasoningOutput {
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
954
|
+
type: 'reasoning';
|
|
955
|
+
/**
|
|
956
|
+
* The reasoning text.
|
|
957
|
+
*/
|
|
958
|
+
text: string;
|
|
959
|
+
/**
|
|
960
|
+
* Additional provider-specific metadata. They are passed through
|
|
961
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
962
|
+
* functionality that can be fully encapsulated in the provider.
|
|
963
|
+
*/
|
|
964
|
+
providerMetadata?: ProviderMetadata;
|
|
952
965
|
}
|
|
953
966
|
/**
|
|
954
967
|
* Reasoning file output of a text generation.
|
|
955
968
|
* It contains a file generated as part of reasoning.
|
|
956
969
|
*/
|
|
957
970
|
interface ReasoningFileOutput {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
971
|
+
type: 'reasoning-file';
|
|
972
|
+
/**
|
|
973
|
+
* The generated file.
|
|
974
|
+
*/
|
|
975
|
+
file: GeneratedFile;
|
|
976
|
+
/**
|
|
977
|
+
* Additional provider-specific metadata. They are passed through
|
|
978
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
979
|
+
* functionality that can be fully encapsulated in the provider.
|
|
980
|
+
*/
|
|
981
|
+
providerMetadata?: ProviderMetadata;
|
|
969
982
|
}
|
|
970
|
-
|
|
983
|
+
//#endregion
|
|
984
|
+
//#region src/util/value-of.d.ts
|
|
971
985
|
/**
|
|
972
986
|
* Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
973
987
|
*
|
|
@@ -1009,499 +1023,501 @@ interface ReasoningFileOutput {
|
|
|
1009
1023
|
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
|
1010
1024
|
*/
|
|
1011
1025
|
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
1012
|
-
|
|
1026
|
+
//#endregion
|
|
1027
|
+
//#region src/generate-text/tool-call.d.ts
|
|
1013
1028
|
type BaseToolCall = {
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1029
|
+
type: 'tool-call';
|
|
1030
|
+
toolCallId: string;
|
|
1031
|
+
providerExecuted?: boolean;
|
|
1032
|
+
providerMetadata?: ProviderMetadata;
|
|
1033
|
+
toolMetadata?: JSONObject;
|
|
1019
1034
|
};
|
|
1020
1035
|
/**
|
|
1021
1036
|
* A tool call whose `toolName` maps to a tool in the declared tool set,
|
|
1022
1037
|
* with an `input` type inferred from that tool's input schema.
|
|
1023
1038
|
*/
|
|
1024
|
-
type StaticToolCall<TOOLS extends ToolSet> = ValueOf<{
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
};
|
|
1033
|
-
}>;
|
|
1039
|
+
type StaticToolCall<TOOLS extends ToolSet> = ValueOf<{ [NAME in keyof TOOLS]: BaseToolCall & {
|
|
1040
|
+
toolName: NAME & string;
|
|
1041
|
+
input: InferToolInput<TOOLS[NAME]>;
|
|
1042
|
+
dynamic?: false | undefined;
|
|
1043
|
+
invalid?: false | undefined;
|
|
1044
|
+
error?: never;
|
|
1045
|
+
title?: string;
|
|
1046
|
+
}; }>;
|
|
1034
1047
|
/**
|
|
1035
1048
|
* A tool call whose `toolName` is only known at runtime, such as an invalid
|
|
1036
1049
|
* or otherwise untyped call that cannot be matched to the declared tool set.
|
|
1037
1050
|
*/
|
|
1038
1051
|
type DynamicToolCall = BaseToolCall & {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
+
toolName: string;
|
|
1053
|
+
input: unknown;
|
|
1054
|
+
dynamic: true;
|
|
1055
|
+
title?: string;
|
|
1056
|
+
/**
|
|
1057
|
+
* True if this is caused by an unparsable tool call or
|
|
1058
|
+
* a tool that does not exist.
|
|
1059
|
+
*/
|
|
1060
|
+
invalid?: boolean;
|
|
1061
|
+
/**
|
|
1062
|
+
* The error that caused the tool call to be invalid.
|
|
1063
|
+
*/
|
|
1064
|
+
error?: unknown;
|
|
1052
1065
|
};
|
|
1053
1066
|
/**
|
|
1054
1067
|
* A tool call returned by text generation, either statically typed from the
|
|
1055
1068
|
* declared tool set or dynamically typed when the tool cannot be inferred.
|
|
1056
1069
|
*/
|
|
1057
1070
|
type TypedToolCall<TOOLS extends ToolSet> = StaticToolCall<TOOLS> | DynamicToolCall;
|
|
1058
|
-
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#region src/generate-text/tool-approval-request-output.d.ts
|
|
1059
1073
|
/**
|
|
1060
1074
|
* Output part that indicates that a tool approval request has been made.
|
|
1061
1075
|
*
|
|
1062
1076
|
* The tool approval request can be approved or denied in the next tool message.
|
|
1063
1077
|
*/
|
|
1064
1078
|
type ToolApprovalRequestOutput<TOOLS extends ToolSet> = {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
};
|
|
1089
|
-
|
|
1079
|
+
type: 'tool-approval-request';
|
|
1080
|
+
/**
|
|
1081
|
+
* ID of the tool approval request.
|
|
1082
|
+
*/
|
|
1083
|
+
approvalId: string;
|
|
1084
|
+
/**
|
|
1085
|
+
* Tool call that the approval request is for.
|
|
1086
|
+
*/
|
|
1087
|
+
toolCall: TypedToolCall<TOOLS>;
|
|
1088
|
+
/**
|
|
1089
|
+
* Reason why the tool call requires approval.
|
|
1090
|
+
*/
|
|
1091
|
+
reason?: string;
|
|
1092
|
+
/**
|
|
1093
|
+
* Flag indicating whether the tool was automatically approved or denied.
|
|
1094
|
+
*
|
|
1095
|
+
* @default false
|
|
1096
|
+
*/
|
|
1097
|
+
isAutomatic?: boolean;
|
|
1098
|
+
/**
|
|
1099
|
+
* HMAC-SHA256 signature binding this approval request to its tool call.
|
|
1100
|
+
*/
|
|
1101
|
+
signature?: string;
|
|
1102
|
+
};
|
|
1103
|
+
//#endregion
|
|
1104
|
+
//#region src/generate-text/tool-approval-response-output.d.ts
|
|
1090
1105
|
/**
|
|
1091
1106
|
* Output part that indicates that a tool approval response is available.
|
|
1092
1107
|
*/
|
|
1093
1108
|
type ToolApprovalResponseOutput<TOOLS extends ToolSet> = {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
};
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
}>;
|
|
1109
|
+
type: 'tool-approval-response';
|
|
1110
|
+
/**
|
|
1111
|
+
* ID of the tool approval.
|
|
1112
|
+
*/
|
|
1113
|
+
approvalId: string;
|
|
1114
|
+
/**
|
|
1115
|
+
* Tool call that the approval response is for.
|
|
1116
|
+
*/
|
|
1117
|
+
toolCall: TypedToolCall<TOOLS>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Flag indicating whether the approval was granted or denied.
|
|
1120
|
+
*/
|
|
1121
|
+
approved: boolean;
|
|
1122
|
+
/**
|
|
1123
|
+
* Optional reason for the approval or denial.
|
|
1124
|
+
*/
|
|
1125
|
+
reason?: string;
|
|
1126
|
+
/**
|
|
1127
|
+
* Flag indicating whether the tool call is provider-executed.
|
|
1128
|
+
* Only provider-executed tool approval responses should be sent to the model.
|
|
1129
|
+
*/
|
|
1130
|
+
providerExecuted?: boolean;
|
|
1131
|
+
};
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region src/generate-text/tool-error.d.ts
|
|
1134
|
+
type StaticToolError<TOOLS extends ToolSet> = ValueOf<{ [NAME in keyof TOOLS]: {
|
|
1135
|
+
type: 'tool-error';
|
|
1136
|
+
toolCallId: string;
|
|
1137
|
+
toolName: NAME & string;
|
|
1138
|
+
input: InferToolInput<TOOLS[NAME]>;
|
|
1139
|
+
error: unknown;
|
|
1140
|
+
providerExecuted?: boolean;
|
|
1141
|
+
providerMetadata?: ProviderMetadata;
|
|
1142
|
+
toolMetadata?: JSONObject;
|
|
1143
|
+
dynamic?: false | undefined;
|
|
1144
|
+
title?: string;
|
|
1145
|
+
}; }>;
|
|
1132
1146
|
type DynamicToolError = {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1147
|
+
type: 'tool-error';
|
|
1148
|
+
toolCallId: string;
|
|
1149
|
+
toolName: string;
|
|
1150
|
+
input: unknown;
|
|
1151
|
+
error: unknown;
|
|
1152
|
+
providerExecuted?: boolean;
|
|
1153
|
+
providerMetadata?: ProviderMetadata;
|
|
1154
|
+
toolMetadata?: JSONObject;
|
|
1155
|
+
dynamic: true;
|
|
1156
|
+
title?: string;
|
|
1143
1157
|
};
|
|
1144
1158
|
type TypedToolError<TOOLS extends ToolSet> = StaticToolError<TOOLS> | DynamicToolError;
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
}>;
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region src/generate-text/tool-result.d.ts
|
|
1161
|
+
type StaticToolResult<TOOLS extends ToolSet> = ValueOf<{ [NAME in keyof TOOLS]: {
|
|
1162
|
+
type: 'tool-result';
|
|
1163
|
+
toolCallId: string;
|
|
1164
|
+
toolName: NAME & string;
|
|
1165
|
+
input: InferToolInput<TOOLS[NAME]>;
|
|
1166
|
+
output: InferToolOutput<TOOLS[NAME]>;
|
|
1167
|
+
providerExecuted?: boolean;
|
|
1168
|
+
providerMetadata?: ProviderMetadata;
|
|
1169
|
+
toolMetadata?: JSONObject;
|
|
1170
|
+
dynamic?: false | undefined;
|
|
1171
|
+
preliminary?: boolean;
|
|
1172
|
+
title?: string;
|
|
1173
|
+
}; }>;
|
|
1161
1174
|
type DynamicToolResult = {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1175
|
+
type: 'tool-result';
|
|
1176
|
+
toolCallId: string;
|
|
1177
|
+
toolName: string;
|
|
1178
|
+
input: unknown;
|
|
1179
|
+
output: unknown;
|
|
1180
|
+
providerExecuted?: boolean;
|
|
1181
|
+
providerMetadata?: ProviderMetadata;
|
|
1182
|
+
toolMetadata?: JSONObject;
|
|
1183
|
+
dynamic: true;
|
|
1184
|
+
preliminary?: boolean;
|
|
1185
|
+
title?: string;
|
|
1173
1186
|
};
|
|
1174
1187
|
type TypedToolResult<TOOLS extends ToolSet> = StaticToolResult<TOOLS> | DynamicToolResult;
|
|
1175
|
-
|
|
1188
|
+
//#endregion
|
|
1189
|
+
//#region src/generate-text/content-part.d.ts
|
|
1176
1190
|
type ContentPart<TOOLS extends ToolSet> = {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1191
|
+
type: 'text';
|
|
1192
|
+
text: string;
|
|
1193
|
+
providerMetadata?: ProviderMetadata;
|
|
1180
1194
|
} | {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1195
|
+
type: 'custom';
|
|
1196
|
+
kind: `${string}.${string}`;
|
|
1197
|
+
providerMetadata?: ProviderMetadata;
|
|
1184
1198
|
} | ReasoningOutput | ReasoningFileOutput | ({
|
|
1185
|
-
|
|
1199
|
+
type: 'source';
|
|
1186
1200
|
} & Source) | {
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1201
|
+
type: 'file';
|
|
1202
|
+
file: GeneratedFile;
|
|
1203
|
+
providerMetadata?: ProviderMetadata;
|
|
1190
1204
|
} | ({
|
|
1191
|
-
|
|
1205
|
+
type: 'tool-call';
|
|
1192
1206
|
} & TypedToolCall<TOOLS> & {
|
|
1193
|
-
|
|
1207
|
+
providerMetadata?: ProviderMetadata;
|
|
1194
1208
|
}) | ({
|
|
1195
|
-
|
|
1209
|
+
type: 'tool-result';
|
|
1196
1210
|
} & TypedToolResult<TOOLS> & {
|
|
1197
|
-
|
|
1211
|
+
providerMetadata?: ProviderMetadata;
|
|
1198
1212
|
}) | ({
|
|
1199
|
-
|
|
1213
|
+
type: 'tool-error';
|
|
1200
1214
|
} & TypedToolError<TOOLS> & {
|
|
1201
|
-
|
|
1215
|
+
providerMetadata?: ProviderMetadata;
|
|
1202
1216
|
}) | ToolApprovalRequestOutput<TOOLS> | ToolApprovalResponseOutput<TOOLS>;
|
|
1203
|
-
|
|
1217
|
+
//#endregion
|
|
1218
|
+
//#region src/generate-text/step-result.d.ts
|
|
1204
1219
|
/**
|
|
1205
1220
|
* Timing statistics for the gaps between generated output chunks.
|
|
1206
1221
|
*/
|
|
1207
1222
|
type OutputChunkTimingStats = {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
};
|
|
1221
|
-
/**
|
|
1222
|
-
* Performance metrics for a single step in the generation process.
|
|
1223
|
-
*/
|
|
1224
|
-
type StepResultPerformance = {
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
};
|
|
1288
|
-
/**
|
|
1289
|
-
* The result of a single step in the generation process.
|
|
1290
|
-
*/
|
|
1291
|
-
type StepResult<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context> = {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
};
|
|
1404
|
-
declare class DefaultStepResult<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context> implements StepResult<TOOLS, RUNTIME_CONTEXT> {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1223
|
+
/** Shortest observed time between output chunks in milliseconds. */
|
|
1224
|
+
readonly min: number;
|
|
1225
|
+
/** 10th percentile time between output chunks in milliseconds. */
|
|
1226
|
+
readonly p10: number;
|
|
1227
|
+
/** Median time between output chunks in milliseconds. */
|
|
1228
|
+
readonly median: number;
|
|
1229
|
+
/** Average time between output chunks in milliseconds. */
|
|
1230
|
+
readonly avg: number;
|
|
1231
|
+
/** 90th percentile time between output chunks in milliseconds. */
|
|
1232
|
+
readonly p90: number;
|
|
1233
|
+
/** Longest observed time between output chunks in milliseconds. */
|
|
1234
|
+
readonly max: number;
|
|
1235
|
+
};
|
|
1236
|
+
/**
|
|
1237
|
+
* Performance metrics for a single step in the generation process.
|
|
1238
|
+
*/
|
|
1239
|
+
type StepResultPerformance = {
|
|
1240
|
+
/**
|
|
1241
|
+
* Effective number of output tokens per second over the full language model
|
|
1242
|
+
* response.
|
|
1243
|
+
*
|
|
1244
|
+
* Calculated as `outputTokens / requestSeconds`.
|
|
1245
|
+
*/
|
|
1246
|
+
readonly effectiveOutputTokensPerSecond: number;
|
|
1247
|
+
/**
|
|
1248
|
+
* Number of output tokens per second after the first generated output chunk
|
|
1249
|
+
* was received.
|
|
1250
|
+
*
|
|
1251
|
+
* Only available for streaming steps.
|
|
1252
|
+
*
|
|
1253
|
+
* Calculated as `outputTokens / outputStreamSeconds`.
|
|
1254
|
+
*/
|
|
1255
|
+
readonly outputTokensPerSecond: number | undefined;
|
|
1256
|
+
/**
|
|
1257
|
+
* Number of input tokens processed per second before the first generated
|
|
1258
|
+
* output chunk was received.
|
|
1259
|
+
*
|
|
1260
|
+
* Only available for streaming steps.
|
|
1261
|
+
*
|
|
1262
|
+
* Calculated as `inputTokens / ttftSeconds`.
|
|
1263
|
+
*/
|
|
1264
|
+
readonly inputTokensPerSecond: number | undefined;
|
|
1265
|
+
/**
|
|
1266
|
+
* Effective number of input and output tokens per second over the full
|
|
1267
|
+
* language model response.
|
|
1268
|
+
*
|
|
1269
|
+
* Calculated as `(inputTokens + outputTokens) / requestSeconds`.
|
|
1270
|
+
*/
|
|
1271
|
+
readonly effectiveTotalTokensPerSecond: number;
|
|
1272
|
+
/**
|
|
1273
|
+
* Total time spent on the step in milliseconds.
|
|
1274
|
+
*/
|
|
1275
|
+
readonly stepTimeMs: number;
|
|
1276
|
+
/**
|
|
1277
|
+
* Time spent waiting for the language model response in milliseconds.
|
|
1278
|
+
*/
|
|
1279
|
+
readonly responseTimeMs: number;
|
|
1280
|
+
/**
|
|
1281
|
+
* Time spent executing each client-side tool call in milliseconds, keyed by
|
|
1282
|
+
* tool call ID.
|
|
1283
|
+
*/
|
|
1284
|
+
readonly toolExecutionMs: Readonly<Record<string, number>>;
|
|
1285
|
+
/**
|
|
1286
|
+
* Time until the first generated output chunk was received in milliseconds.
|
|
1287
|
+
*
|
|
1288
|
+
* This includes text deltas, reasoning deltas, generated files, reasoning
|
|
1289
|
+
* files, tool input deltas, and tool calls.
|
|
1290
|
+
*
|
|
1291
|
+
* Only available for streaming steps.
|
|
1292
|
+
*/
|
|
1293
|
+
readonly timeToFirstOutputMs: number | undefined;
|
|
1294
|
+
/**
|
|
1295
|
+
* Timing statistics for the gaps between generated output chunks in
|
|
1296
|
+
* milliseconds.
|
|
1297
|
+
*
|
|
1298
|
+
* Only available for streaming steps with at least two generated output
|
|
1299
|
+
* chunks.
|
|
1300
|
+
*/
|
|
1301
|
+
readonly timeBetweenOutputChunksMs?: OutputChunkTimingStats;
|
|
1302
|
+
};
|
|
1303
|
+
/**
|
|
1304
|
+
* The result of a single step in the generation process.
|
|
1305
|
+
*/
|
|
1306
|
+
type StepResult<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context> = {
|
|
1307
|
+
/**
|
|
1308
|
+
* Unique identifier for the generation call this step belongs to.
|
|
1309
|
+
*/
|
|
1310
|
+
readonly callId: string;
|
|
1311
|
+
/**
|
|
1312
|
+
* Zero-based index of this step.
|
|
1313
|
+
*/
|
|
1314
|
+
readonly stepNumber: number;
|
|
1315
|
+
/**
|
|
1316
|
+
* Information about the model that produced this step.
|
|
1317
|
+
*/
|
|
1318
|
+
readonly model: {
|
|
1319
|
+
/** The provider of the model. */
|
|
1320
|
+
readonly provider: string;
|
|
1321
|
+
/** The ID of the model. */
|
|
1322
|
+
readonly modelId: string;
|
|
1323
|
+
};
|
|
1324
|
+
/**
|
|
1325
|
+
* Tool context.
|
|
1326
|
+
*/
|
|
1327
|
+
readonly toolsContext: InferToolSetContext<TOOLS>;
|
|
1328
|
+
/**
|
|
1329
|
+
* The runtime context that was used as input for the step.
|
|
1330
|
+
*/
|
|
1331
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
1332
|
+
/**
|
|
1333
|
+
* The content that was generated in the last step.
|
|
1334
|
+
*/
|
|
1335
|
+
readonly content: Array<ContentPart<TOOLS>>;
|
|
1336
|
+
/**
|
|
1337
|
+
* The concatenation of all text parts generated in this step.
|
|
1338
|
+
* It is an empty string if the step contains no text parts.
|
|
1339
|
+
*/
|
|
1340
|
+
readonly text: string;
|
|
1341
|
+
/**
|
|
1342
|
+
* The reasoning that was generated during the generation.
|
|
1343
|
+
*/
|
|
1344
|
+
readonly reasoning: Array<ReasoningPart | ReasoningFilePart>;
|
|
1345
|
+
/**
|
|
1346
|
+
* The reasoning text that was generated during the generation.
|
|
1347
|
+
*
|
|
1348
|
+
* It is a concatenation of all reasoning parts (but excluding reasoning file parts).
|
|
1349
|
+
* Can be undefined if the model has only generated text.
|
|
1350
|
+
*/
|
|
1351
|
+
readonly reasoningText: string | undefined;
|
|
1352
|
+
/**
|
|
1353
|
+
* The files that were generated during the generation.
|
|
1354
|
+
*/
|
|
1355
|
+
readonly files: Array<GeneratedFile>;
|
|
1356
|
+
/**
|
|
1357
|
+
* The sources that were used to generate the text.
|
|
1358
|
+
*/
|
|
1359
|
+
readonly sources: Array<Source>;
|
|
1360
|
+
/**
|
|
1361
|
+
* The tool calls that were made during the generation.
|
|
1362
|
+
*/
|
|
1363
|
+
readonly toolCalls: Array<TypedToolCall<TOOLS>>;
|
|
1364
|
+
/**
|
|
1365
|
+
* The static tool calls that were made in the last step.
|
|
1366
|
+
*/
|
|
1367
|
+
readonly staticToolCalls: Array<StaticToolCall<TOOLS>>;
|
|
1368
|
+
/**
|
|
1369
|
+
* The dynamic tool calls that were made in the last step.
|
|
1370
|
+
*/
|
|
1371
|
+
readonly dynamicToolCalls: Array<DynamicToolCall>;
|
|
1372
|
+
/**
|
|
1373
|
+
* The results of the tool calls.
|
|
1374
|
+
*/
|
|
1375
|
+
readonly toolResults: Array<TypedToolResult<TOOLS>>;
|
|
1376
|
+
/**
|
|
1377
|
+
* The static tool results that were made in the last step.
|
|
1378
|
+
*/
|
|
1379
|
+
readonly staticToolResults: Array<StaticToolResult<TOOLS>>;
|
|
1380
|
+
/**
|
|
1381
|
+
* The dynamic tool results that were made in the last step.
|
|
1382
|
+
*/
|
|
1383
|
+
readonly dynamicToolResults: Array<DynamicToolResult>;
|
|
1384
|
+
/**
|
|
1385
|
+
* The unified reason why the generation finished.
|
|
1386
|
+
*/
|
|
1387
|
+
readonly finishReason: FinishReason;
|
|
1388
|
+
/**
|
|
1389
|
+
* The raw reason why the generation finished (from the provider).
|
|
1390
|
+
*/
|
|
1391
|
+
readonly rawFinishReason: string | undefined;
|
|
1392
|
+
/**
|
|
1393
|
+
* The token usage of the generated text.
|
|
1394
|
+
*/
|
|
1395
|
+
readonly usage: LanguageModelUsage;
|
|
1396
|
+
/**
|
|
1397
|
+
* Performance metrics for the step.
|
|
1398
|
+
*/
|
|
1399
|
+
readonly performance: StepResultPerformance;
|
|
1400
|
+
/**
|
|
1401
|
+
* Warnings from the model provider (e.g. unsupported settings).
|
|
1402
|
+
*/
|
|
1403
|
+
readonly warnings: CallWarning[] | undefined;
|
|
1404
|
+
/**
|
|
1405
|
+
* Additional request information.
|
|
1406
|
+
*/
|
|
1407
|
+
readonly request: LanguageModelRequestMetadata;
|
|
1408
|
+
/**
|
|
1409
|
+
* Additional response information.
|
|
1410
|
+
*/
|
|
1411
|
+
readonly response: LanguageModelResponseMetadata;
|
|
1412
|
+
/**
|
|
1413
|
+
* Additional provider-specific metadata. They are passed through
|
|
1414
|
+
* from the provider to the AI SDK and enable provider-specific
|
|
1415
|
+
* results that can be fully encapsulated in the provider.
|
|
1416
|
+
*/
|
|
1417
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
|
1418
|
+
};
|
|
1419
|
+
export declare class DefaultStepResult<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context> implements StepResult<TOOLS, RUNTIME_CONTEXT> {
|
|
1420
|
+
readonly callId: StepResult<TOOLS, RUNTIME_CONTEXT>['callId'];
|
|
1421
|
+
readonly stepNumber: StepResult<TOOLS, RUNTIME_CONTEXT>['stepNumber'];
|
|
1422
|
+
readonly model: StepResult<TOOLS, RUNTIME_CONTEXT>['model'];
|
|
1423
|
+
readonly toolsContext: StepResult<TOOLS, RUNTIME_CONTEXT>['toolsContext'];
|
|
1424
|
+
readonly runtimeContext: StepResult<TOOLS, RUNTIME_CONTEXT>['runtimeContext'];
|
|
1425
|
+
readonly content: StepResult<TOOLS, RUNTIME_CONTEXT>['content'];
|
|
1426
|
+
readonly finishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['finishReason'];
|
|
1427
|
+
readonly rawFinishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['rawFinishReason'];
|
|
1428
|
+
readonly usage: StepResult<TOOLS, RUNTIME_CONTEXT>['usage'];
|
|
1429
|
+
readonly performance: StepResult<TOOLS, RUNTIME_CONTEXT>['performance'];
|
|
1430
|
+
readonly warnings: StepResult<TOOLS, RUNTIME_CONTEXT>['warnings'];
|
|
1431
|
+
readonly request: StepResult<TOOLS, RUNTIME_CONTEXT>['request'];
|
|
1432
|
+
readonly response: StepResult<TOOLS, RUNTIME_CONTEXT>['response'];
|
|
1433
|
+
readonly providerMetadata: StepResult<TOOLS, RUNTIME_CONTEXT>['providerMetadata'];
|
|
1434
|
+
constructor({ callId, stepNumber, provider, modelId, runtimeContext, toolsContext, content, finishReason, rawFinishReason, usage, performance, warnings, request, response, providerMetadata }: {
|
|
1435
|
+
callId: StepResult<TOOLS, RUNTIME_CONTEXT>['callId'];
|
|
1436
|
+
stepNumber: StepResult<TOOLS, RUNTIME_CONTEXT>['stepNumber'];
|
|
1437
|
+
provider: StepResult<TOOLS, RUNTIME_CONTEXT>['model']['provider'];
|
|
1438
|
+
modelId: StepResult<TOOLS, RUNTIME_CONTEXT>['model']['modelId'];
|
|
1439
|
+
runtimeContext: StepResult<TOOLS, RUNTIME_CONTEXT>['runtimeContext'];
|
|
1440
|
+
toolsContext: StepResult<TOOLS, RUNTIME_CONTEXT>['toolsContext'];
|
|
1441
|
+
content: StepResult<TOOLS, RUNTIME_CONTEXT>['content'];
|
|
1442
|
+
finishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['finishReason'];
|
|
1443
|
+
rawFinishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['rawFinishReason'];
|
|
1444
|
+
usage: StepResult<TOOLS, RUNTIME_CONTEXT>['usage'];
|
|
1445
|
+
performance: StepResult<TOOLS, RUNTIME_CONTEXT>['performance'];
|
|
1446
|
+
warnings: StepResult<TOOLS, RUNTIME_CONTEXT>['warnings'];
|
|
1447
|
+
request: StepResult<TOOLS, RUNTIME_CONTEXT>['request'];
|
|
1448
|
+
response: StepResult<TOOLS, RUNTIME_CONTEXT>['response'];
|
|
1449
|
+
providerMetadata: StepResult<TOOLS, RUNTIME_CONTEXT>['providerMetadata'];
|
|
1450
|
+
});
|
|
1451
|
+
get text(): string;
|
|
1452
|
+
get reasoning(): Array<ReasoningPart | ReasoningFilePart>;
|
|
1453
|
+
get reasoningText(): string | undefined;
|
|
1454
|
+
get files(): GeneratedFile[];
|
|
1455
|
+
get sources(): (({
|
|
1456
|
+
type: "source";
|
|
1457
|
+
} & {
|
|
1458
|
+
type: "source";
|
|
1459
|
+
sourceType: "url";
|
|
1460
|
+
id: string;
|
|
1461
|
+
url: string;
|
|
1462
|
+
title?: string;
|
|
1463
|
+
providerMetadata?: import("@ai-sdk/provider").SharedV4ProviderMetadata;
|
|
1464
|
+
}) | ({
|
|
1465
|
+
type: "source";
|
|
1466
|
+
} & {
|
|
1467
|
+
type: "source";
|
|
1468
|
+
sourceType: "document";
|
|
1469
|
+
id: string;
|
|
1470
|
+
mediaType: string;
|
|
1471
|
+
title: string;
|
|
1472
|
+
filename?: string;
|
|
1473
|
+
providerMetadata?: import("@ai-sdk/provider").SharedV4ProviderMetadata;
|
|
1474
|
+
}))[];
|
|
1475
|
+
get toolCalls(): (({
|
|
1476
|
+
type: "tool-call";
|
|
1477
|
+
} & {
|
|
1478
|
+
type: "tool-call";
|
|
1479
|
+
toolCallId: string;
|
|
1480
|
+
providerExecuted?: boolean;
|
|
1481
|
+
providerMetadata?: ProviderMetadata;
|
|
1482
|
+
toolMetadata?: import("@ai-sdk/provider").JSONObject;
|
|
1483
|
+
} & {
|
|
1484
|
+
toolName: string;
|
|
1485
|
+
input: unknown;
|
|
1486
|
+
dynamic: true;
|
|
1487
|
+
title?: string;
|
|
1488
|
+
invalid?: boolean;
|
|
1489
|
+
error?: unknown;
|
|
1490
|
+
} & {
|
|
1491
|
+
providerMetadata?: ProviderMetadata;
|
|
1492
|
+
}) | ({
|
|
1493
|
+
type: "tool-call";
|
|
1494
|
+
} & StaticToolCall<TOOLS> & {
|
|
1495
|
+
providerMetadata?: ProviderMetadata;
|
|
1496
|
+
}))[];
|
|
1497
|
+
get staticToolCalls(): StaticToolCall<TOOLS>[];
|
|
1498
|
+
get dynamicToolCalls(): DynamicToolCall[];
|
|
1499
|
+
get toolResults(): (({
|
|
1500
|
+
type: "tool-result";
|
|
1501
|
+
} & DynamicToolResult & {
|
|
1502
|
+
providerMetadata?: ProviderMetadata;
|
|
1503
|
+
}) | ({
|
|
1504
|
+
type: "tool-result";
|
|
1505
|
+
} & StaticToolResult<TOOLS> & {
|
|
1506
|
+
providerMetadata?: ProviderMetadata;
|
|
1507
|
+
}))[];
|
|
1508
|
+
get staticToolResults(): StaticToolResult<TOOLS>[];
|
|
1509
|
+
get dynamicToolResults(): DynamicToolResult[];
|
|
1495
1510
|
}
|
|
1496
|
-
|
|
1511
|
+
//#endregion
|
|
1512
|
+
//#region src/generate-text/language-model-events.d.ts
|
|
1497
1513
|
/**
|
|
1498
1514
|
* Common model information used across callback events.
|
|
1499
1515
|
*/
|
|
1500
1516
|
type ModelInfo = {
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1517
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
1518
|
+
readonly provider: string;
|
|
1519
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
1520
|
+
readonly modelId: string;
|
|
1505
1521
|
};
|
|
1506
1522
|
/**
|
|
1507
1523
|
* Event passed to the `onLanguageModelCallStart` callback.
|
|
@@ -1510,10 +1526,10 @@ type ModelInfo = {
|
|
|
1510
1526
|
* Unlike `onStepStart`, this only represents model invocation work.
|
|
1511
1527
|
*/
|
|
1512
1528
|
type LanguageModelCallStartEvent = ModelInfo & {
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1529
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
1530
|
+
readonly callId: string;
|
|
1531
|
+
/** Prepared tool definitions for the model call, if any. */
|
|
1532
|
+
readonly tools: ReadonlyArray<Record<string, unknown>> | undefined;
|
|
1517
1533
|
} & StandardizedPrompt & LanguageModelCallOptions;
|
|
1518
1534
|
/**
|
|
1519
1535
|
* Event passed to the `onLanguageModelCallEnd` callback.
|
|
@@ -1522,59 +1538,59 @@ type LanguageModelCallStartEvent = ModelInfo & {
|
|
|
1522
1538
|
* any client-side tool execution begins.
|
|
1523
1539
|
*/
|
|
1524
1540
|
type LanguageModelCallEndEvent<TOOLS extends ToolSet = ToolSet> = ModelInfo & {
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1541
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
1542
|
+
readonly callId: string;
|
|
1543
|
+
/** The unified reason why the model call finished. */
|
|
1544
|
+
readonly finishReason: FinishReason;
|
|
1545
|
+
/** The token usage reported by the model call. */
|
|
1546
|
+
readonly usage: LanguageModelUsage;
|
|
1547
|
+
/** The content parts produced by the model call. */
|
|
1548
|
+
readonly content: ReadonlyArray<ContentPart<TOOLS>>;
|
|
1549
|
+
/** The provider-returned response id for this model call. */
|
|
1550
|
+
readonly responseId: string;
|
|
1551
|
+
/** Optional provider-specific metadata for this model call. */
|
|
1552
|
+
readonly providerMetadata?: ProviderMetadata;
|
|
1553
|
+
/** Performance metrics for the model call. */
|
|
1554
|
+
readonly performance: {
|
|
1555
|
+
/** Time spent waiting for the language model response in milliseconds. */
|
|
1556
|
+
readonly responseTimeMs: number;
|
|
1557
|
+
/**
|
|
1558
|
+
* Effective number of output tokens per second over the full language
|
|
1559
|
+
* model response.
|
|
1560
|
+
*/
|
|
1561
|
+
readonly effectiveOutputTokensPerSecond: number;
|
|
1562
|
+
/**
|
|
1563
|
+
* Number of output tokens per second after the first generated output
|
|
1564
|
+
* chunk was received.
|
|
1565
|
+
*
|
|
1566
|
+
* Only available for streaming calls.
|
|
1567
|
+
*/
|
|
1568
|
+
readonly outputTokensPerSecond: number | undefined;
|
|
1569
|
+
/**
|
|
1570
|
+
* Number of input tokens processed per second before the first generated
|
|
1571
|
+
* output chunk was received.
|
|
1572
|
+
*
|
|
1573
|
+
* Only available for streaming calls.
|
|
1574
|
+
*/
|
|
1575
|
+
readonly inputTokensPerSecond: number | undefined;
|
|
1576
|
+
/**
|
|
1577
|
+
* Effective number of input and output tokens per second over the full
|
|
1578
|
+
* language model response.
|
|
1579
|
+
*/
|
|
1580
|
+
readonly effectiveTotalTokensPerSecond: number;
|
|
1581
|
+
/**
|
|
1582
|
+
* Time until the first generated output chunk was received in
|
|
1583
|
+
* milliseconds.
|
|
1584
|
+
*/
|
|
1585
|
+
readonly timeToFirstOutputMs: number | undefined;
|
|
1586
|
+
/**
|
|
1587
|
+
* Timing statistics for the gaps between generated output chunks in
|
|
1588
|
+
* milliseconds.
|
|
1589
|
+
*
|
|
1590
|
+
* Only available for streaming calls with at least two output chunks.
|
|
1591
|
+
*/
|
|
1592
|
+
readonly timeBetweenOutputChunksMs?: OutputChunkTimingStats;
|
|
1593
|
+
};
|
|
1578
1594
|
};
|
|
1579
1595
|
/**
|
|
1580
1596
|
* Callback that is set using the `onLanguageModelCallStart` option.
|
|
@@ -1595,7 +1611,8 @@ type OnLanguageModelCallStartCallback = Callback<LanguageModelCallStartEvent>;
|
|
|
1595
1611
|
* @param event - The event object containing model-call-specific outputs.
|
|
1596
1612
|
*/
|
|
1597
1613
|
type OnLanguageModelCallEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<LanguageModelCallEndEvent<TOOLS>>;
|
|
1598
|
-
|
|
1614
|
+
//#endregion
|
|
1615
|
+
//#region src/generate-text/tool-order.d.ts
|
|
1599
1616
|
/**
|
|
1600
1617
|
* Tool names that define the order in which tools are sent to the provider.
|
|
1601
1618
|
*
|
|
@@ -1604,7 +1621,8 @@ type OnLanguageModelCallEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<
|
|
|
1604
1621
|
* listed in `toolOrder` are sent after the listed tools, sorted alphabetically.
|
|
1605
1622
|
*/
|
|
1606
1623
|
type ToolOrder<TOOLS extends ToolSet> = ReadonlyArray<keyof TOOLS & string> | undefined;
|
|
1607
|
-
|
|
1624
|
+
//#endregion
|
|
1625
|
+
//#region src/util/async-iterable-stream.d.ts
|
|
1608
1626
|
/**
|
|
1609
1627
|
* A type that combines AsyncIterable and ReadableStream.
|
|
1610
1628
|
* This allows a ReadableStream to be consumed using for-await-of syntax.
|
|
@@ -1618,143 +1636,144 @@ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
|
|
1618
1636
|
* @param source The source ReadableStream to wrap.
|
|
1619
1637
|
* @returns An AsyncIterableStream that can be used as both a ReadableStream and an AsyncIterable.
|
|
1620
1638
|
*/
|
|
1621
|
-
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
1622
|
-
|
|
1639
|
+
export declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
1640
|
+
//#endregion
|
|
1641
|
+
//#region src/generate-text/tool-output-denied.d.ts
|
|
1623
1642
|
/**
|
|
1624
1643
|
* Tool output when the tool execution has been denied (for static tools).
|
|
1625
1644
|
*/
|
|
1626
|
-
type StaticToolOutputDenied<TOOLS extends ToolSet> = ValueOf<{
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1645
|
+
type StaticToolOutputDenied<TOOLS extends ToolSet> = ValueOf<{ [NAME in keyof TOOLS]: {
|
|
1646
|
+
type: 'tool-output-denied';
|
|
1647
|
+
toolCallId: string;
|
|
1648
|
+
toolName: NAME & string;
|
|
1649
|
+
providerExecuted?: boolean;
|
|
1650
|
+
dynamic?: false | undefined;
|
|
1651
|
+
}; }>;
|
|
1652
|
+
//#endregion
|
|
1653
|
+
//#region src/generate-text/stream-text-result.d.ts
|
|
1636
1654
|
type TextStreamTextDeltaPart = {
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1655
|
+
type: 'text-delta';
|
|
1656
|
+
id: string;
|
|
1657
|
+
providerMetadata?: ProviderMetadata;
|
|
1658
|
+
text: string;
|
|
1641
1659
|
};
|
|
1642
1660
|
type TextStreamTextStartPart = {
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1661
|
+
type: 'text-start';
|
|
1662
|
+
id: string;
|
|
1663
|
+
providerMetadata?: ProviderMetadata;
|
|
1646
1664
|
};
|
|
1647
1665
|
type TextStreamTextEndPart = {
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1666
|
+
type: 'text-end';
|
|
1667
|
+
id: string;
|
|
1668
|
+
providerMetadata?: ProviderMetadata;
|
|
1651
1669
|
};
|
|
1652
1670
|
type TextStreamReasoningStartPart = {
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1671
|
+
type: 'reasoning-start';
|
|
1672
|
+
id: string;
|
|
1673
|
+
providerMetadata?: ProviderMetadata;
|
|
1656
1674
|
};
|
|
1657
1675
|
type TextStreamReasoningEndPart = {
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1676
|
+
type: 'reasoning-end';
|
|
1677
|
+
id: string;
|
|
1678
|
+
providerMetadata?: ProviderMetadata;
|
|
1661
1679
|
};
|
|
1662
1680
|
type TextStreamReasoningDeltaPart = {
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1681
|
+
type: 'reasoning-delta';
|
|
1682
|
+
providerMetadata?: ProviderMetadata;
|
|
1683
|
+
id: string;
|
|
1684
|
+
text: string;
|
|
1667
1685
|
};
|
|
1668
1686
|
type TextStreamCustomPart = {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1687
|
+
type: 'custom';
|
|
1688
|
+
kind: `${string}.${string}`;
|
|
1689
|
+
providerMetadata?: ProviderMetadata;
|
|
1672
1690
|
};
|
|
1673
1691
|
type TextStreamToolInputStartPart = {
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1692
|
+
type: 'tool-input-start';
|
|
1693
|
+
id: string;
|
|
1694
|
+
toolName: string;
|
|
1695
|
+
providerMetadata?: ProviderMetadata;
|
|
1696
|
+
toolMetadata?: JSONObject;
|
|
1697
|
+
providerExecuted?: boolean;
|
|
1698
|
+
dynamic?: boolean;
|
|
1699
|
+
title?: string;
|
|
1682
1700
|
};
|
|
1683
1701
|
type TextStreamToolInputEndPart = {
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1702
|
+
type: 'tool-input-end';
|
|
1703
|
+
id: string;
|
|
1704
|
+
providerMetadata?: ProviderMetadata;
|
|
1687
1705
|
};
|
|
1688
1706
|
type TextStreamToolInputDeltaPart = {
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1707
|
+
type: 'tool-input-delta';
|
|
1708
|
+
id: string;
|
|
1709
|
+
delta: string;
|
|
1710
|
+
providerMetadata?: ProviderMetadata;
|
|
1693
1711
|
};
|
|
1694
1712
|
type TextStreamSourcePart = {
|
|
1695
|
-
|
|
1713
|
+
type: 'source';
|
|
1696
1714
|
} & Source;
|
|
1697
1715
|
type TextStreamFilePart = {
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1716
|
+
type: 'file';
|
|
1717
|
+
file: GeneratedFile;
|
|
1718
|
+
providerMetadata?: ProviderMetadata;
|
|
1701
1719
|
};
|
|
1702
1720
|
type TextStreamReasoningFilePart = {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1721
|
+
type: 'reasoning-file';
|
|
1722
|
+
file: GeneratedFile;
|
|
1723
|
+
providerMetadata?: ProviderMetadata;
|
|
1706
1724
|
};
|
|
1707
1725
|
type TextStreamToolCallPart<TOOLS extends ToolSet> = {
|
|
1708
|
-
|
|
1726
|
+
type: 'tool-call';
|
|
1709
1727
|
} & TypedToolCall<TOOLS>;
|
|
1710
1728
|
type TextStreamToolResultPart<TOOLS extends ToolSet> = {
|
|
1711
|
-
|
|
1729
|
+
type: 'tool-result';
|
|
1712
1730
|
} & TypedToolResult<TOOLS>;
|
|
1713
1731
|
type TextStreamToolErrorPart<TOOLS extends ToolSet> = {
|
|
1714
|
-
|
|
1732
|
+
type: 'tool-error';
|
|
1715
1733
|
} & TypedToolError<TOOLS>;
|
|
1716
1734
|
type TextStreamToolOutputDeniedPart<TOOLS extends ToolSet> = {
|
|
1717
|
-
|
|
1735
|
+
type: 'tool-output-denied';
|
|
1718
1736
|
} & StaticToolOutputDenied<TOOLS>;
|
|
1719
1737
|
type TextStreamToolApprovalRequestPart<TOOLS extends ToolSet> = ToolApprovalRequestOutput<TOOLS>;
|
|
1720
1738
|
type TextStreamToolApprovalResponsePart<TOOLS extends ToolSet> = ToolApprovalResponseOutput<TOOLS>;
|
|
1721
1739
|
type TextStreamStartStepPart = {
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1740
|
+
type: 'start-step';
|
|
1741
|
+
request: LanguageModelRequestMetadata;
|
|
1742
|
+
warnings: CallWarning[];
|
|
1725
1743
|
};
|
|
1726
1744
|
type TextStreamFinishStepPart = {
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1745
|
+
type: 'finish-step';
|
|
1746
|
+
response: Omit<LanguageModelResponseMetadata, 'messages' | 'body'>;
|
|
1747
|
+
usage: LanguageModelUsage;
|
|
1748
|
+
performance: StepResultPerformance;
|
|
1749
|
+
finishReason: FinishReason;
|
|
1750
|
+
rawFinishReason: string | undefined;
|
|
1751
|
+
providerMetadata: ProviderMetadata | undefined;
|
|
1734
1752
|
};
|
|
1735
1753
|
type TextStreamStartPart = {
|
|
1736
|
-
|
|
1754
|
+
type: 'start';
|
|
1737
1755
|
};
|
|
1738
1756
|
type TextStreamFinishPart = {
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1757
|
+
type: 'finish';
|
|
1758
|
+
finishReason: FinishReason;
|
|
1759
|
+
rawFinishReason: string | undefined;
|
|
1760
|
+
totalUsage: LanguageModelUsage;
|
|
1743
1761
|
};
|
|
1744
1762
|
type TextStreamAbortPart = {
|
|
1745
|
-
|
|
1746
|
-
|
|
1763
|
+
type: 'abort';
|
|
1764
|
+
reason?: string;
|
|
1747
1765
|
};
|
|
1748
1766
|
type TextStreamErrorPart = {
|
|
1749
|
-
|
|
1750
|
-
|
|
1767
|
+
type: 'error';
|
|
1768
|
+
error: unknown;
|
|
1751
1769
|
};
|
|
1752
1770
|
type TextStreamRawPart = {
|
|
1753
|
-
|
|
1754
|
-
|
|
1771
|
+
type: 'raw';
|
|
1772
|
+
rawValue: unknown;
|
|
1755
1773
|
};
|
|
1756
1774
|
type TextStreamPart<TOOLS extends ToolSet> = TextStreamTextStartPart | TextStreamTextEndPart | TextStreamTextDeltaPart | TextStreamReasoningStartPart | TextStreamReasoningEndPart | TextStreamReasoningDeltaPart | TextStreamCustomPart | TextStreamToolInputStartPart | TextStreamToolInputEndPart | TextStreamToolInputDeltaPart | TextStreamSourcePart | TextStreamFilePart | TextStreamReasoningFilePart | TextStreamToolCallPart<TOOLS> | TextStreamToolResultPart<TOOLS> | TextStreamToolErrorPart<TOOLS> | TextStreamToolOutputDeniedPart<TOOLS> | TextStreamToolApprovalRequestPart<TOOLS> | TextStreamToolApprovalResponsePart<TOOLS> | TextStreamStartStepPart | TextStreamFinishStepPart | TextStreamStartPart | TextStreamFinishPart | TextStreamAbortPart | TextStreamErrorPart | TextStreamRawPart;
|
|
1757
|
-
|
|
1775
|
+
//#endregion
|
|
1776
|
+
//#region src/generate-text/tool-approval-configuration.d.ts
|
|
1758
1777
|
/**
|
|
1759
1778
|
* The approval status of a tool configuration. This can be one of the following:
|
|
1760
1779
|
*
|
|
@@ -1770,17 +1789,17 @@ type TextStreamPart<TOOLS extends ToolSet> = TextStreamTextStartPart | TextStrea
|
|
|
1770
1789
|
* `undefined` is treated as the `not-applicable` status.
|
|
1771
1790
|
*/
|
|
1772
1791
|
type ToolApprovalStatus = undefined | 'not-applicable' | 'approved' | 'denied' | 'user-approval' | {
|
|
1773
|
-
|
|
1774
|
-
|
|
1792
|
+
type: 'not-applicable';
|
|
1793
|
+
reason?: never;
|
|
1775
1794
|
} | {
|
|
1776
|
-
|
|
1777
|
-
|
|
1795
|
+
type: 'approved';
|
|
1796
|
+
reason?: string;
|
|
1778
1797
|
} | {
|
|
1779
|
-
|
|
1780
|
-
|
|
1798
|
+
type: 'denied';
|
|
1799
|
+
reason?: string;
|
|
1781
1800
|
} | {
|
|
1782
|
-
|
|
1783
|
-
|
|
1801
|
+
type: 'user-approval';
|
|
1802
|
+
reason?: string;
|
|
1784
1803
|
};
|
|
1785
1804
|
/**
|
|
1786
1805
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
@@ -1788,8 +1807,8 @@ type ToolApprovalStatus = undefined | 'not-applicable' | 'approved' | 'denied' |
|
|
|
1788
1807
|
* Return `undefined` for the same effect as the `not-applicable` status.
|
|
1789
1808
|
*/
|
|
1790
1809
|
type SingleToolApprovalFunction<INPUT, TOOL_CONTEXT extends Context | unknown | never, RUNTIME_CONTEXT extends Context | unknown | never> = (input: INPUT, options: Omit<ToolExecutionOptions<TOOL_CONTEXT>, 'abortSignal' | 'context'> & {
|
|
1791
|
-
|
|
1792
|
-
|
|
1810
|
+
toolContext: TOOL_CONTEXT;
|
|
1811
|
+
runtimeContext: RUNTIME_CONTEXT;
|
|
1793
1812
|
}) => MaybePromiseLike<ToolApprovalStatus>;
|
|
1794
1813
|
/**
|
|
1795
1814
|
* Function that is called to determine if a tool call needs approval before it can be executed.
|
|
@@ -1797,27 +1816,27 @@ type SingleToolApprovalFunction<INPUT, TOOL_CONTEXT extends Context | unknown |
|
|
|
1797
1816
|
* Return `undefined` for the same effect as the `not-applicable` status.
|
|
1798
1817
|
*/
|
|
1799
1818
|
type GenericToolApprovalFunction<TOOLS extends ToolSet, TOOLS_CONTEXT extends InferToolSetContext<TOOLS>, RUNTIME_CONTEXT extends Context | unknown | never> = (options: {
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1819
|
+
/**
|
|
1820
|
+
* The tool call that needs approval.
|
|
1821
|
+
*/
|
|
1822
|
+
toolCall: TypedToolCall<TOOLS>;
|
|
1823
|
+
/**
|
|
1824
|
+
* All tools that are available for the model to call.
|
|
1825
|
+
*/
|
|
1826
|
+
tools: TOOLS | undefined;
|
|
1827
|
+
/**
|
|
1828
|
+
* Tool context for all tools that are available for the model to call.
|
|
1829
|
+
*/
|
|
1830
|
+
toolsContext: TOOLS_CONTEXT;
|
|
1831
|
+
/**
|
|
1832
|
+
* Runtime context.
|
|
1833
|
+
*/
|
|
1834
|
+
runtimeContext: RUNTIME_CONTEXT;
|
|
1835
|
+
/**
|
|
1836
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
|
1837
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
|
1838
|
+
*/
|
|
1839
|
+
messages: ModelMessage[];
|
|
1821
1840
|
}) => MaybePromiseLike<ToolApprovalStatus>;
|
|
1822
1841
|
/**
|
|
1823
1842
|
* Configure whether individual tools require approval before they can run.
|
|
@@ -1838,39 +1857,41 @@ type GenericToolApprovalFunction<TOOLS extends ToolSet, TOOLS_CONTEXT extends In
|
|
|
1838
1857
|
* For approved and denied statuses, the reason is emitted on the approval response.
|
|
1839
1858
|
* For user-approval statuses, the reason is emitted on the approval request so it can be shown to the approver.
|
|
1840
1859
|
*/
|
|
1841
|
-
type ToolApprovalConfiguration<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context | unknown | never> = GenericToolApprovalFunction<TOOLS, InferToolSetContext<TOOLS>, RUNTIME_CONTEXT> | {
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1860
|
+
type ToolApprovalConfiguration<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context | unknown | never> = GenericToolApprovalFunction<TOOLS, InferToolSetContext<TOOLS>, RUNTIME_CONTEXT> | { [key in keyof TOOLS]?: ToolApprovalStatus | SingleToolApprovalFunction<InferToolInput<TOOLS[key]>, InferToolContext<TOOLS[key]>, RUNTIME_CONTEXT>; };
|
|
1861
|
+
//#endregion
|
|
1862
|
+
//#region src/generate-text/tool-caller-configuration.d.ts
|
|
1845
1863
|
type ResolvedToolCallers = Record<string, ReadonlyArray<string>>;
|
|
1846
|
-
|
|
1864
|
+
//#endregion
|
|
1865
|
+
//#region src/error/invalid-tool-input-error.d.ts
|
|
1847
1866
|
declare const symbol$1: unique symbol;
|
|
1848
1867
|
declare class InvalidToolInputError extends AISDKError {
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1868
|
+
private readonly [symbol$1];
|
|
1869
|
+
readonly toolName: string;
|
|
1870
|
+
readonly toolInput: string;
|
|
1871
|
+
constructor({ toolInput, toolName, cause, message }: {
|
|
1872
|
+
message?: string;
|
|
1873
|
+
toolInput: string;
|
|
1874
|
+
toolName: string;
|
|
1875
|
+
cause: unknown;
|
|
1876
|
+
});
|
|
1877
|
+
static isInstance(error: unknown): error is InvalidToolInputError;
|
|
1859
1878
|
}
|
|
1860
|
-
|
|
1879
|
+
//#endregion
|
|
1880
|
+
//#region src/error/no-such-tool-error.d.ts
|
|
1861
1881
|
declare const symbol: unique symbol;
|
|
1862
1882
|
declare class NoSuchToolError extends AISDKError {
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1883
|
+
private readonly [symbol];
|
|
1884
|
+
readonly toolName: string;
|
|
1885
|
+
readonly availableTools: string[] | undefined;
|
|
1886
|
+
constructor({ toolName, availableTools, message }: {
|
|
1887
|
+
toolName: string;
|
|
1888
|
+
availableTools?: string[] | undefined;
|
|
1889
|
+
message?: string;
|
|
1890
|
+
});
|
|
1891
|
+
static isInstance(error: unknown): error is NoSuchToolError;
|
|
1872
1892
|
}
|
|
1873
|
-
|
|
1893
|
+
//#endregion
|
|
1894
|
+
//#region src/generate-text/tool-call-repair-function.d.ts
|
|
1874
1895
|
/**
|
|
1875
1896
|
* A function that attempts to repair a tool call that failed to parse.
|
|
1876
1897
|
*
|
|
@@ -1887,38 +1908,38 @@ declare class NoSuchToolError extends AISDKError {
|
|
|
1887
1908
|
* @param options.abortSignal - An optional signal for cancelling the repair.
|
|
1888
1909
|
*/
|
|
1889
1910
|
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1911
|
+
instructions: Instructions | undefined;
|
|
1912
|
+
/**
|
|
1913
|
+
* @deprecated Use `instructions` instead.
|
|
1914
|
+
*/
|
|
1915
|
+
system: Instructions | undefined;
|
|
1916
|
+
messages: ModelMessage$1[];
|
|
1917
|
+
toolCall: LanguageModelV4ToolCall;
|
|
1918
|
+
tools: TOOLS;
|
|
1919
|
+
inputSchema: (options: {
|
|
1920
|
+
toolName: string;
|
|
1921
|
+
}) => PromiseLike<JSONSchema7>;
|
|
1922
|
+
error: NoSuchToolError | InvalidToolInputError;
|
|
1923
|
+
abortSignal?: AbortSignal;
|
|
1903
1924
|
}) => Promise<LanguageModelV4ToolCall | null>;
|
|
1904
|
-
|
|
1925
|
+
//#endregion
|
|
1926
|
+
//#region src/generate-text/tool-output.d.ts
|
|
1905
1927
|
type ToolOutput<TOOLS extends ToolSet> = TypedToolResult<TOOLS> | TypedToolError<TOOLS>;
|
|
1906
|
-
|
|
1928
|
+
//#endregion
|
|
1929
|
+
//#region src/generate-text/tool-execution-events.d.ts
|
|
1907
1930
|
/**
|
|
1908
1931
|
* Resolves a single tool's context type, falling back to `undefined` when the
|
|
1909
1932
|
* tool does not declare a `contextSchema`.
|
|
1910
1933
|
*/
|
|
1911
|
-
type ToolContextFor<TOOL extends ToolSet[keyof ToolSet]> = [
|
|
1912
|
-
InferToolContext<TOOL>
|
|
1913
|
-
] extends [never] ? undefined : InferToolContext<TOOL>;
|
|
1934
|
+
type ToolContextFor<TOOL extends ToolSet[keyof ToolSet]> = [InferToolContext<TOOL>] extends [never] ? undefined : InferToolContext<TOOL>;
|
|
1914
1935
|
type BaseToolExecutionStartFields = {
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1936
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
1937
|
+
readonly callId: string;
|
|
1938
|
+
/**
|
|
1939
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
|
1940
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
|
1941
|
+
*/
|
|
1942
|
+
readonly messages: ModelMessage[];
|
|
1922
1943
|
};
|
|
1923
1944
|
/**
|
|
1924
1945
|
* Precise start event union for statically known tools.
|
|
@@ -1926,20 +1947,18 @@ type BaseToolExecutionStartFields = {
|
|
|
1926
1947
|
* Each union member ties a specific `toolCall.toolName` to that tool's
|
|
1927
1948
|
* validated `toolContext` type.
|
|
1928
1949
|
*/
|
|
1929
|
-
type StaticToolExecutionStartEvent<TOOLS extends ToolSet> = ValueOf<{
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
};
|
|
1936
|
-
}>;
|
|
1950
|
+
type StaticToolExecutionStartEvent<TOOLS extends ToolSet> = ValueOf<{ [NAME in keyof TOOLS]: BaseToolExecutionStartFields & {
|
|
1951
|
+
readonly toolCall: Extract<StaticToolCall<TOOLS>, {
|
|
1952
|
+
toolName: NAME;
|
|
1953
|
+
}>;
|
|
1954
|
+
readonly toolContext: ToolContextFor<TOOLS[NAME]>;
|
|
1955
|
+
}; }>;
|
|
1937
1956
|
/**
|
|
1938
1957
|
* Start event shape for dynamic or untyped tool calls.
|
|
1939
1958
|
*/
|
|
1940
1959
|
type DynamicToolExecutionStartEvent = BaseToolExecutionStartFields & {
|
|
1941
|
-
|
|
1942
|
-
|
|
1960
|
+
readonly toolCall: DynamicToolCall;
|
|
1961
|
+
readonly toolContext: unknown;
|
|
1943
1962
|
};
|
|
1944
1963
|
/**
|
|
1945
1964
|
* Broad start event shape used for the default `ToolSet` specialization.
|
|
@@ -1948,27 +1967,25 @@ type DynamicToolExecutionStartEvent = BaseToolExecutionStartFields & {
|
|
|
1948
1967
|
* a concrete tool set and therefore cannot benefit from per-tool narrowing.
|
|
1949
1968
|
*/
|
|
1950
1969
|
type WidenedToolExecutionStartEvent = BaseToolExecutionStartFields & {
|
|
1951
|
-
|
|
1952
|
-
|
|
1970
|
+
readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
|
|
1971
|
+
readonly toolContext: unknown;
|
|
1953
1972
|
};
|
|
1954
1973
|
/**
|
|
1955
1974
|
* Event passed to the `onToolExecutionStart` callback.
|
|
1956
1975
|
*
|
|
1957
1976
|
* Called when a tool execution begins, before the tool's `execute` function is invoked.
|
|
1958
1977
|
*/
|
|
1959
|
-
type ToolExecutionStartEvent<TOOLS extends ToolSet = ToolSet> = [
|
|
1960
|
-
ToolSet
|
|
1961
|
-
] extends [TOOLS] ? WidenedToolExecutionStartEvent : StaticToolExecutionStartEvent<TOOLS> | DynamicToolExecutionStartEvent;
|
|
1978
|
+
type ToolExecutionStartEvent<TOOLS extends ToolSet = ToolSet> = [ToolSet] extends [TOOLS] ? WidenedToolExecutionStartEvent : StaticToolExecutionStartEvent<TOOLS> | DynamicToolExecutionStartEvent;
|
|
1962
1979
|
type BaseToolExecutionEndFields = {
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1980
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
1981
|
+
readonly callId: string;
|
|
1982
|
+
/** Execution time of the tool call in milliseconds. */
|
|
1983
|
+
readonly toolExecutionMs: number;
|
|
1984
|
+
/**
|
|
1985
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
|
1986
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
|
1987
|
+
*/
|
|
1988
|
+
readonly messages: ModelMessage[];
|
|
1972
1989
|
};
|
|
1973
1990
|
/**
|
|
1974
1991
|
* Precise end event union for statically known tools.
|
|
@@ -1976,22 +1993,20 @@ type BaseToolExecutionEndFields = {
|
|
|
1976
1993
|
* Each union member preserves the link between `toolCall.toolName`, the
|
|
1977
1994
|
* corresponding validated `toolContext`, and the tool execution result.
|
|
1978
1995
|
*/
|
|
1979
|
-
type StaticToolExecutionEndEvent<TOOLS extends ToolSet> = ValueOf<{
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
};
|
|
1987
|
-
}>;
|
|
1996
|
+
type StaticToolExecutionEndEvent<TOOLS extends ToolSet> = ValueOf<{ [NAME in keyof TOOLS]: BaseToolExecutionEndFields & {
|
|
1997
|
+
readonly toolCall: Extract<StaticToolCall<TOOLS>, {
|
|
1998
|
+
toolName: NAME;
|
|
1999
|
+
}>;
|
|
2000
|
+
readonly toolContext: ToolContextFor<TOOLS[NAME]>;
|
|
2001
|
+
readonly toolOutput: ToolOutput<TOOLS>;
|
|
2002
|
+
}; }>;
|
|
1988
2003
|
/**
|
|
1989
2004
|
* End event shape for dynamic or untyped tool calls.
|
|
1990
2005
|
*/
|
|
1991
2006
|
type DynamicToolExecutionEndEvent<TOOLS extends ToolSet> = BaseToolExecutionEndFields & {
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
2007
|
+
readonly toolCall: DynamicToolCall;
|
|
2008
|
+
readonly toolContext: unknown;
|
|
2009
|
+
readonly toolOutput: ToolOutput<TOOLS>;
|
|
1995
2010
|
};
|
|
1996
2011
|
/**
|
|
1997
2012
|
* Broad end event shape used for the default `ToolSet` specialization.
|
|
@@ -2000,9 +2015,9 @@ type DynamicToolExecutionEndEvent<TOOLS extends ToolSet> = BaseToolExecutionEndF
|
|
|
2000
2015
|
* the concrete-tool specialization retains full per-tool narrowing.
|
|
2001
2016
|
*/
|
|
2002
2017
|
type WidenedToolExecutionEndEvent = BaseToolExecutionEndFields & {
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2018
|
+
readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
|
|
2019
|
+
readonly toolContext: unknown;
|
|
2020
|
+
readonly toolOutput: ToolOutput<ToolSet>;
|
|
2006
2021
|
};
|
|
2007
2022
|
/**
|
|
2008
2023
|
* Event passed to the `onToolExecutionEnd` callback.
|
|
@@ -2010,9 +2025,7 @@ type WidenedToolExecutionEndEvent = BaseToolExecutionEndFields & {
|
|
|
2010
2025
|
* Called when a tool execution completes, either successfully or with an error.
|
|
2011
2026
|
* Uses the `toolOutput.type` discriminator to distinguish success and error.
|
|
2012
2027
|
*/
|
|
2013
|
-
type ToolExecutionEndEvent<TOOLS extends ToolSet = ToolSet> = [
|
|
2014
|
-
ToolSet
|
|
2015
|
-
] extends [TOOLS] ? WidenedToolExecutionEndEvent : StaticToolExecutionEndEvent<TOOLS> | DynamicToolExecutionEndEvent<TOOLS>;
|
|
2028
|
+
type ToolExecutionEndEvent<TOOLS extends ToolSet = ToolSet> = [ToolSet] extends [TOOLS] ? WidenedToolExecutionEndEvent : StaticToolExecutionEndEvent<TOOLS> | DynamicToolExecutionEndEvent<TOOLS>;
|
|
2016
2029
|
/**
|
|
2017
2030
|
* Callback that is set using the `onToolExecutionStart` option.
|
|
2018
2031
|
*
|
|
@@ -2035,7 +2048,8 @@ type OnToolExecutionStartCallback<TOOLS extends ToolSet = ToolSet> = Callback<To
|
|
|
2035
2048
|
* @param event - The event object containing tool call result information.
|
|
2036
2049
|
*/
|
|
2037
2050
|
type OnToolExecutionEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<ToolExecutionEndEvent<TOOLS>>;
|
|
2038
|
-
|
|
2051
|
+
//#endregion
|
|
2052
|
+
//#region src/generate-text/tool-input-refinement.d.ts
|
|
2039
2053
|
/**
|
|
2040
2054
|
* Mapping of tool names to functions that refine parsed tool inputs.
|
|
2041
2055
|
*
|
|
@@ -2043,10 +2057,9 @@ type OnToolExecutionEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<Tool
|
|
|
2043
2057
|
* an input with the same type shape. Refined inputs are used for tool execution,
|
|
2044
2058
|
* output parts, lifecycle callbacks, and telemetry.
|
|
2045
2059
|
*/
|
|
2046
|
-
type ToolInputRefinement<TOOLS extends ToolSet> = {
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2060
|
+
type ToolInputRefinement<TOOLS extends ToolSet> = { [NAME in keyof TOOLS]?: (input: InferToolInput<TOOLS[NAME]>) => MaybePromiseLike<InferToolInput<TOOLS[NAME]>>; };
|
|
2061
|
+
//#endregion
|
|
2062
|
+
//#region src/generate-text/tools-context-parameter.d.ts
|
|
2050
2063
|
/**
|
|
2051
2064
|
* Checks whether a tool context map contains any contextual tool entries.
|
|
2052
2065
|
*/
|
|
@@ -2056,95 +2069,98 @@ type IsEmptyObject<OBJECT> = keyof OBJECT extends never ? true : false;
|
|
|
2056
2069
|
* the tool set.
|
|
2057
2070
|
*/
|
|
2058
2071
|
type ToolsContextSettings<TOOLS extends ToolSet> = IsEmptyObject<InferToolSetContext<TOOLS>> extends true ? {
|
|
2059
|
-
|
|
2072
|
+
toolsContext?: never;
|
|
2060
2073
|
} : HasRequiredKey<InferToolSetContext<TOOLS>> extends true ? {
|
|
2061
|
-
|
|
2074
|
+
toolsContext: InferToolSetContext<TOOLS>;
|
|
2062
2075
|
} : {
|
|
2063
|
-
|
|
2076
|
+
toolsContext?: InferToolSetContext<TOOLS>;
|
|
2064
2077
|
};
|
|
2065
|
-
|
|
2078
|
+
//#endregion
|
|
2079
|
+
//#region src/generate-text/stream-text.d.ts
|
|
2066
2080
|
type EnrichedStreamPart<TOOLS extends ToolSet, PARTIAL_OUTPUT> = {
|
|
2067
|
-
|
|
2068
|
-
|
|
2081
|
+
part: TextStreamPart<TOOLS>;
|
|
2082
|
+
partialOutput: PARTIAL_OUTPUT | undefined;
|
|
2069
2083
|
};
|
|
2070
|
-
|
|
2084
|
+
//#endregion
|
|
2085
|
+
//#region src/generate-text/output.d.ts
|
|
2071
2086
|
interface Output<OUTPUT = any, PARTIAL = any, ELEMENT = any> {
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2087
|
+
/**
|
|
2088
|
+
* The name of the output mode.
|
|
2089
|
+
*/
|
|
2090
|
+
name: string;
|
|
2091
|
+
/**
|
|
2092
|
+
* The response format to use for the model.
|
|
2093
|
+
*/
|
|
2094
|
+
responseFormat: PromiseLike<LanguageModelV4CallOptions['responseFormat']>;
|
|
2095
|
+
/**
|
|
2096
|
+
* Parses the complete output of the model.
|
|
2097
|
+
*/
|
|
2098
|
+
parseCompleteOutput(options: {
|
|
2099
|
+
text: string;
|
|
2100
|
+
}, context: {
|
|
2101
|
+
response: Omit<LanguageModelResponseMetadata, 'messages' | 'body'>;
|
|
2102
|
+
usage: LanguageModelUsage;
|
|
2103
|
+
finishReason: FinishReason;
|
|
2104
|
+
}): Promise<OUTPUT>;
|
|
2105
|
+
/**
|
|
2106
|
+
* Parses the partial output of the model.
|
|
2107
|
+
*/
|
|
2108
|
+
parsePartialOutput(options: {
|
|
2109
|
+
text: string;
|
|
2110
|
+
}): Promise<{
|
|
2111
|
+
partial: PARTIAL;
|
|
2112
|
+
} | undefined>;
|
|
2113
|
+
/**
|
|
2114
|
+
* Creates a stream transform that emits individual elements as they complete.
|
|
2115
|
+
*/
|
|
2116
|
+
createElementStreamTransform(): TransformStream<EnrichedStreamPart<any, PARTIAL>, ELEMENT> | undefined;
|
|
2102
2117
|
}
|
|
2103
|
-
|
|
2118
|
+
//#endregion
|
|
2119
|
+
//#region src/generate-text/generate-text-events.d.ts
|
|
2104
2120
|
/**
|
|
2105
2121
|
* Event passed to the `onStart` callback.
|
|
2106
2122
|
*
|
|
2107
2123
|
* Called when the generation operation begins, before any LLM calls.
|
|
2108
2124
|
*/
|
|
2109
2125
|
type GenerateTextStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = {
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2126
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
2127
|
+
readonly callId: string;
|
|
2128
|
+
/** Identifies the operation type (e.g. 'ai.generateText' or 'ai.streamText'). */
|
|
2129
|
+
readonly operationId: string;
|
|
2130
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
2131
|
+
readonly provider: string;
|
|
2132
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
2133
|
+
readonly modelId: string;
|
|
2134
|
+
/** The tools available for this generation. */
|
|
2135
|
+
readonly tools: TOOLS | undefined;
|
|
2136
|
+
/** The tool choice strategy for this generation. */
|
|
2137
|
+
readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
|
|
2138
|
+
/** Limits which tools are available for the model to call. */
|
|
2139
|
+
readonly activeTools: ActiveTools<TOOLS>;
|
|
2140
|
+
/** Controls the order in which tools are sent to the provider. */
|
|
2141
|
+
readonly toolOrder: ToolOrder<TOOLS>;
|
|
2142
|
+
/** Maximum number of retries for failed requests. */
|
|
2143
|
+
readonly maxRetries: number;
|
|
2144
|
+
/**
|
|
2145
|
+
* Timeout configuration for the generation.
|
|
2146
|
+
* Can be a number (milliseconds) or an object with totalMs, stepMs,
|
|
2147
|
+
* firstChunkMs (streaming only), chunkMs, toolMs, and per-tool overrides via tools.
|
|
2148
|
+
*/
|
|
2149
|
+
readonly timeout: TimeoutConfiguration<TOOLS> | undefined;
|
|
2150
|
+
/** Additional HTTP headers sent with the request. */
|
|
2151
|
+
readonly headers: Record<string, string | undefined> | undefined;
|
|
2152
|
+
/** Additional provider-specific options. */
|
|
2153
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
2154
|
+
/** The output specification for structured outputs, if configured. */
|
|
2155
|
+
readonly output: OUTPUT | undefined;
|
|
2156
|
+
/**
|
|
2157
|
+
* Tool context.
|
|
2158
|
+
*/
|
|
2159
|
+
readonly toolsContext: InferToolSetContext<TOOLS>;
|
|
2160
|
+
/**
|
|
2161
|
+
* User-defined runtime context.
|
|
2162
|
+
*/
|
|
2163
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
2148
2164
|
} & LanguageModelCallOptions & StandardizedPrompt;
|
|
2149
2165
|
/**
|
|
2150
2166
|
* Event passed to the `onStepStart` callback.
|
|
@@ -2153,36 +2169,36 @@ type GenerateTextStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT ext
|
|
|
2153
2169
|
* Each step represents a single LLM invocation.
|
|
2154
2170
|
*/
|
|
2155
2171
|
type GenerateTextStepStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = {
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2172
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
2173
|
+
readonly callId: string;
|
|
2174
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
2175
|
+
readonly provider: string;
|
|
2176
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
2177
|
+
readonly modelId: string;
|
|
2178
|
+
/** Zero-based index of the current step. */
|
|
2179
|
+
readonly stepNumber: number;
|
|
2180
|
+
/** The tools available for this generation. */
|
|
2181
|
+
readonly tools: TOOLS | undefined;
|
|
2182
|
+
/** The tool choice configuration for this step. */
|
|
2183
|
+
readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
|
|
2184
|
+
/** Limits which tools are available for this step. */
|
|
2185
|
+
readonly activeTools: ActiveTools<TOOLS>;
|
|
2186
|
+
/** Controls the order in which tools are sent to the provider for this step. */
|
|
2187
|
+
readonly toolOrder: ToolOrder<TOOLS>;
|
|
2188
|
+
/** Array of results from previous steps (empty for first step). */
|
|
2189
|
+
readonly steps: ReadonlyArray<StepResult<TOOLS, RUNTIME_CONTEXT>>;
|
|
2190
|
+
/** Additional provider-specific options for this step. */
|
|
2191
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
2192
|
+
/** The output specification for structured outputs, if configured. */
|
|
2193
|
+
readonly output: OUTPUT | undefined;
|
|
2194
|
+
/**
|
|
2195
|
+
* Runtime context. May be updated from `prepareStep` between steps.
|
|
2196
|
+
*/
|
|
2197
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
2198
|
+
/**
|
|
2199
|
+
* Tool context. May be updated from `prepareStep` between steps.
|
|
2200
|
+
*/
|
|
2201
|
+
readonly toolsContext: InferToolSetContext<TOOLS>;
|
|
2186
2202
|
} & StandardizedPrompt;
|
|
2187
2203
|
/**
|
|
2188
2204
|
* Event passed to the `onStepEnd` callback.
|
|
@@ -2198,94 +2214,94 @@ type GenerateTextStepEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT e
|
|
|
2198
2214
|
* Includes the final step's result along with aggregated data from all steps.
|
|
2199
2215
|
*/
|
|
2200
2216
|
type GenerateTextEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = {
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2217
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
2218
|
+
readonly callId: string;
|
|
2219
|
+
/** Zero-based index of the final step. */
|
|
2220
|
+
readonly stepNumber: number;
|
|
2221
|
+
/** Information about the model that produced the final step. */
|
|
2222
|
+
readonly model: StepResult<TOOLS, RUNTIME_CONTEXT>['model'];
|
|
2223
|
+
/**
|
|
2224
|
+
* Tool context from the final step.
|
|
2225
|
+
*
|
|
2226
|
+
* @deprecated Use `finalStep.toolsContext` instead.
|
|
2227
|
+
*/
|
|
2228
|
+
readonly toolsContext: InferToolSetContext<TOOLS>;
|
|
2229
|
+
/**
|
|
2230
|
+
* Runtime context from the final step.
|
|
2231
|
+
*
|
|
2232
|
+
* @deprecated Use `finalStep.runtimeContext` instead.
|
|
2233
|
+
*/
|
|
2234
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
2235
|
+
/** The content that was generated in all steps. */
|
|
2236
|
+
readonly content: StepResult<TOOLS, RUNTIME_CONTEXT>['content'];
|
|
2237
|
+
/** The text that was generated in the final step. */
|
|
2238
|
+
readonly text: StepResult<TOOLS, RUNTIME_CONTEXT>['text'];
|
|
2239
|
+
/**
|
|
2240
|
+
* The reasoning that was generated in the final step.
|
|
2241
|
+
*
|
|
2242
|
+
* @deprecated Use `finalStep.reasoning` instead.
|
|
2243
|
+
*/
|
|
2244
|
+
readonly reasoning: StepResult<TOOLS, RUNTIME_CONTEXT>['reasoning'];
|
|
2245
|
+
/**
|
|
2246
|
+
* The reasoning text that was generated in the final step.
|
|
2247
|
+
*
|
|
2248
|
+
* @deprecated Use `finalStep.reasoningText` instead.
|
|
2249
|
+
*/
|
|
2250
|
+
readonly reasoningText: StepResult<TOOLS, RUNTIME_CONTEXT>['reasoningText'];
|
|
2251
|
+
/** Files that were generated in all steps. */
|
|
2252
|
+
readonly files: StepResult<TOOLS, RUNTIME_CONTEXT>['files'];
|
|
2253
|
+
/** Sources that were used as references in all steps. */
|
|
2254
|
+
readonly sources: StepResult<TOOLS, RUNTIME_CONTEXT>['sources'];
|
|
2255
|
+
/** Tool calls that were made in all steps. */
|
|
2256
|
+
readonly toolCalls: StepResult<TOOLS, RUNTIME_CONTEXT>['toolCalls'];
|
|
2257
|
+
/** Static tool calls that were made in all steps. */
|
|
2258
|
+
readonly staticToolCalls: StepResult<TOOLS, RUNTIME_CONTEXT>['staticToolCalls'];
|
|
2259
|
+
/** Dynamic tool calls that were made in all steps. */
|
|
2260
|
+
readonly dynamicToolCalls: StepResult<TOOLS, RUNTIME_CONTEXT>['dynamicToolCalls'];
|
|
2261
|
+
/** Tool results that were generated in all steps. */
|
|
2262
|
+
readonly toolResults: StepResult<TOOLS, RUNTIME_CONTEXT>['toolResults'];
|
|
2263
|
+
/** Static tool results that were generated in all steps. */
|
|
2264
|
+
readonly staticToolResults: StepResult<TOOLS, RUNTIME_CONTEXT>['staticToolResults'];
|
|
2265
|
+
/** Dynamic tool results that were generated in all steps. */
|
|
2266
|
+
readonly dynamicToolResults: StepResult<TOOLS, RUNTIME_CONTEXT>['dynamicToolResults'];
|
|
2267
|
+
/** The unified reason why the generation finished. Taken from the final step. */
|
|
2268
|
+
readonly finishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['finishReason'];
|
|
2269
|
+
/** The raw reason why the generation finished. Taken from the final step. */
|
|
2270
|
+
readonly rawFinishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['rawFinishReason'];
|
|
2271
|
+
/** Aggregated token usage across all steps. */
|
|
2272
|
+
readonly usage: LanguageModelUsage;
|
|
2273
|
+
/**
|
|
2274
|
+
* Aggregated token usage across all steps.
|
|
2275
|
+
*
|
|
2276
|
+
* @deprecated Use `usage` instead.
|
|
2277
|
+
*/
|
|
2278
|
+
readonly totalUsage: LanguageModelUsage;
|
|
2279
|
+
/** Warnings from the model provider in all steps. */
|
|
2280
|
+
readonly warnings: StepResult<TOOLS, RUNTIME_CONTEXT>['warnings'];
|
|
2281
|
+
/**
|
|
2282
|
+
* Additional request information from the final step.
|
|
2283
|
+
*
|
|
2284
|
+
* @deprecated Use `finalStep.request` instead.
|
|
2285
|
+
*/
|
|
2286
|
+
readonly request: StepResult<TOOLS, RUNTIME_CONTEXT>['request'];
|
|
2287
|
+
/**
|
|
2288
|
+
* Additional response information from the final step.
|
|
2289
|
+
*
|
|
2290
|
+
* @deprecated Use `finalStep.response` instead.
|
|
2291
|
+
*/
|
|
2292
|
+
readonly response: StepResult<TOOLS, RUNTIME_CONTEXT>['response'];
|
|
2293
|
+
/**
|
|
2294
|
+
* Additional provider-specific metadata from the final step.
|
|
2295
|
+
*
|
|
2296
|
+
* @deprecated Use `finalStep.providerMetadata` instead.
|
|
2297
|
+
*/
|
|
2298
|
+
readonly providerMetadata: StepResult<TOOLS, RUNTIME_CONTEXT>['providerMetadata'];
|
|
2299
|
+
/** The response messages that were generated during the call. */
|
|
2300
|
+
readonly responseMessages: ResponseMessage[];
|
|
2301
|
+
/** Array containing results from all steps in the generation. */
|
|
2302
|
+
readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
|
|
2303
|
+
/** The final step. This is a shortcut for `steps.at(-1)`. */
|
|
2304
|
+
readonly finalStep: StepResult<TOOLS, RUNTIME_CONTEXT>;
|
|
2289
2305
|
};
|
|
2290
2306
|
/**
|
|
2291
2307
|
* Event passed to an `onAbort` callback for text generation.
|
|
@@ -2294,12 +2310,12 @@ type GenerateTextEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT exten
|
|
|
2294
2310
|
* completes.
|
|
2295
2311
|
*/
|
|
2296
2312
|
type GenerateTextAbortEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = {
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2313
|
+
/** Unique identifier for this generation call, used to correlate events. */
|
|
2314
|
+
readonly callId: string;
|
|
2315
|
+
/** Details for all previously finished steps. */
|
|
2316
|
+
readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
|
|
2317
|
+
/** The abort reason from the AbortSignal, when one is available. */
|
|
2318
|
+
readonly reason?: unknown;
|
|
2303
2319
|
};
|
|
2304
2320
|
/**
|
|
2305
2321
|
* Callback that is set using the `onStart` option.
|
|
@@ -2355,34 +2371,35 @@ type GenerateTextOnEndCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT
|
|
|
2355
2371
|
* @param event - The abort event, including finished steps and abort reason.
|
|
2356
2372
|
*/
|
|
2357
2373
|
type GenerateTextOnAbortCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = Callback<GenerateTextAbortEvent<TOOLS, RUNTIME_CONTEXT>>;
|
|
2358
|
-
|
|
2374
|
+
//#endregion
|
|
2375
|
+
//#region src/rerank/rerank-events.d.ts
|
|
2359
2376
|
/**
|
|
2360
2377
|
* Event passed to the `onStart` callback for rerank operations.
|
|
2361
2378
|
*
|
|
2362
2379
|
* Called when the operation begins, before the reranking model is called.
|
|
2363
2380
|
*/
|
|
2364
2381
|
type RerankStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2382
|
+
/** User-defined runtime context. */
|
|
2383
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
2384
|
+
/** Unique identifier for this rerank call, used to correlate events. */
|
|
2385
|
+
readonly callId: string;
|
|
2386
|
+
/** Identifies the operation type ('ai.rerank'). */
|
|
2387
|
+
readonly operationId: string;
|
|
2388
|
+
readonly provider: string;
|
|
2389
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
2390
|
+
readonly modelId: string;
|
|
2391
|
+
/** The documents being reranked. */
|
|
2392
|
+
readonly documents: Array<JSONObject | string>;
|
|
2393
|
+
/** The query to rerank the documents against. */
|
|
2394
|
+
readonly query: string;
|
|
2395
|
+
/** Number of top documents to return. */
|
|
2396
|
+
readonly topN: number | undefined;
|
|
2397
|
+
/** Maximum number of retries for failed requests. */
|
|
2398
|
+
readonly maxRetries: number;
|
|
2399
|
+
/** Additional HTTP headers sent with the request. */
|
|
2400
|
+
readonly headers: Record<string, string | undefined> | undefined;
|
|
2401
|
+
/** Additional provider-specific options. */
|
|
2402
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
2386
2403
|
};
|
|
2387
2404
|
/**
|
|
2388
2405
|
* Event passed to the `onEnd` callback for rerank operations.
|
|
@@ -2390,58 +2407,58 @@ type RerankStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
|
2390
2407
|
* Called when the operation completes, after the reranking model returns.
|
|
2391
2408
|
*/
|
|
2392
2409
|
type RerankEndEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2410
|
+
/** User-defined runtime context. */
|
|
2411
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
2412
|
+
/** Unique identifier for this rerank call, used to correlate events. */
|
|
2413
|
+
readonly callId: string;
|
|
2414
|
+
/** Identifies the operation type ('ai.rerank'). */
|
|
2415
|
+
readonly operationId: string;
|
|
2416
|
+
readonly provider: string;
|
|
2417
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
2418
|
+
readonly modelId: string;
|
|
2419
|
+
/** The documents that were reranked. */
|
|
2420
|
+
readonly documents: Array<JSONObject | string>;
|
|
2421
|
+
/** The query that documents were reranked against. */
|
|
2422
|
+
readonly query: string;
|
|
2423
|
+
/** The reranked results sorted by relevance score in descending order. */
|
|
2424
|
+
readonly ranking: Array<{
|
|
2425
|
+
originalIndex: number;
|
|
2426
|
+
score: number;
|
|
2427
|
+
document: JSONObject | string;
|
|
2428
|
+
}>;
|
|
2429
|
+
/** Warnings from the reranking model. */
|
|
2430
|
+
readonly warnings: Array<Warning>;
|
|
2431
|
+
/** Optional provider-specific metadata. */
|
|
2432
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
|
2433
|
+
/** Response data including headers and body. */
|
|
2434
|
+
readonly response: {
|
|
2435
|
+
id?: string;
|
|
2436
|
+
timestamp: Date;
|
|
2437
|
+
modelId: string;
|
|
2438
|
+
headers?: Record<string, string>;
|
|
2439
|
+
body?: unknown;
|
|
2440
|
+
};
|
|
2424
2441
|
};
|
|
2425
2442
|
/**
|
|
2426
2443
|
* Event fired when an individual reranking model call (inner doRerank) begins.
|
|
2427
2444
|
*/
|
|
2428
2445
|
type RerankingModelCallStartEvent = {
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2446
|
+
/** Unique identifier for this rerank call, used to correlate events. */
|
|
2447
|
+
readonly callId: string;
|
|
2448
|
+
/** Identifies the inner operation ('ai.rerank.doRerank'). */
|
|
2449
|
+
readonly operationId: string;
|
|
2450
|
+
/** The provider identifier. */
|
|
2451
|
+
readonly provider: string;
|
|
2452
|
+
/** The specific model identifier. */
|
|
2453
|
+
readonly modelId: string;
|
|
2454
|
+
/** The documents being reranked. */
|
|
2455
|
+
readonly documents: Array<JSONObject | string>;
|
|
2456
|
+
/** The type of documents ('text' or 'object'). */
|
|
2457
|
+
readonly documentsType: string;
|
|
2458
|
+
/** The query to rerank against. */
|
|
2459
|
+
readonly query: string;
|
|
2460
|
+
/** Number of top documents to return. */
|
|
2461
|
+
readonly topN: number | undefined;
|
|
2445
2462
|
};
|
|
2446
2463
|
/**
|
|
2447
2464
|
* Event fired when an individual reranking model call (doRerank) completes.
|
|
@@ -2449,330 +2466,342 @@ type RerankingModelCallStartEvent = {
|
|
|
2449
2466
|
* Contains the ranking results from the model response.
|
|
2450
2467
|
*/
|
|
2451
2468
|
type RerankingModelCallEndEvent = {
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
};
|
|
2468
|
-
|
|
2469
|
+
/** Unique identifier for this rerank call, used to correlate events. */
|
|
2470
|
+
readonly callId: string;
|
|
2471
|
+
/** Identifies the inner operation ('ai.rerank.doRerank'). */
|
|
2472
|
+
readonly operationId: string;
|
|
2473
|
+
/** The provider identifier. */
|
|
2474
|
+
readonly provider: string;
|
|
2475
|
+
/** The specific model identifier. */
|
|
2476
|
+
readonly modelId: string;
|
|
2477
|
+
/** The type of documents ('text' or 'object'). */
|
|
2478
|
+
readonly documentsType: string;
|
|
2479
|
+
/** The ranking results from the model. */
|
|
2480
|
+
readonly ranking: Array<{
|
|
2481
|
+
index: number;
|
|
2482
|
+
relevanceScore: number;
|
|
2483
|
+
}>;
|
|
2484
|
+
};
|
|
2485
|
+
//#endregion
|
|
2486
|
+
//#region src/telemetry/tracing-channel.d.ts
|
|
2469
2487
|
type TelemetryTracingEventType = 'generateText' | 'streamText' | 'step' | 'languageModelCall' | 'executeTool' | 'embed' | 'embedMany' | 'rerank' | 'experimental_evaluate';
|
|
2470
|
-
|
|
2488
|
+
//#endregion
|
|
2489
|
+
//#region src/telemetry/tracing-channel-publisher.d.ts
|
|
2471
2490
|
type TracingChannelContext = {
|
|
2472
|
-
|
|
2491
|
+
run<T>(execute: () => T): T;
|
|
2473
2492
|
};
|
|
2474
|
-
|
|
2493
|
+
//#endregion
|
|
2494
|
+
//#region src/telemetry/telemetry.d.ts
|
|
2475
2495
|
type InferTelemetryEvent<EVENT> = EVENT & Omit<TelemetryOptions, 'integrations' | 'isEnabled' | 'includeRuntimeContext'>;
|
|
2476
2496
|
type OperationStartEvent = GenerateTextStartEvent | GenerateObjectStartEvent | EmbedStartEvent | RerankStartEvent;
|
|
2477
2497
|
type OperationEndEvent = GenerateTextEndEvent<ToolSet> | GenerateObjectEndEvent<unknown> | EmbedEndEvent | RerankEndEvent;
|
|
2478
2498
|
interface TelemetryDispatcher {
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2499
|
+
/**
|
|
2500
|
+
* Runs awaited work inside a diagnostics-channel tracing span.
|
|
2501
|
+
*/
|
|
2502
|
+
runInTracingChannelSpan?: <T>(options: {
|
|
2503
|
+
type: TelemetryTracingEventType;
|
|
2504
|
+
event: unknown;
|
|
2505
|
+
execute: () => PromiseLike<T>;
|
|
2506
|
+
}) => Promise<T>;
|
|
2507
|
+
/**
|
|
2508
|
+
* Opens a tracing span context whose completion is observed separately.
|
|
2509
|
+
* This is used by streamed operations that must preserve stream timing while
|
|
2510
|
+
* still creating child spans with the correct parent.
|
|
2511
|
+
*/
|
|
2512
|
+
startTracingChannelContext?: (options: {
|
|
2513
|
+
type: TelemetryTracingEventType;
|
|
2514
|
+
event: unknown;
|
|
2515
|
+
completion: PromiseLike<unknown>;
|
|
2516
|
+
}) => TracingChannelContext | undefined;
|
|
2517
|
+
onStart?: Callback<OperationStartEvent>;
|
|
2518
|
+
onStepStart?: Callback<GenerateTextStepStartEvent>;
|
|
2519
|
+
onLanguageModelCallStart?: OnLanguageModelCallStartCallback;
|
|
2520
|
+
onLanguageModelCallEnd?: OnLanguageModelCallEndCallback;
|
|
2521
|
+
onToolExecutionStart?: Callback<ToolExecutionStartEvent>;
|
|
2522
|
+
onToolExecutionEnd?: Callback<ToolExecutionEndEvent>;
|
|
2523
|
+
onStepEnd?: Callback<GenerateTextStepEndEvent>;
|
|
2524
|
+
/** @deprecated Use `onStepEnd` instead. */
|
|
2525
|
+
onStepFinish?: Callback<GenerateTextStepEndEvent>;
|
|
2526
|
+
onObjectStepStart?: Callback<GenerateObjectStepStartEvent>;
|
|
2527
|
+
onObjectStepEnd?: Callback<GenerateObjectStepEndEvent>;
|
|
2528
|
+
onEmbedStart?: Callback<EmbeddingModelCallStartEvent>;
|
|
2529
|
+
onEmbedEnd?: Callback<EmbeddingModelCallEndEvent>;
|
|
2530
|
+
onRerankStart?: Callback<RerankingModelCallStartEvent>;
|
|
2531
|
+
onRerankEnd?: Callback<RerankingModelCallEndEvent>;
|
|
2532
|
+
experimental_onEvaluateStart?: Callback<EvaluateStartEvent>;
|
|
2533
|
+
experimental_onEvaluationModelCallStart?: Callback<EvaluationModelCallStartEvent>;
|
|
2534
|
+
experimental_onEvaluationModelCallEnd?: Callback<EvaluationModelCallEndEvent>;
|
|
2535
|
+
experimental_onEvaluateEnd?: Callback<EvaluateEndEvent>;
|
|
2536
|
+
onEnd?: Callback<OperationEndEvent>;
|
|
2537
|
+
onAbort?: Callback<GenerateTextAbortEvent<ToolSet>>;
|
|
2538
|
+
onError?: Callback<unknown>;
|
|
2539
|
+
executeLanguageModelCall?: Telemetry['executeLanguageModelCall'];
|
|
2540
|
+
executeTool?: Telemetry['executeTool'];
|
|
2521
2541
|
}
|
|
2522
2542
|
/**
|
|
2523
2543
|
* Implement this interface to create custom telemetry integrations.
|
|
2524
2544
|
* Methods can be sync or return a PromiseLike.
|
|
2525
2545
|
*/
|
|
2526
2546
|
interface Telemetry {
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2547
|
+
/**
|
|
2548
|
+
* Called when an operation begins. Fired for text generation
|
|
2549
|
+
* (generateText/streamText), object generation (generateObject/streamObject),
|
|
2550
|
+
* embedding (embed/embedMany), and reranking operations.
|
|
2551
|
+
*
|
|
2552
|
+
* Use the `operationId` field to distinguish between operation types.
|
|
2553
|
+
*/
|
|
2554
|
+
onStart?: Callback<InferTelemetryEvent<OperationStartEvent>>;
|
|
2555
|
+
/**
|
|
2556
|
+
* Called when an individual step (single LLM invocation) begins.
|
|
2557
|
+
* A generation may consist of multiple steps (e.g. when tool calls trigger
|
|
2558
|
+
* follow-up LLM calls). Use this to create per-step spans or record
|
|
2559
|
+
* step-level inputs.
|
|
2560
|
+
*
|
|
2561
|
+
* The event includes the step number, accumulated previous step results,
|
|
2562
|
+
* and the messages that will be sent to the model.
|
|
2563
|
+
*/
|
|
2564
|
+
onStepStart?: Callback<InferTelemetryEvent<GenerateTextStepStartEvent>>;
|
|
2565
|
+
/**
|
|
2566
|
+
* Called immediately before the provider model call begins.
|
|
2567
|
+
* Unlike `onStepStart`, this callback is scoped to model work only and
|
|
2568
|
+
* excludes any later client-side tool execution.
|
|
2569
|
+
*/
|
|
2570
|
+
onLanguageModelCallStart?: Callback<InferTelemetryEvent<LanguageModelCallStartEvent>>;
|
|
2571
|
+
/**
|
|
2572
|
+
* Called after the model response has been normalized and parsed, but before
|
|
2573
|
+
* any client-side tool execution begins.
|
|
2574
|
+
*/
|
|
2575
|
+
onLanguageModelCallEnd?: Callback<InferTelemetryEvent<LanguageModelCallEndEvent>>;
|
|
2576
|
+
/**
|
|
2577
|
+
* Called when a tool execution begins, before the tool's `execute` function
|
|
2578
|
+
* is invoked. Use this to create tool-level spans or log tool invocations.
|
|
2579
|
+
*/
|
|
2580
|
+
onToolExecutionStart?: Callback<InferTelemetryEvent<ToolExecutionStartEvent>>;
|
|
2581
|
+
/**
|
|
2582
|
+
* Called when a tool execution completes, either successfully or with an error.
|
|
2583
|
+
* The event uses a discriminated union on the `success` field — check
|
|
2584
|
+
* `event.success` to determine whether `output` or `error` is available.
|
|
2585
|
+
*
|
|
2586
|
+
* The event includes execution time (`toolExecutionMs`) for performance tracking.
|
|
2587
|
+
*/
|
|
2588
|
+
onToolExecutionEnd?: Callback<InferTelemetryEvent<ToolExecutionEndEvent>>;
|
|
2589
|
+
/**
|
|
2590
|
+
* Called when an individual step (single LLM invocation) completes.
|
|
2591
|
+
* The event is a `StepResult` containing the model's response, tool calls
|
|
2592
|
+
* and results, usage statistics, finish reason, and optional request/response
|
|
2593
|
+
* bodies.
|
|
2594
|
+
*/
|
|
2595
|
+
onStepEnd?: Callback<InferTelemetryEvent<GenerateTextStepEndEvent>>;
|
|
2596
|
+
/**
|
|
2597
|
+
* Called when an individual step (single LLM invocation) completes.
|
|
2598
|
+
*
|
|
2599
|
+
* @deprecated Use `onStepEnd` instead.
|
|
2600
|
+
*/
|
|
2601
|
+
onStepFinish?: Callback<InferTelemetryEvent<GenerateTextStepEndEvent>>;
|
|
2602
|
+
/**
|
|
2603
|
+
* Called when an object generation step (single LLM invocation) begins.
|
|
2604
|
+
* For generateObject/streamObject there is always exactly one step.
|
|
2605
|
+
*
|
|
2606
|
+
* @deprecated
|
|
2607
|
+
*/
|
|
2608
|
+
onObjectStepStart?: Callback<InferTelemetryEvent<GenerateObjectStepStartEvent>>;
|
|
2609
|
+
/**
|
|
2610
|
+
* Called when an object generation step (single LLM invocation) completes,
|
|
2611
|
+
* with the raw result before JSON parsing and schema validation.
|
|
2612
|
+
*
|
|
2613
|
+
* @deprecated
|
|
2614
|
+
*/
|
|
2615
|
+
onObjectStepEnd?: Callback<InferTelemetryEvent<GenerateObjectStepEndEvent>>;
|
|
2616
|
+
/**
|
|
2617
|
+
* Called when an individual embedding model call (doEmbed) begins.
|
|
2618
|
+
* For `embed`, there is one call. For `embedMany`, there may be multiple
|
|
2619
|
+
* calls when values are chunked.
|
|
2620
|
+
*/
|
|
2621
|
+
onEmbedStart?: Callback<InferTelemetryEvent<EmbeddingModelCallStartEvent>>;
|
|
2622
|
+
/**
|
|
2623
|
+
* Called when an individual embedding model call (doEmbed) completes.
|
|
2624
|
+
* Contains the embeddings, usage, and any warnings from the model response.
|
|
2625
|
+
*/
|
|
2626
|
+
onEmbedEnd?: Callback<InferTelemetryEvent<EmbeddingModelCallEndEvent>>;
|
|
2627
|
+
/**
|
|
2628
|
+
* Called when an individual reranking model call (doRerank) begins.
|
|
2629
|
+
* There is one call per `rerank` invocation.
|
|
2630
|
+
*/
|
|
2631
|
+
onRerankStart?: Callback<InferTelemetryEvent<RerankingModelCallStartEvent>>;
|
|
2632
|
+
/**
|
|
2633
|
+
* Called when an individual reranking model call (doRerank) completes.
|
|
2634
|
+
* Contains the ranking results from the model response.
|
|
2635
|
+
*/
|
|
2636
|
+
onRerankEnd?: Callback<InferTelemetryEvent<RerankingModelCallEndEvent>>;
|
|
2637
|
+
/** Called when an experimental evaluation operation begins. */
|
|
2638
|
+
experimental_onEvaluateStart?: Callback<InferTelemetryEvent<EvaluateStartEvent>>;
|
|
2639
|
+
/**
|
|
2640
|
+
* Called immediately before an experimental evaluation model call begins.
|
|
2641
|
+
* The logical model call includes any provider retries.
|
|
2642
|
+
*/
|
|
2643
|
+
experimental_onEvaluationModelCallStart?: Callback<InferTelemetryEvent<EvaluationModelCallStartEvent>>;
|
|
2644
|
+
/**
|
|
2645
|
+
* Called after an experimental evaluation model response has been validated.
|
|
2646
|
+
* The logical model call includes any provider retries.
|
|
2647
|
+
*/
|
|
2648
|
+
experimental_onEvaluationModelCallEnd?: Callback<InferTelemetryEvent<EvaluationModelCallEndEvent>>;
|
|
2649
|
+
/** Called when an experimental evaluation operation completes. */
|
|
2650
|
+
experimental_onEvaluateEnd?: Callback<InferTelemetryEvent<EvaluateEndEvent>>;
|
|
2651
|
+
/**
|
|
2652
|
+
* Called when an operation completes. Fired for text generation
|
|
2653
|
+
* (generateText/streamText), object generation (generateObject/streamObject),
|
|
2654
|
+
* embedding (embed/embedMany), and reranking operations.
|
|
2655
|
+
*
|
|
2656
|
+
* Use the event shape or `operationId` to distinguish between operation types.
|
|
2657
|
+
*/
|
|
2658
|
+
onEnd?: Callback<InferTelemetryEvent<OperationEndEvent>>;
|
|
2659
|
+
/**
|
|
2660
|
+
* Called when a streaming text generation operation is aborted before it
|
|
2661
|
+
* completes.
|
|
2662
|
+
*/
|
|
2663
|
+
onAbort?: Callback<InferTelemetryEvent<GenerateTextAbortEvent<ToolSet>>>;
|
|
2664
|
+
/**
|
|
2665
|
+
* Called when an unrecoverable error occurs during the generation lifecycle.
|
|
2666
|
+
* The error value is untyped — it may be an `Error` instance, an `AISDKError`,
|
|
2667
|
+
* or any thrown value.
|
|
2668
|
+
*
|
|
2669
|
+
* Use this to record error details on telemetry spans and set error status.
|
|
2670
|
+
*/
|
|
2671
|
+
onError?: Callback<unknown>;
|
|
2672
|
+
/**
|
|
2673
|
+
* Optionally runs the language model call in a telemetry-integration-specific context. This enables
|
|
2674
|
+
* auto-instrumented model provider requests to become children of the current
|
|
2675
|
+
* model-call span.
|
|
2676
|
+
*
|
|
2677
|
+
* The options carry the model-call start-event content as context (the event
|
|
2678
|
+
* fields are optional), alongside the always-present `callId` and the
|
|
2679
|
+
* `execute` function that performs the model call.
|
|
2680
|
+
*/
|
|
2681
|
+
executeLanguageModelCall?: <T>(options: Partial<InferTelemetryEvent<LanguageModelCallStartEvent>> & {
|
|
2682
|
+
callId: string;
|
|
2683
|
+
execute: () => PromiseLike<T>;
|
|
2684
|
+
}) => PromiseLike<T>;
|
|
2685
|
+
/**
|
|
2686
|
+
* Optionally runs the tool execute function in a telemetry-integration-specific context. This enables
|
|
2687
|
+
* nested traces — e.g. when a tool's `execute` function calls `generateText`,
|
|
2688
|
+
* the inner call's spans become children of the tool span.
|
|
2689
|
+
*
|
|
2690
|
+
* The options carry the tool-execution start-event content as context (the
|
|
2691
|
+
* event fields are optional), alongside the always-present `callId`,
|
|
2692
|
+
* `toolCallId`, and the `execute` function to run.
|
|
2693
|
+
*/
|
|
2694
|
+
executeTool?: <T>(options: Partial<InferTelemetryEvent<ToolExecutionStartEvent>> & {
|
|
2695
|
+
callId: string;
|
|
2696
|
+
toolCallId: string;
|
|
2697
|
+
execute: () => PromiseLike<T>;
|
|
2698
|
+
}) => PromiseLike<T>;
|
|
2679
2699
|
}
|
|
2680
|
-
|
|
2700
|
+
//#endregion
|
|
2701
|
+
//#region src/global.d.ts
|
|
2681
2702
|
declare global {
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2703
|
+
/**
|
|
2704
|
+
* The default provider to use for the AI SDK.
|
|
2705
|
+
* String model ids are resolved to the default provider and model id.
|
|
2706
|
+
*
|
|
2707
|
+
* If not set, the default provider is the Vercel AI gateway provider.
|
|
2708
|
+
* Experimental evaluation requires an explicitly configured evaluation-capable provider.
|
|
2709
|
+
*
|
|
2710
|
+
* @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
|
|
2711
|
+
*/
|
|
2712
|
+
var AI_SDK_DEFAULT_PROVIDER: ProviderV4 | ProviderV3 | ProviderV2 | undefined;
|
|
2713
|
+
/**
|
|
2714
|
+
* The warning logger to use for the AI SDK.
|
|
2715
|
+
*
|
|
2716
|
+
* If not set, the default logger is the console.warn function.
|
|
2717
|
+
*
|
|
2718
|
+
* If set to false, no warnings are logged.
|
|
2719
|
+
*/
|
|
2720
|
+
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
2721
|
+
/**
|
|
2722
|
+
* Globally registered telemetry integrations for the AI SDK.
|
|
2723
|
+
*
|
|
2724
|
+
* Integrations registered here receive lifecycle events (onStart, onStepStart,
|
|
2725
|
+
* etc.) from every `generateText`, `streamText`, and similar call.
|
|
2726
|
+
*
|
|
2727
|
+
* Prefer using `registerTelemetry()` from `'ai'` instead of
|
|
2728
|
+
* assigning this directly.
|
|
2729
|
+
*/
|
|
2730
|
+
var AI_SDK_TELEMETRY_INTEGRATIONS: Telemetry[] | undefined;
|
|
2710
2731
|
}
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2732
|
+
//#endregion
|
|
2733
|
+
//#region src/prompt/convert-to-language-model-prompt.d.ts
|
|
2734
|
+
export declare function convertToLanguageModelPrompt({ prompt, supportedUrls, download, abortSignal, provider }: {
|
|
2735
|
+
prompt: StandardizedPrompt;
|
|
2736
|
+
supportedUrls: Record<string, RegExp[]>;
|
|
2737
|
+
download: DownloadFunction | undefined;
|
|
2738
|
+
abortSignal?: AbortSignal;
|
|
2739
|
+
provider?: string;
|
|
2718
2740
|
}): Promise<LanguageModelV4Prompt>;
|
|
2719
2741
|
/**
|
|
2720
2742
|
* Downloads files from URLs in the user messages.
|
|
2721
2743
|
*/
|
|
2722
|
-
declare function downloadAssets(messages: ModelMessage[], download: DownloadFunction, supportedUrls: Record<string, RegExp[]>): Promise<Record<string, {
|
|
2744
|
+
export declare function downloadAssets(messages: ModelMessage[], download: DownloadFunction, supportedUrls: Record<string, RegExp[]>): Promise<Record<string, {
|
|
2745
|
+
mediaType: string | undefined;
|
|
2746
|
+
data: Uint8Array;
|
|
2747
|
+
}>>;
|
|
2748
|
+
export declare function mapToolResultOutput({ output, provider, warnings, downloadedAssets }: {
|
|
2749
|
+
output: ToolResultOutput;
|
|
2750
|
+
provider?: string;
|
|
2751
|
+
warnings?: Warning[];
|
|
2752
|
+
downloadedAssets: Record<string, {
|
|
2723
2753
|
mediaType: string | undefined;
|
|
2724
2754
|
data: Uint8Array;
|
|
2725
|
-
}
|
|
2726
|
-
declare function mapToolResultOutput({ output, provider, warnings, downloadedAssets, }: {
|
|
2727
|
-
output: ToolResultOutput;
|
|
2728
|
-
provider?: string;
|
|
2729
|
-
warnings?: Warning[];
|
|
2730
|
-
downloadedAssets: Record<string, {
|
|
2731
|
-
mediaType: string | undefined;
|
|
2732
|
-
data: Uint8Array;
|
|
2733
|
-
}>;
|
|
2755
|
+
}>;
|
|
2734
2756
|
}): LanguageModelV4ToolResultOutput;
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2757
|
+
//#endregion
|
|
2758
|
+
//#region src/prompt/create-tool-model-output.d.ts
|
|
2759
|
+
export declare function createToolModelOutput({ toolCallId, input, output, tool, errorMode }: {
|
|
2760
|
+
toolCallId: string;
|
|
2761
|
+
input: unknown;
|
|
2762
|
+
output: unknown;
|
|
2763
|
+
tool: Tool | undefined;
|
|
2764
|
+
errorMode: 'none' | 'text' | 'json';
|
|
2742
2765
|
}): Promise<ToolResultOutput>;
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2766
|
+
//#endregion
|
|
2767
|
+
//#region src/prompt/prepare-tool-choice.d.ts
|
|
2768
|
+
export declare function prepareToolChoice({ toolChoice }: {
|
|
2769
|
+
toolChoice: ToolChoice<any> | undefined;
|
|
2746
2770
|
}): LanguageModelV4ToolChoice;
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2771
|
+
//#endregion
|
|
2772
|
+
//#region src/prompt/prepare-tools.d.ts
|
|
2773
|
+
export declare function prepareTools<TOOLS extends ToolSet>({ tools, toolOrder, toolsContext, experimental_sandbox: sandbox }: {
|
|
2774
|
+
tools: TOOLS | undefined;
|
|
2775
|
+
toolOrder?: ToolOrder<TOOLS>;
|
|
2776
|
+
toolsContext?: InferToolSetContext<TOOLS>;
|
|
2777
|
+
experimental_sandbox?: Experimental_SandboxSession;
|
|
2753
2778
|
}): Promise<Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined>;
|
|
2754
|
-
|
|
2779
|
+
//#endregion
|
|
2780
|
+
//#region src/prompt/prepare-language-model-call-options.d.ts
|
|
2755
2781
|
/**
|
|
2756
2782
|
* Validates model call options and returns a new object with normalized values.
|
|
2757
2783
|
*/
|
|
2758
|
-
declare function prepareLanguageModelCallOptions({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, seed, stopSequences, reasoning
|
|
2759
|
-
|
|
2784
|
+
export declare function prepareLanguageModelCallOptions({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, seed, stopSequences, reasoning }: LanguageModelCallOptions): LanguageModelCallOptions;
|
|
2785
|
+
//#endregion
|
|
2786
|
+
//#region src/util/prepare-retries.d.ts
|
|
2760
2787
|
/**
|
|
2761
2788
|
* Validate and prepare retries.
|
|
2762
2789
|
*/
|
|
2763
|
-
declare function prepareRetries({ maxRetries, abortSignal, additionalRetryableError, parameter, defaultMaxRetries
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2790
|
+
export declare function prepareRetries({ maxRetries, abortSignal, additionalRetryableError, parameter, defaultMaxRetries }: {
|
|
2791
|
+
maxRetries: number | undefined;
|
|
2792
|
+
abortSignal: AbortSignal | undefined;
|
|
2793
|
+
additionalRetryableError?: ShouldRetryFunction;
|
|
2794
|
+
parameter?: string;
|
|
2795
|
+
defaultMaxRetries?: number;
|
|
2769
2796
|
}): {
|
|
2770
|
-
|
|
2771
|
-
|
|
2797
|
+
maxRetries: number;
|
|
2798
|
+
retry: RetryFunction;
|
|
2772
2799
|
};
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2800
|
+
//#endregion
|
|
2801
|
+
//#region src/model/resolve-model.d.ts
|
|
2802
|
+
export declare function resolveLanguageModel(model: LanguageModel): LanguageModelV4;
|
|
2803
|
+
//#endregion
|
|
2804
|
+
//#region src/util/merge-abort-signals.d.ts
|
|
2776
2805
|
/**
|
|
2777
2806
|
* Merges multiple abort sources into a single `AbortSignal`.
|
|
2778
2807
|
* The returned signal will abort when any input signal aborts or when any
|
|
@@ -2783,8 +2812,9 @@ declare function resolveLanguageModel(model: LanguageModel): LanguageModelV4;
|
|
|
2783
2812
|
* @returns An `AbortSignal` that aborts when any valid source aborts,
|
|
2784
2813
|
* or `undefined` if no valid sources are provided.
|
|
2785
2814
|
*/
|
|
2786
|
-
declare function mergeAbortSignals(...signals: (AbortSignal | null | undefined | number)[]): AbortSignal | undefined;
|
|
2787
|
-
|
|
2815
|
+
export declare function mergeAbortSignals(...signals: (AbortSignal | null | undefined | number)[]): AbortSignal | undefined;
|
|
2816
|
+
//#endregion
|
|
2817
|
+
//#region src/util/merge-callbacks.d.ts
|
|
2788
2818
|
/**
|
|
2789
2819
|
* Creates an async callback that invokes the provided callbacks in parallel.
|
|
2790
2820
|
* Undefined callbacks are skipped, and thrown or rejected callback errors are
|
|
@@ -2794,8 +2824,9 @@ declare function mergeAbortSignals(...signals: (AbortSignal | null | undefined |
|
|
|
2794
2824
|
* @returns A callback that forwards each event to all callbacks and waits for
|
|
2795
2825
|
* them to settle.
|
|
2796
2826
|
*/
|
|
2797
|
-
declare function mergeCallbacks<EVENT>(...callbacks: Array<Callback<EVENT> | undefined>): Callback<EVENT>;
|
|
2798
|
-
|
|
2827
|
+
export declare function mergeCallbacks<EVENT>(...callbacks: Array<Callback<EVENT> | undefined>): Callback<EVENT>;
|
|
2828
|
+
//#endregion
|
|
2829
|
+
//#region src/telemetry/create-telemetry-dispatcher.d.ts
|
|
2799
2830
|
/**
|
|
2800
2831
|
* Creates a telemetry dispatcher that sends telemetry events
|
|
2801
2832
|
* to the resolved set of integrations.
|
|
@@ -2809,45 +2840,48 @@ declare function mergeCallbacks<EVENT>(...callbacks: Array<Callback<EVENT> | und
|
|
|
2809
2840
|
* @returns A telemetry dispatcher that fans out lifecycle events to the
|
|
2810
2841
|
* resolved set of integrations.
|
|
2811
2842
|
*/
|
|
2812
|
-
declare function createTelemetryDispatcher({ telemetry
|
|
2813
|
-
|
|
2843
|
+
export declare function createTelemetryDispatcher({ telemetry }: {
|
|
2844
|
+
telemetry?: TelemetryOptions;
|
|
2814
2845
|
}): TelemetryDispatcher;
|
|
2815
|
-
|
|
2846
|
+
//#endregion
|
|
2847
|
+
//#region src/generate-text/restricted-telemetry-dispatcher.d.ts
|
|
2816
2848
|
/**
|
|
2817
2849
|
* Telemetry dispatcher for text generation with callbacks typed to the
|
|
2818
2850
|
* operation-specific tool set, runtime context, and output shape.
|
|
2819
2851
|
*/
|
|
2820
2852
|
type RestrictedTelemetryDispatcher<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context, OUTPUT extends Output> = Omit<TelemetryDispatcher, 'onStart' | 'onStepStart' | 'onStepEnd' | 'onStepFinish' | 'onEnd' | 'onAbort' | 'onToolExecutionStart' | 'onToolExecutionEnd'> & {
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2853
|
+
onStart: GenerateTextOnStartCallback<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
|
|
2854
|
+
onStepStart: GenerateTextOnStepStartCallback<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
|
|
2855
|
+
onStepEnd: GenerateTextOnStepEndCallback<TOOLS, RUNTIME_CONTEXT>;
|
|
2856
|
+
/** @deprecated Use `onStepEnd` instead. */
|
|
2857
|
+
onStepFinish: GenerateTextOnStepFinishCallback<TOOLS, RUNTIME_CONTEXT>;
|
|
2858
|
+
onEnd: GenerateTextOnEndCallback<TOOLS, RUNTIME_CONTEXT>;
|
|
2859
|
+
onAbort?: GenerateTextOnAbortCallback<TOOLS, RUNTIME_CONTEXT>;
|
|
2860
|
+
onToolExecutionStart?: OnToolExecutionStartCallback<TOOLS>;
|
|
2861
|
+
onToolExecutionEnd?: OnToolExecutionEndCallback<TOOLS>;
|
|
2830
2862
|
};
|
|
2831
2863
|
/**
|
|
2832
2864
|
* Creates a telemetry dispatcher that only includes configured runtime context
|
|
2833
2865
|
* properties in text-generation lifecycle events before dispatching them.
|
|
2834
2866
|
*/
|
|
2835
|
-
declare function createRestrictedTelemetryDispatcher<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context, OUTPUT extends Output>({ telemetry, includeRuntimeContext, includeToolsContext
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2867
|
+
export declare function createRestrictedTelemetryDispatcher<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context, OUTPUT extends Output>({ telemetry, includeRuntimeContext, includeToolsContext }: {
|
|
2868
|
+
telemetry?: TelemetryOptions<RUNTIME_CONTEXT, TOOLS>;
|
|
2869
|
+
includeRuntimeContext: IncludedContext<RUNTIME_CONTEXT>;
|
|
2870
|
+
includeToolsContext?: IncludedToolsContext<TOOLS>;
|
|
2839
2871
|
}): RestrictedTelemetryDispatcher<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2872
|
+
//#endregion
|
|
2873
|
+
//#region src/generate-text/parse-tool-call.d.ts
|
|
2874
|
+
export declare function parseToolCall<TOOLS extends ToolSet>({ toolCall, tools, repairToolCall, refineToolInput, messages, instructions, abortSignal }: {
|
|
2875
|
+
toolCall: LanguageModelV4ToolCall;
|
|
2876
|
+
tools: TOOLS | undefined;
|
|
2877
|
+
repairToolCall: ToolCallRepairFunction<TOOLS> | undefined;
|
|
2878
|
+
refineToolInput?: ToolInputRefinement<TOOLS> | undefined;
|
|
2879
|
+
instructions: Instructions | undefined;
|
|
2880
|
+
messages: ModelMessage[];
|
|
2881
|
+
abortSignal?: AbortSignal;
|
|
2849
2882
|
}): Promise<TypedToolCall<TOOLS>>;
|
|
2850
|
-
|
|
2883
|
+
//#endregion
|
|
2884
|
+
//#region src/generate-text/validate-tool-context.d.ts
|
|
2851
2885
|
/**
|
|
2852
2886
|
* Validates a tool context value against the tool's optional context schema.
|
|
2853
2887
|
*
|
|
@@ -2858,82 +2892,88 @@ declare function parseToolCall<TOOLS extends ToolSet>({ toolCall, tools, repairT
|
|
|
2858
2892
|
* @throws {TypeValidationError} When the provided tool context does not match
|
|
2859
2893
|
* the tool's declared `contextSchema`.
|
|
2860
2894
|
*/
|
|
2861
|
-
declare function validateToolContext<CONTEXT>({ toolName, context, contextSchema
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2895
|
+
export declare function validateToolContext<CONTEXT>({ toolName, context, contextSchema }: {
|
|
2896
|
+
toolName: string;
|
|
2897
|
+
context: unknown;
|
|
2898
|
+
contextSchema: FlexibleSchema<CONTEXT> | undefined;
|
|
2865
2899
|
}): Promise<CONTEXT>;
|
|
2866
|
-
|
|
2900
|
+
//#endregion
|
|
2901
|
+
//#region src/tool-search/prepare-tool-search.d.ts
|
|
2867
2902
|
/** Create discovery state for one generation, never for a shared tool instance. */
|
|
2868
|
-
declare function createToolSearchState({ tools, toolCallers
|
|
2869
|
-
|
|
2870
|
-
|
|
2903
|
+
export declare function createToolSearchState({ tools, toolCallers }: {
|
|
2904
|
+
tools: ToolSet | undefined;
|
|
2905
|
+
toolCallers: ResolvedToolCallers | undefined;
|
|
2871
2906
|
}): (activeTools: ToolSet | undefined, options?: {
|
|
2872
|
-
|
|
2873
|
-
|
|
2907
|
+
toolsContext?: InferToolSetContext<ToolSet>;
|
|
2908
|
+
experimental_sandbox?: Experimental_SandboxSession;
|
|
2874
2909
|
}) => ToolSet | undefined;
|
|
2875
|
-
|
|
2910
|
+
//#endregion
|
|
2911
|
+
//#region src/generate-text/collect-tool-approvals.d.ts
|
|
2876
2912
|
type CollectedToolApprovals<TOOLS extends ToolSet> = {
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2913
|
+
approvalRequest: ToolApprovalRequest;
|
|
2914
|
+
approvalResponse: ToolApprovalResponse;
|
|
2915
|
+
toolCall: TypedToolCall<TOOLS>;
|
|
2916
|
+
existingToolResult?: ToolResultPart;
|
|
2881
2917
|
};
|
|
2882
2918
|
/**
|
|
2883
2919
|
* If the last message is a tool message, this function collects all tool approvals
|
|
2884
2920
|
* from that message.
|
|
2885
2921
|
*/
|
|
2886
|
-
declare function collectToolApprovals<TOOLS extends ToolSet>({ messages
|
|
2887
|
-
|
|
2922
|
+
export declare function collectToolApprovals<TOOLS extends ToolSet>({ messages }: {
|
|
2923
|
+
messages: ModelMessage[];
|
|
2888
2924
|
}): {
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
};
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2925
|
+
approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
|
2926
|
+
deniedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
|
2927
|
+
};
|
|
2928
|
+
//#endregion
|
|
2929
|
+
//#region src/generate-text/tool-approval-signature.d.ts
|
|
2930
|
+
export declare function signToolApproval({ secret, approvalId, toolCallId, toolName, input }: {
|
|
2931
|
+
secret: string | Uint8Array;
|
|
2932
|
+
approvalId: string;
|
|
2933
|
+
toolCallId: string;
|
|
2934
|
+
toolName: string;
|
|
2935
|
+
input: unknown;
|
|
2899
2936
|
}): Promise<string>;
|
|
2900
|
-
declare function verifyToolApprovalSignature({ secret, signature, approvalId, toolCallId, toolName, input
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2937
|
+
export declare function verifyToolApprovalSignature({ secret, signature, approvalId, toolCallId, toolName, input }: {
|
|
2938
|
+
secret: string | Uint8Array;
|
|
2939
|
+
signature: string;
|
|
2940
|
+
approvalId: string;
|
|
2941
|
+
toolCallId: string;
|
|
2942
|
+
toolName: string;
|
|
2943
|
+
input: unknown;
|
|
2907
2944
|
}): Promise<boolean>;
|
|
2908
|
-
|
|
2945
|
+
//#endregion
|
|
2946
|
+
//#region src/generate-text/validate-tool-approvals.d.ts
|
|
2909
2947
|
/**
|
|
2910
2948
|
* Re-validates approved tool approvals reconstructed from client-supplied
|
|
2911
2949
|
* message history before they are executed. Checks HMAC signature (when
|
|
2912
2950
|
* configured), input schema, and approval policy.
|
|
2913
2951
|
*/
|
|
2914
|
-
declare function validateApprovedToolApprovals<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context | unknown | never>({ approvedToolApprovals, tools, toolApproval, messages, toolsContext, runtimeContext, toolApprovalSecret, refineToolInput
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2952
|
+
export declare function validateApprovedToolApprovals<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context | unknown | never>({ approvedToolApprovals, tools, toolApproval, messages, toolsContext, runtimeContext, toolApprovalSecret, refineToolInput }: {
|
|
2953
|
+
approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
|
2954
|
+
tools: TOOLS | undefined;
|
|
2955
|
+
toolApproval: ToolApprovalConfiguration<TOOLS, RUNTIME_CONTEXT> | undefined;
|
|
2956
|
+
messages: ModelMessage[];
|
|
2957
|
+
toolsContext: InferToolSetContext<TOOLS>;
|
|
2958
|
+
runtimeContext: RUNTIME_CONTEXT;
|
|
2959
|
+
toolApprovalSecret?: string | Uint8Array;
|
|
2960
|
+
refineToolInput?: ToolInputRefinement<TOOLS>;
|
|
2923
2961
|
}): Promise<{
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2962
|
+
approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
|
2963
|
+
deniedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
|
2964
|
+
invalidToolApprovals: Array<CollectedToolApprovals<TOOLS> & {
|
|
2965
|
+
error: InvalidToolInputError;
|
|
2966
|
+
}>;
|
|
2929
2967
|
}>;
|
|
2930
|
-
|
|
2968
|
+
//#endregion
|
|
2969
|
+
//#region src/generate-text/to-response-messages.d.ts
|
|
2931
2970
|
/**
|
|
2932
2971
|
* Converts the result of a `generateText` or `streamText` call to a list of response messages.
|
|
2933
2972
|
*/
|
|
2934
|
-
declare function toResponseMessages<TOOLS extends ToolSet>({ content: inputContent, tools
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
}): Promise<Array<AssistantModelMessage | ToolModelMessage>>;
|
|
2938
|
-
|
|
2939
|
-
export { type CollectedToolApprovals,
|
|
2973
|
+
export declare function toResponseMessages<TOOLS extends ToolSet>({ content: inputContent, tools }: {
|
|
2974
|
+
content: Array<ContentPart<TOOLS>>;
|
|
2975
|
+
tools: TOOLS | undefined;
|
|
2976
|
+
}): Promise<Array<AssistantModelMessage$1 | ToolModelMessage$1>>;
|
|
2977
|
+
//#endregion
|
|
2978
|
+
export { type CollectedToolApprovals, type DownloadFunction, type ToolsContextSettings, convertAsyncIteratorToReadableStream, prepareLanguageModelCallOptions as prepareCallSettings };
|
|
2979
|
+
//# sourceMappingURL=index.d.ts.map
|