@magpie-community/opencode-zcode-auth 0.1.11 → 0.1.13
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 +4 -2
- package/index.mjs +24 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,9 +96,11 @@ showing.
|
|
|
96
96
|
trust-build / gift plans (a day's ZCode Trust Build, say) that are not
|
|
97
97
|
on the account until the ZCode app claims them. The plugin reads the
|
|
98
98
|
app's own list of them (`GET /api/v1/zcode-plan/billing/preview`) with
|
|
99
|
-
the card and names them there —
|
|
99
|
+
the card and names them there — the window is named "Gift plans to
|
|
100
|
+
claim in the ZCode app" and the display shows "1 · ZCode Trust Build"
|
|
100
101
|
— set aside, so the line stops nothing and routing, usage caps and the
|
|
101
|
-
menu bar pass it over. The
|
|
102
|
+
menu bar pass it over. The name is a fixed sentence magpie can
|
|
103
|
+
translate; the count and the plan's own name are the display. The plugin never claims one: the claim needs the
|
|
102
104
|
Aliyun captcha attestation only the app's renderer can make. A preview
|
|
103
105
|
that fails, or lists nothing, adds no line at all, and a card that is an
|
|
104
106
|
error keeps its error. Claim the plan in the ZCode app (open it once);
|
package/index.mjs
CHANGED
|
@@ -366,7 +366,9 @@ const isNum = (v) => typeof v === "number" && Number.isFinite(v)
|
|
|
366
366
|
// the current value), else the percentage given. TIME_LIMIT is the month's
|
|
367
367
|
// MCP tool calls, which ZCode shows but never stops the models on, so it is
|
|
368
368
|
// set aside, as is a limit whose whole is told as 0: no cap (an older
|
|
369
|
-
// plan's), which the vendor may still give as 100% used.
|
|
369
|
+
// plan's), which the vendor may still give as 100% used. A window whose
|
|
370
|
+
// count is told carries it as amount of limit, so magpie's card says the
|
|
371
|
+
// count as used or as left, as it says the share beside it (#659).
|
|
370
372
|
function limitWindows(d) {
|
|
371
373
|
const out = []
|
|
372
374
|
for (const x of d?.limits ?? []) {
|
|
@@ -380,9 +382,13 @@ function limitWindows(d) {
|
|
|
380
382
|
if (isNum(x.remaining)) {
|
|
381
383
|
const used = total - x.remaining
|
|
382
384
|
w.used = (100 * used) / total
|
|
385
|
+
w.amount = used
|
|
386
|
+
w.limit = total
|
|
383
387
|
w.display = `${compact(used)} / ${compact(total)}`
|
|
384
388
|
} else if (isNum(x.currentValue)) {
|
|
385
389
|
if (!isNum(x.percentage)) w.used = (100 * x.currentValue) / total
|
|
390
|
+
w.amount = x.currentValue
|
|
391
|
+
w.limit = total
|
|
386
392
|
w.display = `${compact(x.currentValue)} / ${compact(total)}`
|
|
387
393
|
}
|
|
388
394
|
}
|
|
@@ -508,7 +514,11 @@ async function giftOf(s) {
|
|
|
508
514
|
const w = { name: base, used: 0, _plan: str(owner.name), _spent: giftSpent(x) }
|
|
509
515
|
if (used === undefined) used = total !== undefined && left !== undefined ? total - left : 0
|
|
510
516
|
if (total > 0) {
|
|
517
|
+
// the bucket's count as amount of limit, as the Coding windows' is
|
|
518
|
+
// (#659): magpie says it as used or as left, as it says the share
|
|
511
519
|
w.used = (100 * used) / total
|
|
520
|
+
w.amount = used
|
|
521
|
+
w.limit = total
|
|
512
522
|
w.display = `${compact(used)} / ${compact(total)}`
|
|
513
523
|
}
|
|
514
524
|
if (w._spent) w.used = Math.max(100, w.used)
|
|
@@ -531,15 +541,23 @@ async function giftOf(s) {
|
|
|
531
541
|
return out
|
|
532
542
|
}
|
|
533
543
|
|
|
544
|
+
// CLAIM_HINT is the claim line's name: a fixed sentence, so magpie
|
|
545
|
+
// translates it with the interface's own language (the plan's name and
|
|
546
|
+
// the count are data, and go in the display, which is shown as it came).
|
|
547
|
+
const CLAIM_HINT = "Gift plans to claim in the ZCode app"
|
|
548
|
+
|
|
534
549
|
// claimHint is the card's line for gift plans ZCode is holding for the
|
|
535
550
|
// account but has not put on it: GET /billing/preview lists them, and
|
|
536
551
|
// only the ZCode app claims one — its claim takes the Aliyun captcha
|
|
537
552
|
// attestation the app's own renderer makes, so the plugin reads the list
|
|
538
553
|
// and asks the user to claim it there. A window, set aside (it is no
|
|
539
554
|
// allowance: using it up stops nothing), so the card shows it and
|
|
540
|
-
// routing, caps and the menu bar pass it over.
|
|
541
|
-
//
|
|
542
|
-
//
|
|
555
|
+
// routing, caps and the menu bar pass it over. The window's name is a
|
|
556
|
+
// fixed sentence, so magpie can translate it (a display is shown as it
|
|
557
|
+
// came); the count and the plan's own name go in the display. null when
|
|
558
|
+
// there is nothing to claim, the preview failing or listing none among
|
|
559
|
+
// it: a failed read is no line at all, never a card or a refusal of its
|
|
560
|
+
// own.
|
|
543
561
|
async function claimHint(s) {
|
|
544
562
|
if (!s.jwt || jwtExpired(s.jwt)) return null
|
|
545
563
|
let d
|
|
@@ -551,8 +569,8 @@ async function claimHint(s) {
|
|
|
551
569
|
const plans = (Array.isArray(d?.plans) ? d.plans : []).filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
|
552
570
|
if (!plans.length) return null
|
|
553
571
|
const n = plans.length
|
|
554
|
-
const
|
|
555
|
-
return { name, used: 0, aside: true, display: `${n}
|
|
572
|
+
const plan = first(...plans.map((p) => (typeof p?.name === "string" ? p.name : "")), "ZCode gift plan")
|
|
573
|
+
return { name: CLAIM_HINT, used: 0, aside: true, display: `${n} · ${plan}` }
|
|
556
574
|
}
|
|
557
575
|
|
|
558
576
|
// startUsage is a gift-only account's card: its buckets, or the words
|
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.13",
|
|
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",
|