@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.es.js CHANGED
@@ -4035,13 +4035,16 @@ function MastraRuntimeProvider({
4035
4035
  if (message?.toolInvocations?.length > 0) {
4036
4036
  return {
4037
4037
  ...message,
4038
- content: message.toolInvocations.map((toolInvocation) => ({
4039
- type: "tool-call",
4040
- toolCallId: toolInvocation?.toolCallId,
4041
- toolName: toolInvocation?.toolName,
4042
- args: toolInvocation?.args,
4043
- result: toolInvocation?.result
4044
- }))
4038
+ content: [
4039
+ ...typeof message.content === "string" ? [{ type: "text", text: message.content }] : [],
4040
+ ...message.toolInvocations.map((toolInvocation) => ({
4041
+ type: "tool-call",
4042
+ toolCallId: toolInvocation?.toolCallId,
4043
+ toolName: toolInvocation?.toolName,
4044
+ args: toolInvocation?.args,
4045
+ result: toolInvocation?.result
4046
+ }))
4047
+ ]
4045
4048
  };
4046
4049
  }
4047
4050
  return message;
@@ -4156,6 +4159,13 @@ function MastraRuntimeProvider({
4156
4159
  };
4157
4160
  if (!assistantMessageAdded) {
4158
4161
  assistantMessageAdded = true;
4162
+ if (assistantToolCallAddedForUpdater) {
4163
+ assistantToolCallAddedForUpdater = false;
4164
+ }
4165
+ return [...currentConversation, message2];
4166
+ }
4167
+ if (assistantToolCallAddedForUpdater) {
4168
+ assistantToolCallAddedForUpdater = false;
4159
4169
  return [...currentConversation, message2];
4160
4170
  }
4161
4171
  return [...currentConversation.slice(0, -1), message2];
@@ -4183,22 +4193,18 @@ function MastraRuntimeProvider({
4183
4193
  if (!response.body) {
4184
4194
  throw new Error("No response body");
4185
4195
  }
4186
- const parts = [];
4187
4196
  let content = "";
4188
- let currentTextPart = null;
4189
4197
  let assistantMessageAdded = false;
4198
+ let assistantToolCallAddedForUpdater = false;
4199
+ let assistantToolCallAddedForContent = false;
4190
4200
  await response.processDataStream({
4191
4201
  onTextPart(value) {
4192
- if (currentTextPart == null) {
4193
- currentTextPart = {
4194
- type: "text",
4195
- text: value
4196
- };
4197
- parts.push(currentTextPart);
4202
+ if (assistantToolCallAddedForContent) {
4203
+ assistantToolCallAddedForContent = false;
4204
+ content = value;
4198
4205
  } else {
4199
- currentTextPart.text += value;
4206
+ content += value;
4200
4207
  }
4201
- content += value;
4202
4208
  updater();
4203
4209
  },
4204
4210
  async onToolCallPart(value) {
@@ -4225,6 +4231,8 @@ function MastraRuntimeProvider({
4225
4231
  }
4226
4232
  ]
4227
4233
  };
4234
+ assistantToolCallAddedForUpdater = true;
4235
+ assistantToolCallAddedForContent = true;
4228
4236
  return [...currentConversation.slice(0, -1), updatedMessage];
4229
4237
  }
4230
4238
  const newMessage = {
@@ -4239,6 +4247,8 @@ function MastraRuntimeProvider({
4239
4247
  }
4240
4248
  ]
4241
4249
  };
4250
+ assistantToolCallAddedForUpdater = true;
4251
+ assistantToolCallAddedForContent = true;
4242
4252
  return [...currentConversation, newMessage];
4243
4253
  });
4244
4254
  },
@@ -6711,20 +6721,27 @@ const getStepNodeAndEdge = ({
6711
6721
  yIndex,
6712
6722
  prevNodeIds,
6713
6723
  nextStepFlow,
6714
- condition
6724
+ condition,
6725
+ allPrevNodeIds
6715
6726
  }) => {
6716
6727
  let nextNodeIds = [];
6717
6728
  if (nextStepFlow?.type === "step" || nextStepFlow?.type === "foreach" || nextStepFlow?.type === "loop") {
6718
- nextNodeIds = [nextStepFlow?.step.id];
6729
+ const nextStepId = allPrevNodeIds?.includes(nextStepFlow.step.id) ? `${nextStepFlow.step.id}-${yIndex + 1}` : nextStepFlow.step.id;
6730
+ nextNodeIds = [nextStepId];
6719
6731
  }
6720
6732
  if (nextStepFlow?.type === "parallel") {
6721
- nextNodeIds = nextStepFlow?.steps.map((step) => step.step.id) || [];
6733
+ nextNodeIds = nextStepFlow?.steps.map((step) => {
6734
+ const stepId = step.step.id;
6735
+ const nextStepId = allPrevNodeIds?.includes(stepId) ? `${stepId}-${yIndex + 1}` : stepId;
6736
+ return nextStepId;
6737
+ }) || [];
6722
6738
  }
6723
6739
  if (nextStepFlow?.type === "conditional") {
6724
6740
  nextNodeIds = nextStepFlow?.serializedConditions.map((cond) => cond.id) || [];
6725
6741
  }
6726
6742
  if (stepFlow.type === "step" || stepFlow.type === "foreach") {
6727
6743
  const hasGraph = stepFlow.step.component === "WORKFLOW";
6744
+ const nodeId = allPrevNodeIds?.includes(stepFlow.step.id) ? `${stepFlow.step.id}-${yIndex}` : stepFlow.step.id;
6728
6745
  const nodes = [
6729
6746
  ...condition ? [
6730
6747
  {
@@ -6741,7 +6758,7 @@ const getStepNodeAndEdge = ({
6741
6758
  }
6742
6759
  ] : [],
6743
6760
  {
6744
- id: stepFlow.step.id,
6761
+ id: nodeId,
6745
6762
  position: { x: xIndex * 300, y: (yIndex + (condition ? 1 : 0)) * 100 },
6746
6763
  type: hasGraph ? "nested-node" : "default-node",
6747
6764
  data: {
@@ -6749,7 +6766,7 @@ const getStepNodeAndEdge = ({
6749
6766
  description: stepFlow.step.description,
6750
6767
  withoutTopHandle: condition ? false : !prevNodeIds.length,
6751
6768
  withoutBottomHandle: !nextNodeIds.length,
6752
- stepGraph: hasGraph ? stepFlow.step.stepFlow : void 0
6769
+ stepGraph: hasGraph ? stepFlow.step.serializedStepFlow : void 0
6753
6770
  }
6754
6771
  }
6755
6772
  ];
@@ -6762,25 +6779,25 @@ const getStepNodeAndEdge = ({
6762
6779
  ...defaultEdgeOptions
6763
6780
  })),
6764
6781
  {
6765
- id: `e${condition.id}-${stepFlow.step.id}`,
6782
+ id: `e${condition.id}-${nodeId}`,
6766
6783
  source: condition.id,
6767
- target: stepFlow.step.id,
6784
+ target: nodeId,
6768
6785
  ...defaultEdgeOptions
6769
6786
  }
6770
6787
  ] : prevNodeIds.map((prevNodeId) => ({
6771
- id: `e${prevNodeId}-${stepFlow.step.id}`,
6788
+ id: `e${prevNodeId}-${nodeId}`,
6772
6789
  source: prevNodeId,
6773
- target: stepFlow.step.id,
6790
+ target: nodeId,
6774
6791
  ...defaultEdgeOptions
6775
6792
  })),
6776
6793
  ...!nextNodeIds.length ? [] : nextNodeIds.map((nextNodeId) => ({
6777
- id: `e${stepFlow.step.id}-${nextNodeId}`,
6778
- source: stepFlow.step.id,
6794
+ id: `e${nodeId}-${nextNodeId}`,
6795
+ source: nodeId,
6779
6796
  target: nextNodeId,
6780
6797
  ...defaultEdgeOptions
6781
6798
  }))
6782
6799
  ];
6783
- return { nodes, edges, nextPrevNodeIds: [stepFlow.step.id] };
6800
+ return { nodes, edges, nextPrevNodeIds: [nodeId] };
6784
6801
  }
6785
6802
  if (stepFlow.type === "loop") {
6786
6803
  const { step: _step, serializedCondition, loopType } = stepFlow;
@@ -6795,7 +6812,7 @@ const getStepNodeAndEdge = ({
6795
6812
  description: _step.description,
6796
6813
  withoutTopHandle: !prevNodeIds.length,
6797
6814
  withoutBottomHandle: false,
6798
- stepGraph: hasGraph ? _step.stepFlow : void 0
6815
+ stepGraph: hasGraph ? _step.serializedStepFlow : void 0
6799
6816
  }
6800
6817
  },
6801
6818
  {
@@ -6842,7 +6859,8 @@ const getStepNodeAndEdge = ({
6842
6859
  xIndex: index,
6843
6860
  yIndex,
6844
6861
  prevNodeIds,
6845
- nextStepFlow
6862
+ nextStepFlow,
6863
+ allPrevNodeIds
6846
6864
  });
6847
6865
  nodes.push(..._nodes);
6848
6866
  edges.push(..._edges);
@@ -6859,12 +6877,17 @@ const getStepNodeAndEdge = ({
6859
6877
  yIndex,
6860
6878
  prevNodeIds,
6861
6879
  nextStepFlow,
6862
- condition: stepFlow.serializedConditions[index]
6880
+ condition: stepFlow.serializedConditions[index],
6881
+ allPrevNodeIds
6863
6882
  });
6864
6883
  nodes.push(..._nodes);
6865
6884
  edges.push(..._edges);
6866
6885
  });
6867
- return { nodes, edges, nextPrevNodeIds: nodes.map((node) => node.id) };
6886
+ return {
6887
+ nodes,
6888
+ edges,
6889
+ nextPrevNodeIds: nodes.filter(({ type }) => type !== "condition-node").map((node) => node.id)
6890
+ };
6868
6891
  }
6869
6892
  return { nodes: [], edges: [], nextPrevNodeIds: [] };
6870
6893
  };
@@ -6880,6 +6903,7 @@ const constructVNextNodesAndEdges = ({
6880
6903
  let nodes = [];
6881
6904
  let edges = [];
6882
6905
  let prevNodeIds = [];
6906
+ let allPrevNodeIds = [];
6883
6907
  for (let index = 0; index < stepGraph.length; index++) {
6884
6908
  const {
6885
6909
  nodes: _nodes,
@@ -6890,11 +6914,13 @@ const constructVNextNodesAndEdges = ({
6890
6914
  xIndex: index,
6891
6915
  yIndex: index,
6892
6916
  prevNodeIds,
6893
- nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1]
6917
+ nextStepFlow: index === stepGraph.length - 1 ? void 0 : stepGraph[index + 1],
6918
+ allPrevNodeIds
6894
6919
  });
6895
6920
  nodes.push(..._nodes);
6896
6921
  edges.push(..._edges);
6897
6922
  prevNodeIds = nextPrevNodeIds;
6923
+ allPrevNodeIds.push(...prevNodeIds);
6898
6924
  }
6899
6925
  const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements(nodes, edges);
6900
6926
  return { nodes: layoutedNodes, edges: layoutedEdges };
@@ -7427,6 +7453,13 @@ const StringField = ({ inputProps, error, field, id }) => {
7427
7453
 
7428
7454
  const NumberField = ({ inputProps, error, field, id }) => {
7429
7455
  const { key, ...props } = inputProps;
7456
+ useEffect(() => {
7457
+ if (field.default !== void 0) {
7458
+ props.onChange({
7459
+ target: { value: Number(field.default), name: inputProps.name }
7460
+ });
7461
+ }
7462
+ }, [field.default]);
7430
7463
  return /* @__PURE__ */ jsx(
7431
7464
  Input,
7432
7465
  {
@@ -7434,7 +7467,7 @@ const NumberField = ({ inputProps, error, field, id }) => {
7434
7467
  type: "number",
7435
7468
  className: error ? "border-destructive" : "",
7436
7469
  ...props,
7437
- defaultValue: field.default,
7470
+ defaultValue: field.default !== void 0 ? Number(field.default) : void 0,
7438
7471
  onChange: (e) => {
7439
7472
  const value = e.target.value;
7440
7473
  if (value !== "" && !isNaN(Number(value))) {
@@ -8334,7 +8367,8 @@ function VNextWorkflowNestedGraph({ stepGraph, open }) {
8334
8367
  "default-node": WorkflowDefaultNode,
8335
8368
  "condition-node": WorkflowConditionNode,
8336
8369
  "after-node": WorkflowAfterNode,
8337
- "loop-result-node": WorkflowLoopResultNode
8370
+ "loop-result-node": WorkflowLoopResultNode,
8371
+ "nested-node": VNextWorkflowNestedNode
8338
8372
  };
8339
8373
  useEffect(() => {
8340
8374
  if (open) {
@@ -8366,17 +8400,40 @@ const VNextWorkflowNestedGraphContext = createContext(
8366
8400
  );
8367
8401
  function VNextWorkflowNestedGraphProvider({ children }) {
8368
8402
  const [stepGraph, setStepGraph] = useState(null);
8403
+ const [parentStepGraphList, setParentStepGraphList] = useState([]);
8369
8404
  const [openDialog, setOpenDialog] = useState(false);
8370
8405
  const [label, setLabel] = useState("");
8406
+ const [switching, setSwitching] = useState(false);
8371
8407
  const closeNestedGraph = () => {
8372
- setOpenDialog(false);
8373
- setStepGraph(null);
8374
- setLabel("");
8408
+ if (parentStepGraphList.length) {
8409
+ setSwitching(true);
8410
+ const lastStepGraph = parentStepGraphList[parentStepGraphList.length - 1];
8411
+ setStepGraph(lastStepGraph.stepGraph);
8412
+ setLabel(lastStepGraph.label);
8413
+ setParentStepGraphList(parentStepGraphList.slice(0, -1));
8414
+ setTimeout(() => {
8415
+ setSwitching(false);
8416
+ }, 500);
8417
+ } else {
8418
+ setOpenDialog(false);
8419
+ setStepGraph(null);
8420
+ setLabel("");
8421
+ }
8375
8422
  };
8376
- const showNestedGraph = ({ label: label2, stepGraph: stepGraph2 }) => {
8377
- setLabel(label2);
8378
- setStepGraph(stepGraph2);
8423
+ const showNestedGraph = ({
8424
+ label: newLabel,
8425
+ stepGraph: newStepGraph
8426
+ }) => {
8427
+ if (stepGraph) {
8428
+ setSwitching(true);
8429
+ setParentStepGraphList([...parentStepGraphList, { stepGraph, label }]);
8430
+ }
8431
+ setLabel(newLabel);
8432
+ setStepGraph(newStepGraph);
8379
8433
  setOpenDialog(true);
8434
+ setTimeout(() => {
8435
+ setSwitching(false);
8436
+ }, 500);
8380
8437
  };
8381
8438
  return /* @__PURE__ */ jsxs(
8382
8439
  VNextWorkflowNestedGraphContext.Provider,
@@ -8395,7 +8452,7 @@ function VNextWorkflowNestedGraphProvider({ children }) {
8395
8452
  " workflow"
8396
8453
  ] })
8397
8454
  ] }),
8398
- /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(VNextWorkflowNestedGraph, { stepGraph, open: openDialog }) })
8455
+ 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
8456
  ] }) }) })
8400
8457
  ]
8401
8458
  }