@highway1/cli 0.1.33 → 0.1.35

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
@@ -116433,7 +116433,7 @@ function capKey(cap) {
116433
116433
  }
116434
116434
  async function readDIDList(dht, key) {
116435
116435
  try {
116436
- for await (const event of dht.get(key, { signal: AbortSignal.timeout(1e4) })) {
116436
+ for await (const event of dht.get(key, { signal: AbortSignal.timeout(3e4) })) {
116437
116437
  const raw = extractValue(event);
116438
116438
  if (raw) {
116439
116439
  const text = toString2(raw);
@@ -116446,11 +116446,18 @@ async function readDIDList(dht, key) {
116446
116446
  }
116447
116447
  async function writeDIDList(dht, key, dids) {
116448
116448
  const value2 = fromString2([...new Set(dids)].join("\n"));
116449
- try {
116450
- for await (const _ of dht.put(key, value2, { signal: AbortSignal.timeout(5e3) })) {
116449
+ for (let attempt = 1; attempt <= 3; attempt++) {
116450
+ try {
116451
+ for await (const _ of dht.put(key, value2, { signal: AbortSignal.timeout(3e4) })) {
116452
+ }
116453
+ return;
116454
+ } catch (e2) {
116455
+ if (e2?.name === "AbortError" && attempt < 3) {
116456
+ logger4.debug(`DHT put timeout, retrying (${attempt}/3)...`);
116457
+ continue;
116458
+ }
116459
+ if (e2?.name !== "AbortError") throw e2;
116451
116460
  }
116452
- } catch (e2) {
116453
- if (e2?.name !== "AbortError") throw e2;
116454
116461
  }
116455
116462
  }
116456
116463
  function createDHTOperations(libp2p) {
@@ -116462,11 +116469,19 @@ function createDHTOperations(libp2p) {
116462
116469
  const dht = libp2p.services?.dht;
116463
116470
  if (!dht) throw new DiscoveryError("DHT service not available");
116464
116471
  const agentKey = fromString2(`/clawiverse/agent/${card.did}`);
116465
- try {
116466
- for await (const _ of dht.put(agentKey, encodeForDHT(card), { signal: AbortSignal.timeout(5e3) })) {
116472
+ for (let attempt = 1; attempt <= 3; attempt++) {
116473
+ try {
116474
+ for await (const _ of dht.put(agentKey, encodeForDHT(card), { signal: AbortSignal.timeout(3e4) })) {
116475
+ }
116476
+ break;
116477
+ } catch (e2) {
116478
+ if (e2?.name === "AbortError" && attempt < 3) {
116479
+ logger4.debug(`DHT put agent card timeout, retrying (${attempt}/3)...`);
116480
+ continue;
116481
+ }
116482
+ logger4.warn("DHT put agent card failed (non-fatal)", { error: e2.message });
116483
+ break;
116467
116484
  }
116468
- } catch (e2) {
116469
- logger4.warn("DHT put agent card failed (non-fatal)", { error: e2.message });
116470
116485
  }
116471
116486
  const caps = (card.capabilities ?? []).map(
116472
116487
  (c2) => typeof c2 === "string" ? c2 : c2.name
@@ -118292,18 +118307,30 @@ function registerJoinCommand(program2) {
118292
118307
  info("Waiting for relay reservation...");
118293
118308
  await new Promise((resolve) => {
118294
118309
  const timeout = setTimeout(() => {
118295
- info(`Relay reservation timeout after 5s. Multiaddrs: ${node.getMultiaddrs().join(", ")}`);
118310
+ info(`Relay reservation timeout after 10s. Multiaddrs: ${node.getMultiaddrs().join(", ")}`);
118296
118311
  resolve();
118297
- }, 5e3);
118298
- const check = () => {
118312
+ }, 1e4);
118313
+ const onReservation = () => {
118314
+ info(`Relay reservation successful!`);
118315
+ clearTimeout(timeout);
118316
+ setTimeout(() => {
118317
+ info(`Relay addresses: ${node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).join(", ")}`);
118318
+ resolve();
118319
+ }, 500);
118320
+ };
118321
+ const onPeerUpdate = () => {
118299
118322
  if (hasRelayAddr()) {
118300
- info(`Relay address acquired: ${node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).join(", ")}`);
118323
+ info(`Relay address acquired via peer update`);
118301
118324
  clearTimeout(timeout);
118302
118325
  resolve();
118303
118326
  }
118304
118327
  };
118305
- node.libp2p.addEventListener("self:peer:update", check);
118306
- setTimeout(() => node.libp2p.removeEventListener("self:peer:update", check), 5e3);
118328
+ node.libp2p.addEventListener("relay:reservation", onReservation, { once: true });
118329
+ node.libp2p.addEventListener("self:peer:update", onPeerUpdate);
118330
+ setTimeout(() => {
118331
+ node.libp2p.removeEventListener("relay:reservation", onReservation);
118332
+ node.libp2p.removeEventListener("self:peer:update", onPeerUpdate);
118333
+ }, 1e4);
118307
118334
  });
118308
118335
  } else {
118309
118336
  info(`Relay address already present: ${node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).join(", ")}`);