@highway1/cli 0.1.23 → 0.1.25
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 +55 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/join.ts +42 -9
- package/src/commands/send.ts +10 -1
package/dist/index.js
CHANGED
|
@@ -115999,7 +115999,7 @@ var init_fuse = __esm({
|
|
|
115999
115999
|
}
|
|
116000
116000
|
});
|
|
116001
116001
|
|
|
116002
|
-
//
|
|
116002
|
+
// ../../node_modules/.pnpm/@highway1+core@0.1.19/node_modules/@highway1/core/dist/index.js
|
|
116003
116003
|
var dist_exports = {};
|
|
116004
116004
|
__export(dist_exports, {
|
|
116005
116005
|
CLAWIVERSE_CONTEXT: () => CLAWIVERSE_CONTEXT,
|
|
@@ -116424,7 +116424,7 @@ function capKey(cap) {
|
|
|
116424
116424
|
}
|
|
116425
116425
|
async function readDIDList(dht, key) {
|
|
116426
116426
|
try {
|
|
116427
|
-
for await (const event of dht.get(key)) {
|
|
116427
|
+
for await (const event of dht.get(key, { signal: AbortSignal.timeout(1e4) })) {
|
|
116428
116428
|
const raw = extractValue(event);
|
|
116429
116429
|
if (raw) {
|
|
116430
116430
|
const text = toString2(raw);
|
|
@@ -116437,7 +116437,11 @@ async function readDIDList(dht, key) {
|
|
|
116437
116437
|
}
|
|
116438
116438
|
async function writeDIDList(dht, key, dids) {
|
|
116439
116439
|
const value2 = fromString2([...new Set(dids)].join("\n"));
|
|
116440
|
-
|
|
116440
|
+
try {
|
|
116441
|
+
for await (const _ of dht.put(key, value2, { signal: AbortSignal.timeout(1e4) })) {
|
|
116442
|
+
}
|
|
116443
|
+
} catch (e2) {
|
|
116444
|
+
if (e2?.name !== "AbortError") throw e2;
|
|
116441
116445
|
}
|
|
116442
116446
|
}
|
|
116443
116447
|
function createDHTOperations(libp2p) {
|
|
@@ -116449,7 +116453,11 @@ function createDHTOperations(libp2p) {
|
|
|
116449
116453
|
const dht = libp2p.services?.dht;
|
|
116450
116454
|
if (!dht) throw new DiscoveryError("DHT service not available");
|
|
116451
116455
|
const agentKey = fromString2(`/clawiverse/agent/${card.did}`);
|
|
116452
|
-
|
|
116456
|
+
try {
|
|
116457
|
+
for await (const _ of dht.put(agentKey, encodeForDHT(card), { signal: AbortSignal.timeout(1e4) })) {
|
|
116458
|
+
}
|
|
116459
|
+
} catch (e2) {
|
|
116460
|
+
if (e2?.name !== "AbortError") throw e2;
|
|
116453
116461
|
}
|
|
116454
116462
|
const caps = (card.capabilities ?? []).map(
|
|
116455
116463
|
(c2) => typeof c2 === "string" ? c2 : c2.name
|
|
@@ -116887,7 +116895,7 @@ function createTrustSystem(config2) {
|
|
|
116887
116895
|
}
|
|
116888
116896
|
var import_ajv, import_lunr, ClawiverseError, IdentityError, TransportError, DiscoveryError, MessagingError, LogLevel, Logger, createLogger, logger2, legacyAgentCardSchema, ajv, validateLegacySchema, CLAWIVERSE_CONTEXT, SCHEMA_ORG_CONTEXT, clawiverseContext, CapabilityTypes, ParameterTypes, logger22, SearchIndex, CapabilityMatcher, logger3, SemanticSearchEngine, logger4, logger5, TrustMetrics, logger6, InteractionHistory, logger7, EndorsementManager, logger8, SybilDefense, logger9, TrustSystem;
|
|
116889
116897
|
var init_dist3 = __esm({
|
|
116890
|
-
"
|
|
116898
|
+
"../../node_modules/.pnpm/@highway1+core@0.1.19/node_modules/@highway1/core/dist/index.js"() {
|
|
116891
116899
|
init_esm_shims();
|
|
116892
116900
|
init_ed25519();
|
|
116893
116901
|
init_base58();
|
|
@@ -118202,7 +118210,7 @@ function registerInitCommand(program2) {
|
|
|
118202
118210
|
init_esm_shims();
|
|
118203
118211
|
init_dist3();
|
|
118204
118212
|
function registerJoinCommand(program2) {
|
|
118205
|
-
program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").action(async (options) => {
|
|
118213
|
+
program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").option("--relay", "Run as a relay server and advertise relay capability").action(async (options) => {
|
|
118206
118214
|
try {
|
|
118207
118215
|
printHeader("Join Clawiverse Network");
|
|
118208
118216
|
const identity3 = getIdentity();
|
|
@@ -118221,7 +118229,8 @@ function registerJoinCommand(program2) {
|
|
|
118221
118229
|
keyPair,
|
|
118222
118230
|
bootstrapPeers,
|
|
118223
118231
|
enableDHT: true,
|
|
118224
|
-
reserveRelaySlot: true
|
|
118232
|
+
reserveRelaySlot: true,
|
|
118233
|
+
enableRelay: options.relay ?? false
|
|
118225
118234
|
});
|
|
118226
118235
|
await node.start();
|
|
118227
118236
|
spin.succeed("Node started successfully!");
|
|
@@ -118233,22 +118242,36 @@ function registerJoinCommand(program2) {
|
|
|
118233
118242
|
const timeout = setTimeout(resolve, 1e4);
|
|
118234
118243
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
118235
118244
|
clearTimeout(timeout);
|
|
118236
|
-
|
|
118245
|
+
resolve();
|
|
118237
118246
|
}, { once: true });
|
|
118238
118247
|
});
|
|
118248
|
+
const hasRelayAddr = () => node.getMultiaddrs().some((a2) => a2.includes("/p2p-circuit"));
|
|
118249
|
+
if (!hasRelayAddr()) {
|
|
118250
|
+
await new Promise((resolve) => {
|
|
118251
|
+
const timeout = setTimeout(resolve, 5e3);
|
|
118252
|
+
const check = () => {
|
|
118253
|
+
if (hasRelayAddr()) {
|
|
118254
|
+
clearTimeout(timeout);
|
|
118255
|
+
resolve();
|
|
118256
|
+
}
|
|
118257
|
+
};
|
|
118258
|
+
node.libp2p.addEventListener("self:multiaddress:updated", check);
|
|
118259
|
+
setTimeout(() => node.libp2p.removeEventListener("self:multiaddress:updated", check), 5e3);
|
|
118260
|
+
});
|
|
118261
|
+
}
|
|
118239
118262
|
connectSpin.succeed("Connected to network!");
|
|
118240
118263
|
const cardSpin = spinner("Publishing Agent Card to DHT...");
|
|
118241
|
-
const directAddrs = node.getMultiaddrs();
|
|
118242
|
-
const relayAddrs =
|
|
118243
|
-
|
|
118244
|
-
|
|
118245
|
-
|
|
118246
|
-
|
|
118264
|
+
const directAddrs = node.getMultiaddrs().filter((a2) => !a2.includes("/p2p-circuit"));
|
|
118265
|
+
const relayAddrs = node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit"));
|
|
118266
|
+
const fallbackRelayAddrs = relayAddrs.length === 0 ? bootstrapPeers.map((r2) => `${r2}/p2p-circuit/p2p/${node.getPeerId()}`) : [];
|
|
118267
|
+
const allAddrs = [...directAddrs, ...relayAddrs, ...fallbackRelayAddrs];
|
|
118268
|
+
const capabilities = [...card.capabilities ?? []];
|
|
118269
|
+
if (options.relay) capabilities.push("relay");
|
|
118247
118270
|
const agentCard = createAgentCard(
|
|
118248
118271
|
identity3.did,
|
|
118249
118272
|
card.name,
|
|
118250
118273
|
card.description,
|
|
118251
|
-
|
|
118274
|
+
capabilities,
|
|
118252
118275
|
allAddrs,
|
|
118253
118276
|
node.getPeerId()
|
|
118254
118277
|
);
|
|
@@ -118259,6 +118282,14 @@ function registerJoinCommand(program2) {
|
|
|
118259
118282
|
const dht = createDHTOperations(node.libp2p);
|
|
118260
118283
|
await dht.publishAgentCard(signedCard);
|
|
118261
118284
|
cardSpin.succeed("Agent Card published!");
|
|
118285
|
+
const pingInterval = setInterval(async () => {
|
|
118286
|
+
for (const peer of node.libp2p.getPeers()) {
|
|
118287
|
+
try {
|
|
118288
|
+
await node.libp2p.services.ping.ping(peer);
|
|
118289
|
+
} catch {
|
|
118290
|
+
}
|
|
118291
|
+
}
|
|
118292
|
+
}, 3e4);
|
|
118262
118293
|
const router = createMessageRouter(
|
|
118263
118294
|
node.libp2p,
|
|
118264
118295
|
async () => true,
|
|
@@ -118316,6 +118347,7 @@ function registerJoinCommand(program2) {
|
|
|
118316
118347
|
process.on("SIGINT", async () => {
|
|
118317
118348
|
console.log();
|
|
118318
118349
|
const stopSpin = spinner("Stopping node...");
|
|
118350
|
+
clearInterval(pingInterval);
|
|
118319
118351
|
await router.stop();
|
|
118320
118352
|
await node.stop();
|
|
118321
118353
|
stopSpin.succeed("Node stopped");
|
|
@@ -118480,9 +118512,16 @@ function registerSendCommand(program2) {
|
|
|
118480
118512
|
bootstrapPeers,
|
|
118481
118513
|
enableDHT: true
|
|
118482
118514
|
});
|
|
118515
|
+
const identifyDone = new Promise((resolve) => {
|
|
118516
|
+
const timeout = setTimeout(resolve, 12e3);
|
|
118517
|
+
node.libp2p.addEventListener("peer:identify", () => {
|
|
118518
|
+
clearTimeout(timeout);
|
|
118519
|
+
setTimeout(resolve, 500);
|
|
118520
|
+
}, { once: true });
|
|
118521
|
+
});
|
|
118483
118522
|
await node.start();
|
|
118484
118523
|
spin.text = "Connecting to network...";
|
|
118485
|
-
await
|
|
118524
|
+
await identifyDone;
|
|
118486
118525
|
const dht = createDHTOperations(node.libp2p);
|
|
118487
118526
|
const router = createMessageRouter(
|
|
118488
118527
|
node.libp2p,
|