@agentvault/secure-channel 0.6.10 → 0.6.12

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/dist/channel.d.ts CHANGED
@@ -18,6 +18,7 @@ export declare class SecureChannel extends EventEmitter {
18
18
  private _ackTimer;
19
19
  private _stopped;
20
20
  private _persisted;
21
+ private _httpServer;
21
22
  private static readonly PING_INTERVAL_MS;
22
23
  private static readonly PING_TIMEOUT_MS;
23
24
  constructor(config: SecureChannelConfig);
@@ -43,6 +44,8 @@ export declare class SecureChannel extends EventEmitter {
43
44
  topicId?: string;
44
45
  }): Promise<void>;
45
46
  stop(): Promise<void>;
47
+ startHttpServer(port: number): void;
48
+ private _stopHttpServer;
46
49
  /**
47
50
  * Create a new topic within the conversation group.
48
51
  * Requires the channel to be initialized with a groupId (from activation).
@@ -1 +1 @@
1
- {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAa3C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAKb,MAAM,YAAY,CAAC;AAiDpB,qBAAa,aAAc,SAAQ,YAAY;IAwBjC,OAAO,CAAC,MAAM;IAvB1B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,sBAAsB,CAAc;IAC5C,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,SAAS,CAGH;IACd,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,eAAe,CAA8C;IACrE,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,YAAY,CAA8C;IAClE,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,SAAS,CAA8C;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mB;IAkEjC;;;OAGG;YACW,mBAAmB;IA+FjC,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,YAAY;IAKpB;;;OAGG;YACW,aAAa;CAc5B"}
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  // src/channel.ts
4
4
  import { EventEmitter } from "node:events";
5
+ import { createServer } from "node:http";
5
6
  import { randomUUID } from "node:crypto";
6
7
 
7
8
  // ../../node_modules/libsodium-sumo/dist/modules-sumo-esm/libsodium-sumo.mjs
@@ -45083,6 +45084,7 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45083
45084
  _ackTimer = null;
45084
45085
  _stopped = false;
45085
45086
  _persisted = null;
45087
+ _httpServer = null;
45086
45088
  static PING_INTERVAL_MS = 3e4;
45087
45089
  // Send ping every 30s
45088
45090
  static PING_TIMEOUT_MS = 1e4;
@@ -45195,6 +45197,7 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45195
45197
  this._stopped = true;
45196
45198
  this._flushAcks();
45197
45199
  this._stopPing();
45200
+ this._stopHttpServer();
45198
45201
  if (this._ackTimer) {
45199
45202
  clearTimeout(this._ackTimer);
45200
45203
  this._ackTimer = null;
@@ -45214,6 +45217,61 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45214
45217
  }
45215
45218
  this._setState("disconnected");
45216
45219
  }
45220
+ // --- Local HTTP server for proactive sends ---
45221
+ startHttpServer(port) {
45222
+ if (this._httpServer) return;
45223
+ this._httpServer = createServer(async (req, res) => {
45224
+ const remote = req.socket.remoteAddress;
45225
+ if (remote !== "127.0.0.1" && remote !== "::1" && remote !== "::ffff:127.0.0.1") {
45226
+ res.writeHead(403, { "Content-Type": "application/json" });
45227
+ res.end(JSON.stringify({ ok: false, error: "Forbidden" }));
45228
+ return;
45229
+ }
45230
+ if (req.method === "POST" && req.url === "/send") {
45231
+ let body = "";
45232
+ req.on("data", (chunk) => {
45233
+ body += chunk.toString();
45234
+ });
45235
+ req.on("end", async () => {
45236
+ try {
45237
+ const parsed = JSON.parse(body);
45238
+ const text = parsed.text;
45239
+ if (!text || typeof text !== "string") {
45240
+ res.writeHead(400, { "Content-Type": "application/json" });
45241
+ res.end(JSON.stringify({ ok: false, error: "Missing 'text' field" }));
45242
+ return;
45243
+ }
45244
+ await this.send(text, { topicId: parsed.topicId });
45245
+ res.writeHead(200, { "Content-Type": "application/json" });
45246
+ res.end(JSON.stringify({ ok: true }));
45247
+ } catch (err) {
45248
+ res.writeHead(500, { "Content-Type": "application/json" });
45249
+ res.end(JSON.stringify({ ok: false, error: String(err) }));
45250
+ }
45251
+ });
45252
+ } else if (req.method === "GET" && req.url === "/status") {
45253
+ res.writeHead(200, { "Content-Type": "application/json" });
45254
+ res.end(JSON.stringify({
45255
+ ok: true,
45256
+ state: this._state,
45257
+ deviceId: this._deviceId,
45258
+ sessions: this._sessions.size
45259
+ }));
45260
+ } else {
45261
+ res.writeHead(404, { "Content-Type": "application/json" });
45262
+ res.end(JSON.stringify({ ok: false, error: "Not found. Use POST /send or GET /status" }));
45263
+ }
45264
+ });
45265
+ this._httpServer.listen(port, "127.0.0.1", () => {
45266
+ this.emit("http-ready", port);
45267
+ });
45268
+ }
45269
+ _stopHttpServer() {
45270
+ if (this._httpServer) {
45271
+ this._httpServer.close();
45272
+ this._httpServer = null;
45273
+ }
45274
+ }
45217
45275
  // --- Topic management ---
45218
45276
  /**
45219
45277
  * Create a new topic within the conversation group.