@magpie-community/opencode-zcode-auth 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/index.mjs +28 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -239,7 +239,8 @@ names it in a line set aside, "ZCode gift plan not started yet", with
|
|
|
239
239
|
the plan's name and its start in this computer's time as the display
|
|
240
240
|
("Start Plan · 2026-10-29 23:00"), soonest first. An account whose only
|
|
241
241
|
gift plan starts later gets a card with that line, not "ended or never
|
|
242
|
-
started"
|
|
242
|
+
started", and signs in with it too, as ZCode counts such a plan as the
|
|
243
|
+
account's (its "pending" Start Plan). The status ZCode gives such a plan has not been seen, so any
|
|
243
244
|
status but `expired` is taken; `starts_at` decides it.
|
|
244
245
|
|
|
245
246
|
**Resets.** A GLM Coding Plan of the account's own, and a team seat,
|
package/index.mjs
CHANGED
|
@@ -29,7 +29,11 @@ const BIGMODEL_API = "https://bigmodel.cn" // BigModel's business API, where ZCo
|
|
|
29
29
|
const ZAI_BASE = "https://api.z.ai/api/anthropic"
|
|
30
30
|
const BIGMODEL_BASE = "https://open.bigmodel.cn/api/anthropic"
|
|
31
31
|
const START_BASE = ZCODE + "/api/v1/zcode-plan/anthropic"
|
|
32
|
-
|
|
32
|
+
// APP_VERSION is the ZCode this signs in and asks as, on every call. ZCode
|
|
33
|
+
// gates by it: its marketing feed answers empty to an older one (#678),
|
|
34
|
+
// and its Start Plan balance "judges capability by the real app_version"
|
|
35
|
+
// (zaiStartPlanBilling.ts in zai-org/ZCode@a9fe401, 3.17.2).
|
|
36
|
+
const APP_VERSION = "3.17.2"
|
|
33
37
|
const UA = "ZCode/" + APP_VERSION
|
|
34
38
|
|
|
35
39
|
// ZCode's models before its config is read; the Start Plan has all but GLM-5.3.
|
|
@@ -167,7 +171,12 @@ const giftSpent = (x) => {
|
|
|
167
171
|
// the gift when any of them has a live bucket serving it — a bucket past
|
|
168
172
|
// its plan's own end, or one whose remaining_units says none, is skipped
|
|
169
173
|
// rather than asked and refused. models are those live buckets' names.
|
|
170
|
-
|
|
174
|
+
//
|
|
175
|
+
// coming (sign-in only) also takes a plan that has not started yet, as
|
|
176
|
+
// ZCode's own check does (resolveStartPlanBalanceAvailability's "pending"
|
|
177
|
+
// counts as entitled): {name, models: [], coming: true}. Requests and the
|
|
178
|
+
// card never ask for it: a plan not started serves nothing yet.
|
|
179
|
+
async function startPlan(jwt, device, coming = false) {
|
|
171
180
|
if (!jwt) throw new Error("not signed in to ZCode")
|
|
172
181
|
if (jwtExpired(jwt)) throw new Error(EXPIRED)
|
|
173
182
|
const b = (await call("GET", `${ZCODE}/api/v1/zcode-plan/billing/balance?app_version=${APP_VERSION}`, { auth: "Bearer " + jwt, device })) ?? {}
|
|
@@ -198,7 +207,11 @@ async function startPlan(jwt, device) {
|
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
209
|
}
|
|
201
|
-
|
|
210
|
+
if (any) return { name: name || "Start Plan", models: [...ms], allModels: [...all.values()], ttl }
|
|
211
|
+
if (!coming) return null
|
|
212
|
+
const next = plans.filter((p) => notStarted(p, now) && !(num(p?.ends_at) > 0 && num(p?.ends_at) <= now))
|
|
213
|
+
.sort((a, b) => startNum(a.starts_at) - startNum(b.starts_at))[0]
|
|
214
|
+
return next ? { name: String(next.name ?? "").trim() || "Start Plan", models: [], allModels: [], ttl, coming: true } : null
|
|
202
215
|
}
|
|
203
216
|
|
|
204
217
|
// plansOf says where an account's requests go and what more it can spend:
|
|
@@ -679,11 +692,10 @@ const CAPTCHA = 3007
|
|
|
679
692
|
const CAPTCHA_WORDS = /captcha/i
|
|
680
693
|
|
|
681
694
|
// The marketing feed and the claim are gated on the client's version:
|
|
682
|
-
// under an older version's header the feed answers empty (11-03:
|
|
683
|
-
// day's banner showed for 3.17.2 and for no older one), so they go
|
|
684
|
-
// the current client (
|
|
685
|
-
const
|
|
686
|
-
const marketingHeaders = () => ({ "X-ZCode-App-Version": MARKETING_VERSION, "X-Platform": platform(), "X-Client-Language": clientLanguage() })
|
|
695
|
+
// under an older version's header the feed answers empty (11-03, #678:
|
|
696
|
+
// the day's banner showed for 3.17.2 and for no older one), so they go,
|
|
697
|
+
// as every call does, as the current client (APP_VERSION) sends them.
|
|
698
|
+
const marketingHeaders = () => ({ "X-ZCode-App-Version": APP_VERSION, "X-Platform": platform(), "X-Client-Language": clientLanguage() })
|
|
687
699
|
|
|
688
700
|
// claimOne asks /billing/claim for one plan and says what its body says:
|
|
689
701
|
// "claimed" (code 0), "done" (code 1003, claimed before), "captcha" (the
|
|
@@ -730,12 +742,15 @@ async function claimOne(s, planID) {
|
|
|
730
742
|
const TOUCH = "/api/v1/marketing/touch"
|
|
731
743
|
const CLAIM_ACTION = "claim_zcode_plan"
|
|
732
744
|
let touchSeq = 0
|
|
745
|
+
// clientLanguage is the language ZCode names to marketing/touch: zh-CN or
|
|
746
|
+
// en-US, its two UI languages, never another (marketingTouchService's
|
|
747
|
+
// localeSchema), so a computer set to zh-Hans-CN or en-GB asks as ZCode does.
|
|
733
748
|
const clientLanguage = () => {
|
|
749
|
+
let l = ""
|
|
734
750
|
try {
|
|
735
|
-
|
|
736
|
-
} catch {
|
|
737
|
-
|
|
738
|
-
}
|
|
751
|
+
l = Intl.DateTimeFormat().resolvedOptions().locale || ""
|
|
752
|
+
} catch {}
|
|
753
|
+
return /^zh\b/i.test(l) ? "zh-CN" : "en-US"
|
|
739
754
|
}
|
|
740
755
|
|
|
741
756
|
// touchPlans is the plans marketing/touch's deliveries offer to claim:
|
|
@@ -1213,7 +1228,7 @@ async function signedIn(site, token, jwt, device, onTeam = false) {
|
|
|
1213
1228
|
let berr = null
|
|
1214
1229
|
if (jwt) {
|
|
1215
1230
|
try {
|
|
1216
|
-
const sp = await startPlan(jwt, device)
|
|
1231
|
+
const sp = await startPlan(jwt, device, true)
|
|
1217
1232
|
if (sp) return { ...(err || !s?.key ? { base: SITES[site].base } : s), jwt, plan: sp.name }
|
|
1218
1233
|
} catch (e) {
|
|
1219
1234
|
berr = e
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-zcode-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"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",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./opencode.mjs",
|