refactor(device): list 不再带 health 快照
那份值是设备上线时取的一次性快照,会随连接时长过期,放在 list 里容易被当成实时状态。 health 改为纯按需查询(action=health),list 只留设备身份与在线信息。
This commit is contained in:
@@ -86,7 +86,7 @@ function attach(server) {
|
||||
function onConnection(ws) {
|
||||
const dev = {
|
||||
ws, name: null, os: '', arch: '', shell: '', shellPath: '', shellVer: '', root: '', ver: '',
|
||||
connectedAt: Date.now(), lastSeen: Date.now(), health: null, helloTimer: null,
|
||||
connectedAt: Date.now(), lastSeen: Date.now(), helloTimer: null,
|
||||
};
|
||||
dev.helloTimer = setTimeout(() => {
|
||||
if (!dev.name) { try { ws.close(4001, 'hello timeout'); } catch (_) {} }
|
||||
@@ -151,9 +151,6 @@ function onHello(dev, m) {
|
||||
}
|
||||
state.byName.set(dev.name, dev);
|
||||
log.info('devices', `设备上线:${dev.name}(${dev.os}/${dev.arch} shell=${dev.shellPath || dev.shell} ${dev.shellVer} root=${dev.root})`);
|
||||
|
||||
// 上线即取一次健康快照,list 时能顺带看到负载;失败不影响接入
|
||||
health(dev.name).catch(() => {});
|
||||
}
|
||||
|
||||
function pick(name) {
|
||||
@@ -177,7 +174,6 @@ function list() {
|
||||
ver: d.ver,
|
||||
connected_sec: Math.round((now - d.connectedAt) / 1000),
|
||||
idle_sec: Math.round((now - d.lastSeen) / 1000),
|
||||
health: d.health,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -194,13 +190,13 @@ function health(name) {
|
||||
onHealth(m) {
|
||||
clearTimeout(timer);
|
||||
state.pending.delete(id);
|
||||
dev.health = {
|
||||
resolve({
|
||||
device: dev.name, os: dev.os, arch: dev.arch,
|
||||
uptime_sec: m.uptime_sec, host_uptime_sec: m.host_uptime_sec,
|
||||
load1: m.load1, load5: m.load5, load15: m.load15,
|
||||
mem_total_mb: m.mem_total_mb, mem_free_mb: m.mem_free_mb,
|
||||
disk_total_gb: m.disk_total_gb, disk_free_gb: m.disk_free_gb, temp_c: m.temp_c,
|
||||
};
|
||||
resolve({ device: dev.name, os: dev.os, arch: dev.arch, ...dev.health });
|
||||
});
|
||||
},
|
||||
});
|
||||
try {
|
||||
|
||||
@@ -436,7 +436,7 @@
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "device",
|
||||
"description": "Operate the remote devices (other machines) connected to this server. Devices dial out to this server, so they need no inbound port; they stay connected until closed.\n\n- action=list: no other params. Returns every online device with os/arch/shell/root/health. Always call this first when you don't know device names.\n- action=health: requires device. Returns host uptime, load, memory, disk and temperature (fields the platform can't provide are -1).\n- action=exec: requires device and command. Runs the command through a shell on that device (sh -c on Unix, cmd /c on Windows) and returns stdout, stderr and the exit code. `cwd` must be inside that device's work root; omit it to use the root.\n\n- action=pull: requires device and remote_path; copies a file from the device into the session directory so read_file / skills can use it.\n- action=push: requires device, local_path and remote_path; sends a session file to the device.\n\nUse it when the work has to happen on the user's own machine (laptop, box, Windows PC). For the machine running this server use `terminal` instead. If a device is offline, say so explicitly — do not silently run the command elsewhere.",
|
||||
"description": "Operate the remote devices (other machines) connected to this server. Devices dial out to this server, so they need no inbound port; they stay connected until closed.\n\n- action=list: no other params. Returns every online device with os/arch/shell/root. Always call this first when you don't know device names.\n- action=health: requires device. Returns host uptime, load, memory, disk and temperature (fields the platform can't provide are -1).\n- action=exec: requires device and command. Runs the command through a shell on that device (sh -c on Unix, cmd /c on Windows) and returns stdout, stderr and the exit code. `cwd` must be inside that device's work root; omit it to use the root.\n\n- action=pull: requires device and remote_path; copies a file from the device into the session directory so read_file / skills can use it.\n- action=push: requires device, local_path and remote_path; sends a session file to the device.\n\nUse it when the work has to happen on the user's own machine (laptop, box, Windows PC). For the machine running this server use `terminal` instead. If a device is offline, say so explicitly — do not silently run the command elsewhere.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
Reference in New Issue
Block a user