'use client' import { useEffect, useState, useRef } from 'react' import { Network, MessageSquare, Send, Users, CheckCircle, Clock } from 'lucide-react' interface AgentCounts { agents: string[]; counts: Record; total: number } const AGENT_COLORS: Record = { claude: '#FF1D6C', 'claude-sonnet': '#FF1D6C', codex: '#F5A623', 'copilot-2': '#2979FF', 'copilot-3': '#2979FF', 'copilot-window-2': '#2979FF', 'copilot-window-3': '#2979FF', lucidia: '#9C27B0', 'ollama-local': '#22c55e', } export default function MeshPage() { const [mesh, setMesh] = useState(null) const [to, setTo] = useState('all') const [subject, setSubject] = useState('') const [message, setMessage] = useState('') const [sending, setSending] = useState(false) const [sent, setSent] = useState(null) const intervalRef = useRef(null) const load = () => fetch('/api/broadcast').then(r => r.json()).then(setMesh).catch(() => {}) useEffect(() => { load() intervalRef.current = setInterval(load, 15000) return () => clearInterval(intervalRef.current) }, []) const handleSend = async () => { if (!message.trim()) return setSending(true) setSent(null) try { const r = await fetch('/api/broadcast', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ to, subject: subject || 'Message from BlackRoad Web', message }), }) const d = await r.json() setSent(`✅ Delivered to ${d.count} agent${d.count !== 1 ? 's' : ''} — ID: ${d.id}`) setMessage('') setSubject('') setTimeout(load, 500) } catch (e: any) { setSent(`❌ Error: ${e.message}`) } finally { setSending(false) } } return (

Agent Mesh

{mesh?.total ?? 0} messages · {mesh?.agents.length ?? 9} agents · BRAT protocol

{/* Agent Cards */}
Active Agents
{(mesh?.agents ?? ['claude', 'claude-sonnet', 'codex', 'copilot-2', 'copilot-3', 'copilot-window-2', 'copilot-window-3', 'lucidia', 'ollama-local']).map(agent => { const color = AGENT_COLORS[agent] ?? '#888' const count = mesh?.counts[agent] ?? 0 return (
setTo(agent)} style={{ background: to === agent ? `${color}22` : 'rgba(255,255,255,0.04)', border: `1px solid ${to === agent ? color : 'rgba(255,255,255,0.08)'}`, borderRadius: 10, padding: '14px 16px', cursor: 'pointer', transition: 'all .15s', }} >
{agent}
{count} message{count !== 1 ? 's' : ''}
) })}
{/* Broadcast to all card */}
setTo('all')} style={{ marginTop: 12, background: to === 'all' ? 'rgba(255,29,108,0.12)' : 'rgba(255,255,255,0.04)', border: `1px solid ${to === 'all' ? '#FF1D6C' : 'rgba(255,255,255,0.08)'}`, borderRadius: 10, padding: '14px 16px', cursor: 'pointer', transition: 'all .15s', display: 'flex', alignItems: 'center', gap: 10, }} >
Broadcast to all agents
BRAT-RELAY-v1 · {mesh?.agents.length ?? 9} recipients
{/* Compose panel */}
Send Message
{to === 'all' ? '📡 All agents (broadcast)' : `💬 ${to}`}
setSubject(e.target.value)} placeholder="Message from BlackRoad Web" style={{ width: '100%', background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.1)', borderRadius: 6, padding: '8px 12px', color: '#fff', fontSize: 13, outline: 'none', boxSizing: 'border-box' }} />