@magpie-community/opencode-zcode-auth 0.1.39 → 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.
- package/README.md +26 -2
- package/index.mjs +35 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -196,6 +196,19 @@ number written into the plugin would hold a Max account to a Lite one's
|
|
|
196
196
|
with no way to raise it. A user who knows their plan's cap sets it on the
|
|
197
197
|
account or the provider in magpie, and magpie's queue follows that.
|
|
198
198
|
|
|
199
|
+
## Two accounts at once
|
|
200
|
+
|
|
201
|
+
Three ZCode accounts used at once from one address can get the address
|
|
202
|
+
refused with a 405, where two are served (01huadalang on Discord). So the
|
|
203
|
+
plugin declares `maxAccounts` two, on the auth hook and as
|
|
204
|
+
`magpie.maxAccounts` in its `package.json`: magpie sends requests to the
|
|
205
|
+
first two accounts of the user's list only, and holds the others in
|
|
206
|
+
reserve. One that runs out or fails rests, and the first in reserve takes
|
|
207
|
+
its place until it is back. A user changes the number on the provider in
|
|
208
|
+
magpie (Advanced → Accounts at once, or `magpie provider at-once zcode
|
|
209
|
+
<n>`), 0 for every account at once. A magpie older than the one that
|
|
210
|
+
reads it uses every account, as before.
|
|
211
|
+
|
|
199
212
|
## The usage card
|
|
200
213
|
|
|
201
214
|
An account with both plans shows both allowances: the coding plan's
|
|
@@ -255,8 +268,19 @@ plans once a day (`auth.checkin`; `magpie accounts checkin` asks now). It
|
|
|
255
268
|
reads both lists above (the banners' feed and the preview, each plan
|
|
256
269
|
once) and posts each plan to
|
|
257
270
|
`POST /api/v1/zcode-plan/billing/claim` (`{"plan_id": …}`) with the
|
|
258
|
-
account's ZCode session, as the app does.
|
|
259
|
-
|
|
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:
|
|
260
284
|
|
|
261
285
|
- nothing listed: *inactive* (ZCode answers an account with nothing to
|
|
262
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)
|
|
@@ -1746,6 +1768,13 @@ function kept(res, text) {
|
|
|
1746
1768
|
// (https://docs.z.ai/devpack/usage-policy), so a number written here would
|
|
1747
1769
|
// hold a Max account to a Lite one's, with no way for the user to raise it.
|
|
1748
1770
|
const DEFAULT_CONCURRENCY = 3
|
|
1771
|
+
// DEFAULT_ACCOUNTS is how many of a user's ZCode accounts magpie sends
|
|
1772
|
+
// requests to at the same time (maxAccounts, on the auth hook and in
|
|
1773
|
+
// package.json): the first in the user's list, the next taking over once
|
|
1774
|
+
// one runs out or fails. 01huadalang on Discord: three accounts used at
|
|
1775
|
+
// once from one address got the address refused with a 405, two didn't. A
|
|
1776
|
+
// user sets their own on the provider (Accounts at once), 0 for no limit.
|
|
1777
|
+
const DEFAULT_ACCOUNTS = 2
|
|
1749
1778
|
const BUSY_CODES = new Set(["3008", "3009"])
|
|
1750
1779
|
// BUSY_WAITS are the waits between asks, longest last: about ten seconds of
|
|
1751
1780
|
// them. Past that the account is saturated rather than busy, and magpie's
|
|
@@ -2294,6 +2323,9 @@ export async function ZCodeAuthPlugin({ client }, options = {}) {
|
|
|
2294
2323
|
// own cap follows its tier (Max > Pro > Lite) and the time of day, and
|
|
2295
2324
|
// a user who knows theirs can raise this on the account
|
|
2296
2325
|
maxConcurrency: DEFAULT_CONCURRENCY,
|
|
2326
|
+
// how many accounts take requests at once, the others in reserve
|
|
2327
|
+
// (DEFAULT_ACCOUNTS); a magpie that doesn't read it uses them all
|
|
2328
|
+
maxAccounts: DEFAULT_ACCOUNTS,
|
|
2297
2329
|
async loader(getAuth, provider) {
|
|
2298
2330
|
const s0 = stateOf(await getAuth())
|
|
2299
2331
|
if (!s0) return {}
|
|
@@ -2650,4 +2682,4 @@ export async function ZCodeAuthPlugin({ client }, options = {}) {
|
|
|
2650
2682
|
// config sets what zcodeConfig has read, for tests: null is ZCode's config
|
|
2651
2683
|
// out of reach, undefined forgets it
|
|
2652
2684
|
const config = (cfg) => (cfgCache = cfg === undefined ? null : { cfg, at: Date.now() })
|
|
2653
|
-
export const _internal = { config, entry, limitWindows, termOf, startUsage, routes, blocked, plansOf, giftOf, dualUsage, claimHint, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY }
|
|
2685
|
+
export const _internal = { config, entry, limitWindows, termOf, startUsage, routes, blocked, plansOf, giftOf, dualUsage, claimHint, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, 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.
|
|
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",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"directory": "packages/zcode"
|
|
15
15
|
},
|
|
16
16
|
"magpie": {
|
|
17
|
-
"maxConcurrency": 3
|
|
17
|
+
"maxConcurrency": 3,
|
|
18
|
+
"maxAccounts": 2
|
|
18
19
|
}
|
|
19
20
|
}
|