'use client'; import React, { useState } from 'react'; import { ChevronDown, Plus, Star, Bot } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Badge } from '@/components/ui/badge'; import { useAgents } from '@/hooks/react-query/agents/use-agents'; import { useRouter } from 'next/navigation'; import { cn } from '@/lib/utils'; interface AgentSelectorProps { onAgentSelect?: (agentId: string) => void; selectedAgentId?: string; className?: string; } export function AgentSelector({ onAgentSelect, selectedAgentId, className }: AgentSelectorProps) { const { data: agents = [], isLoading } = useAgents(); const router = useRouter(); const [isOpen, setIsOpen] = useState(false); const defaultAgent = agents.find(agent => agent.is_default); const currentAgent = selectedAgentId ? agents.find(agent => agent.agent_id === selectedAgentId) : defaultAgent; const handleAgentSelect = (agentId: string) => { onAgentSelect?.(agentId); setIsOpen(false); }; const handleNewAgent = () => { router.push('/agents'); setIsOpen(false); }; const handleManageAgents = () => { router.push('/agents'); setIsOpen(false); }; if (isLoading) { return (
Loading agents...
); } return (
{agents.length > 0 ? ( <> {agents.map((agent) => ( handleAgentSelect(agent.agent_id)} className="flex flex-col items-start gap-1 p-3 cursor-pointer" >
{agent.name} {agent.is_default && ( Default )}
{currentAgent?.agent_id === agent.agent_id && (
)}
{agent.description && ( {agent.description} )} ))} ) : ( No agents available )} New Agent Manage Agents
); }