@highway1/cli 0.1.42 → 0.1.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
@@ -116492,7 +116492,7 @@ function createDHTOperations(libp2p) {
116492
116492
  }
116493
116493
  const caps = (card.capabilities ?? []).flatMap((c2) => {
116494
116494
  if (typeof c2 === "string") return [c2];
116495
- return [c2.name, c2.id].filter(Boolean);
116495
+ return [c2.name, c2.id].filter((v) => typeof v === "string" && v.length > 0);
116496
116496
  });
116497
116497
  caps.push("__all__");
116498
116498
  const importantCaps = ["__all__"];
@@ -118328,6 +118328,7 @@ function registerJoinCommand(program2) {
118328
118328
  privateKey: identity3.privateKey
118329
118329
  });
118330
118330
  const bootstrapPeers = options.bootstrap || getBootstrapPeers();
118331
+ const bootstrapPeerIds = bootstrapPeers.map((addr) => addr.split("/p2p/")[1]).filter((peerId) => Boolean(peerId));
118331
118332
  const node = await createNode({
118332
118333
  keyPair,
118333
118334
  bootstrapPeers,
@@ -118449,6 +118450,19 @@ function registerJoinCommand(program2) {
118449
118450
  const dht = createDHTOperations(node.libp2p);
118450
118451
  await dht.publishAgentCard(signedCard);
118451
118452
  cardSpin.succeed("Agent Card published!");
118453
+ const ensureBootstrapConnections = async () => {
118454
+ const connections = node.libp2p.getConnections();
118455
+ const connectedPeerIds = new Set(connections.map((conn) => conn.remotePeer.toString()));
118456
+ for (const bootstrapAddr of bootstrapPeers) {
118457
+ const targetPeerId = bootstrapAddr.split("/p2p/")[1];
118458
+ if (!targetPeerId || connectedPeerIds.has(targetPeerId)) continue;
118459
+ try {
118460
+ await node.libp2p.dial(bootstrapAddr);
118461
+ info(`Reconnected bootstrap peer: ${targetPeerId}`);
118462
+ } catch {
118463
+ }
118464
+ }
118465
+ };
118452
118466
  const pingInterval = setInterval(async () => {
118453
118467
  const peers = node.libp2p.getPeers();
118454
118468
  if (peers.length === 0) {
@@ -118461,6 +118475,7 @@ function registerJoinCommand(program2) {
118461
118475
  }
118462
118476
  }
118463
118477
  } else {
118478
+ await ensureBootstrapConnections();
118464
118479
  for (const peer of peers) {
118465
118480
  try {
118466
118481
  await node.libp2p.services.ping.ping(peer);
@@ -118469,6 +118484,21 @@ function registerJoinCommand(program2) {
118469
118484
  }
118470
118485
  }
118471
118486
  }, 15e3);
118487
+ const onPeerDisconnect = async (evt) => {
118488
+ const disconnectedPeerId = evt?.detail?.toString?.() ?? "";
118489
+ if (!bootstrapPeerIds.includes(disconnectedPeerId)) return;
118490
+ info(`Bootstrap peer disconnected: ${disconnectedPeerId}, attempting reconnect...`);
118491
+ for (const bootstrapAddr of bootstrapPeers) {
118492
+ if (!bootstrapAddr.endsWith(`/p2p/${disconnectedPeerId}`)) continue;
118493
+ try {
118494
+ await node.libp2p.dial(bootstrapAddr);
118495
+ info(`Recovered bootstrap connection: ${disconnectedPeerId}`);
118496
+ return;
118497
+ } catch {
118498
+ }
118499
+ }
118500
+ };
118501
+ node.libp2p.addEventListener("peer:disconnect", onPeerDisconnect);
118472
118502
  const verifyFn = async (signature, data) => {
118473
118503
  try {
118474
118504
  const decoded = JSON.parse(new TextDecoder().decode(data));
@@ -118537,6 +118567,7 @@ function registerJoinCommand(program2) {
118537
118567
  console.log();
118538
118568
  const stopSpin = spinner("Stopping node...");
118539
118569
  clearInterval(pingInterval);
118570
+ node.libp2p.removeEventListener("peer:disconnect", onPeerDisconnect);
118540
118571
  await router.stop();
118541
118572
  await node.stop();
118542
118573
  stopSpin.succeed("Node stopped");