@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/workflow",
3
- "version": "2.0.18",
3
+ "version": "2.0.20",
4
4
  "type": "module",
5
5
  "description": "WorkflowAgent for building AI agents with AI SDK",
6
6
  "license": "Apache-2.0",
@@ -31,9 +31,9 @@
31
31
  }
32
32
  },
33
33
  "dependencies": {
34
- "@ai-sdk/provider": "4.0.9",
35
- "@ai-sdk/provider-utils": "5.0.34",
36
- "ai": "7.0.88",
34
+ "@ai-sdk/provider": "4.0.10",
35
+ "@ai-sdk/provider-utils": "5.0.35",
36
+ "ai": "7.0.89",
37
37
  "ajv": "^8.20.0"
38
38
  },
39
39
  "devDependencies": {
@@ -298,7 +298,7 @@ export async function* streamTextIterator({
298
298
  try {
299
299
  // Filter tools if activeTools is specified
300
300
  const effectiveTools =
301
- currentActiveTools && currentActiveTools.length > 0
301
+ currentActiveTools !== undefined
302
302
  ? (filterActiveTools({
303
303
  tools,
304
304
  activeTools: currentActiveTools,
@@ -41,6 +41,7 @@ import {
41
41
  createRestrictedTelemetryDispatcher,
42
42
  collectToolApprovals,
43
43
  convertToLanguageModelPrompt,
44
+ mergeAbortSignals,
44
45
  mergeCallbacks,
45
46
  signToolApproval,
46
47
  standardizePrompt,
@@ -48,7 +49,10 @@ import {
48
49
  verifyToolApprovalSignature,
49
50
  } from 'ai/internal';
50
51
  import { createLanguageModelToolResultOutput } from './create-language-model-tool-result-output.js';
51
- import type { ModelCallStreamPart } from './do-stream-step.js';
52
+ import type {
53
+ ModelCallStreamPart,
54
+ ModelStopCondition,
55
+ } from './do-stream-step.js';
52
56
  import { streamTextIterator } from './stream-text-iterator.js';
53
57
 
54
58
  // Re-export for consumers
@@ -400,8 +404,8 @@ export interface PrepareCallOptions<
400
404
  instructions?: Instructions;
401
405
  toolChoice?: ToolChoice<TTools>;
402
406
  stopWhen?:
403
- | StopCondition<NoInfer<ToolSet>, any>
404
- | Array<StopCondition<NoInfer<ToolSet>, any>>;
407
+ | StopCondition<NoInfer<TTools>, TRuntimeContext>
408
+ | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
405
409
  activeTools?: ActiveTools<NoInfer<TTools>>;
406
410
  experimental_download?: DownloadFunction;
407
411
  telemetry?: TelemetryOptions<TRuntimeContext, TTools>;
@@ -512,8 +516,8 @@ export type WorkflowAgentOptions<
512
516
  * Per-stream `stopWhen` values passed to `stream()` override this default.
513
517
  */
514
518
  stopWhen?:
515
- | StopCondition<NoInfer<ToolSet>, any>
516
- | Array<StopCondition<NoInfer<ToolSet>, any>>;
519
+ | StopCondition<NoInfer<TTools>, TRuntimeContext>
520
+ | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
517
521
 
518
522
  /**
519
523
  * Default set of active tools that limits which tools the model can call,
@@ -936,8 +940,8 @@ export type WorkflowAgentStreamOptions<
936
940
  * When the condition is an array, any of the conditions can be met to stop the generation.
937
941
  */
938
942
  stopWhen?:
939
- | StopCondition<NoInfer<ToolSet>, any>
940
- | Array<StopCondition<NoInfer<ToolSet>, any>>;
943
+ | StopCondition<NoInfer<TTools>, TRuntimeContext>
944
+ | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
941
945
 
942
946
  /**
943
947
  * The tool choice strategy. Default: 'auto'.
@@ -1330,8 +1334,8 @@ export class WorkflowAgent<
1330
1334
  private runtimeContext?: TRuntimeContext;
1331
1335
  private toolsContext?: InferToolSetContext<TBaseTools>;
1332
1336
  private stopWhen?:
1333
- | StopCondition<ToolSet, any>
1334
- | Array<StopCondition<ToolSet, any>>;
1337
+ | StopCondition<TBaseTools, TRuntimeContext>
1338
+ | Array<StopCondition<TBaseTools, TRuntimeContext>>;
1335
1339
  private activeTools?: ActiveTools<TBaseTools>;
1336
1340
  private output?: OutputSpecification<any, any>;
1337
1341
  private repairToolCall?: ToolCallRepairFunction<TBaseTools>;
@@ -1552,6 +1556,12 @@ export class WorkflowAgent<
1552
1556
  } as Prompt);
1553
1557
  const download = effectiveDownloadFromPrepare;
1554
1558
  const sandbox = options.experimental_sandbox ?? this.experimentalSandbox;
1559
+ const effectiveAbortSignal = mergeAbortSignals(
1560
+ options.abortSignal ?? effectiveGenerationSettings.abortSignal,
1561
+ options.timeout,
1562
+ );
1563
+ const timeoutAt =
1564
+ options.timeout == null ? undefined : Date.now() + options.timeout;
1555
1565
  const mergedOnToolExecutionStart = mergeCallbacks(
1556
1566
  this.constructorOnToolExecutionStart,
1557
1567
  options.onToolExecutionStart,
@@ -1811,11 +1821,6 @@ export class WorkflowAgent<
1811
1821
  download,
1812
1822
  });
1813
1823
 
1814
- const effectiveAbortSignal =
1815
- options.abortSignal ?? effectiveGenerationSettings.abortSignal;
1816
- const timeoutAt =
1817
- options.timeout == null ? undefined : Date.now() + options.timeout;
1818
-
1819
1824
  // Merge generation settings: constructor defaults < prepareCall < stream options
1820
1825
  const mergedGenerationSettings: GenerationSettings = {
1821
1826
  ...effectiveGenerationSettings,
@@ -1889,7 +1894,7 @@ export class WorkflowAgent<
1889
1894
  // Filter tools if activeTools is specified (stream-level overrides constructor default)
1890
1895
  const effectiveActiveTools = effectiveActiveToolsFromPrepare;
1891
1896
  const effectiveTools =
1892
- effectiveActiveTools && effectiveActiveTools.length > 0
1897
+ effectiveActiveTools !== undefined
1893
1898
  ? (filterActiveTools({
1894
1899
  tools: this.tools,
1895
1900
  activeTools: effectiveActiveTools,
@@ -1999,6 +2004,7 @@ export class WorkflowAgent<
1999
2004
  tools,
2000
2005
  messages,
2001
2006
  resolvedContext,
2007
+ effectiveAbortSignal,
2002
2008
  download,
2003
2009
  stepSandbox,
2004
2010
  );
@@ -2157,7 +2163,10 @@ export class WorkflowAgent<
2157
2163
  prompt: modelPrompt,
2158
2164
  initialInstructions: effectiveInstructions,
2159
2165
  initialMessages: prompt.messages,
2160
- stopConditions: effectiveStopWhenFromPrepare,
2166
+ stopConditions: effectiveStopWhenFromPrepare as
2167
+ | ModelStopCondition
2168
+ | ModelStopCondition[]
2169
+ | undefined,
2161
2170
  onStepEnd: mergedOnStepEnd as any,
2162
2171
  onStepStart: mergedOnStepStart as any,
2163
2172
  prepareStep: (options.prepareStep ??
@@ -3099,6 +3108,7 @@ async function executeTool(
3099
3108
  tools: ToolSet,
3100
3109
  messages: LanguageModelV4Prompt,
3101
3110
  context?: unknown,
3111
+ abortSignal?: AbortSignal,
3102
3112
  download?: DownloadFunction,
3103
3113
  sandbox?: SandboxSession,
3104
3114
  ): Promise<WorkflowToolExecutionResult> {
@@ -3125,6 +3135,8 @@ async function executeTool(
3125
3135
  toolCallId: toolCall.toolCallId,
3126
3136
  // Pass the conversation messages to the tool so it has context about the conversation
3127
3137
  messages,
3138
+ // Pass the effective agent signal so in-flight tool work can cooperatively cancel
3139
+ abortSignal,
3128
3140
  // Pass per-tool context to the tool (resolved from `toolsContext`)
3129
3141
  context,
3130
3142
  experimental_sandbox: sandbox,