diff --git a/src/lib/config/clientRegistry.ts b/src/lib/config/clientRegistry.ts index 6d0c0d1..7c8fc24 100644 --- a/src/lib/config/clientRegistry.ts +++ b/src/lib/config/clientRegistry.ts @@ -6,11 +6,8 @@ const getClientConfig = (key: string, defaultVal?: any) => { export const getTheme = () => getClientConfig('theme', 'dark'); -export const getAutoImageSearch = () => - Boolean(getClientConfig('autoImageSearch', 'true')); - -export const getAutoVideoSearch = () => - Boolean(getClientConfig('autoVideoSearch', 'true')); +export const getAutoMediaSearch = () => + getClientConfig('autoMediaSearch', 'true') === 'true'; export const getSystemInstructions = () => getClientConfig('systemInstructions', ''); diff --git a/src/lib/hooks/useChat.tsx b/src/lib/hooks/useChat.tsx index 8ef57ef..ee7e9c7 100644 --- a/src/lib/hooks/useChat.tsx +++ b/src/lib/hooks/useChat.tsx @@ -21,6 +21,7 @@ import { useParams, useSearchParams } from 'next/navigation'; import { toast } from 'sonner'; import { getSuggestions } from '../actions'; import { MinimalProvider } from '../models/types'; +import { getAutoMediaSearch } from '../config/clientRegistry'; export type Section = { userMessage: UserMessage; @@ -94,17 +95,6 @@ const checkConfig = async ( 'embeddingModelProviderId', ); - const autoImageSearch = localStorage.getItem('autoImageSearch'); - const autoVideoSearch = localStorage.getItem('autoVideoSearch'); - - if (!autoImageSearch) { - localStorage.setItem('autoImageSearch', 'true'); - } - - if (!autoVideoSearch) { - localStorage.setItem('autoVideoSearch', 'false'); - } - const res = await fetch(`/api/providers`, { headers: { 'Content-Type': 'application/json', @@ -624,16 +614,13 @@ export const ChatProvider = ({ children }: { children: React.ReactNode }) => { const lastMsg = messagesRef.current[messagesRef.current.length - 1]; - const autoImageSearch = localStorage.getItem('autoImageSearch'); - const autoVideoSearch = localStorage.getItem('autoVideoSearch'); + const autoMediaSearch = getAutoMediaSearch(); - if (autoImageSearch === 'true') { + if (autoMediaSearch) { document .getElementById(`search-images-${lastMsg.messageId}`) ?.click(); - } - if (autoVideoSearch === 'true') { document .getElementById(`search-videos-${lastMsg.messageId}`) ?.click();