Repository navigation
Add Z.ai GLM Coding Plan agent usage collector - #7566
FelipeMayerDev wants to merge 5 commits into
Conversation
Adds omarchy-agent-usage-zai so the agents widget gains a Z.ai tab. Rate limits and plan tier come from Z.ai's coding-plan monitor endpoint (.../api/monitor/usage/quota/limit), mapping the rolling 5-hour and weekly TOKENS_LIMIT windows. Keys without a Coding Plan get "no coding plan" and the record falls back to local stats alone, the same way the claude collector degrades without a signed-in CLI. Local stats come from pi/omp sessions that ran through the Z.ai provider (glm-* models), mirroring how the codex collector reads pi/omp sessions. Credentials are discovered from ~/.config/omarchy/agents/zai.json, then ZAI_API_KEY/ZHIPU_API_KEY, then omp/pi .env files; both the global (api.z.ai) and China (open.bigmodel.cn) hosts are supported.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The coding-plan monitor endpoint reports each 5-hour/weekly window as a CREDIT_LIMIT row, not TOKENS_LIMIT. Accept both types so real Coding Plan keys surface their Session and Weekly limits instead of an empty list.
assets/zai.svg (white) for dark surfaces and assets/zai-light.svg (omacom#111) for light surfaces, following the codex mark convention; the panel picks the twin by surface luminance.
|
Thanks for this — the live quota endpoint work is the hard part, and I can confirm the local half works on a real machine: I ran Great foundation. A few things I'd want to land before merge, roughly in priority order — the first two I can demonstrate with real data: Blocking1.
2. Reasoning tokens are dropped pi reports out = number(usage.get("output")) + number(usage.get("reasoning"))3. Dead timestamp fallback silently lands usage on "today"
4. No test Every sibling collector has a Should-fix
Nits
Follow-up idea (not this PR)GLM's Anthropic-compatible endpoint used through Claude Code writes |
|
Follow-up on the limits side, in case it's useful: Z.ai publishes the official credit formula at https://docs.z.ai/devpack/overview#usage-instruction, and it's computable entirely from the local session tokens this collector already scans — so the meters could say From the docs:
I've been running this locally alongside your scanner (sessions on |
- --limits-only/--force reuse a probe cache (15s min interval) and a local-stats scan cache; keep last-known limits while the window is open - fold reasoning tokens into output; date turns by message.timestamp - exact provider match + isinstance guards so one bad line can't drop stats - retryAdvised on transport failure; blame the key only on 401/403 - iso_from_ms accepts seconds; skip unparseable percentage; note unmapped windows - rename tab to Z.ai; README row + manifest providers default; .env export= parsing - add scanner and limits regression tests
|
Thanks @JoseEchave — all addressed in acffe0c:
Success path verified live against a real Coding Plan key (tier + both windows). |
|
On the credit formula: clean follow-up, leaving it out of this PR as you flagged. The |
|
@JoseEchave — went through your review point by point against the current head (acffe0c) and re-ran both suites locally to back the summary above with evidence: Blocking
Should-fix / nits — all in the same commit: Your reasoning-token count (79,402 that day) now lands in the model totals — happy to re-run the scanner against your fixture if anything looks off on your machine. |
|
Updated the PR with the security hardening already reviewed through the standalone plugin marketplace submission (
Focused Z.ai suites are green: 15 assertions across limits/cache and session scanning. The branch remains mergeable. @dhh @ryanrhughes when you have a chance, could you take another look? |
|
Thank you! Brought in with your authorship in #14039, with kept limits marked stale after a failed check. |
What
Adds a
zaiagent usage collector plus a Z.ai brand mark, so the agents widget gains a Z.ai (GLM Coding Plan) tab. Per the plugin README, adding an agent is adding abin/omarchy-agent-usage-<agent>collector that prints the record contract; the panel picks it up automatically.How it works
…/api/monitor/usage/quota/limitand maps the two limit windows —(unit=3, number=5)→ Session (5-hour) and(unit=6, number=1)→ Weekly (7-day) — into the standardlimits[]shape (label,percent0–1 frompercentage/100,resetsAtfromnextResetTime). The endpoint returns each window as aCREDIT_LIMITrow (older responses usedTOKENS_LIMIT); both are accepted. Plan tier comes fromdata.level(e.g. "Lite"). Verified live against a real Coding Plan key.{"success": false, "msg": "…coding plan…"}on HTTP 200; the collector then reportsusageStatusTextand shows local stats only, the same wayclaudedegrades without a signed-in CLI.~/.pi/agent/sessionsand~/.omp/agent/sessionsfor assistant messages on the Z.ai provider (glm-*models), mirroring howcodexreads pi/omp sessions — tokens by model/day, prompts, sessions, active dates.~/.config/omarchy/agents/zai.json→ZAI_API_KEY/ZHIPU_API_KEYenv →~/.omp/agent/.env/~/.pi/agent/.env. Both hosts supported: globalapi.z.aiand Chinaopen.bigmodel.cn(platform: "zai" | "zhipu").assets/zai.svg(white, dark surfaces) +assets/zai-light.svg(Display the active keyboard layout in waybar #111, light surfaces), following thecodexmark convention; the panel selects the twin by surface luminance.Contract
Emits the same record shape as the existing collectors (
schemaVersion,id,name,ready,hasLocalStats,hasPromptStats,tierLabel,usageStatusText,authHelpText,limits[]{label,percent,resetsAt}, plus the standard stats block). Stdlib-only Python, matchingomarchy-agent-usage-codex/fireworks.Testing
tierLabel: "Lite", Session + Weekly limits populated (percent + weeklyresetsAt).limits: []+ status "No GLM Coding Plan on this key", local stats still shown.omarchy-agent-usage-update zai(tempOMARCHY_PATH): passes the dispatcher'sjq -evalidity gate and writeszai.json.glm-*stats picked up from pi/omp sessions (models, per-day chart, prompt/session counts).Notes / follow-ups (intentionally out of scope)
TIME_LIMIT) and the account-global model/tool-usage endpoints are omitted — token stats already come from local sessions, which are richer and machine-scoped.