import { useMemo } from 'react' import { Check } from 'lucide-react' const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase() import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { useAgents } from '@/hooks/useOpenCode' import { getAgentStyleVars } from '@/lib/agent-colors' interface AgentQuickSelectProps { directory?: string currentAgent: string onAgentChange: (agent: string) => void isBashMode?: boolean } interface AgentInfo { id: string name: string color?: string description?: string mode?: string hidden?: boolean } const findAgent = (agents: AgentInfo[], agentId: string): AgentInfo | undefined => { return agents.find(a => a.id.toLowerCase() === agentId.toLowerCase()) } export function AgentQuickSelect({ directory, currentAgent, onAgentChange, isBashMode = false, }: AgentQuickSelectProps) { const { data: agents = [] } = useAgents(directory) const primaryAgents = useMemo(() => { return agents.filter( (agent) => (agent.mode === 'primary' || agent.mode === 'all') && !agent.hidden ) }, [agents]) const handleSelect = (agentId: string) => { onAgentChange(agentId) } const currentAgentInfo = findAgent(agents, currentAgent) const styleVars = isBashMode ? getAgentStyleVars('plan') : getAgentStyleVars(currentAgent, currentAgentInfo?.color) const displayName = isBashMode ? 'Bash' : capitalize(currentAgentInfo?.name ?? currentAgent) const buttonContent = ( {displayName} ) return ( {buttonContent} {primaryAgents.map((agent) => { const apiColor = agent.color const itemStyleVars = getAgentStyleVars(agent.id, apiColor) const isSelected = agent.id.toLowerCase() === currentAgent.toLowerCase() return ( handleSelect(agent.id)} className="group flex items-center justify-between" > {capitalize(agent.name)} {agent.description && ( {agent.description} )} {isSelected && } ) })} ) }