'use client' import { useEffect, useState } from 'react' import { useAgentStore } from '@/hooks/useAgentStore' import { getConnectors } from '@/lib/api' const setConnectorToken = (id: string, token: string) => fetch('/api/v1/connectors/' + id + '/token', { method: 'POST', body: JSON.stringify({ token }), headers: { 'Content-Type': 'application/json' } }) import { Plug, CheckCircle2, XCircle, Eye, EyeOff, ChevronRight, RefreshCw, Zap } from 'lucide-react' const CATEGORY_LABELS: Record = { ai: 'πŸ€– AI Providers', code: 'πŸ’» Code & Dev', deploy: 'πŸš€ Deployment', workflow: 'βš™οΈ Workflow', messaging: 'πŸ’¬ Messaging', infra: 'πŸ—οΈ Infrastructure', } const CATEGORY_ORDER = ['ai', 'code', 'deploy', 'workflow', 'messaging', 'infra'] interface Connector { id: string name: string connected: boolean color: string description: string category: string token_preview?: string } export default function ConnectorsPanel() { const { locale } = useAgentStore() const [connectors, setConnectors] = useState([]) const [loading, setLoading] = useState(true) const [tokenInputs, setTokenInputs] = useState>({}) const [showToken, setShowToken] = useState>({}) const [saving, setSaving] = useState>({}) const [activeCategory, setActiveCategory] = useState(null) const load = async () => { setLoading(true) try { const data = await getConnectors() setConnectors(data.connectors || []) } catch {} setLoading(false) } useEffect(() => { load() }, []) const saveToken = async (id: string) => { const token = tokenInputs[id]?.trim() if (!token) return setSaving(s => ({ ...s, [id]: true })) try { await setConnectorToken(id, token) setConnectors(prev => prev.map(c => c.id === id ? { ...c, connected: true, token_preview: token.slice(0, 8) + '...' } : c)) setTokenInputs(s => ({ ...s, [id]: '' })) } catch {} setSaving(s => ({ ...s, [id]: false })) } const byCategory = CATEGORY_ORDER.reduce((acc, cat) => { const items = connectors.filter(c => c.category === cat) if (items.length) acc[cat] = items return acc }, {} as Record) const connected = connectors.filter(c => c.connected) const total = connectors.length return (
{/* Header */}
{locale === 'my' ? 'ချိတ်ဆက်မှုများ' : 'Connectors'} 0 ? 'rgba(34,197,94,0.15)' : 'rgba(99,102,241,0.15)', color: connected.length > 0 ? '#4ade80' : '#818cf8', border: `1px solid ${connected.length > 0 ? 'rgba(34,197,94,0.3)' : 'rgba(99,102,241,0.3)'}` }}> {connected.length}/{total}
{/* Summary bar */} {connected.length > 0 && (
{connected.slice(0, 6).map(c => (
{c.name}
))} {connected.length > 6 && (
+{connected.length - 6} more
)}
)} {/* Connectors list */}
{loading ? (
{[...Array(4)].map((_, i) => (
))}
) : ( Object.entries(byCategory).map(([cat, items]) => (

{CATEGORY_LABELS[cat] || cat}

{items.map(c => ( setTokenInputs(s => ({ ...s, [c.id]: v }))} onToggleShow={() => setShowToken(s => ({ ...s, [c.id]: !s[c.id] }))} onSave={() => saveToken(c.id)} /> ))}
)) )}
{/* Footer hint */}

{locale === 'my' ? 'Token များ env var တွင် α€‘α€Šα€·α€Ία€žα€½α€„α€Ία€Έα€”α€­α€―α€„α€Ία€žα€Šα€Ί β€” Runtime α€α€½α€„α€Ία€œα€Šα€Ία€Έ α€‘α€Šα€·α€Ία€”α€­α€―α€„α€Ία€žα€Šα€Ί' : 'Add tokens via env vars or set them at runtime above'}

) } function ConnectorCard({ connector: c, tokenInput, showToken, saving, onTokenChange, onToggleShow, onSave }: { connector: Connector tokenInput: string showToken: boolean saving: boolean onTokenChange: (v: string) => void onToggleShow: () => void onSave: () => void }) { const [expanded, setExpanded] = useState(false) return (
{/* Token input (expanded) */} {expanded && !c.connected && (

Add API token to connect:

onTokenChange(e.target.value)} placeholder="Token..." className="flex-1 bg-transparent text-[11px] outline-none" style={{ color: 'var(--text-primary)' }} onKeyDown={e => e.key === 'Enter' && onSave()} />
)}
) }