import { useState, useEffect } from "react"; import { TrendingUp, AlertTriangle, Info, Clock, ArrowRight, RefreshCw } from "lucide-react"; interface AmbientSignal { id: string; domain: string; title: string; summary: string; severity: "critical" | "high" | "medium" | "low" | "info"; score: number; timestamp: number; actionUrl?: string; actionLabel?: string; correlatedDomains?: string[]; signalChainActive?: boolean; live?: boolean; } const DOMAIN_COLORS: Record = { firestorm: "#ef4444", aegis: "#ef4444", vessels: "var(--gi-accent-blue)", terra: "#22c55e", prism: "#8b5cf6", lyte: "#f59e0b", "szl-holdings": "#8b7ac8", carlota: "#ec4899", }; const DOMAIN_LABELS: Record = { firestorm: "PARAGON", aegis: "PARAGON", vessels: "SEXTANT", terra: "DOMAINE", prism: "PRISM", lyte: "KORA", "szl-holdings": "Holdings", carlota: "Carlota Jo", }; const SEVERITY_ICON: Record = { critical: , high: , medium: , low: , info: , }; const SEVERITY_COLOR: Record = { critical: "#ef4444", high: "#f59e0b", medium: "#3b82f6", low: "#6b7280", info: "#22c55e", }; function timeAgo(ts: number) { const diff = Date.now() - ts; if (diff < 60000) return "Just now"; if (diff < 3600000) return `${Math.round(diff / 60000)}m ago`; if (diff < 86400000) return `${Math.round(diff / 3600000)}h ago`; return `${Math.round(diff / 86400000)}d ago`; } const STATIC_SIGNALS: AmbientSignal[] = [ { id: "sig-critical-1", domain: "firestorm", title: "APT-41 Lateral Movement Detected", summary: "Nation-state threat actor active across 3 subsidiaries. Legal hold triggered. Risk score elevated 72→81.", severity: "critical", score: 0.97, timestamp: Date.now() - 1800000, correlatedDomains: ["prism", "szl-holdings"], signalChainActive: true, actionLabel: "View Incident", }, { id: "sig-high-1", domain: "vessels", title: "Port Delay: MV Pacific Star +32h", summary: "Shanghai congestion causing 32-hour delay. 12 DOMAINE properties and 8 PRISM contracts flagged via signal chain.", severity: "high", score: 0.88, timestamp: Date.now() - 3600000, correlatedDomains: ["terra", "prism"], signalChainActive: true, actionLabel: "View Fleet", }, { id: "sig-high-2", domain: "terra", title: "18 Properties Above Distress Threshold", summary: "Rate volatility refresh flagged 18 properties. Correlated with market volatility signal from Holdings.", severity: "high", score: 0.79, timestamp: Date.now() - 7200000, correlatedDomains: ["szl-holdings"], actionLabel: "View Portfolio", }, { id: "sig-medium-1", domain: "szl-holdings", title: "Market Volatility Index: 0.72", summary: "Threshold crossed. Portfolio rebalance signal chain triggered across DOMAINE, SEXTANT, and fund ops.", severity: "medium", score: 0.71, timestamp: Date.now() - 3600000, correlatedDomains: ["terra", "vessels"], signalChainActive: true, actionLabel: "View Dashboard", }, { id: "sig-medium-2", domain: "prism", title: "Judicial Pattern Shift: SDNY", summary: "Ruling pattern shift in Southern District detected. Strategy brief update recommended for 3 active matters.", severity: "medium", score: 0.66, timestamp: Date.now() - 172800000, actionLabel: "View Patterns", }, { id: "sig-info-1", domain: "lyte", title: "Self-Healing: 94% Autonomous Resolve", summary: "Highest self-healing rate on record. KORA autonomously resolved all P1 incidents without human intervention.", severity: "info", score: 0.38, timestamp: Date.now() - 86400000, actionLabel: "View Platform", }, ]; interface AmbientSignalRankerProps { apiBase?: string; } export function AmbientSignalRanker({ apiBase = "" }: AmbientSignalRankerProps) { const [signals, setSignals] = useState(STATIC_SIGNALS); const [loading, setLoading] = useState(false); const [isDemo, setIsDemo] = useState(true); const [lastRefreshed, setLastRefreshed] = useState(Date.now()); async function fetchSignals() { setLoading(true); try { const res = await fetch(`${apiBase}/api/innovation-engine/ambient-signals`); if (res.ok) { const data: AmbientSignal[] = await res.json(); if (Array.isArray(data) && data.length > 0) { const enriched = data.map((s) => ({ ...s, correlatedDomains: STATIC_SIGNALS.find((st) => st.domain === s.domain)?.correlatedDomains, signalChainActive: STATIC_SIGNALS.find((st) => st.domain === s.domain)?.signalChainActive, live: s.live === true, })); setSignals(enriched.sort((a, b) => b.score - a.score)); setIsDemo(false); return; } } setSignals(STATIC_SIGNALS); setIsDemo(true); } catch { setSignals(STATIC_SIGNALS); setIsDemo(true); } finally { setLoading(false); setLastRefreshed(Date.now()); } } useEffect(() => { fetchSignals(); const interval = setInterval(fetchSignals, 120000); return () => clearInterval(interval); }, []); const topSignals = signals.slice(0, 6); return (

Ambient Signal Ranker

{!loading && isDemo && ( Demo )} {!loading && !isDemo && ( Live )}
{timeAgo(lastRefreshed)}
{topSignals.map((sig, idx) => { const domainColor = DOMAIN_COLORS[sig.domain] ?? "#6b7280"; const severityColor = SEVERITY_COLOR[sig.severity] ?? "#6b7280"; const label = DOMAIN_LABELS[sig.domain] ?? sig.domain; return (
{idx + 1}
{Math.round(sig.score * 100)}
{label} {sig.live && ( Live )} {sig.signalChainActive && ( Chain Active )}
{SEVERITY_ICON[sig.severity]} {sig.severity}

{sig.title}

{sig.summary}

{sig.correlatedDomains?.map((cd) => ( ↔ {DOMAIN_LABELS[cd] ?? cd} ))}
{timeAgo(sig.timestamp)}
{sig.actionLabel && ( )}
); })}
); }