2026-02-01 13:30:30 -03:00
|
|
|
export const clampPercent = (value: number | null): number | null => {
|
|
|
|
|
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return Math.max(0, Math.min(100, Math.round(value)));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const formatPercent = (value: number | null): string => {
|
|
|
|
|
const clamped = clampPercent(value);
|
|
|
|
|
if (clamped === null) {
|
|
|
|
|
return '-';
|
|
|
|
|
}
|
|
|
|
|
return `${clamped}%`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const resolveUsageTone = (percent: number | null): 'safe' | 'warn' | 'critical' => {
|
|
|
|
|
if (percent === null) {
|
|
|
|
|
return 'safe';
|
|
|
|
|
}
|
|
|
|
|
if (percent >= 80) {
|
|
|
|
|
return 'critical';
|
|
|
|
|
}
|
|
|
|
|
if (percent >= 50) {
|
|
|
|
|
return 'warn';
|
|
|
|
|
}
|
|
|
|
|
return 'safe';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const formatWindowLabel = (label: string): string => {
|
|
|
|
|
if (label === '5h') return '5-Hour Limit';
|
2026-02-04 01:13:23 -08:00
|
|
|
if (label === '7d') return '7-Day Limit';
|
|
|
|
|
if (label === '7d-sonnet') return '7-Day Sonnet Limit';
|
|
|
|
|
if (label === '7d-opus') return '7-Day Opus Limit';
|
2026-02-01 13:30:30 -03:00
|
|
|
if (label === 'weekly') return 'Weekly Limit';
|
2026-02-04 01:13:23 -08:00
|
|
|
if (label === 'monthly') return 'Monthly Limit';
|
|
|
|
|
if (label === 'credits') return 'Credits';
|
|
|
|
|
if (label === 'premium') return 'Premium Interactions';
|
|
|
|
|
if (label === 'chat') return 'Chat Requests';
|
|
|
|
|
if (label === 'completions') return 'Completions';
|
2026-02-03 08:03:27 -03:00
|
|
|
if (label === 'premium_interactions') return 'Premium interactions';
|
2026-02-01 13:30:30 -03:00
|
|
|
return label;
|
|
|
|
|
};
|