@highway1/cli 0.1.41 → 0.1.43
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 +94 -21
- package/dist/index.js.map +1 -1
- package/package.json +9 -21
- package/bin/clawiverse.js +0 -2
- package/src/commands/card.ts +0 -99
- package/src/commands/discover.ts +0 -168
- package/src/commands/identity.ts +0 -37
- package/src/commands/init.ts +0 -54
- package/src/commands/join.ts +0 -272
- package/src/commands/send.ts +0 -160
- package/src/commands/status.ts +0 -45
- package/src/commands/trust.ts +0 -215
- package/src/config.ts +0 -74
- package/src/index.ts +0 -49
- package/src/ui.ts +0 -38
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
|
-
|
|
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) => {
|
|
@@ -118327,6 +118328,7 @@ function registerJoinCommand(program2) {
|
|
|
118327
118328
|
privateKey: identity3.privateKey
|
|
118328
118329
|
});
|
|
118329
118330
|
const bootstrapPeers = options.bootstrap || getBootstrapPeers();
|
|
118331
|
+
const bootstrapPeerIds = bootstrapPeers.map((addr) => addr.split("/p2p/")[1]).filter((peerId) => Boolean(peerId));
|
|
118330
118332
|
const node = await createNode({
|
|
118331
118333
|
keyPair,
|
|
118332
118334
|
bootstrapPeers,
|
|
@@ -118340,39 +118342,80 @@ function registerJoinCommand(program2) {
|
|
|
118340
118342
|
info(`DID: ${identity3.did}`);
|
|
118341
118343
|
info(`Listening on: ${node.getMultiaddrs().join(", ")}`);
|
|
118342
118344
|
const connectSpin = spinner("Connecting to bootstrap peers...");
|
|
118345
|
+
let connected = false;
|
|
118343
118346
|
await new Promise((resolve) => {
|
|
118344
118347
|
const timeout = setTimeout(resolve, 1e4);
|
|
118345
118348
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
118349
|
+
connected = true;
|
|
118346
118350
|
clearTimeout(timeout);
|
|
118347
118351
|
resolve();
|
|
118348
118352
|
}, { once: true });
|
|
118349
118353
|
});
|
|
118354
|
+
if (!connected && bootstrapPeers.length > 0) {
|
|
118355
|
+
info("No peer discovered yet, dialing bootstrap peers...");
|
|
118356
|
+
for (const bootstrapAddr of bootstrapPeers) {
|
|
118357
|
+
try {
|
|
118358
|
+
await node.libp2p.dial(bootstrapAddr);
|
|
118359
|
+
connected = true;
|
|
118360
|
+
break;
|
|
118361
|
+
} catch {
|
|
118362
|
+
}
|
|
118363
|
+
}
|
|
118364
|
+
}
|
|
118350
118365
|
const countRelayAddrs = () => node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).length;
|
|
118351
118366
|
const initialRelayCount = countRelayAddrs();
|
|
118352
118367
|
info(`Initial relay addresses: ${initialRelayCount}`);
|
|
118353
118368
|
info("Waiting for relay reservation...");
|
|
118354
118369
|
let reservationSucceeded = false;
|
|
118355
|
-
|
|
118356
|
-
|
|
118357
|
-
|
|
118358
|
-
|
|
118359
|
-
|
|
118360
|
-
|
|
118361
|
-
|
|
118362
|
-
|
|
118363
|
-
|
|
118364
|
-
|
|
118365
|
-
|
|
118366
|
-
|
|
118367
|
-
|
|
118368
|
-
|
|
118369
|
-
|
|
118370
|
-
|
|
118371
|
-
|
|
118372
|
-
|
|
118373
|
-
|
|
118370
|
+
if (initialRelayCount === 0) {
|
|
118371
|
+
await new Promise((resolve) => {
|
|
118372
|
+
const RELAY_WAIT_MS = 3e4;
|
|
118373
|
+
const POLL_MS = 500;
|
|
118374
|
+
let settled = false;
|
|
118375
|
+
const finish = () => {
|
|
118376
|
+
if (settled) return;
|
|
118377
|
+
settled = true;
|
|
118378
|
+
clearTimeout(timeout);
|
|
118379
|
+
clearInterval(pollTimer);
|
|
118380
|
+
node.libp2p.removeEventListener("relay:reservation", onReservation);
|
|
118381
|
+
node.libp2p.removeEventListener("self:peer:update", onPeerUpdate);
|
|
118382
|
+
resolve();
|
|
118383
|
+
};
|
|
118384
|
+
const onReservation = () => {
|
|
118385
|
+
reservationSucceeded = true;
|
|
118386
|
+
info("\u2713 Relay reservation successful!");
|
|
118387
|
+
setTimeout(finish, 300);
|
|
118388
|
+
};
|
|
118389
|
+
const onPeerUpdate = () => {
|
|
118390
|
+
if (countRelayAddrs() > 0) {
|
|
118391
|
+
reservationSucceeded = true;
|
|
118392
|
+
info("\u2713 Relay address detected from peer update");
|
|
118393
|
+
finish();
|
|
118394
|
+
}
|
|
118395
|
+
};
|
|
118396
|
+
const pollTimer = setInterval(() => {
|
|
118397
|
+
if (countRelayAddrs() > 0) {
|
|
118398
|
+
reservationSucceeded = true;
|
|
118399
|
+
info("\u2713 Relay address detected");
|
|
118400
|
+
finish();
|
|
118401
|
+
}
|
|
118402
|
+
}, POLL_MS);
|
|
118403
|
+
const timeout = setTimeout(() => {
|
|
118404
|
+
if (!reservationSucceeded) {
|
|
118405
|
+
info(`Relay reservation timeout after ${RELAY_WAIT_MS / 1e3}s.`);
|
|
118406
|
+
info(`Connected peers: ${node.libp2p.getPeers().map((p2) => p2.toString()).join(", ")}`);
|
|
118407
|
+
}
|
|
118408
|
+
finish();
|
|
118409
|
+
}, RELAY_WAIT_MS);
|
|
118410
|
+
node.libp2p.addEventListener("relay:reservation", onReservation);
|
|
118411
|
+
node.libp2p.addEventListener("self:peer:update", onPeerUpdate);
|
|
118412
|
+
});
|
|
118413
|
+
} else {
|
|
118414
|
+
reservationSucceeded = true;
|
|
118415
|
+
info("\u2713 Relay address already present");
|
|
118416
|
+
}
|
|
118374
118417
|
if (!reservationSucceeded) {
|
|
118375
|
-
info("\u26A0 Relay reservation did not complete
|
|
118418
|
+
info("\u26A0 Relay reservation did not complete, continuing with fallback relay addresses");
|
|
118376
118419
|
}
|
|
118377
118420
|
connectSpin.succeed("Connected to network!");
|
|
118378
118421
|
const cardSpin = spinner("Publishing Agent Card to DHT...");
|
|
@@ -118407,6 +118450,19 @@ function registerJoinCommand(program2) {
|
|
|
118407
118450
|
const dht = createDHTOperations(node.libp2p);
|
|
118408
118451
|
await dht.publishAgentCard(signedCard);
|
|
118409
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
|
+
};
|
|
118410
118466
|
const pingInterval = setInterval(async () => {
|
|
118411
118467
|
const peers = node.libp2p.getPeers();
|
|
118412
118468
|
if (peers.length === 0) {
|
|
@@ -118419,6 +118475,7 @@ function registerJoinCommand(program2) {
|
|
|
118419
118475
|
}
|
|
118420
118476
|
}
|
|
118421
118477
|
} else {
|
|
118478
|
+
await ensureBootstrapConnections();
|
|
118422
118479
|
for (const peer of peers) {
|
|
118423
118480
|
try {
|
|
118424
118481
|
await node.libp2p.services.ping.ping(peer);
|
|
@@ -118427,6 +118484,21 @@ function registerJoinCommand(program2) {
|
|
|
118427
118484
|
}
|
|
118428
118485
|
}
|
|
118429
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);
|
|
118430
118502
|
const verifyFn = async (signature, data) => {
|
|
118431
118503
|
try {
|
|
118432
118504
|
const decoded = JSON.parse(new TextDecoder().decode(data));
|
|
@@ -118495,6 +118567,7 @@ function registerJoinCommand(program2) {
|
|
|
118495
118567
|
console.log();
|
|
118496
118568
|
const stopSpin = spinner("Stopping node...");
|
|
118497
118569
|
clearInterval(pingInterval);
|
|
118570
|
+
node.libp2p.removeEventListener("peer:disconnect", onPeerDisconnect);
|
|
118498
118571
|
await router.stop();
|
|
118499
118572
|
await node.stop();
|
|
118500
118573
|
stopSpin.succeed("Node stopped");
|