From 644a35a32adbf045814e71e07a71609b6f87d004 Mon Sep 17 00:00:00 2001 From: Timothy Carambat <rambat1010@gmail.com> Date: Fri, 13 Sep 2024 17:46:24 -0700 Subject: [PATCH] Patch UI bug with agent skill web-search and sql-connector (#2282) * Patch UI bug with agent skill * wrap call in try/catch for failures res?. optional call for settings since null is default * uncheck --- .../Admin/Agents/SQLConnectorSelection/index.jsx | 15 ++++++++++----- .../Admin/Agents/WebSearchSelection/index.jsx | 9 +++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx b/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx index d7eaa23c1..846c5b965 100644 --- a/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx +++ b/frontend/src/pages/Admin/Agents/SQLConnectorSelection/index.jsx @@ -1,21 +1,26 @@ -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((res) => setConnections(res?.settings?.agent_sql_connections ?? [])) + .catch(() => setConnections([])); + }, []); + return ( <> <div className="p-2"> diff --git a/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx b/frontend/src/pages/Admin/Agents/WebSearchSelection/index.jsx index fd201fb90..345d3ef05 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((res) => + setSelectedProvider(res?.settings?.agent_search_provider ?? "none") + ) + .catch(() => setSelectedProvider("none")); + }, []); const selectedSearchProviderObject = SEARCH_PROVIDERS.find( (provider) => provider.value === selectedProvider -- GitLab