// vDeepSeek: cache shape telemetry badge. Displays cache token count with // a colored hit-rate bar in the trace viewer. Color thresholds are relative // to output tokens (tokens_used) since the trace doesn't carry prompt miss // tokens separately: green > 50%, yellow > 10%, red ≤ 10%. export interface CacheShapeBadgeProps { cacheTokens: number | null | undefined; totalTokens: number | null | undefined; } function hitRate(cache: number, total: number): number { if (cache <= 0 || total <= 0) return 0; return cache / (cache + total); } function barColor(rate: number): string { if (rate > 0.5) return 'bg-green-500'; if (rate > 0.1) return 'bg-yellow-500'; return 'bg-red-500'; } export function CacheShapeBadge({ cacheTokens, totalTokens }: CacheShapeBadgeProps) { if (cacheTokens == null || cacheTokens <= 0) return null; const rate = hitRate(cacheTokens, totalTokens ?? 0); const pct = Math.round(rate * 100); const color = barColor(rate); return ( {cacheTokens}c {totalTokens != null && totalTokens > 0 && ( {pct}% )} ); }