fix(wechat): 便携包打包微信插件 + 修连接成功却报「插件未安装」的矛盾提示

根因:微信插件 @tencent-weixin/openclaw-weixin 是独立 npm 包,但 setup/CI
从没装过它,portable/app/ 又被 gitignore —— 发布包 app/extensions/ 是空的,
客户扫码连上后 config-server 找不到插件源,报「插件未安装」。

- release.yml: 装 @tencent-weixin/openclaw-weixin@latest 到 app/extensions/
  (npm 包自带 dist/index.js 无需 build;显式把 qrcode-terminal 放进插件
   node_modules 以满足 server.js:52 的硬要求)
- config-server/public/index.html: 去掉「连接成功」却又「插件未安装」的自相
  矛盾提示。后端已自动装插件+写好 openclaw.json+存账号,只需重启即可,
  不再暴露 pluginInstalled 内部状态吓客户,改为清晰的「重启 U-Claw 即可用」
- config-server/server.js: 插件 copy 失败时容错(不抛错中断 confirmed 流程)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hfshfg
2026-06-17 19:33:25 +08:00
parent 7b561009a5
commit 4fab64e877
3 changed files with 42 additions and 6 deletions

View File

@@ -110,6 +110,32 @@ jobs:
done
fi
# 6b) Install WeChat (Weixin) plugin into app/extensions/openclaw-weixin
# 官方 npm 包 @tencent-weixin/openclaw-weixin 自带 dist/index.js(发布时已编译,无需 build)。
# config-server/server.js 把 app/extensions/openclaw-weixin 当作插件源,扫码登录后整目录
# copy 到 ~/.openclaw/extensions/。它硬要求插件目录内 node_modules/qrcode-terminal 存在
# (server.js:52),而 npm 会把该依赖提升到顶层,故下面显式 copy 进插件的 node_modules。
wx_tmp="$(mktemp -d)"
(
cd "$wx_tmp"
echo '{"name":"wx-tmp","version":"1.0.0","private":true}' > package.json
npm install @tencent-weixin/openclaw-weixin@latest \
--registry="$mirror_npm" --no-audit --no-fund
)
wx_pkg="$wx_tmp/node_modules/@tencent-weixin/openclaw-weixin"
if [ -f "$wx_pkg/dist/index.js" ] && [ -f "$wx_pkg/openclaw.plugin.json" ]; then
wx_dest="$app_dir/extensions/openclaw-weixin"
mkdir -p "$wx_dest"
cp -R "$wx_pkg/." "$wx_dest/"
# 把 qrcode-terminal(被 npm 提升到顶层)放进插件自己的 node_modules
mkdir -p "$wx_dest/node_modules"
cp -R "$wx_tmp/node_modules/qrcode-terminal" "$wx_dest/node_modules/qrcode-terminal"
echo "WeChat plugin installed: $(du -sm "$wx_dest" | cut -f1) MB"
else
echo "WARN: WeChat plugin install failed, skipping (dist/index.js or openclaw.plugin.json missing)"
fi
rm -rf "$wx_tmp"
# 7) Belt-and-suspenders: even though we don't pre-install bundled
# deps, openclaw's own dependencies might still pull large native
# binaries. Prune known offenders just in case.

View File

@@ -628,10 +628,14 @@ async function pollWeChatStatus() {
if (data.status === 'confirmed') {
wechatPolling = false;
qrDiv.innerHTML = '<div style="font-size:3em;">&#10004;</div>';
statusDiv.innerHTML = '<span style="color:#4caf50;font-weight:600;">微信连接成功!</span><br><span style="font-size:0.8em;">账号: ' +
(data.accountId || '') + (data.pluginInstalled ? '' : '<br>⚠️ 插件未安装,请重启 Gateway') + '<br>需重启 Gateway 生效</span>';
// 后端已自动装好插件 + 写好 openclaw.json + 存好账号,剩下只需重启 Gateway 加载插件。
// 不再暴露 pluginInstalled 内部状态——它即使为 false配置也已写好下次启动必加载
// 显示「插件未安装」只会和「连接成功」自相矛盾、吓到客户。
statusDiv.innerHTML = '<span style="color:#4caf50;font-weight:600;">✅ 微信连接成功!</span>' +
'<br><span style="font-size:0.8em;color:#888;">账号 ' + (data.accountId || '') + ' 已绑定</span>' +
'<br><span style="font-size:0.85em;color:#ff9800;font-weight:600;">最后一步:重启 U-Claw关闭后重新打开即可在微信里使用</span>';
statusDiv.style.color = '#4caf50';
showToast('微信连接成功!');
showToast('微信连接成功!重启 U-Claw 后生效');
return;
}

View File

@@ -197,9 +197,15 @@ function ensureWeChatPluginInstalled() {
return { installed: true };
}
// Copy from USB to ~/.openclaw/extensions/
// 容错copy 失败不抛错中断整个 confirmed 流程(账号保存 + openclaw.json 已/将写好)。
try {
const extDir = path.join(OPENCLAW_DIR, 'extensions');
fs.mkdirSync(extDir, { recursive: true });
copyDirSync(USB_PLUGIN_DIR, INSTALLED_PLUGIN_DIR);
} catch (e) {
console.error('WeChat plugin copy failed:', e.message);
return { installed: false, warning: e.message };
}
return { installed: fs.existsSync(path.join(INSTALLED_PLUGIN_DIR, 'openclaw.plugin.json')) };
}