From 5c4be4d03cc3b8a31c4d80e2ac29d60d64db056e Mon Sep 17 00:00:00 2001 From: Raylan LIN Date: Sun, 12 Apr 2026 00:43:16 +0800 Subject: [PATCH] fix: correct quota quiet output calculation for misleading API field naming (#70) The API returns current_interval_usage_count as the REMAINING count, not the used count. The table rendering (quota-table.ts) already handled this correctly, but the quiet output (--quiet flag) was computing it backwards. - src/commands/quota/show.ts: fix quiet output to correctly compute used = total - remaining - src/output/quota-table.ts: add clarifying comment - src/types/api.ts: add JSDoc deprecation notes on misleading fields --- src/commands/quota/show.ts | 7 +++++-- src/output/quota-table.ts | 3 +++ src/types/api.ts | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/commands/quota/show.ts b/src/commands/quota/show.ts index 958ee71..a9bc768 100644 --- a/src/commands/quota/show.ts +++ b/src/commands/quota/show.ts @@ -37,8 +37,11 @@ export default defineCommand({ if (config.quiet) { for (const m of models) { - const remaining = m.current_interval_total_count - m.current_interval_usage_count; - console.log(`${m.model_name}\t${m.current_interval_usage_count}\t${m.current_interval_total_count}\t${remaining}`); + // NOTE: current_interval_usage_count is misleadingly named by the API — + // it represents REMAINING count, not used. See issue #70. + const remaining = m.current_interval_usage_count; + const used = Math.max(0, m.current_interval_total_count - remaining); + console.log(`${m.model_name}\t${used}\t${m.current_interval_total_count}\t${remaining}`); } return; } diff --git a/src/output/quota-table.ts b/src/output/quota-table.ts index 34b0e6f..7f16862 100644 --- a/src/output/quota-table.ts +++ b/src/output/quota-table.ts @@ -114,10 +114,13 @@ export function renderQuotaTable(models: QuotaModelRemain[], config: Config): vo for (const m of models) { console.log(boxLine(W, '├', '─', '┤', useColor)); + // NOTE: current_interval_usage_count is misleadingly named by the API — + // it represents REMAINING count, not used. See issue #70. const remaining = m.current_interval_usage_count; const limit = m.current_interval_total_count; const used = Math.max(0, limit - remaining); const usedPct = limit > 0 ? Math.round((used / limit) * 100) : 0; + // Same misleading naming for weekly. const weekRemaining = m.current_weekly_usage_count; const weekLimit = m.current_weekly_total_count; const weekUsed = Math.max(0, weekLimit - weekRemaining); diff --git a/src/types/api.ts b/src/types/api.ts index b2b0578..72c08bb 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -257,8 +257,10 @@ export interface QuotaModelRemain { end_time: number; remains_time: number; current_interval_total_count: number; + /** @deprecated Misleading API naming: this represents REMAINING count, not usage. */ current_interval_usage_count: number; current_weekly_total_count: number; + /** @deprecated Misleading API naming: this represents REMAINING count, not usage. */ current_weekly_usage_count: number; weekly_start_time: number; weekly_end_time: number;