@agentvault/agentvault 0.9.5 → 0.9.6

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
@@ -27,12 +27,12 @@ export declare class SecureChannel extends EventEmitter {
27
27
  private _lastWakeTick;
28
28
  private _pendingPollTimer;
29
29
  private _syncMessageIds;
30
- /** Recently handled message IDs via WS — survives reconnects so sync skips them. Max 500. */
31
- private _recentlyHandledIds;
32
30
  /** Queued A2A messages for responder channels not yet activated (no first initiator message received). */
33
31
  private _a2aPendingQueue;
34
32
  private _scanEngine;
35
33
  private _scanRuleSetVersion;
34
+ /** Topic ID from the most recent inbound message — used as fallback for replies. */
35
+ private _lastIncomingTopicId;
36
36
  private static readonly PING_INTERVAL_MS;
37
37
  private static readonly SILENCE_TIMEOUT_MS;
38
38
  private static readonly POLL_FALLBACK_INTERVAL_MS;
@@ -1 +1 @@
1
- {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAqB3C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAMZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,QAAQ,EAER,UAAU,EAEX,MAAM,YAAY,CAAC;AAoDpB,qBAAa,aAAc,SAAQ,YAAY;IA4CjC,OAAO,CAAC,MAAM;IA3C1B,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,OA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AAY;IAKpB;;;OAGG;YACW,aAAa;CAmB5B"}
package/dist/cli.js CHANGED
@@ -9,10 +9,10 @@ var __export = (target, all) => {
9
9
  __defProp(target, name2, { get: all[name2], enumerable: true });
10
10
  };
11
11
 
12
- // ../../node_modules/libsodium-sumo/dist/modules-sumo-esm/libsodium-sumo.mjs
12
+ // ../../../../../node_modules/libsodium-sumo/dist/modules-sumo-esm/libsodium-sumo.mjs
13
13
  var __filename, __dirname, url, path, Module, Module, root, window_, crypto_, randomValuesStandard, crypto, randomValueNodeJS, _Module, libsodium_sumo_default;
14
14
  var init_libsodium_sumo = __esm({
15
- async "../../node_modules/libsodium-sumo/dist/modules-sumo-esm/libsodium-sumo.mjs"() {
15
+ async "../../../../../node_modules/libsodium-sumo/dist/modules-sumo-esm/libsodium-sumo.mjs"() {
16
16
  try {
17
17
  if (typeof process !== "undefined" && process.versions && process.versions.node) {
18
18
  url = await import("url");
@@ -210,7 +210,7 @@ var init_libsodium_sumo = __esm({
210
210
  }, Module: function(binary) {
211
211
  }, Instance: function(module2, info) {
212
212
  this.exports = // EMSCRIPTEN_START_ASM
213
- (function instantiate(ea2) {
213
+ function instantiate(ea2) {
214
214
  var a2;
215
215
  var b2 = new Uint8Array(123);
216
216
  for (var c2 = 25; c2 >= 0; --c2) {
@@ -40005,7 +40005,7 @@ var init_libsodium_sumo = __esm({
40005
40005
  } } }), f: yi, g: ma2, h: Ba2, i: ma2, j: ka2, k: Le2, l: Je2, m: zg, n: yg, o: xg, p: wg, q: ka2, r: Ba2, s: ka2, t: ka2, u: Le2, v: ra2, w: vg, x: ug, y: tg, z: sg, A: Ba2, B: rg, C: qg, D: pg, E: ng, F: mg, G: lg, H: kg, I: jg, J: ka2, K: Ce2, L: Ba2, M: ma2, N: Ta2, O: ra2, P: ka2, Q: Oa2, R: Ba2, S: ma2, T: Ta2, U: ra2, V: ig, W: hg, X: gg, Y: fg, Z: ka2, _: Ma2, $: Ba2, aa: ma2, ba: Ta2, ca: ra2, da: ka2, ea: ka2, fa: Kg, ga: wd, ha: vd, ia: ra2, ja: ka2, ka: ka2, la: Cb, ma: ra2, na: Xa2, oa: eg, pa: qb, qa: dg, ra: cg, sa: ua2, ta: ka2, ua: Dc, va: ra2, wa: Va2, xa: ud, ya: Ya2, za: bg, Aa: ag, Ba: ka2, Ca: ka2, Da: Dc, Ea: ra2, Fa: ze2, Ga: ud, Ha: Ng, Ia: wd, Ja: vd, Ka: ka2, La: ka2, Ma: ka2, Na: ka2, Oa: Ma2, Pa: ka2, Qa: ma2, Ra: ma2, Sa: Ta2, Ta: dh2, Ua: ch, Va: bh, Wa: ah, Xa: Lb, Ya: Kb, Za: td, _a: sd, $a: rd, ab: $f, bb: _f, cb: Zf, db: qd, eb: Yf, fb: pd, gb: Xf, hb: Wf, ib: Uf, jb: Md, kb: tc, lb: nb, mb, nb: Lb, ob: Kb, pb: td, qb: sd, rb: ka2, sb: ka2, tb: ka2, ub: ka2, vb: Ma2, wb: ka2, xb: ma2, yb: ma2, zb: Ta2, Ab: Aa2, Bb: ka2, Cb: ma2, Db: ka2, Eb: ma2, Fb: Sa2, Gb: ka2, Hb: ma2, Ib: ka2, Jb: ma2, Kb: vb, Lb: ua2, Mb: ma2, Nb: ka2, Ob: ma2, Pb: ub, Qb: ua2, Rb: ma2, Sb: ka2, Tb: ma2, Ub: tb, Vb: ua2, Wb: ma2, Xb: ka2, Yb: ma2, Zb: ma2, _b: ua2, $b: ka2, ac: ma2, bc: ua2, cc: ka2, dc: Nd, ec: pe2, fc: od, gc: fh, hc: nd, ic: eh, jc: ra2, kc: ma2, lc: ua2, mc: ka2, nc: ma2, oc: ua2, pc: ka2, qc: ma2, rc: ma2, sc: pe2, tc: ra2, uc: od, vc: Tf, wc: Ja2, xc: xh, yc: nd, zc: Ia2, Ac: ua2, Bc: md, Cc: Lg, Dc: ka2, Ec: Ag, Fc: Ub, Gc: Sf, Hc: Ua2, Ic: Rf, Jc: ua2, Kc: Cb, Lc: Za2, Mc: ic, Nc: Ca2, Oc: md, Pc: ma2, Qc: ua2, Rc: Oa2, Sc: ka2, Tc: ld, Uc: Nd, Vc: ma2, Wc: ua2, Xc: Oa2, Yc: ka2, Zc: ld, _c: ra2, $c: Gh, ad: Fh, bd: Eh, cd: Dh, dd: ra2, ed: Ch, fd: ka2, gd: Ba2, hd: Bh, id: Cb, jd: ze2, kd: hi, ld: gi, md: fi, nd: ei, od: di, pd: ua2, qd: Ba2, rd: ci, sd: Dc, td: Gg, ud: nb, vd: Fg, wd: Eg, xd: ka2, yd: ka2, zd: ka2, Ad: ka2, Bd: Dg, Cd: Rc, Dd: ma2, Ed: ka2, Fd: kd, Gd: jd, Hd: Sg, Id: id, Jd: Rg, Kd: Qg, Ld: ra2, Md: kd, Nd: jd, Od: Ga2, Pd: id, Qd: Fa2, Rd: ma2, Sd: ka2, Td: Rc, Ud: ra2, Vd: Db, Wd: ma2, Xd: wa2, Yd: Ba2, Zd: wa2, _d: ma2, $d: yc, ae: wh, be: Vb, ce: wa2, de: xc, ee: wc, fe: vc, ge: me2, he: vh, ie: uh, je: Oa2, ke: th, le: Pf, me: Of, ne: Nf, oe: Mf, pe: Lf, qe: fb, re: ma2, se: wa2, te: Ba2, ue: wa2, ve: ma2, we: yc, xe: fe2, ye: Db, ze: wa2, Ae: xc, Be: wc, Ce: fb, De: ee2, Ee: Vb, Fe: de2, Ge: vc, He: uc, Ie: Kf, Je: hd, Ke: Jf, Le: Db, Me: fb, Ne: fb, Oe: ma2, Pe: wa2, Qe: Ba2, Re: wa2, Se: ma2, Te: yc, Ue: fe2, Ve: Db, We: wa2, Xe: xc, Ye: wc, Ze: fb, _e: ee2, $e: Vb, af: de2, bf: vc, cf: uc, df: Hf, ef: hd, ff: Gf, gf: Ff, hf: Ef, jf: sh, kf: Jg, lf: Ig, mf: Hg, nf: ka2, of: ka2, pf: Ea2, qf: wb, rf: ka2, sf: ka2, tf: ka2, uf: Ma2, vf: ka2, wf: ma2, xf: ma2, yf: Ta2, zf: Mg, Af: Lb, Bf: Kb, Cf: ra2, Df: rd, Ef: Df, Ff: qd, Gf: pd, Hf: Lb, If: Kb, Jf: ka2, Kf: Ma2, Lf: ka2, Mf: ma2, Nf: ma2, Of: Ta2, Pf: ra2, Qf: ra2, Rf: Mh, Sf: Lh, Tf: Kh, Uf: Cf, Vf: Bf, Wf: Jh, Xf: Ih, Yf: Ma2, Zf: ka2, _f: Hh, $f: Ba2, ag: Db, bg: fb, cg: Vb, dg: Oa2, eg: ma2, fg: Tg, gg: gd, hg: Je2, ig: Oa2, jg: ma2, kg: gd, lg: Cb, mg: ua2, ng: ka2, og: ka2, pg: ua2, qg: Wd, rg: lh, sg: kh, tg: jh, ug: fd, vg: ed, wg: dd, xg: cd, yg: ih, zg: ic, Ag: hh, Bg: gh, Cg: Cb, Dg: ua2, Eg: ka2, Fg: ka2, Gg: ua2, Hg: Wd, Ig: nh, Jg: mh, Kg: Vd, Lg: ic, Mg: Ud, Ng: Td, Og: Yd, Pg: Xd, Qg: ph, Rg: oh, Sg: cd, Tg: ed, Ug: dd, Vg: fd, Wg: ka2, Xg: Oa2, Yg: wa2, Zg: ka2, _g: Ce2, $g: wa2, ah: zf, bh: yf, ch: xf, dh: wf, eh: vf, fh: uf, gh: ra2, hh: ra2, ih: ka2, jh: Ma2, kh: wa2, lh: qh, mh: bd, nh: ad, oh: ra2, ph: ka2, qh: Oa2, rh: wa2, sh: tf, th: sf, uh: rf, vh: ra2, wh: bd, xh: qf, yh: ad, zh: ka2, Ah: Ma2, Bh: wa2, Ch: ra2, Dh: ma2, Eh: ka2, Fh: ua2, Gh: db, Hh: kb, Ih: xd, Jh: oi, Kh: ni, Lh: Ae2, Mh: mi, Nh: za2, Oh: li, Ph: ka2, Qh: ki, Rh: pf, Sh: Ah, Th: zh, Uh: yh, Vh: Bc, Wh: Ac, Xh: ti, Yh: ji, Zh: ii, _h: Cg, $h: Bg, ai: fb, bi: Ba2, ci: tc, di: nb, ei: rh, fi: $c, gi: of, hi: nf, ii: mf, ji: _c, ki: lf, li: Yc, mi: kf, ni: ka2, oi: ka2, pi: ka2, qi: ka2, ri: Ma2, si: ma2, ti: Ta2, ui: jf, vi: hf, wi: Md, xi: bi, yi: ai, zi: $h, Ai: _h, Bi: Zh, Ci: ye2, Di: xe2, Ei: we2, Fi: ve2, Gi: ue2, Hi: te2, Ii: se2, Ji: re2, Ki: ka2, Li: ua2, Mi: ka2, Ni: ua2, Oi: ka2, Pi: Yh, Qi: Xh, Ri: Wh, Si: Vh, Ti: Uh, Ui: Th, Vi: Sh, Wi: Rh, Xi: Qh, Yi: Ph, Zi: Oh, _i: re2, $i: Nh, aj: ka2, bj: ua2, cj: ua2, dj: ka2, ej: gf, fj: ma2, gj: wa2, hj: Ba2, ij: wa2, jj: ka2, kj: $g, lj: _g, mj: Zg, nj: wa2, oj: Ed, pj: wa2, qj: Yg, rj: Ed, sj: me2, tj: uc, uj: ff, vj: ef, wj: df, xj: cf, yj: Xg, zj: Wg, Aj: Vg, Bj: Ug, Cj: ka2, Dj: ka2, Ej: Pg, Fj: Og, Gj: ka2, Hj: ka2, Ij: $c, Jj: bf, Kj: _c, Lj: Yc, Mj: ka2, Nj: Ma2, Oj: ma2, Pj: Ta2, Qj: ma2, Rj: ma2, Sj: af, Tj: $e2, Uj: _e2, Vj: ka2, Wj: Oa2, Xj: wa2, Yj: ra2, Zj: Ze2, _j: Ye2, $j: ka2, ak: Oa2, bk: wa2, ck: ra2, dk: ka2, ek: Ma2, fk: wa2, gk: Xe2, hk: We2, ik: Ve2, jk: ra2, kk: Da2, lk: ta2 };
40006
40006
  }
40007
40007
  return da2(ea2);
40008
- })(info);
40008
+ }(info);
40009
40009
  }, instantiate: function(binary, info) {
40010
40010
  return { then: function(ok) {
40011
40011
  var module2 = new WebAssembly2.Module(binary);
@@ -42009,7 +42009,7 @@ var init_libsodium_sumo = __esm({
42009
42009
  }
42010
42010
  });
42011
42011
 
42012
- // ../../node_modules/libsodium-wrappers-sumo/dist/modules-sumo-esm/libsodium-wrappers.mjs
42012
+ // ../../../../../node_modules/libsodium-wrappers-sumo/dist/modules-sumo-esm/libsodium-wrappers.mjs
42013
42013
  function _(e) {
42014
42014
  if ("function" == typeof TextEncoder) return new TextEncoder().encode(e);
42015
42015
  e = unescape(encodeURIComponent(e));
@@ -44529,7 +44529,7 @@ function qr() {
44529
44529
  }
44530
44530
  var a, r, t, c, libsodium_wrappers_default;
44531
44531
  var init_libsodium_wrappers = __esm({
44532
- async "../../node_modules/libsodium-wrappers-sumo/dist/modules-sumo-esm/libsodium-wrappers.mjs"() {
44532
+ async "../../../../../node_modules/libsodium-wrappers-sumo/dist/modules-sumo-esm/libsodium-wrappers.mjs"() {
44533
44533
  await init_libsodium_sumo();
44534
44534
  r = {};
44535
44535
  t = libsodium_sumo_default.ready.then(function() {
@@ -44611,7 +44611,7 @@ var init_libsodium_wrappers = __esm({
44611
44611
  }
44612
44612
  });
44613
44613
 
44614
- // ../crypto/dist/keys.js
44614
+ // ../../../../../packages/crypto/dist/keys.js
44615
44615
  async function generateIdentityKeypair() {
44616
44616
  await libsodium_wrappers_default.ready;
44617
44617
  const kp = libsodium_wrappers_default.crypto_sign_keypair();
@@ -44638,13 +44638,13 @@ function createProofOfPossession(privateKey, publicKey) {
44638
44638
  return libsodium_wrappers_default.crypto_sign_detached(publicKey, privateKey);
44639
44639
  }
44640
44640
  var init_keys = __esm({
44641
- async "../crypto/dist/keys.js"() {
44641
+ async "../../../../../packages/crypto/dist/keys.js"() {
44642
44642
  "use strict";
44643
44643
  await init_libsodium_wrappers();
44644
44644
  }
44645
44645
  });
44646
44646
 
44647
- // ../crypto/dist/x3dh.js
44647
+ // ../../../../../packages/crypto/dist/x3dh.js
44648
44648
  function ed25519PrivateToX25519(edPrivate) {
44649
44649
  return libsodium_wrappers_default.crypto_sign_ed25519_sk_to_curve25519(edPrivate);
44650
44650
  }
@@ -44666,13 +44666,13 @@ function performX3DH(params) {
44666
44666
  return libsodium_wrappers_default.crypto_generichash(32, combined);
44667
44667
  }
44668
44668
  var init_x3dh = __esm({
44669
- async "../crypto/dist/x3dh.js"() {
44669
+ async "../../../../../packages/crypto/dist/x3dh.js"() {
44670
44670
  "use strict";
44671
44671
  await init_libsodium_wrappers();
44672
44672
  }
44673
44673
  });
44674
44674
 
44675
- // ../crypto/dist/ratchet.js
44675
+ // ../../../../../packages/crypto/dist/ratchet.js
44676
44676
  function kdfChainKey(chainKey) {
44677
44677
  const nextChainKey = libsodium_wrappers_default.crypto_generichash(32, chainKey, CHAIN_KEY_SEED);
44678
44678
  const messageKey = libsodium_wrappers_default.crypto_generichash(32, chainKey, MSG_KEY_SEED);
@@ -44711,7 +44711,7 @@ function verifyHeaderSignature(header, signature, identityPublicKey) {
44711
44711
  }
44712
44712
  var MAX_SKIP, CHAIN_KEY_SEED, MSG_KEY_SEED, DoubleRatchet;
44713
44713
  var init_ratchet = __esm({
44714
- async "../crypto/dist/ratchet.js"() {
44714
+ async "../../../../../packages/crypto/dist/ratchet.js"() {
44715
44715
  "use strict";
44716
44716
  await init_libsodium_wrappers();
44717
44717
  MAX_SKIP = 100;
@@ -44940,7 +44940,7 @@ var init_ratchet = __esm({
44940
44940
  }
44941
44941
  });
44942
44942
 
44943
- // ../crypto/dist/file-crypto.js
44943
+ // ../../../../../packages/crypto/dist/file-crypto.js
44944
44944
  function encryptFile(plainData) {
44945
44945
  const fileKey = libsodium_wrappers_default.randombytes_buf(libsodium_wrappers_default.crypto_aead_xchacha20poly1305_ietf_KEYBYTES);
44946
44946
  const fileNonce = libsodium_wrappers_default.randombytes_buf(libsodium_wrappers_default.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
@@ -44973,23 +44973,23 @@ function computeFileDigest(data) {
44973
44973
  return libsodium_wrappers_default.to_hex(digestBytes);
44974
44974
  }
44975
44975
  var init_file_crypto = __esm({
44976
- async "../crypto/dist/file-crypto.js"() {
44976
+ async "../../../../../packages/crypto/dist/file-crypto.js"() {
44977
44977
  "use strict";
44978
44978
  await init_libsodium_wrappers();
44979
44979
  }
44980
44980
  });
44981
44981
 
44982
- // ../crypto/dist/did.js
44982
+ // ../../../../../packages/crypto/dist/did.js
44983
44983
  var init_did = __esm({
44984
- async "../crypto/dist/did.js"() {
44984
+ async "../../../../../packages/crypto/dist/did.js"() {
44985
44985
  "use strict";
44986
44986
  }
44987
44987
  });
44988
44988
 
44989
- // ../crypto/dist/scan-engine.js
44989
+ // ../../../../../packages/crypto/dist/scan-engine.js
44990
44990
  var BUILTIN_PATTERNS, ScanEngine;
44991
44991
  var init_scan_engine = __esm({
44992
- "../crypto/dist/scan-engine.js"() {
44992
+ "../../../../../packages/crypto/dist/scan-engine.js"() {
44993
44993
  "use strict";
44994
44994
  BUILTIN_PATTERNS = {
44995
44995
  pii_ssn: [/\b\d{3}-\d{2}-\d{4}\b/g, /\b\d{9}\b/g],
@@ -45144,14 +45144,14 @@ var init_scan_engine = __esm({
45144
45144
  }
45145
45145
  });
45146
45146
 
45147
- // ../crypto/dist/merkle.js
45147
+ // ../../../../../packages/crypto/dist/merkle.js
45148
45148
  var init_merkle = __esm({
45149
- async "../crypto/dist/merkle.js"() {
45149
+ async "../../../../../packages/crypto/dist/merkle.js"() {
45150
45150
  "use strict";
45151
45151
  }
45152
45152
  });
45153
45153
 
45154
- // ../crypto/dist/transport.js
45154
+ // ../../../../../packages/crypto/dist/transport.js
45155
45155
  function hexToBytes(hex) {
45156
45156
  return libsodium_wrappers_default.from_hex(hex);
45157
45157
  }
@@ -45194,15 +45194,15 @@ function transportToEncryptedMessage(transport) {
45194
45194
  };
45195
45195
  }
45196
45196
  var init_transport = __esm({
45197
- async "../crypto/dist/transport.js"() {
45197
+ async "../../../../../packages/crypto/dist/transport.js"() {
45198
45198
  "use strict";
45199
45199
  await init_libsodium_wrappers();
45200
45200
  }
45201
45201
  });
45202
45202
 
45203
- // ../crypto/dist/index.js
45203
+ // ../../../../../packages/crypto/dist/index.js
45204
45204
  var init_dist = __esm({
45205
- async "../crypto/dist/index.js"() {
45205
+ async "../../../../../packages/crypto/dist/index.js"() {
45206
45206
  "use strict";
45207
45207
  await init_keys();
45208
45208
  await init_x3dh();
@@ -45393,12 +45393,12 @@ var init_channel = __esm({
45393
45393
  _lastWakeTick = Date.now();
45394
45394
  _pendingPollTimer = null;
45395
45395
  _syncMessageIds = null;
45396
- /** Recently handled message IDs via WS — survives reconnects so sync skips them. Max 500. */
45397
- _recentlyHandledIds = /* @__PURE__ */ new Set();
45398
45396
  /** Queued A2A messages for responder channels not yet activated (no first initiator message received). */
45399
45397
  _a2aPendingQueue = {};
45400
45398
  _scanEngine = null;
45401
45399
  _scanRuleSetVersion = 0;
45400
+ /** Topic ID from the most recent inbound message — used as fallback for replies. */
45401
+ _lastIncomingTopicId;
45402
45402
  // Liveness detection: server sends app-level {"event":"ping"} every 30s.
45403
45403
  // We check every 30s; if no data received in 90s (3 missed pings), connection is dead.
45404
45404
  static PING_INTERVAL_MS = 3e4;
@@ -45509,7 +45509,7 @@ var init_channel = __esm({
45509
45509
  if (this._sessions.size === 0) {
45510
45510
  throw new Error("No active sessions");
45511
45511
  }
45512
- const topicId = options?.topicId ?? this._persisted?.defaultTopicId;
45512
+ const topicId = options?.topicId ?? this._lastIncomingTopicId ?? this._persisted?.defaultTopicId;
45513
45513
  const messageType = options?.messageType ?? "text";
45514
45514
  const priority = options?.priority ?? "normal";
45515
45515
  const parentSpanId = options?.parentSpanId;
@@ -46500,20 +46500,6 @@ var init_channel = __esm({
46500
46500
  this.emit("error", openErr);
46501
46501
  }
46502
46502
  });
46503
- const _onUnhandledRejection = (reason) => {
46504
- console.error("[SecureChannel] UNHANDLED REJECTION (would crash process):", reason);
46505
- };
46506
- const _onUncaughtException = (err) => {
46507
- console.error("[SecureChannel] UNCAUGHT EXCEPTION (would crash process):", err);
46508
- };
46509
- process.on("unhandledRejection", _onUnhandledRejection);
46510
- process.on("uncaughtException", _onUncaughtException);
46511
- ws.on("close", (code, reason) => {
46512
- const reasonStr = reason?.toString() || "";
46513
- console.log(`[SecureChannel] WS CLOSED: code=${code} reason=${JSON.stringify(reasonStr)}`);
46514
- process.removeListener("unhandledRejection", _onUnhandledRejection);
46515
- process.removeListener("uncaughtException", _onUncaughtException);
46516
- });
46517
46503
  ws.on("message", async (raw) => {
46518
46504
  this._lastServerMessage = Date.now();
46519
46505
  this._lastWakeTick = Date.now();
@@ -46533,10 +46519,8 @@ var init_channel = __esm({
46533
46519
  return;
46534
46520
  }
46535
46521
  if (data.event === "message") {
46536
- console.log(`[SecureChannel] \u2190 Direct message received: msg=${data.data?.message_id?.slice(0, 8) ?? "?"} conv=${data.data?.conversation_id?.slice(0, 8) ?? "?"}`);
46537
46522
  try {
46538
46523
  await this._handleIncomingMessage(data.data);
46539
- console.log(`[SecureChannel] \u2190 Direct message processed OK: msg=${data.data?.message_id?.slice(0, 8) ?? "?"}`);
46540
46524
  } catch (msgErr) {
46541
46525
  console.error(
46542
46526
  `[SecureChannel] Message handler failed for conv ${data.data?.conversation_id?.slice(0, 8) ?? "?"}...:`,
@@ -46868,9 +46852,7 @@ var init_channel = __esm({
46868
46852
  this.emit("error", err);
46869
46853
  }
46870
46854
  });
46871
- ws.on("close", (code, reason) => {
46872
- const reasonStr = reason?.toString() || "";
46873
- console.log(`[SecureChannel] WS close handler: code=${code} reason=${JSON.stringify(reasonStr)}`);
46855
+ ws.on("close", () => {
46874
46856
  this._stopPing();
46875
46857
  this._stopWakeDetector();
46876
46858
  this._stopPendingPoll();
@@ -46892,11 +46874,6 @@ var init_channel = __esm({
46892
46874
  if (this._syncMessageIds?.has(msgData.message_id)) {
46893
46875
  return;
46894
46876
  }
46895
- this._recentlyHandledIds.add(msgData.message_id);
46896
- if (this._recentlyHandledIds.size > 500) {
46897
- const all = [...this._recentlyHandledIds];
46898
- this._recentlyHandledIds = new Set(all.slice(all.length - 400));
46899
- }
46900
46877
  const convId = msgData.conversation_id;
46901
46878
  const session = this._sessions.get(convId);
46902
46879
  if (!session) {
@@ -46909,14 +46886,7 @@ var init_channel = __esm({
46909
46886
  header_blob: msgData.header_blob,
46910
46887
  ciphertext: msgData.ciphertext
46911
46888
  });
46912
- let plaintext;
46913
- try {
46914
- plaintext = session.ratchet.decrypt(encrypted);
46915
- } catch (decryptErr) {
46916
- console.error(`[SecureChannel] Direct message decrypt FAILED for conv ${convId.slice(0, 8)}...: ${String(decryptErr)}`);
46917
- throw decryptErr;
46918
- }
46919
- console.log(`[SecureChannel] Direct message decrypted OK for conv ${convId.slice(0, 8)}...`);
46889
+ const plaintext = session.ratchet.decrypt(encrypted);
46920
46890
  this._sendAck(msgData.message_id);
46921
46891
  if (!session.activated) {
46922
46892
  session.activated = true;
@@ -46951,6 +46921,7 @@ var init_channel = __esm({
46951
46921
  }
46952
46922
  if (messageType === "message") {
46953
46923
  const topicId = msgData.topic_id;
46924
+ this._lastIncomingTopicId = topicId;
46954
46925
  let attachData;
46955
46926
  if (attachmentInfo) {
46956
46927
  try {
@@ -47009,13 +46980,7 @@ ${messageText}`;
47009
46980
  Promise.resolve(this.config.onMessage?.(emitText, metadata)).catch((err) => {
47010
46981
  console.error("[SecureChannel] onMessage callback error:", err);
47011
46982
  });
47012
- console.log(`[SecureChannel] Relaying sync to ${this._sessions.size - 1} siblings for conv ${convId.slice(0, 8)}...`);
47013
- try {
47014
- await this._relaySyncToSiblings(convId, session.ownerDeviceId, messageText, topicId);
47015
- console.log(`[SecureChannel] Sync relay complete for conv ${convId.slice(0, 8)}...`);
47016
- } catch (relayErr) {
47017
- console.error(`[SecureChannel] Sync relay FAILED: ${String(relayErr)}`);
47018
- }
46983
+ await this._relaySyncToSiblings(convId, session.ownerDeviceId, messageText, topicId);
47019
46984
  }
47020
46985
  if (this._persisted) {
47021
46986
  this._persisted.lastMessageTimestamp = msgData.created_at;
@@ -47140,29 +47105,22 @@ ${messageText}`;
47140
47105
  ts: (/* @__PURE__ */ new Date()).toISOString(),
47141
47106
  topicId
47142
47107
  });
47143
- let relayed = 0;
47144
47108
  for (const [siblingConvId, siblingSession] of this._sessions) {
47145
47109
  if (siblingConvId === sourceConvId) continue;
47146
47110
  if (!siblingSession.activated) continue;
47147
- try {
47148
- const syncEncrypted = siblingSession.ratchet.encrypt(syncPayload);
47149
- const syncTransport = encryptedMessageToTransport(syncEncrypted);
47150
- this._ws.send(
47151
- JSON.stringify({
47152
- event: "message",
47153
- data: {
47154
- conversation_id: siblingConvId,
47155
- header_blob: syncTransport.header_blob,
47156
- ciphertext: syncTransport.ciphertext
47157
- }
47158
- })
47159
- );
47160
- relayed++;
47161
- } catch (err) {
47162
- console.error(`[SecureChannel] Sync send failed for sibling ${siblingConvId.slice(0, 8)}...: ${String(err)}`);
47163
- }
47111
+ const syncEncrypted = siblingSession.ratchet.encrypt(syncPayload);
47112
+ const syncTransport = encryptedMessageToTransport(syncEncrypted);
47113
+ this._ws.send(
47114
+ JSON.stringify({
47115
+ event: "message",
47116
+ data: {
47117
+ conversation_id: siblingConvId,
47118
+ header_blob: syncTransport.header_blob,
47119
+ ciphertext: syncTransport.ciphertext
47120
+ }
47121
+ })
47122
+ );
47164
47123
  }
47165
- console.log(`[SecureChannel] _relaySyncToSiblings: relayed to ${relayed}/${this._sessions.size - 1} siblings`);
47166
47124
  }
47167
47125
  /**
47168
47126
  * Send stored message history to a newly-activated session.
@@ -47264,12 +47222,52 @@ ${messageText}`;
47264
47222
  );
47265
47223
  return;
47266
47224
  }
47267
- const session = this._sessions.get(convId);
47225
+ let session = this._sessions.get(convId);
47268
47226
  if (!session) {
47269
47227
  console.warn(
47270
- `[SecureChannel] No session for room conv ${convId.slice(0, 8)}..., skipping`
47228
+ `[SecureChannel] No session for room conv ${convId.slice(0, 8)}..., fetching room data`
47271
47229
  );
47272
- return;
47230
+ try {
47231
+ const roomRes = await fetch(
47232
+ `${this.config.apiUrl}/api/v1/rooms/${msgData.room_id}`,
47233
+ {
47234
+ headers: {
47235
+ Authorization: `Bearer ${this._persisted.deviceJwt}`
47236
+ }
47237
+ }
47238
+ );
47239
+ if (roomRes.ok) {
47240
+ const roomData = await roomRes.json();
47241
+ await this.joinRoom({
47242
+ roomId: roomData.id,
47243
+ name: roomData.name,
47244
+ members: (roomData.members || []).map((m2) => ({
47245
+ deviceId: m2.device_id,
47246
+ entityType: m2.entity_type,
47247
+ displayName: m2.display_name,
47248
+ identityPublicKey: m2.identity_public_key,
47249
+ ephemeralPublicKey: m2.ephemeral_public_key
47250
+ })),
47251
+ conversations: (roomData.conversations || []).map((c2) => ({
47252
+ id: c2.id,
47253
+ participantA: c2.participant_a,
47254
+ participantB: c2.participant_b
47255
+ }))
47256
+ });
47257
+ session = this._sessions.get(convId);
47258
+ }
47259
+ } catch (fetchErr) {
47260
+ console.error(
47261
+ `[SecureChannel] Failed to fetch room data for ${msgData.room_id}:`,
47262
+ fetchErr
47263
+ );
47264
+ }
47265
+ if (!session) {
47266
+ console.warn(
47267
+ `[SecureChannel] Still no session for room conv ${convId.slice(0, 8)}... after refresh, skipping`
47268
+ );
47269
+ return;
47270
+ }
47273
47271
  }
47274
47272
  const encrypted = transportToEncryptedMessage({
47275
47273
  header_blob: msgData.header_blob,
@@ -47399,7 +47397,6 @@ ${messageText}`;
47399
47397
  const PAGE_SIZE = 200;
47400
47398
  let since = this._persisted.lastMessageTimestamp;
47401
47399
  let totalProcessed = 0;
47402
- let totalSkipped = 0;
47403
47400
  try {
47404
47401
  for (let page = 0; page < MAX_PAGES; page++) {
47405
47402
  const url = `${this.config.apiUrl}/api/v1/devices/${this._deviceId}/messages?since=${encodeURIComponent(since)}&limit=${PAGE_SIZE}`;
@@ -47409,24 +47406,15 @@ ${messageText}`;
47409
47406
  if (!res.ok) break;
47410
47407
  const messages = await res.json();
47411
47408
  if (messages.length === 0) break;
47412
- console.log(`[SecureChannel] Sync page ${page}: ${messages.length} messages since ${since}`);
47413
47409
  for (const msg of messages) {
47414
47410
  if (msg.sender_device_id === this._deviceId) continue;
47415
47411
  if (this._syncMessageIds.has(msg.id)) continue;
47416
47412
  this._syncMessageIds.add(msg.id);
47417
- if (this._recentlyHandledIds.has(msg.id)) {
47418
- this._persisted.lastMessageTimestamp = msg.created_at;
47419
- since = msg.created_at;
47420
- totalSkipped++;
47421
- continue;
47422
- }
47423
47413
  const session = this._sessions.get(msg.conversation_id);
47424
47414
  if (!session) {
47425
47415
  console.warn(
47426
47416
  `[SecureChannel] No session for conversation ${msg.conversation_id} during sync, skipping`
47427
47417
  );
47428
- this._persisted.lastMessageTimestamp = msg.created_at;
47429
- since = msg.created_at;
47430
47418
  continue;
47431
47419
  }
47432
47420
  try {
@@ -47460,6 +47448,9 @@ ${messageText}`;
47460
47448
  topicId
47461
47449
  };
47462
47450
  this.emit("message", messageText, metadata);
47451
+ Promise.resolve(this.config.onMessage?.(messageText, metadata)).catch((err) => {
47452
+ console.error("[SecureChannel] onMessage callback error:", err);
47453
+ });
47463
47454
  }
47464
47455
  this._persisted.lastMessageTimestamp = msg.created_at;
47465
47456
  since = msg.created_at;
@@ -47476,15 +47467,10 @@ ${messageText}`;
47476
47467
  await this._persistState();
47477
47468
  if (messages.length < PAGE_SIZE) break;
47478
47469
  }
47479
- if (totalProcessed > 0 || totalSkipped > 0) {
47480
- console.log(`[SecureChannel] Sync complete: ${totalProcessed} processed, ${totalSkipped} skipped (already handled via WS)`);
47481
- }
47482
- } catch (outerErr) {
47483
- console.warn(`[SecureChannel] Sync interrupted: ${String(outerErr)}`);
47484
- try {
47485
- await this._persistState();
47486
- } catch {
47470
+ if (totalProcessed > 0) {
47471
+ console.log(`[SecureChannel] Synced ${totalProcessed} missed messages`);
47487
47472
  }
47473
+ } catch {
47488
47474
  }
47489
47475
  this._syncMessageIds = null;
47490
47476
  }
@@ -47824,7 +47810,7 @@ var init_gateway_send = __esm({
47824
47810
 
47825
47811
  // src/index.ts
47826
47812
  var VERSION;
47827
- var init_index = __esm({
47813
+ var init_src = __esm({
47828
47814
  async "src/index.ts"() {
47829
47815
  "use strict";
47830
47816
  await init_channel();
@@ -48128,7 +48114,7 @@ var init_setup = __esm({
48128
48114
  async "src/setup.ts"() {
48129
48115
  "use strict";
48130
48116
  await init_channel();
48131
- await init_index();
48117
+ await init_src();
48132
48118
  }
48133
48119
  });
48134
48120