@magpie-community/opencode-zcode-auth 0.1.16 → 0.1.17

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.
Files changed (2) hide show
  1. package/index.mjs +24 -4
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -19,7 +19,7 @@
19
19
  import { createDecipheriv, createHash } from "node:crypto"
20
20
  import { existsSync, readFileSync, readdirSync } from "node:fs"
21
21
  import { arch, homedir, release, userInfo } from "node:os"
22
- import { join } from "node:path"
22
+ import { isAbsolute, join } from "node:path"
23
23
  import PROMPT from "./prompt.mjs"
24
24
 
25
25
  const PROVIDER = "zcode"
@@ -933,8 +933,28 @@ async function authorize(site, log) {
933
933
  // team's plan. An account signed in "as ZCode" reads them for every
934
934
  // request, so it follows ZCode's own sign-in, its renewed session and its
935
935
  // switches between plans, as magpie's built-in did (zcode.go zcodeOwn).
936
+ //
937
+ // ZCode 3.14 can move its data (数据存储路径, "data storage path"): it copies
938
+ // ~/.zcode/v2 to <folder>/.zcode/v2, all but setting.json, and from its next
939
+ // start reads credentials.json and runtime/provider from there. The choice
940
+ // stays in the home folder's setting.json as dataBaseDir, which ZCode's main
941
+ // process reads before anything else (readBootstrapDataBaseDirFromDisk);
942
+ // setting.json itself, and the team plan it names, stay in the home folder.
943
+
944
+ // settingDir is where ZCode keeps setting.json, moved or not.
945
+ const settingDir = () => join(homedir(), ".zcode", "v2")
946
+
947
+ // dataIn is the folder ZCode keeps its .zcode data in: the home folder,
948
+ // unless dataBaseDir moved it. A value that isn't an absolute path is
949
+ // ignored, as magpie's built-in does (internal/appdir ZCodeDataIn).
950
+ function dataIn() {
951
+ const d = readJSON(join(settingDir(), "setting.json"))?.dataBaseDir
952
+ const t = typeof d === "string" ? d.trim() : ""
953
+ return t && isAbsolute(t) ? t : homedir()
954
+ }
936
955
 
937
- const zcodeDir = () => join(homedir(), ".zcode", "v2")
956
+ // zcodeDir is where ZCode keeps credentials.json and runtime/provider.
957
+ const zcodeDir = () => join(dataIn(), ".zcode", "v2")
938
958
 
939
959
  // secret is the key ZCode encrypts its credentials with.
940
960
  function secret() {
@@ -974,7 +994,7 @@ function readJSON(path) {
974
994
 
975
995
  // ownTeam is the team plan ZCode switched to, when it did.
976
996
  function ownTeam(store, key) {
977
- const set = readJSON(join(zcodeDir(), "setting.json"))
997
+ const set = readJSON(join(settingDir(), "setting.json"))
978
998
  if (!set) return null
979
999
  const families = set.providerFamilyDomain === "zai" || set.providerFamilyDomain === "bigmodel" ? [set.providerFamilyDomain] : ["zai", "bigmodel"]
980
1000
  for (const fam of families) {
@@ -1139,7 +1159,7 @@ function modelsOf(cfg, plan) {
1139
1159
  // localConfig is the latest provider config an installed ZCode has.
1140
1160
  function localConfig() {
1141
1161
  const files = []
1142
- const rt = join(homedir(), ".zcode", "v2", "runtime", "provider")
1162
+ const rt = join(zcodeDir(), "runtime", "provider")
1143
1163
  const walk = (dir, depth) => {
1144
1164
  let es = []
1145
1165
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-zcode-auth",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
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",