From 5b73875bd58237d50c37a07c4538bad60c671b67 Mon Sep 17 00:00:00 2001 From: ren Date: Mon, 16 Feb 2026 19:36:12 -0300 Subject: [PATCH] Show usage percentage and remaining time for both providers --- dist/index.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index a25f18e..b6c8348 100644 --- a/dist/index.js +++ b/dist/index.js @@ -81,15 +81,19 @@ async function getGlmUsage() { const limits = response?.data?.limits || []; let tokenPct = 0; let timeRemaining = 0; + let totalMinutes = 0; for (const l of limits) { 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) { - 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]; 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 used = m.current_interval_usage_count; const total = m.current_interval_total_count; 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) { - 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}`; } - let status = `${colors.blue}GLM${colors.reset} ${getColor(glm.tokenPct)}${glm.tokenPct.toFixed(0)}%${colors.reset}`; - if (glm.timeRemaining > 0) { - status += ` ${formatTime(glm.timeRemaining)}`; - } - return status; + const timeStr = glm.timeRemaining > 0 ? formatTime(glm.timeRemaining) : ''; + return `${colors.blue}GLM${colors.reset} ${getColor(glm.tokenPct)}${glm.tokenPct.toFixed(0)}%${colors.reset}${timeStr ? ` ${timeStr}` : ''}`; } // Format MiniMax status @@ -158,11 +160,8 @@ function formatMinimaxStatus(minimax) { 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}`; - if (minimax.remainingMinutes > 0) { - status += ` ${formatTime(minimax.remainingMinutes)}`; - } - return status; + const timeStr = minimax.remainingMinutes > 0 ? formatTime(minimax.remainingMinutes) : ''; + return `${colors.purple}MiniMax${colors.reset} ${getColor(minimax.pct)}${minimax.pct.toFixed(0)}%${colors.reset}${timeStr ? ` ${timeStr}` : ''}`; } // Main function