@dmsdc-ai/aigentry-telepty 0.1.47 → 0.1.49
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 +68 -1
- package/package.json +1 -1
package/daemon.js
CHANGED
|
@@ -1240,12 +1240,79 @@ busWss.on('connection', (ws, req) => {
|
|
|
1240
1240
|
ws.on('message', (message) => {
|
|
1241
1241
|
try {
|
|
1242
1242
|
const msg = JSON.parse(message);
|
|
1243
|
-
//
|
|
1243
|
+
// Broadcast to all other bus clients
|
|
1244
1244
|
busClients.forEach(client => {
|
|
1245
1245
|
if (client !== ws && client.readyState === 1) {
|
|
1246
1246
|
client.send(JSON.stringify(msg));
|
|
1247
1247
|
}
|
|
1248
1248
|
});
|
|
1249
|
+
|
|
1250
|
+
// Auto-router: turn_request / deliberation_route_turn → inject to target session PTY
|
|
1251
|
+
const isRoutable = (msg.type === 'turn_request' || msg.type === 'deliberation_route_turn' || msg.type === 'deliberation_turn_request') && (msg.target_session_id || msg.target || msg.session_id);
|
|
1252
|
+
if (isRoutable) {
|
|
1253
|
+
console.log(`[BUS-ROUTE] Received routable event: type=${msg.type} target=${msg.target_session_id || msg.target || msg.session_id}`);
|
|
1254
|
+
const rawTarget = msg.target_session_id || msg.target || msg.session_id;
|
|
1255
|
+
const targetId = resolveSessionAlias(rawTarget);
|
|
1256
|
+
const targetSession = targetId ? sessions[targetId] : null;
|
|
1257
|
+
if (targetSession) {
|
|
1258
|
+
const prompt = msg.content || msg.prompt || JSON.stringify(msg);
|
|
1259
|
+
const inject_id = crypto.randomUUID();
|
|
1260
|
+
|
|
1261
|
+
// Write to session (kitty primary, WS fallback)
|
|
1262
|
+
const sock = findKittySocket();
|
|
1263
|
+
if (!targetSession.kittyWindowId && sock) targetSession.kittyWindowId = findKittyWindowId(sock, targetId);
|
|
1264
|
+
const wid = targetSession.kittyWindowId;
|
|
1265
|
+
let delivered = false;
|
|
1266
|
+
|
|
1267
|
+
if (wid && sock && targetSession.type === 'wrapped') {
|
|
1268
|
+
try {
|
|
1269
|
+
const escaped = prompt.replace(/\\/g, '\\\\').replace(/'/g, "'\\''");
|
|
1270
|
+
require('child_process').execSync(`kitty @ --to unix:${sock} send-text --match id:${wid} '${escaped}'`, {
|
|
1271
|
+
timeout: 5000, stdio: ['pipe', 'pipe', 'pipe']
|
|
1272
|
+
});
|
|
1273
|
+
setTimeout(() => {
|
|
1274
|
+
try {
|
|
1275
|
+
require('child_process').execSync(`kitty @ --to unix:${sock} send-key --match id:${wid} Return`, {
|
|
1276
|
+
timeout: 3000, stdio: ['pipe', 'pipe', 'pipe']
|
|
1277
|
+
});
|
|
1278
|
+
} catch {}
|
|
1279
|
+
}, 500);
|
|
1280
|
+
delivered = true;
|
|
1281
|
+
} catch {}
|
|
1282
|
+
}
|
|
1283
|
+
if (!delivered) {
|
|
1284
|
+
// WS fallback
|
|
1285
|
+
if (targetSession.type === 'wrapped' && targetSession.ownerWs && targetSession.ownerWs.readyState === 1) {
|
|
1286
|
+
targetSession.ownerWs.send(JSON.stringify({ type: 'inject', data: prompt }));
|
|
1287
|
+
setTimeout(() => {
|
|
1288
|
+
if (targetSession.ownerWs && targetSession.ownerWs.readyState === 1) {
|
|
1289
|
+
targetSession.ownerWs.send(JSON.stringify({ type: 'inject', data: '\r' }));
|
|
1290
|
+
}
|
|
1291
|
+
}, 300);
|
|
1292
|
+
delivered = true;
|
|
1293
|
+
} else if (targetSession.ptyProcess) {
|
|
1294
|
+
targetSession.ptyProcess.write(prompt);
|
|
1295
|
+
setTimeout(() => targetSession.ptyProcess.write('\r'), 300);
|
|
1296
|
+
delivered = true;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// Emit inject_written ack
|
|
1301
|
+
const ackMsg = JSON.stringify({
|
|
1302
|
+
type: 'inject_written',
|
|
1303
|
+
inject_id,
|
|
1304
|
+
sender: 'daemon',
|
|
1305
|
+
target_agent: targetId,
|
|
1306
|
+
source_type: 'bus_auto_route',
|
|
1307
|
+
delivered,
|
|
1308
|
+
timestamp: new Date().toISOString()
|
|
1309
|
+
});
|
|
1310
|
+
busClients.forEach(client => {
|
|
1311
|
+
if (client.readyState === 1) client.send(ackMsg);
|
|
1312
|
+
});
|
|
1313
|
+
console.log(`[BUS-ROUTE] turn_request → ${targetId}: ${delivered ? 'delivered' : 'failed'}`);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1249
1316
|
} catch (e) {
|
|
1250
1317
|
console.error('[BUS] Invalid message format', e);
|
|
1251
1318
|
}
|