diff --git a/web/src/app/chat/ChatPage.tsx b/web/src/app/chat/ChatPage.tsx index 0e48246fc87..51c8337bc0a 100644 --- a/web/src/app/chat/ChatPage.tsx +++ b/web/src/app/chat/ChatPage.tsx @@ -1224,8 +1224,6 @@ export function ChatPage({ } else if (Object.hasOwn(packet, "error")) { error = (packet as StreamingError).error; stackTrace = (packet as StreamingError).stack_trace; - console.log("error", error); - console.log("stackTrace", stackTrace); } else if (Object.hasOwn(packet, "message_id")) { finalMessage = packet as BackendMessage; } else if (Object.hasOwn(packet, "stop_reason")) { @@ -1605,7 +1603,7 @@ export function ChatPage({ {!shouldShowWelcomeModal && !shouldDisplaySourcesIncompleteModal && showApiKeyModal && ( - setShowApiKeyModal(false)} user={user} /> + setShowApiKeyModal(false)} /> )} {shouldShowWelcomeModal ? "should show welcome modal" diff --git a/web/src/app/search/page.tsx b/web/src/app/search/page.tsx index 2fabf8913a5..df8a4b4115a 100644 --- a/web/src/app/search/page.tsx +++ b/web/src/app/search/page.tsx @@ -5,7 +5,6 @@ import { } from "@/lib/userSS"; import { redirect } from "next/navigation"; import { HealthCheckBanner } from "@/components/health/healthcheck"; -import { ApiKeyModal } from "@/components/llm/ApiKeyModal"; import { fetchSS } from "@/lib/utilsSS"; import { CCPairBasicInfo, DocumentSet, Tag, User } from "@/lib/types"; import { cookies } from "next/headers"; @@ -187,10 +186,6 @@ export default async function Home() { {shouldShowWelcomeModal && } - {!shouldShowWelcomeModal && - !shouldDisplayNoSourcesModal && - !shouldDisplaySourcesIncompleteModal && } - {shouldDisplayNoSourcesModal && } {shouldDisplaySourcesIncompleteModal && ( diff --git a/web/src/components/chat_search/NoCredentialText.tsx b/web/src/components/chat_search/NoCredentialText.tsx index 3dc7c07ac58..a05b21230bd 100644 --- a/web/src/components/chat_search/NoCredentialText.tsx +++ b/web/src/components/chat_search/NoCredentialText.tsx @@ -1,37 +1,13 @@ -import { WellKnownLLMProviderDescriptor } from "@/app/admin/configuration/llm/interfaces"; -import { useEffect, useState } from "react"; -import { checkLlmProvider } from "../initialSetup/welcome/lib"; -import { useUser } from "../user/UserProvider"; -import { useRouter } from "next/navigation"; +import { useProviderStatus } from "./hooks"; export default function NoCredentialText({ showConfigureAPIKey, }: { showConfigureAPIKey: () => void; }) { - const { user } = useUser(); - const router = useRouter(); - const [validProviderExists, setValidProviderExists] = useState(true); - const [providerOptions, setProviderOptions] = useState< - WellKnownLLMProviderDescriptor[] - >([]); + const { shouldShowConfigurationNeeded } = useProviderStatus(); - useEffect(() => { - async function fetchProviderInfo() { - const { providers, options, defaultCheckSuccessful } = - await checkLlmProvider(user); - setValidProviderExists(providers.length > 0 && defaultCheckSuccessful); - setProviderOptions(options); - } - - fetchProviderInfo(); - }, [router]); - - // don't show if - // (1) a valid provider has been setup or - // (2) there are no provider options (e.g. user isn't an admin) - // (3) user explicitly hides the modal - if (validProviderExists || !providerOptions.length) { + if (!shouldShowConfigurationNeeded) { return null; } diff --git a/web/src/components/chat_search/hooks.ts b/web/src/components/chat_search/hooks.ts index 3377d9172a0..4d7cc5ddc0b 100644 --- a/web/src/components/chat_search/hooks.ts +++ b/web/src/components/chat_search/hooks.ts @@ -1,3 +1,8 @@ +import { useUser } from "../user/UserProvider"; +import { useRouter } from "next/navigation"; +import { checkLlmProvider } from "../initialSetup/welcome/lib"; +import { WellKnownLLMProviderDescriptor } from "@/app/admin/configuration/llm/interfaces"; + import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react"; interface UseSidebarVisibilityProps { @@ -81,3 +86,32 @@ export const useSidebarVisibility = ({ return { showDocSidebar }; }; + +export function useProviderStatus() { + const { user } = useUser(); + const router = useRouter(); + const [validProviderExists, setValidProviderExists] = useState(true); + const [providerOptions, setProviderOptions] = useState< + WellKnownLLMProviderDescriptor[] + >([]); + + useEffect(() => { + async function fetchProviderInfo() { + const { providers, options, defaultCheckSuccessful } = + await checkLlmProvider(user); + setValidProviderExists(providers.length > 0 && defaultCheckSuccessful); + setProviderOptions(options); + } + + fetchProviderInfo(); + }, [router, user]); + + // don't show if + // (1) a valid provider has been setup or + // (2) there are no provider options (e.g. user isn't an admin) + // (3) (handled elsewhere) user explicitly hides the modal + const shouldShowConfigurationNeeded = + !validProviderExists && providerOptions.length > 0; + + return { shouldShowConfigurationNeeded, providerOptions }; +} diff --git a/web/src/components/llm/ApiKeyModal.tsx b/web/src/components/llm/ApiKeyModal.tsx index 75ff06289cb..6c5e68268de 100644 --- a/web/src/components/llm/ApiKeyModal.tsx +++ b/web/src/components/llm/ApiKeyModal.tsx @@ -1,43 +1,17 @@ "use client"; -import { useState, useEffect } from "react"; import { ApiKeyForm } from "./ApiKeyForm"; import { Modal } from "../Modal"; -import { WellKnownLLMProviderDescriptor } from "@/app/admin/configuration/llm/interfaces"; -import { checkLlmProvider } from "../initialSetup/welcome/lib"; -import { User } from "@/lib/types"; import { useRouter } from "next/navigation"; +import { useProviderStatus } from "../chat_search/hooks"; -export const ApiKeyModal = ({ - user, - hide, -}: { - user: User | null; - hide: () => void; -}) => { +export const ApiKeyModal = ({ hide }: { hide: () => void }) => { const router = useRouter(); - const [validProviderExists, setValidProviderExists] = useState(true); - const [providerOptions, setProviderOptions] = useState< - WellKnownLLMProviderDescriptor[] - >([]); + const { shouldShowConfigurationNeeded, providerOptions } = + useProviderStatus(); - useEffect(() => { - async function fetchProviderInfo() { - const { providers, options, defaultCheckSuccessful } = - await checkLlmProvider(user); - setValidProviderExists(providers.length > 0 && defaultCheckSuccessful); - setProviderOptions(options); - } - - fetchProviderInfo(); - }, []); - - // don't show if - // (1) a valid provider has been setup or - // (2) there are no provider options (e.g. user isn't an admin) - // (3) user explicitly hides the modal - if (validProviderExists || !providerOptions.length) { + if (!shouldShowConfigurationNeeded) { return null; } diff --git a/web/src/components/search/SearchSection.tsx b/web/src/components/search/SearchSection.tsx index 64097731fda..4405c6653f1 100644 --- a/web/src/components/search/SearchSection.tsx +++ b/web/src/components/search/SearchSection.tsx @@ -601,7 +601,7 @@ export const SearchSection = ({ !shouldDisplayNoSources && !shouldDisplaySourcesIncomplete && showApiKeyModal && ( - setShowApiKeyModal(false)} user={user} /> + setShowApiKeyModal(false)} /> )} {deletingChatSession && (