@agentvault/agentvault 0.10.1 → 0.10.2

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
@@ -45631,6 +45631,7 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45631
45631
  if (this._sessions.size === 0) {
45632
45632
  throw new Error("No active sessions");
45633
45633
  }
45634
+ const targetConvId = options?.conversationId;
45634
45635
  const topicId = options?.topicId ?? this._lastIncomingTopicId ?? this._persisted?.defaultTopicId;
45635
45636
  const messageType = options?.messageType ?? "text";
45636
45637
  const priority = options?.priority ?? "normal";
@@ -45655,51 +45656,61 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45655
45656
  }
45656
45657
  }
45657
45658
  const messageGroupId = randomUUID();
45659
+ let sentCount = 0;
45658
45660
  for (const [convId, session] of this._sessions) {
45659
45661
  if (!session.activated) continue;
45660
45662
  if (roomConvIds.has(convId)) continue;
45661
- const encrypted = session.ratchet.encrypt(plaintext);
45662
- const transport = encryptedMessageToTransport(encrypted);
45663
- const msg = {
45664
- convId,
45665
- headerBlob: transport.header_blob,
45666
- ciphertext: transport.ciphertext,
45667
- messageGroupId,
45668
- topicId
45669
- };
45670
- if (this._state === "ready" && this._ws) {
45671
- const payload = {
45672
- conversation_id: msg.convId,
45673
- header_blob: msg.headerBlob,
45674
- ciphertext: msg.ciphertext,
45675
- message_group_id: msg.messageGroupId,
45676
- topic_id: msg.topicId,
45677
- message_type: messageType,
45678
- priority,
45679
- parent_span_id: parentSpanId,
45680
- metadata: scanStatus ? { ...envelopeMetadata ?? {}, scan_status: scanStatus } : envelopeMetadata
45663
+ if (targetConvId && convId !== targetConvId) continue;
45664
+ try {
45665
+ const encrypted = session.ratchet.encrypt(plaintext);
45666
+ const transport = encryptedMessageToTransport(encrypted);
45667
+ const msg = {
45668
+ convId,
45669
+ headerBlob: transport.header_blob,
45670
+ ciphertext: transport.ciphertext,
45671
+ messageGroupId,
45672
+ topicId
45681
45673
  };
45682
- if (this._persisted?.hubAddress) {
45683
- payload.hub_address = this._persisted.hubAddress;
45684
- }
45685
- this._ws.send(
45686
- JSON.stringify({
45687
- event: "message",
45688
- data: payload
45689
- })
45690
- );
45691
- } else {
45692
- if (!this._persisted.outboundQueue) {
45693
- this._persisted.outboundQueue = [];
45694
- }
45695
- if (this._persisted.outboundQueue.length >= 50) {
45696
- this._persisted.outboundQueue.shift();
45697
- console.warn("[SecureChannel] Outbound queue full, dropping oldest message");
45674
+ if (this._state === "ready" && this._ws) {
45675
+ const payload = {
45676
+ conversation_id: msg.convId,
45677
+ header_blob: msg.headerBlob,
45678
+ ciphertext: msg.ciphertext,
45679
+ message_group_id: msg.messageGroupId,
45680
+ topic_id: msg.topicId,
45681
+ message_type: messageType,
45682
+ priority,
45683
+ parent_span_id: parentSpanId,
45684
+ metadata: scanStatus ? { ...envelopeMetadata ?? {}, scan_status: scanStatus } : envelopeMetadata
45685
+ };
45686
+ if (this._persisted?.hubAddress) {
45687
+ payload.hub_address = this._persisted.hubAddress;
45688
+ }
45689
+ this._ws.send(
45690
+ JSON.stringify({
45691
+ event: "message",
45692
+ data: payload
45693
+ })
45694
+ );
45695
+ } else {
45696
+ if (!this._persisted.outboundQueue) {
45697
+ this._persisted.outboundQueue = [];
45698
+ }
45699
+ if (this._persisted.outboundQueue.length >= 50) {
45700
+ this._persisted.outboundQueue.shift();
45701
+ console.warn("[SecureChannel] Outbound queue full, dropping oldest message");
45702
+ }
45703
+ this._persisted.outboundQueue.push(msg);
45704
+ console.log(`[SecureChannel] Message queued (state=${this._state}, queue=${this._persisted.outboundQueue.length})`);
45698
45705
  }
45699
- this._persisted.outboundQueue.push(msg);
45700
- console.log(`[SecureChannel] Message queued (state=${this._state}, queue=${this._persisted.outboundQueue.length})`);
45706
+ sentCount++;
45707
+ } catch (err) {
45708
+ console.error(`[SecureChannel] send() failed for conv ${convId.slice(0, 8)}...:`, err);
45701
45709
  }
45702
45710
  }
45711
+ if (sentCount === 0 && this._sessions.size > 0) {
45712
+ console.warn("[SecureChannel] send() delivered to 0 sessions (all skipped or failed)");
45713
+ }
45703
45714
  await this._persistState();
45704
45715
  }
45705
45716
  /**