@wps365/openclaw-wpsxiezuo 1.6.2 → 1.6.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 +50 -18
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -47,8 +47,7 @@ function env(name) {
47
47
  const CHANNEL_ID = "wps-xiezuo";
48
48
  const LEGACY_CHANNEL_IDS = ["wps", "openclaw-wps-xiezuo"];
49
49
  const ALL_IDS = [CHANNEL_ID, ...LEGACY_CHANNEL_IDS];
50
- // uninstall 只对真实 plugin id 生效(openclaw-wps-xiezuo 是 npm 包名,不是 plugin id)
51
- const UNINSTALL_IDS = [CHANNEL_ID, "wps"];
50
+ const UNINSTALL_IDS = [CHANNEL_ID];
52
51
  const DEFAULT_BASE_URL = "https://openapi.wps.cn";
53
52
  const DEFAULT_AGENT_ID = "digital-assistant";
54
53
  const OPENCLAW_HOME = path.join(os.homedir(), ".openclaw");
@@ -444,30 +443,63 @@ function writeChannelConfig({ appId, appSecret, baseUrl }) {
444
443
  log.info(`已写入 channels.${CHANNEL_ID} + plugins.allow + bindings`);
445
444
  }
446
445
 
447
- function verifyInstall({ requirePluginRegistered = true } = {}) {
446
+ async function verifyInstall({ requirePluginRegistered = true } = {}) {
448
447
  const cfg = readJsonSafe(OPENCLAW_JSON);
449
448
  if (!cfg?.channels?.[CHANNEL_ID]?.enabled) {
450
449
  log.error(`安装验证失败:channels.${CHANNEL_ID} 未写入或未启用`);
451
450
  process.exit(1);
452
451
  }
453
452
 
454
- // 仅在要求插件已注册时,再跑一次 `openclaw plugins list` 兜底验证。
455
- // 说明:不同 OpenClaw 版本的 list 输出格式不尽相同,我们只做"是否出现 channel id"
456
- // 级别的宽松匹配,避免在少见输出上误报。
457
453
  if (!requirePluginRegistered) return;
458
454
 
459
- const list = runOpenclaw(["plugins", "list"], { capture: true });
460
- if (list.status !== 0) {
461
- log.warn(`openclaw plugins list 执行失败(exit=${list.status}),跳过运行时验证`);
462
- return;
463
- }
464
- const output = `${list.stdout}\n${list.stderr}`;
465
- if (!output.includes(CHANNEL_ID)) {
466
- log.error(`安装验证失败:openclaw plugins list 输出未包含 "${CHANNEL_ID}"`);
467
- log.error("这通常表示插件虽被 `plugins install` 接受,但未被网关识别。");
468
- log.error("请手动执行 `openclaw plugins list` 排查,或升级 OpenClaw 后重试。");
469
- process.exit(1);
455
+ // 兼容不同 OpenClaw 版本的输出格式:可能显示 channel id、npm 包名或其片段
456
+ const knownIds = [CHANNEL_ID, "openclaw-wpsxiezuo", "@wps365/openclaw-wpsxiezuo"];
457
+ const RETRIES = 3;
458
+ const INTERVAL_MS = 5000;
459
+
460
+ console.log(`
461
+ ${c.green}${c.bold}✅ 插件安装已完成,正在自动校验注册结果...${c.reset}
462
+
463
+ ${c.cyan}提示:${c.reset}如果不想等待自动校验,可 ${c.bold}Ctrl+C${c.reset} 中止,然后手动执行以下命令确认:
464
+ ${c.cyan}openclaw plugins list${c.reset} 查看已注册插件列表
465
+ ${c.cyan}openclaw gateway restart${c.reset} 重启网关加载插件
466
+ `);
467
+
468
+ for (let attempt = 1; attempt <= RETRIES; attempt++) {
469
+ if (attempt > 1) {
470
+ const secs = INTERVAL_MS / 1000;
471
+ for (let remaining = secs; remaining > 0; remaining--) {
472
+ process.stdout.write(`\r${c.cyan}[INFO]${c.reset} 等待重试(第 ${attempt}/${RETRIES} 次):${remaining}s ... `);
473
+ await new Promise((r) => setTimeout(r, 1000));
474
+ }
475
+ process.stdout.write("\r" + " ".repeat(60) + "\r"); // 清除倒计时行
476
+ }
477
+
478
+ const list = runOpenclaw(["plugins", "list"], { capture: true });
479
+ if (list.status !== 0) {
480
+ log.warn(`openclaw plugins list 执行失败(exit=${list.status},第 ${attempt}/${RETRIES} 次)`);
481
+ continue;
482
+ }
483
+
484
+ // 按行过滤(grep 语义),兼容 Windows / macOS / Linux。
485
+ // 不依赖系统 grep / findstr,用 Node.js 正则逐行匹配,跨平台一致。
486
+ const allLines = `${list.stdout}\n${list.stderr}`.split(/\r?\n/);
487
+ const pattern = new RegExp(knownIds.map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), "i");
488
+ const matchedLines = allLines.filter((line) => pattern.test(line));
489
+
490
+ if (matchedLines.length > 0) {
491
+ log.info("插件已在 openclaw plugins list 中确认注册:");
492
+ matchedLines.forEach((line) => log.info(` ${line.trim()}`));
493
+ return;
494
+ }
495
+
496
+ log.info(`第 ${attempt}/${RETRIES} 次未在 plugins list 中找到插件,稍后重试...`);
470
497
  }
498
+
499
+ // 三次均未匹配,降级为警告(install 和 config 写入均已成功,可能是输出格式差异)
500
+ log.warn(`重试 ${RETRIES} 次后,openclaw plugins list 仍未包含已知标识(${knownIds.join(" / ")})`);
501
+ log.warn("插件注册命令已成功执行,此警告可能是 OpenClaw 版本的输出格式差异导致。");
502
+ log.warn(`请重启网关后手动确认:openclaw gateway restart && openclaw plugins list`);
471
503
  }
472
504
 
473
505
  // ── install 子命令 ──────────────────────────────────────────────────────────
@@ -552,7 +584,7 @@ async function cmdInstall(flags) {
552
584
  runOpenclaw(["doctor", "--fix"], { silent: true });
553
585
 
554
586
  log.step("验证安装");
555
- verifyInstall({ requirePluginRegistered: reg.ok });
587
+ await verifyInstall({ requirePluginRegistered: reg.ok });
556
588
 
557
589
  const successNote = reg.ok
558
590
  ? `${c.green}${c.bold}✅ @wps365/openclaw-wpsxiezuo 安装成功${c.reset}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wps365/openclaw-wpsxiezuo",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "WPS Xiezuo OpenClaw plugin - connect OpenClaw Agent to the WPS Open Platform enterprise robot",
5
5
  "keywords": [
6
6
  "openclaw",