@magpie-community/opencode-zcode-auth 0.1.66 → 0.1.67

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.
Files changed (2) hide show
  1. package/index.mjs +21 -3
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1099,7 +1099,11 @@ async function claimDaily(s) {
1099
1099
  // translate it; why goes in the display. Set aside: it stops nothing.
1100
1100
  const GIFT_SIGN_IN = "ZCode gift plans (-Trial models) need ZCode's sign-in"
1101
1101
  function giftSignIn(s, key) {
1102
- if (!s.jwt) return { name: GIFT_SIGN_IN, used: 0, aside: true, display: key ? "not read with an API key: add the account with a ZCode sign-in" : "this sign-in has no ZCode session: sign in again" }
1102
+ if (!s.jwt) {
1103
+ if (key) return { name: GIFT_SIGN_IN, used: 0, aside: true, display: "not read with an API key: add the account with a ZCode sign-in" }
1104
+ if (s.source === "zcode" && ownStoreUnreadable()) return { name: GIFT_SIGN_IN, used: 0, aside: true, display: UNREADABLE_SIGN_IN }
1105
+ return { name: GIFT_SIGN_IN, used: 0, aside: true, display: "this sign-in has no ZCode session: sign in again" }
1106
+ }
1103
1107
  if (jwtExpired(s.jwt)) return { name: GIFT_SIGN_IN, used: 0, aside: true, display: "ZCode's sign-in has expired: sign in again" }
1104
1108
  return null
1105
1109
  }
@@ -1610,6 +1614,20 @@ function decrypt(key, v) {
1610
1614
  }
1611
1615
  }
1612
1616
 
1617
+ // UNREADABLE_SIGN_IN says why a sign-in "as ZCode" has no session to
1618
+ // read: ZCode 3.18 writes credentials.json's values as "enc:v2:os:…",
1619
+ // which looks bound to the system's own key store, and this plugin reads
1620
+ // enc:v1 alone (#1196).
1621
+ const UNREADABLE_SIGN_IN = "ZCode 3.18 keeps its sign-in in a new form this plugin can't read yet: add the account with a Z.ai or BigModel sign-in"
1622
+
1623
+ // ownStoreUnreadable says whether ZCode's credentials.json holds values
1624
+ // in a form decrypt can't read.
1625
+ function ownStoreUnreadable() {
1626
+ const store = readJSON(join(zcodeDir(), "credentials.json"))
1627
+ if (!store || typeof store !== "object") return false
1628
+ return Object.values(store).some((v) => typeof v === "string" && v.startsWith("enc:") && !v.startsWith("enc:v1:"))
1629
+ }
1630
+
1613
1631
  function readJSON(path) {
1614
1632
  try {
1615
1633
  return JSON.parse(readFileSync(path, "utf8"))
@@ -1876,7 +1894,7 @@ function asZCode() {
1876
1894
  method: "auto",
1877
1895
  async callback() {
1878
1896
  const own = ownSignIn()
1879
- if (!own) return { type: "failed", error: "ZCode isn't signed in on this computer; sign in to ZCode, or sign in to Z.ai or BigModel here" }
1897
+ if (!own) return { type: "failed", error: ownStoreUnreadable() ? UNREADABLE_SIGN_IN : "ZCode isn't signed in on this computer; sign in to ZCode, or sign in to Z.ai or BigModel here" }
1880
1898
  const { user, uid, ...s } = own
1881
1899
  const state = { source: "zcode", device: anyDevice, ...s }
1882
1900
  return { type: "success", refresh: JSON.stringify(state), access: s.key || s.jwt || "", expires: 0, accountId: user, ...(uid ? { uid } : {}) }
@@ -3570,4 +3588,4 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
3570
3588
  // config sets what zcodeConfig has read, for tests: null is ZCode's config
3571
3589
  // out of reach, undefined forgets it
3572
3590
  const config = (cfg) => (cfgCache = cfg === undefined ? null : { cfg, at: Date.now() })
3573
- export const _internal = { wallAnswer, unreached, planFull, notePlan, planFullUntil, locatedKeys, lastKeys, edge, EDGE_HOLD, busyHold, startGate, NARROW_FOR, limitOf, BUSY_N, BUSY_WINDOW, BUSY_HOLD, busyCap, busyHeld, config, entry, limitWindows, termOf, startUsage, routes, blocked, sidelined, plansOf, giftOf, dualUsage, claimHint, unclaimed, unclaimedSeen, aloneGift, aloneSeen, aloneNames, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, queryOf, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY, DEFAULT_ACCOUNTS }
3591
+ export const _internal = { wallAnswer, unreached, planFull, notePlan, planFullUntil, locatedKeys, lastKeys, edge, EDGE_HOLD, busyHold, startGate, NARROW_FOR, limitOf, BUSY_N, BUSY_WINDOW, BUSY_HOLD, busyCap, busyHeld, config, entry, limitWindows, termOf, startUsage, routes, blocked, sidelined, plansOf, giftOf, dualUsage, claimHint, unclaimed, unclaimedSeen, aloneGift, aloneSeen, aloneNames, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, giftSignIn, located, dress, queryOf, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY, DEFAULT_ACCOUNTS }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-zcode-auth",
3
- "version": "0.1.66",
3
+ "version": "0.1.67",
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",