@mastra/ai-sdk 0.3.1 → 0.3.2

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,35 +1,202 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
- ## 0.3.1
3
+ ## 0.3.2
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Added support for tripwire data chunks in streaming responses. ([#10291](https://github.com/mastra-ai/mastra/pull/10291))
7
+ - Support streaming agent text chunks from workflow-step-output ([#10568](https://github.com/mastra-ai/mastra/pull/10568))
8
8
 
9
- Tripwire chunks allow the AI SDK to emit special data events when certain conditions are triggered during stream processing. These chunks include a `tripwireReason` field explaining why the tripwire was activated.
9
+ Adds support for streaming text and tool call chunks from agents running inside workflows via the workflow-step-output event. When you pipe an agent's stream into a workflow step's writer, the text chunks, tool calls, and other streaming events are automatically included in the workflow stream and converted to UI messages.
10
10
 
11
- #### Usage
11
+ **Features:**
12
+ - Added `includeTextStreamParts` option to `WorkflowStreamToAISDKTransformer` (defaults to `true`)
13
+ - Added `isMastraTextStreamChunk` type guard to identify Mastra chunks with text streaming data
14
+ - Support for streaming text chunks: `text-start`, `text-delta`, `text-end`
15
+ - Support for streaming tool calls: `tool-call`, `tool-result`
16
+ - Comprehensive test coverage in `transformers.test.ts`
17
+ - Updated documentation for workflow streaming and `workflowRoute()`
12
18
 
13
- When converting Mastra chunks to AI SDK v5 format, tripwire chunks are now automatically handled:
19
+ **Example:**
14
20
 
15
21
  ```typescript
16
- // Tripwire chunks are converted to data-tripwire format
17
- const chunk = {
18
- type: 'tripwire',
19
- payload: { tripwireReason: 'Rate limit approaching' }
20
- };
22
+ const planActivities = createStep({
23
+ execute: async ({ mastra, writer }) => {
24
+ const agent = mastra?.getAgent('weatherAgent');
25
+ const response = await agent.stream('Plan activities');
26
+ await response.fullStream.pipeTo(writer);
27
+
28
+ return { activities: await response.text };
29
+ },
30
+ });
31
+ ```
21
32
 
22
- // Converts to:
23
- {
24
- type: 'data-tripwire',
25
- data: { tripwireReason: 'Rate limit approaching' }
26
- }
33
+ When served via `workflowRoute()`, the UI receives incremental text updates as the agent generates its response, providing a smooth streaming experience.
34
+
35
+ - Fix chat route to use agent ID instead of agent name for resolution. The `/chat/:agentId` endpoint now correctly resolves agents by their ID property (e.g., `weather-agent`) instead of requiring the camelCase variable name (e.g., `weatherAgent`). This fixes issue #10469 where URLs like `/chat/weather-agent` would return 404 errors. ([#10565](https://github.com/mastra-ai/mastra/pull/10565))
36
+
37
+ - Fixes propagation of custom data chunks from nested workflows in branches to the root stream when using `toAISdkV5Stream` with `{from: 'workflow'}`. ([#10449](https://github.com/mastra-ai/mastra/pull/10449))
38
+
39
+ Previously, when a nested workflow within a branch used `writer.custom()` to write data-\* chunks, those chunks were wrapped in `workflow-step-output` events and not extracted, causing them to be dropped from the root stream.
40
+
41
+ **Changes:**
42
+ - Added handling for `workflow-step-output` chunks in `transformWorkflow()` to extract and propagate data-\* chunks
43
+ - When a `workflow-step-output` chunk contains a data-\* chunk in its `payload.output`, the transformer now extracts it and returns it directly to the root stream
44
+ - Added comprehensive test coverage for nested workflows with branches and custom data propagation
45
+
46
+ This ensures that custom data chunks written via `writer.custom()` in nested workflows (especially those within branches) are properly propagated to the root stream, allowing consumers to receive progress updates, metrics, and other custom data from nested workflow steps.
47
+
48
+ - Fix network data step formatting in AI SDK stream transformation ([#10525](https://github.com/mastra-ai/mastra/pull/10525))
49
+
50
+ Previously, network execution steps were not being tracked correctly in the AI SDK stream transformation. Steps were being duplicated rather than updated, and critical metadata like step IDs, iterations, and task information was missing or incorrectly structured.
51
+
52
+ **Changes:**
53
+ - Enhanced step tracking in `AgentNetworkToAISDKTransformer` to properly maintain step state throughout execution lifecycle
54
+ - Steps are now identified by unique IDs and updated in place rather than creating duplicates
55
+ - Added proper iteration and task metadata to each step in the network execution flow
56
+ - Fixed agent, workflow, and tool execution events to correctly populate step data
57
+ - Updated network stream event types to include `networkId`, `workflowId`, and consistent `runId` tracking
58
+ - Added test coverage for network custom data chunks with comprehensive validation
59
+
60
+ This ensures the AI SDK correctly represents the full execution flow of agent networks with accurate step sequencing and metadata.
61
+
62
+ - [0.x] Make workflowRoute includeTextStreamParts option default to false ([#10574](https://github.com/mastra-ai/mastra/pull/10574))
63
+
64
+ - Add support for tool-call-approval and tool-call-suspended events in chatRoute ([#10360](https://github.com/mastra-ai/mastra/pull/10360))
65
+
66
+ - Backports the `messageMetadata` and `onError` support from [PR #10313](https://github.com/mastra-ai/mastra/pull/10313) to the 0.x branch, adding these features to `toAISdkFormat` function. ([#10314](https://github.com/mastra-ai/mastra/pull/10314))
67
+ - Added `messageMetadata` parameter to `toAISdkFormat` options
68
+ - Function receives the current stream part and returns metadata to attach to start and finish chunks
69
+ - Metadata is included in `start` and `finish` chunks when provided
70
+ - Added `onError` parameter to `toAISdkFormat` options
71
+ - Allows custom error handling during stream conversion
72
+ - Falls back to `safeParseErrorObject` utility when not provided
73
+ - Added `safeParseErrorObject` utility function for error parsing
74
+ - Updated `AgentStreamToAISDKTransformer` to accept and use `messageMetadata` and `onError`
75
+ - Updated JSDoc documentation with parameter descriptions and usage examples
76
+ - Added comprehensive test suite for `messageMetadata` functionality (6 test cases)
77
+ - Fixed existing test file to use `toAISdkFormat` instead of removed `toAISdkV5Stream`
78
+ - All existing tests pass (14 tests across 3 test files)
79
+ - New tests verify:
80
+ - `messageMetadata` is called with correct part structure
81
+ - Metadata is included in start and finish chunks
82
+ - Proper handling when `messageMetadata` is not provided or returns null/undefined
83
+ - Function is called for each relevant part in the stream
84
+ - Uses `UIMessageStreamOptions<UIMessage>['messageMetadata']` and `UIMessageStreamOptions<UIMessage>['onError']` types from AI SDK v5 for full type compatibility
85
+ - Backport of: https://github.com/mastra-ai/mastra/pull/10313
86
+
87
+ - Fixed workflow routes to properly receive request context from middleware. This aligns the behavior of `workflowRoute` with `chatRoute`, ensuring that context set in middleware is consistently forwarded to workflows. ([#10527](https://github.com/mastra-ai/mastra/pull/10527))
88
+
89
+ When both middleware and request body provide a request context, the middleware value now takes precedence, and a warning is emitted to help identify potential conflicts.
90
+
91
+ See [#10427](https://github.com/mastra-ai/mastra/pull/10427)
92
+
93
+ - Updated dependencies [[`5657314`](https://github.com/mastra-ai/mastra/commit/5657314a1f9d49019bb53f357fa48f75a69247ca), [`e5aca78`](https://github.com/mastra-ai/mastra/commit/e5aca78bb7f263bb8b470bedae81efe9805d7544), [`33a607a`](https://github.com/mastra-ai/mastra/commit/33a607a1f716c2029d4a1ff1603dd756129a33b3), [`cc10fc1`](https://github.com/mastra-ai/mastra/commit/cc10fc192d9f527c71a23cc9def10d8718935ee1), [`1f7ee84`](https://github.com/mastra-ai/mastra/commit/1f7ee841a643ef12d90392125881f06fdf877293), [`e7d5149`](https://github.com/mastra-ai/mastra/commit/e7d514995260b63b2108308e85c64de37dcd0f71), [`f195082`](https://github.com/mastra-ai/mastra/commit/f1950822a2425d5ccae78c5d010e02ddb027a869), [`d9986dd`](https://github.com/mastra-ai/mastra/commit/d9986dd3513f7ca3244a8e599a440ccf4d8bc28b), [`a45b0f0`](https://github.com/mastra-ai/mastra/commit/a45b0f0cd19eab1fe4deceae3abf029442c22f74), [`f6e8eb3`](https://github.com/mastra-ai/mastra/commit/f6e8eb3dac53b70b06e906b2818b1d2a5b0486d7), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`3236f35`](https://github.com/mastra-ai/mastra/commit/3236f352ae13cc8552c2965164e97bd125dae48d), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`0230321`](https://github.com/mastra-ai/mastra/commit/02303217870bedea0ef009bea9a952f24ed38aaf), [`7b541f4`](https://github.com/mastra-ai/mastra/commit/7b541f49eda6f5a87b738198edbd136927599475), [`0eea842`](https://github.com/mastra-ai/mastra/commit/0eea8423cbdd37f2111593c6f7d2efcde4b7e4ce), [`63ae8a2`](https://github.com/mastra-ai/mastra/commit/63ae8a22c0c09bbb8b9779f5f38934cd75f616af), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`ac7ef07`](https://github.com/mastra-ai/mastra/commit/ac7ef07633caee89707142171d2873c888ffef85), [`522f0b4`](https://github.com/mastra-ai/mastra/commit/522f0b45330719858794eabffffde4f343f55549), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`8b51d55`](https://github.com/mastra-ai/mastra/commit/8b51d55bae531edf7e383958d7ecee04df31f5d5), [`2131ac5`](https://github.com/mastra-ai/mastra/commit/2131ac571d5065f0a656c57494bca98691bb7609)]:
94
+ - @mastra/core@0.24.6
95
+
96
+ ## 0.3.2-alpha.0
97
+
98
+ ### Patch Changes
99
+
100
+ - Support streaming agent text chunks from workflow-step-output ([#10568](https://github.com/mastra-ai/mastra/pull/10568))
101
+
102
+ Adds support for streaming text and tool call chunks from agents running inside workflows via the workflow-step-output event. When you pipe an agent's stream into a workflow step's writer, the text chunks, tool calls, and other streaming events are automatically included in the workflow stream and converted to UI messages.
103
+
104
+ **Features:**
105
+ - Added `includeTextStreamParts` option to `WorkflowStreamToAISDKTransformer` (defaults to `true`)
106
+ - Added `isMastraTextStreamChunk` type guard to identify Mastra chunks with text streaming data
107
+ - Support for streaming text chunks: `text-start`, `text-delta`, `text-end`
108
+ - Support for streaming tool calls: `tool-call`, `tool-result`
109
+ - Comprehensive test coverage in `transformers.test.ts`
110
+ - Updated documentation for workflow streaming and `workflowRoute()`
111
+
112
+ **Example:**
113
+
114
+ ```typescript
115
+ const planActivities = createStep({
116
+ execute: async ({ mastra, writer }) => {
117
+ const agent = mastra?.getAgent('weatherAgent');
118
+ const response = await agent.stream('Plan activities');
119
+ await response.fullStream.pipeTo(writer);
120
+
121
+ return { activities: await response.text };
122
+ },
123
+ });
27
124
  ```
28
125
 
29
- - Updated dependencies [[`7491cc0`](https://github.com/mastra-ai/mastra/commit/7491cc0350b2ba067f98c4915bf607119bd0150f), [`0d10ac7`](https://github.com/mastra-ai/mastra/commit/0d10ac7b8efa03c2f0c330eb2520148bfa6091e9), [`e3e899c`](https://github.com/mastra-ai/mastra/commit/e3e899c650f4c435445303bd97a66f5840a52a1e)]:
30
- - @mastra/core@0.24.3
126
+ When served via `workflowRoute()`, the UI receives incremental text updates as the agent generates its response, providing a smooth streaming experience.
31
127
 
32
- ## 0.3.1-alpha.0
128
+ - Fix chat route to use agent ID instead of agent name for resolution. The `/chat/:agentId` endpoint now correctly resolves agents by their ID property (e.g., `weather-agent`) instead of requiring the camelCase variable name (e.g., `weatherAgent`). This fixes issue #10469 where URLs like `/chat/weather-agent` would return 404 errors. ([#10565](https://github.com/mastra-ai/mastra/pull/10565))
129
+
130
+ - Fixes propagation of custom data chunks from nested workflows in branches to the root stream when using `toAISdkV5Stream` with `{from: 'workflow'}`. ([#10449](https://github.com/mastra-ai/mastra/pull/10449))
131
+
132
+ Previously, when a nested workflow within a branch used `writer.custom()` to write data-\* chunks, those chunks were wrapped in `workflow-step-output` events and not extracted, causing them to be dropped from the root stream.
133
+
134
+ **Changes:**
135
+ - Added handling for `workflow-step-output` chunks in `transformWorkflow()` to extract and propagate data-\* chunks
136
+ - When a `workflow-step-output` chunk contains a data-\* chunk in its `payload.output`, the transformer now extracts it and returns it directly to the root stream
137
+ - Added comprehensive test coverage for nested workflows with branches and custom data propagation
138
+
139
+ This ensures that custom data chunks written via `writer.custom()` in nested workflows (especially those within branches) are properly propagated to the root stream, allowing consumers to receive progress updates, metrics, and other custom data from nested workflow steps.
140
+
141
+ - Fix network data step formatting in AI SDK stream transformation ([#10525](https://github.com/mastra-ai/mastra/pull/10525))
142
+
143
+ Previously, network execution steps were not being tracked correctly in the AI SDK stream transformation. Steps were being duplicated rather than updated, and critical metadata like step IDs, iterations, and task information was missing or incorrectly structured.
144
+
145
+ **Changes:**
146
+ - Enhanced step tracking in `AgentNetworkToAISDKTransformer` to properly maintain step state throughout execution lifecycle
147
+ - Steps are now identified by unique IDs and updated in place rather than creating duplicates
148
+ - Added proper iteration and task metadata to each step in the network execution flow
149
+ - Fixed agent, workflow, and tool execution events to correctly populate step data
150
+ - Updated network stream event types to include `networkId`, `workflowId`, and consistent `runId` tracking
151
+ - Added test coverage for network custom data chunks with comprehensive validation
152
+
153
+ This ensures the AI SDK correctly represents the full execution flow of agent networks with accurate step sequencing and metadata.
154
+
155
+ - [0.x] Make workflowRoute includeTextStreamParts option default to false ([#10574](https://github.com/mastra-ai/mastra/pull/10574))
156
+
157
+ - Add support for tool-call-approval and tool-call-suspended events in chatRoute ([#10360](https://github.com/mastra-ai/mastra/pull/10360))
158
+
159
+ - Backports the `messageMetadata` and `onError` support from [PR #10313](https://github.com/mastra-ai/mastra/pull/10313) to the 0.x branch, adding these features to `toAISdkFormat` function. ([#10314](https://github.com/mastra-ai/mastra/pull/10314))
160
+ - Added `messageMetadata` parameter to `toAISdkFormat` options
161
+ - Function receives the current stream part and returns metadata to attach to start and finish chunks
162
+ - Metadata is included in `start` and `finish` chunks when provided
163
+ - Added `onError` parameter to `toAISdkFormat` options
164
+ - Allows custom error handling during stream conversion
165
+ - Falls back to `safeParseErrorObject` utility when not provided
166
+ - Added `safeParseErrorObject` utility function for error parsing
167
+ - Updated `AgentStreamToAISDKTransformer` to accept and use `messageMetadata` and `onError`
168
+ - Updated JSDoc documentation with parameter descriptions and usage examples
169
+ - Added comprehensive test suite for `messageMetadata` functionality (6 test cases)
170
+ - Fixed existing test file to use `toAISdkFormat` instead of removed `toAISdkV5Stream`
171
+ - All existing tests pass (14 tests across 3 test files)
172
+ - New tests verify:
173
+ - `messageMetadata` is called with correct part structure
174
+ - Metadata is included in start and finish chunks
175
+ - Proper handling when `messageMetadata` is not provided or returns null/undefined
176
+ - Function is called for each relevant part in the stream
177
+ - Uses `UIMessageStreamOptions<UIMessage>['messageMetadata']` and `UIMessageStreamOptions<UIMessage>['onError']` types from AI SDK v5 for full type compatibility
178
+ - Backport of: https://github.com/mastra-ai/mastra/pull/10313
179
+
180
+ - Fixed workflow routes to properly receive request context from middleware. This aligns the behavior of `workflowRoute` with `chatRoute`, ensuring that context set in middleware is consistently forwarded to workflows. ([#10527](https://github.com/mastra-ai/mastra/pull/10527))
181
+
182
+ When both middleware and request body provide a request context, the middleware value now takes precedence, and a warning is emitted to help identify potential conflicts.
183
+
184
+ See [#10427](https://github.com/mastra-ai/mastra/pull/10427)
185
+
186
+ - Updated dependencies [[`5657314`](https://github.com/mastra-ai/mastra/commit/5657314a1f9d49019bb53f357fa48f75a69247ca), [`e5aca78`](https://github.com/mastra-ai/mastra/commit/e5aca78bb7f263bb8b470bedae81efe9805d7544), [`33a607a`](https://github.com/mastra-ai/mastra/commit/33a607a1f716c2029d4a1ff1603dd756129a33b3), [`cc10fc1`](https://github.com/mastra-ai/mastra/commit/cc10fc192d9f527c71a23cc9def10d8718935ee1), [`1f7ee84`](https://github.com/mastra-ai/mastra/commit/1f7ee841a643ef12d90392125881f06fdf877293), [`e7d5149`](https://github.com/mastra-ai/mastra/commit/e7d514995260b63b2108308e85c64de37dcd0f71), [`f195082`](https://github.com/mastra-ai/mastra/commit/f1950822a2425d5ccae78c5d010e02ddb027a869), [`d9986dd`](https://github.com/mastra-ai/mastra/commit/d9986dd3513f7ca3244a8e599a440ccf4d8bc28b), [`a45b0f0`](https://github.com/mastra-ai/mastra/commit/a45b0f0cd19eab1fe4deceae3abf029442c22f74), [`f6e8eb3`](https://github.com/mastra-ai/mastra/commit/f6e8eb3dac53b70b06e906b2818b1d2a5b0486d7), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`3236f35`](https://github.com/mastra-ai/mastra/commit/3236f352ae13cc8552c2965164e97bd125dae48d), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`0230321`](https://github.com/mastra-ai/mastra/commit/02303217870bedea0ef009bea9a952f24ed38aaf), [`7b541f4`](https://github.com/mastra-ai/mastra/commit/7b541f49eda6f5a87b738198edbd136927599475), [`0eea842`](https://github.com/mastra-ai/mastra/commit/0eea8423cbdd37f2111593c6f7d2efcde4b7e4ce), [`63ae8a2`](https://github.com/mastra-ai/mastra/commit/63ae8a22c0c09bbb8b9779f5f38934cd75f616af), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`ac7ef07`](https://github.com/mastra-ai/mastra/commit/ac7ef07633caee89707142171d2873c888ffef85), [`522f0b4`](https://github.com/mastra-ai/mastra/commit/522f0b45330719858794eabffffde4f343f55549), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`8b51d55`](https://github.com/mastra-ai/mastra/commit/8b51d55bae531edf7e383958d7ecee04df31f5d5), [`2131ac5`](https://github.com/mastra-ai/mastra/commit/2131ac571d5065f0a656c57494bca98691bb7609)]:
187
+ - @mastra/core@0.24.6-alpha.0
188
+
189
+ ## 0.3.1
190
+
191
+ ### Minor Changes
192
+
193
+ - Add sendStart, sendFinish, sendReasoning, and sendSources options to toAISdkV5Stream function, allowing fine-grained control over which message chunks are included in the converted stream. Previously, these values were hardcoded in the transformer. ([#10250](https://github.com/mastra-ai/mastra/pull/10250))
194
+
195
+ BREAKING CHANGE: AgentStreamToAISDKTransformer now accepts an options object instead of a single lastMessageId parameter
196
+
197
+ Also, add sendStart, sendFinish, sendReasoning, and sendSources parameters to
198
+ chatRoute function, enabling fine-grained control over which chunks are
199
+ included in the AI SDK stream output.
33
200
 
34
201
  ### Patch Changes
35
202
 
@@ -56,24 +223,7 @@
56
223
  ```
57
224
 
58
225
  - Updated dependencies [[`7491cc0`](https://github.com/mastra-ai/mastra/commit/7491cc0350b2ba067f98c4915bf607119bd0150f), [`0d10ac7`](https://github.com/mastra-ai/mastra/commit/0d10ac7b8efa03c2f0c330eb2520148bfa6091e9), [`e3e899c`](https://github.com/mastra-ai/mastra/commit/e3e899c650f4c435445303bd97a66f5840a52a1e)]:
59
- - @mastra/core@0.24.3-alpha.0
60
-
61
- ## 0.3.0
62
-
63
- ### Minor Changes
64
-
65
- - Add sendStart, sendFinish, sendReasoning, and sendSources options to toAISdkV5Stream function, allowing fine-grained control over which message chunks are included in the converted stream. Previously, these values were hardcoded in the transformer. ([#10250](https://github.com/mastra-ai/mastra/pull/10250))
66
-
67
- BREAKING CHANGE: AgentStreamToAISDKTransformer now accepts an options object instead of a single lastMessageId parameter
68
-
69
- Also, add sendStart, sendFinish, sendReasoning, and sendSources parameters to
70
- chatRoute function, enabling fine-grained control over which chunks are
71
- included in the AI SDK stream output.
72
-
73
- ### Patch Changes
74
-
75
- - Updated dependencies [[`eebb7bb`](https://github.com/mastra-ai/mastra/commit/eebb7bb407c57342a3be3a2efbe68c696589feeb), [`c6e6d07`](https://github.com/mastra-ai/mastra/commit/c6e6d071ecf346a80dceab410af2c567c7e66a57), [`0e6df8f`](https://github.com/mastra-ai/mastra/commit/0e6df8f66340992cb1b319834657deb17368de52), [`6295fd7`](https://github.com/mastra-ai/mastra/commit/6295fd783d49075d5bf2c18ff9486e94d36aaa56), [`d813cf7`](https://github.com/mastra-ai/mastra/commit/d813cf7251695d85cc60469058384ffa74974484)]:
76
- - @mastra/core@0.24.2
226
+ - @mastra/core@0.24.3
77
227
 
78
228
  ## 0.2.7
79
229