From 0a97ad3915790049a769d2e2f43416efa79a2402 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 17 Dec 2024 12:45:58 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Fix:=20Update=20Agent?= =?UTF-8?q?=20Cache=20and=20Improve=20Actions=20UI=20(#5020)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * style: improve a11y, localization, and styling consistency of actions input form * refactor: move agent mutations to dedicated module * fix: update agent cache on agent deletion + delete and update actions --- .../SidePanel/Agents/ActionsInput.tsx | 87 +++--- .../SidePanel/Agents/ActionsPanel.tsx | 10 +- .../SidePanel/Builder/ActionsInput.tsx | 37 ++- .../SidePanel/Builder/ActionsPanel.tsx | 6 +- client/src/data-provider/Agents/index.ts | 1 + client/src/data-provider/Agents/mutations.ts | 265 ++++++++++++++++++ client/src/data-provider/mutations.ts | 248 ---------------- client/src/localization/languages/Eng.ts | 3 + 8 files changed, 337 insertions(+), 320 deletions(-) create mode 100644 client/src/data-provider/Agents/mutations.ts diff --git a/client/src/components/SidePanel/Agents/ActionsInput.tsx b/client/src/components/SidePanel/Agents/ActionsInput.tsx index f1bc3aecd10..a40be180d1f 100644 --- a/client/src/components/SidePanel/Agents/ActionsInput.tsx +++ b/client/src/components/SidePanel/Agents/ActionsInput.tsx @@ -16,10 +16,10 @@ import type { ActionAuthForm } from '~/common'; import type { Spec } from './ActionsTable'; import { ActionsTable, columns } from './ActionsTable'; import { useUpdateAgentAction } from '~/data-provider'; -import { cn, removeFocusOutlines } from '~/utils'; import { useToastContext } from '~/Providers'; import useLocalize from '~/hooks/useLocalize'; import { Spinner } from '~/components/svg'; +import { logger } from '~/utils'; const debouncedValidation = debounce( (input: string, callback: (result: ValidationResult) => void) => { @@ -56,12 +56,13 @@ export default function ActionsInput({ const [functions, setFunctions] = useState(null); useEffect(() => { - if (!action?.metadata?.raw_spec) { + const rawSpec = action?.metadata.raw_spec ?? ''; + if (!rawSpec) { return; } - setInputValue(action.metadata.raw_spec); - debouncedValidation(action.metadata.raw_spec, handleResult); - }, [action?.metadata?.raw_spec]); + setInputValue(rawSpec); + debouncedValidation(rawSpec, handleResult); + }, [action?.metadata.raw_spec]); useEffect(() => { if (!validationResult || !validationResult.status || !validationResult.spec) { @@ -94,15 +95,16 @@ export default function ActionsInput({ }, onError(error) { showToast({ - message: (error as Error)?.message ?? localize('com_assistants_update_actions_error'), + message: (error as Error).message || localize('com_assistants_update_actions_error'), status: 'error', }); }, }); const saveAction = handleSubmit((authFormData) => { - console.log('authFormData', authFormData); - if (!agent_id) { + logger.log('actions', 'saving action', authFormData); + const currentAgentId = agent_id ?? ''; + if (!currentAgentId) { // alert user? return; } @@ -171,7 +173,7 @@ export default function ActionsInput({ action_id, metadata, functions, - agent_id, + agent_id: currentAgentId, }); }); @@ -186,17 +188,34 @@ export default function ActionsInput({ debouncedValidation(newValue, handleResult); }; + const getButtonContent = () => { + if (updateAgentAction.isLoading) { + return ; + } + + if (action?.action_id != null && action.action_id) { + return localize('com_ui_update'); + } + + return localize('com_ui_create'); + }; + return ( <>
- +
{/* */}
-
+