fix(usage): parse Fable weekly limit from limits[] instead of fabricating a row (#3847)
This commit is contained in:
@@ -102,32 +102,28 @@ async function fetchClaudeUsageRaw(accessToken, proxyOptions = null) {
|
|||||||
quotas["weekly (7d)"] = createQuotaObject(data.seven_day);
|
quotas["weekly (7d)"] = createQuotaObject(data.seven_day);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse model-specific weekly windows (e.g. seven_day_sonnet, seven_day_opus, seven_day_fable)
|
// Parse model-specific weekly windows (e.g. seven_day_sonnet, seven_day_opus)
|
||||||
const MODEL_DISPLAY_NAMES = {
|
|
||||||
fable_5_1: "fable",
|
|
||||||
fable_5: "fable",
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(data)) {
|
for (const [key, value] of Object.entries(data)) {
|
||||||
if (key.startsWith("seven_day_") && key !== "seven_day" && hasUtilization(value)) {
|
if (key.startsWith("seven_day_") && key !== "seven_day" && hasUtilization(value)) {
|
||||||
const rawName = key.replace("seven_day_", "");
|
const modelName = key.replace("seven_day_", "");
|
||||||
const modelName = MODEL_DISPLAY_NAMES[rawName] || rawName;
|
|
||||||
quotas[`weekly ${modelName} (7d)`] = createQuotaObject(value);
|
quotas[`weekly ${modelName} (7d)`] = createQuotaObject(value);
|
||||||
} else if ((key === "fable" || key === "fable_5" || key === "fable_5_1") && hasUtilization(value)) {
|
|
||||||
quotas["weekly fable (7d)"] = createQuotaObject(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: surface Fable quota row if weekly window exists but Fable was not returned yet
|
// Model-scoped weekly limits (e.g. Fable) arrive in limits[], not as
|
||||||
if (!quotas["weekly fable (7d)"] && hasUtilization(data.seven_day)) {
|
// seven_day_* keys: { kind: "weekly_scoped", percent, resets_at,
|
||||||
quotas["weekly fable (7d)"] = {
|
// scope: { model: { display_name: "Fable" } } }. No limits entry means
|
||||||
used: 0,
|
// the account has no such window — omit the row, never fabricate one.
|
||||||
total: 100,
|
if (Array.isArray(data.limits)) {
|
||||||
remaining: 100,
|
for (const limit of data.limits) {
|
||||||
remainingPercentage: 100,
|
if (limit?.kind !== "weekly_scoped") continue;
|
||||||
resetAt: parseResetTime(data.seven_day.resets_at),
|
const modelName = String(limit?.scope?.model?.display_name || "").trim().toLowerCase();
|
||||||
unlimited: false,
|
if (!modelName || typeof limit.percent !== "number") continue;
|
||||||
};
|
quotas[`weekly ${modelName} (7d)`] = createQuotaObject({
|
||||||
|
utilization: Math.max(0, Math.min(100, limit.percent)),
|
||||||
|
resets_at: limit.resets_at,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user