@mastra/playground-ui 5.0.2-alpha.6 → 5.0.3-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 CHANGED
@@ -6743,20 +6743,27 @@ const getStepNodeAndEdge = ({
6743
6743
  yIndex,
6744
6744
  prevNodeIds,
6745
6745
  nextStepFlow,
6746
- condition
6746
+ condition,
6747
+ allPrevNodeIds
6747
6748
  }) => {
6748
6749
  let nextNodeIds = [];
6749
6750
  if (nextStepFlow?.type === "step" || nextStepFlow?.type === "foreach" || nextStepFlow?.type === "loop") {
6750
- nextNodeIds = [nextStepFlow?.step.id];
6751
+ const nextStepId = allPrevNodeIds?.includes(nextStepFlow.step.id) ? `${nextStepFlow.step.id}-${yIndex + 1}` : nextStepFlow.step.id;
6752
+ nextNodeIds = [nextStepId];
6751
6753
  }
6752
6754
  if (nextStepFlow?.type === "parallel") {
6753
- nextNodeIds = nextStepFlow?.steps.map((step) => step.step.id) || [];
6755
+ nextNodeIds = nextStepFlow?.steps.map((step) => {
6756
+ const stepId = step.step.id;
6757
+ const nextStepId = allPrevNodeIds?.includes(stepId) ? `${stepId}-${yIndex + 1}` : stepId;
6758
+ return nextStepId;
6759
+ }) || [];
6754
6760
  }
6755
6761
  if (nextStepFlow?.type === "conditional") {
6756
6762
  nextNodeIds = nextStepFlow?.serializedConditions.map((cond) => cond.id) || [];
6757
6763
  }
6758
6764
  if (stepFlow.type === "step" || stepFlow.type === "foreach") {
6759
6765
  const hasGraph = stepFlow.step.component === "WORKFLOW";
6766
+ const nodeId = allPrevNodeIds?.includes(stepFlow.step.id) ? `${stepFlow.step.id}-${yIndex}` : stepFlow.step.id;
6760
6767
  const nodes = [
6761
6768
  ...condition ? [
6762
6769
  {
@@ -6773,7 +6780,7 @@ const getStepNodeAndEdge = ({
6773
6780
  }
6774
6781
  ] : [],
6775
6782
  {
6776
- id: stepFlow.step.id,
6783
+ id: nodeId,
6777
6784
  position: { x: xIndex * 300, y: (yIndex + (condition ? 1 : 0)) * 100 },
6778
6785
  type: hasGraph ? "nested-node" : "default-node",
6779
6786
  data: {
@@ -6781,7 +6788,7 @@ const getStepNodeAndEdge = ({
6781
6788
  description: stepFlow.step.description,
6782
6789
  withoutTopHandle: condition ? false : !prevNodeIds.length,
6783
6790
  withoutBottomHandle: !nextNodeIds.length,
6784
- stepGraph: hasGraph ? stepFlow.step.stepFlow : void 0
6791
+ stepGraph: hasGraph ? stepFlow.step.serializedStepFlow : void 0
6785
6792
  }
6786
6793
  }
6787
6794
  ];
@@ -6794,25 +6801,25 @@ const getStepNodeAndEdge = ({
6794
6801
  ...defaultEdgeOptions
6795
6802
  })),
6796
6803
  {
6797
- id: `e${condition.id}-${stepFlow.step.id}`,
6804
+ id: `e${condition.id}-${nodeId}`,
6798
6805
  source: condition.id,
6799
- target: stepFlow.step.id,
6806
+ target: nodeId,
6800
6807
  ...defaultEdgeOptions
6801
6808
  }
6802
6809
  ] : prevNodeIds.map((prevNodeId) => ({
6803
- id: `e${prevNodeId}-${stepFlow.step.id}`,
6810
+ id: `e${prevNodeId}-${nodeId}`,
6804
6811
  source: prevNodeId,
6805
- target: stepFlow.step.id,
6812
+ target: nodeId,
6806
6813
  ...defaultEdgeOptions
6807
6814
  })),
6808
6815
  ...!nextNodeIds.length ? [] : nextNodeIds.map((nextNodeId) => ({
6809
- id: `e${stepFlow.step.id}-${nextNodeId}`,
6810
- source: stepFlow.step.id,
6816
+ id: `e${nodeId}-${nextNodeId}`,
6817
+ source: nodeId,
6811
6818
  target: nextNodeId,
6812
6819
  ...defaultEdgeOptions
6813
6820
  }))
6814
6821
  ];
6815
- return { nodes, edges, nextPrevNodeIds: [stepFlow.step.id] };
6822
+ return { nodes, edges, nextPrevNodeIds: [nodeId] };
6816
6823
  }
6817
6824
  if (stepFlow.type === "loop") {
6818
6825
  const { step: _step, serializedCondition, loopType } = stepFlow;
@@ -6827,7 +6834,7 @@ const getStepNodeAndEdge = ({
6827
6834
  description: _step.description,
6828
6835
  withoutTopHandle: !prevNodeIds.length,
6829
6836
  withoutBottomHandle: false,
6830
- stepGraph: hasGraph ? _step.stepFlow : void 0
6837
+ stepGraph: hasGraph ? _step.serializedStepFlow : void 0
6831
6838
  }
6832
6839
  },
6833
6840
  {
@@ -6874,7 +6881,8 @@ const getStepNodeAndEdge = ({
6874
6881
  xIndex: index,
6875
6882
  yIndex,
6876
6883
  prevNodeIds,
6877
- nextStepFlow
6884
+ nextStepFlow,
6885
+ allPrevNodeIds
6878
6886
  });
6879
6887
  nodes.push(..._nodes);
6880
6888
  edges.push(..._edges);
@@ -6891,12 +6899,17 @@ const getStepNodeAndEdge = ({
6891
6899
  yIndex,
6892
6900
  prevNodeIds,
6893
6901
  nextStepFlow,
6894
- condition: stepFlow.serializedConditions[index]
6902
+ condition: stepFlow.serializedConditions[index],
6903
+ allPrevNodeIds
6895
6904
  });
6896
6905
  nodes.push(..._nodes);
6897
6906
  edges.push(..._edges);
6898
6907
  });
6899
- return { nodes, edges, nextPrevNodeIds: nodes.map((node) => node.id) };
6908
+ return {
6909
+ nodes,
6910
+ edges,
6911
+ nextPrevNodeIds: nodes.filter(({ type }) => type !== "condition-node").map((node) => node.id)
6912
+ };
6900
6913
  }
6901
6914
  return { nodes: [], edges: [], nextPrevNodeIds: [] };
6902
6915
  };
@@ -6912,6 +6925,7 @@ const constructVNextNodesAndEdges = ({
6912
6925
  let nodes = [];
6913
6926
  let edges = [];
6914
6927
  let prevNodeIds = [];
6928
+ let allPrevNodeIds = [];
6915
6929
  for (let index = 0; index < stepGraph.length; index++) {
6916
6930
  const {
6917
6931
  nodes: _nodes,
@@ -6922,11 +6936,13 @@ const constructVNextNodesAndEdges = ({
6922
6936
  xIndex: index,
6923
6937
  yIndex: index,
6924
6938
  prevNodeIds,
6925
- nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1]
6939
+ nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1],
6940
+ allPrevNodeIds
6926
6941
  });
6927
6942
  nodes.push(..._nodes);
6928
6943
  edges.push(..._edges);
6929
6944
  prevNodeIds = nextPrevNodeIds;
6945
+ allPrevNodeIds.push(...prevNodeIds);
6930
6946
  }
6931
6947
  const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements(nodes, edges);
6932
6948
  return { nodes: layoutedNodes, edges: layoutedEdges };
@@ -7459,6 +7475,13 @@ const StringField = ({ inputProps, error, field, id }) => {
7459
7475
 
7460
7476
  const NumberField = ({ inputProps, error, field, id }) => {
7461
7477
  const { key, ...props } = inputProps;
7478
+ React.useEffect(() => {
7479
+ if (field.default !== void 0) {
7480
+ props.onChange({
7481
+ target: { value: Number(field.default), name: inputProps.name }
7482
+ });
7483
+ }
7484
+ }, [field.default]);
7462
7485
  return /* @__PURE__ */ jsxRuntime.jsx(
7463
7486
  Input,
7464
7487
  {
@@ -7466,7 +7489,7 @@ const NumberField = ({ inputProps, error, field, id }) => {
7466
7489
  type: "number",
7467
7490
  className: error ? "border-destructive" : "",
7468
7491
  ...props,
7469
- defaultValue: field.default,
7492
+ defaultValue: field.default !== void 0 ? Number(field.default) : void 0,
7470
7493
  onChange: (e) => {
7471
7494
  const value = e.target.value;
7472
7495
  if (value !== "" && !isNaN(Number(value))) {
@@ -8366,7 +8389,8 @@ function VNextWorkflowNestedGraph({ stepGraph, open }) {
8366
8389
  "default-node": WorkflowDefaultNode,
8367
8390
  "condition-node": WorkflowConditionNode,
8368
8391
  "after-node": WorkflowAfterNode,
8369
- "loop-result-node": WorkflowLoopResultNode
8392
+ "loop-result-node": WorkflowLoopResultNode,
8393
+ "nested-node": VNextWorkflowNestedNode
8370
8394
  };
8371
8395
  React.useEffect(() => {
8372
8396
  if (open) {
@@ -8398,17 +8422,40 @@ const VNextWorkflowNestedGraphContext = React.createContext(
8398
8422
  );
8399
8423
  function VNextWorkflowNestedGraphProvider({ children }) {
8400
8424
  const [stepGraph, setStepGraph] = React.useState(null);
8425
+ const [parentStepGraphList, setParentStepGraphList] = React.useState([]);
8401
8426
  const [openDialog, setOpenDialog] = React.useState(false);
8402
8427
  const [label, setLabel] = React.useState("");
8428
+ const [switching, setSwitching] = React.useState(false);
8403
8429
  const closeNestedGraph = () => {
8404
- setOpenDialog(false);
8405
- setStepGraph(null);
8406
- setLabel("");
8430
+ if (parentStepGraphList.length) {
8431
+ setSwitching(true);
8432
+ const lastStepGraph = parentStepGraphList[parentStepGraphList.length - 1];
8433
+ setStepGraph(lastStepGraph.stepGraph);
8434
+ setLabel(lastStepGraph.label);
8435
+ setParentStepGraphList(parentStepGraphList.slice(0, -1));
8436
+ setTimeout(() => {
8437
+ setSwitching(false);
8438
+ }, 500);
8439
+ } else {
8440
+ setOpenDialog(false);
8441
+ setStepGraph(null);
8442
+ setLabel("");
8443
+ }
8407
8444
  };
8408
- const showNestedGraph = ({ label: label2, stepGraph: stepGraph2 }) => {
8409
- setLabel(label2);
8410
- setStepGraph(stepGraph2);
8445
+ const showNestedGraph = ({
8446
+ label: newLabel,
8447
+ stepGraph: newStepGraph
8448
+ }) => {
8449
+ if (stepGraph) {
8450
+ setSwitching(true);
8451
+ setParentStepGraphList([...parentStepGraphList, { stepGraph, label }]);
8452
+ }
8453
+ setLabel(newLabel);
8454
+ setStepGraph(newStepGraph);
8411
8455
  setOpenDialog(true);
8456
+ setTimeout(() => {
8457
+ setSwitching(false);
8458
+ }, 500);
8412
8459
  };
8413
8460
  return /* @__PURE__ */ jsxRuntime.jsxs(
8414
8461
  VNextWorkflowNestedGraphContext.Provider,
@@ -8427,7 +8474,7 @@ function VNextWorkflowNestedGraphProvider({ children }) {
8427
8474
  " workflow"
8428
8475
  ] })
8429
8476
  ] }),
8430
- /* @__PURE__ */ jsxRuntime.jsx(react$2.ReactFlowProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(VNextWorkflowNestedGraph, { stepGraph, open: openDialog }) })
8477
+ switching ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full h-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(Spinner, {}) }) : /* @__PURE__ */ jsxRuntime.jsx(react$2.ReactFlowProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(VNextWorkflowNestedGraph, { stepGraph, open: openDialog }) })
8431
8478
  ] }) }) })
8432
8479
  ]
8433
8480
  }