2026-08-10 19:33:52 +08:00
|
|
|
import { useRef } from "react";
|
|
|
|
|
import {
|
|
|
|
|
Activity,
|
2026-09-10 11:10:51 +08:00
|
|
|
Info,
|
2026-08-10 19:33:52 +08:00
|
|
|
Check,
|
|
|
|
|
ChevronDown,
|
|
|
|
|
ChevronLeft,
|
|
|
|
|
LogOut,
|
2026-09-10 11:10:51 +08:00
|
|
|
Loader2,
|
|
|
|
|
RotateCcw,
|
|
|
|
|
Blocks,
|
2026-08-10 19:33:52 +08:00
|
|
|
Palette,
|
|
|
|
|
Server,
|
|
|
|
|
ShieldCheck,
|
|
|
|
|
SlidersHorizontal,
|
|
|
|
|
type LucideIcon,
|
|
|
|
|
} from "lucide-react";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
SIDEBAR_SELECTION_ITEM_CLASS,
|
|
|
|
|
SidebarSelectionHighlight,
|
|
|
|
|
} from "@/components/SidebarSelectionHighlight";
|
2026-09-10 11:10:51 +08:00
|
|
|
import { isCapabilitySection, type SettingsSectionKey } from "@/components/settings/contracts";
|
2026-08-10 19:33:52 +08:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
|
|
|
|
|
const SETTINGS_NAV_ITEMS: Array<{ key: SettingsSectionKey; icon: LucideIcon; fallback: string }> = [
|
|
|
|
|
{ key: "overview", icon: Activity, fallback: "Overview" },
|
|
|
|
|
{ key: "appearance", icon: Palette, fallback: "Appearance" },
|
|
|
|
|
{ key: "models", icon: SlidersHorizontal, fallback: "Models" },
|
2026-09-10 11:10:51 +08:00
|
|
|
{ key: "capabilities", icon: Blocks, fallback: "Capabilities" },
|
2026-08-10 19:33:52 +08:00
|
|
|
{ key: "runtime", icon: Server, fallback: "System" },
|
2026-09-10 11:10:51 +08:00
|
|
|
{ key: "advanced", icon: ShieldCheck, fallback: "Advanced" },
|
|
|
|
|
{ key: "about", icon: Info, fallback: "About" },
|
2026-08-10 19:33:52 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export function standaloneSectionTitle(section: SettingsSectionKey): string {
|
|
|
|
|
if (section === "apps") return "Apps";
|
|
|
|
|
if (section === "automations") return "Automations";
|
|
|
|
|
if (section === "skills") return "Skills";
|
2026-09-10 11:10:51 +08:00
|
|
|
if (section === "channels") return "Channels";
|
2026-08-10 19:33:52 +08:00
|
|
|
return SETTINGS_NAV_ITEMS.find((item) => item.key === section)?.fallback ?? "Settings";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SettingsSidebar({
|
|
|
|
|
activeSection,
|
|
|
|
|
onSelectSection,
|
|
|
|
|
onBackToChat,
|
|
|
|
|
onLogout,
|
|
|
|
|
hostChromeInset,
|
2026-09-10 11:10:51 +08:00
|
|
|
onRestart,
|
|
|
|
|
isRestarting,
|
|
|
|
|
restartPending,
|
|
|
|
|
isNativeHost,
|
2026-08-10 19:33:52 +08:00
|
|
|
}: {
|
|
|
|
|
activeSection: SettingsSectionKey;
|
|
|
|
|
onSelectSection: (section: SettingsSectionKey) => void;
|
|
|
|
|
onBackToChat: () => void;
|
|
|
|
|
onLogout?: () => void;
|
|
|
|
|
hostChromeInset?: boolean;
|
2026-09-10 11:10:51 +08:00
|
|
|
onRestart?: () => void;
|
|
|
|
|
isRestarting?: boolean;
|
|
|
|
|
restartPending?: boolean;
|
|
|
|
|
isNativeHost?: boolean;
|
2026-08-10 19:33:52 +08:00
|
|
|
}) {
|
|
|
|
|
const { t } = useTranslation();
|
2026-09-10 11:10:51 +08:00
|
|
|
const restartLabel = isRestarting
|
|
|
|
|
? t(isNativeHost ? "app.system.restartingEngine" : "app.system.restarting")
|
|
|
|
|
: t("app.system.restartAction");
|
|
|
|
|
const navSection = isCapabilitySection(activeSection) ? "capabilities" : activeSection;
|
2026-08-10 19:33:52 +08:00
|
|
|
const activeNavItemRef = useRef<HTMLButtonElement>(null);
|
2026-09-10 11:10:51 +08:00
|
|
|
const activeItem = SETTINGS_NAV_ITEMS.find((item) => item.key === navSection)
|
2026-08-10 19:33:52 +08:00
|
|
|
?? SETTINGS_NAV_ITEMS[0];
|
|
|
|
|
const ActiveIcon = activeItem.icon;
|
|
|
|
|
const activeLabel = t(`settings.nav.${activeItem.key}`, {
|
|
|
|
|
defaultValue: activeItem.fallback,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<aside
|
|
|
|
|
className={cn(
|
2026-09-10 11:10:51 +08:00
|
|
|
"flex w-full shrink-0 select-none flex-col bg-settings-surface px-3 pb-2 lg:w-48 lg:px-3 lg:pb-4",
|
2026-09-03 10:23:38 +08:00
|
|
|
hostChromeInset ? "pt-10 lg:pt-10" : "pt-4 lg:pt-4",
|
2026-08-10 19:33:52 +08:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onBackToChat}
|
2026-09-10 11:10:51 +08:00
|
|
|
aria-label={t("settings.backToChat")}
|
2026-09-03 10:23:38 +08:00
|
|
|
className={cn(
|
2026-09-10 11:10:51 +08:00
|
|
|
"touch-target mb-2 inline-flex h-9 w-9 items-center justify-center rounded-full text-[13px] leading-5 font-normal text-sidebar-content transition-colors settings-hover hover:text-foreground lg:mb-3",
|
2026-09-03 10:23:38 +08:00
|
|
|
hostChromeInset && "-ml-1",
|
|
|
|
|
)}
|
2026-08-10 19:33:52 +08:00
|
|
|
>
|
2026-09-10 11:10:51 +08:00
|
|
|
<ChevronLeft className="h-4 w-4" aria-hidden />
|
2026-08-10 19:33:52 +08:00
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<nav
|
|
|
|
|
aria-label={t("settings.sidebar.ariaLabel")}
|
|
|
|
|
className="w-full"
|
|
|
|
|
>
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
aria-label={`${t("settings.sidebar.title")}: ${activeLabel}`}
|
2026-09-10 11:10:51 +08:00
|
|
|
className="touch-target flex h-11 w-full items-center gap-2.5 rounded-control bg-sidebar-accent px-3 text-left text-[13px] leading-5 font-normal text-foreground transition-colors settings-hover lg:hidden"
|
2026-08-10 19:33:52 +08:00
|
|
|
>
|
|
|
|
|
<ActiveIcon className="h-4 w-4 shrink-0" strokeWidth={2} aria-hidden />
|
|
|
|
|
<span className="min-w-0 flex-1 truncate">{activeLabel}</span>
|
2026-09-10 11:10:51 +08:00
|
|
|
<ChevronDown className="h-4 w-4 shrink-0 text-sidebar-content" aria-hidden />
|
2026-08-10 19:33:52 +08:00
|
|
|
</button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent
|
|
|
|
|
align="start"
|
|
|
|
|
sideOffset={6}
|
|
|
|
|
className="w-[var(--radix-dropdown-menu-trigger-width)] max-w-[calc(100vw-1.5rem)]"
|
|
|
|
|
>
|
|
|
|
|
{SETTINGS_NAV_ITEMS.map(({ key, icon: Icon, fallback }) => {
|
2026-09-10 11:10:51 +08:00
|
|
|
const active = key === navSection;
|
2026-08-10 19:33:52 +08:00
|
|
|
return (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
key={key}
|
|
|
|
|
aria-current={active ? "page" : undefined}
|
|
|
|
|
onSelect={() => onSelectSection(key)}
|
|
|
|
|
className={cn(
|
2026-09-10 11:10:51 +08:00
|
|
|
"flex h-10 cursor-default items-center gap-2.5 px-2.5 text-[13px] leading-5 font-normal",
|
2026-08-10 19:33:52 +08:00
|
|
|
active && "bg-sidebar-accent text-foreground focus:bg-sidebar-accent",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<Icon className="h-4 w-4 shrink-0" strokeWidth={2} aria-hidden />
|
|
|
|
|
<span className="min-w-0 flex-1 truncate">
|
|
|
|
|
{t(`settings.nav.${key}`, { defaultValue: fallback })}
|
|
|
|
|
</span>
|
|
|
|
|
{active ? <Check className="h-4 w-4 shrink-0" aria-hidden /> : null}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
|
|
|
|
|
<SidebarSelectionHighlight
|
|
|
|
|
targetRef={activeNavItemRef}
|
2026-09-10 11:10:51 +08:00
|
|
|
activeId={navSection}
|
2026-08-10 19:33:52 +08:00
|
|
|
scope="settings"
|
|
|
|
|
className="relative hidden space-y-1 lg:block"
|
|
|
|
|
>
|
|
|
|
|
{SETTINGS_NAV_ITEMS.map(({ key, icon: Icon, fallback }) => {
|
2026-09-10 11:10:51 +08:00
|
|
|
const active = key === navSection;
|
2026-08-10 19:33:52 +08:00
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
ref={active ? activeNavItemRef : undefined}
|
|
|
|
|
key={key}
|
|
|
|
|
type="button"
|
|
|
|
|
aria-current={active ? "page" : undefined}
|
|
|
|
|
onClick={() => onSelectSection(key)}
|
|
|
|
|
className={cn(
|
2026-09-10 11:10:51 +08:00
|
|
|
"touch-target flex h-9 w-full items-center gap-2 rounded-xl px-2.5 text-left text-[13px] leading-5 font-normal",
|
2026-08-10 19:33:52 +08:00
|
|
|
SIDEBAR_SELECTION_ITEM_CLASS,
|
|
|
|
|
active
|
|
|
|
|
? "text-sidebar-accent-foreground"
|
2026-09-10 11:10:51 +08:00
|
|
|
: "text-sidebar-content settings-hover hover:text-foreground",
|
2026-08-10 19:33:52 +08:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<Icon className="h-4 w-4 shrink-0" strokeWidth={2} aria-hidden />
|
|
|
|
|
<span className="truncate">
|
|
|
|
|
{t(`settings.nav.${key}`, { defaultValue: fallback })}
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</SidebarSelectionHighlight>
|
|
|
|
|
</nav>
|
|
|
|
|
|
2026-09-10 11:10:51 +08:00
|
|
|
<div className="pt-2 lg:mt-auto lg:pt-4">
|
|
|
|
|
{onRestart ? (
|
|
|
|
|
<div>
|
|
|
|
|
{restartPending ? (
|
|
|
|
|
<p id="settings-restart-status" role="status" className="sr-only">
|
|
|
|
|
{t("settings.status.savedRestartApply")}
|
|
|
|
|
</p>
|
|
|
|
|
) : null}
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={onRestart}
|
|
|
|
|
disabled={isRestarting}
|
|
|
|
|
aria-describedby={restartPending ? "settings-restart-status" : undefined}
|
|
|
|
|
className={cn("h-9 w-full justify-start gap-2 rounded-control px-2.5 text-[13px] leading-5 font-normal settings-hover",
|
|
|
|
|
restartPending && !isRestarting
|
|
|
|
|
? "settings-restart-pending text-orange-600 hover:text-orange-700 dark:text-orange-400 dark:hover:text-orange-300"
|
|
|
|
|
: "text-sidebar-content hover:text-foreground")}
|
|
|
|
|
>
|
|
|
|
|
{isRestarting ? <Loader2 className="h-4 w-4 animate-spin" aria-hidden />
|
|
|
|
|
: <RotateCcw className="h-4 w-4" aria-hidden />}
|
|
|
|
|
<span>{restartLabel}</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
2026-08-10 19:33:52 +08:00
|
|
|
{onLogout && !hostChromeInset ? (
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={onLogout}
|
2026-09-10 11:10:51 +08:00
|
|
|
className="hidden h-9 w-full justify-start gap-2 rounded-control px-2.5 text-[13px] leading-5 font-normal text-sidebar-content hover:bg-destructive/8 hover:text-destructive lg:flex"
|
2026-08-10 19:33:52 +08:00
|
|
|
>
|
|
|
|
|
<LogOut className="h-4 w-4" aria-hidden />
|
2026-09-10 11:10:51 +08:00
|
|
|
<span>{t("app.account.logout")}</span>
|
2026-08-10 19:33:52 +08:00
|
|
|
</Button>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
</aside>
|
|
|
|
|
);
|
|
|
|
|
}
|