@magpie-community/opencode-zcode-auth 0.1.46 → 0.1.47
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/index.mjs +9 -3
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -152,6 +152,11 @@ const uniqueModels = (names) => {
|
|
|
152
152
|
return [...byName.values()]
|
|
153
153
|
}
|
|
154
154
|
const giftNames = (g) => g?.allModels ?? g?.models ?? []
|
|
155
|
+
// wireModel is a gift model as ZCode sends it: the buckets name it lowercased
|
|
156
|
+
// ("glm-5.3-flash"), the app's request carries its registry id
|
|
157
|
+
// ("GLM-5.3-Flash"; normalizeOfficialGlmModelId's spelling). Names ZCode
|
|
158
|
+
// does not know go as the bucket wrote them.
|
|
159
|
+
const wireModel = (m) => MODELS.find((x) => x.id.toLowerCase() === String(m).toLowerCase())?.id ?? m
|
|
155
160
|
const giftModel = (g, id) => giftNames(g).find((m) => giftID(m).toLowerCase() === id.toLowerCase())
|
|
156
161
|
const bucketModels = (x) => (Array.isArray(x.capabilities) ? x.capabilities : [])
|
|
157
162
|
.map((c) => String(c ?? "").trim()).filter((c) => c.startsWith("model:") || !c.includes(":"))
|
|
@@ -273,6 +278,7 @@ const blocked = new Map()
|
|
|
273
278
|
// giftServes: the gift's buckets name their models lowercased ("glm-5.3-
|
|
274
279
|
// flash"); what is asked for arrives as the plan lists it ("GLM-5.3-Flash").
|
|
275
280
|
const giftServes = (gift, m) => (gift.models ?? []).some((x) => x.toLowerCase() === m.toLowerCase())
|
|
281
|
+
const giftRested = (s, m) => Date.now() < (blocked.get(s.key + "\0" + s.jwt + "\0" + m.toLowerCase()) ?? 0)
|
|
276
282
|
const giftUsable = (s, gift, m) => !jwtExpired(s.jwt) && giftServes(gift, m) &&
|
|
277
283
|
Date.now() >= (blocked.get(s.key + "\0" + s.jwt + "\0" + m.toLowerCase()) ?? 0)
|
|
278
284
|
|
|
@@ -2405,10 +2411,10 @@ export async function ZCodeAuthPlugin({ client }, options = {}) {
|
|
|
2405
2411
|
const raw = giftModel(gift, m)
|
|
2406
2412
|
const available = raw && giftUsable(s, gift, raw)
|
|
2407
2413
|
if (!available) {
|
|
2408
|
-
const error = { type: raw ? "rate_limit_error" : "invalid_request_error", message: raw ? `ZCode's limited quota for ${raw} is exhausted or temporarily unavailable` : `ZCode has no active limited quota for ${m}` }
|
|
2414
|
+
const error = { type: raw ? "rate_limit_error" : "invalid_request_error", message: raw ? `ZCode's limited quota for ${raw} is exhausted or temporarily unavailable${giftRested(s, raw) ? " (ZCode answered 429 to the last request for it, so it is not asked again for a minute)" : ""}` : `ZCode has no active limited quota for ${m}` }
|
|
2409
2415
|
return kept(new Response(JSON.stringify({ type: "error", error }), { status: raw ? 429 : 400, headers: { "content-type": "application/json" } }))
|
|
2410
2416
|
}
|
|
2411
|
-
orig = opts.body = JSON.stringify({ ...JSON.parse(orig), model: raw })
|
|
2417
|
+
orig = opts.body = JSON.stringify({ ...JSON.parse(orig), model: wireModel(raw) })
|
|
2412
2418
|
m = raw
|
|
2413
2419
|
forcedGift = true
|
|
2414
2420
|
} else if (!alone && !edgeHeld() && freeFirst(provider?.options) && s.jwt && known && giftUsable(s, known, m)) {
|
|
@@ -2421,7 +2427,7 @@ export async function ZCodeAuthPlugin({ client }, options = {}) {
|
|
|
2421
2427
|
// it was. A refusal past this check is replayed on the plan
|
|
2422
2428
|
// in the same request (replayOnPlan below).
|
|
2423
2429
|
const raw = giftNames(known).find((x) => x.toLowerCase() === m.toLowerCase())
|
|
2424
|
-
orig = opts.body = JSON.stringify({ ...JSON.parse(orig), model: raw })
|
|
2430
|
+
orig = opts.body = JSON.stringify({ ...JSON.parse(orig), model: wireModel(raw) })
|
|
2425
2431
|
m = raw
|
|
2426
2432
|
freeGift = true
|
|
2427
2433
|
}
|
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.47",
|
|
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": "./opencode.mjs",
|