From 41f0b1f22cd493169654c36b7452f9312be166fd Mon Sep 17 00:00:00 2001 From: yahyha benzha Date: Sun, 25 Feb 2024 17:48:48 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20delete=20out=20of=20sync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/AgentInputs/HttpToolInput.tsx | 39 ++++++++++++++----- .../components/AgentInputs/ToolsInput.tsx | 17 ++++---- apps/dashboard/components/HttpToolForm.tsx | 8 ++-- .../LeadCaptureToolFormInput.tsx | 4 +- .../pages/agents/[agentId]/index.tsx | 6 +-- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/apps/dashboard/components/AgentInputs/HttpToolInput.tsx b/apps/dashboard/components/AgentInputs/HttpToolInput.tsx index 6101e6e3f..a220a2f0e 100644 --- a/apps/dashboard/components/AgentInputs/HttpToolInput.tsx +++ b/apps/dashboard/components/AgentInputs/HttpToolInput.tsx @@ -66,6 +66,16 @@ export type Fields = }[] | undefined; +type KeyValueNames = + | 'config.queryParameters' + | 'config.pathVariables' + | 'config.body' + | 'config.headers' + | `tools.${number}.config.queryParameters` + | `tools.${number}.config.pathVariables` + | `tools.${number}.config.body` + | `tools.${number}.config.headers`; + const KeyValueFieldArray = ({ name, label, @@ -77,13 +87,13 @@ const KeyValueFieldArray = ({ | 'config.pathVariables' | 'config.body' | 'config.headers' - | 'tools.0.config.queryParameters' - | 'tools.0.config.pathVariables' - | 'tools.0.config.body' - | 'tools.0.config.headers'; + | `tools.${number}.config.queryParameters` + | `tools.${number}.config.pathVariables` + | `tools.${number}.config.body` + | `tools.${number}.config.headers`; label?: string; userOnly?: boolean; - prefix: '' | 'tools.0.'; + prefix: `tools.${number}.` | ''; }) => { const methods = useFormContext(); @@ -286,7 +296,6 @@ const KeyValueFieldArray = ({ (); - const prefix: 'tools.0.' | '' = name ? `${name}.` : ''; + // Narrow down to prevent inference as string. + const prefix: `tools.${number}.` | '' = name ? `${name}.` : ''; const templatesModal = useModal(); const [withApprovalChecked] = methods.watch([`${prefix}config.withApproval`]); const [methodValue] = methods.watch([`${prefix}config.method`]); diff --git a/apps/dashboard/components/AgentInputs/ToolsInput.tsx b/apps/dashboard/components/AgentInputs/ToolsInput.tsx index 51938cc0e..d235f5fab 100644 --- a/apps/dashboard/components/AgentInputs/ToolsInput.tsx +++ b/apps/dashboard/components/AgentInputs/ToolsInput.tsx @@ -137,7 +137,7 @@ function ToolsInput({}: Props) { `tools.${currentToolIndex}.config.method`, `tools.${currentToolIndex}.config.pathVariables`, `tools.${currentToolIndex}.config.queryParameters`, - ] as any); + ]); const newDatastoreModal = useModal(); const newApiToolForm = useModal(); @@ -454,6 +454,8 @@ function ToolsInput({}: Props) { shouldValidate: true, }); newApiToolForm.close(); + // auto save. + btnSubmitRef?.current?.click(); }} /> @@ -550,7 +552,7 @@ function ToolsInput({}: Props) { > {currentToolIndex >= 0 && ( - + { isToolValidRef.current = state; }} - name={`tools.${currentToolIndex}` as `tools.0`} + name={`tools.${currentToolIndex}`} handleCloseModal={validateToolModal.close} /> @@ -577,9 +579,10 @@ function ToolsInput({}: Props) { if (!isToolValidRef.current && formState.isValid) { validateToolModal.open(); return; + } else if (isToolValidRef.current) { + editApiToolForm.close(); + btnSubmitRef?.current?.click(); } - editApiToolForm.close(); - btnSubmitRef?.current?.click(); }} > {isToolValidRef.current ? 'Update' : 'Validate Config'} @@ -599,9 +602,7 @@ function ToolsInput({}: Props) { > {currentToolIndex >= 0 && ( - + @@ -543,7 +541,7 @@ export default function AgentPage() { {({ mutation }) => (