@magpie-community/opencode-zcode-auth 0.1.64 → 0.1.65

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/README.md +6 -2
  2. package/index.mjs +25 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -350,8 +350,12 @@ menu bar pass it over. The name is a fixed sentence magpie can
350
350
  translate; the count and the plan's own name are the display. Reading
351
351
  the card never claims one. A preview that fails, or lists nothing, adds
352
352
  no line at all, and a card that is an error keeps its error. Claim the
353
- plan in the ZCode app (open it once), or let the daily claim below do it;
354
- the next read shows it as an ordinary gift bucket.
353
+ plan in the ZCode app (open it once); while ZCode asks its security check
354
+ for a claim, as it does now, the daily claim below posts none. The next
355
+ read shows it as an ordinary gift bucket: its `-Trial` entry is listed and
356
+ free first spends it. Until then a `-Trial` pick that finds no gift is
357
+ refused with the held plan's name and "claim it in the ZCode app", not
358
+ only "no active limited quota" (heduian and bg5eau on X, 11-14).
355
359
 
356
360
  ## The daily claim
357
361
 
package/index.mjs CHANGED
@@ -715,6 +715,28 @@ async function claimHint(s) {
715
715
  return { name: CLAIM_HINT, used: 0, aside: true, display: `${n} · ${plan}` }
716
716
  }
717
717
 
718
+ // unclaimed names the gift plans ZCode holds for the account but has not
719
+ // put on it (toClaim), for a -Trial pick that finds no gift: the weekend
720
+ // plan (ZCODE WEEKEND BUILD) comes only by a claim, and the claim needs
721
+ // the ZCode app's captcha (claimDaily posts none), so until it is
722
+ // claimed in the app the pick's quota does not exist yet (heduian and
723
+ // bg5eau on X, 11-14). The refusal says where the quota is rather than
724
+ // only that there is none. Kept ten minutes per session, so an agent
725
+ // retrying the pick doesn't read the feed each time; a read that fails
726
+ // names none and is not kept.
727
+ const unclaimedSeen = new Map()
728
+ async function unclaimed(s) {
729
+ if (!s.jwt || jwtExpired(s.jwt)) return []
730
+ const k = s.jwt
731
+ const c = unclaimedSeen.get(k)
732
+ if (c && Date.now() - c.at < 600_000) return c.names
733
+ const got = await toClaim(s).catch(() => null)
734
+ if (!got || got.unread.length) return []
735
+ const names = uniqueModels(got.plans.map((p) => first(p.name, p.plan_id)).filter(Boolean))
736
+ unclaimedSeen.set(k, { at: Date.now(), names })
737
+ return names
738
+ }
739
+
718
740
  // ---- the daily claim ---------------------------------------------------------------
719
741
 
720
742
  // CLAIMED_ALREADY is /billing/claim's body code for a plan the account
@@ -3119,7 +3141,8 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
3119
3141
  const raw = giftModel(gift, m)
3120
3142
  const available = raw && giftUsable(s, gift, raw)
3121
3143
  if (!available) {
3122
- const error = { type: raw ? "rate_limit_error" : "invalid_request_error", message: raw ? `${giftRested(s, raw) ? `ZCode said the last request for ${raw} was over its quota, so it is not asked again for a minute: ` : ""}ZCode's limited quota for ${raw} is exhausted or temporarily unavailable` : `ZCode has no active limited quota for ${m}` }
3144
+ const held = raw ? [] : await unclaimed(s)
3145
+ const error = { type: raw ? "rate_limit_error" : "invalid_request_error", message: raw ? `${giftRested(s, raw) ? `ZCode said the last request for ${raw} was over its quota, so it is not asked again for a minute: ` : ""}ZCode's limited quota for ${raw} is exhausted or temporarily unavailable` : `ZCode has no active limited quota for ${m}${held.length ? `. ZCode holds ${held.join(", ")} for this account unclaimed: claim it in the ZCode app (its claim needs the app's security check), and ${m} spends it` : ""}` }
3123
3146
  return kept(new Response(JSON.stringify({ type: "error", error }), { status: raw ? 429 : 400, headers: { "content-type": "application/json" } }))
3124
3147
  }
3125
3148
  orig = opts.body = JSON.stringify({ ...JSON.parse(orig), model: wireModel(raw) })
@@ -3501,4 +3524,4 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
3501
3524
  // config sets what zcodeConfig has read, for tests: null is ZCode's config
3502
3525
  // out of reach, undefined forgets it
3503
3526
  const config = (cfg) => (cfgCache = cfg === undefined ? null : { cfg, at: Date.now() })
3504
- 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, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, queryOf, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY, DEFAULT_ACCOUNTS }
3527
+ 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, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, 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.64",
3
+ "version": "0.1.65",
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",