@agentvault/agentvault 0.19.10 → 0.19.12

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
@@ -47942,8 +47942,18 @@ var init_channel = __esm({
47942
47942
  }
47943
47943
  resolved = { kind: "room", id: target.roomId };
47944
47944
  } else if (target.kind === "a2a") {
47945
- const a2aEntries = this._persisted?.a2aChannels ? Object.values(this._persisted.a2aChannels) : [];
47946
- const channelEntry = a2aEntries.find((ch) => ch.hubAddress === target.hubAddress);
47945
+ let a2aEntries = this._persisted?.a2aChannels ? Object.values(this._persisted.a2aChannels) : [];
47946
+ let channelEntry = a2aEntries.find((ch) => ch.hubAddress === target.hubAddress);
47947
+ if (!channelEntry) {
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);
47953
+ } catch (syncErr) {
47954
+ console.warn("[deliver] A2A re-sync failed:", syncErr);
47955
+ }
47956
+ }
47947
47957
  if (!channelEntry) {
47948
47958
  const storedAddresses = a2aEntries.map((ch) => ch.hubAddress).join(", ") || "(none)";
47949
47959
  const err = `No A2A channel found for hub address: ${target.hubAddress} (stored: ${storedAddresses})`;
@@ -48412,12 +48422,31 @@ var init_channel = __esm({
48412
48422
  */
48413
48423
  async sendToAgent(hubAddress, text, opts) {
48414
48424
  if (!this._persisted?.a2aChannels) {
48415
- throw new Error("No A2A channels established");
48425
+ try {
48426
+ await this.listA2AChannels();
48427
+ } catch {
48428
+ }
48429
+ if (!this._persisted?.a2aChannels) {
48430
+ throw new Error("No A2A channels established");
48431
+ }
48416
48432
  }
48417
- const allMatches = Object.values(this._persisted.a2aChannels).filter(
48433
+ const a2a = this._persisted.a2aChannels;
48434
+ let allMatches = Object.values(a2a).filter(
48418
48435
  (ch) => ch.hubAddress === hubAddress
48419
48436
  );
48420
- const channelEntry = allMatches.find((ch) => ch.conversationId) ?? allMatches[0];
48437
+ let channelEntry = allMatches.find((ch) => ch.conversationId) ?? allMatches[0];
48438
+ if (!channelEntry) {
48439
+ try {
48440
+ console.log(`[sendToAgent] Channel not found for ${hubAddress}, re-syncing from server...`);
48441
+ await this.listA2AChannels();
48442
+ allMatches = Object.values(this._persisted.a2aChannels ?? {}).filter(
48443
+ (ch) => ch.hubAddress === hubAddress
48444
+ );
48445
+ channelEntry = allMatches.find((ch) => ch.conversationId) ?? allMatches[0];
48446
+ } catch (syncErr) {
48447
+ console.warn("[sendToAgent] A2A re-sync failed:", syncErr);
48448
+ }
48449
+ }
48421
48450
  if (!channelEntry) {
48422
48451
  throw new Error(`No A2A channel found for hub address: ${hubAddress}`);
48423
48452
  }
@@ -49054,66 +49083,51 @@ var init_channel = __esm({
49054
49083
  const channelId = channelData.channel_id;
49055
49084
  const convId = channelData.conversation_id;
49056
49085
  const existingEntry = this._persisted?.a2aChannels?.[channelId];
49057
- if (existingEntry?.conversationId && existingEntry?.hubAddress && (existingEntry.session || existingEntry.pendingEphemeralPrivateKey)) {
49058
- console.log(
49059
- `[SecureChannel] A2A channel ${channelId.slice(0, 8)}... already synced (peer=${existingEntry.hubAddress}), skipping approved event`
49086
+ const myHub = this._persisted?.hubAddress || "";
49087
+ const role = existingEntry?.role || channelData.role || (myHub && channelData.initiator_hub_address === myHub ? "initiator" : "responder");
49088
+ const peerHub = existingEntry?.hubAddress || (role === "initiator" ? channelData.responder_hub_address || "" : channelData.initiator_hub_address || "");
49089
+ if (!myHub && !existingEntry?.hubAddress) {
49090
+ console.warn(
49091
+ `[SecureChannel] WARNING: hubAddress not set during a2a_channel_approved \u2014 peer address may be wrong (role=${role} peer=${peerHub})`
49060
49092
  );
49061
- this.emit("a2a_channel_approved", channelData);
49062
- if (this.config.onA2AChannelReady && convId) {
49063
- this.config.onA2AChannelReady({
49064
- channelId,
49065
- peerHubAddress: existingEntry.hubAddress,
49066
- role: existingEntry.role || "responder",
49067
- conversationId: existingEntry.conversationId
49068
- });
49069
- }
49070
- } else {
49071
- const myHub = this._persisted?.hubAddress || "";
49072
- const role = channelData.role || (myHub && channelData.initiator_hub_address === myHub ? "initiator" : "responder");
49073
- const peerHub = role === "initiator" ? channelData.responder_hub_address || "" : channelData.initiator_hub_address || "";
49074
- if (!myHub) {
49075
- console.warn(
49076
- `[SecureChannel] WARNING: hubAddress not set during a2a_channel_approved \u2014 peer address may be wrong (role=${role} peer=${peerHub})`
49093
+ }
49094
+ if (this._persisted && convId) {
49095
+ if (!this._persisted.a2aChannels) this._persisted.a2aChannels = {};
49096
+ const a2aEphemeral = await generateEphemeralKeypair();
49097
+ const ephPubHex = bytesToHex(a2aEphemeral.publicKey);
49098
+ const ephPrivHex = bytesToHex(a2aEphemeral.privateKey);
49099
+ this._persisted.a2aChannels[channelId] = {
49100
+ channelId,
49101
+ hubAddress: peerHub,
49102
+ conversationId: convId,
49103
+ role,
49104
+ pendingEphemeralPrivateKey: ephPrivHex
49105
+ };
49106
+ if (this._ws) {
49107
+ this._ws.send(
49108
+ JSON.stringify({
49109
+ event: "a2a_key_exchange",
49110
+ data: {
49111
+ channel_id: channelId,
49112
+ ephemeral_key: ephPubHex
49113
+ }
49114
+ })
49115
+ );
49116
+ console.log(
49117
+ `[SecureChannel] A2A key exchange sent for channel ${channelId.slice(0, 8)}... (role=${role})`
49077
49118
  );
49078
49119
  }
49079
- if (this._persisted && convId) {
49080
- if (!this._persisted.a2aChannels) this._persisted.a2aChannels = {};
49081
- const a2aEphemeral = await generateEphemeralKeypair();
49082
- const ephPubHex = bytesToHex(a2aEphemeral.publicKey);
49083
- const ephPrivHex = bytesToHex(a2aEphemeral.privateKey);
49084
- this._persisted.a2aChannels[channelId] = {
49085
- channelId,
49086
- hubAddress: peerHub,
49087
- conversationId: convId,
49088
- role,
49089
- pendingEphemeralPrivateKey: ephPrivHex
49090
- };
49091
- if (this._ws) {
49092
- this._ws.send(
49093
- JSON.stringify({
49094
- event: "a2a_key_exchange",
49095
- data: {
49096
- channel_id: channelId,
49097
- ephemeral_key: ephPubHex
49098
- }
49099
- })
49100
- );
49101
- console.log(
49102
- `[SecureChannel] A2A key exchange sent for channel ${channelId.slice(0, 8)}... (role=${role})`
49103
- );
49104
- }
49105
- await this._persistState();
49106
- }
49107
- this.emit("a2a_channel_approved", channelData);
49108
- if (this.config.onA2AChannelReady && convId) {
49109
- this.config.onA2AChannelReady({
49110
- channelId,
49111
- peerHubAddress: peerHub,
49112
- role,
49113
- conversationId: convId,
49114
- topic: channelData.topic || void 0
49115
- });
49116
- }
49120
+ await this._persistState();
49121
+ }
49122
+ this.emit("a2a_channel_approved", channelData);
49123
+ if (this.config.onA2AChannelReady && convId) {
49124
+ this.config.onA2AChannelReady({
49125
+ channelId,
49126
+ peerHubAddress: peerHub,
49127
+ role,
49128
+ conversationId: convId,
49129
+ topic: channelData.topic || void 0
49130
+ });
49117
49131
  }
49118
49132
  }
49119
49133
  if (data.event === "a2a_channel_activated") {