import {
ModelsIcon,
WebSearchIcon,
ImageGenerationIcon,
VoiceIcon,
} from "@/components/icons/product-icons";
import { useContext, useState, type Dispatch, type SetStateAction } from "react";
import {
ArrowUpCircle,
BookOpen,
MessageCircle,
Check,
ChevronRight,
ExternalLink,
Github,
Loader2,
type LucideIcon,
} from "lucide-react";
import { useTranslation } from "react-i18next";
import { HostNavigationContext } from "@/components/remote/HostSwitcher";
import { StarLink } from "@/components/StarPrompt";
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
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,
SettingsRow,
SettingsSectionTitle,
} from "@/components/settings/shared/SettingsControls";
import { TokenUsageCard } from "@/components/settings/TokenUsageCard";
import { ToggleButton } from "@/components/settings/ToggleButton";
import { Button } from "@/components/ui/button";
import { SegmentedControl } from "@/components/ui/segmented-control";
import { useLogoFallback } from "@/hooks/useLogoFallback";
import { checkVersion } from "@/lib/api";
import type {
FileEditDisplayMode,
LocalActivityMode,
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")}
/>
);
}
type VersionInfoProps = { currentVersion?: string; currentCommit?: string | null };
export function AboutSettings({ settings }: { settings: SettingsPayload }) {
const { t } = useTranslation();
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");
const links = [
{ key: "sourceCode", icon: Github, href: "https://github.com/HKUDS/nanobot" },
{ key: "documentation", icon: BookOpen, href: "https://nanobot.wiki/" },
{ key: "reportIssue", icon: MessageCircle, href: reportIssueUrl.href },
];
return (
);
}
function VersionCheckRow({ currentVersion, currentCommit }: VersionInfoProps) {
const { t } = useTranslation();
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
const { token } = useClient();
const [checking, setChecking] = useState(false);
const [result, setResult] = useState<
| { type: "up-to-date" }
| { type: "update"; latestVersion: string; pypiUrl?: string }
| { type: "error"; message: string }
| null
>(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 (
{tx("settings.about.version", "Version")}
{result?.type === "up-to-date" ? (
{tx("settings.about.upToDate", "You're up to date")}
) : null}
{result?.type === "update" ? (
{t("settings.about.updateAvailable", {
defaultValue: "Update available v{{version}}",
version: result.latestVersion,
})}
{result.pypiUrl ? (
PyPI
) : null}
) : null}
{result?.type === "error" ? (
{result.message}
) : null}
);
}
export function AppearanceSettings({
theme,
onToggleTheme,
localPrefs,
onChangeLocalPrefs,
}: {
theme: "light" | "dark";
onToggleTheme: () => void;
localPrefs: LocalPreferences;
onChangeLocalPrefs: Dispatch>;
}) {
const { t } = useTranslation();
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
return (
{t("settings.sections.interface")}
{
if (nextTheme !== theme) onToggleTheme();
}}
/>
{tx("settings.sections.localPreferences", "Local preferences")}
onChangeLocalPrefs((prev) => ({ ...prev, activityMode: activityMode as LocalActivityMode }))
}
/>
onChangeLocalPrefs((prev) => ({
...prev,
fileEditDisplayMode: fileEditDisplayMode as FileEditDisplayMode,
}))
}
/>
onChangeLocalPrefs((prev) => ({ ...prev, codeWrap }))}
ariaLabel={tx("settings.rows.codeWrap", "Code wrapping")}
label={localPrefs.codeWrap ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
/>
onChangeLocalPrefs((prev) => ({ ...prev, brandLogos }))}
ariaLabel={tx("settings.rows.brandLogos", "Brand logos")}
label={localPrefs.brandLogos ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
/>
{
if (!enabled) {
onChangeLocalPrefs((prev) => ({ ...prev, browserNotifications: false }));
return;
}
if (typeof Notification === "undefined") return;
if (Notification.permission === "granted") {
onChangeLocalPrefs((prev) => ({ ...prev, browserNotifications: true }));
return;
}
void Notification.requestPermission().then((permission) => {
if (permission === "granted") {
onChangeLocalPrefs((prev) => ({ ...prev, browserNotifications: true }));
}
});
}}
ariaLabel={tx("settings.rows.browserNotifications", "Task notifications")}
label={localPrefs.browserNotifications
? tx("settings.values.on", "On")
: tx("settings.values.off", "Off")}
/>
onChangeLocalPrefs((prev) => ({ ...prev, notificationSound }))}
ariaLabel={tx("settings.rows.notificationSound", "Completion sound")}
label={localPrefs.notificationSound
? tx("settings.values.on", "On")
: tx("settings.values.off", "Off")}
/>
);
}
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 (
);
}