@anusornneal/chat-relay 0.8.0 → 0.9.0
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 +339 -336
- package/agent/capability-scheduler.mjs +121 -121
- package/agent/connection-state.mjs +141 -126
- package/agent/desktop-manager.mjs +424 -440
- package/agent/file-manager.mjs +527 -527
- package/agent/lifecycle.mjs +101 -101
- package/agent/local-agent.mjs +494 -475
- package/agent/macos-desktop-helper.js +243 -0
- package/agent/macos-desktop-runner.mjs +292 -0
- package/agent/process-manager.mjs +110 -26
- package/agent/protocol.mjs +67 -67
- package/agent/terminal-manager.mjs +587 -550
- package/agent/windows-desktop-runner.mjs +109 -0
- package/agent/windows-desktop-worker.ps1 +582 -508
- package/cli/config.mjs +114 -114
- package/cli/device-login.mjs +170 -170
- package/cli/index.mjs +241 -241
- package/cli/remote.mjs +139 -139
- package/package.json +76 -75
- package/agent/windows-desktop.ps1 +0 -288
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
const POWERSHELL_TIMEOUT_MS = 15_000;
|
|
8
|
+
const helperPath = path.join(path.dirname(fileURLToPath(import.meta.url)), "windows-desktop-worker.ps1");
|
|
9
|
+
|
|
10
|
+
export class PersistentDesktopRunner {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.platform = options.platform ?? process.platform;
|
|
13
|
+
this.timeoutMs = Number(options.timeoutMs ?? POWERSHELL_TIMEOUT_MS);
|
|
14
|
+
this.process = null;
|
|
15
|
+
this.stdout = null;
|
|
16
|
+
this.pending = new Map();
|
|
17
|
+
this.stderr = "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
ensureStarted() {
|
|
21
|
+
if (this.platform !== "win32") return false;
|
|
22
|
+
if (this.process && !this.process.killed) return true;
|
|
23
|
+
|
|
24
|
+
const child = spawn("powershell.exe", [
|
|
25
|
+
"-NoLogo",
|
|
26
|
+
"-NoProfile",
|
|
27
|
+
"-NonInteractive",
|
|
28
|
+
"-Sta",
|
|
29
|
+
"-ExecutionPolicy",
|
|
30
|
+
"Bypass",
|
|
31
|
+
"-File",
|
|
32
|
+
helperPath,
|
|
33
|
+
], {
|
|
34
|
+
windowsHide: true,
|
|
35
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.process = child;
|
|
39
|
+
this.stderr = "";
|
|
40
|
+
this.stdout = readline.createInterface({ input: child.stdout });
|
|
41
|
+
|
|
42
|
+
this.stdout.on("line", (line) => {
|
|
43
|
+
let message;
|
|
44
|
+
try {
|
|
45
|
+
message = JSON.parse(line);
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const pending = this.pending.get(message?.id);
|
|
50
|
+
if (!pending) return;
|
|
51
|
+
clearTimeout(pending.timer);
|
|
52
|
+
this.pending.delete(message.id);
|
|
53
|
+
pending.resolve(message.result ?? { ok: false, error: "desktop_worker_error" });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
child.stderr.on("data", (chunk) => {
|
|
57
|
+
this.stderr = (this.stderr + String(chunk)).slice(-8192);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
child.on("exit", () => {
|
|
61
|
+
const error = { ok: false, error: "desktop_worker_exited" };
|
|
62
|
+
for (const pending of this.pending.values()) {
|
|
63
|
+
clearTimeout(pending.timer);
|
|
64
|
+
pending.resolve(error);
|
|
65
|
+
}
|
|
66
|
+
this.pending.clear();
|
|
67
|
+
this.stdout?.close();
|
|
68
|
+
this.stdout = null;
|
|
69
|
+
this.process = null;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
child.on("error", () => {
|
|
73
|
+
// exit handler settles pending work.
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async run(operation, args) {
|
|
80
|
+
if (!this.ensureStarted() || !this.process?.stdin?.writable) {
|
|
81
|
+
return { ok: false, error: operation === "screenshot" ? "capture_failed" : "input_failed" };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const id = randomUUID();
|
|
85
|
+
const request = JSON.stringify({ id, operation, args: args || {} }) + "\n";
|
|
86
|
+
|
|
87
|
+
return new Promise((resolve) => {
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
this.pending.delete(id);
|
|
90
|
+
resolve({ ok: false, error: operation === "screenshot" ? "capture_timeout" : "input_timeout" });
|
|
91
|
+
}, this.timeoutMs);
|
|
92
|
+
|
|
93
|
+
this.pending.set(id, { resolve, timer });
|
|
94
|
+
this.process.stdin.write(request, (error) => {
|
|
95
|
+
if (!error) return;
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
this.pending.delete(id);
|
|
98
|
+
resolve({ ok: false, error: operation === "screenshot" ? "capture_failed" : "input_failed" });
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
close() {
|
|
104
|
+
try { this.stdout?.close(); } catch {}
|
|
105
|
+
try { this.process?.kill(); } catch {}
|
|
106
|
+
this.stdout = null;
|
|
107
|
+
this.process = null;
|
|
108
|
+
}
|
|
109
|
+
}
|