Show usage percentage and remaining time for both providers

This commit is contained in:
ren
2026-02-16 19:36:12 -03:00
parent f6ff6c0a7f
commit 5b73875bd5

31
dist/index.js vendored
View File

@@ -81,15 +81,19 @@ async function getGlmUsage() {
const limits = response?.data?.limits || []; const limits = response?.data?.limits || [];
let tokenPct = 0; let tokenPct = 0;
let timeRemaining = 0; let timeRemaining = 0;
let totalMinutes = 0;
for (const l of limits) { for (const l of limits) {
if (l.quota_type === 'TOKENS_LIMIT') tokenPct = l.percentage || 0; if (l.quota_type === 'TOKENS_LIMIT') tokenPct = l.percentage || 0;
if (l.quota_type === 'TIME_LIMIT') timeRemaining = (l.remaining || 0) / 1000 / 60; if (l.quota_type === 'TIME_LIMIT') {
timeRemaining = (l.remaining || 0) / 1000 / 60;
totalMinutes = (l.total || 0) / 1000 / 60;
}
} }
return { tokenPct, timeRemaining, error: null }; return { tokenPct, timeRemaining, totalMinutes, error: null };
} catch (e) { } catch (e) {
return { tokenPct: 0, timeRemaining: 0, error: e.message }; return { tokenPct: 0, timeRemaining: 0, totalMinutes: 0, error: e.message };
} }
} }
@@ -112,17 +116,18 @@ async function getMinimaxUsage() {
const m = response?.model_remains?.[0]; const m = response?.model_remains?.[0];
if (!m) { if (!m) {
return { pct: 0, remainingMinutes: 0, model: '?', error: 'No data' }; return { pct: 0, remainingMinutes: 0, totalMinutes: 0, model: '?', error: 'No data' };
} }
const remainingMinutes = m.remains_time / 1000 / 60; const remainingMinutes = m.remains_time / 1000 / 60;
const used = m.current_interval_usage_count; const used = m.current_interval_usage_count;
const total = m.current_interval_total_count; const total = m.current_interval_total_count;
const pct = (used / total) * 100; const pct = (used / total) * 100;
const totalMinutes = remainingMinutes / (1 - used/total) || 0;
return { pct, remainingMinutes, model: m.model_name, error: null }; return { pct, remainingMinutes, totalMinutes, model: m.model_name, error: null };
} catch (e) { } catch (e) {
return { pct: 0, remainingMinutes: 0, model: '?', error: e.message }; return { pct: 0, remainingMinutes: 0, totalMinutes: 0, model: '?', error: e.message };
} }
} }
@@ -145,11 +150,8 @@ function formatGlmStatus(glm) {
return `${colors.blue}GLM${colors.reset} ${colors.red}offline${colors.reset}`; return `${colors.blue}GLM${colors.reset} ${colors.red}offline${colors.reset}`;
} }
let status = `${colors.blue}GLM${colors.reset} ${getColor(glm.tokenPct)}${glm.tokenPct.toFixed(0)}%${colors.reset}`; const timeStr = glm.timeRemaining > 0 ? formatTime(glm.timeRemaining) : '';
if (glm.timeRemaining > 0) { return `${colors.blue}GLM${colors.reset} ${getColor(glm.tokenPct)}${glm.tokenPct.toFixed(0)}%${colors.reset}${timeStr ? ` ${timeStr}` : ''}`;
status += ` ${formatTime(glm.timeRemaining)}`;
}
return status;
} }
// Format MiniMax status // Format MiniMax status
@@ -158,11 +160,8 @@ function formatMinimaxStatus(minimax) {
return `${colors.purple}MiniMax${colors.reset} ${colors.red}offline${colors.reset}`; return `${colors.purple}MiniMax${colors.reset} ${colors.red}offline${colors.reset}`;
} }
let status = `${colors.purple}MiniMax${colors.reset} ${getColor(minimax.pct)}${minimax.pct.toFixed(0)}%${colors.reset}`; const timeStr = minimax.remainingMinutes > 0 ? formatTime(minimax.remainingMinutes) : '';
if (minimax.remainingMinutes > 0) { return `${colors.purple}MiniMax${colors.reset} ${getColor(minimax.pct)}${minimax.pct.toFixed(0)}%${colors.reset}${timeStr ? ` ${timeStr}` : ''}`;
status += ` ${formatTime(minimax.remainingMinutes)}`;
}
return status;
} }
// Main function // Main function