Skip to content

Commit 5c4be4d

Browse files
committed
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
1 parent aff1e03 commit 5c4be4d

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/commands/quota/show.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ export default defineCommand({
3737

3838
if (config.quiet) {
3939
for (const m of models) {
40-
const remaining = m.current_interval_total_count - m.current_interval_usage_count;
41-
console.log(`${m.model_name}\t${m.current_interval_usage_count}\t${m.current_interval_total_count}\t${remaining}`);
40+
// NOTE: current_interval_usage_count is misleadingly named by the API —
41+
// it represents REMAINING count, not used. See issue #70.
42+
const remaining = m.current_interval_usage_count;
43+
const used = Math.max(0, m.current_interval_total_count - remaining);
44+
console.log(`${m.model_name}\t${used}\t${m.current_interval_total_count}\t${remaining}`);
4245
}
4346
return;
4447
}

src/output/quota-table.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ export function renderQuotaTable(models: QuotaModelRemain[], config: Config): vo
114114
for (const m of models) {
115115
console.log(boxLine(W, '├', '─', '┤', useColor));
116116

117+
// NOTE: current_interval_usage_count is misleadingly named by the API —
118+
// it represents REMAINING count, not used. See issue #70.
117119
const remaining = m.current_interval_usage_count;
118120
const limit = m.current_interval_total_count;
119121
const used = Math.max(0, limit - remaining);
120122
const usedPct = limit > 0 ? Math.round((used / limit) * 100) : 0;
123+
// Same misleading naming for weekly.
121124
const weekRemaining = m.current_weekly_usage_count;
122125
const weekLimit = m.current_weekly_total_count;
123126
const weekUsed = Math.max(0, weekLimit - weekRemaining);

src/types/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ export interface QuotaModelRemain {
257257
end_time: number;
258258
remains_time: number;
259259
current_interval_total_count: number;
260+
/** @deprecated Misleading API naming: this represents REMAINING count, not usage. */
260261
current_interval_usage_count: number;
261262
current_weekly_total_count: number;
263+
/** @deprecated Misleading API naming: this represents REMAINING count, not usage. */
262264
current_weekly_usage_count: number;
263265
weekly_start_time: number;
264266
weekly_end_time: number;

0 commit comments

Comments
 (0)