@anusornneal/chat-relay 0.7.2 → 0.8.1

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.
@@ -0,0 +1,67 @@
1
+ import fs from "node:fs";
2
+
3
+ export const AGENT_PROTOCOL_VERSION = 1;
4
+
5
+ let cachedVersion = null;
6
+
7
+ export function getAgentVersion() {
8
+ if (cachedVersion) return cachedVersion;
9
+ try {
10
+ const packageUrl = new URL("../package.json", import.meta.url);
11
+ const parsed = JSON.parse(fs.readFileSync(packageUrl, "utf8"));
12
+ cachedVersion = typeof parsed.version === "string" && parsed.version ? parsed.version : "0.0.0";
13
+ } catch {
14
+ cachedVersion = "0.0.0";
15
+ }
16
+ return cachedVersion;
17
+ }
18
+
19
+ export function getAgentCapabilities(options = {}) {
20
+ const terminalEnabled = options.terminalEnabled === true;
21
+ const desktopEnabled = options.desktopEnabled === true;
22
+ const platform = String(options.platform || process.platform);
23
+
24
+ const capabilities = [
25
+ "transport.heartbeat",
26
+ "filesystem.stat",
27
+ "filesystem.list",
28
+ "filesystem.read",
29
+ "filesystem.readMany",
30
+ "filesystem.batch",
31
+ "filesystem.artifact",
32
+ "filesystem.write",
33
+ "filesystem.edit",
34
+ "filesystem.mkdir",
35
+ "filesystem.move",
36
+ "filesystem.delete",
37
+ "filesystem.search",
38
+ "process.list",
39
+ "process.kill",
40
+ ];
41
+
42
+ if (terminalEnabled) {
43
+ capabilities.push("terminal.exec", "terminal.sessions", "terminal.batch");
44
+ }
45
+
46
+ if (desktopEnabled && ["win32", "darwin"].includes(platform)) {
47
+ capabilities.push("desktop.screenshot", "desktop.control", "desktop.step");
48
+ }
49
+
50
+ return capabilities;
51
+ }
52
+
53
+ export function buildAgentHello(options = {}) {
54
+ const platform = String(options.platform || process.platform);
55
+ return {
56
+ control: "agent_hello",
57
+ protocolVersion: Number(options.protocolVersion ?? AGENT_PROTOCOL_VERSION),
58
+ agentVersion: String(options.agentVersion || getAgentVersion()),
59
+ platform,
60
+ arch: String(options.arch || process.arch),
61
+ capabilities: getAgentCapabilities({
62
+ terminalEnabled: options.terminalEnabled === true,
63
+ desktopEnabled: options.desktopEnabled === true,
64
+ platform,
65
+ }),
66
+ };
67
+ }