@mastra/playground-ui 5.1.6-alpha.4 → 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.cjs.js
CHANGED
|
@@ -32,7 +32,6 @@ const colors = require('./colors-Du4i-E0i.cjs');
|
|
|
32
32
|
const uiUtils = require('@ai-sdk/ui-utils');
|
|
33
33
|
const Markdown = require('react-markdown');
|
|
34
34
|
const useDebounce = require('use-debounce');
|
|
35
|
-
const runtimeContext = require('@mastra/core/runtime-context');
|
|
36
35
|
const react$2 = require('@xyflow/react');
|
|
37
36
|
require('@xyflow/react/dist/style.css');
|
|
38
37
|
const Dagre = require('@dagrejs/dagre');
|
|
@@ -6941,41 +6940,6 @@ function Skeleton({ className, ...props }) {
|
|
|
6941
6940
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("animate-pulse rounded-md bg-muted/50", className), ...props });
|
|
6942
6941
|
}
|
|
6943
6942
|
|
|
6944
|
-
const sanitizeWorkflowWatchResult = (record) => {
|
|
6945
|
-
const formattedResults = Object.entries(record.payload.workflowState.steps || {}).reduce(
|
|
6946
|
-
(acc, [key, value]) => {
|
|
6947
|
-
let output = value.status === "success" ? value.output : void 0;
|
|
6948
|
-
if (output) {
|
|
6949
|
-
output = Object.entries(output).reduce(
|
|
6950
|
-
(_acc, [_key, _value]) => {
|
|
6951
|
-
const val = _value;
|
|
6952
|
-
_acc[_key] = val.type?.toLowerCase() === "buffer" ? { type: "Buffer", data: `[...buffered data]` } : val;
|
|
6953
|
-
return _acc;
|
|
6954
|
-
},
|
|
6955
|
-
{}
|
|
6956
|
-
);
|
|
6957
|
-
}
|
|
6958
|
-
acc[key] = { ...value, output };
|
|
6959
|
-
return acc;
|
|
6960
|
-
},
|
|
6961
|
-
{}
|
|
6962
|
-
);
|
|
6963
|
-
const sanitizedRecord = {
|
|
6964
|
-
...record,
|
|
6965
|
-
sanitizedOutput: record ? JSON.stringify(
|
|
6966
|
-
{
|
|
6967
|
-
...record,
|
|
6968
|
-
payload: {
|
|
6969
|
-
...record.payload,
|
|
6970
|
-
workflowState: { ...record.payload.workflowState, steps: formattedResults }
|
|
6971
|
-
}
|
|
6972
|
-
},
|
|
6973
|
-
null,
|
|
6974
|
-
2
|
|
6975
|
-
).slice(0, 5e4) : null
|
|
6976
|
-
};
|
|
6977
|
-
return sanitizedRecord;
|
|
6978
|
-
};
|
|
6979
6943
|
const useLegacyWorkflow = (workflowId) => {
|
|
6980
6944
|
const [legacyWorkflow, setLegacyWorkflow] = React.useState(null);
|
|
6981
6945
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
@@ -7033,16 +6997,6 @@ const useExecuteWorkflow = () => {
|
|
|
7033
6997
|
throw error;
|
|
7034
6998
|
}
|
|
7035
6999
|
};
|
|
7036
|
-
const createWorkflowRun = async ({ workflowId, prevRunId }) => {
|
|
7037
|
-
try {
|
|
7038
|
-
const workflow = client.getWorkflow(workflowId);
|
|
7039
|
-
const { runId: newRunId } = await workflow.createRun({ runId: prevRunId });
|
|
7040
|
-
return { runId: newRunId };
|
|
7041
|
-
} catch (error) {
|
|
7042
|
-
console.error("Error creating workflow run:", error);
|
|
7043
|
-
throw error;
|
|
7044
|
-
}
|
|
7045
|
-
};
|
|
7046
7000
|
const startLegacyWorkflowRun = async ({
|
|
7047
7001
|
workflowId,
|
|
7048
7002
|
runId,
|
|
@@ -7056,56 +7010,14 @@ const useExecuteWorkflow = () => {
|
|
|
7056
7010
|
throw error;
|
|
7057
7011
|
}
|
|
7058
7012
|
};
|
|
7059
|
-
const startWorkflowRun = async ({
|
|
7060
|
-
workflowId,
|
|
7061
|
-
runId,
|
|
7062
|
-
input,
|
|
7063
|
-
runtimeContext: playgroundRuntimeContext
|
|
7064
|
-
}) => {
|
|
7065
|
-
try {
|
|
7066
|
-
const runtimeContext$1 = new runtimeContext.RuntimeContext();
|
|
7067
|
-
Object.entries(playgroundRuntimeContext).forEach(([key, value]) => {
|
|
7068
|
-
runtimeContext$1.set(key, value);
|
|
7069
|
-
});
|
|
7070
|
-
const workflow = client.getWorkflow(workflowId);
|
|
7071
|
-
await workflow.start({ runId, inputData: input || {}, runtimeContext: runtimeContext$1 });
|
|
7072
|
-
} catch (error) {
|
|
7073
|
-
console.error("Error starting workflow run:", error);
|
|
7074
|
-
throw error;
|
|
7075
|
-
}
|
|
7076
|
-
};
|
|
7077
|
-
const startAsyncWorkflowRun = async ({
|
|
7078
|
-
workflowId,
|
|
7079
|
-
runId,
|
|
7080
|
-
input,
|
|
7081
|
-
runtimeContext: playgroundRuntimeContext
|
|
7082
|
-
}) => {
|
|
7083
|
-
try {
|
|
7084
|
-
const runtimeContext$1 = new runtimeContext.RuntimeContext();
|
|
7085
|
-
Object.entries(playgroundRuntimeContext).forEach(([key, value]) => {
|
|
7086
|
-
runtimeContext$1.set(key, value);
|
|
7087
|
-
});
|
|
7088
|
-
const workflow = client.getWorkflow(workflowId);
|
|
7089
|
-
const result = await workflow.startAsync({ runId, inputData: input || {}, runtimeContext: runtimeContext$1 });
|
|
7090
|
-
return result;
|
|
7091
|
-
} catch (error) {
|
|
7092
|
-
console.error("Error starting workflow run:", error);
|
|
7093
|
-
throw error;
|
|
7094
|
-
}
|
|
7095
|
-
};
|
|
7096
7013
|
return {
|
|
7097
|
-
startWorkflowRun,
|
|
7098
|
-
createWorkflowRun,
|
|
7099
7014
|
startLegacyWorkflowRun,
|
|
7100
|
-
createLegacyWorkflowRun
|
|
7101
|
-
startAsyncWorkflowRun
|
|
7015
|
+
createLegacyWorkflowRun
|
|
7102
7016
|
};
|
|
7103
7017
|
};
|
|
7104
7018
|
const useWatchWorkflow = () => {
|
|
7105
7019
|
const [isWatchingLegacyWorkflow, setIsWatchingLegacyWorkflow] = React.useState(false);
|
|
7106
|
-
const [isWatchingWorkflow, setIsWatchingWorkflow] = React.useState(false);
|
|
7107
7020
|
const [legacyWatchResult, setLegacyWatchResult] = React.useState(null);
|
|
7108
|
-
const [watchResult, setWatchResult] = React.useState(null);
|
|
7109
7021
|
const client = useMastraClient();
|
|
7110
7022
|
const debouncedSetLegacyWorkflowWatchResult = useDebounce.useDebouncedCallback((record) => {
|
|
7111
7023
|
const formattedResults = Object.entries(record.results || {}).reduce(
|
|
@@ -7153,43 +7065,14 @@ const useWatchWorkflow = () => {
|
|
|
7153
7065
|
setIsWatchingLegacyWorkflow(false);
|
|
7154
7066
|
}
|
|
7155
7067
|
};
|
|
7156
|
-
const debouncedSetWorkflowWatchResult = useDebounce.useDebouncedCallback((record) => {
|
|
7157
|
-
const sanitizedRecord = sanitizeWorkflowWatchResult(record);
|
|
7158
|
-
setWatchResult(sanitizedRecord);
|
|
7159
|
-
}, 100);
|
|
7160
|
-
const watchWorkflow = async ({ workflowId, runId }) => {
|
|
7161
|
-
try {
|
|
7162
|
-
setIsWatchingWorkflow(true);
|
|
7163
|
-
const workflow = client.getWorkflow(workflowId);
|
|
7164
|
-
await workflow.watch({ runId }, (record) => {
|
|
7165
|
-
try {
|
|
7166
|
-
debouncedSetWorkflowWatchResult(record);
|
|
7167
|
-
} catch (err) {
|
|
7168
|
-
console.error("Error processing workflow record:", err);
|
|
7169
|
-
setWatchResult({
|
|
7170
|
-
...record
|
|
7171
|
-
});
|
|
7172
|
-
}
|
|
7173
|
-
});
|
|
7174
|
-
} catch (error) {
|
|
7175
|
-
console.error("Error watching workflow:", error);
|
|
7176
|
-
throw error;
|
|
7177
|
-
} finally {
|
|
7178
|
-
setIsWatchingWorkflow(false);
|
|
7179
|
-
}
|
|
7180
|
-
};
|
|
7181
7068
|
return {
|
|
7182
7069
|
watchLegacyWorkflow,
|
|
7183
7070
|
isWatchingLegacyWorkflow,
|
|
7184
|
-
legacyWatchResult
|
|
7185
|
-
watchWorkflow,
|
|
7186
|
-
isWatchingWorkflow,
|
|
7187
|
-
watchResult
|
|
7071
|
+
legacyWatchResult
|
|
7188
7072
|
};
|
|
7189
7073
|
};
|
|
7190
7074
|
const useResumeWorkflow = () => {
|
|
7191
7075
|
const [isResumingLegacyWorkflow, setIsResumingLegacyWorkflow] = React.useState(false);
|
|
7192
|
-
const [isResumingWorkflow, setIsResumingWorkflow] = React.useState(false);
|
|
7193
7076
|
const client = useMastraClient();
|
|
7194
7077
|
const resumeLegacyWorkflow = async ({
|
|
7195
7078
|
workflowId,
|
|
@@ -7208,33 +7091,9 @@ const useResumeWorkflow = () => {
|
|
|
7208
7091
|
setIsResumingLegacyWorkflow(false);
|
|
7209
7092
|
}
|
|
7210
7093
|
};
|
|
7211
|
-
const resumeWorkflow = async ({
|
|
7212
|
-
workflowId,
|
|
7213
|
-
step,
|
|
7214
|
-
runId,
|
|
7215
|
-
resumeData,
|
|
7216
|
-
runtimeContext: playgroundRuntimeContext
|
|
7217
|
-
}) => {
|
|
7218
|
-
try {
|
|
7219
|
-
setIsResumingWorkflow(true);
|
|
7220
|
-
const runtimeContext$1 = new runtimeContext.RuntimeContext();
|
|
7221
|
-
Object.entries(playgroundRuntimeContext).forEach(([key, value]) => {
|
|
7222
|
-
runtimeContext$1.set(key, value);
|
|
7223
|
-
});
|
|
7224
|
-
const response = await client.getWorkflow(workflowId).resume({ step, runId, resumeData, runtimeContext: runtimeContext$1 });
|
|
7225
|
-
return response;
|
|
7226
|
-
} catch (error) {
|
|
7227
|
-
console.error("Error resuming workflow:", error);
|
|
7228
|
-
throw error;
|
|
7229
|
-
} finally {
|
|
7230
|
-
setIsResumingWorkflow(false);
|
|
7231
|
-
}
|
|
7232
|
-
};
|
|
7233
7094
|
return {
|
|
7234
7095
|
resumeLegacyWorkflow,
|
|
7235
|
-
isResumingLegacyWorkflow
|
|
7236
|
-
resumeWorkflow,
|
|
7237
|
-
isResumingWorkflow
|
|
7096
|
+
isResumingLegacyWorkflow
|
|
7238
7097
|
};
|
|
7239
7098
|
};
|
|
7240
7099
|
|
|
@@ -9844,13 +9703,17 @@ function WorkflowTrigger({
|
|
|
9844
9703
|
workflowId,
|
|
9845
9704
|
setRunId,
|
|
9846
9705
|
workflow,
|
|
9847
|
-
isLoading
|
|
9706
|
+
isLoading,
|
|
9707
|
+
createWorkflowRun,
|
|
9708
|
+
startWorkflowRun,
|
|
9709
|
+
resumeWorkflow,
|
|
9710
|
+
watchWorkflow,
|
|
9711
|
+
watchResult,
|
|
9712
|
+
isWatchingWorkflow,
|
|
9713
|
+
isResumingWorkflow
|
|
9848
9714
|
}) {
|
|
9849
9715
|
const { runtimeContext } = usePlaygroundStore();
|
|
9850
9716
|
const { result, setResult, payload, setPayload } = React.useContext(WorkflowRunContext);
|
|
9851
|
-
const { createWorkflowRun, startWorkflowRun } = useExecuteWorkflow();
|
|
9852
|
-
const { watchWorkflow, watchResult, isWatchingWorkflow } = useWatchWorkflow();
|
|
9853
|
-
const { resumeWorkflow, isResumingWorkflow } = useResumeWorkflow();
|
|
9854
9717
|
const [suspendedSteps, setSuspendedSteps] = React.useState([]);
|
|
9855
9718
|
const [isRunning, setIsRunning] = React.useState(false);
|
|
9856
9719
|
const triggerSchema = workflow?.inputSchema;
|