fix: read dashboard token from ~/.openclaw/openclaw.json instead of running openclaw dashboard command
Made-with: Cursor
This commit is contained in:
@@ -6,7 +6,7 @@ const config = require('./config');
|
||||
const log = require('./logger');
|
||||
const { getBoxId } = require('./fingerprint');
|
||||
const { collect } = require('./metrics');
|
||||
const { getDashboardInfo, startTtyd, FrpcManager } = require('./frpc');
|
||||
const { getDashboardInfo, startTtyd, FrpcManager } = require('./frpc'); // getDashboardInfo 也用于心跳中定期刷新
|
||||
const { ProvisionManager } = require('./provisioning');
|
||||
const { hasInternet } = require('./network');
|
||||
|
||||
@@ -30,6 +30,7 @@ class ClawClient {
|
||||
this._stopped = false;
|
||||
this._frpc = new FrpcManager();
|
||||
this._dashInfo = {};
|
||||
this._hbCount = 0; // 心跳计数器,用于定期刷新 dashboard 信息
|
||||
|
||||
// WS 层活性检测
|
||||
this._pingTimer = null;
|
||||
@@ -268,12 +269,24 @@ class ClawClient {
|
||||
async _sendHeartbeat() {
|
||||
if (!this._ws || this._ws.readyState !== WebSocket.OPEN) return;
|
||||
try {
|
||||
this._hbCount++;
|
||||
|
||||
// 每 10 次心跳(约 5 分钟)刷新一次 dashboard 信息,
|
||||
// 确保初次提取失败时能自动补偿,或在 token 变化后自动同步
|
||||
if (this._hbCount % 10 === 0) {
|
||||
const freshInfo = await getDashboardInfo().catch(() => null);
|
||||
if (freshInfo && Object.keys(freshInfo).length > 0) {
|
||||
this._dashInfo = freshInfo;
|
||||
}
|
||||
}
|
||||
|
||||
const metrics = await collect();
|
||||
this._send({
|
||||
type: 'heartbeat',
|
||||
claw_id: this._cfg.claw_id,
|
||||
token: this._cfg.token,
|
||||
metrics,
|
||||
...this._dashInfo, // 携带 dashboard_token / dashboard_port,供 VPS 幂等更新
|
||||
});
|
||||
} catch (e) {
|
||||
log.error('clawd', '心跳发送失败:', e.message);
|
||||
|
||||
Reference in New Issue
Block a user