fix(zai): accept CREDIT_LIMIT quota entries - #1
Open
taimurrabuske wants to merge 1 commit into
Open
Conversation
Current Z.ai GLM Coding plans return quota entries typed CREDIT_LIMIT rather than TOKENS_LIMIT. The session and weekly lookups matched TOKENS_LIMIT only, so probe() fell through to the 'No usage data' badge despite the API returning real usage. Match either type, keeping both plan generations working. The (unit, number) window encoding and the percentage mapping are unchanged. Same resolution as robinebers#1104.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What happens
The Z.ai provider renders the grey "No usage data" badge even though the API
key is valid and the account has an active, in-use GLM Coding plan. The request
itself succeeds — the plan name is picked up correctly from the subscription
endpoint, so only the quota payload goes unrecognised.
Root cause
Current Z.ai coding plans return quota entries typed
CREDIT_LIMITrather thanTOKENS_LIMIT:plugins/zai/plugin.jsmatches onlyTOKENS_LIMIT:plugin.js:120—findLimit(limits, "TOKENS_LIMIT", 3)(session)plugin.js:142—findLimit(limits, "TOKENS_LIMIT", 6)(weekly)With only
CREDIT_LIMITentries present,tokenLimitisnull, the earlyreturn at
plugin.js:122fires, and the badge is rendered despite real usagebeing reported.
The
(unit, number)window encoding is unchanged —unit: 3is the 5-hoursession window and
unit: 6the weekly one — andpercentageis still supplieddirectly, so no other mapping needs to change.
Fix
Match either type, so both plan generations keep working:
This is the same resolution accepted upstream in OpenUsage
(robinebers#1104, closed), which recommends treating
CREDIT_LIMITexactly like
TOKENS_LIMITfor the session and weekly meters and keeping thewindow classification and
percentagemapping as-is.TIME_LIMIThandling is untouched. Accounts without a web-search allowancereturn no
TIME_LIMITentry, and omitting that line for them is already correct.Tests
Adds a
CREDIT_LIMITfixture toplugins/zai/plugin.test.jscovering thesession and weekly meters, alongside the existing
TOKENS_LIMITcases.npx vitest run plugins/zai/plugin.test.js— 25 passed. With theplugin.jschange reverted the new test fails as expected
(
AssertionError: expected 'badge' to be 'progress'), so it genuinely coversthe regression rather than passing either way.
Verified
Applied against Tuxmeter 0.0.2 on Ubuntu (GNOME 50, Wayland) with a live
GLM Coding account. Before the change the provider cached a single
badgeline reading "No usage data"; after it, the session and weeklyprogresslines populate with the correct percentages and reset times.