@magpie-community/opencode-zcode-auth 0.1.21 → 0.1.22
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 +43 -22
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -29,7 +29,7 @@ const BIGMODEL_API = "https://bigmodel.cn" // BigModel's business API, where ZCo
|
|
|
29
29
|
const ZAI_BASE = "https://api.z.ai/api/anthropic"
|
|
30
30
|
const BIGMODEL_BASE = "https://open.bigmodel.cn/api/anthropic"
|
|
31
31
|
const START_BASE = ZCODE + "/api/v1/zcode-plan/anthropic"
|
|
32
|
-
const APP_VERSION = "3.
|
|
32
|
+
const APP_VERSION = "3.16.3" // the ZCode whose sign-in this makes
|
|
33
33
|
const UA = "ZCode/" + APP_VERSION
|
|
34
34
|
|
|
35
35
|
// ZCode's models before its config is read; the Start Plan has all but GLM-5.3.
|
|
@@ -1400,28 +1400,48 @@ function intl() {
|
|
|
1400
1400
|
}
|
|
1401
1401
|
}
|
|
1402
1402
|
|
|
1403
|
-
// startHeaders
|
|
1403
|
+
// startHeaders is a Start Plan request's headers, jwt its key: ZCode's
|
|
1404
|
+
// own (3.16.3's Frn and Vdt in glm/zcode.cjs) and the body's content-type,
|
|
1405
|
+
// and nothing else. The agent's headers never go on: Claude Code's
|
|
1406
|
+
// anthropic-beta, x-app, x-stainless-*, anthropic-dangerous-direct-browser-
|
|
1407
|
+
// access and x-claude-code-session-id reach the plugin through magpie's
|
|
1408
|
+
// gateway, and ZCode sends none of them (no anthropic-beta at all on the
|
|
1409
|
+
// Start Plan: its tool search beta is for coding plans only). Accept and
|
|
1410
|
+
// accept-encoding are left to the HTTP client, as ZCode leaves them to
|
|
1411
|
+
// Node's.
|
|
1404
1412
|
function startHeaders(h, jwt) {
|
|
1405
|
-
|
|
1406
|
-
h.
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
h.set("X-Release-Channel", "production")
|
|
1413
|
+
const out = new Headers()
|
|
1414
|
+
out.set("content-type", h.get("content-type") || "application/json")
|
|
1415
|
+
out.set("Authorization", "Bearer " + jwt)
|
|
1416
|
+
out.set("anthropic-version", "2023-06-01")
|
|
1417
|
+
out.set("HTTP-Referer", ZCODE)
|
|
1418
|
+
out.set("User-Agent", UA + " ai-sdk/anthropic/3.0.81")
|
|
1419
|
+
out.set("X-ZCode-App-Version", APP_VERSION)
|
|
1420
|
+
out.set("X-Title", "Z Code@cli")
|
|
1421
|
+
out.set("X-Release-Channel", "production")
|
|
1415
1422
|
const o = intl()
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1423
|
+
out.set("X-Client-Language", o.locale || "unknown")
|
|
1424
|
+
out.set("X-Client-Timezone", o.timeZone || "unknown")
|
|
1425
|
+
out.set("X-ZCode-Agent", "glm")
|
|
1426
|
+
out.set("X-Platform", platform())
|
|
1427
|
+
out.set("X-Os-Category", osCategory())
|
|
1428
|
+
// os.release() alone, as ZCode's buildZCodeSourceHeadersFromContext
|
|
1429
|
+
// has it; the prompt's OS line is osVersion()
|
|
1430
|
+
out.set("X-Os-Version", release())
|
|
1431
|
+
out.set("x-request-id", uuid())
|
|
1432
|
+
out.set("x-zcode-session-type", "main")
|
|
1433
|
+
out.set("x-zcode-trace-id", uuid())
|
|
1434
|
+
// 3.16's createModelRequestAttributionHeaders: what asked the model
|
|
1435
|
+
out.set("x-zcode-query-source", "main_turn")
|
|
1436
|
+
return out
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
// startURL is a Start Plan request's URL without the query the agent put
|
|
1440
|
+
// on it: Claude Code asks /v1/messages?beta=true, which magpie passes on,
|
|
1441
|
+
// and ZCode asks /v1/messages alone.
|
|
1442
|
+
function startURL(url) {
|
|
1443
|
+
const i = url.indexOf("?")
|
|
1444
|
+
return i < 0 ? url : url.slice(0, i)
|
|
1425
1445
|
}
|
|
1426
1446
|
|
|
1427
1447
|
// WORK_DIR and WORK_GIT are where magpie tells a plugin's fetch the agent
|
|
@@ -1660,7 +1680,8 @@ export async function ZCodeAuthPlugin({ client }) {
|
|
|
1660
1680
|
if (!s.jwt) throw new Error("ZCode's sign-in has no key; sign in again")
|
|
1661
1681
|
swap(START_BASE)
|
|
1662
1682
|
// the Start Plan is served only to what looks like ZCode's own request
|
|
1663
|
-
|
|
1683
|
+
url = startURL(url)
|
|
1684
|
+
h = startHeaders(h, s.jwt)
|
|
1664
1685
|
if (opts.body != null) {
|
|
1665
1686
|
const text = orig ?? (typeof opts.body === "string" ? opts.body : await new Response(opts.body).text())
|
|
1666
1687
|
opts.body = dress(text, s.site, s.device, place)
|
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.22",
|
|
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",
|