@ai-sdk/workflow 2.0.37 → 2.0.38

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.37",
3
+ "version": "2.0.38",
4
4
  "type": "module",
5
5
  "description": "WorkflowAgent for building AI agents with AI SDK",
6
6
  "license": "Apache-2.0",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@ai-sdk/provider": "4.0.17",
40
- "@ai-sdk/provider-utils": "5.0.44",
41
- "ai": "7.0.106",
40
+ "@ai-sdk/provider-utils": "5.0.45",
41
+ "ai": "7.0.107",
42
42
  "ajv": "^8.20.0"
43
43
  },
44
44
  "devDependencies": {
@@ -19,7 +19,10 @@ import {
19
19
  type ToolChoice,
20
20
  type ToolSet,
21
21
  } from 'ai';
22
- import { createRestrictedTelemetryDispatcher } from 'ai/internal';
22
+ import {
23
+ createRestrictedTelemetryDispatcher,
24
+ createToolSearchState,
25
+ } from 'ai/internal';
23
26
  import {
24
27
  type DoStreamStepRawResult,
25
28
  doStreamStep,
@@ -86,6 +89,8 @@ function mergePrepareStepGenerationSettings(
86
89
  export interface StreamTextIteratorYieldValue {
87
90
  /** The tool calls requested by the model (parsed with typed inputs) */
88
91
  toolCalls: ParsedToolCall[];
92
+ /** The tools available for execution in the current step. */
93
+ tools?: ToolSet;
89
94
  /** The conversation messages up to (and including) the tool call request */
90
95
  messages: LanguageModelV4Prompt;
91
96
  /** The step result from the current step */
@@ -186,6 +191,10 @@ export async function* streamTextIterator({
186
191
  let wasAborted = false;
187
192
  let terminalError: unknown;
188
193
  let hasTerminalError = false;
194
+ const prepareToolSearch = createToolSearchState({
195
+ tools,
196
+ toolCallers: undefined,
197
+ });
189
198
 
190
199
  // TODO(#12164): replace this AI-core telemetry bridge with a
191
200
  // WorkflowAgent-specific typed dispatcher. `streamTextIterator` widens
@@ -306,14 +315,15 @@ export async function* streamTextIterator({
306
315
  });
307
316
 
308
317
  try {
309
- // Filter tools if activeTools is specified
318
+ const stepActiveTools = filterActiveTools({
319
+ tools,
320
+ activeTools: currentActiveTools,
321
+ });
310
322
  const effectiveTools =
311
- currentActiveTools !== undefined
312
- ? (filterActiveTools({
313
- tools,
314
- activeTools: currentActiveTools,
315
- }) ?? tools)
316
- : tools;
323
+ prepareToolSearch(stepActiveTools, {
324
+ toolsContext: currentToolsContext as never,
325
+ experimental_sandbox: stepSandbox,
326
+ }) ?? {};
317
327
 
318
328
  // Serialize tools before crossing the step boundary — zod schemas
319
329
  // contain functions that can't be serialized by the workflow runtime.
@@ -484,6 +494,7 @@ export async function* streamTextIterator({
484
494
  // Also include provider-executed tool results so they can be used instead of local execution
485
495
  const toolResults = yield {
486
496
  toolCalls,
497
+ tools: effectiveTools,
487
498
  messages: conversationPrompt,
488
499
  step,
489
500
  runtimeContext: currentRuntimeContext,
@@ -2350,6 +2350,7 @@ export class WorkflowAgent<
2350
2350
 
2351
2351
  const {
2352
2352
  toolCalls,
2353
+ tools: stepTools = effectiveTools as ToolSet,
2353
2354
  messages: iterMessages,
2354
2355
  step,
2355
2356
  runtimeContext: yieldedRuntimeContext,
@@ -2415,7 +2416,7 @@ export class WorkflowAgent<
2415
2416
  // Check which tools need approval (can be async)
2416
2417
  const approvalNeeded = await Promise.all(
2417
2418
  nonProviderToolCalls.map(async tc => {
2418
- const tool = (effectiveTools as ToolSet)[tc.toolName];
2419
+ const tool = stepTools[tc.toolName];
2419
2420
  if (!tool) return false;
2420
2421
  if (tool.needsApproval == null) return false;
2421
2422
  if (typeof tool.needsApproval === 'boolean')
@@ -2439,14 +2440,14 @@ export class WorkflowAgent<
2439
2440
  // - paused: no execute function (client-side) OR needs approval
2440
2441
  // Note: missing tools (!tool) are left to executeTool which will throw.
2441
2442
  const executableToolCalls = nonProviderToolCalls.filter((tc, i) => {
2442
- const tool = (effectiveTools as ToolSet)[tc.toolName];
2443
+ const tool = stepTools[tc.toolName];
2443
2444
  return (
2444
2445
  (!tool || typeof tool.execute === 'function') &&
2445
2446
  !approvalNeeded[i]
2446
2447
  );
2447
2448
  });
2448
2449
  const pausedToolCalls = nonProviderToolCalls.filter((tc, i) => {
2449
- const tool = (effectiveTools as ToolSet)[tc.toolName];
2450
+ const tool = stepTools[tc.toolName];
2450
2451
  return (
2451
2452
  (tool && typeof tool.execute !== 'function') || approvalNeeded[i]
2452
2453
  );
@@ -2463,7 +2464,7 @@ export class WorkflowAgent<
2463
2464
  (toolCall): Promise<WorkflowToolExecutionResult> =>
2464
2465
  executeToolWithCallbacks(
2465
2466
  toolCall,
2466
- effectiveTools as ToolSet,
2467
+ stepTools,
2467
2468
  iterMessages,
2468
2469
  toolsContext,
2469
2470
  currentStepNumber,
@@ -2479,7 +2480,7 @@ export class WorkflowAgent<
2479
2480
  result: await resolveProviderToolResult(
2480
2481
  toolCall,
2481
2482
  capturedProviderToolResults,
2482
- effectiveTools as ToolSet,
2483
+ stepTools,
2483
2484
  download,
2484
2485
  ),
2485
2486
  })),
@@ -2657,7 +2658,7 @@ export class WorkflowAgent<
2657
2658
  (toolCall): Promise<WorkflowToolExecutionResult> =>
2658
2659
  executeToolWithCallbacks(
2659
2660
  toolCall,
2660
- effectiveTools as ToolSet,
2661
+ stepTools,
2661
2662
  iterMessages,
2662
2663
  toolsContext,
2663
2664
  currentStepNumber,
@@ -2673,7 +2674,7 @@ export class WorkflowAgent<
2673
2674
  result: await resolveProviderToolResult(
2674
2675
  toolCall,
2675
2676
  capturedProviderToolResults,
2676
- effectiveTools as ToolSet,
2677
+ stepTools,
2677
2678
  download,
2678
2679
  ),
2679
2680
  })),