@magpie-community/opencode-zcode-auth 0.1.26 → 0.1.27
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 +8 -6
- package/index.mjs +33 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,12 +25,14 @@ over Anthropic's Messages API. Provider id: `zcode`.
|
|
|
25
25
|
agent's system prompt at the end of the third (a fourth block is
|
|
26
26
|
refused, #343), the day in a `<system-reminder>` turn before the agent's
|
|
27
27
|
turns, and the sign-in's device id in `metadata.user_id`. GLM Coding
|
|
28
|
-
Plan and team requests go as the agent sent them.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
group
|
|
28
|
+
Plan and team requests go as the agent sent them. zcode.z.ai also
|
|
29
|
+
answers 405 code 3012 to every request of an account its risk control
|
|
30
|
+
blocked, ZCode's own app's included (plugins#348). That answer comes
|
|
31
|
+
back as ZCode's words, then "ZCode's risk control blocked this account
|
|
32
|
+
for unusual activity (code 3012); …", which magpie reads as the account
|
|
33
|
+
restricted: it rests, and the group's other providers are used. Only
|
|
34
|
+
ZCode support lifts such a block. A block page from ZCode's edge
|
|
35
|
+
firewall says this network's address was blocked instead.
|
|
34
36
|
- The Start Plan's token can't be refreshed. When it runs out, sign in
|
|
35
37
|
again.
|
|
36
38
|
- **ZCode: a team's GLM Coding Plan**
|
package/index.mjs
CHANGED
|
@@ -1438,39 +1438,51 @@ function model(m, url) {
|
|
|
1438
1438
|
}
|
|
1439
1439
|
|
|
1440
1440
|
// ---- the Start Plan's requests ----------------------------------------------------
|
|
1441
|
-
// zcode.z.ai
|
|
1442
|
-
//
|
|
1443
|
-
//
|
|
1441
|
+
// zcode.z.ai answers 405 "request has been blocked due to unusual
|
|
1442
|
+
// activity" (code 3012) to a request that doesn't look like ZCode's own
|
|
1443
|
+
// (#343: the agent's system prompt as a fourth block), and to every
|
|
1444
|
+
// request of an account its risk control blocked, ZCode's own app's too
|
|
1445
|
+
// (plugins#348). A Start Plan request goes as the plugin
|
|
1444
1446
|
// the plan serves (ARNO's "Freeflow", provider zcode-start) sends it: its
|
|
1445
1447
|
// headers (startHeaders) and its body (dress). The texts are prompt.mjs.
|
|
1446
1448
|
|
|
1447
|
-
//
|
|
1448
|
-
//
|
|
1449
|
-
//
|
|
1450
|
-
//
|
|
1451
|
-
//
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
const
|
|
1455
|
-
|
|
1456
|
-
//
|
|
1457
|
-
//
|
|
1458
|
-
const
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1449
|
+
// START_RESTRICTED is what ZCode's 3012, "request has been blocked due to
|
|
1450
|
+
// unusual activity", means: ZCode's risk control blocked the account
|
|
1451
|
+
// (ZCode's support says so, and ZCode's own app gets the same 405 on such
|
|
1452
|
+
// an account, plugins#348), not that the request was sent wrong. Word for
|
|
1453
|
+
// word magpie's provider.ZCodeRestrictedHint: the gateway reads it as the
|
|
1454
|
+
// account restricted, rests it and asks the group's next member, and the
|
|
1455
|
+
// Routing page says it in the user's language.
|
|
1456
|
+
const START_RESTRICTED = "ZCode's risk control blocked this account for unusual activity (code 3012); it rests, and the group's other providers are used. If the ZCode app fails on this account too, only ZCode support can lift the block"
|
|
1457
|
+
// START_EDGE is what a block page from ZCode's edge firewall (Aliyun's)
|
|
1458
|
+
// means: this network's address, not the account. Word for word magpie's
|
|
1459
|
+
// provider.BlockedHint.
|
|
1460
|
+
const START_EDGE = "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy"
|
|
1461
|
+
const EDGE_PAGE = /errors\.aliyun\.com|<html/i
|
|
1462
|
+
const START_REFUSED = /unusual activity|request has been blocked|"code"\s*:\s*"?3012\b/i
|
|
1463
|
+
|
|
1464
|
+
// startRefused says a Start Plan answer is a refusal: a 405, a block page
|
|
1465
|
+
// or code 3012.
|
|
1466
|
+
const startRefused = (status, text) => status >= 400 && (status === 405 || START_REFUSED.test(text))
|
|
1467
|
+
|
|
1468
|
+
// startBlocked is the refusal's answer: what the vendor said (its status
|
|
1469
|
+
// for a block page), then what it means. A block page is the network's;
|
|
1470
|
+
// anything else, ZCode's JSON 3012 or a bare 405, the account's.
|
|
1462
1471
|
function startBlocked(res, text) {
|
|
1472
|
+
const page = EDGE_PAGE.test(text)
|
|
1463
1473
|
let said = ""
|
|
1464
|
-
if (!
|
|
1474
|
+
if (!page) {
|
|
1465
1475
|
try {
|
|
1466
1476
|
const v = JSON.parse(text)
|
|
1467
1477
|
said = first(v?.error?.message, typeof v?.error === "string" ? v.error : "", v?.message, v?.msg)
|
|
1478
|
+
const code = v?.code ?? v?.error?.code
|
|
1479
|
+
if (said && code != null && !String(said).includes(String(code))) said = `${said} (${res.status}, code ${code})`
|
|
1468
1480
|
} catch {}
|
|
1469
1481
|
}
|
|
1470
1482
|
said ||= `${res.status} ${STATUS_TEXT[res.status] ?? res.statusText}`.trim()
|
|
1471
1483
|
const h = new Headers(res.headers)
|
|
1472
1484
|
h.set("content-type", "application/json")
|
|
1473
|
-
const error = { type: "permission_error", message: `${said} — ${
|
|
1485
|
+
const error = { type: "permission_error", message: `${said} — ${page ? START_EDGE : START_RESTRICTED}` }
|
|
1474
1486
|
return new Response(JSON.stringify({ type: "error", error }), { status: res.status, statusText: res.statusText, headers: h })
|
|
1475
1487
|
}
|
|
1476
1488
|
|
|
@@ -1900,7 +1912,7 @@ export async function ZCodeAuthPlugin({ client }) {
|
|
|
1900
1912
|
}
|
|
1901
1913
|
let res = await fetch(url, { ...opts, headers: h })
|
|
1902
1914
|
// the Start Plan turning the request away says what to do about
|
|
1903
|
-
// it,
|
|
1915
|
+
// it: the account blocked, or the network
|
|
1904
1916
|
if (start && res.status >= 400) {
|
|
1905
1917
|
const text = await res.text()
|
|
1906
1918
|
if (startRefused(res.status, text)) return kept(startBlocked(res, text))
|
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.27",
|
|
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",
|