claudemesh-cli 1.0.0-alpha.35 → 1.0.0-alpha.37
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/entrypoints/cli.js +233 -51
- package/dist/entrypoints/cli.js.map +12 -10
- package/dist/entrypoints/mcp.js +44 -19
- package/dist/entrypoints/mcp.js.map +4 -4
- package/package.json +1 -1
package/dist/entrypoints/mcp.js
CHANGED
|
@@ -1299,6 +1299,7 @@ class BrokerClient {
|
|
|
1299
1299
|
outbound = [];
|
|
1300
1300
|
pushHandlers = new Set;
|
|
1301
1301
|
pushBuffer = [];
|
|
1302
|
+
pushChain = Promise.resolve();
|
|
1302
1303
|
listPeersResolvers = new Map;
|
|
1303
1304
|
stateResolvers = new Map;
|
|
1304
1305
|
stateListResolvers = new Map;
|
|
@@ -2443,6 +2444,22 @@ class BrokerClient {
|
|
|
2443
2444
|
return;
|
|
2444
2445
|
this.ws.send(JSON.stringify(payload));
|
|
2445
2446
|
}
|
|
2447
|
+
async sendAndWait(payload, timeoutMs = 1e4) {
|
|
2448
|
+
const reqId = `rw-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
2449
|
+
return new Promise((resolve, reject) => {
|
|
2450
|
+
const timer = setTimeout(() => {
|
|
2451
|
+
this.genericResolvers.delete(reqId);
|
|
2452
|
+
reject(new Error("sendAndWait timeout"));
|
|
2453
|
+
}, timeoutMs);
|
|
2454
|
+
this.genericResolvers.set(reqId, (msg) => {
|
|
2455
|
+
clearTimeout(timer);
|
|
2456
|
+
this.genericResolvers.delete(reqId);
|
|
2457
|
+
resolve(msg);
|
|
2458
|
+
});
|
|
2459
|
+
this.sendRaw({ ...payload, _reqId: reqId });
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
genericResolvers = new Map;
|
|
2446
2463
|
close() {
|
|
2447
2464
|
this.closed = true;
|
|
2448
2465
|
this.stopStatsReporting();
|
|
@@ -2643,6 +2660,11 @@ class BrokerClient {
|
|
|
2643
2660
|
}
|
|
2644
2661
|
handleServerMessage(msg) {
|
|
2645
2662
|
const msgReqId = msg._reqId;
|
|
2663
|
+
if (msgReqId && this.genericResolvers.has(msgReqId)) {
|
|
2664
|
+
const resolve = this.genericResolvers.get(msgReqId);
|
|
2665
|
+
resolve(msg);
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2646
2668
|
if (msg.type === "ack") {
|
|
2647
2669
|
const pending = this.pendingSends.get(String(msg.id ?? ""));
|
|
2648
2670
|
if (pending) {
|
|
@@ -2663,7 +2685,7 @@ class BrokerClient {
|
|
|
2663
2685
|
const nonce = String(msg.nonce ?? "");
|
|
2664
2686
|
const ciphertext = String(msg.ciphertext ?? "");
|
|
2665
2687
|
const senderPubkey = String(msg.senderPubkey ?? "");
|
|
2666
|
-
(async () => {
|
|
2688
|
+
this.pushChain = this.pushChain.then(async () => {
|
|
2667
2689
|
const isSystem = msg.subtype === "system" || senderPubkey === "system";
|
|
2668
2690
|
const kind = isSystem ? "broadcast" : senderPubkey ? "direct" : "unknown";
|
|
2669
2691
|
let plaintext = null;
|
|
@@ -2740,7 +2762,9 @@ class BrokerClient {
|
|
|
2740
2762
|
h(push);
|
|
2741
2763
|
} catch {}
|
|
2742
2764
|
}
|
|
2743
|
-
})()
|
|
2765
|
+
}).catch((e) => {
|
|
2766
|
+
this.debug(`push handler chain error: ${e instanceof Error ? e.message : e}`);
|
|
2767
|
+
});
|
|
2744
2768
|
return;
|
|
2745
2769
|
}
|
|
2746
2770
|
if (msg.type === "state_result") {
|
|
@@ -3186,11 +3210,17 @@ class BrokerClient {
|
|
|
3186
3210
|
send();
|
|
3187
3211
|
}
|
|
3188
3212
|
scheduleReconnect() {
|
|
3213
|
+
if (this.reconnectTimer) {
|
|
3214
|
+
this.debug("reconnect already scheduled — skipping");
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3189
3217
|
this.setConnStatus("reconnecting");
|
|
3190
|
-
const
|
|
3218
|
+
const base = BACKOFF_CAPS[Math.min(this.reconnectAttempt, BACKOFF_CAPS.length - 1)];
|
|
3219
|
+
const delay = Math.floor(Math.random() * base);
|
|
3191
3220
|
this.reconnectAttempt += 1;
|
|
3192
|
-
this.debug(`reconnect in ${delay}ms (attempt ${this.reconnectAttempt})`);
|
|
3221
|
+
this.debug(`reconnect in ${delay}ms (attempt ${this.reconnectAttempt}, base ${base}ms)`);
|
|
3193
3222
|
this.reconnectTimer = setTimeout(() => {
|
|
3223
|
+
this.reconnectTimer = null;
|
|
3194
3224
|
if (this.closed)
|
|
3195
3225
|
return;
|
|
3196
3226
|
this.connect().catch((e) => {
|
|
@@ -3493,7 +3523,7 @@ __export(exports_urls, {
|
|
|
3493
3523
|
VERSION: () => VERSION,
|
|
3494
3524
|
URLS: () => URLS
|
|
3495
3525
|
});
|
|
3496
|
-
var URLS, VERSION = "1.0.0-alpha.
|
|
3526
|
+
var URLS, VERSION = "1.0.0-alpha.37", env;
|
|
3497
3527
|
var init_urls = __esm(() => {
|
|
3498
3528
|
URLS = {
|
|
3499
3529
|
BROKER: process.env.CLAUDEMESH_BROKER_URL ?? "wss://ic.claudemesh.com/ws",
|
|
@@ -4173,21 +4203,13 @@ async function syncToBroker(meshSlug, grants) {
|
|
|
4173
4203
|
const auth = getStoredToken();
|
|
4174
4204
|
if (!auth)
|
|
4175
4205
|
return;
|
|
4176
|
-
let userId = "";
|
|
4177
|
-
try {
|
|
4178
|
-
const payload = JSON.parse(Buffer.from(auth.session_token.split(".")[1], "base64url").toString());
|
|
4179
|
-
userId = payload.sub ?? "";
|
|
4180
|
-
} catch {
|
|
4181
|
-
return;
|
|
4182
|
-
}
|
|
4183
|
-
if (!userId)
|
|
4184
|
-
return;
|
|
4185
4206
|
try {
|
|
4186
4207
|
await request({
|
|
4187
4208
|
path: `/cli/mesh/${meshSlug}/grants`,
|
|
4188
4209
|
method: "POST",
|
|
4189
|
-
body: {
|
|
4190
|
-
baseUrl: BROKER_HTTP2
|
|
4210
|
+
body: { grants },
|
|
4211
|
+
baseUrl: BROKER_HTTP2,
|
|
4212
|
+
token: auth.session_token
|
|
4191
4213
|
});
|
|
4192
4214
|
} catch (e) {
|
|
4193
4215
|
render.warn(`broker grant sync failed — client filter still active: ${e instanceof Error ? e.message : e}`);
|
|
@@ -4216,8 +4238,11 @@ function resolveCaps(input) {
|
|
|
4216
4238
|
async function resolvePeer(meshSlug, name) {
|
|
4217
4239
|
return await withMesh({ meshSlug }, async (client) => {
|
|
4218
4240
|
const peers = await client.listPeers();
|
|
4219
|
-
const match = peers.find((p) => p.displayName === name || p.pubkey === name || p.pubkey.startsWith(name));
|
|
4220
|
-
|
|
4241
|
+
const match = peers.find((p) => p.displayName === name || p.pubkey === name || p.pubkey.startsWith(name) || p.memberPubkey === name || p.memberPubkey && p.memberPubkey.startsWith(name));
|
|
4242
|
+
if (!match)
|
|
4243
|
+
return null;
|
|
4244
|
+
const key = match.memberPubkey ?? match.pubkey;
|
|
4245
|
+
return { displayName: match.displayName, pubkey: key };
|
|
4221
4246
|
});
|
|
4222
4247
|
}
|
|
4223
4248
|
function pickMesh2(slug) {
|
|
@@ -6532,4 +6557,4 @@ startMcpServer().catch((err) => {
|
|
|
6532
6557
|
process.exit(1);
|
|
6533
6558
|
});
|
|
6534
6559
|
|
|
6535
|
-
//# debugId=
|
|
6560
|
+
//# debugId=23BB7BF268CC536764756E2164756E21
|