fix(usage): resolve Z.ai window assignment using limit IDs
Z.ai assigns both token and request limits the same generic "quota" window ID, so findWindowLimits fell through to array-order fallback. This caused the two bars to swap depending on API response order. Add limit-ID-based matching (zai:tokens → current, zai:requests → week) as a secondary tier after window-ID matching.
This commit is contained in:
@@ -60,8 +60,18 @@ function usageColor(fraction: number): { r: number; g: number; b: number } {
|
||||
|
||||
function findWindowLimits(report: UsageReport): UsageWindows {
|
||||
const windowId = (limit: UsageLimit) => (limit.window?.id ?? limit.scope.windowId ?? "").toLowerCase();
|
||||
const current = report.limits.find(limit => ["5h", "primary"].includes(windowId(limit))) ?? report.limits[0];
|
||||
const week = report.limits.find(limit => ["7d", "secondary"].includes(windowId(limit))) ?? report.limits.find(limit => limit !== current);
|
||||
const limitId = (limit: UsageLimit) => (limit.id ?? "").toLowerCase();
|
||||
|
||||
// Match by Window ID
|
||||
const currentByWindow = report.limits.find(limit => ["5h", "primary"].includes(windowId(limit)));
|
||||
const weekByWindow = report.limits.find(limit => ["7d", "secondary"].includes(windowId(limit)));
|
||||
|
||||
// Match by Limit ID (Z.ai Uses Generic "quota" Window IDs for Both Limits)
|
||||
const currentByLimit = report.limits.find(limit => ["zai:tokens"].includes(limitId(limit)));
|
||||
const weekByLimit = report.limits.find(limit => ["zai:requests"].includes(limitId(limit)));
|
||||
|
||||
const current = currentByWindow ?? currentByLimit ?? report.limits[0];
|
||||
const week = weekByWindow ?? weekByLimit ?? report.limits.find(limit => limit !== current);
|
||||
return { current, week };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user