From aacbab74dbd0791d90a027c709523c6219284ce2 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Fri, 13 Sep 2024 17:38:37 -0700 Subject: [PATCH 1/3] Patch UI bug with agent skill --- .../Agents/SQLConnectorSelection/index.jsx | 17 ++++++++++++----- .../Admin/Agents/WebSearchSelection/index.jsx | 9 +++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx b/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx index d7eaa23c159..31f0398326b 100644 --- a/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx +++ b/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx @@ -1,21 +1,28 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import DBConnection from "./DBConnection"; import { Plus, Database } from "@phosphor-icons/react"; import NewSQLConnection from "./NewConnectionModal"; import { useModal } from "@/hooks/useModal"; import SQLAgentImage from "@/media/agents/sql-agent.png"; +import Admin from "@/models/admin"; export default function AgentSQLConnectorSelection({ skill, - settings, + settings, // unused. toggleSkill, enabled = false, setHasChanges, }) { const { isOpen, openModal, closeModal } = useModal(); - const [connections, setConnections] = useState( - settings?.preferences?.agent_sql_connections || [] - ); + const [connections, setConnections] = useState([]); + useEffect(() => { + Admin.systemPreferencesByFields(["agent_sql_connections"]) + .then(({ settings }) => + setConnections(settings?.agent_sql_connections || []) + ) + .catch(() => setConnections([])); + }, []); + return ( <>
diff --git a/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx b/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx index fd201fb90c7..271cccd3a48 100644 --- a/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx +++ b/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx @@ -1,4 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; +import Admin from "@/models/admin"; import AnythingLLMIcon from "@/media/logo/anything-llm-icon.png"; import GoogleSearchIcon from "./icons/google.png"; import SearchApiIcon from "./icons/searchapi.png"; @@ -119,8 +120,12 @@ export default function AgentWebSearchSelection({ }, [searchQuery, selectedProvider]); useEffect(() => { - setSelectedProvider(settings?.preferences?.agent_search_provider ?? "none"); - }, [settings?.preferences?.agent_search_provider]); + Admin.systemPreferencesByFields(["agent_search_provider"]) + .then(({ settings }) => + setSelectedProvider(settings?.agent_search_provider ?? "none") + ) + .catch(() => setSelectedProvider("none")); + }, []); const selectedSearchProviderObject = SEARCH_PROVIDERS.find( (provider) => provider.value === selectedProvider From 29b83791ff38075cd5787a4ad69f43f16872c78b Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Fri, 13 Sep 2024 17:43:58 -0700 Subject: [PATCH 2/3] wrap call in try/catch for failures res?. optional call for settings since null is default --- frontend/src/models/admin.js | 29 +++++++++++-------- .../Agents/SQLConnectorSelection/index.jsx | 4 +-- .../Admin/Agents/WebSearchSelection/index.jsx | 4 +-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/frontend/src/models/admin.js b/frontend/src/models/admin.js index 336e98789b4..76ae1979be0 100644 --- a/frontend/src/models/admin.js +++ b/frontend/src/models/admin.js @@ -176,18 +176,23 @@ const Admin = { * @returns {Promise<{settings: Object, error: string}>} - System preferences object */ systemPreferencesByFields: async (labels = []) => { - return await fetch( - `${API_BASE}/admin/system-preferences-for?labels=${labels.join(",")}`, - { - method: "GET", - headers: baseHeaders(), - } - ) - .then((res) => res.json()) - .catch((e) => { - console.error(e); - return null; - }); + try { + return await fetch( + `${API_BASE}/admin/system-preferences-for?labels=${labels.join(",")}`, + { + method: "GET", + headers: baseHeaders(), + } + ) + .then((res) => res.json()) + .catch((e) => { + console.error(e); + return null; + }); + } catch (e) { + console.error(e); + return null; + } }, updateSystemPreferences: async (updates = {}) => { return await fetch(`${API_BASE}/admin/system-preferences`, { diff --git a/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx b/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx index 31f0398326b..846c5b96572 100644 --- a/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx +++ b/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx @@ -17,9 +17,7 @@ export default function AgentSQLConnectorSelection({ const [connections, setConnections] = useState([]); useEffect(() => { Admin.systemPreferencesByFields(["agent_sql_connections"]) - .then(({ settings }) => - setConnections(settings?.agent_sql_connections || []) - ) + .then((res) => setConnections(res?.settings?.agent_sql_connections ?? [])) .catch(() => setConnections([])); }, []); diff --git a/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx b/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx index 271cccd3a48..345d3ef05e2 100644 --- a/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx +++ b/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx @@ -121,8 +121,8 @@ export default function AgentWebSearchSelection({ useEffect(() => { Admin.systemPreferencesByFields(["agent_search_provider"]) - .then(({ settings }) => - setSelectedProvider(settings?.agent_search_provider ?? "none") + .then((res) => + setSelectedProvider(res?.settings?.agent_search_provider ?? "none") ) .catch(() => setSelectedProvider("none")); }, []); From edf3f1efc28826207c4ecc494cf68c1cf48bec57 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Fri, 13 Sep 2024 17:45:53 -0700 Subject: [PATCH 3/3] uncheck --- frontend/src/models/admin.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/frontend/src/models/admin.js b/frontend/src/models/admin.js index 76ae1979be0..336e98789b4 100644 --- a/frontend/src/models/admin.js +++ b/frontend/src/models/admin.js @@ -176,23 +176,18 @@ const Admin = { * @returns {Promise<{settings: Object, error: string}>} - System preferences object */ systemPreferencesByFields: async (labels = []) => { - try { - return await fetch( - `${API_BASE}/admin/system-preferences-for?labels=${labels.join(",")}`, - { - method: "GET", - headers: baseHeaders(), - } - ) - .then((res) => res.json()) - .catch((e) => { - console.error(e); - return null; - }); - } catch (e) { - console.error(e); - return null; - } + return await fetch( + `${API_BASE}/admin/system-preferences-for?labels=${labels.join(",")}`, + { + method: "GET", + headers: baseHeaders(), + } + ) + .then((res) => res.json()) + .catch((e) => { + console.error(e); + return null; + }); }, updateSystemPreferences: async (updates = {}) => { return await fetch(`${API_BASE}/admin/system-preferences`, {