ai 7.0.120 → 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.
Files changed (95) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/index.d.ts +7423 -7247
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +19263 -22470
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +2044 -2004
  7. package/dist/internal/index.d.ts.map +1 -0
  8. package/dist/internal/index.js +3255 -3921
  9. package/dist/internal/index.js.map +1 -1
  10. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  11. package/dist/test/index.d.ts +294 -273
  12. package/dist/test/index.d.ts.map +1 -0
  13. package/dist/test/index.js +325 -469
  14. package/dist/test/index.js.map +1 -1
  15. package/docs/02-foundations/03-prompts.mdx +3 -1
  16. package/docs/02-foundations/06-provider-options.mdx +1 -1
  17. package/docs/02-getting-started/06-nodejs.mdx +4 -4
  18. package/docs/02-getting-started/08-tanstack-start.mdx +1 -1
  19. package/docs/03-agents/05-configuring-call-options.mdx +1 -1
  20. package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +1 -1
  21. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +3 -0
  22. package/docs/03-ai-sdk-core/17-mcp-apps.mdx +5 -5
  23. package/docs/03-ai-sdk-core/37-speech.mdx +1 -1
  24. package/docs/03-ai-sdk-core/42-batch.mdx +1 -1
  25. package/docs/03-ai-sdk-core/60-telemetry.mdx +2 -2
  26. package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +24 -0
  27. package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +12 -12
  28. package/docs/04-ai-sdk-ui/02-chatbot.mdx +9 -0
  29. package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +17 -7
  30. package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +12 -5
  31. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +17 -10
  32. package/docs/04-ai-sdk-ui/05-completion.mdx +1 -1
  33. package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +2 -2
  34. package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +8 -7
  35. package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +1 -1
  36. package/docs/05-ai-sdk-rsc/06-loading-state.mdx +19 -10
  37. package/docs/05-ai-sdk-rsc/08-error-handling.mdx +2 -0
  38. package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +4 -3
  39. package/docs/06-advanced/02-stopping-streams.mdx +2 -2
  40. package/docs/06-advanced/04-caching.mdx +9 -5
  41. package/docs/06-advanced/05-multiple-streamables.mdx +1 -1
  42. package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +16 -16
  43. package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
  44. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +4 -4
  45. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +5 -5
  46. package/docs/07-reference/01-ai-sdk-core/14-upload-file.mdx +4 -4
  47. package/docs/07-reference/01-ai-sdk-core/14-upload-skill.mdx +1 -1
  48. package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +1 -1
  49. package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +1 -4
  50. package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +1 -1
  51. package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +1 -1
  52. package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +2 -2
  53. package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +1 -1
  54. package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +1 -1
  55. package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +5 -4
  56. package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +3 -2
  57. package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +7 -0
  58. package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +7 -0
  59. package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +2 -2
  60. package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +2 -2
  61. package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +1 -1
  62. package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +4 -5
  63. package/docs/08-migration-guides/26-migration-guide-5-0.mdx +2 -1
  64. package/docs/08-migration-guides/29-migration-guide-4-0.mdx +9 -9
  65. package/docs/08-migration-guides/37-migration-guide-3-3.mdx +1 -1
  66. package/docs/08-migration-guides/38-migration-guide-3-2.mdx +1 -1
  67. package/docs/08-migration-guides/39-migration-guide-3-1.mdx +1 -1
  68. package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +8 -6
  69. package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +6 -6
  70. package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +1 -1
  71. package/package.json +17 -17
  72. package/src/agent/create-agent-ui-stream-response.ts +3 -0
  73. package/src/agent/pipe-agent-ui-stream-to-response.ts +3 -0
  74. package/src/embed/embed-many.ts +5 -3
  75. package/src/generate-image/generate-image.ts +8 -3
  76. package/src/generate-text/prune-messages.ts +1 -1
  77. package/src/generate-text/smooth-stream.ts +24 -9
  78. package/src/generate-text/stream-text-result.ts +5 -0
  79. package/src/generate-video/generate-video.ts +6 -4
  80. package/src/middleware/extract-reasoning-middleware.ts +27 -11
  81. package/src/registry/provider-registry.ts +1 -1
  82. package/src/ui/chat.ts +13 -4
  83. package/src/ui/convert-to-model-messages.ts +18 -6
  84. package/src/ui/http-chat-transport.ts +19 -3
  85. package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +15 -3
  86. package/src/ui/process-ui-message-stream.ts +51 -14
  87. package/src/ui/ui-messages.ts +14 -0
  88. package/src/ui/validate-ui-messages.ts +2 -0
  89. package/src/ui-message-stream/create-sse-stream-with-keep-alive.ts +89 -0
  90. package/src/ui-message-stream/create-ui-message-stream-response.ts +7 -1
  91. package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +7 -1
  92. package/src/ui-message-stream/to-ui-message-chunk.ts +9 -1
  93. package/src/ui-message-stream/to-ui-message-stream.ts +1 -1
  94. package/src/ui-message-stream/ui-message-stream-response-init.ts +7 -0
  95. package/src/util/set-own.ts +16 -0
@@ -1,54 +1,51 @@
1
- import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { EmbeddingModelV4Embedding, LanguageModelV4Source, SharedV4Warning, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4ProviderMetadata, JSONObject, LanguageModelV4Usage, Experimental_EvaluationModelV4Question, Experimental_EvaluationModelV4Result, Experimental_EvaluationModelV4CallOptions, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, LanguageModelV4ToolResultOutput, LanguageModelV4ToolChoice, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool } from '@ai-sdk/provider';
3
- import { GatewayModelId } from '@ai-sdk/gateway';
4
- import { ModelMessage, AssistantModelMessage, ToolModelMessage, Context, ProviderOptions, ToolSet, SystemModelMessage, InferToolSetContext, Arrayable, InferToolInput, InferToolOutput, ReasoningPart, ReasoningFilePart, MaybePromiseLike, ToolExecutionOptions, InferToolContext, HasRequiredKey, ToolResultOutput, Tool, Experimental_SandboxSession, ShouldRetryFunction, RetryFunction, FlexibleSchema, ToolApprovalRequest, ToolApprovalResponse, ToolResultPart } from '@ai-sdk/provider-utils';
5
- export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';
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
- * 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 {
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
- type: 'tool';
87
- toolName: Extract<keyof TOOLS, string>;
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
- * The input messages that were sent to the model for this step.
96
- */
97
- readonly messages?: Array<ModelMessage>;
98
- /**
99
- * Request HTTP body that was sent to the provider API.
100
- */
101
- readonly body?: unknown;
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
- * 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
-
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 total number of input (prompt) tokens used.
165
+ * The number of non-cached input (prompt) tokens used.
156
166
  */
157
- inputTokens: number | undefined;
167
+ noCacheTokens: number | undefined;
158
168
  /**
159
- * Detailed information about the input tokens.
169
+ * The number of cached input (prompt) tokens read.
160
170
  */
161
- inputTokenDetails: {
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 total output (completion) tokens used.
173
+ * The number of cached input (prompt) tokens written.
177
174
  */
178
- outputTokens: number | undefined;
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
- * Detailed information about the output tokens.
186
+ * The number of text tokens used.
181
187
  */
182
- outputTokenDetails: {
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
- * Raw usage information from the provider.
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
- raw?: JSONObject;
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
- * The number of tokens used in the embedding.
210
- */
211
- tokens: number;
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
- * The warnings returned by the model provider.
238
- */
239
- warnings: Warning[];
240
- /**
241
- * The provider id used for the call, if scoped to a specific provider.
242
- */
243
- provider?: string;
244
- /**
245
- * The model id used for the call, if scoped to a specific provider.
246
- */
247
- model?: string;
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
- /** User-defined runtime context. */
257
- readonly runtimeContext: RUNTIME_CONTEXT;
258
- /** Unique identifier for this embed call, used to correlate events. */
259
- readonly callId: string;
260
- /** Identifies the operation type (e.g. 'ai.embed' or 'ai.embedMany'). */
261
- readonly operationId: string;
262
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
263
- readonly provider: string;
264
- /** The specific model identifier (e.g., 'text-embedding-3-small'). */
265
- readonly modelId: string;
266
- /** The value(s) being embedded. A string for embed, an array for embedMany. */
267
- readonly value: string | Array<string>;
268
- /** Maximum number of retries for failed requests. */
269
- readonly maxRetries: number;
270
- /** Additional HTTP headers sent with the request. */
271
- readonly headers: Record<string, string | undefined> | undefined;
272
- /** Additional provider-specific options. */
273
- readonly providerOptions: ProviderOptions | undefined;
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
- /** User-defined runtime context. */
282
- readonly runtimeContext: RUNTIME_CONTEXT;
283
- /** Unique identifier for this embed call, used to correlate events. */
284
- readonly callId: string;
285
- /** Identifies the operation type (e.g. 'ai.embed' or 'ai.embedMany'). */
286
- readonly operationId: string;
287
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
288
- readonly provider: string;
289
- /** The specific model identifier (e.g., 'text-embedding-3-small'). */
290
- readonly modelId: string;
291
- /** The value(s) that were embedded. A string for embed, an array for embedMany. */
292
- readonly value: string | Array<string>;
293
- /** The resulting embedding(s). A single vector for embed, an array for embedMany. */
294
- readonly embedding: Embedding | Array<Embedding>;
295
- /** Token usage for the embedding operation. */
296
- readonly usage: EmbeddingModelUsage;
297
- /** Warnings from the embedding model, e.g. unsupported settings. */
298
- readonly warnings: Array<Warning>;
299
- /** Optional provider-specific metadata. */
300
- readonly providerMetadata: ProviderMetadata | undefined;
301
- /** Response data including headers and body. A single response for embed, an array for embedMany. */
302
- readonly response: {
303
- headers?: Record<string, string>;
304
- body?: unknown;
305
- } | Array<{
306
- headers?: Record<string, string>;
307
- body?: unknown;
308
- } | undefined> | undefined;
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
- /** Unique identifier for this embed call, used to correlate events. */
318
- readonly callId: string;
319
- /** Unique identifier for this individual doEmbed invocation, used to correlate start/finish within parallel chunks. */
320
- readonly embedCallId: string;
321
- /** Identifies the inner operation (e.g. 'ai.embed.doEmbed' or 'ai.embedMany.doEmbed'). */
322
- readonly operationId: string;
323
- /** The provider identifier. */
324
- readonly provider: string;
325
- /** The specific model identifier. */
326
- readonly modelId: string;
327
- /** The values being embedded in this particular model call. */
328
- readonly values: Array<string>;
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
- /** Unique identifier for this embed call, used to correlate events. */
337
- readonly callId: string;
338
- /** Unique identifier for this individual doEmbed invocation, used to correlate start/finish within parallel chunks. */
339
- readonly embedCallId: string;
340
- /** Identifies the inner operation (e.g. 'ai.embed.doEmbed' or 'ai.embedMany.doEmbed'). */
341
- readonly operationId: string;
342
- /** The provider identifier. */
343
- readonly provider: string;
344
- /** The specific model identifier. */
345
- readonly modelId: string;
346
- /** The values that were embedded in this particular model call. */
347
- readonly values: Array<string>;
348
- /** The resulting embeddings from the model call. */
349
- readonly embeddings: Array<Embedding>;
350
- /** Token usage for this model call. */
351
- readonly usage: EmbeddingModelUsage;
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
- type: 'choice';
357
- criteria: infer CRITERIA;
362
+ type: 'choice';
363
+ criteria: infer CRITERIA;
358
364
  } ? {
359
- type: 'choice';
360
- choice: Extract<keyof CRITERIA, string>;
361
- probabilities?: Record<Extract<keyof CRITERIA, string>, number>;
365
+ type: 'choice';
366
+ choice: Extract<keyof CRITERIA, string>;
367
+ probabilities?: Record<Extract<keyof CRITERIA, string>, number>;
362
368
  } : QUESTION extends {
363
- type: 'score';
369
+ type: 'score';
364
370
  } ? {
365
- type: 'score';
366
- score: number;
367
- probabilities?: Record<string, number>;
371
+ type: 'score';
372
+ score: number;
373
+ probabilities?: Record<string, number>;
368
374
  } : {
369
- type: 'boolean';
370
- probability: number;
375
+ type: 'boolean';
376
+ probability: number;
371
377
  };
372
378
  type EvaluationResult<QUESTIONS extends Record<string, EvaluationQuestion>> = {
373
- readonly answers: {
374
- [ID in keyof QUESTIONS]: EvaluationAnswer<QUESTIONS[ID]>;
375
- };
376
- readonly usage: {
377
- inputTokens: number | undefined;
378
- outputTokens: number | undefined;
379
- totalTokens: number | undefined;
380
- };
381
- readonly warnings: Experimental_EvaluationModelV4Result['warnings'];
382
- readonly rounding: Experimental_EvaluationModelV4Result['rounding'];
383
- readonly providerMetadata: Experimental_EvaluationModelV4Result['providerMetadata'];
384
- readonly response: NonNullable<Experimental_EvaluationModelV4Result['response']> & {
385
- timestamp: Date;
386
- modelId: string;
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
- /** User-defined runtime context. */
397
- readonly runtimeContext: RUNTIME_CONTEXT;
398
- /** Unique identifier for this evaluation call, used to correlate events. */
399
- readonly callId: string;
400
- /** Identifies the operation type (`ai.evaluate`). */
401
- readonly operationId: 'ai.evaluate';
402
- /** The provider identifier. */
403
- readonly provider: string;
404
- /** The evaluation model identifier. */
405
- readonly modelId: string;
406
- /** The shared state being evaluated. */
407
- readonly state: Experimental_EvaluationModelV4CallOptions['state'];
408
- /** The questions being evaluated against the shared state. */
409
- readonly questions: Readonly<Record<string, EvaluationQuestion>>;
410
- /** Maximum number of retries for the evaluation model call. */
411
- readonly maxRetries: number;
412
- /** Additional HTTP headers sent with the request. */
413
- readonly headers: Record<string, string> | undefined;
414
- /** Additional provider-specific options. */
415
- readonly providerOptions: ProviderOptions;
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
- /** Exactly one typed answer per question ID. */
424
- readonly answers: EvaluationResult<Record<string, EvaluationQuestion>>['answers'];
425
- /** Token usage for the evaluation operation. */
426
- readonly usage: EvaluationResult<Record<string, EvaluationQuestion>>['usage'];
427
- /** Warnings from the evaluation model. */
428
- readonly warnings: EvaluationResult<Record<string, EvaluationQuestion>>['warnings'];
429
- /** Provider-declared decimal precision for probabilities and scores. */
430
- readonly rounding: EvaluationResult<Record<string, EvaluationQuestion>>['rounding'];
431
- /** Optional provider-specific metadata. */
432
- readonly providerMetadata: EvaluationResult<Record<string, EvaluationQuestion>>['providerMetadata'];
433
- /** Response metadata, including the resolved model ID and timestamp. */
434
- readonly response: EvaluationResult<Record<string, EvaluationQuestion>>['response'];
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
- /** Unique identifier for the outer evaluation call. */
443
- readonly callId: string;
444
- /** Identifies the inner operation (`ai.evaluate.doEvaluate`). */
445
- readonly operationId: 'ai.evaluate.doEvaluate';
446
- /** The provider identifier. */
447
- readonly provider: string;
448
- /** The evaluation model identifier. */
449
- readonly modelId: string;
450
- /** The shared state being evaluated. */
451
- readonly state: Experimental_EvaluationModelV4CallOptions['state'];
452
- /** The questions being evaluated against the shared state. */
453
- readonly questions: Readonly<Record<string, EvaluationQuestion>>;
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
- /** Exactly one answer per question ID. */
462
- readonly answers: Experimental_EvaluationModelV4Result['answers'];
463
- /** Token usage reported by the evaluation model. */
464
- readonly usage?: Experimental_EvaluationModelV4Result['usage'];
465
- /** Warnings from the evaluation model. */
466
- readonly warnings: Experimental_EvaluationModelV4Result['warnings'];
467
- /** Provider-declared decimal precision for probabilities and scores. */
468
- readonly rounding?: Experimental_EvaluationModelV4Result['rounding'];
469
- /** Optional provider-specific metadata. */
470
- readonly providerMetadata?: Experimental_EvaluationModelV4Result['providerMetadata'];
471
- /** Optional raw response metadata from the provider. */
472
- readonly response?: Experimental_EvaluationModelV4Result['response'];
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
- * Maximum number of tokens to generate.
483
- */
484
- maxOutputTokens?: number;
485
- /**
486
- * Temperature setting. The range depends on the provider and model.
487
- *
488
- * It is recommended to set either `temperature` or `topP`, but not both.
489
- */
490
- temperature?: number;
491
- /**
492
- * Nucleus sampling. This is a number between 0 and 1.
493
- *
494
- * E.g. 0.1 would mean that only tokens with the top 10% probability mass
495
- * are considered.
496
- *
497
- * It is recommended to set either `temperature` or `topP`, but not both.
498
- */
499
- topP?: number;
500
- /**
501
- * Only sample from the top K options for each subsequent token.
502
- *
503
- * Used to remove "long tail" low probability responses.
504
- * Recommended for advanced use cases only. You usually only need to use temperature.
505
- */
506
- topK?: number;
507
- /**
508
- * Presence penalty setting. It affects the likelihood of the model to
509
- * repeat information that is already in the prompt.
510
- *
511
- * The presence penalty is a number between -1 (increase repetition)
512
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
513
- */
514
- presencePenalty?: number;
515
- /**
516
- * Frequency penalty setting. It affects the likelihood of the model
517
- * to repeatedly use the same words or phrases.
518
- *
519
- * The frequency penalty is a number between -1 (increase repetition)
520
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
521
- */
522
- frequencyPenalty?: number;
523
- /**
524
- * Stop sequences.
525
- * If set, the model will stop generating text when one of the stop sequences is generated.
526
- * Providers may have limits on the number of stop sequences.
527
- */
528
- stopSequences?: string[];
529
- /**
530
- * The seed (integer) to use for random sampling. If set and supported
531
- * by the model, calls will generate deterministic results.
532
- */
533
- seed?: number;
534
- /**
535
- * Reasoning effort level for the model. Controls how much reasoning
536
- * the model performs before generating a response.
537
- *
538
- * Use `'provider-default'` to use the provider's default reasoning level.
539
- * Use `'none'` to disable reasoning (if supported by the provider).
540
- */
541
- reasoning?: LanguageModelV4CallOptions['reasoning'];
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
- totalMs?: number;
556
- stepMs?: number;
557
- firstChunkMs?: number;
558
- chunkMs?: number;
559
- toolMs?: number;
560
- tools?: Partial<Record<`${keyof TOOLS & string}Ms`, number>>;
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
- * Instructions to include in the prompt. Can be used with `prompt` or `messages`.
574
- */
575
- instructions?: Instructions;
576
- /**
577
- * Instructions to include in the prompt. Can be used with `prompt` or `messages`.
578
- *
579
- * @deprecated Use `instructions` instead.
580
- */
581
- system?: Instructions;
582
- /**
583
- * Whether system messages are allowed in the `prompt` or `messages` fields.
584
- *
585
- * When disabled, system messages must be provided through the `instructions`
586
- * option.
587
- *
588
- * @default false
589
- */
590
- allowSystemInMessages?: boolean;
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
- * A prompt. It can be either a text prompt or a list of messages.
594
- *
595
- * You can either use `prompt` or `messages` but not both.
596
- */
597
- prompt: string | Array<ModelMessage>;
598
- /**
599
- * A list of messages.
600
- *
601
- * You can either use `prompt` or `messages` but not both.
602
- */
603
- messages?: never;
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
- * A list of messages.
607
- *
608
- * You can either use `prompt` or `messages` but not both.
609
- */
610
- messages: Array<ModelMessage>;
611
- /**
612
- * A prompt. It can be either a text prompt or a list of messages.
613
- *
614
- * You can either use `prompt` or `messages` but not both.
615
- */
616
- prompt?: never;
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
- /** Unique identifier for this generation call, used to correlate events. */
629
- readonly callId: string;
630
- /** Identifies the operation type (e.g. `'ai.generateObject'` or `'ai.streamObject'`). */
631
- readonly operationId: string;
632
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
633
- readonly provider: string;
634
- /** The specific model identifier (e.g., 'gpt-4o'). */
635
- readonly modelId: string;
636
- /** The system message(s) provided to the model. */
637
- readonly system: Instructions | undefined;
638
- /** The prompt string or array of messages if using the prompt option. */
639
- readonly prompt: string | Array<ModelMessage> | undefined;
640
- /** The messages array if using the messages option. */
641
- readonly messages: Array<ModelMessage> | undefined;
642
- /** Maximum number of tokens to generate. */
643
- readonly maxOutputTokens: number | undefined;
644
- /** Sampling temperature for generation. */
645
- readonly temperature: number | undefined;
646
- /** Top-p (nucleus) sampling parameter. */
647
- readonly topP: number | undefined;
648
- /** Top-k sampling parameter. */
649
- readonly topK: number | undefined;
650
- /** Presence penalty for generation. */
651
- readonly presencePenalty: number | undefined;
652
- /** Frequency penalty for generation. */
653
- readonly frequencyPenalty: number | undefined;
654
- /** Random seed for reproducible generation. */
655
- readonly seed: number | undefined;
656
- /** Maximum number of retries for failed requests. */
657
- readonly maxRetries: number;
658
- /** Additional HTTP headers sent with the request. */
659
- readonly headers: Record<string, string | undefined> | undefined;
660
- /** Additional provider-specific options. */
661
- readonly providerOptions: ProviderOptions | undefined;
662
- /** The output strategy type. */
663
- readonly output: 'object' | 'array' | 'enum' | 'no-schema';
664
- /** The JSON Schema used for object generation, if any. */
665
- readonly schema: Record<string, unknown> | undefined;
666
- /** Optional name of the schema. */
667
- readonly schemaName: string | undefined;
668
- /** Optional description of the schema. */
669
- readonly schemaDescription: string | undefined;
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
- /** Unique identifier for this generation call, used to correlate events. */
682
- readonly callId: string;
683
- /** Zero-based index of the current step. Always `0` for object generation. */
684
- readonly stepNumber: 0;
685
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
686
- readonly provider: string;
687
- /** The specific model identifier (e.g., 'gpt-4o'). */
688
- readonly modelId: string;
689
- /** Additional provider-specific options. */
690
- readonly providerOptions: ProviderOptions | undefined;
691
- /** Additional HTTP headers sent with the request. */
692
- readonly headers: Record<string, string | undefined> | undefined;
693
- /** The prompt messages in provider format (for telemetry). */
694
- readonly promptMessages?: LanguageModelV4Prompt;
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
- /** Unique identifier for this generation call, used to correlate events. */
707
- readonly callId: string;
708
- /** Zero-based index of the current step. Always `0` for object generation. */
709
- readonly stepNumber: 0;
710
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
711
- readonly provider: string;
712
- /** The specific model identifier (e.g., 'gpt-4o'). */
713
- readonly modelId: string;
714
- /** The unified reason why the generation finished. */
715
- readonly finishReason: FinishReason;
716
- /** The token usage of the generated response. */
717
- readonly usage: LanguageModelUsage;
718
- /** The raw text output from the model (before JSON parsing). */
719
- readonly objectText: string;
720
- /** The reasoning generated by the model, if any. */
721
- readonly reasoning: string | undefined;
722
- /** Warnings from the model provider (e.g. unsupported settings). */
723
- readonly warnings: CallWarning[] | undefined;
724
- /** Additional request information. */
725
- readonly request: Omit<LanguageModelRequestMetadata, 'messages'>;
726
- /** Additional response information. */
727
- readonly response: Omit<LanguageModelResponseMetadata, 'messages'>;
728
- /** Additional provider-specific metadata. */
729
- readonly providerMetadata: ProviderMetadata | undefined;
730
- /** Milliseconds from the start of the stream to the first chunk (streaming only). */
731
- readonly msToFirstChunk: number | undefined;
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
- /** Unique identifier for this generation call, used to correlate events. */
745
- readonly callId: string;
746
- /**
747
- * The generated object (typed according to the schema).
748
- * Always defined for `generateObject`. May be `undefined` for `streamObject`
749
- * when parsing or validation fails.
750
- */
751
- readonly object: RESULT | undefined;
752
- /**
753
- * Error from parsing or schema validation, if any.
754
- * Always `undefined` for `generateObject` (which throws instead).
755
- */
756
- readonly error: unknown | undefined;
757
- /** The reasoning generated by the model, if any. */
758
- readonly reasoning: string | undefined;
759
- /** The unified reason why the generation finished. */
760
- readonly finishReason: FinishReason;
761
- /** The token usage of the generated response. */
762
- readonly usage: LanguageModelUsage;
763
- /** Warnings from the model provider (e.g. unsupported settings). */
764
- readonly warnings: CallWarning[] | undefined;
765
- /** Additional request information. */
766
- readonly request: Omit<LanguageModelRequestMetadata, 'messages'>;
767
- /** Additional response information. */
768
- readonly response: Omit<LanguageModelResponseMetadata, 'messages'>;
769
- /** Additional provider-specific metadata. */
770
- readonly providerMetadata: ProviderMetadata | undefined;
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
- * Instructions.
776
- */
777
- instructions: Instructions | undefined;
778
- /**
779
- * Messages.
780
- */
781
- messages: ModelMessage[];
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, }: Prompt): Promise<StandardizedPrompt>;
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
- type IncludedContext<CONTEXT extends Context | unknown | never> = {
811
- [KEY in keyof NoInfer<CONTEXT>]?: boolean;
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
- * Enable or disable telemetry. Enabled by default when a telemetry
822
- * integration is registered. Set to `false` to opt out.
823
- */
824
- isEnabled?: boolean;
825
- /**
826
- * Enable or disable input recording. Enabled by default.
827
- *
828
- * You might want to disable input recording to avoid recording sensitive
829
- * information, to reduce data transfers, or to increase performance.
830
- */
831
- recordInputs?: boolean;
832
- /**
833
- * Enable or disable output recording. Enabled by default.
834
- *
835
- * You might want to disable output recording to avoid recording sensitive
836
- * information, to reduce data transfers, or to increase performance.
837
- */
838
- recordOutputs?: boolean;
839
- /**
840
- * Identifier for this function. Used to group telemetry data by function.
841
- */
842
- functionId?: string;
843
- /**
844
- * Top-level runtime context properties that should be included in telemetry.
845
- * Runtime context properties are excluded unless they are explicitly set to `true`.
846
- */
847
- includeRuntimeContext?: IncludedContext<RUNTIME_CONTEXT>;
848
- /**
849
- * Top-level tool context properties that should be included in telemetry,
850
- * configured per tool.
851
- *
852
- * Tool context properties are excluded unless they are explicitly set to `true`.
853
- */
854
- includeToolsContext?: IncludedToolsContext<TOOLS>;
855
- /**
856
- * Per-call telemetry integrations that receive lifecycle events during generation.
857
- *
858
- * When provided, these integrations will take precedence over the globally registered
859
- * integrations for this call.
860
- */
861
- integrations?: Arrayable<Telemetry>;
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
- url: URL;
876
- maxBytes?: number;
877
- abortSignal?: AbortSignal;
884
+ declare const download$1: ({ url, maxBytes, abortSignal }: {
885
+ url: URL;
886
+ maxBytes?: number;
887
+ abortSignal?: AbortSignal;
878
888
  }) => Promise<{
879
- data: Uint8Array<ArrayBufferLike>;
880
- mediaType: string | undefined;
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
- url: URL;
902
- isUrlSupportedByModel: boolean;
912
+ url: URL;
913
+ isUrlSupportedByModel: boolean;
903
914
  }>) => PromiseLike<Array<{
904
- data: Uint8Array;
905
- mediaType: string | undefined;
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
- * File as a base64 encoded string.
919
- */
920
- readonly base64: string;
921
- /**
922
- * File as a Uint8Array.
923
- */
924
- readonly uint8Array: Uint8Array;
925
- /**
926
- * The IANA media type of the file.
927
- *
928
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
929
- */
930
- readonly mediaType: string;
931
- /**
932
- * Provider-specific metadata for this file.
933
- */
934
- readonly providerMetadata?: Record<string, JSONObject>;
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
- type: 'reasoning';
942
- /**
943
- * The reasoning text.
944
- */
945
- text: string;
946
- /**
947
- * Additional provider-specific metadata. They are passed through
948
- * to the provider from the AI SDK and enable provider-specific
949
- * functionality that can be fully encapsulated in the provider.
950
- */
951
- providerMetadata?: ProviderMetadata;
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
- type: 'reasoning-file';
959
- /**
960
- * The generated file.
961
- */
962
- file: GeneratedFile;
963
- /**
964
- * Additional provider-specific metadata. They are passed through
965
- * to the provider from the AI SDK and enable provider-specific
966
- * functionality that can be fully encapsulated in the provider.
967
- */
968
- providerMetadata?: ProviderMetadata;
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
- type: 'tool-call';
1015
- toolCallId: string;
1016
- providerExecuted?: boolean;
1017
- providerMetadata?: ProviderMetadata;
1018
- toolMetadata?: JSONObject;
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
- [NAME in keyof TOOLS]: BaseToolCall & {
1026
- toolName: NAME & string;
1027
- input: InferToolInput<TOOLS[NAME]>;
1028
- dynamic?: false | undefined;
1029
- invalid?: false | undefined;
1030
- error?: never;
1031
- title?: string;
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
- toolName: string;
1040
- input: unknown;
1041
- dynamic: true;
1042
- title?: string;
1043
- /**
1044
- * True if this is caused by an unparsable tool call or
1045
- * a tool that does not exist.
1046
- */
1047
- invalid?: boolean;
1048
- /**
1049
- * The error that caused the tool call to be invalid.
1050
- */
1051
- error?: unknown;
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
- type: 'tool-approval-request';
1066
- /**
1067
- * ID of the tool approval request.
1068
- */
1069
- approvalId: string;
1070
- /**
1071
- * Tool call that the approval request is for.
1072
- */
1073
- toolCall: TypedToolCall<TOOLS>;
1074
- /**
1075
- * Reason why the tool call requires approval.
1076
- */
1077
- reason?: string;
1078
- /**
1079
- * Flag indicating whether the tool was automatically approved or denied.
1080
- *
1081
- * @default false
1082
- */
1083
- isAutomatic?: boolean;
1084
- /**
1085
- * HMAC-SHA256 signature binding this approval request to its tool call.
1086
- */
1087
- signature?: string;
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
- type: 'tool-approval-response';
1095
- /**
1096
- * ID of the tool approval.
1097
- */
1098
- approvalId: string;
1099
- /**
1100
- * Tool call that the approval response is for.
1101
- */
1102
- toolCall: TypedToolCall<TOOLS>;
1103
- /**
1104
- * Flag indicating whether the approval was granted or denied.
1105
- */
1106
- approved: boolean;
1107
- /**
1108
- * Optional reason for the approval or denial.
1109
- */
1110
- reason?: string;
1111
- /**
1112
- * Flag indicating whether the tool call is provider-executed.
1113
- * Only provider-executed tool approval responses should be sent to the model.
1114
- */
1115
- providerExecuted?: boolean;
1116
- };
1117
-
1118
- type StaticToolError<TOOLS extends ToolSet> = ValueOf<{
1119
- [NAME in keyof TOOLS]: {
1120
- type: 'tool-error';
1121
- toolCallId: string;
1122
- toolName: NAME & string;
1123
- input: InferToolInput<TOOLS[NAME]>;
1124
- error: unknown;
1125
- providerExecuted?: boolean;
1126
- providerMetadata?: ProviderMetadata;
1127
- toolMetadata?: JSONObject;
1128
- dynamic?: false | undefined;
1129
- title?: string;
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
- type: 'tool-error';
1134
- toolCallId: string;
1135
- toolName: string;
1136
- input: unknown;
1137
- error: unknown;
1138
- providerExecuted?: boolean;
1139
- providerMetadata?: ProviderMetadata;
1140
- toolMetadata?: JSONObject;
1141
- dynamic: true;
1142
- title?: string;
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
- type StaticToolResult<TOOLS extends ToolSet> = ValueOf<{
1147
- [NAME in keyof TOOLS]: {
1148
- type: 'tool-result';
1149
- toolCallId: string;
1150
- toolName: NAME & string;
1151
- input: InferToolInput<TOOLS[NAME]>;
1152
- output: InferToolOutput<TOOLS[NAME]>;
1153
- providerExecuted?: boolean;
1154
- providerMetadata?: ProviderMetadata;
1155
- toolMetadata?: JSONObject;
1156
- dynamic?: false | undefined;
1157
- preliminary?: boolean;
1158
- title?: string;
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
- type: 'tool-result';
1163
- toolCallId: string;
1164
- toolName: string;
1165
- input: unknown;
1166
- output: unknown;
1167
- providerExecuted?: boolean;
1168
- providerMetadata?: ProviderMetadata;
1169
- toolMetadata?: JSONObject;
1170
- dynamic: true;
1171
- preliminary?: boolean;
1172
- title?: string;
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
- type: 'text';
1178
- text: string;
1179
- providerMetadata?: ProviderMetadata;
1191
+ type: 'text';
1192
+ text: string;
1193
+ providerMetadata?: ProviderMetadata;
1180
1194
  } | {
1181
- type: 'custom';
1182
- kind: `${string}.${string}`;
1183
- providerMetadata?: ProviderMetadata;
1195
+ type: 'custom';
1196
+ kind: `${string}.${string}`;
1197
+ providerMetadata?: ProviderMetadata;
1184
1198
  } | ReasoningOutput | ReasoningFileOutput | ({
1185
- type: 'source';
1199
+ type: 'source';
1186
1200
  } & Source) | {
1187
- type: 'file';
1188
- file: GeneratedFile;
1189
- providerMetadata?: ProviderMetadata;
1201
+ type: 'file';
1202
+ file: GeneratedFile;
1203
+ providerMetadata?: ProviderMetadata;
1190
1204
  } | ({
1191
- type: 'tool-call';
1205
+ type: 'tool-call';
1192
1206
  } & TypedToolCall<TOOLS> & {
1193
- providerMetadata?: ProviderMetadata;
1207
+ providerMetadata?: ProviderMetadata;
1194
1208
  }) | ({
1195
- type: 'tool-result';
1209
+ type: 'tool-result';
1196
1210
  } & TypedToolResult<TOOLS> & {
1197
- providerMetadata?: ProviderMetadata;
1211
+ providerMetadata?: ProviderMetadata;
1198
1212
  }) | ({
1199
- type: 'tool-error';
1213
+ type: 'tool-error';
1200
1214
  } & TypedToolError<TOOLS> & {
1201
- providerMetadata?: ProviderMetadata;
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
- /** Shortest observed time between output chunks in milliseconds. */
1209
- readonly min: number;
1210
- /** 10th percentile time between output chunks in milliseconds. */
1211
- readonly p10: number;
1212
- /** Median time between output chunks in milliseconds. */
1213
- readonly median: number;
1214
- /** Average time between output chunks in milliseconds. */
1215
- readonly avg: number;
1216
- /** 90th percentile time between output chunks in milliseconds. */
1217
- readonly p90: number;
1218
- /** Longest observed time between output chunks in milliseconds. */
1219
- readonly max: number;
1220
- };
1221
- /**
1222
- * Performance metrics for a single step in the generation process.
1223
- */
1224
- type StepResultPerformance = {
1225
- /**
1226
- * Effective number of output tokens per second over the full language model
1227
- * response.
1228
- *
1229
- * Calculated as `outputTokens / requestSeconds`.
1230
- */
1231
- readonly effectiveOutputTokensPerSecond: number;
1232
- /**
1233
- * Number of output tokens per second after the first generated output chunk
1234
- * was received.
1235
- *
1236
- * Only available for streaming steps.
1237
- *
1238
- * Calculated as `outputTokens / outputStreamSeconds`.
1239
- */
1240
- readonly outputTokensPerSecond: number | undefined;
1241
- /**
1242
- * Number of input tokens processed per second before the first generated
1243
- * output chunk was received.
1244
- *
1245
- * Only available for streaming steps.
1246
- *
1247
- * Calculated as `inputTokens / ttftSeconds`.
1248
- */
1249
- readonly inputTokensPerSecond: number | undefined;
1250
- /**
1251
- * Effective number of input and output tokens per second over the full
1252
- * language model response.
1253
- *
1254
- * Calculated as `(inputTokens + outputTokens) / requestSeconds`.
1255
- */
1256
- readonly effectiveTotalTokensPerSecond: number;
1257
- /**
1258
- * Total time spent on the step in milliseconds.
1259
- */
1260
- readonly stepTimeMs: number;
1261
- /**
1262
- * Time spent waiting for the language model response in milliseconds.
1263
- */
1264
- readonly responseTimeMs: number;
1265
- /**
1266
- * Time spent executing each client-side tool call in milliseconds, keyed by
1267
- * tool call ID.
1268
- */
1269
- readonly toolExecutionMs: Readonly<Record<string, number>>;
1270
- /**
1271
- * Time until the first generated output chunk was received in milliseconds.
1272
- *
1273
- * This includes text deltas, reasoning deltas, generated files, reasoning
1274
- * files, tool input deltas, and tool calls.
1275
- *
1276
- * Only available for streaming steps.
1277
- */
1278
- readonly timeToFirstOutputMs: number | undefined;
1279
- /**
1280
- * Timing statistics for the gaps between generated output chunks in
1281
- * milliseconds.
1282
- *
1283
- * Only available for streaming steps with at least two generated output
1284
- * chunks.
1285
- */
1286
- readonly timeBetweenOutputChunksMs?: OutputChunkTimingStats;
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
- * Unique identifier for the generation call this step belongs to.
1294
- */
1295
- readonly callId: string;
1296
- /**
1297
- * Zero-based index of this step.
1298
- */
1299
- readonly stepNumber: number;
1300
- /**
1301
- * Information about the model that produced this step.
1302
- */
1303
- readonly model: {
1304
- /** The provider of the model. */
1305
- readonly provider: string;
1306
- /** The ID of the model. */
1307
- readonly modelId: string;
1308
- };
1309
- /**
1310
- * Tool context.
1311
- */
1312
- readonly toolsContext: InferToolSetContext<TOOLS>;
1313
- /**
1314
- * The runtime context that was used as input for the step.
1315
- */
1316
- readonly runtimeContext: RUNTIME_CONTEXT;
1317
- /**
1318
- * The content that was generated in the last step.
1319
- */
1320
- readonly content: Array<ContentPart<TOOLS>>;
1321
- /**
1322
- * The concatenation of all text parts generated in this step.
1323
- * It is an empty string if the step contains no text parts.
1324
- */
1325
- readonly text: string;
1326
- /**
1327
- * The reasoning that was generated during the generation.
1328
- */
1329
- readonly reasoning: Array<ReasoningPart | ReasoningFilePart>;
1330
- /**
1331
- * The reasoning text that was generated during the generation.
1332
- *
1333
- * It is a concatenation of all reasoning parts (but excluding reasoning file parts).
1334
- * Can be undefined if the model has only generated text.
1335
- */
1336
- readonly reasoningText: string | undefined;
1337
- /**
1338
- * The files that were generated during the generation.
1339
- */
1340
- readonly files: Array<GeneratedFile>;
1341
- /**
1342
- * The sources that were used to generate the text.
1343
- */
1344
- readonly sources: Array<Source>;
1345
- /**
1346
- * The tool calls that were made during the generation.
1347
- */
1348
- readonly toolCalls: Array<TypedToolCall<TOOLS>>;
1349
- /**
1350
- * The static tool calls that were made in the last step.
1351
- */
1352
- readonly staticToolCalls: Array<StaticToolCall<TOOLS>>;
1353
- /**
1354
- * The dynamic tool calls that were made in the last step.
1355
- */
1356
- readonly dynamicToolCalls: Array<DynamicToolCall>;
1357
- /**
1358
- * The results of the tool calls.
1359
- */
1360
- readonly toolResults: Array<TypedToolResult<TOOLS>>;
1361
- /**
1362
- * The static tool results that were made in the last step.
1363
- */
1364
- readonly staticToolResults: Array<StaticToolResult<TOOLS>>;
1365
- /**
1366
- * The dynamic tool results that were made in the last step.
1367
- */
1368
- readonly dynamicToolResults: Array<DynamicToolResult>;
1369
- /**
1370
- * The unified reason why the generation finished.
1371
- */
1372
- readonly finishReason: FinishReason;
1373
- /**
1374
- * The raw reason why the generation finished (from the provider).
1375
- */
1376
- readonly rawFinishReason: string | undefined;
1377
- /**
1378
- * The token usage of the generated text.
1379
- */
1380
- readonly usage: LanguageModelUsage;
1381
- /**
1382
- * Performance metrics for the step.
1383
- */
1384
- readonly performance: StepResultPerformance;
1385
- /**
1386
- * Warnings from the model provider (e.g. unsupported settings).
1387
- */
1388
- readonly warnings: CallWarning[] | undefined;
1389
- /**
1390
- * Additional request information.
1391
- */
1392
- readonly request: LanguageModelRequestMetadata;
1393
- /**
1394
- * Additional response information.
1395
- */
1396
- readonly response: LanguageModelResponseMetadata;
1397
- /**
1398
- * Additional provider-specific metadata. They are passed through
1399
- * from the provider to the AI SDK and enable provider-specific
1400
- * results that can be fully encapsulated in the provider.
1401
- */
1402
- readonly providerMetadata: ProviderMetadata | undefined;
1403
- };
1404
- declare class DefaultStepResult<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context> implements StepResult<TOOLS, RUNTIME_CONTEXT> {
1405
- readonly callId: StepResult<TOOLS, RUNTIME_CONTEXT>['callId'];
1406
- readonly stepNumber: StepResult<TOOLS, RUNTIME_CONTEXT>['stepNumber'];
1407
- readonly model: StepResult<TOOLS, RUNTIME_CONTEXT>['model'];
1408
- readonly toolsContext: StepResult<TOOLS, RUNTIME_CONTEXT>['toolsContext'];
1409
- readonly runtimeContext: StepResult<TOOLS, RUNTIME_CONTEXT>['runtimeContext'];
1410
- readonly content: StepResult<TOOLS, RUNTIME_CONTEXT>['content'];
1411
- readonly finishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['finishReason'];
1412
- readonly rawFinishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['rawFinishReason'];
1413
- readonly usage: StepResult<TOOLS, RUNTIME_CONTEXT>['usage'];
1414
- readonly performance: StepResult<TOOLS, RUNTIME_CONTEXT>['performance'];
1415
- readonly warnings: StepResult<TOOLS, RUNTIME_CONTEXT>['warnings'];
1416
- readonly request: StepResult<TOOLS, RUNTIME_CONTEXT>['request'];
1417
- readonly response: StepResult<TOOLS, RUNTIME_CONTEXT>['response'];
1418
- readonly providerMetadata: StepResult<TOOLS, RUNTIME_CONTEXT>['providerMetadata'];
1419
- constructor({ callId, stepNumber, provider, modelId, runtimeContext, toolsContext, content, finishReason, rawFinishReason, usage, performance, warnings, request, response, providerMetadata, }: {
1420
- callId: StepResult<TOOLS, RUNTIME_CONTEXT>['callId'];
1421
- stepNumber: StepResult<TOOLS, RUNTIME_CONTEXT>['stepNumber'];
1422
- provider: StepResult<TOOLS, RUNTIME_CONTEXT>['model']['provider'];
1423
- modelId: StepResult<TOOLS, RUNTIME_CONTEXT>['model']['modelId'];
1424
- runtimeContext: StepResult<TOOLS, RUNTIME_CONTEXT>['runtimeContext'];
1425
- toolsContext: StepResult<TOOLS, RUNTIME_CONTEXT>['toolsContext'];
1426
- content: StepResult<TOOLS, RUNTIME_CONTEXT>['content'];
1427
- finishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['finishReason'];
1428
- rawFinishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['rawFinishReason'];
1429
- usage: StepResult<TOOLS, RUNTIME_CONTEXT>['usage'];
1430
- performance: StepResult<TOOLS, RUNTIME_CONTEXT>['performance'];
1431
- warnings: StepResult<TOOLS, RUNTIME_CONTEXT>['warnings'];
1432
- request: StepResult<TOOLS, RUNTIME_CONTEXT>['request'];
1433
- response: StepResult<TOOLS, RUNTIME_CONTEXT>['response'];
1434
- providerMetadata: StepResult<TOOLS, RUNTIME_CONTEXT>['providerMetadata'];
1435
- });
1436
- get text(): string;
1437
- get reasoning(): Array<ReasoningPart | ReasoningFilePart>;
1438
- get reasoningText(): string | undefined;
1439
- get files(): GeneratedFile[];
1440
- get sources(): (({
1441
- type: "source";
1442
- } & {
1443
- type: "source";
1444
- sourceType: "url";
1445
- id: string;
1446
- url: string;
1447
- title?: string;
1448
- providerMetadata?: _ai_sdk_provider.SharedV4ProviderMetadata;
1449
- }) | ({
1450
- type: "source";
1451
- } & {
1452
- type: "source";
1453
- sourceType: "document";
1454
- id: string;
1455
- mediaType: string;
1456
- title: string;
1457
- filename?: string;
1458
- providerMetadata?: _ai_sdk_provider.SharedV4ProviderMetadata;
1459
- }))[];
1460
- get toolCalls(): (({
1461
- type: "tool-call";
1462
- } & {
1463
- type: "tool-call";
1464
- toolCallId: string;
1465
- providerExecuted?: boolean;
1466
- providerMetadata?: ProviderMetadata;
1467
- toolMetadata?: _ai_sdk_provider.JSONObject;
1468
- } & {
1469
- toolName: string;
1470
- input: unknown;
1471
- dynamic: true;
1472
- title?: string;
1473
- invalid?: boolean;
1474
- error?: unknown;
1475
- } & {
1476
- providerMetadata?: ProviderMetadata;
1477
- }) | ({
1478
- type: "tool-call";
1479
- } & StaticToolCall<TOOLS> & {
1480
- providerMetadata?: ProviderMetadata;
1481
- }))[];
1482
- get staticToolCalls(): StaticToolCall<TOOLS>[];
1483
- get dynamicToolCalls(): DynamicToolCall[];
1484
- get toolResults(): (({
1485
- type: "tool-result";
1486
- } & DynamicToolResult & {
1487
- providerMetadata?: ProviderMetadata;
1488
- }) | ({
1489
- type: "tool-result";
1490
- } & StaticToolResult<TOOLS> & {
1491
- providerMetadata?: ProviderMetadata;
1492
- }))[];
1493
- get staticToolResults(): StaticToolResult<TOOLS>[];
1494
- get dynamicToolResults(): DynamicToolResult[];
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
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
1502
- readonly provider: string;
1503
- /** The specific model identifier (e.g., 'gpt-4o'). */
1504
- readonly modelId: string;
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
- /** Unique identifier for this generation call, used to correlate events. */
1514
- readonly callId: string;
1515
- /** Prepared tool definitions for the model call, if any. */
1516
- readonly tools: ReadonlyArray<Record<string, unknown>> | undefined;
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
- /** Unique identifier for this generation call, used to correlate events. */
1526
- readonly callId: string;
1527
- /** The unified reason why the model call finished. */
1528
- readonly finishReason: FinishReason;
1529
- /** The token usage reported by the model call. */
1530
- readonly usage: LanguageModelUsage;
1531
- /** The content parts produced by the model call. */
1532
- readonly content: ReadonlyArray<ContentPart<TOOLS>>;
1533
- /** The provider-returned response id for this model call. */
1534
- readonly responseId: string;
1535
- /** Optional provider-specific metadata for this model call. */
1536
- readonly providerMetadata?: ProviderMetadata;
1537
- /** Performance metrics for the model call. */
1538
- readonly performance: {
1539
- /** Time spent waiting for the language model response in milliseconds. */
1540
- readonly responseTimeMs: number;
1541
- /**
1542
- * Effective number of output tokens per second over the full language
1543
- * model response.
1544
- */
1545
- readonly effectiveOutputTokensPerSecond: number;
1546
- /**
1547
- * Number of output tokens per second after the first generated output
1548
- * chunk was received.
1549
- *
1550
- * Only available for streaming calls.
1551
- */
1552
- readonly outputTokensPerSecond: number | undefined;
1553
- /**
1554
- * Number of input tokens processed per second before the first generated
1555
- * output chunk was received.
1556
- *
1557
- * Only available for streaming calls.
1558
- */
1559
- readonly inputTokensPerSecond: number | undefined;
1560
- /**
1561
- * Effective number of input and output tokens per second over the full
1562
- * language model response.
1563
- */
1564
- readonly effectiveTotalTokensPerSecond: number;
1565
- /**
1566
- * Time until the first generated output chunk was received in
1567
- * milliseconds.
1568
- */
1569
- readonly timeToFirstOutputMs: number | undefined;
1570
- /**
1571
- * Timing statistics for the gaps between generated output chunks in
1572
- * milliseconds.
1573
- *
1574
- * Only available for streaming calls with at least two output chunks.
1575
- */
1576
- readonly timeBetweenOutputChunksMs?: OutputChunkTimingStats;
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
- [NAME in keyof TOOLS]: {
1628
- type: 'tool-output-denied';
1629
- toolCallId: string;
1630
- toolName: NAME & string;
1631
- providerExecuted?: boolean;
1632
- dynamic?: false | undefined;
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
- type: 'text-delta';
1638
- id: string;
1639
- providerMetadata?: ProviderMetadata;
1640
- text: string;
1655
+ type: 'text-delta';
1656
+ id: string;
1657
+ providerMetadata?: ProviderMetadata;
1658
+ text: string;
1641
1659
  };
1642
1660
  type TextStreamTextStartPart = {
1643
- type: 'text-start';
1644
- id: string;
1645
- providerMetadata?: ProviderMetadata;
1661
+ type: 'text-start';
1662
+ id: string;
1663
+ providerMetadata?: ProviderMetadata;
1646
1664
  };
1647
1665
  type TextStreamTextEndPart = {
1648
- type: 'text-end';
1649
- id: string;
1650
- providerMetadata?: ProviderMetadata;
1666
+ type: 'text-end';
1667
+ id: string;
1668
+ providerMetadata?: ProviderMetadata;
1651
1669
  };
1652
1670
  type TextStreamReasoningStartPart = {
1653
- type: 'reasoning-start';
1654
- id: string;
1655
- providerMetadata?: ProviderMetadata;
1671
+ type: 'reasoning-start';
1672
+ id: string;
1673
+ providerMetadata?: ProviderMetadata;
1656
1674
  };
1657
1675
  type TextStreamReasoningEndPart = {
1658
- type: 'reasoning-end';
1659
- id: string;
1660
- providerMetadata?: ProviderMetadata;
1676
+ type: 'reasoning-end';
1677
+ id: string;
1678
+ providerMetadata?: ProviderMetadata;
1661
1679
  };
1662
1680
  type TextStreamReasoningDeltaPart = {
1663
- type: 'reasoning-delta';
1664
- providerMetadata?: ProviderMetadata;
1665
- id: string;
1666
- text: string;
1681
+ type: 'reasoning-delta';
1682
+ providerMetadata?: ProviderMetadata;
1683
+ id: string;
1684
+ text: string;
1667
1685
  };
1668
1686
  type TextStreamCustomPart = {
1669
- type: 'custom';
1670
- kind: `${string}.${string}`;
1671
- providerMetadata?: ProviderMetadata;
1687
+ type: 'custom';
1688
+ kind: `${string}.${string}`;
1689
+ providerMetadata?: ProviderMetadata;
1672
1690
  };
1673
1691
  type TextStreamToolInputStartPart = {
1674
- type: 'tool-input-start';
1675
- id: string;
1676
- toolName: string;
1677
- providerMetadata?: ProviderMetadata;
1678
- toolMetadata?: JSONObject;
1679
- providerExecuted?: boolean;
1680
- dynamic?: boolean;
1681
- title?: string;
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
- type: 'tool-input-end';
1685
- id: string;
1686
- providerMetadata?: ProviderMetadata;
1702
+ type: 'tool-input-end';
1703
+ id: string;
1704
+ providerMetadata?: ProviderMetadata;
1687
1705
  };
1688
1706
  type TextStreamToolInputDeltaPart = {
1689
- type: 'tool-input-delta';
1690
- id: string;
1691
- delta: string;
1692
- providerMetadata?: ProviderMetadata;
1707
+ type: 'tool-input-delta';
1708
+ id: string;
1709
+ delta: string;
1710
+ providerMetadata?: ProviderMetadata;
1693
1711
  };
1694
1712
  type TextStreamSourcePart = {
1695
- type: 'source';
1713
+ type: 'source';
1696
1714
  } & Source;
1697
1715
  type TextStreamFilePart = {
1698
- type: 'file';
1699
- file: GeneratedFile;
1700
- providerMetadata?: ProviderMetadata;
1716
+ type: 'file';
1717
+ file: GeneratedFile;
1718
+ providerMetadata?: ProviderMetadata;
1701
1719
  };
1702
1720
  type TextStreamReasoningFilePart = {
1703
- type: 'reasoning-file';
1704
- file: GeneratedFile;
1705
- providerMetadata?: ProviderMetadata;
1721
+ type: 'reasoning-file';
1722
+ file: GeneratedFile;
1723
+ providerMetadata?: ProviderMetadata;
1706
1724
  };
1707
1725
  type TextStreamToolCallPart<TOOLS extends ToolSet> = {
1708
- type: 'tool-call';
1726
+ type: 'tool-call';
1709
1727
  } & TypedToolCall<TOOLS>;
1710
1728
  type TextStreamToolResultPart<TOOLS extends ToolSet> = {
1711
- type: 'tool-result';
1729
+ type: 'tool-result';
1712
1730
  } & TypedToolResult<TOOLS>;
1713
1731
  type TextStreamToolErrorPart<TOOLS extends ToolSet> = {
1714
- type: 'tool-error';
1732
+ type: 'tool-error';
1715
1733
  } & TypedToolError<TOOLS>;
1716
1734
  type TextStreamToolOutputDeniedPart<TOOLS extends ToolSet> = {
1717
- type: 'tool-output-denied';
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
- type: 'start-step';
1723
- request: LanguageModelRequestMetadata;
1724
- warnings: CallWarning[];
1740
+ type: 'start-step';
1741
+ request: LanguageModelRequestMetadata;
1742
+ warnings: CallWarning[];
1725
1743
  };
1726
1744
  type TextStreamFinishStepPart = {
1727
- type: 'finish-step';
1728
- response: Omit<LanguageModelResponseMetadata, 'messages' | 'body'>;
1729
- usage: LanguageModelUsage;
1730
- performance: StepResultPerformance;
1731
- finishReason: FinishReason;
1732
- rawFinishReason: string | undefined;
1733
- providerMetadata: ProviderMetadata | undefined;
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
- type: 'start';
1754
+ type: 'start';
1737
1755
  };
1738
1756
  type TextStreamFinishPart = {
1739
- type: 'finish';
1740
- finishReason: FinishReason;
1741
- rawFinishReason: string | undefined;
1742
- totalUsage: LanguageModelUsage;
1757
+ type: 'finish';
1758
+ finishReason: FinishReason;
1759
+ rawFinishReason: string | undefined;
1760
+ totalUsage: LanguageModelUsage;
1743
1761
  };
1744
1762
  type TextStreamAbortPart = {
1745
- type: 'abort';
1746
- reason?: string;
1763
+ type: 'abort';
1764
+ reason?: string;
1747
1765
  };
1748
1766
  type TextStreamErrorPart = {
1749
- type: 'error';
1750
- error: unknown;
1767
+ type: 'error';
1768
+ error: unknown;
1751
1769
  };
1752
1770
  type TextStreamRawPart = {
1753
- type: 'raw';
1754
- rawValue: unknown;
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
- type: 'not-applicable';
1774
- reason?: never;
1792
+ type: 'not-applicable';
1793
+ reason?: never;
1775
1794
  } | {
1776
- type: 'approved';
1777
- reason?: string;
1795
+ type: 'approved';
1796
+ reason?: string;
1778
1797
  } | {
1779
- type: 'denied';
1780
- reason?: string;
1798
+ type: 'denied';
1799
+ reason?: string;
1781
1800
  } | {
1782
- type: 'user-approval';
1783
- reason?: string;
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
- toolContext: TOOL_CONTEXT;
1792
- runtimeContext: RUNTIME_CONTEXT;
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
- * The tool call that needs approval.
1802
- */
1803
- toolCall: TypedToolCall<TOOLS>;
1804
- /**
1805
- * All tools that are available for the model to call.
1806
- */
1807
- tools: TOOLS | undefined;
1808
- /**
1809
- * Tool context for all tools that are available for the model to call.
1810
- */
1811
- toolsContext: TOOLS_CONTEXT;
1812
- /**
1813
- * Runtime context.
1814
- */
1815
- runtimeContext: RUNTIME_CONTEXT;
1816
- /**
1817
- * Messages that were sent to the language model to initiate the response that contained the tool call.
1818
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
1819
- */
1820
- messages: ModelMessage[];
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
- [key in keyof TOOLS]?: ToolApprovalStatus | SingleToolApprovalFunction<InferToolInput<TOOLS[key]>, InferToolContext<TOOLS[key]>, RUNTIME_CONTEXT>;
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
- private readonly [symbol$1];
1850
- readonly toolName: string;
1851
- readonly toolInput: string;
1852
- constructor({ toolInput, toolName, cause, message, }: {
1853
- message?: string;
1854
- toolInput: string;
1855
- toolName: string;
1856
- cause: unknown;
1857
- });
1858
- static isInstance(error: unknown): error is InvalidToolInputError;
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
- private readonly [symbol];
1864
- readonly toolName: string;
1865
- readonly availableTools: string[] | undefined;
1866
- constructor({ toolName, availableTools, message, }: {
1867
- toolName: string;
1868
- availableTools?: string[] | undefined;
1869
- message?: string;
1870
- });
1871
- static isInstance(error: unknown): error is NoSuchToolError;
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
- instructions: Instructions | undefined;
1891
- /**
1892
- * @deprecated Use `instructions` instead.
1893
- */
1894
- system: Instructions | undefined;
1895
- messages: ModelMessage[];
1896
- toolCall: LanguageModelV4ToolCall;
1897
- tools: TOOLS;
1898
- inputSchema: (options: {
1899
- toolName: string;
1900
- }) => PromiseLike<JSONSchema7>;
1901
- error: NoSuchToolError | InvalidToolInputError;
1902
- abortSignal?: AbortSignal;
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
- /** Unique identifier for this generation call, used to correlate events. */
1916
- readonly callId: string;
1917
- /**
1918
- * Messages that were sent to the language model to initiate the response that contained the tool call.
1919
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
1920
- */
1921
- readonly messages: ModelMessage[];
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
- [NAME in keyof TOOLS]: BaseToolExecutionStartFields & {
1931
- readonly toolCall: Extract<StaticToolCall<TOOLS>, {
1932
- toolName: NAME;
1933
- }>;
1934
- readonly toolContext: ToolContextFor<TOOLS[NAME]>;
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
- readonly toolCall: DynamicToolCall;
1942
- readonly toolContext: unknown;
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
- readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
1952
- readonly toolContext: unknown;
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
- /** Unique identifier for this generation call, used to correlate events. */
1964
- readonly callId: string;
1965
- /** Execution time of the tool call in milliseconds. */
1966
- readonly toolExecutionMs: number;
1967
- /**
1968
- * Messages that were sent to the language model to initiate the response that contained the tool call.
1969
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
1970
- */
1971
- readonly messages: ModelMessage[];
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
- [NAME in keyof TOOLS]: BaseToolExecutionEndFields & {
1981
- readonly toolCall: Extract<StaticToolCall<TOOLS>, {
1982
- toolName: NAME;
1983
- }>;
1984
- readonly toolContext: ToolContextFor<TOOLS[NAME]>;
1985
- readonly toolOutput: ToolOutput<TOOLS>;
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
- readonly toolCall: DynamicToolCall;
1993
- readonly toolContext: unknown;
1994
- readonly toolOutput: ToolOutput<TOOLS>;
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
- readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
2004
- readonly toolContext: unknown;
2005
- readonly toolOutput: ToolOutput<ToolSet>;
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
- [NAME in keyof TOOLS]?: (input: InferToolInput<TOOLS[NAME]>) => MaybePromiseLike<InferToolInput<TOOLS[NAME]>>;
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
- toolsContext?: never;
2072
+ toolsContext?: never;
2060
2073
  } : HasRequiredKey<InferToolSetContext<TOOLS>> extends true ? {
2061
- toolsContext: InferToolSetContext<TOOLS>;
2074
+ toolsContext: InferToolSetContext<TOOLS>;
2062
2075
  } : {
2063
- toolsContext?: InferToolSetContext<TOOLS>;
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
- part: TextStreamPart<TOOLS>;
2068
- partialOutput: PARTIAL_OUTPUT | undefined;
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
- * The name of the output mode.
2074
- */
2075
- name: string;
2076
- /**
2077
- * The response format to use for the model.
2078
- */
2079
- responseFormat: PromiseLike<LanguageModelV4CallOptions['responseFormat']>;
2080
- /**
2081
- * Parses the complete output of the model.
2082
- */
2083
- parseCompleteOutput(options: {
2084
- text: string;
2085
- }, context: {
2086
- response: Omit<LanguageModelResponseMetadata, 'messages' | 'body'>;
2087
- usage: LanguageModelUsage;
2088
- finishReason: FinishReason;
2089
- }): Promise<OUTPUT>;
2090
- /**
2091
- * Parses the partial output of the model.
2092
- */
2093
- parsePartialOutput(options: {
2094
- text: string;
2095
- }): Promise<{
2096
- partial: PARTIAL;
2097
- } | undefined>;
2098
- /**
2099
- * Creates a stream transform that emits individual elements as they complete.
2100
- */
2101
- createElementStreamTransform(): TransformStream<EnrichedStreamPart<any, PARTIAL>, ELEMENT> | undefined;
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
- /** Unique identifier for this generation call, used to correlate events. */
2111
- readonly callId: string;
2112
- /** Identifies the operation type (e.g. 'ai.generateText' or 'ai.streamText'). */
2113
- readonly operationId: string;
2114
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
2115
- readonly provider: string;
2116
- /** The specific model identifier (e.g., 'gpt-4o'). */
2117
- readonly modelId: string;
2118
- /** The tools available for this generation. */
2119
- readonly tools: TOOLS | undefined;
2120
- /** The tool choice strategy for this generation. */
2121
- readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
2122
- /** Limits which tools are available for the model to call. */
2123
- readonly activeTools: ActiveTools<TOOLS>;
2124
- /** Controls the order in which tools are sent to the provider. */
2125
- readonly toolOrder: ToolOrder<TOOLS>;
2126
- /** Maximum number of retries for failed requests. */
2127
- readonly maxRetries: number;
2128
- /**
2129
- * Timeout configuration for the generation.
2130
- * Can be a number (milliseconds) or an object with totalMs, stepMs,
2131
- * firstChunkMs (streaming only), chunkMs, toolMs, and per-tool overrides via tools.
2132
- */
2133
- readonly timeout: TimeoutConfiguration<TOOLS> | undefined;
2134
- /** Additional HTTP headers sent with the request. */
2135
- readonly headers: Record<string, string | undefined> | undefined;
2136
- /** Additional provider-specific options. */
2137
- readonly providerOptions: ProviderOptions | undefined;
2138
- /** The output specification for structured outputs, if configured. */
2139
- readonly output: OUTPUT | undefined;
2140
- /**
2141
- * Tool context.
2142
- */
2143
- readonly toolsContext: InferToolSetContext<TOOLS>;
2144
- /**
2145
- * User-defined runtime context.
2146
- */
2147
- readonly runtimeContext: RUNTIME_CONTEXT;
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
- /** Unique identifier for this generation call, used to correlate events. */
2157
- readonly callId: string;
2158
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
2159
- readonly provider: string;
2160
- /** The specific model identifier (e.g., 'gpt-4o'). */
2161
- readonly modelId: string;
2162
- /** Zero-based index of the current step. */
2163
- readonly stepNumber: number;
2164
- /** The tools available for this generation. */
2165
- readonly tools: TOOLS | undefined;
2166
- /** The tool choice configuration for this step. */
2167
- readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
2168
- /** Limits which tools are available for this step. */
2169
- readonly activeTools: ActiveTools<TOOLS>;
2170
- /** Controls the order in which tools are sent to the provider for this step. */
2171
- readonly toolOrder: ToolOrder<TOOLS>;
2172
- /** Array of results from previous steps (empty for first step). */
2173
- readonly steps: ReadonlyArray<StepResult<TOOLS, RUNTIME_CONTEXT>>;
2174
- /** Additional provider-specific options for this step. */
2175
- readonly providerOptions: ProviderOptions | undefined;
2176
- /** The output specification for structured outputs, if configured. */
2177
- readonly output: OUTPUT | undefined;
2178
- /**
2179
- * Runtime context. May be updated from `prepareStep` between steps.
2180
- */
2181
- readonly runtimeContext: RUNTIME_CONTEXT;
2182
- /**
2183
- * Tool context. May be updated from `prepareStep` between steps.
2184
- */
2185
- readonly toolsContext: InferToolSetContext<TOOLS>;
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
- /** Unique identifier for this generation call, used to correlate events. */
2202
- readonly callId: string;
2203
- /** Zero-based index of the final step. */
2204
- readonly stepNumber: number;
2205
- /** Information about the model that produced the final step. */
2206
- readonly model: StepResult<TOOLS, RUNTIME_CONTEXT>['model'];
2207
- /**
2208
- * Tool context from the final step.
2209
- *
2210
- * @deprecated Use `finalStep.toolsContext` instead.
2211
- */
2212
- readonly toolsContext: InferToolSetContext<TOOLS>;
2213
- /**
2214
- * Runtime context from the final step.
2215
- *
2216
- * @deprecated Use `finalStep.runtimeContext` instead.
2217
- */
2218
- readonly runtimeContext: RUNTIME_CONTEXT;
2219
- /** The content that was generated in all steps. */
2220
- readonly content: StepResult<TOOLS, RUNTIME_CONTEXT>['content'];
2221
- /** The text that was generated in the final step. */
2222
- readonly text: StepResult<TOOLS, RUNTIME_CONTEXT>['text'];
2223
- /**
2224
- * The reasoning that was generated in the final step.
2225
- *
2226
- * @deprecated Use `finalStep.reasoning` instead.
2227
- */
2228
- readonly reasoning: StepResult<TOOLS, RUNTIME_CONTEXT>['reasoning'];
2229
- /**
2230
- * The reasoning text that was generated in the final step.
2231
- *
2232
- * @deprecated Use `finalStep.reasoningText` instead.
2233
- */
2234
- readonly reasoningText: StepResult<TOOLS, RUNTIME_CONTEXT>['reasoningText'];
2235
- /** Files that were generated in all steps. */
2236
- readonly files: StepResult<TOOLS, RUNTIME_CONTEXT>['files'];
2237
- /** Sources that were used as references in all steps. */
2238
- readonly sources: StepResult<TOOLS, RUNTIME_CONTEXT>['sources'];
2239
- /** Tool calls that were made in all steps. */
2240
- readonly toolCalls: StepResult<TOOLS, RUNTIME_CONTEXT>['toolCalls'];
2241
- /** Static tool calls that were made in all steps. */
2242
- readonly staticToolCalls: StepResult<TOOLS, RUNTIME_CONTEXT>['staticToolCalls'];
2243
- /** Dynamic tool calls that were made in all steps. */
2244
- readonly dynamicToolCalls: StepResult<TOOLS, RUNTIME_CONTEXT>['dynamicToolCalls'];
2245
- /** Tool results that were generated in all steps. */
2246
- readonly toolResults: StepResult<TOOLS, RUNTIME_CONTEXT>['toolResults'];
2247
- /** Static tool results that were generated in all steps. */
2248
- readonly staticToolResults: StepResult<TOOLS, RUNTIME_CONTEXT>['staticToolResults'];
2249
- /** Dynamic tool results that were generated in all steps. */
2250
- readonly dynamicToolResults: StepResult<TOOLS, RUNTIME_CONTEXT>['dynamicToolResults'];
2251
- /** The unified reason why the generation finished. Taken from the final step. */
2252
- readonly finishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['finishReason'];
2253
- /** The raw reason why the generation finished. Taken from the final step. */
2254
- readonly rawFinishReason: StepResult<TOOLS, RUNTIME_CONTEXT>['rawFinishReason'];
2255
- /** Aggregated token usage across all steps. */
2256
- readonly usage: LanguageModelUsage;
2257
- /**
2258
- * Aggregated token usage across all steps.
2259
- *
2260
- * @deprecated Use `usage` instead.
2261
- */
2262
- readonly totalUsage: LanguageModelUsage;
2263
- /** Warnings from the model provider in all steps. */
2264
- readonly warnings: StepResult<TOOLS, RUNTIME_CONTEXT>['warnings'];
2265
- /**
2266
- * Additional request information from the final step.
2267
- *
2268
- * @deprecated Use `finalStep.request` instead.
2269
- */
2270
- readonly request: StepResult<TOOLS, RUNTIME_CONTEXT>['request'];
2271
- /**
2272
- * Additional response information from the final step.
2273
- *
2274
- * @deprecated Use `finalStep.response` instead.
2275
- */
2276
- readonly response: StepResult<TOOLS, RUNTIME_CONTEXT>['response'];
2277
- /**
2278
- * Additional provider-specific metadata from the final step.
2279
- *
2280
- * @deprecated Use `finalStep.providerMetadata` instead.
2281
- */
2282
- readonly providerMetadata: StepResult<TOOLS, RUNTIME_CONTEXT>['providerMetadata'];
2283
- /** The response messages that were generated during the call. */
2284
- readonly responseMessages: ResponseMessage[];
2285
- /** Array containing results from all steps in the generation. */
2286
- readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
2287
- /** The final step. This is a shortcut for `steps.at(-1)`. */
2288
- readonly finalStep: StepResult<TOOLS, RUNTIME_CONTEXT>;
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
- /** Unique identifier for this generation call, used to correlate events. */
2298
- readonly callId: string;
2299
- /** Details for all previously finished steps. */
2300
- readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
2301
- /** The abort reason from the AbortSignal, when one is available. */
2302
- readonly reason?: unknown;
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
- /** User-defined runtime context. */
2366
- readonly runtimeContext: RUNTIME_CONTEXT;
2367
- /** Unique identifier for this rerank call, used to correlate events. */
2368
- readonly callId: string;
2369
- /** Identifies the operation type ('ai.rerank'). */
2370
- readonly operationId: string;
2371
- readonly provider: string;
2372
- /** The specific model identifier (e.g., 'gpt-4o'). */
2373
- readonly modelId: string;
2374
- /** The documents being reranked. */
2375
- readonly documents: Array<JSONObject | string>;
2376
- /** The query to rerank the documents against. */
2377
- readonly query: string;
2378
- /** Number of top documents to return. */
2379
- readonly topN: number | undefined;
2380
- /** Maximum number of retries for failed requests. */
2381
- readonly maxRetries: number;
2382
- /** Additional HTTP headers sent with the request. */
2383
- readonly headers: Record<string, string | undefined> | undefined;
2384
- /** Additional provider-specific options. */
2385
- readonly providerOptions: ProviderOptions | undefined;
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
- /** User-defined runtime context. */
2394
- readonly runtimeContext: RUNTIME_CONTEXT;
2395
- /** Unique identifier for this rerank call, used to correlate events. */
2396
- readonly callId: string;
2397
- /** Identifies the operation type ('ai.rerank'). */
2398
- readonly operationId: string;
2399
- readonly provider: string;
2400
- /** The specific model identifier (e.g., 'gpt-4o'). */
2401
- readonly modelId: string;
2402
- /** The documents that were reranked. */
2403
- readonly documents: Array<JSONObject | string>;
2404
- /** The query that documents were reranked against. */
2405
- readonly query: string;
2406
- /** The reranked results sorted by relevance score in descending order. */
2407
- readonly ranking: Array<{
2408
- originalIndex: number;
2409
- score: number;
2410
- document: JSONObject | string;
2411
- }>;
2412
- /** Warnings from the reranking model. */
2413
- readonly warnings: Array<Warning>;
2414
- /** Optional provider-specific metadata. */
2415
- readonly providerMetadata: ProviderMetadata | undefined;
2416
- /** Response data including headers and body. */
2417
- readonly response: {
2418
- id?: string;
2419
- timestamp: Date;
2420
- modelId: string;
2421
- headers?: Record<string, string>;
2422
- body?: unknown;
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
- /** Unique identifier for this rerank call, used to correlate events. */
2430
- readonly callId: string;
2431
- /** Identifies the inner operation ('ai.rerank.doRerank'). */
2432
- readonly operationId: string;
2433
- /** The provider identifier. */
2434
- readonly provider: string;
2435
- /** The specific model identifier. */
2436
- readonly modelId: string;
2437
- /** The documents being reranked. */
2438
- readonly documents: Array<JSONObject | string>;
2439
- /** The type of documents ('text' or 'object'). */
2440
- readonly documentsType: string;
2441
- /** The query to rerank against. */
2442
- readonly query: string;
2443
- /** Number of top documents to return. */
2444
- readonly topN: number | undefined;
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
- /** Unique identifier for this rerank call, used to correlate events. */
2453
- readonly callId: string;
2454
- /** Identifies the inner operation ('ai.rerank.doRerank'). */
2455
- readonly operationId: string;
2456
- /** The provider identifier. */
2457
- readonly provider: string;
2458
- /** The specific model identifier. */
2459
- readonly modelId: string;
2460
- /** The type of documents ('text' or 'object'). */
2461
- readonly documentsType: string;
2462
- /** The ranking results from the model. */
2463
- readonly ranking: Array<{
2464
- index: number;
2465
- relevanceScore: number;
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
- run<T>(execute: () => T): T;
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
- * Runs awaited work inside a diagnostics-channel tracing span.
2481
- */
2482
- runInTracingChannelSpan?: <T>(options: {
2483
- type: TelemetryTracingEventType;
2484
- event: unknown;
2485
- execute: () => PromiseLike<T>;
2486
- }) => Promise<T>;
2487
- /**
2488
- * Opens a tracing span context whose completion is observed separately.
2489
- * This is used by streamed operations that must preserve stream timing while
2490
- * still creating child spans with the correct parent.
2491
- */
2492
- startTracingChannelContext?: (options: {
2493
- type: TelemetryTracingEventType;
2494
- event: unknown;
2495
- completion: PromiseLike<unknown>;
2496
- }) => TracingChannelContext | undefined;
2497
- onStart?: Callback<OperationStartEvent>;
2498
- onStepStart?: Callback<GenerateTextStepStartEvent>;
2499
- onLanguageModelCallStart?: OnLanguageModelCallStartCallback;
2500
- onLanguageModelCallEnd?: OnLanguageModelCallEndCallback;
2501
- onToolExecutionStart?: Callback<ToolExecutionStartEvent>;
2502
- onToolExecutionEnd?: Callback<ToolExecutionEndEvent>;
2503
- onStepEnd?: Callback<GenerateTextStepEndEvent>;
2504
- /** @deprecated Use `onStepEnd` instead. */
2505
- onStepFinish?: Callback<GenerateTextStepEndEvent>;
2506
- onObjectStepStart?: Callback<GenerateObjectStepStartEvent>;
2507
- onObjectStepEnd?: Callback<GenerateObjectStepEndEvent>;
2508
- onEmbedStart?: Callback<EmbeddingModelCallStartEvent>;
2509
- onEmbedEnd?: Callback<EmbeddingModelCallEndEvent>;
2510
- onRerankStart?: Callback<RerankingModelCallStartEvent>;
2511
- onRerankEnd?: Callback<RerankingModelCallEndEvent>;
2512
- experimental_onEvaluateStart?: Callback<EvaluateStartEvent>;
2513
- experimental_onEvaluationModelCallStart?: Callback<EvaluationModelCallStartEvent>;
2514
- experimental_onEvaluationModelCallEnd?: Callback<EvaluationModelCallEndEvent>;
2515
- experimental_onEvaluateEnd?: Callback<EvaluateEndEvent>;
2516
- onEnd?: Callback<OperationEndEvent>;
2517
- onAbort?: Callback<GenerateTextAbortEvent<ToolSet>>;
2518
- onError?: Callback<unknown>;
2519
- executeLanguageModelCall?: Telemetry['executeLanguageModelCall'];
2520
- executeTool?: Telemetry['executeTool'];
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
- * Called when an operation begins. Fired for text generation
2529
- * (generateText/streamText), object generation (generateObject/streamObject),
2530
- * embedding (embed/embedMany), and reranking operations.
2531
- *
2532
- * Use the `operationId` field to distinguish between operation types.
2533
- */
2534
- onStart?: Callback<InferTelemetryEvent<OperationStartEvent>>;
2535
- /**
2536
- * Called when an individual step (single LLM invocation) begins.
2537
- * A generation may consist of multiple steps (e.g. when tool calls trigger
2538
- * follow-up LLM calls). Use this to create per-step spans or record
2539
- * step-level inputs.
2540
- *
2541
- * The event includes the step number, accumulated previous step results,
2542
- * and the messages that will be sent to the model.
2543
- */
2544
- onStepStart?: Callback<InferTelemetryEvent<GenerateTextStepStartEvent>>;
2545
- /**
2546
- * Called immediately before the provider model call begins.
2547
- * Unlike `onStepStart`, this callback is scoped to model work only and
2548
- * excludes any later client-side tool execution.
2549
- */
2550
- onLanguageModelCallStart?: Callback<InferTelemetryEvent<LanguageModelCallStartEvent>>;
2551
- /**
2552
- * Called after the model response has been normalized and parsed, but before
2553
- * any client-side tool execution begins.
2554
- */
2555
- onLanguageModelCallEnd?: Callback<InferTelemetryEvent<LanguageModelCallEndEvent>>;
2556
- /**
2557
- * Called when a tool execution begins, before the tool's `execute` function
2558
- * is invoked. Use this to create tool-level spans or log tool invocations.
2559
- */
2560
- onToolExecutionStart?: Callback<InferTelemetryEvent<ToolExecutionStartEvent>>;
2561
- /**
2562
- * Called when a tool execution completes, either successfully or with an error.
2563
- * The event uses a discriminated union on the `success` field — check
2564
- * `event.success` to determine whether `output` or `error` is available.
2565
- *
2566
- * The event includes execution time (`toolExecutionMs`) for performance tracking.
2567
- */
2568
- onToolExecutionEnd?: Callback<InferTelemetryEvent<ToolExecutionEndEvent>>;
2569
- /**
2570
- * Called when an individual step (single LLM invocation) completes.
2571
- * The event is a `StepResult` containing the model's response, tool calls
2572
- * and results, usage statistics, finish reason, and optional request/response
2573
- * bodies.
2574
- */
2575
- onStepEnd?: Callback<InferTelemetryEvent<GenerateTextStepEndEvent>>;
2576
- /**
2577
- * Called when an individual step (single LLM invocation) completes.
2578
- *
2579
- * @deprecated Use `onStepEnd` instead.
2580
- */
2581
- onStepFinish?: Callback<InferTelemetryEvent<GenerateTextStepEndEvent>>;
2582
- /**
2583
- * Called when an object generation step (single LLM invocation) begins.
2584
- * For generateObject/streamObject there is always exactly one step.
2585
- *
2586
- * @deprecated
2587
- */
2588
- onObjectStepStart?: Callback<InferTelemetryEvent<GenerateObjectStepStartEvent>>;
2589
- /**
2590
- * Called when an object generation step (single LLM invocation) completes,
2591
- * with the raw result before JSON parsing and schema validation.
2592
- *
2593
- * @deprecated
2594
- */
2595
- onObjectStepEnd?: Callback<InferTelemetryEvent<GenerateObjectStepEndEvent>>;
2596
- /**
2597
- * Called when an individual embedding model call (doEmbed) begins.
2598
- * For `embed`, there is one call. For `embedMany`, there may be multiple
2599
- * calls when values are chunked.
2600
- */
2601
- onEmbedStart?: Callback<InferTelemetryEvent<EmbeddingModelCallStartEvent>>;
2602
- /**
2603
- * Called when an individual embedding model call (doEmbed) completes.
2604
- * Contains the embeddings, usage, and any warnings from the model response.
2605
- */
2606
- onEmbedEnd?: Callback<InferTelemetryEvent<EmbeddingModelCallEndEvent>>;
2607
- /**
2608
- * Called when an individual reranking model call (doRerank) begins.
2609
- * There is one call per `rerank` invocation.
2610
- */
2611
- onRerankStart?: Callback<InferTelemetryEvent<RerankingModelCallStartEvent>>;
2612
- /**
2613
- * Called when an individual reranking model call (doRerank) completes.
2614
- * Contains the ranking results from the model response.
2615
- */
2616
- onRerankEnd?: Callback<InferTelemetryEvent<RerankingModelCallEndEvent>>;
2617
- /** Called when an experimental evaluation operation begins. */
2618
- experimental_onEvaluateStart?: Callback<InferTelemetryEvent<EvaluateStartEvent>>;
2619
- /**
2620
- * Called immediately before an experimental evaluation model call begins.
2621
- * The logical model call includes any provider retries.
2622
- */
2623
- experimental_onEvaluationModelCallStart?: Callback<InferTelemetryEvent<EvaluationModelCallStartEvent>>;
2624
- /**
2625
- * Called after an experimental evaluation model response has been validated.
2626
- * The logical model call includes any provider retries.
2627
- */
2628
- experimental_onEvaluationModelCallEnd?: Callback<InferTelemetryEvent<EvaluationModelCallEndEvent>>;
2629
- /** Called when an experimental evaluation operation completes. */
2630
- experimental_onEvaluateEnd?: Callback<InferTelemetryEvent<EvaluateEndEvent>>;
2631
- /**
2632
- * Called when an operation completes. Fired for text generation
2633
- * (generateText/streamText), object generation (generateObject/streamObject),
2634
- * embedding (embed/embedMany), and reranking operations.
2635
- *
2636
- * Use the event shape or `operationId` to distinguish between operation types.
2637
- */
2638
- onEnd?: Callback<InferTelemetryEvent<OperationEndEvent>>;
2639
- /**
2640
- * Called when a streaming text generation operation is aborted before it
2641
- * completes.
2642
- */
2643
- onAbort?: Callback<InferTelemetryEvent<GenerateTextAbortEvent<ToolSet>>>;
2644
- /**
2645
- * Called when an unrecoverable error occurs during the generation lifecycle.
2646
- * The error value is untyped — it may be an `Error` instance, an `AISDKError`,
2647
- * or any thrown value.
2648
- *
2649
- * Use this to record error details on telemetry spans and set error status.
2650
- */
2651
- onError?: Callback<unknown>;
2652
- /**
2653
- * Optionally runs the language model call in a telemetry-integration-specific context. This enables
2654
- * auto-instrumented model provider requests to become children of the current
2655
- * model-call span.
2656
- *
2657
- * The options carry the model-call start-event content as context (the event
2658
- * fields are optional), alongside the always-present `callId` and the
2659
- * `execute` function that performs the model call.
2660
- */
2661
- executeLanguageModelCall?: <T>(options: Partial<InferTelemetryEvent<LanguageModelCallStartEvent>> & {
2662
- callId: string;
2663
- execute: () => PromiseLike<T>;
2664
- }) => PromiseLike<T>;
2665
- /**
2666
- * Optionally runs the tool execute function in a telemetry-integration-specific context. This enables
2667
- * nested traces — e.g. when a tool's `execute` function calls `generateText`,
2668
- * the inner call's spans become children of the tool span.
2669
- *
2670
- * The options carry the tool-execution start-event content as context (the
2671
- * event fields are optional), alongside the always-present `callId`,
2672
- * `toolCallId`, and the `execute` function to run.
2673
- */
2674
- executeTool?: <T>(options: Partial<InferTelemetryEvent<ToolExecutionStartEvent>> & {
2675
- callId: string;
2676
- toolCallId: string;
2677
- execute: () => PromiseLike<T>;
2678
- }) => PromiseLike<T>;
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
- * The default provider to use for the AI SDK.
2684
- * String model ids are resolved to the default provider and model id.
2685
- *
2686
- * If not set, the default provider is the Vercel AI gateway provider.
2687
- * Experimental evaluation requires an explicitly configured evaluation-capable provider.
2688
- *
2689
- * @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
2690
- */
2691
- var AI_SDK_DEFAULT_PROVIDER: ProviderV4 | ProviderV3 | ProviderV2 | undefined;
2692
- /**
2693
- * The warning logger to use for the AI SDK.
2694
- *
2695
- * If not set, the default logger is the console.warn function.
2696
- *
2697
- * If set to false, no warnings are logged.
2698
- */
2699
- var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
2700
- /**
2701
- * Globally registered telemetry integrations for the AI SDK.
2702
- *
2703
- * Integrations registered here receive lifecycle events (onStart, onStepStart,
2704
- * etc.) from every `generateText`, `streamText`, and similar call.
2705
- *
2706
- * Prefer using `registerTelemetry()` from `'ai'` instead of
2707
- * assigning this directly.
2708
- */
2709
- var AI_SDK_TELEMETRY_INTEGRATIONS: Telemetry[] | undefined;
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
- declare function convertToLanguageModelPrompt({ prompt, supportedUrls, download, abortSignal, provider, }: {
2713
- prompt: StandardizedPrompt;
2714
- supportedUrls: Record<string, RegExp[]>;
2715
- download: DownloadFunction | undefined;
2716
- abortSignal?: AbortSignal;
2717
- provider?: string;
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
- declare function createToolModelOutput({ toolCallId, input, output, tool, errorMode, }: {
2737
- toolCallId: string;
2738
- input: unknown;
2739
- output: unknown;
2740
- tool: Tool | undefined;
2741
- errorMode: 'none' | 'text' | 'json';
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
- declare function prepareToolChoice({ toolChoice, }: {
2745
- toolChoice: ToolChoice<any> | undefined;
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
- declare function prepareTools<TOOLS extends ToolSet>({ tools, toolOrder, toolsContext, experimental_sandbox: sandbox, }: {
2749
- tools: TOOLS | undefined;
2750
- toolOrder?: ToolOrder<TOOLS>;
2751
- toolsContext?: InferToolSetContext<TOOLS>;
2752
- experimental_sandbox?: Experimental_SandboxSession;
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, }: LanguageModelCallOptions): LanguageModelCallOptions;
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
- maxRetries: number | undefined;
2765
- abortSignal: AbortSignal | undefined;
2766
- additionalRetryableError?: ShouldRetryFunction;
2767
- parameter?: string;
2768
- defaultMaxRetries?: number;
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
- maxRetries: number;
2771
- retry: RetryFunction;
2797
+ maxRetries: number;
2798
+ retry: RetryFunction;
2772
2799
  };
2773
-
2774
- declare function resolveLanguageModel(model: LanguageModel): LanguageModelV4;
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
- telemetry?: TelemetryOptions;
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
- onStart: GenerateTextOnStartCallback<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
2822
- onStepStart: GenerateTextOnStepStartCallback<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
2823
- onStepEnd: GenerateTextOnStepEndCallback<TOOLS, RUNTIME_CONTEXT>;
2824
- /** @deprecated Use `onStepEnd` instead. */
2825
- onStepFinish: GenerateTextOnStepFinishCallback<TOOLS, RUNTIME_CONTEXT>;
2826
- onEnd: GenerateTextOnEndCallback<TOOLS, RUNTIME_CONTEXT>;
2827
- onAbort?: GenerateTextOnAbortCallback<TOOLS, RUNTIME_CONTEXT>;
2828
- onToolExecutionStart?: OnToolExecutionStartCallback<TOOLS>;
2829
- onToolExecutionEnd?: OnToolExecutionEndCallback<TOOLS>;
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
- telemetry?: TelemetryOptions<RUNTIME_CONTEXT, TOOLS>;
2837
- includeRuntimeContext: IncludedContext<RUNTIME_CONTEXT>;
2838
- includeToolsContext?: IncludedToolsContext<TOOLS>;
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
- declare function parseToolCall<TOOLS extends ToolSet>({ toolCall, tools, repairToolCall, refineToolInput, messages, instructions, abortSignal, }: {
2842
- toolCall: LanguageModelV4ToolCall;
2843
- tools: TOOLS | undefined;
2844
- repairToolCall: ToolCallRepairFunction<TOOLS> | undefined;
2845
- refineToolInput?: ToolInputRefinement<TOOLS> | undefined;
2846
- instructions: Instructions | undefined;
2847
- messages: ModelMessage[];
2848
- abortSignal?: AbortSignal;
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
- toolName: string;
2863
- context: unknown;
2864
- contextSchema: FlexibleSchema<CONTEXT> | undefined;
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
- tools: ToolSet | undefined;
2870
- toolCallers: ResolvedToolCallers | undefined;
2903
+ export declare function createToolSearchState({ tools, toolCallers }: {
2904
+ tools: ToolSet | undefined;
2905
+ toolCallers: ResolvedToolCallers | undefined;
2871
2906
  }): (activeTools: ToolSet | undefined, options?: {
2872
- toolsContext?: InferToolSetContext<ToolSet>;
2873
- experimental_sandbox?: Experimental_SandboxSession;
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
- approvalRequest: ToolApprovalRequest;
2878
- approvalResponse: ToolApprovalResponse;
2879
- toolCall: TypedToolCall<TOOLS>;
2880
- existingToolResult?: ToolResultPart;
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
- messages: ModelMessage[];
2922
+ export declare function collectToolApprovals<TOOLS extends ToolSet>({ messages }: {
2923
+ messages: ModelMessage[];
2888
2924
  }): {
2889
- approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
2890
- deniedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
2891
- };
2892
-
2893
- declare function signToolApproval({ secret, approvalId, toolCallId, toolName, input, }: {
2894
- secret: string | Uint8Array;
2895
- approvalId: string;
2896
- toolCallId: string;
2897
- toolName: string;
2898
- input: unknown;
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
- secret: string | Uint8Array;
2902
- signature: string;
2903
- approvalId: string;
2904
- toolCallId: string;
2905
- toolName: string;
2906
- input: unknown;
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
- approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
2916
- tools: TOOLS | undefined;
2917
- toolApproval: ToolApprovalConfiguration<TOOLS, RUNTIME_CONTEXT> | undefined;
2918
- messages: ModelMessage[];
2919
- toolsContext: InferToolSetContext<TOOLS>;
2920
- runtimeContext: RUNTIME_CONTEXT;
2921
- toolApprovalSecret?: string | Uint8Array;
2922
- refineToolInput?: ToolInputRefinement<TOOLS>;
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
- approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
2925
- deniedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
2926
- invalidToolApprovals: Array<CollectedToolApprovals<TOOLS> & {
2927
- error: InvalidToolInputError;
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
- content: Array<ContentPart<TOOLS>>;
2936
- tools: TOOLS | undefined;
2937
- }): Promise<Array<AssistantModelMessage | ToolModelMessage>>;
2938
-
2939
- export { type CollectedToolApprovals, DefaultStepResult, type DownloadFunction, type ToolsContextSettings, addLanguageModelUsage, asLanguageModelUsage, collectToolApprovals, convertToLanguageModelPrompt, createAsyncIterableStream, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, mapToolResultOutput, mergeAbortSignals, mergeCallbacks, parseToolCall, prepareLanguageModelCallOptions as prepareCallSettings, prepareLanguageModelCallOptions, prepareRetries, prepareToolChoice, prepareTools, resolveLanguageModel, signToolApproval, standardizePrompt, toResponseMessages, validateApprovedToolApprovals, validateToolContext, verifyToolApprovalSignature };
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