import { useCallback, useEffect, useMemo, useState } from 'react' import { Check, ShieldCheck, X } from 'lucide-react' import { fetchApprovalHistory } from '../../lib/api' import type { Agent, Approval } from '../../types' import { getAgentMeta } from '../../lib/agentMeta' import { Badge } from '../ui/Badge' import { Button } from '../ui/Button' import { cn } from '../../lib/utils' type Filter = 'pending' | 'approved' | 'denied' | 'all' type Props = { agents: Agent[] livePending: Approval[] onDecide: (id: string, approved: boolean, decidedBy: string, note: string) => Promise } export function ApprovalInbox({ agents, livePending, onDecide }: Props) { const [filter, setFilter] = useState('pending') const [items, setItems] = useState([]) const [stats, setStats] = useState({ pending: 0, approved: 0, denied: 0, total: 0 }) const [selectedId, setSelectedId] = useState(null) const [decider, setDecider] = useState<'mo-commander' | 'bart-commander'>('mo-commander') const [note, setNote] = useState('') const [busy, setBusy] = useState(false) const load = useCallback(async () => { const res = await fetchApprovalHistory(filter === 'all' ? 'all' : filter) setItems(res.approvals) if (res.stats) setStats(res.stats) }, [filter]) useEffect(() => { load() }, [load, livePending]) const selected = useMemo(() => items.find((a) => a.id === selectedId) || items[0] || null, [items, selectedId]) const agentOf = (id: string) => agents.find((a) => a.id === id) const handleDecide = async (approved: boolean) => { if (!selected || selected.status !== 'pending') return setBusy(true) try { await onDecide(selected.id, approved, decider, note) setNote('') await load() } finally { setBusy(false) } } return (

Approval Inbox

Mo & Bart review mutating agent actions

{stats.pending} pending {stats.approved} ok {stats.denied} denied
{(['pending', 'approved', 'denied', 'all'] as Filter[]).map((f) => ( ))}
{!items.length &&

No {filter} requests.

} {items.map((a) => { const ag = agentOf(a.agent_id) const meta = ag ? getAgentMeta(ag.id) : null const Icon = meta?.icon return ( ) })}
{selected && (
{selected.status}
Agent
{agentOf(selected.agent_id)?.name}
Type
{selected.action_type}
Action
{selected.action}
Reason
{selected.reason}
{selected.status === 'pending' && (
setNote(e.target.value)} placeholder="Note (optional)" className="w-full rounded border border-border bg-surface px-2 py-1 text-[10px] text-foreground-muted" />
)}
)}
) }