@highway1/cli 0.1.44 → 0.1.45
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 +742 -162
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/daemon.ts +207 -0
- package/src/commands/join.ts +36 -6
- package/src/commands/send.ts +149 -10
- package/src/daemon/client.ts +68 -0
- package/src/daemon/server.ts +267 -0
- package/src/index.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import path, { join } from 'path';
|
|
2
|
+
import path, { join, resolve, basename } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { setMaxListeners as setMaxListeners$1 } from 'events';
|
|
5
5
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
@@ -7,7 +7,7 @@ import * as crypto7 from 'crypto';
|
|
|
7
7
|
import crypto7__default, { webcrypto } from 'crypto';
|
|
8
8
|
import util, { promisify } from 'util';
|
|
9
9
|
import { Resolver } from 'dns/promises';
|
|
10
|
-
import net, { isIPv4, isIPv6 } from 'net';
|
|
10
|
+
import net, { connect, createServer, isIPv4, isIPv6 } from 'net';
|
|
11
11
|
import process3 from 'process';
|
|
12
12
|
import os, { homedir } from 'os';
|
|
13
13
|
import tty from 'tty';
|
|
@@ -19,8 +19,11 @@ import { Command } from 'commander';
|
|
|
19
19
|
import Conf from 'conf';
|
|
20
20
|
import chalk from 'chalk';
|
|
21
21
|
import ora from 'ora';
|
|
22
|
+
import { mkdir, writeFile, readFile } from 'fs/promises';
|
|
22
23
|
import Table from 'cli-table3';
|
|
23
24
|
import inquirer from 'inquirer';
|
|
25
|
+
import { spawn } from 'child_process';
|
|
26
|
+
import { writeFileSync, existsSync, unlinkSync } from 'fs';
|
|
24
27
|
|
|
25
28
|
var __create = Object.create;
|
|
26
29
|
var __defProp = Object.defineProperty;
|
|
@@ -10948,17 +10951,17 @@ var init_src13 = __esm({
|
|
|
10948
10951
|
|
|
10949
10952
|
// ../../node_modules/.pnpm/@libp2p+logger@5.2.0/node_modules/@libp2p/logger/dist/src/index.js
|
|
10950
10953
|
function createDisabledLogger(namespace) {
|
|
10951
|
-
const
|
|
10954
|
+
const logger13 = () => {
|
|
10952
10955
|
};
|
|
10953
|
-
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10956
|
+
logger13.enabled = false;
|
|
10957
|
+
logger13.color = "";
|
|
10958
|
+
logger13.diff = 0;
|
|
10959
|
+
logger13.log = () => {
|
|
10957
10960
|
};
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
10961
|
-
return
|
|
10961
|
+
logger13.namespace = namespace;
|
|
10962
|
+
logger13.destroy = () => true;
|
|
10963
|
+
logger13.extend = () => logger13;
|
|
10964
|
+
return logger13;
|
|
10962
10965
|
}
|
|
10963
10966
|
function defaultLogger() {
|
|
10964
10967
|
return {
|
|
@@ -12215,8 +12218,8 @@ var init_src19 = __esm({
|
|
|
12215
12218
|
// ../../node_modules/.pnpm/p-defer@4.0.1/node_modules/p-defer/index.js
|
|
12216
12219
|
function pDefer() {
|
|
12217
12220
|
const deferred = {};
|
|
12218
|
-
deferred.promise = new Promise((
|
|
12219
|
-
deferred.resolve =
|
|
12221
|
+
deferred.promise = new Promise((resolve2, reject) => {
|
|
12222
|
+
deferred.resolve = resolve2;
|
|
12220
12223
|
deferred.reject = reject;
|
|
12221
12224
|
});
|
|
12222
12225
|
return deferred;
|
|
@@ -12350,12 +12353,12 @@ function _pushable(getNext, options) {
|
|
|
12350
12353
|
if (ended) {
|
|
12351
12354
|
return { done: true };
|
|
12352
12355
|
}
|
|
12353
|
-
return await new Promise((
|
|
12356
|
+
return await new Promise((resolve2, reject) => {
|
|
12354
12357
|
onNext = (next) => {
|
|
12355
12358
|
onNext = null;
|
|
12356
12359
|
buffer.push(next);
|
|
12357
12360
|
try {
|
|
12358
|
-
|
|
12361
|
+
resolve2(getNext(buffer));
|
|
12359
12362
|
} catch (err2) {
|
|
12360
12363
|
reject(err2);
|
|
12361
12364
|
}
|
|
@@ -12431,7 +12434,7 @@ function _pushable(getNext, options) {
|
|
|
12431
12434
|
let cancel;
|
|
12432
12435
|
let listener;
|
|
12433
12436
|
if (signal != null) {
|
|
12434
|
-
cancel = new Promise((
|
|
12437
|
+
cancel = new Promise((resolve2, reject) => {
|
|
12435
12438
|
listener = () => {
|
|
12436
12439
|
reject(new AbortError3());
|
|
12437
12440
|
};
|
|
@@ -12523,7 +12526,7 @@ async function raceEvent(emitter, eventName, signal, opts) {
|
|
|
12523
12526
|
if (signal?.aborted === true) {
|
|
12524
12527
|
return Promise.reject(error2);
|
|
12525
12528
|
}
|
|
12526
|
-
return new Promise((
|
|
12529
|
+
return new Promise((resolve2, reject) => {
|
|
12527
12530
|
function removeListeners() {
|
|
12528
12531
|
removeListener(signal, "abort", abortListener);
|
|
12529
12532
|
removeListener(emitter, eventName, eventListener);
|
|
@@ -12540,7 +12543,7 @@ async function raceEvent(emitter, eventName, signal, opts) {
|
|
|
12540
12543
|
return;
|
|
12541
12544
|
}
|
|
12542
12545
|
removeListeners();
|
|
12543
|
-
|
|
12546
|
+
resolve2(evt);
|
|
12544
12547
|
};
|
|
12545
12548
|
const errorEventListener = (evt) => {
|
|
12546
12549
|
removeListeners();
|
|
@@ -12622,7 +12625,7 @@ async function raceSignal(promise, signal, opts) {
|
|
|
12622
12625
|
try {
|
|
12623
12626
|
return await Promise.race([
|
|
12624
12627
|
promise,
|
|
12625
|
-
new Promise((
|
|
12628
|
+
new Promise((resolve2, reject) => {
|
|
12626
12629
|
listener = () => {
|
|
12627
12630
|
reject(translateError(signal));
|
|
12628
12631
|
};
|
|
@@ -13092,7 +13095,7 @@ var init_channel = __esm({
|
|
|
13092
13095
|
name: requestEvent.name,
|
|
13093
13096
|
identifier: requestEvent.identifier
|
|
13094
13097
|
});
|
|
13095
|
-
await new Promise((
|
|
13098
|
+
await new Promise((resolve2) => {
|
|
13096
13099
|
const releaseEventListener = (event2) => {
|
|
13097
13100
|
if (event2?.data == null) {
|
|
13098
13101
|
return;
|
|
@@ -13104,7 +13107,7 @@ var init_channel = __esm({
|
|
|
13104
13107
|
};
|
|
13105
13108
|
if (releaseEvent.type === releaseType && releaseEvent.identifier === requestEvent.identifier) {
|
|
13106
13109
|
channel.removeEventListener("message", releaseEventListener);
|
|
13107
|
-
|
|
13110
|
+
resolve2();
|
|
13108
13111
|
}
|
|
13109
13112
|
};
|
|
13110
13113
|
channel.addEventListener("message", releaseEventListener);
|
|
@@ -13167,11 +13170,11 @@ var init_cluster = __esm({
|
|
|
13167
13170
|
name: requestEvent.name,
|
|
13168
13171
|
identifier: requestEvent.identifier
|
|
13169
13172
|
});
|
|
13170
|
-
await new Promise((
|
|
13173
|
+
await new Promise((resolve2) => {
|
|
13171
13174
|
const releaseEventListener = (releaseEvent) => {
|
|
13172
13175
|
if (releaseEvent.type === releaseType && releaseEvent.identifier === requestEvent.identifier) {
|
|
13173
13176
|
worker2.removeListener("message", releaseEventListener);
|
|
13174
|
-
|
|
13177
|
+
resolve2();
|
|
13175
13178
|
}
|
|
13176
13179
|
};
|
|
13177
13180
|
worker2.on("message", releaseEventListener);
|
|
@@ -13258,7 +13261,7 @@ var init_channel2 = __esm({
|
|
|
13258
13261
|
identifier: id,
|
|
13259
13262
|
name: this.name
|
|
13260
13263
|
});
|
|
13261
|
-
return new Promise((
|
|
13264
|
+
return new Promise((resolve2, reject) => {
|
|
13262
13265
|
const abortListener = () => {
|
|
13263
13266
|
this.channel.postMessage({
|
|
13264
13267
|
type: abortType,
|
|
@@ -13276,7 +13279,7 @@ var init_channel2 = __esm({
|
|
|
13276
13279
|
if (event.data?.type === grantType) {
|
|
13277
13280
|
this.channel.removeEventListener("message", listener);
|
|
13278
13281
|
options?.signal?.removeEventListener("abort", abortListener);
|
|
13279
|
-
|
|
13282
|
+
resolve2(() => {
|
|
13280
13283
|
this.channel.postMessage({
|
|
13281
13284
|
type: releaseType,
|
|
13282
13285
|
identifier: id,
|
|
@@ -13342,7 +13345,7 @@ var init_cluster2 = __esm({
|
|
|
13342
13345
|
identifier: id,
|
|
13343
13346
|
name: this.name
|
|
13344
13347
|
});
|
|
13345
|
-
return new Promise((
|
|
13348
|
+
return new Promise((resolve2, reject) => {
|
|
13346
13349
|
const abortListener = () => {
|
|
13347
13350
|
process.send?.({
|
|
13348
13351
|
type: abortType,
|
|
@@ -13360,7 +13363,7 @@ var init_cluster2 = __esm({
|
|
|
13360
13363
|
if (event.type === grantType) {
|
|
13361
13364
|
process.removeListener("message", listener);
|
|
13362
13365
|
options?.signal?.removeEventListener("abort", abortListener);
|
|
13363
|
-
|
|
13366
|
+
resolve2(() => {
|
|
13364
13367
|
process.send?.({
|
|
13365
13368
|
type: releaseType,
|
|
13366
13369
|
identifier: id,
|
|
@@ -13506,8 +13509,8 @@ function getImplementation(opts) {
|
|
|
13506
13509
|
async function createReleasable(queue, options) {
|
|
13507
13510
|
let res;
|
|
13508
13511
|
let rej;
|
|
13509
|
-
const p2 = new Promise((
|
|
13510
|
-
res =
|
|
13512
|
+
const p2 = new Promise((resolve2, reject) => {
|
|
13513
|
+
res = resolve2;
|
|
13511
13514
|
rej = reject;
|
|
13512
13515
|
});
|
|
13513
13516
|
const listener = () => {
|
|
@@ -13517,10 +13520,10 @@ async function createReleasable(queue, options) {
|
|
|
13517
13520
|
once: true
|
|
13518
13521
|
});
|
|
13519
13522
|
queue.add(async () => {
|
|
13520
|
-
await new Promise((
|
|
13523
|
+
await new Promise((resolve2) => {
|
|
13521
13524
|
res(() => {
|
|
13522
13525
|
options?.signal?.removeEventListener("abort", listener);
|
|
13523
|
-
|
|
13526
|
+
resolve2();
|
|
13524
13527
|
});
|
|
13525
13528
|
});
|
|
13526
13529
|
}, {
|
|
@@ -17147,10 +17150,10 @@ function createDelay({ clearTimeout: defaultClear, setTimeout: defaultSet } = {}
|
|
|
17147
17150
|
signal.removeEventListener("abort", signalListener);
|
|
17148
17151
|
}
|
|
17149
17152
|
};
|
|
17150
|
-
const delayPromise = new Promise((
|
|
17153
|
+
const delayPromise = new Promise((resolve2, reject) => {
|
|
17151
17154
|
settle = () => {
|
|
17152
17155
|
cleanup();
|
|
17153
|
-
|
|
17156
|
+
resolve2(value2);
|
|
17154
17157
|
};
|
|
17155
17158
|
rejectFunction = reject;
|
|
17156
17159
|
timeoutId = (defaultSet ?? setTimeout)(settle, milliseconds);
|
|
@@ -17668,7 +17671,7 @@ async function raceSignal2(promise, signal, opts) {
|
|
|
17668
17671
|
try {
|
|
17669
17672
|
return await Promise.race([
|
|
17670
17673
|
promise,
|
|
17671
|
-
new Promise((
|
|
17674
|
+
new Promise((resolve2, reject) => {
|
|
17672
17675
|
listener = () => {
|
|
17673
17676
|
reject(error2);
|
|
17674
17677
|
};
|
|
@@ -18948,7 +18951,7 @@ var init_is_network_error = __esm({
|
|
|
18948
18951
|
|
|
18949
18952
|
// ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
18950
18953
|
async function pRetry(input, options) {
|
|
18951
|
-
return new Promise((
|
|
18954
|
+
return new Promise((resolve2, reject) => {
|
|
18952
18955
|
options = { ...options };
|
|
18953
18956
|
options.onFailedAttempt ??= () => {
|
|
18954
18957
|
};
|
|
@@ -18970,7 +18973,7 @@ async function pRetry(input, options) {
|
|
|
18970
18973
|
try {
|
|
18971
18974
|
const result = await input(attemptNumber);
|
|
18972
18975
|
cleanUp();
|
|
18973
|
-
|
|
18976
|
+
resolve2(result);
|
|
18974
18977
|
} catch (error2) {
|
|
18975
18978
|
try {
|
|
18976
18979
|
if (!(error2 instanceof Error)) {
|
|
@@ -22708,7 +22711,7 @@ function pTimeout(promise, options) {
|
|
|
22708
22711
|
} = options;
|
|
22709
22712
|
let timer;
|
|
22710
22713
|
let abortHandler;
|
|
22711
|
-
const wrappedPromise = new Promise((
|
|
22714
|
+
const wrappedPromise = new Promise((resolve2, reject) => {
|
|
22712
22715
|
if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
|
|
22713
22716
|
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
22714
22717
|
}
|
|
@@ -22723,14 +22726,14 @@ function pTimeout(promise, options) {
|
|
|
22723
22726
|
signal.addEventListener("abort", abortHandler, { once: true });
|
|
22724
22727
|
}
|
|
22725
22728
|
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
22726
|
-
promise.then(
|
|
22729
|
+
promise.then(resolve2, reject);
|
|
22727
22730
|
return;
|
|
22728
22731
|
}
|
|
22729
22732
|
const timeoutError = new TimeoutError2();
|
|
22730
22733
|
timer = customTimers.setTimeout.call(void 0, () => {
|
|
22731
22734
|
if (fallback) {
|
|
22732
22735
|
try {
|
|
22733
|
-
|
|
22736
|
+
resolve2(fallback());
|
|
22734
22737
|
} catch (error2) {
|
|
22735
22738
|
reject(error2);
|
|
22736
22739
|
}
|
|
@@ -22740,7 +22743,7 @@ function pTimeout(promise, options) {
|
|
|
22740
22743
|
promise.cancel();
|
|
22741
22744
|
}
|
|
22742
22745
|
if (message2 === false) {
|
|
22743
|
-
|
|
22746
|
+
resolve2();
|
|
22744
22747
|
} else if (message2 instanceof Error) {
|
|
22745
22748
|
reject(message2);
|
|
22746
22749
|
} else {
|
|
@@ -22750,7 +22753,7 @@ function pTimeout(promise, options) {
|
|
|
22750
22753
|
}, milliseconds);
|
|
22751
22754
|
(async () => {
|
|
22752
22755
|
try {
|
|
22753
|
-
|
|
22756
|
+
resolve2(await promise);
|
|
22754
22757
|
} catch (error2) {
|
|
22755
22758
|
reject(error2);
|
|
22756
22759
|
}
|
|
@@ -22796,7 +22799,7 @@ var init_p_timeout = __esm({
|
|
|
22796
22799
|
// ../../node_modules/.pnpm/p-event@6.0.1/node_modules/p-event/index.js
|
|
22797
22800
|
function pEventMultiple(emitter, event, options) {
|
|
22798
22801
|
let cancel;
|
|
22799
|
-
const returnValue = new Promise((
|
|
22802
|
+
const returnValue = new Promise((resolve2, reject) => {
|
|
22800
22803
|
options = {
|
|
22801
22804
|
rejectionEvents: ["error"],
|
|
22802
22805
|
multiArgs: false,
|
|
@@ -22818,7 +22821,7 @@ function pEventMultiple(emitter, event, options) {
|
|
|
22818
22821
|
items.push(value2);
|
|
22819
22822
|
if (options.count === items.length) {
|
|
22820
22823
|
cancel();
|
|
22821
|
-
|
|
22824
|
+
resolve2(items);
|
|
22822
22825
|
}
|
|
22823
22826
|
};
|
|
22824
22827
|
const rejectHandler = (error2) => {
|
|
@@ -22845,7 +22848,7 @@ function pEventMultiple(emitter, event, options) {
|
|
|
22845
22848
|
}, { once: true });
|
|
22846
22849
|
}
|
|
22847
22850
|
if (options.resolveImmediately) {
|
|
22848
|
-
|
|
22851
|
+
resolve2(items);
|
|
22849
22852
|
}
|
|
22850
22853
|
});
|
|
22851
22854
|
returnValue.cancel = cancel;
|
|
@@ -22986,20 +22989,20 @@ function sink(writable) {
|
|
|
22986
22989
|
drainCb?.();
|
|
22987
22990
|
};
|
|
22988
22991
|
const waitForDrainOrClose = async () => {
|
|
22989
|
-
return new Promise((
|
|
22990
|
-
closeCb = drainCb =
|
|
22992
|
+
return new Promise((resolve2, reject) => {
|
|
22993
|
+
closeCb = drainCb = resolve2;
|
|
22991
22994
|
errCb = reject;
|
|
22992
22995
|
writable.once("drain", drainHandler);
|
|
22993
22996
|
});
|
|
22994
22997
|
};
|
|
22995
22998
|
const waitForDone = async () => {
|
|
22996
22999
|
await maybeEndSource();
|
|
22997
|
-
return new Promise((
|
|
23000
|
+
return new Promise((resolve2, reject) => {
|
|
22998
23001
|
if (closed || finished || error2 != null) {
|
|
22999
|
-
|
|
23002
|
+
resolve2();
|
|
23000
23003
|
return;
|
|
23001
23004
|
}
|
|
23002
|
-
finishCb = closeCb =
|
|
23005
|
+
finishCb = closeCb = resolve2;
|
|
23003
23006
|
errCb = reject;
|
|
23004
23007
|
});
|
|
23005
23008
|
};
|
|
@@ -23450,9 +23453,9 @@ var init_listener = __esm({
|
|
|
23450
23453
|
return;
|
|
23451
23454
|
}
|
|
23452
23455
|
const netConfig = this.status.netConfig;
|
|
23453
|
-
await new Promise((
|
|
23456
|
+
await new Promise((resolve2, reject) => {
|
|
23454
23457
|
this.server.once("error", reject);
|
|
23455
|
-
this.server.listen(netConfig,
|
|
23458
|
+
this.server.listen(netConfig, resolve2);
|
|
23456
23459
|
});
|
|
23457
23460
|
this.status = { ...this.status, code: TCPListenerStatusCode.ACTIVE };
|
|
23458
23461
|
this.log("listening on %s", this.server.address());
|
|
@@ -23542,7 +23545,7 @@ var init_tcp = __esm({
|
|
|
23542
23545
|
options.signal.throwIfAborted();
|
|
23543
23546
|
options.onProgress?.(new CustomProgressEvent("tcp:open-connection"));
|
|
23544
23547
|
let rawSocket;
|
|
23545
|
-
return new Promise((
|
|
23548
|
+
return new Promise((resolve2, reject) => {
|
|
23546
23549
|
const start2 = Date.now();
|
|
23547
23550
|
const cOpts = multiaddrToNetConfig(ma, {
|
|
23548
23551
|
...this.opts.dialOpts ?? {},
|
|
@@ -23584,7 +23587,7 @@ var init_tcp = __esm({
|
|
|
23584
23587
|
reject(err2);
|
|
23585
23588
|
return;
|
|
23586
23589
|
}
|
|
23587
|
-
|
|
23590
|
+
resolve2(rawSocket);
|
|
23588
23591
|
};
|
|
23589
23592
|
rawSocket.on("error", onError);
|
|
23590
23593
|
rawSocket.on("timeout", onTimeout);
|
|
@@ -31007,7 +31010,7 @@ function byteStream2(duplex2, opts) {
|
|
|
31007
31010
|
read: async (bytes, options) => {
|
|
31008
31011
|
options?.signal?.throwIfAborted();
|
|
31009
31012
|
let listener;
|
|
31010
|
-
const abortPromise = new Promise((
|
|
31013
|
+
const abortPromise = new Promise((resolve2, reject) => {
|
|
31011
31014
|
listener = () => {
|
|
31012
31015
|
reject(new AbortError7("Read aborted"));
|
|
31013
31016
|
};
|
|
@@ -32199,7 +32202,7 @@ var init_dist2 = __esm({
|
|
|
32199
32202
|
throwOnTimeout: this.#throwOnTimeout,
|
|
32200
32203
|
...options
|
|
32201
32204
|
};
|
|
32202
|
-
return new Promise((
|
|
32205
|
+
return new Promise((resolve2, reject) => {
|
|
32203
32206
|
this.#queue.enqueue(async () => {
|
|
32204
32207
|
this.#pending++;
|
|
32205
32208
|
try {
|
|
@@ -32213,11 +32216,11 @@ var init_dist2 = __esm({
|
|
|
32213
32216
|
operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
|
|
32214
32217
|
}
|
|
32215
32218
|
const result = await operation;
|
|
32216
|
-
|
|
32219
|
+
resolve2(result);
|
|
32217
32220
|
this.emit("completed", result);
|
|
32218
32221
|
} catch (error2) {
|
|
32219
32222
|
if (error2 instanceof TimeoutError2 && !options.throwOnTimeout) {
|
|
32220
|
-
|
|
32223
|
+
resolve2();
|
|
32221
32224
|
return;
|
|
32222
32225
|
}
|
|
32223
32226
|
reject(error2);
|
|
@@ -32292,13 +32295,13 @@ var init_dist2 = __esm({
|
|
|
32292
32295
|
await this.#onEvent("idle");
|
|
32293
32296
|
}
|
|
32294
32297
|
async #onEvent(event, filter2) {
|
|
32295
|
-
return new Promise((
|
|
32298
|
+
return new Promise((resolve2) => {
|
|
32296
32299
|
const listener = () => {
|
|
32297
32300
|
if (filter2 && !filter2()) {
|
|
32298
32301
|
return;
|
|
32299
32302
|
}
|
|
32300
32303
|
this.off(event, listener);
|
|
32301
|
-
|
|
32304
|
+
resolve2();
|
|
32302
32305
|
};
|
|
32303
32306
|
this.on(event, listener);
|
|
32304
32307
|
});
|
|
@@ -106574,7 +106577,7 @@ var require_compile = __commonJS({
|
|
|
106574
106577
|
const schOrFunc = root.refs[ref];
|
|
106575
106578
|
if (schOrFunc)
|
|
106576
106579
|
return schOrFunc;
|
|
106577
|
-
let _sch =
|
|
106580
|
+
let _sch = resolve2.call(this, root, ref);
|
|
106578
106581
|
if (_sch === void 0) {
|
|
106579
106582
|
const schema = (_a2 = root.localRefs) === null || _a2 === void 0 ? void 0 : _a2[ref];
|
|
106580
106583
|
const { schemaId } = this.opts;
|
|
@@ -106601,7 +106604,7 @@ var require_compile = __commonJS({
|
|
|
106601
106604
|
function sameSchemaEnv(s1, s2) {
|
|
106602
106605
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
106603
106606
|
}
|
|
106604
|
-
function
|
|
106607
|
+
function resolve2(root, ref) {
|
|
106605
106608
|
let sch;
|
|
106606
106609
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
106607
106610
|
ref = sch;
|
|
@@ -107176,7 +107179,7 @@ var require_fast_uri = __commonJS({
|
|
|
107176
107179
|
}
|
|
107177
107180
|
return uri;
|
|
107178
107181
|
}
|
|
107179
|
-
function
|
|
107182
|
+
function resolve2(baseURI, relativeURI, options) {
|
|
107180
107183
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
107181
107184
|
const resolved = resolveComponent(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
107182
107185
|
schemelessOptions.skipEscape = true;
|
|
@@ -107403,7 +107406,7 @@ var require_fast_uri = __commonJS({
|
|
|
107403
107406
|
var fastUri = {
|
|
107404
107407
|
SCHEMES,
|
|
107405
107408
|
normalize,
|
|
107406
|
-
resolve,
|
|
107409
|
+
resolve: resolve2,
|
|
107407
107410
|
resolveComponent,
|
|
107408
107411
|
equal,
|
|
107409
107412
|
serialize,
|
|
@@ -107958,13 +107961,13 @@ var require_core = __commonJS({
|
|
|
107958
107961
|
}, warn() {
|
|
107959
107962
|
}, error() {
|
|
107960
107963
|
} };
|
|
107961
|
-
function getLogger(
|
|
107962
|
-
if (
|
|
107964
|
+
function getLogger(logger13) {
|
|
107965
|
+
if (logger13 === false)
|
|
107963
107966
|
return noLogs;
|
|
107964
|
-
if (
|
|
107967
|
+
if (logger13 === void 0)
|
|
107965
107968
|
return console;
|
|
107966
|
-
if (
|
|
107967
|
-
return
|
|
107969
|
+
if (logger13.log && logger13.warn && logger13.error)
|
|
107970
|
+
return logger13;
|
|
107968
107971
|
throw new Error("logger must implement log, warn and error methods");
|
|
107969
107972
|
}
|
|
107970
107973
|
var KEYWORD_NAME = /^[a-z_$][a-z0-9_$:-]*$/i;
|
|
@@ -112401,7 +112404,7 @@ var require_filesystem = __commonJS({
|
|
|
112401
112404
|
var LDD_PATH = "/usr/bin/ldd";
|
|
112402
112405
|
var SELF_PATH = "/proc/self/exe";
|
|
112403
112406
|
var MAX_LENGTH = 2048;
|
|
112404
|
-
var
|
|
112407
|
+
var readFileSync2 = (path3) => {
|
|
112405
112408
|
const fd = fs.openSync(path3, "r");
|
|
112406
112409
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
112407
112410
|
const bytesRead = fs.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
@@ -112409,14 +112412,14 @@ var require_filesystem = __commonJS({
|
|
|
112409
112412
|
});
|
|
112410
112413
|
return buffer.subarray(0, bytesRead);
|
|
112411
112414
|
};
|
|
112412
|
-
var
|
|
112415
|
+
var readFile2 = (path3) => new Promise((resolve2, reject) => {
|
|
112413
112416
|
fs.open(path3, "r", (err2, fd) => {
|
|
112414
112417
|
if (err2) {
|
|
112415
112418
|
reject(err2);
|
|
112416
112419
|
} else {
|
|
112417
112420
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
112418
112421
|
fs.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
|
|
112419
|
-
|
|
112422
|
+
resolve2(buffer.subarray(0, bytesRead));
|
|
112420
112423
|
fs.close(fd, () => {
|
|
112421
112424
|
});
|
|
112422
112425
|
});
|
|
@@ -112426,8 +112429,8 @@ var require_filesystem = __commonJS({
|
|
|
112426
112429
|
module.exports = {
|
|
112427
112430
|
LDD_PATH,
|
|
112428
112431
|
SELF_PATH,
|
|
112429
|
-
readFileSync,
|
|
112430
|
-
readFile
|
|
112432
|
+
readFileSync: readFileSync2,
|
|
112433
|
+
readFile: readFile2
|
|
112431
112434
|
};
|
|
112432
112435
|
}
|
|
112433
112436
|
});
|
|
@@ -112475,7 +112478,7 @@ var require_detect_libc = __commonJS({
|
|
|
112475
112478
|
init_esm_shims();
|
|
112476
112479
|
var childProcess = __require("child_process");
|
|
112477
112480
|
var { isLinux, getReport } = require_process();
|
|
112478
|
-
var { LDD_PATH, SELF_PATH, readFile, readFileSync } = require_filesystem();
|
|
112481
|
+
var { LDD_PATH, SELF_PATH, readFile: readFile2, readFileSync: readFileSync2 } = require_filesystem();
|
|
112479
112482
|
var { interpreterPath } = require_elf();
|
|
112480
112483
|
var cachedFamilyInterpreter;
|
|
112481
112484
|
var cachedFamilyFilesystem;
|
|
@@ -112484,10 +112487,10 @@ var require_detect_libc = __commonJS({
|
|
|
112484
112487
|
var commandOut = "";
|
|
112485
112488
|
var safeCommand = () => {
|
|
112486
112489
|
if (!commandOut) {
|
|
112487
|
-
return new Promise((
|
|
112490
|
+
return new Promise((resolve2) => {
|
|
112488
112491
|
childProcess.exec(command, (err2, out) => {
|
|
112489
112492
|
commandOut = err2 ? " " : out;
|
|
112490
|
-
|
|
112493
|
+
resolve2(commandOut);
|
|
112491
112494
|
});
|
|
112492
112495
|
});
|
|
112493
112496
|
}
|
|
@@ -112555,7 +112558,7 @@ var require_detect_libc = __commonJS({
|
|
|
112555
112558
|
}
|
|
112556
112559
|
cachedFamilyFilesystem = null;
|
|
112557
112560
|
try {
|
|
112558
|
-
const lddContent = await
|
|
112561
|
+
const lddContent = await readFile2(LDD_PATH);
|
|
112559
112562
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
112560
112563
|
} catch (e2) {
|
|
112561
112564
|
}
|
|
@@ -112567,7 +112570,7 @@ var require_detect_libc = __commonJS({
|
|
|
112567
112570
|
}
|
|
112568
112571
|
cachedFamilyFilesystem = null;
|
|
112569
112572
|
try {
|
|
112570
|
-
const lddContent =
|
|
112573
|
+
const lddContent = readFileSync2(LDD_PATH);
|
|
112571
112574
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
112572
112575
|
} catch (e2) {
|
|
112573
112576
|
}
|
|
@@ -112579,7 +112582,7 @@ var require_detect_libc = __commonJS({
|
|
|
112579
112582
|
}
|
|
112580
112583
|
cachedFamilyInterpreter = null;
|
|
112581
112584
|
try {
|
|
112582
|
-
const selfContent = await
|
|
112585
|
+
const selfContent = await readFile2(SELF_PATH);
|
|
112583
112586
|
const path3 = interpreterPath(selfContent);
|
|
112584
112587
|
cachedFamilyInterpreter = familyFromInterpreterPath(path3);
|
|
112585
112588
|
} catch (e2) {
|
|
@@ -112592,7 +112595,7 @@ var require_detect_libc = __commonJS({
|
|
|
112592
112595
|
}
|
|
112593
112596
|
cachedFamilyInterpreter = null;
|
|
112594
112597
|
try {
|
|
112595
|
-
const selfContent =
|
|
112598
|
+
const selfContent = readFileSync2(SELF_PATH);
|
|
112596
112599
|
const path3 = interpreterPath(selfContent);
|
|
112597
112600
|
cachedFamilyInterpreter = familyFromInterpreterPath(path3);
|
|
112598
112601
|
} catch (e2) {
|
|
@@ -112641,7 +112644,7 @@ var require_detect_libc = __commonJS({
|
|
|
112641
112644
|
}
|
|
112642
112645
|
cachedVersionFilesystem = null;
|
|
112643
112646
|
try {
|
|
112644
|
-
const lddContent = await
|
|
112647
|
+
const lddContent = await readFile2(LDD_PATH);
|
|
112645
112648
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
112646
112649
|
if (versionMatch) {
|
|
112647
112650
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -112656,7 +112659,7 @@ var require_detect_libc = __commonJS({
|
|
|
112656
112659
|
}
|
|
112657
112660
|
cachedVersionFilesystem = null;
|
|
112658
112661
|
try {
|
|
112659
|
-
const lddContent =
|
|
112662
|
+
const lddContent = readFileSync2(LDD_PATH);
|
|
112660
112663
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
112661
112664
|
if (versionMatch) {
|
|
112662
112665
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -112769,9 +112772,9 @@ var require_node_gyp_build_optional_packages = __commonJS({
|
|
|
112769
112772
|
var debug = getFirst(path3.join(dir, "build/Debug"), matchBuild);
|
|
112770
112773
|
if (debug) return debug;
|
|
112771
112774
|
}
|
|
112772
|
-
var prebuild =
|
|
112775
|
+
var prebuild = resolve2(dir);
|
|
112773
112776
|
if (prebuild) return prebuild;
|
|
112774
|
-
var nearby =
|
|
112777
|
+
var nearby = resolve2(path3.dirname(process.execPath));
|
|
112775
112778
|
if (nearby) return nearby;
|
|
112776
112779
|
var platformPackage = (packageName[0] == "@" ? "" : "@" + packageName + "/") + packageName + "-" + platform + "-" + arch;
|
|
112777
112780
|
try {
|
|
@@ -112793,7 +112796,7 @@ var require_node_gyp_build_optional_packages = __commonJS({
|
|
|
112793
112796
|
// eslint-disable-line
|
|
112794
112797
|
].filter(Boolean).join(" ");
|
|
112795
112798
|
throw new Error("No native build was found for " + target2 + "\n attempted loading from: " + dir + " and package: " + platformPackage + "\n");
|
|
112796
|
-
function
|
|
112799
|
+
function resolve2(dir2) {
|
|
112797
112800
|
var tuples = readdirSync(path3.join(dir2, "prebuilds")).map(parseTuple);
|
|
112798
112801
|
var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
|
|
112799
112802
|
if (!tuple) return;
|
|
@@ -115999,7 +116002,7 @@ var init_fuse = __esm({
|
|
|
115999
116002
|
}
|
|
116000
116003
|
});
|
|
116001
116004
|
|
|
116002
|
-
//
|
|
116005
|
+
// ../../node_modules/.pnpm/@highway1+core@0.1.45/node_modules/@highway1/core/dist/index.js
|
|
116003
116006
|
var dist_exports = {};
|
|
116004
116007
|
__export(dist_exports, {
|
|
116005
116008
|
CLAWIVERSE_CONTEXT: () => CLAWIVERSE_CONTEXT,
|
|
@@ -116216,8 +116219,8 @@ async function createNode(config2) {
|
|
|
116216
116219
|
// Optimize for small networks: reduce replication factor and query timeout
|
|
116217
116220
|
kBucketSize: 20,
|
|
116218
116221
|
// Default K=20, keep for compatibility
|
|
116219
|
-
querySelfInterval:
|
|
116220
|
-
// Self-query every
|
|
116222
|
+
querySelfInterval: 3e4,
|
|
116223
|
+
// Self-query every 30 seconds (libp2p default)
|
|
116221
116224
|
// Allow queries to complete faster in small networks
|
|
116222
116225
|
allowQueryWithZeroPeers: true
|
|
116223
116226
|
});
|
|
@@ -116620,6 +116623,11 @@ function createDHTOperations(libp2p) {
|
|
|
116620
116623
|
},
|
|
116621
116624
|
resolveDID: async (did) => {
|
|
116622
116625
|
try {
|
|
116626
|
+
const cached = peerCache.get(did);
|
|
116627
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
116628
|
+
logger4.debug("Using cached peer info", { did });
|
|
116629
|
+
return { peerId: cached.peerId, multiaddrs: cached.multiaddrs };
|
|
116630
|
+
}
|
|
116623
116631
|
const dht = libp2p.services?.dht;
|
|
116624
116632
|
if (!dht) throw new DiscoveryError("DHT service not available");
|
|
116625
116633
|
const key = fromString2(`/clawiverse/agent/${did}`);
|
|
@@ -116629,7 +116637,13 @@ function createDHTOperations(libp2p) {
|
|
|
116629
116637
|
const card = decodeFromCBOR(raw);
|
|
116630
116638
|
if (card.peerId) {
|
|
116631
116639
|
logger4.debug("Resolved DID to peer", { did, peerId: card.peerId });
|
|
116632
|
-
|
|
116640
|
+
const result = { peerId: card.peerId, multiaddrs: card.endpoints || [] };
|
|
116641
|
+
peerCache.set(did, {
|
|
116642
|
+
peerId: result.peerId,
|
|
116643
|
+
multiaddrs: result.multiaddrs,
|
|
116644
|
+
timestamp: Date.now()
|
|
116645
|
+
});
|
|
116646
|
+
return result;
|
|
116633
116647
|
}
|
|
116634
116648
|
logger4.warn("Agent Card found but has no peerId", { did });
|
|
116635
116649
|
return null;
|
|
@@ -116718,6 +116732,18 @@ function decodeMessageJSON(json) {
|
|
|
116718
116732
|
throw new MessagingError("Failed to decode message from JSON", error2);
|
|
116719
116733
|
}
|
|
116720
116734
|
}
|
|
116735
|
+
function concatUint8Arrays(arrays) {
|
|
116736
|
+
if (arrays.length === 0) return new Uint8Array(0);
|
|
116737
|
+
if (arrays.length === 1) return arrays[0];
|
|
116738
|
+
const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0);
|
|
116739
|
+
const result = new Uint8Array(totalLength);
|
|
116740
|
+
let offset = 0;
|
|
116741
|
+
for (const arr of arrays) {
|
|
116742
|
+
result.set(arr, offset);
|
|
116743
|
+
offset += arr.length;
|
|
116744
|
+
}
|
|
116745
|
+
return result;
|
|
116746
|
+
}
|
|
116721
116747
|
function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
116722
116748
|
const handlers = /* @__PURE__ */ new Map();
|
|
116723
116749
|
let catchAllHandler;
|
|
@@ -116768,16 +116794,25 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116768
116794
|
multiaddrs: targetMultiaddrs
|
|
116769
116795
|
});
|
|
116770
116796
|
let stream;
|
|
116797
|
+
const DIAL_TIMEOUT2 = 3e3;
|
|
116771
116798
|
const relayMultiaddrs = targetMultiaddrs.filter((a2) => a2.includes("/p2p-circuit/"));
|
|
116772
116799
|
const directMultiaddrs = targetMultiaddrs.filter((a2) => !a2.includes("/p2p-circuit/"));
|
|
116773
|
-
|
|
116774
|
-
|
|
116775
|
-
|
|
116776
|
-
|
|
116777
|
-
|
|
116778
|
-
|
|
116779
|
-
|
|
116780
|
-
|
|
116800
|
+
if (directMultiaddrs.length > 0) {
|
|
116801
|
+
const directDialPromises = directMultiaddrs.map(async (addr) => {
|
|
116802
|
+
try {
|
|
116803
|
+
const conn = await libp2p.dial(multiaddr(addr), {
|
|
116804
|
+
signal: AbortSignal.timeout(DIAL_TIMEOUT2)
|
|
116805
|
+
});
|
|
116806
|
+
const s2 = await conn.newStream(PROTOCOL_PREFIX3, { runOnLimitedConnection: true });
|
|
116807
|
+
logger5.info("Direct dial succeeded", { addr });
|
|
116808
|
+
return s2;
|
|
116809
|
+
} catch {
|
|
116810
|
+
return null;
|
|
116811
|
+
}
|
|
116812
|
+
});
|
|
116813
|
+
stream = await Promise.race(
|
|
116814
|
+
directDialPromises.map((p2) => p2.then((s2) => s2 || Promise.reject()))
|
|
116815
|
+
).catch(() => void 0);
|
|
116781
116816
|
}
|
|
116782
116817
|
let lastError;
|
|
116783
116818
|
if (!stream) {
|
|
@@ -116786,17 +116821,25 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116786
116821
|
...(relayPeers ?? []).map((r2) => buildCircuitRelayAddr(r2, targetPeerIdStr))
|
|
116787
116822
|
];
|
|
116788
116823
|
const uniqueRelayAddrs = [...new Set(allRelayAddrs)];
|
|
116789
|
-
|
|
116790
|
-
|
|
116791
|
-
|
|
116792
|
-
|
|
116793
|
-
|
|
116794
|
-
|
|
116795
|
-
|
|
116796
|
-
|
|
116797
|
-
|
|
116798
|
-
|
|
116799
|
-
|
|
116824
|
+
if (uniqueRelayAddrs.length > 0) {
|
|
116825
|
+
const relayDialPromises = uniqueRelayAddrs.map(async (addr) => {
|
|
116826
|
+
try {
|
|
116827
|
+
const conn = await libp2p.dial(multiaddr(addr), {
|
|
116828
|
+
signal: AbortSignal.timeout(DIAL_TIMEOUT2)
|
|
116829
|
+
});
|
|
116830
|
+
logger5.info("Relay connection established", { addr });
|
|
116831
|
+
const s2 = await conn.newStream(PROTOCOL_PREFIX3, { runOnLimitedConnection: true });
|
|
116832
|
+
logger5.info("Relay stream opened", { addr });
|
|
116833
|
+
return s2;
|
|
116834
|
+
} catch (relayErr) {
|
|
116835
|
+
logger5.warn("Relay dial failed", { addr, error: relayErr.message });
|
|
116836
|
+
lastError = relayErr;
|
|
116837
|
+
return null;
|
|
116838
|
+
}
|
|
116839
|
+
});
|
|
116840
|
+
stream = await Promise.race(
|
|
116841
|
+
relayDialPromises.map((p2) => p2.then((s2) => s2 || Promise.reject()))
|
|
116842
|
+
).catch(() => void 0);
|
|
116800
116843
|
}
|
|
116801
116844
|
}
|
|
116802
116845
|
if (!stream && dht && "queryRelayPeers" in dht) {
|
|
@@ -116832,21 +116875,14 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116832
116875
|
if (envelope.type === "request") {
|
|
116833
116876
|
logger5.debug("Waiting for response to request", { id: envelope.id });
|
|
116834
116877
|
try {
|
|
116835
|
-
const RESPONSE_TIMEOUT =
|
|
116878
|
+
const RESPONSE_TIMEOUT = 5e3;
|
|
116836
116879
|
const responsePromise = (async () => {
|
|
116837
116880
|
const responseChunks = [];
|
|
116838
116881
|
for await (const chunk of stream.source) {
|
|
116839
116882
|
responseChunks.push(chunk.subarray());
|
|
116840
116883
|
}
|
|
116841
116884
|
if (responseChunks.length > 0) {
|
|
116842
|
-
const responseData =
|
|
116843
|
-
responseChunks.reduce((acc, chunk) => acc + chunk.length, 0)
|
|
116844
|
-
);
|
|
116845
|
-
let offset = 0;
|
|
116846
|
-
for (const chunk of responseChunks) {
|
|
116847
|
-
responseData.set(chunk, offset);
|
|
116848
|
-
offset += chunk.length;
|
|
116849
|
-
}
|
|
116885
|
+
const responseData = concatUint8Arrays(responseChunks);
|
|
116850
116886
|
const responseEnvelope = decodeMessage2(responseData);
|
|
116851
116887
|
logger5.info("Received response", {
|
|
116852
116888
|
id: responseEnvelope.id,
|
|
@@ -116858,10 +116894,10 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116858
116894
|
return void 0;
|
|
116859
116895
|
}
|
|
116860
116896
|
})();
|
|
116861
|
-
const timeoutPromise = new Promise((
|
|
116897
|
+
const timeoutPromise = new Promise((resolve2) => {
|
|
116862
116898
|
setTimeout(() => {
|
|
116863
116899
|
logger5.warn("Response timeout", { id: envelope.id, timeout: RESPONSE_TIMEOUT });
|
|
116864
|
-
|
|
116900
|
+
resolve2(void 0);
|
|
116865
116901
|
}, RESPONSE_TIMEOUT);
|
|
116866
116902
|
});
|
|
116867
116903
|
const response = await Promise.race([responsePromise, timeoutPromise]);
|
|
@@ -116904,14 +116940,7 @@ async function handleIncomingStream(stream, handlers, catchAllHandler, verifyFn)
|
|
|
116904
116940
|
for await (const chunk of stream.source) {
|
|
116905
116941
|
chunks.push(chunk.subarray());
|
|
116906
116942
|
}
|
|
116907
|
-
const data =
|
|
116908
|
-
chunks.reduce((acc, chunk) => acc + chunk.length, 0)
|
|
116909
|
-
);
|
|
116910
|
-
let offset = 0;
|
|
116911
|
-
for (const chunk of chunks) {
|
|
116912
|
-
data.set(chunk, offset);
|
|
116913
|
-
offset += chunk.length;
|
|
116914
|
-
}
|
|
116943
|
+
const data = concatUint8Arrays(chunks);
|
|
116915
116944
|
const envelope = decodeMessage2(data);
|
|
116916
116945
|
if (!validateEnvelope(envelope)) {
|
|
116917
116946
|
logger5.warn("Received invalid message envelope");
|
|
@@ -116996,9 +117025,9 @@ function createDefaultTrustScore() {
|
|
|
116996
117025
|
function createTrustSystem(config2) {
|
|
116997
117026
|
return new TrustSystem(config2);
|
|
116998
117027
|
}
|
|
116999
|
-
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;
|
|
117028
|
+
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, peerCache, CACHE_TTL, logger5, TrustMetrics, logger6, InteractionHistory, logger7, EndorsementManager, logger8, SybilDefense, logger9, TrustSystem;
|
|
117000
117029
|
var init_dist3 = __esm({
|
|
117001
|
-
"
|
|
117030
|
+
"../../node_modules/.pnpm/@highway1+core@0.1.45/node_modules/@highway1/core/dist/index.js"() {
|
|
117002
117031
|
init_esm_shims();
|
|
117003
117032
|
init_ed25519();
|
|
117004
117033
|
init_base58();
|
|
@@ -117644,6 +117673,8 @@ var init_dist3 = __esm({
|
|
|
117644
117673
|
}
|
|
117645
117674
|
};
|
|
117646
117675
|
logger4 = createLogger("dht");
|
|
117676
|
+
peerCache = /* @__PURE__ */ new Map();
|
|
117677
|
+
CACHE_TTL = 5 * 60 * 1e3;
|
|
117647
117678
|
logger5 = createLogger("router");
|
|
117648
117679
|
TrustMetrics = class {
|
|
117649
117680
|
/**
|
|
@@ -118313,7 +118344,7 @@ function registerInitCommand(program2) {
|
|
|
118313
118344
|
init_esm_shims();
|
|
118314
118345
|
init_dist3();
|
|
118315
118346
|
function registerJoinCommand(program2) {
|
|
118316
|
-
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) => {
|
|
118347
|
+
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").option("--save-dir <path>", "Directory to save received file attachments", "./downloads").action(async (options) => {
|
|
118317
118348
|
try {
|
|
118318
118349
|
printHeader("Join Clawiverse Network");
|
|
118319
118350
|
const identity3 = getIdentity();
|
|
@@ -118343,12 +118374,12 @@ function registerJoinCommand(program2) {
|
|
|
118343
118374
|
info(`Listening on: ${node.getMultiaddrs().join(", ")}`);
|
|
118344
118375
|
const connectSpin = spinner("Connecting to bootstrap peers...");
|
|
118345
118376
|
let connected = false;
|
|
118346
|
-
await new Promise((
|
|
118347
|
-
const timeout = setTimeout(
|
|
118377
|
+
await new Promise((resolve2) => {
|
|
118378
|
+
const timeout = setTimeout(resolve2, 1e4);
|
|
118348
118379
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
118349
118380
|
connected = true;
|
|
118350
118381
|
clearTimeout(timeout);
|
|
118351
|
-
|
|
118382
|
+
resolve2();
|
|
118352
118383
|
}, { once: true });
|
|
118353
118384
|
});
|
|
118354
118385
|
if (!connected && bootstrapPeers.length > 0) {
|
|
@@ -118368,7 +118399,7 @@ function registerJoinCommand(program2) {
|
|
|
118368
118399
|
info("Waiting for relay reservation...");
|
|
118369
118400
|
let reservationSucceeded = false;
|
|
118370
118401
|
if (initialRelayCount === 0) {
|
|
118371
|
-
await new Promise((
|
|
118402
|
+
await new Promise((resolve2) => {
|
|
118372
118403
|
const RELAY_WAIT_MS = 3e4;
|
|
118373
118404
|
const POLL_MS = 500;
|
|
118374
118405
|
let settled = false;
|
|
@@ -118379,7 +118410,7 @@ function registerJoinCommand(program2) {
|
|
|
118379
118410
|
clearInterval(pollTimer);
|
|
118380
118411
|
node.libp2p.removeEventListener("relay:reservation", onReservation);
|
|
118381
118412
|
node.libp2p.removeEventListener("self:peer:update", onPeerUpdate);
|
|
118382
|
-
|
|
118413
|
+
resolve2();
|
|
118383
118414
|
};
|
|
118384
118415
|
const onReservation = () => {
|
|
118385
118416
|
reservationSucceeded = true;
|
|
@@ -118514,6 +118545,7 @@ function registerJoinCommand(program2) {
|
|
|
118514
118545
|
verifyFn,
|
|
118515
118546
|
dht
|
|
118516
118547
|
);
|
|
118548
|
+
const saveDir = resolve(options.saveDir ?? "./downloads");
|
|
118517
118549
|
const messageHandler = async (envelope) => {
|
|
118518
118550
|
const payload = envelope.payload;
|
|
118519
118551
|
console.log();
|
|
@@ -118521,7 +118553,24 @@ function registerJoinCommand(program2) {
|
|
|
118521
118553
|
info(` Message ID: ${envelope.id}`);
|
|
118522
118554
|
info(` Protocol: ${envelope.protocol}`);
|
|
118523
118555
|
info(` Type: ${envelope.type}`);
|
|
118524
|
-
|
|
118556
|
+
let savedPath;
|
|
118557
|
+
if (payload.attachment) {
|
|
118558
|
+
const att = payload.attachment;
|
|
118559
|
+
try {
|
|
118560
|
+
await mkdir(saveDir, { recursive: true });
|
|
118561
|
+
const safeName = att.filename.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
118562
|
+
savedPath = join(saveDir, `${envelope.id.slice(-8)}_${safeName}`);
|
|
118563
|
+
await writeFile(savedPath, Buffer.from(att.data, "base64"));
|
|
118564
|
+
success(` Attachment saved: ${savedPath}`);
|
|
118565
|
+
info(` File: ${att.filename} (${att.size} bytes, ${att.mimeType})`);
|
|
118566
|
+
} catch (e2) {
|
|
118567
|
+
error(` Failed to save attachment: ${e2.message}`);
|
|
118568
|
+
}
|
|
118569
|
+
const displayPayload = { ...payload, attachment: "[binary data omitted]" };
|
|
118570
|
+
info(` Payload: ${JSON.stringify(displayPayload, null, 2)}`);
|
|
118571
|
+
} else {
|
|
118572
|
+
info(` Payload: ${JSON.stringify(payload, null, 2)}`);
|
|
118573
|
+
}
|
|
118525
118574
|
console.log();
|
|
118526
118575
|
if (envelope.type === "request") {
|
|
118527
118576
|
info(" Sending acknowledgment response...");
|
|
@@ -118533,19 +118582,16 @@ function registerJoinCommand(program2) {
|
|
|
118533
118582
|
});
|
|
118534
118583
|
const responseEnvelope = createEnvelope2(
|
|
118535
118584
|
envelope.to,
|
|
118536
|
-
// We are the recipient, now we're the sender
|
|
118537
118585
|
envelope.from,
|
|
118538
|
-
// Original sender is now the recipient
|
|
118539
118586
|
"response",
|
|
118540
118587
|
envelope.protocol,
|
|
118541
118588
|
{
|
|
118542
118589
|
status: "received",
|
|
118543
118590
|
message: "Message received and processed",
|
|
118544
|
-
|
|
118591
|
+
savedPath: savedPath ?? null,
|
|
118545
118592
|
timestamp: Date.now()
|
|
118546
118593
|
},
|
|
118547
118594
|
envelope.id
|
|
118548
|
-
// replyTo: original message ID
|
|
118549
118595
|
);
|
|
118550
118596
|
const signedResponse = await signEnvelope2(
|
|
118551
118597
|
responseEnvelope,
|
|
@@ -118607,11 +118653,11 @@ function registerDiscoverCommand(program2) {
|
|
|
118607
118653
|
});
|
|
118608
118654
|
await node.start();
|
|
118609
118655
|
spin.text = "Waiting for DHT peers...";
|
|
118610
|
-
await new Promise((
|
|
118611
|
-
const timeout = setTimeout(
|
|
118656
|
+
await new Promise((resolve2) => {
|
|
118657
|
+
const timeout = setTimeout(resolve2, 15e3);
|
|
118612
118658
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
118613
118659
|
clearTimeout(timeout);
|
|
118614
|
-
setTimeout(
|
|
118660
|
+
setTimeout(resolve2, 3e3);
|
|
118615
118661
|
}, { once: true });
|
|
118616
118662
|
});
|
|
118617
118663
|
spin.text = "Querying DHT...";
|
|
@@ -118705,8 +118751,68 @@ function registerDiscoverCommand(program2) {
|
|
|
118705
118751
|
// src/commands/send.ts
|
|
118706
118752
|
init_esm_shims();
|
|
118707
118753
|
init_dist3();
|
|
118754
|
+
|
|
118755
|
+
// src/daemon/client.ts
|
|
118756
|
+
init_esm_shims();
|
|
118757
|
+
init_dist3();
|
|
118758
|
+
var logger10 = createLogger("daemon-client");
|
|
118759
|
+
var DaemonClient = class {
|
|
118760
|
+
socketPath;
|
|
118761
|
+
constructor(socketPath = "/tmp/clawiverse.sock") {
|
|
118762
|
+
this.socketPath = socketPath;
|
|
118763
|
+
}
|
|
118764
|
+
async send(command, params) {
|
|
118765
|
+
return new Promise((resolve2, reject) => {
|
|
118766
|
+
const socket = connect(this.socketPath);
|
|
118767
|
+
const requestId = `req_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
118768
|
+
let responseReceived = false;
|
|
118769
|
+
socket.on("connect", () => {
|
|
118770
|
+
const request = { id: requestId, command, params };
|
|
118771
|
+
logger10.debug("Sending request", { command, id: requestId });
|
|
118772
|
+
socket.write(JSON.stringify(request));
|
|
118773
|
+
});
|
|
118774
|
+
socket.on("data", (data) => {
|
|
118775
|
+
try {
|
|
118776
|
+
const response = JSON.parse(data.toString());
|
|
118777
|
+
responseReceived = true;
|
|
118778
|
+
socket.end();
|
|
118779
|
+
logger10.debug("Received response", { success: response.success, id: response.id });
|
|
118780
|
+
if (response.success) {
|
|
118781
|
+
resolve2(response.data);
|
|
118782
|
+
} else {
|
|
118783
|
+
reject(new Error(response.error));
|
|
118784
|
+
}
|
|
118785
|
+
} catch (error2) {
|
|
118786
|
+
reject(new Error(`Failed to parse response: ${error2.message}`));
|
|
118787
|
+
}
|
|
118788
|
+
});
|
|
118789
|
+
socket.on("error", (err2) => {
|
|
118790
|
+
if (!responseReceived) {
|
|
118791
|
+
logger10.debug("Socket error", { error: err2.message });
|
|
118792
|
+
reject(err2);
|
|
118793
|
+
}
|
|
118794
|
+
});
|
|
118795
|
+
socket.setTimeout(3e4, () => {
|
|
118796
|
+
if (!responseReceived) {
|
|
118797
|
+
socket.destroy();
|
|
118798
|
+
reject(new Error("Request timeout"));
|
|
118799
|
+
}
|
|
118800
|
+
});
|
|
118801
|
+
});
|
|
118802
|
+
}
|
|
118803
|
+
async isDaemonRunning() {
|
|
118804
|
+
try {
|
|
118805
|
+
await this.send("status", {});
|
|
118806
|
+
return true;
|
|
118807
|
+
} catch {
|
|
118808
|
+
return false;
|
|
118809
|
+
}
|
|
118810
|
+
}
|
|
118811
|
+
};
|
|
118812
|
+
|
|
118813
|
+
// src/commands/send.ts
|
|
118708
118814
|
function registerSendCommand(program2) {
|
|
118709
|
-
program2.command("send").description("Send a message to another agent").requiredOption("--to <did>", "Recipient DID").requiredOption("--protocol <protocol>", "Protocol identifier").
|
|
118815
|
+
program2.command("send").description("Send a message to another agent").requiredOption("--to <did>", "Recipient DID").requiredOption("--protocol <protocol>", "Protocol identifier").option("--payload <json>", "Message payload (JSON)").option("--file <path>", "Attach a file (image, binary, text) as payload attachment").option("--type <type>", "Message type (request|notification)", "request").option("--bootstrap <peers...>", "Bootstrap peer addresses").option("--peer <multiaddr>", "Direct peer multiaddr (bypasses DHT lookup)").action(async (options) => {
|
|
118710
118816
|
try {
|
|
118711
118817
|
printHeader("Send Message");
|
|
118712
118818
|
const identity3 = getIdentity();
|
|
@@ -118714,13 +118820,95 @@ function registerSendCommand(program2) {
|
|
|
118714
118820
|
error('No identity found. Run "hw1 init" first.');
|
|
118715
118821
|
process.exit(1);
|
|
118716
118822
|
}
|
|
118717
|
-
|
|
118718
|
-
|
|
118719
|
-
payload = JSON.parse(options.payload);
|
|
118720
|
-
} catch {
|
|
118721
|
-
error("Invalid JSON payload");
|
|
118823
|
+
if (!options.payload && !options.file) {
|
|
118824
|
+
error("Either --payload <json> or --file <path> is required.");
|
|
118722
118825
|
process.exit(1);
|
|
118723
118826
|
}
|
|
118827
|
+
let payload = {};
|
|
118828
|
+
if (options.payload) {
|
|
118829
|
+
try {
|
|
118830
|
+
payload = JSON.parse(options.payload);
|
|
118831
|
+
} catch {
|
|
118832
|
+
error("Invalid JSON payload");
|
|
118833
|
+
process.exit(1);
|
|
118834
|
+
}
|
|
118835
|
+
}
|
|
118836
|
+
if (options.file) {
|
|
118837
|
+
const filePath = options.file;
|
|
118838
|
+
let fileBytes;
|
|
118839
|
+
try {
|
|
118840
|
+
fileBytes = await readFile(filePath);
|
|
118841
|
+
} catch {
|
|
118842
|
+
error(`Cannot read file: ${filePath}`);
|
|
118843
|
+
process.exit(1);
|
|
118844
|
+
}
|
|
118845
|
+
const filename = basename(filePath);
|
|
118846
|
+
const mimeType = guessMimeType(filename);
|
|
118847
|
+
payload.attachment = {
|
|
118848
|
+
filename,
|
|
118849
|
+
mimeType,
|
|
118850
|
+
size: fileBytes.length,
|
|
118851
|
+
data: fileBytes.toString("base64")
|
|
118852
|
+
};
|
|
118853
|
+
info(`Attaching file: ${filename} (${fileBytes.length} bytes, ${mimeType})`);
|
|
118854
|
+
}
|
|
118855
|
+
const client = new DaemonClient();
|
|
118856
|
+
if (await client.isDaemonRunning()) {
|
|
118857
|
+
const spin2 = spinner("Sending message via daemon...");
|
|
118858
|
+
try {
|
|
118859
|
+
const result = await client.send("send", {
|
|
118860
|
+
to: options.to,
|
|
118861
|
+
protocol: options.protocol,
|
|
118862
|
+
payload,
|
|
118863
|
+
type: options.type,
|
|
118864
|
+
peer: options.peer
|
|
118865
|
+
});
|
|
118866
|
+
spin2.succeed("Message sent successfully!");
|
|
118867
|
+
console.log();
|
|
118868
|
+
info(`Message ID: ${result.id}`);
|
|
118869
|
+
info(`To: ${options.to}`);
|
|
118870
|
+
info(`Protocol: ${options.protocol}`);
|
|
118871
|
+
info(`Type: ${options.type}`);
|
|
118872
|
+
if (payload.attachment) {
|
|
118873
|
+
const att = payload.attachment;
|
|
118874
|
+
info(`Attachment: ${att.filename} (${att.size} bytes, ${att.mimeType})`);
|
|
118875
|
+
const rest = { ...payload, attachment: "[binary data omitted]" };
|
|
118876
|
+
info(`Payload: ${JSON.stringify(rest)}`);
|
|
118877
|
+
} else {
|
|
118878
|
+
info(`Payload: ${JSON.stringify(payload)}`);
|
|
118879
|
+
}
|
|
118880
|
+
if (result.response) {
|
|
118881
|
+
console.log();
|
|
118882
|
+
success(">>> Received response from recipient");
|
|
118883
|
+
info(`Response ID: ${result.response.id}`);
|
|
118884
|
+
info(`Reply To: ${result.response.replyTo}`);
|
|
118885
|
+
info(`Protocol: ${result.response.protocol}`);
|
|
118886
|
+
const respPayload = result.response.payload;
|
|
118887
|
+
if (respPayload?.attachment) {
|
|
118888
|
+
const att = respPayload.attachment;
|
|
118889
|
+
info(`Attachment: ${att.filename} (${att.size} bytes, ${att.mimeType})`);
|
|
118890
|
+
info(`Payload: ${JSON.stringify({ ...respPayload, attachment: "[binary data omitted]" }, null, 2)}`);
|
|
118891
|
+
} else {
|
|
118892
|
+
info(`Payload: ${JSON.stringify(result.response.payload, null, 2)}`);
|
|
118893
|
+
}
|
|
118894
|
+
} else if (options.type === "request") {
|
|
118895
|
+
console.log();
|
|
118896
|
+
info("No response received (recipient may not have returned a response)");
|
|
118897
|
+
}
|
|
118898
|
+
success("Done");
|
|
118899
|
+
return;
|
|
118900
|
+
} catch (err2) {
|
|
118901
|
+
spin2.fail("Daemon send failed, falling back to ephemeral node");
|
|
118902
|
+
console.log();
|
|
118903
|
+
info('Tip: Restart daemon with "clawiverse daemon restart" if issues persist');
|
|
118904
|
+
console.log();
|
|
118905
|
+
}
|
|
118906
|
+
} else {
|
|
118907
|
+
console.log();
|
|
118908
|
+
info("\u26A0 Daemon not running, using ephemeral node (slower)");
|
|
118909
|
+
info('Tip: Start daemon with "clawiverse daemon start" for faster messaging');
|
|
118910
|
+
console.log();
|
|
118911
|
+
}
|
|
118724
118912
|
const spin = spinner("Starting node...");
|
|
118725
118913
|
const keyPair = importKeyPair({
|
|
118726
118914
|
publicKey: identity3.publicKey,
|
|
@@ -118732,11 +118920,11 @@ function registerSendCommand(program2) {
|
|
|
118732
118920
|
bootstrapPeers,
|
|
118733
118921
|
enableDHT: true
|
|
118734
118922
|
});
|
|
118735
|
-
const identifyDone = new Promise((
|
|
118736
|
-
const timeout = setTimeout(
|
|
118923
|
+
const identifyDone = new Promise((resolve2) => {
|
|
118924
|
+
const timeout = setTimeout(resolve2, 2e3);
|
|
118737
118925
|
node.libp2p.addEventListener("peer:identify", () => {
|
|
118738
118926
|
clearTimeout(timeout);
|
|
118739
|
-
|
|
118927
|
+
resolve2();
|
|
118740
118928
|
}, { once: true });
|
|
118741
118929
|
});
|
|
118742
118930
|
await node.start();
|
|
@@ -118791,14 +118979,28 @@ function registerSendCommand(program2) {
|
|
|
118791
118979
|
info(`To: ${options.to}`);
|
|
118792
118980
|
info(`Protocol: ${options.protocol}`);
|
|
118793
118981
|
info(`Type: ${options.type}`);
|
|
118794
|
-
|
|
118982
|
+
if (payload.attachment) {
|
|
118983
|
+
const att = payload.attachment;
|
|
118984
|
+
info(`Attachment: ${att.filename} (${att.size} bytes, ${att.mimeType})`);
|
|
118985
|
+
const rest = { ...payload, attachment: "[binary data omitted]" };
|
|
118986
|
+
info(`Payload: ${JSON.stringify(rest)}`);
|
|
118987
|
+
} else {
|
|
118988
|
+
info(`Payload: ${JSON.stringify(payload)}`);
|
|
118989
|
+
}
|
|
118795
118990
|
if (response) {
|
|
118796
118991
|
console.log();
|
|
118797
118992
|
success(">>> Received response from recipient");
|
|
118798
118993
|
info(`Response ID: ${response.id}`);
|
|
118799
118994
|
info(`Reply To: ${response.replyTo}`);
|
|
118800
118995
|
info(`Protocol: ${response.protocol}`);
|
|
118801
|
-
|
|
118996
|
+
const respPayload = response.payload;
|
|
118997
|
+
if (respPayload?.attachment) {
|
|
118998
|
+
const att = respPayload.attachment;
|
|
118999
|
+
info(`Attachment: ${att.filename} (${att.size} bytes, ${att.mimeType})`);
|
|
119000
|
+
info(`Payload: ${JSON.stringify({ ...respPayload, attachment: "[binary data omitted]" }, null, 2)}`);
|
|
119001
|
+
} else {
|
|
119002
|
+
info(`Payload: ${JSON.stringify(response.payload, null, 2)}`);
|
|
119003
|
+
}
|
|
118802
119004
|
} else if (options.type === "request") {
|
|
118803
119005
|
console.log();
|
|
118804
119006
|
info("No response received (recipient may not have returned a response)");
|
|
@@ -118814,6 +119016,32 @@ function registerSendCommand(program2) {
|
|
|
118814
119016
|
}
|
|
118815
119017
|
});
|
|
118816
119018
|
}
|
|
119019
|
+
function guessMimeType(filename) {
|
|
119020
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
|
119021
|
+
const map2 = {
|
|
119022
|
+
// images
|
|
119023
|
+
png: "image/png",
|
|
119024
|
+
jpg: "image/jpeg",
|
|
119025
|
+
jpeg: "image/jpeg",
|
|
119026
|
+
gif: "image/gif",
|
|
119027
|
+
webp: "image/webp",
|
|
119028
|
+
svg: "image/svg+xml",
|
|
119029
|
+
// documents
|
|
119030
|
+
pdf: "application/pdf",
|
|
119031
|
+
txt: "text/plain",
|
|
119032
|
+
md: "text/markdown",
|
|
119033
|
+
json: "application/json",
|
|
119034
|
+
csv: "text/csv",
|
|
119035
|
+
// audio/video
|
|
119036
|
+
mp3: "audio/mpeg",
|
|
119037
|
+
mp4: "video/mp4",
|
|
119038
|
+
wav: "audio/wav",
|
|
119039
|
+
// archives
|
|
119040
|
+
zip: "application/zip",
|
|
119041
|
+
gz: "application/gzip"
|
|
119042
|
+
};
|
|
119043
|
+
return map2[ext] ?? "application/octet-stream";
|
|
119044
|
+
}
|
|
118817
119045
|
|
|
118818
119046
|
// src/commands/status.ts
|
|
118819
119047
|
init_esm_shims();
|
|
@@ -118950,7 +119178,7 @@ function registerCardCommand(program2) {
|
|
|
118950
119178
|
// src/commands/trust.ts
|
|
118951
119179
|
init_esm_shims();
|
|
118952
119180
|
init_dist3();
|
|
118953
|
-
var
|
|
119181
|
+
var logger11 = createLogger("cli:trust");
|
|
118954
119182
|
function createTrustCommand() {
|
|
118955
119183
|
const trust = new Command("trust").description("Manage trust scores and endorsements");
|
|
118956
119184
|
trust.command("show").description("Show trust score for an agent").argument("<did>", "Agent DID").action(async (did) => {
|
|
@@ -118983,7 +119211,7 @@ function createTrustCommand() {
|
|
|
118983
119211
|
}
|
|
118984
119212
|
await trustSystem.stop();
|
|
118985
119213
|
} catch (error2) {
|
|
118986
|
-
|
|
119214
|
+
logger11.error("Failed to show trust score", error2);
|
|
118987
119215
|
console.error("Error:", error2 instanceof Error ? error2.message : error2);
|
|
118988
119216
|
process.exit(1);
|
|
118989
119217
|
}
|
|
@@ -119024,7 +119252,7 @@ function createTrustCommand() {
|
|
|
119024
119252
|
console.log(`Reason: ${endorsement.reason}`);
|
|
119025
119253
|
await trustSystem.stop();
|
|
119026
119254
|
} catch (error2) {
|
|
119027
|
-
|
|
119255
|
+
logger11.error("Failed to endorse agent", error2);
|
|
119028
119256
|
console.error("Error:", error2 instanceof Error ? error2.message : error2);
|
|
119029
119257
|
process.exit(1);
|
|
119030
119258
|
}
|
|
@@ -119060,7 +119288,7 @@ function createTrustCommand() {
|
|
|
119060
119288
|
}
|
|
119061
119289
|
await trustSystem.stop();
|
|
119062
119290
|
} catch (error2) {
|
|
119063
|
-
|
|
119291
|
+
logger11.error("Failed to show history", error2);
|
|
119064
119292
|
console.error("Error:", error2 instanceof Error ? error2.message : error2);
|
|
119065
119293
|
process.exit(1);
|
|
119066
119294
|
}
|
|
@@ -119097,7 +119325,7 @@ function createTrustCommand() {
|
|
|
119097
119325
|
await history.close();
|
|
119098
119326
|
await trustSystem.stop();
|
|
119099
119327
|
} catch (error2) {
|
|
119100
|
-
|
|
119328
|
+
logger11.error("Failed to show stats", error2);
|
|
119101
119329
|
console.error("Error:", error2 instanceof Error ? error2.message : error2);
|
|
119102
119330
|
process.exit(1);
|
|
119103
119331
|
}
|
|
@@ -119105,16 +119333,367 @@ function createTrustCommand() {
|
|
|
119105
119333
|
return trust;
|
|
119106
119334
|
}
|
|
119107
119335
|
|
|
119336
|
+
// src/commands/daemon.ts
|
|
119337
|
+
init_esm_shims();
|
|
119338
|
+
|
|
119339
|
+
// src/daemon/server.ts
|
|
119340
|
+
init_esm_shims();
|
|
119341
|
+
init_dist3();
|
|
119342
|
+
init_dist3();
|
|
119343
|
+
var logger12 = createLogger("daemon");
|
|
119344
|
+
var ClawDaemon = class {
|
|
119345
|
+
node = null;
|
|
119346
|
+
router = null;
|
|
119347
|
+
dht = null;
|
|
119348
|
+
server = null;
|
|
119349
|
+
socketPath;
|
|
119350
|
+
identity;
|
|
119351
|
+
bootstrapPeers;
|
|
119352
|
+
constructor(socketPath = "/tmp/clawiverse.sock") {
|
|
119353
|
+
this.socketPath = socketPath;
|
|
119354
|
+
this.identity = getIdentity();
|
|
119355
|
+
this.bootstrapPeers = getBootstrapPeers();
|
|
119356
|
+
if (!this.identity) {
|
|
119357
|
+
throw new Error('No identity found. Run "clawiverse init" first.');
|
|
119358
|
+
}
|
|
119359
|
+
}
|
|
119360
|
+
async start() {
|
|
119361
|
+
try {
|
|
119362
|
+
logger12.info("Starting Clawiverse daemon", { socketPath: this.socketPath });
|
|
119363
|
+
const keyPair = importKeyPair({
|
|
119364
|
+
publicKey: this.identity.publicKey,
|
|
119365
|
+
privateKey: this.identity.privateKey
|
|
119366
|
+
});
|
|
119367
|
+
this.node = await createNode({
|
|
119368
|
+
keyPair,
|
|
119369
|
+
bootstrapPeers: this.bootstrapPeers,
|
|
119370
|
+
enableDHT: true
|
|
119371
|
+
});
|
|
119372
|
+
await this.node.start();
|
|
119373
|
+
logger12.info("Node started", { peerId: this.node.getPeerId() });
|
|
119374
|
+
this.dht = createDHTOperations(this.node.libp2p);
|
|
119375
|
+
const verifyFn = async (signature, data) => {
|
|
119376
|
+
try {
|
|
119377
|
+
const decoded = JSON.parse(new TextDecoder().decode(data));
|
|
119378
|
+
if (!decoded.from || typeof decoded.from !== "string") return false;
|
|
119379
|
+
const senderPublicKey = extractPublicKey(decoded.from);
|
|
119380
|
+
return verify(signature, data, senderPublicKey);
|
|
119381
|
+
} catch {
|
|
119382
|
+
return false;
|
|
119383
|
+
}
|
|
119384
|
+
};
|
|
119385
|
+
this.router = createMessageRouter(
|
|
119386
|
+
this.node.libp2p,
|
|
119387
|
+
verifyFn,
|
|
119388
|
+
this.dht,
|
|
119389
|
+
this.bootstrapPeers
|
|
119390
|
+
);
|
|
119391
|
+
await this.router.start();
|
|
119392
|
+
logger12.info("Router started");
|
|
119393
|
+
this.server = createServer((socket) => {
|
|
119394
|
+
this.handleConnection(socket);
|
|
119395
|
+
});
|
|
119396
|
+
this.server.listen(this.socketPath);
|
|
119397
|
+
logger12.info("Daemon listening", { socketPath: this.socketPath });
|
|
119398
|
+
console.log(`\u2713 Clawiverse daemon started`);
|
|
119399
|
+
console.log(` Socket: ${this.socketPath}`);
|
|
119400
|
+
console.log(` Peer ID: ${this.node.getPeerId()}`);
|
|
119401
|
+
console.log(` DID: ${this.identity.did}`);
|
|
119402
|
+
} catch (error2) {
|
|
119403
|
+
logger12.error("Failed to start daemon", error2);
|
|
119404
|
+
throw error2;
|
|
119405
|
+
}
|
|
119406
|
+
}
|
|
119407
|
+
handleConnection(socket) {
|
|
119408
|
+
socket.on("data", async (data) => {
|
|
119409
|
+
try {
|
|
119410
|
+
const request = JSON.parse(data.toString());
|
|
119411
|
+
logger12.debug("Received request", { command: request.command, id: request.id });
|
|
119412
|
+
const response = await this.handleRequest(request);
|
|
119413
|
+
socket.write(JSON.stringify(response) + "\n");
|
|
119414
|
+
} catch (error2) {
|
|
119415
|
+
const errorResponse = {
|
|
119416
|
+
id: "unknown",
|
|
119417
|
+
success: false,
|
|
119418
|
+
error: error2.message
|
|
119419
|
+
};
|
|
119420
|
+
socket.write(JSON.stringify(errorResponse) + "\n");
|
|
119421
|
+
}
|
|
119422
|
+
});
|
|
119423
|
+
socket.on("error", (error2) => {
|
|
119424
|
+
logger12.warn("Socket error", { error: error2.message });
|
|
119425
|
+
});
|
|
119426
|
+
}
|
|
119427
|
+
async handleRequest(req) {
|
|
119428
|
+
try {
|
|
119429
|
+
switch (req.command) {
|
|
119430
|
+
case "send":
|
|
119431
|
+
return await this.handleSend(req);
|
|
119432
|
+
case "discover":
|
|
119433
|
+
return await this.handleDiscover(req);
|
|
119434
|
+
case "status":
|
|
119435
|
+
return this.handleStatus(req);
|
|
119436
|
+
case "shutdown":
|
|
119437
|
+
await this.shutdown();
|
|
119438
|
+
return { id: req.id, success: true };
|
|
119439
|
+
default:
|
|
119440
|
+
return { id: req.id, success: false, error: "Unknown command" };
|
|
119441
|
+
}
|
|
119442
|
+
} catch (error2) {
|
|
119443
|
+
logger12.error("Request handler error", { command: req.command, error: error2 });
|
|
119444
|
+
return { id: req.id, success: false, error: error2.message };
|
|
119445
|
+
}
|
|
119446
|
+
}
|
|
119447
|
+
async handleSend(req) {
|
|
119448
|
+
const { to, protocol, payload, type, peer } = req.params;
|
|
119449
|
+
if (!this.router) {
|
|
119450
|
+
return { id: req.id, success: false, error: "Router not initialized" };
|
|
119451
|
+
}
|
|
119452
|
+
const envelope = createEnvelope(
|
|
119453
|
+
this.identity.did,
|
|
119454
|
+
to,
|
|
119455
|
+
type || "request",
|
|
119456
|
+
protocol,
|
|
119457
|
+
payload
|
|
119458
|
+
);
|
|
119459
|
+
const keyPair = importKeyPair({
|
|
119460
|
+
publicKey: this.identity.publicKey,
|
|
119461
|
+
privateKey: this.identity.privateKey
|
|
119462
|
+
});
|
|
119463
|
+
const signedEnvelope = await signEnvelope(
|
|
119464
|
+
envelope,
|
|
119465
|
+
(data) => sign(data, keyPair.privateKey)
|
|
119466
|
+
);
|
|
119467
|
+
let peerHint = void 0;
|
|
119468
|
+
if (peer) {
|
|
119469
|
+
const parts = peer.split("/p2p/");
|
|
119470
|
+
if (parts.length === 2) {
|
|
119471
|
+
peerHint = {
|
|
119472
|
+
peerId: parts[1],
|
|
119473
|
+
multiaddrs: [peer]
|
|
119474
|
+
};
|
|
119475
|
+
}
|
|
119476
|
+
}
|
|
119477
|
+
const response = await this.router.sendMessage(signedEnvelope, peerHint);
|
|
119478
|
+
return {
|
|
119479
|
+
id: req.id,
|
|
119480
|
+
success: true,
|
|
119481
|
+
data: {
|
|
119482
|
+
id: signedEnvelope.id,
|
|
119483
|
+
response: response || null
|
|
119484
|
+
}
|
|
119485
|
+
};
|
|
119486
|
+
}
|
|
119487
|
+
async handleDiscover(req) {
|
|
119488
|
+
const { query } = req.params;
|
|
119489
|
+
if (!this.dht) {
|
|
119490
|
+
return { id: req.id, success: false, error: "DHT not initialized" };
|
|
119491
|
+
}
|
|
119492
|
+
const results = await this.dht.searchSemantic(query);
|
|
119493
|
+
return {
|
|
119494
|
+
id: req.id,
|
|
119495
|
+
success: true,
|
|
119496
|
+
data: results
|
|
119497
|
+
};
|
|
119498
|
+
}
|
|
119499
|
+
handleStatus(req) {
|
|
119500
|
+
if (!this.node) {
|
|
119501
|
+
return { id: req.id, success: false, error: "Node not initialized" };
|
|
119502
|
+
}
|
|
119503
|
+
return {
|
|
119504
|
+
id: req.id,
|
|
119505
|
+
success: true,
|
|
119506
|
+
data: {
|
|
119507
|
+
running: true,
|
|
119508
|
+
peerId: this.node.getPeerId(),
|
|
119509
|
+
did: this.identity.did,
|
|
119510
|
+
multiaddrs: this.node.getMultiaddrs(),
|
|
119511
|
+
bootstrapPeers: this.bootstrapPeers
|
|
119512
|
+
}
|
|
119513
|
+
};
|
|
119514
|
+
}
|
|
119515
|
+
async shutdown() {
|
|
119516
|
+
logger12.info("Shutting down daemon");
|
|
119517
|
+
if (this.router) {
|
|
119518
|
+
await this.router.stop();
|
|
119519
|
+
this.router = null;
|
|
119520
|
+
}
|
|
119521
|
+
if (this.node) {
|
|
119522
|
+
await this.node.stop();
|
|
119523
|
+
this.node = null;
|
|
119524
|
+
}
|
|
119525
|
+
if (this.server) {
|
|
119526
|
+
this.server.close();
|
|
119527
|
+
this.server = null;
|
|
119528
|
+
}
|
|
119529
|
+
logger12.info("Daemon stopped");
|
|
119530
|
+
}
|
|
119531
|
+
};
|
|
119532
|
+
var PID_FILE = "/tmp/clawiverse.pid";
|
|
119533
|
+
var SOCKET_PATH = "/tmp/clawiverse.sock";
|
|
119534
|
+
function registerDaemonCommand(program2) {
|
|
119535
|
+
const daemonCommand = program2.command("daemon").description("Manage Clawiverse daemon for fast messaging");
|
|
119536
|
+
daemonCommand.command("start").description("Start daemon in background").action(async () => {
|
|
119537
|
+
try {
|
|
119538
|
+
const client = new DaemonClient(SOCKET_PATH);
|
|
119539
|
+
if (await client.isDaemonRunning()) {
|
|
119540
|
+
success("Daemon already running");
|
|
119541
|
+
const status = await client.send("status", {});
|
|
119542
|
+
info(`Peer ID: ${status.peerId}`);
|
|
119543
|
+
info(`DID: ${status.did}`);
|
|
119544
|
+
return;
|
|
119545
|
+
}
|
|
119546
|
+
const child = spawn(process.execPath, [
|
|
119547
|
+
process.argv[1],
|
|
119548
|
+
"daemon",
|
|
119549
|
+
"run"
|
|
119550
|
+
], {
|
|
119551
|
+
detached: true,
|
|
119552
|
+
stdio: "ignore"
|
|
119553
|
+
});
|
|
119554
|
+
child.unref();
|
|
119555
|
+
writeFileSync(PID_FILE, child.pid.toString());
|
|
119556
|
+
for (let i2 = 0; i2 < 20; i2++) {
|
|
119557
|
+
await new Promise((resolve2) => setTimeout(resolve2, 500));
|
|
119558
|
+
if (await client.isDaemonRunning()) {
|
|
119559
|
+
success("Daemon started");
|
|
119560
|
+
const status = await client.send("status", {});
|
|
119561
|
+
info(`Peer ID: ${status.peerId}`);
|
|
119562
|
+
info(`DID: ${status.did}`);
|
|
119563
|
+
info(`Socket: ${SOCKET_PATH}`);
|
|
119564
|
+
return;
|
|
119565
|
+
}
|
|
119566
|
+
}
|
|
119567
|
+
error("Failed to start daemon (timeout)");
|
|
119568
|
+
process.exit(1);
|
|
119569
|
+
} catch (err2) {
|
|
119570
|
+
error(`Failed to start daemon: ${err2.message}`);
|
|
119571
|
+
process.exit(1);
|
|
119572
|
+
}
|
|
119573
|
+
});
|
|
119574
|
+
daemonCommand.command("run").description("Run daemon in foreground (internal use)").action(async () => {
|
|
119575
|
+
try {
|
|
119576
|
+
const daemon = new ClawDaemon(SOCKET_PATH);
|
|
119577
|
+
await daemon.start();
|
|
119578
|
+
process.on("SIGINT", async () => {
|
|
119579
|
+
console.log("\nShutting down...");
|
|
119580
|
+
await daemon.shutdown();
|
|
119581
|
+
process.exit(0);
|
|
119582
|
+
});
|
|
119583
|
+
process.on("SIGTERM", async () => {
|
|
119584
|
+
await daemon.shutdown();
|
|
119585
|
+
process.exit(0);
|
|
119586
|
+
});
|
|
119587
|
+
} catch (err2) {
|
|
119588
|
+
error(`Failed to run daemon: ${err2.message}`);
|
|
119589
|
+
process.exit(1);
|
|
119590
|
+
}
|
|
119591
|
+
});
|
|
119592
|
+
daemonCommand.command("stop").description("Stop daemon").action(async () => {
|
|
119593
|
+
try {
|
|
119594
|
+
const client = new DaemonClient(SOCKET_PATH);
|
|
119595
|
+
if (!await client.isDaemonRunning()) {
|
|
119596
|
+
info("Daemon not running");
|
|
119597
|
+
return;
|
|
119598
|
+
}
|
|
119599
|
+
await client.send("shutdown", {});
|
|
119600
|
+
success("Daemon stopped");
|
|
119601
|
+
try {
|
|
119602
|
+
if (existsSync(PID_FILE)) {
|
|
119603
|
+
unlinkSync(PID_FILE);
|
|
119604
|
+
}
|
|
119605
|
+
} catch {
|
|
119606
|
+
}
|
|
119607
|
+
try {
|
|
119608
|
+
if (existsSync(SOCKET_PATH)) {
|
|
119609
|
+
unlinkSync(SOCKET_PATH);
|
|
119610
|
+
}
|
|
119611
|
+
} catch {
|
|
119612
|
+
}
|
|
119613
|
+
} catch (err2) {
|
|
119614
|
+
error(`Failed to stop daemon: ${err2.message}`);
|
|
119615
|
+
process.exit(1);
|
|
119616
|
+
}
|
|
119617
|
+
});
|
|
119618
|
+
daemonCommand.command("status").description("Check daemon status").action(async () => {
|
|
119619
|
+
try {
|
|
119620
|
+
const client = new DaemonClient(SOCKET_PATH);
|
|
119621
|
+
if (await client.isDaemonRunning()) {
|
|
119622
|
+
const status = await client.send("status", {});
|
|
119623
|
+
success("Daemon running");
|
|
119624
|
+
console.log();
|
|
119625
|
+
info(`Peer ID: ${status.peerId}`);
|
|
119626
|
+
info(`DID: ${status.did}`);
|
|
119627
|
+
info(`Socket: ${SOCKET_PATH}`);
|
|
119628
|
+
info(`Bootstrap peers: ${status.bootstrapPeers.length}`);
|
|
119629
|
+
console.log();
|
|
119630
|
+
info("Multiaddrs:");
|
|
119631
|
+
status.multiaddrs.forEach((addr) => {
|
|
119632
|
+
console.log(` ${addr}`);
|
|
119633
|
+
});
|
|
119634
|
+
} else {
|
|
119635
|
+
info("Daemon not running");
|
|
119636
|
+
console.log();
|
|
119637
|
+
info("Start daemon with: clawiverse daemon start");
|
|
119638
|
+
}
|
|
119639
|
+
} catch (err2) {
|
|
119640
|
+
error(`Failed to check status: ${err2.message}`);
|
|
119641
|
+
process.exit(1);
|
|
119642
|
+
}
|
|
119643
|
+
});
|
|
119644
|
+
daemonCommand.command("restart").description("Restart daemon").action(async () => {
|
|
119645
|
+
try {
|
|
119646
|
+
const client = new DaemonClient(SOCKET_PATH);
|
|
119647
|
+
if (await client.isDaemonRunning()) {
|
|
119648
|
+
info("Stopping daemon...");
|
|
119649
|
+
await client.send("shutdown", {});
|
|
119650
|
+
await new Promise((resolve2) => setTimeout(resolve2, 1e3));
|
|
119651
|
+
}
|
|
119652
|
+
try {
|
|
119653
|
+
if (existsSync(PID_FILE)) unlinkSync(PID_FILE);
|
|
119654
|
+
if (existsSync(SOCKET_PATH)) unlinkSync(SOCKET_PATH);
|
|
119655
|
+
} catch {
|
|
119656
|
+
}
|
|
119657
|
+
info("Starting daemon...");
|
|
119658
|
+
const child = spawn(process.execPath, [
|
|
119659
|
+
process.argv[1],
|
|
119660
|
+
"daemon",
|
|
119661
|
+
"run"
|
|
119662
|
+
], {
|
|
119663
|
+
detached: true,
|
|
119664
|
+
stdio: "ignore"
|
|
119665
|
+
});
|
|
119666
|
+
child.unref();
|
|
119667
|
+
writeFileSync(PID_FILE, child.pid.toString());
|
|
119668
|
+
for (let i2 = 0; i2 < 20; i2++) {
|
|
119669
|
+
await new Promise((resolve2) => setTimeout(resolve2, 500));
|
|
119670
|
+
if (await client.isDaemonRunning()) {
|
|
119671
|
+
success("Daemon restarted");
|
|
119672
|
+
const status = await client.send("status", {});
|
|
119673
|
+
info(`Peer ID: ${status.peerId}`);
|
|
119674
|
+
info(`DID: ${status.did}`);
|
|
119675
|
+
return;
|
|
119676
|
+
}
|
|
119677
|
+
}
|
|
119678
|
+
error("Failed to restart daemon (timeout)");
|
|
119679
|
+
process.exit(1);
|
|
119680
|
+
} catch (err2) {
|
|
119681
|
+
error(`Failed to restart daemon: ${err2.message}`);
|
|
119682
|
+
process.exit(1);
|
|
119683
|
+
}
|
|
119684
|
+
});
|
|
119685
|
+
}
|
|
119686
|
+
|
|
119108
119687
|
// src/index.ts
|
|
119109
119688
|
if (!Promise.withResolvers) {
|
|
119110
119689
|
Promise.withResolvers = function() {
|
|
119111
|
-
let
|
|
119690
|
+
let resolve2;
|
|
119112
119691
|
let reject;
|
|
119113
119692
|
const promise = new Promise((res, rej) => {
|
|
119114
|
-
|
|
119693
|
+
resolve2 = res;
|
|
119115
119694
|
reject = rej;
|
|
119116
119695
|
});
|
|
119117
|
-
return { promise, resolve, reject };
|
|
119696
|
+
return { promise, resolve: resolve2, reject };
|
|
119118
119697
|
};
|
|
119119
119698
|
}
|
|
119120
119699
|
var require2 = createRequire(import.meta.url);
|
|
@@ -119129,6 +119708,7 @@ registerSendCommand(program);
|
|
|
119129
119708
|
registerStatusCommand(program);
|
|
119130
119709
|
registerIdentityCommand(program);
|
|
119131
119710
|
registerCardCommand(program);
|
|
119711
|
+
registerDaemonCommand(program);
|
|
119132
119712
|
program.addCommand(createTrustCommand());
|
|
119133
119713
|
program.parse();
|
|
119134
119714
|
/*! Bundled license information:
|