zcode 0.1.18: ZCode app's sign-in reads ZCode 3.15's plan key from config.json, so a valid GLM Coding Plan no longer reads as "no plan" (yetone/magpie#2130)

What changed: ZCode 3.15 keeps no coding plan key in credentials.json any
more. The key it uses is in config.json, at provider["builtin:bigmodel-
coding-plan" / "builtin:zai-coding-plan"].options.apiKey; ZCode 3.15.3's
host reads that value as it is. ownSignIn found no key, so a signed-in
GLM Coding Plan account fell to the Start Plan and read as having no plan.

ownSignIn now falls back to config.json (configKey) when credentials.json
has no key: Z.ai's first, then BigModel. It also takes the provider ids
3.15 normalizes to (account:*-individual-coding-plan) and a value written
encrypted. A value that isn't a key, such as "{env:...}", is skipped. A key
in credentials.json and a team switch still come first. This matches
magpie's built-in (magpie 1d8e83a79, zcodeOwn/zcodeConfigKey).

What was run:
- The new own.test.mjs case uses the reporter's layout (BigModel sign-in,
  no key in credentials.json, key in config.json). It fails without the
  fallback ("j1" in place of "bm.secret").
- Every packages/zcode test file passes under a scratch HOME/TMPDIR:
  dual 25, gift 20, models 1, moved 1, own 6, signin 3, start 10, usage 15.
- bun scripts/check.mjs passes.

Not tried: a real ZCode 3.15 account.
This commit is contained in:
yetone
2026-10-14 15:45:44 +08:00
parent e7d37b0801
commit 5c0aebce8f
3 changed files with 54 additions and 1 deletions
+24
View File
@@ -1026,6 +1026,27 @@ function ownTeam(store, key) {
return null
}
// configKey is the coding plan key ZCode's config.json gives its built-in
// coding plan provider, Z.ai's first, as ZCode lists them; ZCode reads it
// as it is, and one written encrypted is read too.
function configKey(key) {
const providers = readJSON(join(zcodeDir(), "config.json"))?.provider
if (!providers || typeof providers !== "object") return null
for (const [ids, base] of [
[["builtin:zai-coding-plan", "account:zai-individual-coding-plan"], ZAI_BASE],
[["builtin:bigmodel-coding-plan", "account:bigmodel-individual-coding-plan"], BIGMODEL_BASE],
]) {
for (const id of ids) {
let k = providers[id]?.options?.apiKey
if (typeof k !== "string") continue
k = k.trim()
if (k.startsWith("enc:")) k = first(decrypt(key, k))
if (k.includes(".") && !/[\s{$]/.test(k)) return { key: k, base }
}
}
return null
}
// ownSignIn is what ZCode is signed in to now: the account, its coding
// plan key, ZCode's session token (the Start Plan's key) and the team plan
// it is switched to; null when it has none of them.
@@ -1043,6 +1064,9 @@ function ownSignIn() {
// Z.ai's first, as ZCode lists it
if (!s.key || (base === ZAI_BASE && s.base !== ZAI_BASE)) s = { key: k, base }
}
// ZCode 3.15 keeps no plan key in its credentials; the one it uses sits
// in config.json, the provider's options.apiKey (yetone/magpie#2130)
if (!s.key) s = configKey(key) || s
const jwt = first(first(decrypt(key, store.zcodejwttoken)).replace(/^Bearer /, ""))
const team = ownTeam(store, key)
if (team) s = { ...team, jwt }