@ai-sdk/workflow 1.0.0-beta.1 → 1.0.0-beta.10
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 +63 -0
- package/dist/index.d.mts +124 -28
- package/dist/index.mjs +81 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/do-stream-step.ts +6 -22
- package/src/index.ts +4 -3
- package/src/providers/mock.ts +79 -92
- package/src/stream-text-iterator.ts +8 -13
- package/src/workflow-agent.ts +427 -298
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ai@7.0.0-beta.96
|
|
8
|
+
|
|
9
|
+
## 1.0.0-beta.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [c4f4b5f]
|
|
14
|
+
- ai@7.0.0-beta.95
|
|
15
|
+
|
|
16
|
+
## 1.0.0-beta.8
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 0455f24: Enrich WorkflowAgent callback event shapes to align with ToolLoopAgent:
|
|
21
|
+
- Add `stepNumber` to `onToolCallStart` and `onToolCallFinish`
|
|
22
|
+
- Add `steps` (previous step results) to `onStepStart`
|
|
23
|
+
- Adopt discriminated union pattern (`success: true/false`) for `onToolCallFinish`
|
|
24
|
+
- Add `durationMs` to `onToolCallFinish`
|
|
25
|
+
|
|
26
|
+
## 1.0.0-beta.7
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [1582efa]
|
|
31
|
+
- ai@7.0.0-beta.94
|
|
32
|
+
|
|
33
|
+
## 1.0.0-beta.6
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [bc47739]
|
|
38
|
+
- ai@7.0.0-beta.93
|
|
39
|
+
|
|
40
|
+
## 1.0.0-beta.5
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- bf6c17b: Add `id` property to WorkflowAgent for telemetry identification, matching ToolLoopAgent's API surface.
|
|
45
|
+
- 3ca592a: Add `prompt` as an alternative to `messages` in `WorkflowAgent.stream()`, matching the `AgentCallParameters` pattern from ToolLoopAgent.
|
|
46
|
+
- eb49d29: Add constructor-level defaults for `stopWhen`, `activeTools`, `output`, `experimental_repairToolCall`, and `experimental_download` to WorkflowAgent, matching ToolLoopAgent's pattern. Stream-level values override constructor defaults.
|
|
47
|
+
|
|
48
|
+
## 1.0.0-beta.4
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- ai@7.0.0-beta.92
|
|
53
|
+
|
|
54
|
+
## 1.0.0-beta.3
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- 0e462a7: Use `LanguageModel` type for model parameter, aligning with `ToolLoopAgent`. Remove async factory model form. Rename callback types to use `WorkflowAgentOn*` prefix.
|
|
59
|
+
|
|
60
|
+
## 1.0.0-beta.2
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- ai@7.0.0-beta.91
|
|
65
|
+
|
|
3
66
|
## 1.0.0-beta.1
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LanguageModelV4, SharedV4ProviderOptions,
|
|
2
|
-
import { ToolSet, SystemModelMessage, ToolChoice,
|
|
1
|
+
import { LanguageModelV4, SharedV4ProviderOptions, LanguageModelV4CallOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart } from '@ai-sdk/provider';
|
|
2
|
+
import { ToolSet, LanguageModel, SystemModelMessage, ToolChoice, StopCondition, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, StepResult, StreamTextOnStepFinishCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
|
|
3
3
|
export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, ToolCallRepairFunction } from 'ai';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,6 +13,12 @@ export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, To
|
|
|
13
13
|
*/
|
|
14
14
|
type CompatibleLanguageModel = LanguageModelV4;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Callback function to be called after each step completes.
|
|
18
|
+
* Alias for the AI SDK's StreamTextOnStepFinishCallback, using
|
|
19
|
+
* WorkflowAgent-consistent naming.
|
|
20
|
+
*/
|
|
21
|
+
type WorkflowAgentOnStepFinishCallback<TTools extends ToolSet = ToolSet> = StreamTextOnStepFinishCallback<TTools, any>;
|
|
16
22
|
/**
|
|
17
23
|
* Infer the type of the tools of a workflow agent.
|
|
18
24
|
*/
|
|
@@ -181,7 +187,7 @@ interface PrepareStepInfo<TTools extends ToolSet = ToolSet> {
|
|
|
181
187
|
* The current model configuration (string or function).
|
|
182
188
|
* The function should return a LanguageModelV4 instance.
|
|
183
189
|
*/
|
|
184
|
-
model:
|
|
190
|
+
model: LanguageModel;
|
|
185
191
|
/**
|
|
186
192
|
* The current step number (0-indexed).
|
|
187
193
|
*/
|
|
@@ -207,9 +213,8 @@ interface PrepareStepInfo<TTools extends ToolSet = ToolSet> {
|
|
|
207
213
|
interface PrepareStepResult extends Partial<GenerationSettings> {
|
|
208
214
|
/**
|
|
209
215
|
* Override the model for this step.
|
|
210
|
-
* The function should return a LanguageModelV4 instance.
|
|
211
216
|
*/
|
|
212
|
-
model?:
|
|
217
|
+
model?: LanguageModel;
|
|
213
218
|
/**
|
|
214
219
|
* Override the system message for this step.
|
|
215
220
|
*/
|
|
@@ -243,7 +248,7 @@ type PrepareStepCallback<TTools extends ToolSet = ToolSet> = (info: PrepareStepI
|
|
|
243
248
|
* Options passed to the prepareCall callback.
|
|
244
249
|
*/
|
|
245
250
|
interface PrepareCallOptions<TTools extends ToolSet = ToolSet> extends Partial<GenerationSettings> {
|
|
246
|
-
model:
|
|
251
|
+
model: LanguageModel;
|
|
247
252
|
tools: TTools;
|
|
248
253
|
instructions?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
249
254
|
toolChoice?: ToolChoice<TTools>;
|
|
@@ -266,13 +271,17 @@ type PrepareCallCallback<TTools extends ToolSet = ToolSet> = (options: PrepareCa
|
|
|
266
271
|
* Configuration options for creating a {@link WorkflowAgent} instance.
|
|
267
272
|
*/
|
|
268
273
|
interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends GenerationSettings {
|
|
274
|
+
/**
|
|
275
|
+
* The id of the agent.
|
|
276
|
+
*/
|
|
277
|
+
id?: string;
|
|
269
278
|
/**
|
|
270
279
|
* The model provider to use for the agent.
|
|
271
280
|
*
|
|
272
281
|
* This should be a string compatible with the Vercel AI Gateway (e.g., 'anthropic/claude-opus'),
|
|
273
|
-
* or a
|
|
282
|
+
* or a LanguageModelV4 instance from a provider.
|
|
274
283
|
*/
|
|
275
|
-
model:
|
|
284
|
+
model: LanguageModel;
|
|
276
285
|
/**
|
|
277
286
|
* A set of tools available to the agent.
|
|
278
287
|
* Tools can be implemented as workflow steps for automatic retries and persistence,
|
|
@@ -305,6 +314,39 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
|
|
|
305
314
|
* @default undefined
|
|
306
315
|
*/
|
|
307
316
|
experimental_context?: unknown;
|
|
317
|
+
/**
|
|
318
|
+
* Default stop condition for the agent loop. When the condition is an array,
|
|
319
|
+
* any of the conditions can be met to stop the generation.
|
|
320
|
+
*
|
|
321
|
+
* Per-stream `stopWhen` values passed to `stream()` override this default.
|
|
322
|
+
*/
|
|
323
|
+
stopWhen?: StopCondition<NoInfer<ToolSet>, any> | Array<StopCondition<NoInfer<ToolSet>, any>>;
|
|
324
|
+
/**
|
|
325
|
+
* Default set of active tools that limits which tools the model can call,
|
|
326
|
+
* without changing the tool call and result types in the result.
|
|
327
|
+
*
|
|
328
|
+
* Per-stream `activeTools` values passed to `stream()` override this default.
|
|
329
|
+
*/
|
|
330
|
+
activeTools?: Array<keyof NoInfer<TTools>>;
|
|
331
|
+
/**
|
|
332
|
+
* Default output specification for structured outputs.
|
|
333
|
+
* Use `Output.object({ schema })` for structured output or `Output.text()` for text output.
|
|
334
|
+
*
|
|
335
|
+
* Per-stream `output` values passed to `stream()` override this default.
|
|
336
|
+
*/
|
|
337
|
+
output?: OutputSpecification<any, any>;
|
|
338
|
+
/**
|
|
339
|
+
* Default function that attempts to repair a tool call that failed to parse.
|
|
340
|
+
*
|
|
341
|
+
* Per-stream `experimental_repairToolCall` values passed to `stream()` override this default.
|
|
342
|
+
*/
|
|
343
|
+
experimental_repairToolCall?: ToolCallRepairFunction<TTools>;
|
|
344
|
+
/**
|
|
345
|
+
* Default custom download function to use for URLs.
|
|
346
|
+
*
|
|
347
|
+
* Per-stream `experimental_download` values passed to `stream()` override this default.
|
|
348
|
+
*/
|
|
349
|
+
experimental_download?: DownloadFunction;
|
|
308
350
|
/**
|
|
309
351
|
* Default callback function called before each step in the agent loop.
|
|
310
352
|
* Use this to modify settings, manage context, or inject messages dynamically
|
|
@@ -316,11 +358,11 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
|
|
|
316
358
|
/**
|
|
317
359
|
* Callback function to be called after each step completes.
|
|
318
360
|
*/
|
|
319
|
-
onStepFinish?:
|
|
361
|
+
onStepFinish?: WorkflowAgentOnStepFinishCallback<ToolSet>;
|
|
320
362
|
/**
|
|
321
363
|
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
322
364
|
*/
|
|
323
|
-
onFinish?:
|
|
365
|
+
onFinish?: WorkflowAgentOnFinishCallback<ToolSet>;
|
|
324
366
|
/**
|
|
325
367
|
* Callback called when the agent starts streaming, before any LLM calls.
|
|
326
368
|
*/
|
|
@@ -347,7 +389,7 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
|
|
|
347
389
|
/**
|
|
348
390
|
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
349
391
|
*/
|
|
350
|
-
type
|
|
392
|
+
type WorkflowAgentOnFinishCallback<TTools extends ToolSet = ToolSet, OUTPUT = never> = (event: {
|
|
351
393
|
/**
|
|
352
394
|
* Details for all steps.
|
|
353
395
|
*/
|
|
@@ -381,13 +423,13 @@ type StreamTextOnFinishCallback<TTools extends ToolSet = ToolSet, OUTPUT = never
|
|
|
381
423
|
/**
|
|
382
424
|
* Callback that is invoked when an error occurs during streaming.
|
|
383
425
|
*/
|
|
384
|
-
type
|
|
426
|
+
type WorkflowAgentOnErrorCallback = (event: {
|
|
385
427
|
error: unknown;
|
|
386
428
|
}) => PromiseLike<void> | void;
|
|
387
429
|
/**
|
|
388
430
|
* Callback that is set using the `onAbort` option.
|
|
389
431
|
*/
|
|
390
|
-
type
|
|
432
|
+
type WorkflowAgentOnAbortCallback<TTools extends ToolSet = ToolSet> = (event: {
|
|
391
433
|
/**
|
|
392
434
|
* Details for all previously finished steps.
|
|
393
435
|
*/
|
|
@@ -398,20 +440,22 @@ type StreamTextOnAbortCallback<TTools extends ToolSet = ToolSet> = (event: {
|
|
|
398
440
|
*/
|
|
399
441
|
type WorkflowAgentOnStartCallback = (event: {
|
|
400
442
|
/** The model being used */
|
|
401
|
-
readonly model:
|
|
443
|
+
readonly model: LanguageModel;
|
|
402
444
|
/** The messages being sent */
|
|
403
445
|
readonly messages: ModelMessage[];
|
|
404
446
|
}) => PromiseLike<void> | void;
|
|
405
447
|
/**
|
|
406
448
|
* Callback that is called before each step (LLM call) begins.
|
|
407
449
|
*/
|
|
408
|
-
type WorkflowAgentOnStepStartCallback = (event: {
|
|
450
|
+
type WorkflowAgentOnStepStartCallback<TTools extends ToolSet = ToolSet> = (event: {
|
|
409
451
|
/** The current step number (0-based) */
|
|
410
452
|
readonly stepNumber: number;
|
|
411
453
|
/** The model being used for this step */
|
|
412
|
-
readonly model:
|
|
454
|
+
readonly model: LanguageModel;
|
|
413
455
|
/** The messages being sent for this step */
|
|
414
456
|
readonly messages: ModelMessage[];
|
|
457
|
+
/** Results from all previously finished steps */
|
|
458
|
+
readonly steps: ReadonlyArray<StepResult<TTools, any>>;
|
|
415
459
|
}) => PromiseLike<void> | void;
|
|
416
460
|
/**
|
|
417
461
|
* Callback that is called before a tool's execute function runs.
|
|
@@ -419,26 +463,69 @@ type WorkflowAgentOnStepStartCallback = (event: {
|
|
|
419
463
|
type WorkflowAgentOnToolCallStartCallback = (event: {
|
|
420
464
|
/** The tool call being executed */
|
|
421
465
|
readonly toolCall: ToolCall;
|
|
466
|
+
/** The current step number (0-based) */
|
|
467
|
+
readonly stepNumber: number;
|
|
422
468
|
}) => PromiseLike<void> | void;
|
|
423
469
|
/**
|
|
424
470
|
* Callback that is called after a tool execution completes.
|
|
471
|
+
* Uses a discriminated union pattern: check `success` to determine
|
|
472
|
+
* whether `output` or `error` is available.
|
|
425
473
|
*/
|
|
426
474
|
type WorkflowAgentOnToolCallFinishCallback = (event: {
|
|
427
475
|
/** The tool call that was executed */
|
|
428
476
|
readonly toolCall: ToolCall;
|
|
429
|
-
/** The
|
|
430
|
-
readonly
|
|
431
|
-
/**
|
|
432
|
-
readonly
|
|
477
|
+
/** The current step number (0-based) */
|
|
478
|
+
readonly stepNumber: number;
|
|
479
|
+
/** Execution time in milliseconds */
|
|
480
|
+
readonly durationMs: number;
|
|
481
|
+
/** Whether the tool call succeeded */
|
|
482
|
+
readonly success: true;
|
|
483
|
+
/** The tool result */
|
|
484
|
+
readonly output: unknown;
|
|
485
|
+
readonly error?: never;
|
|
486
|
+
} | {
|
|
487
|
+
/** The tool call that was executed */
|
|
488
|
+
readonly toolCall: ToolCall;
|
|
489
|
+
/** The current step number (0-based) */
|
|
490
|
+
readonly stepNumber: number;
|
|
491
|
+
/** Execution time in milliseconds */
|
|
492
|
+
readonly durationMs: number;
|
|
493
|
+
/** Whether the tool call succeeded */
|
|
494
|
+
readonly success: false;
|
|
495
|
+
/** The error that occurred */
|
|
496
|
+
readonly error: unknown;
|
|
497
|
+
readonly output?: never;
|
|
433
498
|
}) => PromiseLike<void> | void;
|
|
434
499
|
/**
|
|
435
500
|
* Options for the {@link WorkflowAgent.stream} method.
|
|
436
501
|
*/
|
|
437
|
-
|
|
502
|
+
type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never> = Partial<GenerationSettings> & ({
|
|
503
|
+
/**
|
|
504
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
505
|
+
*
|
|
506
|
+
* You can either use `prompt` or `messages` but not both.
|
|
507
|
+
*/
|
|
508
|
+
prompt: string | Array<ModelMessage>;
|
|
509
|
+
/**
|
|
510
|
+
* A list of messages.
|
|
511
|
+
*
|
|
512
|
+
* You can either use `prompt` or `messages` but not both.
|
|
513
|
+
*/
|
|
514
|
+
messages?: never;
|
|
515
|
+
} | {
|
|
438
516
|
/**
|
|
439
517
|
* The conversation messages to process. Should follow the AI SDK's ModelMessage format.
|
|
518
|
+
*
|
|
519
|
+
* You can either use `prompt` or `messages` but not both.
|
|
440
520
|
*/
|
|
441
|
-
messages: ModelMessage
|
|
521
|
+
messages: Array<ModelMessage>;
|
|
522
|
+
/**
|
|
523
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
524
|
+
*
|
|
525
|
+
* You can either use `prompt` or `messages` but not both.
|
|
526
|
+
*/
|
|
527
|
+
prompt?: never;
|
|
528
|
+
}) & {
|
|
442
529
|
/**
|
|
443
530
|
* Optional system prompt override. If provided, overrides the system prompt from the constructor.
|
|
444
531
|
*/
|
|
@@ -546,21 +633,21 @@ interface WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, OUTPUT =
|
|
|
546
633
|
/**
|
|
547
634
|
* Callback function to be called after each step completes.
|
|
548
635
|
*/
|
|
549
|
-
onStepFinish?:
|
|
636
|
+
onStepFinish?: WorkflowAgentOnStepFinishCallback<TTools>;
|
|
550
637
|
/**
|
|
551
638
|
* Callback that is invoked when an error occurs during streaming.
|
|
552
639
|
* You can use it to log errors.
|
|
553
640
|
*/
|
|
554
|
-
onError?:
|
|
641
|
+
onError?: WorkflowAgentOnErrorCallback;
|
|
555
642
|
/**
|
|
556
643
|
* Callback that is called when the LLM response and all request tool executions
|
|
557
644
|
* (for tools that have an `execute` function) are finished.
|
|
558
645
|
*/
|
|
559
|
-
onFinish?:
|
|
646
|
+
onFinish?: WorkflowAgentOnFinishCallback<TTools, OUTPUT>;
|
|
560
647
|
/**
|
|
561
648
|
* Callback that is called when the operation is aborted.
|
|
562
649
|
*/
|
|
563
|
-
onAbort?:
|
|
650
|
+
onAbort?: WorkflowAgentOnAbortCallback<TTools>;
|
|
564
651
|
/**
|
|
565
652
|
* Callback called when the agent starts streaming, before any LLM calls.
|
|
566
653
|
*/
|
|
@@ -612,7 +699,7 @@ interface WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, OUTPUT =
|
|
|
612
699
|
* @default false
|
|
613
700
|
*/
|
|
614
701
|
preventClose?: boolean;
|
|
615
|
-
}
|
|
702
|
+
};
|
|
616
703
|
/**
|
|
617
704
|
* A tool call made by the model. Matches the AI SDK's tool call shape.
|
|
618
705
|
*/
|
|
@@ -712,6 +799,10 @@ interface WorkflowAgentStreamResult<TTools extends ToolSet = ToolSet, OUTPUT = n
|
|
|
712
799
|
* ```
|
|
713
800
|
*/
|
|
714
801
|
declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet> {
|
|
802
|
+
/**
|
|
803
|
+
* The id of the agent.
|
|
804
|
+
*/
|
|
805
|
+
readonly id: string | undefined;
|
|
715
806
|
private model;
|
|
716
807
|
/**
|
|
717
808
|
* The tool set configured for this agent.
|
|
@@ -722,6 +813,11 @@ declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet> {
|
|
|
722
813
|
private toolChoice?;
|
|
723
814
|
private telemetry?;
|
|
724
815
|
private experimentalContext;
|
|
816
|
+
private stopWhen?;
|
|
817
|
+
private activeTools?;
|
|
818
|
+
private output?;
|
|
819
|
+
private experimentalRepairToolCall?;
|
|
820
|
+
private experimentalDownload?;
|
|
725
821
|
private prepareStep?;
|
|
726
822
|
private constructorOnStepFinish?;
|
|
727
823
|
private constructorOnFinish?;
|
|
@@ -901,4 +997,4 @@ declare class WorkflowChatTransport<UI_MESSAGE extends UIMessage> implements Cha
|
|
|
901
997
|
private onFinish;
|
|
902
998
|
}
|
|
903
999
|
|
|
904
|
-
export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type
|
|
1000
|
+
export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextTransform, type TelemetrySettings, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolCallFinishCallback, type WorkflowAgentOnToolCallStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, createModelCallToUIChunkTransform, toUIMessageChunk };
|