@anusornneal/chat-relay 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/agent/desktop-manager.mjs +319 -175
- package/agent/file-manager.mjs +36 -23
- package/agent/local-agent.mjs +35 -5
- package/agent/terminal-manager.mjs +550 -229
- package/agent/windows-desktop-worker.ps1 +380 -0
- package/agent/windows-desktop.ps1 +26 -1
- package/package.json +73 -73
package/agent/local-agent.mjs
CHANGED
|
@@ -12,7 +12,10 @@ const reconnectMs = Number(process.env.RECONNECT_MS ?? 2000);
|
|
|
12
12
|
const terminalEnabled = process.env.TERMINAL_ENABLED === "1";
|
|
13
13
|
const desktopEnabled = process.env.DESKTOP_ENABLED === "1";
|
|
14
14
|
const MAX_RESPONSE_BYTES = 60 * 1024;
|
|
15
|
-
const terminals = new TerminalManager(
|
|
15
|
+
const terminals = new TerminalManager({
|
|
16
|
+
batchConcurrency: process.env.TERMINAL_BATCH_CONCURRENCY,
|
|
17
|
+
maxQueuedJobs: process.env.TERMINAL_BATCH_MAX_QUEUED,
|
|
18
|
+
});
|
|
16
19
|
const files = new FileManager(process.env.ALLOWED_ROOTS);
|
|
17
20
|
const processes = new ProcessManager();
|
|
18
21
|
const desktop = new DesktopManager({ enabled: desktopEnabled });
|
|
@@ -52,6 +55,7 @@ async function handlePayload(payload) {
|
|
|
52
55
|
agentId,
|
|
53
56
|
agentName,
|
|
54
57
|
terminalEnabled,
|
|
58
|
+
terminalBatch: terminals.getBatchConfig(),
|
|
55
59
|
desktop: desktop.getConfig(),
|
|
56
60
|
allowedRoots: files.getRoots(),
|
|
57
61
|
reconnectMs,
|
|
@@ -62,7 +66,7 @@ async function handlePayload(payload) {
|
|
|
62
66
|
case "fs.stat":
|
|
63
67
|
return files.stat(payload.path);
|
|
64
68
|
case "fs.list":
|
|
65
|
-
return files.list(payload.path, payload.depth);
|
|
69
|
+
return files.list(payload.path, payload.depth, payload.offset, payload.limit, payload.maxBytes);
|
|
66
70
|
case "fs.read":
|
|
67
71
|
return files.read(payload.path, payload.offset, payload.length, payload.maxBytes);
|
|
68
72
|
case "fs.readMany":
|
|
@@ -88,21 +92,35 @@ async function handlePayload(payload) {
|
|
|
88
92
|
return processes.kill(payload.pid);
|
|
89
93
|
|
|
90
94
|
case "desktop.screenshot":
|
|
91
|
-
return desktop.screenshot();
|
|
95
|
+
return desktop.screenshot(payload);
|
|
92
96
|
case "desktop.mouse.click":
|
|
93
97
|
return desktop.mouseClick(payload);
|
|
94
98
|
case "desktop.keyboard.input":
|
|
95
99
|
return desktop.keyboardInput(payload);
|
|
100
|
+
case "desktop.step":
|
|
101
|
+
return desktop.step(payload);
|
|
96
102
|
|
|
97
103
|
case "terminal.exec":
|
|
98
104
|
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
99
105
|
return terminals.exec(payload.command, payload.cwd, payload.timeoutMs);
|
|
106
|
+
case "terminal.batch.start":
|
|
107
|
+
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
108
|
+
return terminals.batchStart(payload.jobs, { cwd: payload.cwd, timeoutMs: payload.timeoutMs, concurrency: payload.concurrency, observability: payload.observability });
|
|
109
|
+
case "terminal.batch.status":
|
|
110
|
+
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
111
|
+
return terminals.batchStatus(payload.batchId);
|
|
112
|
+
case "terminal.batch.read":
|
|
113
|
+
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
114
|
+
return terminals.batchRead(payload.batchId, payload.maxChars);
|
|
115
|
+
case "terminal.batch.cancel":
|
|
116
|
+
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
117
|
+
return terminals.batchCancel(payload.batchId);
|
|
100
118
|
case "terminal.start":
|
|
101
119
|
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
102
|
-
return terminals.start(payload.command, payload.cwd);
|
|
120
|
+
return terminals.start(payload.command, payload.cwd, payload.observability);
|
|
103
121
|
case "terminal.shell.start":
|
|
104
122
|
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
105
|
-
return terminals.startShell(payload.cwd);
|
|
123
|
+
return terminals.startShell(payload.cwd, payload.observability);
|
|
106
124
|
case "terminal.read":
|
|
107
125
|
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
108
126
|
return terminals.read(payload.sessionId, payload.afterSeq, payload.maxChars);
|
|
@@ -115,6 +133,9 @@ async function handlePayload(payload) {
|
|
|
115
133
|
case "terminal.list":
|
|
116
134
|
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
117
135
|
return terminals.list();
|
|
136
|
+
case "terminal.observability":
|
|
137
|
+
if (!terminalEnabled) return { ok: false, error: "terminal_disabled" };
|
|
138
|
+
return terminals.observability();
|
|
118
139
|
|
|
119
140
|
default:
|
|
120
141
|
return { ok: false, error: "unknown_action" };
|
|
@@ -124,6 +145,7 @@ async function handlePayload(payload) {
|
|
|
124
145
|
function requireReauthorization() {
|
|
125
146
|
if (reauthorizationRequired) return;
|
|
126
147
|
reauthorizationRequired = true;
|
|
148
|
+
desktop.close();
|
|
127
149
|
process.exitCode = 2;
|
|
128
150
|
console.error("Agent credential was revoked or rejected.");
|
|
129
151
|
console.error('Recovery: run "chat-relay login --force", then "chat-relay remote".');
|
|
@@ -209,4 +231,12 @@ function connect() {
|
|
|
209
231
|
});
|
|
210
232
|
}
|
|
211
233
|
|
|
234
|
+
function shutdown() {
|
|
235
|
+
desktop.close();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
process.once("SIGINT", shutdown);
|
|
239
|
+
process.once("SIGTERM", shutdown);
|
|
240
|
+
process.once("exit", shutdown);
|
|
241
|
+
|
|
212
242
|
connect();
|