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.

Multiple optimizations : connections drag , debug button toggle, debug states update

alaa-eddineb0e752c05762
diff --git a/packages/app/src/backend/routes/dbg/router.ts b/packages/app/src/backend/routes/dbg/router.ts
index b1b641cd..0c9dd9c7 100644
--- a/packages/app/src/backend/routes/dbg/router.ts
+++ b/packages/app/src/backend/routes/dbg/router.ts
@@ -37,10 +37,12 @@ router.get('/debugSession/:id', async (req, res, next) => {
router.post(`/api`, async (req, res) => {
try {
- const url = `${config.env.API_SERVER}/api/`;
+ const { includeNewState } = req.query;
+ const url = `${config.env.API_SERVER}/api/${includeNewState ? '?includeNewState=true' : ''}`;
//x-hash-id is configured in smyth load balancer to use user IP by default or custom value if provided
//here we force it to use the real client IP in order to keep debug sessions consistent
+ //TODO : set trust proxy to true in production and use req.ip instead of req.headers['x-forwarded-for']
const client_ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
const headers = {
diff --git a/packages/app/src/builder-ui/components/Component.class/index.ts b/packages/app/src/builder-ui/components/Component.class/index.ts
index 84d5f788..2fac8b47 100644
--- a/packages/app/src/builder-ui/components/Component.class/index.ts
+++ b/packages/app/src/builder-ui/components/Component.class/index.ts
@@ -3001,8 +3001,18 @@ export class Component extends EventEmitter {
debugBtn.classList.add('active');
- await this.workspace.debugger.injectComponentDebugInfo(agent.id, this._uid, data);
- const stepResponse = await this.workspace.debugger.readDebugStep(agent.id);
+ const injResult = await this.workspace.debugger.injectComponentDebugInfo(
+ agent.id,
+ this._uid,
+ data,
+ );
+ const stepResponse = await this.workspace.debugger.processDebugStep(
+ injResult.newState,
+ agent.id,
+ );
+
+ //console.log('Step Response', stepResponse);
+ //console.log('Inj Result', injResult.newState);
resolve({ status: 'success' });
return stepResponse;
diff --git a/packages/app/src/builder-ui/debugger.ts b/packages/app/src/builder-ui/debugger.ts
index 8bcd786e..a33f1908 100644
--- a/packages/app/src/builder-ui/debugger.ts
+++ b/packages/app/src/builder-ui/debugger.ts
@@ -345,7 +345,8 @@ export async function init() {
});
workspace.saveAgent();
setTimeout(() => {
- workspace.redraw();
+ //workspace.redraw();
+ repaintDebugComponentsAfter();
updateDebugControlsOnSelection();
}, 500);
});
@@ -361,7 +362,8 @@ export async function init() {
workspace.domElement.classList.add('debug-enabled');
});
setTimeout(() => {
- workspace.redraw();
+ //workspace.redraw();
+ repaintDebugComponentsAfter();
if (workspace?.agent?.id) {
//force stop any existing debug session to avoid conflicts
stopDebugSession();
@@ -456,9 +458,10 @@ export async function init() {
});
try {
- const sessionID = await runDebugStep(agent.id);
+ const debugStepResult: any = await runDebugStep(agent.id);
+ const sessionID = debugStepResult?.sessionID;
if (sessionID) {
- const result = await readDebugStep(agent.id);
+ const result = await processDebugStep(debugStepResult?.result?.newState, agent.id);
// Show deploy agent toast if the workflow executed successfully until the last component
if (!result?.errorOccurred && result?.states?.sessionClosed) {
@@ -618,7 +621,11 @@ export async function runDebug() {
const agent = workspace.agent;
if (!debugSessions?.[agent.id]?.sessionID) break;
- if (processComponents) sessionID = await runDebugStep(agent.id);
+ let debugStepResult;
+ if (processComponents) {
+ debugStepResult = await runDebugStep(agent.id);
+ sessionID = debugStepResult?.sessionID;
+ }
if (!sessionID) {
errorToast(
@@ -630,7 +637,8 @@ export async function runDebug() {
break;
}
- result = await readDebugStep(agent.id);
+ //if newState is included no need to send a read request
+ result = await processDebugStep(debugStepResult?.result?.newState, agent.id);
const activeComponents = Object.values(result.states.state).filter((c: any) => c.active);
console.log(activeComponents);
processComponents = activeComponents.length > 0;
@@ -895,7 +903,7 @@ async function _attachLiveDebugSession(agentID) {
const SessionID = result.dbgSession;
if (SessionID) {
- const dbgResult = await readDebugStep(workspace.agent.id, SessionID);
+ const dbgResult = await processDebugStep(null, workspace.agent.id, SessionID);
if (!dbgResult.attached) {
warningToast(
'Cannot attach to this session.<br />Make sure that the session ID is valid and that the corresponding agent is loaded',
@@ -1339,7 +1347,7 @@ function showOutputInfo(outputEndpoint, outputContent, compName?) {
if (endpoint && dbgTextarea && !endpoint.classList.contains('pinned')) {
// Clear selection when mouse leaves the endpoint (hover window closes)
- const clearSelectionHandler = () => {
+ const clearSelectionHandler = async () => {
// Only clear if selection is within this debug textarea
const selection = window.getSelection();
if (
@@ -1355,7 +1363,7 @@ function showOutputInfo(outputEndpoint, outputContent, compName?) {
endpoint.addEventListener('mouseleave', clearSelectionHandler);
// Also clear selection when clicking outside the debug element
- document.addEventListener('click', (e) => {
+ document.addEventListener('click', async (e) => {
if (!div.contains(e.target as Node) && !endpoint.classList.contains('pinned')) {
const selection = window.getSelection();
if (
@@ -1446,8 +1454,8 @@ function showInputInfo(inputEndpoint, inputContent) {
let lastStepData: any = {};
const DEBUG_LOG_MAX_LENGTH = 10000;
-export async function readDebugStep(agentID, sessionID?, IDFilter?: any[]) {
- console.log('readDebugStep', agentID, sessionID);
+export async function processDebugStep(debugInfo, agentID, sessionID?, IDFilter?: any[]) {
+ console.log('processDebugStep', agentID, sessionID);
if (!sessionID) sessionID = debugSessions?.[agentID]?.sessionID;
@@ -1460,7 +1468,7 @@ export async function readDebugStep(agentID, sessionID?, IDFilter?: any[]) {
if (!debugSessions[agentID]) debugSessions[agentID] = {};
debugSessions[agentID].sessionID = sessionID;
- const result = await readDebugInfo(agentID, sessionID);
+ const result = debugInfo || (await readDebugInfo(agentID, sessionID));
lastStepData = result;
let attached = sessionID ? false : true;
@@ -2094,7 +2102,7 @@ export function startDebugListener(agentID, sessionID, callback) {
if (!sessionID) return;
debugSessions[agentID][sessionID] = setInterval(async () => {
- const result = await readDebugStep(agentID, sessionID);
+ const result = await processDebugStep(null, agentID, sessionID);
if (typeof callback === 'function') callback(result);
}, 5000);
}
@@ -2122,7 +2130,7 @@ export async function injectComponentDebugInfo(agentID, componentID, { input, ou
// attachBtn.setAttribute('disabled', 'true');
const sessionID = debugSessions?.[agentID]?.sessionID || '';
- const dbgUrl = DEBUG_ENDPOINT;
+ const dbgUrl = DEBUG_ENDPOINT + '?includeNewState=true';
const headers = {
'Content-type': 'application/json; charset=UTF-8',
'X-AGENT-ID': agentID,
@@ -2233,7 +2241,7 @@ export async function runDebugStep(agentID, sessionID?) {
}
}
- const dbgUrl = DEBUG_ENDPOINT + '?run';
+ const dbgUrl = DEBUG_ENDPOINT + '?run&includeNewState=true';
const headers = {
'Content-type': 'application/json; charset=UTF-8',
'X-AGENT-ID': agentID,
@@ -2263,7 +2271,7 @@ export async function runDebugStep(agentID, sessionID?) {
return null;
}
- return sessionID;
+ return { result, sessionID };
}
export async function clearDebuggerSession(agentID, sessionID?) {
@@ -2294,23 +2302,25 @@ export async function clearDebuggerSession(agentID, sessionID?) {
return true;
}
-async function waitPendingAsyncComponents() {
- const agent = workspace.agent;
- if (!debugSessions?.[agent.id]?.sessionID) return;
- const sessionID = await runDebugStep(agent.id);
- if (!sessionID) return;
- let asyncRunning = [];
- do {
- asyncRunning = [...document.querySelectorAll('.dbg-async')].map((c) => c.id);
- console.log('asyncRunning', asyncRunning, asyncRunning.length);
- if (asyncRunning.length > 0) {
- await readDebugStep(agent.id, sessionID);
- }
- await delay(3000);
- } while (asyncRunning.length > 0);
-}
+// async function waitPendingAsyncComponents() {
+// const agent = workspace.agent;
+// if (!debugSessions?.[agent.id]?.sessionID) return;
+// const debugStepResult = await runDebugStep(agent.id);
+// const sessionID = debugStepResult?.sessionID;
+// if (!sessionID) return;
+// let asyncRunning = [];
+// do {
+// asyncRunning = [...document.querySelectorAll('.dbg-async')].map((c) => c.id);
+// console.log('asyncRunning', asyncRunning, asyncRunning.length);
+// if (asyncRunning.length > 0) {
+// await readDebugStep(agent.id, sessionID);
+// }
+// await delay(3000);
+// } while (asyncRunning.length > 0);
+// }
function stopDebugUI(clearInfo = true) {
+ repaintDebugComponentsAfter();
lastStepData = {};
workspace.domElement.classList.remove('debugging');
workspace.domElement.querySelectorAll('.btn-debug').forEach((el: HTMLElement) => {
@@ -2371,6 +2381,7 @@ function clearDebugUIInfo() {
});
}
export async function stopDebugSession(resetUI = true) {
+ repaintDebugComponentsAfter();
stopDebugUI(resetUI);
const sessionID = getDebugSessionID();
@@ -3222,7 +3233,8 @@ function resetComponentsState({
// Redraw workspace on next tick to ensure DOM updates are complete
requestAnimationFrame(() => {
- workspace.redraw();
+ //workspace.redraw();
+ //TODO: redraw the active components
});
}
@@ -3272,3 +3284,17 @@ function showDeployAgentToast() {
},
});
}
+
+function repaintDebugComponentsAfter(ms = 300) {
+ const components = [
+ ...workspace.container.querySelectorAll(
+ '.component.state-success, .component.dbg-active, .component.state-error',
+ ),
+ ];
+
+ setTimeout(() => {
+ components.forEach((component) => {
+ workspace.jsPlumbInstance.repaint(component);
+ });
+ }, ms);
+}
diff --git a/packages/app/src/builder-ui/workspace/Workspace.class.ts b/packages/app/src/builder-ui/workspace/Workspace.class.ts
index 4ea1b9b6..23c38232 100644
--- a/packages/app/src/builder-ui/workspace/Workspace.class.ts
+++ b/packages/app/src/builder-ui/workspace/Workspace.class.ts
@@ -995,13 +995,19 @@ export class Workspace extends EventEmitter {
const parent = zoom.parentElement;
workspaceContainer.addEventListener('pointerdown', (event) => {
+ if (this.hoveredElement != this.container && this.hoveredElement != this.domElement) return;
this.panzoom.handleDown(event);
});
document.addEventListener('pointermove', (event) => {
+ if (this.hoveredElement != this.container && this.hoveredElement != this.domElement) return;
if (event.ctrlKey || event.metaKey) return;
+
this.panzoom.handleMove(event);
});
- document.addEventListener('pointerup', this.panzoom.handleUp);
+ document.addEventListener('pointerup', (event) => {
+ if (this.hoveredElement != this.container && this.hoveredElement != this.domElement) return;
+ this.panzoom.handleUp(event);
+ });
// Completely custom wheel handling for better touchpad experience
parent.addEventListener('wheel', (event) => {
diff --git a/packages/app/static/css/smyth-builder-override.css b/packages/app/static/css/smyth-builder-override.css
index a937cdc5..cb1ddbc3 100644
--- a/packages/app/static/css/smyth-builder-override.css
+++ b/packages/app/static/css/smyth-builder-override.css
@@ -918,7 +918,7 @@ code.language-plan.done::before {
/* Success border for components */
.component.state-success {
- border: 1px solid #45c9a9 !important;
+ /*border: 1px solid #45c9a9 !important;*/
border-bottom: 5px solid #45c9a9 !important;
}