arena-bridge 0.18.15 → 0.18.16
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/catalog.mjs +9 -0
- package/src/device.mjs +30 -5
- package/src/hub.mjs +18 -4
- package/src/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All notable changes to this project are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/) and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## 0.18.16
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- The macOS app no longer refreshes the full interface for every SSE heartbeat; background refreshes are coalesced, spaced out, and publish state only when it changes.
|
|
11
|
+
- Hub devices retry result delivery after transient network failures, and expired queued jobs are removed instead of executing later.
|
|
12
|
+
- Hub job queues are bounded and completed process sessions are pruned after retention.
|
|
13
|
+
|
|
7
14
|
## 0.18.15
|
|
8
15
|
|
|
9
16
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arena-bridge",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.16",
|
|
4
4
|
"description": "Give a cloud AI agent (Arena.ai Agent Mode, Claude, Cursor, ...) controlled access to your own machine over HTTP/MCP: files, shell, Chrome and the macOS desktop, with an approval gate, trust windows and an audit log.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/catalog.mjs
CHANGED
|
@@ -9,6 +9,13 @@ import { clip, runShell } from './engine_helpers.mjs';
|
|
|
9
9
|
import { errorResponse } from './errors.mjs';
|
|
10
10
|
|
|
11
11
|
let lastNoteAt = 0;
|
|
12
|
+
const SESSION_RETENTION_MS = 10 * 60 * 1000;
|
|
13
|
+
|
|
14
|
+
function pruneSessions(sessions, now = Date.now()) {
|
|
15
|
+
for (const [id, session] of sessions) {
|
|
16
|
+
if (session.exited && session.endedAt && now - session.endedAt > SESSION_RETENTION_MS) sessions.delete(id);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
12
19
|
|
|
13
20
|
const S = (o) => ({ type: 'object', properties: o, required: [], additionalProperties: false });
|
|
14
21
|
|
|
@@ -448,6 +455,7 @@ export function toolCatalog() {
|
|
|
448
455
|
handler: async (args, ctx) => {
|
|
449
456
|
const command = String(args.command ?? '');
|
|
450
457
|
if (!command.trim()) return { ok: false, error: 'command is required' };
|
|
458
|
+
pruneSessions(ctx.sessions);
|
|
451
459
|
const base = args.cwd ? resolveTarget(args.cwd, ctx.base) : ctx.base;
|
|
452
460
|
const chk = checkPath(base, ctx.cfg, ctx.base);
|
|
453
461
|
if (!chk.ok) return { ok: false, error: chk.error, reason: chk.reason };
|
|
@@ -489,6 +497,7 @@ export function toolCatalog() {
|
|
|
489
497
|
child.on('close', (code) => {
|
|
490
498
|
session.exited = true;
|
|
491
499
|
session.exitCode = code;
|
|
500
|
+
session.endedAt = Date.now();
|
|
492
501
|
});
|
|
493
502
|
// R6: limit bash sessions to 20, cleanup oldest
|
|
494
503
|
if (ctx.sessions.size >= 20) {
|
package/src/device.mjs
CHANGED
|
@@ -4,6 +4,35 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
6
6
|
|
|
7
|
+
/** Retry a result while the hub may still be waiting for it. A 404 means the job expired. */
|
|
8
|
+
export async function postResult(base, headers, payload, {
|
|
9
|
+
fetchImpl = fetch,
|
|
10
|
+
sleepImpl = sleep,
|
|
11
|
+
log = () => {},
|
|
12
|
+
maxAttempts = 8,
|
|
13
|
+
} = {}) {
|
|
14
|
+
let delay = 1000;
|
|
15
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
16
|
+
try {
|
|
17
|
+
const res = await fetchImpl(`${base}/device/result`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers,
|
|
20
|
+
body: JSON.stringify(payload),
|
|
21
|
+
});
|
|
22
|
+
if (res.ok) return true;
|
|
23
|
+
if (res.status === 404) return false;
|
|
24
|
+
log(`[device] result failed: HTTP ${res.status} (attempt ${attempt}/${maxAttempts})`);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
log(`[device] result connection error (attempt ${attempt}/${maxAttempts}): ${e.message}`);
|
|
27
|
+
}
|
|
28
|
+
if (attempt < maxAttempts) {
|
|
29
|
+
await sleepImpl(delay);
|
|
30
|
+
delay = Math.min(delay * 2, 30_000);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
7
36
|
export async function runDevice(cfg, engine, { log = console.log } = {}) {
|
|
8
37
|
const base = String(cfg.hub || '').replace(/\/+$/, '');
|
|
9
38
|
if (!base) throw new Error('cfg.hub is required in hub mode');
|
|
@@ -48,11 +77,7 @@ export async function runDevice(cfg, engine, { log = console.log } = {}) {
|
|
|
48
77
|
result = { ok: false, error: e.message };
|
|
49
78
|
}
|
|
50
79
|
|
|
51
|
-
await
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers,
|
|
54
|
-
body: JSON.stringify({ id: job.id, result }),
|
|
55
|
-
});
|
|
80
|
+
await postResult(base, headers, { id: job.id, result }, { log });
|
|
56
81
|
} catch (e) {
|
|
57
82
|
log(`[device] connection error: ${e.message}`);
|
|
58
83
|
await sleep(backoff);
|
package/src/hub.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { audit } from './audit.mjs';
|
|
|
13
13
|
import { sourceOf, describeSource, admitUnauthorized } from './source.mjs';
|
|
14
14
|
|
|
15
15
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
16
|
+
const MAX_QUEUED_PER_DEVICE = 100;
|
|
16
17
|
|
|
17
18
|
function deviceTokens(cfg) {
|
|
18
19
|
const list = [];
|
|
@@ -34,10 +35,23 @@ export function createHubServer(cfg) {
|
|
|
34
35
|
const queues = new Map(); // name -> [{id, tool, args}]
|
|
35
36
|
const jobs = new Map(); // id -> { resolve, timer }
|
|
36
37
|
|
|
37
|
-
const
|
|
38
|
-
|
|
38
|
+
const removeQueued = (device, id) => {
|
|
39
|
+
const q = queues.get(device);
|
|
40
|
+
if (!q) return;
|
|
41
|
+
const remaining = q.filter((job) => job.id !== id);
|
|
42
|
+
if (remaining.length) queues.set(device, remaining);
|
|
43
|
+
else queues.delete(device);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const dispatch = (device, tool, args, timeoutSec = 120, source = null) => {
|
|
47
|
+
const q = queues.get(device) || [];
|
|
48
|
+
if (q.length >= MAX_QUEUED_PER_DEVICE) {
|
|
49
|
+
return Promise.resolve({ ok: false, error: 'DEVICE_BUSY', reason: `device "${device}" has too many queued jobs` });
|
|
50
|
+
}
|
|
51
|
+
return new Promise((resolve) => {
|
|
39
52
|
const id = crypto.randomUUID();
|
|
40
53
|
const timer = setTimeout(() => {
|
|
54
|
+
removeQueued(device, id);
|
|
41
55
|
jobs.delete(id);
|
|
42
56
|
resolve({
|
|
43
57
|
ok: false,
|
|
@@ -46,10 +60,10 @@ export function createHubServer(cfg) {
|
|
|
46
60
|
});
|
|
47
61
|
}, (timeoutSec + 15) * 1000);
|
|
48
62
|
jobs.set(id, { resolve, timer });
|
|
49
|
-
const q = queues.get(device) || [];
|
|
50
63
|
q.push({ id, tool, args, source });
|
|
51
64
|
queues.set(device, q);
|
|
52
65
|
});
|
|
66
|
+
};
|
|
53
67
|
|
|
54
68
|
const callTool = async (tool, args, source = null) => {
|
|
55
69
|
const device = args?.device || cfg.device;
|
|
@@ -259,4 +273,4 @@ export function createHubServer(cfg) {
|
|
|
259
273
|
return server;
|
|
260
274
|
}
|
|
261
275
|
|
|
262
|
-
export { sleep };
|
|
276
|
+
export { sleep };
|