@magpie-community/opencode-zcode-auth 0.1.52 → 0.1.53
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 +20 -5
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -315,6 +315,19 @@ function spentUp(text, status) {
|
|
|
315
315
|
return c1 === "1113" || c1 === "1005" || c2 === "1113" || c2 === "1005"
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
// spentSaid is an answer that carries spentUp's code inside a 200, as a
|
|
319
|
+
// spent bucket's can, said as the 429 it is (plugins#817: a Start Plan
|
|
320
|
+
// account's GLM-5.3 out for the day answered 200 "exceed quota limit",
|
|
321
|
+
// which magpie took for a reply that did not stream and rested the whole
|
|
322
|
+
// account, GLM-5.3-Flash's own bucket with it). Any other answer goes on
|
|
323
|
+
// as it came; a stream's body is never read here.
|
|
324
|
+
async function spentSaid(res) {
|
|
325
|
+
if (res.status >= 400 || !(res.headers.get("content-type") ?? "").includes("application/json")) return res
|
|
326
|
+
const text = await res.text()
|
|
327
|
+
const status = spentUp(text, res.status) ? 429 : res.status
|
|
328
|
+
return new Response(text, { status, statusText: status === 429 ? "Too Many Requests" : res.statusText, headers: res.headers })
|
|
329
|
+
}
|
|
330
|
+
|
|
318
331
|
// ---- keys ------------------------------------------------------------------------
|
|
319
332
|
|
|
320
333
|
function teamHeaders(base, org, project) {
|
|
@@ -2708,7 +2721,7 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
|
|
|
2708
2721
|
if (EDGE_PAGE.test(text)) edge.until = Date.now() + EDGE_HOLD
|
|
2709
2722
|
if (freeGift) {
|
|
2710
2723
|
restModel(false)
|
|
2711
|
-
return done(kept(await replayOnPlan()))
|
|
2724
|
+
return done(kept(await spentSaid(await replayOnPlan())))
|
|
2712
2725
|
}
|
|
2713
2726
|
if (s.key && !forcedGift) routes.delete(s.key + "\0" + s.jwt)
|
|
2714
2727
|
return kept(startBlocked(res, text))
|
|
@@ -2756,18 +2769,20 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
|
|
|
2756
2769
|
const spent = !cap && spentUp(text, res.status)
|
|
2757
2770
|
if (spent) {
|
|
2758
2771
|
restModel(true)
|
|
2759
|
-
return done(kept(await replayOnPlan()))
|
|
2772
|
+
return done(kept(await spentSaid(await replayOnPlan())))
|
|
2760
2773
|
}
|
|
2761
2774
|
if (res.status >= 400) {
|
|
2762
2775
|
if (!cap && (res.status === 401 || res.status === 403)) routes.delete(s.key + "\0" + s.jwt)
|
|
2763
|
-
return done(kept(await replayOnPlan()))
|
|
2776
|
+
return done(kept(await spentSaid(await replayOnPlan())))
|
|
2764
2777
|
}
|
|
2765
2778
|
return done(kept(res, text))
|
|
2766
2779
|
}
|
|
2767
2780
|
}
|
|
2768
2781
|
// the plan's answer goes on as it came, the account kept: the
|
|
2769
|
-
// built-in never marked a ZCode account lapsed nor cleared one
|
|
2770
|
-
|
|
2782
|
+
// built-in never marked a ZCode account lapsed nor cleared one.
|
|
2783
|
+
// A spent bucket's 200 says 429 (spentSaid), as a trial
|
|
2784
|
+
// entry's does, so magpie rests the model, not the account
|
|
2785
|
+
return done(kept(await spentSaid(res)))
|
|
2771
2786
|
},
|
|
2772
2787
|
}
|
|
2773
2788
|
},
|
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.53",
|
|
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",
|