fix(claude): correct utilization inversion and propagate remainingPercentage

- Fix createQuotaObject: utilization is percentage USED, not remaining
- Add optional chaining to window access in createQuotaObject
- Use typeof object guards for five_hour/seven_day instead of !== undefined
- Use nullish coalescing for extra_usage
- Propagate remainingPercentage in parseQuotaData claude case
This commit is contained in:
DavyMassoneto
2026-03-04 22:17:00 -03:00
parent d19f336286
commit 2ec0cd13cd
2 changed files with 10 additions and 7 deletions

View File

@@ -443,23 +443,25 @@ async function getClaudeUsage(accessToken) {
const data = await oauthResponse.json();
const quotas: Record<string, any> = {};
// utilization = percentage remaining, not used
// utilization = percentage USED (e.g., 22 means 22% used, 78% remaining)
const createQuotaObject = (window: any) => {
const remaining = window.utilization ?? 0;
const used = window?.utilization ?? 0;
const remaining = 100 - used;
return {
used: 100 - remaining,
used,
total: 100,
resetAt: parseResetTime(window.resets_at) || null,
remaining,
resetAt: parseResetTime(window?.resets_at),
remainingPercentage: remaining,
unlimited: false,
};
};
if (data.five_hour !== undefined) {
if (data.five_hour && typeof data.five_hour === "object") {
quotas["session (5h)"] = createQuotaObject(data.five_hour);
}
if (data.seven_day !== undefined) {
if (data.seven_day && typeof data.seven_day === "object") {
quotas["weekly (7d)"] = createQuotaObject(data.seven_day);
}
@@ -479,7 +481,7 @@ async function getClaudeUsage(accessToken) {
return {
plan: "Claude Code",
quotas,
extraUsage: data.extra_usage || null,
extraUsage: data.extra_usage ?? null,
};
}

View File

@@ -159,6 +159,7 @@ export function parseQuotaData(provider, data) {
used: quota.used || 0,
total: quota.total || 0,
resetAt: quota.resetAt || null,
remainingPercentage: quota.remainingPercentage,
});
});
}