@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/dist/index.js
CHANGED
|
@@ -457,7 +457,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
457
457
|
mode: "stream",
|
|
458
458
|
requireApprovalMetadata: {
|
|
459
459
|
...lastRequireApprovalMetadata,
|
|
460
|
-
[chunk.payload.
|
|
460
|
+
[chunk.payload.toolName]: {
|
|
461
461
|
toolCallId: chunk.payload.toolCallId,
|
|
462
462
|
toolName: chunk.payload.toolName,
|
|
463
463
|
args: chunk.payload.args
|
|
@@ -467,6 +467,30 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
467
467
|
}
|
|
468
468
|
];
|
|
469
469
|
}
|
|
470
|
+
case "tool-call-suspended": {
|
|
471
|
+
const lastMessage = result[result.length - 1];
|
|
472
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
473
|
+
const lastSuspendedTools = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.suspendedTools : {};
|
|
474
|
+
return [
|
|
475
|
+
...result.slice(0, -1),
|
|
476
|
+
{
|
|
477
|
+
...lastMessage,
|
|
478
|
+
metadata: {
|
|
479
|
+
...lastMessage.metadata,
|
|
480
|
+
mode: "stream",
|
|
481
|
+
suspendedTools: {
|
|
482
|
+
...lastSuspendedTools,
|
|
483
|
+
[chunk.payload.toolName]: {
|
|
484
|
+
toolCallId: chunk.payload.toolCallId,
|
|
485
|
+
toolName: chunk.payload.toolName,
|
|
486
|
+
args: chunk.payload.args,
|
|
487
|
+
suspendPayload: chunk.payload.suspendPayload
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
];
|
|
493
|
+
}
|
|
470
494
|
case "finish": {
|
|
471
495
|
const lastMessage = result[result.length - 1];
|
|
472
496
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
@@ -682,13 +706,14 @@ const toAssistantUIMessage = (message) => {
|
|
|
682
706
|
return baseToolCall;
|
|
683
707
|
}
|
|
684
708
|
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
685
|
-
const
|
|
709
|
+
const toolName2 = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
|
|
710
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
686
711
|
const baseToolCall = {
|
|
687
712
|
type: "tool-call",
|
|
688
713
|
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
689
|
-
toolName,
|
|
690
|
-
argsText:
|
|
691
|
-
args:
|
|
714
|
+
toolName: toolName2,
|
|
715
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
716
|
+
args: cleanInput ?? {},
|
|
692
717
|
metadata: message.metadata
|
|
693
718
|
};
|
|
694
719
|
if ("output" in part) {
|
|
@@ -698,17 +723,19 @@ const toAssistantUIMessage = (message) => {
|
|
|
698
723
|
}
|
|
699
724
|
return baseToolCall;
|
|
700
725
|
}
|
|
726
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
701
727
|
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
728
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
702
729
|
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
703
|
-
const suspensionData =
|
|
730
|
+
const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
|
|
704
731
|
if (suspensionData) {
|
|
705
|
-
const
|
|
732
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
706
733
|
return {
|
|
707
734
|
type: "tool-call",
|
|
708
735
|
toolCallId: partToolCallId,
|
|
709
736
|
toolName,
|
|
710
|
-
argsText:
|
|
711
|
-
args:
|
|
737
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
738
|
+
args: cleanInput,
|
|
712
739
|
metadata: extendedMessage.metadata
|
|
713
740
|
};
|
|
714
741
|
}
|
|
@@ -773,28 +800,34 @@ const resolveInitialMessages = (messages) => {
|
|
|
773
800
|
const primitiveType = json.primitiveType || "";
|
|
774
801
|
const primitiveId = json.primitiveId || "";
|
|
775
802
|
const finalResult = json.finalResult;
|
|
776
|
-
const
|
|
803
|
+
const messages2 = finalResult?.messages || [];
|
|
777
804
|
const childMessages = [];
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
805
|
+
const toolResultMap = /* @__PURE__ */ new Map();
|
|
806
|
+
for (const msg of messages2) {
|
|
807
|
+
if (Array.isArray(msg.content)) {
|
|
808
|
+
for (const part of msg.content) {
|
|
809
|
+
if (typeof part === "object" && part.type === "tool-result") {
|
|
810
|
+
toolResultMap.set(part.toolCallId, part);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
for (const msg of messages2) {
|
|
816
|
+
if (msg.type === "tool-call" && Array.isArray(msg.content)) {
|
|
817
|
+
for (const part of msg.content) {
|
|
818
|
+
if (typeof part === "object" && part.type === "tool-call") {
|
|
819
|
+
const toolCallContent = part;
|
|
820
|
+
const toolResult = toolResultMap.get(toolCallContent.toolCallId);
|
|
821
|
+
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
822
|
+
childMessages.push({
|
|
823
|
+
type: "tool",
|
|
824
|
+
toolCallId: toolCallContent.toolCallId,
|
|
825
|
+
toolName: toolCallContent.toolName,
|
|
826
|
+
args: toolCallContent.args,
|
|
827
|
+
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
828
|
+
});
|
|
788
829
|
}
|
|
789
830
|
}
|
|
790
|
-
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
791
|
-
childMessages.push({
|
|
792
|
-
type: "tool",
|
|
793
|
-
toolCallId: toolCall.payload.toolCallId,
|
|
794
|
-
toolName: toolCall.payload.toolName,
|
|
795
|
-
args: toolCall.payload.args,
|
|
796
|
-
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
797
|
-
});
|
|
798
831
|
}
|
|
799
832
|
}
|
|
800
833
|
if (finalResult && finalResult.text) {
|
|
@@ -846,6 +879,17 @@ const resolveInitialMessages = (messages) => {
|
|
|
846
879
|
}
|
|
847
880
|
};
|
|
848
881
|
}
|
|
882
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
883
|
+
if (suspendedTools && typeof suspendedTools === "object") {
|
|
884
|
+
return {
|
|
885
|
+
...message,
|
|
886
|
+
metadata: {
|
|
887
|
+
...message.metadata,
|
|
888
|
+
mode: "stream",
|
|
889
|
+
suspendedTools
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
}
|
|
849
893
|
return message;
|
|
850
894
|
});
|
|
851
895
|
};
|