/** * SubAgentSelector — Database-driven AI Agent selection * * Displays real AI Agents from the database as toggleable items. * Parent component fetches available agents and passes them via props. * Selected agents are tracked by numeric row_id. */ import { Check, Bot, Loader2 } from 'lucide-react'; import { cn } from '@/shared/utils/cn'; import { useLanguage } from '@/shared/i18n/LanguageContext'; /** A single available agent from the database */ export interface AvailableAgent { row_id: number; name: string; icon?: string | null; description?: string; } export interface SubAgentSelectorProps { /** Currently selected sub-agent row_ids */ value: number[]; /** Callback when selection changes */ onChange: (rowIds: number[]) => void; /** Available agents to pick from (fetched by parent) */ availableAgents: AvailableAgent[]; /** Whether the selector is disabled */ disabled?: boolean; /** Whether agents are loading */ isLoading?: boolean; } export function SubAgentSelector({ value, onChange, availableAgents, disabled = false, isLoading = false, }: SubAgentSelectorProps) { const { t } = useLanguage(); const toggleAgent = (rowId: number) => { if (disabled) return; const isSelected = value.includes(rowId); if (isSelected) { onChange(value.filter(id => id !== rowId)); } else { onChange([...value, rowId]); } }; return (
{/* Header */}
{t('chat.subAgents') || 'Sub-agents'}
{/* Loading state */} {isLoading && (
)} {/* Empty state */} {!isLoading && availableAgents.length === 0 && (
{t('chat.noAgentsAvailable') || 'No agents available'}
)} {/* Agent list */} {!isLoading && availableAgents.length > 0 && (
{availableAgents.map(agent => { const isSelected = value.includes(agent.row_id); return ( ); })}
)}
); } export default SubAgentSelector;