@magpie-community/opencode-zcode-auth 0.1.56 → 0.1.57
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 +19 -3
- package/opencode2.mjs +0 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2158,6 +2158,15 @@ function busyCap() {
|
|
|
2158
2158
|
}
|
|
2159
2159
|
}
|
|
2160
2160
|
|
|
2161
|
+
// BUSY_HOLD_MARK marks an answer the hold made up: a request the gate or the
|
|
2162
|
+
// hold stopped locally never reached ZCode, and it says nothing about the
|
|
2163
|
+
// gift's quota. The gift paths (a -Trial pick, free first) read the mark
|
|
2164
|
+
// before they judge the answer spent, so a hold's 429 passes through as the
|
|
2165
|
+
// rate limit it is and arms no minute's rest (11-08: the hold's answer
|
|
2166
|
+
// through a -Trial entry read as "over its quota" with half the free quota
|
|
2167
|
+
// left).
|
|
2168
|
+
const BUSY_HOLD_MARK = "x-magpie-busy-hold"
|
|
2169
|
+
|
|
2161
2170
|
function busyHeldAnswer() {
|
|
2162
2171
|
const wait = Math.max(1, Math.ceil((busyHold.until - busyHold.now()) / 1000))
|
|
2163
2172
|
const error = {
|
|
@@ -2165,7 +2174,8 @@ function busyHeldAnswer() {
|
|
|
2165
2174
|
message: `ZCode turned away ${BUSY_N} requests in the last minute as too many requests at once, each again when asked a second later. So that ZCode's firewall does not block this network, magpie sends no free Start Plan requests for the next ${wait}s. Wait, run fewer agents or subagents on ZCode at once, or use a GLM Coding Plan model`,
|
|
2166
2175
|
}
|
|
2167
2176
|
return new Response(JSON.stringify({ type: "error", error }), {
|
|
2168
|
-
status: 429, statusText: STATUS_TEXT[429],
|
|
2177
|
+
status: 429, statusText: STATUS_TEXT[429],
|
|
2178
|
+
headers: { "content-type": "application/json", "retry-after": String(wait), [BUSY_HOLD_MARK]: "1" },
|
|
2169
2179
|
})
|
|
2170
2180
|
}
|
|
2171
2181
|
|
|
@@ -3067,7 +3077,11 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
|
|
|
3067
3077
|
const json = (res.headers.get("content-type") ?? "").includes("application/json")
|
|
3068
3078
|
if (res.status >= 400 || json) {
|
|
3069
3079
|
const text = await res.text()
|
|
3070
|
-
|
|
3080
|
+
// the hold's own answer (BUSY_HOLD_MARK) is a rate limit the
|
|
3081
|
+
// gift never said: it passes through as it came and arms
|
|
3082
|
+
// no rest
|
|
3083
|
+
const held = res.headers.get(BUSY_HOLD_MARK) === "1"
|
|
3084
|
+
const spent = !held && spentUp(text, res.status)
|
|
3071
3085
|
if (!spent && res.status < 400) return done(kept(res, text))
|
|
3072
3086
|
if (spent) rest(blocked, s.key + "\0" + s.jwt + "\0" + modelOf(orig).toLowerCase())
|
|
3073
3087
|
return spent && res.status < 400 ? kept(new Response(text, { status: 429, headers: res.headers })) : done(kept(res, text))
|
|
@@ -3087,7 +3101,9 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
|
|
|
3087
3101
|
if (res.status >= 400 || json) {
|
|
3088
3102
|
const text = await res.text()
|
|
3089
3103
|
const cap = busy(res.status, text)
|
|
3090
|
-
|
|
3104
|
+
// the hold's own answer is no spent answer either (see the
|
|
3105
|
+
// -Trial path above)
|
|
3106
|
+
const spent = !cap && res.headers.get(BUSY_HOLD_MARK) !== "1" && spentUp(text, res.status)
|
|
3091
3107
|
if (spent) {
|
|
3092
3108
|
restModel(true)
|
|
3093
3109
|
return done(kept(await spentSaid(await replayOnPlan())))
|
package/opencode2.mjs
CHANGED
|
@@ -85,7 +85,6 @@ export function fieldsOf(prompts) {
|
|
|
85
85
|
if (p.placeholder) f.placeholder = String(p.placeholder)
|
|
86
86
|
if (p.type === "select" && Array.isArray(p.options))
|
|
87
87
|
f.options = p.options.map((o) => ({ value: String(o.value), label: String(o.label ?? o.value), ...(o.hint ? { description: String(o.hint) } : {}) }))
|
|
88
|
-
// a prompt shown only when another answer says so can't be required
|
|
89
88
|
// a prompt shown only when another answer says so can't be required, and
|
|
90
89
|
// neither can one whose own validate() accepts an empty answer (the
|
|
91
90
|
// browser sign-in's optional API key)
|
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.57",
|
|
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",
|