@mastra/playground-ui 5.0.2 → 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.es.js CHANGED
@@ -6711,20 +6711,27 @@ const getStepNodeAndEdge = ({
6711
6711
  yIndex,
6712
6712
  prevNodeIds,
6713
6713
  nextStepFlow,
6714
- condition
6714
+ condition,
6715
+ allPrevNodeIds
6715
6716
  }) => {
6716
6717
  let nextNodeIds = [];
6717
6718
  if (nextStepFlow?.type === "step" || nextStepFlow?.type === "foreach" || nextStepFlow?.type === "loop") {
6718
- nextNodeIds = [nextStepFlow?.step.id];
6719
+ const nextStepId = allPrevNodeIds?.includes(nextStepFlow.step.id) ? `${nextStepFlow.step.id}-${yIndex + 1}` : nextStepFlow.step.id;
6720
+ nextNodeIds = [nextStepId];
6719
6721
  }
6720
6722
  if (nextStepFlow?.type === "parallel") {
6721
- nextNodeIds = nextStepFlow?.steps.map((step) => step.step.id) || [];
6723
+ nextNodeIds = nextStepFlow?.steps.map((step) => {
6724
+ const stepId = step.step.id;
6725
+ const nextStepId = allPrevNodeIds?.includes(stepId) ? `${stepId}-${yIndex + 1}` : stepId;
6726
+ return nextStepId;
6727
+ }) || [];
6722
6728
  }
6723
6729
  if (nextStepFlow?.type === "conditional") {
6724
6730
  nextNodeIds = nextStepFlow?.serializedConditions.map((cond) => cond.id) || [];
6725
6731
  }
6726
6732
  if (stepFlow.type === "step" || stepFlow.type === "foreach") {
6727
6733
  const hasGraph = stepFlow.step.component === "WORKFLOW";
6734
+ const nodeId = allPrevNodeIds?.includes(stepFlow.step.id) ? `${stepFlow.step.id}-${yIndex}` : stepFlow.step.id;
6728
6735
  const nodes = [
6729
6736
  ...condition ? [
6730
6737
  {
@@ -6741,7 +6748,7 @@ const getStepNodeAndEdge = ({
6741
6748
  }
6742
6749
  ] : [],
6743
6750
  {
6744
- id: stepFlow.step.id,
6751
+ id: nodeId,
6745
6752
  position: { x: xIndex * 300, y: (yIndex + (condition ? 1 : 0)) * 100 },
6746
6753
  type: hasGraph ? "nested-node" : "default-node",
6747
6754
  data: {
@@ -6749,7 +6756,7 @@ const getStepNodeAndEdge = ({
6749
6756
  description: stepFlow.step.description,
6750
6757
  withoutTopHandle: condition ? false : !prevNodeIds.length,
6751
6758
  withoutBottomHandle: !nextNodeIds.length,
6752
- stepGraph: hasGraph ? stepFlow.step.stepFlow : void 0
6759
+ stepGraph: hasGraph ? stepFlow.step.serializedStepFlow : void 0
6753
6760
  }
6754
6761
  }
6755
6762
  ];
@@ -6762,25 +6769,25 @@ const getStepNodeAndEdge = ({
6762
6769
  ...defaultEdgeOptions
6763
6770
  })),
6764
6771
  {
6765
- id: `e${condition.id}-${stepFlow.step.id}`,
6772
+ id: `e${condition.id}-${nodeId}`,
6766
6773
  source: condition.id,
6767
- target: stepFlow.step.id,
6774
+ target: nodeId,
6768
6775
  ...defaultEdgeOptions
6769
6776
  }
6770
6777
  ] : prevNodeIds.map((prevNodeId) => ({
6771
- id: `e${prevNodeId}-${stepFlow.step.id}`,
6778
+ id: `e${prevNodeId}-${nodeId}`,
6772
6779
  source: prevNodeId,
6773
- target: stepFlow.step.id,
6780
+ target: nodeId,
6774
6781
  ...defaultEdgeOptions
6775
6782
  })),
6776
6783
  ...!nextNodeIds.length ? [] : nextNodeIds.map((nextNodeId) => ({
6777
- id: `e${stepFlow.step.id}-${nextNodeId}`,
6778
- source: stepFlow.step.id,
6784
+ id: `e${nodeId}-${nextNodeId}`,
6785
+ source: nodeId,
6779
6786
  target: nextNodeId,
6780
6787
  ...defaultEdgeOptions
6781
6788
  }))
6782
6789
  ];
6783
- return { nodes, edges, nextPrevNodeIds: [stepFlow.step.id] };
6790
+ return { nodes, edges, nextPrevNodeIds: [nodeId] };
6784
6791
  }
6785
6792
  if (stepFlow.type === "loop") {
6786
6793
  const { step: _step, serializedCondition, loopType } = stepFlow;
@@ -6795,7 +6802,7 @@ const getStepNodeAndEdge = ({
6795
6802
  description: _step.description,
6796
6803
  withoutTopHandle: !prevNodeIds.length,
6797
6804
  withoutBottomHandle: false,
6798
- stepGraph: hasGraph ? _step.stepFlow : void 0
6805
+ stepGraph: hasGraph ? _step.serializedStepFlow : void 0
6799
6806
  }
6800
6807
  },
6801
6808
  {
@@ -6842,7 +6849,8 @@ const getStepNodeAndEdge = ({
6842
6849
  xIndex: index,
6843
6850
  yIndex,
6844
6851
  prevNodeIds,
6845
- nextStepFlow
6852
+ nextStepFlow,
6853
+ allPrevNodeIds
6846
6854
  });
6847
6855
  nodes.push(..._nodes);
6848
6856
  edges.push(..._edges);
@@ -6859,12 +6867,17 @@ const getStepNodeAndEdge = ({
6859
6867
  yIndex,
6860
6868
  prevNodeIds,
6861
6869
  nextStepFlow,
6862
- condition: stepFlow.serializedConditions[index]
6870
+ condition: stepFlow.serializedConditions[index],
6871
+ allPrevNodeIds
6863
6872
  });
6864
6873
  nodes.push(..._nodes);
6865
6874
  edges.push(..._edges);
6866
6875
  });
6867
- return { nodes, edges, nextPrevNodeIds: nodes.map((node) => node.id) };
6876
+ return {
6877
+ nodes,
6878
+ edges,
6879
+ nextPrevNodeIds: nodes.filter(({ type }) => type !== "condition-node").map((node) => node.id)
6880
+ };
6868
6881
  }
6869
6882
  return { nodes: [], edges: [], nextPrevNodeIds: [] };
6870
6883
  };
@@ -6880,6 +6893,7 @@ const constructVNextNodesAndEdges = ({
6880
6893
  let nodes = [];
6881
6894
  let edges = [];
6882
6895
  let prevNodeIds = [];
6896
+ let allPrevNodeIds = [];
6883
6897
  for (let index = 0; index < stepGraph.length; index++) {
6884
6898
  const {
6885
6899
  nodes: _nodes,
@@ -6890,11 +6904,13 @@ const constructVNextNodesAndEdges = ({
6890
6904
  xIndex: index,
6891
6905
  yIndex: index,
6892
6906
  prevNodeIds,
6893
- nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1]
6907
+ nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1],
6908
+ allPrevNodeIds
6894
6909
  });
6895
6910
  nodes.push(..._nodes);
6896
6911
  edges.push(..._edges);
6897
6912
  prevNodeIds = nextPrevNodeIds;
6913
+ allPrevNodeIds.push(...prevNodeIds);
6898
6914
  }
6899
6915
  const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements(nodes, edges);
6900
6916
  return { nodes: layoutedNodes, edges: layoutedEdges };
@@ -7427,6 +7443,13 @@ const StringField = ({ inputProps, error, field, id }) => {
7427
7443
 
7428
7444
  const NumberField = ({ inputProps, error, field, id }) => {
7429
7445
  const { key, ...props } = inputProps;
7446
+ useEffect(() => {
7447
+ if (field.default !== void 0) {
7448
+ props.onChange({
7449
+ target: { value: Number(field.default), name: inputProps.name }
7450
+ });
7451
+ }
7452
+ }, [field.default]);
7430
7453
  return /* @__PURE__ */ jsx(
7431
7454
  Input,
7432
7455
  {
@@ -7434,7 +7457,7 @@ const NumberField = ({ inputProps, error, field, id }) => {
7434
7457
  type: "number",
7435
7458
  className: error ? "border-destructive" : "",
7436
7459
  ...props,
7437
- defaultValue: field.default,
7460
+ defaultValue: field.default !== void 0 ? Number(field.default) : void 0,
7438
7461
  onChange: (e) => {
7439
7462
  const value = e.target.value;
7440
7463
  if (value !== "" && !isNaN(Number(value))) {
@@ -8334,7 +8357,8 @@ function VNextWorkflowNestedGraph({ stepGraph, open }) {
8334
8357
  "default-node": WorkflowDefaultNode,
8335
8358
  "condition-node": WorkflowConditionNode,
8336
8359
  "after-node": WorkflowAfterNode,
8337
- "loop-result-node": WorkflowLoopResultNode
8360
+ "loop-result-node": WorkflowLoopResultNode,
8361
+ "nested-node": VNextWorkflowNestedNode
8338
8362
  };
8339
8363
  useEffect(() => {
8340
8364
  if (open) {
@@ -8366,17 +8390,40 @@ const VNextWorkflowNestedGraphContext = createContext(
8366
8390
  );
8367
8391
  function VNextWorkflowNestedGraphProvider({ children }) {
8368
8392
  const [stepGraph, setStepGraph] = useState(null);
8393
+ const [parentStepGraphList, setParentStepGraphList] = useState([]);
8369
8394
  const [openDialog, setOpenDialog] = useState(false);
8370
8395
  const [label, setLabel] = useState("");
8396
+ const [switching, setSwitching] = useState(false);
8371
8397
  const closeNestedGraph = () => {
8372
- setOpenDialog(false);
8373
- setStepGraph(null);
8374
- setLabel("");
8398
+ if (parentStepGraphList.length) {
8399
+ setSwitching(true);
8400
+ const lastStepGraph = parentStepGraphList[parentStepGraphList.length - 1];
8401
+ setStepGraph(lastStepGraph.stepGraph);
8402
+ setLabel(lastStepGraph.label);
8403
+ setParentStepGraphList(parentStepGraphList.slice(0, -1));
8404
+ setTimeout(() => {
8405
+ setSwitching(false);
8406
+ }, 500);
8407
+ } else {
8408
+ setOpenDialog(false);
8409
+ setStepGraph(null);
8410
+ setLabel("");
8411
+ }
8375
8412
  };
8376
- const showNestedGraph = ({ label: label2, stepGraph: stepGraph2 }) => {
8377
- setLabel(label2);
8378
- setStepGraph(stepGraph2);
8413
+ const showNestedGraph = ({
8414
+ label: newLabel,
8415
+ stepGraph: newStepGraph
8416
+ }) => {
8417
+ if (stepGraph) {
8418
+ setSwitching(true);
8419
+ setParentStepGraphList([...parentStepGraphList, { stepGraph, label }]);
8420
+ }
8421
+ setLabel(newLabel);
8422
+ setStepGraph(newStepGraph);
8379
8423
  setOpenDialog(true);
8424
+ setTimeout(() => {
8425
+ setSwitching(false);
8426
+ }, 500);
8380
8427
  };
8381
8428
  return /* @__PURE__ */ jsxs(
8382
8429
  VNextWorkflowNestedGraphContext.Provider,
@@ -8395,7 +8442,7 @@ function VNextWorkflowNestedGraphProvider({ children }) {
8395
8442
  " workflow"
8396
8443
  ] })
8397
8444
  ] }),
8398
- /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(VNextWorkflowNestedGraph, { stepGraph, open: openDialog }) })
8445
+ switching ? /* @__PURE__ */ jsx("div", { className: "w-full h-full flex items-center justify-center", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(VNextWorkflowNestedGraph, { stepGraph, open: openDialog }) })
8399
8446
  ] }) }) })
8400
8447
  ]
8401
8448
  }