重做配置边界(撤销 9b6bfff 思路):config.example.yml 回归 app/——config.yml 是 core 专属(内含平台密钥/登录 secret),executor/wxbot 一律不挂不读;executor 与 wxbot 接线纯 env(EXECUTOR_URL/EXECUTOR_TOKEN、WXBOT_URL/WXBOT_TOKEN,compose 经根 .env 注入,旧文件段忽略),config.example.yml 两段随之删除;wxbot 日志等级改 env WXBOT_LOG_LEVEL(compose 注入,同 EXECUTOR_LOG_LEVEL 模式;none/off→silent,debug 打印收信原始结构保留);.env.example 收敛为密钥+地址类变量,其余旋钮归 compose;compose 撤掉 wxbot 的 config.yml 只读挂载、新增 WXBOT_LOG_LEVEL、WXBOT_URL 保留单横线修复(该文件仍有主人 WIP,未随本提交);文档同步
This commit is contained in:
+15
-13
@@ -74,11 +74,8 @@ const DEFAULTS = {
|
||||
data_root: '/workspace/data',
|
||||
// 缺省 data_root/.agent.db。
|
||||
db_path: '',
|
||||
// 命令执行服务:url 非空走远端 executor,留空本地 spawn;留空时回退 env EXECUTOR_URL / EXECUTOR_TOKEN。
|
||||
executor: { url: '', token: '' },
|
||||
// 微信接入(可选能力):url 非空才启用(留空时整个微信功能静默下线,不影响其他一切);
|
||||
// 留空时回退 env WXBOT_URL / WXBOT_TOKEN(compose 注入,同 executor 模式;wxbot 只在内网,走容器名)。
|
||||
wxbot: { url: '', token: '' },
|
||||
// executor / 微信接入(wxbot)均不占配置字段:两组件接线纯 env(compose 经根 .env 注入,见 parseAndValidate);
|
||||
// 本配置文件内含密钥,只给 core 进程读,executor/wxbot 一律不挂不读。
|
||||
terminal: { default_timeout_ms: 30000, max_output_chars: 10000 },
|
||||
// fetch:timeout_ms 覆盖请求发出到 body 读完的全生命周期;max_bytes 为流式抓取字节上限(超限即断开)。
|
||||
fetch: { timeout_ms: 30000, max_bytes: 1048576 },
|
||||
@@ -268,15 +265,20 @@ function parseAndValidate(rawText, configPath) {
|
||||
cfg.data_root = path.resolve(cfg.data_root);
|
||||
if (!cfg.db_path) cfg.db_path = path.join(cfg.data_root, '.agent.db');
|
||||
|
||||
// executor 远程执行:配置优先,env 兑底(compose 注入 EXECUTOR_URL/EXECUTOR_TOKEN);url 去尾部斜杠(拼 /exec 用)。
|
||||
if (!cfg.executor || typeof cfg.executor !== 'object') cfg.executor = {};
|
||||
cfg.executor.url = String(cfg.executor.url || process.env.EXECUTOR_URL || '').trim().replace(/\/+$/, '');
|
||||
cfg.executor.token = String(cfg.executor.token || process.env.EXECUTOR_TOKEN || '').trim();
|
||||
// executor 远程执行:纯 env 接线(compose 注 EXECUTOR_URL/EXECUTOR_TOKEN;未注 = 本地 spawn,单机调试形态)。
|
||||
// cfg.executor 仍作运行期访问器供 remote-exec 读取;url 去尾部斜杠(拼 /exec 用)。executor 进程不读本配置文件(防密钥外泄)。
|
||||
cfg.executor = {
|
||||
url: String(process.env.EXECUTOR_URL || '').trim().replace(/\/+$/, ''),
|
||||
token: String(process.env.EXECUTOR_TOKEN || '').trim(),
|
||||
};
|
||||
|
||||
// 微信接入(wechat.js):同上模式;url 留空 = 功能关闭(不报错、不建实例、面板隐藏)。
|
||||
if (!cfg.wxbot || typeof cfg.wxbot !== 'object') cfg.wxbot = {};
|
||||
cfg.wxbot.url = String(cfg.wxbot.url || process.env.WXBOT_URL || '').trim().replace(/\/+$/, '');
|
||||
cfg.wxbot.token = String(cfg.wxbot.token || process.env.WXBOT_TOKEN || '').trim();
|
||||
// 微信接入(wechat.js):纯 env 接线(wxbot 为栈内组件,不再是 config.yml 字段;旧文件里的 wxbot: 段直接忽略)。
|
||||
// WXBOT_URL 缺省 http://wxbot:8093(compose 注同名 env,置空 = 微信入口整体静默关闭);
|
||||
// WXBOT_TOKEN 未配 = 关闭(init.sh 生成,core ↔ wxbot 两侧同值)。cfg.wxbot 仍作为运行期访问器供 wechat/routes 读取。
|
||||
cfg.wxbot = {
|
||||
url: String(process.env.WXBOT_URL != null ? process.env.WXBOT_URL : 'http://wxbot:8093').trim().replace(/\/+$/, ''),
|
||||
token: String(process.env.WXBOT_TOKEN || '').trim(),
|
||||
};
|
||||
|
||||
// 日志等级:只认 debug/info/warn/error/none(off 是 none 别名),非法值按 info(不影响启动)
|
||||
cfg.log_level = String(cfg.log_level || 'info').trim().toLowerCase();
|
||||
|
||||
@@ -41,7 +41,7 @@ function timingEqual(a, b) {
|
||||
function requireService(req, res, next) {
|
||||
const cfg = engine.getConfig();
|
||||
const token = (cfg.wxbot && cfg.wxbot.token) || '';
|
||||
if (!token) return res.status(503).json({ error: '微信接入服务 token 未配置(config wxbot.token / env WXBOT_TOKEN)' });
|
||||
if (!token) return res.status(503).json({ error: '微信接入服务 token 未配置(env WXBOT_TOKEN)' });
|
||||
const h = String(req.headers.authorization || '');
|
||||
if (!h.startsWith('Bearer ') || !timingEqual(h.slice(7).trim(), token)) {
|
||||
return res.status(401).json({ error: 'invalid service token' });
|
||||
@@ -69,7 +69,7 @@ function rowFor(req) {
|
||||
return b;
|
||||
}
|
||||
|
||||
// 面板总览:enabled=false(wxbot.url 未配)时前端整卡隐藏——没配置就当功能不存在;
|
||||
// 面板总览:enabled=false(WXBOT_URL/WXBOT_TOKEN 未就位)时前端整卡隐藏——没配置就当功能不存在;
|
||||
// alive/has_qr 与状态自愈全在 wechat.overview()(hook 丢事件也能从实例快照纠回来)。
|
||||
router.get('/', wrap(async (req, res) => {
|
||||
res.json(await wechat.overview(String(req.user || '')));
|
||||
|
||||
@@ -27,7 +27,7 @@ engine.init();
|
||||
//(active/遗留 queued → held),首轮 tick 才不会看到脏状态。
|
||||
scheduler.start(engine);
|
||||
|
||||
// 微信接入(wechat.js,可选能力):wxbot.url 未配 = 全部静默关闭;配了但 wxbot 没起 =
|
||||
// 微信接入(wechat.js,可选能力):env WXBOT_URL/WXBOT_TOKEN 未就位 = 全部静默关闭;配了但 wxbot 没起 =
|
||||
// restore 只留一行日志,不重试不报错(用户在设置页点刷新自愈),不影响 Web 主流程。
|
||||
wechat.init(cfg, db, bus);
|
||||
|
||||
@@ -175,7 +175,7 @@ mcp.init(cfg).then(async () => {
|
||||
const mcpList = (cfg.mcp_servers || []).map(s => s.name + '@' + s.url + (s.enable === false ? '(禁用)' : '')).join(', ');
|
||||
log.info('startup', ' mcp_servers=' + (mcpList || '(none)'));
|
||||
log.info('startup', ' auth=' + (auth.enabled ? 'login: ' + cfg.auth.users.map(u => u.user).join(', ') : '(disabled)'));
|
||||
log.info('startup', ' wxbot=' + (cfg.wxbot.url ? cfg.wxbot.url : '(未启用)'));
|
||||
log.info('startup', ' wxbot=' + (cfg.wxbot.url && cfg.wxbot.token ? cfg.wxbot.url : '(未启用)'));
|
||||
log.info('startup', ' log_level=' + cfg.log_level);
|
||||
// 微信实例恢复 fire-and-forget:wxbot 没起只留日志,绝不阻塞/抛错影响启动。
|
||||
wechat.restore().catch(e => log.warn('wechat', '启动恢复异常:' + (e && e.message || e)));
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// wxbot → core /wxhook/{inbox,hook}(Bearer 服务 token,挂在 auth.middleware 之前)
|
||||
// core → wxbot /api/deliver(assistant 最终回复推送;总线内部监听驱动,游标落库不重发)
|
||||
// + /api/deliver_media(正文里的 /p/ 链接→本地读字节→微信文件/图片卡片,尽力而为)
|
||||
// 降级承诺:wxbot.url 未配置 = 功能整体静默关闭;配置了但 wxbot 没起 = 启动只留一行日志,
|
||||
// 降级承诺:微信接入未配置(env WXBOT_URL 置空或未配 WXBOT_TOKEN)= 功能整体静默关闭;配了但 wxbot 没起 = 启动只留一行日志,
|
||||
// 面板显示「未连接」、操作时报可读错误,绝不抛出未捕获异常影响 Web 主流程。
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
@@ -32,13 +32,13 @@ const now = () => Date.now();
|
||||
const msg = e => String((e && e.message) || e || 'unknown');
|
||||
|
||||
// ---------- 开关与 wxbot 客户端 ----------
|
||||
function enabled() { return !!(cfg && cfg.wxbot && cfg.wxbot.url); }
|
||||
function enabled() { return !!(cfg && cfg.wxbot && cfg.wxbot.url && cfg.wxbot.token); }
|
||||
|
||||
function wxUrl() { return (cfg.wxbot && cfg.wxbot.url) || ''; }
|
||||
function wxToken() { return (cfg.wxbot && cfg.wxbot.token) || ''; }
|
||||
|
||||
async function wxbotApi(method, path, body, timeoutMs) {
|
||||
if (!enabled()) throw Object.assign(new Error('微信接入未配置:wxbot.url 为空'), { status_code: 409 });
|
||||
if (!enabled()) throw Object.assign(new Error('微信接入未配置:env WXBOT_URL / WXBOT_TOKEN 未就位'), { status_code: 409 });
|
||||
const res = await fetch(wxUrl() + path, {
|
||||
method,
|
||||
headers: Object.assign(
|
||||
@@ -94,7 +94,7 @@ function touchBinding(id, fields) {
|
||||
|
||||
// 一人一绑(自用形态;换微信号走「解绑→重绑」);id 兼作 channel 后缀与 wxbot 存储目录名 → 只允许安全字符。
|
||||
async function createBinding(user) {
|
||||
if (!enabled()) throw Object.assign(new Error('微信接入未配置(wxbot.url 为空),请联系管理员在 config.yml / 环境变量 WXBOT_URL 启用后重启'), { status_code: 409 });
|
||||
if (!enabled()) throw Object.assign(new Error('微信接入未配置(WXBOT_URL/WXBOT_TOKEN 未就位),请联系管理员运行 scripts/init.sh 后 docker compose up -d 重建'), { status_code: 409 });
|
||||
const dup = db.prepare('SELECT id FROM wechat_bindings WHERE user = ?').get(user);
|
||||
if (dup) throw Object.assign(new Error('你已绑定微信(' + dup.id + '),请先解绑'), { status_code: 409 });
|
||||
const id = 'wx' + crypto.randomBytes(5).toString('hex');
|
||||
|
||||
Reference in New Issue
Block a user