@ai-sdk/workflow 1.0.0-canary.92 → 1.0.0

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 CHANGED
@@ -1,5 +1,179 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 1949571: feat(ai): make experimental_telemetry stable
8
+ - b3976a2: initial version
9
+
10
+ ### Patch Changes
11
+
12
+ - 19736ee: feat(ai): rename onStepFinish to onStepEnd
13
+ - 382d53b: refactoring: rename context to runtimeContext
14
+ - b567a6c: dependency updates
15
+ - b402b95: `WorkflowAgent` now rejects system messages inside `prompt` or `messages` by default, matching the behavior of `generateText`/`streamText`. Set `allowSystemInMessages: true` to opt in to the previous behavior.
16
+ - eea8d98: refactoring: rename tool execution events
17
+ - 98627e5: feat(ai): remove onChunk event from telemetry
18
+ - ca446f8: feat: flexible tool descriptions
19
+ - 75763b0: agents: tag outgoing requests with an ai-sdk-agent user-agent segment for usage attribution (tool-loop, workflow)
20
+ - 9f0e36c: trigger release for all packages after provenance setup
21
+ - 29d8cf4: feat(ai): rename the core-event types
22
+ - 7fc6bd6: Raise minimum supported Node.js version to 22. Supported versions: 22, 24, and 26.
23
+ - a0ca584: fix (workflow): preserve invalid tool calls as errors instead of emitting synthetic success results
24
+ - eba685c: Remove `maxSteps` option from `WorkflowAgent`. Use `stopWhen` with stop conditions like `isStepCount()` instead.
25
+ - 0c4c275: trigger initial canary release
26
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
27
+ - 334ae5d: Update step performance metrics with explicit effective, input, output, and total token throughput fields.
28
+ - b8396f0: trigger initial beta release
29
+ - c3d4019: chore(ai): rename 'TelemetrySettings' to 'TelemetryOptions'
30
+ - 083947b: feat(ai): separate toolsContext from context
31
+ - bae5e2b: fix(security): re-validate tool approvals from client message history before execution
32
+
33
+ The approval-replay path in `generateText`/`streamText` (and `WorkflowAgent.stream`) reconstructed approved tool calls from the client-supplied messages array and executed them without re-validating input against the tool's schema or re-applying the approval policy. A client could forge an assistant message with a pre-approved tool-call part and have the server execute a tool with attacker-chosen arguments.
34
+
35
+ The replay path now validates HMAC signature (when `experimental_toolApprovalSecret` is configured), re-validates tool-call input against the tool's input schema, and re-resolves the approval policy before execution.
36
+
37
+ - d775a57: feat: introduce Instructions type
38
+ - f32c750: refactoring(ai): simplify mergeAbortSignals
39
+ - bf6c17b: Add `id` property to WorkflowAgent for telemetry identification, matching ToolLoopAgent's API surface.
40
+ - 3ca592a: Add `prompt` as an alternative to `messages` in `WorkflowAgent.stream()`, matching the `AgentCallParameters` pattern from ToolLoopAgent.
41
+ - eb49d29: Add constructor-level defaults for `stopWhen`, `activeTools`, `output`, `experimental_repairToolCall`, and `experimental_download` to WorkflowAgent, matching ToolLoopAgent's pattern. Stream-level values override constructor defaults.
42
+ - 0455f24: Enrich WorkflowAgent callback event shapes to align with ToolLoopAgent:
43
+ - Add `stepNumber` to `onToolCallStart` and `onToolCallFinish`
44
+ - Add `steps` (previous step results) to `onStepStart`
45
+ - Adopt discriminated union pattern (`success: true/false`) for `onToolCallFinish`
46
+ - Add `durationMs` to `onToolCallFinish`
47
+ - 43543dc: Add `experimental_sandbox` support to `WorkflowAgent`. The sandbox is passed to tool execution, configurable on the constructor or per stream, and available to `prepareStep` for per-step overrides.
48
+ - 0e462a7: Use `LanguageModel` type for model parameter, aligning with `ToolLoopAgent`. Remove async factory model form. Rename callback types to use `WorkflowAgentOn*` prefix.
49
+ - 39dad72: feat(workflow): add stable telemetry integration support to `WorkflowAgent` and remove legacy telemetry options.
50
+ - 1e4b350: Honor `tool.toModelOutput` in `WorkflowAgent`.
51
+
52
+ `WorkflowAgent` now routes successful local, provider-executed, and approved tool results through each tool's optional `toModelOutput` hook, matching `generateText`, `streamText`, and `ToolLoopAgent`. Previously the hook was ignored and results were always serialized as `text` or `json`.
53
+
54
+ Internally exports the shared tool-result model-output helpers from `ai/internal`, and uses the shared `getErrorMessage` behavior for workflow tool error results.
55
+
56
+ - c3a6524: Add a `stepNumber` option to `doStreamStep` so callers can create `StepResult` objects with the correct step number.
57
+ - 907e002: fix (workflow): forward provider-executed tool approvals to the provider on resume
58
+
59
+ `WorkflowAgent` stripped every `tool-approval-request` and `tool-approval-response` part from the messages when resuming after a tool approval, regardless of whether the tool was locally or provider-executed. For provider-executed tools (e.g. MCP via the OpenAI Responses API) this silently dropped the approval before `convertToLanguageModelPrompt` could forward it, so the provider never learned of the approval and the tool was never executed. Local approvals are still executed and stripped, while provider-executed approvals are now preserved and forwarded to the provider, matching the discriminator core's `streamText` already uses. This is the inverse of the bug fixed in #14289.
60
+
61
+ - 1d56275: feat(workflow): add `runtimeContext` and `toolsContext` to `WorkflowAgent`.
62
+
63
+ `runtimeContext` is shared agent state that flows through `prepareCall`, `prepareStep`, step results, and `onFinish`. `toolsContext` is a per-tool map; each tool receives its own validated entry as `context`, validated against `tool.contextSchema` when defined. The previous `experimental_context` option (and corresponding fields on related callbacks and option types) has been removed — use `runtimeContext` for shared state and `toolsContext` for per-tool values. Context values in `WorkflowAgent` should be serializable because they can cross workflow and step boundaries.
64
+
65
+ - 81e68da: Fix `stepNumber` on telemetry events emitted by `WorkflowAgent.stream` so per-step telemetry integrations (e.g. `@ai-sdk/devtools`) correctly key state per step.
66
+ - 69d7128: fix(workflow): reuse the core tool-approval validation in WorkflowAgent
67
+
68
+ `WorkflowAgent.stream` previously reconstructed approved tool calls with a copy of the core collection logic and validated them inline. Because the logic was duplicated, it could drift from the hardened `generateText`/`streamText` implementation. WorkflowAgent now collects approvals via the shared `collectToolApprovals` and re-validates each one through the shared `validateApprovedToolApprovals` (input-schema re-validation, HMAC signature verification when configured, and approval-policy re-resolution) in addition to its existing `needsApproval` guard, so a client-forged approval cannot execute a tool with unvalidated input. The duplicated collector was removed; `collectToolApprovals` and `validateApprovedToolApprovals` are now exported from `ai/internal`.
69
+
70
+ - fbea042: refactor: replace duplicate `filterTools`/`filterToolSet` with shared `experimental_filterActiveTools` from `ai`
71
+
72
+ ## 1.0.0-beta.107
73
+
74
+ ### Patch Changes
75
+
76
+ - ai@7.0.0-beta.187
77
+
78
+ ## 1.0.0-beta.106
79
+
80
+ ### Patch Changes
81
+
82
+ - ai@7.0.0-beta.186
83
+
84
+ ## 1.0.0-beta.105
85
+
86
+ ### Patch Changes
87
+
88
+ - 75763b0: agents: tag outgoing requests with an ai-sdk-agent user-agent segment for usage attribution (tool-loop, workflow)
89
+ - Updated dependencies [75763b0]
90
+ - ai@7.0.0-beta.185
91
+
92
+ ## 1.0.0-beta.104
93
+
94
+ ### Patch Changes
95
+
96
+ - 43543dc: Add `experimental_sandbox` support to `WorkflowAgent`. The sandbox is passed to tool execution, configurable on the constructor or per stream, and available to `prepareStep` for per-step overrides.
97
+
98
+ ## 1.0.0-beta.103
99
+
100
+ ### Patch Changes
101
+
102
+ - Updated dependencies [0416e3e]
103
+ - @ai-sdk/provider@4.0.0-beta.20
104
+ - ai@7.0.0-beta.184
105
+ - @ai-sdk/provider-utils@5.0.0-beta.50
106
+
107
+ ## 1.0.0-beta.102
108
+
109
+ ### Patch Changes
110
+
111
+ - ai@7.0.0-beta.183
112
+
113
+ ## 1.0.0-beta.101
114
+
115
+ ### Patch Changes
116
+
117
+ - b402b95: `WorkflowAgent` now rejects system messages inside `prompt` or `messages` by default, matching the behavior of `generateText`/`streamText`. Set `allowSystemInMessages: true` to opt in to the previous behavior.
118
+
119
+ ## 1.0.0-beta.100
120
+
121
+ ### Patch Changes
122
+
123
+ - 907e002: fix (workflow): forward provider-executed tool approvals to the provider on resume
124
+
125
+ `WorkflowAgent` stripped every `tool-approval-request` and `tool-approval-response` part from the messages when resuming after a tool approval, regardless of whether the tool was locally or provider-executed. For provider-executed tools (e.g. MCP via the OpenAI Responses API) this silently dropped the approval before `convertToLanguageModelPrompt` could forward it, so the provider never learned of the approval and the tool was never executed. Local approvals are still executed and stripped, while provider-executed approvals are now preserved and forwarded to the provider, matching the discriminator core's `streamText` already uses. This is the inverse of the bug fixed in #14289.
126
+
127
+ ## 1.0.0-beta.99
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [cc6ab90]
132
+ - ai@7.0.0-beta.182
133
+
134
+ ## 1.0.0-beta.98
135
+
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [6a2caf9]
139
+ - ai@7.0.0-beta.181
140
+
141
+ ## 1.0.0-beta.97
142
+
143
+ ### Patch Changes
144
+
145
+ - Updated dependencies [81a284b]
146
+ - ai@7.0.0-beta.180
147
+
148
+ ## 1.0.0-beta.96
149
+
150
+ ### Patch Changes
151
+
152
+ - ai@7.0.0-beta.179
153
+
154
+ ## 1.0.0-beta.95
155
+
156
+ ### Patch Changes
157
+
158
+ - Updated dependencies [b097c52]
159
+ - ai@7.0.0-beta.178
160
+
161
+ ## 1.0.0-beta.94
162
+
163
+ ### Patch Changes
164
+
165
+ - b8396f0: trigger initial beta release
166
+ - Updated dependencies [b8396f0]
167
+ - @ai-sdk/provider-utils@5.0.0-beta.49
168
+ - @ai-sdk/provider@4.0.0-beta.19
169
+ - ai@7.0.0-beta.177
170
+
171
+ ## 1.0.0-canary.93
172
+
173
+ ### Patch Changes
174
+
175
+ - ai@7.0.0-canary.176
176
+
3
177
  ## 1.0.0-canary.92
4
178
 
5
179
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LanguageModelV4, SharedV4ProviderOptions, LanguageModelV4CallOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart } from '@ai-sdk/provider';
2
2
  import { Context, HasRequiredKey, InferToolSetContext } from '@ai-sdk/provider-utils';
3
- import { ToolSet, LanguageModel, Instructions, ToolChoice, TelemetryOptions as TelemetryOptions$1, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, StepResult, GenerateTextOnStepEndCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
3
+ import { ToolSet, LanguageModel, Instructions, ToolChoice, TelemetryOptions as TelemetryOptions$1, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, Experimental_SandboxSession, StepResult, GenerateTextOnStepEndCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
4
4
  export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, ToolCallRepairFunction } from 'ai';
5
5
 
6
6
  /**
@@ -193,6 +193,10 @@ interface PrepareStepInfo<TTools extends ToolSet = ToolSet, TRuntimeContext exte
193
193
  * `prepareStep` to update it for the current and subsequent steps.
194
194
  */
195
195
  toolsContext: InferToolSetContext<TTools>;
196
+ /**
197
+ * The sandbox environment that the step is operating in.
198
+ */
199
+ experimental_sandbox?: Experimental_SandboxSession;
196
200
  }
197
201
  /**
198
202
  * Return type from the prepareStep callback.
@@ -231,6 +235,10 @@ interface PrepareStepResult<TTools extends ToolSet = ToolSet, TRuntimeContext ex
231
235
  * Returning a value replaces the agent's tools context.
232
236
  */
233
237
  toolsContext?: InferToolSetContext<TTools>;
238
+ /**
239
+ * Override the sandbox environment for this step.
240
+ */
241
+ experimental_sandbox?: Experimental_SandboxSession;
234
242
  }
235
243
  /**
236
244
  * Callback function called before each step in the agent loop.
@@ -354,6 +362,13 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
354
362
  * Per-stream `experimental_download` values passed to `stream()` override this default.
355
363
  */
356
364
  experimental_download?: DownloadFunction;
365
+ /**
366
+ * Default sandbox environment passed through to tool execution as
367
+ * `experimental_sandbox`.
368
+ *
369
+ * Per-stream `experimental_sandbox` values passed to `stream()` override this default.
370
+ */
371
+ experimental_sandbox?: Experimental_SandboxSession;
357
372
  /**
358
373
  * Default callback function called before each step in the agent loop.
359
374
  * Use this to modify settings, manage context, or inject messages dynamically
@@ -404,6 +419,15 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
404
419
  * model, tools, instructions, or other settings based on runtime context.
405
420
  */
406
421
  prepareCall?: PrepareCallCallback<TTools, TRuntimeContext>;
422
+ /**
423
+ * Whether to allow system messages inside the `prompt` or `messages` fields.
424
+ * When `false` (the default), system messages in `prompt` or `messages` are
425
+ * rejected to prevent prompt-injection attacks. Set to `true` only when you
426
+ * intentionally interleave system messages with user messages.
427
+ *
428
+ * @default false
429
+ */
430
+ allowSystemInMessages?: boolean;
407
431
  };
408
432
  /**
409
433
  * Callback that is called when the LLM response and all request tool executions are finished.
@@ -694,6 +718,11 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, TRuntimeContex
694
718
  * By default, files are downloaded if the model does not support the URL for the given media type.
695
719
  */
696
720
  experimental_download?: DownloadFunction;
721
+ /**
722
+ * Sandbox environment passed through to tool execution as
723
+ * `experimental_sandbox`. Overrides the constructor-level value if provided.
724
+ */
725
+ experimental_sandbox?: Experimental_SandboxSession;
697
726
  /**
698
727
  * Callback function to be called after each step completes.
699
728
  */
@@ -896,7 +925,9 @@ declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet, TRuntimeContex
896
925
  private output?;
897
926
  private experimentalRepairToolCall?;
898
927
  private experimentalDownload?;
928
+ private experimentalSandbox?;
899
929
  private prepareStep?;
930
+ private allowSystemInMessages;
900
931
  private constructorOnStepEnd?;
901
932
  private constructorOnEnd?;
902
933
  private constructorOnStart?;