import { ArchiveIcon, SkillsIcon, AutomationsIcon, ChannelsIcon, SearchIcon, SettingsIcon, NewChatIcon, ComposeIcon, AppsIcon, } from "@/components/icons/product-icons"; import { type ReactNode, type RefObject, useRef, useState, } from "react"; import { PanelLeftClose } from "lucide-react"; import { useTranslation } from "react-i18next"; import { ChatList, type SidebarDeleteDecision, type SidebarDeleteItem, type SidebarPaneGroup, } from "@/components/ChatList"; import { HostSwitcher } from "@/components/remote/HostSwitcher"; import { UpdateNotice } from "@/components/UpdateNotice"; import { SIDEBAR_SELECTION_ACTION_ITEM_CLASS, SidebarSelectionHighlight, } from "@/components/SidebarSelectionHighlight"; import { Button } from "@/components/ui/button"; import { HoverHint } from "@/components/ui/tooltip"; import type { ChatSummary, SidebarViewState, } from "@/lib/types"; import { cn } from "@/lib/utils"; import type { UpdateMethod } from "@/lib/api"; import { sidebarShortcutAria, sidebarShortcutLabel } from "@/lib/sidebar-shortcuts"; interface SidebarProps { sessions: ChatSummary[]; temporarySessions?: ChatSummary[]; activeKey: string | null; loading: boolean; initialLoading?: boolean; newChatActive: boolean; onNewChat: () => void; onSelect: (key: string) => void; onCloseTemporaryChat?: (key: string) => void; onRequestDelete: (key: string, label: string, onDecision?: SidebarDeleteDecision) => void; onRequestDeleteMany?: (items: SidebarDeleteItem[], onDecision?: SidebarDeleteDecision) => void; onTogglePin: (key: string) => void; onRequestRename: (key: string, title: string) => Promise; onRequestRenameTab?: (key: string, label: string) => void; onToggleArchive: (key: string) => void; onArchiveMany?: (keys: string[], archive: boolean) => void; paneGroups?: Record; onSelectPane?: (tabKey: string, paneKey: string) => void; onCreateTab?: (paneKey: string) => void; onDetachPane?: (tabKey: string, paneKey: string) => void; onDissolveTab?: (tabKey: string) => void; onAttachPane?: ( paneKey: string, tabKey: string, ) => void; onToggleGroup: (groupId: string) => void; onRequestRenameProject: (projectKey: string, label: string) => void; onNewChatInProject: (projectPath: string, projectName: string) => void; onOpenSettings: () => void; onOpenUpdates?: () => void; availableUpdate?: { version: string; onDismiss: () => void; onRequestUpdate?: () => void; installationMethod?: UpdateMethod | null }; onOpenApps: () => void; onOpenSkills: () => void; onOpenAutomations: () => void; onOpenChannels: () => void; onSettingsIntent?: () => void; onOpenSearch: () => void; activeUtility?: "apps" | "skills" | "automations" | "channels" | null; onToggleArchived: () => void; onCollapse?: () => void; onExpand?: () => void; containActionMenus?: boolean; collapsed?: boolean; pinnedKeys?: string[]; archivedKeys?: string[]; pinnedPaneKeys?: string[]; archivedPaneKeys?: string[]; sessionOrder?: string[]; titleOverrides?: Record; projectNameOverrides?: Record; collapsedGroups?: Record; runningChatIds?: string[]; updatedChatIds?: string[]; recoveryChatIds?: string[]; viewState?: SidebarViewState; showArchived?: boolean; archivedCount?: number; defaultWorkspacePath?: string | null; hostChromeInset?: boolean; } type NavigatorWithUserAgentData = Navigator & { userAgentData?: { platform?: string }; }; function isApplePlatform(): boolean { if (typeof navigator === "undefined") return false; const platform = navigator.platform || ""; const userAgentPlatform = (navigator as NavigatorWithUserAgentData).userAgentData?.platform || ""; return /mac|iphone|ipad|ipod/i.test(`${platform} ${userAgentPlatform}`); } export function Sidebar(props: SidebarProps) { const { t } = useTranslation(); const [menuPortalContainer, setMenuPortalContainer] = useState(null); const collapsed = Boolean(props.collapsed); const toggleLabel = t("thread.header.toggleSidebar"); const apple = isApplePlatform(); const activeActionRef = useRef(null); const activeActionId = collapsed && props.newChatActive ? "new-chat" : props.activeUtility ? `utility:${props.activeUtility}` : null; const newChatButton = ( : } shortcut={sidebarShortcutLabel("newChat", apple)} ariaKeyShortcuts={sidebarShortcutAria("newChat")} /> ); const searchButton = ( } /> ); return ( ); } function SidebarActionButton({ collapsed, iconOnly = false, label, icon, onClick, active = false, className, shortcut, ariaKeyShortcuts, onIntent, selectionRef, }: { collapsed: boolean; iconOnly?: boolean; label: string; icon: ReactNode; onClick: () => void; active?: boolean; className?: string; shortcut?: string; ariaKeyShortcuts?: string; onIntent?: () => void; selectionRef?: RefObject; }) { const compact = collapsed || iconOnly; const button = ( ); return compact || shortcut ? ( {label} {shortcut ? {shortcut} : null} }> {button} ) : button; }