@dotrino/remote-agent 0.3.2 → 0.4.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.
package/README.md CHANGED
@@ -62,6 +62,10 @@ const ra = await startRemoteAgent({
62
62
  onRevoked () { console.log('me revocaron') }
63
63
  })
64
64
  // ra.machine, ra.machineId, ra.master, ra.close()
65
+ // ra.client → el WebSocketProxyClient ya conectado e identificado bajo esta
66
+ // máquina. Si tu agente necesita algo más del transporte (anunciarse en un
67
+ // canal, por ejemplo), REUSA este: abrir una segunda conexión sería un segundo
68
+ // `identify`, una segunda identidad de transporte y una segunda cola.
65
69
  ```
66
70
 
67
71
  Enrolar la máquina (una vez, con el QR del vault):
package/node-globals.js CHANGED
@@ -34,7 +34,24 @@ let _installed = false
34
34
  export function installNodeGlobals (dir) {
35
35
  if (_installed) return
36
36
  if (typeof globalThis.WebSocket === 'undefined') globalThis.WebSocket = WebSocket
37
- // Node ≥22 expone un `localStorage` no funcional sin flag → forzamos el shim.
38
- globalThis.localStorage = fileLocalStorage(path.join(dir, 'transport.json'))
37
+
38
+ // Node ≥22 expone un `localStorage` NO funcional sin `--localstorage-file`, así
39
+ // que aquí se pone el shim de archivo igual. Pero se pone con `defineProperty` y
40
+ // NO asignando:
41
+ //
42
+ // · lo que Node define es un ACCESOR (getter/setter nativos), y asignarle
43
+ // revienta con «Cannot assign to read only property 'localStorage'» — medido
44
+ // en Node 25.9. Con la asignación, cualquier agente headless dejaba de
45
+ // arrancar su plano de control en un Node moderno, y el mensaje no decía nada
46
+ // de esto;
47
+ // · el descriptor tampoco se LEE (nada de `globalThis.localStorage`): tocar el
48
+ // getter nativo sin el flag emite un warning por consola.
49
+ //
50
+ // Es lo mismo que hace `@dotrino/vault`, que ya se topó con esto.
51
+ Object.defineProperty(globalThis, 'localStorage', {
52
+ configurable: true,
53
+ writable: true,
54
+ value: fileLocalStorage(path.join(dir, 'transport.json'))
55
+ })
39
56
  _installed = true
40
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/remote-agent",
3
- "version": "0.3.2",
3
+ "version": "0.4.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",
@@ -19,12 +19,12 @@
19
19
  "src"
20
20
  ],
21
21
  "scripts": {
22
- "test": "node -e \"import('@dotrino/remote-agent').then(()=>console.log('ok'))\"",
22
+ "test": "node --test 'test/**/*.test.js'",
23
23
  "type-check": "tsc --noEmit"
24
24
  },
25
25
  "dependencies": {
26
26
  "@dotrino/identity": "0.53.0",
27
- "@dotrino/proxy-client": "0.10.0",
27
+ "@dotrino/proxy-client": "0.10.1",
28
28
  "ws": "8.21.0"
29
29
  },
30
30
  "engines": {
package/src/agent.js CHANGED
@@ -74,6 +74,13 @@ class AgentSession {
74
74
  * @param {()=>void} [opts.onReady] agente listo y escuchando.
75
75
  * @param {boolean} [opts.quiet] sin logs.
76
76
  * @param {object} [opts.client] transporte ya conectado (SOLO pruebas).
77
+ *
78
+ * Devuelve además el **`client`** (el `WebSocketProxyClient` ya conectado e
79
+ * identificado bajo la pubkey de esta máquina). Se expone a propósito: un agente
80
+ * que necesite algo más del transporte —anunciarse en un canal, por ejemplo— debe
81
+ * reusar ESTA conexión y no abrir otra. Dos conexiones del mismo aparato al proxy
82
+ * son dos identidades de transporte, dos `identify` y dos colas: exactamente el
83
+ * lío que este middleware existe para evitar.
77
84
  */
78
85
  export async function startRemoteAgent (opts = {}) {
79
86
  const dir = opts.dir || dataDir()
@@ -279,7 +286,7 @@ export async function startRemoteAgent (opts = {}) {
279
286
  }
280
287
  if (opts.onReady) { try { opts.onReady({ machine: myPub, machineId: myId, master }) } catch (_) {} }
281
288
 
282
- return { machine: myPub, machineId: myId, master, close: stop }
289
+ return { machine: myPub, machineId: myId, master, client, close: stop }
283
290
  }
284
291
 
285
292
  export default { startRemoteAgent }