import React, { useMemo, useState } from 'react'; import { Link } from 'wouter'; import { toast } from 'sonner'; import { emitProof } from '@workspace/a11oy-orchestration/client'; import { RELAY_DESTINATIONS, RELAY_MAPPINGS, RELAY_OUTCOMES, RELAY_POLICIES, RELAY_RUN_EVENTS, RELAY_SOURCES, RELAY_MODELS, AMARU_AGENTS, VERTICAL_PLAYBOOKS, } from '@/data/fabric'; import { buildApprovalQueue, buildCockpitKpis, calculateDestinationHealth, computeLutarSigma, rankSyncRisk, generateRecommendedAction, } from '@/lib/agentic'; import { ConduitGovernancePanels } from '../components/GovernancePanels'; import { FabricCard, FabricStat, GovernanceDot, HeatCell, MicroBar, SeverityChip, Sparkline, } from '@/components/fabric/primitives'; import { Badge, Button } from '@/components/ui'; import { INNOVATION_CAPABILITIES } from '@/data/innovation/competitive'; import { useStats, useConnections, useSyncs } from '@/lib/api-hooks'; import { AmaruHealthPanel } from '@/components/AmaruLive'; export default function Dashboard() { const liveStats = useStats(); const liveConnections = useConnections(); const liveSyncs = useSyncs(); const kpis = useMemo( () => buildCockpitKpis({ events: RELAY_RUN_EVENTS, destinations: RELAY_DESTINATIONS, mappings: RELAY_MAPPINGS, outcomes: RELAY_OUTCOMES, policies: RELAY_POLICIES }), [], ); const approvals = useMemo( () => buildApprovalQueue(RELAY_MAPPINGS, (mid) => { const m = RELAY_MODELS.find((mo) => mo.id === mid); return m ? RELAY_SOURCES.find((s) => s.id === m.sourceId) ?? null : null; }), [], ); const risk = useMemo(() => rankSyncRisk(RELAY_RUN_EVENTS).slice(0, 6), []); const sigma = useMemo( () => computeLutarSigma({ P: 0.92, K: RELAY_DESTINATIONS.reduce((s, d) => s + d.fieldContractStrength, 0) / RELAY_DESTINATIONS.length, phi: RELAY_MAPPINGS.reduce((s, m) => s + m.confidence, 0) / RELAY_MAPPINGS.length, C: kpis.failedRecords24h === 0 ? 1 : Math.max(0.5, 1 - kpis.failedRecords24h / Math.max(1, kpis.recordsActivated24h)), }), [kpis], ); const blockFeed = useMemo( () => RELAY_POLICIES.flatMap((p) => p.recentHits.map((h) => ({ ...h, policy: p }))) .sort((a, b) => (a.atIso < b.atIso ? 1 : -1)) .slice(0, 8), [], ); const throughput = useMemo(() => { const buckets = new Array(12).fill(0); const now = Date.now(); for (const e of RELAY_RUN_EVENTS) { if (e.type !== 'completed') continue; const idx = Math.floor((now - Date.parse(e.atIso)) / (60 * 60 * 1000)); if (idx >= 0 && idx < 12) buckets[11 - idx] += e.recordsAffected; } return buckets; }, []); const heat = useMemo(() => { const verticals = Array.from(new Set(RELAY_RUN_EVENTS.map((e) => e.verticalId))).slice(0, 7); const cats = Array.from(new Set(RELAY_DESTINATIONS.map((d) => d.category))); const grid: { vertical: string; category: string; count: number }[] = []; for (const v of verticals) { for (const c of cats) { const count = RELAY_RUN_EVENTS.filter( (e) => (e.type === 'failed' || e.type === 'rolled_back' || e.type === 'quarantined') && e.verticalId === v && RELAY_DESTINATIONS.find((d) => d.id === e.destinationId)?.category === c, ).length; grid.push({ vertical: v, category: c, count }); } } const max = Math.max(1, ...grid.map((g) => g.count)); return { verticals, cats, grid, max }; }, []); const [handoffPending, setHandoffPending] = useState(false); async function handoffToA11oy() { if (handoffPending) return; setHandoffPending(true); const refId = `amaru-cycle-${Date.now().toString(36)}`; try { const proof = await emitProof({ product: 'amaru', kind: 'action_executed', summary: `Amaru ouroboros cycle snapshot · ${kpis.activeSyncs} active syncs · LUTAR Σ ${(sigma.sigma * 100).toFixed(1)}%`, deepLink: '/conduit/', payload: { cycleRefId: refId, activeSyncs: kpis.activeSyncs, recordsActivated24h: kpis.recordsActivated24h, failedRecords24h: kpis.failedRecords24h, lutarSigma: sigma.sigma, }, }); toast.success(`Anchored to A11oy ledger · proof ${proof.id.slice(0, 12)}…`, { description: 'Inspect the cycle in A11oy → Conductor → Recent Proofs.', }); } catch (err) { toast.error('A11oy handoff failed', { description: (err as Error).message }); } finally { setHandoffPending(false); } } return (
Sovereign agentic activation. The serpent that holds the spine: discover sources, compose models, govern by policy, deliver with witness, and learn from outcomes — in one closed loop, replay-grade.
Original capabilities assembled from field research across 10 public reverse ETL projects — re-implemented as A11oy-native, governed, proof-anchored primitives.