@ai-sdk/workflow 1.0.0-canary.82 → 1.0.0-canary.83
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 +10 -0
- package/dist/index.d.mts +24 -5
- package/dist/index.mjs +39 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/stream-text-iterator.ts +8 -3
- package/src/workflow-agent.ts +35 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/workflow",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.83",
|
|
4
4
|
"description": "WorkflowAgent for building AI agents with AI SDK",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"ajv": "^8.20.0",
|
|
30
30
|
"@ai-sdk/provider": "4.0.0-canary.18",
|
|
31
31
|
"@ai-sdk/provider-utils": "5.0.0-canary.46",
|
|
32
|
-
"ai": "7.0.0-canary.
|
|
32
|
+
"ai": "7.0.0-canary.166"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "22.19.19",
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
GenerationSettings,
|
|
27
27
|
PrepareStepCallback,
|
|
28
28
|
WorkflowAgentOnErrorCallback,
|
|
29
|
+
WorkflowAgentOnStepEndCallback,
|
|
29
30
|
WorkflowAgentOnStepFinishCallback,
|
|
30
31
|
TelemetryOptions,
|
|
31
32
|
WorkflowAgentOnStepStartCallback,
|
|
@@ -60,6 +61,7 @@ export async function* streamTextIterator({
|
|
|
60
61
|
writable,
|
|
61
62
|
model,
|
|
62
63
|
stopConditions,
|
|
64
|
+
onStepEnd,
|
|
63
65
|
onStepFinish,
|
|
64
66
|
onStepStart,
|
|
65
67
|
onError,
|
|
@@ -78,6 +80,8 @@ export async function* streamTextIterator({
|
|
|
78
80
|
writable?: WritableStream<ModelCallStreamPart<ToolSet>>;
|
|
79
81
|
model: LanguageModel;
|
|
80
82
|
stopConditions?: ModelStopCondition[] | ModelStopCondition;
|
|
83
|
+
onStepEnd?: WorkflowAgentOnStepEndCallback<any>;
|
|
84
|
+
/** @deprecated Use `onStepEnd` instead. */
|
|
81
85
|
onStepFinish?: WorkflowAgentOnStepFinishCallback<any>;
|
|
82
86
|
onStepStart?: WorkflowAgentOnStepStartCallback;
|
|
83
87
|
onError?: WorkflowAgentOnErrorCallback;
|
|
@@ -448,10 +452,11 @@ export async function* streamTextIterator({
|
|
|
448
452
|
);
|
|
449
453
|
}
|
|
450
454
|
|
|
451
|
-
|
|
452
|
-
|
|
455
|
+
const resolvedOnStepEnd = onStepEnd ?? onStepFinish;
|
|
456
|
+
if (resolvedOnStepEnd) {
|
|
457
|
+
await resolvedOnStepEnd(step);
|
|
453
458
|
}
|
|
454
|
-
await telemetryDispatcher.
|
|
459
|
+
await telemetryDispatcher.onStepEnd?.(normalizeStepForTelemetry(step));
|
|
455
460
|
} catch (error) {
|
|
456
461
|
if (onError) {
|
|
457
462
|
await onError({ error });
|
package/src/workflow-agent.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
type ModelMessage,
|
|
23
23
|
type StepResult,
|
|
24
24
|
type StopCondition,
|
|
25
|
-
type
|
|
25
|
+
type GenerateTextOnStepEndCallback,
|
|
26
26
|
type ActiveTools,
|
|
27
27
|
type ToolCallRepairFunction,
|
|
28
28
|
type ToolChoice,
|
|
@@ -47,13 +47,24 @@ export type { CompatibleLanguageModel } from './types.js';
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Callback function to be called after each step completes.
|
|
50
|
-
* Alias for the AI SDK's
|
|
50
|
+
* Alias for the AI SDK's GenerateTextOnStepEndCallback, using
|
|
51
51
|
* WorkflowAgent-consistent naming.
|
|
52
52
|
*/
|
|
53
|
+
export type WorkflowAgentOnStepEndCallback<
|
|
54
|
+
TTools extends ToolSet = ToolSet,
|
|
55
|
+
TRuntimeContext extends Context = Context,
|
|
56
|
+
> = GenerateTextOnStepEndCallback<TTools, TRuntimeContext>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Callback function to be called after each step completes.
|
|
60
|
+
* Deprecated alias for `WorkflowAgentOnStepEndCallback`.
|
|
61
|
+
*
|
|
62
|
+
* @deprecated Use `WorkflowAgentOnStepEndCallback` instead.
|
|
63
|
+
*/
|
|
53
64
|
export type WorkflowAgentOnStepFinishCallback<
|
|
54
65
|
TTools extends ToolSet = ToolSet,
|
|
55
66
|
TRuntimeContext extends Context = Context,
|
|
56
|
-
> =
|
|
67
|
+
> = WorkflowAgentOnStepEndCallback<TTools, TRuntimeContext>;
|
|
57
68
|
|
|
58
69
|
/**
|
|
59
70
|
* Infer the type of the tools of a workflow agent.
|
|
@@ -492,6 +503,13 @@ export type WorkflowAgentOptions<
|
|
|
492
503
|
/**
|
|
493
504
|
* Callback function to be called after each step completes.
|
|
494
505
|
*/
|
|
506
|
+
onStepEnd?: WorkflowAgentOnStepEndCallback<TTools, TRuntimeContext>;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Callback function to be called after each step completes.
|
|
510
|
+
*
|
|
511
|
+
* @deprecated Use `onStepEnd` instead.
|
|
512
|
+
*/
|
|
495
513
|
onStepFinish?: WorkflowAgentOnStepFinishCallback<TTools, TRuntimeContext>;
|
|
496
514
|
|
|
497
515
|
/**
|
|
@@ -905,6 +923,13 @@ export type WorkflowAgentStreamOptions<
|
|
|
905
923
|
/**
|
|
906
924
|
* Callback function to be called after each step completes.
|
|
907
925
|
*/
|
|
926
|
+
onStepEnd?: WorkflowAgentOnStepEndCallback<TTools, TRuntimeContext>;
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Callback function to be called after each step completes.
|
|
930
|
+
*
|
|
931
|
+
* @deprecated Use `onStepEnd` instead.
|
|
932
|
+
*/
|
|
908
933
|
onStepFinish?: WorkflowAgentOnStepFinishCallback<TTools, TRuntimeContext>;
|
|
909
934
|
|
|
910
935
|
/**
|
|
@@ -1134,7 +1159,7 @@ export class WorkflowAgent<
|
|
|
1134
1159
|
private experimentalRepairToolCall?: ToolCallRepairFunction<TBaseTools>;
|
|
1135
1160
|
private experimentalDownload?: DownloadFunction;
|
|
1136
1161
|
private prepareStep?: PrepareStepCallback<TBaseTools, TRuntimeContext>;
|
|
1137
|
-
private
|
|
1162
|
+
private constructorOnStepEnd?: WorkflowAgentOnStepEndCallback<
|
|
1138
1163
|
TBaseTools,
|
|
1139
1164
|
TRuntimeContext
|
|
1140
1165
|
>;
|
|
@@ -1170,7 +1195,7 @@ export class WorkflowAgent<
|
|
|
1170
1195
|
this.experimentalRepairToolCall = options.experimental_repairToolCall;
|
|
1171
1196
|
this.experimentalDownload = options.experimental_download;
|
|
1172
1197
|
this.prepareStep = options.prepareStep;
|
|
1173
|
-
this.
|
|
1198
|
+
this.constructorOnStepEnd = options.onStepEnd ?? options.onStepFinish;
|
|
1174
1199
|
const { onFinish, onEnd = onFinish } = options;
|
|
1175
1200
|
this.constructorOnEnd = onEnd;
|
|
1176
1201
|
this.constructorOnStart = options.experimental_onStart;
|
|
@@ -1533,11 +1558,11 @@ export class WorkflowAgent<
|
|
|
1533
1558
|
};
|
|
1534
1559
|
|
|
1535
1560
|
// Merge constructor + stream callbacks (constructor first, then stream)
|
|
1536
|
-
const
|
|
1537
|
-
this.
|
|
1538
|
-
|
|
|
1561
|
+
const mergedOnStepEnd = mergeCallbacks(
|
|
1562
|
+
this.constructorOnStepEnd as
|
|
1563
|
+
| WorkflowAgentOnStepEndCallback<TTools, TRuntimeContext>
|
|
1539
1564
|
| undefined,
|
|
1540
|
-
options.onStepFinish,
|
|
1565
|
+
options.onStepEnd ?? options.onStepFinish,
|
|
1541
1566
|
);
|
|
1542
1567
|
const mergedOnEnd = mergeCallbacks(
|
|
1543
1568
|
this.constructorOnEnd as
|
|
@@ -1857,7 +1882,7 @@ export class WorkflowAgent<
|
|
|
1857
1882
|
prompt: modelPrompt,
|
|
1858
1883
|
stopConditions: options.stopWhen ?? this.stopWhen,
|
|
1859
1884
|
|
|
1860
|
-
|
|
1885
|
+
onStepEnd: mergedOnStepEnd as any,
|
|
1861
1886
|
onStepStart: mergedOnStepStart as any,
|
|
1862
1887
|
onError: options.onError,
|
|
1863
1888
|
prepareStep: (options.prepareStep ??
|