@magpie-community/opencode-zcode-auth 0.1.25 → 0.1.26
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 +13 -2
- package/index.mjs +37 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,9 @@ over Anthropic's Messages API. Provider id: `zcode`.
|
|
|
57
57
|
Start Plan, ZCode 1024 Dev Day) are served to ZCode's own session,
|
|
58
58
|
which a key doesn't carry: for an account with only a gift plan, the
|
|
59
59
|
card and each refused request (1113) say to sign in with ZCode
|
|
60
|
-
instead.
|
|
60
|
+
instead. For an account with a GLM Coding Plan, the card says the
|
|
61
|
+
gift plans' `-Trial` models need ZCode's sign-in, since a key lists
|
|
62
|
+
none of them.
|
|
61
63
|
|
|
62
64
|
## Where the sign-in is kept
|
|
63
65
|
|
|
@@ -139,12 +141,21 @@ that fails, or lists nothing, adds no line at all, and a card that is an
|
|
|
139
141
|
error keeps its error. Claim the plan in the ZCode app (open it once);
|
|
140
142
|
the next read shows it as an ordinary gift bucket.
|
|
141
143
|
|
|
144
|
+
**No ZCode session.** A card read with a key, or with a sign-in whose
|
|
145
|
+
ZCode session has run out (it can't be renewed), sets aside a line named
|
|
146
|
+
"ZCode gift plans (-Trial models) need ZCode's sign-in", with why in its
|
|
147
|
+
display: such an account reads no gift and lists no `-Trial` entries.
|
|
148
|
+
Sign in again with ZCode to get them back. A gift read that fails
|
|
149
|
+
otherwise is asked again a minute later, not ten.
|
|
150
|
+
|
|
142
151
|
## Models
|
|
143
152
|
|
|
144
153
|
The models are the ones ZCode offers for the account's plan. They come
|
|
145
154
|
from ZCode's provider config: the release zcode.z.ai names, or an
|
|
146
155
|
installed ZCode's copy if that one is newer. The list is kept for 10
|
|
147
|
-
minutes. When the config can't be read, the plugin falls back to this list
|
|
156
|
+
minutes. When the config can't be read, the plugin falls back to this list
|
|
157
|
+
(and magpie keeps the list it was told last, unless the account's gift
|
|
158
|
+
plans add `-Trial` entries, which are told as read):
|
|
148
159
|
|
|
149
160
|
| Model | Context | Output | Efforts |
|
|
150
161
|
|---|---|---|---|
|
package/index.mjs
CHANGED
|
@@ -214,8 +214,15 @@ async function plansOf(s) {
|
|
|
214
214
|
let sure = false
|
|
215
215
|
try {
|
|
216
216
|
if (!(await plan(s))) start = true
|
|
217
|
-
else
|
|
218
|
-
|
|
217
|
+
else {
|
|
218
|
+
// a gift read that failed is unknown, not "no gift": asked again in
|
|
219
|
+
// a minute, so its trial entries come back with the next list (an
|
|
220
|
+
// expired session is known: the card says to sign in again)
|
|
221
|
+
let failed = false
|
|
222
|
+
gift = await startPlan(s.jwt, s.device).catch(() => ((failed = !jwtExpired(s.jwt)), null))
|
|
223
|
+
sure = !failed
|
|
224
|
+
}
|
|
225
|
+
if (start) sure = true
|
|
219
226
|
} catch {
|
|
220
227
|
// the plan list could not be read: a key account takes the dual route
|
|
221
228
|
// (start stays false, the gift is kept, a minute's ttl), so a gift
|
|
@@ -616,6 +623,21 @@ async function claimHint(s) {
|
|
|
616
623
|
return { name: CLAIM_HINT, used: 0, aside: true, display: `${n} · ${plan}` }
|
|
617
624
|
}
|
|
618
625
|
|
|
626
|
+
// GIFT_SIGN_IN is the card's line for an account whose gift plans can't
|
|
627
|
+
// be read: ZCode's gift plans (the Start Plan, ZCode 1024 Dev Day, ZCode
|
|
628
|
+
// Trust Build) are served by zcode.z.ai to ZCode's own session alone, so
|
|
629
|
+
// a GLM Coding Plan key, or a sign-in whose ZCode session has run out
|
|
630
|
+
// (that token can't be renewed), lists no <model>-Trial entries and
|
|
631
|
+
// spends the coding plan alone. A fixed sentence, so magpie can
|
|
632
|
+
// translate it; why goes in the display. Set aside: it stops nothing.
|
|
633
|
+
const GIFT_SIGN_IN = "ZCode gift plans (-Trial models) need ZCode's sign-in"
|
|
634
|
+
function giftSignIn(s, key) {
|
|
635
|
+
if (isTeam(s)) return null
|
|
636
|
+
if (!s.jwt) return { name: GIFT_SIGN_IN, used: 0, aside: true, display: key ? "not read with an API key: add the account with a ZCode sign-in" : "this sign-in has no ZCode session: sign in again" }
|
|
637
|
+
if (jwtExpired(s.jwt)) return { name: GIFT_SIGN_IN, used: 0, aside: true, display: "ZCode's sign-in has expired: sign in again" }
|
|
638
|
+
return null
|
|
639
|
+
}
|
|
640
|
+
|
|
619
641
|
// startUsage is a gift-only account's card: its buckets, or the words
|
|
620
642
|
// for having none to show. The card's header already names the plan, so
|
|
621
643
|
// the windows of one plan keep their own names; with several plans each
|
|
@@ -1781,7 +1803,11 @@ export async function ZCodeAuthPlugin({ client }) {
|
|
|
1781
1803
|
if (out[id]) continue
|
|
1782
1804
|
out[id] = model({ ...about(raw), id }, url)
|
|
1783
1805
|
}
|
|
1784
|
-
|
|
1806
|
+
// a fallback tells magpie to keep the list it was told last, which
|
|
1807
|
+
// predates the gift read just made: an account whose gift lists
|
|
1808
|
+
// trial entries is told this list, so ZCode's config out of reach
|
|
1809
|
+
// (a remote box that can't get its CDN) never hides them
|
|
1810
|
+
if (fell && !giftNames(gift).length) out[Symbol.for("magpie.fellBack")] = true
|
|
1785
1811
|
return out
|
|
1786
1812
|
},
|
|
1787
1813
|
},
|
|
@@ -1953,6 +1979,10 @@ export async function ZCodeAuthPlugin({ client }) {
|
|
|
1953
1979
|
if (!card.error) {
|
|
1954
1980
|
const hint = await claimHint(s)
|
|
1955
1981
|
if (hint) card.windows = [...(card.windows ?? []), hint]
|
|
1982
|
+
// a key, or a ZCode session that ran out: no gift read, so no
|
|
1983
|
+
// -Trial models, said on the card rather than left out unsaid
|
|
1984
|
+
const need = start ? null : giftSignIn(s, auth?.type === "api")
|
|
1985
|
+
if (need) card.windows = [...(card.windows ?? []), need]
|
|
1956
1986
|
}
|
|
1957
1987
|
return card
|
|
1958
1988
|
} catch (e) {
|
|
@@ -2002,4 +2032,7 @@ export async function ZCodeAuthPlugin({ client }) {
|
|
|
2002
2032
|
}
|
|
2003
2033
|
|
|
2004
2034
|
// for tests
|
|
2005
|
-
|
|
2035
|
+
// config sets what zcodeConfig has read, for tests: null is ZCode's config
|
|
2036
|
+
// out of reach, undefined forgets it
|
|
2037
|
+
const config = (cfg) => (cfgCache = cfg === undefined ? null : { cfg, at: Date.now() })
|
|
2038
|
+
export const _internal = { config, entry, limitWindows, termOf, startUsage, routes, blocked, plansOf, giftOf, dualUsage, claimHint, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, dress, PROMPT }
|
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.26",
|
|
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",
|