@mastra/playground-ui 5.0.2 → 5.0.3-alpha.1

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
@@ -4067,13 +4067,16 @@ function MastraRuntimeProvider({
4067
4067
  if (message?.toolInvocations?.length > 0) {
4068
4068
  return {
4069
4069
  ...message,
4070
- content: message.toolInvocations.map((toolInvocation) => ({
4071
- type: "tool-call",
4072
- toolCallId: toolInvocation?.toolCallId,
4073
- toolName: toolInvocation?.toolName,
4074
- args: toolInvocation?.args,
4075
- result: toolInvocation?.result
4076
- }))
4070
+ content: [
4071
+ ...typeof message.content === "string" ? [{ type: "text", text: message.content }] : [],
4072
+ ...message.toolInvocations.map((toolInvocation) => ({
4073
+ type: "tool-call",
4074
+ toolCallId: toolInvocation?.toolCallId,
4075
+ toolName: toolInvocation?.toolName,
4076
+ args: toolInvocation?.args,
4077
+ result: toolInvocation?.result
4078
+ }))
4079
+ ]
4077
4080
  };
4078
4081
  }
4079
4082
  return message;
@@ -4188,6 +4191,13 @@ function MastraRuntimeProvider({
4188
4191
  };
4189
4192
  if (!assistantMessageAdded) {
4190
4193
  assistantMessageAdded = true;
4194
+ if (assistantToolCallAddedForUpdater) {
4195
+ assistantToolCallAddedForUpdater = false;
4196
+ }
4197
+ return [...currentConversation, message2];
4198
+ }
4199
+ if (assistantToolCallAddedForUpdater) {
4200
+ assistantToolCallAddedForUpdater = false;
4191
4201
  return [...currentConversation, message2];
4192
4202
  }
4193
4203
  return [...currentConversation.slice(0, -1), message2];
@@ -4215,22 +4225,18 @@ function MastraRuntimeProvider({
4215
4225
  if (!response.body) {
4216
4226
  throw new Error("No response body");
4217
4227
  }
4218
- const parts = [];
4219
4228
  let content = "";
4220
- let currentTextPart = null;
4221
4229
  let assistantMessageAdded = false;
4230
+ let assistantToolCallAddedForUpdater = false;
4231
+ let assistantToolCallAddedForContent = false;
4222
4232
  await response.processDataStream({
4223
4233
  onTextPart(value) {
4224
- if (currentTextPart == null) {
4225
- currentTextPart = {
4226
- type: "text",
4227
- text: value
4228
- };
4229
- parts.push(currentTextPart);
4234
+ if (assistantToolCallAddedForContent) {
4235
+ assistantToolCallAddedForContent = false;
4236
+ content = value;
4230
4237
  } else {
4231
- currentTextPart.text += value;
4238
+ content += value;
4232
4239
  }
4233
- content += value;
4234
4240
  updater();
4235
4241
  },
4236
4242
  async onToolCallPart(value) {
@@ -4257,6 +4263,8 @@ function MastraRuntimeProvider({
4257
4263
  }
4258
4264
  ]
4259
4265
  };
4266
+ assistantToolCallAddedForUpdater = true;
4267
+ assistantToolCallAddedForContent = true;
4260
4268
  return [...currentConversation.slice(0, -1), updatedMessage];
4261
4269
  }
4262
4270
  const newMessage = {
@@ -4271,6 +4279,8 @@ function MastraRuntimeProvider({
4271
4279
  }
4272
4280
  ]
4273
4281
  };
4282
+ assistantToolCallAddedForUpdater = true;
4283
+ assistantToolCallAddedForContent = true;
4274
4284
  return [...currentConversation, newMessage];
4275
4285
  });
4276
4286
  },
@@ -6743,20 +6753,27 @@ const getStepNodeAndEdge = ({
6743
6753
  yIndex,
6744
6754
  prevNodeIds,
6745
6755
  nextStepFlow,
6746
- condition
6756
+ condition,
6757
+ allPrevNodeIds
6747
6758
  }) => {
6748
6759
  let nextNodeIds = [];
6749
6760
  if (nextStepFlow?.type === "step" || nextStepFlow?.type === "foreach" || nextStepFlow?.type === "loop") {
6750
- nextNodeIds = [nextStepFlow?.step.id];
6761
+ const nextStepId = allPrevNodeIds?.includes(nextStepFlow.step.id) ? `${nextStepFlow.step.id}-${yIndex + 1}` : nextStepFlow.step.id;
6762
+ nextNodeIds = [nextStepId];
6751
6763
  }
6752
6764
  if (nextStepFlow?.type === "parallel") {
6753
- nextNodeIds = nextStepFlow?.steps.map((step) => step.step.id) || [];
6765
+ nextNodeIds = nextStepFlow?.steps.map((step) => {
6766
+ const stepId = step.step.id;
6767
+ const nextStepId = allPrevNodeIds?.includes(stepId) ? `${stepId}-${yIndex + 1}` : stepId;
6768
+ return nextStepId;
6769
+ }) || [];
6754
6770
  }
6755
6771
  if (nextStepFlow?.type === "conditional") {
6756
6772
  nextNodeIds = nextStepFlow?.serializedConditions.map((cond) => cond.id) || [];
6757
6773
  }
6758
6774
  if (stepFlow.type === "step" || stepFlow.type === "foreach") {
6759
6775
  const hasGraph = stepFlow.step.component === "WORKFLOW";
6776
+ const nodeId = allPrevNodeIds?.includes(stepFlow.step.id) ? `${stepFlow.step.id}-${yIndex}` : stepFlow.step.id;
6760
6777
  const nodes = [
6761
6778
  ...condition ? [
6762
6779
  {
@@ -6773,7 +6790,7 @@ const getStepNodeAndEdge = ({
6773
6790
  }
6774
6791
  ] : [],
6775
6792
  {
6776
- id: stepFlow.step.id,
6793
+ id: nodeId,
6777
6794
  position: { x: xIndex * 300, y: (yIndex + (condition ? 1 : 0)) * 100 },
6778
6795
  type: hasGraph ? "nested-node" : "default-node",
6779
6796
  data: {
@@ -6781,7 +6798,7 @@ const getStepNodeAndEdge = ({
6781
6798
  description: stepFlow.step.description,
6782
6799
  withoutTopHandle: condition ? false : !prevNodeIds.length,
6783
6800
  withoutBottomHandle: !nextNodeIds.length,
6784
- stepGraph: hasGraph ? stepFlow.step.stepFlow : void 0
6801
+ stepGraph: hasGraph ? stepFlow.step.serializedStepFlow : void 0
6785
6802
  }
6786
6803
  }
6787
6804
  ];
@@ -6794,25 +6811,25 @@ const getStepNodeAndEdge = ({
6794
6811
  ...defaultEdgeOptions
6795
6812
  })),
6796
6813
  {
6797
- id: `e${condition.id}-${stepFlow.step.id}`,
6814
+ id: `e${condition.id}-${nodeId}`,
6798
6815
  source: condition.id,
6799
- target: stepFlow.step.id,
6816
+ target: nodeId,
6800
6817
  ...defaultEdgeOptions
6801
6818
  }
6802
6819
  ] : prevNodeIds.map((prevNodeId) => ({
6803
- id: `e${prevNodeId}-${stepFlow.step.id}`,
6820
+ id: `e${prevNodeId}-${nodeId}`,
6804
6821
  source: prevNodeId,
6805
- target: stepFlow.step.id,
6822
+ target: nodeId,
6806
6823
  ...defaultEdgeOptions
6807
6824
  })),
6808
6825
  ...!nextNodeIds.length ? [] : nextNodeIds.map((nextNodeId) => ({
6809
- id: `e${stepFlow.step.id}-${nextNodeId}`,
6810
- source: stepFlow.step.id,
6826
+ id: `e${nodeId}-${nextNodeId}`,
6827
+ source: nodeId,
6811
6828
  target: nextNodeId,
6812
6829
  ...defaultEdgeOptions
6813
6830
  }))
6814
6831
  ];
6815
- return { nodes, edges, nextPrevNodeIds: [stepFlow.step.id] };
6832
+ return { nodes, edges, nextPrevNodeIds: [nodeId] };
6816
6833
  }
6817
6834
  if (stepFlow.type === "loop") {
6818
6835
  const { step: _step, serializedCondition, loopType } = stepFlow;
@@ -6827,7 +6844,7 @@ const getStepNodeAndEdge = ({
6827
6844
  description: _step.description,
6828
6845
  withoutTopHandle: !prevNodeIds.length,
6829
6846
  withoutBottomHandle: false,
6830
- stepGraph: hasGraph ? _step.stepFlow : void 0
6847
+ stepGraph: hasGraph ? _step.serializedStepFlow : void 0
6831
6848
  }
6832
6849
  },
6833
6850
  {
@@ -6874,7 +6891,8 @@ const getStepNodeAndEdge = ({
6874
6891
  xIndex: index,
6875
6892
  yIndex,
6876
6893
  prevNodeIds,
6877
- nextStepFlow
6894
+ nextStepFlow,
6895
+ allPrevNodeIds
6878
6896
  });
6879
6897
  nodes.push(..._nodes);
6880
6898
  edges.push(..._edges);
@@ -6891,12 +6909,17 @@ const getStepNodeAndEdge = ({
6891
6909
  yIndex,
6892
6910
  prevNodeIds,
6893
6911
  nextStepFlow,
6894
- condition: stepFlow.serializedConditions[index]
6912
+ condition: stepFlow.serializedConditions[index],
6913
+ allPrevNodeIds
6895
6914
  });
6896
6915
  nodes.push(..._nodes);
6897
6916
  edges.push(..._edges);
6898
6917
  });
6899
- return { nodes, edges, nextPrevNodeIds: nodes.map((node) => node.id) };
6918
+ return {
6919
+ nodes,
6920
+ edges,
6921
+ nextPrevNodeIds: nodes.filter(({ type }) => type !== "condition-node").map((node) => node.id)
6922
+ };
6900
6923
  }
6901
6924
  return { nodes: [], edges: [], nextPrevNodeIds: [] };
6902
6925
  };
@@ -6912,6 +6935,7 @@ const constructVNextNodesAndEdges = ({
6912
6935
  let nodes = [];
6913
6936
  let edges = [];
6914
6937
  let prevNodeIds = [];
6938
+ let allPrevNodeIds = [];
6915
6939
  for (let index = 0; index < stepGraph.length; index++) {
6916
6940
  const {
6917
6941
  nodes: _nodes,
@@ -6922,11 +6946,13 @@ const constructVNextNodesAndEdges = ({
6922
6946
  xIndex: index,
6923
6947
  yIndex: index,
6924
6948
  prevNodeIds,
6925
- nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1]
6949
+ nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1],
6950
+ allPrevNodeIds
6926
6951
  });
6927
6952
  nodes.push(..._nodes);
6928
6953
  edges.push(..._edges);
6929
6954
  prevNodeIds = nextPrevNodeIds;
6955
+ allPrevNodeIds.push(...prevNodeIds);
6930
6956
  }
6931
6957
  const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements(nodes, edges);
6932
6958
  return { nodes: layoutedNodes, edges: layoutedEdges };
@@ -7459,6 +7485,13 @@ const StringField = ({ inputProps, error, field, id }) => {
7459
7485
 
7460
7486
  const NumberField = ({ inputProps, error, field, id }) => {
7461
7487
  const { key, ...props } = inputProps;
7488
+ React.useEffect(() => {
7489
+ if (field.default !== void 0) {
7490
+ props.onChange({
7491
+ target: { value: Number(field.default), name: inputProps.name }
7492
+ });
7493
+ }
7494
+ }, [field.default]);
7462
7495
  return /* @__PURE__ */ jsxRuntime.jsx(
7463
7496
  Input,
7464
7497
  {
@@ -7466,7 +7499,7 @@ const NumberField = ({ inputProps, error, field, id }) => {
7466
7499
  type: "number",
7467
7500
  className: error ? "border-destructive" : "",
7468
7501
  ...props,
7469
- defaultValue: field.default,
7502
+ defaultValue: field.default !== void 0 ? Number(field.default) : void 0,
7470
7503
  onChange: (e) => {
7471
7504
  const value = e.target.value;
7472
7505
  if (value !== "" && !isNaN(Number(value))) {
@@ -8366,7 +8399,8 @@ function VNextWorkflowNestedGraph({ stepGraph, open }) {
8366
8399
  "default-node": WorkflowDefaultNode,
8367
8400
  "condition-node": WorkflowConditionNode,
8368
8401
  "after-node": WorkflowAfterNode,
8369
- "loop-result-node": WorkflowLoopResultNode
8402
+ "loop-result-node": WorkflowLoopResultNode,
8403
+ "nested-node": VNextWorkflowNestedNode
8370
8404
  };
8371
8405
  React.useEffect(() => {
8372
8406
  if (open) {
@@ -8398,17 +8432,40 @@ const VNextWorkflowNestedGraphContext = React.createContext(
8398
8432
  );
8399
8433
  function VNextWorkflowNestedGraphProvider({ children }) {
8400
8434
  const [stepGraph, setStepGraph] = React.useState(null);
8435
+ const [parentStepGraphList, setParentStepGraphList] = React.useState([]);
8401
8436
  const [openDialog, setOpenDialog] = React.useState(false);
8402
8437
  const [label, setLabel] = React.useState("");
8438
+ const [switching, setSwitching] = React.useState(false);
8403
8439
  const closeNestedGraph = () => {
8404
- setOpenDialog(false);
8405
- setStepGraph(null);
8406
- setLabel("");
8440
+ if (parentStepGraphList.length) {
8441
+ setSwitching(true);
8442
+ const lastStepGraph = parentStepGraphList[parentStepGraphList.length - 1];
8443
+ setStepGraph(lastStepGraph.stepGraph);
8444
+ setLabel(lastStepGraph.label);
8445
+ setParentStepGraphList(parentStepGraphList.slice(0, -1));
8446
+ setTimeout(() => {
8447
+ setSwitching(false);
8448
+ }, 500);
8449
+ } else {
8450
+ setOpenDialog(false);
8451
+ setStepGraph(null);
8452
+ setLabel("");
8453
+ }
8407
8454
  };
8408
- const showNestedGraph = ({ label: label2, stepGraph: stepGraph2 }) => {
8409
- setLabel(label2);
8410
- setStepGraph(stepGraph2);
8455
+ const showNestedGraph = ({
8456
+ label: newLabel,
8457
+ stepGraph: newStepGraph
8458
+ }) => {
8459
+ if (stepGraph) {
8460
+ setSwitching(true);
8461
+ setParentStepGraphList([...parentStepGraphList, { stepGraph, label }]);
8462
+ }
8463
+ setLabel(newLabel);
8464
+ setStepGraph(newStepGraph);
8411
8465
  setOpenDialog(true);
8466
+ setTimeout(() => {
8467
+ setSwitching(false);
8468
+ }, 500);
8412
8469
  };
8413
8470
  return /* @__PURE__ */ jsxRuntime.jsxs(
8414
8471
  VNextWorkflowNestedGraphContext.Provider,
@@ -8427,7 +8484,7 @@ function VNextWorkflowNestedGraphProvider({ children }) {
8427
8484
  " workflow"
8428
8485
  ] })
8429
8486
  ] }),
8430
- /* @__PURE__ */ jsxRuntime.jsx(react$2.ReactFlowProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(VNextWorkflowNestedGraph, { stepGraph, open: openDialog }) })
8487
+ 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
8488
  ] }) }) })
8432
8489
  ]
8433
8490
  }