@mastra/playground-ui 5.1.6-alpha.3 → 5.1.6-alpha.5

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
@@ -30,7 +30,6 @@ import { C as Colors } from './colors-CBG_Mm7P.js';
30
30
  import { processDataStream } from '@ai-sdk/ui-utils';
31
31
  import Markdown from 'react-markdown';
32
32
  import { useDebouncedCallback } from 'use-debounce';
33
- import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/runtime-context';
34
33
  import { MarkerType, Handle, Position, useNodesState, useEdgesState, ReactFlow, Controls, MiniMap, Background, BackgroundVariant, ReactFlowProvider, useViewport, useReactFlow, Panel } from '@xyflow/react';
35
34
  import '@xyflow/react/dist/style.css';
36
35
  import Dagre from '@dagrejs/dagre';
@@ -6909,41 +6908,6 @@ function Skeleton({ className, ...props }) {
6909
6908
  return /* @__PURE__ */ jsx("div", { className: cn("animate-pulse rounded-md bg-muted/50", className), ...props });
6910
6909
  }
6911
6910
 
6912
- const sanitizeWorkflowWatchResult = (record) => {
6913
- const formattedResults = Object.entries(record.payload.workflowState.steps || {}).reduce(
6914
- (acc, [key, value]) => {
6915
- let output = value.status === "success" ? value.output : void 0;
6916
- if (output) {
6917
- output = Object.entries(output).reduce(
6918
- (_acc, [_key, _value]) => {
6919
- const val = _value;
6920
- _acc[_key] = val.type?.toLowerCase() === "buffer" ? { type: "Buffer", data: `[...buffered data]` } : val;
6921
- return _acc;
6922
- },
6923
- {}
6924
- );
6925
- }
6926
- acc[key] = { ...value, output };
6927
- return acc;
6928
- },
6929
- {}
6930
- );
6931
- const sanitizedRecord = {
6932
- ...record,
6933
- sanitizedOutput: record ? JSON.stringify(
6934
- {
6935
- ...record,
6936
- payload: {
6937
- ...record.payload,
6938
- workflowState: { ...record.payload.workflowState, steps: formattedResults }
6939
- }
6940
- },
6941
- null,
6942
- 2
6943
- ).slice(0, 5e4) : null
6944
- };
6945
- return sanitizedRecord;
6946
- };
6947
6911
  const useLegacyWorkflow = (workflowId) => {
6948
6912
  const [legacyWorkflow, setLegacyWorkflow] = useState(null);
6949
6913
  const [isLoading, setIsLoading] = useState(true);
@@ -7001,16 +6965,6 @@ const useExecuteWorkflow = () => {
7001
6965
  throw error;
7002
6966
  }
7003
6967
  };
7004
- const createWorkflowRun = async ({ workflowId, prevRunId }) => {
7005
- try {
7006
- const workflow = client.getWorkflow(workflowId);
7007
- const { runId: newRunId } = await workflow.createRun({ runId: prevRunId });
7008
- return { runId: newRunId };
7009
- } catch (error) {
7010
- console.error("Error creating workflow run:", error);
7011
- throw error;
7012
- }
7013
- };
7014
6968
  const startLegacyWorkflowRun = async ({
7015
6969
  workflowId,
7016
6970
  runId,
@@ -7024,56 +6978,14 @@ const useExecuteWorkflow = () => {
7024
6978
  throw error;
7025
6979
  }
7026
6980
  };
7027
- const startWorkflowRun = async ({
7028
- workflowId,
7029
- runId,
7030
- input,
7031
- runtimeContext: playgroundRuntimeContext
7032
- }) => {
7033
- try {
7034
- const runtimeContext = new RuntimeContext$1();
7035
- Object.entries(playgroundRuntimeContext).forEach(([key, value]) => {
7036
- runtimeContext.set(key, value);
7037
- });
7038
- const workflow = client.getWorkflow(workflowId);
7039
- await workflow.start({ runId, inputData: input || {}, runtimeContext });
7040
- } catch (error) {
7041
- console.error("Error starting workflow run:", error);
7042
- throw error;
7043
- }
7044
- };
7045
- const startAsyncWorkflowRun = async ({
7046
- workflowId,
7047
- runId,
7048
- input,
7049
- runtimeContext: playgroundRuntimeContext
7050
- }) => {
7051
- try {
7052
- const runtimeContext = new RuntimeContext$1();
7053
- Object.entries(playgroundRuntimeContext).forEach(([key, value]) => {
7054
- runtimeContext.set(key, value);
7055
- });
7056
- const workflow = client.getWorkflow(workflowId);
7057
- const result = await workflow.startAsync({ runId, inputData: input || {}, runtimeContext });
7058
- return result;
7059
- } catch (error) {
7060
- console.error("Error starting workflow run:", error);
7061
- throw error;
7062
- }
7063
- };
7064
6981
  return {
7065
- startWorkflowRun,
7066
- createWorkflowRun,
7067
6982
  startLegacyWorkflowRun,
7068
- createLegacyWorkflowRun,
7069
- startAsyncWorkflowRun
6983
+ createLegacyWorkflowRun
7070
6984
  };
7071
6985
  };
7072
6986
  const useWatchWorkflow = () => {
7073
6987
  const [isWatchingLegacyWorkflow, setIsWatchingLegacyWorkflow] = useState(false);
7074
- const [isWatchingWorkflow, setIsWatchingWorkflow] = useState(false);
7075
6988
  const [legacyWatchResult, setLegacyWatchResult] = useState(null);
7076
- const [watchResult, setWatchResult] = useState(null);
7077
6989
  const client = useMastraClient();
7078
6990
  const debouncedSetLegacyWorkflowWatchResult = useDebouncedCallback((record) => {
7079
6991
  const formattedResults = Object.entries(record.results || {}).reduce(
@@ -7121,43 +7033,14 @@ const useWatchWorkflow = () => {
7121
7033
  setIsWatchingLegacyWorkflow(false);
7122
7034
  }
7123
7035
  };
7124
- const debouncedSetWorkflowWatchResult = useDebouncedCallback((record) => {
7125
- const sanitizedRecord = sanitizeWorkflowWatchResult(record);
7126
- setWatchResult(sanitizedRecord);
7127
- }, 100);
7128
- const watchWorkflow = async ({ workflowId, runId }) => {
7129
- try {
7130
- setIsWatchingWorkflow(true);
7131
- const workflow = client.getWorkflow(workflowId);
7132
- await workflow.watch({ runId }, (record) => {
7133
- try {
7134
- debouncedSetWorkflowWatchResult(record);
7135
- } catch (err) {
7136
- console.error("Error processing workflow record:", err);
7137
- setWatchResult({
7138
- ...record
7139
- });
7140
- }
7141
- });
7142
- } catch (error) {
7143
- console.error("Error watching workflow:", error);
7144
- throw error;
7145
- } finally {
7146
- setIsWatchingWorkflow(false);
7147
- }
7148
- };
7149
7036
  return {
7150
7037
  watchLegacyWorkflow,
7151
7038
  isWatchingLegacyWorkflow,
7152
- legacyWatchResult,
7153
- watchWorkflow,
7154
- isWatchingWorkflow,
7155
- watchResult
7039
+ legacyWatchResult
7156
7040
  };
7157
7041
  };
7158
7042
  const useResumeWorkflow = () => {
7159
7043
  const [isResumingLegacyWorkflow, setIsResumingLegacyWorkflow] = useState(false);
7160
- const [isResumingWorkflow, setIsResumingWorkflow] = useState(false);
7161
7044
  const client = useMastraClient();
7162
7045
  const resumeLegacyWorkflow = async ({
7163
7046
  workflowId,
@@ -7176,33 +7059,9 @@ const useResumeWorkflow = () => {
7176
7059
  setIsResumingLegacyWorkflow(false);
7177
7060
  }
7178
7061
  };
7179
- const resumeWorkflow = async ({
7180
- workflowId,
7181
- step,
7182
- runId,
7183
- resumeData,
7184
- runtimeContext: playgroundRuntimeContext
7185
- }) => {
7186
- try {
7187
- setIsResumingWorkflow(true);
7188
- const runtimeContext = new RuntimeContext$1();
7189
- Object.entries(playgroundRuntimeContext).forEach(([key, value]) => {
7190
- runtimeContext.set(key, value);
7191
- });
7192
- const response = await client.getWorkflow(workflowId).resume({ step, runId, resumeData, runtimeContext });
7193
- return response;
7194
- } catch (error) {
7195
- console.error("Error resuming workflow:", error);
7196
- throw error;
7197
- } finally {
7198
- setIsResumingWorkflow(false);
7199
- }
7200
- };
7201
7062
  return {
7202
7063
  resumeLegacyWorkflow,
7203
- isResumingLegacyWorkflow,
7204
- resumeWorkflow,
7205
- isResumingWorkflow
7064
+ isResumingLegacyWorkflow
7206
7065
  };
7207
7066
  };
7208
7067
 
@@ -9812,13 +9671,17 @@ function WorkflowTrigger({
9812
9671
  workflowId,
9813
9672
  setRunId,
9814
9673
  workflow,
9815
- isLoading
9674
+ isLoading,
9675
+ createWorkflowRun,
9676
+ startWorkflowRun,
9677
+ resumeWorkflow,
9678
+ watchWorkflow,
9679
+ watchResult,
9680
+ isWatchingWorkflow,
9681
+ isResumingWorkflow
9816
9682
  }) {
9817
9683
  const { runtimeContext } = usePlaygroundStore();
9818
9684
  const { result, setResult, payload, setPayload } = useContext(WorkflowRunContext);
9819
- const { createWorkflowRun, startWorkflowRun } = useExecuteWorkflow();
9820
- const { watchWorkflow, watchResult, isWatchingWorkflow } = useWatchWorkflow();
9821
- const { resumeWorkflow, isResumingWorkflow } = useResumeWorkflow();
9822
9685
  const [suspendedSteps, setSuspendedSteps] = useState([]);
9823
9686
  const [isRunning, setIsRunning] = useState(false);
9824
9687
  const triggerSchema = workflow?.inputSchema;