import { ModelsIcon, WebSearchIcon, ImageGenerationIcon, VoiceIcon, } from "@/components/icons/product-icons"; import { useContext, useState, type Dispatch, type SetStateAction } from "react"; import { ChevronRight, type LucideIcon, } from "lucide-react"; import { useTranslation } from "react-i18next"; import { HostNavigationContext } from "@/components/remote/HostSwitcher"; import { StarLink } from "@/components/StarPrompt"; import { AboutSettingsView } from "./AboutSettingsView"; import { AppearanceSettingsView } from "./AppearanceSettingsView"; import { VersionCheckRowView, type VersionCheckState, type VersionInfoProps } from "./VersionCheckRowView"; import { DEFAULT_TRANSCRIPTION_SETTINGS } from "@/components/settings/capabilities/TranscriptionSettings"; import type { SettingsSectionKey } from "@/components/settings/contracts"; import { settingsProviderConfigured } from "@/components/settings/shared/ModelControls"; import { SettingsGroup, SettingsSectionTitle, } from "@/components/settings/shared/SettingsControls"; import { TokenUsageCard } from "@/components/settings/TokenUsageCard"; import { useLogoFallback } from "@/hooks/useLogoFallback"; import { checkVersion } from "@/lib/api"; import type { LocalPreferences, } from "@/lib/local-preferences"; import { providerBrand, providerDisplayLabel } from "@/lib/provider-brand"; import type { SettingsPayload } from "@/lib/types"; import { cn } from "@/lib/utils"; import { useClient } from "@/providers/ClientProvider"; export function OverviewSettings({ settings, onSelectSection, showBrandLogos, }: { settings: SettingsPayload; onSelectSection: (section: SettingsSectionKey) => void; showBrandLogos: boolean; }) { const { t } = useTranslation(); const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); const activePresetName = settings.agent.model_preset; const activePreset = activePresetName && activePresetName !== "default" ? settings.model_presets.find((preset) => preset.name === activePresetName)?.name ?? activePresetName : null; const activeProvider = settings.agent.resolved_provider ?? settings.agent.provider; const activeProviderConfigured = settingsProviderConfigured(settings, activeProvider); const activeProviderLabel = providerDisplayLabel(settings.providers, activeProvider); const activeModelValue = activeProviderConfigured ? settings.agent.model : tx("settings.values.notConfigured", "Not configured"); const activeModelCaption = activeProviderConfigured ? [activeProvider, activePreset].filter(Boolean).join(" ") : activeProviderLabel || settings.agent.model ? [activeProviderLabel, settings.agent.model].filter(Boolean).join(" ") : tx("settings.byok.noConfiguredProviders", "No configured providers"); const webStatus = settings.web.enable ? tx("settings.values.enabled", "Enabled") : tx("settings.values.disabled", "Disabled"); const imageStatus = settings.image_generation.enabled ? tx("settings.values.enabled", "Enabled") : tx("settings.values.disabled", "Disabled"); const transcription = settings.transcription ?? DEFAULT_TRANSCRIPTION_SETTINGS; const voiceStatus = transcription.enabled ? tx("settings.values.enabled", "Enabled") : tx("settings.values.disabled", "Disabled"); return (
{tx("settings.sections.ai", "AI")} onSelectSection("models")} />
{tx("settings.sections.capabilities", "Capabilities")} onSelectSection("browser")} /> onSelectSection("image")} /> onSelectSection("voice")} />
); } export function AboutSettings({ settings }: { settings: SettingsPayload }) { const hostPicker = useContext(HostNavigationContext); const currentVersion = settings.version?.current; const currentCommit = settings.version?.commit; const environment = settings.environment; const reportIssueUrl = new URL("https://github.com/HKUDS/nanobot/issues/new"); reportIssueUrl.searchParams.set("template", "bug_report.yml"); const reportedVersion = [currentVersion, currentCommit && `(commit ${currentCommit})`] .filter(Boolean).join(" "); if (reportedVersion) reportIssueUrl.searchParams.set("version", reportedVersion); reportIssueUrl.searchParams.set("channel", "WebSocket"); if (environment) { reportIssueUrl.searchParams.set("python_version", environment.python_version); const osName = environment.os === "Darwin" ? "macOS" : environment.os; const osVersion = [osName, environment.os_version].filter(Boolean).join(" "); reportIssueUrl.searchParams.set("os", environment.architecture ? `${osVersion} (${environment.architecture})` : osVersion); } if (settings.agent.model) reportIssueUrl.searchParams.set("model", settings.agent.model); const provider = settings.agent.resolved_provider || settings.agent.provider; if (provider) reportIssueUrl.searchParams.set("llm_provider", provider); reportIssueUrl.searchParams.set("browser", navigator.userAgent); reportIssueUrl.searchParams.set("connection", hostPicker?.kind === "embedded" ? "Remote host" : hostPicker ? "Local host" : "Direct WebUI"); return } starLink={} />; } function VersionCheckRow({ currentVersion, currentCommit }: VersionInfoProps) { const { token } = useClient(); const [checking, setChecking] = useState(false); const [result, setResult] = useState(null); const handleCheck = async () => { setChecking(true); setResult(null); try { const res = await checkVersion(token); if (res.updateAvailable) { setResult({ type: "update", latestVersion: res.updateAvailable.latestVersion, pypiUrl: res.updateAvailable.pypiUrl, }); } else { setResult({ type: "up-to-date" }); } } catch (err) { setResult({ type: "error", message: (err as Error).message }); } finally { setChecking(false); } }; return void handleCheck()} />; } export function AppearanceSettings({ theme, onToggleTheme, localPrefs, onChangeLocalPrefs }: { theme: "light" | "dark"; onToggleTheme: () => void; localPrefs: LocalPreferences; onChangeLocalPrefs: Dispatch>; }) { return ; } function OverviewRowIcon({ icon: Icon, }: { icon: LucideIcon; }) { return ( ); } function OverviewValueLogo({ provider, showBrandLogos, }: { provider: string | null | undefined; showBrandLogos: boolean; }) { const brand = provider ? providerBrand(provider) : null; const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls); const isLogoTile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl; if (!provider || !showBrandLogos || !brand) return null; if (logoUrl) { return ( {brand.initials} ); } return ( {brand.initials} ); } function OverviewListRow({ icon: Icon, valueLogoProvider, title, value, caption, showBrandLogos = false, onClick, }: { icon: LucideIcon; valueLogoProvider?: string | null; title: string; value: string; caption?: string; showBrandLogos?: boolean; onClick: () => void; }) { return ( ); }