@agentvault/agentvault 0.19.13 → 0.19.15

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
@@ -47946,12 +47946,27 @@ var init_channel = __esm({
47946
47946
  let channelEntry = a2aEntries.find((ch) => ch.hubAddress === target.hubAddress);
47947
47947
  if (!channelEntry) {
47948
47948
  try {
47949
- console.log(`[deliver] A2A channel not found for ${target.hubAddress}, re-syncing from server...`);
47950
- await this.listA2AChannels();
47951
- a2aEntries = this._persisted?.a2aChannels ? Object.values(this._persisted.a2aChannels) : [];
47952
- channelEntry = a2aEntries.find((ch) => ch.hubAddress === target.hubAddress);
47949
+ console.log(`[deliver] A2A local miss for ${target.hubAddress}, fetching from API...`);
47950
+ const channels = await this.listA2AChannels();
47951
+ const myHub = this._persisted?.hubAddress || "";
47952
+ const match = channels.find(
47953
+ (ch) => (ch.status === "active" || ch.status === "approved") && (ch.initiatorHubAddress === target.hubAddress || ch.responderHubAddress === target.hubAddress)
47954
+ );
47955
+ if (match) {
47956
+ const isInit = match.initiatorHubAddress === myHub;
47957
+ const peerId = isInit ? match.responderHubAddress : match.initiatorHubAddress;
47958
+ if (this._persisted?.a2aChannels) {
47959
+ const entry = this._persisted.a2aChannels[match.channelId];
47960
+ if (entry) {
47961
+ entry.hubAddress = peerId;
47962
+ entry.conversationId = match.conversationId || entry.conversationId;
47963
+ }
47964
+ }
47965
+ a2aEntries = this._persisted?.a2aChannels ? Object.values(this._persisted.a2aChannels) : [];
47966
+ channelEntry = a2aEntries.find((ch) => ch.hubAddress === target.hubAddress);
47967
+ }
47953
47968
  } catch (syncErr) {
47954
- console.warn("[deliver] A2A re-sync failed:", syncErr);
47969
+ console.warn("[deliver] A2A API lookup failed:", syncErr);
47955
47970
  }
47956
47971
  }
47957
47972
  if (!channelEntry) {
@@ -49095,31 +49110,37 @@ var init_channel = __esm({
49095
49110
  }
49096
49111
  if (this._persisted && convId) {
49097
49112
  if (!this._persisted.a2aChannels) this._persisted.a2aChannels = {};
49098
- const a2aEphemeral = await generateEphemeralKeypair();
49099
- const ephPubHex = bytesToHex(a2aEphemeral.publicKey);
49100
- const ephPrivHex = bytesToHex(a2aEphemeral.privateKey);
49101
- this._persisted.a2aChannels[channelId] = {
49102
- channelId,
49103
- hubAddress: peerHub,
49104
- conversationId: convId,
49105
- role,
49106
- pendingEphemeralPrivateKey: ephPrivHex
49107
- };
49108
- if (this._ws) {
49109
- this._ws.send(
49110
- JSON.stringify({
49111
- event: "a2a_key_exchange",
49112
- data: {
49113
- channel_id: channelId,
49114
- ephemeral_key: ephPubHex
49115
- }
49116
- })
49117
- );
49118
- console.log(
49119
- `[SecureChannel] A2A key exchange sent for channel ${channelId.slice(0, 8)}... (role=${role})`
49120
- );
49113
+ const existingNow = this._persisted.a2aChannels[channelId];
49114
+ if (existingNow?.pendingEphemeralPrivateKey || existingNow?.session) {
49115
+ console.log(`[SecureChannel] A2A channel ${channelId.slice(0, 8)}... key exchange already in progress, skipping`);
49116
+ } else {
49117
+ const a2aEphemeral = await generateEphemeralKeypair();
49118
+ const ephPubHex = bytesToHex(a2aEphemeral.publicKey);
49119
+ const ephPrivHex = bytesToHex(a2aEphemeral.privateKey);
49120
+ this._persisted.a2aChannels[channelId] = {
49121
+ ...existingNow,
49122
+ channelId,
49123
+ hubAddress: existingNow?.hubAddress || peerHub,
49124
+ conversationId: convId,
49125
+ role: existingNow?.role || role,
49126
+ pendingEphemeralPrivateKey: ephPrivHex
49127
+ };
49128
+ if (this._ws) {
49129
+ this._ws.send(
49130
+ JSON.stringify({
49131
+ event: "a2a_key_exchange",
49132
+ data: {
49133
+ channel_id: channelId,
49134
+ ephemeral_key: ephPubHex
49135
+ }
49136
+ })
49137
+ );
49138
+ console.log(
49139
+ `[SecureChannel] A2A key exchange sent for channel ${channelId.slice(0, 8)}... (role=${role})`
49140
+ );
49141
+ }
49142
+ await this._persistState();
49121
49143
  }
49122
- await this._persistState();
49123
49144
  }
49124
49145
  this.emit("a2a_channel_approved", channelData);
49125
49146
  if (this.config.onA2AChannelReady && convId) {