@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/dist/index.js
CHANGED
|
@@ -47,7 +47,7 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
47
47
|
return {
|
|
48
48
|
...prev,
|
|
49
49
|
status: chunk.payload.workflowStatus,
|
|
50
|
-
...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : {}
|
|
50
|
+
...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 } : {}
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
const { stepCallId, stepName, ...newPayload } = chunk.payload ?? {};
|
|
@@ -135,12 +135,17 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
135
135
|
parts: [
|
|
136
136
|
{
|
|
137
137
|
type: "text",
|
|
138
|
-
text: chunk.payload.
|
|
138
|
+
text: chunk.payload.reason
|
|
139
139
|
}
|
|
140
140
|
],
|
|
141
141
|
metadata: {
|
|
142
142
|
...metadata,
|
|
143
|
-
status: "
|
|
143
|
+
status: "tripwire",
|
|
144
|
+
tripwire: {
|
|
145
|
+
retry: chunk.payload.retry,
|
|
146
|
+
tripwirePayload: chunk.payload.metadata,
|
|
147
|
+
processorId: chunk.payload.processorId
|
|
148
|
+
}
|
|
144
149
|
}
|
|
145
150
|
};
|
|
146
151
|
return [...result, newMessage];
|
|
@@ -452,7 +457,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
452
457
|
mode: "stream",
|
|
453
458
|
requireApprovalMetadata: {
|
|
454
459
|
...lastRequireApprovalMetadata,
|
|
455
|
-
[chunk.payload.
|
|
460
|
+
[chunk.payload.toolName]: {
|
|
456
461
|
toolCallId: chunk.payload.toolCallId,
|
|
457
462
|
toolName: chunk.payload.toolName,
|
|
458
463
|
args: chunk.payload.args
|
|
@@ -462,6 +467,30 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
462
467
|
}
|
|
463
468
|
];
|
|
464
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
|
+
}
|
|
465
494
|
case "finish": {
|
|
466
495
|
const lastMessage = result[result.length - 1];
|
|
467
496
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
@@ -677,13 +706,14 @@ const toAssistantUIMessage = (message) => {
|
|
|
677
706
|
return baseToolCall;
|
|
678
707
|
}
|
|
679
708
|
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
680
|
-
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 : {};
|
|
681
711
|
const baseToolCall = {
|
|
682
712
|
type: "tool-call",
|
|
683
713
|
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
684
|
-
toolName,
|
|
685
|
-
argsText:
|
|
686
|
-
args:
|
|
714
|
+
toolName: toolName2,
|
|
715
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
716
|
+
args: cleanInput ?? {},
|
|
687
717
|
metadata: message.metadata
|
|
688
718
|
};
|
|
689
719
|
if ("output" in part) {
|
|
@@ -693,17 +723,19 @@ const toAssistantUIMessage = (message) => {
|
|
|
693
723
|
}
|
|
694
724
|
return baseToolCall;
|
|
695
725
|
}
|
|
726
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
696
727
|
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
728
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
697
729
|
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
698
|
-
const suspensionData =
|
|
730
|
+
const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
|
|
699
731
|
if (suspensionData) {
|
|
700
|
-
const
|
|
732
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
701
733
|
return {
|
|
702
734
|
type: "tool-call",
|
|
703
735
|
toolCallId: partToolCallId,
|
|
704
736
|
toolName,
|
|
705
|
-
argsText:
|
|
706
|
-
args:
|
|
737
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
738
|
+
args: cleanInput,
|
|
707
739
|
metadata: extendedMessage.metadata
|
|
708
740
|
};
|
|
709
741
|
}
|
|
@@ -768,28 +800,34 @@ const resolveInitialMessages = (messages) => {
|
|
|
768
800
|
const primitiveType = json.primitiveType || "";
|
|
769
801
|
const primitiveId = json.primitiveId || "";
|
|
770
802
|
const finalResult = json.finalResult;
|
|
771
|
-
const
|
|
803
|
+
const messages2 = finalResult?.messages || [];
|
|
772
804
|
const childMessages = [];
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
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
|
+
});
|
|
783
829
|
}
|
|
784
830
|
}
|
|
785
|
-
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
786
|
-
childMessages.push({
|
|
787
|
-
type: "tool",
|
|
788
|
-
toolCallId: toolCall.payload.toolCallId,
|
|
789
|
-
toolName: toolCall.payload.toolName,
|
|
790
|
-
args: toolCall.payload.args,
|
|
791
|
-
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
792
|
-
});
|
|
793
831
|
}
|
|
794
832
|
}
|
|
795
833
|
if (finalResult && finalResult.text) {
|
|
@@ -841,6 +879,17 @@ const resolveInitialMessages = (messages) => {
|
|
|
841
879
|
}
|
|
842
880
|
};
|
|
843
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
|
+
}
|
|
844
893
|
return message;
|
|
845
894
|
});
|
|
846
895
|
};
|