@langlink/memoq-mcp 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -23558,6 +23558,33 @@ var StdioServerTransport = class {
23558
23558
  }
23559
23559
  };
23560
23560
 
23561
+ // packages/memoq-mcp/package.json
23562
+ var package_default = {
23563
+ name: "@langlink/memoq-mcp",
23564
+ version: "0.2.6",
23565
+ private: true,
23566
+ type: "module",
23567
+ main: "./src/server.ts",
23568
+ bin: {
23569
+ "langlink-memoq-mcp": "./src/server.ts"
23570
+ },
23571
+ exports: {
23572
+ ".": "./src/server.ts"
23573
+ },
23574
+ dependencies: {
23575
+ "@langlink/memoq-bridge": "workspace:*",
23576
+ "@modelcontextprotocol/sdk": "^1.32.2",
23577
+ zod: "^4.6.7"
23578
+ },
23579
+ description: "LangLink memoQ connector over stdio MCP for WorkBuddy, Codex, ZCode, and Trae: live Preview read/jump, staged translations, confirmed feedback, and local setup wizard.",
23580
+ license: "MIT",
23581
+ repository: {
23582
+ type: "git",
23583
+ url: "git+https://github.com/langlink-tech/langlink-harness-toolsets.git",
23584
+ directory: "packages/memoq-mcp"
23585
+ }
23586
+ };
23587
+
23561
23588
  // packages/memoq-bridge/src/contract.ts
23562
23589
  import { homedir } from "node:os";
23563
23590
  import { join } from "node:path";
@@ -28080,6 +28107,47 @@ function escapeCsvField(value) {
28080
28107
 
28081
28108
  // packages/l10n-core/src/qa/review-data.ts
28082
28109
  import { unzipSync } from "fflate";
28110
+
28111
+ // packages/l10n-core/package.json
28112
+ var package_default2 = {
28113
+ name: "@langlink/l10n-core",
28114
+ version: "0.0.0",
28115
+ private: true,
28116
+ type: "module",
28117
+ exports: {
28118
+ ".": "./src/index.ts",
28119
+ "./assets": "./src/assets/index.ts",
28120
+ "./qa": "./src/qa/index.ts",
28121
+ "./aiqa": "./src/qa/aiqa.ts",
28122
+ "./qa-catalog": "./src/qa/catalog.ts",
28123
+ "./qa-review": "./src/qa/review-server.ts",
28124
+ "./agent-review": "./src/qa/agent-review.ts"
28125
+ },
28126
+ dependencies: {
28127
+ exceljs: "^4.4.0",
28128
+ fflate: "^0.8.3",
28129
+ htmlparser2: "^12.0.0",
28130
+ saxes: "^6.0.0"
28131
+ }
28132
+ };
28133
+
28134
+ // packages/l10n-core/src/qa/review-data.ts
28135
+ var DEFAULT_REVIEW_TOOL = {
28136
+ name: package_default2.name,
28137
+ version: package_default2.version
28138
+ };
28139
+ function sanitizeReviewTool(value) {
28140
+ if (!value || typeof value !== "object") return void 0;
28141
+ const candidate = value;
28142
+ const name = typeof candidate.name === "string" ? candidate.name.trim() : "";
28143
+ const version2 = typeof candidate.version === "string" ? candidate.version.trim() : "";
28144
+ if (!name || !version2 || name.length > 120 || version2.length > 120) return void 0;
28145
+ if (/[\r\n\u0000-\u001f\u007f]/u.test(name) || /[\r\n\u0000-\u001f\u007f]/u.test(version2)) return void 0;
28146
+ return { name, version: version2 };
28147
+ }
28148
+ function formatReviewTool(tool) {
28149
+ return tool?.name && tool?.version ? `${tool.name}@${tool.version}` : "";
28150
+ }
28083
28151
  var REVIEW_GROUPS = [
28084
28152
  { label: "\u6807\u70B9\u4E0E\u7A7A\u683C", rules: ["UNPAIRED_BRACKET", "PUNCT_DUP", "WHITESPACE"] },
28085
28153
  { label: "Tag \u4E0E\u53D8\u91CF", rules: ["TAG_MISMATCH", "PLACEHOLDER_MISSING", "PLACEHOLDER_EXTRA"] },
@@ -28326,6 +28394,11 @@ async function writeReviewXlsx(Workbook, rows, { collectSections, aiStatus, aiTy
28326
28394
  const limitMessage = "\u7ED3\u679C\u8D85\u8FC7 Excel \u7684\u884C\u6570\u6216\u5355\u5143\u683C\u957F\u5EA6\u9650\u5236\uFF0C\u8BF7\u7F29\u5C0F\u5BFC\u51FA\u8303\u56F4\u3002";
28327
28395
  if (total > 1048575) throw new Error(limitMessage);
28328
28396
  const workbook = new Workbook();
28397
+ const toolLabel = report?.tool?.name && report?.tool?.version ? `${report.tool.name}@${report.tool.version}` : "";
28398
+ if (toolLabel) {
28399
+ workbook.creator = toolLabel;
28400
+ workbook.description = `Generated by ${toolLabel}`;
28401
+ }
28329
28402
  const sheet = workbook.addWorksheet("QA", { views: [{ state: "frozen", ySplit: 1 }] });
28330
28403
  const headers = ["\u89C4\u5219\u7C7B\u522B", "\u6587\u4EF6", "\u53E5\u6BB5\u7F16\u53F7", "\u539F\u6587", "\u8BD1\u6587", "\u8BC4\u8BBA", "AI QA \u7ED3\u679C", "AI \u8BC4\u8BBA"];
28331
28404
  const widths = [23, 31, 14, 42, 42, 42, 21, 64];
@@ -28350,13 +28423,18 @@ async function writeReviewXlsx(Workbook, rows, { collectSections, aiStatus, aiTy
28350
28423
  }
28351
28424
  sheet.getRow(1).font = { bold: true };
28352
28425
  sheet.autoFilter = { from: { row: 1, column: 1 }, to: { row: Math.max(2, sheet.rowCount), column: headers.length } };
28353
- if (report?.configuration) {
28354
- const { files, aiqa, configuration } = report;
28426
+ if (report?.configuration || toolLabel) {
28427
+ const { files = [], aiqa, configuration } = report ?? {};
28355
28428
  const summary = workbook.addWorksheet("\u68C0\u67E5\u6982\u51B5");
28356
28429
  summary.columns = [{ width: 30 }, { width: 74, style: { alignment: { wrapText: true } } }];
28357
- summary.addRow(["\u68C0\u67E5\u72B6\u6001", aiqa?.pending || aiqa?.unavailable || files.some((file) => file.incomplete) ? "\u68C0\u67E5\u672A\u5B8C\u6574\u5B8C\u6210" : "\u68C0\u67E5\u5B8C\u6210"]);
28358
- summary.addRow(["\u57FA\u7840\u68C0\u67E5", configuration.checks.join("\u3001") || "\u672A\u542F\u7528"]);
28359
- summary.addRow(["AIQA", aiqa ? `\u5DF2\u5224\u5B9A ${aiqa.completedSegments} / ${aiqa.totalSegments} \u6BB5\uFF0C\u65E0\u6CD5\u5224\u5B9A ${aiqa.unavailable} \u6BB5\uFF0C\u672A\u5B8C\u6210 ${aiqa.pending} \u6BB5` : "\u672A\u542F\u7528"]);
28430
+ if (configuration) {
28431
+ summary.addRow(["\u68C0\u67E5\u72B6\u6001", aiqa?.pending || aiqa?.unavailable || files.some((file) => file.incomplete) ? "\u68C0\u67E5\u672A\u5B8C\u6574\u5B8C\u6210" : "\u68C0\u67E5\u5B8C\u6210"]);
28432
+ summary.addRow(["\u57FA\u7840\u68C0\u67E5", configuration.checks.join("\u3001") || "\u672A\u542F\u7528"]);
28433
+ summary.addRow(["AIQA", aiqa ? `\u5DF2\u5224\u5B9A ${aiqa.completedSegments} / ${aiqa.totalSegments} \u6BB5\uFF0C\u65E0\u6CD5\u5224\u5B9A ${aiqa.unavailable} \u6BB5\uFF0C\u672A\u5B8C\u6210 ${aiqa.pending} \u6BB5` : "\u672A\u542F\u7528"]);
28434
+ }
28435
+ if (toolLabel) {
28436
+ summary.addRow(["\u5DE5\u5177\u7248\u672C", toolLabel]);
28437
+ }
28360
28438
  for (const file of files) {
28361
28439
  summary.addRow([file.name, file.incomplete ? file.error ?? "\u90E8\u5206\u89C4\u5219\u672A\u5B8C\u6210" : `\u5DF2\u68C0\u67E5 ${file.segments} \u6BB5`]);
28362
28440
  }
@@ -28365,13 +28443,19 @@ async function writeReviewXlsx(Workbook, rows, { collectSections, aiStatus, aiTy
28365
28443
  }
28366
28444
 
28367
28445
  // packages/l10n-core/src/qa/review-page.ts
28446
+ function escapeHtml(value) {
28447
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
28448
+ }
28368
28449
  var styles = `
28369
28450
  :root { color-scheme: light; --paper: #f4f6f9; --ink: #192438; --muted: #4b5a6f;
28370
28451
  --border: #d9e0ea; --blue: #164aa4; --surface: #fff; font: 15px/1.5 system-ui, sans-serif; }
28371
28452
  * { box-sizing: border-box; }
28372
28453
  body { margin: 0; color: var(--ink); background: var(--paper); }
28373
28454
  main { width: min(1480px, 100%); margin: auto; padding: 28px clamp(14px, 3vw, 36px) 44px; }
28455
+ .header-bar { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
28374
28456
  .brand { color: var(--blue); font-weight: 700; letter-spacing: .04em; }
28457
+ .tool-version { font-size: 12px; color: var(--muted); background: #edf2f8; border: 1px solid var(--border);
28458
+ border-radius: 999px; padding: 2px 10px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
28375
28459
  h1 { font-size: clamp(26px, 4vw, 35px); margin: 4px 0 22px; letter-spacing: -.03em; }
28376
28460
  h2 { font-size: 18px; margin: 0 0 14px; }
28377
28461
  p { margin: 0; } small, .muted { color: var(--muted); }
@@ -28471,6 +28555,7 @@ function reviewClient(presentation, writeXlsx) {
28471
28555
  let report = { rows: [], files: [] };
28472
28556
  let filtered = [];
28473
28557
  let lastScan;
28558
+ let lastChecks = [];
28474
28559
  let aiqaRunning = false;
28475
28560
  const collapsed = /* @__PURE__ */ new Set();
28476
28561
  const pageSize = 50;
@@ -28770,16 +28855,39 @@ function reviewClient(presentation, writeXlsx) {
28770
28855
  const chosen = get("export-scope").value === "all" ? [...report.rows, ...aiqaRows.values()] : filtered;
28771
28856
  let blob;
28772
28857
  if (form) {
28858
+ const totalSegments = report.segments?.length ?? report.files.reduce((sum, item) => sum + item.segments, 0);
28859
+ let autoPass = 0;
28860
+ let humanReview = 0;
28861
+ let unavailable = 0;
28862
+ for (const row of aiqaRows.values()) {
28863
+ if (row.rule === "AIQA_UNAVAILABLE") unavailable += 1;
28864
+ else if (row.message === "AUTO_PASS") autoPass += 1;
28865
+ else humanReview += 1;
28866
+ }
28867
+ const aiqaSummary = aiqaRows.size > 0 ? {
28868
+ totalSegments,
28869
+ completedSegments: autoPass + humanReview,
28870
+ autoPass,
28871
+ humanReview,
28872
+ unavailable,
28873
+ pending: Math.max(0, totalSegments - aiqaRows.size)
28874
+ } : void 0;
28875
+ const exportPayload = {
28876
+ rows: chosen,
28877
+ files: report.files,
28878
+ configuration: { checks: lastChecks, aiqa: aiqaRows.size > 0 },
28879
+ ...aiqaSummary ? { aiqa: aiqaSummary } : {}
28880
+ };
28773
28881
  const response = await requestLocal("/export/" + format, {
28774
28882
  method: "POST",
28775
28883
  headers: { "Content-Type": "application/json" },
28776
- body: JSON.stringify({ rows: chosen, files: report.files })
28884
+ body: JSON.stringify(exportPayload)
28777
28885
  });
28778
28886
  if (!response.ok) throw new Error((await response.json()).error || "\u5BFC\u51FA\u5931\u8D25\u3002");
28779
28887
  blob = await response.blob();
28780
28888
  } else {
28781
28889
  const { ExcelJS: ExcelJS2 } = globalThis;
28782
- const bytes = await writeXlsx(ExcelJS2.Workbook, chosen, presentation);
28890
+ const bytes = await writeXlsx(ExcelJS2.Workbook, chosen, presentation, report);
28783
28891
  blob = new Blob([bytes], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
28784
28892
  }
28785
28893
  const url = URL.createObjectURL(blob);
@@ -28816,7 +28924,9 @@ function reviewClient(presentation, writeXlsx) {
28816
28924
  if (run.disabled) return;
28817
28925
  const body = new FormData();
28818
28926
  for (const upload of get("uploads").files ?? []) body.append("file", upload);
28819
- const rules = Array.from(form.querySelectorAll("input[data-rules]:checked")).flatMap((item) => (item.dataset.rules ?? "").split(","));
28927
+ const checkInputs = Array.from(form.querySelectorAll("input[data-rules]:checked"));
28928
+ const rules = checkInputs.flatMap((item) => (item.dataset.rules ?? "").split(","));
28929
+ const checkedLabels = checkInputs.map((item) => item.closest("label")?.textContent?.trim() ?? "").filter(Boolean);
28820
28930
  const identicalWhitelist = get("whitelist").value.split("\n").map((text) => text.trim()).filter(Boolean);
28821
28931
  const customRules = Array.from(ruleList.querySelectorAll("fieldset")).map((row) => ({
28822
28932
  name: row.querySelector("[data-name]").value.trim(),
@@ -28824,6 +28934,7 @@ function reviewClient(presentation, writeXlsx) {
28824
28934
  kind: row.querySelector("select").value,
28825
28935
  value: row.querySelector("[data-value]").value.trim()
28826
28936
  }));
28937
+ lastChecks = [...checkedLabels, ...customRules.map((rule) => rule.name).filter(Boolean)];
28827
28938
  body.append("options", JSON.stringify({ rules, identicalWhitelist, customRules }));
28828
28939
  run.disabled = true;
28829
28940
  lastScan = void 0;
@@ -28915,8 +29026,11 @@ function excelScript() {
28915
29026
  }
28916
29027
  return excelBrowserScript;
28917
29028
  }
28918
- function renderReviewPage(report, nonce = "", aiqaEnabled = false) {
29029
+ function renderReviewPage(report, nonce = "", aiqaEnabled = false, tool) {
28919
29030
  const offline = report !== void 0;
29031
+ const resolvedTool = report?.tool ?? tool;
29032
+ const toolLabel = formatReviewTool(resolvedTool);
29033
+ const reportPayload = report ? resolvedTool && !report.tool ? { ...report, tool: resolvedTool } : report : void 0;
28920
29034
  const title = offline ? "\u53CC\u8BED QA \u62A5\u544A" : "\u53CC\u8BED\u6587\u4EF6\u68C0\u67E5";
28921
29035
  const settings = offline ? "" : `<form class="panel" id="settings">
28922
29036
  <h2>\u672C\u6B21\u68C0\u67E5</h2>
@@ -28952,11 +29066,13 @@ function renderReviewPage(report, nonce = "", aiqaEnabled = false) {
28952
29066
  <small>\u8FD0\u884C\u65F6\uFF0C\u6240\u9009\u6BB5\u843D\u3001\u76F8\u90BB\u539F\u6587\u548C\u9879\u76EE\u8981\u6C42\u4F1A\u53D1\u9001\u5230\u5DF2\u914D\u7F6E\u7684\u6A21\u578B\u7F51\u5173\u3002</small>
28953
29067
  <p id="aiqa-status" role="status"></p>` : "<small>\u914D\u7F6E\u6A21\u578B\u7F51\u5173\u540E\u53EF\u8FD0\u884C AIQA\u3002</small>"}
28954
29068
  </div>`;
28955
- const data = offline ? `<script type="application/json" id="report-data">${JSON.stringify(report).replaceAll("<", "\\u003c")}</script>` : "";
29069
+ const data = reportPayload ? `<script type="application/json" id="report-data">${JSON.stringify(reportPayload).replaceAll("<", "\\u003c")}</script>` : "";
28956
29070
  const scriptNonce = nonce ? ` nonce="${nonce}"` : "";
29071
+ const generatorMeta = toolLabel ? `<meta name="generator" content="${escapeHtml(toolLabel)}">` : "";
29072
+ const versionBadge = toolLabel ? `<span class="tool-version" id="tool-version">\u5DE5\u5177\u7248\u672C\uFF1A${escapeHtml(toolLabel)}</span>` : "";
28957
29073
  return `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8">
28958
- <meta name="viewport" content="width=device-width, initial-scale=1"><title>${title} \xB7 LangLink</title>
28959
- <style>${styles}</style></head><body><main><p class="brand">LangLink</p><h1>${title}</h1>
29074
+ <meta name="viewport" content="width=device-width, initial-scale=1">${generatorMeta}<title>${title} \xB7 LangLink</title>
29075
+ <style>${styles}</style></head><body><main><div class="header-bar"><p class="brand">LangLink</p>${versionBadge}</div><h1>${title}</h1>
28960
29076
  <div class="layout${offline ? " offline" : ""}">${settings}
28961
29077
  <section class="panel" aria-labelledby="results-title"><h2 id="results-title">\u68C0\u67E5\u7ED3\u679C</h2>
28962
29078
  <p class="muted" id="status" role="status">${offline ? "" : "\u9009\u62E9\u6587\u4EF6\u548C\u68C0\u67E5\u9879\uFF0C\u7136\u540E\u8FD0\u884C\u68C0\u67E5\u3002"}</p>
@@ -28997,18 +29113,28 @@ function validateReviewExportReport(bytes) {
28997
29113
  if (report.aiqa && typeof report.aiqa === "object" && ["totalSegments", "completedSegments", "autoPass", "humanReview", "unavailable", "pending"].every((key) => Number.isSafeInteger(report.aiqa[key]))) {
28998
29114
  optional2.aiqa = report.aiqa;
28999
29115
  }
29116
+ const tool = sanitizeReviewTool(report.tool);
29117
+ if (tool) optional2.tool = tool;
29000
29118
  return { rows: report.rows, files: report.files, ...optional2 };
29001
29119
  }
29002
29120
  function csvCell(value) {
29003
29121
  return escapeCsvField(/^[\s\uFEFF]*[=+@-]|^[\t\r\n]/u.test(value) ? "'" + value : value);
29004
29122
  }
29005
29123
  async function buildReviewExportArtifact(format, report) {
29124
+ const toolLabel = formatReviewTool(report.tool);
29006
29125
  if (format === "html") {
29007
- return { contentType: "text/html; charset=utf-8", body: renderReviewPage(report) };
29126
+ return { contentType: "text/html; charset=utf-8", body: renderReviewPage(report, "", false, report.tool) };
29008
29127
  }
29009
- const headers = Object.values(REVIEW_COLUMNS);
29128
+ const headers = toolLabel ? [...Object.values(REVIEW_COLUMNS), "\u5DE5\u5177\u7248\u672C"] : Object.values(REVIEW_COLUMNS);
29010
29129
  if (format === "csv") {
29011
- const lines = [headers.join(","), ...report.rows.map((row) => columnKeys.map((key) => csvCell(row[key])).join(","))];
29130
+ const lines = [
29131
+ headers.join(","),
29132
+ ...report.rows.map((row) => {
29133
+ const cells = columnKeys.map((key) => csvCell(row[key]));
29134
+ if (toolLabel) cells.push(csvCell(toolLabel));
29135
+ return cells.join(",");
29136
+ })
29137
+ ];
29012
29138
  return { contentType: "text/csv; charset=utf-8", body: "\uFEFF" + lines.join("\r\n") + "\r\n" };
29013
29139
  }
29014
29140
  const bytes = await writeReviewXlsx(ExcelJS.Workbook, report.rows, createReviewPresentation(), report);
@@ -29778,17 +29904,26 @@ async function runMemoqAiqa(input) {
29778
29904
  }
29779
29905
 
29780
29906
  // packages/memoq-bridge/src/review-page.ts
29907
+ function escapeHtmlAttr(value) {
29908
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
29909
+ }
29781
29910
  function renderReviewWorkbenchHtml(options) {
29911
+ const toolInfo = options.tool?.name && options.tool?.version ? options.tool : void 0;
29912
+ const toolLabel = toolInfo ? `${toolInfo.name}@${toolInfo.version}` : "";
29913
+ const toolShort = toolInfo ? `v${toolInfo.version}` : "";
29914
+ const generatorMeta = toolLabel ? `
29915
+ <meta name="generator" content="${escapeHtmlAttr(toolLabel)}" />` : "";
29782
29916
  const bootJson = JSON.stringify({
29783
29917
  reviewToken: options.reviewToken,
29784
29918
  initialDocumentName: options.initialDocumentName ?? "",
29785
- aiqaLimit: options.aiqaSelectionLimit ?? 20
29919
+ aiqaLimit: options.aiqaSelectionLimit ?? 20,
29920
+ tool: toolInfo ?? null
29786
29921
  }).replace(/</gu, "\\u003c");
29787
29922
  return `<!DOCTYPE html>
29788
29923
  <html lang="zh-CN">
29789
29924
  <head>
29790
29925
  <meta charset="utf-8" />
29791
- <meta name="viewport" content="width=device-width, initial-scale=1" />
29926
+ <meta name="viewport" content="width=device-width, initial-scale=1" />${generatorMeta}
29792
29927
  <title>LangLink memoQ CAT \u53CC\u8BED\u5BA1\u6821\u4E0E QA \u5DE5\u4F5C\u53F0</title>
29793
29928
  <style>
29794
29929
  :root {
@@ -30488,6 +30623,7 @@ function renderReviewWorkbenchHtml(options) {
30488
30623
  <header class="cat-ribbon">
30489
30624
  <div class="ribbon-left">
30490
30625
  <span class="brand-chip"><span class="brand-badge">CAT</span><span id="docTitle" class="doc-title">LangLink memoQ \u5DE5\u4F5C\u53F0</span></span>
30626
+ <span id="toolVersionBadge" class="pill mono${toolShort ? "" : " hidden"}" title="${escapeHtmlAttr(toolLabel)}">${escapeHtmlAttr(toolShort)}</span>
30491
30627
  <select id="docSelector" class="doc-select" aria-label="\u6587\u6863\u5207\u6362"></select>
30492
30628
  <span id="langPair" class="pill">- \u2192 -</span>
30493
30629
  <span id="previewBadge" class="pill">Preview: \u68C0\u6D4B\u4E2D</span>
@@ -30690,6 +30826,7 @@ function renderReviewWorkbenchHtml(options) {
30690
30826
  <span class="pill info" id="pillMqm">MQM: -</span>
30691
30827
  </div>
30692
30828
  <div class="status-group">
30829
+ <span id="toolVersionFooter" class="mono${toolLabel ? "" : " hidden"}" style="color:var(--muted);">${escapeHtmlAttr(toolLabel)}</span>
30693
30830
  <span id="bridgeStatusPill" class="pill ok">\u25CF \u6865\u63A5\u5DF2\u8FDE\u63A5</span>
30694
30831
  </div>
30695
30832
  </footer>
@@ -31172,6 +31309,19 @@ function renderReviewWorkbenchHtml(options) {
31172
31309
 
31173
31310
  const projInput = document.getElementById("inpProjectDir");
31174
31311
  if (!projInput.value && d.projectDir) projInput.value = d.projectDir;
31312
+ const toolMeta = (d.tool && d.tool.name && d.tool.version) ? d.tool : BOOT.tool;
31313
+ const toolText = toolMeta && toolMeta.name && toolMeta.version ? (toolMeta.name + "@" + toolMeta.version) : "";
31314
+ const tvBadge = document.getElementById("toolVersionBadge");
31315
+ if (tvBadge) {
31316
+ tvBadge.textContent = toolText ? ("v" + toolMeta.version) : "";
31317
+ tvBadge.title = toolText;
31318
+ tvBadge.classList.toggle("hidden", !toolText);
31319
+ }
31320
+ const tvFooter = document.getElementById("toolVersionFooter");
31321
+ if (tvFooter) {
31322
+ tvFooter.textContent = toolText;
31323
+ tvFooter.classList.toggle("hidden", !toolText);
31324
+ }
31175
31325
  renderBridgePill();
31176
31326
  }
31177
31327
 
@@ -32235,6 +32385,10 @@ function renderReviewWorkbenchHtml(options) {
32235
32385
  ? catalog.filter((c) => state.selectedRules.has(c.ruleId)).map((c) => c.label)
32236
32386
  : [];
32237
32387
  const aiSummary = state.qaAiqaRows.size > 0 ? computeAiqaSummaryCounts() : undefined;
32388
+ const activeTool = (state.qa && state.qa.tool) || (state.data && state.data.tool) || BOOT.tool;
32389
+ const toolPayload = activeTool && activeTool.name && activeTool.version
32390
+ ? { name: String(activeTool.name), version: String(activeTool.version) }
32391
+ : undefined;
32238
32392
  const payload = {
32239
32393
  rows: cleanRows,
32240
32394
  files,
@@ -32242,7 +32396,8 @@ function renderReviewWorkbenchHtml(options) {
32242
32396
  aiqa: Boolean(state.data && state.data.aiqaAvailable && state.qaAiqaRows.size > 0),
32243
32397
  checks: checkedLabels
32244
32398
  },
32245
- ...(aiSummary ? { aiqa: aiSummary } : {})
32399
+ ...(aiSummary ? { aiqa: aiSummary } : {}),
32400
+ ...(toolPayload ? { tool: toolPayload } : {})
32246
32401
  };
32247
32402
 
32248
32403
  const res = await fetch("/review/api/qa/export/" + format, {
@@ -32844,6 +32999,8 @@ async function createMtGateway(options) {
32844
32999
  const requestedPort = options.port ?? DEFAULT_PORT;
32845
33000
  const productName = options.productName ?? BRIDGE_PRODUCT_NAME;
32846
33001
  const desktopVersion = options.desktopVersion ?? BRIDGE_VERSION;
33002
+ const toolName = options.toolName?.trim() || "@langlink/memoq-bridge";
33003
+ const toolInfo = { name: toolName, version: desktopVersion };
32847
33004
  const controlToken = options.controlToken ?? randomUUID3().replace(/-/gu, "");
32848
33005
  const candidateReviewToken = typeof options.reviewToken === "string" ? options.reviewToken.trim() : "";
32849
33006
  const reviewToken = candidateReviewToken.length >= 24 && candidateReviewToken !== controlToken ? candidateReviewToken : randomBytes(24).toString("hex");
@@ -33213,6 +33370,7 @@ async function createMtGateway(options) {
33213
33370
  sendJson(response, 200, {
33214
33371
  ok: true,
33215
33372
  productName,
33373
+ toolName,
33216
33374
  mode: effectiveMode(),
33217
33375
  contractVersion: CONTRACT_VERSION,
33218
33376
  desktopVersion
@@ -33222,6 +33380,7 @@ async function createMtGateway(options) {
33222
33380
  if (method === "GET" && pathname === ROUTES.desktopVersion) {
33223
33381
  sendJson(response, 200, {
33224
33382
  productName,
33383
+ toolName,
33225
33384
  desktopVersion,
33226
33385
  contractVersion: CONTRACT_VERSION
33227
33386
  });
@@ -33602,6 +33761,7 @@ async function createMtGateway(options) {
33602
33761
  renderReviewWorkbenchHtml({
33603
33762
  nonce,
33604
33763
  reviewToken,
33764
+ tool: toolInfo,
33605
33765
  ...initialDocName ? { initialDocumentName: initialDocName } : {}
33606
33766
  }),
33607
33767
  csp,
@@ -33715,6 +33875,7 @@ async function createMtGateway(options) {
33715
33875
  qaCatalog: MEMOQ_QA_RULE_CATALOG,
33716
33876
  qaRuleGroups: MEMOQ_QA_RULE_GROUPS,
33717
33877
  aiqaAvailable: Boolean(aiqaProvider),
33878
+ tool: toolInfo,
33718
33879
  projectDir: options.getLiveConfig?.().projectDir ?? "",
33719
33880
  maxStaged: DEFAULT_MAX_STAGED
33720
33881
  });
@@ -33775,7 +33936,7 @@ async function createMtGateway(options) {
33775
33936
  }
33776
33937
  if (method === "POST" && pathname === "/review/api/qa") {
33777
33938
  const body = await readJsonBody(request);
33778
- sendJson(response, 200, runQaFromBody(body));
33939
+ sendJson(response, 200, { ...runQaFromBody(body), tool: toolInfo });
33779
33940
  return;
33780
33941
  }
33781
33942
  if (method === "POST" && pathname === "/review/api/qa/aiqa") {
@@ -33854,7 +34015,7 @@ async function createMtGateway(options) {
33854
34015
  } catch (error2) {
33855
34016
  throw new BodyError(400, "INVALID_EXPORT_REPORT", error2 instanceof Error ? error2.message : String(error2));
33856
34017
  }
33857
- const artifact = await buildReviewExportArtifact(exportFormat, reportPayload);
34018
+ const artifact = await buildReviewExportArtifact(exportFormat, { ...reportPayload, tool: toolInfo });
33858
34019
  response.writeHead(200, {
33859
34020
  "Content-Type": artifact.contentType,
33860
34021
  "Content-Disposition": `attachment; filename="langlink-memoq-qa.${exportFormat}"`,
@@ -33875,10 +34036,13 @@ async function createMtGateway(options) {
33875
34036
  gateway: {
33876
34037
  running: true,
33877
34038
  owner: "langlink-memoq-bridge",
34039
+ toolName,
34040
+ version: desktopVersion,
33878
34041
  mode: effectiveMode(),
33879
34042
  url: `http://${host}:${actualPort}`,
33880
34043
  contractVersion: CONTRACT_VERSION
33881
34044
  },
34045
+ tool: toolInfo,
33882
34046
  reviewUrl: getReviewUrl(),
33883
34047
  preview: options.previewClient?.getStatus() ?? null,
33884
34048
  documents: unified,
@@ -34031,7 +34195,8 @@ async function createMtGateway(options) {
34031
34195
  const body = await readJsonBody(request);
34032
34196
  sendJson(response, 200, {
34033
34197
  ...runQaFromBody(body),
34034
- reviewUrl: getReviewUrl()
34198
+ reviewUrl: getReviewUrl(),
34199
+ tool: toolInfo
34035
34200
  });
34036
34201
  return;
34037
34202
  }
@@ -34167,16 +34332,33 @@ async function createMtGateway(options) {
34167
34332
  }
34168
34333
 
34169
34334
  // packages/memoq-bridge/src/dll-assets.ts
34335
+ import { execFile } from "node:child_process";
34170
34336
  import { createHash as createHash2, randomUUID as randomUUID4 } from "node:crypto";
34171
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync5, renameSync as renameSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
34337
+ import {
34338
+ closeSync,
34339
+ existsSync as existsSync4,
34340
+ mkdirSync as mkdirSync3,
34341
+ openSync,
34342
+ readdirSync,
34343
+ readFileSync as readFileSync5,
34344
+ readSync,
34345
+ renameSync as renameSync2,
34346
+ rmSync as rmSync2,
34347
+ statSync as statSync2,
34348
+ writeFileSync as writeFileSync3
34349
+ } from "node:fs";
34172
34350
  import { homedir as homedir2 } from "node:os";
34173
34351
  import { dirname as dirname4, join as join5, resolve as resolve3 } from "node:path";
34352
+ import { promisify } from "node:util";
34353
+ import { inflateRawSync } from "node:zlib";
34174
34354
  import { unzipSync as unzipSync2 } from "fflate";
34355
+ var execFileAsync = promisify(execFile);
34175
34356
  var DEFAULT_PLUGIN_DLL_MANIFEST = {
34176
34357
  pluginDllName: PLUGIN_DLL_NAME,
34177
34358
  version: "1.0.7.0",
34178
- sha256: "E0C731FFBDD7F613104D372C376F35596C95B46A628B8C574C753EAAF4A20CE1",
34359
+ sha256: "BB8250B5EFB6F742E1F10DA43E40008EB5DC04587B5DBA262AEAB0F7B7F5545E",
34179
34360
  compatibleSha256s: [
34361
+ "BB8250B5EFB6F742E1F10DA43E40008EB5DC04587B5DBA262AEAB0F7B7F5545E",
34180
34362
  "E0C731FFBDD7F613104D372C376F35596C95B46A628B8C574C753EAAF4A20CE1",
34181
34363
  "385F22C08DBBBB98A962A2119DA10675ADF996ECD16F397B50CE627AFBAFA4F9"
34182
34364
  ],
@@ -34185,8 +34367,23 @@ var DEFAULT_PLUGIN_DLL_MANIFEST = {
34185
34367
  };
34186
34368
  var MAX_DISCOVERY_DIR_ENTRIES = 200;
34187
34369
  var MAX_ZIP_INSPECT_BYTES = 200 * 1024 * 1024;
34188
- var MAX_FAST_ZIP_HASH_BYTES = 25 * 1024 * 1024;
34370
+ var MAX_DLL_BYTES = 50 * 1024 * 1024;
34371
+ var MAX_REDIRECTS = 5;
34372
+ var DEFAULT_DOWNLOAD_TIMEOUT_MS = 25e3;
34189
34373
  var ZIP_CANDIDATE_NAME_RE = /memoq.*(?:ai[-_]?hub|plugin)|memoq\.ai\.hub\.plugin/iu;
34374
+ var PluginAssetIntegrityError = class extends Error {
34375
+ };
34376
+ var PluginAssetPolicyError = class extends Error {
34377
+ };
34378
+ function isLoopbackHost(hostname) {
34379
+ const host = hostname.replace(/^\[/u, "").replace(/\]$/u, "").toLowerCase();
34380
+ return host === "127.0.0.1" || host === "localhost" || host === "::1";
34381
+ }
34382
+ function isPluginDllZipEntry(name) {
34383
+ const normalized = name.replace(/\\/gu, "/").toLowerCase();
34384
+ const target = PLUGIN_DLL_NAME.toLowerCase();
34385
+ return normalized === target || normalized.endsWith(`/${target}`);
34386
+ }
34190
34387
  function acceptedPluginSha256s(explicitExpectedSha256) {
34191
34388
  const override = (explicitExpectedSha256?.trim() || process.env.MEMOQ_PLUGIN_DLL_SHA256?.trim() || "").toUpperCase();
34192
34389
  if (override) {
@@ -34206,26 +34403,101 @@ function computeBufferSha256(bytes) {
34206
34403
  function computeFileSha256(filePath) {
34207
34404
  return computeBufferSha256(readFileSync5(filePath));
34208
34405
  }
34209
- function parseAllowedAssetUrl(raw) {
34406
+ function parseAllowedAssetUrl(raw, options) {
34210
34407
  let url;
34211
34408
  try {
34212
34409
  url = new URL(raw);
34213
34410
  } catch {
34214
- throw new Error("Plugin DLL download URL is not a valid URL.");
34411
+ throw new PluginAssetPolicyError("Plugin DLL download URL is not a valid URL.");
34215
34412
  }
34216
34413
  if (url.protocol !== "https:" && url.protocol !== "http:") {
34217
- throw new Error("Plugin DLL download URL must use https or loopback http.");
34414
+ throw new PluginAssetPolicyError("Plugin DLL download URL must use https or loopback http.");
34415
+ }
34416
+ const isLoopback = isLoopbackHost(url.hostname);
34417
+ if (options?.allowLoopback === false && isLoopback) {
34418
+ throw new PluginAssetPolicyError("External plugin DLL download URL must not redirect to loopback.");
34218
34419
  }
34219
- const host = url.hostname.replace(/^\[/u, "").replace(/\]$/u, "").toLowerCase();
34220
- const isLoopback = host === "127.0.0.1" || host === "localhost" || host === "::1";
34221
34420
  if (url.protocol === "http:" && !isLoopback) {
34222
- throw new Error("Plugin DLL download URL must use https unless it points at loopback.");
34421
+ throw new PluginAssetPolicyError("Plugin DLL download URL must use https unless it points at loopback.");
34223
34422
  }
34224
34423
  if (url.username !== "" || url.password !== "") {
34225
- throw new Error("Plugin DLL download URL must not embed credentials.");
34424
+ throw new PluginAssetPolicyError("Plugin DLL download URL must not embed credentials.");
34226
34425
  }
34227
34426
  return url;
34228
34427
  }
34428
+ async function fetchFollowingValidatedRedirects(initialUrl, init, fetchFn, timeoutMs) {
34429
+ const allowLoopback = isLoopbackHost(initialUrl.hostname);
34430
+ let currentUrl = initialUrl;
34431
+ for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {
34432
+ const response = await fetchFn(currentUrl, {
34433
+ ...init,
34434
+ redirect: "manual",
34435
+ signal: AbortSignal.timeout(timeoutMs)
34436
+ });
34437
+ if ([301, 302, 303, 307, 308].includes(response.status)) {
34438
+ const location = response.headers.get("location");
34439
+ await response.body?.cancel?.().catch(() => {
34440
+ });
34441
+ if (hop >= MAX_REDIRECTS) {
34442
+ throw new Error(`Exceeded maximum redirect limit (${MAX_REDIRECTS}).`);
34443
+ }
34444
+ if (!location) {
34445
+ throw new Error(`Redirect response (${response.status}) missing Location header.`);
34446
+ }
34447
+ currentUrl = parseAllowedAssetUrl(new URL(location, currentUrl).href, { allowLoopback });
34448
+ continue;
34449
+ }
34450
+ if (response.url) {
34451
+ parseAllowedAssetUrl(response.url, { allowLoopback });
34452
+ }
34453
+ return { response, finalUrl: currentUrl };
34454
+ }
34455
+ throw new Error(`Exceeded maximum redirect limit (${MAX_REDIRECTS}).`);
34456
+ }
34457
+ async function readResponseBytesBounded(response, maxBytes) {
34458
+ const contentLengthHeader = response.headers?.get?.("content-length");
34459
+ if (contentLengthHeader) {
34460
+ const declared = Number.parseInt(contentLengthHeader, 10);
34461
+ if (Number.isFinite(declared) && declared > maxBytes) {
34462
+ await response.body?.cancel?.().catch(() => {
34463
+ });
34464
+ throw new PluginAssetIntegrityError(`Downloaded plugin artifact exceeds maximum size limit (${maxBytes} bytes).`);
34465
+ }
34466
+ }
34467
+ if (response.body && typeof response.body.getReader === "function") {
34468
+ const reader = response.body.getReader();
34469
+ const chunks = [];
34470
+ let total = 0;
34471
+ try {
34472
+ while (true) {
34473
+ const { done, value } = await reader.read();
34474
+ if (done) break;
34475
+ if (!value) continue;
34476
+ total += value.byteLength;
34477
+ if (total > maxBytes) {
34478
+ await reader.cancel().catch(() => {
34479
+ });
34480
+ throw new PluginAssetIntegrityError(`Downloaded plugin artifact exceeds maximum size limit (${maxBytes} bytes).`);
34481
+ }
34482
+ chunks.push(value);
34483
+ }
34484
+ } finally {
34485
+ reader.releaseLock?.();
34486
+ }
34487
+ const combined = new Uint8Array(total);
34488
+ let offset = 0;
34489
+ for (const chunk of chunks) {
34490
+ combined.set(chunk, offset);
34491
+ offset += chunk.byteLength;
34492
+ }
34493
+ return combined;
34494
+ }
34495
+ const rawBytes = new Uint8Array(await response.arrayBuffer());
34496
+ if (rawBytes.byteLength > maxBytes) {
34497
+ throw new PluginAssetIntegrityError(`Downloaded plugin artifact exceeds maximum size limit (${maxBytes} bytes).`);
34498
+ }
34499
+ return rawBytes;
34500
+ }
34229
34501
  function normalizeExpectedShaList(expectedSha256) {
34230
34502
  if (Array.isArray(expectedSha256)) {
34231
34503
  return Array.from(new Set(expectedSha256.map((s) => s.trim().toUpperCase()).filter(Boolean)));
@@ -34237,38 +34509,361 @@ function normalizeExpectedShaList(expectedSha256) {
34237
34509
  }
34238
34510
  function extractPluginDllFromBytes(bytes, expectedSha256) {
34239
34511
  if (bytes.length < 2) {
34240
- throw new Error("Downloaded plugin artifact is empty.");
34512
+ throw new PluginAssetIntegrityError("Downloaded plugin artifact is empty.");
34513
+ }
34514
+ if (bytes.byteLength > MAX_ZIP_INSPECT_BYTES) {
34515
+ throw new PluginAssetIntegrityError(`Plugin artifact exceeds maximum size limit (${MAX_ZIP_INSPECT_BYTES} bytes).`);
34241
34516
  }
34242
34517
  let dllBytes;
34243
34518
  const isZip = bytes[0] === 80 && bytes[1] === 75;
34244
34519
  if (isZip) {
34245
- const entries = unzipSync2(bytes);
34520
+ const entries = unzipSync2(bytes, {
34521
+ filter: (file) => isPluginDllZipEntry(file.name) && (file.originalSize === void 0 || file.originalSize <= MAX_DLL_BYTES)
34522
+ });
34246
34523
  for (const [name, content] of Object.entries(entries)) {
34247
- const normalized = name.replace(/\\/gu, "/").toLowerCase();
34248
- if (normalized === PLUGIN_DLL_NAME.toLowerCase() || normalized.endsWith(`/${PLUGIN_DLL_NAME.toLowerCase()}`)) {
34524
+ if (isPluginDllZipEntry(name)) {
34249
34525
  dllBytes = content;
34250
34526
  break;
34251
34527
  }
34252
34528
  }
34253
34529
  if (!dllBytes) {
34254
- throw new Error(`Archive did not contain ${PLUGIN_DLL_NAME}.`);
34530
+ throw new PluginAssetIntegrityError(`Archive did not contain ${PLUGIN_DLL_NAME}.`);
34255
34531
  }
34256
34532
  } else {
34257
- const isPe = bytes[0] === 77 && bytes[1] === 90;
34258
- if (!isPe) {
34259
- throw new Error(`Artifact is neither a PE DLL nor a ZIP archive containing ${PLUGIN_DLL_NAME}.`);
34260
- }
34261
34533
  dllBytes = bytes;
34262
34534
  }
34535
+ return verifyExtractedDllBytes(dllBytes, expectedSha256);
34536
+ }
34537
+ function verifyExtractedDllBytes(dllBytes, expectedSha256) {
34538
+ if (dllBytes.length < 2 || dllBytes[0] !== 77 || dllBytes[1] !== 90) {
34539
+ throw new PluginAssetIntegrityError(`Artifact is not a valid PE DLL (${PLUGIN_DLL_NAME}).`);
34540
+ }
34263
34541
  const actualSha256 = computeBufferSha256(dllBytes);
34264
34542
  const expectedList = normalizeExpectedShaList(expectedSha256);
34265
34543
  if (expectedList.length > 0 && !expectedList.includes(actualSha256)) {
34266
- throw new Error(
34544
+ throw new PluginAssetIntegrityError(
34267
34545
  `Plugin DLL SHA-256 mismatch. Expected ${expectedList.join(" or ")}, actual ${actualSha256}.`
34268
34546
  );
34269
34547
  }
34270
34548
  return { dllBytes, sha256: actualSha256 };
34271
34549
  }
34550
+ function matchSig4(bytes, pos, b0, b1, b2, b3) {
34551
+ return pos >= 0 && pos + 3 < bytes.length && bytes[pos] === b0 && bytes[pos + 1] === b1 && bytes[pos + 2] === b2 && bytes[pos + 3] === b3;
34552
+ }
34553
+ function parseEocdTail(tail, totalLength) {
34554
+ const minIdx = Math.max(0, tail.length - 65560);
34555
+ let eocdPos = -1;
34556
+ for (let i = tail.length - 4; i >= minIdx; i -= 1) {
34557
+ if (matchSig4(tail, i, 80, 75, 5, 6)) {
34558
+ eocdPos = i;
34559
+ break;
34560
+ }
34561
+ }
34562
+ if (eocdPos < 0 || eocdPos + 22 > tail.length) {
34563
+ return null;
34564
+ }
34565
+ const dv = new DataView(tail.buffer, tail.byteOffset, tail.byteLength);
34566
+ const cdSize = dv.getUint32(eocdPos + 12, true);
34567
+ const cdOffset = dv.getUint32(eocdPos + 16, true);
34568
+ if (cdSize !== 4294967295 && cdOffset !== 4294967295) {
34569
+ return { cdSize, cdOffset };
34570
+ }
34571
+ const locPos = eocdPos - 20;
34572
+ if (locPos < 0 || !matchSig4(tail, locPos, 80, 75, 6, 7)) {
34573
+ return null;
34574
+ }
34575
+ const eocd64Offset = Number(dv.getBigUint64(locPos + 8, true));
34576
+ if (!Number.isSafeInteger(eocd64Offset) || eocd64Offset < 0 || eocd64Offset + 56 > totalLength) {
34577
+ return null;
34578
+ }
34579
+ return { cdSize, cdOffset, eocd64Offset };
34580
+ }
34581
+ function parseEocd64Header(buf) {
34582
+ if (buf.length < 56 || !matchSig4(buf, 0, 80, 75, 6, 6)) {
34583
+ return null;
34584
+ }
34585
+ const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
34586
+ const cdSize = Number(dv.getBigUint64(40, true));
34587
+ const cdOffset = Number(dv.getBigUint64(48, true));
34588
+ if (!Number.isSafeInteger(cdSize) || !Number.isSafeInteger(cdOffset)) {
34589
+ return null;
34590
+ }
34591
+ return { cdSize, cdOffset };
34592
+ }
34593
+ function findPluginEntryInCd(cd) {
34594
+ const dv = new DataView(cd.buffer, cd.byteOffset, cd.byteLength);
34595
+ let pos = 0;
34596
+ while (pos + 46 <= cd.length) {
34597
+ if (!matchSig4(cd, pos, 80, 75, 1, 2)) {
34598
+ break;
34599
+ }
34600
+ const compMethod = dv.getUint16(pos + 10, true);
34601
+ let compSize = dv.getUint32(pos + 20, true);
34602
+ let uncompSize = dv.getUint32(pos + 24, true);
34603
+ const fileNameLength = dv.getUint16(pos + 28, true);
34604
+ const extraLength = dv.getUint16(pos + 30, true);
34605
+ const commentLength = dv.getUint16(pos + 32, true);
34606
+ let localHeaderOffset = dv.getUint32(pos + 42, true);
34607
+ const entryEnd = pos + 46 + fileNameLength + extraLength + commentLength;
34608
+ if (entryEnd > cd.length) {
34609
+ break;
34610
+ }
34611
+ const name = Buffer.from(cd.buffer, cd.byteOffset + pos + 46, fileNameLength).toString("utf8");
34612
+ if (isPluginDllZipEntry(name)) {
34613
+ if (uncompSize === 4294967295 || compSize === 4294967295 || localHeaderOffset === 4294967295) {
34614
+ let extraPos = pos + 46 + fileNameLength;
34615
+ const extraEnd = extraPos + extraLength;
34616
+ while (extraPos + 4 <= extraEnd) {
34617
+ const headerId = dv.getUint16(extraPos, true);
34618
+ const fieldSize = dv.getUint16(extraPos + 2, true);
34619
+ const fieldData = extraPos + 4;
34620
+ if (fieldData + fieldSize > extraEnd) break;
34621
+ if (headerId === 1) {
34622
+ let cursor = fieldData;
34623
+ if (uncompSize === 4294967295 && cursor + 8 <= fieldData + fieldSize) {
34624
+ uncompSize = Number(dv.getBigUint64(cursor, true));
34625
+ cursor += 8;
34626
+ }
34627
+ if (compSize === 4294967295 && cursor + 8 <= fieldData + fieldSize) {
34628
+ compSize = Number(dv.getBigUint64(cursor, true));
34629
+ cursor += 8;
34630
+ }
34631
+ if (localHeaderOffset === 4294967295 && cursor + 8 <= fieldData + fieldSize) {
34632
+ localHeaderOffset = Number(dv.getBigUint64(cursor, true));
34633
+ }
34634
+ break;
34635
+ }
34636
+ extraPos = fieldData + fieldSize;
34637
+ }
34638
+ }
34639
+ return { compMethod, compSize, uncompSize, fileNameLength, localHeaderOffset };
34640
+ }
34641
+ pos = entryEnd;
34642
+ }
34643
+ return null;
34644
+ }
34645
+ function decodePluginLocalEntry(localChunk, entry) {
34646
+ if (entry.compSize < 0 || entry.compSize > MAX_DLL_BYTES || entry.uncompSize > MAX_DLL_BYTES) {
34647
+ throw new PluginAssetIntegrityError(`ZIP entry size exceeds allowed limit (${MAX_DLL_BYTES} bytes).`);
34648
+ }
34649
+ if (localChunk.length < 30 || !matchSig4(localChunk, 0, 80, 75, 3, 4)) {
34650
+ throw new PluginAssetIntegrityError("Invalid ZIP local file header.");
34651
+ }
34652
+ const dv = new DataView(localChunk.buffer, localChunk.byteOffset, localChunk.byteLength);
34653
+ const lhNameLen = dv.getUint16(26, true);
34654
+ const lhExtraLen = dv.getUint16(28, true);
34655
+ const dataOffset = 30 + lhNameLen + lhExtraLen;
34656
+ const neededLength = dataOffset + entry.compSize;
34657
+ if (neededLength > localChunk.length) {
34658
+ return { ok: false, neededLength };
34659
+ }
34660
+ const payload = localChunk.subarray(dataOffset, neededLength);
34661
+ if (entry.compMethod === 0) {
34662
+ return { ok: true, dllBytes: Uint8Array.from(payload) };
34663
+ }
34664
+ if (entry.compMethod === 8) {
34665
+ return { ok: true, dllBytes: new Uint8Array(inflateRawSync(payload, { maxOutputLength: MAX_DLL_BYTES })) };
34666
+ }
34667
+ throw new PluginAssetIntegrityError(`Unsupported ZIP compression method: ${entry.compMethod}.`);
34668
+ }
34669
+ function readFdSlice(fd, start, endInclusive) {
34670
+ const length = Math.max(0, endInclusive - start + 1);
34671
+ const buf = Buffer.allocUnsafe(length);
34672
+ let totalRead = 0;
34673
+ while (totalRead < length) {
34674
+ const n = readSync(fd, buf, totalRead, length - totalRead, start + totalRead);
34675
+ if (n <= 0) break;
34676
+ totalRead += n;
34677
+ }
34678
+ return totalRead === length ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : new Uint8Array(buf.subarray(0, totalRead));
34679
+ }
34680
+ function tryExtractPluginFromLocalZipFast(filePath, expectedSha256) {
34681
+ const stats = statSync2(filePath);
34682
+ if (stats.size <= 22 || stats.size > MAX_ZIP_INSPECT_BYTES) {
34683
+ return null;
34684
+ }
34685
+ const fd = openSync(filePath, "r");
34686
+ try {
34687
+ const tailSize = Math.min(65536, stats.size);
34688
+ const tailStart = stats.size - tailSize;
34689
+ const tail = readFdSlice(fd, tailStart, stats.size - 1);
34690
+ const eocd = parseEocdTail(tail, stats.size);
34691
+ if (!eocd) return null;
34692
+ let cdSize = eocd.cdSize;
34693
+ let cdOffset = eocd.cdOffset;
34694
+ if (eocd.eocd64Offset !== void 0) {
34695
+ const eocd64 = parseEocd64Header(readFdSlice(fd, eocd.eocd64Offset, eocd.eocd64Offset + 55));
34696
+ if (!eocd64) return null;
34697
+ cdSize = eocd64.cdSize;
34698
+ cdOffset = eocd64.cdOffset;
34699
+ }
34700
+ if (cdSize <= 0 || cdSize > 32 * 1024 * 1024 || cdOffset < 0 || cdOffset + cdSize > stats.size) {
34701
+ return null;
34702
+ }
34703
+ const cd = cdOffset >= tailStart && cdOffset + cdSize <= stats.size ? tail.subarray(cdOffset - tailStart, cdOffset - tailStart + cdSize) : readFdSlice(fd, cdOffset, cdOffset + cdSize - 1);
34704
+ const entry = findPluginEntryInCd(cd);
34705
+ if (!entry) {
34706
+ throw new PluginAssetIntegrityError(`Archive did not contain ${PLUGIN_DLL_NAME}.`);
34707
+ }
34708
+ if (entry.compSize <= 0 || entry.compSize > 50 * 1024 * 1024) {
34709
+ return null;
34710
+ }
34711
+ const probeEnd = Math.min(stats.size - 1, entry.localHeaderOffset + 30 + entry.fileNameLength + 1024 + entry.compSize - 1);
34712
+ let localChunk = readFdSlice(fd, entry.localHeaderOffset, probeEnd);
34713
+ let decoded = decodePluginLocalEntry(localChunk, entry);
34714
+ if (!decoded.ok) {
34715
+ const exactEnd = entry.localHeaderOffset + decoded.neededLength - 1;
34716
+ if (exactEnd >= stats.size) return null;
34717
+ localChunk = readFdSlice(fd, entry.localHeaderOffset, exactEnd);
34718
+ decoded = decodePluginLocalEntry(localChunk, entry);
34719
+ if (!decoded.ok) return null;
34720
+ }
34721
+ return verifyExtractedDllBytes(decoded.dllBytes, expectedSha256);
34722
+ } finally {
34723
+ closeSync(fd);
34724
+ }
34725
+ }
34726
+ async function downloadPluginDllViaHttpRange(parsedUrl, acceptedShas, fetchFn, timeoutMs) {
34727
+ const { response: headRes, finalUrl } = await fetchFollowingValidatedRedirects(
34728
+ parsedUrl,
34729
+ { method: "HEAD" },
34730
+ fetchFn,
34731
+ timeoutMs
34732
+ );
34733
+ await headRes.body?.cancel?.().catch(() => {
34734
+ });
34735
+ if (!headRes.ok) {
34736
+ return null;
34737
+ }
34738
+ const contentLength = Number.parseInt(headRes.headers.get("content-length") ?? "", 10);
34739
+ const acceptRanges = headRes.headers.get("accept-ranges") ?? "";
34740
+ if (!Number.isFinite(contentLength) || contentLength <= 22 || !/\bbytes\b/iu.test(acceptRanges)) {
34741
+ return null;
34742
+ }
34743
+ const fetchRange = async (start, endInclusive) => {
34744
+ const { response: res } = await fetchFollowingValidatedRedirects(
34745
+ finalUrl,
34746
+ {
34747
+ method: "GET",
34748
+ headers: {
34749
+ Range: `bytes=${start}-${endInclusive}`,
34750
+ "Accept-Encoding": "identity"
34751
+ }
34752
+ },
34753
+ fetchFn,
34754
+ timeoutMs
34755
+ );
34756
+ if (res.status !== 206) {
34757
+ await res.body?.cancel?.().catch(() => {
34758
+ });
34759
+ return null;
34760
+ }
34761
+ return readResponseBytesBounded(res, Math.min(MAX_ZIP_INSPECT_BYTES, endInclusive - start + 1 + 1024));
34762
+ };
34763
+ const tailSize = Math.min(65536, contentLength);
34764
+ const tailStart = contentLength - tailSize;
34765
+ const tail = await fetchRange(tailStart, contentLength - 1);
34766
+ if (!tail) return null;
34767
+ const eocd = parseEocdTail(tail, contentLength);
34768
+ if (!eocd) return null;
34769
+ let cdSize = eocd.cdSize;
34770
+ let cdOffset = eocd.cdOffset;
34771
+ if (eocd.eocd64Offset !== void 0) {
34772
+ const eocd64Slice = await fetchRange(eocd.eocd64Offset, Math.min(contentLength - 1, eocd.eocd64Offset + 55));
34773
+ if (!eocd64Slice) return null;
34774
+ const eocd64 = parseEocd64Header(eocd64Slice);
34775
+ if (!eocd64) return null;
34776
+ cdSize = eocd64.cdSize;
34777
+ cdOffset = eocd64.cdOffset;
34778
+ }
34779
+ if (cdSize <= 0 || cdSize > 32 * 1024 * 1024 || cdOffset < 0 || cdOffset + cdSize > contentLength) {
34780
+ return null;
34781
+ }
34782
+ const cd = cdOffset >= tailStart && cdOffset + cdSize <= contentLength ? tail.subarray(cdOffset - tailStart, cdOffset - tailStart + cdSize) : await fetchRange(cdOffset, cdOffset + cdSize - 1);
34783
+ if (!cd) return null;
34784
+ const entry = findPluginEntryInCd(cd);
34785
+ if (!entry) {
34786
+ throw new PluginAssetIntegrityError(`Archive did not contain ${PLUGIN_DLL_NAME}.`);
34787
+ }
34788
+ if (entry.compSize <= 0 || entry.compSize > 50 * 1024 * 1024) {
34789
+ return null;
34790
+ }
34791
+ const probeEnd = Math.min(
34792
+ contentLength - 1,
34793
+ entry.localHeaderOffset + 30 + entry.fileNameLength + 1024 + entry.compSize - 1
34794
+ );
34795
+ let localChunk = await fetchRange(entry.localHeaderOffset, probeEnd);
34796
+ if (!localChunk) return null;
34797
+ let decoded = decodePluginLocalEntry(localChunk, entry);
34798
+ if (!decoded.ok) {
34799
+ const exactEnd = entry.localHeaderOffset + decoded.neededLength - 1;
34800
+ if (exactEnd >= contentLength) return null;
34801
+ localChunk = await fetchRange(entry.localHeaderOffset, exactEnd);
34802
+ if (!localChunk) return null;
34803
+ decoded = decodePluginLocalEntry(localChunk, entry);
34804
+ if (!decoded.ok) return null;
34805
+ }
34806
+ return verifyExtractedDllBytes(decoded.dllBytes, acceptedShas);
34807
+ }
34808
+ async function tryDownloadViaWindowsHelper(options) {
34809
+ if (process.platform !== "win32") {
34810
+ return null;
34811
+ }
34812
+ let helperPath = options.helperExecutablePath ?? null;
34813
+ if (!helperPath) {
34814
+ try {
34815
+ helperPath = ensureRunnableHelperBinary({
34816
+ dataDir: options.dataDir,
34817
+ ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot }
34818
+ });
34819
+ } catch {
34820
+ helperPath = null;
34821
+ }
34822
+ }
34823
+ if (!helperPath || !existsSync4(helperPath)) {
34824
+ return null;
34825
+ }
34826
+ const tmpDir = join5(options.dataDir, "tmp");
34827
+ mkdirSync3(tmpDir, { recursive: true });
34828
+ const tempOut = join5(tmpDir, `fetch-dll-${randomUUID4()}.dll`);
34829
+ try {
34830
+ const { stdout } = await execFileAsync(
34831
+ helperPath,
34832
+ [
34833
+ "--fetch-plugin-dll",
34834
+ "--url",
34835
+ options.url,
34836
+ "--out",
34837
+ tempOut,
34838
+ ...options.acceptedShas.length > 0 ? ["--sha256", options.acceptedShas.join(",")] : []
34839
+ ],
34840
+ {
34841
+ encoding: "utf8",
34842
+ windowsHide: true,
34843
+ timeout: Math.max(options.timeoutMs, 45e3)
34844
+ }
34845
+ );
34846
+ const line = stdout.trim().split(/\r?\n/u).pop() ?? "";
34847
+ if (line.startsWith("{")) {
34848
+ const parsed = JSON.parse(line);
34849
+ if (parsed.ok === false) {
34850
+ if (parsed.error && /SHA-256 mismatch|Archive did not contain|not a valid/iu.test(parsed.error)) {
34851
+ throw new PluginAssetIntegrityError(parsed.error);
34852
+ }
34853
+ throw new Error(parsed.error || "Windows helper asset fetch failed.");
34854
+ }
34855
+ }
34856
+ if (!existsSync4(tempOut)) {
34857
+ throw new Error("Windows helper fetch completed without output file.");
34858
+ }
34859
+ const dllBytes = new Uint8Array(readFileSync5(tempOut));
34860
+ return verifyExtractedDllBytes(dllBytes, options.acceptedShas);
34861
+ } finally {
34862
+ if (existsSync4(tempOut)) {
34863
+ rmSync2(tempOut, { force: true });
34864
+ }
34865
+ }
34866
+ }
34272
34867
  function defaultDiscoveryCandidates() {
34273
34868
  const results = [];
34274
34869
  if (process.env.LOCALAPPDATA) {
@@ -34293,35 +34888,41 @@ function getPluginAssetCachePath(dataDir, version2 = DEFAULT_PLUGIN_DLL_MANIFEST
34293
34888
  function writeAtomicCacheDll(cachePath, dllBytes) {
34294
34889
  mkdirSync3(dirname4(cachePath), { recursive: true });
34295
34890
  const temp = `${cachePath}.${randomUUID4()}.tmp`;
34296
- writeFileSync3(temp, dllBytes);
34297
- renameSync2(temp, cachePath);
34891
+ try {
34892
+ writeFileSync3(temp, dllBytes);
34893
+ renameSync2(temp, cachePath);
34894
+ } catch (error2) {
34895
+ rmSync2(temp, { force: true });
34896
+ throw error2;
34897
+ }
34898
+ }
34899
+ function readHeadTwoBytes(filePath) {
34900
+ const fd = openSync(filePath, "r");
34901
+ try {
34902
+ const buf = Buffer.allocUnsafe(2);
34903
+ const n = readSync(fd, buf, 0, 2, 0);
34904
+ if (n < 2) return null;
34905
+ return [buf[0] ?? 0, buf[1] ?? 0];
34906
+ } finally {
34907
+ closeSync(fd);
34908
+ }
34909
+ }
34910
+ function extractFromLocalZip(filePath, expectedSha256) {
34911
+ const fast = tryExtractPluginFromLocalZipFast(filePath, expectedSha256);
34912
+ if (fast) return fast;
34913
+ return extractPluginDllFromBytes(readFileSync5(filePath), expectedSha256);
34298
34914
  }
34299
- function inspectCandidateFile(filePath, source, acceptedShas, maxZipHashBytes) {
34915
+ function inspectCandidateFile(filePath, source, acceptedShas) {
34300
34916
  try {
34301
34917
  const resolved = resolve3(filePath);
34302
34918
  if (!existsSync4(resolved)) return null;
34303
34919
  const stats = statSync2(resolved);
34304
- if (!stats.isFile()) return null;
34305
- const lower = resolved.toLowerCase();
34306
- let isZip = lower.endsWith(".zip");
34307
- if (!isZip && stats.size >= 2) {
34308
- const head = readFileSync5(resolved).subarray(0, 2);
34309
- isZip = head[0] === 80 && head[1] === 75;
34310
- }
34920
+ if (!stats.isFile() || stats.size < 2) return null;
34921
+ const head = readHeadTwoBytes(resolved);
34922
+ const isZip = resolved.toLowerCase().endsWith(".zip") || head !== null && head[0] === 80 && head[1] === 75;
34311
34923
  if (isZip) {
34312
34924
  if (stats.size > MAX_ZIP_INSPECT_BYTES) return null;
34313
- if (stats.size > maxZipHashBytes) {
34314
- return {
34315
- path: resolved,
34316
- kind: "zip",
34317
- source,
34318
- sha256: "",
34319
- sha256MatchesExpected: false,
34320
- sizeBytes: stats.size
34321
- };
34322
- }
34323
- const bytes2 = readFileSync5(resolved);
34324
- const { sha256: sha2562 } = extractPluginDllFromBytes(bytes2);
34925
+ const { sha256: sha2562 } = extractFromLocalZip(resolved);
34325
34926
  return {
34326
34927
  path: resolved,
34327
34928
  kind: "zip",
@@ -34331,10 +34932,10 @@ function inspectCandidateFile(filePath, source, acceptedShas, maxZipHashBytes) {
34331
34932
  sizeBytes: stats.size
34332
34933
  };
34333
34934
  }
34334
- const bytes = readFileSync5(resolved);
34335
- if (bytes.length < 2 || bytes[0] !== 77 || bytes[1] !== 90) {
34935
+ if (head === null || head[0] !== 77 || head[1] !== 90) {
34336
34936
  return null;
34337
34937
  }
34938
+ const bytes = readFileSync5(resolved);
34338
34939
  const sha256 = computeBufferSha256(bytes);
34339
34940
  return {
34340
34941
  path: resolved,
@@ -34363,16 +34964,16 @@ function discoverLocalPluginDllCandidates(options = {}) {
34363
34964
  };
34364
34965
  const explicitPath = (options.dllPath ?? process.env.MEMOQ_PLUGIN_DLL_PATH ?? "").trim();
34365
34966
  if (explicitPath) {
34366
- pushCandidate(inspectCandidateFile(explicitPath, "explicit", acceptedShas, MAX_ZIP_INSPECT_BYTES));
34967
+ pushCandidate(inspectCandidateFile(explicitPath, "explicit", acceptedShas));
34367
34968
  }
34368
34969
  const cachePath = getPluginAssetCachePath(dataDir, version2);
34369
- pushCandidate(inspectCandidateFile(cachePath, "cache", acceptedShas, MAX_FAST_ZIP_HASH_BYTES));
34970
+ pushCandidate(inspectCandidateFile(cachePath, "cache", acceptedShas));
34370
34971
  for (const hubCandidate of defaultDiscoveryCandidates()) {
34371
- pushCandidate(inspectCandidateFile(hubCandidate, "memoq-ai-hub", acceptedShas, MAX_FAST_ZIP_HASH_BYTES));
34972
+ pushCandidate(inspectCandidateFile(hubCandidate, "memoq-ai-hub", acceptedShas));
34372
34973
  }
34373
34974
  for (const extra of options.extraFilePaths ?? []) {
34374
34975
  if (!extra?.trim()) continue;
34375
- pushCandidate(inspectCandidateFile(extra, "memoq-addins", acceptedShas, MAX_FAST_ZIP_HASH_BYTES));
34976
+ pushCandidate(inspectCandidateFile(extra, "memoq-addins", acceptedShas));
34376
34977
  }
34377
34978
  const rawDirs = [...options.searchDirs ?? []];
34378
34979
  if (options.includeDefaultUserDirs !== false) {
@@ -34395,16 +34996,24 @@ function discoverLocalPluginDllCandidates(options = {}) {
34395
34996
  try {
34396
34997
  const entries = readdirSync(resolvedDir, { withFileTypes: true }).slice(0, MAX_DISCOVERY_DIR_ENTRIES);
34397
34998
  for (const entry of entries) {
34398
- if (!entry.isFile()) continue;
34399
- const lowerName = entry.name.toLowerCase();
34400
- if (lowerName === PLUGIN_DLL_NAME.toLowerCase()) {
34401
- pushCandidate(
34402
- inspectCandidateFile(join5(resolvedDir, entry.name), "local-folder", acceptedShas, MAX_FAST_ZIP_HASH_BYTES)
34403
- );
34404
- } else if (lowerName.endsWith(".zip") && ZIP_CANDIDATE_NAME_RE.test(entry.name)) {
34405
- pushCandidate(
34406
- inspectCandidateFile(join5(resolvedDir, entry.name), "local-folder", acceptedShas, MAX_FAST_ZIP_HASH_BYTES)
34407
- );
34999
+ if (entry.isFile()) {
35000
+ const lowerName = entry.name.toLowerCase();
35001
+ if (lowerName === PLUGIN_DLL_NAME.toLowerCase()) {
35002
+ pushCandidate(inspectCandidateFile(join5(resolvedDir, entry.name), "local-folder", acceptedShas));
35003
+ } else if (lowerName.endsWith(".zip") && ZIP_CANDIDATE_NAME_RE.test(entry.name)) {
35004
+ pushCandidate(inspectCandidateFile(join5(resolvedDir, entry.name), "local-folder", acceptedShas));
35005
+ }
35006
+ continue;
35007
+ }
35008
+ if (entry.isDirectory() && /memoq/iu.test(entry.name)) {
35009
+ const subDir = join5(resolvedDir, entry.name);
35010
+ for (const rel of [
35011
+ PLUGIN_DLL_NAME,
35012
+ join5("resources", PLUGIN_DLL_NAME),
35013
+ join5("resources", "memoq-integration", PLUGIN_DLL_NAME)
35014
+ ]) {
35015
+ pushCandidate(inspectCandidateFile(join5(subDir, rel), "local-folder", acceptedShas));
35016
+ }
34408
35017
  }
34409
35018
  }
34410
35019
  } catch {
@@ -34428,81 +35037,83 @@ async function resolvePluginDllAsset(options = {}) {
34428
35037
  if (!existsSync4(resolved)) {
34429
35038
  throw new Error(`Configured MEMOQ_PLUGIN_DLL_PATH does not exist: ${resolved}`);
34430
35039
  }
34431
- const rawBytes2 = readFileSync5(resolved);
34432
- const isZip = rawBytes2.length >= 2 && rawBytes2[0] === 80 && rawBytes2[1] === 75;
35040
+ const head = readHeadTwoBytes(resolved);
35041
+ const isZip = resolved.toLowerCase().endsWith(".zip") || head !== null && head[0] === 80 && head[1] === 75;
34433
35042
  if (isZip) {
34434
- const extracted = extractPluginDllFromBytes(
34435
- rawBytes2,
35043
+ const extracted2 = extractFromLocalZip(
35044
+ resolved,
34436
35045
  options.allowUnverifiedLocalDev ? void 0 : acceptedShas
34437
35046
  );
34438
- writeAtomicCacheDll(cachePath, extracted.dllBytes);
35047
+ writeAtomicCacheDll(cachePath, extracted2.dllBytes);
34439
35048
  return {
34440
35049
  path: cachePath,
34441
- sha256: extracted.sha256,
35050
+ sha256: extracted2.sha256,
34442
35051
  version: version2,
34443
35052
  source: "explicit",
34444
- verified: acceptedShas.includes(extracted.sha256)
35053
+ verified: acceptedShas.includes(extracted2.sha256)
34445
35054
  };
34446
35055
  }
34447
- const isPe = rawBytes2.length >= 2 && rawBytes2[0] === 77 && rawBytes2[1] === 90;
34448
- if (!isPe) {
35056
+ if (head === null || head[0] !== 77 || head[1] !== 90) {
34449
35057
  throw new Error(`File is neither a PE DLL nor a ZIP archive containing ${PLUGIN_DLL_NAME}: ${resolved}`);
34450
35058
  }
34451
- const sha2562 = computeBufferSha256(rawBytes2);
34452
- const verified = acceptedShas.includes(sha2562);
35059
+ const rawBytes = readFileSync5(resolved);
35060
+ const sha256 = computeBufferSha256(rawBytes);
35061
+ const verified = acceptedShas.includes(sha256);
34453
35062
  if (!options.allowUnverifiedLocalDev && acceptedShas.length > 0 && !verified) {
34454
- throw new Error(`Plugin DLL SHA-256 mismatch at ${resolved}. Expected ${expectedDisplay}, actual ${sha2562}.`);
35063
+ throw new Error(`Plugin DLL SHA-256 mismatch at ${resolved}. Expected ${expectedDisplay}, actual ${sha256}.`);
34455
35064
  }
34456
35065
  return {
34457
35066
  path: resolved,
34458
- sha256: sha2562,
35067
+ sha256,
34459
35068
  version: version2,
34460
35069
  source: "explicit",
34461
35070
  verified
34462
35071
  };
34463
35072
  }
34464
35073
  if (existsSync4(cachePath)) {
34465
- const sha2562 = computeFileSha256(cachePath);
34466
- if (acceptedShas.length === 0 || acceptedShas.includes(sha2562)) {
35074
+ const sha256 = computeFileSha256(cachePath);
35075
+ if (acceptedShas.length === 0 || acceptedShas.includes(sha256)) {
34467
35076
  return {
34468
35077
  path: cachePath,
34469
- sha256: sha2562,
35078
+ sha256,
34470
35079
  version: version2,
34471
35080
  source: "cache",
34472
- verified: acceptedShas.includes(sha2562)
35081
+ verified: acceptedShas.includes(sha256)
34473
35082
  };
34474
35083
  }
34475
35084
  }
34476
35085
  const discoveryPaths = [...options.searchPaths ?? [], ...defaultDiscoveryCandidates()];
34477
35086
  for (const candidate of discoveryPaths) {
34478
35087
  if (!candidate || !existsSync4(candidate)) continue;
34479
- const rawBytes2 = readFileSync5(candidate);
34480
- const isZip = rawBytes2.length >= 2 && rawBytes2[0] === 80 && rawBytes2[1] === 75;
34481
- if (isZip) {
34482
- try {
34483
- const extracted = extractPluginDllFromBytes(rawBytes2, acceptedShas);
34484
- writeAtomicCacheDll(cachePath, extracted.dllBytes);
35088
+ try {
35089
+ const head = readHeadTwoBytes(candidate);
35090
+ const isZip = candidate.toLowerCase().endsWith(".zip") || head !== null && head[0] === 80 && head[1] === 75;
35091
+ if (isZip) {
35092
+ const extracted2 = extractFromLocalZip(candidate, acceptedShas);
35093
+ writeAtomicCacheDll(cachePath, extracted2.dllBytes);
34485
35094
  return {
34486
35095
  path: cachePath,
34487
- sha256: extracted.sha256,
35096
+ sha256: extracted2.sha256,
34488
35097
  version: version2,
34489
35098
  source: "local-discovery",
34490
35099
  verified: true
34491
35100
  };
34492
- } catch {
34493
- continue;
34494
35101
  }
35102
+ if (head === null || head[0] !== 77 || head[1] !== 90) continue;
35103
+ const rawBytes = readFileSync5(candidate);
35104
+ const sha256 = computeBufferSha256(rawBytes);
35105
+ if (acceptedShas.length > 0 && !acceptedShas.includes(sha256)) continue;
35106
+ writeAtomicCacheDll(cachePath, rawBytes);
35107
+ return {
35108
+ path: cachePath,
35109
+ sha256,
35110
+ version: version2,
35111
+ source: "local-discovery",
35112
+ verified: true
35113
+ };
35114
+ } catch {
35115
+ continue;
34495
35116
  }
34496
- const sha2562 = computeBufferSha256(rawBytes2);
34497
- if (acceptedShas.length > 0 && !acceptedShas.includes(sha2562)) continue;
34498
- writeAtomicCacheDll(cachePath, rawBytes2);
34499
- return {
34500
- path: cachePath,
34501
- sha256: sha2562,
34502
- version: version2,
34503
- source: "local-discovery",
34504
- verified: true
34505
- };
34506
35117
  }
34507
35118
  if (options.searchDirs && options.searchDirs.length > 0 || options.includeDefaultUserDirs === true) {
34508
35119
  const folderCandidates = discoverLocalPluginDllCandidates({
@@ -34514,24 +35125,24 @@ async function resolvePluginDllAsset(options = {}) {
34514
35125
  });
34515
35126
  for (const candidate of folderCandidates) {
34516
35127
  try {
34517
- const rawBytes2 = readFileSync5(candidate.path);
34518
35128
  if (candidate.kind === "zip") {
34519
- const extracted = extractPluginDllFromBytes(rawBytes2, acceptedShas);
34520
- writeAtomicCacheDll(cachePath, extracted.dllBytes);
35129
+ const extracted2 = extractFromLocalZip(candidate.path, acceptedShas);
35130
+ writeAtomicCacheDll(cachePath, extracted2.dllBytes);
34521
35131
  return {
34522
35132
  path: cachePath,
34523
- sha256: extracted.sha256,
35133
+ sha256: extracted2.sha256,
34524
35134
  version: version2,
34525
35135
  source: "local-discovery",
34526
35136
  verified: true
34527
35137
  };
34528
35138
  }
34529
- const sha2562 = computeBufferSha256(rawBytes2);
34530
- if (acceptedShas.length > 0 && !acceptedShas.includes(sha2562)) continue;
34531
- writeAtomicCacheDll(cachePath, rawBytes2);
35139
+ const rawBytes = readFileSync5(candidate.path);
35140
+ const sha256 = computeBufferSha256(rawBytes);
35141
+ if (acceptedShas.length > 0 && !acceptedShas.includes(sha256)) continue;
35142
+ writeAtomicCacheDll(cachePath, rawBytes);
34532
35143
  return {
34533
35144
  path: cachePath,
34534
- sha256: sha2562,
35145
+ sha256,
34535
35146
  version: version2,
34536
35147
  source: "local-discovery",
34537
35148
  verified: true
@@ -34549,30 +35160,78 @@ async function resolvePluginDllAsset(options = {}) {
34549
35160
  const rawUrl = (options.downloadUrl ?? process.env.MEMOQ_PLUGIN_DLL_URL ?? DEFAULT_PLUGIN_DLL_MANIFEST.downloadUrl).trim();
34550
35161
  const parsedUrl = parseAllowedAssetUrl(rawUrl);
34551
35162
  const fetchFn = options.fetchImpl ?? fetch;
34552
- const response = await fetchFn(parsedUrl, { redirect: "follow" });
34553
- if (!response.ok) {
34554
- throw new Error(`Failed to download ${PLUGIN_DLL_NAME} (${response.status} ${response.statusText}).`);
35163
+ const timeoutMs = options.timeoutMs ?? DEFAULT_DOWNLOAD_TIMEOUT_MS;
35164
+ let extracted = null;
35165
+ let primaryError = null;
35166
+ try {
35167
+ extracted = await downloadPluginDllViaHttpRange(parsedUrl, acceptedShas, fetchFn, timeoutMs);
35168
+ if (!extracted) {
35169
+ const { response } = await fetchFollowingValidatedRedirects(parsedUrl, { method: "GET" }, fetchFn, timeoutMs);
35170
+ if (!response.ok) {
35171
+ await response.body?.cancel?.().catch(() => {
35172
+ });
35173
+ throw new Error(`Failed to download ${PLUGIN_DLL_NAME} (${response.status} ${response.statusText}).`);
35174
+ }
35175
+ const rawBytes = await readResponseBytesBounded(response, MAX_ZIP_INSPECT_BYTES);
35176
+ extracted = extractPluginDllFromBytes(rawBytes, acceptedShas);
35177
+ }
35178
+ } catch (error2) {
35179
+ if (error2 instanceof PluginAssetIntegrityError || error2 instanceof PluginAssetPolicyError) {
35180
+ throw error2;
35181
+ }
35182
+ primaryError = error2 instanceof Error ? error2 : new Error(String(error2));
34555
35183
  }
34556
- const rawBytes = new Uint8Array(await response.arrayBuffer());
34557
- const { dllBytes, sha256 } = extractPluginDllFromBytes(rawBytes, acceptedShas);
34558
- writeAtomicCacheDll(cachePath, dllBytes);
35184
+ if (!extracted && options.fetchImpl === void 0 && process.platform === "win32") {
35185
+ try {
35186
+ extracted = await tryDownloadViaWindowsHelper({
35187
+ url: parsedUrl.href,
35188
+ acceptedShas,
35189
+ dataDir,
35190
+ ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
35191
+ ...options.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.helperExecutablePath },
35192
+ timeoutMs
35193
+ });
35194
+ } catch (helperError) {
35195
+ if (helperError instanceof PluginAssetIntegrityError || helperError instanceof PluginAssetPolicyError) {
35196
+ throw helperError;
35197
+ }
35198
+ const helperMsg = helperError instanceof Error ? helperError.message : String(helperError);
35199
+ const primaryMsg = primaryError?.message ?? "unknown fetch failure";
35200
+ throw new Error(
35201
+ `Unable to download ${PLUGIN_DLL_NAME} from ${parsedUrl.href}. Node fetch error: ${primaryMsg}. Windows system-proxy helper error: ${helperMsg}. Please check network/proxy access or pass a local dllPath / MEMOQ_PLUGIN_DLL_PATH.`
35202
+ );
35203
+ }
35204
+ }
35205
+ if (!extracted) {
35206
+ const primaryMsg = primaryError?.message ?? "unknown fetch failure";
35207
+ throw new Error(
35208
+ `Unable to download ${PLUGIN_DLL_NAME} from ${parsedUrl.href}: ${primaryMsg}. Please check network/proxy access or pass a local dllPath / MEMOQ_PLUGIN_DLL_PATH.`
35209
+ );
35210
+ }
35211
+ writeAtomicCacheDll(cachePath, extracted.dllBytes);
34559
35212
  return {
34560
35213
  path: cachePath,
34561
- sha256,
35214
+ sha256: extracted.sha256,
34562
35215
  version: version2,
34563
35216
  source: "downloaded",
34564
- verified: acceptedShas.includes(sha256)
35217
+ verified: acceptedShas.includes(extracted.sha256)
34565
35218
  };
34566
35219
  }
34567
35220
 
34568
35221
  // packages/memoq-bridge/src/dll-installer.ts
34569
- import { execFile, execFileSync } from "node:child_process";
35222
+ import { execFile as execFile2, execFileSync } from "node:child_process";
34570
35223
  import { randomUUID as randomUUID5 } from "node:crypto";
34571
- import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync6, rmSync as rmSync2 } from "node:fs";
35224
+ import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync6, rmSync as rmSync3 } from "node:fs";
34572
35225
  import { basename, join as join6, resolve as resolve4, win32 } from "node:path";
34573
- import { promisify } from "node:util";
34574
- var execFileAsync = promisify(execFile);
35226
+ import { promisify as promisify2 } from "node:util";
35227
+ var execFileAsync2 = promisify2(execFile2);
34575
35228
  var SUPPORTED_VERSIONS = ["12", "11", "10"];
35229
+ var MEMOQ_FIRST_TIME_RESOURCE_STEPS = [
35230
+ "\u5B8C\u5168\u5173\u95ED\u5E76\u91CD\u65B0\u542F\u52A8 memoQ\uFF08memoQ \u4EC5\u5728\u542F\u52A8\u65F6\u626B\u63CF Addins \u76EE\u5F55\u52A0\u8F7D\u65B0\u63D2\u4EF6\uFF09\u3002",
35231
+ "\u9996\u6B21\u4F7F\u7528\u9700\u5728 memoQ \u4E2D\u65B0\u5EFA MT \u8D44\u6E90\uFF1A\u6253\u5F00 Resource Console\uFF08\u8D44\u6E90\u63A7\u5236\u53F0\uFF09\u2192 MT settings \u2192 Create new\uFF08\u9009\u62E9 My Computer\uFF0C\u586B\u5199\u540D\u79F0\u5982 memoQ AI Hub / LangLink\uFF09\u3002",
35232
+ "\u7F16\u8F91\u65B0\u5EFA\u7684 MT \u8D44\u6E90\uFF1A\u52FE\u9009\u542F\u7528 memoQ AI Hub \u5E76\u70B9\u5F00\u8BBE\u7F6E\uFF08Options\uFF09\uFF0C\u786E\u8BA4 Gateway Base URL \u4E3A http://127.0.0.1:5271\u3001\u5DF2\u52FE\u9009 Enable Gateway\u3001Formatting Mode \u4FDD\u6301 BothFormattingAndTags\uFF1B\u540C\u65F6\u5728 MT \u8D44\u6E90\u9009\u9879\u4E2D\u542F\u7528 Pre-translation\u3001Match and Patch\u3001Send best fuzzy TM match \u4E0E Self-learning MT \u5E76\u4FDD\u5B58\u3002",
35233
+ "\u8BBE\u4E3A\u9ED8\u8BA4\u5E76\u542F\u7528\u5230\u5F53\u524D\u9879\u76EE\uFF1A\u5728 Options \u2192 Default resources \u2192 MT settings \u4E2D\u52FE\u9009\u8BE5\u8D44\u6E90\uFF08\u4F9B\u65B0\u9879\u76EE\u9ED8\u8BA4\u751F\u6548\uFF09\uFF1B\u5BF9\u4E8E\u5DF2\u7ECF\u521B\u5EFA\u7684\u9879\u76EE\uFF0C\u8FD8\u5FC5\u987B\u5728 Project home \u2192 Settings \u2192 MT settings \u4E2D\u52FE\u9009\u542F\u7528\u8BE5\u8D44\u6E90\uFF0C\u968F\u540E\u5373\u53EF\u5728 WorkBuddy \u653E\u884C\u8BD1\u6587\u540E\u901A\u8FC7 memoQ \u7684 Pre-translate \u5199\u5165\u3002"
35234
+ ];
34576
35235
  function defaultMemoQRooDirs() {
34577
35236
  return SUPPORTED_VERSIONS.map((version2) => ({
34578
35237
  version: version2,
@@ -34762,7 +35421,7 @@ function getIntegrationStatus(options = {}) {
34762
35421
  }
34763
35422
  async function runHelperCommand(helperPath, args, resultFile) {
34764
35423
  try {
34765
- const { stdout } = await execFileAsync(helperPath, args, {
35424
+ const { stdout } = await execFileAsync2(helperPath, args, {
34766
35425
  windowsHide: true,
34767
35426
  encoding: "utf8",
34768
35427
  timeout: 6e4
@@ -34793,7 +35452,7 @@ async function runHelperCommand(helperPath, args, resultFile) {
34793
35452
  throw new Error(err.stderr?.trim() || err.message || "Helper execution failed.");
34794
35453
  } finally {
34795
35454
  if (existsSync5(resultFile)) {
34796
- rmSync2(resultFile, { force: true });
35455
+ rmSync3(resultFile, { force: true });
34797
35456
  }
34798
35457
  }
34799
35458
  }
@@ -34943,6 +35602,7 @@ function buildPluginInstallPlan(options = {}) {
34943
35602
  selectedDllCandidate,
34944
35603
  willDownloadFromRelease,
34945
35604
  downloadUrl: DEFAULT_PLUGIN_DLL_MANIFEST.downloadUrl,
35605
+ firstTimeResourceSteps: [...MEMOQ_FIRST_TIME_RESOURCE_STEPS],
34946
35606
  plannedChanges: {
34947
35607
  sourceDllPath: selectedDllCandidate?.path ?? null,
34948
35608
  sourceKind: selectedDllCandidate ? selectedDllCandidate.kind : "release-download",
@@ -34987,6 +35647,8 @@ async function executeConfirmedPluginInstall(options = {}) {
34987
35647
  const siblingDllPaths = integrationBefore.installations.filter((item) => item.pluginInstalled).map((item) => item.pluginTarget);
34988
35648
  const sourceAsset = await resolvePluginDllAsset({
34989
35649
  ...options.dataDir === void 0 ? {} : { dataDir: options.dataDir },
35650
+ ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
35651
+ ...options.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.helperExecutablePath },
34990
35652
  ...options.dllPath === void 0 ? {} : { dllPath: options.dllPath },
34991
35653
  ...options.downloadUrl === void 0 ? {} : { downloadUrl: options.downloadUrl },
34992
35654
  ...options.expectedSha256 === void 0 ? {} : { expectedSha256: options.expectedSha256 },
@@ -35035,10 +35697,7 @@ async function executeConfirmedPluginInstall(options = {}) {
35035
35697
  sourceAsset,
35036
35698
  result,
35037
35699
  integration: integrationAfter,
35038
- nextSteps: [
35039
- "\u5B8C\u5168\u5173\u95ED\u5E76\u91CD\u65B0\u542F\u52A8 memoQ\uFF08memoQ \u4EC5\u5728\u542F\u52A8\u65F6\u626B\u63CF Addins \u76EE\u5F55\uFF09\u3002",
35040
- "\u5728 memoQ \u4E2D\u6253\u5F00 Options \u2192 Default resources \u2192 MT settings\uFF0C\u52FE\u9009\u542F\u7528 memoQ AI Hub\uFF08\u7AEF\u53E3\u4FDD\u6301 5271\uFF09\u3002"
35041
- ]
35700
+ nextSteps: [...MEMOQ_FIRST_TIME_RESOURCE_STEPS]
35042
35701
  };
35043
35702
  }
35044
35703
  async function executeConfirmedPluginUninstall(options = {}) {
@@ -35099,7 +35758,7 @@ import { dirname as dirname5 } from "node:path";
35099
35758
 
35100
35759
  // packages/memoq-bridge/src/daemon.ts
35101
35760
  import { randomBytes as randomBytes2 } from "node:crypto";
35102
- import { chmodSync, existsSync as existsSync6, readFileSync as readFileSync7, rmSync as rmSync3 } from "node:fs";
35761
+ import { chmodSync, existsSync as existsSync6, readFileSync as readFileSync7, rmSync as rmSync4 } from "node:fs";
35103
35762
  import { join as join7 } from "node:path";
35104
35763
  async function probeGatewayPort(port = DEFAULT_PORT, host = DEFAULT_HOST, timeoutMs = 1500) {
35105
35764
  const url = `http://${host}:${port}`;
@@ -35197,7 +35856,7 @@ function removeDaemonRecord(expectedToken, dataDir = defaultBridgeDataDir()) {
35197
35856
  const current = readDaemonRecord(dataDir);
35198
35857
  if (current && current.controlToken !== expectedToken) return;
35199
35858
  }
35200
- rmSync3(path, { force: true });
35859
+ rmSync4(path, { force: true });
35201
35860
  }
35202
35861
  var BridgeHttpClient = class {
35203
35862
  baseUrl;
@@ -35360,6 +36019,7 @@ async function startBridgeRuntime(options = {}) {
35360
36019
  host,
35361
36020
  port: bindPort,
35362
36021
  mode: options.mode ?? "staging",
36022
+ ...options.toolName === void 0 ? {} : { toolName: options.toolName },
35363
36023
  ...options.version === void 0 ? {} : { desktopVersion: options.version },
35364
36024
  ...persistedReviewToken ? { reviewToken: persistedReviewToken } : {},
35365
36025
  stagingStore,
@@ -35439,16 +36099,19 @@ async function readJson(request) {
35439
36099
  if (!text) return {};
35440
36100
  return JSON.parse(text);
35441
36101
  }
35442
- function escapeHtml(text) {
36102
+ function escapeHtml2(text) {
35443
36103
  return text.replace(/&/gu, "&amp;").replace(/</gu, "&lt;").replace(/>/gu, "&gt;").replace(/"/gu, "&quot;");
35444
36104
  }
35445
- function renderSetupHtml(nonce, token, initialStatus) {
36105
+ function renderSetupHtml(nonce, token, initialStatus, toolLabel) {
35446
36106
  const payloadJson = JSON.stringify({ token, initialStatus }).replace(/</gu, "\\u003c");
36107
+ const generatorMeta = toolLabel ? `
36108
+ <meta name="generator" content="${escapeHtml2(toolLabel)}" />` : "";
36109
+ const toolBadge = toolLabel ? `<span id="setup-tool-version" style="margin-left:8px;font-family:ui-monospace,Consolas,monospace;font-size:12px;">\u5DE5\u5177\u7248\u672C\uFF1A${escapeHtml2(toolLabel)}</span>` : "";
35447
36110
  return `<!DOCTYPE html>
35448
36111
  <html lang="zh-CN">
35449
36112
  <head>
35450
36113
  <meta charset="utf-8" />
35451
- <meta name="viewport" content="width=device-width, initial-scale=1" />
36114
+ <meta name="viewport" content="width=device-width, initial-scale=1" />${generatorMeta}
35452
36115
  <title>LangLink memoQ \u8FDE\u63A5\u5668\u8BBE\u7F6E\u4E0E\u8BCA\u65AD</title>
35453
36116
  <style>
35454
36117
  :root { color-scheme: light dark; --bg: #f6f7f9; --card: #ffffff; --text: #111827; --muted: #4b5563; --border: #d1d5db; --accent: #1d4ed8; --ok: #15803d; --warn: #b45309; --err: #b91c1c; }
@@ -35483,7 +36146,7 @@ function renderSetupHtml(nonce, token, initialStatus) {
35483
36146
  <body>
35484
36147
  <main>
35485
36148
  <h1>LangLink memoQ \u8FDE\u63A5\u5668 \u2014 \u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC</h1>
35486
- <p class="sub">\u900F\u660E\u5B89\u88C5 \xB7 \u96F6\u811A\u672C\u9ED1\u6846 \xB7 \u4EC5\u5728\u60A8\u70B9\u51FB\u6309\u94AE\u5E76\u786E\u8BA4\u7CFB\u7EDF UAC \u540E\u5199\u5165\u4E0B\u9762\u5217\u51FA\u7684\u4E24\u4E2A\u4F4D\u7F6E\u3002</p>
36149
+ <p class="sub">\u900F\u660E\u5B89\u88C5 \xB7 \u96F6\u811A\u672C\u9ED1\u6846 \xB7 \u4EC5\u5728\u60A8\u70B9\u51FB\u6309\u94AE\u5E76\u786E\u8BA4\u7CFB\u7EDF UAC \u540E\u5199\u5165\u4E0B\u9762\u5217\u51FA\u7684\u4E24\u4E2A\u4F4D\u7F6E\u3002${toolBadge}</p>
35487
36150
 
35488
36151
  <section class="card">
35489
36152
  <h2>1. \u5F53\u524D\u672C\u673A\u72B6\u6001</h2>
@@ -35511,11 +36174,11 @@ function renderSetupHtml(nonce, token, initialStatus) {
35511
36174
  <section class="card">
35512
36175
  <h2>3. \u900F\u660E\u53D8\u66F4\u6E05\u5355\uFF08\u70B9\u51FB\u5B89\u88C5\u524D\u8BF7\u786E\u8BA4\uFF09</h2>
35513
36176
  <ol>
35514
- <li>\u63D2\u4EF6\u6587\u4EF6\uFF1A<code>&lt;\u6240\u9009 memoQ \u6839\u76EE\u5F55&gt;\\Addins\\${escapeHtml(PLUGIN_DLL_NAME)}</code></li>
35515
- <li>\u5F00\u53D1\u914D\u7F6E\uFF1A<code>${escapeHtml(initialStatus.integration.clientDevConfig.path || "C:\\ProgramData\\MemoQ\\ClientDevConfig.xml")}</code>\uFF08\u82E5\u5DF2\u5B58\u5728\u5219\u5148\u5907\u4EFD <code>.bak</code> \u518D\u589E\u91CF\u5408\u5E76 <code>&lt;LoadUnsignedPlugins&gt;true&lt;/LoadUnsignedPlugins&gt;</code>\uFF09</li>
36177
+ <li>\u63D2\u4EF6\u6587\u4EF6\uFF1A<code>&lt;\u6240\u9009 memoQ \u6839\u76EE\u5F55&gt;\\Addins\\${escapeHtml2(PLUGIN_DLL_NAME)}</code></li>
36178
+ <li>\u5F00\u53D1\u914D\u7F6E\uFF1A<code>${escapeHtml2(initialStatus.integration.clientDevConfig.path || "C:\\ProgramData\\MemoQ\\ClientDevConfig.xml")}</code>\uFF08\u82E5\u5DF2\u5B58\u5728\u5219\u5148\u5907\u4EFD <code>.bak</code> \u518D\u589E\u91CF\u5408\u5E76 <code>&lt;LoadUnsignedPlugins&gt;true&lt;/LoadUnsignedPlugins&gt;</code>\uFF09</li>
35516
36179
  </ol>
35517
36180
  <div class="notice">
35518
- <div><strong>\u671F\u671B DLL \u7248\u672C\u4E0E\u6821\u9A8C\u503C\uFF1A</strong>v${escapeHtml(initialStatus.integration.expectedPluginVersion)} \xB7 SHA-256 <code>${escapeHtml(initialStatus.integration.expectedPluginSha256)}</code></div>
36181
+ <div><strong>\u671F\u671B DLL \u7248\u672C\u4E0E\u6821\u9A8C\u503C\uFF1A</strong>v${escapeHtml2(initialStatus.integration.expectedPluginVersion)} \xB7 SHA-256 <code>${escapeHtml2(initialStatus.integration.expectedPluginSha256)}</code></div>
35519
36182
  <div style="margin-top: 4px;"><strong>\u5B89\u5168\u627F\u8BFA\uFF1A</strong>\u4E0D\u4FEE\u6539 Windows \u6CE8\u518C\u8868 \xB7 \u4E0D\u6CE8\u518C\u5F00\u673A\u81EA\u542F\u670D\u52A1 \xB7 \u4E0D\u8BFB\u53D6\u60A8\u7684\u6A21\u578B\u5BC6\u94A5\u3002\u4F7F\u7528\u7EAF .NET \u539F\u751F\u62F7\u8D1D\u5E76\u81EA\u52A8\u6E05\u9664\u6587\u4EF6\u9501\u5B9A\u6807\u8BB0\uFF08MOTW\uFF09\u3002</div>
35520
36183
  </div>
35521
36184
  <div class="row">
@@ -35526,28 +36189,34 @@ function renderSetupHtml(nonce, token, initialStatus) {
35526
36189
  </section>
35527
36190
 
35528
36191
  <section class="card">
35529
- <h2>4. \u5B89\u88C5\u540E 2 \u6B65\u5B8C\u6210\u542F\u7528</h2>
36192
+ <h2>4. \u5B89\u88C5\u540E\u9996\u6B21\u914D\u7F6E\uFF08\u5728 memoQ \u4E2D\u6DFB\u52A0\u5E76\u542F\u7528 MT \u8D44\u6E90\uFF09</h2>
35530
36193
  <ol>
35531
- <li>\u5B8C\u5168\u5173\u95ED\u5E76\u91CD\u65B0\u542F\u52A8 <strong>memoQ</strong>\uFF08memoQ \u53EA\u5728\u542F\u52A8\u65F6\u626B\u63CF Addins \u76EE\u5F55\uFF09\u3002</li>
35532
- <li>\u5728 memoQ \u4E2D\u6253\u5F00 <strong>Options \u2192 Default resources \u2192 MT settings</strong>\uFF0C\u52FE\u9009\u542F\u7528 <strong>memoQ AI Hub</strong>\uFF08\u7AEF\u53E3\u4FDD\u6301\u9ED8\u8BA4 <code>5271</code>\uFF09\u3002</li>
36194
+ <li>\u5B8C\u5168\u5173\u95ED\u5E76\u91CD\u65B0\u542F\u52A8 <strong>memoQ</strong>\uFF08memoQ \u53EA\u5728\u542F\u52A8\u65F6\u626B\u63CF <code>Addins</code> \u76EE\u5F55\u52A0\u8F7D\u65B0\u63D2\u4EF6\uFF09\u3002</li>
36195
+ <li>\u9996\u6B21\u4F7F\u7528\u9700\u65B0\u5EFA MT \u8D44\u6E90\uFF1A\u6253\u5F00 <strong>Resource Console \u2192 MT settings \u2192 Create new</strong>\uFF08\u9009\u62E9 <strong>My Computer</strong>\uFF0C\u586B\u5199\u8D44\u6E90\u540D\u79F0\u5982 <code>memoQ AI Hub</code>\uFF09\uFF0C\u52FE\u9009\u542F\u7528 <strong>memoQ AI Hub</strong>\u3002</li>
36196
+ <li>\u70B9\u51FB\u8BE5\u8D44\u6E90\u8BBE\u7F6E\uFF08<strong>Options</strong>\uFF09\uFF0C\u786E\u8BA4 <strong>Gateway Base URL</strong> \u4E3A <code>http://127.0.0.1:5271</code>\u3001\u52FE\u9009 <strong>Enable Gateway</strong>\u3001<strong>Formatting Mode</strong> \u4E3A <code>BothFormattingAndTags</code>\uFF1B\u5E76\u5728\u8D44\u6E90\u529F\u80FD\u4E2D\u542F\u7528 <strong>Pre-translation</strong>\u3001<strong>Match and Patch</strong>\u3001<strong>Send best fuzzy TM match</strong> \u4E0E <strong>Self-learning MT</strong>\u3002</li>
36197
+ <li>\u5728 <strong>Options \u2192 Default resources \u2192 MT settings</strong> \u4E2D\u8BBE\u4E3A\u9ED8\u8BA4\uFF1B<strong>\u5BF9\u4E8E\u5DF2\u6709\u9879\u76EE</strong>\uFF0C\u8FD8\u5FC5\u987B\u6253\u5F00 <strong>Project home \u2192 Settings \u2192 MT settings</strong> \u52FE\u9009\u542F\u7528\u8BE5\u8D44\u6E90\uFF0C\u624D\u80FD\u4F7F\u7528 Pre-translate \u5199\u5165\u8BD1\u6587\u3002</li>
35533
36198
  </ol>
35534
36199
  <details style="margin-top: 12px;">
35535
36200
  <summary>\u4F01\u4E1A\u9650\u5236\u65E0\u6CD5 UAC \u63D0\u6743\uFF1F\u67E5\u770B\u624B\u52A8\u5B89\u88C5 3 \u6B65\u65B9\u6848</summary>
35536
36201
  <ol>
35537
- <li>\u70B9\u51FB\u4E0A\u65B9\u300C\u6253\u5F00\u672C\u5730\u63D2\u4EF6\u7F13\u5B58\u76EE\u5F55\u300D\uFF0C\u5982\u5C1A\u672A\u4E0B\u8F7D\u53EF\u5148\u4ECE GitHub Release \u4E0B\u8F7D <code>${escapeHtml(PLUGIN_DLL_NAME)}</code>\u3002</li>
36202
+ <li>\u70B9\u51FB\u4E0A\u65B9\u300C\u6253\u5F00\u672C\u5730\u63D2\u4EF6\u7F13\u5B58\u76EE\u5F55\u300D\uFF0C\u5982\u5C1A\u672A\u4E0B\u8F7D\u53EF\u5148\u4ECE GitHub Release \u4E0B\u8F7D <code>${escapeHtml2(PLUGIN_DLL_NAME)}</code>\u3002</li>
35538
36203
  <li>\u53F3\u952E DLL \u5C5E\u6027\u52FE\u9009\u300C\u89E3\u9664\u9501\u5B9A\u300D\uFF0C\u590D\u5236\u5230 memoQ \u5B89\u88C5\u76EE\u5F55\u4E0B\u7684 <code>Addins</code> \u6587\u4EF6\u5939\u3002</li>
35539
- <li>\u5728 <code>C:\\ProgramData\\MemoQ\\ClientDevConfig.xml</code> \u4E2D\u786E\u4FDD\u5305\u542B <code>&lt;ClientDevConfig&gt;&lt;LoadUnsignedPlugins&gt;true&lt;/LoadUnsignedPlugins&gt;&lt;/ClientDevConfig&gt;</code>\uFF0C\u7136\u540E\u91CD\u542F memoQ\u3002</li>
36204
+ <li>\u5728 <code>C:\\ProgramData\\MemoQ\\ClientDevConfig.xml</code> \u4E2D\u786E\u4FDD\u5305\u542B <code>&lt;ClientDevConfig&gt;&lt;LoadUnsignedPlugins&gt;true&lt;/LoadUnsignedPlugins&gt;&lt;/ClientDevConfig&gt;</code>\uFF0C\u91CD\u542F memoQ \u5E76\u6309\u4E0A\u65B9\u7B2C 2\u20134 \u6B65\u6DFB\u52A0 MT \u8D44\u6E90\u3002</li>
35540
36205
  </ol>
35541
36206
  </details>
35542
36207
  </section>
35543
36208
  </main>
35544
36209
 
35545
- <script nonce="${escapeHtml(nonce)}">
36210
+ <script nonce="${escapeHtml2(nonce)}">
35546
36211
  const BOOT = ${payloadJson};
35547
36212
  const token = BOOT.token;
35548
36213
  let currentState = BOOT.initialStatus;
35549
36214
  let selectedRoot = (currentState.integration.installations[0] && currentState.integration.installations[0].rootDir) || "";
35550
36215
 
36216
+ function esc(s) {
36217
+ return String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
36218
+ }
36219
+
35551
36220
  function render(state) {
35552
36221
  currentState = state;
35553
36222
  const grid = document.getElementById("status-grid");
@@ -35587,8 +36256,8 @@ function renderSetupHtml(nonce, token, initialStatus) {
35587
36256
  const checked = item.rootDir === selectedRoot ? "checked" : "";
35588
36257
  const badge = item.status === "installed" ? "\u2705 \u5DF2\u5B89\u88C5" : item.status === "needs_repair" ? "\u26A0\uFE0F \u9700\u4FEE\u590D" : "\u672A\u5B89\u88C5";
35589
36258
  return '<label style="display:block;padding:8px 10px;border:1px solid var(--border);border-radius:6px;margin-bottom:8px;cursor:pointer;">'
35590
- + '<input type="radio" name="memoqRoot" value="' + item.rootDir.replace(/"/g, "&quot;") + '" ' + checked + ' data-idx="' + idx + '" /> '
35591
- + '<strong>' + item.label + '</strong> \u2014 <code>' + item.rootDir + '</code> (' + badge + ')'
36259
+ + '<input type="radio" name="memoqRoot" value="' + esc(item.rootDir) + '" ' + checked + ' data-idx="' + idx + '" /> '
36260
+ + '<strong>' + esc(item.label) + '</strong> \u2014 <code>' + esc(item.rootDir) + '</code> (' + badge + ')'
35592
36261
  + '</label>';
35593
36262
  }).join("");
35594
36263
  targetsEl.querySelectorAll('input[name="memoqRoot"]').forEach(function (el) {
@@ -35600,11 +36269,11 @@ function renderSetupHtml(nonce, token, initialStatus) {
35600
36269
  const dllList = state.discoveredDlls || [];
35601
36270
  if (dllsEl) {
35602
36271
  if (!dllList.length) {
35603
- dllsEl.textContent = "\u672A\u5728\u672C\u673A\u5E38\u7528\u76EE\u5F55\u9884\u53D1\u73B0 DLL\uFF1B\u70B9\u51FB\u5B89\u88C5\u65F6\u5C06\u6309\u9700\u4ECE\u5B89\u5168 Release \u62C9\u53D6\u5E76\u6821\u9A8C SHA-256\u3002";
36272
+ dllsEl.textContent = "\u672A\u5728\u672C\u673A\u5E38\u7528\u76EE\u5F55\u9884\u53D1\u73B0 DLL\uFF1B\u70B9\u51FB\u5B89\u88C5\u65F6\u5C06\u81EA\u52A8\u901A\u8FC7 HTTP Range \u4EC5\u62C9\u53D6\u6240\u9700 DLL\uFF08\u7EA6 150 KB\uFF0C\u652F\u6301\u7CFB\u7EDF\u4EE3\u7406\uFF09\u5E76\u6821\u9A8C SHA-256\u3002";
35604
36273
  } else {
35605
36274
  dllsEl.innerHTML = "\u672C\u673A\u5DF2\u53D1\u73B0\u53EF\u7528\u5305\uFF08\u70B9\u51FB\u53EF\u586B\u5165\u8DEF\u5F84\uFF09\uFF1A" + dllList.slice(0, 4).map(function (c, i) {
35606
36275
  const ok = c.sha256MatchesExpected ? "\u2705" : "\u26A0\uFE0F";
35607
- return '<button type="button" class="pick-dll" data-idx="' + i + '" style="margin:4px 6px 0 0;padding:3px 8px;font-size:12px;">' + ok + " " + c.path.replace(/</g, "&lt;") + "</button>";
36276
+ return '<button type="button" class="pick-dll" data-idx="' + i + '" style="margin:4px 6px 0 0;padding:3px 8px;font-size:12px;">' + ok + " " + esc(c.path) + "</button>";
35608
36277
  }).join("");
35609
36278
  dllsEl.querySelectorAll(".pick-dll").forEach(function (btn) {
35610
36279
  btn.addEventListener("click", function () {
@@ -35628,7 +36297,8 @@ function renderSetupHtml(nonce, token, initialStatus) {
35628
36297
  }
35629
36298
 
35630
36299
  async function api(path, method, body) {
35631
- const res = await fetch(path + "?token=" + encodeURIComponent(token), {
36300
+ const sep = path.indexOf("?") >= 0 ? "&" : "?";
36301
+ const res = await fetch(path + sep + "token=" + encodeURIComponent(token), {
35632
36302
  method: method,
35633
36303
  headers: { "Content-Type": "application/json", "X-Setup-Token": token },
35634
36304
  body: body ? JSON.stringify(body) : undefined
@@ -35641,7 +36311,7 @@ function renderSetupHtml(nonce, token, initialStatus) {
35641
36311
  document.getElementById("btn-refresh").addEventListener("click", async function () {
35642
36312
  try {
35643
36313
  const custom = document.getElementById("custom-dir").value.trim();
35644
- const data = await api("/api/status" + (custom ? "&customDir=" + encodeURIComponent(custom) : ""), "GET");
36314
+ const data = await api("/api/status" + (custom ? "?customDir=" + encodeURIComponent(custom) : ""), "GET");
35645
36315
  render(data);
35646
36316
  showMessage("\u5DF2\u5237\u65B0\u672C\u673A\u72B6\u6001\u3002", false);
35647
36317
  } catch (e) { showMessage(e.message, true); }
@@ -35665,7 +36335,7 @@ function renderSetupHtml(nonce, token, initialStatus) {
35665
36335
  const payload = dllPath ? { memoqRoot: root, dllPath: dllPath } : { memoqRoot: root };
35666
36336
  const res = await api("/api/install", "POST", payload);
35667
36337
  render(res.status);
35668
- showMessage("\u5B89\u88C5\u6210\u529F\uFF01DLL \u6821\u9A8C\u503C " + res.result.dllSha256 + "\u3002\u8BF7\u91CD\u542F memoQ \u5E76\u5728 MT settings \u4E2D\u542F\u7528\u3002", false);
36338
+ showMessage("\u5B89\u88C5\u6210\u529F\uFF01DLL \u6821\u9A8C\u503C " + res.result.dllSha256 + "\u3002\u8BF7\u5B8C\u5168\u91CD\u542F memoQ\uFF0C\u5E76\u6309\u7B2C 4 \u8282\u5728 Resource Console \u4E0E\u5F53\u524D\u9879\u76EE\u4E2D\u542F\u7528 memoQ AI Hub\u3002", false);
35669
36339
  } catch (e) { showMessage("\u5B89\u88C5\u5931\u8D25\uFF1A" + e.message, true); }
35670
36340
  finally { btn.disabled = false; }
35671
36341
  });
@@ -35696,6 +36366,8 @@ async function startSetupServer(options = {}) {
35696
36366
  const probeGateway = options.probeGateway ?? ((p) => probeGatewayPort(p ?? gatewayPort));
35697
36367
  const resolveDll = options.resolveDll ?? resolvePluginDllAsset;
35698
36368
  const dataDir = options.dataDir ?? defaultBridgeDataDir();
36369
+ const tool = sanitizeReviewTool(options.tool) ?? { name: "@langlink/memoq-bridge", version: BRIDGE_VERSION };
36370
+ const toolLabel = formatReviewTool(tool);
35699
36371
  let actualPort = requestedPort;
35700
36372
  let expectedOrigin = "";
35701
36373
  let expectedHost = "";
@@ -35742,7 +36414,7 @@ async function startSetupServer(options = {}) {
35742
36414
  `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none';`
35743
36415
  );
35744
36416
  const status = await collectStatus(url.searchParams.get("customDir") ?? void 0);
35745
- send(response, 200, "text/html; charset=utf-8", renderSetupHtml(nonce, token, status));
36417
+ send(response, 200, "text/html; charset=utf-8", renderSetupHtml(nonce, token, status, toolLabel));
35746
36418
  return;
35747
36419
  }
35748
36420
  if (method === "GET" && url.pathname === "/api/status") {
@@ -35762,11 +36434,22 @@ async function startSetupServer(options = {}) {
35762
36434
  sendJson2(response, 400, { error: "memoqRoot \u4E0D\u80FD\u4E3A\u7A7A\u3002" });
35763
36435
  return;
35764
36436
  }
36437
+ const currentIntegration = getIntegrationStatus({
36438
+ ...options.detectOptions,
36439
+ dataDir,
36440
+ ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
36441
+ customInstallDir: memoqRoot
36442
+ });
36443
+ const siblingDllPaths = currentIntegration.installations.filter((item) => item.pluginInstalled).map((item) => item.pluginTarget);
35765
36444
  const resolvedAsset = await resolveDll({
35766
36445
  dataDir,
36446
+ ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
36447
+ ...options.detectOptions?.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.detectOptions.helperExecutablePath },
35767
36448
  ...dllPath ? { dllPath } : {},
35768
36449
  ...options.allowDownload === void 0 ? {} : { allowDownload: options.allowDownload },
35769
- ...options.detectOptions?.expectedSha256 === void 0 ? {} : { expectedSha256: options.detectOptions.expectedSha256 }
36450
+ ...options.detectOptions?.expectedSha256 === void 0 ? {} : { expectedSha256: options.detectOptions.expectedSha256 },
36451
+ searchPaths: siblingDllPaths,
36452
+ includeDefaultUserDirs: !options.detectOptions?.skipHostDiscovery
35770
36453
  });
35771
36454
  const elevate = options.elevate ?? process.platform === "win32";
35772
36455
  const result = await installPluginWithHelper({
@@ -36013,12 +36696,12 @@ async function writeRecipe(recipe) {
36013
36696
  }
36014
36697
 
36015
36698
  // packages/memoq-mcp/src/daemon-launcher.ts
36016
- import { execFile as execFile2, spawn as spawn3 } from "node:child_process";
36699
+ import { execFile as execFile3, spawn as spawn3 } from "node:child_process";
36017
36700
  import { randomUUID as randomUUID6 } from "node:crypto";
36018
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync8, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
36701
+ import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync8, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
36019
36702
  import { dirname as dirname7, join as join9, resolve as resolve5 } from "node:path";
36020
- import { promisify as promisify2 } from "node:util";
36021
- var execFileAsync2 = promisify2(execFile2);
36703
+ import { promisify as promisify3 } from "node:util";
36704
+ var execFileAsync3 = promisify3(execFile3);
36022
36705
  var MEMOQ_BRIDGE_DAEMON_FLAG = "--memoq-bridge-daemon";
36023
36706
  var MEMOQ_SETUP_WORKER_FLAG = "--memoq-setup-worker";
36024
36707
  var WORKER_START_TIMEOUT_MS = 15e3;
@@ -36073,7 +36756,7 @@ async function trySpawnViaWindowsWmi(entrypoint, workerArgs, dataDir) {
36073
36756
  }),
36074
36757
  "utf8"
36075
36758
  );
36076
- const { stdout } = await execFileAsync2(
36759
+ const { stdout } = await execFileAsync3(
36077
36760
  helperPath,
36078
36761
  ["--spawn-detached", "--spec-file", specFile],
36079
36762
  { timeout: 1e4, windowsHide: true }
@@ -36084,7 +36767,7 @@ async function trySpawnViaWindowsWmi(entrypoint, workerArgs, dataDir) {
36084
36767
  return false;
36085
36768
  } finally {
36086
36769
  try {
36087
- rmSync4(specFile, { force: true });
36770
+ rmSync5(specFile, { force: true });
36088
36771
  } catch {
36089
36772
  }
36090
36773
  }
@@ -36138,7 +36821,7 @@ async function spawnDetachedWorker(entrypoint, flag, options) {
36138
36821
  throw new Error(`memoQ worker timed out (${flag}).`);
36139
36822
  } finally {
36140
36823
  try {
36141
- rmSync4(readyFile, { force: true });
36824
+ rmSync5(readyFile, { force: true });
36142
36825
  } catch {
36143
36826
  }
36144
36827
  }
@@ -36288,6 +36971,7 @@ async function runBridgeDaemonWorker(argv = process.argv.slice(2), version2, run
36288
36971
  dataDir,
36289
36972
  ...args.port === void 0 ? {} : { preferredPort: args.port },
36290
36973
  ownerLabel: "memoq-mcp-daemon",
36974
+ toolName: runtimeOptions.toolName ?? "@langlink/memoq-mcp",
36291
36975
  ...version2 ? { version: version2 } : {},
36292
36976
  ...runtimeOptions.startPreview === void 0 ? {} : { startPreview: runtimeOptions.startPreview },
36293
36977
  mode: "staging",
@@ -36317,7 +37001,7 @@ async function runBridgeDaemonWorker(argv = process.argv.slice(2), version2, run
36317
37001
  throw error2;
36318
37002
  }
36319
37003
  }
36320
- async function runSetupWorker(argv = process.argv.slice(2)) {
37004
+ async function runSetupWorker(argv = process.argv.slice(2), tool) {
36321
37005
  const args = parseWorkerCliArgs(argv);
36322
37006
  if (!args.readyFile && (!process.send || !process.connected)) {
36323
37007
  throw new Error("memoQ setup worker requires --ready-file or IPC.");
@@ -36326,7 +37010,8 @@ async function runSetupWorker(argv = process.argv.slice(2)) {
36326
37010
  try {
36327
37011
  const setup = await startSetupServer({
36328
37012
  keepAlive: true,
36329
- dataDir
37013
+ dataDir,
37014
+ ...tool ? { tool } : {}
36330
37015
  });
36331
37016
  try {
36332
37017
  await publishWorkerOutcome(args.readyFile, {
@@ -36353,7 +37038,8 @@ function textResult(value) {
36353
37038
  content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value) }]
36354
37039
  };
36355
37040
  }
36356
- var MEMOQ_MCP_VERSION = "0.2.5";
37041
+ var MEMOQ_MCP_VERSION = package_default.version;
37042
+ var MEMOQ_MCP_TOOL = { name: package_default.name, version: package_default.version };
36357
37043
  function createMemoqMcpServer(options = {}) {
36358
37044
  const server = new McpServer({ name: "langlink-memoq", version: MEMOQ_MCP_VERSION });
36359
37045
  const here = dirname8(fileURLToPath2(import.meta.url));
@@ -36386,9 +37072,13 @@ function createMemoqMcpServer(options = {}) {
36386
37072
  const status = await client.getStatus();
36387
37073
  const probe = await probeGatewayPort(Number(process.env.MEMOQ_BRIDGE_PORT || DEFAULT_PORT));
36388
37074
  const coverage = status.coverage;
37075
+ const integ = status.integration;
36389
37076
  return textResult({
36390
37077
  ...status,
36391
37078
  port5271Owner: probe.owner,
37079
+ ...integ?.status && integ.status !== "installed" ? {
37080
+ setupHint: "\u68C0\u6D4B\u5230 memoQ MT \u63D2\u4EF6\u5C1A\u672A\u5B8C\u5168\u5C31\u7EEA\uFF0C\u53EF\u8BA9 Agent \u8C03\u7528 memoq_setup\uFF08action: 'plan' / 'install'\uFF09\u83B7\u53D6\u672C\u5730 DLL \u5E76\u5F15\u5BFC\u5B8C\u6210\u9996\u6B21\u914D\u7F6E\u3002"
37081
+ } : {},
36392
37082
  ...coverage?.attentionMessage ? { warning: coverage.attentionMessage } : {},
36393
37083
  ...probe.owner === "memoq-ai-hub" ? {
36394
37084
  note: "memoQ AI Hub is currently using port 5271. Preview tools work normally; to use agent staging via port 5271, close memoQ AI Hub or change MEMOQ_BRIDGE_PORT and plugin gateway port."
@@ -36790,7 +37480,8 @@ function createMemoqMcpServer(options = {}) {
36790
37480
  return textResult({
36791
37481
  action: "install",
36792
37482
  installed: true,
36793
- ...installResult
37483
+ ...installResult,
37484
+ memoqResourceSetupSteps: [...MEMOQ_FIRST_TIME_RESOURCE_STEPS]
36794
37485
  });
36795
37486
  }
36796
37487
  if (effectiveAction === "uninstall") {
@@ -36836,7 +37527,8 @@ function createMemoqMcpServer(options = {}) {
36836
37527
  plan,
36837
37528
  gateway: probe,
36838
37529
  confirmationRequired: true,
36839
- nextStep: integration.canReuseExisting ? "\u68C0\u6D4B\u5230\u5DF2\u5B89\u88C5\u7684\u517C\u5BB9\u63D2\u4EF6\u53EF\u76F4\u63A5\u590D\u7528\u3002\u5982\u9700\u4FEE\u590D\u6216\u5B89\u88C5\u5230\u5176\u4ED6\u7248\u672C\uFF0C\u8BF7\u5411\u7528\u6237\u5C55\u793A plan.plannedChanges \u5E76\u83B7\u660E\u786E\u786E\u8BA4\u540E\u8C03\u7528 memoq_setup({ action: 'install', confirmed: true, memoqRoot, dllPath })\u3002" : plan.readyToInstall ? "\u5DF2\u5B9A\u4F4D\u76EE\u6807 memoQ \u76EE\u5F55\u4E0E\u6E90 DLL\u3002\u8BF7\u5148\u5728\u5BF9\u8BDD\u4E2D\u5217\u51FA plan.plannedChanges\uFF08\u6E90\u8DEF\u5F84\u3001\u590D\u5236\u76EE\u6807\u8DEF\u5F84\u3001SHA-256\u3001ClientDevConfig.xml \u5907\u4EFD\u5408\u5E76\u8BA1\u5212\u3001\u662F\u5426\u5F39 UAC\uFF09\uFF0C\u7B49\u7528\u6237\u786E\u8BA4\u540E\u518D\u8C03\u7528 memoq_setup({ action: 'install', confirmed: true, memoqRoot: plan.recommendedMemoqRoot, dllPath: plan.plannedChanges.sourceDllPath })\u3002" : `\u5C1A\u672A\u5C31\u7EEA\uFF1A${plan.blockers.join("\uFF1B")}\u3002\u8BF7\u5411\u7528\u6237\u786E\u8BA4 memoQ \u76EE\u5F55 (customInstallDir) \u6216\u672C\u5730 DLL/ZIP \u8DEF\u5F84 (dllPath)\uFF0C\u6216\u4F7F\u7528\u672C\u5730\u53EF\u89C6\u5316\u5411\u5BFC\u3002`,
37530
+ memoqResourceSetupSteps: [...MEMOQ_FIRST_TIME_RESOURCE_STEPS],
37531
+ nextStep: integration.canReuseExisting ? "\u68C0\u6D4B\u5230\u5DF2\u5B89\u88C5\u7684\u517C\u5BB9\u63D2\u4EF6\u53EF\u76F4\u63A5\u590D\u7528\u3002\u5982\u679C\u7528\u6237\u662F\u9996\u6B21\u4F7F\u7528\u672C\u5DE5\u5177\uFF0C\u8BF7\u5BF9\u7167 memoqResourceSetupSteps \u5F15\u5BFC\u7528\u6237\u5728 memoQ \u4E2D\u6253\u5F00 Resource Console \u2192 MT settings \u2192 Create new \u65B0\u5EFA\u5E76\u52FE\u9009 memoQ AI Hub\uFF0C\u540C\u65F6\u5728\u5F53\u524D\u9879\u76EE\u7684 Project home \u2192 Settings \u2192 MT settings \u4E2D\u542F\u7528\u8BE5\u8D44\u6E90\uFF1B\u5982\u9700\u4FEE\u590D\u6216\u5B89\u88C5\u5230\u5176\u4ED6\u7248\u672C\uFF0C\u8BF7\u5148\u5411\u7528\u6237\u5C55\u793A plan.plannedChanges \u5E76\u83B7\u660E\u786E\u786E\u8BA4\u540E\u518D\u8C03\u7528 memoq_setup({ action: 'install', confirmed: true, memoqRoot, dllPath })\u3002" : plan.readyToInstall ? "\u5DF2\u5B9A\u4F4D\u76EE\u6807 memoQ \u76EE\u5F55\u4E0E\u6E90 DLL\u3002\u8BF7\u5148\u5728\u5BF9\u8BDD\u4E2D\u5217\u51FA plan.plannedChanges\uFF08\u6E90\u8DEF\u5F84\u3001\u590D\u5236\u76EE\u6807\u8DEF\u5F84\u3001SHA-256\u3001ClientDevConfig.xml \u5907\u4EFD\u5408\u5E76\u8BA1\u5212\u3001\u662F\u5426\u5F39 UAC\uFF09\uFF0C\u7B49\u7528\u6237\u786E\u8BA4\u540E\u518D\u8C03\u7528 memoq_setup({ action: 'install', confirmed: true, memoqRoot: plan.recommendedMemoqRoot, dllPath: plan.plannedChanges.sourceDllPath })\uFF0C\u5B89\u88C5\u5B8C\u6210\u540E\u518D\u5BF9\u7167 memoqResourceSetupSteps \u5F15\u5BFC\u7528\u6237\u5728 memoQ \u4E2D\u65B0\u5EFA\u5E76\u542F\u7528 MT \u8D44\u6E90\u3002" : `\u5C1A\u672A\u5C31\u7EEA\uFF1A${plan.blockers.join("\uFF1B")}\u3002\u8BF7\u5411\u7528\u6237\u786E\u8BA4 memoQ \u76EE\u5F55 (customInstallDir) \u6216\u672C\u5730 DLL/ZIP \u8DEF\u5F84 (dllPath)\uFF0C\u6216\u4F7F\u7528\u672C\u5730\u53EF\u89C6\u5316\u5411\u5BFC\u3002`,
36840
37532
  message: integration.canReuseExisting ? `\u68C0\u6D4B\u5230\u5DF2\u5B89\u88C5\u7684 memoQ \u63D2\u4EF6\u53EF\u76F4\u63A5\u590D\u7528\u3002${url ? `\u5982\u9700\u67E5\u770B\u8BE6\u60C5\u6216\u4FEE\u590D\uFF0C\u8BF7\u6253\u5F00\uFF1A[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})` : ""}` : plan.readyToInstall ? `\u5DF2\u627E\u5230\u5B89\u88C5\u8DEF\u5F84\u4E0E\u63D2\u4EF6\u6587\u4EF6\uFF08\u5C06\u590D\u5236\u5E76\u4FDD\u7559\u539F\u4EF6\uFF09\u3002\u8BF7\u5728\u4E0E\u7528\u6237\u786E\u8BA4\u5177\u4F53\u53D8\u66F4\u8DEF\u5F84\u540E\u8C03\u7528 memoq_setup({ action: "install", confirmed: true, ... }) \u5B8C\u6210\u5B89\u88C5${url ? `\uFF0C\u6216\u6253\u5F00\u53EF\u89C6\u5316\u5411\u5BFC\uFF1A[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})` : ""}\u3002` : `\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00\u672C\u5730\u8BBE\u7F6E\u5411\u5BFC\u67E5\u770B\u5C06\u8981\u5199\u5165\u7684 2 \u4E2A\u8DEF\u5F84\u5E76\u70B9\u51FB\u5B89\u88C5${url ? `\uFF1A[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})` : ""}`
36841
37533
  });
36842
37534
  }
@@ -36887,11 +37579,11 @@ async function runConfigCommand(args) {
36887
37579
  async function main() {
36888
37580
  const command = process.argv[2];
36889
37581
  if (command === MEMOQ_BRIDGE_DAEMON_FLAG) {
36890
- await runBridgeDaemonWorker(process.argv.slice(3), MEMOQ_MCP_VERSION);
37582
+ await runBridgeDaemonWorker(process.argv.slice(3), MEMOQ_MCP_VERSION, { toolName: package_default.name });
36891
37583
  return;
36892
37584
  }
36893
37585
  if (command === MEMOQ_SETUP_WORKER_FLAG) {
36894
- await runSetupWorker(process.argv.slice(3));
37586
+ await runSetupWorker(process.argv.slice(3), MEMOQ_MCP_TOOL);
36895
37587
  return;
36896
37588
  }
36897
37589
  if (command === "config" || command === "setup") {
@@ -36916,6 +37608,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.ar
36916
37608
  });
36917
37609
  }
36918
37610
  export {
37611
+ MEMOQ_MCP_TOOL,
36919
37612
  MEMOQ_MCP_VERSION,
36920
37613
  createMemoqMcpServer
36921
37614
  };