@dmsdc-ai/aigentry-telepty 0.1.79 → 0.1.80
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/daemon.js +43 -4
- package/package.json +1 -1
package/daemon.js
CHANGED
|
@@ -13,6 +13,7 @@ const terminalBackend = require('./terminal-backend');
|
|
|
13
13
|
const config = getConfig();
|
|
14
14
|
const EXPECTED_TOKEN = config.authToken;
|
|
15
15
|
const MACHINE_ID = process.env.TELEPTY_MACHINE_ID || os.hostname();
|
|
16
|
+
const net = require('net');
|
|
16
17
|
const fs = require('fs');
|
|
17
18
|
const SESSION_PERSIST_PATH = require('path').join(os.homedir(), '.config', 'aigentry-telepty', 'sessions.json');
|
|
18
19
|
const SESSION_STALE_SECONDS = Math.max(1, Number(process.env.TELEPTY_SESSION_STALE_SECONDS || 60));
|
|
@@ -34,6 +35,8 @@ function persistSessions() {
|
|
|
34
35
|
cmuxSurfaceId: s.cmuxSurfaceId || null,
|
|
35
36
|
termProgram: s.termProgram || null,
|
|
36
37
|
term: s.term || null,
|
|
38
|
+
delivery: s.delivery || null,
|
|
39
|
+
deliveryEndpoint: s.deliveryEndpoint || null,
|
|
37
40
|
createdAt: s.createdAt,
|
|
38
41
|
lastActivityAt: s.lastActivityAt || null,
|
|
39
42
|
lastConnectedAt: s.lastConnectedAt || null,
|
|
@@ -219,7 +222,7 @@ function getSessionHealthStatus(session, options = {}) {
|
|
|
219
222
|
}
|
|
220
223
|
|
|
221
224
|
if (session.type === 'aterm') {
|
|
222
|
-
if (session.deliveryEndpoint) {
|
|
225
|
+
if (session.deliveryEndpoint || (session.delivery && session.delivery.address)) {
|
|
223
226
|
return 'CONNECTED';
|
|
224
227
|
}
|
|
225
228
|
if (disconnectedMs !== null && disconnectedMs >= staleMs) {
|
|
@@ -426,6 +429,33 @@ function emitInjectFailureEvent(sessionId, code, error, extra = {}, session = nu
|
|
|
426
429
|
|
|
427
430
|
async function writeDataToSession(id, session, data) {
|
|
428
431
|
if (session.type === 'aterm') {
|
|
432
|
+
// UDS delivery via net.connect()
|
|
433
|
+
if (session.delivery && session.delivery.transport === 'unix_socket' && session.delivery.address) {
|
|
434
|
+
return new Promise((resolve) => {
|
|
435
|
+
const payload = JSON.stringify({ text: data, session_id: id }) + '\n';
|
|
436
|
+
const timeout = setTimeout(() => {
|
|
437
|
+
sock.destroy();
|
|
438
|
+
resolve(buildErrorBody('TIMEOUT', 'UDS delivery timed out.', { httpStatus: 504 }));
|
|
439
|
+
}, DELIVERY_TIMEOUT_MS);
|
|
440
|
+
const sock = net.connect(session.delivery.address, () => {
|
|
441
|
+
sock.end(payload);
|
|
442
|
+
});
|
|
443
|
+
sock.on('data', () => {}); // drain
|
|
444
|
+
sock.on('end', () => {
|
|
445
|
+
clearTimeout(timeout);
|
|
446
|
+
resolve({ success: true });
|
|
447
|
+
});
|
|
448
|
+
sock.on('error', (err) => {
|
|
449
|
+
clearTimeout(timeout);
|
|
450
|
+
resolve(buildErrorBody('DISCONNECTED', 'UDS endpoint is unreachable.', {
|
|
451
|
+
httpStatus: 503,
|
|
452
|
+
detail: err.message
|
|
453
|
+
}));
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// HTTP delivery (backward compat)
|
|
429
459
|
if (!session.deliveryEndpoint) {
|
|
430
460
|
return buildErrorBody('DISCONNECTED', 'Delivery endpoint is missing.', { httpStatus: 503 });
|
|
431
461
|
}
|
|
@@ -504,7 +534,7 @@ async function deliverInjectionToSession(id, session, prompt, options = {}) {
|
|
|
504
534
|
strategy: session.type === 'wrapped'
|
|
505
535
|
? 'ws_split_cr'
|
|
506
536
|
: session.type === 'aterm'
|
|
507
|
-
? 'aterm_endpoint'
|
|
537
|
+
? (session.delivery && session.delivery.transport === 'unix_socket' ? 'aterm_uds' : 'aterm_endpoint')
|
|
508
538
|
: 'pty_split_cr',
|
|
509
539
|
submit: options.noEnter ? 'skipped' : 'deferred'
|
|
510
540
|
};
|
|
@@ -568,6 +598,7 @@ function serializeSession(id, session, options = {}) {
|
|
|
568
598
|
idleSeconds,
|
|
569
599
|
active_clients: session.clients ? session.clients.size : 0,
|
|
570
600
|
ready: session.ready || false,
|
|
601
|
+
delivery: session.delivery || null,
|
|
571
602
|
deliveryEndpoint: session.deliveryEndpoint || null,
|
|
572
603
|
healthStatus,
|
|
573
604
|
healthReason,
|
|
@@ -787,6 +818,12 @@ app.post('/api/sessions/register', (req, res) => {
|
|
|
787
818
|
if (Object.prototype.hasOwnProperty.call(req.body, 'term')) existing.term = term || null;
|
|
788
819
|
if (req.body.delivery_type) existing.type = req.body.delivery_type;
|
|
789
820
|
if (req.body.delivery_endpoint) existing.deliveryEndpoint = req.body.delivery_endpoint;
|
|
821
|
+
if (req.body.delivery) {
|
|
822
|
+
existing.delivery = req.body.delivery;
|
|
823
|
+
if (!existing.deliveryEndpoint && req.body.delivery.address) {
|
|
824
|
+
existing.deliveryEndpoint = req.body.delivery.address;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
790
827
|
if (req.body.delivery_type === 'aterm') {
|
|
791
828
|
existing.ready = true;
|
|
792
829
|
markSessionConnected(existing);
|
|
@@ -795,7 +832,8 @@ app.post('/api/sessions/register', (req, res) => {
|
|
|
795
832
|
return res.status(200).json({ session_id, type: existing.type, command: existing.command, cwd: existing.cwd, reregistered: true });
|
|
796
833
|
}
|
|
797
834
|
|
|
798
|
-
const { delivery_type, delivery_endpoint } = req.body;
|
|
835
|
+
const { delivery_type, delivery_endpoint, delivery } = req.body;
|
|
836
|
+
const resolvedEndpoint = delivery_endpoint || (delivery && delivery.address) || null;
|
|
799
837
|
const sessionRecord = {
|
|
800
838
|
id: session_id,
|
|
801
839
|
type: delivery_type || 'wrapped',
|
|
@@ -808,7 +846,8 @@ app.post('/api/sessions/register', (req, res) => {
|
|
|
808
846
|
cmuxSurfaceId: cmux_surface_id || null,
|
|
809
847
|
termProgram: term_program || null,
|
|
810
848
|
term: term || null,
|
|
811
|
-
|
|
849
|
+
delivery: delivery || null,
|
|
850
|
+
deliveryEndpoint: resolvedEndpoint,
|
|
812
851
|
createdAt: new Date().toISOString(),
|
|
813
852
|
lastActivityAt: new Date().toISOString(),
|
|
814
853
|
lastConnectedAt: delivery_type === 'aterm' ? new Date().toISOString() : null,
|