@mastra/react 0.0.0-remove-unused-model-providers-api-20251030210744 → 0.0.0-scorers-logs-20251208093427
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 +139 -4
- package/dist/index.cjs +99 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -33
- package/dist/index.js.map +1 -1
- package/dist/react.css +1 -1
- package/dist/src/agent/hooks.d.ts +4 -1
- package/dist/src/lib/ai-sdk/types.d.ts +10 -0
- package/dist/src/lib/ai-sdk/utils/fromCoreUserMessageToUIMessage.d.ts +1 -1
- package/package.json +12 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,154 @@
|
|
|
1
1
|
# @mastra/react-hooks
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-scorers-logs-20251208093427
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
|
|
8
|
+
|
|
9
|
+
- Rename RuntimeContext to RequestContext ([#9511](https://github.com/mastra-ai/mastra/pull/9511))
|
|
10
|
+
|
|
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
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Adjust the types to accept tracingOptions ([#10742](https://github.com/mastra-ai/mastra/pull/10742))
|
|
17
|
+
|
|
18
|
+
- Configurable resourceId in react useChat ([#10461](https://github.com/mastra-ai/mastra/pull/10461))
|
|
19
|
+
|
|
20
|
+
- Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
|
|
21
|
+
|
|
22
|
+
- fix(agent): persist messages before tool suspension ([#10369](https://github.com/mastra-ai/mastra/pull/10369))
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
**Backend changes (@mastra/core):**
|
|
27
|
+
- Add assistant messages to messageList immediately after LLM execution
|
|
28
|
+
- Flush messages synchronously before suspension to persist state
|
|
29
|
+
- Create thread if it doesn't exist before flushing
|
|
30
|
+
- Add metadata helpers to persist and remove tool approval state
|
|
31
|
+
- Pass saveQueueManager and memory context through workflow for immediate persistence
|
|
32
|
+
|
|
33
|
+
**Frontend changes (@mastra/react):**
|
|
34
|
+
- Extract runId from pending approvals to enable resumption after refresh
|
|
35
|
+
- Convert `pendingToolApprovals` (DB format) to `requireApprovalMetadata` (runtime format)
|
|
36
|
+
- Handle both `dynamic-tool` and `tool-{NAME}` part types for approval state
|
|
37
|
+
- Change runId from hardcoded `agentId` to unique `uuid()`
|
|
38
|
+
|
|
39
|
+
**UI changes (@mastra/playground-ui):**
|
|
40
|
+
- Handle tool calls awaiting approval in message initialization
|
|
41
|
+
- Convert approval metadata format when loading initial messages
|
|
42
|
+
|
|
43
|
+
Fixes #9745, #9906
|
|
44
|
+
|
|
45
|
+
- Fix multi modal in react sdk ([#9373](https://github.com/mastra-ai/mastra/pull/9373))
|
|
46
|
+
|
|
47
|
+
- 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), [`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), [`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), [`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), [`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), [`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), [`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), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`21735a7`](https://github.com/mastra-ai/mastra/commit/21735a7ef306963554a69a89b44f06c3bcd85141), [`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)]:
|
|
48
|
+
- @mastra/client-js@0.0.0-scorers-logs-20251208093427
|
|
49
|
+
|
|
50
|
+
## 0.1.0-beta.8
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- Updated dependencies:
|
|
55
|
+
- @mastra/client-js@1.0.0-beta.8
|
|
56
|
+
|
|
57
|
+
## 0.1.0-beta.7
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [[`5fe71bc`](https://github.com/mastra-ai/mastra/commit/5fe71bc925dfce597df69c89241f33b378028c63), [`21735a7`](https://github.com/mastra-ai/mastra/commit/21735a7ef306963554a69a89b44f06c3bcd85141)]:
|
|
62
|
+
- @mastra/client-js@1.0.0-beta.7
|
|
63
|
+
|
|
64
|
+
## 0.1.0-beta.6
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- Adjust the types to accept tracingOptions ([#10742](https://github.com/mastra-ai/mastra/pull/10742))
|
|
69
|
+
|
|
70
|
+
- 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)]:
|
|
71
|
+
- @mastra/client-js@1.0.0-beta.6
|
|
72
|
+
|
|
73
|
+
## 0.1.0-beta.5
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Configurable resourceId in react useChat ([#10461](https://github.com/mastra-ai/mastra/pull/10461))
|
|
78
|
+
|
|
79
|
+
- fix(agent): persist messages before tool suspension ([#10369](https://github.com/mastra-ai/mastra/pull/10369))
|
|
80
|
+
|
|
81
|
+
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.
|
|
82
|
+
|
|
83
|
+
**Backend changes (@mastra/core):**
|
|
84
|
+
- Add assistant messages to messageList immediately after LLM execution
|
|
85
|
+
- Flush messages synchronously before suspension to persist state
|
|
86
|
+
- Create thread if it doesn't exist before flushing
|
|
87
|
+
- Add metadata helpers to persist and remove tool approval state
|
|
88
|
+
- Pass saveQueueManager and memory context through workflow for immediate persistence
|
|
89
|
+
|
|
90
|
+
**Frontend changes (@mastra/react):**
|
|
91
|
+
- Extract runId from pending approvals to enable resumption after refresh
|
|
92
|
+
- Convert `pendingToolApprovals` (DB format) to `requireApprovalMetadata` (runtime format)
|
|
93
|
+
- Handle both `dynamic-tool` and `tool-{NAME}` part types for approval state
|
|
94
|
+
- Change runId from hardcoded `agentId` to unique `uuid()`
|
|
95
|
+
|
|
96
|
+
**UI changes (@mastra/playground-ui):**
|
|
97
|
+
- Handle tool calls awaiting approval in message initialization
|
|
98
|
+
- Convert approval metadata format when loading initial messages
|
|
99
|
+
|
|
100
|
+
Fixes #9745, #9906
|
|
101
|
+
|
|
102
|
+
- Updated dependencies [[`898a972`](https://github.com/mastra-ai/mastra/commit/898a9727d286c2510d6b702dfd367e6aaf5c6b0f)]:
|
|
103
|
+
- @mastra/client-js@1.0.0-beta.5
|
|
104
|
+
|
|
105
|
+
## 0.1.0-beta.4
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- Updated dependencies [[`6a86fe5`](https://github.com/mastra-ai/mastra/commit/6a86fe56b8ff53ca2eb3ed87ffc0748749ebadce), [`595a3b8`](https://github.com/mastra-ai/mastra/commit/595a3b8727c901f44e333909c09843c711224440)]:
|
|
110
|
+
- @mastra/client-js@1.0.0-beta.4
|
|
111
|
+
|
|
112
|
+
## 0.1.0-beta.3
|
|
113
|
+
|
|
114
|
+
### Patch Changes
|
|
115
|
+
|
|
116
|
+
- Updated dependencies [[`e1bb9c9`](https://github.com/mastra-ai/mastra/commit/e1bb9c94b4eb68b019ae275981be3feb769b5365)]:
|
|
117
|
+
- @mastra/client-js@1.0.0-beta.3
|
|
118
|
+
|
|
119
|
+
## 0.1.0-beta.2
|
|
120
|
+
|
|
121
|
+
### Patch Changes
|
|
122
|
+
|
|
123
|
+
- Updated dependencies []:
|
|
124
|
+
- @mastra/client-js@1.0.0-beta.2
|
|
125
|
+
|
|
126
|
+
## 0.1.0-beta.1
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- Updated dependencies [[`dbd9db0`](https://github.com/mastra-ai/mastra/commit/dbd9db0d5c2797a210b9098e7e3e613718e5442f)]:
|
|
131
|
+
- @mastra/client-js@1.0.0-beta.1
|
|
132
|
+
|
|
133
|
+
## 0.1.0-beta.0
|
|
134
|
+
|
|
135
|
+
### Minor Changes
|
|
136
|
+
|
|
137
|
+
- Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
|
|
6
138
|
|
|
7
139
|
- Rename RuntimeContext to RequestContext ([#9511](https://github.com/mastra-ai/mastra/pull/9511))
|
|
8
140
|
|
|
141
|
+
- Renamed `MastraMessageV2` to `MastraDBMessage` ([#9255](https://github.com/mastra-ai/mastra/pull/9255))
|
|
142
|
+
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
|
|
143
|
+
|
|
9
144
|
### Patch Changes
|
|
10
145
|
|
|
11
146
|
- Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
|
|
12
147
|
|
|
13
148
|
- Fix multi modal in react sdk ([#9373](https://github.com/mastra-ai/mastra/pull/9373))
|
|
14
149
|
|
|
15
|
-
- Updated dependencies [[`3852192`](https://github.com/mastra-ai/mastra/commit/3852192c81b2a4f1f883f17d80ce50e0c60dba55), [`3443770`](https://github.com/mastra-ai/mastra/commit/3443770662df8eb24c9df3589b2792d78cfcb811), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`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), [`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), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`
|
|
16
|
-
- @mastra/client-js@0.0.0
|
|
150
|
+
- 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)]:
|
|
151
|
+
- @mastra/client-js@1.0.0-beta.0
|
|
17
152
|
|
|
18
153
|
## 0.0.10
|
|
19
154
|
|
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
|
|
272
|
-
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
|
|
292
|
-
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
|
-
|
|
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
|
-
|
|
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,11 +442,10 @@ 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 (part
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return { ...part, state: "done" };
|
|
445
|
+
if (typeof part === "object" && part !== null && "type" in part && "state" in part && part.state === "streaming") {
|
|
446
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
447
|
+
return { ...part, state: "done" };
|
|
448
|
+
}
|
|
436
449
|
}
|
|
437
450
|
return part;
|
|
438
451
|
});
|
|
@@ -656,6 +669,20 @@ const toAssistantUIMessage = (message) => {
|
|
|
656
669
|
}
|
|
657
670
|
return baseToolCall;
|
|
658
671
|
}
|
|
672
|
+
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
673
|
+
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
674
|
+
const suspensionData = partToolCallId ? requireApprovalMetadata?.[partToolCallId] : void 0;
|
|
675
|
+
if (suspensionData) {
|
|
676
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
677
|
+
return {
|
|
678
|
+
type: "tool-call",
|
|
679
|
+
toolCallId: partToolCallId,
|
|
680
|
+
toolName,
|
|
681
|
+
argsText: "input" in part ? JSON.stringify(part.input) : "{}",
|
|
682
|
+
args: "input" in part ? part.input : {},
|
|
683
|
+
metadata: extendedMessage.metadata
|
|
684
|
+
};
|
|
685
|
+
}
|
|
659
686
|
return {
|
|
660
687
|
type: "text",
|
|
661
688
|
text: "",
|
|
@@ -697,7 +724,9 @@ const toAssistantUIMessage = (message) => {
|
|
|
697
724
|
|
|
698
725
|
const resolveInitialMessages = (messages) => {
|
|
699
726
|
return messages.map((message) => {
|
|
700
|
-
const networkPart = message.parts.find(
|
|
727
|
+
const networkPart = message.parts.find(
|
|
728
|
+
(part) => typeof part === "object" && part !== null && "type" in part && part.type === "text" && "text" in part && typeof part.text === "string" && part.text.includes('"isNetwork":true')
|
|
729
|
+
);
|
|
701
730
|
if (networkPart && networkPart.type === "text") {
|
|
702
731
|
try {
|
|
703
732
|
const json = JSON.parse(networkPart.text);
|
|
@@ -740,7 +769,6 @@ const resolveInitialMessages = (messages) => {
|
|
|
740
769
|
childMessages,
|
|
741
770
|
result: finalResult?.text || ""
|
|
742
771
|
};
|
|
743
|
-
console.log("json", json);
|
|
744
772
|
const nextMessage = {
|
|
745
773
|
role: "assistant",
|
|
746
774
|
parts: [
|
|
@@ -768,6 +796,18 @@ const resolveInitialMessages = (messages) => {
|
|
|
768
796
|
return message;
|
|
769
797
|
}
|
|
770
798
|
}
|
|
799
|
+
const extendedMessage = message;
|
|
800
|
+
const pendingToolApprovals = extendedMessage.metadata?.pendingToolApprovals;
|
|
801
|
+
if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
|
|
802
|
+
return {
|
|
803
|
+
...message,
|
|
804
|
+
metadata: {
|
|
805
|
+
...message.metadata,
|
|
806
|
+
mode: "stream",
|
|
807
|
+
requireApprovalMetadata: pendingToolApprovals
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
}
|
|
771
811
|
return message;
|
|
772
812
|
});
|
|
773
813
|
};
|
|
@@ -1216,12 +1256,24 @@ const fromCoreUserMessageToUIMessage = (coreUserMessage) => {
|
|
|
1216
1256
|
};
|
|
1217
1257
|
};
|
|
1218
1258
|
|
|
1219
|
-
const useChat = ({ agentId, initializeMessages }) => {
|
|
1220
|
-
const
|
|
1259
|
+
const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
1260
|
+
const extractRunIdFromMessages = (messages2) => {
|
|
1261
|
+
for (const message of messages2) {
|
|
1262
|
+
const pendingToolApprovals = message.metadata?.pendingToolApprovals;
|
|
1263
|
+
if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
|
|
1264
|
+
const suspensionData = Object.values(pendingToolApprovals)[0];
|
|
1265
|
+
if (suspensionData?.runId) {
|
|
1266
|
+
return suspensionData.runId;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
return void 0;
|
|
1271
|
+
};
|
|
1272
|
+
const initialMessages = initializeMessages?.() || [];
|
|
1273
|
+
const initialRunId = extractRunIdFromMessages(initialMessages);
|
|
1274
|
+
const _currentRunId = react.useRef(initialRunId);
|
|
1221
1275
|
const _onChunk = react.useRef(void 0);
|
|
1222
|
-
const [messages, setMessages] = react.useState(
|
|
1223
|
-
() => resolveInitialMessages(initializeMessages?.() || [])
|
|
1224
|
-
);
|
|
1276
|
+
const [messages, setMessages] = react.useState(() => resolveInitialMessages(initialMessages));
|
|
1225
1277
|
const [toolCallApprovals, setToolCallApprovals] = react.useState({});
|
|
1226
1278
|
const baseClient = useMastraClient();
|
|
1227
1279
|
const [isRunning, setIsRunning] = react.useState(false);
|
|
@@ -1231,7 +1283,8 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1231
1283
|
threadId,
|
|
1232
1284
|
modelSettings,
|
|
1233
1285
|
signal,
|
|
1234
|
-
onFinish
|
|
1286
|
+
onFinish,
|
|
1287
|
+
tracingOptions
|
|
1235
1288
|
}) => {
|
|
1236
1289
|
const {
|
|
1237
1290
|
frequencyPenalty,
|
|
@@ -1253,7 +1306,7 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1253
1306
|
const agent = clientWithAbort.getAgent(agentId);
|
|
1254
1307
|
const response = await agent.generate({
|
|
1255
1308
|
messages: coreUserMessages,
|
|
1256
|
-
runId:
|
|
1309
|
+
runId: uuid.v4(),
|
|
1257
1310
|
maxSteps,
|
|
1258
1311
|
modelSettings: {
|
|
1259
1312
|
frequencyPenalty,
|
|
@@ -1266,8 +1319,9 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1266
1319
|
},
|
|
1267
1320
|
instructions,
|
|
1268
1321
|
requestContext,
|
|
1269
|
-
...threadId ? { threadId, resourceId: agentId } : {},
|
|
1270
|
-
providerOptions
|
|
1322
|
+
...threadId ? { threadId, resourceId: resourceId || agentId } : {},
|
|
1323
|
+
providerOptions,
|
|
1324
|
+
tracingOptions
|
|
1271
1325
|
});
|
|
1272
1326
|
setIsRunning(false);
|
|
1273
1327
|
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
@@ -1281,7 +1335,15 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1281
1335
|
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
1282
1336
|
}
|
|
1283
1337
|
};
|
|
1284
|
-
const stream = async ({
|
|
1338
|
+
const stream = async ({
|
|
1339
|
+
coreUserMessages,
|
|
1340
|
+
requestContext,
|
|
1341
|
+
threadId,
|
|
1342
|
+
onChunk,
|
|
1343
|
+
modelSettings,
|
|
1344
|
+
signal,
|
|
1345
|
+
tracingOptions
|
|
1346
|
+
}) => {
|
|
1285
1347
|
const {
|
|
1286
1348
|
frequencyPenalty,
|
|
1287
1349
|
presencePenalty,
|
|
@@ -1301,7 +1363,7 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1301
1363
|
abortSignal: signal
|
|
1302
1364
|
});
|
|
1303
1365
|
const agent = clientWithAbort.getAgent(agentId);
|
|
1304
|
-
const runId =
|
|
1366
|
+
const runId = uuid.v4();
|
|
1305
1367
|
const response = await agent.stream({
|
|
1306
1368
|
messages: coreUserMessages,
|
|
1307
1369
|
runId,
|
|
@@ -1317,9 +1379,10 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1317
1379
|
},
|
|
1318
1380
|
instructions,
|
|
1319
1381
|
requestContext,
|
|
1320
|
-
...threadId ? { threadId, resourceId: agentId } : {},
|
|
1382
|
+
...threadId ? { threadId, resourceId: resourceId || agentId } : {},
|
|
1321
1383
|
providerOptions,
|
|
1322
|
-
requireToolApproval
|
|
1384
|
+
requireToolApproval,
|
|
1385
|
+
tracingOptions
|
|
1323
1386
|
});
|
|
1324
1387
|
_onChunk.current = onChunk;
|
|
1325
1388
|
_currentRunId.current = runId;
|
|
@@ -1337,7 +1400,8 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1337
1400
|
threadId,
|
|
1338
1401
|
onNetworkChunk,
|
|
1339
1402
|
modelSettings,
|
|
1340
|
-
signal
|
|
1403
|
+
signal,
|
|
1404
|
+
tracingOptions
|
|
1341
1405
|
}) => {
|
|
1342
1406
|
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
|
|
1343
1407
|
setIsRunning(true);
|
|
@@ -1346,6 +1410,7 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1346
1410
|
abortSignal: signal
|
|
1347
1411
|
});
|
|
1348
1412
|
const agent = clientWithAbort.getAgent(agentId);
|
|
1413
|
+
const runId = uuid.v4();
|
|
1349
1414
|
const response = await agent.network({
|
|
1350
1415
|
messages: coreUserMessages,
|
|
1351
1416
|
maxSteps,
|
|
@@ -1358,9 +1423,10 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1358
1423
|
topK,
|
|
1359
1424
|
topP
|
|
1360
1425
|
},
|
|
1361
|
-
runId
|
|
1426
|
+
runId,
|
|
1362
1427
|
requestContext,
|
|
1363
|
-
...threadId ? { thread: threadId, resourceId: agentId } : {}
|
|
1428
|
+
...threadId ? { thread: threadId, resourceId: resourceId || agentId } : {},
|
|
1429
|
+
tracingOptions
|
|
1364
1430
|
});
|
|
1365
1431
|
const transformer = new AISdkNetworkTransformer();
|
|
1366
1432
|
await response.processDataStream({
|