@highway1/cli 0.1.17 → 0.1.19
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 +91 -37
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/discover.ts +2 -2
- package/src/commands/join.ts +89 -32
package/dist/index.js
CHANGED
|
@@ -116189,7 +116189,12 @@ async function createNode(config2) {
|
|
|
116189
116189
|
}
|
|
116190
116190
|
};
|
|
116191
116191
|
if (enableRelay) {
|
|
116192
|
-
libp2pConfig.services.relay = circuitRelayServer(
|
|
116192
|
+
libp2pConfig.services.relay = circuitRelayServer({
|
|
116193
|
+
reservations: {
|
|
116194
|
+
maxReservations: 100
|
|
116195
|
+
// Allow up to 100 concurrent relay reservations
|
|
116196
|
+
}
|
|
116197
|
+
});
|
|
116193
116198
|
}
|
|
116194
116199
|
if (enableDHT) {
|
|
116195
116200
|
libp2pConfig.services.dht = kadDHT({
|
|
@@ -116523,10 +116528,6 @@ function createDHTOperations(libp2p) {
|
|
|
116523
116528
|
},
|
|
116524
116529
|
searchSemantic: async (query) => {
|
|
116525
116530
|
try {
|
|
116526
|
-
const local = searchEngine.getAllIndexedCards();
|
|
116527
|
-
if (local.length > 0) {
|
|
116528
|
-
return searchEngine.search(query);
|
|
116529
|
-
}
|
|
116530
116531
|
const dht = libp2p.services?.dht;
|
|
116531
116532
|
if (dht) {
|
|
116532
116533
|
const allKey = fromString2("/clawiverse/cap/__all__");
|
|
@@ -118220,16 +118221,23 @@ function registerInitCommand(program2) {
|
|
|
118220
118221
|
init_esm_shims();
|
|
118221
118222
|
init_dist3();
|
|
118222
118223
|
function registerJoinCommand(program2) {
|
|
118223
|
-
program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").action(async (options) => {
|
|
118224
|
+
program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").option("--json", "Output messages as JSON (for agent automation)").action(async (options) => {
|
|
118224
118225
|
try {
|
|
118225
|
-
|
|
118226
|
+
const jsonMode = options.json;
|
|
118227
|
+
if (!jsonMode) {
|
|
118228
|
+
printHeader("Join Clawiverse Network");
|
|
118229
|
+
}
|
|
118226
118230
|
const identity3 = getIdentity();
|
|
118227
118231
|
const card = getAgentCard();
|
|
118228
118232
|
if (!identity3 || !card) {
|
|
118229
|
-
|
|
118233
|
+
if (jsonMode) {
|
|
118234
|
+
console.log(JSON.stringify({ error: 'No identity found. Run "hw1 init" first.' }));
|
|
118235
|
+
} else {
|
|
118236
|
+
error('No identity found. Run "hw1 init" first.');
|
|
118237
|
+
}
|
|
118230
118238
|
process.exit(1);
|
|
118231
118239
|
}
|
|
118232
|
-
const spin = spinner("Starting libp2p node...");
|
|
118240
|
+
const spin = jsonMode ? null : spinner("Starting libp2p node...");
|
|
118233
118241
|
const keyPair = importKeyPair({
|
|
118234
118242
|
publicKey: identity3.publicKey,
|
|
118235
118243
|
privateKey: identity3.privateKey
|
|
@@ -118241,11 +118249,20 @@ function registerJoinCommand(program2) {
|
|
|
118241
118249
|
enableDHT: true
|
|
118242
118250
|
});
|
|
118243
118251
|
await node.start();
|
|
118244
|
-
spin
|
|
118245
|
-
|
|
118246
|
-
|
|
118247
|
-
|
|
118248
|
-
|
|
118252
|
+
if (spin) {
|
|
118253
|
+
spin.succeed("Node started successfully!");
|
|
118254
|
+
info(`Peer ID: ${node.getPeerId()}`);
|
|
118255
|
+
info(`DID: ${identity3.did}`);
|
|
118256
|
+
info(`Listening on: ${node.getMultiaddrs().join(", ")}`);
|
|
118257
|
+
} else {
|
|
118258
|
+
console.log(JSON.stringify({
|
|
118259
|
+
event: "node_started",
|
|
118260
|
+
peerId: node.getPeerId(),
|
|
118261
|
+
did: identity3.did,
|
|
118262
|
+
multiaddrs: node.getMultiaddrs()
|
|
118263
|
+
}));
|
|
118264
|
+
}
|
|
118265
|
+
const connectSpin = jsonMode ? null : spinner("Connecting to bootstrap peers...");
|
|
118249
118266
|
await new Promise((resolve) => {
|
|
118250
118267
|
const timeout = setTimeout(resolve, 1e4);
|
|
118251
118268
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
@@ -118253,8 +118270,10 @@ function registerJoinCommand(program2) {
|
|
|
118253
118270
|
setTimeout(resolve, 500);
|
|
118254
118271
|
}, { once: true });
|
|
118255
118272
|
});
|
|
118256
|
-
connectSpin
|
|
118257
|
-
|
|
118273
|
+
if (connectSpin) {
|
|
118274
|
+
connectSpin.succeed("Connected to network!");
|
|
118275
|
+
}
|
|
118276
|
+
const cardSpin = jsonMode ? null : spinner("Publishing Agent Card to DHT...");
|
|
118258
118277
|
const directAddrs = node.getMultiaddrs();
|
|
118259
118278
|
const relayAddrs = bootstrapPeers.map((relayAddr) => {
|
|
118260
118279
|
const peerId = node.getPeerId();
|
|
@@ -118275,7 +118294,11 @@ function registerJoinCommand(program2) {
|
|
|
118275
118294
|
);
|
|
118276
118295
|
const dht = createDHTOperations(node.libp2p);
|
|
118277
118296
|
await dht.publishAgentCard(signedCard);
|
|
118278
|
-
cardSpin
|
|
118297
|
+
if (cardSpin) {
|
|
118298
|
+
cardSpin.succeed("Agent Card published!");
|
|
118299
|
+
} else {
|
|
118300
|
+
console.log(JSON.stringify({ event: "agent_card_published" }));
|
|
118301
|
+
}
|
|
118279
118302
|
const router = createMessageRouter(
|
|
118280
118303
|
node.libp2p,
|
|
118281
118304
|
async () => true,
|
|
@@ -118283,15 +118306,30 @@ function registerJoinCommand(program2) {
|
|
|
118283
118306
|
);
|
|
118284
118307
|
const messageHandler = async (envelope) => {
|
|
118285
118308
|
const payload = envelope.payload;
|
|
118286
|
-
|
|
118287
|
-
|
|
118288
|
-
|
|
118289
|
-
|
|
118290
|
-
|
|
118291
|
-
|
|
118292
|
-
|
|
118309
|
+
if (jsonMode) {
|
|
118310
|
+
console.log(JSON.stringify({
|
|
118311
|
+
event: "message_received",
|
|
118312
|
+
id: envelope.id,
|
|
118313
|
+
from: envelope.from,
|
|
118314
|
+
to: envelope.to,
|
|
118315
|
+
protocol: envelope.protocol,
|
|
118316
|
+
type: envelope.type,
|
|
118317
|
+
payload,
|
|
118318
|
+
timestamp: Date.now()
|
|
118319
|
+
}));
|
|
118320
|
+
} else {
|
|
118321
|
+
console.log();
|
|
118322
|
+
success(`>>> Received message from ${envelope.from}`);
|
|
118323
|
+
info(` Message ID: ${envelope.id}`);
|
|
118324
|
+
info(` Protocol: ${envelope.protocol}`);
|
|
118325
|
+
info(` Type: ${envelope.type}`);
|
|
118326
|
+
info(` Payload: ${JSON.stringify(payload, null, 2)}`);
|
|
118327
|
+
console.log();
|
|
118328
|
+
}
|
|
118293
118329
|
if (envelope.type === "request") {
|
|
118294
|
-
|
|
118330
|
+
if (!jsonMode) {
|
|
118331
|
+
info(" Sending acknowledgment response...");
|
|
118332
|
+
}
|
|
118295
118333
|
const { createEnvelope: createEnvelope2, signEnvelope: signEnvelope2, sign: sign2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports));
|
|
118296
118334
|
const identity4 = getIdentity();
|
|
118297
118335
|
const keyPair2 = importKeyPair({
|
|
@@ -118326,22 +118364,38 @@ function registerJoinCommand(program2) {
|
|
|
118326
118364
|
router.registerHandler("/clawiverse/greet/1.0.0", messageHandler);
|
|
118327
118365
|
router.registerCatchAllHandler(messageHandler);
|
|
118328
118366
|
await router.start();
|
|
118329
|
-
|
|
118330
|
-
success("Successfully joined the Clawiverse network!");
|
|
118331
|
-
info("Listening for incoming messages...");
|
|
118332
|
-
info("Press Ctrl+C to stop");
|
|
118333
|
-
process.on("SIGINT", async () => {
|
|
118367
|
+
if (!jsonMode) {
|
|
118334
118368
|
console.log();
|
|
118335
|
-
|
|
118336
|
-
|
|
118337
|
-
|
|
118338
|
-
|
|
118369
|
+
success("Successfully joined the Clawiverse network!");
|
|
118370
|
+
info("Listening for incoming messages...");
|
|
118371
|
+
info("Press Ctrl+C to stop");
|
|
118372
|
+
} else {
|
|
118373
|
+
console.log(JSON.stringify({ event: "ready", status: "listening" }));
|
|
118374
|
+
}
|
|
118375
|
+
const shutdown = async () => {
|
|
118376
|
+
if (!jsonMode) {
|
|
118377
|
+
console.log();
|
|
118378
|
+
const stopSpin = spinner("Stopping node...");
|
|
118379
|
+
await router.stop();
|
|
118380
|
+
await node.stop();
|
|
118381
|
+
stopSpin.succeed("Node stopped");
|
|
118382
|
+
} else {
|
|
118383
|
+
await router.stop();
|
|
118384
|
+
await node.stop();
|
|
118385
|
+
console.log(JSON.stringify({ event: "shutdown", status: "stopped" }));
|
|
118386
|
+
}
|
|
118339
118387
|
process.exit(0);
|
|
118340
|
-
}
|
|
118388
|
+
};
|
|
118389
|
+
process.on("SIGINT", shutdown);
|
|
118390
|
+
process.on("SIGTERM", shutdown);
|
|
118341
118391
|
await new Promise(() => {
|
|
118342
118392
|
});
|
|
118343
118393
|
} catch (err2) {
|
|
118344
|
-
|
|
118394
|
+
if (options.json) {
|
|
118395
|
+
console.log(JSON.stringify({ error: err2.message }));
|
|
118396
|
+
} else {
|
|
118397
|
+
error(`Failed to join network: ${err2.message}`);
|
|
118398
|
+
}
|
|
118345
118399
|
process.exit(1);
|
|
118346
118400
|
}
|
|
118347
118401
|
});
|
|
@@ -118376,7 +118430,7 @@ function registerDiscoverCommand(program2) {
|
|
|
118376
118430
|
const timeout = setTimeout(resolve, 15e3);
|
|
118377
118431
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
118378
118432
|
clearTimeout(timeout);
|
|
118379
|
-
setTimeout(resolve,
|
|
118433
|
+
setTimeout(resolve, 3e3);
|
|
118380
118434
|
}, { once: true });
|
|
118381
118435
|
});
|
|
118382
118436
|
spin.text = "Querying DHT...";
|