@mastra/react 0.1.0-beta.10 → 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 +66 -0
- package/dist/index.cjs +80 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +80 -31
- package/dist/index.js.map +1 -1
- package/dist/src/lib/ai-sdk/types.d.ts +23 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
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
|
+
|
|
43
|
+
## 0.1.0-beta.11
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 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))
|
|
48
|
+
|
|
49
|
+
When a workflow contains an agent step that triggers a tripwire, the workflow returns with `status: 'tripwire'` and includes tripwire details:
|
|
50
|
+
|
|
51
|
+
```typescript showLineNumbers copy
|
|
52
|
+
const run = await workflow.createRun();
|
|
53
|
+
const result = await run.start({ inputData: { message: 'Hello' } });
|
|
54
|
+
|
|
55
|
+
if (result.status === 'tripwire') {
|
|
56
|
+
console.log('Workflow terminated by tripwire:', result.tripwire?.reason);
|
|
57
|
+
console.log('Processor ID:', result.tripwire?.processorId);
|
|
58
|
+
console.log('Retry requested:', result.tripwire?.retry);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Adds new UI state for tripwire in agent chat and workflow UI.
|
|
63
|
+
|
|
64
|
+
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).
|
|
65
|
+
|
|
66
|
+
- Updated dependencies [[`3bf6c5f`](https://github.com/mastra-ai/mastra/commit/3bf6c5f104c25226cd84e0c77f9dec15f2cac2db)]:
|
|
67
|
+
- @mastra/client-js@1.0.0-beta.11
|
|
68
|
+
|
|
3
69
|
## 0.1.0-beta.10
|
|
4
70
|
|
|
5
71
|
### Minor Changes
|
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 ?? {};
|
|
@@ -139,12 +139,17 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
139
139
|
parts: [
|
|
140
140
|
{
|
|
141
141
|
type: "text",
|
|
142
|
-
text: chunk.payload.
|
|
142
|
+
text: chunk.payload.reason
|
|
143
143
|
}
|
|
144
144
|
],
|
|
145
145
|
metadata: {
|
|
146
146
|
...metadata,
|
|
147
|
-
status: "
|
|
147
|
+
status: "tripwire",
|
|
148
|
+
tripwire: {
|
|
149
|
+
retry: chunk.payload.retry,
|
|
150
|
+
tripwirePayload: chunk.payload.metadata,
|
|
151
|
+
processorId: chunk.payload.processorId
|
|
152
|
+
}
|
|
148
153
|
}
|
|
149
154
|
};
|
|
150
155
|
return [...result, newMessage];
|
|
@@ -456,7 +461,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
456
461
|
mode: "stream",
|
|
457
462
|
requireApprovalMetadata: {
|
|
458
463
|
...lastRequireApprovalMetadata,
|
|
459
|
-
[chunk.payload.
|
|
464
|
+
[chunk.payload.toolName]: {
|
|
460
465
|
toolCallId: chunk.payload.toolCallId,
|
|
461
466
|
toolName: chunk.payload.toolName,
|
|
462
467
|
args: chunk.payload.args
|
|
@@ -466,6 +471,30 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
466
471
|
}
|
|
467
472
|
];
|
|
468
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
|
+
}
|
|
469
498
|
case "finish": {
|
|
470
499
|
const lastMessage = result[result.length - 1];
|
|
471
500
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
@@ -681,13 +710,14 @@ const toAssistantUIMessage = (message) => {
|
|
|
681
710
|
return baseToolCall;
|
|
682
711
|
}
|
|
683
712
|
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
684
|
-
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 : {};
|
|
685
715
|
const baseToolCall = {
|
|
686
716
|
type: "tool-call",
|
|
687
717
|
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
688
|
-
toolName,
|
|
689
|
-
argsText:
|
|
690
|
-
args:
|
|
718
|
+
toolName: toolName2,
|
|
719
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
720
|
+
args: cleanInput ?? {},
|
|
691
721
|
metadata: message.metadata
|
|
692
722
|
};
|
|
693
723
|
if ("output" in part) {
|
|
@@ -697,17 +727,19 @@ const toAssistantUIMessage = (message) => {
|
|
|
697
727
|
}
|
|
698
728
|
return baseToolCall;
|
|
699
729
|
}
|
|
730
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
700
731
|
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
732
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
701
733
|
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
702
|
-
const suspensionData =
|
|
734
|
+
const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
|
|
703
735
|
if (suspensionData) {
|
|
704
|
-
const
|
|
736
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
705
737
|
return {
|
|
706
738
|
type: "tool-call",
|
|
707
739
|
toolCallId: partToolCallId,
|
|
708
740
|
toolName,
|
|
709
|
-
argsText:
|
|
710
|
-
args:
|
|
741
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
742
|
+
args: cleanInput,
|
|
711
743
|
metadata: extendedMessage.metadata
|
|
712
744
|
};
|
|
713
745
|
}
|
|
@@ -772,28 +804,34 @@ const resolveInitialMessages = (messages) => {
|
|
|
772
804
|
const primitiveType = json.primitiveType || "";
|
|
773
805
|
const primitiveId = json.primitiveId || "";
|
|
774
806
|
const finalResult = json.finalResult;
|
|
775
|
-
const
|
|
807
|
+
const messages2 = finalResult?.messages || [];
|
|
776
808
|
const childMessages = [];
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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
|
+
});
|
|
787
833
|
}
|
|
788
834
|
}
|
|
789
|
-
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
790
|
-
childMessages.push({
|
|
791
|
-
type: "tool",
|
|
792
|
-
toolCallId: toolCall.payload.toolCallId,
|
|
793
|
-
toolName: toolCall.payload.toolName,
|
|
794
|
-
args: toolCall.payload.args,
|
|
795
|
-
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
796
|
-
});
|
|
797
835
|
}
|
|
798
836
|
}
|
|
799
837
|
if (finalResult && finalResult.text) {
|
|
@@ -845,6 +883,17 @@ const resolveInitialMessages = (messages) => {
|
|
|
845
883
|
}
|
|
846
884
|
};
|
|
847
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
|
+
}
|
|
848
897
|
return message;
|
|
849
898
|
});
|
|
850
899
|
};
|