@ai-sdk/workflow 1.0.0-beta.104 → 1.0.0-beta.105
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 +8 -0
- package/dist/index.mjs +35 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/workflow-agent.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.105
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 75763b0: agents: tag outgoing requests with an ai-sdk-agent user-agent segment for usage attribution (tool-loop, workflow)
|
|
8
|
+
- Updated dependencies [75763b0]
|
|
9
|
+
- ai@7.0.0-beta.185
|
|
10
|
+
|
|
3
11
|
## 1.0.0-beta.104
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/workflow-agent.ts
|
|
2
2
|
import {
|
|
3
3
|
getErrorMessage,
|
|
4
|
-
validateTypes
|
|
4
|
+
validateTypes,
|
|
5
|
+
withUserAgentSuffix
|
|
5
6
|
} from "@ai-sdk/provider-utils";
|
|
6
7
|
import {
|
|
7
8
|
Output,
|
|
@@ -751,7 +752,7 @@ var WorkflowAgent = class {
|
|
|
751
752
|
throw new Error("Not implemented");
|
|
752
753
|
}
|
|
753
754
|
async stream(options) {
|
|
754
|
-
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, _O, _P, _Q;
|
|
755
|
+
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, _O, _P, _Q, _R;
|
|
755
756
|
const { onFinish, onEnd = onFinish } = options;
|
|
756
757
|
let effectiveModel = this.model;
|
|
757
758
|
let effectiveInstructions = (_a = options.system) != null ? _a : this.instructions;
|
|
@@ -1113,9 +1114,13 @@ var WorkflowAgent = class {
|
|
|
1113
1114
|
providerOptions: options.providerOptions
|
|
1114
1115
|
}
|
|
1115
1116
|
};
|
|
1117
|
+
mergedGenerationSettings.headers = withUserAgentSuffix(
|
|
1118
|
+
(_p = mergedGenerationSettings.headers) != null ? _p : {},
|
|
1119
|
+
"ai-sdk-agent/workflow"
|
|
1120
|
+
);
|
|
1116
1121
|
const mergedOnStepEnd = mergeCallbacks(
|
|
1117
1122
|
this.constructorOnStepEnd,
|
|
1118
|
-
(
|
|
1123
|
+
(_q = options.onStepEnd) != null ? _q : options.onStepFinish
|
|
1119
1124
|
);
|
|
1120
1125
|
const mergedOnEnd = mergeCallbacks(
|
|
1121
1126
|
this.constructorOnEnd,
|
|
@@ -1138,11 +1143,11 @@ var WorkflowAgent = class {
|
|
|
1138
1143
|
options.onToolExecutionEnd
|
|
1139
1144
|
);
|
|
1140
1145
|
const effectiveToolChoice = effectiveToolChoiceFromPrepare;
|
|
1141
|
-
const effectiveActiveTools = (
|
|
1142
|
-
const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (
|
|
1146
|
+
const effectiveActiveTools = (_r = options.activeTools) != null ? _r : this.activeTools;
|
|
1147
|
+
const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_s = filterActiveTools2({
|
|
1143
1148
|
tools: this.tools,
|
|
1144
1149
|
activeTools: effectiveActiveTools
|
|
1145
|
-
})) != null ?
|
|
1150
|
+
})) != null ? _s : this.tools : this.tools;
|
|
1146
1151
|
const effectiveModelInfo = getModelInfo2(effectiveModel);
|
|
1147
1152
|
let runtimeContext = effectiveRuntimeContext;
|
|
1148
1153
|
let toolsContext = effectiveToolsContext;
|
|
@@ -1157,7 +1162,7 @@ var WorkflowAgent = class {
|
|
|
1157
1162
|
toolsContext
|
|
1158
1163
|
});
|
|
1159
1164
|
}
|
|
1160
|
-
await ((
|
|
1165
|
+
await ((_v = telemetryDispatcher.onStart) == null ? void 0 : _v.call(telemetryDispatcher, {
|
|
1161
1166
|
callId: "workflow-agent",
|
|
1162
1167
|
operationId: "ai.workflowAgent.stream",
|
|
1163
1168
|
provider: effectiveModelInfo.provider,
|
|
@@ -1175,11 +1180,11 @@ var WorkflowAgent = class {
|
|
|
1175
1180
|
frequencyPenalty: mergedGenerationSettings.frequencyPenalty,
|
|
1176
1181
|
stopSequences: mergedGenerationSettings.stopSequences,
|
|
1177
1182
|
seed: mergedGenerationSettings.seed,
|
|
1178
|
-
maxRetries: (
|
|
1183
|
+
maxRetries: (_t = mergedGenerationSettings.maxRetries) != null ? _t : 2,
|
|
1179
1184
|
timeout: void 0,
|
|
1180
1185
|
headers: mergedGenerationSettings.headers,
|
|
1181
1186
|
providerOptions: mergedGenerationSettings.providerOptions,
|
|
1182
|
-
output: (
|
|
1187
|
+
output: (_u = options.output) != null ? _u : this.output,
|
|
1183
1188
|
runtimeContext,
|
|
1184
1189
|
toolsContext
|
|
1185
1190
|
}));
|
|
@@ -1329,7 +1334,7 @@ var WorkflowAgent = class {
|
|
|
1329
1334
|
}
|
|
1330
1335
|
}));
|
|
1331
1336
|
};
|
|
1332
|
-
if ((
|
|
1337
|
+
if ((_w = mergedGenerationSettings.abortSignal) == null ? void 0 : _w.aborted) {
|
|
1333
1338
|
if (options.onAbort) {
|
|
1334
1339
|
await options.onAbort({ steps });
|
|
1335
1340
|
}
|
|
@@ -1346,19 +1351,19 @@ var WorkflowAgent = class {
|
|
|
1346
1351
|
tools: effectiveTools,
|
|
1347
1352
|
writable: options.writable,
|
|
1348
1353
|
prompt: modelPrompt,
|
|
1349
|
-
stopConditions: (
|
|
1354
|
+
stopConditions: (_x = options.stopWhen) != null ? _x : this.stopWhen,
|
|
1350
1355
|
onStepEnd: mergedOnStepEnd,
|
|
1351
1356
|
onStepStart: mergedOnStepStart,
|
|
1352
1357
|
onError: options.onError,
|
|
1353
|
-
prepareStep: (
|
|
1358
|
+
prepareStep: (_y = options.prepareStep) != null ? _y : this.prepareStep,
|
|
1354
1359
|
generationSettings: mergedGenerationSettings,
|
|
1355
1360
|
toolChoice: effectiveToolChoice,
|
|
1356
1361
|
runtimeContext,
|
|
1357
1362
|
toolsContext,
|
|
1358
1363
|
telemetry: effectiveTelemetry,
|
|
1359
|
-
includeRawChunks: (
|
|
1360
|
-
repairToolCall: (
|
|
1361
|
-
responseFormat: await ((
|
|
1364
|
+
includeRawChunks: (_z = options.includeRawChunks) != null ? _z : false,
|
|
1365
|
+
repairToolCall: (_A = options.experimental_repairToolCall) != null ? _A : this.experimentalRepairToolCall,
|
|
1366
|
+
responseFormat: await ((_C = (_B = options.output) != null ? _B : this.output) == null ? void 0 : _C.responseFormat),
|
|
1362
1367
|
experimental_sandbox: sandbox
|
|
1363
1368
|
});
|
|
1364
1369
|
let finalMessages;
|
|
@@ -1367,7 +1372,7 @@ var WorkflowAgent = class {
|
|
|
1367
1372
|
try {
|
|
1368
1373
|
let result = await iterator.next();
|
|
1369
1374
|
while (!result.done) {
|
|
1370
|
-
if ((
|
|
1375
|
+
if ((_D = mergedGenerationSettings.abortSignal) == null ? void 0 : _D.aborted) {
|
|
1371
1376
|
wasAborted = true;
|
|
1372
1377
|
if (options.onAbort) {
|
|
1373
1378
|
await options.onAbort({ steps });
|
|
@@ -1503,8 +1508,8 @@ var WorkflowAgent = class {
|
|
|
1503
1508
|
await mergedOnEnd({
|
|
1504
1509
|
steps,
|
|
1505
1510
|
messages: messages2,
|
|
1506
|
-
text: (
|
|
1507
|
-
finishReason: (
|
|
1511
|
+
text: (_E = lastStep == null ? void 0 : lastStep.text) != null ? _E : "",
|
|
1512
|
+
finishReason: (_F = lastStep == null ? void 0 : lastStep.finishReason) != null ? _F : "other",
|
|
1508
1513
|
usage: totalUsage,
|
|
1509
1514
|
totalUsage,
|
|
1510
1515
|
runtimeContext,
|
|
@@ -1516,7 +1521,7 @@ var WorkflowAgent = class {
|
|
|
1516
1521
|
const telemetrySteps = steps.map(normalizeStepForTelemetry2);
|
|
1517
1522
|
const lastStep = telemetrySteps[telemetrySteps.length - 1];
|
|
1518
1523
|
const totalUsage = aggregateUsage(steps);
|
|
1519
|
-
await ((
|
|
1524
|
+
await ((_G = telemetryDispatcher.onEnd) == null ? void 0 : _G.call(telemetryDispatcher, {
|
|
1520
1525
|
...lastStep,
|
|
1521
1526
|
steps: telemetrySteps,
|
|
1522
1527
|
usage: totalUsage,
|
|
@@ -1541,8 +1546,8 @@ var WorkflowAgent = class {
|
|
|
1541
1546
|
}
|
|
1542
1547
|
}
|
|
1543
1548
|
if (options.writable) {
|
|
1544
|
-
const sendFinish = (
|
|
1545
|
-
const preventClose = (
|
|
1549
|
+
const sendFinish = (_H = options.sendFinish) != null ? _H : true;
|
|
1550
|
+
const preventClose = (_I = options.preventClose) != null ? _I : false;
|
|
1546
1551
|
if (sendFinish || !preventClose) {
|
|
1547
1552
|
await closeStream(options.writable, preventClose, sendFinish);
|
|
1548
1553
|
}
|
|
@@ -1666,10 +1671,10 @@ var WorkflowAgent = class {
|
|
|
1666
1671
|
} else if (options.onError) {
|
|
1667
1672
|
await options.onError({ error });
|
|
1668
1673
|
}
|
|
1669
|
-
await ((
|
|
1674
|
+
await ((_J = telemetryDispatcher.onError) == null ? void 0 : _J.call(telemetryDispatcher, error));
|
|
1670
1675
|
}
|
|
1671
1676
|
const messages = finalMessages != null ? finalMessages : prompt.messages;
|
|
1672
|
-
const effectiveOutput = (
|
|
1677
|
+
const effectiveOutput = (_K = options.output) != null ? _K : this.output;
|
|
1673
1678
|
let experimentalOutput = void 0;
|
|
1674
1679
|
if (effectiveOutput && steps.length > 0) {
|
|
1675
1680
|
const lastStep = steps[steps.length - 1];
|
|
@@ -1697,8 +1702,8 @@ var WorkflowAgent = class {
|
|
|
1697
1702
|
await mergedOnEnd({
|
|
1698
1703
|
steps,
|
|
1699
1704
|
messages,
|
|
1700
|
-
text: (
|
|
1701
|
-
finishReason: (
|
|
1705
|
+
text: (_L = lastStep == null ? void 0 : lastStep.text) != null ? _L : "",
|
|
1706
|
+
finishReason: (_M = lastStep == null ? void 0 : lastStep.finishReason) != null ? _M : "other",
|
|
1702
1707
|
usage: totalUsage,
|
|
1703
1708
|
totalUsage,
|
|
1704
1709
|
runtimeContext,
|
|
@@ -1710,7 +1715,7 @@ var WorkflowAgent = class {
|
|
|
1710
1715
|
const telemetrySteps = steps.map(normalizeStepForTelemetry2);
|
|
1711
1716
|
const lastStep = telemetrySteps[telemetrySteps.length - 1];
|
|
1712
1717
|
const totalUsage = aggregateUsage(steps);
|
|
1713
|
-
await ((
|
|
1718
|
+
await ((_N = telemetryDispatcher.onEnd) == null ? void 0 : _N.call(telemetryDispatcher, {
|
|
1714
1719
|
...lastStep,
|
|
1715
1720
|
steps: telemetrySteps,
|
|
1716
1721
|
usage: totalUsage,
|
|
@@ -1719,8 +1724,8 @@ var WorkflowAgent = class {
|
|
|
1719
1724
|
}
|
|
1720
1725
|
if (encounteredError) {
|
|
1721
1726
|
if (options.writable) {
|
|
1722
|
-
const sendFinish = (
|
|
1723
|
-
const preventClose = (
|
|
1727
|
+
const sendFinish = (_O = options.sendFinish) != null ? _O : true;
|
|
1728
|
+
const preventClose = (_P = options.preventClose) != null ? _P : false;
|
|
1724
1729
|
if (sendFinish || !preventClose) {
|
|
1725
1730
|
await closeStream(options.writable, preventClose, sendFinish);
|
|
1726
1731
|
}
|
|
@@ -1728,8 +1733,8 @@ var WorkflowAgent = class {
|
|
|
1728
1733
|
throw encounteredError;
|
|
1729
1734
|
}
|
|
1730
1735
|
if (options.writable) {
|
|
1731
|
-
const sendFinish = (
|
|
1732
|
-
const preventClose = (
|
|
1736
|
+
const sendFinish = (_Q = options.sendFinish) != null ? _Q : true;
|
|
1737
|
+
const preventClose = (_R = options.preventClose) != null ? _R : false;
|
|
1733
1738
|
if (sendFinish || !preventClose) {
|
|
1734
1739
|
await closeStream(options.writable, preventClose, sendFinish);
|
|
1735
1740
|
}
|