import { useLayoutEffect, useRef, useState } from "preact/hooks"; import { ArrowLeft, Bell, ChevronRight, Cpu, Keyboard, LoaderCircle, LogOut, Server, X } from "lucide-preact"; import { AgentNotifications } from "@/components/agent/agent-notifications"; import { ModelSettings, type ModelSettingsProps } from "@/components/settings/model-settings"; import { Button } from "@/components/ui/button"; import type { AuthMode } from "@/hooks/use-session-auth"; import { getApiBaseUrl } from "@/lib/api"; import { cn } from "@/lib/utils"; type Section = "notifications" | "models" | "connection"; const sections = [ { id: "notifications", title: "Notifications", description: "Agent alerts and permissions", icon: Bell }, { id: "models", title: "Models", description: "Chats and Quick Questions", icon: Cpu }, { id: "connection", title: "Connection & session", description: "Server, sign-in, and shortcuts", icon: Server }, ] as const; function displayServerUrl() { try { const url = new URL(getApiBaseUrl(), window.location.href); return `${url.origin}${url.pathname}`.replace(/\/$/, ""); } catch { return "Unavailable"; } } export function AppSettings({ authMode, onClose, onLogout, ...modelSettings }: ModelSettingsProps & { authMode: AuthMode | null; onClose: () => void; onLogout: () => Promise; }) { const dialogRef = useRef(null); const contentRef = useRef(null); const navRef = useRef(null); const lastSectionRef = useRef
(null); const [section, setSection] = useState
(null); const [signingOut, setSigningOut] = useState(false); const activeSection = section ?? "notifications"; const modifier = /Mac|iPhone|iPad|iPod/i.test(navigator.platform) ? "⌘" : "Ctrl"; useLayoutEffect(() => { const dialog = dialogRef.current; const previouslyFocused = document.activeElement; dialog?.showModal(); return () => { dialog?.close(); if (previouslyFocused instanceof HTMLElement && previouslyFocused.isConnected) previouslyFocused.focus({ preventScroll: true }); }; }, []); useLayoutEffect(() => { if (section) { lastSectionRef.current = section; if (contentRef.current) contentRef.current.scrollTop = 0; contentRef.current?.focus({ preventScroll: true }); } else if (lastSectionRef.current) { navRef.current?.querySelector(`[data-section="${lastSectionRef.current}"]`)?.focus({ preventScroll: true }); } }, [section]); return { event.preventDefault(); onClose(); }} onClick={(event) => { if (event.target === event.currentTarget) onClose(); }} >
{section ? : null}

Settings

item.id === activeSection)?.title} tabIndex={-1} className={cn("app-settings-content min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain outline-none md:block", !section && "hidden")}> {activeSection === "notifications" ? authMode === "token" ? : (

Agent notifications require a server with token sign-in.

) : activeSection === "models" ? : (

Server
{displayServerUrl()}
Sign-in
{authMode === "token" ? "Signed in on this browser." : "Open mode. No sign-in required."}
{authMode === "token" ? : null}
{[ ["New chat", `${modifier} + J`], ["New search", `${modifier} + Shift + J`], ["Quick Question", `${modifier} + I`], ["Previous / next item", `${modifier} + ↑ / ↓`] ].map(([label, keys]) =>
{label}
{keys}
)}
)}
; }