| 1 | import type { DictKey } from "../locales/en"; |
| 2 | |
| 3 | export interface ContextWindowStatus { |
| 4 | tone: "good" | "notice" | "warn"; |
| 5 | key: DictKey; |
| 6 | } |
| 7 | |
| 8 | export function formatCacheHitRate(hitTokens: number, missTokens: number): string { |
| 9 | const denom = hitTokens + missTokens; |
| 10 | if (denom <= 0) return "-"; |
| 11 | return `${((hitTokens / denom) * 100).toFixed(2)}%`; |
| 12 | } |
| 13 | |
| 14 | export function contextWindowStatus(rawUsagePct: number, compactPct: number): ContextWindowStatus { |
| 15 | if (rawUsagePct > 100) return { tone: "warn", key: "context.windowStatusOverLimit" }; |
| 16 | const usagePct = Math.min(100, Math.max(0, rawUsagePct)); |
| 17 | if (usagePct >= 90) return { tone: "warn", key: "context.windowStatusNearLimit" }; |
| 18 | if (compactPct > 0 && usagePct >= compactPct) return { tone: "warn", key: "context.windowStatusPastCompact" }; |
| 19 | if (compactPct > 0 && usagePct >= Math.max(0, compactPct - 10)) return { tone: "notice", key: "context.windowStatusWatch" }; |
| 20 | return { tone: "good", key: "context.windowStatusHealthy" }; |
| 21 | } |
| 22 |