@agentvault/agentvault 0.9.2 → 0.9.4

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/index.js CHANGED
@@ -46379,18 +46379,35 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
46379
46379
  const ws = new WebSocket(url);
46380
46380
  this._ws = ws;
46381
46381
  ws.on("open", async () => {
46382
- this._reconnectAttempt = 0;
46383
- this._startPing(ws);
46384
- this._startWakeDetector();
46385
- this._startPendingPoll();
46386
- await this._syncMissedMessages();
46387
- await this._flushOutboundQueue();
46388
- this._setState("ready");
46389
- if (this.config.enableScanning) {
46390
- this._scanEngine = new ScanEngine();
46391
- await this._fetchScanRules();
46382
+ try {
46383
+ this._reconnectAttempt = 0;
46384
+ this._startPing(ws);
46385
+ this._startWakeDetector();
46386
+ this._startPendingPoll();
46387
+ await this._syncMissedMessages();
46388
+ await this._flushOutboundQueue();
46389
+ this._setState("ready");
46390
+ if (this.config.enableScanning) {
46391
+ this._scanEngine = new ScanEngine();
46392
+ await this._fetchScanRules();
46393
+ }
46394
+ this.emit("ready");
46395
+ } catch (openErr) {
46396
+ console.error("[SecureChannel] Error in WS open handler:", openErr);
46397
+ this.emit("error", openErr);
46392
46398
  }
46393
- this.emit("ready");
46399
+ });
46400
+ const _onUnhandledRejection = (reason) => {
46401
+ console.error("[SecureChannel] UNHANDLED REJECTION (would crash process):", reason);
46402
+ };
46403
+ const _onUncaughtException = (err) => {
46404
+ console.error("[SecureChannel] UNCAUGHT EXCEPTION (would crash process):", err);
46405
+ };
46406
+ process.on("unhandledRejection", _onUnhandledRejection);
46407
+ process.on("uncaughtException", _onUncaughtException);
46408
+ ws.on("close", () => {
46409
+ process.removeListener("unhandledRejection", _onUnhandledRejection);
46410
+ process.removeListener("uncaughtException", _onUncaughtException);
46394
46411
  });
46395
46412
  ws.on("message", async (raw) => {
46396
46413
  this._lastServerMessage = Date.now();
@@ -46868,7 +46885,9 @@ ${messageText}`;
46868
46885
  envelopeVersion: msgData.envelope_version ?? "1.0.0"
46869
46886
  };
46870
46887
  this.emit("message", emitText, metadata);
46871
- this.config.onMessage?.(emitText, metadata);
46888
+ Promise.resolve(this.config.onMessage?.(emitText, metadata)).catch((err) => {
46889
+ console.error("[SecureChannel] onMessage callback error:", err);
46890
+ });
46872
46891
  await this._relaySyncToSiblings(convId, session.ownerDeviceId, messageText, topicId);
46873
46892
  }
46874
46893
  if (this._persisted) {
@@ -47213,7 +47232,9 @@ ${messageText}`;
47213
47232
  messageType,
47214
47233
  timestamp: msgData.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
47215
47234
  });
47216
- this.config.onMessage?.(messageText, metadata);
47235
+ Promise.resolve(this.config.onMessage?.(messageText, metadata)).catch((err) => {
47236
+ console.error("[SecureChannel] onMessage callback error:", err);
47237
+ });
47217
47238
  }
47218
47239
  /**
47219
47240
  * Find the pairwise conversation ID for a given sender in a room.
@@ -47295,7 +47316,9 @@ ${messageText}`;
47295
47316
  topicId
47296
47317
  };
47297
47318
  this.emit("message", messageText, metadata);
47298
- this.config.onMessage?.(messageText, metadata);
47319
+ Promise.resolve(this.config.onMessage?.(messageText, metadata)).catch((err) => {
47320
+ console.error("[SecureChannel] onMessage callback error:", err);
47321
+ });
47299
47322
  }
47300
47323
  this._persisted.lastMessageTimestamp = msg.created_at;
47301
47324
  since = msg.created_at;
@@ -47522,7 +47545,9 @@ ${messageText}`;
47522
47545
  topicId
47523
47546
  };
47524
47547
  this.emit("message", messageText, metadata);
47525
- this.config.onMessage?.(messageText, metadata);
47548
+ Promise.resolve(this.config.onMessage?.(messageText, metadata)).catch((err) => {
47549
+ console.error("[SecureChannel] onMessage callback error:", err);
47550
+ });
47526
47551
  foundMessages = true;
47527
47552
  }
47528
47553
  this._persisted.lastMessageTimestamp = msg.created_at;