@memoraone/mcp 0.1.58 → 0.1.59
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/cli.cjs +1 -1
- package/dist/gateway.cjs +27 -24
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
package/dist/gateway.cjs
CHANGED
|
@@ -14322,6 +14322,9 @@ function sendPairingGate(res, body) {
|
|
|
14322
14322
|
});
|
|
14323
14323
|
res.end(body);
|
|
14324
14324
|
}
|
|
14325
|
+
function canWriteGatewayResponse(res) {
|
|
14326
|
+
return !res.writableEnded && !res.destroyed;
|
|
14327
|
+
}
|
|
14325
14328
|
async function handleGatewayMcpAuthRequest(req, res, url, options = {}) {
|
|
14326
14329
|
if (url.pathname !== GATEWAY_MCP_PATH) return false;
|
|
14327
14330
|
const env2 = options.env ?? process.env;
|
|
@@ -14393,8 +14396,7 @@ async function handleGatewayMcpAuthRequest(req, res, url, options = {}) {
|
|
|
14393
14396
|
return true;
|
|
14394
14397
|
}
|
|
14395
14398
|
const pairing = await coordinator.ensure(parsed2.workspaceRoot);
|
|
14396
|
-
if (
|
|
14397
|
-
sendPairingGate(res, "Pairing pending");
|
|
14399
|
+
if (!canWriteGatewayResponse(res)) {
|
|
14398
14400
|
return true;
|
|
14399
14401
|
}
|
|
14400
14402
|
if (pairing.status === "failed") {
|
|
@@ -14434,6 +14436,9 @@ async function handleGatewayMcpAuthRequest(req, res, url, options = {}) {
|
|
|
14434
14436
|
);
|
|
14435
14437
|
return true;
|
|
14436
14438
|
} catch {
|
|
14439
|
+
if (!canWriteGatewayResponse(res)) {
|
|
14440
|
+
return true;
|
|
14441
|
+
}
|
|
14437
14442
|
sendUnauthorized(res, env2, parsed2.workspaceRoot);
|
|
14438
14443
|
return true;
|
|
14439
14444
|
}
|
|
@@ -14486,13 +14491,19 @@ function createGatewayUnboundPairingCoordinator(options = {}) {
|
|
|
14486
14491
|
const openUrl = options.openUrl ?? ((url) => openUrlInBrowser(url));
|
|
14487
14492
|
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS2;
|
|
14488
14493
|
const apiUrl = (options.apiUrl ?? config2.apiUrl).replace(/\/+$/, "");
|
|
14494
|
+
function settleLatch(key, entry, status) {
|
|
14495
|
+
if (entry.status !== "pending") return;
|
|
14496
|
+
entry.status = status;
|
|
14497
|
+
entry.settle(status);
|
|
14498
|
+
latches.delete(key);
|
|
14499
|
+
}
|
|
14489
14500
|
async function pollInBackground(key, session, entry) {
|
|
14490
14501
|
for (; ; ) {
|
|
14491
14502
|
let result;
|
|
14492
14503
|
try {
|
|
14493
14504
|
result = await session.poll();
|
|
14494
14505
|
} catch {
|
|
14495
|
-
entry
|
|
14506
|
+
settleLatch(key, entry, "failed");
|
|
14496
14507
|
return;
|
|
14497
14508
|
}
|
|
14498
14509
|
if (result.status === "pending") {
|
|
@@ -14500,15 +14511,14 @@ function createGatewayUnboundPairingCoordinator(options = {}) {
|
|
|
14500
14511
|
continue;
|
|
14501
14512
|
}
|
|
14502
14513
|
if (result.status === "ready") {
|
|
14503
|
-
entry
|
|
14504
|
-
latches.delete(key);
|
|
14514
|
+
settleLatch(key, entry, "ready");
|
|
14505
14515
|
return;
|
|
14506
14516
|
}
|
|
14507
14517
|
if (result.status === "backend_failure" && result.operation === "poll") {
|
|
14508
14518
|
await delay3(pollIntervalMs);
|
|
14509
14519
|
continue;
|
|
14510
14520
|
}
|
|
14511
|
-
entry
|
|
14521
|
+
settleLatch(key, entry, "failed");
|
|
14512
14522
|
return;
|
|
14513
14523
|
}
|
|
14514
14524
|
}
|
|
@@ -14530,18 +14540,16 @@ function createGatewayUnboundPairingCoordinator(options = {}) {
|
|
|
14530
14540
|
try {
|
|
14531
14541
|
await openUrl(authorizationUrl);
|
|
14532
14542
|
} catch {
|
|
14533
|
-
entry
|
|
14543
|
+
settleLatch(key, entry, "failed");
|
|
14534
14544
|
return;
|
|
14535
14545
|
}
|
|
14536
14546
|
} else {
|
|
14537
|
-
entry
|
|
14547
|
+
settleLatch(key, entry, "failed");
|
|
14538
14548
|
return;
|
|
14539
14549
|
}
|
|
14540
|
-
|
|
14541
|
-
void pollInBackground(key, session, entry);
|
|
14542
|
-
});
|
|
14550
|
+
void pollInBackground(key, session, entry);
|
|
14543
14551
|
} catch {
|
|
14544
|
-
entry
|
|
14552
|
+
settleLatch(key, entry, "failed");
|
|
14545
14553
|
}
|
|
14546
14554
|
}
|
|
14547
14555
|
return {
|
|
@@ -14549,21 +14557,16 @@ function createGatewayUnboundPairingCoordinator(options = {}) {
|
|
|
14549
14557
|
const key = path51.resolve(workspaceRoot);
|
|
14550
14558
|
const existing = latches.get(key);
|
|
14551
14559
|
if (existing) {
|
|
14552
|
-
await existing.
|
|
14553
|
-
return { status: existing.status };
|
|
14560
|
+
return { status: await existing.settled };
|
|
14554
14561
|
}
|
|
14555
|
-
let
|
|
14556
|
-
const
|
|
14557
|
-
|
|
14562
|
+
let settle;
|
|
14563
|
+
const settled = new Promise((resolve47) => {
|
|
14564
|
+
settle = resolve47;
|
|
14558
14565
|
});
|
|
14559
|
-
const entry = { status: "pending",
|
|
14566
|
+
const entry = { status: "pending", settled, settle };
|
|
14560
14567
|
latches.set(key, entry);
|
|
14561
|
-
|
|
14562
|
-
|
|
14563
|
-
} finally {
|
|
14564
|
-
resolveStart();
|
|
14565
|
-
}
|
|
14566
|
-
return { status: entry.status };
|
|
14568
|
+
void startPairing(key, entry);
|
|
14569
|
+
return { status: await entry.settled };
|
|
14567
14570
|
}
|
|
14568
14571
|
};
|
|
14569
14572
|
}
|