import { ReactNode, useEffect } from "react"; import { MdRefresh } from "react-icons/md"; import { FaGithub } from "react-icons/fa"; import { TbRobot, TbAlertTriangle } from "react-icons/tb"; import { useTranslation } from "react-i18next"; import Logo from "@/assets/logo.svg"; import LanguageSwitcher from "../language-switcher/language-switcher"; import { useModelStore } from "../../store/modelStore"; function Header({ onReset, children, modelName }: { onReset: () => void; children?: ReactNode; modelName?: string; }) { const { t } = useTranslation(); const { currentModel, envConfig, setCurrentModel, fetchModelInfo } = useModelStore(); // Update state when modelName in props changes useEffect(() => { if (modelName) { // If modelName is provided, prioritize the value passed in props setCurrentModel(modelName); } else if (!currentModel) { // Otherwise, get from global store; if store is empty, trigger API request fetchModelInfo(); } }, [modelName, currentModel, setCurrentModel, fetchModelInfo]); // Extract the short name of the model const getShortModelName = (modelName: string) => { if (!modelName) return ""; // Extract the main part of the model name if (modelName.includes("/")) { return modelName.split("/").pop() || modelName; } return modelName; }; // Check if model-related environment variables are configured const isModelConfigured = currentModel || (envConfig && (envConfig.model || envConfig.apiKey)); return (

DeepSite Logo {t('app.title')}

|

{t('app.subtitle')}

{isModelConfigured ? ( currentModel && ( <>

|

{getShortModelName(currentModel)}
) ) : ( <>

|

{t('header.modelNotConfigured')}
)}
{children}
); } export default Header;