import { useRef } from "react" import { useVirtualizer } from "@tanstack/react-virtual" import { CheckCircle } from "@phosphor-icons/react" import type { AgentRecord, ConnectorRecord, WorkspaceRecord } from "@shared/types" import { EmptyState, StatusPill } from "../ui" import { useT } from "../../i18n" import { useRovingTabIndex } from "../../lib/keyboard" import { BudgetBar } from "./helpers" export function AgentRoster({ agents, connectors, workspaces, selectedAgentId, onSelect, }: { agents: AgentRecord[] connectors: ConnectorRecord[] workspaces: WorkspaceRecord[] selectedAgentId: string | null onSelect: (agentId: string) => void }) { const t = useT() const parentRef = useRef(null) const { handleKeyDown, getTabIndex, focusedIndex } = useRovingTabIndex(agents.length) const virtualizer = useVirtualizer({ count: agents.length, getScrollElement: () => parentRef.current, estimateSize: () => 56, overscan: 10, }) if (agents.length === 0) { return } return (
{virtualizer.getVirtualItems().map((virtualRow) => { const agent = agents[virtualRow.index] const connector = connectors.find((c) => c.id === agent.connectorId) const workspace = agent.workspaceId ? workspaces.find((w) => w.id === agent.workspaceId) : null const isSelected = agent.id === selectedAgentId return (
) })}
) }