@mastra/react 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-new-button-export-20251219130424
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 +179 -6
- package/dist/index.cjs +137 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +137 -38
- package/dist/index.js.map +1 -1
- package/dist/src/agent/hooks.d.ts +2 -0
- package/dist/src/lib/ai-sdk/types.d.ts +23 -2
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/react-hooks
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-new-button-export-20251219130424
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -11,15 +11,43 @@
|
|
|
11
11
|
- Renamed `MastraMessageV2` to `MastraDBMessage` ([#9255](https://github.com/mastra-ai/mastra/pull/9255))
|
|
12
12
|
Made the return format of all methods that return db messages consistent. It's always `{ messages: MastraDBMessage[] }` now, and messages can be converted after that using `@mastra/ai-sdk/ui`'s `toAISdkV4/5Messages()` function
|
|
13
13
|
|
|
14
|
+
- Fix "MessagePartRuntime is not available" error when chatting with agents in Studio playground by replacing deprecated `useMessagePart` hook with `useAssistantState` ([#11039](https://github.com/mastra-ai/mastra/pull/11039))
|
|
15
|
+
|
|
14
16
|
### Patch Changes
|
|
15
17
|
|
|
18
|
+
- Remove redundant toolCalls from network agent finalResult ([#11189](https://github.com/mastra-ai/mastra/pull/11189))
|
|
19
|
+
|
|
20
|
+
The network agent's `finalResult` was storing `toolCalls` separately even though all tool call information is already present in the `messages` array (as `tool-call` and `tool-result` type messages). This caused significant token waste since the routing agent reads this data from memory on every iteration.
|
|
21
|
+
|
|
22
|
+
**Before:** `finalResult: { text, toolCalls, messages }`
|
|
23
|
+
**After:** `finalResult: { text, messages }`
|
|
24
|
+
|
|
25
|
+
+**Migration:** If you were accessing `finalResult.toolCalls`, retrieve tool calls from `finalResult.messages` by filtering for messages with `type: 'tool-call'`.
|
|
26
|
+
|
|
27
|
+
Updated `@mastra/react` to extract tool calls directly from the `messages` array instead of the removed `toolCalls` field when resolving initial messages from memory.
|
|
28
|
+
|
|
29
|
+
Fixes #11059
|
|
30
|
+
|
|
31
|
+
- Auto resume suspended tools if `autoResumeSuspendedTools: true` ([#11157](https://github.com/mastra-ai/mastra/pull/11157))
|
|
32
|
+
|
|
33
|
+
The flag can be added to `defaultAgentOptions` when creating the agent or to options in `agent.stream` or `agent.generate`
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
const agent = new Agent({
|
|
37
|
+
//...agent information,
|
|
38
|
+
defaultAgentOptions: {
|
|
39
|
+
autoResumeSuspendedTools: true,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- Adjust the types to accept tracingOptions ([#10742](https://github.com/mastra-ai/mastra/pull/10742))
|
|
45
|
+
|
|
16
46
|
- Configurable resourceId in react useChat ([#10461](https://github.com/mastra-ai/mastra/pull/10461))
|
|
17
47
|
|
|
18
48
|
- Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
|
|
19
49
|
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
Fixes issues where thread and messages were not saved before suspension when tools require approval or call suspend() during execution. This caused conversation history to be lost if users refreshed during tool approval or suspension.
|
|
50
|
+
- Fixes issues where thread and messages were not saved before suspension when tools require approval or call suspend() during execution. This caused conversation history to be lost if users refreshed during tool approval or suspension. ([#10369](https://github.com/mastra-ai/mastra/pull/10369))
|
|
23
51
|
|
|
24
52
|
**Backend changes (@mastra/core):**
|
|
25
53
|
- Add assistant messages to messageList immediately after LLM execution
|
|
@@ -42,8 +70,153 @@
|
|
|
42
70
|
|
|
43
71
|
- Fix multi modal in react sdk ([#9373](https://github.com/mastra-ai/mastra/pull/9373))
|
|
44
72
|
|
|
45
|
-
-
|
|
46
|
-
|
|
73
|
+
- Support new Workflow tripwire run status. Tripwires that are thrown from within a workflow will now bubble up and return a graceful state with information about tripwires. ([#10947](https://github.com/mastra-ai/mastra/pull/10947))
|
|
74
|
+
|
|
75
|
+
When a workflow contains an agent step that triggers a tripwire, the workflow returns with `status: 'tripwire'` and includes tripwire details:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const run = await workflow.createRun();
|
|
79
|
+
const result = await run.start({ inputData: { message: 'Hello' } });
|
|
80
|
+
|
|
81
|
+
if (result.status === 'tripwire') {
|
|
82
|
+
console.log('Workflow terminated by tripwire:', result.tripwire?.reason);
|
|
83
|
+
console.log('Processor ID:', result.tripwire?.processorId);
|
|
84
|
+
console.log('Retry requested:', result.tripwire?.retry);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Adds new UI state for tripwire in agent chat and workflow UI.
|
|
89
|
+
|
|
90
|
+
This is distinct from `status: 'failed'` which indicates an unexpected error. A tripwire status means a processor intentionally stopped execution (e.g., for content moderation).
|
|
91
|
+
|
|
92
|
+
- - Add persistence for custom data chunks (`data-*` parts) emitted via `writer.custom()` in tools ([#10884](https://github.com/mastra-ai/mastra/pull/10884))
|
|
93
|
+
- Data chunks are now saved to message storage so they survive page refreshes
|
|
94
|
+
- Update `@assistant-ui/react` to v0.11.47 with native `DataMessagePart` support
|
|
95
|
+
- Convert `data-*` parts to `DataMessagePart` format (`{ type: 'data', name: string, data: T }`)
|
|
96
|
+
- Update related `@assistant-ui/*` packages for compatibility
|
|
97
|
+
- Updated dependencies [[`6edf340`](https://github.com/mastra-ai/mastra/commit/6edf3402f6a46ee8def2f42a2287785251fbffd6), [`3852192`](https://github.com/mastra-ai/mastra/commit/3852192c81b2a4f1f883f17d80ce50e0c60dba55), [`fec5129`](https://github.com/mastra-ai/mastra/commit/fec5129de7fc64423ea03661a56cef31dc747a0d), [`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808), [`3443770`](https://github.com/mastra-ai/mastra/commit/3443770662df8eb24c9df3589b2792d78cfcb811), [`f0a07e0`](https://github.com/mastra-ai/mastra/commit/f0a07e0111b3307c5fabfa4094c5c2cfb734fbe6), [`aaa40e7`](https://github.com/mastra-ai/mastra/commit/aaa40e788628b319baa8e889407d11ad626547fa), [`695a621`](https://github.com/mastra-ai/mastra/commit/695a621528bdabeb87f83c2277cf2bb084c7f2b4), [`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`ad7e8f1`](https://github.com/mastra-ai/mastra/commit/ad7e8f16ac843cbd16687ad47b66ba96bcffe111), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`e1b7118`](https://github.com/mastra-ai/mastra/commit/e1b7118f42ca0a97247afc75e57dcd5fdf987752), [`441c7b6`](https://github.com/mastra-ai/mastra/commit/441c7b6665915cfa7fd625fded8c0f518530bf10), [`b7de533`](https://github.com/mastra-ai/mastra/commit/b7de53361667eb51fefd89fcaed924f3c57cee8d), [`1b85674`](https://github.com/mastra-ai/mastra/commit/1b85674123708d9b85834dccc9eae601a9d0891c), [`5a1ede1`](https://github.com/mastra-ai/mastra/commit/5a1ede1f7ab527b9ead11f7eee2f73e67aeca9e4), [`7051bf3`](https://github.com/mastra-ai/mastra/commit/7051bf38b3b122a069008f861f7bfc004a6d9f6e), [`1ee3411`](https://github.com/mastra-ai/mastra/commit/1ee34113192b11aa8bcdd8d9d5830ae13254b345), [`dbd9db0`](https://github.com/mastra-ai/mastra/commit/dbd9db0d5c2797a210b9098e7e3e613718e5442f), [`6a86fe5`](https://github.com/mastra-ai/mastra/commit/6a86fe56b8ff53ca2eb3ed87ffc0748749ebadce), [`898a972`](https://github.com/mastra-ai/mastra/commit/898a9727d286c2510d6b702dfd367e6aaf5c6b0f), [`0793497`](https://github.com/mastra-ai/mastra/commit/079349753620c40246ffd673e3f9d7d9820beff3), [`66741d1`](https://github.com/mastra-ai/mastra/commit/66741d1a99c4f42cf23a16109939e8348ac6852e), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`f93d992`](https://github.com/mastra-ai/mastra/commit/f93d992a37d5431ab4a71246835d403ef7c4ce85), [`c576fc0`](https://github.com/mastra-ai/mastra/commit/c576fc0b100b2085afded91a37c97a0ea0ec09c7), [`9f4a683`](https://github.com/mastra-ai/mastra/commit/9f4a6833e88b52574665c028fd5508ad5c2f6004), [`595a3b8`](https://github.com/mastra-ai/mastra/commit/595a3b8727c901f44e333909c09843c711224440), [`ea0b8de`](https://github.com/mastra-ai/mastra/commit/ea0b8dec0d4bc86a72a7e75b2f56c6017c58786d), [`261473a`](https://github.com/mastra-ai/mastra/commit/261473ac637e633064a22076671e2e02b002214d), [`eb09742`](https://github.com/mastra-ai/mastra/commit/eb09742197f66c4c38154c3beec78313e69760b2), [`486352b`](https://github.com/mastra-ai/mastra/commit/486352b66c746602b68a95839f830de14c7fb8c0), [`a1bd7b8`](https://github.com/mastra-ai/mastra/commit/a1bd7b8571db16b94eb01588f451a74758c96d65), [`0633100`](https://github.com/mastra-ai/mastra/commit/0633100a911ad22f5256471bdf753da21c104742), [`354ad0b`](https://github.com/mastra-ai/mastra/commit/354ad0b7b1b8183ac567f236a884fc7ede6d7138), [`519d9e6`](https://github.com/mastra-ai/mastra/commit/519d9e6d31910457c54bdae8b7b7cb3a69f41831), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`5fe71bc`](https://github.com/mastra-ai/mastra/commit/5fe71bc925dfce597df69c89241f33b378028c63), [`dfe3f8c`](https://github.com/mastra-ai/mastra/commit/dfe3f8c7376ffe159236819e19ca522143c1f972), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`e8dcd71`](https://github.com/mastra-ai/mastra/commit/e8dcd71fa5e473c8ba1d6dad99eef182d20a0491), [`e849603`](https://github.com/mastra-ai/mastra/commit/e849603a596269069f58a438b98449ea2770493d), [`63f2f18`](https://github.com/mastra-ai/mastra/commit/63f2f1863dffe3ad23221d0660ed4e4f2b81789d), [`c23200d`](https://github.com/mastra-ai/mastra/commit/c23200ddfd60830effb39329674ba4ca93be6aac), [`363284b`](https://github.com/mastra-ai/mastra/commit/363284bb974e850f06f40f89a28c79d9f432d7e4), [`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc), [`439eaf7`](https://github.com/mastra-ai/mastra/commit/439eaf75447809b05e326666675a4dcbf9c334ce), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`a7ce182`](https://github.com/mastra-ai/mastra/commit/a7ce1822a8785ce45d62dd5c911af465e144f7d7), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`21735a7`](https://github.com/mastra-ai/mastra/commit/21735a7ef306963554a69a89b44f06c3bcd85141), [`3bf6c5f`](https://github.com/mastra-ai/mastra/commit/3bf6c5f104c25226cd84e0c77f9dec15f2cac2db), [`a0c8c1b`](https://github.com/mastra-ai/mastra/commit/a0c8c1b87d4fee252aebda73e8637fbe01d761c9), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014), [`e1bb9c9`](https://github.com/mastra-ai/mastra/commit/e1bb9c94b4eb68b019ae275981be3feb769b5365)]:
|
|
98
|
+
- @mastra/client-js@0.0.0-new-button-export-20251219130424
|
|
99
|
+
|
|
100
|
+
## 0.1.0-beta.14
|
|
101
|
+
|
|
102
|
+
### Patch Changes
|
|
103
|
+
|
|
104
|
+
- Updated dependencies [[`66741d1`](https://github.com/mastra-ai/mastra/commit/66741d1a99c4f42cf23a16109939e8348ac6852e), [`a7ce182`](https://github.com/mastra-ai/mastra/commit/a7ce1822a8785ce45d62dd5c911af465e144f7d7)]:
|
|
105
|
+
- @mastra/client-js@1.0.0-beta.14
|
|
106
|
+
|
|
107
|
+
## 0.1.0-beta.13
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- Updated dependencies:
|
|
112
|
+
- @mastra/client-js@1.0.0-beta.13
|
|
113
|
+
|
|
114
|
+
## 0.1.0-beta.12
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- Remove redundant toolCalls from network agent finalResult ([#11189](https://github.com/mastra-ai/mastra/pull/11189))
|
|
119
|
+
|
|
120
|
+
The network agent's `finalResult` was storing `toolCalls` separately even though all tool call information is already present in the `messages` array (as `tool-call` and `tool-result` type messages). This caused significant token waste since the routing agent reads this data from memory on every iteration.
|
|
121
|
+
|
|
122
|
+
**Before:** `finalResult: { text, toolCalls, messages }`
|
|
123
|
+
**After:** `finalResult: { text, messages }`
|
|
124
|
+
|
|
125
|
+
+**Migration:** If you were accessing `finalResult.toolCalls`, retrieve tool calls from `finalResult.messages` by filtering for messages with `type: 'tool-call'`.
|
|
126
|
+
|
|
127
|
+
Updated `@mastra/react` to extract tool calls directly from the `messages` array instead of the removed `toolCalls` field when resolving initial messages from memory.
|
|
128
|
+
|
|
129
|
+
Fixes #11059
|
|
130
|
+
|
|
131
|
+
- Auto resume suspended tools if `autoResumeSuspendedTools: true` ([#11157](https://github.com/mastra-ai/mastra/pull/11157))
|
|
132
|
+
|
|
133
|
+
The flag can be added to `defaultAgentOptions` when creating the agent or to options in `agent.stream` or `agent.generate`
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const agent = new Agent({
|
|
137
|
+
//...agent information,
|
|
138
|
+
defaultAgentOptions: {
|
|
139
|
+
autoResumeSuspendedTools: true,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
- Updated dependencies [[`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808), [`695a621`](https://github.com/mastra-ai/mastra/commit/695a621528bdabeb87f83c2277cf2bb084c7f2b4), [`1b85674`](https://github.com/mastra-ai/mastra/commit/1b85674123708d9b85834dccc9eae601a9d0891c), [`486352b`](https://github.com/mastra-ai/mastra/commit/486352b66c746602b68a95839f830de14c7fb8c0), [`439eaf7`](https://github.com/mastra-ai/mastra/commit/439eaf75447809b05e326666675a4dcbf9c334ce)]:
|
|
145
|
+
- @mastra/client-js@1.0.0-beta.12
|
|
146
|
+
|
|
147
|
+
## 0.1.0-beta.11
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- Support new Workflow tripwire run status. Tripwires that are thrown from within a workflow will now bubble up and return a graceful state with information about tripwires. ([#10947](https://github.com/mastra-ai/mastra/pull/10947))
|
|
152
|
+
|
|
153
|
+
When a workflow contains an agent step that triggers a tripwire, the workflow returns with `status: 'tripwire'` and includes tripwire details:
|
|
154
|
+
|
|
155
|
+
```typescript showLineNumbers copy
|
|
156
|
+
const run = await workflow.createRun();
|
|
157
|
+
const result = await run.start({ inputData: { message: 'Hello' } });
|
|
158
|
+
|
|
159
|
+
if (result.status === 'tripwire') {
|
|
160
|
+
console.log('Workflow terminated by tripwire:', result.tripwire?.reason);
|
|
161
|
+
console.log('Processor ID:', result.tripwire?.processorId);
|
|
162
|
+
console.log('Retry requested:', result.tripwire?.retry);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Adds new UI state for tripwire in agent chat and workflow UI.
|
|
167
|
+
|
|
168
|
+
This is distinct from `status: 'failed'` which indicates an unexpected error. A tripwire status means a processor intentionally stopped execution (e.g., for content moderation).
|
|
169
|
+
|
|
170
|
+
- Updated dependencies [[`3bf6c5f`](https://github.com/mastra-ai/mastra/commit/3bf6c5f104c25226cd84e0c77f9dec15f2cac2db)]:
|
|
171
|
+
- @mastra/client-js@1.0.0-beta.11
|
|
172
|
+
|
|
173
|
+
## 0.1.0-beta.10
|
|
174
|
+
|
|
175
|
+
### Minor Changes
|
|
176
|
+
|
|
177
|
+
- Fix "MessagePartRuntime is not available" error when chatting with agents in Studio playground by replacing deprecated `useMessagePart` hook with `useAssistantState` ([#11039](https://github.com/mastra-ai/mastra/pull/11039))
|
|
178
|
+
|
|
179
|
+
### Patch Changes
|
|
180
|
+
|
|
181
|
+
- fix: persist data-\* chunks from writer.custom() to memory storage ([#10884](https://github.com/mastra-ai/mastra/pull/10884))
|
|
182
|
+
- Add persistence for custom data chunks (`data-*` parts) emitted via `writer.custom()` in tools
|
|
183
|
+
- Data chunks are now saved to message storage so they survive page refreshes
|
|
184
|
+
- Update `@assistant-ui/react` to v0.11.47 with native `DataMessagePart` support
|
|
185
|
+
- Convert `data-*` parts to `DataMessagePart` format (`{ type: 'data', name: string, data: T }`)
|
|
186
|
+
- Update related `@assistant-ui/*` packages for compatibility
|
|
187
|
+
|
|
188
|
+
- Updated dependencies [[`261473a`](https://github.com/mastra-ai/mastra/commit/261473ac637e633064a22076671e2e02b002214d)]:
|
|
189
|
+
- @mastra/client-js@1.0.0-beta.10
|
|
190
|
+
|
|
191
|
+
## 0.1.0-beta.9
|
|
192
|
+
|
|
193
|
+
### Patch Changes
|
|
194
|
+
|
|
195
|
+
- Updated dependencies [[`5a1ede1`](https://github.com/mastra-ai/mastra/commit/5a1ede1f7ab527b9ead11f7eee2f73e67aeca9e4)]:
|
|
196
|
+
- @mastra/client-js@1.0.0-beta.9
|
|
197
|
+
|
|
198
|
+
## 0.1.0-beta.8
|
|
199
|
+
|
|
200
|
+
### Patch Changes
|
|
201
|
+
|
|
202
|
+
- Updated dependencies:
|
|
203
|
+
- @mastra/client-js@1.0.0-beta.8
|
|
204
|
+
|
|
205
|
+
## 0.1.0-beta.7
|
|
206
|
+
|
|
207
|
+
### Patch Changes
|
|
208
|
+
|
|
209
|
+
- Updated dependencies [[`5fe71bc`](https://github.com/mastra-ai/mastra/commit/5fe71bc925dfce597df69c89241f33b378028c63), [`21735a7`](https://github.com/mastra-ai/mastra/commit/21735a7ef306963554a69a89b44f06c3bcd85141)]:
|
|
210
|
+
- @mastra/client-js@1.0.0-beta.7
|
|
211
|
+
|
|
212
|
+
## 0.1.0-beta.6
|
|
213
|
+
|
|
214
|
+
### Patch Changes
|
|
215
|
+
|
|
216
|
+
- Adjust the types to accept tracingOptions ([#10742](https://github.com/mastra-ai/mastra/pull/10742))
|
|
217
|
+
|
|
218
|
+
- Updated dependencies [[`6edf340`](https://github.com/mastra-ai/mastra/commit/6edf3402f6a46ee8def2f42a2287785251fbffd6), [`ad7e8f1`](https://github.com/mastra-ai/mastra/commit/ad7e8f16ac843cbd16687ad47b66ba96bcffe111), [`e1b7118`](https://github.com/mastra-ai/mastra/commit/e1b7118f42ca0a97247afc75e57dcd5fdf987752), [`441c7b6`](https://github.com/mastra-ai/mastra/commit/441c7b6665915cfa7fd625fded8c0f518530bf10), [`e849603`](https://github.com/mastra-ai/mastra/commit/e849603a596269069f58a438b98449ea2770493d)]:
|
|
219
|
+
- @mastra/client-js@1.0.0-beta.6
|
|
47
220
|
|
|
48
221
|
## 0.1.0-beta.5
|
|
49
222
|
|
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
51
51
|
return {
|
|
52
52
|
...prev,
|
|
53
53
|
status: chunk.payload.workflowStatus,
|
|
54
|
-
...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : {}
|
|
54
|
+
...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : finalStatus === "tripwire" && chunk.payload.tripwire ? { tripwire: chunk.payload.tripwire } : {}
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
const { stepCallId, stepName, ...newPayload } = chunk.payload ?? {};
|
|
@@ -103,6 +103,34 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
103
103
|
};
|
|
104
104
|
const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
105
105
|
const result = [...conversation];
|
|
106
|
+
if (chunk.type.startsWith("data-")) {
|
|
107
|
+
const lastMessage = result[result.length - 1];
|
|
108
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
109
|
+
const newMessage = {
|
|
110
|
+
id: `data-${chunk.runId}-${Date.now()}`,
|
|
111
|
+
role: "assistant",
|
|
112
|
+
parts: [
|
|
113
|
+
{
|
|
114
|
+
type: chunk.type,
|
|
115
|
+
data: "data" in chunk ? chunk.data : void 0
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
metadata
|
|
119
|
+
};
|
|
120
|
+
return [...result, newMessage];
|
|
121
|
+
}
|
|
122
|
+
const updatedMessage = {
|
|
123
|
+
...lastMessage,
|
|
124
|
+
parts: [
|
|
125
|
+
...lastMessage.parts,
|
|
126
|
+
{
|
|
127
|
+
type: chunk.type,
|
|
128
|
+
data: "data" in chunk ? chunk.data : void 0
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
};
|
|
132
|
+
return [...result.slice(0, -1), updatedMessage];
|
|
133
|
+
}
|
|
106
134
|
switch (chunk.type) {
|
|
107
135
|
case "tripwire": {
|
|
108
136
|
const newMessage = {
|
|
@@ -111,19 +139,24 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
111
139
|
parts: [
|
|
112
140
|
{
|
|
113
141
|
type: "text",
|
|
114
|
-
text: chunk.payload.
|
|
142
|
+
text: chunk.payload.reason
|
|
115
143
|
}
|
|
116
144
|
],
|
|
117
145
|
metadata: {
|
|
118
146
|
...metadata,
|
|
119
|
-
status: "
|
|
147
|
+
status: "tripwire",
|
|
148
|
+
tripwire: {
|
|
149
|
+
retry: chunk.payload.retry,
|
|
150
|
+
tripwirePayload: chunk.payload.metadata,
|
|
151
|
+
processorId: chunk.payload.processorId
|
|
152
|
+
}
|
|
120
153
|
}
|
|
121
154
|
};
|
|
122
155
|
return [...result, newMessage];
|
|
123
156
|
}
|
|
124
157
|
case "start": {
|
|
125
158
|
const newMessage = {
|
|
126
|
-
id: `start-${chunk.runId + Date.now()}`,
|
|
159
|
+
id: typeof chunk.payload.messageId === "string" ? chunk.payload.messageId : `start-${chunk.runId + Date.now()}`,
|
|
127
160
|
role: "assistant",
|
|
128
161
|
parts: [],
|
|
129
162
|
metadata
|
|
@@ -428,7 +461,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
428
461
|
mode: "stream",
|
|
429
462
|
requireApprovalMetadata: {
|
|
430
463
|
...lastRequireApprovalMetadata,
|
|
431
|
-
[chunk.payload.
|
|
464
|
+
[chunk.payload.toolName]: {
|
|
432
465
|
toolCallId: chunk.payload.toolCallId,
|
|
433
466
|
toolName: chunk.payload.toolName,
|
|
434
467
|
args: chunk.payload.args
|
|
@@ -438,6 +471,30 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
438
471
|
}
|
|
439
472
|
];
|
|
440
473
|
}
|
|
474
|
+
case "tool-call-suspended": {
|
|
475
|
+
const lastMessage = result[result.length - 1];
|
|
476
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
477
|
+
const lastSuspendedTools = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.suspendedTools : {};
|
|
478
|
+
return [
|
|
479
|
+
...result.slice(0, -1),
|
|
480
|
+
{
|
|
481
|
+
...lastMessage,
|
|
482
|
+
metadata: {
|
|
483
|
+
...lastMessage.metadata,
|
|
484
|
+
mode: "stream",
|
|
485
|
+
suspendedTools: {
|
|
486
|
+
...lastSuspendedTools,
|
|
487
|
+
[chunk.payload.toolName]: {
|
|
488
|
+
toolCallId: chunk.payload.toolCallId,
|
|
489
|
+
toolName: chunk.payload.toolName,
|
|
490
|
+
args: chunk.payload.args,
|
|
491
|
+
suspendPayload: chunk.payload.suspendPayload
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
];
|
|
497
|
+
}
|
|
441
498
|
case "finish": {
|
|
442
499
|
const lastMessage = result[result.length - 1];
|
|
443
500
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
@@ -653,13 +710,14 @@ const toAssistantUIMessage = (message) => {
|
|
|
653
710
|
return baseToolCall;
|
|
654
711
|
}
|
|
655
712
|
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
656
|
-
const
|
|
713
|
+
const toolName2 = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
|
|
714
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
657
715
|
const baseToolCall = {
|
|
658
716
|
type: "tool-call",
|
|
659
717
|
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
660
|
-
toolName,
|
|
661
|
-
argsText:
|
|
662
|
-
args:
|
|
718
|
+
toolName: toolName2,
|
|
719
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
720
|
+
args: cleanInput ?? {},
|
|
663
721
|
metadata: message.metadata
|
|
664
722
|
};
|
|
665
723
|
if ("output" in part) {
|
|
@@ -669,20 +727,31 @@ const toAssistantUIMessage = (message) => {
|
|
|
669
727
|
}
|
|
670
728
|
return baseToolCall;
|
|
671
729
|
}
|
|
730
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
672
731
|
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
732
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
673
733
|
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
674
|
-
const suspensionData =
|
|
734
|
+
const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
|
|
675
735
|
if (suspensionData) {
|
|
676
|
-
const
|
|
736
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
677
737
|
return {
|
|
678
738
|
type: "tool-call",
|
|
679
739
|
toolCallId: partToolCallId,
|
|
680
740
|
toolName,
|
|
681
|
-
argsText:
|
|
682
|
-
args:
|
|
741
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
742
|
+
args: cleanInput,
|
|
683
743
|
metadata: extendedMessage.metadata
|
|
684
744
|
};
|
|
685
745
|
}
|
|
746
|
+
if (part.type.startsWith("data-")) {
|
|
747
|
+
return {
|
|
748
|
+
type: "data",
|
|
749
|
+
name: part.type.substring(5),
|
|
750
|
+
// Extract name from 'data-{name}'
|
|
751
|
+
data: part.data,
|
|
752
|
+
metadata: message.metadata
|
|
753
|
+
};
|
|
754
|
+
}
|
|
686
755
|
return {
|
|
687
756
|
type: "text",
|
|
688
757
|
text: "",
|
|
@@ -735,28 +804,34 @@ const resolveInitialMessages = (messages) => {
|
|
|
735
804
|
const primitiveType = json.primitiveType || "";
|
|
736
805
|
const primitiveId = json.primitiveId || "";
|
|
737
806
|
const finalResult = json.finalResult;
|
|
738
|
-
const
|
|
807
|
+
const messages2 = finalResult?.messages || [];
|
|
739
808
|
const childMessages = [];
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
809
|
+
const toolResultMap = /* @__PURE__ */ new Map();
|
|
810
|
+
for (const msg of messages2) {
|
|
811
|
+
if (Array.isArray(msg.content)) {
|
|
812
|
+
for (const part of msg.content) {
|
|
813
|
+
if (typeof part === "object" && part.type === "tool-result") {
|
|
814
|
+
toolResultMap.set(part.toolCallId, part);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
for (const msg of messages2) {
|
|
820
|
+
if (msg.type === "tool-call" && Array.isArray(msg.content)) {
|
|
821
|
+
for (const part of msg.content) {
|
|
822
|
+
if (typeof part === "object" && part.type === "tool-call") {
|
|
823
|
+
const toolCallContent = part;
|
|
824
|
+
const toolResult = toolResultMap.get(toolCallContent.toolCallId);
|
|
825
|
+
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
826
|
+
childMessages.push({
|
|
827
|
+
type: "tool",
|
|
828
|
+
toolCallId: toolCallContent.toolCallId,
|
|
829
|
+
toolName: toolCallContent.toolName,
|
|
830
|
+
args: toolCallContent.args,
|
|
831
|
+
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
832
|
+
});
|
|
750
833
|
}
|
|
751
834
|
}
|
|
752
|
-
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
753
|
-
childMessages.push({
|
|
754
|
-
type: "tool",
|
|
755
|
-
toolCallId: toolCall.payload.toolCallId,
|
|
756
|
-
toolName: toolCall.payload.toolName,
|
|
757
|
-
args: toolCall.payload.args,
|
|
758
|
-
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
759
|
-
});
|
|
760
835
|
}
|
|
761
836
|
}
|
|
762
837
|
if (finalResult && finalResult.text) {
|
|
@@ -808,6 +883,17 @@ const resolveInitialMessages = (messages) => {
|
|
|
808
883
|
}
|
|
809
884
|
};
|
|
810
885
|
}
|
|
886
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
887
|
+
if (suspendedTools && typeof suspendedTools === "object") {
|
|
888
|
+
return {
|
|
889
|
+
...message,
|
|
890
|
+
metadata: {
|
|
891
|
+
...message.metadata,
|
|
892
|
+
mode: "stream",
|
|
893
|
+
suspendedTools
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
}
|
|
811
897
|
return message;
|
|
812
898
|
});
|
|
813
899
|
};
|
|
@@ -1283,7 +1369,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
|
1283
1369
|
threadId,
|
|
1284
1370
|
modelSettings,
|
|
1285
1371
|
signal,
|
|
1286
|
-
onFinish
|
|
1372
|
+
onFinish,
|
|
1373
|
+
tracingOptions
|
|
1287
1374
|
}) => {
|
|
1288
1375
|
const {
|
|
1289
1376
|
frequencyPenalty,
|
|
@@ -1319,7 +1406,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
|
1319
1406
|
instructions,
|
|
1320
1407
|
requestContext,
|
|
1321
1408
|
...threadId ? { threadId, resourceId: resourceId || agentId } : {},
|
|
1322
|
-
providerOptions
|
|
1409
|
+
providerOptions,
|
|
1410
|
+
tracingOptions
|
|
1323
1411
|
});
|
|
1324
1412
|
setIsRunning(false);
|
|
1325
1413
|
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
@@ -1333,7 +1421,15 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
|
1333
1421
|
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
1334
1422
|
}
|
|
1335
1423
|
};
|
|
1336
|
-
const stream = async ({
|
|
1424
|
+
const stream = async ({
|
|
1425
|
+
coreUserMessages,
|
|
1426
|
+
requestContext,
|
|
1427
|
+
threadId,
|
|
1428
|
+
onChunk,
|
|
1429
|
+
modelSettings,
|
|
1430
|
+
signal,
|
|
1431
|
+
tracingOptions
|
|
1432
|
+
}) => {
|
|
1337
1433
|
const {
|
|
1338
1434
|
frequencyPenalty,
|
|
1339
1435
|
presencePenalty,
|
|
@@ -1371,7 +1467,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
|
1371
1467
|
requestContext,
|
|
1372
1468
|
...threadId ? { threadId, resourceId: resourceId || agentId } : {},
|
|
1373
1469
|
providerOptions,
|
|
1374
|
-
requireToolApproval
|
|
1470
|
+
requireToolApproval,
|
|
1471
|
+
tracingOptions
|
|
1375
1472
|
});
|
|
1376
1473
|
_onChunk.current = onChunk;
|
|
1377
1474
|
_currentRunId.current = runId;
|
|
@@ -1389,7 +1486,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
|
1389
1486
|
threadId,
|
|
1390
1487
|
onNetworkChunk,
|
|
1391
1488
|
modelSettings,
|
|
1392
|
-
signal
|
|
1489
|
+
signal,
|
|
1490
|
+
tracingOptions
|
|
1393
1491
|
}) => {
|
|
1394
1492
|
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
|
|
1395
1493
|
setIsRunning(true);
|
|
@@ -1413,7 +1511,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
|
1413
1511
|
},
|
|
1414
1512
|
runId,
|
|
1415
1513
|
requestContext,
|
|
1416
|
-
...threadId ? { thread: threadId, resourceId: resourceId || agentId } : {}
|
|
1514
|
+
...threadId ? { thread: threadId, resourceId: resourceId || agentId } : {},
|
|
1515
|
+
tracingOptions
|
|
1417
1516
|
});
|
|
1418
1517
|
const transformer = new AISdkNetworkTransformer();
|
|
1419
1518
|
await response.processDataStream({
|