import { useStorage } from "@plasmohq/storage/hook" import { BrainCog, ChevronLeft, CogIcon, ComputerIcon, GithubIcon, PanelLeftIcon, SquarePen, ZapIcon } from "lucide-react" import { useTranslation } from "react-i18next" import { useLocation, NavLink } from "react-router-dom" import { OllamaIcon } from "../Icons/Ollama" import { SelectedKnowledge } from "../Option/Knowledge/SelectedKnwledge" import { ModelSelect } from "../Common/ModelSelect" import { PromptSelect } from "../Common/PromptSelect" import { useQuery } from "@tanstack/react-query" import { fetchChatModels } from "~/services/ollama" import { useMessageOption } from "~/hooks/useMessageOption" import { Select, Tooltip } from "antd" import { getAllPrompts } from "@/db" import { ShareBtn } from "~/components/Common/ShareBtn" import { ProviderIcons } from "../Common/ProviderIcon" type Props = { setSidebarOpen: (open: boolean) => void setOpenModelSettings: (open: boolean) => void } export const Header: React.FC = ({ setOpenModelSettings, setSidebarOpen }) => { const { t } = useTranslation(["option", "common"]) const [shareModeEnabled] = useStorage("shareMode", false) const [hideCurrentChatModelSettings] = useStorage( "hideCurrentChatModelSettings", false ) const { selectedModel, setSelectedModel, clearChat, selectedSystemPrompt, setSelectedQuickPrompt, setSelectedSystemPrompt, messages, streaming, historyId } = useMessageOption() const { data: models, isLoading: isModelsLoading, isFetching: isModelsFetching } = useQuery({ queryKey: ["fetchModel"], queryFn: () => fetchChatModels({ returnEmpty: true }), refetchInterval: 15000 }) const { data: prompts, isLoading: isPromptLoading } = useQuery({ queryKey: ["fetchAllPromptsLayout"], queryFn: getAllPrompts }) const { pathname } = useLocation() const getPromptInfoById = (id: string) => { return prompts?.find((prompt) => prompt.id === id) } const handlePromptChange = (value?: string) => { if (!value) { setSelectedSystemPrompt(undefined) setSelectedQuickPrompt(undefined) return } const prompt = getPromptInfoById(value) if (prompt?.is_system) { setSelectedSystemPrompt(prompt.id) } else { setSelectedSystemPrompt(undefined) setSelectedQuickPrompt(prompt!.content) } } return (
{pathname !== "/" && (
)}
{"/"}
//@ts-ignore option.label.key.toLowerCase().indexOf(input.toLowerCase()) >= 0 } options={prompts?.map((prompt) => ({ label: ( {prompt.is_system ? ( ) : ( )} {prompt.title} ), value: prompt.id }))} />
{!hideCurrentChatModelSettings && ( )} {pathname === "/" && messages.length > 0 && !streaming && shareModeEnabled && }
) }