@ai-sdk/workflow 2.0.18 → 2.0.20
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.ts +3 -3
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/stream-text-iterator.ts +1 -1
- package/src/workflow-agent.ts +28 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 2.0.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 85d2081: fix(workflow): preserve configured tool and runtime context types in stop conditions
|
|
8
|
+
|
|
9
|
+
## 2.0.19
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 902ce3b: fix(workflow): respect empty activeTools lists
|
|
14
|
+
- c143af4: fix(workflow): propagate agent abort signals to local tool executions
|
|
15
|
+
- Updated dependencies [5190b67]
|
|
16
|
+
- @ai-sdk/provider@4.0.10
|
|
17
|
+
- @ai-sdk/provider-utils@5.0.35
|
|
18
|
+
- ai@7.0.89
|
|
19
|
+
|
|
3
20
|
## 2.0.18
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -284,7 +284,7 @@ interface PrepareCallOptions<TTools extends ToolSet = ToolSet, TRuntimeContext e
|
|
|
284
284
|
tools: TTools;
|
|
285
285
|
instructions?: Instructions;
|
|
286
286
|
toolChoice?: ToolChoice<TTools>;
|
|
287
|
-
stopWhen?: StopCondition<NoInfer<
|
|
287
|
+
stopWhen?: StopCondition<NoInfer<TTools>, TRuntimeContext> | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
|
|
288
288
|
activeTools?: ActiveTools<NoInfer<TTools>>;
|
|
289
289
|
experimental_download?: DownloadFunction;
|
|
290
290
|
telemetry?: TelemetryOptions<TRuntimeContext, TTools>;
|
|
@@ -369,7 +369,7 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
|
|
|
369
369
|
*
|
|
370
370
|
* Per-stream `stopWhen` values passed to `stream()` override this default.
|
|
371
371
|
*/
|
|
372
|
-
stopWhen?: StopCondition<NoInfer<
|
|
372
|
+
stopWhen?: StopCondition<NoInfer<TTools>, TRuntimeContext> | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
|
|
373
373
|
/**
|
|
374
374
|
* Default set of active tools that limits which tools the model can call,
|
|
375
375
|
* without changing the tool call and result types in the result.
|
|
@@ -705,7 +705,7 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, TRuntimeContex
|
|
|
705
705
|
* Condition for stopping the generation when there are tool results in the last step.
|
|
706
706
|
* When the condition is an array, any of the conditions can be met to stop the generation.
|
|
707
707
|
*/
|
|
708
|
-
stopWhen?: StopCondition<NoInfer<
|
|
708
|
+
stopWhen?: StopCondition<NoInfer<TTools>, TRuntimeContext> | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
|
|
709
709
|
/**
|
|
710
710
|
* The tool choice strategy. Default: 'auto'.
|
|
711
711
|
* Overrides the toolChoice from the constructor if provided.
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
createRestrictedTelemetryDispatcher as createRestrictedTelemetryDispatcher2,
|
|
17
17
|
collectToolApprovals,
|
|
18
18
|
convertToLanguageModelPrompt,
|
|
19
|
+
mergeAbortSignals,
|
|
19
20
|
mergeCallbacks,
|
|
20
21
|
signToolApproval,
|
|
21
22
|
standardizePrompt,
|
|
@@ -511,7 +512,7 @@ async function* streamTextIterator({
|
|
|
511
512
|
toolsContext: currentToolsContext
|
|
512
513
|
}));
|
|
513
514
|
try {
|
|
514
|
-
const effectiveTools = currentActiveTools
|
|
515
|
+
const effectiveTools = currentActiveTools !== void 0 ? (_d = filterActiveTools({
|
|
515
516
|
tools,
|
|
516
517
|
activeTools: currentActiveTools
|
|
517
518
|
})) != null ? _d : tools : tools;
|
|
@@ -941,6 +942,11 @@ var WorkflowAgent = class {
|
|
|
941
942
|
});
|
|
942
943
|
const download = effectiveDownloadFromPrepare;
|
|
943
944
|
const sandbox = (_n = options.experimental_sandbox) != null ? _n : this.experimentalSandbox;
|
|
945
|
+
const effectiveAbortSignal = mergeAbortSignals(
|
|
946
|
+
(_o = options.abortSignal) != null ? _o : effectiveGenerationSettings.abortSignal,
|
|
947
|
+
options.timeout
|
|
948
|
+
);
|
|
949
|
+
const timeoutAt = options.timeout == null ? void 0 : Date.now() + options.timeout;
|
|
944
950
|
const mergedOnToolExecutionStart = mergeCallbacks(
|
|
945
951
|
this.constructorOnToolExecutionStart,
|
|
946
952
|
options.onToolExecutionStart
|
|
@@ -1029,7 +1035,7 @@ var WorkflowAgent = class {
|
|
|
1029
1035
|
invalidToolApprovals[0].error
|
|
1030
1036
|
);
|
|
1031
1037
|
} else if (policyDenied.length > 0) {
|
|
1032
|
-
revalidationReason = (
|
|
1038
|
+
revalidationReason = (_p = policyDenied[0].approvalResponse.reason) != null ? _p : "Tool approval denied";
|
|
1033
1039
|
}
|
|
1034
1040
|
} catch (error) {
|
|
1035
1041
|
revalidationReason = getErrorMessage(error);
|
|
@@ -1134,8 +1140,6 @@ var WorkflowAgent = class {
|
|
|
1134
1140
|
supportedUrls: {},
|
|
1135
1141
|
download
|
|
1136
1142
|
});
|
|
1137
|
-
const effectiveAbortSignal = (_p = options.abortSignal) != null ? _p : effectiveGenerationSettings.abortSignal;
|
|
1138
|
-
const timeoutAt = options.timeout == null ? void 0 : Date.now() + options.timeout;
|
|
1139
1143
|
const mergedGenerationSettings = {
|
|
1140
1144
|
...effectiveGenerationSettings,
|
|
1141
1145
|
...options.maxOutputTokens !== void 0 && {
|
|
@@ -1190,7 +1194,7 @@ var WorkflowAgent = class {
|
|
|
1190
1194
|
);
|
|
1191
1195
|
const effectiveToolChoice = effectiveToolChoiceFromPrepare;
|
|
1192
1196
|
const effectiveActiveTools = effectiveActiveToolsFromPrepare;
|
|
1193
|
-
const effectiveTools = effectiveActiveTools
|
|
1197
|
+
const effectiveTools = effectiveActiveTools !== void 0 ? (_u = filterActiveTools2({
|
|
1194
1198
|
tools: this.tools,
|
|
1195
1199
|
activeTools: effectiveActiveTools
|
|
1196
1200
|
})) != null ? _u : this.tools : this.tools;
|
|
@@ -1272,6 +1276,7 @@ var WorkflowAgent = class {
|
|
|
1272
1276
|
tools,
|
|
1273
1277
|
messages2,
|
|
1274
1278
|
resolvedContext,
|
|
1279
|
+
effectiveAbortSignal,
|
|
1275
1280
|
download,
|
|
1276
1281
|
stepSandbox
|
|
1277
1282
|
);
|
|
@@ -2119,7 +2124,7 @@ function getToolCallbackMessages(messages) {
|
|
|
2119
2124
|
const withoutAssistantToolCall = ((_a = messages.at(-1)) == null ? void 0 : _a.role) === "assistant" ? messages.slice(0, -1) : messages;
|
|
2120
2125
|
return withoutAssistantToolCall;
|
|
2121
2126
|
}
|
|
2122
|
-
async function executeTool(toolCall, tools, messages, context, download, sandbox) {
|
|
2127
|
+
async function executeTool(toolCall, tools, messages, context, abortSignal, download, sandbox) {
|
|
2123
2128
|
const tool2 = tools[toolCall.toolName];
|
|
2124
2129
|
if (!tool2) throw new Error(`Tool "${toolCall.toolName}" not found`);
|
|
2125
2130
|
if (typeof tool2.execute !== "function") {
|
|
@@ -2135,6 +2140,8 @@ async function executeTool(toolCall, tools, messages, context, download, sandbox
|
|
|
2135
2140
|
toolCallId: toolCall.toolCallId,
|
|
2136
2141
|
// Pass the conversation messages to the tool so it has context about the conversation
|
|
2137
2142
|
messages,
|
|
2143
|
+
// Pass the effective agent signal so in-flight tool work can cooperatively cancel
|
|
2144
|
+
abortSignal,
|
|
2138
2145
|
// Pass per-tool context to the tool (resolved from `toolsContext`)
|
|
2139
2146
|
context,
|
|
2140
2147
|
experimental_sandbox: sandbox
|