@mastra/playground-ui 5.1.7 → 5.1.8-alpha.0
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/dist/index.cjs.js +179 -49
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +179 -49
- package/dist/index.es.js.map +1 -1
- package/dist/src/domains/networks/network-context.d.ts +4 -0
- package/dist/src/domains/networks/v-next/tool-fallback.d.ts +0 -0
- package/dist/src/services/vnext-network-chat-provider.d.ts +1 -2
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -6861,8 +6861,12 @@ const defaultModelSettings = {
|
|
|
6861
6861
|
const NetworkContext = createContext({});
|
|
6862
6862
|
function NetworkProvider({ children }) {
|
|
6863
6863
|
const [modelSettings, setModelSettings] = useState(defaultModelSettings);
|
|
6864
|
+
const [chatWithLoop, setChatWithLoop] = useState(false);
|
|
6865
|
+
const [maxIterations, setMaxIterations] = useState(void 0);
|
|
6864
6866
|
const resetModelSettings = () => {
|
|
6865
6867
|
setModelSettings(defaultModelSettings);
|
|
6868
|
+
setChatWithLoop(false);
|
|
6869
|
+
setMaxIterations(void 0);
|
|
6866
6870
|
};
|
|
6867
6871
|
return /* @__PURE__ */ jsx(
|
|
6868
6872
|
NetworkContext.Provider,
|
|
@@ -6870,7 +6874,11 @@ function NetworkProvider({ children }) {
|
|
|
6870
6874
|
value: {
|
|
6871
6875
|
modelSettings,
|
|
6872
6876
|
setModelSettings,
|
|
6873
|
-
resetModelSettings
|
|
6877
|
+
resetModelSettings,
|
|
6878
|
+
chatWithLoop,
|
|
6879
|
+
setChatWithLoop,
|
|
6880
|
+
maxIterations,
|
|
6881
|
+
setMaxIterations
|
|
6874
6882
|
},
|
|
6875
6883
|
children
|
|
6876
6884
|
}
|
|
@@ -6883,9 +6891,11 @@ const NetworkChat = ({ agentId, memory }) => {
|
|
|
6883
6891
|
};
|
|
6884
6892
|
|
|
6885
6893
|
const VNextNetworkChatContext = createContext(void 0);
|
|
6886
|
-
const VNextNetworkChatProvider = ({ children
|
|
6894
|
+
const VNextNetworkChatProvider = ({ children }) => {
|
|
6887
6895
|
const [state, setState] = useState({});
|
|
6896
|
+
const { chatWithLoop } = useContext(NetworkContext);
|
|
6888
6897
|
const handleStep = (uuid, record) => {
|
|
6898
|
+
const addFinishStep = chatWithLoop && record.type === "step-finish" && record.payload?.id === "final-step";
|
|
6889
6899
|
const id = record?.type === "finish" ? "finish" : record.type === "start" ? "start" : record.payload?.id;
|
|
6890
6900
|
if (id.includes("mapping_")) return;
|
|
6891
6901
|
setState((prevState) => {
|
|
@@ -6904,7 +6914,7 @@ const VNextNetworkChatProvider = ({ children, networkId }) => {
|
|
|
6904
6914
|
[uuid]: {
|
|
6905
6915
|
...current,
|
|
6906
6916
|
runId: current?.runId || record?.payload?.runId,
|
|
6907
|
-
executionSteps: current?.steps?.[id] ? current?.executionSteps : [...current?.executionSteps || [], id],
|
|
6917
|
+
executionSteps: current?.steps?.[id] ? [...current?.executionSteps, ...addFinishStep ? ["finish"] : []] : [...current?.executionSteps || [], id],
|
|
6908
6918
|
steps: {
|
|
6909
6919
|
...current?.steps,
|
|
6910
6920
|
[id]: {
|
|
@@ -8587,7 +8597,8 @@ const useResumeWorkflow = () => {
|
|
|
8587
8597
|
const LabelMappings = {
|
|
8588
8598
|
"routing-step": "Decision making process",
|
|
8589
8599
|
"agent-step": "Agent execution",
|
|
8590
|
-
"workflow-step": "Workflow execution"
|
|
8600
|
+
"workflow-step": "Workflow execution",
|
|
8601
|
+
"final-step": "Task completed"
|
|
8591
8602
|
};
|
|
8592
8603
|
const StepDropdown = () => {
|
|
8593
8604
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
@@ -8615,7 +8626,7 @@ const StepDropdown = () => {
|
|
|
8615
8626
|
const Steps = ({ id }) => {
|
|
8616
8627
|
const { state } = useVNextNetworkChat();
|
|
8617
8628
|
const currentState = state[id];
|
|
8618
|
-
return /* @__PURE__ */ jsx("ol", { className: "flex flex-col gap-px rounded-lg overflow-hidden", children: currentState.executionSteps.filter((stepId) => stepId !== "start").map((stepId, index) => /* @__PURE__ */ jsx(StepEntry, { stepId, step: currentState.steps[stepId], runId: currentState.runId }, index)) });
|
|
8629
|
+
return /* @__PURE__ */ jsx("ol", { className: "flex flex-col gap-px rounded-lg overflow-hidden", children: currentState.executionSteps.filter((stepId) => stepId !== "start").map((stepId, index) => /* @__PURE__ */ jsx(StepEntry, { stepId, step: currentState.steps[stepId] || {}, runId: currentState.runId }, index)) });
|
|
8619
8630
|
};
|
|
8620
8631
|
const StepEntry = ({ stepId, step, runId }) => {
|
|
8621
8632
|
const [expanded, setExpanded] = useState(false);
|
|
@@ -8648,6 +8659,16 @@ const StepEntry = ({ stepId, step, runId }) => {
|
|
|
8648
8659
|
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon6", children: stepResult?.output?.resourceId || "N/A" })
|
|
8649
8660
|
] })
|
|
8650
8661
|
] }),
|
|
8662
|
+
stepId === "final-step" && expanded && /* @__PURE__ */ jsxs("div", { className: "bg-surface1 p-3 space-y-4", children: [
|
|
8663
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
8664
|
+
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon3 font-medium", children: "Task:" }),
|
|
8665
|
+
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon6", children: stepResult?.output?.task || "N/A" })
|
|
8666
|
+
] }),
|
|
8667
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
8668
|
+
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon3 font-medium", children: "Number of iterations:" }),
|
|
8669
|
+
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon6", children: stepResult?.output?.iteration || "N/A" })
|
|
8670
|
+
] })
|
|
8671
|
+
] }),
|
|
8651
8672
|
stepId === "workflow-step" && stepResult?.output?.resourceId ? /* @__PURE__ */ jsx(
|
|
8652
8673
|
WorkflowStepResultDialog,
|
|
8653
8674
|
{
|
|
@@ -8903,6 +8924,7 @@ function VNextMastraNetworkRuntimeProvider({
|
|
|
8903
8924
|
const { messages, setMessages, appendToLastMessage } = useMessages();
|
|
8904
8925
|
const [currentThreadId, setCurrentThreadId] = useState(threadId);
|
|
8905
8926
|
const { handleStep, state, setState } = useVNextNetworkChat();
|
|
8927
|
+
const { chatWithLoop, maxIterations } = useContext(NetworkContext);
|
|
8906
8928
|
const id = runIdRef.current;
|
|
8907
8929
|
const currentState = id ? state[id] : void 0;
|
|
8908
8930
|
useEffect(() => {
|
|
@@ -9037,53 +9059,161 @@ ${formatted}\`\`\``;
|
|
|
9037
9059
|
setMessages((currentConversation) => [...currentConversation, { role: "user", content: input }]);
|
|
9038
9060
|
setIsRunning(true);
|
|
9039
9061
|
try {
|
|
9040
|
-
|
|
9041
|
-
{
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
|
|
9045
|
-
|
|
9046
|
-
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9062
|
+
if (chatWithLoop) {
|
|
9063
|
+
const run = async (result, messageId) => {
|
|
9064
|
+
const formatted = await formatJSON(result);
|
|
9065
|
+
const finalResponse = `\`\`\`json
|
|
9066
|
+
${formatted}\`\`\``;
|
|
9067
|
+
setMessages((currentConversation) => {
|
|
9068
|
+
return currentConversation.map((message2) => {
|
|
9069
|
+
if (message2.metadata?.custom?.id === messageId) {
|
|
9070
|
+
return { ...message2, content: [{ type: "text", text: finalResponse }] };
|
|
9071
|
+
}
|
|
9072
|
+
return message2;
|
|
9073
|
+
});
|
|
9074
|
+
});
|
|
9075
|
+
};
|
|
9076
|
+
let isAgentNetworkOuterWorkflowCompleted = false;
|
|
9077
|
+
await network.loopStream(
|
|
9078
|
+
{
|
|
9079
|
+
message: input,
|
|
9080
|
+
threadId,
|
|
9081
|
+
resourceId: networkId,
|
|
9082
|
+
maxIterations
|
|
9083
|
+
},
|
|
9084
|
+
async (record) => {
|
|
9085
|
+
if (record.type === "step-start" && record.payload?.id === "Agent-Network-Outer-Workflow") {
|
|
9086
|
+
const id2 = v4();
|
|
9087
|
+
runIdRef.current = id2;
|
|
9088
|
+
setMessages((currentConversation) => {
|
|
9089
|
+
return [
|
|
9090
|
+
...currentConversation,
|
|
9091
|
+
{
|
|
9092
|
+
role: "assistant",
|
|
9093
|
+
metadata: {
|
|
9094
|
+
custom: {
|
|
9095
|
+
id: id2
|
|
9096
|
+
}
|
|
9097
|
+
},
|
|
9098
|
+
content: [
|
|
9099
|
+
{
|
|
9100
|
+
type: "text",
|
|
9101
|
+
text: "start"
|
|
9102
|
+
}
|
|
9103
|
+
]
|
|
9104
|
+
}
|
|
9105
|
+
];
|
|
9106
|
+
});
|
|
9107
|
+
} else if (runIdRef.current) {
|
|
9108
|
+
if (record.type === "tool-call-delta") {
|
|
9109
|
+
appendToLastMessage(record.argsTextDelta);
|
|
9110
|
+
} else if (record.type === "tool-call-streaming-start") {
|
|
9111
|
+
setMessages((msgs) => [...msgs, { role: "assistant", content: [{ type: "text", text: "" }] }]);
|
|
9112
|
+
setTimeout(() => {
|
|
9113
|
+
refreshThreadList?.();
|
|
9114
|
+
}, 500);
|
|
9115
|
+
return;
|
|
9116
|
+
} else {
|
|
9117
|
+
if (record.type === "step-finish" && record.payload?.id === "Agent-Network-Outer-Workflow") {
|
|
9118
|
+
if (!isAgentNetworkOuterWorkflowCompleted) {
|
|
9119
|
+
handleStep(runIdRef.current, { ...record, type: "finish" });
|
|
9120
|
+
runIdRef.current = void 0;
|
|
9121
|
+
}
|
|
9122
|
+
} else if (record.type === "step-result" && record.payload?.id === "workflow-step") {
|
|
9123
|
+
handleStep(runIdRef.current, record);
|
|
9124
|
+
const parsedResult = JSON.parse(record?.payload?.output?.result ?? "{}") ?? {};
|
|
9125
|
+
const runResult = parsedResult?.runResult ?? {};
|
|
9126
|
+
const formatedOutputId = v4();
|
|
9127
|
+
setMessages((msgs) => [
|
|
9128
|
+
...msgs,
|
|
9073
9129
|
{
|
|
9074
|
-
|
|
9075
|
-
|
|
9130
|
+
role: "assistant",
|
|
9131
|
+
content: [
|
|
9132
|
+
{
|
|
9133
|
+
type: "text",
|
|
9134
|
+
text: ""
|
|
9135
|
+
}
|
|
9136
|
+
],
|
|
9137
|
+
metadata: {
|
|
9138
|
+
custom: {
|
|
9139
|
+
id: formatedOutputId
|
|
9140
|
+
}
|
|
9141
|
+
}
|
|
9076
9142
|
}
|
|
9077
|
-
]
|
|
9143
|
+
]);
|
|
9144
|
+
run(JSON.stringify(runResult), formatedOutputId);
|
|
9145
|
+
} else if (record.payload?.id === "Agent-Network-Outer-Workflow" || record.payload?.id === "finish-step") {
|
|
9146
|
+
if (record.type === "step-result" && record.payload?.id === "Agent-Network-Outer-Workflow") {
|
|
9147
|
+
isAgentNetworkOuterWorkflowCompleted = record?.payload?.output?.isComplete;
|
|
9148
|
+
}
|
|
9149
|
+
} else {
|
|
9150
|
+
handleStep(runIdRef.current, record);
|
|
9078
9151
|
}
|
|
9079
|
-
|
|
9080
|
-
}
|
|
9152
|
+
}
|
|
9153
|
+
}
|
|
9154
|
+
if (record.type === "step-result" && record.payload?.id === "final-step") {
|
|
9155
|
+
setMessages((msgs) => [
|
|
9156
|
+
...msgs,
|
|
9157
|
+
{ role: "assistant", content: [{ type: "text", text: record.payload?.output?.result }] }
|
|
9158
|
+
]);
|
|
9159
|
+
}
|
|
9160
|
+
if (record.type === "step-finish" && record.payload?.id === "final-step") {
|
|
9161
|
+
runIdRef.current = void 0;
|
|
9162
|
+
}
|
|
9163
|
+
setTimeout(() => {
|
|
9164
|
+
refreshThreadList?.();
|
|
9165
|
+
}, 500);
|
|
9081
9166
|
}
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9167
|
+
);
|
|
9168
|
+
} else {
|
|
9169
|
+
await network.stream(
|
|
9170
|
+
{
|
|
9171
|
+
message: input,
|
|
9172
|
+
threadId,
|
|
9173
|
+
resourceId: networkId
|
|
9174
|
+
},
|
|
9175
|
+
(record) => {
|
|
9176
|
+
if (runIdRef.current) {
|
|
9177
|
+
if (record.type === "tool-call-delta") {
|
|
9178
|
+
appendToLastMessage(record.argsTextDelta);
|
|
9179
|
+
} else if (record.type === "tool-call-streaming-start") {
|
|
9180
|
+
setMessages((msgs) => [...msgs, { role: "assistant", content: [{ type: "text", text: "" }] }]);
|
|
9181
|
+
setTimeout(() => {
|
|
9182
|
+
refreshThreadList?.();
|
|
9183
|
+
}, 500);
|
|
9184
|
+
return;
|
|
9185
|
+
} else {
|
|
9186
|
+
handleStep(runIdRef.current, record);
|
|
9187
|
+
}
|
|
9188
|
+
} else if (record.type === "start") {
|
|
9189
|
+
const id2 = v4();
|
|
9190
|
+
runIdRef.current = id2;
|
|
9191
|
+
setMessages((currentConversation) => {
|
|
9192
|
+
return [
|
|
9193
|
+
...currentConversation,
|
|
9194
|
+
{
|
|
9195
|
+
role: "assistant",
|
|
9196
|
+
metadata: {
|
|
9197
|
+
custom: {
|
|
9198
|
+
id: id2
|
|
9199
|
+
}
|
|
9200
|
+
},
|
|
9201
|
+
content: [
|
|
9202
|
+
{
|
|
9203
|
+
type: "text",
|
|
9204
|
+
text: "start"
|
|
9205
|
+
}
|
|
9206
|
+
]
|
|
9207
|
+
}
|
|
9208
|
+
];
|
|
9209
|
+
});
|
|
9210
|
+
}
|
|
9211
|
+
setTimeout(() => {
|
|
9212
|
+
refreshThreadList?.();
|
|
9213
|
+
}, 500);
|
|
9214
|
+
}
|
|
9215
|
+
);
|
|
9216
|
+
}
|
|
9087
9217
|
setIsRunning(false);
|
|
9088
9218
|
} catch (error) {
|
|
9089
9219
|
console.error("Error occurred in VNextMastraNetworkRuntimeProvider", error);
|
|
@@ -9111,7 +9241,7 @@ const VNextNetworkChat = ({
|
|
|
9111
9241
|
memory,
|
|
9112
9242
|
refreshThreadList
|
|
9113
9243
|
}) => {
|
|
9114
|
-
return /* @__PURE__ */ jsx(MessagesProvider, { children: /* @__PURE__ */ jsx(VNextNetworkChatProvider, {
|
|
9244
|
+
return /* @__PURE__ */ jsx(MessagesProvider, { children: /* @__PURE__ */ jsx(VNextNetworkChatProvider, { children: /* @__PURE__ */ jsx(
|
|
9115
9245
|
VNextMastraNetworkRuntimeProvider,
|
|
9116
9246
|
{
|
|
9117
9247
|
networkId,
|