@dotrino/remote-agent 0.26.0 → 0.27.0
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/package.json +1 -1
- package/src/agent.js +13 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/remote-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Middleware compartido del ecosistema Dotrino para apps de agente remoto cifrado punto a punto (handshake E2E, emparejamiento SAS con vault, revocación, descubrimiento). Lo consumen dotrino-terminal (PTY) y dotrino-ia (chat con IA).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
package/src/agent.js
CHANGED
|
@@ -121,6 +121,7 @@ export class AgentSession {
|
|
|
121
121
|
* @param {()=>void} [opts.onReady] agente listo y escuchando.
|
|
122
122
|
* @param {boolean} [opts.quiet] sin logs.
|
|
123
123
|
* @param {number} [opts.sessionGoneMs] cuánto se espera a un cliente cuya conexión se fue (`SESSION_GONE_MS`).
|
|
124
|
+
* @param {number} [opts.sessionTtlMs] cuánto dura una sesión sin mensajes (`SESSION_TTL_MS`, 30 min).
|
|
124
125
|
* @param {number} [opts.netLogMs] cada cuánto van al log las estadísticas de red (5 min).
|
|
125
126
|
* @param {object} [opts.client] transporte ya conectado (SOLO pruebas).
|
|
126
127
|
* @param {string} [opts.product] qué producto es (`accounts`, `terminal-agent`…), para el anuncio a la bóveda.
|
|
@@ -369,12 +370,20 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
369
370
|
vaultTick()
|
|
370
371
|
const revTimer = setInterval(vaultTick, REVOKE_REFRESH_MS); revTimer.unref?.()
|
|
371
372
|
|
|
373
|
+
const ttlMs = opts.sessionTtlMs ?? SESSION_TTL_MS
|
|
374
|
+
// UNA SESIÓN QUE VENCE SE LE DICE AL CLIENTE en ese momento, con el mismo `unknown-session`
|
|
375
|
+
// que recibiría al mandar algo. Antes vencía callada: la ventana de una consola quieta seguía
|
|
376
|
+
// pareciendo abierta y solo se enteraba al teclear, con la consola ya perdida (2026-11-04).
|
|
377
|
+
// Así el cliente vuelve a saludar enseguida y la app decide qué enseña.
|
|
372
378
|
const sweeper = setInterval(() => {
|
|
373
379
|
const now = Date.now()
|
|
374
380
|
for (const [sid, s] of sessions) {
|
|
375
|
-
if (now > s._exp) {
|
|
381
|
+
if (now > s._exp) {
|
|
382
|
+
s.close(); sessions.delete(sid); audit('session-expire', { sid: sid.slice(0, 8) })
|
|
383
|
+
if (!s._gone) send(s.from, { type: ERROR, code: 'unknown-session', sid, error: 'unknown or expired session' })
|
|
384
|
+
}
|
|
376
385
|
}
|
|
377
|
-
}, 60 * 1000); sweeper.unref?.()
|
|
386
|
+
}, Math.min(60 * 1000, ttlMs)); sweeper.unref?.()
|
|
378
387
|
|
|
379
388
|
async function handleHandshake (from, p) {
|
|
380
389
|
const { data, signature, cert } = p
|
|
@@ -439,7 +448,7 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
439
448
|
const { signature: ackSig } = await signWithDevice({ privateJwk: link.device.privateJwk, data: ack })
|
|
440
449
|
|
|
441
450
|
const session = new AgentSession({ sid, key, from, device: chk.device, send, isDirect: typeof client.isWebRTCOpen === 'function' ? (t) => client.isWebRTCOpen(t) : null })
|
|
442
|
-
session._exp = Date.now() +
|
|
451
|
+
session._exp = Date.now() + ttlMs
|
|
443
452
|
// El papel con que entró: si después se retira (`revoked`), la sesión se cierra.
|
|
444
453
|
session._certNonce = cert.nonce || null
|
|
445
454
|
sessions.set(sid, session)
|
|
@@ -455,7 +464,7 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
455
464
|
// se reinició, o venció) y vuelve a saludar solo, en vez de quedarse con un error. Se
|
|
456
465
|
// comprueba por el código, no por la frase.
|
|
457
466
|
if (!s) return send(from, { type: ERROR, code: 'unknown-session', sid: p.sid, error: 'unknown or expired session' })
|
|
458
|
-
s._exp = Date.now() +
|
|
467
|
+
s._exp = Date.now() + ttlMs
|
|
459
468
|
s.from = from
|
|
460
469
|
if (s._gone) { clearTimeout(s._gone); s._gone = null }
|
|
461
470
|
s._ingest(p.env).catch(() => send(from, { type: ERROR, error: 'invalid envelope' }))
|