"use client"; import { useEffect } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { IconSettings, IconFolder, IconRobot, IconBell, IconCode, IconCpu, IconKey, IconMicrophone, IconMessageCircle, IconBrandGithub, IconBrandGitlab, IconBrandSlack, IconHexagon, IconWand, IconGitBranch, IconArrowsShuffle, IconTicket, IconPlugConnected, IconBolt, IconActivity, IconDatabase, IconArchive, IconFileText, IconRefresh, IconScale, IconInfoCircle, IconServerCog, } from "@tabler/icons-react"; import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupLabel, SidebarGroupContent, SidebarMenu, SidebarMenuItem, SidebarMenuButton, SidebarMenuSub, SidebarMenuSubItem, SidebarMenuSubButton, SidebarHeader, useSidebar, } from "@kandev/ui/sidebar"; import { ScrollArea } from "@kandev/ui/scroll-area"; import { ScrollOnOverflow } from "@kandev/ui/scroll-on-overflow"; import { useAppStore } from "@/components/state-provider"; import { useAvailableAgents } from "@/hooks/domains/settings/use-available-agents"; import { AgentLogo } from "@/components/agent-logo"; import { getExecutorIcon } from "@/lib/executor-icons"; import { getCapabilityWarning } from "@/lib/capability-warning"; import type { Agent, AgentProfile, Executor } from "@/lib/types/http"; import type { WorkspaceState } from "@/lib/state/slices"; type WorkspaceItem = WorkspaceState["items"][number]; type GeneralSidebarSectionProps = { pathname: string; }; function GeneralSidebarSection({ pathname }: GeneralSidebarSectionProps) { return ( General Notifications Editors ); } type WorkspacesSidebarSectionProps = { pathname: string; workspaces: WorkspaceItem[]; }; function WorkspacesSidebarSection({ pathname, workspaces }: WorkspacesSidebarSectionProps) { return ( Workspaces {workspaces.length > 0 && ( {workspaces.map((workspace) => { const workspacePath = `/settings/workspace/${workspace.id}`; const workflowsPath = `${workspacePath}/workflows`; const repositoriesPath = `${workspacePath}/repositories`; return ( {workspace.name} Repositories Workflows ); })} )} ); } function SystemSidebarSection({ pathname }: { pathname: string }) { const items: Array<{ href: string; label: string; Icon: typeof IconBrandGithub }> = [ { href: "/settings/system/status", label: "Status", Icon: IconActivity }, { href: "/settings/system/database", label: "Database", Icon: IconDatabase }, { href: "/settings/system/backups", label: "Backups", Icon: IconArchive }, { href: "/settings/system/logs", label: "Logs", Icon: IconFileText }, { href: "/settings/system/updates", label: "Updates", Icon: IconRefresh }, { href: "/settings/system/about", label: "About", Icon: IconInfoCircle }, { href: "/settings/system/licenses", label: "Licenses", Icon: IconScale }, ]; const isSystem = pathname.startsWith("/settings/system"); return ( System {items.map(({ href, label, Icon }) => ( {label} ))} ); } function IntegrationsSidebarSection({ pathname }: { pathname: string }) { const items: Array<{ href: string; label: string; Icon: typeof IconBrandGithub }> = [ { href: "/settings/integrations/github", label: "GitHub", Icon: IconBrandGithub }, { href: "/settings/integrations/gitlab", label: "GitLab", Icon: IconBrandGitlab }, { href: "/settings/integrations/jira", label: "Jira", Icon: IconTicket }, { href: "/settings/integrations/linear", label: "Linear", Icon: IconHexagon }, { href: "/settings/integrations/slack", label: "Slack", Icon: IconBrandSlack }, ]; return ( Integrations {items.map(({ href, label, Icon }) => ( {label} ))} ); } type AgentsSidebarSectionProps = { pathname: string; agents: Agent[]; }; function AgentsSidebarSection({ pathname, agents }: AgentsSidebarSectionProps) { return ( Agents {agents.length > 0 && ( {agents.flatMap((agent: Agent) => agent.profiles.map((profile: AgentProfile) => { const encodedAgent = encodeURIComponent(agent.name); const profilePath = `/settings/agents/${encodedAgent}/profiles/${profile.id}`; const agentLabel = profile.agentDisplayName || agent.name; const warning = getCapabilityWarning(agent.capability_status, agent.capability_error); return ( {agentLabel} • {profile.name} {warning && } ); }), )} )} ); } type ExecutorsSidebarSectionProps = { pathname: string; executors: Executor[]; }; function ExecutorsSidebarSection({ pathname, executors }: ExecutorsSidebarSectionProps) { const allProfiles = executors.flatMap((e) => (e.profiles ?? []).map((p) => ({ ...p, executorType: e.type })), ); return ( Executors {allProfiles.length > 0 && ( {allProfiles.map((profile) => { const Icon = getExecutorIcon(profile.executorType); const profilePath = `/settings/executors/${profile.id}`; return ( {profile.name} ); })} )} ); } type SimpleSidebarEntry = { href: string; label: string; Icon: typeof IconBrandGithub; }; /** * A short row of single-link sidebar entries (Automations, Prompts, Voice * Mode, Utility Agents, External MCP) — extracted from `SettingsAppSidebar` * so the parent function stays under the 100-line lint limit. */ function SimpleSidebarRows({ pathname, entries, }: { pathname: string; entries: SimpleSidebarEntry[]; }) { return ( <> {entries.map(({ href, label, Icon }) => ( {label} ))} ); } function SecretsSidebarSection({ pathname }: { pathname: string }) { return ( Secrets ); } export function SettingsAppSidebar() { const pathname = usePathname(); const { setOpenMobile, isMobile } = useSidebar(); const workspaces = useAppStore((state) => state.workspaces.items); const executors = useAppStore((state) => state.executors.items); const agents = useAppStore((state) => state.settingsAgents.items); useAvailableAgents(); // Close mobile sidebar when navigating to a new page useEffect(() => { if (isMobile) { setOpenMobile(false); } }, [pathname, isMobile, setOpenMobile]); return ( Kandev Settings {/* System */} ); }