"use client"; import { MetricCard } from "@/components/ui/metric-card"; import { Flag, Activity, AlertCircle, ShieldAlert, TrendingUp, Target, Users2, CheckCircle2, AlertTriangle, Zap } from "lucide-react"; import { Area, AreaChart, Tooltip, XAxis, YAxis, CartesianGrid, BarChart, Bar, Cell, ResponsiveContainer } from "recharts"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Progress } from "@/components/ui/progress"; import { useMemo, useEffect, useState } from "react"; import { Observation, api } from "@/lib/api"; import { cn } from "@/lib/utils"; import { useEnv } from "@/components/env-provider"; const Dashboard = () => { const { dashboard: data, state, connectionState, connectionText, isSimulating, setIsSimulating, runSimulationStep, fetchData } = useEnv(); const loading = useMemo(() => connectionState === "checking" && !data && !state, [connectionState, data, state]); useEffect(() => { let simInterval: NodeJS.Timeout; if (isSimulating) { simInterval = setInterval(runSimulationStep, 2000); } return () => clearInterval(simInterval); }, [isSimulating, state]); const lastObs: Observation | undefined = state?.history?.[state.history.length - 1]?.observation; const healthScore = lastObs?.system_health_score ?? data?.summary?.health_score ?? 0; const errorRate = (lastObs?.error_rate ?? data?.summary?.error_rate ?? 0) * 100; const latency = lastObs?.latency_p99_ms ?? data?.summary?.latency_p99_ms ?? 0; const extra = lastObs?.extra_context as Record | undefined; const anomalyRaw = (extra?.anomaly ?? extra?.tenant_anomaly) as unknown; const anomaly = anomalyRaw && typeof anomalyRaw === "object" ? (anomalyRaw as Record) : {}; const anomalyIs = Boolean(anomaly.is_anomaly); const anomalyScore = Number(anomaly.anomaly_score ?? 0); const anomalyList = Array.isArray(anomaly.anomalies) ? (anomaly.anomalies as unknown[]) : []; const benchmarkingRaw = extra?.benchmarking as unknown; const benchmarking = benchmarkingRaw && typeof benchmarkingRaw === "object" ? (benchmarkingRaw as Record) : {}; const benchmarkingPercentile = Number(benchmarking.percentile ?? 0); const benchmarkingComparison = typeof benchmarking.comparison === "string" ? benchmarking.comparison : ""; const patternRisk = Number(extra?.pattern_risk ?? extra?.tenant_pattern_risk ?? 0); const chaos = (lastObs?.chaos_incident && typeof lastObs.chaos_incident === "object") ? (lastObs.chaos_incident as Record) : null; const chaosType = typeof chaos?.type === "string" ? chaos.type : "incident"; const chaosDescription = typeof chaos?.description === "string" ? chaos.description : ""; const chaosIntensity = Number(chaos?.intensity ?? 0); const stakeholderData = [ { name: "DevOps", score: lastObs?.stakeholder_devops_sentiment ?? 0 }, { name: "Product", score: lastObs?.stakeholder_product_sentiment ?? 0 }, { name: "Customer", score: lastObs?.stakeholder_customer_sentiment ?? 0 }, ]; return (

Enterprise Overview

Real-time autonomous deployment monitoring.

{loading ? "Syncing..." : connectionText}
{/* Primary Metrics */}
} trend={{ value: 2.4, label: "vs baseline", isPositive: healthScore > 0.9 }} /> } /> } trend={{ value: 2.1, label: "from baseline", isPositive: latency < 150 }} /> } trend={{ value: 0.05, label: "increase", isPositive: errorRate < 0.1 }} />
{/* Mission Progress */} {lastObs?.mission_name && (
Mission: {lastObs.mission_name} Phase {lastObs.phase_index !== undefined ? lastObs.phase_index + 1 : 0} of {lastObs.total_phases}: {lastObs.current_phase}
{((lastObs.phase_progress ?? 0) * 100).toFixed(0)}% Completed
{lastObs.phase_objectives?.map((obj, i) => ( {obj} ))}
)} {/* Anomaly & Risk Sidecar */} Advanced Sidecars
Anomaly Score {anomalyScore.toFixed(2)}
Pattern Risk
{(patternRisk * 100).toFixed(0)}%
Detected Anomalies
{anomalyList.length > 0 ? ( anomalyList.map((a) => ( {String(a)} )) ) : ( None detected )}
{/* Main Traffic Chart */} Evaluation Traffic Live Stream
({ time: h.observation?.time_step, rollout: h.observation?.current_rollout_percentage, error: (h.observation?.error_rate ?? 0) * 100 })) : [ { time: -2, rollout: 5, error: 0.1 }, { time: -1, rollout: 5, error: 0.15 }, { time: 0, rollout: 5, error: 0.1 } ]} margin={{ top: 20, right: 30, left: 0, bottom: 0 }} >
{/* Stakeholder Sentiments */} Stakeholder Sentiments Real-time feedback from cross-functional teams.
{stakeholderData.map((entry, index) => ( 0 ? "var(--primary)" : "var(--destructive)"} opacity={0.8} /> ))}
Overall Approval {lastObs?.stakeholder_overall_approval ? "APPROVED" : "BLOCKED"}
{/* Bottom Row: Benchmarking & Chaos */}
Benchmarking
{(benchmarkingPercentile * 100).toFixed(0)}th Global Percentile

{benchmarkingComparison ? <> "{benchmarkingComparison}" : "—"}

Active Alerts & Incidents
Slack
{chaos ? (

{chaosType}

{chaosDescription}

INTENSITY: {(chaosIntensity * 100).toFixed(0)}% CRITICAL ACTION REQUIRED
) : (
No active chaos incidents.
)}
); }; export default Dashboard;