@dotrino/remote-agent 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/agent.js +8 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/remote-agent",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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
@@ -127,11 +127,16 @@ export async function startRemoteAgent (opts = {}) {
127
127
  async function vaultRpc (sendType, okType, data, timeoutMs = 15000) {
128
128
  const { signature } = await signWithDevice({ privateJwk: link.device.privateJwk, data })
129
129
  return new Promise((resolve, reject) => {
130
+ // El temporizador se LIMPIA al contestar (y no retiene el bucle de eventos):
131
+ // sin eso, cada consulta al vault dejaba 15 s de espera pendiente y un proceso
132
+ // corto que solo quería preguntar algo se quedaba colgado hasta que vencía.
133
+ const done = (fn, v) => { off(); clearTimeout(timer); fn(v) }
130
134
  const off = client.on('message', (_f, p) => {
131
- if (p?.type === okType) { off(); resolve(p) }
132
- else if (p?.type === VMSG.ERROR) { off(); reject(new Error(p.error)) }
135
+ if (p?.type === okType) done(resolve, p)
136
+ else if (p?.type === VMSG.ERROR) done(reject, new Error(p.error))
133
137
  })
134
- setTimeout(() => { off(); reject(new Error('timeout')) }, timeoutMs)
138
+ const timer = setTimeout(() => done(reject, new Error('timeout')), timeoutMs)
139
+ timer.unref?.()
135
140
  client.sendByPubkey(master, { type: sendType, data, signature, cert: link.cert })
136
141
  })
137
142
  }