zcode 0.1.35: claims each account's ZCode gift plans daily through magpie's check-in (#503)
ZCode hands out gift/resource plans that sit on an account until claimed,
and an account used only through magpie let them lapse. The plugin now has
auth.checkin, so magpie's daily check-in (`magpie accounts checkin`, and
Settings -> Daily check-in, where ZCode is off until the user turns it on)
claims them, the shape the MiniMax, Qoder and Loomy plugins use.
claimDaily reads GET /api/v1/zcode-plan/billing/preview (the list the card
already read) and POSTs {"plan_id"} to /billing/claim for each plan it
lists, with the account's ZCode jwt, X-Device-Mid, X-ZCode-App-Version and
X-Platform, as kongbai01203 captured them. The claim is judged by the body's
code: 0 claimed, 1003 "target already exists" (HTTP 200) done, 3007 or a
captcha message "captcha" (claim it in the ZCode app), anything else, an
HTTP error without a code or a body that isn't JSON failed. A failed read is
never taken as claimed, and no answer carries signIn, so a failed claim
leaves the account as it was. Nothing listed is inactive; a key-only
account is ineligible; an expired ZCode session is failed with no request.
A plan claimed now drops the account's cached route, so the next request
uses it. One failed among several makes the whole answer failed (with the
claimed ones named), so magpie asks again later and the claimed ones then
answer 1003.
Run (on mote, HOME=$(mktemp -d)): `bun test` in packages/zcode, 150 pass;
the whole repo's `bun test`, 3698 pass 0 fail of 3706 across 297 files;
`bun scripts/check.mjs zcode` ok. checkin.test.mjs covers preview empty,
one plan claimed with code 0 (request body and headers checked), 1003,
3007, seven unreadable claim answers, five unreadable previews, one
claimed + one failed then asked again, and key/expired accounts asking
nothing. Broken by hand: 1003 -> claimed and an unreadable reply ->
claimed turned three of these tests red; put back, green.
Not tried: a real claim that answers code 0. No account has a plan to
claim right now (every preview answers plans: []), so the code 0 body is
a fixture carrying only its code, and nothing else of it is read. On
10-06 a claim without the ZCode app's Aliyun captcha was answered 400
code 3007 (#30); if ZCode still asks that for a fresh plan, the check-in
says "captcha" and the plan is claimed in the app, as before. The real
1003 reply is in the tests as captured.
This commit is contained in:
@@ -197,12 +197,36 @@ the card and names them there — the window is named "Gift plans to
|
||||
claim in the ZCode app" and the display shows "1 · ZCode Trust Build"
|
||||
— set aside, so the line stops nothing and routing, usage caps and the
|
||||
menu bar pass it over. The name is a fixed sentence magpie can
|
||||
translate; the count and the plan's own name are the display. The plugin never claims one: the claim needs the
|
||||
Aliyun captcha attestation only the app's renderer can make. A preview
|
||||
that fails, or lists nothing, adds no line at all, and a card that is an
|
||||
error keeps its error. Claim the plan in the ZCode app (open it once);
|
||||
translate; the count and the plan's own name are the display. Reading
|
||||
the card never claims one. A preview that fails, or lists nothing, adds
|
||||
no line at all, and a card that is an error keeps its error. Claim the
|
||||
plan in the ZCode app (open it once), or let the daily claim below do it;
|
||||
the next read shows it as an ordinary gift bucket.
|
||||
|
||||
## The daily claim
|
||||
|
||||
With ZCode turned on in magpie's Settings → Daily check-in (it is off
|
||||
until you turn it on), magpie has the plugin claim each account's gift
|
||||
plans once a day (`auth.checkin`; `magpie accounts checkin` asks now). It
|
||||
reads the app's preview list and posts each plan it lists to
|
||||
`POST /api/v1/zcode-plan/billing/claim` (`{"plan_id": …}`) with the
|
||||
account's ZCode session, as the app does. The answer is judged by the
|
||||
body's code, not the HTTP status:
|
||||
|
||||
- nothing listed: *inactive*;
|
||||
- code 0: *claimed* (the next request uses the plan);
|
||||
- code 1003 "target already exists" (HTTP 200): *done*, claimed before;
|
||||
- code 3007 "captcha verify failed": *captcha*, the plan is claimed in
|
||||
the ZCode app (on 10-06 ZCode wanted the app's Aliyun captcha for a
|
||||
claim; whether it still does for a fresh plan is not known yet);
|
||||
- anything else, an HTTP error without a code, or a reply that isn't
|
||||
JSON: *failed*, which magpie asks again later that day. It is never
|
||||
taken as claimed, and a failed claim leaves the account's sign-in
|
||||
alone.
|
||||
|
||||
An account added with a GLM Coding Plan key has no ZCode session to claim
|
||||
with (*ineligible*).
|
||||
|
||||
**No ZCode session.** A card read with a key, or with a sign-in whose
|
||||
ZCode session has run out (it can't be renewed), sets aside a line named
|
||||
"ZCode gift plans (-Trial models) need ZCode's sign-in", with why in its
|
||||
|
||||
Reference in New Issue
Block a user