@mastra/ai-sdk 0.3.2-alpha.0 → 0.3.3-alpha.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 +108 -0
- package/dist/index.cjs +42 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -20
- package/dist/index.js.map +1 -1
- package/dist/transformers.d.ts +1 -0
- package/dist/transformers.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,113 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
+
## 0.3.3-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Return NetworkDataPart on each agent-execution-event and workflow-execution-event in network streams ([#10979](https://github.com/mastra-ai/mastra/pull/10979))
|
|
8
|
+
|
|
9
|
+
- Fixed tool-call-suspended chunks being dropped in workflow-step-output when using AI SDK. Previously, when an agent inside a workflow step called a tool that got suspended, the tool-call-suspended chunk was not received on the frontend even though tool-input-available chunks were correctly received. ([#10988](https://github.com/mastra-ai/mastra/pull/10988))
|
|
10
|
+
|
|
11
|
+
The issue occurred because tool-call-suspended was not included in the isMastraTextStreamChunk list, causing it to be filtered out in transformWorkflow. Now tool-call-suspended, tool-call-approval, object, and tripwire chunks are properly included in the text stream chunk list and will be transformed and passed through correctly.
|
|
12
|
+
|
|
13
|
+
Fixes #10978
|
|
14
|
+
|
|
15
|
+
- Updated dependencies []:
|
|
16
|
+
- @mastra/core@0.24.7-alpha.3
|
|
17
|
+
|
|
18
|
+
## 0.3.2
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Support streaming agent text chunks from workflow-step-output ([#10568](https://github.com/mastra-ai/mastra/pull/10568))
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
**Features:**
|
|
27
|
+
- Added `includeTextStreamParts` option to `WorkflowStreamToAISDKTransformer` (defaults to `true`)
|
|
28
|
+
- Added `isMastraTextStreamChunk` type guard to identify Mastra chunks with text streaming data
|
|
29
|
+
- Support for streaming text chunks: `text-start`, `text-delta`, `text-end`
|
|
30
|
+
- Support for streaming tool calls: `tool-call`, `tool-result`
|
|
31
|
+
- Comprehensive test coverage in `transformers.test.ts`
|
|
32
|
+
- Updated documentation for workflow streaming and `workflowRoute()`
|
|
33
|
+
|
|
34
|
+
**Example:**
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const planActivities = createStep({
|
|
38
|
+
execute: async ({ mastra, writer }) => {
|
|
39
|
+
const agent = mastra?.getAgent('weatherAgent');
|
|
40
|
+
const response = await agent.stream('Plan activities');
|
|
41
|
+
await response.fullStream.pipeTo(writer);
|
|
42
|
+
|
|
43
|
+
return { activities: await response.text };
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
When served via `workflowRoute()`, the UI receives incremental text updates as the agent generates its response, providing a smooth streaming experience.
|
|
49
|
+
|
|
50
|
+
- 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))
|
|
51
|
+
|
|
52
|
+
- 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))
|
|
53
|
+
|
|
54
|
+
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.
|
|
55
|
+
|
|
56
|
+
**Changes:**
|
|
57
|
+
- Added handling for `workflow-step-output` chunks in `transformWorkflow()` to extract and propagate data-\* chunks
|
|
58
|
+
- 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
|
|
59
|
+
- Added comprehensive test coverage for nested workflows with branches and custom data propagation
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
- Fix network data step formatting in AI SDK stream transformation ([#10525](https://github.com/mastra-ai/mastra/pull/10525))
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
**Changes:**
|
|
68
|
+
- Enhanced step tracking in `AgentNetworkToAISDKTransformer` to properly maintain step state throughout execution lifecycle
|
|
69
|
+
- Steps are now identified by unique IDs and updated in place rather than creating duplicates
|
|
70
|
+
- Added proper iteration and task metadata to each step in the network execution flow
|
|
71
|
+
- Fixed agent, workflow, and tool execution events to correctly populate step data
|
|
72
|
+
- Updated network stream event types to include `networkId`, `workflowId`, and consistent `runId` tracking
|
|
73
|
+
- Added test coverage for network custom data chunks with comprehensive validation
|
|
74
|
+
|
|
75
|
+
This ensures the AI SDK correctly represents the full execution flow of agent networks with accurate step sequencing and metadata.
|
|
76
|
+
|
|
77
|
+
- [0.x] Make workflowRoute includeTextStreamParts option default to false ([#10574](https://github.com/mastra-ai/mastra/pull/10574))
|
|
78
|
+
|
|
79
|
+
- Add support for tool-call-approval and tool-call-suspended events in chatRoute ([#10360](https://github.com/mastra-ai/mastra/pull/10360))
|
|
80
|
+
|
|
81
|
+
- 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))
|
|
82
|
+
- Added `messageMetadata` parameter to `toAISdkFormat` options
|
|
83
|
+
- Function receives the current stream part and returns metadata to attach to start and finish chunks
|
|
84
|
+
- Metadata is included in `start` and `finish` chunks when provided
|
|
85
|
+
- Added `onError` parameter to `toAISdkFormat` options
|
|
86
|
+
- Allows custom error handling during stream conversion
|
|
87
|
+
- Falls back to `safeParseErrorObject` utility when not provided
|
|
88
|
+
- Added `safeParseErrorObject` utility function for error parsing
|
|
89
|
+
- Updated `AgentStreamToAISDKTransformer` to accept and use `messageMetadata` and `onError`
|
|
90
|
+
- Updated JSDoc documentation with parameter descriptions and usage examples
|
|
91
|
+
- Added comprehensive test suite for `messageMetadata` functionality (6 test cases)
|
|
92
|
+
- Fixed existing test file to use `toAISdkFormat` instead of removed `toAISdkV5Stream`
|
|
93
|
+
- All existing tests pass (14 tests across 3 test files)
|
|
94
|
+
- New tests verify:
|
|
95
|
+
- `messageMetadata` is called with correct part structure
|
|
96
|
+
- Metadata is included in start and finish chunks
|
|
97
|
+
- Proper handling when `messageMetadata` is not provided or returns null/undefined
|
|
98
|
+
- Function is called for each relevant part in the stream
|
|
99
|
+
- Uses `UIMessageStreamOptions<UIMessage>['messageMetadata']` and `UIMessageStreamOptions<UIMessage>['onError']` types from AI SDK v5 for full type compatibility
|
|
100
|
+
- Backport of: https://github.com/mastra-ai/mastra/pull/10313
|
|
101
|
+
|
|
102
|
+
- 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))
|
|
103
|
+
|
|
104
|
+
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.
|
|
105
|
+
|
|
106
|
+
See [#10427](https://github.com/mastra-ai/mastra/pull/10427)
|
|
107
|
+
|
|
108
|
+
- 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)]:
|
|
109
|
+
- @mastra/core@0.24.6
|
|
110
|
+
|
|
3
111
|
## 0.3.2-alpha.0
|
|
4
112
|
|
|
5
113
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,8 @@ var isMastraTextStreamChunk = (chunk) => {
|
|
|
22
22
|
"source",
|
|
23
23
|
"tool-input-start",
|
|
24
24
|
"tool-input-delta",
|
|
25
|
+
"tool-call-approval",
|
|
26
|
+
"tool-call-suspended",
|
|
25
27
|
"tool-call",
|
|
26
28
|
"tool-result",
|
|
27
29
|
"tool-error",
|
|
@@ -32,6 +34,8 @@ var isMastraTextStreamChunk = (chunk) => {
|
|
|
32
34
|
"finish",
|
|
33
35
|
"abort",
|
|
34
36
|
"tool-input-end",
|
|
37
|
+
"object",
|
|
38
|
+
"tripwire",
|
|
35
39
|
"raw"
|
|
36
40
|
].includes(chunk.type);
|
|
37
41
|
};
|
|
@@ -1134,6 +1138,26 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
1134
1138
|
};
|
|
1135
1139
|
}
|
|
1136
1140
|
default: {
|
|
1141
|
+
if (isAgentExecutionDataChunkType(payload)) {
|
|
1142
|
+
if (!("data" in payload.payload)) {
|
|
1143
|
+
throw new Error(
|
|
1144
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1145
|
+
${JSON.stringify(payload)}`
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
const { type, data } = payload.payload;
|
|
1149
|
+
return { type, data };
|
|
1150
|
+
}
|
|
1151
|
+
if (isWorkflowExecutionDataChunkType(payload)) {
|
|
1152
|
+
if (!("data" in payload.payload)) {
|
|
1153
|
+
throw new Error(
|
|
1154
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1155
|
+
${JSON.stringify(payload)}`
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
const { type, data } = payload.payload;
|
|
1159
|
+
return { type, data };
|
|
1160
|
+
}
|
|
1137
1161
|
if (payload.type.startsWith("agent-execution-event-")) {
|
|
1138
1162
|
const stepId = payload.payload.runId;
|
|
1139
1163
|
const current = bufferedNetworks.get(payload.runId);
|
|
@@ -1148,6 +1172,15 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
1148
1172
|
const { request, response, ...data } = result.data;
|
|
1149
1173
|
step.task = data;
|
|
1150
1174
|
}
|
|
1175
|
+
bufferedNetworks.set(payload.runId, current);
|
|
1176
|
+
return {
|
|
1177
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
1178
|
+
id: payload.runId,
|
|
1179
|
+
data: {
|
|
1180
|
+
...current,
|
|
1181
|
+
status: "running"
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1151
1184
|
}
|
|
1152
1185
|
if (payload.type.startsWith("workflow-execution-event-")) {
|
|
1153
1186
|
const stepId = payload.payload.runId;
|
|
@@ -1166,6 +1199,15 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
1166
1199
|
step.task.id = data.name;
|
|
1167
1200
|
}
|
|
1168
1201
|
}
|
|
1202
|
+
bufferedNetworks.set(payload.runId, current);
|
|
1203
|
+
return {
|
|
1204
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
1205
|
+
id: payload.runId,
|
|
1206
|
+
data: {
|
|
1207
|
+
...current,
|
|
1208
|
+
status: "running"
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1169
1211
|
}
|
|
1170
1212
|
if (isDataChunkType(payload)) {
|
|
1171
1213
|
if (!("data" in payload)) {
|
|
@@ -1177,26 +1219,6 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
1177
1219
|
const { type, data } = payload;
|
|
1178
1220
|
return { type, data };
|
|
1179
1221
|
}
|
|
1180
|
-
if (isAgentExecutionDataChunkType(payload)) {
|
|
1181
|
-
if (!("data" in payload.payload)) {
|
|
1182
|
-
throw new Error(
|
|
1183
|
-
`UI Messages require a data property when using data- prefixed chunks
|
|
1184
|
-
${JSON.stringify(payload)}`
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
const { type, data } = payload.payload;
|
|
1188
|
-
return { type, data };
|
|
1189
|
-
}
|
|
1190
|
-
if (isWorkflowExecutionDataChunkType(payload)) {
|
|
1191
|
-
if (!("data" in payload.payload)) {
|
|
1192
|
-
throw new Error(
|
|
1193
|
-
`UI Messages require a data property when using data- prefixed chunks
|
|
1194
|
-
${JSON.stringify(payload)}`
|
|
1195
|
-
);
|
|
1196
|
-
}
|
|
1197
|
-
const { type, data } = payload.payload;
|
|
1198
|
-
return { type, data };
|
|
1199
|
-
}
|
|
1200
1222
|
return null;
|
|
1201
1223
|
}
|
|
1202
1224
|
}
|