@agentvault/agentvault 0.19.43 → 0.19.44

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
@@ -62887,22 +62887,18 @@ var init_channel = __esm({
62887
62887
  if (roomConvIds.has(convId)) continue;
62888
62888
  if (targetConvId && convId !== targetConvId) continue;
62889
62889
  try {
62890
- const encrypted = session.ratchet.encrypt(plaintext);
62891
- const transport = encryptedMessageToTransport(encrypted);
62892
- const msg = {
62893
- convId,
62894
- headerBlob: transport.header_blob,
62895
- ciphertext: transport.ciphertext,
62896
- messageGroupId,
62897
- topicId
62898
- };
62899
- if (this._state === "ready" && this._ws) {
62890
+ const mlsGroup = this._mlsGroups.get(`conv:${convId}`);
62891
+ const mlsGroupId = this._persisted?.mlsConversations?.[convId]?.mlsGroupId;
62892
+ if (mlsGroup?.isInitialized && mlsGroupId && this._state === "ready" && this._ws) {
62893
+ const plaintextBytes = new TextEncoder().encode(plaintext);
62894
+ const cipherBytes = await mlsGroup.encrypt(plaintextBytes);
62895
+ await saveMlsState(this.config.dataDir, mlsGroupId, JSON.stringify(mlsGroup.exportState()));
62900
62896
  const payload = {
62901
- conversation_id: msg.convId,
62902
- header_blob: msg.headerBlob,
62903
- ciphertext: msg.ciphertext,
62904
- message_group_id: msg.messageGroupId,
62905
- topic_id: msg.topicId,
62897
+ conversation_id: convId,
62898
+ group_id: mlsGroupId,
62899
+ epoch: Number(mlsGroup.epoch),
62900
+ payload: Buffer.from(cipherBytes).toString("hex"),
62901
+ topic_id: topicId,
62906
62902
  message_type: messageType,
62907
62903
  priority,
62908
62904
  parent_span_id: parentSpanId,
@@ -62916,20 +62912,55 @@ var init_channel = __esm({
62916
62912
  }
62917
62913
  pendingWsSends.push(
62918
62914
  JSON.stringify({
62919
- event: "message",
62915
+ event: "message_mls",
62920
62916
  data: payload
62921
62917
  })
62922
62918
  );
62923
62919
  } else {
62924
- if (!this._persisted.outboundQueue) {
62925
- this._persisted.outboundQueue = [];
62926
- }
62927
- if (this._persisted.outboundQueue.length >= 50) {
62928
- this._persisted.outboundQueue.shift();
62929
- console.warn("[SecureChannel] Outbound queue full, dropping oldest message");
62920
+ const encrypted = session.ratchet.encrypt(plaintext);
62921
+ const transport = encryptedMessageToTransport(encrypted);
62922
+ const msg = {
62923
+ convId,
62924
+ headerBlob: transport.header_blob,
62925
+ ciphertext: transport.ciphertext,
62926
+ messageGroupId,
62927
+ topicId
62928
+ };
62929
+ if (this._state === "ready" && this._ws) {
62930
+ const payload = {
62931
+ conversation_id: msg.convId,
62932
+ header_blob: msg.headerBlob,
62933
+ ciphertext: msg.ciphertext,
62934
+ message_group_id: msg.messageGroupId,
62935
+ topic_id: msg.topicId,
62936
+ message_type: messageType,
62937
+ priority,
62938
+ parent_span_id: parentSpanId,
62939
+ metadata: scanStatus ? { ...envelopeMetadata ?? {}, scan_status: scanStatus } : envelopeMetadata
62940
+ };
62941
+ if (this._persisted?.hubAddress) {
62942
+ payload.hub_address = this._persisted.hubAddress;
62943
+ }
62944
+ if (this._persisted?.hubId) {
62945
+ payload.sender_hub_id = this._persisted.hubId;
62946
+ }
62947
+ pendingWsSends.push(
62948
+ JSON.stringify({
62949
+ event: "message",
62950
+ data: payload
62951
+ })
62952
+ );
62953
+ } else {
62954
+ if (!this._persisted.outboundQueue) {
62955
+ this._persisted.outboundQueue = [];
62956
+ }
62957
+ if (this._persisted.outboundQueue.length >= 50) {
62958
+ this._persisted.outboundQueue.shift();
62959
+ console.warn("[SecureChannel] Outbound queue full, dropping oldest message");
62960
+ }
62961
+ this._persisted.outboundQueue.push(msg);
62962
+ console.log(`[SecureChannel] Message queued (state=${this._state}, queue=${this._persisted.outboundQueue.length})`);
62930
62963
  }
62931
- this._persisted.outboundQueue.push(msg);
62932
- console.log(`[SecureChannel] Message queued (state=${this._state}, queue=${this._persisted.outboundQueue.length})`);
62933
62964
  }
62934
62965
  sentCount++;
62935
62966
  } catch (err) {