@mastra/react 0.0.0-dynamic-model-router-20251010193247 → 0.0.0-error-handler-fix-20251020202607
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 +76 -2
- package/dist/index.cjs +88 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +88 -22
- package/dist/index.js.map +1 -1
- package/dist/react.css +1 -1
- package/dist/src/agent/hooks.d.ts +14 -4
- package/dist/src/lib/ai-sdk/transformers/AISdkNetworkTransformer.d.ts +1 -0
- package/package.json +13 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
# @mastra/react-hooks
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-error-handler-fix-20251020202607
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix perf issue: removed flush sync ([#9014](https://github.com/mastra-ai/mastra/pull/9014))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @mastra/client-js@0.0.0-error-handler-fix-20251020202607
|
|
11
|
+
|
|
12
|
+
## 0.0.8-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies []:
|
|
17
|
+
- @mastra/client-js@0.16.2-alpha.0
|
|
18
|
+
|
|
19
|
+
## 0.0.7
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Add @mastra/react to peer deps ([#8857](https://github.com/mastra-ai/mastra/pull/8857))
|
|
24
|
+
|
|
25
|
+
- Updated dependencies []:
|
|
26
|
+
- @mastra/client-js@0.16.1
|
|
27
|
+
|
|
28
|
+
## 0.0.7-alpha.0
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Add @mastra/react to peer deps ([#8857](https://github.com/mastra-ai/mastra/pull/8857))
|
|
33
|
+
|
|
34
|
+
- Updated dependencies []:
|
|
35
|
+
- @mastra/client-js@0.16.1-alpha.0
|
|
36
|
+
|
|
37
|
+
## 0.0.6
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
|
6
40
|
|
|
@@ -8,14 +42,54 @@
|
|
|
8
42
|
|
|
9
43
|
- Prepares some basic set of homemade components ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
|
|
10
44
|
|
|
45
|
+
- Improve the surface API of the react sdk ([#8715](https://github.com/mastra-ai/mastra/pull/8715))
|
|
46
|
+
|
|
47
|
+
- Move react and react-dom deps to peer and dev deps ([#8698](https://github.com/mastra-ai/mastra/pull/8698))
|
|
48
|
+
|
|
11
49
|
- Fix back the tripwire verification inside the new react system ([#8674](https://github.com/mastra-ai/mastra/pull/8674))
|
|
12
50
|
|
|
13
51
|
- handle error case in react sdk ([#8676](https://github.com/mastra-ai/mastra/pull/8676))
|
|
14
52
|
|
|
15
53
|
- fix maxSteps model settings not being passed to generate and stream endpoints ([#8627](https://github.com/mastra-ai/mastra/pull/8627))
|
|
16
54
|
|
|
55
|
+
- Stream finalResult from network loop ([#8795](https://github.com/mastra-ai/mastra/pull/8795))
|
|
56
|
+
|
|
17
57
|
- Updated dependencies [[`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`78cfb6b`](https://github.com/mastra-ai/mastra/commit/78cfb6b66fe88bc848105fccb6459fd75413ec87)]:
|
|
18
|
-
- @mastra/client-js@0.
|
|
58
|
+
- @mastra/client-js@0.16.0
|
|
59
|
+
|
|
60
|
+
## 0.0.6-alpha.4
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- Updated dependencies []:
|
|
65
|
+
- @mastra/client-js@0.16.0-alpha.4
|
|
66
|
+
|
|
67
|
+
## 0.0.6-alpha.3
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- Updated dependencies []:
|
|
72
|
+
- @mastra/client-js@0.16.0-alpha.3
|
|
73
|
+
|
|
74
|
+
## 0.0.6-alpha.2
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- Updated dependencies []:
|
|
79
|
+
- @mastra/client-js@0.16.0-alpha.2
|
|
80
|
+
|
|
81
|
+
## 0.0.6-alpha.1
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- Improve the surface API of the react sdk ([#8715](https://github.com/mastra-ai/mastra/pull/8715))
|
|
86
|
+
|
|
87
|
+
- Move react and react-dom deps to peer and dev deps ([#8698](https://github.com/mastra-ai/mastra/pull/8698))
|
|
88
|
+
|
|
89
|
+
- Stream finalResult from network loop ([#8795](https://github.com/mastra-ai/mastra/pull/8795))
|
|
90
|
+
|
|
91
|
+
- Updated dependencies []:
|
|
92
|
+
- @mastra/client-js@0.16.0-alpha.1
|
|
19
93
|
|
|
20
94
|
## 0.0.6-alpha.0
|
|
21
95
|
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ 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 reactDom = require('react-dom');
|
|
9
8
|
const lucideReact = require('lucide-react');
|
|
10
9
|
const tailwindMerge = require('tailwind-merge');
|
|
11
10
|
const hastUtilToJsxRuntime = require('hast-util-to-jsx-runtime');
|
|
@@ -554,6 +553,9 @@ const toAssistantUIMessage = (message) => {
|
|
|
554
553
|
class AISdkNetworkTransformer {
|
|
555
554
|
transform({ chunk, conversation, metadata }) {
|
|
556
555
|
const newConversation = [...conversation];
|
|
556
|
+
if (chunk.type === "routing-agent-text-delta") {
|
|
557
|
+
return this.handleRoutingAgentConversation(chunk, newConversation);
|
|
558
|
+
}
|
|
557
559
|
if (chunk.type.startsWith("agent-execution-")) {
|
|
558
560
|
return this.handleAgentConversation(chunk, newConversation, metadata);
|
|
559
561
|
}
|
|
@@ -564,22 +566,80 @@ class AISdkNetworkTransformer {
|
|
|
564
566
|
return this.handleToolConversation(chunk, newConversation, metadata);
|
|
565
567
|
}
|
|
566
568
|
if (chunk.type === "network-execution-event-step-finish") {
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
569
|
+
const lastMessage = newConversation[newConversation.length - 1];
|
|
570
|
+
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
571
|
+
const agentChunk = chunk.payload;
|
|
572
|
+
const parts = [...lastMessage.parts];
|
|
573
|
+
const textPartIndex = parts.findIndex((part) => part.type === "text");
|
|
574
|
+
if (textPartIndex === -1) {
|
|
575
|
+
parts.push({
|
|
576
|
+
type: "text",
|
|
577
|
+
text: agentChunk.result,
|
|
578
|
+
state: "done"
|
|
579
|
+
});
|
|
580
|
+
return [
|
|
581
|
+
...newConversation.slice(0, -1),
|
|
571
582
|
{
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
state: "done"
|
|
583
|
+
...lastMessage,
|
|
584
|
+
parts
|
|
575
585
|
}
|
|
576
|
-
]
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
586
|
+
];
|
|
587
|
+
}
|
|
588
|
+
const textPart = parts[textPartIndex];
|
|
589
|
+
if (textPart.type === "text") {
|
|
590
|
+
parts[textPartIndex] = {
|
|
591
|
+
...textPart,
|
|
592
|
+
state: "done"
|
|
593
|
+
};
|
|
594
|
+
return [
|
|
595
|
+
...newConversation.slice(0, -1),
|
|
596
|
+
{
|
|
597
|
+
...lastMessage,
|
|
598
|
+
parts
|
|
599
|
+
}
|
|
600
|
+
];
|
|
601
|
+
}
|
|
602
|
+
return newConversation;
|
|
580
603
|
}
|
|
581
604
|
return newConversation;
|
|
582
605
|
}
|
|
606
|
+
handleRoutingAgentConversation = (chunk, newConversation) => {
|
|
607
|
+
const lastMessage = newConversation[newConversation.length - 1];
|
|
608
|
+
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
609
|
+
const agentChunk = chunk.payload;
|
|
610
|
+
const parts = [...lastMessage.parts];
|
|
611
|
+
const textPartIndex = parts.findIndex((part) => part.type === "text");
|
|
612
|
+
if (textPartIndex === -1) {
|
|
613
|
+
parts.push({
|
|
614
|
+
type: "text",
|
|
615
|
+
text: agentChunk.text,
|
|
616
|
+
state: "streaming"
|
|
617
|
+
});
|
|
618
|
+
return [
|
|
619
|
+
...newConversation.slice(0, -1),
|
|
620
|
+
{
|
|
621
|
+
...lastMessage,
|
|
622
|
+
parts
|
|
623
|
+
}
|
|
624
|
+
];
|
|
625
|
+
}
|
|
626
|
+
const textPart = parts[textPartIndex];
|
|
627
|
+
if (textPart.type === "text") {
|
|
628
|
+
parts[textPartIndex] = {
|
|
629
|
+
...textPart,
|
|
630
|
+
text: textPart.text + agentChunk.text,
|
|
631
|
+
state: "streaming"
|
|
632
|
+
};
|
|
633
|
+
return [
|
|
634
|
+
...newConversation.slice(0, -1),
|
|
635
|
+
{
|
|
636
|
+
...lastMessage,
|
|
637
|
+
parts
|
|
638
|
+
}
|
|
639
|
+
];
|
|
640
|
+
}
|
|
641
|
+
return newConversation;
|
|
642
|
+
};
|
|
583
643
|
handleAgentConversation = (chunk, newConversation, metadata) => {
|
|
584
644
|
if (chunk.type === "agent-execution-start") {
|
|
585
645
|
const primitiveId = chunk.payload?.args?.primitiveId;
|
|
@@ -1044,9 +1104,7 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1044
1104
|
}
|
|
1045
1105
|
await response.processDataStream({
|
|
1046
1106
|
onChunk: async (chunk) => {
|
|
1047
|
-
|
|
1048
|
-
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
1049
|
-
});
|
|
1107
|
+
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
1050
1108
|
onChunk?.(chunk);
|
|
1051
1109
|
}
|
|
1052
1110
|
});
|
|
@@ -1086,21 +1144,29 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1086
1144
|
const transformer = new AISdkNetworkTransformer();
|
|
1087
1145
|
await response.processDataStream({
|
|
1088
1146
|
onChunk: async (chunk) => {
|
|
1089
|
-
|
|
1090
|
-
setMessages((prev) => transformer.transform({ chunk, conversation: prev, metadata: { mode: "network" } }));
|
|
1091
|
-
});
|
|
1147
|
+
setMessages((prev) => transformer.transform({ chunk, conversation: prev, metadata: { mode: "network" } }));
|
|
1092
1148
|
onNetworkChunk?.(chunk);
|
|
1093
1149
|
}
|
|
1094
1150
|
});
|
|
1095
1151
|
setIsRunning(false);
|
|
1096
1152
|
};
|
|
1153
|
+
const sendMessage = async ({ mode = "stream", ...args }) => {
|
|
1154
|
+
const nextMessage = { role: "user", content: [{ type: "text", text: args.message }] };
|
|
1155
|
+
const messages2 = args.coreUserMessages ? [nextMessage, ...args.coreUserMessages] : [nextMessage];
|
|
1156
|
+
setMessages((s) => [...s, { role: "user", parts: [{ type: "text", text: args.message }] }]);
|
|
1157
|
+
if (mode === "generate") {
|
|
1158
|
+
await generate({ ...args, coreUserMessages: messages2 });
|
|
1159
|
+
} else if (mode === "stream") {
|
|
1160
|
+
await stream({ ...args, coreUserMessages: messages2 });
|
|
1161
|
+
} else if (mode === "network") {
|
|
1162
|
+
await network({ ...args, coreUserMessages: messages2 });
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1097
1165
|
return {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
generate,
|
|
1166
|
+
setMessages,
|
|
1167
|
+
sendMessage,
|
|
1101
1168
|
isRunning,
|
|
1102
1169
|
messages,
|
|
1103
|
-
setMessages,
|
|
1104
1170
|
cancelRun: () => setIsRunning(false)
|
|
1105
1171
|
};
|
|
1106
1172
|
};
|