Show usage percentage and remaining time for both providers
This commit is contained in:
31
dist/index.js
vendored
31
dist/index.js
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user