@highway1/cli 0.1.27 → 0.1.29

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
@@ -115999,7 +115999,7 @@ var init_fuse = __esm({
115999
115999
  }
116000
116000
  });
116001
116001
 
116002
- // ../../node_modules/.pnpm/@highway1+core@0.1.19/node_modules/@highway1/core/dist/index.js
116002
+ // ../core/dist/index.js
116003
116003
  var dist_exports = {};
116004
116004
  __export(dist_exports, {
116005
116005
  CLAWIVERSE_CONTEXT: () => CLAWIVERSE_CONTEXT,
@@ -116169,10 +116169,10 @@ async function createNode(config2) {
116169
116169
  bootstrapPeers = [],
116170
116170
  enableDHT = true,
116171
116171
  enableRelay = false,
116172
- reserveRelaySlot = false,
116172
+ enableMDNS = false,
116173
116173
  privateKey
116174
116174
  } = config2;
116175
- const relayListenAddrs = reserveRelaySlot ? bootstrapPeers.map((peer) => `${peer}/p2p-circuit`) : [];
116175
+ const relayListenAddrs = [];
116176
116176
  const libp2pConfig = {
116177
116177
  addresses: {
116178
116178
  listen: [...listenAddresses, ...relayListenAddrs]
@@ -116184,6 +116184,10 @@ async function createNode(config2) {
116184
116184
  ],
116185
116185
  connectionEncrypters: [noise()],
116186
116186
  streamMuxers: [mplex()],
116187
+ connectionManager: {
116188
+ minConnections: bootstrapPeers.length > 0 ? 1 : 0,
116189
+ maxConnections: 50
116190
+ },
116187
116191
  services: {
116188
116192
  identify: identify(),
116189
116193
  ping: ping()
@@ -116210,13 +116214,13 @@ async function createNode(config2) {
116210
116214
  }
116211
116215
  });
116212
116216
  }
116213
- if (bootstrapPeers.length > 0) {
116214
- libp2pConfig.peerDiscovery = [
116215
- bootstrap({
116216
- list: bootstrapPeers
116217
- })
116218
- ];
116217
+ const peerDiscovery = [];
116218
+ if (bootstrapPeers.length > 0) peerDiscovery.push(bootstrap({ list: bootstrapPeers }));
116219
+ if (enableMDNS) {
116220
+ const { mdns } = await import('@libp2p/mdns');
116221
+ peerDiscovery.push(mdns());
116219
116222
  }
116223
+ if (peerDiscovery.length > 0) libp2pConfig.peerDiscovery = peerDiscovery;
116220
116224
  const libp2p = await createLibp2p(libp2pConfig);
116221
116225
  logger2.info("Libp2p node created");
116222
116226
  return {
@@ -116438,7 +116442,7 @@ async function readDIDList(dht, key) {
116438
116442
  async function writeDIDList(dht, key, dids) {
116439
116443
  const value2 = fromString2([...new Set(dids)].join("\n"));
116440
116444
  try {
116441
- for await (const _ of dht.put(key, value2, { signal: AbortSignal.timeout(1e4) })) {
116445
+ for await (const _ of dht.put(key, value2, { signal: AbortSignal.timeout(5e3) })) {
116442
116446
  }
116443
116447
  } catch (e2) {
116444
116448
  if (e2?.name !== "AbortError") throw e2;
@@ -116454,24 +116458,33 @@ function createDHTOperations(libp2p) {
116454
116458
  if (!dht) throw new DiscoveryError("DHT service not available");
116455
116459
  const agentKey = fromString2(`/clawiverse/agent/${card.did}`);
116456
116460
  try {
116457
- for await (const _ of dht.put(agentKey, encodeForDHT(card), { signal: AbortSignal.timeout(1e4) })) {
116461
+ for await (const _ of dht.put(agentKey, encodeForDHT(card), { signal: AbortSignal.timeout(5e3) })) {
116458
116462
  }
116459
116463
  } catch (e2) {
116460
116464
  if (e2?.name !== "AbortError") throw e2;
116461
116465
  }
116466
+ try {
116467
+ await dht.provide(agentKey, { signal: AbortSignal.timeout(5e3) });
116468
+ } catch (e2) {
116469
+ logger4.debug("DHT provide failed (non-fatal)", { error: e2.message });
116470
+ }
116462
116471
  const caps = (card.capabilities ?? []).map(
116463
116472
  (c2) => typeof c2 === "string" ? c2 : c2.name
116464
116473
  ).filter(Boolean);
116465
116474
  caps.push("__all__");
116466
- for (const cap of caps) {
116475
+ await Promise.all(caps.map(async (cap) => {
116467
116476
  const capKeyStr = `/clawiverse/cap/${capKey(cap)}`;
116468
116477
  const capDHTKey = fromString2(capKeyStr);
116469
- const existing = await readDIDList(dht, capDHTKey);
116470
- if (!existing.includes(card.did)) {
116471
- await writeDIDList(dht, capDHTKey, [...existing, card.did]);
116472
- logger4.debug("Indexed capability in DHT", { cap: capKey(cap), did: card.did });
116478
+ try {
116479
+ const existing = await readDIDList(dht, capDHTKey);
116480
+ if (!existing.includes(card.did)) {
116481
+ await writeDIDList(dht, capDHTKey, [...existing, card.did]);
116482
+ logger4.debug("Indexed capability in DHT", { cap: capKey(cap), did: card.did });
116483
+ }
116484
+ } catch (e2) {
116485
+ logger4.warn("Failed to index capability (non-fatal)", { cap: capKey(cap), error: e2.message });
116473
116486
  }
116474
- }
116487
+ }));
116475
116488
  searchEngine.indexAgentCard(card);
116476
116489
  logger4.info("Published Agent Card to DHT", { did: card.did });
116477
116490
  } catch (error2) {
@@ -116563,6 +116576,20 @@ function createDHTOperations(libp2p) {
116563
116576
  throw new DiscoveryError("Failed to perform semantic search", error2);
116564
116577
  }
116565
116578
  },
116579
+ queryRelayPeers: async () => {
116580
+ const dht = libp2p.services?.dht;
116581
+ if (!dht) return [];
116582
+ const capDHTKey = fromString2("/clawiverse/cap/relay");
116583
+ const dids = await readDIDList(dht, capDHTKey);
116584
+ const addrs = [];
116585
+ await Promise.all(dids.map(async (did) => {
116586
+ const card = await operations.queryAgentCard(did);
116587
+ if (card?.endpoints) {
116588
+ addrs.push(...card.endpoints.filter((e2) => !e2.includes("/p2p-circuit/")));
116589
+ }
116590
+ }));
116591
+ return addrs;
116592
+ },
116566
116593
  resolveDID: async (did) => {
116567
116594
  try {
116568
116595
  const dht = libp2p.services?.dht;
@@ -116745,6 +116772,21 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
116745
116772
  }
116746
116773
  if (!stream) throw lastError ?? new MessagingError("All dial attempts failed");
116747
116774
  }
116775
+ if (!stream && dht && "queryRelayPeers" in dht) {
116776
+ const discoveredRelays = await dht.queryRelayPeers();
116777
+ for (const relayAddr of discoveredRelays) {
116778
+ const circuitAddr = buildCircuitRelayAddr(relayAddr, targetPeerIdStr);
116779
+ try {
116780
+ const conn = await libp2p.dial(multiaddr(circuitAddr));
116781
+ stream = await conn.newStream(PROTOCOL_PREFIX3, { runOnLimitedConnection: true });
116782
+ logger5.info("DHT-discovered relay succeeded", { relayAddr });
116783
+ break;
116784
+ } catch (e2) {
116785
+ logger5.warn("DHT relay failed", { relayAddr, error: e2.message });
116786
+ }
116787
+ }
116788
+ if (!stream) throw new MessagingError("All dial attempts failed (including DHT-discovered relays)");
116789
+ }
116748
116790
  const encoded = encodeMessage2(envelope);
116749
116791
  await stream.sink(
116750
116792
  (async function* () {
@@ -116895,7 +116937,7 @@ function createTrustSystem(config2) {
116895
116937
  }
116896
116938
  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;
116897
116939
  var init_dist3 = __esm({
116898
- "../../node_modules/.pnpm/@highway1+core@0.1.19/node_modules/@highway1/core/dist/index.js"() {
116940
+ "../core/dist/index.js"() {
116899
116941
  init_esm_shims();
116900
116942
  init_ed25519();
116901
116943
  init_base58();