@mastra/react 0.1.0-beta.11 → 0.1.0-beta.13
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 +40 -0
- package/dist/index.cjs +72 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -28
- package/dist/index.js.map +1 -1
- package/dist/src/lib/ai-sdk/types.d.ts +9 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @mastra/react-hooks
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- @mastra/client-js@1.0.0-beta.13
|
|
9
|
+
|
|
10
|
+
## 0.1.0-beta.12
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Remove redundant toolCalls from network agent finalResult ([#11189](https://github.com/mastra-ai/mastra/pull/11189))
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
**Before:** `finalResult: { text, toolCalls, messages }`
|
|
19
|
+
**After:** `finalResult: { text, messages }`
|
|
20
|
+
|
|
21
|
+
+**Migration:** If you were accessing `finalResult.toolCalls`, retrieve tool calls from `finalResult.messages` by filtering for messages with `type: 'tool-call'`.
|
|
22
|
+
|
|
23
|
+
Updated `@mastra/react` to extract tool calls directly from the `messages` array instead of the removed `toolCalls` field when resolving initial messages from memory.
|
|
24
|
+
|
|
25
|
+
Fixes #11059
|
|
26
|
+
|
|
27
|
+
- Auto resume suspended tools if `autoResumeSuspendedTools: true` ([#11157](https://github.com/mastra-ai/mastra/pull/11157))
|
|
28
|
+
|
|
29
|
+
The flag can be added to `defaultAgentOptions` when creating the agent or to options in `agent.stream` or `agent.generate`
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const agent = new Agent({
|
|
33
|
+
//...agent information,
|
|
34
|
+
defaultAgentOptions: {
|
|
35
|
+
autoResumeSuspendedTools: true,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- 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)]:
|
|
41
|
+
- @mastra/client-js@1.0.0-beta.12
|
|
42
|
+
|
|
3
43
|
## 0.1.0-beta.11
|
|
4
44
|
|
|
5
45
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -461,7 +461,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
461
461
|
mode: "stream",
|
|
462
462
|
requireApprovalMetadata: {
|
|
463
463
|
...lastRequireApprovalMetadata,
|
|
464
|
-
[chunk.payload.
|
|
464
|
+
[chunk.payload.toolName]: {
|
|
465
465
|
toolCallId: chunk.payload.toolCallId,
|
|
466
466
|
toolName: chunk.payload.toolName,
|
|
467
467
|
args: chunk.payload.args
|
|
@@ -471,6 +471,30 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
471
471
|
}
|
|
472
472
|
];
|
|
473
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
|
+
}
|
|
474
498
|
case "finish": {
|
|
475
499
|
const lastMessage = result[result.length - 1];
|
|
476
500
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
@@ -686,13 +710,14 @@ const toAssistantUIMessage = (message) => {
|
|
|
686
710
|
return baseToolCall;
|
|
687
711
|
}
|
|
688
712
|
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
689
|
-
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 : {};
|
|
690
715
|
const baseToolCall = {
|
|
691
716
|
type: "tool-call",
|
|
692
717
|
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
693
|
-
toolName,
|
|
694
|
-
argsText:
|
|
695
|
-
args:
|
|
718
|
+
toolName: toolName2,
|
|
719
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
720
|
+
args: cleanInput ?? {},
|
|
696
721
|
metadata: message.metadata
|
|
697
722
|
};
|
|
698
723
|
if ("output" in part) {
|
|
@@ -702,17 +727,19 @@ const toAssistantUIMessage = (message) => {
|
|
|
702
727
|
}
|
|
703
728
|
return baseToolCall;
|
|
704
729
|
}
|
|
730
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
705
731
|
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
732
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
706
733
|
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
707
|
-
const suspensionData =
|
|
734
|
+
const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
|
|
708
735
|
if (suspensionData) {
|
|
709
|
-
const
|
|
736
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
710
737
|
return {
|
|
711
738
|
type: "tool-call",
|
|
712
739
|
toolCallId: partToolCallId,
|
|
713
740
|
toolName,
|
|
714
|
-
argsText:
|
|
715
|
-
args:
|
|
741
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
742
|
+
args: cleanInput,
|
|
716
743
|
metadata: extendedMessage.metadata
|
|
717
744
|
};
|
|
718
745
|
}
|
|
@@ -777,28 +804,34 @@ const resolveInitialMessages = (messages) => {
|
|
|
777
804
|
const primitiveType = json.primitiveType || "";
|
|
778
805
|
const primitiveId = json.primitiveId || "";
|
|
779
806
|
const finalResult = json.finalResult;
|
|
780
|
-
const
|
|
807
|
+
const messages2 = finalResult?.messages || [];
|
|
781
808
|
const childMessages = [];
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
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
|
+
});
|
|
792
833
|
}
|
|
793
834
|
}
|
|
794
|
-
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
795
|
-
childMessages.push({
|
|
796
|
-
type: "tool",
|
|
797
|
-
toolCallId: toolCall.payload.toolCallId,
|
|
798
|
-
toolName: toolCall.payload.toolName,
|
|
799
|
-
args: toolCall.payload.args,
|
|
800
|
-
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
801
|
-
});
|
|
802
835
|
}
|
|
803
836
|
}
|
|
804
837
|
if (finalResult && finalResult.text) {
|
|
@@ -850,6 +883,17 @@ const resolveInitialMessages = (messages) => {
|
|
|
850
883
|
}
|
|
851
884
|
};
|
|
852
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
|
+
}
|
|
853
897
|
return message;
|
|
854
898
|
});
|
|
855
899
|
};
|