File size: 4,334 Bytes
5d10875
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/** Shared chips + labels for the Launch Readiness UI. */
import Box from '@mui/material/Box';
import Chip from '@mui/material/Chip';
import Tooltip from '@mui/material/Tooltip';
import Typography from '@mui/material/Typography';
import type { EvidenceStatus, PolicyOutcome, Severity } from '../../types/agentic';

export const SEVERITY_COLORS: Record<Severity, string> = {
  S0: '#455a64',
  S1: '#546e7a',
  S2: '#f9a825',
  S3: '#ef6c00',
  S4: '#d84315',
  S5: '#b71c1c',
};

export const OUTCOME_STYLE: Record<PolicyOutcome, { bg: string; fg: string; label: string }> = {
  AUTOMATIC_STOP_SHIP: { bg: '#b71c1c', fg: '#fff', label: 'AUTOMATIC STOP-SHIP' },
  LAUNCH_REVIEW_REQUIRED: { bg: '#e65100', fg: '#fff', label: 'LAUNCH REVIEW REQUIRED' },
  CONTINUE_INVESTIGATION: { bg: '#0d47a1', fg: '#90caf9', label: 'CONTINUE INVESTIGATION' },
  NO_LAUNCH_IMPACT: { bg: '#1b5e20', fg: '#a5d6a7', label: 'NO LAUNCH IMPACT' },
  INDETERMINATE: { bg: '#4a148c', fg: '#ce93d8', label: 'INDETERMINATE (FAIL-SAFE)' },
};

export const EVIDENCE_STATUS_COLORS: Record<EvidenceStatus, string> = {
  OBSERVED: '#2e7d32',
  DERIVED: '#0277bd',
  HYPOTHESIS: '#f9a825',
  UNAVAILABLE: '#757575',
};

export function SeverityChip({ severity }: { severity: Severity | null | undefined }) {
  if (!severity) return <Chip size="small" label="unrated" sx={{ height: 20, fontSize: 11 }} />;
  return (
    <Chip
      size="small"
      label={severity}
      sx={{
        height: 20,
        fontSize: 11,
        fontWeight: 800,
        bgcolor: SEVERITY_COLORS[severity],
        color: '#fff',
      }}
    />
  );
}

export function OutcomeChip({ outcome }: { outcome: PolicyOutcome | null | undefined }) {
  if (!outcome) return <Chip size="small" label="no decision" sx={{ height: 20, fontSize: 11 }} />;
  const s = OUTCOME_STYLE[outcome];
  return (
    <Chip
      size="small"
      label={s.label}
      sx={{ height: 20, fontSize: 10.5, fontWeight: 800, bgcolor: s.bg, color: s.fg }}
    />
  );
}

export function EvidenceStatusChip({ status }: { status: EvidenceStatus }) {
  return (
    <Chip
      size="small"
      label={status}
      sx={{
        height: 18,
        fontSize: 10,
        fontWeight: 700,
        bgcolor: EVIDENCE_STATUS_COLORS[status],
        color: '#fff',
      }}
    />
  );
}

/** Marks a value as AI analysis (advisory) vs a deterministic measurement. */
export function OriginBadge({ origin }: { origin: 'ai' | 'deterministic' }) {
  const isAi = origin === 'ai';
  return (
    <Tooltip
      title={
        isAi
          ? 'Produced by an advisory AI agent — a recommendation or hypothesis, never an authorization.'
          : 'Produced by deterministic code (metrics, statistics, policy) — reproducible and testable.'
      }
    >
      <Chip
        size="small"
        label={isAi ? 'AI ANALYSIS (ADVISORY)' : 'DETERMINISTIC'}
        sx={{
          height: 18,
          fontSize: 9.5,
          fontWeight: 800,
          letterSpacing: 0.4,
          bgcolor: isAi ? '#4a148c' : '#1b3a4b',
          color: isAi ? '#ce93d8' : '#4fc3f7',
        }}
      />
    </Tooltip>
  );
}

export function PanelTitle({
  title,
  origin,
  extra,
}: {
  title: string;
  origin?: 'ai' | 'deterministic';
  extra?: React.ReactNode;
}) {
  return (
    <Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mb: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 800, flex: 1 }}>
        {title}
      </Typography>
      {origin ? <OriginBadge origin={origin} /> : null}
      {extra}
    </Box>
  );
}

export function KV({ k, v, mono }: { k: string; v: React.ReactNode; mono?: boolean }) {
  return (
    <Box sx={{ display: 'flex', gap: 1, py: 0.25 }}>
      <Typography variant="caption" sx={{ color: '#8a949e', minWidth: 170, flexShrink: 0 }}>
        {k}
      </Typography>
      <Typography
        variant="caption"
        component="div"
        sx={{ fontFamily: mono ? 'monospace' : undefined, wordBreak: 'break-word' }}
      >
        {v}
      </Typography>
    </Box>
  );
}

export const fmtRate = (r: number | null | undefined): string =>
  r === null || r === undefined ? '—' : r === 0 ? '0' : r.toExponential(3);

export const fmtCi = (ci: number[] | null | undefined): string =>
  ci && ci.length === 2 ? `[${fmtRate(ci[0])}, ${fmtRate(ci[1])}]` : '—';