@ai-sdk/workflow 2.0.53 → 2.0.55
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 +25 -0
- package/dist/client.d.ts +2 -160
- package/dist/client.js +2 -8
- package/dist/index.d.ts +879 -887
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2344 -2914
- package/dist/index.js.map +1 -1
- package/dist/video.d.ts +7 -6
- package/dist/video.d.ts.map +1 -0
- package/dist/video.js +108 -69
- package/dist/video.js.map +1 -1
- package/dist/workflow-chat-transport-Bduf4ZDx.js +366 -0
- package/dist/workflow-chat-transport-Bduf4ZDx.js.map +1 -0
- package/dist/workflow-chat-transport-DwOgX7dK.d.ts +161 -0
- package/dist/workflow-chat-transport-DwOgX7dK.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/do-stream-step.ts +81 -3
- package/src/stream-text-iterator.ts +32 -42
- package/dist/chunk-CKYLPPDM.js +0 -358
- package/dist/chunk-CKYLPPDM.js.map +0 -1
- package/dist/chunk-UAWBPTDW.js +0 -51
- package/dist/chunk-UAWBPTDW.js.map +0 -1
- package/dist/client.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context, HasRequiredKey,
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { i as WorkflowChatTransportOptions, n as SendMessagesOptions, r as WorkflowChatTransport, t as ReconnectToStreamOptions } from "./workflow-chat-transport-DwOgX7dK.js";
|
|
2
|
+
import { Context, HasRequiredKey, InferToolContext, InferToolInput, InferToolOutput, InferToolSetContext } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { ActiveTools, Experimental_LanguageModelStreamPart, Experimental_SandboxSession, FinishReason, GenerateTextOnStepEndCallback, InferUITools, Instructions, LanguageModel, LanguageModelResponseMetadata, LanguageModelUsage, ModelMessage, Output, StepResult, StopCondition, TelemetryOptions as TelemetryOptions$1, ToolCallRepairFunction, ToolCallRepairFunction as ToolCallRepairFunction$1, ToolChoice, ToolSet, UIMessage, UIMessageChunk } from "ai";
|
|
4
|
+
import { LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart, SharedV4ProviderOptions } from "@ai-sdk/provider";
|
|
5
|
+
//#region src/do-stream-step.d.ts
|
|
7
6
|
type ModelCallStreamPart<TTools extends ToolSet = ToolSet> = Experimental_LanguageModelStreamPart<TTools> | {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
type: 'tool-approval-request';
|
|
8
|
+
approvalId: string;
|
|
9
|
+
toolCallId: string;
|
|
10
|
+
signature?: string;
|
|
12
11
|
} | {
|
|
13
|
-
|
|
12
|
+
type: 'reset-step';
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Shared types for AI SDK V4.
|
|
18
|
-
*/
|
|
19
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/types.d.ts
|
|
20
16
|
/**
|
|
21
17
|
* Language model type for AI SDK V4.
|
|
22
18
|
*
|
|
23
19
|
* This is a simple alias for LanguageModelV4 from @ai-sdk/provider.
|
|
24
20
|
*/
|
|
25
21
|
type CompatibleLanguageModel = LanguageModelV4;
|
|
26
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/workflow-agent.d.ts
|
|
27
24
|
/**
|
|
28
25
|
* Callback function to be called after each step completes.
|
|
29
26
|
* Alias for the AI SDK's GenerateTextOnStepEndCallback, using
|
|
@@ -45,26 +42,25 @@ type InferWorkflowAgentTools<WORKFLOW_AGENT> = WORKFLOW_AGENT extends WorkflowAg
|
|
|
45
42
|
* Infer the UI message type of a workflow agent.
|
|
46
43
|
*/
|
|
47
44
|
type InferWorkflowAgentUIMessage<WORKFLOW_AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_METADATA, never, InferUITools<InferWorkflowAgentTools<WORKFLOW_AGENT>>>;
|
|
48
|
-
|
|
49
45
|
/**
|
|
50
46
|
* Output specification interface for structured outputs.
|
|
51
47
|
* Use `Output.object({ schema })` or `Output.text()` to create an output specification.
|
|
52
48
|
*/
|
|
53
49
|
interface OutputSpecification<OUTPUT, PARTIAL> {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
readonly name: string;
|
|
51
|
+
responseFormat: PromiseLike<LanguageModelV4CallOptions['responseFormat']>;
|
|
52
|
+
parsePartialOutput(options: {
|
|
53
|
+
text: string;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
partial: PARTIAL;
|
|
56
|
+
} | undefined>;
|
|
57
|
+
parseCompleteOutput(options: {
|
|
58
|
+
text: string;
|
|
59
|
+
}, context: {
|
|
60
|
+
response: LanguageModelResponseMetadata;
|
|
61
|
+
usage: LanguageModelUsage;
|
|
62
|
+
finishReason: FinishReason;
|
|
63
|
+
}): Promise<OUTPUT>;
|
|
68
64
|
}
|
|
69
65
|
type DefaultWorkflowAgentOutput<OUTPUT> = 0 extends 1 & OUTPUT ? never : OUTPUT;
|
|
70
66
|
/**
|
|
@@ -76,202 +72,201 @@ type ProviderOptions = SharedV4ProviderOptions;
|
|
|
76
72
|
* secret used to sign and verify tool approvals.
|
|
77
73
|
*/
|
|
78
74
|
type WorkflowToolApprovalSecret = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Name of an environment variable containing a high-entropy secret.
|
|
77
|
+
*/
|
|
78
|
+
environmentVariable: string;
|
|
83
79
|
};
|
|
84
80
|
type WorkflowAgentToolsContextParameter<TTools extends ToolSet> = HasRequiredKey<InferToolSetContext<TTools>> extends true ? {
|
|
85
|
-
|
|
81
|
+
toolsContext: InferToolSetContext<TTools>;
|
|
86
82
|
} : {
|
|
87
|
-
|
|
83
|
+
toolsContext?: never;
|
|
88
84
|
};
|
|
89
85
|
type TelemetryOptions<TRuntimeContext extends Context = Context, TTools extends ToolSet = ToolSet> = TelemetryOptions$1<TRuntimeContext, TTools>;
|
|
90
86
|
/**
|
|
91
87
|
* A transformation that is applied to the stream.
|
|
92
88
|
*/
|
|
93
89
|
type StreamTextTransform<TTools extends ToolSet> = (options: {
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
tools: TTools;
|
|
91
|
+
stopStream: () => void;
|
|
96
92
|
}) => TransformStream<LanguageModelV4StreamPart, LanguageModelV4StreamPart>;
|
|
97
|
-
|
|
98
93
|
/**
|
|
99
94
|
* Custom download function for URLs.
|
|
100
95
|
* The function receives an array of URLs with information about whether
|
|
101
96
|
* the model supports them directly.
|
|
102
97
|
*/
|
|
103
98
|
type DownloadFunction = (options: {
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
url: URL;
|
|
100
|
+
isUrlSupportedByModel: boolean;
|
|
106
101
|
}[]) => PromiseLike<({
|
|
107
|
-
|
|
108
|
-
|
|
102
|
+
data: Uint8Array;
|
|
103
|
+
mediaType: string | undefined;
|
|
109
104
|
} | null)[]>;
|
|
110
105
|
/**
|
|
111
106
|
* Generation settings that can be passed to the model.
|
|
112
107
|
* These map directly to LanguageModelV4CallOptions.
|
|
113
108
|
*/
|
|
114
109
|
interface GenerationSettings {
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Maximum number of tokens to generate.
|
|
112
|
+
*/
|
|
113
|
+
maxOutputTokens?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Temperature setting. The range depends on the provider and model.
|
|
116
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
|
117
|
+
*/
|
|
118
|
+
temperature?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Nucleus sampling. This is a number between 0 and 1.
|
|
121
|
+
* E.g. 0.1 would mean that only tokens with the top 10% probability mass are considered.
|
|
122
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
|
123
|
+
*/
|
|
124
|
+
topP?: number;
|
|
125
|
+
/**
|
|
126
|
+
* Only sample from the top K options for each subsequent token.
|
|
127
|
+
* Used to remove "long tail" low probability responses.
|
|
128
|
+
* Recommended for advanced use cases only. You usually only need to use temperature.
|
|
129
|
+
*/
|
|
130
|
+
topK?: number;
|
|
131
|
+
/**
|
|
132
|
+
* Presence penalty setting. It affects the likelihood of the model to
|
|
133
|
+
* repeat information that is already in the prompt.
|
|
134
|
+
* The presence penalty is a number between -1 (increase repetition)
|
|
135
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
|
136
|
+
*/
|
|
137
|
+
presencePenalty?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Frequency penalty setting. It affects the likelihood of the model
|
|
140
|
+
* to repeatedly use the same words or phrases.
|
|
141
|
+
* The frequency penalty is a number between -1 (increase repetition)
|
|
142
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
|
143
|
+
*/
|
|
144
|
+
frequencyPenalty?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Stop sequences. If set, the model will stop generating text when one of the stop sequences is generated.
|
|
147
|
+
* Providers may have limits on the number of stop sequences.
|
|
148
|
+
*/
|
|
149
|
+
stopSequences?: string[];
|
|
150
|
+
/**
|
|
151
|
+
* The seed (integer) to use for random sampling. If set and supported
|
|
152
|
+
* by the model, calls will generate deterministic results.
|
|
153
|
+
*/
|
|
154
|
+
seed?: number;
|
|
155
|
+
/**
|
|
156
|
+
* Maximum number of retries for retryable model call failures. Set to 0 to disable retries.
|
|
157
|
+
* @default 2
|
|
158
|
+
*/
|
|
159
|
+
maxRetries?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Abort signal for cancelling the operation.
|
|
162
|
+
*/
|
|
163
|
+
abortSignal?: AbortSignal;
|
|
164
|
+
/**
|
|
165
|
+
* Additional HTTP headers to be sent with the request.
|
|
166
|
+
* Only applicable for HTTP-based providers.
|
|
167
|
+
*/
|
|
168
|
+
headers?: Record<string, string | undefined>;
|
|
169
|
+
/**
|
|
170
|
+
* Reasoning effort level for the model. Controls how much reasoning
|
|
171
|
+
* the model performs before generating a response.
|
|
172
|
+
*/
|
|
173
|
+
reasoning?: LanguageModelV4CallOptions['reasoning'];
|
|
174
|
+
/**
|
|
175
|
+
* Additional provider-specific options. They are passed through
|
|
176
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
177
|
+
* functionality that can be fully encapsulated in the provider.
|
|
178
|
+
*/
|
|
179
|
+
providerOptions?: ProviderOptions;
|
|
185
180
|
}
|
|
186
181
|
/**
|
|
187
182
|
* Information passed to the prepareStep callback.
|
|
188
183
|
*/
|
|
189
184
|
interface PrepareStepInfo<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context> {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
185
|
+
/**
|
|
186
|
+
* The current model configuration (string or function).
|
|
187
|
+
* The function should return a LanguageModelV4 instance.
|
|
188
|
+
*/
|
|
189
|
+
model: LanguageModel;
|
|
190
|
+
/**
|
|
191
|
+
* The initial instructions passed to the stream.
|
|
192
|
+
*/
|
|
193
|
+
initialInstructions: Instructions | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* The initial messages passed to the stream.
|
|
196
|
+
*/
|
|
197
|
+
initialMessages: Array<ModelMessage>;
|
|
198
|
+
/**
|
|
199
|
+
* The current step number (0-indexed).
|
|
200
|
+
*/
|
|
201
|
+
stepNumber: number;
|
|
202
|
+
/**
|
|
203
|
+
* All previous steps with their results.
|
|
204
|
+
*/
|
|
205
|
+
steps: StepResult<TTools, TRuntimeContext>[];
|
|
206
|
+
/**
|
|
207
|
+
* The messages that will be sent to the model.
|
|
208
|
+
* This is the LanguageModelV4Prompt format used internally.
|
|
209
|
+
*/
|
|
210
|
+
messages: LanguageModelV4Prompt;
|
|
211
|
+
/**
|
|
212
|
+
* The runtime context that flows through the agent loop.
|
|
213
|
+
* Treat the value as immutable; return a new `runtimeContext` from
|
|
214
|
+
* `prepareStep` to update it for the current and subsequent steps.
|
|
215
|
+
*/
|
|
216
|
+
runtimeContext: TRuntimeContext;
|
|
217
|
+
/**
|
|
218
|
+
* Per-tool context, keyed by tool name. Each tool receives only its own
|
|
219
|
+
* validated entry as `context` during execution.
|
|
220
|
+
* Treat the value as immutable; return a new `toolsContext` from
|
|
221
|
+
* `prepareStep` to update it for the current and subsequent steps.
|
|
222
|
+
*/
|
|
223
|
+
toolsContext: InferToolSetContext<TTools>;
|
|
224
|
+
/**
|
|
225
|
+
* The sandbox environment that the step is operating in.
|
|
226
|
+
*/
|
|
227
|
+
experimental_sandbox?: Experimental_SandboxSession;
|
|
233
228
|
}
|
|
234
229
|
/**
|
|
235
230
|
* Return type from the prepareStep callback.
|
|
236
231
|
* All properties are optional - only return the ones you want to override.
|
|
237
232
|
*/
|
|
238
233
|
interface PrepareStepResult<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context> extends Partial<GenerationSettings> {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Override the model for this step.
|
|
236
|
+
*/
|
|
237
|
+
model?: LanguageModel;
|
|
238
|
+
/**
|
|
239
|
+
* Override the system message for this step.
|
|
240
|
+
*/
|
|
241
|
+
system?: string;
|
|
242
|
+
/**
|
|
243
|
+
* Override the messages for this step.
|
|
244
|
+
* Use this for context management or message injection.
|
|
245
|
+
*/
|
|
246
|
+
messages?: LanguageModelV4Prompt;
|
|
247
|
+
/**
|
|
248
|
+
* Override the tool choice for this step.
|
|
249
|
+
*/
|
|
250
|
+
toolChoice?: ToolChoice<ToolSet>;
|
|
251
|
+
/**
|
|
252
|
+
* Override the active tools for this step.
|
|
253
|
+
* Limits the tools that are available for the model to call.
|
|
254
|
+
*/
|
|
255
|
+
activeTools?: ActiveTools<NoInfer<TTools>>;
|
|
256
|
+
/**
|
|
257
|
+
* Updated runtime context for the current and subsequent steps.
|
|
258
|
+
* Returning a value replaces the agent's runtime context.
|
|
259
|
+
*/
|
|
260
|
+
runtimeContext?: TRuntimeContext;
|
|
261
|
+
/**
|
|
262
|
+
* Updated per-tool context for the current and subsequent steps.
|
|
263
|
+
* Returning a value replaces the agent's tools context.
|
|
264
|
+
*/
|
|
265
|
+
toolsContext?: InferToolSetContext<TTools>;
|
|
266
|
+
/**
|
|
267
|
+
* Override the sandbox environment for this step.
|
|
268
|
+
*/
|
|
269
|
+
experimental_sandbox?: Experimental_SandboxSession;
|
|
275
270
|
}
|
|
276
271
|
/**
|
|
277
272
|
* Callback function called before each step in the agent loop.
|
|
@@ -282,24 +277,24 @@ type PrepareStepCallback<TTools extends ToolSet = ToolSet, TRuntimeContext exten
|
|
|
282
277
|
* Options passed to the prepareCall callback.
|
|
283
278
|
*/
|
|
284
279
|
interface PrepareCallOptions<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context> extends Partial<GenerationSettings> {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
280
|
+
model: LanguageModel;
|
|
281
|
+
tools: TTools;
|
|
282
|
+
instructions?: Instructions;
|
|
283
|
+
toolChoice?: ToolChoice<TTools>;
|
|
284
|
+
stopWhen?: StopCondition<NoInfer<TTools>, TRuntimeContext> | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
|
|
285
|
+
activeTools?: ActiveTools<NoInfer<TTools>>;
|
|
286
|
+
experimental_download?: DownloadFunction;
|
|
287
|
+
telemetry?: TelemetryOptions<TRuntimeContext, TTools>;
|
|
288
|
+
/**
|
|
289
|
+
* Runtime context that flows through the agent loop.
|
|
290
|
+
* Treat as immutable; return a new `runtimeContext` to update it for the call.
|
|
291
|
+
*/
|
|
292
|
+
runtimeContext?: TRuntimeContext;
|
|
293
|
+
/**
|
|
294
|
+
* Per-tool context, keyed by tool name.
|
|
295
|
+
*/
|
|
296
|
+
toolsContext?: InferToolSetContext<TTools>;
|
|
297
|
+
messages: ModelMessage[];
|
|
303
298
|
}
|
|
304
299
|
/**
|
|
305
300
|
* Result of the prepareCall callback. All fields are optional —
|
|
@@ -316,227 +311,227 @@ type PrepareCallCallback<TTools extends ToolSet = ToolSet, TRuntimeContext exten
|
|
|
316
311
|
* Configuration options for creating a {@link WorkflowAgent} instance.
|
|
317
312
|
*/
|
|
318
313
|
type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context, OUTPUT = any, PARTIAL_OUTPUT = any> = GenerationSettings & WorkflowAgentToolsContextParameter<TTools> & {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
314
|
+
/**
|
|
315
|
+
* The id of the agent.
|
|
316
|
+
*/
|
|
317
|
+
id?: string;
|
|
318
|
+
/**
|
|
319
|
+
* The model provider to use for the agent.
|
|
320
|
+
*
|
|
321
|
+
* This should be a string compatible with the Vercel AI Gateway (e.g., 'anthropic/claude-opus'),
|
|
322
|
+
* or a LanguageModelV4 instance from a provider.
|
|
323
|
+
*/
|
|
324
|
+
model: LanguageModel;
|
|
325
|
+
/**
|
|
326
|
+
* A set of tools available to the agent.
|
|
327
|
+
* Tools can be implemented as workflow steps for automatic retries and persistence,
|
|
328
|
+
* or as regular workflow-level logic using core library features like sleep() and Hooks.
|
|
329
|
+
*/
|
|
330
|
+
tools?: TTools;
|
|
331
|
+
/**
|
|
332
|
+
* Agent instructions. Can be a string, a SystemModelMessage, or an array of SystemModelMessages.
|
|
333
|
+
* Supports provider-specific options (e.g., caching) when using the SystemModelMessage form.
|
|
334
|
+
*/
|
|
335
|
+
instructions?: Instructions;
|
|
336
|
+
/**
|
|
337
|
+
* Optional system prompt to guide the agent's behavior.
|
|
338
|
+
* @deprecated Use `instructions` instead.
|
|
339
|
+
*/
|
|
340
|
+
system?: string;
|
|
341
|
+
/**
|
|
342
|
+
* The tool choice strategy. Default: 'auto'.
|
|
343
|
+
*/
|
|
344
|
+
toolChoice?: ToolChoice<TTools>;
|
|
345
|
+
/**
|
|
346
|
+
* Optional telemetry configuration.
|
|
347
|
+
*/
|
|
348
|
+
telemetry?: TelemetryOptions<TRuntimeContext, TTools>;
|
|
349
|
+
/**
|
|
350
|
+
* Default runtime context for every stream call on this agent.
|
|
351
|
+
*
|
|
352
|
+
* The runtime context flows through `prepareStep`, lifecycle callbacks,
|
|
353
|
+
* and step results.
|
|
354
|
+
* Treat as immutable; return a new `runtimeContext` from `prepareStep`
|
|
355
|
+
* to update it between steps.
|
|
356
|
+
*
|
|
357
|
+
* In workflow context, keep values serializable so they can cross workflow
|
|
358
|
+
* and step boundaries.
|
|
359
|
+
*
|
|
360
|
+
* Per-stream `runtimeContext` values passed to `stream()` override this default.
|
|
361
|
+
*/
|
|
362
|
+
runtimeContext?: TRuntimeContext;
|
|
363
|
+
/**
|
|
364
|
+
* Default stop condition for the agent loop. When the condition is an array,
|
|
365
|
+
* any of the conditions can be met to stop the generation.
|
|
366
|
+
*
|
|
367
|
+
* Per-stream `stopWhen` values passed to `stream()` override this default.
|
|
368
|
+
*/
|
|
369
|
+
stopWhen?: StopCondition<NoInfer<TTools>, TRuntimeContext> | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
|
|
370
|
+
/**
|
|
371
|
+
* Default set of active tools that limits which tools the model can call,
|
|
372
|
+
* without changing the tool call and result types in the result.
|
|
373
|
+
*
|
|
374
|
+
* Per-stream `activeTools` values passed to `stream()` override this default.
|
|
375
|
+
*/
|
|
376
|
+
activeTools?: ActiveTools<NoInfer<TTools>>;
|
|
377
|
+
/**
|
|
378
|
+
* Default output specification for structured outputs.
|
|
379
|
+
* Use `Output.object({ schema })` for structured output or `Output.text()` for text output.
|
|
380
|
+
*
|
|
381
|
+
* Per-stream `output` values passed to `stream()` override this default.
|
|
382
|
+
*/
|
|
383
|
+
output?: OutputSpecification<OUTPUT, PARTIAL_OUTPUT>;
|
|
384
|
+
/**
|
|
385
|
+
* Default function that attempts to repair a tool call that failed to parse.
|
|
386
|
+
*
|
|
387
|
+
* Per-stream `repairToolCall` values passed to `stream()` override this default.
|
|
388
|
+
*/
|
|
389
|
+
repairToolCall?: ToolCallRepairFunction$1<TTools>;
|
|
390
|
+
/**
|
|
391
|
+
* Default function that attempts to repair a tool call that failed to parse.
|
|
392
|
+
*
|
|
393
|
+
* Per-stream `repairToolCall` values passed to `stream()` override this default.
|
|
394
|
+
*
|
|
395
|
+
* @deprecated Use `repairToolCall` instead.
|
|
396
|
+
*/
|
|
397
|
+
experimental_repairToolCall?: ToolCallRepairFunction$1<TTools>;
|
|
398
|
+
/**
|
|
399
|
+
* Default custom download function to use for URLs.
|
|
400
|
+
*
|
|
401
|
+
* Per-stream `experimental_download` values passed to `stream()` override this default.
|
|
402
|
+
*/
|
|
403
|
+
experimental_download?: DownloadFunction;
|
|
404
|
+
/**
|
|
405
|
+
* Default sandbox environment passed through to tool execution as
|
|
406
|
+
* `experimental_sandbox`.
|
|
407
|
+
*
|
|
408
|
+
* Per-stream `experimental_sandbox` values passed to `stream()` override this default.
|
|
409
|
+
*/
|
|
410
|
+
experimental_sandbox?: Experimental_SandboxSession;
|
|
411
|
+
/**
|
|
412
|
+
* Workflow-safe reference to the environment variable containing the
|
|
413
|
+
* secret for HMAC-signing tool approval requests. When set, the agent signs
|
|
414
|
+
* each approval request and verifies the signature before executing an
|
|
415
|
+
* approved tool replayed from client-supplied message history.
|
|
416
|
+
*
|
|
417
|
+
* Only the environment variable name crosses workflow boundaries. The
|
|
418
|
+
* secret value is read inside signing and verification steps and is never
|
|
419
|
+
* serialized. Per-stream values override this default.
|
|
420
|
+
*/
|
|
421
|
+
experimental_toolApprovalSecret?: WorkflowToolApprovalSecret;
|
|
422
|
+
/**
|
|
423
|
+
* Default callback function called before each step in the agent loop.
|
|
424
|
+
* Use this to modify settings, manage context, or inject messages dynamically
|
|
425
|
+
* for every stream call on this agent instance.
|
|
426
|
+
*
|
|
427
|
+
* Per-stream `prepareStep` values passed to `stream()` override this default.
|
|
428
|
+
*/
|
|
429
|
+
prepareStep?: PrepareStepCallback<TTools, TRuntimeContext>;
|
|
430
|
+
/**
|
|
431
|
+
* Callback function to be called after each step completes.
|
|
432
|
+
*/
|
|
433
|
+
onStepEnd?: WorkflowAgentOnStepEndCallback<TTools, TRuntimeContext>;
|
|
434
|
+
/**
|
|
435
|
+
* Callback function to be called after each step completes.
|
|
436
|
+
*
|
|
437
|
+
* @deprecated Use `onStepEnd` instead.
|
|
438
|
+
*/
|
|
439
|
+
onStepFinish?: WorkflowAgentOnStepFinishCallback<TTools, TRuntimeContext>;
|
|
440
|
+
/**
|
|
441
|
+
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
442
|
+
*/
|
|
443
|
+
onEnd?: WorkflowAgentOnEndCallback<TTools, TRuntimeContext>;
|
|
444
|
+
/**
|
|
445
|
+
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
446
|
+
*
|
|
447
|
+
* @deprecated Use `onEnd` instead.
|
|
448
|
+
*/
|
|
449
|
+
onFinish?: WorkflowAgentOnFinishCallback<TTools, TRuntimeContext>;
|
|
450
|
+
/**
|
|
451
|
+
* Callback called when the agent starts streaming, before any LLM calls.
|
|
452
|
+
*/
|
|
453
|
+
onStart?: WorkflowAgentOnStartCallback<TTools, TRuntimeContext>;
|
|
454
|
+
/**
|
|
455
|
+
* Callback called when the agent starts streaming, before any LLM calls.
|
|
456
|
+
*
|
|
457
|
+
* @deprecated Use `onStart` instead.
|
|
458
|
+
*/
|
|
459
|
+
experimental_onStart?: WorkflowAgentOnStartCallback<TTools, TRuntimeContext>;
|
|
460
|
+
/**
|
|
461
|
+
* Callback called before each step (LLM call) begins.
|
|
462
|
+
*/
|
|
463
|
+
onStepStart?: WorkflowAgentOnStepStartCallback<TTools, TRuntimeContext>;
|
|
464
|
+
/**
|
|
465
|
+
* Callback called before each step (LLM call) begins.
|
|
466
|
+
*
|
|
467
|
+
* @deprecated Use `onStepStart` instead.
|
|
468
|
+
*/
|
|
469
|
+
experimental_onStepStart?: WorkflowAgentOnStepStartCallback<TTools, TRuntimeContext>;
|
|
470
|
+
/**
|
|
471
|
+
* Callback called before a tool's execute function runs.
|
|
472
|
+
*/
|
|
473
|
+
onToolExecutionStart?: WorkflowAgentOnToolExecutionStartCallback<TTools>;
|
|
474
|
+
/**
|
|
475
|
+
* Callback called after a tool execution completes.
|
|
476
|
+
*/
|
|
477
|
+
onToolExecutionEnd?: WorkflowAgentOnToolExecutionEndCallback<TTools>;
|
|
478
|
+
/**
|
|
479
|
+
* Prepare the parameters for the stream call.
|
|
480
|
+
* Called once before the agent loop starts. Use this to transform
|
|
481
|
+
* model, tools, instructions, or other settings based on runtime context.
|
|
482
|
+
*/
|
|
483
|
+
prepareCall?: PrepareCallCallback<TTools, TRuntimeContext>;
|
|
484
|
+
/**
|
|
485
|
+
* Whether to allow system messages inside the `prompt` or `messages` fields.
|
|
486
|
+
* When `false` (the default), system messages in `prompt` or `messages` are
|
|
487
|
+
* rejected to prevent prompt-injection attacks. Set to `true` only when you
|
|
488
|
+
* intentionally interleave system messages with user messages.
|
|
489
|
+
*
|
|
490
|
+
* @default false
|
|
491
|
+
*/
|
|
492
|
+
allowSystemInMessages?: boolean;
|
|
498
493
|
};
|
|
499
494
|
/**
|
|
500
495
|
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
501
496
|
*/
|
|
502
497
|
type WorkflowAgentOnEndCallback<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context, OUTPUT = never> = (event: {
|
|
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
|
-
|
|
498
|
+
/**
|
|
499
|
+
* Details for all steps.
|
|
500
|
+
*/
|
|
501
|
+
readonly steps: StepResult<TTools, TRuntimeContext>[];
|
|
502
|
+
/**
|
|
503
|
+
* The final messages including all tool calls and results.
|
|
504
|
+
*/
|
|
505
|
+
readonly messages: ModelMessage[];
|
|
506
|
+
/**
|
|
507
|
+
* The text output from the last step.
|
|
508
|
+
*/
|
|
509
|
+
readonly text: string;
|
|
510
|
+
/**
|
|
511
|
+
* The finish reason from the last step.
|
|
512
|
+
*/
|
|
513
|
+
readonly finishReason: FinishReason;
|
|
514
|
+
/**
|
|
515
|
+
* The total token usage across all steps.
|
|
516
|
+
*/
|
|
517
|
+
readonly usage: LanguageModelUsage;
|
|
518
|
+
/**
|
|
519
|
+
* The total token usage across all steps.
|
|
520
|
+
*/
|
|
521
|
+
readonly totalUsage: LanguageModelUsage;
|
|
522
|
+
/**
|
|
523
|
+
* The runtime context at the end of the agent loop.
|
|
524
|
+
*/
|
|
525
|
+
readonly runtimeContext: TRuntimeContext;
|
|
526
|
+
/**
|
|
527
|
+
* The per-tool context at the end of the agent loop.
|
|
528
|
+
*/
|
|
529
|
+
readonly toolsContext: InferToolSetContext<TTools>;
|
|
530
|
+
/**
|
|
531
|
+
* The generated structured output. It uses the `output` specification.
|
|
532
|
+
* Only available when `output` is specified.
|
|
533
|
+
*/
|
|
534
|
+
readonly output: OUTPUT;
|
|
540
535
|
}) => PromiseLike<void> | void;
|
|
541
536
|
/**
|
|
542
537
|
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
@@ -548,53 +543,51 @@ type WorkflowAgentOnFinishCallback<TTools extends ToolSet = ToolSet, TRuntimeCon
|
|
|
548
543
|
* Callback that is invoked when an error occurs during streaming.
|
|
549
544
|
*/
|
|
550
545
|
type WorkflowAgentOnErrorCallback = (event: {
|
|
551
|
-
|
|
546
|
+
error: unknown;
|
|
552
547
|
}) => PromiseLike<void> | void;
|
|
553
548
|
/**
|
|
554
549
|
* Callback that is set using the `onAbort` option.
|
|
555
550
|
*/
|
|
556
551
|
type WorkflowAgentOnAbortCallback<TTools extends ToolSet = ToolSet> = (event: {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
552
|
+
/**
|
|
553
|
+
* Details for all previously finished steps.
|
|
554
|
+
*/
|
|
555
|
+
readonly steps: StepResult<TTools, any>[];
|
|
561
556
|
}) => PromiseLike<void> | void;
|
|
562
557
|
/**
|
|
563
558
|
* Callback that is called when the agent starts streaming, before any LLM calls.
|
|
564
559
|
*/
|
|
565
560
|
type WorkflowAgentOnStartCallback<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context> = (event: {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
561
|
+
/** The model being used */
|
|
562
|
+
readonly model: LanguageModel;
|
|
563
|
+
/** The messages being sent */
|
|
564
|
+
readonly messages: ModelMessage[];
|
|
565
|
+
/** Shared runtime context for this agent loop */
|
|
566
|
+
readonly runtimeContext: TRuntimeContext;
|
|
567
|
+
/** Per-tool context map for this agent loop */
|
|
568
|
+
readonly toolsContext: InferToolSetContext<TTools>;
|
|
574
569
|
}) => PromiseLike<void> | void;
|
|
575
570
|
/**
|
|
576
571
|
* Callback that is called before each step (LLM call) begins.
|
|
577
572
|
*/
|
|
578
573
|
type WorkflowAgentOnStepStartCallback<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context> = (event: {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
574
|
+
/** The current step number (0-based) */
|
|
575
|
+
readonly stepNumber: number;
|
|
576
|
+
/** The model being used for this step */
|
|
577
|
+
readonly model: LanguageModel;
|
|
578
|
+
/** The messages being sent for this step */
|
|
579
|
+
readonly messages: ModelMessage[];
|
|
580
|
+
/** Results from all previously finished steps */
|
|
581
|
+
readonly steps: ReadonlyArray<StepResult<TTools, TRuntimeContext>>;
|
|
582
|
+
/** Shared runtime context for this step */
|
|
583
|
+
readonly runtimeContext: TRuntimeContext;
|
|
584
|
+
/** Per-tool context map for this step */
|
|
585
|
+
readonly toolsContext: InferToolSetContext<TTools>;
|
|
591
586
|
}) => PromiseLike<void> | void;
|
|
592
|
-
type WorkflowToolContext<TOOL extends ToolSet[keyof ToolSet]> = [
|
|
593
|
-
InferToolContext<TOOL>
|
|
594
|
-
] extends [never] ? undefined : InferToolContext<TOOL>;
|
|
587
|
+
type WorkflowToolContext<TOOL extends ToolSet[keyof ToolSet]> = [InferToolContext<TOOL>] extends [never] ? undefined : InferToolContext<TOOL>;
|
|
595
588
|
type WorkflowToolCall<TTools extends ToolSet, NAME extends keyof TTools> = ToolCall & {
|
|
596
|
-
|
|
597
|
-
|
|
589
|
+
readonly toolName: NAME & string;
|
|
590
|
+
readonly input: InferToolInput<TTools[NAME]>;
|
|
598
591
|
};
|
|
599
592
|
/**
|
|
600
593
|
* Event passed to a WorkflowAgent tool-execution-start callback.
|
|
@@ -604,18 +597,16 @@ type WorkflowToolCall<TTools extends ToolSet, NAME extends keyof TTools> = ToolC
|
|
|
604
597
|
* `Extract` or a user-defined type guard to narrow correlated sibling fields.
|
|
605
598
|
*/
|
|
606
599
|
type WorkflowAgentToolExecutionStartEvent<TTools extends ToolSet = ToolSet> = [ToolSet] extends [TTools] ? {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
} : {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
};
|
|
618
|
-
}[keyof TTools];
|
|
600
|
+
readonly toolCall: ToolCall;
|
|
601
|
+
readonly stepNumber: number;
|
|
602
|
+
readonly messages: ModelMessage[];
|
|
603
|
+
readonly toolContext: unknown;
|
|
604
|
+
} : { [NAME in keyof TTools]: {
|
|
605
|
+
readonly toolCall: WorkflowToolCall<TTools, NAME>;
|
|
606
|
+
readonly stepNumber: number;
|
|
607
|
+
readonly messages: ModelMessage[];
|
|
608
|
+
readonly toolContext: WorkflowToolContext<TTools[NAME]>;
|
|
609
|
+
}; }[keyof TTools];
|
|
619
610
|
/**
|
|
620
611
|
* Callback that is called before a tool's execute function runs.
|
|
621
612
|
*/
|
|
@@ -629,44 +620,42 @@ type WorkflowAgentOnToolExecutionStartCallback<TTools extends ToolSet = ToolSet>
|
|
|
629
620
|
* correlated sibling fields by tool name.
|
|
630
621
|
*/
|
|
631
622
|
type WorkflowAgentToolExecutionEndEvent<TTools extends ToolSet = ToolSet> = [ToolSet] extends [TTools] ? {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
623
|
+
readonly toolCall: ToolCall;
|
|
624
|
+
readonly stepNumber: number;
|
|
625
|
+
readonly durationMs: number;
|
|
626
|
+
readonly messages: ModelMessage[];
|
|
627
|
+
readonly toolContext: unknown;
|
|
628
|
+
readonly success: true;
|
|
629
|
+
readonly output: unknown;
|
|
630
|
+
readonly error?: never;
|
|
640
631
|
} | {
|
|
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
|
-
}[keyof TTools];
|
|
632
|
+
readonly toolCall: ToolCall;
|
|
633
|
+
readonly stepNumber: number;
|
|
634
|
+
readonly durationMs: number;
|
|
635
|
+
readonly messages: ModelMessage[];
|
|
636
|
+
readonly toolContext: unknown;
|
|
637
|
+
readonly success: false;
|
|
638
|
+
readonly error: unknown;
|
|
639
|
+
readonly output?: never;
|
|
640
|
+
} : { [NAME in keyof TTools]: {
|
|
641
|
+
readonly toolCall: WorkflowToolCall<TTools, NAME>;
|
|
642
|
+
readonly stepNumber: number;
|
|
643
|
+
readonly durationMs: number;
|
|
644
|
+
readonly messages: ModelMessage[];
|
|
645
|
+
readonly toolContext: WorkflowToolContext<TTools[NAME]>;
|
|
646
|
+
readonly success: true;
|
|
647
|
+
readonly output: InferToolOutput<TTools[NAME]>;
|
|
648
|
+
readonly error?: never;
|
|
649
|
+
} | {
|
|
650
|
+
readonly toolCall: WorkflowToolCall<TTools, NAME>;
|
|
651
|
+
readonly stepNumber: number;
|
|
652
|
+
readonly durationMs: number;
|
|
653
|
+
readonly messages: ModelMessage[];
|
|
654
|
+
readonly toolContext: WorkflowToolContext<TTools[NAME]>;
|
|
655
|
+
readonly success: false;
|
|
656
|
+
readonly error: unknown;
|
|
657
|
+
readonly output?: never;
|
|
658
|
+
}; }[keyof TTools];
|
|
670
659
|
/**
|
|
671
660
|
* Callback that is called after a tool execution completes.
|
|
672
661
|
* Uses a discriminated union pattern: check `success` to determine
|
|
@@ -677,356 +666,356 @@ type WorkflowAgentOnToolExecutionEndCallback<TTools extends ToolSet = ToolSet> =
|
|
|
677
666
|
* Options for the {@link WorkflowAgent.stream} method.
|
|
678
667
|
*/
|
|
679
668
|
type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context, OUTPUT = never, PARTIAL_OUTPUT = never> = Partial<GenerationSettings> & ({
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
669
|
+
/**
|
|
670
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
671
|
+
*
|
|
672
|
+
* You can either use `prompt` or `messages` but not both.
|
|
673
|
+
*/
|
|
674
|
+
prompt: string | Array<ModelMessage>;
|
|
675
|
+
/**
|
|
676
|
+
* A list of messages.
|
|
677
|
+
*
|
|
678
|
+
* You can either use `prompt` or `messages` but not both.
|
|
679
|
+
*/
|
|
680
|
+
messages?: never;
|
|
692
681
|
} | {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
682
|
+
/**
|
|
683
|
+
* The conversation messages to process. Should follow the AI SDK's ModelMessage format.
|
|
684
|
+
*
|
|
685
|
+
* You can either use `prompt` or `messages` but not both.
|
|
686
|
+
*/
|
|
687
|
+
messages: Array<ModelMessage>;
|
|
688
|
+
/**
|
|
689
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
690
|
+
*
|
|
691
|
+
* You can either use `prompt` or `messages` but not both.
|
|
692
|
+
*/
|
|
693
|
+
prompt?: never;
|
|
705
694
|
}) & {
|
|
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
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
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
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
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
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
695
|
+
/**
|
|
696
|
+
* Instructions override for this stream call.
|
|
697
|
+
*/
|
|
698
|
+
instructions?: Instructions;
|
|
699
|
+
/**
|
|
700
|
+
* Optional system prompt override.
|
|
701
|
+
*
|
|
702
|
+
* @deprecated Use `instructions` instead.
|
|
703
|
+
*/
|
|
704
|
+
system?: string;
|
|
705
|
+
/**
|
|
706
|
+
* A WritableStream that receives raw LanguageModelV4StreamPart chunks in real-time
|
|
707
|
+
* as the model generates them. This enables streaming to the client without
|
|
708
|
+
* coupling WorkflowAgent to UIMessageChunk format.
|
|
709
|
+
*
|
|
710
|
+
* Convert to UIMessageChunks at the response boundary using
|
|
711
|
+
* `createUIMessageChunkTransform()` from `@ai-sdk/workflow`.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* ```typescript
|
|
715
|
+
* // In the workflow:
|
|
716
|
+
* await agent.stream({
|
|
717
|
+
* messages,
|
|
718
|
+
* writable: getWritable<ModelCallStreamPart>(),
|
|
719
|
+
* });
|
|
720
|
+
*
|
|
721
|
+
* // In the route handler:
|
|
722
|
+
* return createUIMessageStreamResponse({
|
|
723
|
+
* stream: run.readable.pipeThrough(createModelCallToUIChunkTransform()),
|
|
724
|
+
* });
|
|
725
|
+
* ```
|
|
726
|
+
*/
|
|
727
|
+
writable?: WritableStream<ModelCallStreamPart<ToolSet>>;
|
|
728
|
+
/**
|
|
729
|
+
* Condition for stopping the generation when there are tool results in the last step.
|
|
730
|
+
* When the condition is an array, any of the conditions can be met to stop the generation.
|
|
731
|
+
*/
|
|
732
|
+
stopWhen?: StopCondition<NoInfer<TTools>, TRuntimeContext> | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
|
|
733
|
+
/**
|
|
734
|
+
* The tool choice strategy. Default: 'auto'.
|
|
735
|
+
* Overrides the toolChoice from the constructor if provided.
|
|
736
|
+
*/
|
|
737
|
+
toolChoice?: ToolChoice<TTools>;
|
|
738
|
+
/**
|
|
739
|
+
* Limits the tools that are available for the model to call without
|
|
740
|
+
* changing the tool call and result types in the result.
|
|
741
|
+
*/
|
|
742
|
+
activeTools?: ActiveTools<NoInfer<TTools>>;
|
|
743
|
+
/**
|
|
744
|
+
* Optional telemetry configuration.
|
|
745
|
+
*/
|
|
746
|
+
telemetry?: TelemetryOptions<TRuntimeContext, TTools>;
|
|
747
|
+
/**
|
|
748
|
+
* Runtime context that flows through the agent loop.
|
|
749
|
+
*
|
|
750
|
+
* Treat as immutable; return a new `runtimeContext` from `prepareStep`
|
|
751
|
+
* to update it between steps.
|
|
752
|
+
*
|
|
753
|
+
* In workflow context, keep values serializable so they can cross workflow
|
|
754
|
+
* and step boundaries.
|
|
755
|
+
*
|
|
756
|
+
* Overrides the constructor-level `runtimeContext` if provided.
|
|
757
|
+
*/
|
|
758
|
+
runtimeContext?: TRuntimeContext;
|
|
759
|
+
/**
|
|
760
|
+
* Per-tool context, keyed by tool name. Each tool receives only its own
|
|
761
|
+
* validated entry as `context` during execution. Tools that declare a
|
|
762
|
+
* `contextSchema` validate their entry against the schema.
|
|
763
|
+
*
|
|
764
|
+
* In workflow context, keep values serializable so they can cross workflow
|
|
765
|
+
* and step boundaries.
|
|
766
|
+
*
|
|
767
|
+
* Overrides the constructor-level `toolsContext` if provided.
|
|
768
|
+
*/
|
|
769
|
+
toolsContext?: InferToolSetContext<TTools>;
|
|
770
|
+
/**
|
|
771
|
+
* Optional specification for parsing structured outputs from the LLM response.
|
|
772
|
+
* Use `Output.object({ schema })` for structured output or `Output.text()` for text output.
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```typescript
|
|
776
|
+
* import { Output } from '@workflow/ai';
|
|
777
|
+
* import { z } from 'zod';
|
|
778
|
+
*
|
|
779
|
+
* const result = await agent.stream({
|
|
780
|
+
* messages: [...],
|
|
781
|
+
* writable: getWritable(),
|
|
782
|
+
* output: Output.object({
|
|
783
|
+
* schema: z.object({
|
|
784
|
+
* sentiment: z.enum(['positive', 'negative', 'neutral']),
|
|
785
|
+
* confidence: z.number(),
|
|
786
|
+
* }),
|
|
787
|
+
* }),
|
|
788
|
+
* });
|
|
789
|
+
*
|
|
790
|
+
* console.log(result.output); // { sentiment: 'positive', confidence: 0.95 }
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
output?: OutputSpecification<OUTPUT, PARTIAL_OUTPUT>;
|
|
794
|
+
/**
|
|
795
|
+
* Whether to include raw chunks from the provider in the stream.
|
|
796
|
+
* When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
|
|
797
|
+
* This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
|
|
798
|
+
* Defaults to false.
|
|
799
|
+
*/
|
|
800
|
+
includeRawChunks?: boolean;
|
|
801
|
+
/**
|
|
802
|
+
* A function that attempts to repair a tool call that failed to parse.
|
|
803
|
+
*/
|
|
804
|
+
repairToolCall?: ToolCallRepairFunction$1<TTools>;
|
|
805
|
+
/**
|
|
806
|
+
* A function that attempts to repair a tool call that failed to parse.
|
|
807
|
+
*
|
|
808
|
+
* @deprecated Use `repairToolCall` instead.
|
|
809
|
+
*/
|
|
810
|
+
experimental_repairToolCall?: ToolCallRepairFunction$1<TTools>;
|
|
811
|
+
/**
|
|
812
|
+
* Optional stream transformations.
|
|
813
|
+
* They are applied in the order they are provided.
|
|
814
|
+
* The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
815
|
+
*/
|
|
816
|
+
experimental_transform?: StreamTextTransform<TTools> | Array<StreamTextTransform<TTools>>;
|
|
817
|
+
/**
|
|
818
|
+
* Custom download function to use for URLs.
|
|
819
|
+
* By default, files are downloaded if the model does not support the URL for the given media type.
|
|
820
|
+
*/
|
|
821
|
+
experimental_download?: DownloadFunction;
|
|
822
|
+
/**
|
|
823
|
+
* Sandbox environment passed through to tool execution as
|
|
824
|
+
* `experimental_sandbox`. Overrides the constructor-level value if provided.
|
|
825
|
+
*/
|
|
826
|
+
experimental_sandbox?: Experimental_SandboxSession;
|
|
827
|
+
/**
|
|
828
|
+
* Workflow-safe reference to the environment variable containing the
|
|
829
|
+
* secret for HMAC-signing tool approval requests. When set, the agent signs
|
|
830
|
+
* each approval request and verifies the signature before executing an
|
|
831
|
+
* approved tool replayed from client-supplied message history.
|
|
832
|
+
*
|
|
833
|
+
* Only the environment variable name crosses workflow boundaries. The
|
|
834
|
+
* secret value is read inside signing and verification steps and is never
|
|
835
|
+
* serialized. Overrides the constructor-level value if provided.
|
|
836
|
+
*/
|
|
837
|
+
experimental_toolApprovalSecret?: WorkflowToolApprovalSecret;
|
|
838
|
+
/**
|
|
839
|
+
* Callback function to be called after each step completes.
|
|
840
|
+
*/
|
|
841
|
+
onStepEnd?: WorkflowAgentOnStepEndCallback<TTools, TRuntimeContext>;
|
|
842
|
+
/**
|
|
843
|
+
* Callback function to be called after each step completes.
|
|
844
|
+
*
|
|
845
|
+
* @deprecated Use `onStepEnd` instead.
|
|
846
|
+
*/
|
|
847
|
+
onStepFinish?: WorkflowAgentOnStepFinishCallback<TTools, TRuntimeContext>;
|
|
848
|
+
/**
|
|
849
|
+
* Callback that is invoked when an error occurs during streaming.
|
|
850
|
+
* You can use it to log errors.
|
|
851
|
+
*/
|
|
852
|
+
onError?: WorkflowAgentOnErrorCallback;
|
|
853
|
+
/**
|
|
854
|
+
* Callback that is called when the LLM response and all request tool executions
|
|
855
|
+
* (for tools that have an `execute` function) are finished.
|
|
856
|
+
*/
|
|
857
|
+
onEnd?: WorkflowAgentOnEndCallback<TTools, TRuntimeContext, OUTPUT>;
|
|
858
|
+
/**
|
|
859
|
+
* Callback that is called when the LLM response and all request tool executions
|
|
860
|
+
* (for tools that have an `execute` function) are finished.
|
|
861
|
+
*
|
|
862
|
+
* @deprecated Use `onEnd` instead.
|
|
863
|
+
*/
|
|
864
|
+
onFinish?: WorkflowAgentOnFinishCallback<TTools, TRuntimeContext, OUTPUT>;
|
|
865
|
+
/**
|
|
866
|
+
* Callback that is called when the operation is aborted.
|
|
867
|
+
*/
|
|
868
|
+
onAbort?: WorkflowAgentOnAbortCallback<TTools>;
|
|
869
|
+
/**
|
|
870
|
+
* Callback called when the agent starts streaming, before any LLM calls.
|
|
871
|
+
*/
|
|
872
|
+
onStart?: WorkflowAgentOnStartCallback<TTools, TRuntimeContext>;
|
|
873
|
+
/**
|
|
874
|
+
* Callback called when the agent starts streaming, before any LLM calls.
|
|
875
|
+
*
|
|
876
|
+
* @deprecated Use `onStart` instead.
|
|
877
|
+
*/
|
|
878
|
+
experimental_onStart?: WorkflowAgentOnStartCallback<TTools, TRuntimeContext>;
|
|
879
|
+
/**
|
|
880
|
+
* Callback called before each step (LLM call) begins.
|
|
881
|
+
*/
|
|
882
|
+
onStepStart?: WorkflowAgentOnStepStartCallback<TTools, TRuntimeContext>;
|
|
883
|
+
/**
|
|
884
|
+
* Callback called before each step (LLM call) begins.
|
|
885
|
+
*
|
|
886
|
+
* @deprecated Use `onStepStart` instead.
|
|
887
|
+
*/
|
|
888
|
+
experimental_onStepStart?: WorkflowAgentOnStepStartCallback<TTools, TRuntimeContext>;
|
|
889
|
+
/**
|
|
890
|
+
* Callback called before a tool's execute function runs.
|
|
891
|
+
*/
|
|
892
|
+
onToolExecutionStart?: WorkflowAgentOnToolExecutionStartCallback<TTools>;
|
|
893
|
+
/**
|
|
894
|
+
* Callback called after a tool execution completes.
|
|
895
|
+
*/
|
|
896
|
+
onToolExecutionEnd?: WorkflowAgentOnToolExecutionEndCallback<TTools>;
|
|
897
|
+
/**
|
|
898
|
+
* Callback function called before each step in the agent loop.
|
|
899
|
+
* Use this to modify settings, manage context, or inject messages dynamically.
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* ```typescript
|
|
903
|
+
* prepareStep: async ({ messages, stepNumber }) => {
|
|
904
|
+
* // Inject messages from a queue
|
|
905
|
+
* const queuedMessages = await getQueuedMessages();
|
|
906
|
+
* if (queuedMessages.length > 0) {
|
|
907
|
+
* return {
|
|
908
|
+
* messages: [...messages, ...queuedMessages],
|
|
909
|
+
* };
|
|
910
|
+
* }
|
|
911
|
+
* return {};
|
|
912
|
+
* }
|
|
913
|
+
* ```
|
|
914
|
+
*/
|
|
915
|
+
prepareStep?: PrepareStepCallback<TTools, TRuntimeContext>;
|
|
916
|
+
/**
|
|
917
|
+
* Timeout in milliseconds for the stream operation.
|
|
918
|
+
* When specified, creates an AbortSignal that will abort the operation after the given time.
|
|
919
|
+
* If both `timeout` and `abortSignal` are provided, whichever triggers first will abort.
|
|
920
|
+
*/
|
|
921
|
+
timeout?: number;
|
|
922
|
+
/**
|
|
923
|
+
* Whether to send a 'finish' chunk to the writable stream when streaming completes.
|
|
924
|
+
* @default true
|
|
925
|
+
*/
|
|
926
|
+
sendFinish?: boolean;
|
|
927
|
+
/**
|
|
928
|
+
* Whether to prevent the writable stream from being closed after streaming completes.
|
|
929
|
+
* @default false
|
|
930
|
+
*/
|
|
931
|
+
preventClose?: boolean;
|
|
943
932
|
};
|
|
944
933
|
/**
|
|
945
934
|
* A tool call made by the model. Matches the AI SDK's tool call shape.
|
|
946
935
|
*/
|
|
947
936
|
interface ToolCall {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
937
|
+
/** Discriminator for content part arrays */
|
|
938
|
+
type: 'tool-call';
|
|
939
|
+
/** The unique identifier of the tool call */
|
|
940
|
+
toolCallId: string;
|
|
941
|
+
/** The name of the tool that was called */
|
|
942
|
+
toolName: string;
|
|
943
|
+
/** The parsed input arguments for the tool call */
|
|
944
|
+
input: unknown;
|
|
956
945
|
}
|
|
957
946
|
/**
|
|
958
947
|
* A tool result from executing a tool. Matches the AI SDK's tool result shape.
|
|
959
948
|
*/
|
|
960
949
|
interface ToolResult {
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
950
|
+
/** Discriminator for content part arrays */
|
|
951
|
+
type: 'tool-result';
|
|
952
|
+
/** The tool call ID this result corresponds to */
|
|
953
|
+
toolCallId: string;
|
|
954
|
+
/** The name of the tool that was executed */
|
|
955
|
+
toolName: string;
|
|
956
|
+
/** The parsed input arguments that were passed to the tool */
|
|
957
|
+
input: unknown;
|
|
958
|
+
/** The output produced by the tool */
|
|
959
|
+
output: unknown;
|
|
971
960
|
}
|
|
972
961
|
/**
|
|
973
962
|
* Result of the WorkflowAgent.stream method.
|
|
974
963
|
*/
|
|
975
964
|
interface WorkflowAgentStreamResult<TTools extends ToolSet = ToolSet, OUTPUT = never> {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
965
|
+
/**
|
|
966
|
+
* The final messages including all tool calls and results.
|
|
967
|
+
*/
|
|
968
|
+
messages: ModelMessage[];
|
|
969
|
+
/**
|
|
970
|
+
* Details for all steps.
|
|
971
|
+
*/
|
|
972
|
+
steps: StepResult<TTools, any>[];
|
|
973
|
+
/**
|
|
974
|
+
* The tool calls from the last step.
|
|
975
|
+
* Includes all tool calls regardless of whether they were executed.
|
|
976
|
+
*
|
|
977
|
+
* When the agent stops because a tool without an `execute` function was called,
|
|
978
|
+
* this array will contain those calls. Compare with `toolResults` to find
|
|
979
|
+
* unresolved tool calls that need client-side handling:
|
|
980
|
+
*
|
|
981
|
+
* ```ts
|
|
982
|
+
* const unresolved = result.toolCalls.filter(
|
|
983
|
+
* tc => !result.toolResults.some(tr => tr.toolCallId === tc.toolCallId)
|
|
984
|
+
* );
|
|
985
|
+
* ```
|
|
986
|
+
*
|
|
987
|
+
* This matches the AI SDK's `GenerateTextResult.toolCalls` behavior.
|
|
988
|
+
*/
|
|
989
|
+
toolCalls: ToolCall[];
|
|
990
|
+
/**
|
|
991
|
+
* The tool results from the last step.
|
|
992
|
+
* Only includes results for tools that were actually executed (server-side or provider-executed).
|
|
993
|
+
* Tools without an `execute` function will NOT have entries here.
|
|
994
|
+
*
|
|
995
|
+
* This matches the AI SDK's `GenerateTextResult.toolResults` behavior.
|
|
996
|
+
*/
|
|
997
|
+
toolResults: ToolResult[];
|
|
998
|
+
/**
|
|
999
|
+
* The finish reason from the last step.
|
|
1000
|
+
*/
|
|
1001
|
+
finishReason: FinishReason;
|
|
1002
|
+
/**
|
|
1003
|
+
* The original value from a model stream error part.
|
|
1004
|
+
*
|
|
1005
|
+
* This property is present when the model emitted an error part, including
|
|
1006
|
+
* when the supplied value is `undefined`. Check with `'error' in result` to
|
|
1007
|
+
* distinguish that case from a result without a model stream error.
|
|
1008
|
+
*/
|
|
1009
|
+
error?: unknown;
|
|
1010
|
+
/**
|
|
1011
|
+
* The total token usage across all steps.
|
|
1012
|
+
*/
|
|
1013
|
+
totalUsage: LanguageModelUsage;
|
|
1014
|
+
/**
|
|
1015
|
+
* The generated structured output. It uses the `output` specification.
|
|
1016
|
+
* Only available when `output` is specified.
|
|
1017
|
+
*/
|
|
1018
|
+
output: OUTPUT;
|
|
1030
1019
|
}
|
|
1031
1020
|
/**
|
|
1032
1021
|
* A class for building durable AI agents within workflows.
|
|
@@ -1055,48 +1044,49 @@ interface WorkflowAgentStreamResult<TTools extends ToolSet = ToolSet, OUTPUT = n
|
|
|
1055
1044
|
* });
|
|
1056
1045
|
* ```
|
|
1057
1046
|
*/
|
|
1058
|
-
declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context, OUTPUT = any, PARTIAL_OUTPUT = any> {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
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
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1047
|
+
export declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context, OUTPUT = any, PARTIAL_OUTPUT = any> {
|
|
1048
|
+
/**
|
|
1049
|
+
* The id of the agent.
|
|
1050
|
+
*/
|
|
1051
|
+
readonly id: string | undefined;
|
|
1052
|
+
private model;
|
|
1053
|
+
/**
|
|
1054
|
+
* The tool set configured for this agent.
|
|
1055
|
+
*/
|
|
1056
|
+
readonly tools: TBaseTools;
|
|
1057
|
+
private instructions?;
|
|
1058
|
+
private generationSettings;
|
|
1059
|
+
private toolChoice?;
|
|
1060
|
+
private telemetry?;
|
|
1061
|
+
private runtimeContext?;
|
|
1062
|
+
private toolsContext?;
|
|
1063
|
+
private stopWhen?;
|
|
1064
|
+
private activeTools?;
|
|
1065
|
+
private output?;
|
|
1066
|
+
private repairToolCall?;
|
|
1067
|
+
private experimentalDownload?;
|
|
1068
|
+
private experimentalSandbox?;
|
|
1069
|
+
private experimentalToolApprovalSecret?;
|
|
1070
|
+
private prepareStep?;
|
|
1071
|
+
private allowSystemInMessages;
|
|
1072
|
+
private constructorOnStepEnd?;
|
|
1073
|
+
private constructorOnEnd?;
|
|
1074
|
+
private constructorOnStart?;
|
|
1075
|
+
private constructorOnStepStart?;
|
|
1076
|
+
private constructorOnToolExecutionStart?;
|
|
1077
|
+
private constructorOnToolExecutionEnd?;
|
|
1078
|
+
private prepareCall?;
|
|
1079
|
+
constructor(options: WorkflowAgentOptions<TBaseTools, TRuntimeContext, OUTPUT, PARTIAL_OUTPUT>);
|
|
1080
|
+
generate(): void;
|
|
1081
|
+
stream<TTools extends TBaseTools = TBaseTools, TOutput = DefaultWorkflowAgentOutput<OUTPUT>, TPartialOutput = DefaultWorkflowAgentOutput<PARTIAL_OUTPUT>>(options: WorkflowAgentStreamOptions<TTools, TRuntimeContext, TOutput, TPartialOutput>): Promise<WorkflowAgentStreamResult<TTools, TOutput>>;
|
|
1093
1082
|
}
|
|
1094
|
-
|
|
1083
|
+
//#endregion
|
|
1084
|
+
//#region src/to-ui-message-chunk.d.ts
|
|
1095
1085
|
/**
|
|
1096
1086
|
* Convert a single ModelCallStreamPart to a UIMessageChunk.
|
|
1097
1087
|
* Returns undefined for parts that don't map to UI chunks.
|
|
1098
1088
|
*/
|
|
1099
|
-
declare function toUIMessageChunk(part: ModelCallStreamPart<ToolSet>): UIMessageChunk | undefined;
|
|
1089
|
+
export declare function toUIMessageChunk(part: ModelCallStreamPart<ToolSet>): UIMessageChunk | undefined;
|
|
1100
1090
|
/**
|
|
1101
1091
|
* Create a TransformStream that converts ModelCallStreamPart to UIMessageChunk.
|
|
1102
1092
|
* Wraps toUIMessageChunk with start/start-step/finish-step lifecycle chunks.
|
|
@@ -1107,14 +1097,15 @@ declare function toUIMessageChunk(part: ModelCallStreamPart<ToolSet>): UIMessage
|
|
|
1107
1097
|
* message chunks do not have a one-to-one relationship, so a UI chunk index
|
|
1108
1098
|
* must not be used as the source stream's start index.
|
|
1109
1099
|
*/
|
|
1110
|
-
declare function createModelCallToUIChunkTransform({ uiStartIndex
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1100
|
+
export declare function createModelCallToUIChunkTransform({ uiStartIndex }?: {
|
|
1101
|
+
/**
|
|
1102
|
+
* Number of transformed UIMessageChunks to omit from the output.
|
|
1103
|
+
* Must be a non-negative safe integer.
|
|
1104
|
+
*/
|
|
1105
|
+
uiStartIndex?: number;
|
|
1116
1106
|
}): TransformStream<ModelCallStreamPart<ToolSet>, UIMessageChunk>;
|
|
1117
|
-
|
|
1107
|
+
//#endregion
|
|
1108
|
+
//#region src/normalize-ui-message-stream.d.ts
|
|
1118
1109
|
/**
|
|
1119
1110
|
* Normalizes the part framing of a UI message stream so it is always
|
|
1120
1111
|
* well-formed for the AI SDK's stream consumer (`processUIMessageStream`,
|
|
@@ -1165,6 +1156,7 @@ declare function createModelCallToUIChunkTransform({ uiStartIndex, }?: {
|
|
|
1165
1156
|
* @param source the raw UI message chunk stream to normalize.
|
|
1166
1157
|
* @yields the framing-corrected UI message chunks.
|
|
1167
1158
|
*/
|
|
1168
|
-
declare function normalizeUIMessageStreamParts(source: AsyncIterable<UIMessageChunk>): AsyncGenerator<UIMessageChunk>;
|
|
1169
|
-
|
|
1170
|
-
export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type ModelCallStreamPart, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type StreamTextTransform, type TelemetryOptions,
|
|
1159
|
+
export declare function normalizeUIMessageStreamParts(source: AsyncIterable<UIMessageChunk>): AsyncGenerator<UIMessageChunk>;
|
|
1160
|
+
//#endregion
|
|
1161
|
+
export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type ModelCallStreamPart, Output, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextTransform, type TelemetryOptions, type ToolCallRepairFunction, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnEndCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepEndCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolExecutionEndCallback, type WorkflowAgentOnToolExecutionStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, type WorkflowAgentToolExecutionEndEvent, type WorkflowAgentToolExecutionStartEvent, WorkflowChatTransport, type WorkflowChatTransportOptions, type WorkflowToolApprovalSecret };
|
|
1162
|
+
//# sourceMappingURL=index.d.ts.map
|