zcode 0.1.8: spend an account's gift plans before its GLM Coding Plan, and show both on the usage card (#19)
Why: a GLM Coding Plan account can also hold gift plans from ZCode activities (a "Trust Build" grant, say). They lapse on a fixed date, and every request went to the coding plan, so their allowance went unspent. What: plansOf now reads the gift's balance (per the ZCode session, kept 10 minutes) and takes the union of the models every live bucket of every active gift plan still serves (not expired, remaining_units > 0). A request for a model the gift serves goes to the Start Plan first, dressed as ZCode's own client; when the gift can't serve it — any answer 400 or over, or its quota error inside an HTTP 200 (code 1113/1005) — the request is replayed once to the coding plan as the agent sent it. Only a quota answer keeps that model off the gift for a minute; a 405 refusal is asked again next request. The usage card shows the coding plan's windows and the gift's buckets together, each bucket prefixed with its plan's name; a gift read that fails leaves just the coding card. A pure gift account (no coding plan) behaves as before. Tests: dual.test.mjs, 14 tests — routing, replay, the 60s quota block, the 200-with-quota-error case, stream passthrough, an expired ZCode session, the cache TTLs, a multi-plan union and a gift-only account; HOME=$(mktemp -d) bun test (37 pass) and bun scripts/check.mjs zcode pass.
This commit is contained in:
@@ -54,12 +54,42 @@ Before each request, the plugin checks which plan the account is on, and
|
||||
asks again every 10 minutes:
|
||||
|
||||
- If the key's account has a GLM Coding Plan
|
||||
(`/api/biz/subscription/list`), requests go to that plan.
|
||||
- Otherwise they go to the Start Plan.
|
||||
(`/api/biz/subscription/list`), its requests go to that plan —
|
||||
except for a model the account's gift plans also serve, which goes to
|
||||
the gift first (see below).
|
||||
- Otherwise they go to the gift plans.
|
||||
|
||||
Every request carries the key as both `x-api-key` and
|
||||
`Authorization: Bearer`.
|
||||
|
||||
**Spending the gift first.** An account with a GLM Coding Plan can also
|
||||
hold gift plans from ZCode activities, ones that expire on a fixed date.
|
||||
Their allowance would lapse unused if every request went to the coding
|
||||
plan, so the plugin reads the gift's balance (per the sign-in's session,
|
||||
kept for 10 minutes) and sends a request for a model the gift still has
|
||||
quota to spend to the gift first, dressed as ZCode's own. A bucket is
|
||||
judged spent only by its `remaining_units` — a missing one is unknown,
|
||||
not spent — and a model whose every bucket says none goes straight to
|
||||
the coding plan without asking. When the gift can't serve the request —
|
||||
any answer 400 or over (its 405, its 401, its 5xx), or its quota error
|
||||
(code 1113 "Insufficient balance or no resource package", code 1005
|
||||
"exceed quota limit", which it can answer inside an HTTP 200) — the
|
||||
plugin replays the request once to the coding plan, as the agent sent
|
||||
it. Only a quota answer keeps that model off the gift for a minute; a
|
||||
refusal that says nothing about quota is asked again next request. Every
|
||||
429 counts as spent, Z.ai's 1302/1303 rate limits among them. A stream's
|
||||
body is never read or buffered on the way.
|
||||
|
||||
## The usage card
|
||||
|
||||
An account with both plans shows both allowances: the coding plan's
|
||||
windows first, then the gift's buckets, each with its own name, models
|
||||
and end. The card's plan and term stay the coding plan's. A gift read
|
||||
that fails leaves just the coding card — magpie hides a card's windows
|
||||
behind an error, so a gift hiccup must not black out a working Coding
|
||||
Plan. A gift that goes out of date while requests use it simply stops
|
||||
showing.
|
||||
|
||||
## Models
|
||||
|
||||
The models are the ones ZCode offers for the account's plan. They come
|
||||
|
||||
Reference in New Issue
Block a user