@magpie-community/opencode-zcode-auth 0.1.9 → 0.1.10
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 +6 -0
- package/index.mjs +30 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,3 +112,9 @@ A gift plan's models appear again as `<model>-Trial` entries, so a
|
|
|
112
112
|
request can spend the gift's quota on purpose. A trial entry is listed
|
|
113
113
|
while any live bucket serves its model, spent buckets included (a spent
|
|
114
114
|
entry answers 429 rather than vanishing mid-session).
|
|
115
|
+
|
|
116
|
+
Two plans can give one model (ZCode Trust Build and the Start Plan both
|
|
117
|
+
give GLM-5.3-Flash). The server picks the bucket, so the usage card
|
|
118
|
+
counts the model on its live bucket, the least used, and sets a spent
|
|
119
|
+
sibling aside. A spent sibling never makes the model, or the account,
|
|
120
|
+
look used up while another bucket still has quota.
|
package/index.mjs
CHANGED
|
@@ -538,14 +538,38 @@ const NO_START = "this account has no GLM Coding Plan, and ZCode's Start Plan ha
|
|
|
538
538
|
async function startUsage(s) {
|
|
539
539
|
const g = await giftOf(s)
|
|
540
540
|
if (!g) return { error: NO_START }
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
541
|
+
const best = bestBuckets(g.windows)
|
|
542
|
+
g.windows = g.windows.map(({ _plan, _spent, ...w }, i) => {
|
|
543
|
+
if (!w.models?.length) return w
|
|
544
|
+
// a model two plans give (Trust Build's and the Start Plan's Flash)
|
|
545
|
+
// counts on the bucket ZCode spends now; the other stays on the card
|
|
546
|
+
// without holding the model up (ganlerk, Discord)
|
|
547
|
+
const models = w.models.filter((m) => best.get(m.toLowerCase()) === i)
|
|
548
|
+
if (!models.length) {
|
|
549
|
+
delete w.models
|
|
550
|
+
return { ...w, aside: true }
|
|
551
|
+
}
|
|
552
|
+
return { ...w, models: [...models, ...models.map(giftID)] }
|
|
553
|
+
})
|
|
546
554
|
return g
|
|
547
555
|
}
|
|
548
556
|
|
|
557
|
+
// bestBuckets is, for each model the gift's buckets serve, the index of
|
|
558
|
+
// the one a request spends: a live one before a spent one, the least
|
|
559
|
+
// used of those. The server picks among an account's buckets itself
|
|
560
|
+
// (ZCode sends no plan with a request), so one spent bucket doesn't stop
|
|
561
|
+
// a model another still has.
|
|
562
|
+
function bestBuckets(windows) {
|
|
563
|
+
const best = new Map()
|
|
564
|
+
windows.forEach((w, i) => {
|
|
565
|
+
for (const m of w.models ?? []) {
|
|
566
|
+
const key = m.toLowerCase(), old = best.get(key), prev = windows[old]
|
|
567
|
+
if (old === undefined || (prev._spent && !w._spent) || (prev._spent === w._spent && w.used < prev.used)) best.set(key, i)
|
|
568
|
+
}
|
|
569
|
+
})
|
|
570
|
+
return best
|
|
571
|
+
}
|
|
572
|
+
|
|
549
573
|
// dualUsage shows both pools but only the pool a request can use counts
|
|
550
574
|
// for its model. Live gift models don't spend the Coding windows; spent
|
|
551
575
|
// or blocked gift buckets stay visible without holding up the Coding Plan.
|
|
@@ -571,13 +595,7 @@ async function dualUsage(s) {
|
|
|
571
595
|
const notModels = gift.allModels.map((m) => giftID(m).toLowerCase())
|
|
572
596
|
if (notModels.length) out.windows = out.windows.map((w) => w.aside ? w : { ...w, notModels })
|
|
573
597
|
// Several buckets may serve one model: one spent sibling cannot block it.
|
|
574
|
-
const best =
|
|
575
|
-
g.windows.forEach((w, i) => {
|
|
576
|
-
for (const m of w.models ?? []) {
|
|
577
|
-
const key = m.toLowerCase(), old = best.get(key), prev = g.windows[old]
|
|
578
|
-
if (old === undefined || (prev._spent && !w._spent) || (prev._spent === w._spent && w.used < prev.used)) best.set(key, i)
|
|
579
|
-
}
|
|
580
|
-
})
|
|
598
|
+
const best = bestBuckets(g.windows)
|
|
581
599
|
out.windows.push(...g.windows.map(({ _plan: p, _spent, ...w }, i) => {
|
|
582
600
|
const selected = gift.allModels.filter((m) => best.get(m.toLowerCase()) === i)
|
|
583
601
|
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.10",
|
|
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",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|