inkmap-mcp 0.3.4 → 0.3.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.
@@ -103,18 +103,61 @@ function sanitizeViewState(raw) {
103
103
  }
104
104
 
105
105
  // packages/vscode/src/extension.ts
106
- var import_node_child_process2 = require("node:child_process");
106
+ var import_node_child_process3 = require("node:child_process");
107
107
  var import_node_fs2 = require("node:fs");
108
108
  var import_promises4 = require("node:fs/promises");
109
109
  var import_node_os3 = require("node:os");
110
110
  var import_node_path3 = require("node:path");
111
- var vscode6 = __toESM(require("vscode"));
111
+ var vscode5 = __toESM(require("vscode"));
112
112
 
113
113
  // packages/cli/src/license.ts
114
+ var import_node_child_process = require("node:child_process");
114
115
  var import_promises = require("node:fs/promises");
115
116
  var import_node_crypto = require("node:crypto");
116
117
  var import_node_os = require("node:os");
117
118
  var import_node_path = require("node:path");
119
+ var cachedOsLocale;
120
+ function detectOsLocale() {
121
+ const explicit = (process.env.INKMAP_LOCALE || "").trim();
122
+ if (/^zh\b/i.test(explicit)) return "zh";
123
+ if (/^en\b/i.test(explicit)) return "en";
124
+ if (cachedOsLocale) return cachedOsLocale;
125
+ let domestic = false;
126
+ try {
127
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || "";
128
+ if (/^(Asia\/(Shanghai|Chongqing|Chungking|Harbin|Urumqi|Beijing)|PRC)$/i.test(tz)) {
129
+ domestic = true;
130
+ }
131
+ } catch {
132
+ }
133
+ if (!domestic) {
134
+ if (process.platform === "darwin") {
135
+ try {
136
+ const out = (0, import_node_child_process.execFileSync)("defaults", ["read", "-g", "AppleLanguages"], {
137
+ encoding: "utf8",
138
+ timeout: 800,
139
+ stdio: ["ignore", "pipe", "ignore"]
140
+ });
141
+ const firstLang = /"([^"]+)"/.exec(out)?.[1] ?? "";
142
+ if (/^zh\b/i.test(firstLang)) domestic = true;
143
+ } catch {
144
+ const raw = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || "").trim();
145
+ if (/^zh\b/i.test(raw)) domestic = true;
146
+ }
147
+ } else if (process.platform === "win32") {
148
+ try {
149
+ const loc = Intl.DateTimeFormat().resolvedOptions().locale || "";
150
+ if (/^zh\b/i.test(loc)) domestic = true;
151
+ } catch {
152
+ }
153
+ } else {
154
+ const raw = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || "").trim();
155
+ if (/^zh\b/i.test(raw)) domestic = true;
156
+ }
157
+ }
158
+ cachedOsLocale = domestic ? "zh" : "en";
159
+ return cachedOsLocale;
160
+ }
118
161
  function billingOrigin(raw) {
119
162
  if (!raw) throw new Error("Inkmap checkout is not configured.");
120
163
  const url = new URL(raw);
@@ -142,6 +185,13 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
142
185
  let pendingWrite = Promise.resolve();
143
186
  let pendingCheckout;
144
187
  let cachedOrder;
188
+ let magicPollTimer;
189
+ let magicSession = 0;
190
+ function stopMagicPoll() {
191
+ ++magicSession;
192
+ clearTimeout(magicPollTimer);
193
+ magicPollTimer = void 0;
194
+ }
145
195
  function mergeCookies(existing, response) {
146
196
  const map = /* @__PURE__ */ new Map();
147
197
  if (existing) {
@@ -173,19 +223,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
173
223
  const h = (hint || "").trim();
174
224
  if (/^zh\b/i.test(h)) return "zh";
175
225
  if (/^en\b/i.test(h)) return "en";
176
- const envLocale = (process.env.INKMAP_LOCALE || "").trim();
177
- if (/^zh\b/i.test(envLocale)) return "zh";
178
- if (/^en\b/i.test(envLocale)) return "en";
179
- const raw = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || "").trim();
180
- if (/^zh\b/i.test(raw)) return "zh";
181
- try {
182
- const opts = Intl.DateTimeFormat().resolvedOptions();
183
- if (/^zh\b/i.test(opts.locale || "")) return "zh";
184
- const tz = opts.timeZone || "";
185
- if (/^(Asia\/(Shanghai|Chongqing|Chungking|Harbin|Urumqi|Beijing)|PRC)$/i.test(tz)) return "zh";
186
- } catch {
187
- }
188
- return "en";
226
+ return detectOsLocale();
189
227
  }
190
228
  function writeSession(operation) {
191
229
  const next = pendingWrite.then(operation);
@@ -330,7 +368,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
330
368
  const state = await response.json();
331
369
  if (version !== generation || disposed) return;
332
370
  applyEntitlement(state);
333
- delay = state.active !== true && state.pending === true ? 4e3 : 6e4;
371
+ delay = state.active !== true && state.pending === true ? 2500 : 6e4;
334
372
  } catch {
335
373
  if (version === generation && Date.now() - lastCheck > 15 * 6e4) update(false);
336
374
  } finally {
@@ -341,6 +379,44 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
341
379
  });
342
380
  return connection;
343
381
  }
382
+ function startMagicPoll(origin, pendingToken) {
383
+ stopMagicPoll();
384
+ const id = magicSession;
385
+ const deadline = Date.now() + 10 * 6e4;
386
+ const poll = () => {
387
+ if (disposed || id !== magicSession || Date.now() >= deadline) return;
388
+ magicPollTimer = setTimeout(async () => {
389
+ if (disposed || id !== magicSession) return;
390
+ try {
391
+ const res = await entitlement(origin, pendingToken);
392
+ if (disposed || id !== magicSession) return;
393
+ if (res.status === 401) {
394
+ stopMagicPoll();
395
+ return;
396
+ }
397
+ if (res.ok) {
398
+ const body = await res.json();
399
+ if (body?.connected === true && body.entitlement === PRODUCT.entitlement) {
400
+ stopMagicPoll();
401
+ await writeSession(async () => {
402
+ if (disposed || origin !== billingOrigin(getOrigin())) return;
403
+ await storage.write(JSON.stringify({ origin, token: pendingToken }));
404
+ ++generation;
405
+ activeOrigin = origin;
406
+ applyEntitlement(body);
407
+ schedule(body.active === true ? 6e4 : 2500);
408
+ });
409
+ return;
410
+ }
411
+ }
412
+ } catch {
413
+ }
414
+ if (!disposed && id === magicSession && Date.now() < deadline) poll();
415
+ }, 2e3);
416
+ magicPollTimer.unref();
417
+ };
418
+ poll();
419
+ }
344
420
  return {
345
421
  async state() {
346
422
  await (trial ??= startTrial());
@@ -488,7 +564,14 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
488
564
  }
489
565
  }
490
566
  const response = await phoneRequest(origin, "send", phone, void 0, locale);
491
- return response.status === 204 ? { ok: true, value: void 0 } : phoneFailure(response.status);
567
+ if (response.status === 204) {
568
+ const pendingToken = response.headers.get("x-inkmap-pending-token")?.trim();
569
+ if (pendingToken && /^[A-Za-z0-9_-]{43}$/.test(pendingToken)) {
570
+ startMagicPoll(origin, pendingToken);
571
+ }
572
+ return { ok: true, value: void 0 };
573
+ }
574
+ return phoneFailure(response.status);
492
575
  } catch {
493
576
  return phoneFailure();
494
577
  }
@@ -564,6 +647,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
564
647
  if (cachedOrder?.result.status === "active") state.active = true;
565
648
  return await writeSession(async () => {
566
649
  if (version !== generation || disposed || origin !== billingOrigin(getOrigin())) return phoneFailure();
650
+ stopMagicPoll();
567
651
  await storage.write(JSON.stringify({ origin, token, ...checkoutUrl && { checkoutUrl }, ...cookie && { cookie } }));
568
652
  ++generation;
569
653
  activeOrigin = origin;
@@ -577,6 +661,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
577
661
  }
578
662
  },
579
663
  async deactivate() {
664
+ stopMagicPoll();
580
665
  pendingCheckout = void 0;
581
666
  cachedOrder = void 0;
582
667
  const saved = await writeSession(async () => {
@@ -645,7 +730,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
645
730
  installId: id,
646
731
  host: hostName,
647
732
  os,
648
- version: "0.3.4",
733
+ version: "0.3.6",
649
734
  locale: clientLocale(),
650
735
  tier,
651
736
  events
@@ -659,6 +744,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
659
744
  },
660
745
  dispose() {
661
746
  disposed = true;
747
+ stopMagicPoll();
662
748
  clearTimeout(trialTimer);
663
749
  clearTimeout(timer);
664
750
  clearTimeout(telemetryTimer);
@@ -742,8 +828,8 @@ function adFeed(url) {
742
828
  }
743
829
 
744
830
  // packages/vscode/src/browser.ts
745
- var import_node_child_process = require("node:child_process");
746
- var vscode3 = __toESM(require("vscode"));
831
+ var import_node_child_process2 = require("node:child_process");
832
+ var vscode2 = __toESM(require("vscode"));
747
833
 
748
834
  // packages/cli/src/server.ts
749
835
  var import_node_crypto2 = require("node:crypto");
@@ -1038,8 +1124,19 @@ data: ${JSON.stringify(data)}
1038
1124
  const sendFile = async (res, full) => {
1039
1125
  if (!full) return json(res, 403, { error: "forbidden" });
1040
1126
  try {
1127
+ const ext = (0, import_node_path2.extname)(full).toLowerCase();
1128
+ if (ext === ".html") {
1129
+ const osLoc = detectOsLocale();
1130
+ const htmlText = (await (0, import_promises2.readFile)(full, "utf8")).replace(
1131
+ /<html\b([^>]*)>/i,
1132
+ `<html lang="${osLoc === "zh" ? "zh-CN" : "en"}" data-os-locale="${osLoc}">`
1133
+ );
1134
+ res.writeHead(200, { "content-type": TYPES[".html"], "cache-control": "no-store" });
1135
+ res.end(htmlText, "utf8");
1136
+ return;
1137
+ }
1041
1138
  const body = await (0, import_promises2.readFile)(full);
1042
- res.writeHead(200, { "content-type": TYPES[(0, import_node_path2.extname)(full).toLowerCase()] ?? "application/octet-stream", "cache-control": sidebar ? "no-store" : "no-cache" });
1139
+ res.writeHead(200, { "content-type": TYPES[ext] ?? "application/octet-stream", "cache-control": sidebar ? "no-store" : "no-cache" });
1043
1140
  res.end(body);
1044
1141
  } catch {
1045
1142
  json(res, 404, { error: "not found" });
@@ -1298,7 +1395,6 @@ async function viaTextEditor(document, range) {
1298
1395
  }
1299
1396
 
1300
1397
  // packages/vscode/src/i18n.ts
1301
- var vscode2 = __toESM(require("vscode"));
1302
1398
  var zh = {
1303
1399
  openMarkdownFirst: "\u8BF7\u5148\u6253\u5F00\u4E00\u4E2A Markdown \u6587\u4EF6",
1304
1400
  browserOpened: "\u601D\u7EF4\u5BFC\u56FE\u5DF2\u5728\u6D4F\u89C8\u5668\u6253\u5F00\uFF1A{url}",
@@ -1339,17 +1435,7 @@ var en = {
1339
1435
  remove: "Sign Out",
1340
1436
  saveExport: "Export"
1341
1437
  };
1342
- var isChinese = () => {
1343
- if (/^zh/i.test(vscode2.env.language)) return true;
1344
- try {
1345
- const opts = Intl.DateTimeFormat().resolvedOptions();
1346
- if (/^zh\b/i.test(opts.locale || "")) return true;
1347
- const tz = opts.timeZone || "";
1348
- if (/^(Asia\/(Shanghai|Chongqing|Chungking|Harbin|Urumqi|Beijing)|PRC)$/i.test(tz)) return true;
1349
- } catch {
1350
- }
1351
- return false;
1352
- };
1438
+ var isChinese = () => detectOsLocale() === "zh";
1353
1439
  function t(key, vars = {}) {
1354
1440
  return (isChinese() ? zh : en)[key].replace(/\{(\w+)\}/g, (_, k) => vars[k] ?? "");
1355
1441
  }
@@ -1392,7 +1478,7 @@ var BrowserServers = class {
1392
1478
  }
1393
1479
  };
1394
1480
  function documentSource(uri, context) {
1395
- const document = () => vscode3.workspace.openTextDocument(uri);
1481
+ const document = () => vscode2.workspace.openTextDocument(uri);
1396
1482
  const viewKey = VIEW_STATE_PREFIX + uri.toString();
1397
1483
  return {
1398
1484
  name: docName2(uri),
@@ -1401,10 +1487,10 @@ function documentSource(uri, context) {
1401
1487
  async write(md) {
1402
1488
  const doc = await document();
1403
1489
  if (!await replaceText(doc, md)) throw new Error(t("readOnly"));
1404
- if (vscode3.workspace.getConfiguration("inkmap").get("browserAutoSave", true) && !doc.isUntitled) await doc.save();
1490
+ if (vscode2.workspace.getConfiguration("inkmap").get("browserAutoSave", true) && !doc.isUntitled) await doc.save();
1405
1491
  },
1406
1492
  watch(onChange) {
1407
- const sub = vscode3.workspace.onDidChangeTextDocument((e) => {
1493
+ const sub = vscode2.workspace.onDidChangeTextDocument((e) => {
1408
1494
  if (e.document.uri.toString() === uri.toString() && e.contentChanges.length) onChange();
1409
1495
  });
1410
1496
  return () => sub.dispose();
@@ -1416,11 +1502,11 @@ function documentSource(uri, context) {
1416
1502
  };
1417
1503
  }
1418
1504
  async function openUrl(url) {
1419
- const fallback = () => vscode3.env.openExternal(vscode3.Uri.parse(url));
1420
- if (vscode3.workspace.getConfiguration("inkmap").get("browser", "chrome") !== "chrome") return fallback();
1505
+ const fallback = () => vscode2.env.openExternal(vscode2.Uri.parse(url));
1506
+ if (vscode2.workspace.getConfiguration("inkmap").get("browser", "chrome") !== "chrome") return fallback();
1421
1507
  const [cmd, args] = process.platform === "darwin" ? ["open", ["-a", "Google Chrome", url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", "chrome", url]] : ["google-chrome", [url]];
1422
1508
  const ok = await new Promise((done) => {
1423
- const child = (0, import_node_child_process.spawn)(cmd, args, { stdio: "ignore", detached: true });
1509
+ const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1424
1510
  child.on("error", () => done(false));
1425
1511
  child.on("exit", (code) => done(code === 0));
1426
1512
  child.unref();
@@ -1429,10 +1515,10 @@ async function openUrl(url) {
1429
1515
  }
1430
1516
 
1431
1517
  // packages/vscode/src/license.ts
1432
- var vscode4 = __toESM(require("vscode"));
1518
+ var vscode3 = __toESM(require("vscode"));
1433
1519
  var KEY = "inkmap.billing.session";
1434
1520
  function extensionLicense(context) {
1435
- const app = (vscode4.env.appName || "").toLowerCase();
1521
+ const app = (vscode3.env.appName || "").toLowerCase();
1436
1522
  const host = app.includes("cursor") ? "cursor" : app.includes("windsurf") ? "windsurf" : app.includes("antigravity") ? "antigravity" : "vscode";
1437
1523
  return licenseService({
1438
1524
  read: () => Promise.resolve(context.secrets.get(KEY)),
@@ -1440,47 +1526,21 @@ function extensionLicense(context) {
1440
1526
  if (token) await context.secrets.store(KEY, token);
1441
1527
  else await context.secrets.delete(KEY);
1442
1528
  }
1443
- }, () => vscode4.workspace.getConfiguration("inkmap").get("billingOrigin") || process.env.INKMAP_BILLING_ORIGIN || "" || YUNFAN_BILLING_ORIGIN, { host });
1529
+ }, () => vscode3.workspace.getConfiguration("inkmap").get("billingOrigin") || process.env.INKMAP_BILLING_ORIGIN || "" || YUNFAN_BILLING_ORIGIN, { host });
1444
1530
  }
1445
1531
  async function openCheckout(license, mode, localeHint) {
1446
1532
  const url = await license.connect(mode, localeHint);
1447
- if (!await vscode4.env.openExternal(vscode4.Uri.parse(url))) throw new Error(t("checkoutFailed"));
1448
- }
1449
- async function offerPro(license) {
1450
- const state = await license.state();
1451
- const accountDetail = state.account ? t("accountLine", { account: state.account }) : state.connected ? t("accountConnected") : "";
1452
- if (state.pro) {
1453
- const signOut = t("remove");
1454
- const detail2 = [t("proActiveDetail"), accountDetail || t("accountConnected")].join("\n");
1455
- const pick2 = await vscode4.window.showInformationMessage("Inkmap Pro", { modal: true, detail: detail2 }, signOut);
1456
- if (pick2 === signOut) {
1457
- await license.deactivate();
1458
- vscode4.window.showInformationMessage(t("removed"));
1459
- }
1460
- return true;
1461
- }
1462
- const buy = t("buyPro");
1463
- const signIn = t(state.connected ? "switchAccount" : "signIn");
1464
- const detail = accountDetail ? `${accountDetail}
1465
- ${t("checkoutHint")}` : t("checkoutHint");
1466
- const pick = await vscode4.window.showInformationMessage("Inkmap Pro", { modal: true, detail }, buy, signIn);
1467
- if (pick) {
1468
- try {
1469
- await openCheckout(license, pick === buy ? "buy" : "restore");
1470
- } catch (error) {
1471
- vscode4.window.showErrorMessage(error instanceof Error ? error.message : t("checkoutFailed"));
1472
- }
1473
- }
1474
- return false;
1533
+ if (!await vscode3.env.openExternal(vscode3.Uri.parse(url))) throw new Error(t("checkoutFailed"));
1475
1534
  }
1476
1535
 
1477
1536
  // packages/vscode/src/mindmapEditor.ts
1478
1537
  var import_node_crypto3 = require("node:crypto");
1479
1538
  var import_promises3 = require("node:fs/promises");
1480
- var vscode5 = __toESM(require("vscode"));
1539
+ var vscode4 = __toESM(require("vscode"));
1481
1540
 
1482
1541
  // packages/vscode/src/html.ts
1483
1542
  function webviewHtml(html, { webBase, assetBase, cspSource, nonce, locale }) {
1543
+ const osLoc = locale === "auto" ? "" : /^zh\b/i.test(locale) ? "zh" : "en";
1484
1544
  const csp = [
1485
1545
  "default-src 'none'",
1486
1546
  `img-src ${cspSource} https: data: blob:`,
@@ -1490,8 +1550,8 @@ function webviewHtml(html, { webBase, assetBase, cspSource, nonce, locale }) {
1490
1550
  "form-action 'none'"
1491
1551
  ].join("; ");
1492
1552
  const head = `<meta http-equiv="Content-Security-Policy" content="${csp}">
1493
- <script nonce="${nonce}">window.INKMAP_ASSET_BASE = ${JSON.stringify(assetBase)}; window.INKMAP_LOCALE = ${JSON.stringify(locale)};</script>`;
1494
- return html.replace(/ crossorigin/g, "").replace(/(src|href)="\.\/assets\//g, `$1="${webBase}/assets/`).replace(/(src|href)="\.\/(app\.(?:js|css))"/g, `$1="${webBase}/$2"`).replace(/<script /g, `<script nonce="${nonce}" `).replace("<head>", `<head>
1553
+ <script nonce="${nonce}">window.INKMAP_ASSET_BASE = ${JSON.stringify(assetBase)}; window.INKMAP_LOCALE = ${JSON.stringify(osLoc || locale)};</script>`;
1554
+ return html.replace(/<html\b([^>]*)>/i, osLoc ? `<html lang="${osLoc === "zh" ? "zh-CN" : "en"}" data-os-locale="${osLoc}">` : "<html$1>").replace(/ crossorigin/g, "").replace(/(src|href)="\.\/assets\//g, `$1="${webBase}/assets/`).replace(/(src|href)="\.\/(app\.(?:js|css))"/g, `$1="${webBase}/$2"`).replace(/<script /g, `<script nonce="${nonce}" `).replace("<head>", `<head>
1495
1555
  ${head}`);
1496
1556
  }
1497
1557
 
@@ -1512,14 +1572,21 @@ var MindmapEditorProvider = class {
1512
1572
  const panel = [...this.panels].find((p) => p.active);
1513
1573
  return panel ? panel.webview.postMessage({ type: "requestChat" }) : openChat();
1514
1574
  }
1575
+ /** Opens the inline Category 1 account & payment panel directly inside the active Inkmap editor tab. */
1576
+ openAccount() {
1577
+ const panel = [...this.panels].find((p) => p.active) ?? [...this.panels].find((p) => p.visible);
1578
+ if (!panel) return false;
1579
+ void panel.webview.postMessage({ type: "openAccount" });
1580
+ return true;
1581
+ }
1515
1582
  async resolveCustomTextEditor(document, panel) {
1516
1583
  const webview = panel.webview;
1517
1584
  this.panels.add(panel);
1518
- const webRoot = vscode5.Uri.joinPath(this.context.extensionUri, "dist", "web");
1585
+ const webRoot = vscode4.Uri.joinPath(this.context.extensionUri, "dist", "web");
1519
1586
  const assets = docDir(document.uri);
1520
1587
  webview.options = {
1521
1588
  enableScripts: true,
1522
- localResourceRoots: [webRoot, ...assets ? [assets] : [], ...(vscode5.workspace.workspaceFolders ?? []).map((f) => f.uri)]
1589
+ localResourceRoots: [webRoot, ...assets ? [assets] : [], ...(vscode4.workspace.workspaceFolders ?? []).map((f) => f.uri)]
1523
1590
  };
1524
1591
  webview.html = await editorHtml(webview, webRoot, assets);
1525
1592
  const viewKey = VIEW_STATE_PREFIX2 + document.uri.toString();
@@ -1549,18 +1616,18 @@ var MindmapEditorProvider = class {
1549
1616
  panel.onDidChangeViewState(({ webviewPanel }) => {
1550
1617
  if (webviewPanel.visible) void syncLicense();
1551
1618
  }),
1552
- vscode5.window.onDidChangeWindowState(({ focused }) => {
1619
+ vscode4.window.onDidChangeWindowState(({ focused }) => {
1553
1620
  if (focused && panel.visible) void syncLicense();
1554
1621
  }),
1555
- vscode5.workspace.onDidChangeTextDocument((e) => {
1622
+ vscode4.workspace.onDidChangeTextDocument((e) => {
1556
1623
  if (applying || e.document !== document || !e.contentChanges.length) return;
1557
1624
  clearTimeout(changeTimer);
1558
1625
  changeTimer = setTimeout(() => post({ type: "change", doc: state() }), CHANGE_DELAY);
1559
1626
  }),
1560
- vscode5.window.onDidChangeTextEditorSelection((e) => {
1627
+ vscode4.window.onDidChangeTextEditorSelection((e) => {
1561
1628
  if (e.textEditor.document !== document) return;
1562
1629
  linkedEditor = e.textEditor;
1563
- const userMoved = e.kind === vscode5.TextEditorSelectionChangeKind.Keyboard || e.kind === vscode5.TextEditorSelectionChangeKind.Mouse;
1630
+ const userMoved = e.kind === vscode4.TextEditorSelectionChangeKind.Keyboard || e.kind === vscode4.TextEditorSelectionChangeKind.Mouse;
1564
1631
  if (!userMoved) return;
1565
1632
  clearTimeout(revealTimer);
1566
1633
  revealTimer = setTimeout(() => post({ type: "reveal", line: e.selections[0].active.line }), REVEAL_DELAY);
@@ -1601,25 +1668,25 @@ var MindmapEditorProvider = class {
1601
1668
  }
1602
1669
  case "undo":
1603
1670
  case "redo":
1604
- return vscode5.commands.executeCommand(msg.type);
1671
+ return vscode4.commands.executeCommand(msg.type);
1605
1672
  case "select": {
1606
1673
  const line = Math.max(0, Math.min(msg.line, document.lineCount - 1));
1607
1674
  const endLine = Math.max(line, Math.min(msg.endLine ?? line, document.lineCount - 1));
1608
1675
  const reveal = (editor2) => {
1609
- const start = new vscode5.Position(line, 0);
1610
- const end = new vscode5.Position(endLine, document.lineAt(endLine).text.length);
1611
- editor2.selection = new vscode5.Selection(start, end);
1612
- editor2.revealRange(new vscode5.Range(start, end), vscode5.TextEditorRevealType.InCenter);
1676
+ const start = new vscode4.Position(line, 0);
1677
+ const end = new vscode4.Position(endLine, document.lineAt(endLine).text.length);
1678
+ editor2.selection = new vscode4.Selection(start, end);
1679
+ editor2.revealRange(new vscode4.Range(start, end), vscode4.TextEditorRevealType.InCenter);
1613
1680
  };
1614
- const editor = linkedEditor?.document === document ? linkedEditor : vscode5.window.visibleTextEditors.find((e) => e.document === document);
1681
+ const editor = linkedEditor?.document === document ? linkedEditor : vscode4.window.visibleTextEditors.find((e) => e.document === document);
1615
1682
  if (editor) {
1616
1683
  reveal(editor);
1617
1684
  return;
1618
1685
  }
1619
- const opened = await vscode5.window.showTextDocument(document, {
1686
+ const opened = await vscode4.window.showTextDocument(document, {
1620
1687
  preview: false,
1621
1688
  preserveFocus: true,
1622
- viewColumn: vscode5.ViewColumn.Beside
1689
+ viewColumn: vscode4.ViewColumn.Beside
1623
1690
  });
1624
1691
  reveal(opened);
1625
1692
  return;
@@ -1638,7 +1705,7 @@ var MindmapEditorProvider = class {
1638
1705
  try {
1639
1706
  const result = await this.license.orderPro(msg.locale);
1640
1707
  if (result.status === "redirect" && /^https:\/\//.test(result.url)) {
1641
- void vscode5.env.openExternal(vscode5.Uri.parse(result.url));
1708
+ void vscode4.env.openExternal(vscode4.Uri.parse(result.url));
1642
1709
  }
1643
1710
  return post({ type: "proOrder", id: msg.id, result });
1644
1711
  } catch (error) {
@@ -1646,7 +1713,7 @@ var MindmapEditorProvider = class {
1646
1713
  }
1647
1714
  case "openExternal":
1648
1715
  if (typeof msg.url === "string" && /^https:\/\//.test(msg.url)) {
1649
- void vscode5.env.openExternal(vscode5.Uri.parse(msg.url));
1716
+ void vscode4.env.openExternal(vscode4.Uri.parse(msg.url));
1650
1717
  }
1651
1718
  return;
1652
1719
  case "signOut":
@@ -1673,8 +1740,8 @@ async function saveDataUrl(name, dataUrl, dir) {
1673
1740
  const match = dataUrl.match(/^data:([^;,]+)?(;base64)?,(.*)$/s);
1674
1741
  if (!match) return false;
1675
1742
  const ext = name.split(".").pop() ?? "";
1676
- const target = await vscode5.window.showSaveDialog({
1677
- defaultUri: dir ? vscode5.Uri.joinPath(dir, name) : void 0,
1743
+ const target = await vscode4.window.showSaveDialog({
1744
+ defaultUri: dir ? vscode4.Uri.joinPath(dir, name) : void 0,
1678
1745
  filters: { [ext.toUpperCase()]: [ext] },
1679
1746
  saveLabel: t("saveExport")
1680
1747
  });
@@ -1684,12 +1751,12 @@ async function saveDataUrl(name, dataUrl, dir) {
1684
1751
  return true;
1685
1752
  }
1686
1753
  async function editorHtml(webview, webRoot, assets) {
1687
- return webviewHtml(await (0, import_promises3.readFile)(vscode5.Uri.joinPath(webRoot, "index.html").fsPath, "utf8"), {
1754
+ return webviewHtml(await (0, import_promises3.readFile)(vscode4.Uri.joinPath(webRoot, "index.html").fsPath, "utf8"), {
1688
1755
  webBase: webview.asWebviewUri(webRoot).toString(),
1689
1756
  assetBase: assets ? webview.asWebviewUri(assets).toString() + "/" : "",
1690
1757
  cspSource: webview.cspSource,
1691
1758
  nonce: (0, import_node_crypto3.randomBytes)(16).toString("base64"),
1692
- locale: isChinese() ? "zh-cn" : vscode5.env.language
1759
+ locale: detectOsLocale()
1693
1760
  });
1694
1761
  }
1695
1762
 
@@ -1700,22 +1767,22 @@ function insideOrEqual(root, target) {
1700
1767
  return Boolean(rel && !(0, import_node_path3.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(".." + import_node_path3.sep));
1701
1768
  }
1702
1769
  function resolveEditorUri(filePath) {
1703
- for (const folder of vscode6.workspace.workspaceFolders ?? []) {
1770
+ for (const folder of vscode5.workspace.workspaceFolders ?? []) {
1704
1771
  const folderPath = folder.uri.fsPath || folder.uri.path;
1705
1772
  if (folderPath && insideOrEqual(folderPath, filePath)) {
1706
1773
  const rel = (0, import_node_path3.relative)(folderPath, filePath).split(import_node_path3.sep).join("/");
1707
- return rel ? vscode6.Uri.joinPath(folder.uri, rel) : folder.uri;
1774
+ return rel ? vscode5.Uri.joinPath(folder.uri, rel) : folder.uri;
1708
1775
  }
1709
1776
  }
1710
- const first = vscode6.workspace.workspaceFolders?.[0];
1777
+ const first = vscode5.workspace.workspaceFolders?.[0];
1711
1778
  if (first && first.uri.scheme !== "file") {
1712
1779
  return first.uri.with({ path: filePath });
1713
1780
  }
1714
- return vscode6.Uri.file(filePath);
1781
+ return vscode5.Uri.file(filePath);
1715
1782
  }
1716
1783
  function findColumnForFile(fileUri) {
1717
1784
  const targetFs = fileUri.fsPath || fileUri.path;
1718
- for (const group of vscode6.window.tabGroups.all) {
1785
+ for (const group of vscode5.window.tabGroups.all) {
1719
1786
  for (const tab of group.tabs) {
1720
1787
  const input = tab.input;
1721
1788
  if (input?.uri && (input.uri.fsPath === targetFs || input.uri.path === targetFs)) {
@@ -1726,7 +1793,7 @@ function findColumnForFile(fileUri) {
1726
1793
  }
1727
1794
  }
1728
1795
  }
1729
- return vscode6.window.activeTextEditor?.viewColumn ?? vscode6.ViewColumn.Active;
1796
+ return vscode5.window.activeTextEditor?.viewColumn ?? vscode5.ViewColumn.Active;
1730
1797
  }
1731
1798
  function localEditorUrl(value) {
1732
1799
  if (typeof value !== "string") return void 0;
@@ -1741,7 +1808,7 @@ function localEditorUrl(value) {
1741
1808
  }
1742
1809
  }
1743
1810
  async function openUrlInEditorPane(url) {
1744
- await vscode6.commands.executeCommand("workbench.action.openBrowserEditor", {
1811
+ await vscode5.commands.executeCommand("workbench.action.openBrowserEditor", {
1745
1812
  url,
1746
1813
  preserveFocus: false,
1747
1814
  inactive: false,
@@ -1751,7 +1818,7 @@ async function openUrlInEditorPane(url) {
1751
1818
  async function openFileInEditorPane(filePath) {
1752
1819
  const fileUri = resolveEditorUri(filePath);
1753
1820
  const viewColumn = findColumnForFile(fileUri);
1754
- await vscode6.commands.executeCommand("vscode.openWith", fileUri, MindmapEditorProvider.viewType, {
1821
+ await vscode5.commands.executeCommand("vscode.openWith", fileUri, MindmapEditorProvider.viewType, {
1755
1822
  viewColumn,
1756
1823
  preserveFocus: false
1757
1824
  });
@@ -1770,10 +1837,10 @@ function startMcpTargetBridge() {
1770
1837
  await (0, import_promises4.writeFile)(statusPath, JSON.stringify({
1771
1838
  pid: process.pid,
1772
1839
  activatedAt: Date.now(),
1773
- appName: vscode6.env.appName,
1774
- remoteName: vscode6.env.remoteName,
1775
- focused: vscode6.window.state.focused,
1776
- folders: (vscode6.workspace.workspaceFolders ?? []).map((f) => f.uri.toString())
1840
+ appName: vscode5.env.appName,
1841
+ remoteName: vscode5.env.remoteName,
1842
+ focused: vscode5.window.state.focused,
1843
+ folders: (vscode5.workspace.workspaceFolders ?? []).map((f) => f.uri.toString())
1777
1844
  }, null, 2), { mode: 384 });
1778
1845
  } catch {
1779
1846
  }
@@ -1796,7 +1863,7 @@ function startMcpTargetBridge() {
1796
1863
  const seq = Number(raw.seq) || 0;
1797
1864
  if (seq <= lastSeq || typeof raw.file !== "string") return;
1798
1865
  const realTarget = await (0, import_promises4.realpath)(raw.file).catch(() => raw.file);
1799
- const folders = vscode6.workspace.workspaceFolders ?? [];
1866
+ const folders = vscode5.workspace.workspaceFolders ?? [];
1800
1867
  let matchesWindow = false;
1801
1868
  for (const folder of folders) {
1802
1869
  const folderPath = folder.uri.fsPath || folder.uri.path;
@@ -1807,7 +1874,7 @@ function startMcpTargetBridge() {
1807
1874
  break;
1808
1875
  }
1809
1876
  }
1810
- if (!matchesWindow && vscode6.window.state.focused) {
1877
+ if (!matchesWindow && vscode5.window.state.focused) {
1811
1878
  matchesWindow = true;
1812
1879
  }
1813
1880
  if (!matchesWindow) return;
@@ -1898,7 +1965,7 @@ async function syncDeepSeekHarnessIfInstalled() {
1898
1965
  ].filter(Boolean);
1899
1966
  const dshBin = candidates.find((c) => (0, import_node_fs2.existsSync)(c));
1900
1967
  if (dshBin) {
1901
- const child = (0, import_node_child_process2.spawn)(dshBin, ["plugin", "--profile", "desktop", "add", spec], { stdio: "ignore", detached: true });
1968
+ const child = (0, import_node_child_process3.spawn)(dshBin, ["plugin", "--profile", "desktop", "add", spec], { stdio: "ignore", detached: true });
1902
1969
  child.unref();
1903
1970
  }
1904
1971
  } catch {
@@ -1906,29 +1973,29 @@ async function syncDeepSeekHarnessIfInstalled() {
1906
1973
  }
1907
1974
  function activate(context) {
1908
1975
  void syncDeepSeekHarnessIfInstalled();
1909
- const log = vscode6.window.createOutputChannel("Inkmap");
1976
+ const log = vscode5.window.createOutputChannel("Inkmap");
1910
1977
  const license = extensionLicense(context);
1911
1978
  const ads = adFeed(PRODUCT.adFeedUrl);
1912
- const browsers = new BrowserServers(context, vscode6.Uri.joinPath(context.extensionUri, "dist", "web").fsPath, log, license, ads);
1979
+ const browsers = new BrowserServers(context, vscode5.Uri.joinPath(context.extensionUri, "dist", "web").fsPath, log, license, ads);
1913
1980
  const withUri = (run) => (arg) => {
1914
1981
  const uri = targetUri(arg);
1915
- if (!uri) return vscode6.window.showWarningMessage(t("openMarkdownFirst"));
1982
+ if (!uri) return vscode5.window.showWarningMessage(t("openMarkdownFirst"));
1916
1983
  return run(uri);
1917
1984
  };
1918
1985
  const openToSide = withUri(
1919
- (uri) => vscode6.commands.executeCommand("vscode.openWith", uri, MindmapEditorProvider.viewType, {
1920
- viewColumn: vscode6.ViewColumn.Beside,
1986
+ (uri) => vscode5.commands.executeCommand("vscode.openWith", uri, MindmapEditorProvider.viewType, {
1987
+ viewColumn: vscode5.ViewColumn.Beside,
1921
1988
  preserveFocus: true
1922
1989
  })
1923
1990
  );
1924
1991
  const editors = new MindmapEditorProvider(context, license, ads);
1925
- chatAvailable().then((available) => vscode6.commands.executeCommand("setContext", "inkmap.chatAvailable", available));
1992
+ chatAvailable().then((available) => vscode5.commands.executeCommand("setContext", "inkmap.chatAvailable", available));
1926
1993
  context.subscriptions.push(
1927
1994
  log,
1928
1995
  license,
1929
1996
  browsers,
1930
1997
  startMcpTargetBridge(),
1931
- vscode6.window.registerUriHandler({
1998
+ vscode5.window.registerUriHandler({
1932
1999
  handleUri(uri) {
1933
2000
  if (uri.path === "/open") {
1934
2001
  const target = new URLSearchParams(uri.query).get("path");
@@ -1936,43 +2003,40 @@ function activate(context) {
1936
2003
  }
1937
2004
  }
1938
2005
  }),
1939
- vscode6.window.registerCustomEditorProvider(MindmapEditorProvider.viewType, editors, {
2006
+ vscode5.window.registerCustomEditorProvider(MindmapEditorProvider.viewType, editors, {
1940
2007
  webviewOptions: { retainContextWhenHidden: true }
1941
2008
  }),
1942
- vscode6.commands.registerCommand("inkmap.addToChat", () => editors.requestChat()),
1943
- vscode6.commands.registerCommand("inkmap.open", openToSide),
1944
- vscode6.commands.registerCommand("inkmap.openToSide", openToSide),
1945
- vscode6.commands.registerCommand(
2009
+ vscode5.commands.registerCommand("inkmap.addToChat", () => editors.requestChat()),
2010
+ vscode5.commands.registerCommand("inkmap.open", openToSide),
2011
+ vscode5.commands.registerCommand("inkmap.openToSide", openToSide),
2012
+ vscode5.commands.registerCommand(
1946
2013
  "inkmap.showSource",
1947
- withUri((uri) => vscode6.window.showTextDocument(uri, { viewColumn: vscode6.ViewColumn.Beside, preview: false }))
2014
+ withUri((uri) => vscode5.window.showTextDocument(uri, { viewColumn: vscode5.ViewColumn.Beside, preview: false }))
1948
2015
  ),
1949
- vscode6.commands.registerCommand(
2016
+ vscode5.commands.registerCommand(
1950
2017
  "inkmap.openInBrowser",
1951
2018
  withUri(async (uri) => {
1952
- if (!hasAccess(await license.state()) && !await offerPro(license)) return;
2019
+ if (!hasAccess(await license.state())) {
2020
+ await openToSide(uri);
2021
+ setTimeout(() => editors.openAccount(), 250);
2022
+ return;
2023
+ }
1953
2024
  try {
1954
2025
  license.track?.("feature_browser");
1955
2026
  const url = await browsers.open(uri);
1956
- const pick = await vscode6.window.showInformationMessage(t("browserOpened", { url }), t("copyLink"));
1957
- if (pick) await vscode6.env.clipboard.writeText(url);
2027
+ const pick = await vscode5.window.showInformationMessage(t("browserOpened", { url }), t("copyLink"));
2028
+ if (pick) await vscode5.env.clipboard.writeText(url);
1958
2029
  } catch (err) {
1959
- vscode6.window.showErrorMessage(t("browserFailed", { error: err instanceof Error ? err.message : String(err) }));
2030
+ vscode5.window.showErrorMessage(t("browserFailed", { error: err instanceof Error ? err.message : String(err) }));
1960
2031
  }
1961
2032
  })
1962
2033
  ),
1963
- vscode6.commands.registerCommand("inkmap.upgrade", () => offerPro(license)),
1964
- vscode6.commands.registerCommand("inkmap.restorePro", async () => {
1965
- try {
1966
- await openCheckout(license, "restore");
1967
- } catch (error) {
1968
- vscode6.window.showErrorMessage(error instanceof Error ? error.message : t("checkoutFailed"));
1969
- }
1970
- }),
1971
- vscode6.commands.registerCommand("inkmap.signOut", async () => {
1972
- const remove = t("remove");
1973
- if (await vscode6.window.showWarningMessage(t("removeConfirm"), { modal: true }, remove) !== remove) return;
1974
- await license.deactivate();
1975
- vscode6.window.showInformationMessage(t("removed"));
2034
+ vscode5.commands.registerCommand("inkmap.upgrade", async (arg) => {
2035
+ if (editors.openAccount()) return;
2036
+ const uri = targetUri(arg);
2037
+ if (!uri) return vscode5.window.showWarningMessage(t("openMarkdownFirst"));
2038
+ await openToSide(uri);
2039
+ setTimeout(() => editors.openAccount(), 280);
1976
2040
  })
1977
2041
  );
1978
2042
  }