@langlink/memoq-mcp 0.2.1 → 0.2.2
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/bin/MemoQ.Bridge.Helper.exe +0 -0
- package/dist/index.js +304 -130
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2985,7 +2985,7 @@ var require_compile = __commonJS({
|
|
|
2985
2985
|
const schOrFunc = root.refs[ref];
|
|
2986
2986
|
if (schOrFunc)
|
|
2987
2987
|
return schOrFunc;
|
|
2988
|
-
let _sch =
|
|
2988
|
+
let _sch = resolve6.call(this, root, ref);
|
|
2989
2989
|
if (_sch === void 0) {
|
|
2990
2990
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
2991
2991
|
const { schemaId } = this.opts;
|
|
@@ -3012,7 +3012,7 @@ var require_compile = __commonJS({
|
|
|
3012
3012
|
function sameSchemaEnv(s1, s2) {
|
|
3013
3013
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
3014
3014
|
}
|
|
3015
|
-
function
|
|
3015
|
+
function resolve6(root, ref) {
|
|
3016
3016
|
let sch;
|
|
3017
3017
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
3018
3018
|
ref = sch;
|
|
@@ -3876,7 +3876,7 @@ var require_fast_uri = __commonJS({
|
|
|
3876
3876
|
}
|
|
3877
3877
|
return uri;
|
|
3878
3878
|
}
|
|
3879
|
-
function
|
|
3879
|
+
function resolve6(baseURI, relativeURI, options) {
|
|
3880
3880
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
3881
3881
|
const {
|
|
3882
3882
|
parsed: baseParsed,
|
|
@@ -4267,7 +4267,7 @@ var require_fast_uri = __commonJS({
|
|
|
4267
4267
|
var fastUri = {
|
|
4268
4268
|
SCHEMES,
|
|
4269
4269
|
normalize,
|
|
4270
|
-
resolve:
|
|
4270
|
+
resolve: resolve6,
|
|
4271
4271
|
resolveComponent,
|
|
4272
4272
|
equal,
|
|
4273
4273
|
serialize,
|
|
@@ -7258,7 +7258,7 @@ var require_dist = __commonJS({
|
|
|
7258
7258
|
|
|
7259
7259
|
// packages/memoq-mcp/src/server.ts
|
|
7260
7260
|
import { realpathSync } from "node:fs";
|
|
7261
|
-
import { dirname as
|
|
7261
|
+
import { dirname as dirname7, resolve as resolve5 } from "node:path";
|
|
7262
7262
|
import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
|
|
7263
7263
|
|
|
7264
7264
|
// node_modules/.pnpm/zod@4.6.7/node_modules/zod/v3/helpers/util.js
|
|
@@ -14510,7 +14510,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
14510
14510
|
var NONE = 0;
|
|
14511
14511
|
var ASSUMED = 1;
|
|
14512
14512
|
var PROVEN = 2;
|
|
14513
|
-
function isRecursive(inst, stack,
|
|
14513
|
+
function isRecursive(inst, stack, resolve6) {
|
|
14514
14514
|
const cached2 = recursive.get(inst);
|
|
14515
14515
|
if (cached2 !== void 0)
|
|
14516
14516
|
return cached2 ? PROVEN : NONE;
|
|
@@ -14520,7 +14520,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
14520
14520
|
let result = NONE;
|
|
14521
14521
|
const check = (child) => {
|
|
14522
14522
|
if (result !== PROVEN && child?._zod) {
|
|
14523
|
-
const answer = isRecursive(child, stack,
|
|
14523
|
+
const answer = isRecursive(child, stack, resolve6);
|
|
14524
14524
|
if (answer > result)
|
|
14525
14525
|
result = answer;
|
|
14526
14526
|
}
|
|
@@ -14531,7 +14531,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
14531
14531
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
14532
14532
|
if (spread && !desc.enumerable)
|
|
14533
14533
|
continue;
|
|
14534
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
14534
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve6) : NONE;
|
|
14535
14535
|
if (child > answer)
|
|
14536
14536
|
answer = child;
|
|
14537
14537
|
}
|
|
@@ -14595,7 +14595,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
14595
14595
|
break;
|
|
14596
14596
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
14597
14597
|
case "lazy": {
|
|
14598
|
-
const inner = def._cachedInner ?? (
|
|
14598
|
+
const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
|
|
14599
14599
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
14600
14600
|
break;
|
|
14601
14601
|
}
|
|
@@ -21381,7 +21381,7 @@ var Protocol = class {
|
|
|
21381
21381
|
return;
|
|
21382
21382
|
}
|
|
21383
21383
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
21384
|
-
await new Promise((
|
|
21384
|
+
await new Promise((resolve6) => setTimeout(resolve6, pollInterval));
|
|
21385
21385
|
options?.signal?.throwIfAborted();
|
|
21386
21386
|
}
|
|
21387
21387
|
} catch (error2) {
|
|
@@ -21398,7 +21398,7 @@ var Protocol = class {
|
|
|
21398
21398
|
*/
|
|
21399
21399
|
request(request, resultSchema, options) {
|
|
21400
21400
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
21401
|
-
return new Promise((
|
|
21401
|
+
return new Promise((resolve6, reject) => {
|
|
21402
21402
|
const earlyReject = (error2) => {
|
|
21403
21403
|
reject(error2);
|
|
21404
21404
|
};
|
|
@@ -21476,7 +21476,7 @@ var Protocol = class {
|
|
|
21476
21476
|
if (!parseResult.success) {
|
|
21477
21477
|
reject(parseResult.error);
|
|
21478
21478
|
} else {
|
|
21479
|
-
|
|
21479
|
+
resolve6(parseResult.data);
|
|
21480
21480
|
}
|
|
21481
21481
|
} catch (error2) {
|
|
21482
21482
|
reject(error2);
|
|
@@ -21738,12 +21738,12 @@ var Protocol = class {
|
|
|
21738
21738
|
}
|
|
21739
21739
|
} catch {
|
|
21740
21740
|
}
|
|
21741
|
-
return new Promise((
|
|
21741
|
+
return new Promise((resolve6, reject) => {
|
|
21742
21742
|
if (signal.aborted) {
|
|
21743
21743
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
21744
21744
|
return;
|
|
21745
21745
|
}
|
|
21746
|
-
const timeoutId = setTimeout(
|
|
21746
|
+
const timeoutId = setTimeout(resolve6, interval);
|
|
21747
21747
|
signal.addEventListener("abort", () => {
|
|
21748
21748
|
clearTimeout(timeoutId);
|
|
21749
21749
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -22883,7 +22883,7 @@ var McpServer = class {
|
|
|
22883
22883
|
let task = createTaskResult.task;
|
|
22884
22884
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
22885
22885
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
22886
|
-
await new Promise((
|
|
22886
|
+
await new Promise((resolve6) => setTimeout(resolve6, pollInterval));
|
|
22887
22887
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
22888
22888
|
if (!updatedTask) {
|
|
22889
22889
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -23547,12 +23547,12 @@ var StdioServerTransport = class {
|
|
|
23547
23547
|
this.onclose?.();
|
|
23548
23548
|
}
|
|
23549
23549
|
send(message) {
|
|
23550
|
-
return new Promise((
|
|
23550
|
+
return new Promise((resolve6) => {
|
|
23551
23551
|
const json2 = serializeMessage(message);
|
|
23552
23552
|
if (this._stdout.write(json2)) {
|
|
23553
|
-
|
|
23553
|
+
resolve6();
|
|
23554
23554
|
} else {
|
|
23555
|
-
this._stdout.once("drain",
|
|
23555
|
+
this._stdout.once("drain", resolve6);
|
|
23556
23556
|
}
|
|
23557
23557
|
});
|
|
23558
23558
|
}
|
|
@@ -24378,18 +24378,18 @@ function createPreviewClient(options = {}) {
|
|
|
24378
24378
|
}
|
|
24379
24379
|
const id = randomUUID();
|
|
24380
24380
|
const message = JSON.stringify({ ...payload, id }) + "\n";
|
|
24381
|
-
return new Promise((
|
|
24381
|
+
return new Promise((resolve6) => {
|
|
24382
24382
|
const timer = setTimeout(() => {
|
|
24383
24383
|
pendingAcks.delete(id);
|
|
24384
|
-
|
|
24384
|
+
resolve6({ ok: false, error: `Preview helper command timed out (${String(payload.type ?? "unknown")}).` });
|
|
24385
24385
|
}, timeoutMs);
|
|
24386
|
-
pendingAcks.set(id, { resolve:
|
|
24386
|
+
pendingAcks.set(id, { resolve: resolve6, timer });
|
|
24387
24387
|
try {
|
|
24388
24388
|
child.stdin.write(message, "utf8");
|
|
24389
24389
|
} catch (error2) {
|
|
24390
24390
|
clearTimeout(timer);
|
|
24391
24391
|
pendingAcks.delete(id);
|
|
24392
|
-
|
|
24392
|
+
resolve6({ ok: false, error: error2 instanceof Error ? error2.message : String(error2) });
|
|
24393
24393
|
}
|
|
24394
24394
|
});
|
|
24395
24395
|
}
|
|
@@ -24527,9 +24527,9 @@ function createPreviewClient(options = {}) {
|
|
|
24527
24527
|
const settleMs = Math.max(0, Math.min(500, query.settleMs ?? 80));
|
|
24528
24528
|
if (settleMs > 0 && lastEventAtMs > 0 && Date.now() - lastEventAtMs < settleMs) {
|
|
24529
24529
|
const firstRev = revision;
|
|
24530
|
-
await new Promise((
|
|
24530
|
+
await new Promise((resolve6) => setTimeout(resolve6, settleMs));
|
|
24531
24531
|
if (revision !== firstRev) {
|
|
24532
|
-
await new Promise((
|
|
24532
|
+
await new Promise((resolve6) => setTimeout(resolve6, settleMs));
|
|
24533
24533
|
}
|
|
24534
24534
|
}
|
|
24535
24535
|
const doc = resolveDocument();
|
|
@@ -29153,7 +29153,8 @@ async function createMtGateway(options) {
|
|
|
29153
29153
|
const productName = options.productName ?? BRIDGE_PRODUCT_NAME;
|
|
29154
29154
|
const desktopVersion = options.desktopVersion ?? BRIDGE_VERSION;
|
|
29155
29155
|
const controlToken = options.controlToken ?? randomUUID3().replace(/-/gu, "");
|
|
29156
|
-
const
|
|
29156
|
+
const candidateReviewToken = typeof options.reviewToken === "string" ? options.reviewToken.trim() : "";
|
|
29157
|
+
const reviewToken = candidateReviewToken.length >= 24 && candidateReviewToken !== controlToken ? candidateReviewToken : randomBytes(24).toString("hex");
|
|
29157
29158
|
const aggregateJobs = /* @__PURE__ */ new Map();
|
|
29158
29159
|
function getReviewUrl() {
|
|
29159
29160
|
return `http://${host}:${actualPort}/review?token=${reviewToken}`;
|
|
@@ -29753,7 +29754,13 @@ async function createMtGateway(options) {
|
|
|
29753
29754
|
if (method === "GET" && pathname === "/review") {
|
|
29754
29755
|
const provided = url.searchParams.get("token") ?? "";
|
|
29755
29756
|
if (!safeTokenEquals(provided, reviewToken)) {
|
|
29756
|
-
|
|
29757
|
+
const errorCsp = "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'; base-uri 'none'";
|
|
29758
|
+
sendHtml(
|
|
29759
|
+
response,
|
|
29760
|
+
401,
|
|
29761
|
+
`<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><title>\u5BA1\u6821\u5DE5\u4F5C\u53F0\u94FE\u63A5\u5DF2\u5931\u6548</title><style>body{font-family:system-ui,-apple-system,sans-serif;max-width:560px;margin:64px auto;padding:24px;line-height:1.6;color:#1f2328}code{background:#f3f4f6;padding:2px 6px;border-radius:4px}</style></head><body><h2>\u5BA1\u6821\u5DE5\u4F5C\u53F0\u94FE\u63A5\u5DF2\u8FC7\u671F\u6216\u65E0\u6548</h2><p>\u5F53\u524D\u643A\u5E26\u7684\u8BBF\u95EE\u51ED\u8BC1\u4E0E\u6B63\u5728\u8FD0\u884C\u7684\u672C\u5730 memoQ \u6865\u63A5\u670D\u52A1\u4E0D\u5339\u914D\u3002</p><p>\u8BF7\u5728 AI \u5BF9\u8BDD\u4E2D\u91CD\u65B0\u8C03\u7528 <code>memoq_open_review</code> \u83B7\u53D6\u6700\u65B0\u5DE5\u4F5C\u53F0\u94FE\u63A5\u540E\u518D\u6253\u5F00\u3002</p><hr><p>Review Workbench token is missing, rotated, or invalid. Call <code>memoq_open_review</code> in your agent session to obtain the current link.</p></body></html>`,
|
|
29762
|
+
errorCsp
|
|
29763
|
+
);
|
|
29757
29764
|
return;
|
|
29758
29765
|
}
|
|
29759
29766
|
const nonce = randomBytes(16).toString("base64");
|
|
@@ -30128,14 +30135,14 @@ async function createMtGateway(options) {
|
|
|
30128
30135
|
}
|
|
30129
30136
|
sendJson(response, 404, { error: `Unknown control route: ${pathname}` });
|
|
30130
30137
|
}
|
|
30131
|
-
await new Promise((
|
|
30138
|
+
await new Promise((resolve6, reject) => {
|
|
30132
30139
|
const onError = (error2) => {
|
|
30133
30140
|
server.off("listening", onListening);
|
|
30134
30141
|
reject(error2);
|
|
30135
30142
|
};
|
|
30136
30143
|
const onListening = () => {
|
|
30137
30144
|
server.off("error", onError);
|
|
30138
|
-
|
|
30145
|
+
resolve6();
|
|
30139
30146
|
};
|
|
30140
30147
|
server.once("error", onError);
|
|
30141
30148
|
server.once("listening", onListening);
|
|
@@ -30155,8 +30162,8 @@ async function createMtGateway(options) {
|
|
|
30155
30162
|
reviewUrl: getReviewUrl(),
|
|
30156
30163
|
close: () => {
|
|
30157
30164
|
options.stagingStore.flush?.();
|
|
30158
|
-
return new Promise((
|
|
30159
|
-
server.close((error2) => error2 ? reject(error2) :
|
|
30165
|
+
return new Promise((resolve6, reject) => {
|
|
30166
|
+
server.close((error2) => error2 ? reject(error2) : resolve6());
|
|
30160
30167
|
});
|
|
30161
30168
|
},
|
|
30162
30169
|
handleTranslateForTest: processTranslate
|
|
@@ -30560,13 +30567,14 @@ async function uninstallPluginWithHelper(options) {
|
|
|
30560
30567
|
|
|
30561
30568
|
// packages/memoq-bridge/src/setup-page.ts
|
|
30562
30569
|
import { spawn as spawn2 } from "node:child_process";
|
|
30563
|
-
import { randomBytes as
|
|
30570
|
+
import { randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
30564
30571
|
import { existsSync as existsSync7, mkdirSync as mkdirSync5 } from "node:fs";
|
|
30565
30572
|
import { createServer as createServer2 } from "node:http";
|
|
30566
30573
|
import { dirname as dirname4 } from "node:path";
|
|
30567
30574
|
|
|
30568
30575
|
// packages/memoq-bridge/src/daemon.ts
|
|
30569
|
-
import {
|
|
30576
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
30577
|
+
import { chmodSync, existsSync as existsSync6, readFileSync as readFileSync6, rmSync as rmSync3 } from "node:fs";
|
|
30570
30578
|
import { join as join7 } from "node:path";
|
|
30571
30579
|
async function probeGatewayPort(port = DEFAULT_PORT, host = DEFAULT_HOST, timeoutMs = 1500) {
|
|
30572
30580
|
const url = `http://${host}:${port}`;
|
|
@@ -30605,6 +30613,31 @@ async function probeGatewayPort(port = DEFAULT_PORT, host = DEFAULT_HOST, timeou
|
|
|
30605
30613
|
};
|
|
30606
30614
|
}
|
|
30607
30615
|
}
|
|
30616
|
+
function loadOrCreateReviewToken(dataDir = defaultBridgeDataDir(), excludeToken) {
|
|
30617
|
+
const tokenPath = join7(dataDir, "review-token.json");
|
|
30618
|
+
if (existsSync6(tokenPath)) {
|
|
30619
|
+
try {
|
|
30620
|
+
const parsed = JSON.parse(readFileSync6(tokenPath, "utf8"));
|
|
30621
|
+
const candidate = typeof parsed?.token === "string" ? parsed.token.trim() : "";
|
|
30622
|
+
if (/^[0-9a-f]{48,}$/iu.test(candidate) && candidate !== excludeToken) {
|
|
30623
|
+
return candidate;
|
|
30624
|
+
}
|
|
30625
|
+
} catch {
|
|
30626
|
+
}
|
|
30627
|
+
}
|
|
30628
|
+
let token = randomBytes2(24).toString("hex");
|
|
30629
|
+
while (token === excludeToken) {
|
|
30630
|
+
token = randomBytes2(24).toString("hex");
|
|
30631
|
+
}
|
|
30632
|
+
atomicWriteTextSync(tokenPath, JSON.stringify({ token }, null, 2));
|
|
30633
|
+
if (process.platform !== "win32") {
|
|
30634
|
+
try {
|
|
30635
|
+
chmodSync(tokenPath, 384);
|
|
30636
|
+
} catch {
|
|
30637
|
+
}
|
|
30638
|
+
}
|
|
30639
|
+
return token;
|
|
30640
|
+
}
|
|
30608
30641
|
function getDaemonRecordPath(dataDir = defaultBridgeDataDir()) {
|
|
30609
30642
|
return join7(dataDir, "daemon.json");
|
|
30610
30643
|
}
|
|
@@ -30788,10 +30821,13 @@ async function startBridgeRuntime(options = {}) {
|
|
|
30788
30821
|
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
30789
30822
|
...options.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.helperExecutablePath }
|
|
30790
30823
|
}));
|
|
30824
|
+
const shouldWriteDaemon = options.writeDaemonFile !== false;
|
|
30825
|
+
const persistedReviewToken = options.reviewToken ?? (shouldWriteDaemon ? loadOrCreateReviewToken(dataDir) : void 0);
|
|
30791
30826
|
const gateway = await createMtGateway({
|
|
30792
30827
|
host,
|
|
30793
30828
|
port: bindPort,
|
|
30794
30829
|
mode: options.mode ?? "staging",
|
|
30830
|
+
...persistedReviewToken ? { reviewToken: persistedReviewToken } : {},
|
|
30795
30831
|
stagingStore,
|
|
30796
30832
|
previewClient,
|
|
30797
30833
|
getIntegrationStatus: integrationFn,
|
|
@@ -30800,7 +30836,6 @@ async function startBridgeRuntime(options = {}) {
|
|
|
30800
30836
|
...options.getLiveConfig === void 0 ? {} : { getLiveConfig: options.getLiveConfig },
|
|
30801
30837
|
...options.updateLiveConfig === void 0 ? {} : { updateLiveConfig: options.updateLiveConfig }
|
|
30802
30838
|
});
|
|
30803
|
-
const shouldWriteDaemon = options.writeDaemonFile !== false;
|
|
30804
30839
|
if (shouldWriteDaemon) {
|
|
30805
30840
|
writeDaemonRecord(
|
|
30806
30841
|
{
|
|
@@ -31093,7 +31128,7 @@ function renderSetupHtml(nonce, token, initialStatus) {
|
|
|
31093
31128
|
async function startSetupServer(options = {}) {
|
|
31094
31129
|
const host = options.host ?? DEFAULT_HOST;
|
|
31095
31130
|
const requestedPort = options.port ?? 0;
|
|
31096
|
-
const token =
|
|
31131
|
+
const token = randomBytes3(24).toString("hex");
|
|
31097
31132
|
const gatewayPort = options.gatewayPort ?? DEFAULT_PORT;
|
|
31098
31133
|
const probeGateway = options.probeGateway ?? ((p) => probeGatewayPort(p ?? gatewayPort));
|
|
31099
31134
|
const resolveDll = options.resolveDll ?? resolvePluginDllAsset;
|
|
@@ -31132,7 +31167,7 @@ async function startSetupServer(options = {}) {
|
|
|
31132
31167
|
return;
|
|
31133
31168
|
}
|
|
31134
31169
|
if (method === "GET" && (url.pathname === "/" || url.pathname === "/setup")) {
|
|
31135
|
-
const nonce =
|
|
31170
|
+
const nonce = randomBytes3(16).toString("base64");
|
|
31136
31171
|
response.setHeader(
|
|
31137
31172
|
"Content-Security-Policy",
|
|
31138
31173
|
`default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none';`
|
|
@@ -31211,14 +31246,14 @@ async function startSetupServer(options = {}) {
|
|
|
31211
31246
|
sendJson2(response, 500, { error: error2 instanceof Error ? error2.message : String(error2) });
|
|
31212
31247
|
});
|
|
31213
31248
|
});
|
|
31214
|
-
await new Promise((
|
|
31249
|
+
await new Promise((resolve6, reject) => {
|
|
31215
31250
|
const onError = (error2) => {
|
|
31216
31251
|
server.off("listening", onListening);
|
|
31217
31252
|
reject(error2);
|
|
31218
31253
|
};
|
|
31219
31254
|
const onListening = () => {
|
|
31220
31255
|
server.off("error", onError);
|
|
31221
|
-
|
|
31256
|
+
resolve6();
|
|
31222
31257
|
};
|
|
31223
31258
|
server.once("error", onError);
|
|
31224
31259
|
server.once("listening", onListening);
|
|
@@ -31231,11 +31266,11 @@ async function startSetupServer(options = {}) {
|
|
|
31231
31266
|
actualPort = addr.port;
|
|
31232
31267
|
expectedHost = `${host}:${actualPort}`;
|
|
31233
31268
|
expectedOrigin = `http://${expectedHost}`;
|
|
31234
|
-
const close = () => new Promise((
|
|
31269
|
+
const close = () => new Promise((resolve6) => {
|
|
31235
31270
|
clearTimeout(idleTimer);
|
|
31236
31271
|
server.close(() => {
|
|
31237
31272
|
options.onClose?.();
|
|
31238
|
-
|
|
31273
|
+
resolve6();
|
|
31239
31274
|
});
|
|
31240
31275
|
});
|
|
31241
31276
|
idleTimer = setTimeout(() => {
|
|
@@ -31407,35 +31442,156 @@ async function writeRecipe(recipe) {
|
|
|
31407
31442
|
}
|
|
31408
31443
|
|
|
31409
31444
|
// packages/memoq-mcp/src/daemon-launcher.ts
|
|
31410
|
-
import { spawn as spawn3 } from "node:child_process";
|
|
31445
|
+
import { execFile as execFile2, spawn as spawn3 } from "node:child_process";
|
|
31446
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
31447
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync7, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
31448
|
+
import { dirname as dirname6, join as join9, resolve as resolve4 } from "node:path";
|
|
31449
|
+
import { promisify as promisify2 } from "node:util";
|
|
31450
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
31411
31451
|
var MEMOQ_BRIDGE_DAEMON_FLAG = "--memoq-bridge-daemon";
|
|
31412
31452
|
var MEMOQ_SETUP_WORKER_FLAG = "--memoq-setup-worker";
|
|
31413
|
-
var WORKER_START_TIMEOUT_MS =
|
|
31414
|
-
|
|
31415
|
-
|
|
31416
|
-
|
|
31417
|
-
|
|
31418
|
-
|
|
31419
|
-
|
|
31420
|
-
|
|
31421
|
-
|
|
31422
|
-
|
|
31423
|
-
|
|
31424
|
-
|
|
31425
|
-
|
|
31426
|
-
|
|
31427
|
-
|
|
31428
|
-
|
|
31429
|
-
|
|
31430
|
-
|
|
31431
|
-
|
|
31432
|
-
|
|
31433
|
-
|
|
31434
|
-
|
|
31435
|
-
|
|
31436
|
-
|
|
31437
|
-
|
|
31453
|
+
var WORKER_START_TIMEOUT_MS = 15e3;
|
|
31454
|
+
var READY_POLL_INTERVAL_MS = 50;
|
|
31455
|
+
function parseWorkerCliArgs(argv) {
|
|
31456
|
+
const result = {};
|
|
31457
|
+
for (let i = 0; i < argv.length - 1; i += 1) {
|
|
31458
|
+
const flag = argv[i];
|
|
31459
|
+
const value = argv[i + 1];
|
|
31460
|
+
if (value === void 0) continue;
|
|
31461
|
+
if (flag === "--data-dir") {
|
|
31462
|
+
result.dataDir = value;
|
|
31463
|
+
i += 1;
|
|
31464
|
+
} else if (flag === "--ready-file") {
|
|
31465
|
+
result.readyFile = value;
|
|
31466
|
+
i += 1;
|
|
31467
|
+
} else if (flag === "--port") {
|
|
31468
|
+
const parsed = Number(value);
|
|
31469
|
+
if (Number.isInteger(parsed) && parsed >= 0 && parsed <= 65535) {
|
|
31470
|
+
result.port = parsed;
|
|
31471
|
+
}
|
|
31472
|
+
i += 1;
|
|
31473
|
+
}
|
|
31474
|
+
}
|
|
31475
|
+
return result;
|
|
31476
|
+
}
|
|
31477
|
+
function parseConfiguredBridgePort() {
|
|
31478
|
+
const raw = process.env.MEMOQ_BRIDGE_PORT?.trim();
|
|
31479
|
+
if (!raw) return void 0;
|
|
31480
|
+
const parsed = Number(raw);
|
|
31481
|
+
if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
|
|
31482
|
+
return void 0;
|
|
31483
|
+
}
|
|
31484
|
+
return parsed;
|
|
31485
|
+
}
|
|
31486
|
+
async function trySpawnViaWindowsWmi(entrypoint, workerArgs, dataDir) {
|
|
31487
|
+
if (process.platform !== "win32") return false;
|
|
31488
|
+
const helperPath = ensureRunnableHelperBinary({
|
|
31489
|
+
dataDir,
|
|
31490
|
+
packageRoot: resolve4(dirname6(entrypoint), "..")
|
|
31438
31491
|
});
|
|
31492
|
+
if (!helperPath) return false;
|
|
31493
|
+
const specFile = join9(dataDir, `launch-${randomUUID6()}.json`);
|
|
31494
|
+
try {
|
|
31495
|
+
mkdirSync6(dataDir, { recursive: true });
|
|
31496
|
+
writeFileSync4(
|
|
31497
|
+
specFile,
|
|
31498
|
+
JSON.stringify({
|
|
31499
|
+
executable: process.execPath,
|
|
31500
|
+
args: workerArgs,
|
|
31501
|
+
workingDirectory: dirname6(entrypoint)
|
|
31502
|
+
}),
|
|
31503
|
+
"utf8"
|
|
31504
|
+
);
|
|
31505
|
+
const { stdout } = await execFileAsync2(
|
|
31506
|
+
helperPath,
|
|
31507
|
+
["--spawn-detached", "--spec-file", specFile],
|
|
31508
|
+
{ timeout: 1e4, windowsHide: true }
|
|
31509
|
+
);
|
|
31510
|
+
const parsed = JSON.parse(stdout.trim());
|
|
31511
|
+
return parsed.ok === true && typeof parsed.pid === "number" && parsed.pid > 0;
|
|
31512
|
+
} catch {
|
|
31513
|
+
return false;
|
|
31514
|
+
} finally {
|
|
31515
|
+
try {
|
|
31516
|
+
rmSync4(specFile, { force: true });
|
|
31517
|
+
} catch {
|
|
31518
|
+
}
|
|
31519
|
+
}
|
|
31520
|
+
}
|
|
31521
|
+
function spawnViaNodeDetached(entrypoint, workerArgs, dataDir) {
|
|
31522
|
+
const child = spawn3(process.execPath, workerArgs, {
|
|
31523
|
+
detached: true,
|
|
31524
|
+
windowsHide: true,
|
|
31525
|
+
stdio: "ignore",
|
|
31526
|
+
cwd: dirname6(entrypoint),
|
|
31527
|
+
env: { ...process.env, MEMOQ_BRIDGE_DATA_DIR: dataDir }
|
|
31528
|
+
});
|
|
31529
|
+
child.unref();
|
|
31530
|
+
}
|
|
31531
|
+
async function spawnDetachedWorker(entrypoint, flag, options) {
|
|
31532
|
+
mkdirSync6(options.dataDir, { recursive: true });
|
|
31533
|
+
const readyFile = join9(options.dataDir, `ready-${randomUUID6()}.json`);
|
|
31534
|
+
const workerArgs = [
|
|
31535
|
+
entrypoint,
|
|
31536
|
+
flag,
|
|
31537
|
+
"--data-dir",
|
|
31538
|
+
options.dataDir,
|
|
31539
|
+
"--ready-file",
|
|
31540
|
+
readyFile,
|
|
31541
|
+
...options.port === void 0 ? [] : ["--port", String(options.port)]
|
|
31542
|
+
];
|
|
31543
|
+
const launchedByWmi = await trySpawnViaWindowsWmi(entrypoint, workerArgs, options.dataDir);
|
|
31544
|
+
if (!launchedByWmi) {
|
|
31545
|
+
spawnViaNodeDetached(entrypoint, workerArgs, options.dataDir);
|
|
31546
|
+
}
|
|
31547
|
+
try {
|
|
31548
|
+
const deadline = Date.now() + WORKER_START_TIMEOUT_MS;
|
|
31549
|
+
while (Date.now() < deadline) {
|
|
31550
|
+
if (existsSync8(readyFile)) {
|
|
31551
|
+
try {
|
|
31552
|
+
const parsed = JSON.parse(readFileSync7(readyFile, "utf8"));
|
|
31553
|
+
if (parsed.ok === true && parsed.payload !== void 0) {
|
|
31554
|
+
return parsed.payload;
|
|
31555
|
+
}
|
|
31556
|
+
if (parsed.ok === false) {
|
|
31557
|
+
throw new Error(parsed.error || `Unable to start memoQ worker (${flag}).`);
|
|
31558
|
+
}
|
|
31559
|
+
} catch (error2) {
|
|
31560
|
+
if (!(error2 instanceof SyntaxError)) {
|
|
31561
|
+
throw error2;
|
|
31562
|
+
}
|
|
31563
|
+
}
|
|
31564
|
+
}
|
|
31565
|
+
await new Promise((res) => setTimeout(res, READY_POLL_INTERVAL_MS));
|
|
31566
|
+
}
|
|
31567
|
+
throw new Error(`memoQ worker timed out (${flag}).`);
|
|
31568
|
+
} finally {
|
|
31569
|
+
try {
|
|
31570
|
+
rmSync4(readyFile, { force: true });
|
|
31571
|
+
} catch {
|
|
31572
|
+
}
|
|
31573
|
+
}
|
|
31574
|
+
}
|
|
31575
|
+
async function publishWorkerOutcome(readyFile, outcome) {
|
|
31576
|
+
if (readyFile) {
|
|
31577
|
+
atomicWriteTextSync(readyFile, JSON.stringify(outcome));
|
|
31578
|
+
return;
|
|
31579
|
+
}
|
|
31580
|
+
if (!process.send || !process.connected) {
|
|
31581
|
+
return;
|
|
31582
|
+
}
|
|
31583
|
+
if (!outcome.ok) {
|
|
31584
|
+
return;
|
|
31585
|
+
}
|
|
31586
|
+
try {
|
|
31587
|
+
await new Promise((resolveSend, rejectSend) => {
|
|
31588
|
+
process.send(outcome.payload, (error2) => error2 ? rejectSend(error2) : resolveSend());
|
|
31589
|
+
});
|
|
31590
|
+
} finally {
|
|
31591
|
+
if (process.connected) {
|
|
31592
|
+
process.disconnect?.();
|
|
31593
|
+
}
|
|
31594
|
+
}
|
|
31439
31595
|
}
|
|
31440
31596
|
async function connectOrLaunchBridgeClient(entrypoint, options = {}) {
|
|
31441
31597
|
const dataDir = options.dataDir ?? defaultBridgeDataDir();
|
|
@@ -31448,94 +31604,112 @@ async function connectOrLaunchBridgeClient(entrypoint, options = {}) {
|
|
|
31448
31604
|
} catch {
|
|
31449
31605
|
}
|
|
31450
31606
|
}
|
|
31451
|
-
const
|
|
31452
|
-
|
|
31453
|
-
|
|
31454
|
-
{
|
|
31455
|
-
);
|
|
31607
|
+
const configuredPort = parseConfiguredBridgePort();
|
|
31608
|
+
const payload = await spawnDetachedWorker(entrypoint, MEMOQ_BRIDGE_DAEMON_FLAG, {
|
|
31609
|
+
dataDir,
|
|
31610
|
+
...configuredPort === void 0 ? {} : { port: configuredPort }
|
|
31611
|
+
});
|
|
31456
31612
|
if (!payload || !payload.port || !payload.controlToken) {
|
|
31457
31613
|
throw new Error("memoQ bridge daemon returned invalid connection details.");
|
|
31458
31614
|
}
|
|
31459
31615
|
return new BridgeHttpClient(`http://${payload.host}:${payload.port}`, payload.controlToken);
|
|
31460
31616
|
}
|
|
31461
31617
|
function createSetupWizardLauncher(entrypoint, options = {}) {
|
|
31462
|
-
let
|
|
31618
|
+
let cachedUrl;
|
|
31619
|
+
let inFlight;
|
|
31463
31620
|
return async () => {
|
|
31464
|
-
|
|
31465
|
-
|
|
31466
|
-
|
|
31467
|
-
|
|
31468
|
-
|
|
31621
|
+
if (cachedUrl) {
|
|
31622
|
+
try {
|
|
31623
|
+
const probe = await fetch(cachedUrl, { signal: AbortSignal.timeout(1e3) });
|
|
31624
|
+
if (probe.ok) {
|
|
31625
|
+
return cachedUrl;
|
|
31626
|
+
}
|
|
31627
|
+
} catch {
|
|
31628
|
+
cachedUrl = void 0;
|
|
31629
|
+
}
|
|
31630
|
+
}
|
|
31631
|
+
inFlight ??= spawnDetachedWorker(entrypoint, MEMOQ_SETUP_WORKER_FLAG, {
|
|
31632
|
+
dataDir: options.dataDir ?? defaultBridgeDataDir()
|
|
31633
|
+
}).then((payload) => {
|
|
31469
31634
|
if (!payload?.url || !/^http:\/\/127\.0\.0\.1:\d+\/setup\?token=/u.test(payload.url)) {
|
|
31470
|
-
child.kill();
|
|
31471
31635
|
throw new Error("Invalid setup wizard URL.");
|
|
31472
31636
|
}
|
|
31473
|
-
|
|
31474
|
-
active = void 0;
|
|
31475
|
-
});
|
|
31637
|
+
cachedUrl = payload.url;
|
|
31476
31638
|
return payload.url;
|
|
31477
|
-
}).
|
|
31478
|
-
|
|
31479
|
-
throw error2;
|
|
31639
|
+
}).finally(() => {
|
|
31640
|
+
inFlight = void 0;
|
|
31480
31641
|
});
|
|
31481
|
-
return
|
|
31642
|
+
return inFlight;
|
|
31482
31643
|
};
|
|
31483
31644
|
}
|
|
31484
|
-
async function runBridgeDaemonWorker() {
|
|
31485
|
-
|
|
31486
|
-
|
|
31645
|
+
async function runBridgeDaemonWorker(argv = process.argv.slice(2)) {
|
|
31646
|
+
const args = parseWorkerCliArgs(argv);
|
|
31647
|
+
if (!args.readyFile && (!process.send || !process.connected)) {
|
|
31648
|
+
throw new Error("memoQ bridge daemon requires --ready-file or IPC.");
|
|
31487
31649
|
}
|
|
31488
|
-
const dataDir = defaultBridgeDataDir();
|
|
31489
|
-
const runtime = await startBridgeRuntime({
|
|
31490
|
-
dataDir,
|
|
31491
|
-
ownerLabel: "memoq-mcp-daemon",
|
|
31492
|
-
mode: "staging"
|
|
31493
|
-
});
|
|
31494
|
-
const cleanup = () => {
|
|
31495
|
-
removeDaemonRecord(runtime.gateway.controlToken, dataDir);
|
|
31496
|
-
void runtime.close().finally(() => process.exit(0));
|
|
31497
|
-
};
|
|
31498
|
-
process.once("SIGINT", cleanup);
|
|
31499
|
-
process.once("SIGTERM", cleanup);
|
|
31650
|
+
const dataDir = args.dataDir ?? defaultBridgeDataDir();
|
|
31500
31651
|
try {
|
|
31501
|
-
|
|
31502
|
-
|
|
31503
|
-
|
|
31652
|
+
const runtime = await startBridgeRuntime({
|
|
31653
|
+
dataDir,
|
|
31654
|
+
...args.port === void 0 ? {} : { preferredPort: args.port },
|
|
31655
|
+
ownerLabel: "memoq-mcp-daemon",
|
|
31656
|
+
mode: "staging"
|
|
31657
|
+
});
|
|
31658
|
+
const cleanup = () => {
|
|
31659
|
+
removeDaemonRecord(runtime.gateway.controlToken, dataDir);
|
|
31660
|
+
void runtime.close().finally(() => process.exit(0));
|
|
31661
|
+
};
|
|
31662
|
+
process.once("SIGINT", cleanup);
|
|
31663
|
+
process.once("SIGTERM", cleanup);
|
|
31664
|
+
try {
|
|
31665
|
+
await publishWorkerOutcome(args.readyFile, {
|
|
31666
|
+
ok: true,
|
|
31667
|
+
payload: {
|
|
31504
31668
|
port: runtime.actualPort,
|
|
31505
31669
|
host: runtime.gateway.host,
|
|
31506
31670
|
controlToken: runtime.gateway.controlToken
|
|
31507
|
-
}
|
|
31508
|
-
|
|
31509
|
-
|
|
31510
|
-
|
|
31671
|
+
}
|
|
31672
|
+
});
|
|
31673
|
+
} catch (error2) {
|
|
31674
|
+
await runtime.close();
|
|
31675
|
+
throw error2;
|
|
31676
|
+
}
|
|
31511
31677
|
} catch (error2) {
|
|
31512
|
-
|
|
31513
|
-
|
|
31514
|
-
|
|
31515
|
-
|
|
31516
|
-
process.disconnect?.();
|
|
31678
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
31679
|
+
try {
|
|
31680
|
+
await publishWorkerOutcome(args.readyFile, { ok: false, error: message });
|
|
31681
|
+
} catch {
|
|
31517
31682
|
}
|
|
31683
|
+
throw error2;
|
|
31518
31684
|
}
|
|
31519
31685
|
}
|
|
31520
|
-
async function runSetupWorker() {
|
|
31521
|
-
|
|
31522
|
-
|
|
31686
|
+
async function runSetupWorker(argv = process.argv.slice(2)) {
|
|
31687
|
+
const args = parseWorkerCliArgs(argv);
|
|
31688
|
+
if (!args.readyFile && (!process.send || !process.connected)) {
|
|
31689
|
+
throw new Error("memoQ setup worker requires --ready-file or IPC.");
|
|
31523
31690
|
}
|
|
31524
|
-
const
|
|
31525
|
-
keepAlive: true,
|
|
31526
|
-
dataDir: defaultBridgeDataDir()
|
|
31527
|
-
});
|
|
31691
|
+
const dataDir = args.dataDir ?? defaultBridgeDataDir();
|
|
31528
31692
|
try {
|
|
31529
|
-
|
|
31530
|
-
|
|
31693
|
+
const setup = await startSetupServer({
|
|
31694
|
+
keepAlive: true,
|
|
31695
|
+
dataDir
|
|
31531
31696
|
});
|
|
31697
|
+
try {
|
|
31698
|
+
await publishWorkerOutcome(args.readyFile, {
|
|
31699
|
+
ok: true,
|
|
31700
|
+
payload: { url: setup.url }
|
|
31701
|
+
});
|
|
31702
|
+
} catch (error2) {
|
|
31703
|
+
await setup.close();
|
|
31704
|
+
throw error2;
|
|
31705
|
+
}
|
|
31532
31706
|
} catch (error2) {
|
|
31533
|
-
|
|
31534
|
-
|
|
31535
|
-
|
|
31536
|
-
|
|
31537
|
-
process.disconnect?.();
|
|
31707
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
31708
|
+
try {
|
|
31709
|
+
await publishWorkerOutcome(args.readyFile, { ok: false, error: message });
|
|
31710
|
+
} catch {
|
|
31538
31711
|
}
|
|
31712
|
+
throw error2;
|
|
31539
31713
|
}
|
|
31540
31714
|
}
|
|
31541
31715
|
|
|
@@ -31546,10 +31720,10 @@ function textResult(value) {
|
|
|
31546
31720
|
};
|
|
31547
31721
|
}
|
|
31548
31722
|
function createMemoqMcpServer(options = {}) {
|
|
31549
|
-
const server = new McpServer({ name: "langlink-memoq", version: "0.2.
|
|
31550
|
-
const here =
|
|
31723
|
+
const server = new McpServer({ name: "langlink-memoq", version: "0.2.2" });
|
|
31724
|
+
const here = dirname7(fileURLToPath2(import.meta.url));
|
|
31551
31725
|
const entrypoint = fileURLToPath2(import.meta.url);
|
|
31552
|
-
const packageRoot =
|
|
31726
|
+
const packageRoot = resolve5(here, "..");
|
|
31553
31727
|
let clientPromise;
|
|
31554
31728
|
const resolveClient = async () => {
|
|
31555
31729
|
if (options.bridgeClient) return options.bridgeClient;
|
|
@@ -31955,11 +32129,11 @@ async function runConfigCommand(args) {
|
|
|
31955
32129
|
async function main() {
|
|
31956
32130
|
const command = process.argv[2];
|
|
31957
32131
|
if (command === MEMOQ_BRIDGE_DAEMON_FLAG) {
|
|
31958
|
-
await runBridgeDaemonWorker();
|
|
32132
|
+
await runBridgeDaemonWorker(process.argv.slice(3));
|
|
31959
32133
|
return;
|
|
31960
32134
|
}
|
|
31961
32135
|
if (command === MEMOQ_SETUP_WORKER_FLAG) {
|
|
31962
|
-
await runSetupWorker();
|
|
32136
|
+
await runSetupWorker(process.argv.slice(3));
|
|
31963
32137
|
return;
|
|
31964
32138
|
}
|
|
31965
32139
|
if (command === "config" || command === "setup") {
|