@manturhub/cli 0.9.10-dev.20260810.6 → 0.9.10-dev.20260810.7

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/lib/config.js +31 -31
  2. package/package.json +1 -1
package/lib/config.js CHANGED
@@ -1,84 +1,84 @@
1
- import { homedir } from "node:os";
2
- import { join } from "node:path";
1
+ import { homedir } from "node:os"
2
+ import { join } from "node:path"
3
3
  import {
4
4
  readFileSync,
5
5
  writeFileSync,
6
6
  mkdirSync,
7
7
  existsSync,
8
8
  chmodSync,
9
- } from "node:fs";
9
+ } from "node:fs"
10
10
 
11
11
  // Local config lives at ~/.manturhub/config.json (chmod 600). Env vars win over it.
12
- const DIR = join(homedir(), ".manturhub");
13
- const FILE = join(DIR, "config.json");
14
- const DEVELOPMENT_HTTP_ORIGIN = "http://gateway-dev.guiyi.cn";
15
- const PRODUCTION_ORIGIN = "https://hub.mantur.ai";
12
+ const DIR = join(homedir(), ".manturhub")
13
+ const FILE = join(DIR, "config.json")
14
+ const DEVELOPMENT_ORIGIN = "https://gateway-dev.guiyi.cn"
15
+ const PRODUCTION_ORIGIN = "https://hub.mantur.ai"
16
16
  const PACKAGE_VERSION = JSON.parse(
17
17
  readFileSync(new URL("../package.json", import.meta.url), "utf8")
18
- ).version;
18
+ ).version
19
19
 
20
20
  export function defaultBaseForVersion(version) {
21
- return /-dev(?:\.|$)/.test(String(version)) ? DEVELOPMENT_HTTP_ORIGIN : PRODUCTION_ORIGIN;
21
+ return /-dev(?:\.|$)/.test(String(version)) ? DEVELOPMENT_ORIGIN : PRODUCTION_ORIGIN
22
22
  }
23
23
 
24
24
  // dev 预发布包默认连接开发网关,稳定包默认连接生产网关。MANTURHUB_BASE
25
25
  // 仍可显式覆盖;历史配置中保存过的官方默认地址不应覆盖当前发布通道。
26
- const DEFAULT_BASE = defaultBaseForVersion(PACKAGE_VERSION);
26
+ const DEFAULT_BASE = defaultBaseForVersion(PACKAGE_VERSION)
27
27
  const KNOWN_DEFAULT_BASES = new Set([
28
- DEVELOPMENT_HTTP_ORIGIN,
28
+ DEVELOPMENT_ORIGIN,
29
29
  PRODUCTION_ORIGIN,
30
30
  "https://hub.mantur.cn",
31
31
  "https://manturhub.leisurecat.cloud",
32
32
  "https://api.ophub.com",
33
- ]);
33
+ ])
34
34
 
35
35
  export function isAllowedHttpUrl(url) {
36
36
  const loopback =
37
- url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
38
- return url.protocol === "http:" && (loopback || url.origin === DEVELOPMENT_HTTP_ORIGIN);
37
+ url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]"
38
+ return url.protocol === "http:" && loopback
39
39
  }
40
40
 
41
41
  export function loadConfig() {
42
42
  try {
43
- return JSON.parse(readFileSync(FILE, "utf8"));
43
+ return JSON.parse(readFileSync(FILE, "utf8"))
44
44
  } catch {
45
- return {};
45
+ return {}
46
46
  }
47
47
  }
48
48
 
49
49
  export function saveConfig(cfg) {
50
- if (!existsSync(DIR)) mkdirSync(DIR, { recursive: true });
51
- writeFileSync(FILE, JSON.stringify(cfg, null, 2), { mode: 0o600 });
50
+ if (!existsSync(DIR)) mkdirSync(DIR, { recursive: true })
51
+ writeFileSync(FILE, JSON.stringify(cfg, null, 2), { mode: 0o600 })
52
52
  try {
53
- chmodSync(FILE, 0o600);
53
+ chmodSync(FILE, 0o600)
54
54
  } catch {
55
55
  /* best-effort on platforms without chmod */
56
56
  }
57
57
  }
58
58
 
59
59
  export function getKey() {
60
- return process.env.MANTURHUB_KEY || loadConfig().key || null;
60
+ return process.env.MANTURHUB_KEY || loadConfig().key || null
61
61
  }
62
62
 
63
63
  function validateBaseUrl(value) {
64
- let url;
64
+ let url
65
65
  try {
66
- url = new URL(value);
66
+ url = new URL(value)
67
67
  } catch {
68
- throw new Error(`ManturHub 网关地址不合法: ${value}`);
68
+ throw new Error(`ManturHub 网关地址不合法: ${value}`)
69
69
  }
70
70
  if (url.protocol !== "https:" && !isAllowedHttpUrl(url)) {
71
71
  throw new Error(
72
- "MANTURHUB_BASE 必须使用 HTTPS(仅本机地址和 http://gateway-dev.guiyi.cn 可使用 HTTP)"
73
- );
72
+ "MANTURHUB_BASE 必须使用 HTTPS(仅本机地址可使用 HTTP)"
73
+ )
74
74
  }
75
- if (url.username || url.password) throw new Error("MANTURHUB_BASE 不得包含用户名或密码");
76
- return url.href.replace(/\/$/, "");
75
+ if (url.username || url.password) throw new Error("MANTURHUB_BASE 不得包含用户名或密码")
76
+ return url.href.replace(/\/$/, "")
77
77
  }
78
78
 
79
79
  export function getBaseUrl() {
80
- if (process.env.MANTURHUB_BASE) return validateBaseUrl(process.env.MANTURHUB_BASE);
81
- const storedBase = loadConfig().baseUrl?.replace(/\/$/, "");
82
- if (storedBase && !KNOWN_DEFAULT_BASES.has(storedBase)) return validateBaseUrl(storedBase);
83
- return DEFAULT_BASE;
80
+ if (process.env.MANTURHUB_BASE) return validateBaseUrl(process.env.MANTURHUB_BASE)
81
+ const storedBase = loadConfig().baseUrl?.replace(/\/$/, "")
82
+ if (storedBase && !KNOWN_DEFAULT_BASES.has(storedBase)) return validateBaseUrl(storedBase)
83
+ return DEFAULT_BASE
84
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manturhub/cli",
3
- "version": "0.9.10-dev.20260810.6",
3
+ "version": "0.9.10-dev.20260810.7",
4
4
  "description": "ManturHub 算子广场 CLI:通过 REST 发现和调用 AI 算子、浏览配方,并安装 Skill 与 Agent 套件",
5
5
  "type": "module",
6
6
  "bin": {