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.

Refactor AgentCard to integrate destroyCanvasContextMenu for improved context menu handling on various button clicks

Muhammad Hamza Khan91ea81818697
diff --git a/packages/app/src/builder-ui/components/AgentCard.class.ts b/packages/app/src/builder-ui/components/AgentCard.class.ts
index 2829b54b..03c5e44d 100644
--- a/packages/app/src/builder-ui/components/AgentCard.class.ts
+++ b/packages/app/src/builder-ui/components/AgentCard.class.ts
@@ -7,6 +7,7 @@ import { ComponentProperties, DrawSettingsType, Settings } from '../types/compon
import { alert, openAgentSettingsRightSidebar } from '../ui/dialogs';
import { renderAgentSettingsSidebar } from '../ui/react-injects';
import { delay, uid } from '../utils';
+import { destroyMenu as destroyCanvasContextMenu } from '../workspace/CanvasContextMenu';
import { Workspace } from '../workspace/Workspace.class';
import { Component } from './Component.class';
@@ -172,24 +173,24 @@ export class AgentCard extends EventEmitter {
*/
public async repaintSkillConnections(): Promise<void> {
if (!this.workspace.agent?.data?.components) return;
-
+
// Get skills once to avoid duplicate filtering
const skills = this.workspace.agent.data.components.filter((c) => c.name === 'APIEndpoint');
if (skills.length === 0) return;
-
+
// Handle connections for all skills
for (const skill of skills) {
await this.handleCompConn(skill.id);
}
-
+
// Single repaint operation for all affected elements
// This is more efficient than multiple individual repaints
const elementsToRepaint = [
this.domElement, // Agent card
- ...skills.map(skill => document.querySelector(`#${skill.id}`)).filter(Boolean)
+ ...skills.map((skill) => document.querySelector(`#${skill.id}`)).filter(Boolean),
];
-
- elementsToRepaint.forEach(element => {
+
+ elementsToRepaint.forEach((element) => {
if (element) {
this.workspace.jsPlumbInstance.repaint(element);
}
@@ -243,8 +244,9 @@ export class AgentCard extends EventEmitter {
// create a placeholder for the agent image (if no image found). the placeholder will be the first letter of the agent name. use tailwind
const agentImagePlaceholder = document.createElement('div');
agentImagePlaceholder.id = 'agent-card-avatar-placeholder';
- agentImagePlaceholder.className = `h-full w-full flex items-center justify-center bg-uipink rounded-[7px] w-8 h-8 flex items-center justify-center text-white font-medium truncate ${agentAvatar ? 'hidden' : ''
- }`;
+ agentImagePlaceholder.className = `h-full w-full flex items-center justify-center bg-uipink rounded-[7px] w-8 h-8 flex items-center justify-center text-white font-medium truncate ${
+ agentAvatar ? 'hidden' : ''
+ }`;
agentImagePlaceholder.style.fontSize = '77px';
setTimeout(() => {
agentImagePlaceholder.textContent =
@@ -531,6 +533,7 @@ export class AgentCard extends EventEmitter {
const addSkillButton = this.domElement.querySelector('#add-skill-button');
if (addSkillButton) {
addSkillButton.addEventListener('click', async (e) => {
+ destroyCanvasContextMenu();
e.stopPropagation();
// console.log('Add skill button clicked');
// Functionality will be added later
@@ -591,6 +594,7 @@ export class AgentCard extends EventEmitter {
const agentSettingsButton = this.domElement.querySelector('.agent-settings-button');
if (agentSettingsButton) {
agentSettingsButton.addEventListener('click', (e) => {
+ destroyCanvasContextMenu();
e.stopPropagation(); // Prevent the main card click handler from firing
// Toggle React component mount state
@@ -607,6 +611,7 @@ export class AgentCard extends EventEmitter {
// Add click handler to the entire card (now opens sidebar)
this.domElement.addEventListener('click', (e) => {
+ destroyCanvasContextMenu();
e.stopPropagation();
// Check if clicked target is an HTMLElement before using closest()
@@ -631,6 +636,7 @@ export class AgentCard extends EventEmitter {
const previewButton = this.domElement.querySelector('.preview-button');
if (previewButton) {
previewButton.addEventListener('click', (e) => {
+ destroyCanvasContextMenu();
e.stopPropagation();
PostHog.track('app_preview_as_chatbot_click');
@@ -674,7 +680,6 @@ export class AgentCard extends EventEmitter {
agentNameElement.textContent = this.workspace.agent?.data?.name || '';
await this.repaintSkillConnections();
}
-
// const topBarAgentAvatarElm: HTMLImageElement | null = document.querySelector('#agent-avatar');