import React from 'react'; import { RiAddLine, RiArrowDownSLine, RiMore2Line, RiSearchLine, RiGitBranchLine, } from '@remixicon/react'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { cn } from '@/lib/utils'; import { useAgentGroupsStore, type AgentGroup } from '@/stores/useAgentGroupsStore'; import { useDirectoryStore } from '@/stores/useDirectoryStore'; const formatRelativeTime = (timestamp: number): string => { const now = Date.now(); const diff = now - timestamp; const minutes = Math.floor(diff / (60 * 1000)); const hours = Math.floor(diff / (60 * 60 * 1000)); const days = Math.floor(diff / (24 * 60 * 60 * 1000)); if (minutes < 1) return 'now'; if (minutes < 60) return `${minutes}m`; if (hours < 24) return `${hours}h`; return `${days}d`; }; interface AgentGroupItemProps { group: AgentGroup; isSelected: boolean; onSelect: () => void; } const AgentGroupItem: React.FC = ({ group, isSelected, onSelect }) => { const [menuOpen, setMenuOpen] = React.useState(false); return (
Delete
); }; interface AgentManagerSidebarProps { className?: string; selectedGroupName?: string | null; onGroupSelect?: (groupName: string) => void; onNewAgent?: () => void; } export const AgentManagerSidebar: React.FC = ({ className, selectedGroupName, onGroupSelect, onNewAgent, }) => { const [searchQuery, setSearchQuery] = React.useState(''); const [showAll, setShowAll] = React.useState(false); const { groups, isLoading, loadGroups } = useAgentGroupsStore(); const currentDirectory = useDirectoryStore((state) => state.currentDirectory); // Load groups when directory changes React.useEffect(() => { if (currentDirectory) { loadGroups(); } }, [currentDirectory, loadGroups]); const MAX_VISIBLE = 5; const filteredGroups = React.useMemo(() => { if (!searchQuery.trim()) return groups; const query = searchQuery.toLowerCase(); return groups.filter(group => group.name.toLowerCase().includes(query) ); }, [searchQuery, groups]); const visibleGroups = showAll ? filteredGroups : filteredGroups.slice(0, MAX_VISIBLE); const remainingCount = filteredGroups.length - MAX_VISIBLE; return (
{/* Search Input */}
setSearchQuery(e.target.value)} placeholder="Search Agent Groups..." className="pl-8 h-8 rounded-lg border-border/40 bg-background/50 typography-meta" />
{/* New Agent Button */}
{/* Agent Groups Section Header */}
Agent Groups {isLoading && ( Loading... )}
{/* Group List */} {visibleGroups.map((group) => ( onGroupSelect?.(group.name)} /> ))} {/* Show More Link */} {!showAll && remainingCount > 0 && ( )} {/* Show Less Link */} {showAll && filteredGroups.length > MAX_VISIBLE && ( )} {/* Empty State */} {!isLoading && filteredGroups.length === 0 && (

{searchQuery.trim() ? 'No groups found' : 'No agent groups yet'}

{!searchQuery.trim() && (

Create a new agent group to get started

)}
)}
); };