@magpie-community/opencode-zcode-auth 0.1.17 → 0.1.18
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 +24 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1026,6 +1026,27 @@ function ownTeam(store, key) {
|
|
|
1026
1026
|
return null
|
|
1027
1027
|
}
|
|
1028
1028
|
|
|
1029
|
+
// configKey is the coding plan key ZCode's config.json gives its built-in
|
|
1030
|
+
// coding plan provider, Z.ai's first, as ZCode lists them; ZCode reads it
|
|
1031
|
+
// as it is, and one written encrypted is read too.
|
|
1032
|
+
function configKey(key) {
|
|
1033
|
+
const providers = readJSON(join(zcodeDir(), "config.json"))?.provider
|
|
1034
|
+
if (!providers || typeof providers !== "object") return null
|
|
1035
|
+
for (const [ids, base] of [
|
|
1036
|
+
[["builtin:zai-coding-plan", "account:zai-individual-coding-plan"], ZAI_BASE],
|
|
1037
|
+
[["builtin:bigmodel-coding-plan", "account:bigmodel-individual-coding-plan"], BIGMODEL_BASE],
|
|
1038
|
+
]) {
|
|
1039
|
+
for (const id of ids) {
|
|
1040
|
+
let k = providers[id]?.options?.apiKey
|
|
1041
|
+
if (typeof k !== "string") continue
|
|
1042
|
+
k = k.trim()
|
|
1043
|
+
if (k.startsWith("enc:")) k = first(decrypt(key, k))
|
|
1044
|
+
if (k.includes(".") && !/[\s{$]/.test(k)) return { key: k, base }
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return null
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1029
1050
|
// ownSignIn is what ZCode is signed in to now: the account, its coding
|
|
1030
1051
|
// plan key, ZCode's session token (the Start Plan's key) and the team plan
|
|
1031
1052
|
// it is switched to; null when it has none of them.
|
|
@@ -1043,6 +1064,9 @@ function ownSignIn() {
|
|
|
1043
1064
|
// Z.ai's first, as ZCode lists it
|
|
1044
1065
|
if (!s.key || (base === ZAI_BASE && s.base !== ZAI_BASE)) s = { key: k, base }
|
|
1045
1066
|
}
|
|
1067
|
+
// ZCode 3.15 keeps no plan key in its credentials; the one it uses sits
|
|
1068
|
+
// in config.json, the provider's options.apiKey (yetone/magpie#2130)
|
|
1069
|
+
if (!s.key) s = configKey(key) || s
|
|
1046
1070
|
const jwt = first(first(decrypt(key, store.zcodejwttoken)).replace(/^Bearer /, ""))
|
|
1047
1071
|
const team = ownTeam(store, key)
|
|
1048
1072
|
if (team) s = { ...team, jwt }
|
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.18",
|
|
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",
|