agentroam 0.2.0-preview.41 → 0.2.0-preview.43
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.
|
@@ -4,6 +4,12 @@ import { promisify } from "node:util";
|
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { DesktopProbeRpcError, readDesktopActivity, withDesktopRpc } from "./codex-desktop-probe.js";
|
|
6
6
|
const execFileAsync = promisify(execFile);
|
|
7
|
+
function isUnsupportedGatewayMethod(error) {
|
|
8
|
+
if (!(error instanceof DesktopProbeRpcError))
|
|
9
|
+
return false;
|
|
10
|
+
return error.code === -32601 || (error.code === -32600
|
|
11
|
+
&& error.message.startsWith("Invalid request: unknown variant `account/gatewayOAuth/read`, expected one of "));
|
|
12
|
+
}
|
|
7
13
|
async function inspectBackend(endpoint) {
|
|
8
14
|
return withDesktopRpc(endpoint, async (request, becameActive) => {
|
|
9
15
|
try {
|
|
@@ -13,7 +19,7 @@ async function inspectBackend(endpoint) {
|
|
|
13
19
|
}
|
|
14
20
|
catch (error) {
|
|
15
21
|
// Older servers may not have the Desktop gateway RPC.
|
|
16
|
-
if (!(error
|
|
22
|
+
if (!isUnsupportedGatewayMethod(error))
|
|
17
23
|
throw error;
|
|
18
24
|
}
|
|
19
25
|
return true;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createConnection } from "node:net";
|
|
2
|
+
import WebSocket from "ws";
|
|
2
3
|
export class DesktopProbeRpcError extends Error {
|
|
3
4
|
code;
|
|
4
5
|
constructor(code, message) {
|
|
@@ -19,18 +20,18 @@ export async function probeDesktopActivity(endpoint, timeoutMs = 5_000) {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
export async function withDesktopRpc(endpoint, operation, timeoutMs = 5_000) {
|
|
22
|
-
let dispatcher;
|
|
23
23
|
let socket;
|
|
24
24
|
let timer;
|
|
25
25
|
let rejectPending;
|
|
26
26
|
try {
|
|
27
27
|
const address = new URL(endpoint);
|
|
28
28
|
let url = endpoint;
|
|
29
|
+
let socketPath;
|
|
29
30
|
if (address.protocol === "ws+unix:") {
|
|
30
31
|
const separator = address.pathname.indexOf(":");
|
|
31
32
|
if (address.hostname !== "localhost" || separator < 1)
|
|
32
33
|
throw new Error("invalid local socket");
|
|
33
|
-
|
|
34
|
+
socketPath = decodeURIComponent(address.pathname.slice(0, separator));
|
|
34
35
|
url = `ws://localhost${address.pathname.slice(separator + 1)}`;
|
|
35
36
|
}
|
|
36
37
|
else if (!(["ws:", "wss:"].includes(address.protocol)
|
|
@@ -39,27 +40,32 @@ export async function withDesktopRpc(endpoint, operation, timeoutMs = 5_000) {
|
|
|
39
40
|
}
|
|
40
41
|
if (address.username || address.password || address.search || address.hash)
|
|
41
42
|
throw new Error("invalid endpoint");
|
|
42
|
-
socket = new WebSocket(url,
|
|
43
|
+
socket = new WebSocket(url, {
|
|
44
|
+
...(socketPath ? { createConnection: () => createConnection({ path: socketPath }) } : {}),
|
|
45
|
+
handshakeTimeout: timeoutMs,
|
|
46
|
+
// Older Codex backends reject a Sec-WebSocket-Extensions offer.
|
|
47
|
+
perMessageDeflate: false,
|
|
48
|
+
});
|
|
43
49
|
const connection = socket;
|
|
44
50
|
let nextId = 0;
|
|
45
51
|
let changedToActive = false;
|
|
46
52
|
const pending = new Map();
|
|
47
|
-
const fail = () => {
|
|
53
|
+
const fail = (error = new Error("Desktop probe disconnected")) => {
|
|
48
54
|
for (const item of pending.values())
|
|
49
|
-
item.reject(
|
|
55
|
+
item.reject(error);
|
|
50
56
|
pending.clear();
|
|
51
57
|
};
|
|
52
58
|
rejectPending = fail;
|
|
53
59
|
const opened = new Promise((resolve, reject) => {
|
|
54
|
-
connection.
|
|
55
|
-
connection.
|
|
56
|
-
connection.
|
|
60
|
+
connection.once("open", () => resolve());
|
|
61
|
+
connection.once("error", (error) => reject(new Error(`Desktop probe connection failed: ${error.message}`, { cause: error })));
|
|
62
|
+
connection.once("close", () => reject(new Error("Desktop probe disconnected")));
|
|
57
63
|
});
|
|
58
|
-
connection.
|
|
59
|
-
connection.
|
|
60
|
-
connection.
|
|
64
|
+
connection.on("error", fail);
|
|
65
|
+
connection.on("close", () => fail());
|
|
66
|
+
connection.on("message", (data) => {
|
|
61
67
|
try {
|
|
62
|
-
const message = JSON.parse(String(
|
|
68
|
+
const message = JSON.parse(String(data));
|
|
63
69
|
if (message.method === "thread/status/changed" && message.params?.status?.type === "active")
|
|
64
70
|
changedToActive = true;
|
|
65
71
|
const item = pending.get(message.id);
|
|
@@ -101,8 +107,7 @@ export async function withDesktopRpc(endpoint, operation, timeoutMs = 5_000) {
|
|
|
101
107
|
if (timer)
|
|
102
108
|
clearTimeout(timer);
|
|
103
109
|
rejectPending?.();
|
|
104
|
-
socket?.
|
|
105
|
-
await dispatcher?.destroy();
|
|
110
|
+
socket?.terminate();
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
export async function readDesktopActivity(request) {
|
|
@@ -51,7 +51,7 @@ export async function resolveOpenCodeRuntime(options) {
|
|
|
51
51
|
return install({ ...options, environment, platform, dependencies, managedRoot });
|
|
52
52
|
}
|
|
53
53
|
export function parseOpenCodeVersion(output) {
|
|
54
|
-
return output.match(/(?:^|\s)((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(?:\s|$)/)?.[1] ?? null;
|
|
54
|
+
return output.match(/(?:^|\s)v?((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(?:\s|$)/)?.[1] ?? null;
|
|
55
55
|
}
|
|
56
56
|
export function managedOpenCodeBinaryCandidates(root, platform) {
|
|
57
57
|
return platform === "win32"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentroam",
|
|
3
|
-
"version": "0.2.0-preview.
|
|
3
|
+
"version": "0.2.0-preview.43",
|
|
4
4
|
"description": "Zero-install mobile remote terminal and file console",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,19 +23,21 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"qrcode-terminal": "^0.12.0",
|
|
26
|
-
"undici": "^6.25.0"
|
|
26
|
+
"undici": "^6.25.0",
|
|
27
|
+
"ws": "^8.21.3"
|
|
27
28
|
},
|
|
28
29
|
"optionalDependencies": {
|
|
29
|
-
"agentroam-runtime-darwin-arm64": "0.2.0-preview.
|
|
30
|
-
"agentroam-runtime-win32-x64": "0.2.0-preview.
|
|
30
|
+
"agentroam-runtime-darwin-arm64": "0.2.0-preview.43",
|
|
31
|
+
"agentroam-runtime-win32-x64": "0.2.0-preview.43",
|
|
31
32
|
"agentroam-cloudflared-darwin-arm64": "0.2.0-preview.39",
|
|
32
33
|
"agentroam-cloudflared-win32-x64": "0.2.0-preview.39",
|
|
33
|
-
"agentroam-tui-darwin-arm64": "0.2.0-preview.
|
|
34
|
-
"@caoqu/agentroam-tui-win32-x64": "0.2.0-preview.
|
|
34
|
+
"agentroam-tui-darwin-arm64": "0.2.0-preview.43",
|
|
35
|
+
"@caoqu/agentroam-tui-win32-x64": "0.2.0-preview.43"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/node": "^22.0.0",
|
|
38
39
|
"@types/qrcode-terminal": "^0.12.2",
|
|
40
|
+
"@types/ws": "^8.18.1",
|
|
39
41
|
"typescript": "^5.6.0",
|
|
40
42
|
"vitest": "^2.1.0"
|
|
41
43
|
},
|