mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-11 10:47:51 +08:00
🛸 Sync 2026-07-10 20:47:34
This commit is contained in:
1 parent
bc43e5009d
commit
bdfb23c9ce
25 files changed
+3111
-2838
No files matched your search
@@ -61,6 +61,29 @@ _oc_fix_opt
|
||||
NODE_BIN="${NODE_BASE}/bin/node"
|
||||
CONFIG_FILE="${OC_DATA}/.openclaw/openclaw.json"
|
||||
|
||||
run_openclaw_cli_as_user() {
|
||||
local oc_entry="$1"
|
||||
shift
|
||||
local pid_file="/tmp/openclaw-cli-$$.pid"
|
||||
local rc
|
||||
|
||||
[ -x "$NODE_BIN" ] || return 127
|
||||
id -u openclaw >/dev/null 2>&1 || return 127
|
||||
rm -f "$pid_file"
|
||||
ulimit -v unlimited 2>/dev/null || true
|
||||
ulimit -m unlimited 2>/dev/null || true
|
||||
ulimit -d unlimited 2>/dev/null || true
|
||||
HOME="$OC_DATA" OPENCLAW_HOME="$OC_DATA" OPENCLAW_STATE_DIR="${OC_DATA}/.openclaw" \
|
||||
OPENCLAW_CONFIG_PATH="$CONFIG_FILE" NODE_ICU_DATA="${NODE_BASE}/share/icu" \
|
||||
NPM_CONFIG_CACHE="${OC_DATA}/.npm" npm_config_cache="${OC_DATA}/.npm" TMPDIR="${OC_DATA}/.tmp" \
|
||||
PATH="${NODE_BASE}/bin:${OC_GLOBAL}/bin:$PATH" \
|
||||
start-stop-daemon -S -m -p "$pid_file" -c openclaw:openclaw -d "$OC_INSTALL_PATH" \
|
||||
-x "$NODE_BIN" -- "$oc_entry" "$@"
|
||||
rc=$?
|
||||
rm -f "$pid_file"
|
||||
return "$rc"
|
||||
}
|
||||
|
||||
get_oc_entry() {
|
||||
local search_dirs="${OC_GLOBAL}/lib/node_modules/openclaw
|
||||
${OC_GLOBAL}/node_modules/openclaw
|
||||
@@ -333,9 +356,6 @@ if(Array.isArray(d.plugins.allow)){
|
||||
delete d.plugins[ns].weixin;
|
||||
}
|
||||
});
|
||||
if(d.plugins.entries&&d.plugins.entries['openclaw-weixin']){
|
||||
delete d.plugins.entries['openclaw-weixin'];
|
||||
}
|
||||
['channel','channels'].forEach(ns=>{
|
||||
if(d[ns]&&d[ns].weixin){
|
||||
if(!d[ns]['openclaw-weixin'])d[ns]['openclaw-weixin']=d[ns].weixin;
|
||||
@@ -392,34 +412,67 @@ fi
|
||||
# 同步 UCI 到 JSON
|
||||
sync_uci_to_json
|
||||
|
||||
# 微信 npm 插件自愈注册:
|
||||
# 有些环境里 npm projects 已安装 @tencent-weixin/openclaw-weixin,
|
||||
# 但 openclaw.json 缺少 plugins.installs / plugins.allow / channels 配置,
|
||||
# 会导致页面显示“已安装”而 Gateway 或登录流程无法稳定加载插件。
|
||||
# 微信 npm 插件自愈注册:OpenClaw 2026.6.11 已把安装记录从
|
||||
# openclaw.json 的 plugins.installs 迁移到 SQLite installed_plugin_index。
|
||||
# 所有官方 CLI 和 SQLite 注册表操作都以 openclaw 用户执行;完成配置写入后
|
||||
# 强制 refresh 并检查 channel capability,避免重启后只加载 memory-core。
|
||||
self_heal_wechat_npm_plugin_config() {
|
||||
[ -x "$NODE_BIN" ] || return 0
|
||||
[ -f "$CONFIG_FILE" ] || return 0
|
||||
local npm_projects_dir="${OC_DATA}/.openclaw/npm/projects"
|
||||
[ -d "$npm_projects_dir" ] || return 0
|
||||
local wechat_plugin_json wechat_plugin_dir heal_out
|
||||
local wechat_plugin_json heal_out index_ok inspect_ok config_ok inspect_file
|
||||
wechat_plugin_json=$(find "$npm_projects_dir" -path "*/node_modules/@tencent-weixin/openclaw-weixin/openclaw.plugin.json" -type f 2>/dev/null | head -n 1)
|
||||
[ -n "$wechat_plugin_json" ] || return 0
|
||||
wechat_plugin_dir="${wechat_plugin_json%/openclaw.plugin.json}"
|
||||
heal_out=$(OC_CONFIG="$CONFIG_FILE" OC_WECHAT_PLUGIN_DIR="$wechat_plugin_dir" "$NODE_BIN" -e "
|
||||
inspect_file="/tmp/openclaw-wechat-self-heal.inspect"
|
||||
rm -f "$inspect_file"
|
||||
: > /tmp/openclaw-wechat-self-heal.log
|
||||
index_ok=0
|
||||
inspect_ok=0
|
||||
config_ok=0
|
||||
if run_openclaw_cli_as_user "$oc_entry" plugins inspect openclaw-weixin >"$inspect_file" 2>&1; then
|
||||
grep -q '^Install:$' "$inspect_file" && grep -q '^Source: npm$' "$inspect_file" && index_ok=1
|
||||
grep -q '^Status: loaded$' "$inspect_file" && grep -q '^channel: openclaw-weixin$' "$inspect_file" && inspect_ok=1
|
||||
fi
|
||||
OC_CONFIG="$CONFIG_FILE" "$NODE_BIN" -e "
|
||||
try {
|
||||
const d=JSON.parse(require('fs').readFileSync(process.env.OC_CONFIG,'utf8'));
|
||||
const ok=d.plugins&&Array.isArray(d.plugins.allow)&&d.plugins.allow.includes('openclaw-weixin')&&
|
||||
d.plugins.entries&&d.plugins.entries['openclaw-weixin']&&d.plugins.entries['openclaw-weixin'].enabled===true&&
|
||||
d.channels&&d.channels['openclaw-weixin']&&d.channels['openclaw-weixin'].enabled===true&&
|
||||
!(d.plugins.installs&&d.plugins.installs['openclaw-weixin']);
|
||||
process.exit(ok?0:1);
|
||||
} catch(e) { process.exit(1); }
|
||||
" >/dev/null 2>&1 && config_ok=1
|
||||
if [ "$index_ok" = "1" ] && [ "$inspect_ok" = "1" ] && [ "$config_ok" = "1" ]; then
|
||||
cat "$inspect_file" >> /tmp/openclaw-wechat-self-heal.log
|
||||
logger -t openclaw "微信插件注册状态已有效,跳过重复刷新"
|
||||
rm -f "$inspect_file"
|
||||
return 0
|
||||
fi
|
||||
if [ "$index_ok" != "1" ]; then
|
||||
logger -t openclaw "检测到旧微信直装目录,正在迁移到 SQLite 插件索引"
|
||||
mkdir -p "${OC_DATA}/.npm" "${OC_DATA}/.tmp" 2>/dev/null || true
|
||||
if run_openclaw_cli_as_user "$oc_entry" plugins install --force --pin '@tencent-weixin/openclaw-weixin@2.4.6' \
|
||||
>>/tmp/openclaw-wechat-self-heal.log 2>&1; then
|
||||
logger -t openclaw "微信插件已迁移到 SQLite installed_plugin_index"
|
||||
else
|
||||
logger -t openclaw "微信插件 SQLite 索引迁移失败,请查看 /tmp/openclaw-wechat-self-heal.log"
|
||||
rm -f "$inspect_file"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
heal_out=$(OC_CONFIG="$CONFIG_FILE" "$NODE_BIN" -e "
|
||||
const fs=require('fs');
|
||||
const p=process.env.OC_CONFIG;
|
||||
const pluginDir=process.env.OC_WECHAT_PLUGIN_DIR;
|
||||
let d={};
|
||||
try{d=JSON.parse(fs.readFileSync(p,'utf8'));}catch(e){}
|
||||
if(!d.plugins||typeof d.plugins!=='object')d.plugins={};
|
||||
if(!d.plugins.installs||typeof d.plugins.installs!=='object')d.plugins.installs={};
|
||||
if(!Array.isArray(d.plugins.allow))d.plugins.allow=[];
|
||||
if(!d.channels||typeof d.channels!=='object')d.channels={};
|
||||
let changed=false;
|
||||
const want={kind:'npm',installPath:pluginDir,packageName:'@tencent-weixin/openclaw-weixin'};
|
||||
const cur=d.plugins.installs['openclaw-weixin'];
|
||||
if(!cur||cur.kind!==want.kind||cur.installPath!==want.installPath||cur.packageName!==want.packageName){
|
||||
d.plugins.installs['openclaw-weixin']=want; changed=true;
|
||||
if(d.plugins.installs&&d.plugins.installs['openclaw-weixin']){
|
||||
delete d.plugins.installs['openclaw-weixin']; changed=true;
|
||||
}
|
||||
if(!d.plugins.allow.includes('openclaw-weixin')){
|
||||
d.plugins.allow.push('openclaw-weixin'); changed=true;
|
||||
@@ -430,9 +483,6 @@ if(!d.channels['openclaw-weixin']||typeof d.channels['openclaw-weixin']!=='objec
|
||||
if(d.channels['openclaw-weixin'].enabled!==true){
|
||||
d.channels['openclaw-weixin'].enabled=true; changed=true;
|
||||
}
|
||||
if(d.plugins.entries&&d.plugins.entries['openclaw-weixin']){
|
||||
delete d.plugins.entries['openclaw-weixin']; changed=true;
|
||||
}
|
||||
if(changed){
|
||||
fs.writeFileSync(p,JSON.stringify(d,null,2)+'\n');
|
||||
console.log('FIXED');
|
||||
@@ -440,8 +490,29 @@ if(changed){
|
||||
" 2>/dev/null)
|
||||
if echo "$heal_out" | grep -q "FIXED"; then
|
||||
chown openclaw:openclaw "$CONFIG_FILE" 2>/dev/null || true
|
||||
logger -t openclaw "已自愈注册 openclaw-weixin npm plugin: $wechat_plugin_dir"
|
||||
logger -t openclaw "已自愈启用 openclaw-weixin channel"
|
||||
fi
|
||||
if ! run_openclaw_cli_as_user "$oc_entry" plugins enable openclaw-weixin \
|
||||
>>/tmp/openclaw-wechat-self-heal.log 2>&1; then
|
||||
logger -t openclaw "微信插件启用失败,请查看 /tmp/openclaw-wechat-self-heal.log"
|
||||
rm -f "$inspect_file"
|
||||
return 0
|
||||
fi
|
||||
if ! run_openclaw_cli_as_user "$oc_entry" plugins registry --refresh \
|
||||
>>/tmp/openclaw-wechat-self-heal.log 2>&1; then
|
||||
logger -t openclaw "微信插件注册表刷新失败,请查看 /tmp/openclaw-wechat-self-heal.log"
|
||||
rm -f "$inspect_file"
|
||||
return 0
|
||||
fi
|
||||
if run_openclaw_cli_as_user "$oc_entry" plugins inspect openclaw-weixin >"$inspect_file" 2>&1 && \
|
||||
grep -q '^Status: loaded$' "$inspect_file" && grep -q '^channel: openclaw-weixin$' "$inspect_file"; then
|
||||
cat "$inspect_file" >> /tmp/openclaw-wechat-self-heal.log
|
||||
logger -t openclaw "微信插件 SQLite 注册表已刷新并通过加载验证"
|
||||
else
|
||||
cat "$inspect_file" >> /tmp/openclaw-wechat-self-heal.log 2>/dev/null || true
|
||||
logger -t openclaw "微信插件加载验证失败,请查看 /tmp/openclaw-wechat-self-heal.log"
|
||||
fi
|
||||
rm -f "$inspect_file"
|
||||
}
|
||||
self_heal_wechat_npm_plugin_config
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#!/bin/sh
|
||||
# OpenClaw state permission helper.
|
||||
# Keep runtime state writable by the openclaw user, while keeping plugin source
|
||||
# directories root-owned for OpenClaw's official ownership checks.
|
||||
# Keep runtime state and managed npm plugin generations writable by the
|
||||
# openclaw user. OpenClaw 2026.6.11 installs and retires these generations
|
||||
# itself, so root-owned files under npm/projects break later cleanup.
|
||||
|
||||
oc_perm_state_dir() {
|
||||
if [ -n "${1:-}" ]; then
|
||||
@@ -24,33 +25,16 @@ oc_perm_data_dir_from_state() {
|
||||
}
|
||||
|
||||
oc_fix_npm_projects_permissions() {
|
||||
local state_dir npm_projects plugin_json plugin_dir
|
||||
local state_dir npm_projects
|
||||
state_dir="$(oc_perm_state_dir "${1:-}")"
|
||||
npm_projects="${state_dir}/npm/projects"
|
||||
[ -d "$npm_projects" ] || return 0
|
||||
|
||||
# Gateway must be able to clean npm project generations.
|
||||
# The official plugin installer runs as openclaw and the Gateway removes
|
||||
# retired generations asynchronously. Keep the complete tree writable by
|
||||
# that user, including plugin source files.
|
||||
chown -R openclaw:openclaw "$npm_projects" 2>/dev/null || true
|
||||
chmod u+rwx,go+rx "$npm_projects" 2>/dev/null || true
|
||||
|
||||
# Actual OpenClaw plugin roots must stay root-owned, otherwise OpenClaw refuses
|
||||
# to load them with "suspicious ownership".
|
||||
find "$npm_projects" -name openclaw.plugin.json -type f 2>/dev/null | while IFS= read -r plugin_json; do
|
||||
plugin_dir="${plugin_json%/openclaw.plugin.json}"
|
||||
case "$plugin_dir" in
|
||||
*__openclaw-generation__*)
|
||||
# Retained generation dirs are temporary and must remain removable by openclaw.
|
||||
;;
|
||||
"$npm_projects"/*/node_modules/*)
|
||||
chown -R root:root "$plugin_dir" 2>/dev/null || true
|
||||
chmod -R 755 "$plugin_dir" 2>/dev/null || true
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Compatibility for the WeChat plugin path even if its manifest scan fails.
|
||||
find "$npm_projects" -path '*/node_modules/@tencent-weixin/openclaw-weixin' -type d -prune \
|
||||
-exec chown -R root:root {} \; -exec chmod -R 755 {} \; 2>/dev/null || true
|
||||
chmod -R u+rwX,go+rX "$npm_projects" 2>/dev/null || true
|
||||
}
|
||||
|
||||
oc_fix_state_permissions() {
|
||||
@@ -106,8 +90,7 @@ oc_prepare_openclaw_workdirs() {
|
||||
chown openclaw:openclaw "$data_dir" "$state_dir" "${state_dir}/npm" "$npm_dir" 2>/dev/null || true
|
||||
chmod u+rwx,go+rx "${data_dir}/.npm" "${data_dir}/.tmp" "$state_dir" "${state_dir}/npm" "$npm_dir" 2>/dev/null || true
|
||||
|
||||
# During install/upgrade, allow openclaw to update npm generations. Call
|
||||
# fix-state after the install to restore plugin roots to root:root.
|
||||
# During install/upgrade, allow openclaw to update npm generations.
|
||||
[ -d "$npm_dir" ] && chown -R openclaw:openclaw "$npm_dir" 2>/dev/null || true
|
||||
}
|
||||
|
||||
|
||||
@@ -1277,7 +1277,7 @@ async function configureYiwanAIFanAPI() {
|
||||
if (!apiKey) { console.log(`${C.yellow}已取消${C.reset}`); return false; }
|
||||
|
||||
authSetApikey(providerName, apiKey, `${providerName}:fan`);
|
||||
registerCustomProvider(providerName, baseUrl, apiKey, modelName, modelName);
|
||||
registerCustomProvider(providerName, baseUrl, apiKey, modelName, modelName, 1000000, 32000);
|
||||
const config = readConfig();
|
||||
const provider = config.models?.providers?.[providerName];
|
||||
if (provider?.models?.[0]) {
|
||||
|
||||
@@ -1448,7 +1448,7 @@ configure_model() {
|
||||
prompt_with_default "API Key" "" api_key
|
||||
if [ -n "$api_key" ]; then
|
||||
auth_set_apikey yiwanai "$api_key" "yiwanai:fan"
|
||||
register_custom_provider yiwanai "https://api.910501.xyz/v1" "$api_key" "gpt-5.5" "gpt-5.5"
|
||||
register_custom_provider yiwanai "https://api.910501.xyz/v1" "$api_key" "gpt-5.5" "gpt-5.5" 1000000 32000
|
||||
_YW_PROV="yiwanai" "$NODE_BIN" -e "
|
||||
const fs=require('fs');
|
||||
let d={};
|
||||
|
||||
Reference in new issue
Block a user