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:
@@ -37,7 +37,7 @@ subscription and makes its requests. The packages work in OpenCode and in
|
||||
| [trae](packages/trae) | Trae CN (trae.cn) and Trae international (trae.ai), free tier included, with Trae's browser sign-in (experimental) | `trae-cn`, `trae-global` |
|
||||
| [workbuddy](packages/workbuddy) | WorkBuddy (China build, CodeBuddy plan) | `workbuddy` |
|
||||
| [workbuddy](packages/workbuddy) | WorkBuddy (international build) | `workbuddy-ai` |
|
||||
| [zcode](packages/zcode) | ZCode: Z.ai / BigModel (智谱) GLM Coding Plan, team seats, Start Plan | `zcode` |
|
||||
| [zcode](packages/zcode) | ZCode: Z.ai / BigModel (智谱) GLM Coding Plan, team seats, Start Plan, daily claim of its gift plans | `zcode` |
|
||||
| [zed](packages/zed) | Zed (Pro, Pro Trial, Student, Business): Anthropic, OpenAI, Google and xAI models hosted by Zed | `zed` |
|
||||
| [zen-free](packages/zen-free) | OpenCode Zen free models with the public credential | `opencode-zen-free` |
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
// auth.checkin claims the gift plans ZCode's preview lists for an account
|
||||
// (magpie-community/plugins#503). The preview and the "already claimed"
|
||||
// replies are real (#503's capture of 10-29, the 10-06 preview in
|
||||
// usage.test.mjs); the code 0 claim reply has not been seen yet, so its
|
||||
// fixture carries only the code.
|
||||
import { test, expect, afterAll, beforeAll, beforeEach } from "bun:test"
|
||||
import { homedir, tmpdir } from "node:os"
|
||||
import { realpathSync } from "node:fs"
|
||||
|
||||
let ZCodeAuthPlugin, _internal
|
||||
beforeAll(async () => {
|
||||
if (![tmpdir(), realpathSync(tmpdir())].some((t) => homedir().startsWith(t))) throw new Error("run with HOME=$(mktemp -d) bun test")
|
||||
;({ ZCodeAuthPlugin, _internal } = await import("./index.mjs"))
|
||||
})
|
||||
const offline = async () => { throw new Error("no network in tests") }
|
||||
const real = globalThis.fetch
|
||||
afterAll(() => (globalThis.fetch = real))
|
||||
beforeEach(() => {
|
||||
globalThis.fetch = offline
|
||||
_internal.routes.clear()
|
||||
})
|
||||
|
||||
// serve is the fake zcode.z.ai: route answers each request, and a request
|
||||
// it doesn't answer is a 404
|
||||
function serve(route) {
|
||||
const calls = []
|
||||
globalThis.fetch = async (url, init = {}) => {
|
||||
const u = new URL(String(url))
|
||||
const c = { url: u, method: init.method ?? "GET", headers: init.headers ?? {}, body: init.body }
|
||||
calls.push(c)
|
||||
return (await route(c)) ?? new Response("", { status: 404 })
|
||||
}
|
||||
return calls
|
||||
}
|
||||
const json = (v, status = 200) => new Response(typeof v === "string" ? v : JSON.stringify(v), { status })
|
||||
const jwt = (exp) => ["{}", JSON.stringify({ exp })].map((s) => Buffer.from(s).toString("base64url")).join(".") + ".sig"
|
||||
const now = Math.trunc(Date.now() / 1000)
|
||||
const DEVICE = "11111111-2222-4333-8444-555555555555"
|
||||
const TOKEN = jwt(now + 86400)
|
||||
const oauth = (state) => ({ type: "oauth", access: state.key ?? state.jwt ?? "", refresh: JSON.stringify(state), expires: 0 })
|
||||
const SIGNED_IN = oauth({ site: "zai", jwt: TOKEN, device: DEVICE })
|
||||
async function checkin(auth = SIGNED_IN) {
|
||||
const hooks = await ZCodeAuthPlugin({ client: { auth: { set: async () => {} } } })
|
||||
return hooks.auth.checkin(async () => auth, { id: "zcode" })
|
||||
}
|
||||
|
||||
// #503: the preview of an account with nothing to claim
|
||||
const PREVIEW_NONE = '{"code":0,"msg":"","data":{"plans":[],"server_time":1793318263}}'
|
||||
// usage.test.mjs's real preview, the day's ZCode Trust Build unclaimed
|
||||
const PREVIEW_ONE = {
|
||||
code: 0, msg: "",
|
||||
data: {
|
||||
server_time: 1791216750,
|
||||
plans: [{
|
||||
user_plan_id: "upl_2107141892427358208", plan_id: "zcode-v3-start-plan-trust-1006", name: "ZCode Trust Build",
|
||||
description: "ZCode Global Build", priority: 110, status: "active", starts_at: 1791216750, ends_at: 1791302400,
|
||||
entitlements: [{ entitlement_id: "zcode-v3-start-plan-trust-1006", show_name: "GLM-5.3-Flash", meter: "model_usage",
|
||||
unit_type: "token", capabilities: ["model:glm-5.3-flash"], grant_units: 100000000, period: "one_time", priority: 110, effective_at: 0 }],
|
||||
}],
|
||||
},
|
||||
}
|
||||
const PREVIEW_TWO = { ...PREVIEW_ONE, data: { ...PREVIEW_ONE.data, plans: [...PREVIEW_ONE.data.plans, { plan_id: "zcode-v3-start-plan-1029", name: "ZCODE GLOBAL BUILD", status: "active" }] } }
|
||||
// #503's reply to claiming a plan claimed before, as it came
|
||||
const CLAIMED_BEFORE = '{"code":1003,"msg":"target already exists","data":{"server_time":1793318302,"message":"You have already claimed this plan."},"logid":"202610292358223079156af0f90065850e"}'
|
||||
// a code 0 claim: only the code is known
|
||||
const CLAIMED_NOW = '{"code":0,"msg":""}'
|
||||
// the 10-06 answer to a claim without the app's captcha (#30)
|
||||
const CAPTCHA = '{"code":3007,"msg":"captcha verify failed"}'
|
||||
|
||||
const PREVIEW = "/api/v1/zcode-plan/billing/preview"
|
||||
const CLAIM = "/api/v1/zcode-plan/billing/claim"
|
||||
// claimWith serves the preview and answers each claim with claim(plan_id)
|
||||
function claimWith(preview, claim) {
|
||||
return serve(({ url, method, body }) => {
|
||||
if (url.pathname === PREVIEW && method === "GET") return json(preview)
|
||||
if (url.pathname === CLAIM && method === "POST") return claim(JSON.parse(body).plan_id)
|
||||
})
|
||||
}
|
||||
const claims = (calls) => calls.filter((c) => c.url.pathname === CLAIM)
|
||||
|
||||
test("nothing to claim: inactive, and no claim is asked", async () => {
|
||||
const calls = claimWith(PREVIEW_NONE, () => json(CLAIMED_NOW))
|
||||
const r = await checkin()
|
||||
expect(r).toEqual({ outcome: "inactive", message: "no ZCode gift plan to claim" })
|
||||
expect(claims(calls)).toEqual([])
|
||||
// the preview went out as the app's billing calls do
|
||||
const p = calls[0]
|
||||
expect(p.url.pathname).toBe(PREVIEW)
|
||||
expect(p.url.searchParams.get("app_version")).toBe("3.16.3")
|
||||
expect(p.url.searchParams.get("platform")).toBe(`${process.platform}-${process.arch}`)
|
||||
expect(p.headers.Authorization).toBe("Bearer " + TOKEN)
|
||||
expect(p.headers["X-Device-Mid"]).toBe(DEVICE)
|
||||
expect(p.headers["X-ZCode-App-Version"]).toBe("3.16.3")
|
||||
expect(p.headers["X-Platform"]).toBe(`${process.platform}-${process.arch}`)
|
||||
})
|
||||
|
||||
test("one plan to claim, claimed with code 0", async () => {
|
||||
_internal.routes.set("\0" + TOKEN, { stale: true })
|
||||
const calls = claimWith(PREVIEW_ONE, () => json(CLAIMED_NOW))
|
||||
const r = await checkin()
|
||||
expect(r).toEqual({ outcome: "claimed", message: "claimed ZCode Trust Build" })
|
||||
const [c] = claims(calls)
|
||||
expect(claims(calls).length).toBe(1)
|
||||
expect(c.url.origin).toBe("https://zcode.z.ai")
|
||||
expect(JSON.parse(c.body)).toEqual({ plan_id: "zcode-v3-start-plan-trust-1006" })
|
||||
expect(c.headers.Authorization).toBe("Bearer " + TOKEN)
|
||||
expect(c.headers["X-Device-Mid"]).toBe(DEVICE)
|
||||
expect(c.headers["X-ZCode-App-Version"]).toBe("3.16.3")
|
||||
expect(c.headers["X-Platform"]).toBe(`${process.platform}-${process.arch}`)
|
||||
expect(c.headers["Content-Type"]).toBe("application/json")
|
||||
// the route is read again, so the next request uses the plan
|
||||
expect(_internal.routes.has("\0" + TOKEN)).toBe(false)
|
||||
})
|
||||
|
||||
test("a plan claimed before (HTTP 200, code 1003) is done, not a failure", async () => {
|
||||
claimWith(PREVIEW_ONE, () => json(CLAIMED_BEFORE))
|
||||
expect(await checkin()).toEqual({ outcome: "done", message: "already claimed: ZCode Trust Build" })
|
||||
})
|
||||
|
||||
test("a claim ZCode wants the app's captcha for is captcha: claimed in the ZCode app", async () => {
|
||||
claimWith(PREVIEW_ONE, () => json(CAPTCHA, 400))
|
||||
const r = await checkin()
|
||||
expect(r.outcome).toBe("captcha")
|
||||
expect(r.message).toContain("ZCode Trust Build: claim it in the ZCode app (captcha verify failed)")
|
||||
})
|
||||
|
||||
test("a claim that doesn't read is failed (unknown), never claimed", async () => {
|
||||
for (const answer of [
|
||||
() => json("", 500),
|
||||
() => json("<html>bad gateway</html>", 502),
|
||||
() => json("not json at all"), // HTTP 200, garbled
|
||||
() => json("{}"), // no code
|
||||
() => json('{"code":0}', 500), // a code 0 on an HTTP error is no claim
|
||||
() => json('{"code":1001,"msg":"system busy"}'),
|
||||
() => { throw new Error("socket hang up") },
|
||||
]) {
|
||||
claimWith(PREVIEW_ONE, answer)
|
||||
const r = await checkin()
|
||||
expect(r.outcome).toBe("failed")
|
||||
expect(r.message).toStartWith("ZCode Trust Build: ")
|
||||
// a failed claim never touches the account's sign-in
|
||||
expect(r.signIn).toBeUndefined()
|
||||
}
|
||||
})
|
||||
|
||||
test("a preview that doesn't read is failed (unknown), and nothing is claimed", async () => {
|
||||
for (const answer of [
|
||||
() => json("", 500),
|
||||
() => json("garbled"),
|
||||
() => json('{"code":0,"data":{}}'), // no plan list
|
||||
() => json('{"code":401,"msg":"token invalid"}', 401),
|
||||
() => { throw new Error("no network in tests") },
|
||||
]) {
|
||||
const calls = serve(({ url }) => (url.pathname === PREVIEW ? answer() : json(CLAIMED_NOW)))
|
||||
const r = await checkin()
|
||||
expect(r.outcome).toBe("failed")
|
||||
expect(r.signIn).toBeUndefined()
|
||||
expect(claims(calls)).toEqual([])
|
||||
}
|
||||
})
|
||||
|
||||
test("one claimed and one failed is failed, naming the claimed one, so it is asked again", async () => {
|
||||
claimWith(PREVIEW_TWO, (id) => (id === "zcode-v3-start-plan-1029" ? json("", 503) : json(CLAIMED_NOW)))
|
||||
const r = await checkin()
|
||||
expect(r.outcome).toBe("failed")
|
||||
expect(r.message).toBe("claimed ZCode Trust Build; ZCODE GLOBAL BUILD: HTTP 503, unreadable reply (empty)")
|
||||
// asked again: the one claimed answers 1003 now
|
||||
claimWith(PREVIEW_TWO, (id) => (id === "zcode-v3-start-plan-1029" ? json(CLAIMED_NOW) : json(CLAIMED_BEFORE)))
|
||||
expect(await checkin()).toEqual({ outcome: "claimed", message: "claimed ZCODE GLOBAL BUILD" })
|
||||
})
|
||||
|
||||
test("an account with no ZCode session asks nothing", async () => {
|
||||
const calls = serve(() => json(CLAIMED_NOW))
|
||||
const key = await checkin({ type: "api", key: "k", metadata: { site: "zai" } })
|
||||
expect(key.outcome).toBe("ineligible")
|
||||
const expired = await checkin(oauth({ site: "zai", jwt: jwt(now - 60), device: DEVICE }))
|
||||
expect(expired.outcome).toBe("failed")
|
||||
expect(expired.message).toContain("sign-in has expired")
|
||||
expect(expired.signIn).toBeUndefined()
|
||||
expect(calls).toEqual([])
|
||||
})
|
||||
+103
-5
@@ -644,10 +644,10 @@ async function giftOf(s) {
|
||||
const CLAIM_HINT = "Gift plans to claim in the ZCode app"
|
||||
|
||||
// claimHint is the card's line for gift plans ZCode is holding for the
|
||||
// account but has not put on it: GET /billing/preview lists them, and
|
||||
// only the ZCode app claims one — its claim takes the Aliyun captcha
|
||||
// attestation the app's own renderer makes, so the plugin reads the list
|
||||
// and asks the user to claim it there. A window, set aside (it is no
|
||||
// account but has not put on it: GET /billing/preview lists them. The
|
||||
// card only names them: they are claimed in the ZCode app, or by the
|
||||
// daily claim (claimDaily) when the user turned it on; on 10-06 a claim
|
||||
// without the app's Aliyun captcha attestation was refused (3007). A window, set aside (it is no
|
||||
// allowance: using it up stops nothing), so the card shows it and
|
||||
// routing, caps and the menu bar pass it over. The window's name is a
|
||||
// fixed sentence, so magpie can translate it (a display is shown as it
|
||||
@@ -670,6 +670,93 @@ async function claimHint(s) {
|
||||
return { name: CLAIM_HINT, used: 0, aside: true, display: `${n} · ${plan}` }
|
||||
}
|
||||
|
||||
// ---- the daily claim ---------------------------------------------------------------
|
||||
|
||||
// CLAIMED_ALREADY is /billing/claim's body code for a plan the account
|
||||
// has claimed before: HTTP 200 {"code":1003,"msg":"target already
|
||||
// exists"} (magpie-community/plugins#503, a real reply), the desktop
|
||||
// app's manualClaimPlan.claim.failure.alreadyClaimed. CAPTCHA is its
|
||||
// answer to a claim without the Aliyun captcha attestation the ZCode app's
|
||||
// renderer makes: HTTP 400 {"code":3007,"msg":"captcha verify failed"}
|
||||
// (seen 10-06, #30).
|
||||
const CLAIMED_ALREADY = 1003
|
||||
const CAPTCHA = 3007
|
||||
const CAPTCHA_WORDS = /captcha/i
|
||||
|
||||
// zcodeHeaders are what the ZCode app sends on its billing calls beside
|
||||
// the session (#503's capture): its version and platform.
|
||||
const zcodeHeaders = () => ({ "X-ZCode-App-Version": APP_VERSION, "X-Platform": platform() })
|
||||
|
||||
// claimOne asks /billing/claim for one plan and says what its body says:
|
||||
// "claimed" (code 0), "done" (code 1003, claimed before), "captcha" (the
|
||||
// claim wants the app's captcha), else "failed" with why. Only a body
|
||||
// that reads decides: an HTTP error without one, or text that isn't
|
||||
// JSON, is failed (unknown), never claimed. The code 0 body hasn't been
|
||||
// seen yet, so nothing but its code is read.
|
||||
async function claimOne(s, planID) {
|
||||
let res, text
|
||||
try {
|
||||
res = await fetch(`${ZCODE}/api/v1/zcode-plan/billing/claim`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Accept: "application/json", "User-Agent": UA, Authorization: "Bearer " + s.jwt, "X-Device-Mid": s.device || anyDevice, ...zcodeHeaders() },
|
||||
body: JSON.stringify({ plan_id: planID }),
|
||||
})
|
||||
text = await res.text()
|
||||
} catch (e) {
|
||||
return { outcome: "failed", why: e?.message ?? String(e) }
|
||||
}
|
||||
let env
|
||||
try {
|
||||
env = JSON.parse(text)
|
||||
} catch {}
|
||||
const code = env && typeof env === "object" && env.code != null && String(env.code).trim() !== "" ? Number(env.code) : NaN
|
||||
const msg = typeof env?.msg === "string" ? env.msg : ""
|
||||
if (code === CAPTCHA || CAPTCHA_WORDS.test(msg)) return { outcome: "captcha", why: msg || `code ${code}` }
|
||||
if (code === CLAIMED_ALREADY) return { outcome: "done" }
|
||||
if (code === 0 && res.ok) return { outcome: "claimed" }
|
||||
if (!Number.isFinite(code)) return { outcome: "failed", why: `HTTP ${res.status}, unreadable reply ${String(text ?? "").trim().slice(0, 120) || "(empty)"}` }
|
||||
return { outcome: "failed", why: `${msg || "error"} (HTTP ${res.status}, code ${code})` }
|
||||
}
|
||||
|
||||
// claimDaily claims every gift plan ZCode's preview lists for the account
|
||||
// (#503), as auth.checkin's answer: inactive when it lists none, claimed
|
||||
// when one was claimed now, done when each was claimed before, captcha
|
||||
// when ZCode wants the app's captcha for one (it is claimed in the ZCode
|
||||
// app), failed when the list or a claim can't be read. A failed one is
|
||||
// asked again later in the day, when a plan claimed now answers 1003.
|
||||
// Nothing here marks the account: a failed claim keeps its sign-in.
|
||||
async function claimDaily(s) {
|
||||
if (!s?.jwt) return { outcome: "ineligible", message: "ZCode's gift plans are claimed with a ZCode sign-in; this account has none" }
|
||||
if (jwtExpired(s.jwt)) return { outcome: "failed", message: EXPIRED }
|
||||
let d
|
||||
try {
|
||||
d = await call("GET", `${ZCODE}/api/v1/zcode-plan/billing/preview?app_version=${APP_VERSION}&platform=${platform()}`, { auth: "Bearer " + s.jwt, device: s.device, headers: zcodeHeaders() })
|
||||
} catch (e) {
|
||||
return { outcome: "failed", message: `gift plans to claim: ${e?.message ?? String(e)}` }
|
||||
}
|
||||
if (!Array.isArray(d?.plans)) return { outcome: "failed", message: "gift plans to claim: no plan list in the reply" }
|
||||
const plans = d.plans.filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
||||
if (!plans.length) return { outcome: "inactive", message: "no ZCode gift plan to claim" }
|
||||
const got = []
|
||||
for (const p of plans) {
|
||||
const name = first(typeof p.name === "string" ? p.name : "", p.plan_id)
|
||||
got.push({ name, ...(await claimOne(s, p.plan_id.trim())) })
|
||||
}
|
||||
const named = (o) => got.filter((g) => g.outcome === o).map((g) => g.name)
|
||||
const claimed = named("claimed")
|
||||
const said = [
|
||||
claimed.length ? `claimed ${claimed.join(", ")}` : "",
|
||||
...got.filter((g) => g.outcome === "captcha").map((g) => `${g.name}: claim it in the ZCode app (${g.why})`),
|
||||
...got.filter((g) => g.outcome === "failed").map((g) => `${g.name}: ${g.why}`),
|
||||
].filter(Boolean).join("; ")
|
||||
// a plan claimed now is used by the next request, not ten minutes on
|
||||
if (claimed.length) routes.delete(s.key + "\0" + s.jwt)
|
||||
if (got.some((g) => g.outcome === "failed")) return { outcome: "failed", message: said }
|
||||
if (got.some((g) => g.outcome === "captcha")) return { outcome: "captcha", message: said }
|
||||
if (claimed.length) return { outcome: "claimed", message: said }
|
||||
return { outcome: "done", message: `already claimed: ${named("done").join(", ")}` }
|
||||
}
|
||||
|
||||
// GIFT_SIGN_IN is the card's line for an account whose gift plans can't
|
||||
// be read: ZCode's gift plans (the Start Plan, ZCode 1024 Dev Day, ZCode
|
||||
// Trust Build) are served by zcode.z.ai to ZCode's own session alone, so
|
||||
@@ -2321,6 +2408,17 @@ export async function ZCodeAuthPlugin({ client }) {
|
||||
return saved({ error: e?.message ?? String(e) })
|
||||
}
|
||||
},
|
||||
// the daily claim of ZCode's gift plans (#503): magpie runs it once a
|
||||
// day per account while Settings' Daily check-in has ZCode on (off
|
||||
// until the user turns it on), and its Check in now button asks
|
||||
// right away. See claimDaily.
|
||||
async checkin(getAuth) {
|
||||
try {
|
||||
return await claimDaily(stateOf(await getAuth()))
|
||||
} catch (e) {
|
||||
return { outcome: "failed", message: e?.message ?? String(e) }
|
||||
}
|
||||
},
|
||||
methods: [
|
||||
oauth("zai"),
|
||||
oauth("bigmodel"),
|
||||
@@ -2367,4 +2465,4 @@ export async function ZCodeAuthPlugin({ client }) {
|
||||
// config sets what zcodeConfig has read, for tests: null is ZCode's config
|
||||
// out of reach, undefined forgets it
|
||||
const config = (cfg) => (cfgCache = cfg === undefined ? null : { cfg, at: Date.now() })
|
||||
export const _internal = { config, entry, limitWindows, termOf, startUsage, routes, blocked, plansOf, giftOf, dualUsage, claimHint, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY }
|
||||
export const _internal = { config, entry, limitWindows, termOf, startUsage, routes, blocked, plansOf, giftOf, dualUsage, claimHint, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-zcode-auth",
|
||||
"version": "0.1.34",
|
||||
"description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan",
|
||||
"version": "0.1.35",
|
||||
"description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan, and claims its gift plans daily",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
"exports": "./index.mjs",
|
||||
|
||||
@@ -361,7 +361,7 @@ test("a model ZCode's config gives no limits has none made up", () => {
|
||||
// hold is named on the card, to be claimed in the ZCode app (the claim needs
|
||||
// the app's captcha attestation, see claimHint). Both fixtures are real
|
||||
// responses: one account's preview while the day's ZCode Trust Build was
|
||||
// still unclaimed, and one after it had claimed it. The plugin never asks
|
||||
// still unclaimed, and one after it had claimed it. Reading the card never asks
|
||||
// the claim endpoint. The window's name is the fixed sentence magpie
|
||||
// translates; the count and the plan's own name are the display.
|
||||
const PREVIEW_CLAIMABLE = {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
{ "package": "@magpie-community/opencode-zen-free-auth", "name": "OpenCode Zen Free", "icon": "opencode", "providers": ["opencode-zen-free"], "community": true,
|
||||
"summary": { "en": "OpenCode Zen's free models with the public credential, automatic discovery and native streaming protocols.", "zh": "使用 public 凭证接入 OpenCode Zen 免费模型,自动发现模型并支持原生流式协议。" } },
|
||||
{ "package": "@magpie-community/opencode-zcode-auth", "name": "ZCode", "icon": "zcode", "providers": ["zcode"], "community": true, "replaces": "zcode",
|
||||
"summary": { "en": "Z.ai and BigModel GLM Coding Plan, team seats and ZCode's free Start Plan.", "zh": "Z.ai 与智谱 GLM Coding Plan,支持团队席位和 ZCode 免费 Start Plan。" } },
|
||||
"summary": { "en": "Z.ai and BigModel GLM Coding Plan, team seats and ZCode's free Start Plan, with a daily claim of its gift plans.", "zh": "Z.ai 与智谱 GLM Coding Plan,支持团队席位和 ZCode 免费 Start Plan,可每日领取 ZCode 活动包。" } },
|
||||
{ "package": "@magpie-community/opencode-qoder-auth", "name": "Qoder", "icon": "qoder", "providers": ["qoder", "qoder-cn", "qwenwork", "qwenwork-enterprise"], "community": true, "replaces": "qoder",
|
||||
"summary": { "en": "Your Qoder subscription (qoder.com or Qoder CN), and QwenWork (千问办公): the public cloud or the enterprise flagship with its own domain. Unofficial for QwenWork.", "zh": "用 Qoder 自己的设备登录使用 Qoder 订阅(国际版或 Qoder CN);也接入千问办公:公有云与企业旗舰版(输入企业自己的域名)。千问办公部分非官方。" } },
|
||||
{ "package": "@magpie-community/opencode-devin-auth", "name": "Devin", "icon": "devin", "providers": ["devin"], "community": true, "replaces": "devin",
|
||||
|
||||
Reference in New Issue
Block a user