feat(device): 文件通道 pull/push
core 与设备复用同一条 WS 搬文件:256KiB 分块、base64、50MiB 上限, 写盘先 .part 再校验 size/sha256 后 rename;device 工具新增 pull/push 两个动作。
This commit is contained in:
@@ -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\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/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.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -448,7 +448,9 @@
|
||||
"enum": [
|
||||
"list",
|
||||
"health",
|
||||
"exec"
|
||||
"exec",
|
||||
"pull",
|
||||
"push"
|
||||
],
|
||||
"description": "Operation to perform."
|
||||
},
|
||||
@@ -467,6 +469,14 @@
|
||||
"timeout_ms": {
|
||||
"type": "integer",
|
||||
"description": "Default 120000, max 600000 (action=exec)."
|
||||
},
|
||||
"remote_path": {
|
||||
"type": "string",
|
||||
"description": "设备上的绝对路径,必须在设备工作根内(pull/push)。"
|
||||
},
|
||||
"local_path": {
|
||||
"type": "string",
|
||||
"description": "会话目录内的相对路径。pull 省略则用远端文件名;push 必填(源文件)。"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -834,7 +834,39 @@ async function toolDevice(ctx, args) {
|
||||
}
|
||||
}
|
||||
|
||||
return 'Error: action 必须是 list / health / exec';
|
||||
if (action === 'pull') {
|
||||
const name = String(args.device || '').trim();
|
||||
const remote = String(args.remote_path || '').trim();
|
||||
if (!name) return 'Error: action=pull 需要 device 参数(先调 action=list 看设备名)';
|
||||
if (!remote) return 'Error: action=pull 需要 remote_path 参数';
|
||||
try {
|
||||
const rel = String(args.local_path || '').trim() || path.basename(remote);
|
||||
const abs = resolveInTask(ctx.taskDir, rel, fsRoot(ctx));
|
||||
const r = await devices.pull({ device: name, remotePath: remote, localPath: abs });
|
||||
recordFile(ctx, abs);
|
||||
return `已拉到 ${path.relative(ctx.taskDir, abs) || path.basename(abs)}(${r.bytes} 字节,sha256 ${r.sha256.slice(0, 16)}…)`;
|
||||
} catch (e) {
|
||||
return 'Error: ' + e.message;
|
||||
}
|
||||
}
|
||||
|
||||
if (action === 'push') {
|
||||
const name = String(args.device || '').trim();
|
||||
const local = String(args.local_path || '').trim();
|
||||
const remote = String(args.remote_path || '').trim();
|
||||
if (!name) return 'Error: action=push 需要 device 参数(先调 action=list 看设备名)';
|
||||
if (!local) return 'Error: action=push 需要 local_path 参数(会话目录内的相对路径)';
|
||||
if (!remote) return 'Error: action=push 需要 remote_path 参数(设备上的绝对路径,须在工作根内)';
|
||||
try {
|
||||
const abs = resolveInTask(ctx.taskDir, local, fsRoot(ctx));
|
||||
const r = await devices.push({ device: name, localPath: abs, remotePath: remote });
|
||||
return `已推到 ${name}:${remote}(${r.bytes} 字节,sha256 ${r.sha256.slice(0, 16)}…)`;
|
||||
} catch (e) {
|
||||
return 'Error: ' + e.message;
|
||||
}
|
||||
}
|
||||
|
||||
return 'Error: action 必须是 list / health / exec / pull / push';
|
||||
}
|
||||
|
||||
async function toolTerminal(ctx, args) {
|
||||
|
||||
Reference in New Issue
Block a user