Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Implement workflow extraction and debug state reset in createDebugInjectDialog

Muhammad Hamza Khan1810e3312c4f
diff --git a/packages/app/src/builder-ui/debugger.ts b/packages/app/src/builder-ui/debugger.ts
index 0b2f503c..05e5ce1d 100644
--- a/packages/app/src/builder-ui/debugger.ts
+++ b/packages/app/src/builder-ui/debugger.ts
@@ -32,6 +32,7 @@ import {
updateDebugControls,
updateDebugControlsOnSelection,
} from './utils/debugger.utils';
+import { extractWorkflows } from './workspace/ComponentSort';
import { Monitor } from './workspace/Monitor';
const DEBUG_INJECT_TEXT_EXPERIMENT_VARIANTS = {
@@ -2692,6 +2693,38 @@ export function createDebugInjectDialog(
dialog,
actionType: 'step' | 'run',
) {
+ const agentData = (await workspace.export(false)) || workspace?.agent?.data;
+ const workflows = await extractWorkflows(agentData);
+
+ const selectedWorkflow = workflows.filter((wf) =>
+ wf.components.some((wc) => wc?.id === component?.uid),
+ );
+
+ // Before moving to the new session
+ // Reset the debug state of the selected workflow
+ selectedWorkflow?.forEach((wf) => {
+ wf?.components?.forEach((wc) => {
+ const compElement = document.querySelector(`#${wc?.id}`);
+ const dbgValues = compElement.querySelectorAll(`.dbg-output`);
+ const dbgBar: HTMLElement = compElement.querySelector(`.debug-bar`);
+ const dbgBox: HTMLElement = document.querySelector(`.debug-box[rel="${wc?.id}"]`);
+
+ if (compElement && dbgValues?.length > 0) {
+ dbgValues.forEach((dbgValue) => {
+ dbgValue?.remove();
+ });
+ }
+
+ if (compElement && dbgBar) {
+ dbgBar.style.display = 'none';
+ }
+
+ if (compElement && dbgBox) {
+ dbgBox?.remove();
+ }
+ });
+ });
+
// Check if the current component has an error
const hasError = component.domElement.querySelector('.error');
diff --git a/packages/app/src/builder-ui/workspace/ComponentSort.ts b/packages/app/src/builder-ui/workspace/ComponentSort.ts
index 4c3cf513..9477b6f4 100644
--- a/packages/app/src/builder-ui/workspace/ComponentSort.ts
+++ b/packages/app/src/builder-ui/workspace/ComponentSort.ts
@@ -53,7 +53,7 @@ function updateWFBoundingBox(workflows) {
});
}
-async function extractWorkflows(data) {
+export async function extractWorkflows(data) {
const { components, connections } = data;
// Build adjacency list for graph representation