@magpie-community/opencode-zcode-auth 0.1.40 → 0.1.41

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 +13 -2
  2. package/index.mjs +24 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -268,8 +268,19 @@ plans once a day (`auth.checkin`; `magpie accounts checkin` asks now). It
268
268
  reads both lists above (the banners' feed and the preview, each plan
269
269
  once) and posts each plan to
270
270
  `POST /api/v1/zcode-plan/billing/claim` (`{"plan_id": …}`) with the
271
- account's ZCode session, as the app does. The answer is judged by the
272
- body's code, not the HTTP status:
271
+ account's ZCode session, as the app does. An answer of nothing to claim
272
+ carries an `until` half an hour out, so magpie's loop asks again then,
273
+ and again, all day while neither list names a plan — two GETs, nothing
274
+ posted: ZCode drops plans into the feed on its own schedule (a reset
275
+ card, a weekend banner starting at 19:00 Beijing), and one that arrives
276
+ after the day's ask used to sit unclaimed past its short life. The
277
+ other answers stand for the day: a claimed plan leaves the feed, so
278
+ asking again half an hour later would find nothing and flip the card
279
+ from "Checked in today" to "No check-in event now"; a captcha plan
280
+ re-asked makes ZCode demand its captcha again; a done plan re-asked
281
+ posts a claim ZCode already answered. So a second plan the same day,
282
+ after one was claimed, is seen the next day. The answer is judged by
283
+ the body's code, not the HTTP status:
273
284
 
274
285
  - nothing listed: *inactive* (ZCode answers an account with nothing to
275
286
  claim `{"code":0,"msg":""}`, with no list at all). A list that doesn't
package/index.mjs CHANGED
@@ -802,20 +802,42 @@ async function toClaim(s) {
802
802
  return { plans, unread }
803
803
  }
804
804
 
805
+ // RECHECK is how long an "nothing to claim" stands before magpie's loop
806
+ // asks again: ZCode drops gift plans into the feed during the day (a
807
+ // reset card, a weekend banner) on its own schedule, and the day's ask
808
+ // may have run hours before, so an inactive settled for the day lets a
809
+ // plan sit unclaimed past its short life (the weekend plan of
810
+ // testdata/touch-1030-wk.json starts 19:00 Beijing). `until` wakes the
811
+ // loop again in half an hour, and it asks again all day while neither
812
+ // list names a plan — two GETs and no claim posted. The other settled
813
+ // answers stand for the day: a claimed plan leaves the feed, so asking
814
+ // a claimed account again half an hour later finds nothing and flips
815
+ // its card from "Checked in today" to "No check-in event now"; a
816
+ // captcha plan re-asked makes ZCode demand its captcha again each time,
817
+ // and a done plan re-asked posts a claim it already answered 1003. The
818
+ // same shape as Qoder's campaign that opens mid-day, asked again on
819
+ // magpie's side there (yetone/magpie#2696). A failed needs no until:
820
+ // magpie asks a failed again after 30 minutes of its own.
821
+ const RECHECK_MS = 30 * 60_000
822
+ const recheck = () => new Date(Date.now() + RECHECK_MS).toISOString()
823
+
805
824
  // claimDaily claims every gift plan ZCode offers the account (#503:
806
825
  // toClaim, the app's banners and its preview), as auth.checkin's answer:
807
826
  // inactive when neither lists one, claimed when one was claimed now,
808
827
  // done when each was claimed before, captcha when ZCode wants the app's
809
828
  // captcha for one (it is claimed in the ZCode app), failed when a list
810
829
  // or a claim can't be read. A failed one is asked again later in the
811
- // day, when a plan claimed now answers 1003.
830
+ // day, when a plan claimed now answers 1003. An inactive stands only
831
+ // until RECHECK_MS from now, so a plan dropped into the feed later in
832
+ // the day is still claimed; the other settled answers stand for the day
833
+ // (see RECHECK).
812
834
  // Nothing here marks the account: a failed claim keeps its sign-in.
813
835
  async function claimDaily(s) {
814
836
  if (!s?.jwt) return { outcome: "ineligible", message: "ZCode's gift plans are claimed with a ZCode sign-in; this account has none" }
815
837
  if (jwtExpired(s.jwt)) return { outcome: "failed", message: EXPIRED }
816
838
  const { plans, unread } = await toClaim(s)
817
839
  if (!plans.length && unread.length) return { outcome: "failed", message: unread.join("; ") }
818
- if (!plans.length) return { outcome: "inactive", message: "no ZCode gift plan to claim" }
840
+ if (!plans.length) return { outcome: "inactive", message: "no ZCode gift plan to claim", until: recheck() }
819
841
  const got = []
820
842
  for (const p of plans) got.push({ name: p.name, ...(await claimOne(s, p.plan_id)) })
821
843
  const named = (o) => got.filter((g) => g.outcome === o).map((g) => g.name)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-zcode-auth",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
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": "./index.mjs",