feat: proxy CutOS agent console

This commit is contained in:
yankun
2026-08-02 15:58:32 +08:00
parent 9489b334c5
commit 40ca8cd5af
4 changed files with 27 additions and 7 deletions
+2 -1
View File
@@ -112,7 +112,8 @@ systemd 安装后环境变量文件位于 `/etc/clawd/env`。
切换 Agent 类型前,必须先在云端解绑设备,再修改 `/etc/clawd/env` 中的
`AGENT_TYPE`,重启 `clawd` 后重新绑定。`cutos-agent` 模式会维护 Pi 的 `providers.cutos`
模型配置,但不会读写 OpenClaw 配置、重启 OpenClaw Gateway 或调用 OpenClaw 微信能力。
模型配置,并将本地 `http://127.0.0.1:30141/` 控制台接入设备 Dashboard 子域名;它不会读写
OpenClaw 配置、重启 OpenClaw Gateway 或调用 OpenClaw 微信能力。
## 服务管理
+2 -4
View File
@@ -196,9 +196,7 @@ class ClawClient {
async _proceedWithConnection() {
const [dashInfo] = await Promise.all([
this._isOpenClaw()
? getDashboardInfo().catch(e => { log.warn('clawd', 'dashboard 信息获取失败:', e.message); return null; })
: Promise.resolve({}),
getDashboardInfo(this._agentType).catch(e => { log.warn('clawd', 'dashboard 信息获取失败:', e.message); return null; }),
startTtyd().catch(e => log.warn('ttyd', '启动失败:', e.message)),
]);
this._dashInfo = dashInfo || {};
@@ -460,7 +458,7 @@ class ClawClient {
this._applyStatus(msg);
if (msg.frp && msg.frp.server && msg.frp.auth_token) {
this._frpc.start(msg.claw_id, msg.frp, this._cfg.ssh_secret_key ?? null, this._isOpenClaw()).catch(e => {
this._frpc.start(msg.claw_id, msg.frp, this._cfg.ssh_secret_key ?? null, true).catch(e => {
log.error('frpc', '启动失败:', e.message);
});
}
+13 -2
View File
@@ -7,6 +7,7 @@ const path = require('path');
const https = require('https');
const log = require('./logger');
const { Watchdog } = require('./watchdog');
const { CUTOS_AGENT } = require('./agent-type');
const CONFIG_DIR = process.env.CLAWD_CONFIG_DIR
|| (process.getuid && process.getuid() === 0 ? '/etc/clawd' : path.join(os.homedir(), '.clawd'));
@@ -15,6 +16,7 @@ const FRPC_CONFIG = path.join(CONFIG_DIR, 'frpc.toml');
const FRP_VERSION = '0.62.0';
const TTYD_PORT = 7681;
const CUTOS_DASHBOARD_PORT = 30141;
function findTtydBin() {
const candidates = ['/usr/bin/ttyd', '/usr/local/bin/ttyd', path.join(CONFIG_DIR, 'ttyd')];
@@ -49,7 +51,10 @@ function resolveOpenclawConfigFile() {
* 直接读取比执行命令更可靠(不依赖 PATH、不需要进程启动等待)。
* systemd 服务的 ProtectHome=read-only 允许读取 /home 下的文件。
*/
function getDashboardInfo() {
function getDashboardInfo(agentType) {
if (agentType === CUTOS_AGENT) {
return Promise.resolve({ dashboard_port: CUTOS_DASHBOARD_PORT });
}
for (const cfgPath of OPENCLAW_JSON_CANDIDATES) {
try {
const raw = fs.readFileSync(cfgPath, 'utf8');
@@ -226,4 +231,10 @@ class FrpcManager {
}
}
module.exports = { getDashboardInfo, resolveOpenclawConfigFile, startTtyd, FrpcManager };
module.exports = {
CUTOS_DASHBOARD_PORT,
getDashboardInfo,
resolveOpenclawConfigFile,
startTtyd,
FrpcManager,
};
+10
View File
@@ -0,0 +1,10 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const { CUTOS_DASHBOARD_PORT, getDashboardInfo } = require('../lib/frpc');
test('CutOS Agent dashboard uses the fixed local console port without a token', async () => {
assert.equal(CUTOS_DASHBOARD_PORT, 30141);
assert.deepEqual(await getDashboardInfo('cutos-agent'), { dashboard_port: 30141 });
});