@magpie-community/opencode-zcode-auth 0.1.60 → 0.1.63

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 (3) hide show
  1. package/index.mjs +10 -2
  2. package/opencode2.mjs +25 -1
  3. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1251,6 +1251,7 @@ async function personalResets(root, key) {
1251
1251
  // hours and of the week, of which only those still available count (one
1252
1252
  // run out stays listed a week, available false), each with its own end
1253
1253
  // (each, soonest first, one with no end last) and the soonest as until.
1254
+ // One whose end has passed is not counted, whatever its flag says.
1254
1255
  // null when the list can't be read, so no count is shown rather than 0,
1255
1256
  // and when it holds none.
1256
1257
  async function resetsOf(url, auth, headers) {
@@ -1266,8 +1267,11 @@ async function resetsOf(url, auth, headers) {
1266
1267
  let n = 0
1267
1268
  for (const x of Array.isArray(rs) ? rs : []) {
1268
1269
  if (x?.available !== true) continue
1269
- n++
1270
1270
  const t = when(x.expireTime)
1271
+ // a reset past its end is no reset: the list can still flag it
1272
+ // available, and the vendor's page puts it among the expired
1273
+ if (t && t <= Date.now()) continue
1274
+ n++
1271
1275
  if (t && (!until || t < until)) until = t
1272
1276
  each.push(t ? { until: new Date(t).toISOString(), window } : { window })
1273
1277
  }
@@ -1800,7 +1804,11 @@ function ownSignIn() {
1800
1804
  else s = { ...s, jwt, base: s.base || ZAI_BASE, site: s.base === BIGMODEL_BASE ? "bigmodel" : "zai" }
1801
1805
  if (!s.key && !s.jwt && !isTeam(s)) return null
1802
1806
  let info = {}
1803
- for (const name of ["oauth:zai:user_info", "oauth:bigmodel:user_info"]) {
1807
+ // The JWT belongs to the app's active sign-in. Cached profiles from
1808
+ // another provider must not name it, and 3.18's China sign-in is zai_cn.
1809
+ const active = decrypt(key, store["oauth:active_provider"])
1810
+ const families = [...new Set([active, "zai", "zai_cn", "bigmodel"].filter((x) => ["zai", "zai_cn", "bigmodel"].includes(x)))]
1811
+ for (const name of families.map((x) => `oauth:${x}:user_info`)) {
1804
1812
  const v = decrypt(key, store[name])
1805
1813
  if (v && !first(info.email, info.name, info.user_id)) {
1806
1814
  try {
package/opencode2.mjs CHANGED
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
575
575
  }
576
576
  } catch {}
577
577
  })()
578
- void refresh()
578
+ // A plugin still reading its list in the background when the first read
579
+ // returned (agy-cli: `agy models` and a session probe take seconds, and
580
+ // the first read gets its static list) says so through
581
+ // provider.warming(): the list is read once more when that ends, once,
582
+ // and no later than a minute on.
583
+ const warmed = async () => {
584
+ let w
585
+ try {
586
+ w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
587
+ } catch {
588
+ return
589
+ }
590
+ if (!w || typeof w.then !== "function") return
591
+ let timer
592
+ await Promise.race([
593
+ Promise.resolve(w).catch(() => {}),
594
+ new Promise((r) => {
595
+ timer = setTimeout(r, 60_000)
596
+ timer.unref?.()
597
+ }),
598
+ ])
599
+ clearTimeout(timer)
600
+ if (live.on) await refresh()
601
+ }
602
+ void refresh().then(warmed, () => {})
579
603
  }
580
604
 
581
605
  export async function setup(ctx, mod = v1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-zcode-auth",
3
- "version": "0.1.60",
3
+ "version": "0.1.63",
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",