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.

trigger variables + oauth UI fixes

alaa-eddine1f5482533660
diff --git a/packages/app/src/backend/routes/api/page/builder.ts b/packages/app/src/backend/routes/api/page/builder.ts
index e377b7e2..135d4afd 100644
--- a/packages/app/src/backend/routes/api/page/builder.ts
+++ b/packages/app/src/backend/routes/api/page/builder.ts
@@ -1356,4 +1356,30 @@ router.post('/store-limit-reached', async (req, res) => {
}
});
+router.post('/trigger/:id/register', async (req, res) => {
+ try {
+ const { id } = req.params;
+ const { payload } = req.body;
+
+ const url = `${config.env.API_SERVER}/trigger/${id}/register`;
+
+ const headers = {
+ 'X-AGENT-ID': req.headers['x-agent-id'],
+ };
+
+ console.log('trigger register url', url, headers);
+
+ const result: any = await axios.post(url, { ...payload }, { headers });
+
+ console.log('>>> trigger register result', result.data);
+
+ res
+ .status(result.status || 200)
+ .send(result.error ? { error: result.error } : { ...result.data });
+ } catch (error) {
+ console.error('Error registering trigger:', error);
+ res.status(500).send({ error: 'Error registering trigger' });
+ }
+});
+
export default router;
diff --git a/packages/app/src/backend/routes/pages/builder-sidebar.ts b/packages/app/src/backend/routes/pages/builder-sidebar.ts
index 194c99a5..908fd655 100644
--- a/packages/app/src/backend/routes/pages/builder-sidebar.ts
+++ b/packages/app/src/backend/routes/pages/builder-sidebar.ts
@@ -94,7 +94,11 @@ const baseMenu: Menu = {
],
//hide triggers for now
- //Triggers: [{ name: 'GmailTrigger', label: 'Gmail Trigger', description: '' }],
+ Triggers: [
+ { name: 'GmailTrigger', label: 'Gmail Trigger', description: '' },
+ { name: 'WhatsAppTrigger', label: 'Whatsapp Trigger', description: '' },
+ { name: 'JobSchedulerTrigger', label: 'Job Scheduler Trigger', description: '' },
+ ],
Integrations: [],
};
diff --git a/packages/app/src/builder-ui/components/APIEndpoint.class.ts b/packages/app/src/builder-ui/components/APIEndpoint.class.ts
index 708d7d44..98e9482a 100644
--- a/packages/app/src/builder-ui/components/APIEndpoint.class.ts
+++ b/packages/app/src/builder-ui/components/APIEndpoint.class.ts
@@ -155,7 +155,7 @@ export class APIEndpoint extends Component {
type: 'textarea',
label: 'Description',
value: '',
- help: 'Provide a short overview for teammates and AI to understand the skill\'s purpose.',
+ help: "Provide a short overview for teammates and AI to understand the skill's purpose.",
tooltipClasses: 'w-56 ',
arrowClasses: '-ml-11',
validate: `maxlength=1000`,
@@ -269,6 +269,28 @@ export class APIEndpoint extends Component {
},
},
},
+
+ triggerBinding: {
+ type: 'string',
+ default: '',
+ allowDefaultEdit: true,
+
+ editConfig: {
+ type: 'textarea',
+ label: 'Triggers Binding',
+ class: 'm-2 p-2 bg-emerald-50 rounded-lg',
+ fieldCls:
+ 'bg-white border text-gray-900 rounded block w-full outline-none focus:outline-none focus:ring-0 focus:ring-offset-0 focus:ring-shadow-none text-sm font-normal placeholder:text-sm placeholder:font-normal py-2 px-3 transition-all duration-150 ease-in-out border-gray-300 border-b-gray-500 focus:border-b-2 focus:border-b-blue-500 focus-visible:border-b-2 focus-visible:border-b-blue-500',
+ attributes: {
+ 'data-trigger-vars': 'true',
+ 'data-auto-size': 'true',
+ rows: '2',
+ placeholder: `Map the triggers variables to this input`,
+ }, // Enable auto-size for consistent UX with 2-line default
+ //section: 'Advanced_Options',
+ hintPosition: 'after_label',
+ },
+ },
};
const dataEntries = [
@@ -465,6 +487,7 @@ export class APIEndpoint extends Component {
if (prop === 'name') {
const oldName = oldValue;
const newName = newValue;
+ const newOutputName = `_.${newName}`;
const inputName = inputDiv.getAttribute('smt-name');
const outputName = outputDiv.getAttribute('smt-name');
@@ -473,9 +496,9 @@ export class APIEndpoint extends Component {
inputDiv.querySelector('.name').innerText = newName;
}
- if (outputName != newName) {
- outputDiv.setAttribute('smt-name', newName);
- outputDiv.querySelector('.name').innerText = newName;
+ if (outputName != newOutputName) {
+ outputDiv.setAttribute('smt-name', newOutputName);
+ outputDiv.querySelector('.name').innerText = newOutputName;
// Update the expression attribute to use the new name
if (outputDiv?.hasAttribute('smt-expression')) {
@@ -499,6 +522,22 @@ export class APIEndpoint extends Component {
}
});
+ this.addEventListener('inputEditorReady', (dialog) => {
+ //try to find the triggerBinding field by name
+ const triggerBinding = dialog.querySelector('.form-box [name="triggerBinding"]');
+ if (!triggerBinding) return;
+
+ const connectedToTriggers = this.workspace.agent.data.connections
+ .filter((c) => c.targetId === this.uid)
+ .map((c) => c.sourceId);
+ if (connectedToTriggers.length > 0) {
+ triggerBinding.classList.remove('hidden');
+ triggerBinding.setAttribute('data-triggers', connectedToTriggers.join(','));
+ } else {
+ triggerBinding.classList.add('hidden');
+ triggerBinding.removeAttribute('data-triggers');
+ }
+ });
await delay(50);
this.advancedModeActions(this.isOnAdvancedMode);
}
@@ -509,7 +548,7 @@ export class APIEndpoint extends Component {
this.updateFormPreviewButton();
return result;
}
- if (this.properties.defaultOutputs.includes(name)) return super.addInput(parent, name);
+ //if (this.properties.defaultOutputs.includes(name)) return super.addInput(parent, name);
const inputDiv: any = await super.addInput(parent, name, inputProperties);
const outputParent = parent.parentElement.querySelector('.output-container');
@@ -521,7 +560,7 @@ export class APIEndpoint extends Component {
const outputDiv: any = await super.addOutput(
outputParent,
- name,
+ `_.${name}`,
{
expression: `body.${name}`,
},
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..f57f184c 100644
--- a/packages/app/src/builder-ui/components/Component.class/index.ts
+++ b/packages/app/src/builder-ui/components/Component.class/index.ts
@@ -174,6 +174,7 @@ export class Component extends EventEmitter {
displayName: this.constructor.name,
cssClass: '',
iconCSSClass: 'mif-cog',
+ icon: '',
showSettings: true,
addOutputButton: 'Outputs',
addInputButton: 'Inputs',
@@ -1007,6 +1008,8 @@ export class Component extends EventEmitter {
titleElm.appendChild(buttonElm);
}
+ this.emit('inputEditorReady', dialog);
+
// requires a tiny delay to make sure the input is focused
delay(50).then(() => focusField(nameElm));
},
@@ -1424,6 +1427,8 @@ export class Component extends EventEmitter {
titleElm.appendChild(buttonElm);
}
+ this.emit('inputEditorReady', dialog);
+
// requires a tiny delay to make sure the input is focused
delay(50).then(() => focusField(nameElm));
},
@@ -1951,7 +1956,7 @@ export class Component extends EventEmitter {
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
- const iconCss = this.drawSettings.iconCSSClass || '';
+ const iconCss = this.drawSettings.icon || this.drawSettings.iconCSSClass || '';
if (iconCss.startsWith('<svg')) {
const color = this.drawSettings.color || '#000';
@@ -1969,6 +1974,15 @@ export class Component extends EventEmitter {
if (!pathFill) {
allPathes.forEach((p) => p.setAttribute('fill', color));
}
+ } else if (iconCss.startsWith('/img/')) {
+ titleBar.innerHTML = `<div class="flex flex-row items-center gap-1 title-bar-top">
+ <span class="icon h-full">
+ <img src="${iconCss}" />
+ </span>
+ <span class="title font-semibold">${this.title}</span>
+ </div>
+ <span class="description">${this.description}</span>
+ `;
} else {
titleBar.innerHTML = `<div class="flex flex-row items-center gap-1 title-bar-top">
<span class="icon ${iconCss} h-full"></span>
@@ -2777,6 +2791,8 @@ export class Component extends EventEmitter {
titleElm.appendChild(buttonElm);
}
+ this.emit('inputEditorReady', dialog);
+
// requires a tiny delay to make sure the input is focused
delay(50).then(() => focusField(nameElm));
},
@@ -2886,6 +2902,8 @@ export class Component extends EventEmitter {
titleElm.appendChild(buttonElm);
}
+ this.emit('inputEditorReady', dialog);
+
// requires a tiny delay to make sure the input is focused
delay(50).then(() => focusField(nameElm));
},
diff --git a/packages/app/src/builder-ui/components/Triggers/Gmail.trigger.ts b/packages/app/src/builder-ui/components/Triggers/Gmail.trigger.ts
new file mode 100644
index 00000000..e42b61d5
--- /dev/null
+++ b/packages/app/src/builder-ui/components/Triggers/Gmail.trigger.ts
@@ -0,0 +1,95 @@
+import { oAuthSettings } from '../../helpers/oauth/oauth-settings.helper';
+import { Trigger } from './Trigger.class';
+
+declare var Metro;
+
+/**
+ * Gmail Trigger Component - Clean and Modular
+ *
+ * This component handles Gmail-based triggers with OAuth authentication.
+ * All OAuth logic has been extracted to the oAuthSettings() helper class
+ * for better separation of concerns and reusability.
+ */
+export class GmailTrigger extends Trigger {
+ public schema: any = {
+ email: {
+ id: 'string',
+ threadId: 'string',
+ labelIds: 'array',
+ snippet: 'string',
+ sizeEstimate: 'number',
+ internalDate: 'string',
+ headers: {
+ from: 'string',
+ to: 'string',
+ cc: 'string',
+ bcc: 'string',
+ subject: 'string',
+ date: 'string',
+ messageId: 'string',
+ },
+ body: {
+ text: 'string',
+ html: 'string',
+ },
+ attachments: 'array',
+ isUnread: 'boolean',
+ },
+ };
+ private oauth: oAuthSettings | undefined;
+
+ protected async prepare(): Promise<boolean> {
+ try {
+ // Initialize OAuth settings helper
+ this.oauth = new oAuthSettings(this, 'oauth_cred_id');
+ await this.oauth.initialize();
+ return true;
+ } catch (error) {
+ console.error('Error preparing Gmail trigger:', error);
+ return false;
+ }
+ }
+
+ protected async init(): Promise<void> {
+ await super.init();
+
+ // Set up component settings with OAuth configuration
+ this.settings = {
+ ...this.settings,
+ interval: {
+ type: 'range',
+ label: 'Interval',
+ min: 1,
+ max: 720,
+ value: 5,
+ step: 1,
+ validate: 'min=1 max=720',
+ validateMessage: 'Allowed range 1 to 720',
+ desc: 'Interval in minutes',
+ },
+ ...this.oauth?.configure(),
+ };
+
+ this.drawSettings.icon = `/img/triggers/gmail.svg`;
+
+ this.drawSettings.color = '#00ff00';
+ this.drawSettings.componentDescription = 'Poll Gmail for new incoming emails';
+ this.drawSettings.displayName = '<i class="fa-solid fa-bolt"></i> Gmail';
+ }
+
+ public async checkSettings(): Promise<void> {
+ await this.oauth?.checkSettings();
+ }
+
+ /**
+ * Clean up event listeners and resources
+ */
+ destroy(): void {
+ // Clean up OAuth helper
+ if (this.oauth) {
+ this.oauth.destroy();
+ }
+
+ super.destroy?.();
+ }
+}
diff --git a/packages/app/src/builder-ui/components/Triggers/GmailTrigger.class.ts b/packages/app/src/builder-ui/components/Triggers/JobScheduler.trigger.ts
similarity index 64%
rename from packages/app/src/builder-ui/components/Triggers/GmailTrigger.class.ts
rename to packages/app/src/builder-ui/components/Triggers/JobScheduler.trigger.ts
index 21db51aa..aba87392 100644
--- a/packages/app/src/builder-ui/components/Triggers/GmailTrigger.class.ts
+++ b/packages/app/src/builder-ui/components/Triggers/JobScheduler.trigger.ts
@@ -10,21 +10,12 @@ declare var Metro;
* All OAuth logic has been extracted to the oAuthSettings() helper class
* for better separation of concerns and reusability.
*/
-export class GmailTrigger extends Trigger {
+export class JobSchedulerTrigger extends Trigger {
+ public schema: any = {
+ job: 'object',
+ };
private oauth: oAuthSettings | undefined;
- protected async prepare(): Promise<boolean> {
- try {
- // Initialize OAuth settings helper
- this.oauth = new oAuthSettings(this);
- await this.oauth.initialize();
- return true;
- } catch (error) {
- console.error('Error preparing Gmail trigger:', error);
- return false;
- }
- }
-
protected async init(): Promise<void> {
await super.init();
@@ -42,11 +33,13 @@ export class GmailTrigger extends Trigger {
validateMessage: 'Allowed range 1 to 720',
desc: 'Interval in minutes',
},
- ...this.oauth?.configure(),
};
- this.drawSettings.iconCSSClass = 'svg-icon ' + this.constructor.name;
- this.drawSettings.color = '#ff00f2';
+ this.drawSettings.icon = `/img/triggers/job-scheduler.svg`;
+
+ this.drawSettings.color = '#00ff00';
+ this.drawSettings.componentDescription = 'Poll Job Scheduler for new incoming jobs';
+ this.drawSettings.displayName = '<i class="fa-solid fa-bolt"></i> JobScheduler';
}
public async checkSettings(): Promise<void> {
@@ -57,11 +50,6 @@ export class GmailTrigger extends Trigger {
* Clean up event listeners and resources
*/
destroy(): void {
- // Clean up OAuth helper
- if (this.oauth) {
- this.oauth.destroy();
- }
-
super.destroy?.();
}
}
diff --git a/packages/app/src/builder-ui/components/Triggers/Trigger.class.ts b/packages/app/src/builder-ui/components/Triggers/Trigger.class.ts
index f7384304..73c72cfb 100644
--- a/packages/app/src/builder-ui/components/Triggers/Trigger.class.ts
+++ b/packages/app/src/builder-ui/components/Triggers/Trigger.class.ts
@@ -16,17 +16,23 @@ export class Trigger extends Component {
// #region [ I/O config ] ==================
this.properties.defaultOutputs = ['Payload'];
this.properties.defaultInputs = [];
+ this.properties.outputProps = [{ name: 'Payload', type: 'string', color: '#95f562' }];
// #endregion
+ const dataEntries = ['triggerEndpoint'];
+ for (let item of dataEntries) {
+ if (typeof this.data[item] === 'undefined') this.data[item] = this.settings[item].value;
+ }
+
// #region [ Draw config ] ==================
this.drawSettings.addOutputButton = null;
this.drawSettings.addInputButton = null;
this.drawSettings.addOutputButtonLabel = '';
this.drawSettings.addInputButtonLabel = '';
- this.drawSettings.componentDescription = 'Trigger';
+ this.drawSettings.componentDescription = ' ';
- this.drawSettings.shortDescription = 'Trigger';
+ this.drawSettings.shortDescription = '';
this.drawSettings.color = '#ff00f2';
// #endregion
}
@@ -37,5 +43,11 @@ export class Trigger extends Component {
// add new connection endpoint
this.domElement.classList.add('Trigger');
this.domElement.setAttribute('smt-trigger', '');
+
+ // const _ResultOutput = document.createElement('div');
+ // _ResultOutput.className = 'smyth endpoint output-endpoint GmailTrigger';
+ // _ResultOutput.setAttribute('smt-name', 'Result');
+ // _ResultOutput.innerHTML = `<span class="name"><span class="label">Result</span></span>`;
+ // this.outputContainer.appendChild(_ResultOutput);
}
}
diff --git a/packages/app/src/builder-ui/components/Triggers/WhatsApp.trigger.ts b/packages/app/src/builder-ui/components/Triggers/WhatsApp.trigger.ts
new file mode 100644
index 00000000..3d59e434
--- /dev/null
+++ b/packages/app/src/builder-ui/components/Triggers/WhatsApp.trigger.ts
@@ -0,0 +1,91 @@
+import { Trigger } from './Trigger.class';
+
+/**
+ * Gmail Trigger Component - Clean and Modular
+ *
+ * This component handles Gmail-based triggers with OAuth authentication.
+ * All OAuth logic has been extracted to the oAuthSettings() helper class
+ * for better separation of concerns and reusability.
+ */
+export class WhatsAppTrigger extends Trigger {
+ public schema: any = {
+ message: {
+ id: 'string',
+ from: 'string',
+ profileName: 'string',
+ text: 'string',
+ type: 'string',
+ timestamp: 'string',
+ phoneNumberId: 'string',
+ },
+ };
+
+ protected async init(): Promise<void> {
+ await super.init();
+
+ // Set up component settings with OAuth configuration
+ this.settings = {
+ ...this.settings,
+ verifyToken: {
+ type: 'input',
+ label: 'Verify Token',
+ hint: 'Verify Token',
+ validate: `required maxlength=256`,
+ validateMessage: `Provide a valid verify token that only contains 'a-z', 'A-Z', '0-9', '-', '_' , without leading or trailing spaces. Length should be less than 50 characters.`,
+ },
+ clientId: {
+ type: 'input',
+ label: 'Client ID',
+ hint: 'Client ID',
+ validate: `required maxlength=512`,
+ validateMessage: `Provide a valid client id that only contains 'a-z', 'A-Z', '0-9', '-', '_' , without leading or trailing spaces. Length should be less than 50 characters.`,
+ },
+ clientSecret: {
+ type: 'input',
+ label: 'Client Secret',
+ hint: 'Client Secret',
+ validate: `required maxlength=512`,
+ validateMessage: `Provide a valid client secret that only contains 'a-z', 'A-Z', '0-9', '-', '_' , without leading or trailing spaces. Length should be less than 50 characters.`,
+ },
+ };
+
+ this.drawSettings.icon = `/img/triggers/whatsapp.svg`;
+
+ this.drawSettings.color = '#00ff00';
+ this.drawSettings.componentDescription = 'Poll Whatsapp for new incoming messages';
+ this.drawSettings.displayName = '<i class="fa-solid fa-bolt"></i> WhatsApp';
+ }
+
+ // public async checkSettings(): Promise<void> {
+
+ // }
+
+ /**
+ * Clean up event listeners and resources
+ */
+ destroy(): void {
+ //
+ super.destroy?.();
+ }
+
+ protected async run(): Promise<any> {
+ this.addEventListener('settingsSaved', async (settingsValues) => {
+ await this.workspace.waitServerData();
+ await this.workspace.saveAgent();
+ const base = this.workspace.serverData.frontUrl;
+ const id = this.uid;
+ const url = `${base}/api/page/builder/trigger/${id}/register`;
+ //const result: any = await axios.post(url, { data: '123' });
+ const headers = {
+ 'X-AGENT-ID': this.workspace.agent.id,
+ };
+ const result: any = await fetch(url, {
+ method: 'POST',
+ body: JSON.stringify({ data: '123' }),
+ headers,
+ });
+ const json = await result.json();
+ console.log('WhatsappTrigger result', json);
+ });
+ }
+}
diff --git a/packages/app/src/builder-ui/components/index.ts b/packages/app/src/builder-ui/components/index.ts
index 125248be..278ae0a3 100644
--- a/packages/app/src/builder-ui/components/index.ts
+++ b/packages/app/src/builder-ui/components/index.ts
@@ -37,7 +37,9 @@ import { VisionLLM } from './VisionLLM.class';
import { ZapierAction } from './ZapierAction.class';
import { AgentCard } from './AgentCard.class';
-import { GmailTrigger } from './Triggers/GmailTrigger.class';
+import { GmailTrigger } from './Triggers/Gmail.trigger';
+import { WhatsAppTrigger } from './Triggers/WhatsApp.trigger';
+import { JobSchedulerTrigger } from './Triggers/JobScheduler.trigger';
const baseComponents = {
Component,
@@ -77,7 +79,9 @@ const baseComponents = {
ImageGenerator,
MCPClient,
GmailTrigger,
+ WhatsAppTrigger,
AgentCard,
+ JobSchedulerTrigger,
};
export const getBuilderComponents = () => {
diff --git a/packages/app/src/builder-ui/helpers/oauth/oauth-settings.helper.ts b/packages/app/src/builder-ui/helpers/oauth/oauth-settings.helper.ts
index 355d1bcb..30880919 100644
--- a/packages/app/src/builder-ui/helpers/oauth/oauth-settings.helper.ts
+++ b/packages/app/src/builder-ui/helpers/oauth/oauth-settings.helper.ts
@@ -10,7 +10,6 @@ import { UIHelper } from './ui.helper';
* for components to integrate OAuth functionality without cluttering the component code.
*/
export class oAuthSettings {
- private component: any;
private oauthService: OAuthService | undefined;
private uiHelper: UIHelper | undefined;
private oauthConnectionNames: SelectOption[] = [];
@@ -18,7 +17,10 @@ export class oAuthSettings {
private boundHandleFocusAfterAuth: () => Promise<void>;
private boundHandleAuthMessage: (event: MessageEvent) => void;
- constructor(component: any) {
+ constructor(
+ private component: any,
+ private setting_name: string = 'oauth_con_id',
+ ) {
this.component = component;
this.boundHandleFocusAfterAuth = this.handleFocusAfterAuth.bind(this);
this.boundHandleAuthMessage = this.handleAuthMessage.bind(this);
@@ -29,8 +31,10 @@ export class oAuthSettings {
* Minimal integration so other components can just call oauth.checkSettings().
*/
public async checkSettings(): Promise<void> {
- const connectionId: string | undefined = this.component?.data?.oauth_con_id;
- const existingBtn = this.component?.domElement?.querySelector('button.oauthButton') as HTMLButtonElement || null;
+ const connectionId: string | undefined = this.component?.data?.[this.setting_name];
+ const existingBtn =
+ (this.component?.domElement?.querySelector('button.oauthButton') as HTMLButtonElement) ||
+ null;
// If no connection chosen, remove component-level button (if any) and exit
if (!connectionId || connectionId === 'None') {
@@ -87,12 +91,12 @@ export class oAuthSettings {
*/
configure(): Record<string, any> {
return {
- oauth_con_id: {
+ [this.setting_name]: {
type: 'select',
label: 'OAuth Connection',
section: 'OAuth',
options: this.oauthConnectionNames,
- value: this.component.data.oauth_con_id || 'None',
+ value: this.component.data[this.setting_name] || 'None',
events: {
change: (event: Event) =>
this.handleOAuthConnectionChange((event.target as HTMLSelectElement).value),
@@ -106,7 +110,7 @@ export class oAuthSettings {
visible: () => true,
events: {
click: () => {
- this.component.data.oauth_con_id = 'None';
+ this.component.data[this.setting_name] = 'None';
this.handleOAuthConnectionAction();
},
},
@@ -117,7 +121,8 @@ export class oAuthSettings {
id: 'editOAuthConnection',
cls: 'mt-[7px] !mr-[24px] !pt-[10px]',
visible: () =>
- this.component.data.oauth_con_id && this.component.data.oauth_con_id !== 'None',
+ this.component.data[this.setting_name] &&
+ this.component.data[this.setting_name] !== 'None',
events: {
click: () => this.handleOAuthConnectionAction(),
},
@@ -200,13 +205,13 @@ export class oAuthSettings {
await this.oauthService.loadConnections();
const options = this.oauthService.buildSelectOptions();
- if (this.component.settings?.oauth_con_id) {
- this.component.settings.oauth_con_id.options = options;
+ if (this.component.settings?.[this.setting_name]) {
+ this.component.settings[this.setting_name].options = options;
}
} catch (error) {
console.error('Error updating OAuth connection options:', error);
- if (this.component.settings?.oauth_con_id) {
- this.component.settings.oauth_con_id.options = [{ value: 'None', text: 'None' }];
+ if (this.component.settings?.[this.setting_name]) {
+ this.component.settings[this.setting_name].options = [{ value: 'None', text: 'None' }];
}
}
}
@@ -220,7 +225,7 @@ export class oAuthSettings {
return;
}
- const selectedConnectionId = this.component.data.oauth_con_id;
+ const selectedConnectionId = this.component.data[this.setting_name];
if (selectedConnectionId === 'None' || !selectedConnectionId) {
errorToast('Please select a valid OAuth Connection first', 'Error', 'alert');
return;
@@ -277,7 +282,7 @@ export class oAuthSettings {
this.uiHelper.activateSpinner(button);
- const success = await this.oauthService.signOut(this.component.data.oauth_con_id);
+ const success = await this.oauthService.signOut(this.component.data[this.setting_name]);
if (success) {
await this.uiHelper.updateAuthButtonState(false);
@@ -297,7 +302,7 @@ export class oAuthSettings {
return;
}
- const currentValue = this.component.data.oauth_con_id;
+ const currentValue = this.component.data[this.setting_name];
try {
const connections = await this.oauthService.loadConnections();
@@ -311,7 +316,7 @@ export class oAuthSettings {
await this.oauthService.saveConnection(connectionId, formData);
// Update component state
- this.component.data.oauth_con_id = connectionId;
+ this.component.data[this.setting_name] = connectionId;
await this.updateOAuthConnectionOptions();
this.component.refreshSettingsSidebar();
this.uiHelper.updateOAuthActionButtons(this.hasValidConnection());
@@ -330,7 +335,7 @@ export class oAuthSettings {
* Handles OAuth connection selection change
*/
private async handleOAuthConnectionChange(selectedValue: string): Promise<void> {
- this.component.data.oauth_con_id = selectedValue;
+ this.component.data[this.setting_name] = selectedValue;
if (!selectedValue || selectedValue === 'None') {
await this.uiHelper?.updateAuthButtonState(false);
@@ -369,7 +374,7 @@ export class oAuthSettings {
this.uiHelper.activateSpinner(authButton);
const isAuthenticated =
- this.component.data.oauth_con_id && this.component.data.oauth_con_id !== 'None'
+ this.component.data[this.setting_name] && this.component.data[this.setting_name] !== 'None'
? await this.checkAuthentication()
: false;
@@ -381,14 +386,16 @@ export class oAuthSettings {
*/
private async checkAuthentication(): Promise<boolean> {
if (!this.oauthService) return false;
- return this.oauthService.checkAuthentication(this.component.data.oauth_con_id);
+ return this.oauthService.checkAuthentication(this.component.data[this.setting_name]);
}
/**
* Helper to check if current connection is valid
*/
private hasValidConnection(): boolean {
- return !!(this.component.data.oauth_con_id && this.component.data.oauth_con_id !== 'None');
+ return !!(
+ this.component.data[this.setting_name] && this.component.data[this.setting_name] !== 'None'
+ );
}
/**
diff --git a/packages/app/src/builder-ui/types/component.types.ts b/packages/app/src/builder-ui/types/component.types.ts
index 396d564f..d4fcfb97 100644
--- a/packages/app/src/builder-ui/types/component.types.ts
+++ b/packages/app/src/builder-ui/types/component.types.ts
@@ -37,6 +37,7 @@ export type DrawSettingsType = {
displayName?: string;
cssClass?: string;
iconCSSClass?: string;
+ icon?: string;
showSettings?: boolean;
addOutputButton?: string;
addInputButton?: string;
diff --git a/packages/app/src/builder-ui/ui/form/misc.ts b/packages/app/src/builder-ui/ui/form/misc.ts
index 147875ff..83f009a1 100644
--- a/packages/app/src/builder-ui/ui/form/misc.ts
+++ b/packages/app/src/builder-ui/ui/form/misc.ts
@@ -135,6 +135,8 @@ export function createTemplateVarBtn(
cls = ' btn-field-var';
} else if (type === 'global') {
cls = ' btn-global-var';
+ } else if (type === 'trigger') {
+ cls = ' btn-trigger-var';
}
button.className = `button primary small template-var-button${cls}`;
@@ -170,6 +172,9 @@ export function generateTemplateVarBtns(
const globalVarWrapper = document.createElement('div');
globalVarWrapper.classList.add('global-vars-wrapper');
+ const triggerVarWrapper = document.createElement('div');
+ triggerVarWrapper.classList.add('trigger-vars-wrapper');
+
if (variables?.size > 0) {
for (const [key, value] of variables) {
if (key) {
@@ -178,9 +183,15 @@ export function generateTemplateVarBtns(
switch (value?.type) {
case 'field':
fieldVarWrapper.appendChild(button);
+ wrapper.classList.add('fields');
break;
case 'global':
globalVarWrapper.appendChild(button);
+ wrapper.classList.add('globals');
+ break;
+ case 'trigger':
+ triggerVarWrapper.appendChild(button);
+ wrapper.classList.add('triggers');
break;
default:
// Default case handles standard input types (e.g. Any, String, Binary) by adding them to inputVarWrapper
@@ -199,6 +210,9 @@ export function generateTemplateVarBtns(
if (globalVarWrapper?.children?.length) {
wrapper.appendChild(globalVarWrapper);
}
+ if (triggerVarWrapper?.children?.length) {
+ wrapper.appendChild(triggerVarWrapper);
+ }
wrapper.style.display = 'block';
} else {
@@ -235,7 +249,10 @@ export function handleTemplateVars(targetElm) {
.querySelector('[data-template-vars=true]') as HTMLTextAreaElement) ||
(buttonElm
.closest('.form-group')
- .querySelector('[data-agent-vars=true]') as HTMLTextAreaElement);
+ .querySelector('[data-agent-vars=true]') as HTMLTextAreaElement) ||
+ (buttonElm
+ .closest('.form-group')
+ .querySelector('[data-trigger-vars=true]') as HTMLTextAreaElement);
// changing select element does not remove template-var-buttons and these buttons can add inputs to readonly field
if (!focusedField.hasAttribute('readonly')) {
@@ -347,6 +364,31 @@ export function handleTemplateVars(targetElm) {
if (!buttonsContainer) return;
+ const focusedElmParent = clickedElm.closest('.form-group');
+ focusedElmParent.appendChild(buttonsContainer);
+ } else if (
+ clickedElm.getAttribute('data-trigger-vars') === 'true' &&
+ !clickedElm?.hasAttribute('readonly')
+ ) {
+ console.log('clicked elm', clickedElm);
+ const triggersList = clickedElm.getAttribute('data-triggers')?.split(',');
+ const triggersSchema = triggersList.map((triggerId) => {
+ const component = document.getElementById(triggerId);
+ const control = (component as any)?._control;
+ return control?.schema;
+ });
+
+ //generate variables from schema
+ let variables = new Map();
+ for (const schema of triggersSchema) {
+ const triggerVariables = extractTriggerVariables(schema);
+ for (const [key, value] of triggerVariables) {
+ variables.set(key, value);
+ }
+ }
+
+ const buttonsContainer = generateTemplateVarBtns(variables, compUid) as HTMLDivElement;
+ if (!buttonsContainer) return;
const focusedElmParent = clickedElm.closest('.form-group');
focusedElmParent.appendChild(buttonsContainer);
} else {
@@ -358,6 +400,21 @@ export function handleTemplateVars(targetElm) {
}
};
}
+function extractTriggerVariables(schema: any, path = '') {
+ let variables = new Map();
+
+ for (const key in schema) {
+ const fullPath = `${path?.trim() ? `${path}.` : ''}${key}`;
+ variables.set(fullPath, { var: `{{${fullPath}}}`, type: 'trigger' });
+ if (typeof schema[key] === 'object') {
+ const nestedVariables = extractTriggerVariables(schema[key], fullPath);
+ for (const [nestedKey, nestedValue] of nestedVariables) {
+ variables.set(nestedKey, nestedValue);
+ }
+ }
+ }
+ return variables;
+}
export const setTabIndex = (selector: string): void => {
// prevent to focus the fake textarea with tab key
diff --git a/packages/app/static/css/smyth-components.css b/packages/app/static/css/smyth-components.css
index 74de7de3..c1b0a56d 100644
--- a/packages/app/static/css/smyth-components.css
+++ b/packages/app/static/css/smyth-components.css
@@ -50,7 +50,6 @@
height: 60px;
}
-
.component.Async .output-endpoint:not(.default) .name .label::before {
content: '[ async ]';
font-size: 10px;
@@ -268,4 +267,85 @@
.Note .note-markdown li {
display: list-item !important;
-}
\ No newline at end of file
+}
+
+/*Trigger styles*/
+
+.component.Trigger {
+ min-height: 100px;
+ min-width: 280px;
+ border-radius: 100px 10px 10px 100px;
+}
+
+.component.Trigger .internal-name {
+ padding-left: 40px;
+}
+
+.component.Trigger .title-bar-top {
+ height: 100px;
+}
+.debug-enabled .component.Trigger .debug-bar {
+ position: absolute;
+ width: calc(100% - 85px);
+ margin-left: 85px !important;
+ margin-top: 10px;
+}
+.component.Trigger .title-bar {
+ padding-top: 0px !important;
+ padding-bottom: 0px !important;
+ position: absolute !important;
+ top: 0 !important;
+ left: 0 !important;
+ width: 100% !important;
+ height: 100% !important;
+}
+.component.Trigger .title-bar .title {
+ position: absolute;
+ bottom: 0px;
+ margin-left: 100px;
+ padding: 5px 0px;
+ color: #888;
+}
+.component.Trigger .title-bar .icon {
+ border-radius: 100px 10px 10px 100px;
+ padding: 10px;
+}
+.component.Trigger .title-bar .icon img {
+ height: 100%;
+ padding: 5px 0px;
+}
+
+.component.Trigger .ep-control {
+ display: none !important;
+ visibility: hidden !important;
+}
+
+.component.Trigger .output-endpoint button {
+ visibility: hidden !important;
+ display: none !important;
+ width: 0px !important;
+ height: 0px !important;
+ padding: 0px !important;
+ margin: 0px !important;
+ border: 0px !important;
+ opacity: 0 !important;
+ pointer-events: none !important;
+ cursor: default !important;
+ user-select: none !important;
+}
+
+.component.Trigger .output-endpoint .name .label {
+ color: #55ad26;
+}
+
+.component.Trigger .output-container {
+ margin-top: 10px;
+}
+
+.component.Trigger .cpt-overlay {
+ border-radius: 100px 10px 10px 100px !important;
+}
+
+.component.Trigger .cpt-overlay .content {
+ margin: 0px 0px !important;
+}
diff --git a/packages/app/static/img/triggers/gmail.svg b/packages/app/static/img/triggers/gmail.svg
new file mode 100644
index 00000000..47b9cf57
--- /dev/null
+++ b/packages/app/static/img/triggers/gmail.svg
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
+<svg xmlns="http://www.w3.org/2000/svg"
+aria-label="Gmail" role="img"
+viewBox="0 0 512 512"><rect
+width="512" height="512"
+rx="15%"
+fill="#ffffff"/><path d="M158 391v-142l-82-63V361q0 30 30 30" fill="#4285f4"/><path d="M 154 248l102 77l102-77v-98l-102 77l-102-77" fill="#ea4335"/><path d="M354 391v-142l82-63V361q0 30-30 30" fill="#34a853"/><path d="M76 188l82 63v-98l-30-23c-27-21-52 0-52 26" fill="#c5221f"/><path d="M436 188l-82 63v-98l30-23c27-21 52 0 52 26" fill="#fbbc04"/></svg>
\ No newline at end of file
diff --git a/packages/app/static/img/triggers/job-scheduler.svg b/packages/app/static/img/triggers/job-scheduler.svg
new file mode 100644
index 00000000..22cdd6a7
--- /dev/null
+++ b/packages/app/static/img/triggers/job-scheduler.svg
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
+<svg fill="#000000" width="800px" height="800px" viewBox="0 0 24 24" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg">
+<path d="M9,24H1a1,1,0,0,1,0-2H9a1,1,0,0,1,0,2Z
+M7,20H1a1,1,0,0,1,0-2H7a1,1,0,0,1,0,2Z
+M5,16H1a1,1,0,0,1,0-2H5a1,1,0,0,1,0,2Z
+M13,23.955a1,1,0,0,1-.089-2A10,10,0,1,0,2.041,11.09a1,1,0,0,1-1.992-.18A12,12,0,0,1,24,12,11.934,11.934,0,0,1,13.09,23.951C13.06,23.954,13.029,23.955,13,23.955Z
+M12,6a1,1,0,0,0-1,1v5a1,1,0,0,0,.293.707l3,3a1,1,0,0,0,1.414-1.414L13,11.586V7A1,1,0,0,0,12,6Z"/></svg>
\ No newline at end of file
diff --git a/packages/app/static/img/triggers/whatsapp.svg b/packages/app/static/img/triggers/whatsapp.svg
new file mode 100644
index 00000000..1636ec0f
--- /dev/null
+++ b/packages/app/static/img/triggers/whatsapp.svg
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg height="800px" width="800px" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
+ viewBox="0 0 58 58" xml:space="preserve">
+<g>
+ <path style="fill:#2CB742;" d="M0,58l4.988-14.963C2.457,38.78,1,33.812,1,28.5C1,12.76,13.76,0,29.5,0S58,12.76,58,28.5
+ S45.24,57,29.5,57c-4.789,0-9.299-1.187-13.26-3.273L0,58z"/>
+ <path style="fill:#FFFFFF;" d="M47.683,37.985c-1.316-2.487-6.169-5.331-6.169-5.331c-1.098-0.626-2.423-0.696-3.049,0.42
+ c0,0-1.577,1.891-1.978,2.163c-1.832,1.241-3.529,1.193-5.242-0.52l-3.981-3.981l-3.981-3.981c-1.713-1.713-1.761-3.41-0.52-5.242
+ c0.272-0.401,2.163-1.978,2.163-1.978c1.116-0.627,1.046-1.951,0.42-3.049c0,0-2.844-4.853-5.331-6.169
+ c-1.058-0.56-2.357-0.364-3.203,0.482l-1.758,1.758c-5.577,5.577-2.831,11.873,2.746,17.45l5.097,5.097l5.097,5.097
+ c5.577,5.577,11.873,8.323,17.45,2.746l1.758-1.758C48.048,40.341,48.243,39.042,47.683,37.985z"/>
+</g>
+</svg>
\ No newline at end of file