@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.cjs.js
CHANGED
|
@@ -6893,8 +6893,12 @@ const defaultModelSettings = {
|
|
|
6893
6893
|
const NetworkContext = React.createContext({});
|
|
6894
6894
|
function NetworkProvider({ children }) {
|
|
6895
6895
|
const [modelSettings, setModelSettings] = React.useState(defaultModelSettings);
|
|
6896
|
+
const [chatWithLoop, setChatWithLoop] = React.useState(false);
|
|
6897
|
+
const [maxIterations, setMaxIterations] = React.useState(void 0);
|
|
6896
6898
|
const resetModelSettings = () => {
|
|
6897
6899
|
setModelSettings(defaultModelSettings);
|
|
6900
|
+
setChatWithLoop(false);
|
|
6901
|
+
setMaxIterations(void 0);
|
|
6898
6902
|
};
|
|
6899
6903
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6900
6904
|
NetworkContext.Provider,
|
|
@@ -6902,7 +6906,11 @@ function NetworkProvider({ children }) {
|
|
|
6902
6906
|
value: {
|
|
6903
6907
|
modelSettings,
|
|
6904
6908
|
setModelSettings,
|
|
6905
|
-
resetModelSettings
|
|
6909
|
+
resetModelSettings,
|
|
6910
|
+
chatWithLoop,
|
|
6911
|
+
setChatWithLoop,
|
|
6912
|
+
maxIterations,
|
|
6913
|
+
setMaxIterations
|
|
6906
6914
|
},
|
|
6907
6915
|
children
|
|
6908
6916
|
}
|
|
@@ -6915,9 +6923,11 @@ const NetworkChat = ({ agentId, memory }) => {
|
|
|
6915
6923
|
};
|
|
6916
6924
|
|
|
6917
6925
|
const VNextNetworkChatContext = React.createContext(void 0);
|
|
6918
|
-
const VNextNetworkChatProvider = ({ children
|
|
6926
|
+
const VNextNetworkChatProvider = ({ children }) => {
|
|
6919
6927
|
const [state, setState] = React.useState({});
|
|
6928
|
+
const { chatWithLoop } = React.useContext(NetworkContext);
|
|
6920
6929
|
const handleStep = (uuid, record) => {
|
|
6930
|
+
const addFinishStep = chatWithLoop && record.type === "step-finish" && record.payload?.id === "final-step";
|
|
6921
6931
|
const id = record?.type === "finish" ? "finish" : record.type === "start" ? "start" : record.payload?.id;
|
|
6922
6932
|
if (id.includes("mapping_")) return;
|
|
6923
6933
|
setState((prevState) => {
|
|
@@ -6936,7 +6946,7 @@ const VNextNetworkChatProvider = ({ children, networkId }) => {
|
|
|
6936
6946
|
[uuid]: {
|
|
6937
6947
|
...current,
|
|
6938
6948
|
runId: current?.runId || record?.payload?.runId,
|
|
6939
|
-
executionSteps: current?.steps?.[id] ? current?.executionSteps : [...current?.executionSteps || [], id],
|
|
6949
|
+
executionSteps: current?.steps?.[id] ? [...current?.executionSteps, ...addFinishStep ? ["finish"] : []] : [...current?.executionSteps || [], id],
|
|
6940
6950
|
steps: {
|
|
6941
6951
|
...current?.steps,
|
|
6942
6952
|
[id]: {
|
|
@@ -8619,7 +8629,8 @@ const useResumeWorkflow = () => {
|
|
|
8619
8629
|
const LabelMappings = {
|
|
8620
8630
|
"routing-step": "Decision making process",
|
|
8621
8631
|
"agent-step": "Agent execution",
|
|
8622
|
-
"workflow-step": "Workflow execution"
|
|
8632
|
+
"workflow-step": "Workflow execution",
|
|
8633
|
+
"final-step": "Task completed"
|
|
8623
8634
|
};
|
|
8624
8635
|
const StepDropdown = () => {
|
|
8625
8636
|
const [isExpanded, setIsExpanded] = React.useState(false);
|
|
@@ -8647,7 +8658,7 @@ const StepDropdown = () => {
|
|
|
8647
8658
|
const Steps = ({ id }) => {
|
|
8648
8659
|
const { state } = useVNextNetworkChat();
|
|
8649
8660
|
const currentState = state[id];
|
|
8650
|
-
return /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "flex flex-col gap-px rounded-lg overflow-hidden", children: currentState.executionSteps.filter((stepId) => stepId !== "start").map((stepId, index) => /* @__PURE__ */ jsxRuntime.jsx(StepEntry, { stepId, step: currentState.steps[stepId], runId: currentState.runId }, index)) });
|
|
8661
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "flex flex-col gap-px rounded-lg overflow-hidden", children: currentState.executionSteps.filter((stepId) => stepId !== "start").map((stepId, index) => /* @__PURE__ */ jsxRuntime.jsx(StepEntry, { stepId, step: currentState.steps[stepId] || {}, runId: currentState.runId }, index)) });
|
|
8651
8662
|
};
|
|
8652
8663
|
const StepEntry = ({ stepId, step, runId }) => {
|
|
8653
8664
|
const [expanded, setExpanded] = React.useState(false);
|
|
@@ -8680,6 +8691,16 @@ const StepEntry = ({ stepId, step, runId }) => {
|
|
|
8680
8691
|
/* @__PURE__ */ jsxRuntime.jsx(Txt, { variant: "ui-sm", className: "text-icon6", children: stepResult?.output?.resourceId || "N/A" })
|
|
8681
8692
|
] })
|
|
8682
8693
|
] }),
|
|
8694
|
+
stepId === "final-step" && expanded && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-surface1 p-3 space-y-4", children: [
|
|
8695
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8696
|
+
/* @__PURE__ */ jsxRuntime.jsx(Txt, { variant: "ui-sm", className: "text-icon3 font-medium", children: "Task:" }),
|
|
8697
|
+
/* @__PURE__ */ jsxRuntime.jsx(Txt, { variant: "ui-sm", className: "text-icon6", children: stepResult?.output?.task || "N/A" })
|
|
8698
|
+
] }),
|
|
8699
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8700
|
+
/* @__PURE__ */ jsxRuntime.jsx(Txt, { variant: "ui-sm", className: "text-icon3 font-medium", children: "Number of iterations:" }),
|
|
8701
|
+
/* @__PURE__ */ jsxRuntime.jsx(Txt, { variant: "ui-sm", className: "text-icon6", children: stepResult?.output?.iteration || "N/A" })
|
|
8702
|
+
] })
|
|
8703
|
+
] }),
|
|
8683
8704
|
stepId === "workflow-step" && stepResult?.output?.resourceId ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
8684
8705
|
WorkflowStepResultDialog,
|
|
8685
8706
|
{
|
|
@@ -8935,6 +8956,7 @@ function VNextMastraNetworkRuntimeProvider({
|
|
|
8935
8956
|
const { messages, setMessages, appendToLastMessage } = useMessages();
|
|
8936
8957
|
const [currentThreadId, setCurrentThreadId] = React.useState(threadId);
|
|
8937
8958
|
const { handleStep, state, setState } = useVNextNetworkChat();
|
|
8959
|
+
const { chatWithLoop, maxIterations } = React.useContext(NetworkContext);
|
|
8938
8960
|
const id = runIdRef.current;
|
|
8939
8961
|
const currentState = id ? state[id] : void 0;
|
|
8940
8962
|
React.useEffect(() => {
|
|
@@ -9069,53 +9091,161 @@ ${formatted}\`\`\``;
|
|
|
9069
9091
|
setMessages((currentConversation) => [...currentConversation, { role: "user", content: input }]);
|
|
9070
9092
|
setIsRunning(true);
|
|
9071
9093
|
try {
|
|
9072
|
-
|
|
9073
|
-
{
|
|
9074
|
-
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9094
|
+
if (chatWithLoop) {
|
|
9095
|
+
const run = async (result, messageId) => {
|
|
9096
|
+
const formatted = await formatJSON(result);
|
|
9097
|
+
const finalResponse = `\`\`\`json
|
|
9098
|
+
${formatted}\`\`\``;
|
|
9099
|
+
setMessages((currentConversation) => {
|
|
9100
|
+
return currentConversation.map((message2) => {
|
|
9101
|
+
if (message2.metadata?.custom?.id === messageId) {
|
|
9102
|
+
return { ...message2, content: [{ type: "text", text: finalResponse }] };
|
|
9103
|
+
}
|
|
9104
|
+
return message2;
|
|
9105
|
+
});
|
|
9106
|
+
});
|
|
9107
|
+
};
|
|
9108
|
+
let isAgentNetworkOuterWorkflowCompleted = false;
|
|
9109
|
+
await network.loopStream(
|
|
9110
|
+
{
|
|
9111
|
+
message: input,
|
|
9112
|
+
threadId,
|
|
9113
|
+
resourceId: networkId,
|
|
9114
|
+
maxIterations
|
|
9115
|
+
},
|
|
9116
|
+
async (record) => {
|
|
9117
|
+
if (record.type === "step-start" && record.payload?.id === "Agent-Network-Outer-Workflow") {
|
|
9118
|
+
const id2 = uuid.v4();
|
|
9119
|
+
runIdRef.current = id2;
|
|
9120
|
+
setMessages((currentConversation) => {
|
|
9121
|
+
return [
|
|
9122
|
+
...currentConversation,
|
|
9123
|
+
{
|
|
9124
|
+
role: "assistant",
|
|
9125
|
+
metadata: {
|
|
9126
|
+
custom: {
|
|
9127
|
+
id: id2
|
|
9128
|
+
}
|
|
9129
|
+
},
|
|
9130
|
+
content: [
|
|
9131
|
+
{
|
|
9132
|
+
type: "text",
|
|
9133
|
+
text: "start"
|
|
9134
|
+
}
|
|
9135
|
+
]
|
|
9136
|
+
}
|
|
9137
|
+
];
|
|
9138
|
+
});
|
|
9139
|
+
} else if (runIdRef.current) {
|
|
9140
|
+
if (record.type === "tool-call-delta") {
|
|
9141
|
+
appendToLastMessage(record.argsTextDelta);
|
|
9142
|
+
} else if (record.type === "tool-call-streaming-start") {
|
|
9143
|
+
setMessages((msgs) => [...msgs, { role: "assistant", content: [{ type: "text", text: "" }] }]);
|
|
9144
|
+
setTimeout(() => {
|
|
9145
|
+
refreshThreadList?.();
|
|
9146
|
+
}, 500);
|
|
9147
|
+
return;
|
|
9148
|
+
} else {
|
|
9149
|
+
if (record.type === "step-finish" && record.payload?.id === "Agent-Network-Outer-Workflow") {
|
|
9150
|
+
if (!isAgentNetworkOuterWorkflowCompleted) {
|
|
9151
|
+
handleStep(runIdRef.current, { ...record, type: "finish" });
|
|
9152
|
+
runIdRef.current = void 0;
|
|
9153
|
+
}
|
|
9154
|
+
} else if (record.type === "step-result" && record.payload?.id === "workflow-step") {
|
|
9155
|
+
handleStep(runIdRef.current, record);
|
|
9156
|
+
const parsedResult = JSON.parse(record?.payload?.output?.result ?? "{}") ?? {};
|
|
9157
|
+
const runResult = parsedResult?.runResult ?? {};
|
|
9158
|
+
const formatedOutputId = uuid.v4();
|
|
9159
|
+
setMessages((msgs) => [
|
|
9160
|
+
...msgs,
|
|
9105
9161
|
{
|
|
9106
|
-
|
|
9107
|
-
|
|
9162
|
+
role: "assistant",
|
|
9163
|
+
content: [
|
|
9164
|
+
{
|
|
9165
|
+
type: "text",
|
|
9166
|
+
text: ""
|
|
9167
|
+
}
|
|
9168
|
+
],
|
|
9169
|
+
metadata: {
|
|
9170
|
+
custom: {
|
|
9171
|
+
id: formatedOutputId
|
|
9172
|
+
}
|
|
9173
|
+
}
|
|
9108
9174
|
}
|
|
9109
|
-
]
|
|
9175
|
+
]);
|
|
9176
|
+
run(JSON.stringify(runResult), formatedOutputId);
|
|
9177
|
+
} else if (record.payload?.id === "Agent-Network-Outer-Workflow" || record.payload?.id === "finish-step") {
|
|
9178
|
+
if (record.type === "step-result" && record.payload?.id === "Agent-Network-Outer-Workflow") {
|
|
9179
|
+
isAgentNetworkOuterWorkflowCompleted = record?.payload?.output?.isComplete;
|
|
9180
|
+
}
|
|
9181
|
+
} else {
|
|
9182
|
+
handleStep(runIdRef.current, record);
|
|
9110
9183
|
}
|
|
9111
|
-
|
|
9112
|
-
}
|
|
9184
|
+
}
|
|
9185
|
+
}
|
|
9186
|
+
if (record.type === "step-result" && record.payload?.id === "final-step") {
|
|
9187
|
+
setMessages((msgs) => [
|
|
9188
|
+
...msgs,
|
|
9189
|
+
{ role: "assistant", content: [{ type: "text", text: record.payload?.output?.result }] }
|
|
9190
|
+
]);
|
|
9191
|
+
}
|
|
9192
|
+
if (record.type === "step-finish" && record.payload?.id === "final-step") {
|
|
9193
|
+
runIdRef.current = void 0;
|
|
9194
|
+
}
|
|
9195
|
+
setTimeout(() => {
|
|
9196
|
+
refreshThreadList?.();
|
|
9197
|
+
}, 500);
|
|
9113
9198
|
}
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9199
|
+
);
|
|
9200
|
+
} else {
|
|
9201
|
+
await network.stream(
|
|
9202
|
+
{
|
|
9203
|
+
message: input,
|
|
9204
|
+
threadId,
|
|
9205
|
+
resourceId: networkId
|
|
9206
|
+
},
|
|
9207
|
+
(record) => {
|
|
9208
|
+
if (runIdRef.current) {
|
|
9209
|
+
if (record.type === "tool-call-delta") {
|
|
9210
|
+
appendToLastMessage(record.argsTextDelta);
|
|
9211
|
+
} else if (record.type === "tool-call-streaming-start") {
|
|
9212
|
+
setMessages((msgs) => [...msgs, { role: "assistant", content: [{ type: "text", text: "" }] }]);
|
|
9213
|
+
setTimeout(() => {
|
|
9214
|
+
refreshThreadList?.();
|
|
9215
|
+
}, 500);
|
|
9216
|
+
return;
|
|
9217
|
+
} else {
|
|
9218
|
+
handleStep(runIdRef.current, record);
|
|
9219
|
+
}
|
|
9220
|
+
} else if (record.type === "start") {
|
|
9221
|
+
const id2 = uuid.v4();
|
|
9222
|
+
runIdRef.current = id2;
|
|
9223
|
+
setMessages((currentConversation) => {
|
|
9224
|
+
return [
|
|
9225
|
+
...currentConversation,
|
|
9226
|
+
{
|
|
9227
|
+
role: "assistant",
|
|
9228
|
+
metadata: {
|
|
9229
|
+
custom: {
|
|
9230
|
+
id: id2
|
|
9231
|
+
}
|
|
9232
|
+
},
|
|
9233
|
+
content: [
|
|
9234
|
+
{
|
|
9235
|
+
type: "text",
|
|
9236
|
+
text: "start"
|
|
9237
|
+
}
|
|
9238
|
+
]
|
|
9239
|
+
}
|
|
9240
|
+
];
|
|
9241
|
+
});
|
|
9242
|
+
}
|
|
9243
|
+
setTimeout(() => {
|
|
9244
|
+
refreshThreadList?.();
|
|
9245
|
+
}, 500);
|
|
9246
|
+
}
|
|
9247
|
+
);
|
|
9248
|
+
}
|
|
9119
9249
|
setIsRunning(false);
|
|
9120
9250
|
} catch (error) {
|
|
9121
9251
|
console.error("Error occurred in VNextMastraNetworkRuntimeProvider", error);
|
|
@@ -9143,7 +9273,7 @@ const VNextNetworkChat = ({
|
|
|
9143
9273
|
memory,
|
|
9144
9274
|
refreshThreadList
|
|
9145
9275
|
}) => {
|
|
9146
|
-
return /* @__PURE__ */ jsxRuntime.jsx(MessagesProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(VNextNetworkChatProvider, {
|
|
9276
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MessagesProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(VNextNetworkChatProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9147
9277
|
VNextMastraNetworkRuntimeProvider,
|
|
9148
9278
|
{
|
|
9149
9279
|
networkId,
|