@agentvault/agentvault 0.19.4 → 0.19.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/index.js CHANGED
@@ -48412,9 +48412,10 @@ var init_channel = __esm({
48412
48412
  if (!this._persisted?.a2aChannels) {
48413
48413
  throw new Error("No A2A channels established");
48414
48414
  }
48415
- const channelEntry = Object.values(this._persisted.a2aChannels).find(
48415
+ const allMatches = Object.values(this._persisted.a2aChannels).filter(
48416
48416
  (ch) => ch.hubAddress === hubAddress
48417
48417
  );
48418
+ const channelEntry = allMatches.find((ch) => ch.conversationId) ?? allMatches[0];
48418
48419
  if (!channelEntry) {
48419
48420
  throw new Error(`No A2A channel found for hub address: ${hubAddress}`);
48420
48421
  }
@@ -48532,11 +48533,27 @@ var init_channel = __esm({
48532
48533
  for (const ch of channels) {
48533
48534
  if (ch.status === "active" || ch.status === "approved") {
48534
48535
  const otherAddress = ch.initiatorHubAddress === this._persisted.hubAddress ? ch.responderHubAddress : ch.initiatorHubAddress;
48535
- this._persisted.a2aChannels[ch.channelId] = {
48536
- channelId: ch.channelId,
48537
- hubAddress: otherAddress,
48538
- conversationId: ch.conversationId || ""
48539
- };
48536
+ const existing = this._persisted.a2aChannels[ch.channelId];
48537
+ if (existing) {
48538
+ existing.hubAddress = otherAddress;
48539
+ existing.conversationId = ch.conversationId || existing.conversationId;
48540
+ } else {
48541
+ const role = ch.initiatorHubAddress === this._persisted.hubAddress ? "initiator" : "responder";
48542
+ this._persisted.a2aChannels[ch.channelId] = {
48543
+ channelId: ch.channelId,
48544
+ hubAddress: otherAddress,
48545
+ conversationId: ch.conversationId || "",
48546
+ role
48547
+ };
48548
+ }
48549
+ }
48550
+ }
48551
+ const activeIds = new Set(
48552
+ channels.filter((c2) => c2.status === "active" || c2.status === "approved").map((c2) => c2.channelId)
48553
+ );
48554
+ for (const id of Object.keys(this._persisted.a2aChannels)) {
48555
+ if (!activeIds.has(id)) {
48556
+ delete this._persisted.a2aChannels[id];
48540
48557
  }
48541
48558
  }
48542
48559
  await this._persistState();