Repository navigation
feat: add Z.ai usage quota monitor - #11
Conversation
Add zai.py provider that monitors Z.ai (GLM models) usage via the api.z.ai quota/limit endpoint. Uses token-based auth from ~/.config/waybar-ai-usage/zai.conf (same pattern as Copilot). Displays 5-hour token usage in the Waybar text with reset timer, and monthly tool quota (web search, reader, ZRead) breakdown in the tooltip. Color-coded by usage level: green (low), yellow (mid), red (high).
Add window_not_started check (matching claude/codex pattern) so Z.ai shows 'Ready' instead of '0% ??' when the API returns percentage 0 with no nextResetTime or remaining fields.
There was a problem hiding this comment.
Thanks for the PR! Overall the integration looks solid — pattern matches Copilot, setup CLI / CSS / cleanup are all wired up. A few small things I'd like to see fixed before merge:
1. is_unused and window_not_started collapse to the same condition (zai.py:179-180)
is_unused = pct == 0 and tl and tl.get("remaining") is not None
window_not_started = pct == 0 and tl and tl.get("nextResetTime") is NoneTheir union is just pct == 0 and tl, so status = "Ready" whenever pct == 0. The two-variable split implies a distinction that doesn't exist. Either collapse into a single check, or actually distinguish the two cases (e.g. only "Ready" when the API explicitly reports an unused window vs. one that hasn't started yet).
2. Redundant branch in _format_ms_reset (zai.py:111-119)
return format_eta(None) if secs <= 0 else format_eta(reset_dt.isoformat())format_eta already handles the secs <= 0 case internally (returns "0m00s"), so the branch is unnecessary — and worse, format_eta(None) returns "0′00″", a different format. Simplify to:
return format_eta(reset_dt.isoformat())(The try/except and secs calculation can also go away if you just pass through to format_eta.)
3. _format_tokens is unused (zai.py:96-101)
Dead code — please either drop it, or wire it into the tooltip (showing token counts alongside percentages would actually be nice).
4. Stray blank line / extra indentation inside the cleanup tuple (waybar_ai_usage.py:478-482)
"#custom-zen-balance",
"#custom-zai-usage",
)The blank line and 4-space indent inside the tuple literal look like a merge artifact. Should just be:
"#custom-zen-balance",
"#custom-zai-usage",
)Thanks again — happy to merge once these are addressed.
|
Thanks for the review! I pushed the requested fixes: collapsed the redundant Ready-state checks, simplified the reset formatting through format_eta, wired _format_tokens into the tooltip, and cleaned up the stray tuple formatting in waybar_ai_usage.py. Appreciate the detailed feedback! |
|
Thanks for the quick turnaround — all four points addressed cleanly, and the diff actually got smaller in the process. Merged. Thanks for the solid contribution! |
Summary
zai.pyprovider that monitors Z.ai usage via theapi.z.ai/api/monitor/usage/quota/limitendpoint~/.config/waybar-ai-usage/zai.conf(same pattern as Copilot module)zai-low), yellow (zai-mid), red (zai-high)Changes
zai.pypyproject.tomlzai-usagescript entry pointwaybar_ai_usage.pywaybar-config-example.jsoncwaybar-style-example.cssREADME.mdSetup
Auth Notes
Z.ai uses an HS512 JWT for API calls that is generated in JavaScript memory (not persisted to cookies or localStorage). Unlike Claude/Codex, browser auto-detection is not feasible, so config-file auth (like Copilot) is the only reliable approach.