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.

Enhance auto-save functionality and update data handling in APICall and component utilities

Muhammad Hamza Khane721fa15ff95
diff --git a/packages/app/src/builder-ui/components/APICall.class.ts b/packages/app/src/builder-ui/components/APICall.class.ts
index cf044007..ad833296 100644
--- a/packages/app/src/builder-ui/components/APICall.class.ts
+++ b/packages/app/src/builder-ui/components/APICall.class.ts
@@ -1117,6 +1117,11 @@ export class APICall extends Component {
this.handleBodyEditButtons(sidebar);
await this.addRightSidebarFunction(sidebar);
+ // Body field Ace Editor event listener is handled in handleBodyEditButtons method
+
+ // Headers field uses key-value editor which dispatches change events
+ // The auto-save system now listens for change events on textareas
+
// Update the OAuth action button when sidebar opens
// Note: updateAuthenticationButtonState is already called in addRightSidebarFunction -> setCallbackUrl
// So we only need to update the action button here
@@ -1180,6 +1185,24 @@ export class APICall extends Component {
if (_editor) {
_editor.style.minHeight = '80px !important';
}
+
+ // Add event listener to the Ace editor for auto-save
+ const body_editor = bodyElm._editor;
+ if (body_editor) {
+ body_editor.session.setOption('useWorker', false);
+ body_editor.clearSelection();
+
+ // Remove any existing event listeners to avoid duplicates
+ body_editor.off('change');
+
+ // Add event listener to the Ace editor for auto-save
+ body_editor.on('change', () => {
+ // Trigger the form's input event to activate auto-save
+ const inputEvent = new Event('input', { bubbles: true });
+ bodyElm.dispatchEvent(inputEvent);
+ });
+ }
+
if (value !== this.data.contentType) {
bodyElm.value = '';
this.data.body = '';
@@ -1194,7 +1217,7 @@ export class APICall extends Component {
bodyElm?._editor?.setValue('');
this.data.body = '';
}
- this.data.contentType = value;
+ // Don't update this.data.contentType directly - let the form save mechanism handle it
}, 150);
}
@@ -1542,25 +1565,16 @@ export class APICall extends Component {
// First handle the selection change
if (!selectedValue || selectedValue === 'None') {
// Clear OAuth-related fields
- this.data.oauth_con_id = 'None';
+ // Don't update this.data.oauth_con_id directly - let the form save mechanism handle it
const oauth_button: any = sidebar?.querySelector(`[data-field-name="authenticate"] button`);
if (oauth_button) {
oauth_button.innerHTML = 'Authenticate';
}
} else {
- // Set the oauth_con_id in the component's data
- this.data.oauth_con_id = selectedValue;
-
- // Always synchronize the component's legacy field (oauthService) with the selected connection
- // to avoid stale/broken state across legacy/new structures.
- const selectedConn = this.oauthConnections[selectedValue];
- const selectedOauthInfo = this.getConnectionOauthInfo(selectedConn, selectedValue);
- if (selectedOauthInfo?.service) {
- // Store a user-friendly value for legacy consumers
- this.data.oauthService = mapInternalToServiceName(selectedOauthInfo.service);
- } else {
- this.data.oauthService = 'None';
- }
+ // Don't update this.data.oauth_con_id directly - let the form save mechanism handle it
+
+ // Don't update this.data.oauthService directly - let the form save mechanism handle it
+ // The oauthService field will be updated through the form save mechanism
// If the selection has changed, check authentication status and update button
if (selectedValue !== previousValue) {
diff --git a/packages/app/src/builder-ui/utils/component.utils/index.ts b/packages/app/src/builder-ui/utils/component.utils/index.ts
index 477afccc..533c4565 100644
--- a/packages/app/src/builder-ui/utils/component.utils/index.ts
+++ b/packages/app/src/builder-ui/utils/component.utils/index.ts
@@ -50,14 +50,19 @@ export async function handleKvFieldEditBtn(
if (queryParamValues) {
const data = JSON.stringify(queryParamValues?.[`_${fieldName}`] || {}, null, 2);
- this.data[fieldName] = data;
+ // Don't update this.data directly - let the form save mechanism handle it
+ // this.data[fieldName] = data;
const field = document.getElementById(fieldName) as HTMLTextAreaElement;
field.value = data;
//dispatch custom event for consistency
- const event = new Event('change');
- field.dispatchEvent(event);
+ const changeEvent = new Event('change');
+ field.dispatchEvent(changeEvent);
+
+ // Also dispatch input event for auto-save
+ const inputEvent = new Event('input', { bubbles: true });
+ field.dispatchEvent(inputEvent);
}
}