galaxy-opc 0.3.2 → 0.3.4

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/bin/cli.mjs +37 -18
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -128,8 +128,6 @@ const HOME = os.homedir();
128
128
  const STATE_DIR = path.join(HOME, ".openclaw");
129
129
  const CONFIG_PATH = path.join(STATE_DIR, "openclaw.json");
130
130
  const ENV_PATH = path.join(STATE_DIR, ".env");
131
- // 插件由 openclaw plugins install 写入 ~/.openclaw/extensions/galaxy-opc-plugin
132
- const PLUGIN_INSTALL_DIR = path.join(STATE_DIR, "extensions", "galaxy-opc-plugin");
133
131
 
134
132
  // ─── 命令路由 ───────────────────────────────────────────────────────────────
135
133
  const args = process.argv.slice(2);
@@ -208,8 +206,9 @@ ${bold(cyan(" ╚════════════════════
208
206
  console.log(bold(" 步骤 3 / 4 安装 OPC Platform 插件"));
209
207
  separator();
210
208
 
211
- if (fs.existsSync(PLUGIN_INSTALL_DIR)) {
212
- console.log(yellow(` 检测到插件已存在: ${PLUGIN_INSTALL_DIR}`));
209
+ const pluginInstallDir = path.join(STATE_DIR, "extensions", "galaxy-opc-plugin");
210
+ if (fs.existsSync(pluginInstallDir)) {
211
+ console.log(yellow(` 检测到插件已存在: ${pluginInstallDir}`));
213
212
  const update = await askYesNo(" 更新到最新版本?", true);
214
213
  if (!update) {
215
214
  console.log(green(" ✓ 跳过,使用现有版本"));
@@ -225,6 +224,25 @@ ${bold(cyan(" ╚════════════════════
225
224
  }
226
225
 
227
226
  async function installPlugin() {
227
+ // 清理可能残留的旧插件路径配置,否则 openclaw 会因路径不存在而拒绝启动
228
+ const cfg = readJson(CONFIG_PATH);
229
+ let dirty = false;
230
+ if (cfg.plugins?.load?.paths?.length) {
231
+ delete cfg.plugins.load.paths;
232
+ dirty = true;
233
+ }
234
+ if (cfg.plugins?.load && Object.keys(cfg.plugins.load).length === 0) {
235
+ delete cfg.plugins.load;
236
+ }
237
+ if (cfg.plugins?.entries?.["opc-platform"]) {
238
+ delete cfg.plugins.entries["opc-platform"];
239
+ dirty = true;
240
+ }
241
+ if (dirty) {
242
+ writeJson(CONFIG_PATH, cfg);
243
+ console.log(dim(" 已清理旧插件配置"));
244
+ }
245
+
228
246
  console.log(dim(" 正在通过 OpenClaw 安装插件...\n"));
229
247
  try {
230
248
  await runCommand("openclaw", ["plugins", "install", "galaxy-opc-plugin"]);
@@ -246,19 +264,14 @@ async function cmdSetup() {
246
264
  let newConfig = readJson(CONFIG_PATH);
247
265
  let newEnv = readEnv(ENV_PATH);
248
266
 
249
- // 注册插件路径(plugins.load.paths 是 openclaw 识别的正确 key)
250
- const existingPaths = newConfig.plugins?.load?.paths ?? [];
251
- const mergedPaths = Array.from(new Set([...existingPaths, PLUGIN_INSTALL_DIR]));
267
+ // gateway.mode 必须设置否则无法启动
252
268
  newConfig = deepMerge(newConfig, {
253
269
  gateway: { mode: "local" },
254
- plugins: { load: { paths: mergedPaths } },
255
270
  });
256
271
 
257
- // 清理可能残留的错误 entries key(openclaw plugins install 会写入 galaxy-opc-plugin,
258
- // 但旧版本或手动配置可能留下 opc-platform key 导致 id mismatch 警告)
259
- if (newConfig.plugins?.entries?.["opc-platform"]) {
260
- delete newConfig.plugins.entries["opc-platform"];
261
- }
272
+ // 清理残留的旧插件路径(由旧版向导写入,openclaw 会因路径不存在报错)
273
+ if (newConfig.plugins?.load?.paths) delete newConfig.plugins.load.paths;
274
+ if (newConfig.plugins?.entries?.["opc-platform"]) delete newConfig.plugins.entries["opc-platform"];
262
275
 
263
276
  const regionIdx = await askChoice("选择 AI 模型地区", [
264
277
  { label: "国产模型", desc: "通义千问 / MiniMax / 豆包 / Kimi / DeepSeek", recommended: true },
@@ -360,9 +373,15 @@ async function cmdSetup() {
360
373
  console.log(yellow(`\n 已跳过,稍后手动编辑: ${gray(CONFIG_PATH)}`));
361
374
  }
362
375
 
363
- // Gateway Token
364
- if (!newEnv["OPENCLAW_GATEWAY_TOKEN"] || newEnv["OPENCLAW_GATEWAY_TOKEN"] === "change-me-to-a-long-random-token") {
365
- newEnv["OPENCLAW_GATEWAY_TOKEN"] = crypto.randomBytes(32).toString("hex");
376
+ // Gateway Token — 写入 openclaw.json(openclaw 从这里读取鉴权 token)
377
+ const existingToken = newConfig.gateway?.auth?.token;
378
+ const gatewayToken = (existingToken && existingToken !== "change-me-to-a-long-random-token")
379
+ ? existingToken
380
+ : crypto.randomBytes(16).toString("hex");
381
+ newConfig = deepMerge(newConfig, {
382
+ gateway: { auth: { mode: "token", token: gatewayToken } },
383
+ });
384
+ if (!existingToken || existingToken === "change-me-to-a-long-random-token") {
366
385
  console.log(green("\n ✓ 已自动生成 Gateway 访问令牌"));
367
386
  }
368
387
 
@@ -377,8 +396,8 @@ async function cmdSetup() {
377
396
  启动命令:
378
397
  ${cyan("openclaw gateway")}
379
398
 
380
- 管理后台:
381
- ${cyan("http://localhost:18789/opc/admin")}
399
+ 管理后台(需带 token):
400
+ ${cyan(`http://localhost:18789/opc/admin?token=${gatewayToken}`)}
382
401
 
383
402
  后台驻守(开机自启):
384
403
  ${cyan("openclaw onboard --install-daemon")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "galaxy-opc",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "星环 Galaxy OPC — 一人公司孵化与赋能平台 AI 员工系统",
5
5
  "keywords": [
6
6
  "ai",