import{r as c,k as e}from"./index-BVfpSx5Q.js";const m=["checkout","auth","inventory","payments","notifications","search","cdn","postgres","redis","kafka"];function u(){const s=Date.now();return[{id:"ci-1",timestamp:s-3e5,title:"Checkout latency spike — 5x above p99 baseline",severity:"critical",status:"root-caused",rootCause:"PostgreSQL connection pool exhaustion caused by leaked connections in payments service",affectedServices:["checkout","payments","postgres"],causalChain:[{id:"cn-1",service:"postgres",metric:"pg.connections.active",value:95,baseline:40,deviation:137.5,isRootCause:!0,confidence:.94,depth:0,children:["cn-2"]},{id:"cn-2",service:"payments",metric:"http.request.duration_p99",value:2400,baseline:150,deviation:1500,isRootCause:!1,confidence:.88,depth:1,children:["cn-3"]},{id:"cn-3",service:"checkout",metric:"http.request.duration_p99",value:3200,baseline:200,deviation:1500,isRootCause:!1,confidence:.91,depth:2,children:[]}],mttrMs:18e4,counterfactuals:["If pg.connections.max increased to 200, predicted latency impact: -85%","If payments service connection pooling fixed, predicted p99: ~180ms","If read replicas active, predicted checkout impact: negligible"]},{id:"ci-2",timestamp:s-18e5,title:"Auth service error rate surge — 12% of requests failing",severity:"high",status:"resolved",rootCause:"Redis primary node memory pressure causing eviction of session tokens",affectedServices:["auth","redis","checkout","search"],causalChain:[{id:"cn-4",service:"redis",metric:"redis.memory.used_percent",value:98,baseline:65,deviation:50.8,isRootCause:!0,confidence:.91,depth:0,children:["cn-5"]},{id:"cn-5",service:"auth",metric:"http.error_rate",value:12.3,baseline:.1,deviation:12200,isRootCause:!1,confidence:.87,depth:1,children:["cn-6","cn-7"]},{id:"cn-6",service:"checkout",metric:"http.error_rate",value:8.1,baseline:.05,deviation:16100,isRootCause:!1,confidence:.83,depth:2,children:[]},{id:"cn-7",service:"search",metric:"http.error_rate",value:3.2,baseline:.1,deviation:3100,isRootCause:!1,confidence:.79,depth:2,children:[]}],mttrMs:42e4,counterfactuals:["If redis.maxmemory increased 2x, predicted memory: 49% (safe)","If session TTL reduced from 24h to 4h, predicted eviction rate: 0%","If auth fallback to DB-backed sessions, predicted error rate: 0.3%"]},{id:"ci-3",timestamp:s-72e5,title:"Kafka consumer lag causing stale inventory data",severity:"medium",status:"resolved",rootCause:"Consumer group rebalance storm due to aggressive session timeout (10s)",affectedServices:["kafka","inventory","search"],causalChain:[{id:"cn-8",service:"kafka",metric:"kafka.consumer.rebalance_rate",value:14,baseline:.1,deviation:13900,isRootCause:!0,confidence:.89,depth:0,children:["cn-9"]},{id:"cn-9",service:"inventory",metric:"kafka.consumer.lag",value:45e3,baseline:200,deviation:22400,isRootCause:!1,confidence:.86,depth:1,children:["cn-10"]},{id:"cn-10",service:"search",metric:"search.stale_results_ratio",value:8.5,baseline:.1,deviation:8400,isRootCause:!1,confidence:.82,depth:2,children:[]}],mttrMs:3e5,counterfactuals:["If session.timeout.ms increased to 45s, predicted rebalance rate: 0.2/min","If consumer instances scaled from 4 to 8, predicted lag: < 500","If partition count increased, predicted throughput: +150%"]}]}function o({severity:s}){const i={critical:"bg-red-500",high:"bg-orange-500",medium:"bg-yellow-500",low:"bg-green-500"};return e.jsx("div",{className:`w-2 h-2 rounded-full ${i[s]||i.low} ${s==="critical"?"animate-pulse":""}`})}function l({status:s}){const i={investigating:"bg-blue-500/10 text-blue-400 border-blue-500/20","root-caused":"bg-purple-500/10 text-purple-400 border-purple-500/20",remediating:"bg-orange-500/10 text-orange-400 border-orange-500/20",resolved:"bg-green-500/10 text-green-400 border-green-500/20"};return e.jsx("span",{className:`inline-flex items-center px-1.5 py-0.5 text-[10px] font-mono rounded border uppercase ${i[s]||""}`,children:s})}function p(){const[s,i]=c.useState([]),[a,n]=c.useState(null);c.useEffect(()=>{const t=u();i(t),n(t[0])},[]);const d=s.length?Math.round(s.reduce((t,r)=>t+r.mttrMs,0)/s.length/6e4):0;return e.jsxs("div",{className:"space-y-6 max-w-[1400px] mx-auto",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-mono uppercase tracking-[0.2em] text-[#f5f5f5]/40 mb-1",children:"A11OY · INTELLIGENCE · CAUSAL RCA"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight text-[#f5f5f5]",children:"Causal Root-Cause Analysis"}),e.jsx("p",{className:"text-sm text-[#f5f5f5]/50 mt-1 max-w-3xl",children:`Structural causal models for incident diagnosis — inspired by Causely's causal reasoning platform. Encodes service dependency graphs as directed acyclic graphs (DAGs) to trace anomaly propagation and identify true root causes, not just symptoms. Counterfactual "what-if" analysis for remediation planning.`})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[{label:"Active Incidents",value:s.filter(t=>t.status!=="resolved").length,color:"#ef4444"},{label:"Avg MTTR",value:`${d}m`,color:"#06b6d4"},{label:"Auto-Diagnosed",value:`${s.length}/${s.length}`,color:"#4ade80"},{label:"Services Modeled",value:m.length,color:"#c9b787"}].map(t=>e.jsxs("div",{className:"bg-[#0a0a0f] border border-white/[0.06] rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"text-[10px] font-mono uppercase tracking-widest text-white/30",children:t.label}),e.jsx("p",{className:"text-xl font-mono font-bold",style:{color:t.color},children:t.value})]},t.label))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-[#0a0a0f] border border-white/[0.06] rounded-lg overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b border-white/[0.06]",children:e.jsx("h2",{className:"text-sm font-mono font-semibold uppercase tracking-wider text-white/70",children:"Incidents"})}),e.jsx("div",{className:"divide-y divide-white/[0.03] max-h-[500px] overflow-y-auto",children:s.map(t=>e.jsxs("button",{type:"button",className:`w-full text-left px-4 py-3 cursor-pointer transition-colors ${(a==null?void 0:a.id)===t.id?"bg-white/[0.04]":"hover:bg-white/[0.02]"}`,onClick:()=>n(t),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(o,{severity:t.severity}),e.jsx(l,{status:t.status})]}),e.jsx("p",{className:"text-xs font-bold text-white/80",children:t.title}),e.jsxs("p",{className:"text-[10px] text-white/30 mt-0.5",children:[new Date(t.timestamp).toLocaleTimeString()," · ",t.affectedServices.length," services"]})]},t.id))})]}),a&&e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs("div",{className:"bg-[#0a0a0f] border border-white/[0.06] rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(o,{severity:a.severity}),e.jsx("h2",{className:"text-sm font-mono font-semibold text-white/80",children:a.title}),e.jsx(l,{status:a.status})]}),e.jsxs("div",{className:"p-3 rounded bg-red-500/5 border border-red-500/10 mb-4",children:[e.jsx("p",{className:"text-[10px] font-mono uppercase tracking-wider text-red-400/60 mb-1",children:"ROOT CAUSE"}),e.jsx("p",{className:"text-xs text-white/70",children:a.rootCause})]}),e.jsx("h3",{className:"text-xs font-mono uppercase tracking-wider text-white/50 mb-3",children:"Causal Chain (DAG)"}),e.jsx("div",{className:"space-y-2",children:a.causalChain.map((t,r)=>e.jsxs("div",{className:"flex items-start gap-3",style:{paddingLeft:t.depth*24},children:[t.depth>0&&e.jsx("div",{className:"flex items-center gap-1 text-white/15 flex-shrink-0",children:e.jsx("span",{className:"text-[10px] font-mono",children:"└→"})}),e.jsxs("div",{className:`flex-1 p-3 rounded border ${t.isRootCause?"bg-red-500/5 border-red-500/20":"bg-white/[0.02] border-white/[0.04]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono font-bold text-[#c9b787]",children:t.service}),t.isRootCause&&e.jsx("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-red-500/10 text-red-400 border border-red-500/20",children:"ROOT CAUSE"})]}),e.jsxs("span",{className:"text-[10px] font-mono text-white/30",children:[(t.confidence*100).toFixed(0),"% confidence"]})]}),e.jsxs("p",{className:"text-[10px] font-mono text-white/50 mt-1",children:[t.metric,": ",e.jsx("span",{className:"text-white/70",children:t.value}),e.jsxs("span",{className:"text-white/25",children:[" (baseline: ",t.baseline,", +",t.deviation.toFixed(0),"%)"]})]})]})]},t.id))})]}),e.jsxs("div",{className:"bg-[#0a0a0f] border border-white/[0.06] rounded-lg p-5",children:[e.jsx("h3",{className:"text-xs font-mono uppercase tracking-wider text-white/50 mb-3",children:"Counterfactual Analysis"}),e.jsx("p",{className:"text-[10px] font-mono text-white/30 mb-3",children:"What-if scenarios generated by causal structural model"}),e.jsx("div",{className:"space-y-2",children:a.counterfactuals.map((t,r)=>e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-white/[0.02] border border-white/[0.04]",children:[e.jsx("span",{className:"text-[10px] font-mono text-purple-400 flex-shrink-0 mt-0.5",children:"↳"}),e.jsx("p",{className:"text-[11px] text-white/50",children:t})]},r))})]})]})]})]})}export{p as CausalRCA};