fix(glm-coding-plan): recognize CREDIT_LIMIT windows for the Zhipu descriptor - #256
Merged
Merged
Conversation
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.
Summary
Fixes #255
The Zhipu Coding Plan provider renders as 100% used regardless of actual usage
whenever the account returns
CREDIT_LIMITquota windows (credit-based plans, e.g.Lite on
bigmodel.cn). Auth resolves and the HTTP request succeeds (/quota_statusreports
zhipu: enabled available), but every window is silently dropped duringparsing, so the UI falls back to the fully-used display with no error surfaced.
The parser already handles
CREDIT_LIMIT— but only for the Z.ai descriptor. Thischange removes the envelope gate on the window type so both descriptors treat
CREDIT_LIMITidentically.Root cause (timeline of two changes)
This is a coverage gap between two merged changes, not a faulty provider:
2026-05-08 — feat: add Zhipu Coding Plan provider (domestic China) #78 (
bc5c20e) introduces the Zhipu provider. At that pointglm-coding-plan.tsaccepted onlyTOKENS_LIMITwindows, and the Zhipu testfixtures mocked
TOKENS_LIMITresponses only.2026-08-16 —
928a16e"fix(provider): support Z.ai credit quota windows"teaches the parser to recognize
CREDIT_LIMITunits 3 and 6 as the existingfiveHour/weekly percent windows — because Z.ai credit-plan users were hitting
the same empty-windows failure. The envelope gate added there,
(descriptor.envelope === "zai" && limit.type === "CREDIT_LIMIT"), scoped thefix to Z.ai only; the existing test "maps Z.ai credit limits…" even asserted
the Zhipu descriptor returns
windows: {}for the same payload.Result: Zhipu + credit-plan responses still drop every window on current
main.Live capture against
bigmodel.cnwith a valid Lite key (before this change:opencode-quota showrenders[Zhipu] 100% used):{"code":200,"success":true,"data":{"limits":[ {"type":"CREDIT_LIMIT","unit":3,"number":5,"usage":2000,"currentValue":27,"remaining":1972,"percentage":1,"nextResetTime":1788739057523}, {"type":"CREDIT_LIMIT","unit":6,"number":1,"usage":10000,"currentValue":3193,"remaining":6806,"percentage":31,"nextResetTime":1789095331982}], "level":"lite"}}The request succeeds → auth resolves →
limitsparses → the type filter rejectsboth entries →
windowsis{}→ the display silently degrades to "100% used".Why the type filter cannot be envelope-gated
CREDIT_LIMITis not platform-specific:928a16eexists precisely because Z.ai returnsCREDIT_LIMITwindows with units 3 and 6; its test pins the mapping.The official Z.ai plugin
(zai-org/zai-coding-plugins,
plugins/glm-plan-usage/.../scripts/query-usage.mjs) confirms both platforms areone API surface: identical endpoint paths (
/api/monitor/usage/quota/limit), auth(raw key in
Authorization), envelope (data.limits[]), and unit semantics —differing only by domain (
api.z.aivsopen.bigmodel.cn). Whether theTOKENS_LIMITvsCREDIT_LIMITsplit maps strictly to plan tiers is likely butunverified; the fix only requires the proven fact that both types occur on both
platforms. (The official plugin maps
TOKENS_LIMIT→ "Token usage(5 Hour)" andTIME_LIMIT→ "MCP usage(1 Month)", matching the unit semantics alreadyimplemented in this parser.)
Fix
Smallest safe change — drop the envelope gate on the type (
src/lib/glm-coding-plan.ts):Everything else already matches the official reference and is covered by existing
tests: unit 3 →
fiveHour, unit 6 →weekly,TIME_LIMIT→mcp,percentRemaining = clampPercent(100 - percentage)(the API'spercentageis theused percent — live:
27/2000 → percentage 1),nextResetTimeepoch-ms.This change intentionally does not start surfacing raw credit amounts
(
usage/currentValue/remaining):928a16eexplicitly deferred that untilprovider units are defined, and its tests assert windows stay percent-only. That
invariant is preserved.
Tests updated
tests/lib.glm-coding-plan.test.ts— the existing case"maps Z.ai credit limits to percent windows…" asserted the broken behavior for
Zhipu (
windows: {}). It now:CREDIT_LIMITunits 3/6 payload through both descriptors andasserts populated
fiveHour/weeklypercent windows for each;(
not.toHaveProperty("windows.fiveHour.usage" | "currentValue" | "remaining"));inferring credit amounts".
OpenCode Validation
version where the broken
[Zhipu] 100% usedrendering was observed, and wherethe fixed rendering was re-verified.
Live end-to-end against
bigmodel.cn(valid Lite key),opencode-quota show:Before:
After:
Quality Checklist
pnpm run typecheckpnpm run buildpnpm test