@magpie-community/opencode-zcode-auth 0.1.35 → 0.1.37
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 +8 -4
- package/index.mjs +27 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -166,9 +166,12 @@ and end. The card's plan and term stay the coding plan's. A gift read
|
|
|
166
166
|
that fails leaves just the coding card — magpie hides a card's windows
|
|
167
167
|
behind an error, so a gift hiccup must not black out a working Coding
|
|
168
168
|
Plan. A gift that goes out of date while requests use it simply stops
|
|
169
|
-
showing. Beside the coding plan's windows each gift bucket is named
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
showing. Beside the coding plan's windows each gift bucket is named by
|
|
170
|
+
its model first, as ZCode's own "Today's balance" lists it, then by its
|
|
171
|
+
plan ("GLM-5.1-Trial · Start Plan"), one plan or several, so the two
|
|
172
|
+
allowances can't be read as one. The model comes first because magpie's
|
|
173
|
+
ring and account row cut a long name short: "ZCODE GLOBAL BUI…" (the
|
|
174
|
+
Start Plan claimed on 10-29) said neither (#504).
|
|
172
175
|
|
|
173
176
|
**Gift plans that start later.** A plan on the balance whose `starts_at`
|
|
174
177
|
is still to come (a Start Plan taking effect at 23:00 today) serves
|
|
@@ -213,7 +216,8 @@ reads the app's preview list and posts each plan it lists to
|
|
|
213
216
|
account's ZCode session, as the app does. The answer is judged by the
|
|
214
217
|
body's code, not the HTTP status:
|
|
215
218
|
|
|
216
|
-
- nothing listed: *inactive
|
|
219
|
+
- nothing listed: *inactive* (ZCode answers an account with nothing to
|
|
220
|
+
claim `{"code":0,"msg":""}`, with no list at all);
|
|
217
221
|
- code 0: *claimed* (the next request uses the plan);
|
|
218
222
|
- code 1003 "target already exists" (HTTP 200): *done*, claimed before;
|
|
219
223
|
- code 3007 "captcha verify failed": *captcha*, the plan is claimed in
|
package/index.mjs
CHANGED
|
@@ -663,7 +663,7 @@ async function claimHint(s) {
|
|
|
663
663
|
} catch {
|
|
664
664
|
return null
|
|
665
665
|
}
|
|
666
|
-
const plans = (
|
|
666
|
+
const plans = (previewPlans(d) ?? []).filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
|
667
667
|
if (!plans.length) return null
|
|
668
668
|
const n = plans.length
|
|
669
669
|
const plan = first(...plans.map((p) => (typeof p?.name === "string" ? p.name : "")), "ZCode gift plan")
|
|
@@ -718,6 +718,20 @@ async function claimOne(s, planID) {
|
|
|
718
718
|
return { outcome: "failed", why: `${msg || "error"} (HTTP ${res.status}, code ${code})` }
|
|
719
719
|
}
|
|
720
720
|
|
|
721
|
+
// previewPlans is /billing/preview's plan list. An account with nothing to
|
|
722
|
+
// claim is answered {"code":0,"msg":"","logid":…}: no data at all, not
|
|
723
|
+
// "plans": [] (the owner's account read 10-30 for hykql's report on
|
|
724
|
+
// Discord; the list is left out when it is empty). call has already judged the code, so a reply
|
|
725
|
+
// without data, or data without plans, is a list of none. Only data that
|
|
726
|
+
// isn't an object, or plans that are there and aren't a list, don't read
|
|
727
|
+
// (null, unknown).
|
|
728
|
+
function previewPlans(d) {
|
|
729
|
+
if (d == null) return []
|
|
730
|
+
if (typeof d !== "object" || Array.isArray(d)) return null
|
|
731
|
+
if (d.plans == null) return []
|
|
732
|
+
return Array.isArray(d.plans) ? d.plans : null
|
|
733
|
+
}
|
|
734
|
+
|
|
721
735
|
// claimDaily claims every gift plan ZCode's preview lists for the account
|
|
722
736
|
// (#503), as auth.checkin's answer: inactive when it lists none, claimed
|
|
723
737
|
// when one was claimed now, done when each was claimed before, captcha
|
|
@@ -734,8 +748,9 @@ async function claimDaily(s) {
|
|
|
734
748
|
} catch (e) {
|
|
735
749
|
return { outcome: "failed", message: `gift plans to claim: ${e?.message ?? String(e)}` }
|
|
736
750
|
}
|
|
737
|
-
|
|
738
|
-
|
|
751
|
+
const listed = previewPlans(d)
|
|
752
|
+
if (!listed) return { outcome: "failed", message: "gift plans to claim: the plan list doesn't read" }
|
|
753
|
+
const plans = listed.filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
|
739
754
|
if (!plans.length) return { outcome: "inactive", message: "no ZCode gift plan to claim" }
|
|
740
755
|
const got = []
|
|
741
756
|
for (const p of plans) {
|
|
@@ -800,7 +815,7 @@ async function startUsage(s) {
|
|
|
800
815
|
return g
|
|
801
816
|
}
|
|
802
817
|
|
|
803
|
-
// byPlan names a bucket after its plan ("ZCode 1024 Dev Day
|
|
818
|
+
// byPlan names a bucket after its plan ("GLM-5.3 · ZCode 1024 Dev Day")
|
|
804
819
|
// when the gift's buckets come from more than one plan: two plans each
|
|
805
820
|
// give a GLM-5.3, and named alike a spent one and a live one can't be
|
|
806
821
|
// told apart (01huadalang, Discord: the new-user plan's spent GLM-5.3
|
|
@@ -808,7 +823,7 @@ async function startUsage(s) {
|
|
|
808
823
|
// their own names, as the card's header names the plan.
|
|
809
824
|
function byPlan(windows) {
|
|
810
825
|
const several = new Set(windows.map((w) => w._plan || "")).size > 1
|
|
811
|
-
return (name, plan) => (several && plan ?
|
|
826
|
+
return (name, plan) => (several && plan ? name + " · " + plan : name)
|
|
812
827
|
}
|
|
813
828
|
|
|
814
829
|
// countedFirst puts the buckets a request spends before those set aside
|
|
@@ -869,9 +884,13 @@ async function dualUsage(s, out) {
|
|
|
869
884
|
// Several buckets may serve one model: one spent sibling cannot block it.
|
|
870
885
|
const best = bestBuckets(g.windows)
|
|
871
886
|
// beside the Coding Plan's windows every gift bucket is named after
|
|
872
|
-
// its plan, one plan or several: "
|
|
873
|
-
// be read as the Coding Plan's own (windy, Discord)
|
|
874
|
-
|
|
887
|
+
// its plan, one plan or several: "GLM-5.1-Trial · Start Plan" can't
|
|
888
|
+
// be read as the Coding Plan's own (windy, Discord). The bucket's
|
|
889
|
+
// own name (ZCode's show_name, as its "Today's balance" lists it)
|
|
890
|
+
// comes first: magpie's ring and account row cut a long name short,
|
|
891
|
+
// and "ZCODE GLOBAL BUI…" said neither the model nor the plan's
|
|
892
|
+
// kind, so the Start Plan read as missing (Danbuth, plugins#504)
|
|
893
|
+
const label = (name, plan) => name + " · " + first(plan, "Start Plan")
|
|
875
894
|
out.windows.push(...countedFirst(g.windows.map(({ _plan: p, _spent, ...w }, i) => {
|
|
876
895
|
const selected = gift.allModels.filter((m) => best.get(m.toLowerCase()) === i)
|
|
877
896
|
const models = selected.map(giftID)
|
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.37",
|
|
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",
|