/** * 请求延迟健康度分档(用于用量明细"延迟"列的纵向健康扫视)。 * * 首 Token(TTFT):10s 内正常,10-30s 偏慢,30-60s 缓慢,60s 及以上严重。 * 总耗时:流式请求整体时长天然更长,阈值放宽为 1min / 3min / 5min。 */ export type LatencySeverity = 'good' | 'warn' | 'slow' | 'critical' export const FIRST_TOKEN_THRESHOLDS_MS = { warn: 10_000, slow: 30_000, critical: 60_000, } as const export const DURATION_THRESHOLDS_MS = { warn: 60_000, slow: 180_000, critical: 300_000, } as const interface Thresholds { warn: number slow: number critical: number } const classify = (ms: number, thresholds: Thresholds): LatencySeverity => { if (ms >= thresholds.critical) return 'critical' if (ms >= thresholds.slow) return 'slow' if (ms >= thresholds.warn) return 'warn' return 'good' } export const firstTokenSeverity = (ms: number): LatencySeverity => classify(ms, FIRST_TOKEN_THRESHOLDS_MS) export const durationSeverity = (ms: number): LatencySeverity => classify(ms, DURATION_THRESHOLDS_MS) export const LATENCY_TEXT_CLASSES: Record = { good: 'text-emerald-600 dark:text-emerald-400', warn: 'text-amber-600 dark:text-amber-400', slow: 'text-orange-600 dark:text-orange-400', critical: 'text-red-600 dark:text-red-400', } /** 无首字数据时的纯色色条(仅按总耗时档着色)。 */ export const LATENCY_BAR_CLASSES: Record = { good: 'bg-emerald-500', warn: 'bg-amber-400', slow: 'bg-orange-500', critical: 'bg-red-500', } /** 渐变色条上端(首字档);与 LATENCY_BAR_TO_CLASSES 组合成上下渐变,避免两段硬切割裂感。 */ export const LATENCY_BAR_FROM_CLASSES: Record = { good: 'from-emerald-500', warn: 'from-amber-400', slow: 'from-orange-500', critical: 'from-red-500', } /** 渐变色条下端(总耗时档)。 */ export const LATENCY_BAR_TO_CLASSES: Record = { good: 'to-emerald-500', warn: 'to-amber-400', slow: 'to-orange-500', critical: 'to-red-500', }