@ai-sdk/workflow 1.0.0-canary.70 → 1.0.0-canary.72
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 +17 -0
- package/dist/index.d.mts +26 -3
- package/dist/index.mjs +23 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/do-stream-step.ts +1 -1
- package/src/index.ts +1 -0
- package/src/workflow-agent.ts +59 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 1.0.0-canary.72
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [e67d80e]
|
|
8
|
+
- Updated dependencies [6cca112]
|
|
9
|
+
- Updated dependencies [82fc0ab]
|
|
10
|
+
- Updated dependencies [76fd58c]
|
|
11
|
+
- ai@7.0.0-canary.155
|
|
12
|
+
|
|
13
|
+
## 1.0.0-canary.71
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [594029e]
|
|
18
|
+
- ai@7.0.0-canary.154
|
|
19
|
+
|
|
3
20
|
## 1.0.0-canary.70
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -362,6 +362,12 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
|
|
|
362
362
|
/**
|
|
363
363
|
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
364
364
|
*/
|
|
365
|
+
onEnd?: WorkflowAgentOnEndCallback<TTools, TRuntimeContext>;
|
|
366
|
+
/**
|
|
367
|
+
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
368
|
+
*
|
|
369
|
+
* @deprecated Use `onEnd` instead.
|
|
370
|
+
*/
|
|
365
371
|
onFinish?: WorkflowAgentOnFinishCallback<TTools, TRuntimeContext>;
|
|
366
372
|
/**
|
|
367
373
|
* Callback called when the agent starts streaming, before any LLM calls.
|
|
@@ -389,7 +395,7 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
|
|
|
389
395
|
/**
|
|
390
396
|
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
391
397
|
*/
|
|
392
|
-
type
|
|
398
|
+
type WorkflowAgentOnEndCallback<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context, OUTPUT = never> = (event: {
|
|
393
399
|
/**
|
|
394
400
|
* Details for all steps.
|
|
395
401
|
*/
|
|
@@ -406,6 +412,10 @@ type WorkflowAgentOnFinishCallback<TTools extends ToolSet = ToolSet, TRuntimeCon
|
|
|
406
412
|
* The finish reason from the last step.
|
|
407
413
|
*/
|
|
408
414
|
readonly finishReason: FinishReason;
|
|
415
|
+
/**
|
|
416
|
+
* The total token usage across all steps.
|
|
417
|
+
*/
|
|
418
|
+
readonly usage: LanguageModelUsage;
|
|
409
419
|
/**
|
|
410
420
|
* The total token usage across all steps.
|
|
411
421
|
*/
|
|
@@ -424,6 +434,12 @@ type WorkflowAgentOnFinishCallback<TTools extends ToolSet = ToolSet, TRuntimeCon
|
|
|
424
434
|
*/
|
|
425
435
|
readonly output: OUTPUT;
|
|
426
436
|
}) => PromiseLike<void> | void;
|
|
437
|
+
/**
|
|
438
|
+
* Callback that is called when the LLM response and all request tool executions are finished.
|
|
439
|
+
*
|
|
440
|
+
* @deprecated Use `WorkflowAgentOnEndCallback` instead.
|
|
441
|
+
*/
|
|
442
|
+
type WorkflowAgentOnFinishCallback<TTools extends ToolSet = ToolSet, TRuntimeContext extends Context = Context, OUTPUT = never> = WorkflowAgentOnEndCallback<TTools, TRuntimeContext, OUTPUT>;
|
|
427
443
|
/**
|
|
428
444
|
* Callback that is invoked when an error occurs during streaming.
|
|
429
445
|
*/
|
|
@@ -678,6 +694,13 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, TRuntimeContex
|
|
|
678
694
|
* Callback that is called when the LLM response and all request tool executions
|
|
679
695
|
* (for tools that have an `execute` function) are finished.
|
|
680
696
|
*/
|
|
697
|
+
onEnd?: WorkflowAgentOnEndCallback<TTools, TRuntimeContext, OUTPUT>;
|
|
698
|
+
/**
|
|
699
|
+
* Callback that is called when the LLM response and all request tool executions
|
|
700
|
+
* (for tools that have an `execute` function) are finished.
|
|
701
|
+
*
|
|
702
|
+
* @deprecated Use `onEnd` instead.
|
|
703
|
+
*/
|
|
681
704
|
onFinish?: WorkflowAgentOnFinishCallback<TTools, TRuntimeContext, OUTPUT>;
|
|
682
705
|
/**
|
|
683
706
|
* Callback that is called when the operation is aborted.
|
|
@@ -856,7 +879,7 @@ declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet, TRuntimeContex
|
|
|
856
879
|
private experimentalDownload?;
|
|
857
880
|
private prepareStep?;
|
|
858
881
|
private constructorOnStepFinish?;
|
|
859
|
-
private
|
|
882
|
+
private constructorOnEnd?;
|
|
860
883
|
private constructorOnStart?;
|
|
861
884
|
private constructorOnStepStart?;
|
|
862
885
|
private constructorOnToolExecutionStart?;
|
|
@@ -1033,4 +1056,4 @@ declare class WorkflowChatTransport<UI_MESSAGE extends UIMessage> implements Cha
|
|
|
1033
1056
|
private onFinish;
|
|
1034
1057
|
}
|
|
1035
1058
|
|
|
1036
|
-
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 TelemetryOptions, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolExecutionEndCallback, type WorkflowAgentOnToolExecutionStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, createModelCallToUIChunkTransform, toUIMessageChunk };
|
|
1059
|
+
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 TelemetryOptions, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnEndCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolExecutionEndCallback, type WorkflowAgentOnToolExecutionStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, createModelCallToUIChunkTransform, toUIMessageChunk };
|
package/dist/index.mjs
CHANGED
|
@@ -269,7 +269,7 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
|
|
|
269
269
|
stepTimeMs: 0,
|
|
270
270
|
responseTimeMs: 0,
|
|
271
271
|
toolExecutionMs: {},
|
|
272
|
-
|
|
272
|
+
timeToFirstOutputMs: void 0
|
|
273
273
|
},
|
|
274
274
|
warnings,
|
|
275
275
|
request: {
|
|
@@ -663,7 +663,8 @@ var WorkflowAgent = class {
|
|
|
663
663
|
this.experimentalDownload = options.experimental_download;
|
|
664
664
|
this.prepareStep = options.prepareStep;
|
|
665
665
|
this.constructorOnStepFinish = options.onStepFinish;
|
|
666
|
-
|
|
666
|
+
const { onFinish, onEnd = onFinish } = options;
|
|
667
|
+
this.constructorOnEnd = onEnd;
|
|
667
668
|
this.constructorOnStart = options.experimental_onStart;
|
|
668
669
|
this.constructorOnStepStart = options.experimental_onStepStart;
|
|
669
670
|
this.constructorOnToolExecutionStart = options.onToolExecutionStart;
|
|
@@ -689,6 +690,7 @@ var WorkflowAgent = class {
|
|
|
689
690
|
}
|
|
690
691
|
async stream(options) {
|
|
691
692
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N;
|
|
693
|
+
const { onFinish, onEnd = onFinish } = options;
|
|
692
694
|
let effectiveModel = this.model;
|
|
693
695
|
let effectiveInstructions = (_a = options.system) != null ? _a : this.instructions;
|
|
694
696
|
let effectivePrompt = options.prompt;
|
|
@@ -941,9 +943,9 @@ var WorkflowAgent = class {
|
|
|
941
943
|
this.constructorOnStepFinish,
|
|
942
944
|
options.onStepFinish
|
|
943
945
|
);
|
|
944
|
-
const
|
|
945
|
-
this.
|
|
946
|
-
|
|
946
|
+
const mergedOnEnd = mergeCallbacks(
|
|
947
|
+
this.constructorOnEnd,
|
|
948
|
+
onEnd
|
|
947
949
|
);
|
|
948
950
|
const mergedOnStart = mergeCallbacks(
|
|
949
951
|
this.constructorOnStart,
|
|
@@ -1306,14 +1308,16 @@ var WorkflowAgent = class {
|
|
|
1306
1308
|
});
|
|
1307
1309
|
}
|
|
1308
1310
|
const messages2 = iterMessages;
|
|
1309
|
-
if (
|
|
1311
|
+
if (mergedOnEnd && !wasAborted) {
|
|
1310
1312
|
const lastStep = steps[steps.length - 1];
|
|
1311
|
-
|
|
1313
|
+
const totalUsage = aggregateUsage(steps);
|
|
1314
|
+
await mergedOnEnd({
|
|
1312
1315
|
steps,
|
|
1313
1316
|
messages: messages2,
|
|
1314
1317
|
text: (_A = lastStep == null ? void 0 : lastStep.text) != null ? _A : "",
|
|
1315
1318
|
finishReason: (_B = lastStep == null ? void 0 : lastStep.finishReason) != null ? _B : "other",
|
|
1316
|
-
|
|
1319
|
+
usage: totalUsage,
|
|
1320
|
+
totalUsage,
|
|
1317
1321
|
runtimeContext,
|
|
1318
1322
|
toolsContext,
|
|
1319
1323
|
output: void 0
|
|
@@ -1322,10 +1326,12 @@ var WorkflowAgent = class {
|
|
|
1322
1326
|
if (!wasAborted && steps.length > 0) {
|
|
1323
1327
|
const telemetrySteps = steps.map(normalizeStepForTelemetry2);
|
|
1324
1328
|
const lastStep = telemetrySteps[telemetrySteps.length - 1];
|
|
1329
|
+
const totalUsage = aggregateUsage(steps);
|
|
1325
1330
|
await ((_C = telemetryDispatcher.onEnd) == null ? void 0 : _C.call(telemetryDispatcher, {
|
|
1326
1331
|
...lastStep,
|
|
1327
1332
|
steps: telemetrySteps,
|
|
1328
|
-
|
|
1333
|
+
usage: totalUsage,
|
|
1334
|
+
totalUsage
|
|
1329
1335
|
}));
|
|
1330
1336
|
}
|
|
1331
1337
|
if (options.writable) {
|
|
@@ -1480,14 +1486,16 @@ var WorkflowAgent = class {
|
|
|
1480
1486
|
}
|
|
1481
1487
|
}
|
|
1482
1488
|
}
|
|
1483
|
-
if (
|
|
1489
|
+
if (mergedOnEnd && !wasAborted) {
|
|
1484
1490
|
const lastStep = steps[steps.length - 1];
|
|
1485
|
-
|
|
1491
|
+
const totalUsage = aggregateUsage(steps);
|
|
1492
|
+
await mergedOnEnd({
|
|
1486
1493
|
steps,
|
|
1487
1494
|
messages,
|
|
1488
1495
|
text: (_H = lastStep == null ? void 0 : lastStep.text) != null ? _H : "",
|
|
1489
1496
|
finishReason: (_I = lastStep == null ? void 0 : lastStep.finishReason) != null ? _I : "other",
|
|
1490
|
-
|
|
1497
|
+
usage: totalUsage,
|
|
1498
|
+
totalUsage,
|
|
1491
1499
|
runtimeContext,
|
|
1492
1500
|
toolsContext,
|
|
1493
1501
|
output: experimentalOutput
|
|
@@ -1496,10 +1504,12 @@ var WorkflowAgent = class {
|
|
|
1496
1504
|
if (!wasAborted && steps.length > 0) {
|
|
1497
1505
|
const telemetrySteps = steps.map(normalizeStepForTelemetry2);
|
|
1498
1506
|
const lastStep = telemetrySteps[telemetrySteps.length - 1];
|
|
1507
|
+
const totalUsage = aggregateUsage(steps);
|
|
1499
1508
|
await ((_J = telemetryDispatcher.onEnd) == null ? void 0 : _J.call(telemetryDispatcher, {
|
|
1500
1509
|
...lastStep,
|
|
1501
1510
|
steps: telemetrySteps,
|
|
1502
|
-
|
|
1511
|
+
usage: totalUsage,
|
|
1512
|
+
totalUsage
|
|
1503
1513
|
}));
|
|
1504
1514
|
}
|
|
1505
1515
|
if (encounteredError) {
|