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