@mastra/react 0.0.0-refactor-agent-information-for-recomposable-ui-20251112151814 → 0.0.0-safe-stringify-telemetry-20251205024938

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,58 +1,232 @@
1
1
  # @mastra/react-hooks
2
2
 
3
- ## 0.0.0-refactor-agent-information-for-recomposable-ui-20251112151814
3
+ ## 0.0.0-safe-stringify-telemetry-20251205024938
4
4
 
5
- ### Minor Changes
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`5de72e1`](https://github.com/mastra-ai/mastra/commit/5de72e1a3fa51b860e7e0a606b66cf6f97fc100c), [`2b62302`](https://github.com/mastra-ai/mastra/commit/2b623027a9d65c1dbc963bf651e9e6a9d09da1fa)]:
8
+ - @mastra/client-js@0.0.0-safe-stringify-telemetry-20251205024938
6
9
 
7
- - Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
10
+ ## 0.0.22-alpha.0
8
11
 
9
- - Rename RuntimeContext to RequestContext ([#9511](https://github.com/mastra-ai/mastra/pull/9511))
12
+ ### Patch Changes
10
13
 
11
- - Renamed `MastraMessageV2` to `MastraDBMessage` ([#9255](https://github.com/mastra-ai/mastra/pull/9255))
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
14
+ - Updated dependencies []:
15
+ - @mastra/client-js@0.16.16-alpha.0
16
+
17
+ ## 0.0.21
13
18
 
14
19
  ### Patch Changes
15
20
 
16
- - Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
21
+ - Configurable resourceId in react useChat ([#10561](https://github.com/mastra-ai/mastra/pull/10561))
22
+
23
+ - fix(agent): persist messages before tool suspension ([#10542](https://github.com/mastra-ai/mastra/pull/10542))
24
+
25
+ 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.
26
+
27
+ **Backend changes (@mastra/core):**
28
+ - Add assistant messages to messageList immediately after LLM execution
29
+ - Flush messages synchronously before suspension to persist state
30
+ - Create thread if it doesn't exist before flushing
31
+ - Add metadata helpers to persist and remove tool approval state
32
+ - Pass saveQueueManager and memory context through workflow for immediate persistence
33
+
34
+ **Frontend changes (@mastra/react):**
35
+ - Extract runId from pending approvals to enable resumption after refresh
36
+ - Convert `pendingToolApprovals` (DB format) to `requireApprovalMetadata` (runtime format)
37
+ - Handle both `dynamic-tool` and `tool-{NAME}` part types for approval state
38
+ - Change runId from hardcoded `agentId` to unique `uuid()`
39
+
40
+ **UI changes (@mastra/playground-ui):**
41
+ - Handle tool calls awaiting approval in message initialization
42
+ - Convert approval metadata format when loading initial messages
43
+
44
+ Fixes #9745, #9906
45
+
46
+ - Updated dependencies []:
47
+ - @mastra/client-js@0.16.15
48
+
49
+ ## 0.0.21-alpha.0
50
+
51
+ ### Patch Changes
52
+
53
+ - Configurable resourceId in react useChat ([#10561](https://github.com/mastra-ai/mastra/pull/10561))
54
+
55
+ - fix(agent): persist messages before tool suspension ([#10542](https://github.com/mastra-ai/mastra/pull/10542))
56
+
57
+ 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.
58
+
59
+ **Backend changes (@mastra/core):**
60
+ - Add assistant messages to messageList immediately after LLM execution
61
+ - Flush messages synchronously before suspension to persist state
62
+ - Create thread if it doesn't exist before flushing
63
+ - Add metadata helpers to persist and remove tool approval state
64
+ - Pass saveQueueManager and memory context through workflow for immediate persistence
65
+
66
+ **Frontend changes (@mastra/react):**
67
+ - Extract runId from pending approvals to enable resumption after refresh
68
+ - Convert `pendingToolApprovals` (DB format) to `requireApprovalMetadata` (runtime format)
69
+ - Handle both `dynamic-tool` and `tool-{NAME}` part types for approval state
70
+ - Change runId from hardcoded `agentId` to unique `uuid()`
71
+
72
+ **UI changes (@mastra/playground-ui):**
73
+ - Handle tool calls awaiting approval in message initialization
74
+ - Convert approval metadata format when loading initial messages
75
+
76
+ Fixes #9745, #9906
77
+
78
+ - Updated dependencies []:
79
+ - @mastra/client-js@0.16.15-alpha.0
80
+
81
+ ## 0.0.20
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies []:
86
+ - @mastra/client-js@0.16.14
87
+
88
+ ## 0.0.20-alpha.0
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies []:
93
+ - @mastra/client-js@0.16.14-alpha.0
94
+
95
+ ## 0.0.19
96
+
97
+ ### Patch Changes
98
+
99
+ - Updated dependencies []:
100
+ - @mastra/client-js@0.16.13
101
+
102
+ ## 0.0.19-alpha.0
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies []:
107
+ - @mastra/client-js@0.16.13-alpha.0
108
+
109
+ ## 0.0.18
110
+
111
+ ### Patch Changes
112
+
113
+ - Updated dependencies [[`91fa2b0`](https://github.com/mastra-ai/mastra/commit/91fa2b0cf077561d835baef8519a1422f1decd55)]:
114
+ - @mastra/client-js@0.16.12
17
115
 
18
- - Fix multi modal in react sdk ([#9373](https://github.com/mastra-ai/mastra/pull/9373))
116
+ ## 0.0.18-alpha.0
19
117
 
20
- - Updated dependencies [[`3852192`](https://github.com/mastra-ai/mastra/commit/3852192c81b2a4f1f883f17d80ce50e0c60dba55), [`fec5129`](https://github.com/mastra-ai/mastra/commit/fec5129de7fc64423ea03661a56cef31dc747a0d), [`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), [`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`b7de533`](https://github.com/mastra-ai/mastra/commit/b7de53361667eb51fefd89fcaed924f3c57cee8d), [`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), [`0793497`](https://github.com/mastra-ai/mastra/commit/079349753620c40246ffd673e3f9d7d9820beff3), [`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), [`ea0b8de`](https://github.com/mastra-ai/mastra/commit/ea0b8dec0d4bc86a72a7e75b2f56c6017c58786d), [`eb09742`](https://github.com/mastra-ai/mastra/commit/eb09742197f66c4c38154c3beec78313e69760b2), [`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), [`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), [`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), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`a0c8c1b`](https://github.com/mastra-ai/mastra/commit/a0c8c1b87d4fee252aebda73e8637fbe01d761c9), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014)]:
21
- - @mastra/client-js@0.0.0-refactor-agent-information-for-recomposable-ui-20251112151814
118
+ ### Patch Changes
119
+
120
+ - Updated dependencies [[`91fa2b0`](https://github.com/mastra-ai/mastra/commit/91fa2b0cf077561d835baef8519a1422f1decd55)]:
121
+ - @mastra/client-js@0.16.12-alpha.0
122
+
123
+ ## 0.0.17
124
+
125
+ ### Patch Changes
126
+
127
+ - Updated dependencies []:
128
+ - @mastra/client-js@0.16.11
129
+
130
+ ## 0.0.17-alpha.0
131
+
132
+ ### Patch Changes
133
+
134
+ - Updated dependencies []:
135
+ - @mastra/client-js@0.16.11-alpha.0
136
+
137
+ ## 0.0.16
138
+
139
+ ### Patch Changes
140
+
141
+ - Updated dependencies [[`082393c`](https://github.com/mastra-ai/mastra/commit/082393c002f3751113a48da28e4c0ed3db9824d7)]:
142
+ - @mastra/client-js@0.16.10
143
+
144
+ ## 0.0.16-alpha.0
145
+
146
+ ### Patch Changes
147
+
148
+ - Updated dependencies [[`082393c`](https://github.com/mastra-ai/mastra/commit/082393c002f3751113a48da28e4c0ed3db9824d7)]:
149
+ - @mastra/client-js@0.16.10-alpha.0
150
+
151
+ ## 0.0.15
152
+
153
+ ### Patch Changes
154
+
155
+ - update peerdeps ([`5ca1cca`](https://github.com/mastra-ai/mastra/commit/5ca1ccac61ffa7141e6d9fa8f22d3ad4d03bf5dc))
156
+
157
+ - Updated dependencies [[`5ca1cca`](https://github.com/mastra-ai/mastra/commit/5ca1ccac61ffa7141e6d9fa8f22d3ad4d03bf5dc), [`23c2614`](https://github.com/mastra-ai/mastra/commit/23c26140fdbf04b8c59e8d7d52106d67dad962ec), [`139588d`](https://github.com/mastra-ai/mastra/commit/139588df7755c9111a3060f72a789c1a8c95e091), [`186b29b`](https://github.com/mastra-ai/mastra/commit/186b29bd51ac1dcc24ad3825fdb7207a6d6391a6)]:
158
+ - @mastra/client-js@0.16.9
22
159
 
23
- ## 0.1.0-beta.2
160
+ ## 0.0.15-alpha.0
161
+
162
+ ### Patch Changes
163
+
164
+ - update peerdeps ([`5ca1cca`](https://github.com/mastra-ai/mastra/commit/5ca1ccac61ffa7141e6d9fa8f22d3ad4d03bf5dc))
165
+
166
+ - Updated dependencies [[`5ca1cca`](https://github.com/mastra-ai/mastra/commit/5ca1ccac61ffa7141e6d9fa8f22d3ad4d03bf5dc), [`23c2614`](https://github.com/mastra-ai/mastra/commit/23c26140fdbf04b8c59e8d7d52106d67dad962ec), [`139588d`](https://github.com/mastra-ai/mastra/commit/139588df7755c9111a3060f72a789c1a8c95e091), [`186b29b`](https://github.com/mastra-ai/mastra/commit/186b29bd51ac1dcc24ad3825fdb7207a6d6391a6)]:
167
+ - @mastra/client-js@0.16.9-alpha.0
168
+
169
+ ## 0.0.14
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies [[`b55bbce`](https://github.com/mastra-ai/mastra/commit/b55bbce89404d35fdd967012dd503fae343d4c2d), [`e742d37`](https://github.com/mastra-ai/mastra/commit/e742d371f24ef8059670cc05e9aee308eac068b9)]:
174
+ - @mastra/client-js@0.16.8
175
+
176
+ ## 0.0.14-alpha.0
177
+
178
+ ### Patch Changes
179
+
180
+ - Updated dependencies [[`b55bbce`](https://github.com/mastra-ai/mastra/commit/b55bbce89404d35fdd967012dd503fae343d4c2d), [`e742d37`](https://github.com/mastra-ai/mastra/commit/e742d371f24ef8059670cc05e9aee308eac068b9)]:
181
+ - @mastra/client-js@0.16.8-alpha.0
182
+
183
+ ## 0.0.13
24
184
 
25
185
  ### Patch Changes
26
186
 
27
187
  - Updated dependencies []:
28
- - @mastra/client-js@1.0.0-beta.2
188
+ - @mastra/client-js@0.16.7
29
189
 
30
- ## 0.1.0-beta.1
190
+ ## 0.0.13-alpha.1
31
191
 
32
192
  ### Patch Changes
33
193
 
34
- - Updated dependencies [[`dbd9db0`](https://github.com/mastra-ai/mastra/commit/dbd9db0d5c2797a210b9098e7e3e613718e5442f)]:
35
- - @mastra/client-js@1.0.0-beta.1
194
+ - Updated dependencies []:
195
+ - @mastra/client-js@0.16.7-alpha.1
196
+
197
+ ## 0.0.13-alpha.0
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies []:
202
+ - @mastra/client-js@0.16.7-alpha.0
36
203
 
37
- ## 0.1.0-beta.0
204
+ ## 0.0.12
38
205
 
39
- ### Minor Changes
206
+ ### Patch Changes
40
207
 
41
- - Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
208
+ - Fix peerdependencies ([`eb7c1c8`](https://github.com/mastra-ai/mastra/commit/eb7c1c8c592d8fb16dfd250e337d9cdc73c8d5de))
42
209
 
43
- - Rename RuntimeContext to RequestContext ([#9511](https://github.com/mastra-ai/mastra/pull/9511))
210
+ - Updated dependencies [[`eb7c1c8`](https://github.com/mastra-ai/mastra/commit/eb7c1c8c592d8fb16dfd250e337d9cdc73c8d5de)]:
211
+ - @mastra/client-js@0.16.6
44
212
 
45
- - Renamed `MastraMessageV2` to `MastraDBMessage` ([#9255](https://github.com/mastra-ai/mastra/pull/9255))
46
- 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
213
+ ## 0.0.11
47
214
 
48
215
  ### Patch Changes
49
216
 
50
217
  - Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
51
218
 
52
- - Fix multi modal in react sdk ([#9373](https://github.com/mastra-ai/mastra/pull/9373))
219
+ - Updated dependencies [[`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18)]:
220
+ - @mastra/client-js@0.16.5
221
+
222
+ ## 0.0.11-alpha.0
223
+
224
+ ### Patch Changes
225
+
226
+ - Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
53
227
 
54
- - Updated dependencies [[`3852192`](https://github.com/mastra-ai/mastra/commit/3852192c81b2a4f1f883f17d80ce50e0c60dba55), [`fec5129`](https://github.com/mastra-ai/mastra/commit/fec5129de7fc64423ea03661a56cef31dc747a0d), [`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), [`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`b7de533`](https://github.com/mastra-ai/mastra/commit/b7de53361667eb51fefd89fcaed924f3c57cee8d), [`7051bf3`](https://github.com/mastra-ai/mastra/commit/7051bf38b3b122a069008f861f7bfc004a6d9f6e), [`1ee3411`](https://github.com/mastra-ai/mastra/commit/1ee34113192b11aa8bcdd8d9d5830ae13254b345), [`0793497`](https://github.com/mastra-ai/mastra/commit/079349753620c40246ffd673e3f9d7d9820beff3), [`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), [`ea0b8de`](https://github.com/mastra-ai/mastra/commit/ea0b8dec0d4bc86a72a7e75b2f56c6017c58786d), [`eb09742`](https://github.com/mastra-ai/mastra/commit/eb09742197f66c4c38154c3beec78313e69760b2), [`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), [`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), [`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), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`a0c8c1b`](https://github.com/mastra-ai/mastra/commit/a0c8c1b87d4fee252aebda73e8637fbe01d761c9), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014)]:
55
- - @mastra/client-js@1.0.0-beta.0
228
+ - Updated dependencies [[`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18)]:
229
+ - @mastra/client-js@0.16.5-alpha.0
56
230
 
57
231
  ## 0.0.10
58
232
 
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  const jsxRuntime = require('react/jsx-runtime');
6
6
  const react = require('react');
7
7
  const clientJs = require('@mastra/client-js');
8
+ const uuid = require('@lukeed/uuid');
8
9
  const lucideReact = require('lucide-react');
9
10
  const tailwindMerge = require('tailwind-merge');
10
11
  const hastUtilToJsxRuntime = require('hast-util-to-jsx-runtime');
@@ -259,17 +260,19 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
259
260
  if (!lastMessage || lastMessage.role !== "assistant") return result;
260
261
  const parts = [...lastMessage.parts];
261
262
  const toolPartIndex = parts.findIndex(
262
- (part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
263
+ (part) => (part.type === "dynamic-tool" || typeof part.type === "string" && part.type.startsWith("tool-")) && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
263
264
  );
264
265
  if (toolPartIndex !== -1) {
265
266
  const toolPart = parts[toolPartIndex];
266
- if (toolPart.type === "dynamic-tool") {
267
+ if (toolPart.type === "dynamic-tool" || typeof toolPart.type === "string" && toolPart.type.startsWith("tool-")) {
268
+ const toolName = "toolName" in toolPart && typeof toolPart.toolName === "string" ? toolPart.toolName : toolPart.type.startsWith("tool-") ? toolPart.type.substring(5) : "";
269
+ const toolCallId = toolPart.toolCallId;
267
270
  if (chunk.type === "tool-result" && chunk.payload.isError || chunk.type === "tool-error") {
268
271
  const error = chunk.type === "tool-error" ? chunk.payload.error : chunk.payload.result;
269
272
  parts[toolPartIndex] = {
270
273
  type: "dynamic-tool",
271
- toolName: toolPart.toolName,
272
- toolCallId: toolPart.toolCallId,
274
+ toolName,
275
+ toolCallId,
273
276
  state: "output-error",
274
277
  input: toolPart.input,
275
278
  errorText: String(error),
@@ -288,8 +291,8 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
288
291
  }
289
292
  parts[toolPartIndex] = {
290
293
  type: "dynamic-tool",
291
- toolName: toolPart.toolName,
292
- toolCallId: toolPart.toolCallId,
294
+ toolName,
295
+ toolCallId,
293
296
  state: "output-available",
294
297
  input: toolPart.input,
295
298
  output,
@@ -311,11 +314,14 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
311
314
  if (!lastMessage || lastMessage.role !== "assistant") return result;
312
315
  const parts = [...lastMessage.parts];
313
316
  const toolPartIndex = parts.findIndex(
314
- (part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
317
+ (part) => (part.type === "dynamic-tool" || typeof part.type === "string" && part.type.startsWith("tool-")) && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
315
318
  );
316
319
  if (toolPartIndex !== -1) {
317
320
  const toolPart = parts[toolPartIndex];
318
- if (toolPart.type === "dynamic-tool") {
321
+ if (toolPart.type === "dynamic-tool" || typeof toolPart.type === "string" && toolPart.type.startsWith("tool-")) {
322
+ const toolName = "toolName" in toolPart && typeof toolPart.toolName === "string" ? toolPart.toolName : typeof toolPart.type === "string" && toolPart.type.startsWith("tool-") ? toolPart.type.substring(5) : "";
323
+ const toolCallId = toolPart.toolCallId;
324
+ const input = toolPart.input;
319
325
  if (chunk.payload.output?.type?.startsWith("workflow-")) {
320
326
  const existingWorkflowState = toolPart.output || {};
321
327
  const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(
@@ -323,7 +329,11 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
323
329
  chunk.payload.output
324
330
  );
325
331
  parts[toolPartIndex] = {
326
- ...toolPart,
332
+ type: "dynamic-tool",
333
+ toolName,
334
+ toolCallId,
335
+ state: "input-streaming",
336
+ input,
327
337
  output: updatedWorkflowState
328
338
  };
329
339
  } else if (chunk.payload.output?.from === "AGENT" || chunk.payload.output?.from === "USER" && chunk.payload.output?.payload?.output?.type?.startsWith("workflow-")) {
@@ -332,7 +342,11 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
332
342
  const currentOutput = toolPart.output || [];
333
343
  const existingOutput = Array.isArray(currentOutput) ? currentOutput : [];
334
344
  parts[toolPartIndex] = {
335
- ...toolPart,
345
+ type: "dynamic-tool",
346
+ toolName,
347
+ toolCallId,
348
+ state: "input-streaming",
349
+ input,
336
350
  output: [...existingOutput, chunk.payload.output]
337
351
  };
338
352
  }
@@ -428,10 +442,11 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
428
442
  const lastMessage = result[result.length - 1];
429
443
  if (!lastMessage || lastMessage.role !== "assistant") return result;
430
444
  const parts = lastMessage.parts.map((part) => {
431
- if (typeof part === "object" && part !== null && "type" in part && "state" in part && part.state === "streaming") {
432
- if (part.type === "text" || part.type === "reasoning") {
433
- return { ...part, state: "done" };
434
- }
445
+ if (part.type === "text" && part.state === "streaming") {
446
+ return { ...part, state: "done" };
447
+ }
448
+ if (part.type === "reasoning" && part.state === "streaming") {
449
+ return { ...part, state: "done" };
435
450
  }
436
451
  return part;
437
452
  });
@@ -603,23 +618,13 @@ const toAssistantUIMessage = (message) => {
603
618
  };
604
619
  }
605
620
  if (part.type === "file") {
606
- const type = part.mediaType.includes("image/") ? "image" : "file";
607
- if (type === "file") {
608
- return {
609
- type,
610
- mimeType: part.mediaType,
611
- data: part.url,
612
- // Use URL as data source
613
- metadata: message.metadata
614
- };
615
- }
616
- if (type === "image") {
617
- return {
618
- type,
619
- image: part.url,
620
- metadata: message.metadata
621
- };
622
- }
621
+ return {
622
+ type: "file",
623
+ mimeType: part.mediaType,
624
+ data: part.url,
625
+ // Use URL as data source
626
+ metadata: message.metadata
627
+ };
623
628
  }
624
629
  if (part.type === "dynamic-tool") {
625
630
  const baseToolCall = {
@@ -655,6 +660,20 @@ const toAssistantUIMessage = (message) => {
655
660
  }
656
661
  return baseToolCall;
657
662
  }
663
+ const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
664
+ const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
665
+ const suspensionData = partToolCallId ? requireApprovalMetadata?.[partToolCallId] : void 0;
666
+ if (suspensionData) {
667
+ const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
668
+ return {
669
+ type: "tool-call",
670
+ toolCallId: partToolCallId,
671
+ toolName,
672
+ argsText: "input" in part ? JSON.stringify(part.input) : "{}",
673
+ args: "input" in part ? part.input : {},
674
+ metadata: extendedMessage.metadata
675
+ };
676
+ }
658
677
  return {
659
678
  type: "text",
660
679
  text: "",
@@ -696,9 +715,7 @@ const toAssistantUIMessage = (message) => {
696
715
 
697
716
  const resolveInitialMessages = (messages) => {
698
717
  return messages.map((message) => {
699
- const networkPart = message.parts.find(
700
- (part) => typeof part === "object" && part !== null && "type" in part && part.type === "text" && "text" in part && typeof part.text === "string" && part.text.includes('"isNetwork":true')
701
- );
718
+ const networkPart = message.parts.find((part) => part.type === "text" && part.text.includes('"isNetwork":true'));
702
719
  if (networkPart && networkPart.type === "text") {
703
720
  try {
704
721
  const json = JSON.parse(networkPart.text);
@@ -741,7 +758,6 @@ const resolveInitialMessages = (messages) => {
741
758
  childMessages,
742
759
  result: finalResult?.text || ""
743
760
  };
744
- console.log("json", json);
745
761
  const nextMessage = {
746
762
  role: "assistant",
747
763
  parts: [
@@ -769,6 +785,18 @@ const resolveInitialMessages = (messages) => {
769
785
  return message;
770
786
  }
771
787
  }
788
+ const extendedMessage = message;
789
+ const pendingToolApprovals = extendedMessage.metadata?.pendingToolApprovals;
790
+ if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
791
+ return {
792
+ ...message,
793
+ metadata: {
794
+ ...message.metadata,
795
+ mode: "stream",
796
+ requireApprovalMetadata: pendingToolApprovals
797
+ }
798
+ };
799
+ }
772
800
  return message;
773
801
  });
774
802
  };
@@ -1172,63 +1200,30 @@ class AISdkNetworkTransformer {
1172
1200
  };
1173
1201
  }
1174
1202
 
1175
- const fromCoreUserMessageToUIMessage = (coreUserMessage) => {
1176
- const id = `user-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1177
- const parts = typeof coreUserMessage.content === "string" ? [
1178
- {
1179
- type: "text",
1180
- text: coreUserMessage.content
1181
- }
1182
- ] : coreUserMessage.content.map((part) => {
1183
- switch (part.type) {
1184
- case "text": {
1185
- return {
1186
- type: "text",
1187
- text: part.text
1188
- };
1189
- }
1190
- case "image": {
1191
- const url = typeof part.image === "string" ? part.image : part.image instanceof URL ? part.image.toString() : "";
1192
- return {
1193
- type: "file",
1194
- mediaType: part.mimeType ?? "image/*",
1195
- url
1196
- };
1197
- }
1198
- case "file": {
1199
- const url = typeof part.data === "string" ? part.data : part.data instanceof URL ? part.data.toString() : "";
1200
- return {
1201
- type: "file",
1202
- mediaType: part.mimeType,
1203
- url,
1204
- ...part.filename !== void 0 ? { filename: part.filename } : {}
1205
- };
1206
- }
1207
- default: {
1208
- const exhaustiveCheck = part;
1209
- throw new Error(`Unhandled content part type: ${exhaustiveCheck.type}`);
1203
+ const useChat = ({ agentId, resourceId, initializeMessages }) => {
1204
+ const extractRunIdFromMessages = (messages2) => {
1205
+ for (const message of messages2) {
1206
+ const pendingToolApprovals = message.metadata?.pendingToolApprovals;
1207
+ if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
1208
+ const suspensionData = Object.values(pendingToolApprovals)[0];
1209
+ if (suspensionData?.runId) {
1210
+ return suspensionData.runId;
1211
+ }
1210
1212
  }
1211
1213
  }
1212
- });
1213
- return {
1214
- id,
1215
- role: "user",
1216
- parts
1214
+ return void 0;
1217
1215
  };
1218
- };
1219
-
1220
- const useChat = ({ agentId, initializeMessages }) => {
1221
- const _currentRunId = react.useRef(void 0);
1216
+ const initialMessages = initializeMessages?.() || [];
1217
+ const initialRunId = extractRunIdFromMessages(initialMessages);
1218
+ const _currentRunId = react.useRef(initialRunId);
1222
1219
  const _onChunk = react.useRef(void 0);
1223
- const [messages, setMessages] = react.useState(
1224
- () => resolveInitialMessages(initializeMessages?.() || [])
1225
- );
1220
+ const [messages, setMessages] = react.useState(() => resolveInitialMessages(initialMessages));
1226
1221
  const [toolCallApprovals, setToolCallApprovals] = react.useState({});
1227
1222
  const baseClient = useMastraClient();
1228
1223
  const [isRunning, setIsRunning] = react.useState(false);
1229
1224
  const generate = async ({
1230
1225
  coreUserMessages,
1231
- requestContext,
1226
+ runtimeContext,
1232
1227
  threadId,
1233
1228
  modelSettings,
1234
1229
  signal,
@@ -1254,7 +1249,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1254
1249
  const agent = clientWithAbort.getAgent(agentId);
1255
1250
  const response = await agent.generate({
1256
1251
  messages: coreUserMessages,
1257
- runId: agentId,
1252
+ runId: uuid.v4(),
1258
1253
  maxSteps,
1259
1254
  modelSettings: {
1260
1255
  frequencyPenalty,
@@ -1266,8 +1261,8 @@ const useChat = ({ agentId, initializeMessages }) => {
1266
1261
  topP
1267
1262
  },
1268
1263
  instructions,
1269
- requestContext,
1270
- ...threadId ? { threadId, resourceId: agentId } : {},
1264
+ runtimeContext,
1265
+ ...threadId ? { threadId, resourceId: resourceId || agentId } : {},
1271
1266
  providerOptions
1272
1267
  });
1273
1268
  setIsRunning(false);
@@ -1282,7 +1277,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1282
1277
  setMessages((prev) => [...prev, ...mastraUIMessages]);
1283
1278
  }
1284
1279
  };
1285
- const stream = async ({ coreUserMessages, requestContext, threadId, onChunk, modelSettings, signal }) => {
1280
+ const stream = async ({ coreUserMessages, runtimeContext, threadId, onChunk, modelSettings, signal }) => {
1286
1281
  const {
1287
1282
  frequencyPenalty,
1288
1283
  presencePenalty,
@@ -1302,7 +1297,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1302
1297
  abortSignal: signal
1303
1298
  });
1304
1299
  const agent = clientWithAbort.getAgent(agentId);
1305
- const runId = agentId;
1300
+ const runId = uuid.v4();
1306
1301
  const response = await agent.stream({
1307
1302
  messages: coreUserMessages,
1308
1303
  runId,
@@ -1317,8 +1312,8 @@ const useChat = ({ agentId, initializeMessages }) => {
1317
1312
  topP
1318
1313
  },
1319
1314
  instructions,
1320
- requestContext,
1321
- ...threadId ? { threadId, resourceId: agentId } : {},
1315
+ runtimeContext,
1316
+ ...threadId ? { threadId, resourceId: resourceId || agentId } : {},
1322
1317
  providerOptions,
1323
1318
  requireToolApproval
1324
1319
  });
@@ -1334,7 +1329,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1334
1329
  };
1335
1330
  const network = async ({
1336
1331
  coreUserMessages,
1337
- requestContext,
1332
+ runtimeContext,
1338
1333
  threadId,
1339
1334
  onNetworkChunk,
1340
1335
  modelSettings,
@@ -1347,6 +1342,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1347
1342
  abortSignal: signal
1348
1343
  });
1349
1344
  const agent = clientWithAbort.getAgent(agentId);
1345
+ const runId = uuid.v4();
1350
1346
  const response = await agent.network({
1351
1347
  messages: coreUserMessages,
1352
1348
  maxSteps,
@@ -1359,9 +1355,9 @@ const useChat = ({ agentId, initializeMessages }) => {
1359
1355
  topK,
1360
1356
  topP
1361
1357
  },
1362
- runId: agentId,
1363
- requestContext,
1364
- ...threadId ? { thread: threadId, resourceId: agentId } : {}
1358
+ runId,
1359
+ runtimeContext,
1360
+ ...threadId ? { thread: threadId, resourceId: resourceId || agentId } : {}
1365
1361
  });
1366
1362
  const transformer = new AISdkNetworkTransformer();
1367
1363
  await response.processDataStream({
@@ -1413,18 +1409,14 @@ const useChat = ({ agentId, initializeMessages }) => {
1413
1409
  };
1414
1410
  const sendMessage = async ({ mode = "stream", ...args }) => {
1415
1411
  const nextMessage = { role: "user", content: [{ type: "text", text: args.message }] };
1416
- const coreUserMessages = [nextMessage];
1417
- if (args.coreUserMessages) {
1418
- coreUserMessages.push(...args.coreUserMessages);
1419
- }
1420
- const uiMessages = coreUserMessages.map(fromCoreUserMessageToUIMessage);
1421
- setMessages((s) => [...s, ...uiMessages]);
1412
+ const messages2 = args.coreUserMessages ? [nextMessage, ...args.coreUserMessages] : [nextMessage];
1413
+ setMessages((s) => [...s, { role: "user", parts: [{ type: "text", text: args.message }] }]);
1422
1414
  if (mode === "generate") {
1423
- await generate({ ...args, coreUserMessages });
1415
+ await generate({ ...args, coreUserMessages: messages2 });
1424
1416
  } else if (mode === "stream") {
1425
- await stream({ ...args, coreUserMessages });
1417
+ await stream({ ...args, coreUserMessages: messages2 });
1426
1418
  } else if (mode === "network") {
1427
- await network({ ...args, coreUserMessages });
1419
+ await network({ ...args, coreUserMessages: messages2 });
1428
1420
  }
1429
1421
  };
1430
1422
  return {