@dmsdc-ai/aigentry-telepty 0.1.53 → 0.1.54
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/cli.js +7 -0
- package/daemon.js +34 -0
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -208,6 +208,13 @@ function getDiscoveryHosts() {
|
|
|
208
208
|
.filter(Boolean);
|
|
209
209
|
extraHosts.forEach((host) => hosts.add(host));
|
|
210
210
|
|
|
211
|
+
// Also include relay peers for cross-machine session discovery
|
|
212
|
+
const relayPeers = String(process.env.TELEPTY_RELAY_PEERS || '')
|
|
213
|
+
.split(',')
|
|
214
|
+
.map((host) => host.trim())
|
|
215
|
+
.filter(Boolean);
|
|
216
|
+
relayPeers.forEach((host) => hosts.add(host));
|
|
217
|
+
|
|
211
218
|
if (REMOTE_HOST && REMOTE_HOST !== '127.0.0.1') {
|
|
212
219
|
return Array.from(hosts);
|
|
213
220
|
}
|
package/daemon.js
CHANGED
|
@@ -39,6 +39,36 @@ app.use(express.json());
|
|
|
39
39
|
// Peer allowlist: comma-separated IPs/CIDRs in TELEPTY_PEER_ALLOWLIST env
|
|
40
40
|
const PEER_ALLOWLIST = (process.env.TELEPTY_PEER_ALLOWLIST || '').split(',').map(s => s.trim()).filter(Boolean);
|
|
41
41
|
|
|
42
|
+
// Cross-machine bus relay: forward bus events to peer daemons
|
|
43
|
+
const RELAY_PEERS = (process.env.TELEPTY_RELAY_PEERS || '').split(',').map(s => s.trim()).filter(Boolean);
|
|
44
|
+
const RELAY_SEEN = new Set(); // dedup by message_id
|
|
45
|
+
|
|
46
|
+
function relayToPeers(msg) {
|
|
47
|
+
if (RELAY_PEERS.length === 0) return;
|
|
48
|
+
if (!msg.message_id) msg.message_id = crypto.randomUUID();
|
|
49
|
+
if (RELAY_SEEN.has(msg.message_id)) return; // already relayed
|
|
50
|
+
RELAY_SEEN.add(msg.message_id);
|
|
51
|
+
// Prevent unbounded growth
|
|
52
|
+
if (RELAY_SEEN.size > 10000) {
|
|
53
|
+
const arr = [...RELAY_SEEN];
|
|
54
|
+
arr.splice(0, 5000);
|
|
55
|
+
RELAY_SEEN.clear();
|
|
56
|
+
arr.forEach(id => RELAY_SEEN.add(id));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
msg.source_host = msg.source_host || MACHINE_ID;
|
|
60
|
+
msg._relayed_from = MACHINE_ID;
|
|
61
|
+
|
|
62
|
+
for (const peer of RELAY_PEERS) {
|
|
63
|
+
fetch(`http://${peer}:${PORT}/api/bus/publish`, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: { 'Content-Type': 'application/json', 'x-telepty-token': EXPECTED_TOKEN },
|
|
66
|
+
body: JSON.stringify(msg),
|
|
67
|
+
signal: AbortSignal.timeout(3000)
|
|
68
|
+
}).catch(() => {}); // fire-and-forget
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
42
72
|
function isAllowedPeer(ip) {
|
|
43
73
|
if (!ip) return false;
|
|
44
74
|
const cleanIp = ip.replace('::ffff:', '');
|
|
@@ -976,6 +1006,8 @@ app.post('/api/bus/publish', (req, res) => {
|
|
|
976
1006
|
|
|
977
1007
|
// Auto-route if this is a turn_request
|
|
978
1008
|
busAutoRoute(payload);
|
|
1009
|
+
// Relay to peer daemons (dedup prevents loops)
|
|
1010
|
+
if (!payload._relayed_from) relayToPeers(payload);
|
|
979
1011
|
|
|
980
1012
|
res.json({ success: true, delivered: deliveredCount });
|
|
981
1013
|
});
|
|
@@ -1386,6 +1418,8 @@ busWss.on('connection', (ws, req) => {
|
|
|
1386
1418
|
|
|
1387
1419
|
// Auto-route turn_request events (shared logic with HTTP publish)
|
|
1388
1420
|
busAutoRoute(msg);
|
|
1421
|
+
// Relay to peer daemons (dedup prevents loops)
|
|
1422
|
+
if (!msg._relayed_from) relayToPeers(msg);
|
|
1389
1423
|
} catch (e) {
|
|
1390
1424
|
console.error('[BUS] Invalid message format', e);
|
|
1391
1425
|
}
|