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

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 +20 -8
  2. package/index.mjs +29 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -136,14 +136,15 @@ never read or buffered on the way.
136
136
 
137
137
  **Free first.** Picking `-Trial` by hand keeps the choice the user's,
138
138
  but an agent that always asks the plain model never sees the gift.
139
- `freeFirst` turns the preference around: the plain model spends the
140
- account's own live gift first, and falls back to the coding plan when
141
- the gift cannot serve it — a bucket that is spent, a model the gift
142
- does not serve, no ZCode session, or the minute's rest a refusal just
143
- earned. Turn it on for the whole plugin in magpie's Plugins › Options
139
+ `freeFirst`, on by default since 0.1.42, turns the preference around:
140
+ the plain model spends the account's own live gift first, and falls
141
+ back to the coding plan when the gift cannot serve it — a bucket that
142
+ is spent, a model the gift does not serve, no ZCode session, or the
143
+ minute's rest a refusal just earned. Turn it off for the whole plugin
144
+ in magpie's Plugins › Options
144
145
 
145
146
  ```json
146
- { "freeFirst": true }
147
+ { "freeFirst": false }
147
148
  ```
148
149
 
149
150
  or on the provider alone, under `provider.zcode.options` in the config
@@ -268,8 +269,19 @@ plans once a day (`auth.checkin`; `magpie accounts checkin` asks now). It
268
269
  reads both lists above (the banners' feed and the preview, each plan
269
270
  once) and posts each plan to
270
271
  `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:
272
+ account's ZCode session, as the app does. An answer of nothing to claim
273
+ carries an `until` half an hour out, so magpie's loop asks again then,
274
+ and again, all day while neither list names a plan — two GETs, nothing
275
+ posted: ZCode drops plans into the feed on its own schedule (a weekend
276
+ banner starting at 19:00 Beijing, say), and one that arrives
277
+ after the day's ask used to sit unclaimed past its short life. The
278
+ other answers stand for the day: a claimed plan leaves the feed, so
279
+ asking again half an hour later would find nothing and flip the card
280
+ from "Checked in today" to "No check-in event now"; a captcha plan
281
+ re-asked makes ZCode demand its captcha again; a done plan re-asked
282
+ posts a claim ZCode already answered. So a second plan the same day,
283
+ after one was claimed, is seen the next day. The answer is judged by
284
+ the body's code, not the HTTP status:
273
285
 
274
286
  - nothing listed: *inactive* (ZCode answers an account with nothing to
275
287
  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
+ // weekend banner, say) 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)
@@ -2219,9 +2241,12 @@ export async function ZCodeAuthPlugin({ client }, options = {}) {
2219
2241
  }
2220
2242
  // freeFirst reads the option from the provider config's options first,
2221
2243
  // and from the plugin's own (magpie's Plugins › Options) when the
2222
- // provider carries no freeFirst of its own.
2244
+ // provider carries no freeFirst of its own. It is on unless one of them
2245
+ // says false: a gift ZCode hands out (each weekend, sgfvdsg86265 on X)
2246
+ // lapses unused behind an agent that asks the plain model, and every
2247
+ // failure of the gift is answered from the plan.
2223
2248
  const freeFirst = (providerOptions) =>
2224
- providerOptions?.freeFirst !== undefined ? providerOptions.freeFirst === true : options?.freeFirst === true
2249
+ providerOptions?.freeFirst !== undefined ? providerOptions.freeFirst !== false : options?.freeFirst !== false
2225
2250
  const oauth = (site) => ({
2226
2251
  type: "oauth",
2227
2252
  label: `ZCode: ${SITES[site].name}${site === "bigmodel" ? " (智谱)" : ""} GLM Coding Plan`,
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.42",
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",