'use client'; import React, { useState } from 'react'; import { ChevronDown, Plus, Star, Bot, Edit, User } 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'; import { CreateAgentDialog } from '@/app/(dashboard)/agents/_components/create-agent-dialog'; interface AgentSelectorProps { onAgentSelect?: (agentId: string | undefined) => void; selectedAgentId?: string; className?: string; variant?: 'default' | 'heading'; } export function AgentSelector({ onAgentSelect, selectedAgentId, className, variant = 'default' }: AgentSelectorProps) { const { data: agents = [], isLoading, refetch: loadAgents } = useAgents(); const router = useRouter(); const [isOpen, setIsOpen] = useState(false); const [createDialogOpen, setCreateDialogOpen] = useState(false); const defaultAgent = agents.find(agent => agent.is_default); const currentAgent = selectedAgentId ? agents.find(agent => agent.agent_id === selectedAgentId) : null; // Display name logic: show selected agent, default agent, or "Suna" as fallback const displayName = currentAgent?.name || defaultAgent?.name || 'Suna'; const isUsingSuna = !currentAgent && !defaultAgent; const handleAgentSelect = (agentId: string | undefined) => { onAgentSelect?.(agentId); setIsOpen(false); }; const handleCreateAgent = () => { setCreateDialogOpen(true); setIsOpen(false); }; const handleManageAgents = () => { router.push('/agents'); setIsOpen(false); }; const handleClearSelection = () => { onAgentSelect?.(undefined); setIsOpen(false); }; if (isLoading) { if (variant === 'heading') { return (
Loading...
); } return (
Loading agents...
); } if (variant === 'heading') { return ( <>

Select an agent

You can create your own agent

handleClearSelection()} className="flex flex-col items-start gap-1 p-3 cursor-pointer" >
Suna Default
{isUsingSuna && (
)}
Your personal AI employee {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 && ( System )}
{currentAgent?.agent_id === agent.agent_id && (
)}
{agent.description && ( {agent.description} )} ))} ) : null} Create New Agent Manage All Agents
); } return ( <>
handleClearSelection()} className="flex flex-col items-start gap-1 p-3 cursor-pointer" >
Suna Default
{isUsingSuna && (
)}
Your personal AI employee {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 && ( System )}
{currentAgent?.agent_id === agent.agent_id && (
)}
{agent.description && ( {agent.description} )} ))} ) : null} Create New Agent Manage All Agents
); }