@highway1/cli 0.1.40 → 0.1.42

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
@@ -116515,7 +116515,8 @@ function createDHTOperations(libp2p) {
116515
116515
  searchEngine.indexAgentCard(card);
116516
116516
  logger4.info("Published Agent Card to DHT", { did: card.did });
116517
116517
  } catch (error2) {
116518
- throw new DiscoveryError("Failed to publish Agent Card", error2);
116518
+ logger4.warn("Failed to publish Agent Card to DHT (non-fatal)", { error: error2.message });
116519
+ searchEngine.indexAgentCard(card);
116519
116520
  }
116520
116521
  },
116521
116522
  queryAgentCard: async (did) => {
@@ -118340,39 +118341,80 @@ function registerJoinCommand(program2) {
118340
118341
  info(`DID: ${identity3.did}`);
118341
118342
  info(`Listening on: ${node.getMultiaddrs().join(", ")}`);
118342
118343
  const connectSpin = spinner("Connecting to bootstrap peers...");
118344
+ let connected = false;
118343
118345
  await new Promise((resolve) => {
118344
118346
  const timeout = setTimeout(resolve, 1e4);
118345
118347
  node.libp2p.addEventListener("peer:connect", () => {
118348
+ connected = true;
118346
118349
  clearTimeout(timeout);
118347
118350
  resolve();
118348
118351
  }, { once: true });
118349
118352
  });
118353
+ if (!connected && bootstrapPeers.length > 0) {
118354
+ info("No peer discovered yet, dialing bootstrap peers...");
118355
+ for (const bootstrapAddr of bootstrapPeers) {
118356
+ try {
118357
+ await node.libp2p.dial(bootstrapAddr);
118358
+ connected = true;
118359
+ break;
118360
+ } catch {
118361
+ }
118362
+ }
118363
+ }
118350
118364
  const countRelayAddrs = () => node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).length;
118351
118365
  const initialRelayCount = countRelayAddrs();
118352
118366
  info(`Initial relay addresses: ${initialRelayCount}`);
118353
118367
  info("Waiting for relay reservation...");
118354
118368
  let reservationSucceeded = false;
118355
- await new Promise((resolve) => {
118356
- const timeout = setTimeout(() => {
118357
- if (!reservationSucceeded) {
118358
- info(`Relay reservation timeout after 15s.`);
118359
- info(`Connected peers: ${node.libp2p.getPeers().map((p2) => p2.toString()).join(", ")}`);
118360
- }
118361
- resolve();
118362
- }, 15e3);
118363
- const onReservation = () => {
118364
- reservationSucceeded = true;
118365
- info(`\u2713 Relay reservation successful!`);
118366
- clearTimeout(timeout);
118367
- setTimeout(resolve, 500);
118368
- };
118369
- node.libp2p.addEventListener("relay:reservation", onReservation, { once: true });
118370
- setTimeout(() => {
118371
- node.libp2p.removeEventListener("relay:reservation", onReservation);
118372
- }, 15e3);
118373
- });
118369
+ if (initialRelayCount === 0) {
118370
+ await new Promise((resolve) => {
118371
+ const RELAY_WAIT_MS = 3e4;
118372
+ const POLL_MS = 500;
118373
+ let settled = false;
118374
+ const finish = () => {
118375
+ if (settled) return;
118376
+ settled = true;
118377
+ clearTimeout(timeout);
118378
+ clearInterval(pollTimer);
118379
+ node.libp2p.removeEventListener("relay:reservation", onReservation);
118380
+ node.libp2p.removeEventListener("self:peer:update", onPeerUpdate);
118381
+ resolve();
118382
+ };
118383
+ const onReservation = () => {
118384
+ reservationSucceeded = true;
118385
+ info("\u2713 Relay reservation successful!");
118386
+ setTimeout(finish, 300);
118387
+ };
118388
+ const onPeerUpdate = () => {
118389
+ if (countRelayAddrs() > 0) {
118390
+ reservationSucceeded = true;
118391
+ info("\u2713 Relay address detected from peer update");
118392
+ finish();
118393
+ }
118394
+ };
118395
+ const pollTimer = setInterval(() => {
118396
+ if (countRelayAddrs() > 0) {
118397
+ reservationSucceeded = true;
118398
+ info("\u2713 Relay address detected");
118399
+ finish();
118400
+ }
118401
+ }, POLL_MS);
118402
+ const timeout = setTimeout(() => {
118403
+ if (!reservationSucceeded) {
118404
+ info(`Relay reservation timeout after ${RELAY_WAIT_MS / 1e3}s.`);
118405
+ info(`Connected peers: ${node.libp2p.getPeers().map((p2) => p2.toString()).join(", ")}`);
118406
+ }
118407
+ finish();
118408
+ }, RELAY_WAIT_MS);
118409
+ node.libp2p.addEventListener("relay:reservation", onReservation);
118410
+ node.libp2p.addEventListener("self:peer:update", onPeerUpdate);
118411
+ });
118412
+ } else {
118413
+ reservationSucceeded = true;
118414
+ info("\u2713 Relay address already present");
118415
+ }
118374
118416
  if (!reservationSucceeded) {
118375
- info("\u26A0 Relay reservation did not complete - using fallback relay addresses");
118417
+ info("\u26A0 Relay reservation did not complete, continuing with fallback relay addresses");
118376
118418
  }
118377
118419
  connectSpin.succeed("Connected to network!");
118378
118420
  const cardSpin = spinner("Publishing Agent Card to DHT...");