import { useId, useRef, useState } from "react"; import { Plus, Search, Users, X } from "lucide-react"; import type { Agent } from "@paperclipai/shared"; import { AgentChatPicker } from "@/components/AgentChatPicker"; import { AgentAvatar } from "@/components/AgentAvatar"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Link, useNavigate } from "@/lib/router"; import { agentRouteRef, cn } from "@/lib/utils"; export interface AgentConversationSidebarProps { agents: Agent[]; /** Agents with a saved conversation; defaults to every listed agent. */ existingChatAgentIds?: readonly string[]; availableAgents?: Agent[]; activeId?: string; previews?: Record; loading?: boolean; error?: Error | null; onRetry?: () => void; initialSearch?: string; onSelect?: (agent: Agent, signal?: AbortSignal) => void | Promise; onBrowse?: () => void; onAddChat?: (agent: Agent, signal?: AbortSignal) => void | Promise; historyLoading?: boolean; historyError?: Error | null; onRetryHistory?: () => void; } /** Searchable navigation for one conversation per agent. */ export function AgentConversationSidebar({ agents, existingChatAgentIds, availableAgents = agents, activeId, previews = {}, loading = false, error, onRetry, initialSearch = "", onSelect, onBrowse, onAddChat, historyLoading, historyError, onRetryHistory }: AgentConversationSidebarProps) { const navigate = useNavigate(); const [pickerOpen, setPickerOpen] = useState(false); const [search, setSearch] = useState(initialSearch); const searchRef = useRef(null); const headingId = useId(); const query = search.trim().toLocaleLowerCase(); const visible = agents.filter(agent => `${agent.name} ${agent.title ?? ""} ${agent.role}`.toLocaleLowerCase().includes(query)); function focusSearch() { setSearch(""); searchRef.current?.focus(); } return ; }