fix: 微信插件兼容性检测改为版本号判断,修复 SDK 文件路径误判

之前通过检查 dist/plugin-sdk/root-alias.cjs/channel-config-schema.js 文件是否存在来判断兼容性,
但 Windows 上 cli_path.parent().parent() 定位不到 npm 包目录,导致 OpenClaw 2026.3.24 也被误判为不兼容。
改为直接比较 OpenClaw 版本号 >= 2026.3.22。
This commit is contained in:
晴天
2026-03-26 05:39:19 +08:00
parent f3d7a478ae
commit 7490a66dc9

View File

@@ -1090,55 +1090,32 @@ pub async fn check_weixin_plugin_status() -> Result<Value, String> {
_ => false, _ => false,
}; };
// 兼容性检查:检测插件是否能在当前 OpenClaw 版本下正常加载 // 兼容性检查:微信插件要求 OpenClaw >= 2026.3.22,通过版本号判断
let mut compatible = true; let mut compatible = true;
let mut compat_error = String::new(); let mut compat_error = String::new();
if installed { if installed {
// 检查插件引用的 SDK 模块是否存在channel-config-schema 是 2026.3.14+ 新增的) let oc_ver = crate::utils::resolve_openclaw_cli_path()
if let Some(cli_path) = crate::utils::resolve_openclaw_cli_path() { .and_then(|_| {
let cli_dir = std::path::Path::new(&cli_path) let out = crate::utils::openclaw_command()
.parent() .arg("--version")
.and_then(|p| p.parent()) .output()
.unwrap_or(std::path::Path::new("")); .ok()?;
let sdk_path = cli_dir let raw = String::from_utf8_lossy(&out.stdout).trim().to_string();
.join("dist") raw.split_whitespace()
.join("plugin-sdk") .find(|w| w.chars().next().map_or(false, |c| c.is_ascii_digit()))
.join("root-alias.cjs") .map(String::from)
.join("channel-config-schema.js"); })
if !sdk_path.exists() { .unwrap_or_default();
// 也检查 npm 全局路径 let oc_nums: Vec<u32> = oc_ver
let npm_sdk_exists = { .split(|c: char| !c.is_ascii_digit())
#[cfg(target_os = "windows")] .filter_map(|s| s.parse().ok())
{ .collect();
std::env::var("APPDATA") if oc_nums < vec![2026, 3, 22] {
.ok() compatible = false;
.map(|appdata| { compat_error = format!(
let base = std::path::PathBuf::from(appdata) "插件版本与当前 OpenClaw {} 不兼容(要求 >= 2026.3.22),请先升级 OpenClaw 或在终端执行: npx -y @tencent-weixin/openclaw-weixin-cli@latest install",
.join("npm") oc_ver
.join("node_modules"); );
["openclaw", "@qingchencloud/openclaw-zh"]
.iter()
.any(|pkg| {
base.join(pkg)
.join("dist")
.join("plugin-sdk")
.join("root-alias.cjs")
.join("channel-config-schema.js")
.exists()
})
})
.unwrap_or(false)
}
#[cfg(not(target_os = "windows"))]
{
false
}
};
if !npm_sdk_exists {
compatible = false;
compat_error = "插件版本与当前 OpenClaw 不兼容(缺少 channel-config-schema 模块),请点击「一键安装插件」重新安装兼容版本".to_string();
}
}
} }
} }