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 debounced auto-save functionality in OverviewWidgetsContainer component

Muhammad Hamza Khan448be15a0089
diff --git a/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx b/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx
index 5ddd3925..4efadae6 100644
--- a/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx
+++ b/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx
@@ -437,34 +437,41 @@ const OverviewWidgetsContainer = ({ isWriteAccess }: { isWriteAccess: boolean })
[chatbotEmbodiment, settingsQuery.data],
);
+ const [callAPI, setCallAPI] = useState(false);
+
// Auto-save with debouncing
useEffect(() => {
- // Skip auto-save on initial mount
- if (!agentQuery.data || !settingsQuery.data) {
- return;
- }
+ const currentTimeoutId = setTimeout(() => {
+ // Skip auto-save on initial mount
+ if (!agentQuery.data || !settingsQuery.data) {
+ return;
+ }
- // Check if fields have actually changed
- const hasChanges =
- currentFormValues.current.name?.trim() !== initialFormValues.current.name ||
- currentFormValues.current.shortDescription?.trim() !==
- initialFormValues.current.shortDescription ||
- currentFormValues.current.chatGptModel !== initialFormValues.current.chatGptModel ||
- currentFormValues.current.behavior?.trim() !== initialFormValues.current.behavior;
+ // Check if fields have actually changed
+ const hasChanges =
+ currentFormValues.current.name?.trim() !== initialFormValues.current.name ||
+ currentFormValues.current.shortDescription?.trim() !==
+ initialFormValues.current.shortDescription ||
+ currentFormValues.current.chatGptModel !== initialFormValues.current.chatGptModel ||
+ currentFormValues.current.behavior?.trim() !== initialFormValues.current.behavior;
- if (!hasChanges || !isWriteAccess || savingStatus !== 'idle') {
- return;
- }
+ if (!hasChanges || !isWriteAccess || savingStatus !== 'idle') {
+ return;
+ }
- // Debounce the save by 500ms
- const timeoutId = setTimeout(() => {
- formik.submitForm();
- clearTimeout(timeoutId);
+ setCallAPI(true);
}, 500);
- return () => clearTimeout(timeoutId);
+ return () => clearTimeout(currentTimeoutId);
}, [formik, isWriteAccess, savingStatus, agentQuery.data, settingsQuery.data]);
+ useEffect(() => {
+ if (callAPI) {
+ formik.submitForm();
+ setCallAPI(false);
+ }
+ }, [callAPI, formik]);
+
const updateCurrentFormValues = useCallback((values: FormValues) => {
currentFormValues.current = { ...currentFormValues.current, ...values };
}, []);