2025-08-14 08:04:48 -04:00
|
|
|
import { useEffect } from "react";
|
2025-08-01 09:16:54 -04:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
import { ReactFlowProvider } from "@xyflow/react";
|
2025-07-16 17:39:51 -04:00
|
|
|
|
|
|
|
|
import { useWorkflowQuery } from "../hooks/useWorkflowQuery";
|
|
|
|
|
import { WorkflowSettings } from "../types/workflowTypes";
|
2025-12-08 20:38:21 +03:00
|
|
|
import {
|
|
|
|
|
getElements,
|
|
|
|
|
upgradeWorkflowBlocksV1toV2,
|
|
|
|
|
} from "@/routes/workflows/editor/workflowEditorUtils";
|
2025-08-15 07:25:04 -04:00
|
|
|
import { getInitialParameters } from "@/routes/workflows/editor/utils";
|
|
|
|
|
import { Workspace } from "@/routes/workflows/editor/Workspace";
|
2025-08-29 13:30:53 -04:00
|
|
|
import { useDebugSessionBlockOutputsQuery } from "../hooks/useDebugSessionBlockOutputsQuery";
|
2025-08-14 08:04:48 -04:00
|
|
|
import { useWorkflowParametersStore } from "@/store/WorkflowParametersStore";
|
2025-08-29 13:30:53 -04:00
|
|
|
import { useBlockOutputStore } from "@/store/BlockOutputStore";
|
2025-08-07 17:13:02 -04:00
|
|
|
|
2025-08-15 07:25:04 -04:00
|
|
|
function Debugger() {
|
2025-08-13 14:13:00 -04:00
|
|
|
const { workflowPermanentId } = useParams();
|
2025-07-16 17:39:51 -04:00
|
|
|
const { data: workflow } = useWorkflowQuery({
|
|
|
|
|
workflowPermanentId,
|
|
|
|
|
});
|
2025-08-29 13:30:53 -04:00
|
|
|
const { data: outputParameters } = useDebugSessionBlockOutputsQuery({
|
|
|
|
|
workflowPermanentId,
|
|
|
|
|
});
|
2025-07-16 17:39:51 -04:00
|
|
|
|
2025-08-14 08:04:48 -04:00
|
|
|
const setParameters = useWorkflowParametersStore(
|
|
|
|
|
(state) => state.setParameters,
|
|
|
|
|
);
|
|
|
|
|
|
2025-08-29 13:30:53 -04:00
|
|
|
const setBlockOutputs = useBlockOutputStore((state) => state.setOutputs);
|
|
|
|
|
|
2025-08-14 08:04:48 -04:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (workflow) {
|
|
|
|
|
const initialParameters = getInitialParameters(workflow);
|
|
|
|
|
setParameters(initialParameters);
|
|
|
|
|
}
|
|
|
|
|
}, [workflow, setParameters]);
|
|
|
|
|
|
2025-08-29 13:30:53 -04:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!outputParameters) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const blockOutputs = Object.entries(outputParameters).reduce<{
|
|
|
|
|
[k: string]: Record<string, unknown>;
|
|
|
|
|
}>((acc, [blockLabel, outputs]) => {
|
|
|
|
|
acc[blockLabel] = outputs ?? null;
|
|
|
|
|
return acc;
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
setBlockOutputs(blockOutputs);
|
|
|
|
|
}, [outputParameters, setBlockOutputs]);
|
|
|
|
|
|
2025-07-16 17:39:51 -04:00
|
|
|
if (!workflow) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 20:38:21 +03:00
|
|
|
// Auto-upgrade v1 workflows to v2 by assigning sequential next_block_label values
|
|
|
|
|
const workflowVersion = workflow.workflow_definition.version ?? 1;
|
|
|
|
|
const blocksToRender =
|
|
|
|
|
workflowVersion < 2
|
|
|
|
|
? upgradeWorkflowBlocksV1toV2(workflow.workflow_definition.blocks)
|
|
|
|
|
: workflow.workflow_definition.blocks;
|
|
|
|
|
|
2025-07-16 17:39:51 -04:00
|
|
|
const settings: WorkflowSettings = {
|
|
|
|
|
persistBrowserSession: workflow.persist_browser_session,
|
|
|
|
|
proxyLocation: workflow.proxy_location,
|
|
|
|
|
webhookCallbackUrl: workflow.webhook_callback_url,
|
|
|
|
|
model: workflow.model,
|
|
|
|
|
maxScreenshotScrolls: workflow.max_screenshot_scrolls,
|
|
|
|
|
extraHttpHeaders: workflow.extra_http_headers
|
|
|
|
|
? JSON.stringify(workflow.extra_http_headers)
|
|
|
|
|
: null,
|
2025-09-29 18:59:31 -04:00
|
|
|
runWith: workflow.run_with,
|
2025-08-07 13:36:14 -04:00
|
|
|
scriptCacheKey: workflow.cache_key,
|
2025-09-06 08:51:11 -07:00
|
|
|
aiFallback: workflow.ai_fallback ?? true,
|
2025-09-18 17:40:59 +08:00
|
|
|
runSequentially: workflow.run_sequentially ?? false,
|
2025-09-24 14:34:42 +08:00
|
|
|
sequentialKey: workflow.sequential_key ?? null,
|
2025-07-16 17:39:51 -04:00
|
|
|
};
|
|
|
|
|
|
2025-12-08 20:38:21 +03:00
|
|
|
const elements = getElements(blocksToRender, settings, true);
|
2025-07-16 17:39:51 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="relative flex h-screen w-full">
|
|
|
|
|
<ReactFlowProvider>
|
2025-08-13 14:13:00 -04:00
|
|
|
<Workspace
|
2025-07-16 17:39:51 -04:00
|
|
|
initialEdges={elements.edges}
|
|
|
|
|
initialNodes={elements.nodes}
|
|
|
|
|
initialTitle={workflow.title}
|
2025-08-13 14:13:00 -04:00
|
|
|
showBrowser={true}
|
2025-07-16 17:39:51 -04:00
|
|
|
workflow={workflow}
|
|
|
|
|
/>
|
|
|
|
|
</ReactFlowProvider>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-15 07:25:04 -04:00
|
|
|
export { Debugger };
|