zcode 0.1.9: the gift's models are trial entries the user picks, not an automatic gift-first route (#21)

Why: 0.1.8 sent every request for a gift-served model to the gift first, so a user who meant to spend the coding plan had no say, and the card hid the gift's models behind notModels. The gift is an allowance outside the plan; spending it should be a choice.

What: every model a live gift bucket serves is listed again as <model>-Trial, in the catalog's spelling (GLM-5.3-Flash-Trial), and a request for that entry goes to the gift dressed as ZCode's own; a plain model always spends the coding plan. A trial entry whose bucket is spent or blocked answers 429 without touching the coding plan, as do the gift's quota errors (1113, 1005 inside a 200); any other gift answer goes on as it came. The usage card names the gift window by its trial model, drops the plan prefix, and puts MCP - Month last.

Tests: dual.test.mjs rewritten for the new routing (a plain model to the coding plan whatever the gift holds, a trial entry to the gift), usage.test.mjs and gift.test.mjs follow the naming; bun test (65 pass in the package, 516 in the repo) and bun scripts/check.mjs zcode pass.
This commit is contained in:
erlinerd
2026-10-05 14:24:17 +08:00
committed by GitHub
parent a26f884820
commit dbd14ccb98
7 changed files with 590 additions and 113 deletions
+25 -18
View File
@@ -54,30 +54,32 @@ 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`), 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).
(`/api/biz/subscription/list`), its requests go to that plan. A model
the account's gift plans also serve is listed again as
`<model>-Trial`; asking that entry spends the gift (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
**The gift's trial entries.** 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 lists every model a live bucket
serves again as `<model>-Trial`, named in the catalog's spelling
(GLM-5.3-Flash-Trial). Asking a trial entry sends the model to the
gift, dressed as ZCode's own; asking the plain model spends the coding
plan — the choice is the user's. A bucket is judged spent only by its
`remaining_units` — a missing one is unknown, not spent. A trial entry
whose bucket is spent or blocked answers 429 without touching the
coding plan; when the gift answers a trial entry with a 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
"exceed quota limit", which it can answer inside an HTTP 200) that too
becomes a 429 and keeps the entry off for a minute. Any other gift
answer (its 405, its 401, its 5xx) goes on as it came: the user picked
the gift, so the coding plan is not spent behind their back. 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
@@ -105,3 +107,8 @@ minutes. When the config can't be read, the plugin falls back to this list:
| GLM-5-Turbo | 200K | 64K | none, high |
The Start Plan has all of these except GLM-5.3.
A gift plan's models appear again as `<model>-Trial` entries, so a
request can spend the gift's quota on purpose. A trial entry is listed
while any live bucket serves its model, spent buckets included (a spent
entry answers 429 rather than vanishing mid-session).