inkmap-mcp 0.3.10 → 0.3.11
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/bundles/antigravity/sidecars/inkmap/bridge.js +145 -126
- package/dist/bundles/antigravity/sidecars/inkmap/main.mjs +789 -587
- package/dist/bundles/codex/inkmap-codex/.codex-plugin/plugin.json +1 -1
- package/dist/bundles/codex/inkmap-codex/plugin.json +1 -1
- package/dist/bundles/harness/client.js +14 -3
- package/dist/bundles/harness/host.js +597 -327
- package/dist/bundles/harness/package.json +1 -1
- package/dist/bundles/vscode/dist/extension.js +741 -447
- package/dist/bundles/vscode/package.json +6 -1
- package/dist/bundles/vscode/package.nls.json +1 -0
- package/dist/bundles/vscode/package.nls.zh-cn.json +1 -0
- package/dist/cli.cjs +1371 -967
- package/dist/codex.html +728 -680
- package/dist/web/app.js +29831 -29591
- package/dist/web/index.html +4 -4
- package/package.json +1 -1
- package/server.json +2 -2
- package/dist/bundles/antigravity/sidecars/inkmap/select.mjs +0 -74
- package/dist/web/app.css +0 -11
|
@@ -38,9 +38,7 @@ module.exports = __toCommonJS(extension_exports);
|
|
|
38
38
|
// packages/core/dist/product.js
|
|
39
39
|
var PRODUCT = {
|
|
40
40
|
id: "inkmap-pro",
|
|
41
|
-
entitlement: "inkmap.pro"
|
|
42
|
-
/** JSON list of sponsor ads shown in the free edition; empty means house ads only. */
|
|
43
|
-
adFeedUrl: ""
|
|
41
|
+
entitlement: "inkmap.pro"
|
|
44
42
|
};
|
|
45
43
|
var YUNFAN_BILLING_ORIGIN = "https://zhiyuanv.com";
|
|
46
44
|
function billingFlowUrl(raw, origin, mode, legacy = false) {
|
|
@@ -58,24 +56,6 @@ var TRIAL_MS = 7 * DAY_MS;
|
|
|
58
56
|
function hasAccess(state, now = Date.now()) {
|
|
59
57
|
return state.pro || (state.trialUntil ?? 0) > now;
|
|
60
58
|
}
|
|
61
|
-
function sanitizeAds(input) {
|
|
62
|
-
if (!Array.isArray(input))
|
|
63
|
-
return [];
|
|
64
|
-
const str = (v, max) => typeof v === "string" && v.trim() ? v.trim().slice(0, max) : void 0;
|
|
65
|
-
const out = [];
|
|
66
|
-
for (const raw of input.slice(0, 20)) {
|
|
67
|
-
const r = raw;
|
|
68
|
-
const id = str(r?.id, 64);
|
|
69
|
-
const title = str(r?.title, 60);
|
|
70
|
-
const text = str(r?.text, 140);
|
|
71
|
-
const url = str(r?.url, 500);
|
|
72
|
-
if (!id || !title || !text || !url || !/^https:\/\//.test(url))
|
|
73
|
-
continue;
|
|
74
|
-
const locale = r.locale === "zh" || r.locale === "en" ? r.locale : void 0;
|
|
75
|
-
out.push({ id, title, text, url, cta: str(r.cta, 20), locale });
|
|
76
|
-
}
|
|
77
|
-
return out;
|
|
78
|
-
}
|
|
79
59
|
|
|
80
60
|
// packages/core/dist/index.js
|
|
81
61
|
function sanitizeViewState(raw) {
|
|
@@ -105,10 +85,23 @@ function sanitizeViewState(raw) {
|
|
|
105
85
|
// packages/vscode/src/extension.ts
|
|
106
86
|
var import_node_child_process4 = require("node:child_process");
|
|
107
87
|
var import_node_fs2 = require("node:fs");
|
|
108
|
-
var
|
|
88
|
+
var import_promises5 = require("node:fs/promises");
|
|
89
|
+
var import_node_os4 = require("node:os");
|
|
90
|
+
var import_node_path4 = require("node:path");
|
|
91
|
+
var vscode5 = __toESM(require("vscode"));
|
|
92
|
+
|
|
93
|
+
// packages/vscode/src/browser.ts
|
|
94
|
+
var import_node_child_process3 = require("node:child_process");
|
|
95
|
+
var vscode2 = __toESM(require("vscode"));
|
|
96
|
+
|
|
97
|
+
// packages/cli/src/server.ts
|
|
98
|
+
var import_node_child_process2 = require("node:child_process");
|
|
99
|
+
var import_node_crypto2 = require("node:crypto");
|
|
100
|
+
var import_node_fs = require("node:fs");
|
|
101
|
+
var import_promises3 = require("node:fs/promises");
|
|
102
|
+
var import_node_http = require("node:http");
|
|
109
103
|
var import_node_os3 = require("node:os");
|
|
110
104
|
var import_node_path3 = require("node:path");
|
|
111
|
-
var vscode5 = __toESM(require("vscode"));
|
|
112
105
|
|
|
113
106
|
// packages/cli/src/license.ts
|
|
114
107
|
var import_node_child_process = require("node:child_process");
|
|
@@ -116,47 +109,75 @@ var import_promises = require("node:fs/promises");
|
|
|
116
109
|
var import_node_crypto = require("node:crypto");
|
|
117
110
|
var import_node_os = require("node:os");
|
|
118
111
|
var import_node_path = require("node:path");
|
|
112
|
+
|
|
113
|
+
// packages/cli/src/version.ts
|
|
114
|
+
var INKMAP_VERSION = "0.3.11";
|
|
115
|
+
|
|
116
|
+
// packages/cli/src/license.ts
|
|
117
|
+
var ZH_LOCALE_RE = /^zh(?:[-_.]|$)/i;
|
|
118
|
+
var EN_LOCALE_RE = /^en(?:[-_.]|$)/i;
|
|
119
119
|
var cachedOsLocale;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
120
|
+
var WAIT_FAST_MS = 2500;
|
|
121
|
+
var WAIT_SLOW_MS = 3e4;
|
|
122
|
+
var WAIT_FAST_FOR_MS = 30 * 6e4;
|
|
123
|
+
var WAIT_MAX_MS = 3 * 24 * 60 * 6e4;
|
|
124
|
+
var MAX_WAITING = 5;
|
|
125
|
+
function isWaitingToken(value) {
|
|
126
|
+
const w = value;
|
|
127
|
+
return Boolean(w) && typeof w.origin === "string" && typeof w.token === "string" && /^[A-Za-z0-9_-]{43}$/.test(w.token) && typeof w.email === "string" && typeof w.since === "number" && typeof w.fastUntil === "number";
|
|
128
|
+
}
|
|
129
|
+
var DOMESTIC_TIME_ZONE = /^(Asia\/(Shanghai|Chongqing|Chungking|Harbin|Urumqi|Beijing)|PRC)$/i;
|
|
130
|
+
function parseAppleLanguages(output) {
|
|
131
|
+
const match = /^\(\s*(?:"([^"]+)"|([^\s,)]+))/m.exec(output);
|
|
132
|
+
return match?.[1] ?? match?.[2] ?? "";
|
|
133
|
+
}
|
|
134
|
+
var posixLocale = (env5) => (env5.LC_ALL || env5.LC_MESSAGES || env5.LANG || "").trim();
|
|
135
|
+
function resolveOsLocale(probe) {
|
|
136
|
+
const explicit = (probe.env.INKMAP_LOCALE || "").trim();
|
|
137
|
+
if (ZH_LOCALE_RE.test(explicit)) return "zh";
|
|
138
|
+
if (EN_LOCALE_RE.test(explicit)) return "en";
|
|
139
|
+
if (DOMESTIC_TIME_ZONE.test(probe.timeZone)) return "zh";
|
|
140
|
+
let language = "";
|
|
141
|
+
if (probe.platform === "darwin") {
|
|
142
|
+
try {
|
|
143
|
+
language = parseAppleLanguages(probe.run("defaults", ["read", "-g", "AppleLanguages"]));
|
|
144
|
+
} catch {
|
|
145
|
+
language = posixLocale(probe.env);
|
|
130
146
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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;
|
|
147
|
+
} else if (probe.platform === "win32") {
|
|
148
|
+
try {
|
|
149
|
+
const output = probe.run("reg", ["query", "HKCU\\Control Panel\\International", "/v", "LocaleName"]);
|
|
150
|
+
language = /LocaleName\s+REG_\w+\s+(\S+)/i.exec(output)?.[1] ?? "";
|
|
151
|
+
} catch {
|
|
156
152
|
}
|
|
153
|
+
if (!language) language = probe.intlLocale;
|
|
154
|
+
} else {
|
|
155
|
+
language = posixLocale(probe.env);
|
|
157
156
|
}
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
return ZH_LOCALE_RE.test(language) ? "zh" : "en";
|
|
158
|
+
}
|
|
159
|
+
function systemLocaleProbe() {
|
|
160
|
+
let timeZone = "";
|
|
161
|
+
let intlLocale = "";
|
|
162
|
+
try {
|
|
163
|
+
const options = Intl.DateTimeFormat().resolvedOptions();
|
|
164
|
+
timeZone = options.timeZone || "";
|
|
165
|
+
intlLocale = options.locale || "";
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
platform: process.platform,
|
|
170
|
+
env: process.env,
|
|
171
|
+
timeZone,
|
|
172
|
+
intlLocale,
|
|
173
|
+
run: (command, args) => (0, import_node_child_process.execFileSync)(command, args, { encoding: "utf8", timeout: 800, windowsHide: true, stdio: ["ignore", "pipe", "ignore"] })
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function detectOsLocale() {
|
|
177
|
+
const explicit = (process.env.INKMAP_LOCALE || "").trim();
|
|
178
|
+
if (ZH_LOCALE_RE.test(explicit)) return "zh";
|
|
179
|
+
if (EN_LOCALE_RE.test(explicit)) return "en";
|
|
180
|
+
return cachedOsLocale ??= resolveOsLocale(systemLocaleProbe());
|
|
160
181
|
}
|
|
161
182
|
function billingOrigin(raw) {
|
|
162
183
|
if (!raw) throw new Error("Inkmap checkout is not configured.");
|
|
@@ -166,7 +187,7 @@ function billingOrigin(raw) {
|
|
|
166
187
|
}
|
|
167
188
|
return url.origin;
|
|
168
189
|
}
|
|
169
|
-
function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "" } = {}) {
|
|
190
|
+
function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS } = {}) {
|
|
170
191
|
const listeners = /* @__PURE__ */ new Set();
|
|
171
192
|
let current = { pro: false };
|
|
172
193
|
let trial;
|
|
@@ -178,6 +199,9 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
178
199
|
let detectedHost = defaultHost;
|
|
179
200
|
const pendingEvents = /* @__PURE__ */ new Map();
|
|
180
201
|
let lastCheck = 0;
|
|
202
|
+
let fastPollUntil = 0;
|
|
203
|
+
const expectPurchase = () => void (fastPollUntil = Date.now() + 15 * 6e4);
|
|
204
|
+
let flowCreation;
|
|
181
205
|
let disposed = false;
|
|
182
206
|
let generation = 0;
|
|
183
207
|
let connection;
|
|
@@ -185,12 +209,32 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
185
209
|
let pendingWrite = Promise.resolve();
|
|
186
210
|
let pendingCheckout;
|
|
187
211
|
let cachedOrder;
|
|
188
|
-
let
|
|
189
|
-
let
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
212
|
+
let waiting = [];
|
|
213
|
+
let waitTimer;
|
|
214
|
+
let waitRound = 0;
|
|
215
|
+
let lastSignIn;
|
|
216
|
+
const sessionRecord = (fields) => JSON.stringify({ ...fields, ...lastSignIn && { lastSignIn } });
|
|
217
|
+
const signedOutRecord = () => lastSignIn || waiting.length ? JSON.stringify({ ...lastSignIn && { lastSignIn }, ...waiting.length && { waiting } }) : void 0;
|
|
218
|
+
async function rememberSignIn(id) {
|
|
219
|
+
const clean = id.trim().slice(0, 254);
|
|
220
|
+
if (!clean || clean === lastSignIn) return;
|
|
221
|
+
lastSignIn = clean;
|
|
222
|
+
current = { ...current, lastSignIn };
|
|
223
|
+
await writeSession(async () => {
|
|
224
|
+
let record = {};
|
|
225
|
+
try {
|
|
226
|
+
record = JSON.parse(await storage.read() || "{}");
|
|
227
|
+
} catch {
|
|
228
|
+
}
|
|
229
|
+
await storage.write(JSON.stringify({ ...record, lastSignIn }));
|
|
230
|
+
}).catch(() => {
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function clearWaiting() {
|
|
234
|
+
waiting = [];
|
|
235
|
+
++waitRound;
|
|
236
|
+
clearTimeout(waitTimer);
|
|
237
|
+
waitTimer = void 0;
|
|
194
238
|
}
|
|
195
239
|
function mergeCookies(existing, response) {
|
|
196
240
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -219,10 +263,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
219
263
|
}
|
|
220
264
|
return /^1\d{10}$/.test(clean) ? `${clean.slice(0, 3)}****${clean.slice(7)}` : clean.slice(0, 32);
|
|
221
265
|
}
|
|
222
|
-
function clientLocale(
|
|
223
|
-
const h = (hint || "").trim();
|
|
224
|
-
if (/^zh\b/i.test(h)) return "zh";
|
|
225
|
-
if (/^en\b/i.test(h)) return "en";
|
|
266
|
+
function clientLocale(_uiLocaleHint) {
|
|
226
267
|
return detectOsLocale();
|
|
227
268
|
}
|
|
228
269
|
function writeSession(operation) {
|
|
@@ -253,7 +294,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
253
294
|
if (typeof data.token !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(data.token)) {
|
|
254
295
|
throw new Error("Invalid Inkmap checkout response.");
|
|
255
296
|
}
|
|
256
|
-
return { origin, url, token: data.token, ...cookie && { cookie } };
|
|
297
|
+
return { origin, url, token: data.token, locale: loc, ...cookie && { cookie } };
|
|
257
298
|
}
|
|
258
299
|
function checkoutPost(checkoutUrl, action, origin, body, token, cookie, localeHint) {
|
|
259
300
|
const loc = clientLocale(localeHint);
|
|
@@ -312,11 +353,25 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
312
353
|
pro,
|
|
313
354
|
...current.trialUntil !== void 0 && { trialUntil: current.trialUntil },
|
|
314
355
|
...connected && { connected: true },
|
|
315
|
-
...cleanAccount && { account: cleanAccount }
|
|
356
|
+
...cleanAccount && { account: cleanAccount },
|
|
357
|
+
...lastSignIn && { lastSignIn }
|
|
316
358
|
};
|
|
317
359
|
for (const listener of listeners) listener(current);
|
|
318
360
|
}
|
|
319
361
|
async function startTrial() {
|
|
362
|
+
try {
|
|
363
|
+
const record = JSON.parse(await storage.read() || "{}");
|
|
364
|
+
const remembered = record.lastSignIn;
|
|
365
|
+
if (typeof remembered === "string" && remembered.trim() && !lastSignIn) {
|
|
366
|
+
lastSignIn = remembered.trim().slice(0, 254);
|
|
367
|
+
current = { ...current, lastSignIn };
|
|
368
|
+
}
|
|
369
|
+
if (typeof record.token !== "string" && Array.isArray(record.waiting) && !waiting.length) {
|
|
370
|
+
waiting = record.waiting.filter(isWaitingToken).slice(-MAX_WAITING);
|
|
371
|
+
scheduleWait(waitPollMs);
|
|
372
|
+
}
|
|
373
|
+
} catch {
|
|
374
|
+
}
|
|
320
375
|
const trialUntil = await localTrialDeadline().catch(() => void 0);
|
|
321
376
|
if (disposed || trialUntil === void 0) return;
|
|
322
377
|
current = { ...current, trialUntil };
|
|
@@ -359,7 +414,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
359
414
|
token = void 0;
|
|
360
415
|
return await writeSession(async () => {
|
|
361
416
|
if (version !== generation || disposed) return;
|
|
362
|
-
await storage.write(
|
|
417
|
+
await storage.write(signedOutRecord()).catch(() => {
|
|
363
418
|
});
|
|
364
419
|
update(false);
|
|
365
420
|
});
|
|
@@ -379,43 +434,117 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
379
434
|
});
|
|
380
435
|
return connection;
|
|
381
436
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
437
|
+
async function mustPayFirst() {
|
|
438
|
+
if (!loginOnly) return false;
|
|
439
|
+
await (trial ??= startTrial());
|
|
440
|
+
return current.trialUntil !== void 0 && current.trialUntil <= Date.now();
|
|
441
|
+
}
|
|
442
|
+
async function waitFor(origin, token, email) {
|
|
443
|
+
const now = Date.now();
|
|
444
|
+
const same = (other) => !other || !email || other.toLowerCase() === email.toLowerCase();
|
|
445
|
+
waiting = waiting.filter((w) => w.token !== token && same(w.email)).map((w) => ({ ...w, fastUntil: now + WAIT_FAST_FOR_MS }));
|
|
446
|
+
waiting.push({ origin, token, email, since: now, fastUntil: now + WAIT_FAST_FOR_MS });
|
|
447
|
+
waiting = waiting.slice(-MAX_WAITING);
|
|
448
|
+
scheduleWait(waitPollMs);
|
|
449
|
+
await writeSession(async () => {
|
|
450
|
+
let record = {};
|
|
451
|
+
try {
|
|
452
|
+
record = JSON.parse(await storage.read() || "{}");
|
|
453
|
+
} catch {
|
|
454
|
+
}
|
|
455
|
+
if (typeof record.token !== "string") await storage.write(signedOutRecord());
|
|
456
|
+
}).catch(() => {
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
function scheduleWait(delay) {
|
|
460
|
+
clearTimeout(waitTimer);
|
|
461
|
+
if (disposed || !waiting.length) return;
|
|
462
|
+
waitTimer = setTimeout(() => void checkWaiting(), delay);
|
|
463
|
+
waitTimer.unref();
|
|
464
|
+
}
|
|
465
|
+
async function checkWaiting() {
|
|
466
|
+
const round = ++waitRound;
|
|
467
|
+
const now = Date.now();
|
|
468
|
+
const before = waiting.length;
|
|
469
|
+
let origin;
|
|
470
|
+
try {
|
|
471
|
+
origin = billingOrigin(getOrigin());
|
|
472
|
+
} catch {
|
|
473
|
+
return scheduleWait(WAIT_SLOW_MS);
|
|
474
|
+
}
|
|
475
|
+
waiting = waiting.filter((w) => w.origin === origin && now - w.since < WAIT_MAX_MS);
|
|
476
|
+
for (const w of [...waiting]) {
|
|
477
|
+
let response;
|
|
478
|
+
try {
|
|
479
|
+
response = await entitlement(w.origin, w.token);
|
|
480
|
+
} catch {
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (disposed || round !== waitRound) return;
|
|
484
|
+
if (response.status === 401) {
|
|
485
|
+
waiting = waiting.filter((other) => other !== w);
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (!response.ok) continue;
|
|
489
|
+
const body = await response.json().catch(() => null);
|
|
490
|
+
if (disposed || round !== waitRound) return;
|
|
491
|
+
if (body?.connected !== true || body.entitlement !== PRODUCT.entitlement) continue;
|
|
492
|
+
if (body.active !== true && await mustPayFirst()) continue;
|
|
493
|
+
if (disposed || round !== waitRound) return;
|
|
494
|
+
await writeSession(async () => {
|
|
495
|
+
if (disposed || round !== waitRound || w.origin !== billingOrigin(getOrigin())) return;
|
|
496
|
+
clearWaiting();
|
|
497
|
+
await storage.write(sessionRecord({ origin: w.origin, token: w.token }));
|
|
498
|
+
++generation;
|
|
499
|
+
activeOrigin = w.origin;
|
|
500
|
+
applyEntitlement(body);
|
|
501
|
+
schedule(body.active === true ? 6e4 : 2500);
|
|
502
|
+
});
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (disposed || round !== waitRound) return;
|
|
506
|
+
if (waiting.length !== before) {
|
|
507
|
+
await writeSession(async () => {
|
|
508
|
+
let record = {};
|
|
390
509
|
try {
|
|
391
|
-
|
|
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
|
-
}
|
|
510
|
+
record = JSON.parse(await storage.read() || "{}");
|
|
412
511
|
} catch {
|
|
413
512
|
}
|
|
414
|
-
if (
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
|
|
513
|
+
if (typeof record.token !== "string") await storage.write(signedOutRecord());
|
|
514
|
+
}).catch(() => {
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
scheduleWait(waiting.some((w) => Date.now() < w.fastUntil) ? waitPollMs : WAIT_SLOW_MS);
|
|
518
|
+
}
|
|
519
|
+
async function parkUnpaidSession() {
|
|
520
|
+
if (current.pro || !current.connected || !await mustPayFirst()) return;
|
|
521
|
+
await writeSession(async () => {
|
|
522
|
+
if (current.pro || !current.connected) return;
|
|
523
|
+
let record = {};
|
|
524
|
+
try {
|
|
525
|
+
record = JSON.parse(await storage.read() || "{}");
|
|
526
|
+
} catch {
|
|
527
|
+
}
|
|
528
|
+
if (typeof record.token !== "string" || typeof record.origin !== "string") return;
|
|
529
|
+
const response = await entitlement(record.origin, record.token).catch(() => null);
|
|
530
|
+
if (!response?.ok) return;
|
|
531
|
+
const latest = await response.json().catch(() => null);
|
|
532
|
+
if (!latest || latest.active === true || latest.connected !== true) {
|
|
533
|
+
if (latest) applyEntitlement(latest);
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
++generation;
|
|
537
|
+
clearTimeout(timer);
|
|
538
|
+
lastCheck = 0;
|
|
539
|
+
const now = Date.now();
|
|
540
|
+
waiting = [
|
|
541
|
+
...waiting.filter((w) => w.token !== record.token),
|
|
542
|
+
{ origin: record.origin, token: record.token, email: lastSignIn ?? "", since: now, fastUntil: now + WAIT_FAST_FOR_MS }
|
|
543
|
+
].slice(-MAX_WAITING);
|
|
544
|
+
await storage.write(signedOutRecord());
|
|
545
|
+
update(false);
|
|
546
|
+
});
|
|
547
|
+
scheduleWait(waitPollMs);
|
|
419
548
|
}
|
|
420
549
|
async function sendPendingTelemetry() {
|
|
421
550
|
if (disposed || !pendingEvents.size) return;
|
|
@@ -428,7 +557,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
428
557
|
if (process.env.INKMAP_ALLOW_TEST_TELEMETRY !== "1") {
|
|
429
558
|
if (origin === "https://billing.example.com" || process.env.INKMAP_DISABLE_TELEMETRY === "1" || process.env.NODE_TEST_CONTEXT) return;
|
|
430
559
|
const customHome = process.env.INKMAP_HOME || "";
|
|
431
|
-
|
|
560
|
+
const sysTmp = (0, import_node_os.tmpdir)();
|
|
561
|
+
if (customHome && (customHome === sysTmp || customHome.startsWith(sysTmp + import_node_path.sep) || customHome.startsWith("/tmp/") || customHome.startsWith("/private/tmp/") || customHome.includes("/var/folders/") || customHome.includes("inkmap-npm-isolated-") || customHome.includes("inkmap-antigravity-mcp-") || customHome.includes("inkmap-local-editor-") || customHome.includes("inkmap-harness-"))) {
|
|
432
562
|
return;
|
|
433
563
|
}
|
|
434
564
|
}
|
|
@@ -450,7 +580,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
450
580
|
installId: id,
|
|
451
581
|
host: hostName,
|
|
452
582
|
os,
|
|
453
|
-
version:
|
|
583
|
+
version: INKMAP_VERSION,
|
|
454
584
|
locale: clientLocale(),
|
|
455
585
|
tier,
|
|
456
586
|
events
|
|
@@ -462,11 +592,14 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
462
592
|
return {
|
|
463
593
|
async state() {
|
|
464
594
|
await (trial ??= startTrial());
|
|
465
|
-
|
|
595
|
+
const interval = !current.pro && Date.now() < fastPollUntil ? 4e3 : 6e4;
|
|
596
|
+
if (Date.now() - lastCheck >= interval) await refresh();
|
|
597
|
+
await parkUnpaidSession();
|
|
466
598
|
return current;
|
|
467
599
|
},
|
|
468
600
|
async connect(mode, localeHint) {
|
|
469
601
|
if (loginOnly && mode !== "restore") throw new Error("Only Yunfan account sign-in is available.");
|
|
602
|
+
expectPurchase();
|
|
470
603
|
const origin = billingOrigin(getOrigin());
|
|
471
604
|
const loc = clientLocale(localeHint);
|
|
472
605
|
const version = generation;
|
|
@@ -506,7 +639,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
506
639
|
if (version !== generation || disposed || origin !== billingOrigin(getOrigin())) {
|
|
507
640
|
throw new Error("The Yunfan account session changed. Please try again.");
|
|
508
641
|
}
|
|
509
|
-
|
|
642
|
+
clearWaiting();
|
|
643
|
+
await storage.write(sessionRecord({ origin, token: data.token, ...mode === "buy" && { checkoutUrl: url } }));
|
|
510
644
|
++generation;
|
|
511
645
|
lastCheck = 0;
|
|
512
646
|
if (mode !== "buy" || !current.connected) update(false);
|
|
@@ -516,8 +650,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
516
650
|
},
|
|
517
651
|
async orderPro(localeHint) {
|
|
518
652
|
if (loginOnly) throw new Error("Only Yunfan account sign-in is available.");
|
|
653
|
+
expectPurchase();
|
|
519
654
|
const origin = billingOrigin(getOrigin());
|
|
520
|
-
|
|
655
|
+
const loc = clientLocale(localeHint);
|
|
656
|
+
if (cachedOrder && cachedOrder.origin === origin && cachedOrder.locale === loc && Date.now() - cachedOrder.at < 8e3) {
|
|
521
657
|
const hit = cachedOrder.result;
|
|
522
658
|
cachedOrder = void 0;
|
|
523
659
|
schedule(hit.status === "qr" || hit.status === "redirect" ? 4e3 : 6e4);
|
|
@@ -539,7 +675,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
539
675
|
if (persist || nextCookie !== cookie) {
|
|
540
676
|
await writeSession(async () => {
|
|
541
677
|
if (version !== generation || disposed || origin !== billingOrigin(getOrigin())) return;
|
|
542
|
-
await storage.write(
|
|
678
|
+
await storage.write(sessionRecord({ origin, token, checkoutUrl, ...nextCookie && { cookie: nextCookie } }));
|
|
543
679
|
if (persist) {
|
|
544
680
|
++generation;
|
|
545
681
|
lastCheck = 0;
|
|
@@ -583,34 +719,42 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
583
719
|
},
|
|
584
720
|
async sendPhoneCode(phone, localeHint) {
|
|
585
721
|
if (typeof phone !== "string" || !phone.trim() || phone.length > 254) return phoneFailure(400);
|
|
722
|
+
expectPurchase();
|
|
586
723
|
const isEmail = phone.includes("@");
|
|
587
724
|
const locale = clientLocale(localeHint);
|
|
588
725
|
try {
|
|
589
726
|
const origin = billingOrigin(getOrigin());
|
|
590
727
|
if (!loginOnly) {
|
|
591
728
|
try {
|
|
592
|
-
|
|
593
|
-
|
|
729
|
+
const newFlow = () => flowCreation ??= createCheckoutFlow(origin, void 0, void 0, locale).finally(() => {
|
|
730
|
+
flowCreation = void 0;
|
|
731
|
+
});
|
|
732
|
+
let flow = pendingCheckout;
|
|
733
|
+
if (!flow || flow.origin !== origin || flow.locale !== locale) {
|
|
734
|
+
flow = await newFlow();
|
|
735
|
+
pendingCheckout = flow;
|
|
594
736
|
}
|
|
595
737
|
const sendAction = isEmail ? "email/send" : "sms";
|
|
596
738
|
const sendBody = isEmail ? { email: phone, locale } : { phone };
|
|
597
|
-
let smsRes = await checkoutPost(
|
|
598
|
-
if (smsRes.status ===
|
|
599
|
-
|
|
600
|
-
|
|
739
|
+
let smsRes = await checkoutPost(flow.url, sendAction, origin, sendBody, flow.token, flow.cookie, locale);
|
|
740
|
+
if (smsRes.status === 401 || smsRes.status === 403 || smsRes.status === 404 || smsRes.status === 410) {
|
|
741
|
+
flow = await newFlow();
|
|
742
|
+
pendingCheckout = flow;
|
|
743
|
+
smsRes = await checkoutPost(flow.url, sendAction, origin, sendBody, flow.token, flow.cookie, locale);
|
|
601
744
|
}
|
|
602
|
-
|
|
603
|
-
|
|
745
|
+
flow.cookie = mergeCookies(flow.cookie, smsRes);
|
|
746
|
+
if (smsRes.status !== 204) return phoneFailure(smsRes.status);
|
|
747
|
+
await rememberSignIn(phone);
|
|
748
|
+
return { ok: true, value: void 0 };
|
|
604
749
|
} catch {
|
|
605
750
|
pendingCheckout = void 0;
|
|
606
751
|
}
|
|
607
752
|
}
|
|
608
753
|
const response = await phoneRequest(origin, "send", phone, void 0, locale);
|
|
609
754
|
if (response.status === 204) {
|
|
755
|
+
await rememberSignIn(phone);
|
|
610
756
|
const pendingToken = response.headers.get("x-inkmap-pending-token")?.trim();
|
|
611
|
-
if (pendingToken && /^[A-Za-z0-9_-]{43}$/.test(pendingToken))
|
|
612
|
-
startMagicPoll(origin, pendingToken);
|
|
613
|
-
}
|
|
757
|
+
if (pendingToken && /^[A-Za-z0-9_-]{43}$/.test(pendingToken)) await waitFor(origin, pendingToken, phone);
|
|
614
758
|
return { ok: true, value: void 0 };
|
|
615
759
|
}
|
|
616
760
|
return phoneFailure(response.status);
|
|
@@ -618,39 +762,44 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
618
762
|
return phoneFailure();
|
|
619
763
|
}
|
|
620
764
|
},
|
|
621
|
-
async signInByPhone(phone, code) {
|
|
765
|
+
async signInByPhone(phone, code, localeHint) {
|
|
622
766
|
if (typeof phone !== "string" || !phone.trim() || phone.length > 254 || typeof code !== "string" || !/^\d{6}$/.test(code)) return phoneFailure(400);
|
|
623
767
|
const isEmail = phone.includes("@");
|
|
768
|
+
const locale = clientLocale(localeHint);
|
|
624
769
|
const version = generation;
|
|
625
770
|
try {
|
|
626
771
|
const origin = billingOrigin(getOrigin());
|
|
627
772
|
let token;
|
|
628
773
|
let checkoutUrl;
|
|
629
774
|
let cookie;
|
|
630
|
-
|
|
775
|
+
const flow = pendingCheckout;
|
|
776
|
+
if (!loginOnly && flow && flow.origin === origin) {
|
|
631
777
|
const verifyAction = isEmail ? "email/verify" : "login";
|
|
632
778
|
const verifyBody = isEmail ? { email: phone, code } : { phone, code };
|
|
633
|
-
const loginRes = await checkoutPost(
|
|
779
|
+
const loginRes = await checkoutPost(flow.url, verifyAction, origin, verifyBody, flow.token, flow.cookie, locale);
|
|
634
780
|
if (!loginRes.ok) {
|
|
635
|
-
if (loginRes.status ===
|
|
781
|
+
if (loginRes.status === 401 || loginRes.status === 403 || loginRes.status === 404 || loginRes.status === 410) {
|
|
782
|
+
if (pendingCheckout === flow) pendingCheckout = void 0;
|
|
783
|
+
}
|
|
636
784
|
return phoneFailure(loginRes.status);
|
|
637
785
|
}
|
|
638
|
-
cookie = mergeCookies(
|
|
639
|
-
token =
|
|
640
|
-
checkoutUrl =
|
|
641
|
-
pendingCheckout = void 0;
|
|
642
|
-
const orderRes = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie).catch(() => null);
|
|
786
|
+
cookie = mergeCookies(flow.cookie, loginRes);
|
|
787
|
+
token = flow.token;
|
|
788
|
+
checkoutUrl = flow.url;
|
|
789
|
+
if (pendingCheckout === flow) pendingCheckout = void 0;
|
|
790
|
+
const orderRes = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie, locale).catch(() => null);
|
|
643
791
|
if (orderRes?.ok) {
|
|
644
792
|
cookie = mergeCookies(cookie, orderRes);
|
|
645
793
|
const orderData = await orderRes.json().catch(() => null);
|
|
646
794
|
if (orderData && typeof orderData === "object") {
|
|
647
795
|
if (orderData.active === true) {
|
|
648
|
-
cachedOrder = { at: Date.now(), origin, result: { status: "active", state: current } };
|
|
796
|
+
cachedOrder = { at: Date.now(), origin, locale, result: { status: "active", state: current } };
|
|
649
797
|
} else if (typeof orderData.qr === "string" && orderData.qr) {
|
|
650
798
|
const qr = orderData.qr.startsWith("data:image/") ? orderData.qr : "data:image/png;base64," + orderData.qr;
|
|
651
799
|
cachedOrder = {
|
|
652
800
|
at: Date.now(),
|
|
653
801
|
origin,
|
|
802
|
+
locale,
|
|
654
803
|
result: {
|
|
655
804
|
status: "qr",
|
|
656
805
|
qr,
|
|
@@ -659,12 +808,12 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
659
808
|
}
|
|
660
809
|
};
|
|
661
810
|
} else if (typeof orderData.checkoutUrl === "string" && /^https:\/\//.test(orderData.checkoutUrl)) {
|
|
662
|
-
cachedOrder = { at: Date.now(), origin, result: { status: "redirect", url: orderData.checkoutUrl } };
|
|
811
|
+
cachedOrder = { at: Date.now(), origin, locale, result: { status: "redirect", url: orderData.checkoutUrl } };
|
|
663
812
|
}
|
|
664
813
|
}
|
|
665
814
|
}
|
|
666
815
|
} else {
|
|
667
|
-
const response = await phoneRequest(origin, "verify", phone, code);
|
|
816
|
+
const response = await phoneRequest(origin, "verify", phone, code, locale);
|
|
668
817
|
if (response.status !== 201) return phoneFailure(response.status);
|
|
669
818
|
cookie = mergeCookies(void 0, response);
|
|
670
819
|
const body = await response.json();
|
|
@@ -687,10 +836,15 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
687
836
|
return phoneFailure();
|
|
688
837
|
}
|
|
689
838
|
if (cachedOrder?.result.status === "active") state.active = true;
|
|
839
|
+
if (!checkoutUrl && state.active !== true && await mustPayFirst()) {
|
|
840
|
+
await rememberSignIn(phone);
|
|
841
|
+
await waitFor(origin, token, phone);
|
|
842
|
+
return { ok: false, reason: "notPro" };
|
|
843
|
+
}
|
|
690
844
|
return await writeSession(async () => {
|
|
691
845
|
if (version !== generation || disposed || origin !== billingOrigin(getOrigin())) return phoneFailure();
|
|
692
|
-
|
|
693
|
-
await storage.write(
|
|
846
|
+
clearWaiting();
|
|
847
|
+
await storage.write(sessionRecord({ origin, token, ...checkoutUrl && { checkoutUrl }, ...cookie && { cookie } }));
|
|
694
848
|
++generation;
|
|
695
849
|
activeOrigin = origin;
|
|
696
850
|
applyEntitlement(state);
|
|
@@ -703,12 +857,12 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
703
857
|
}
|
|
704
858
|
},
|
|
705
859
|
async deactivate() {
|
|
706
|
-
|
|
860
|
+
clearWaiting();
|
|
707
861
|
pendingCheckout = void 0;
|
|
708
862
|
cachedOrder = void 0;
|
|
709
863
|
const saved = await writeSession(async () => {
|
|
710
864
|
const previous = await storage.read();
|
|
711
|
-
await storage.write(
|
|
865
|
+
await storage.write(signedOutRecord());
|
|
712
866
|
++generation;
|
|
713
867
|
clearTimeout(timer);
|
|
714
868
|
lastCheck = 0;
|
|
@@ -718,7 +872,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
718
872
|
if (!saved) return;
|
|
719
873
|
try {
|
|
720
874
|
const { origin, token } = JSON.parse(saved);
|
|
721
|
-
if (origin !== billingOrigin(getOrigin())) return;
|
|
875
|
+
if (origin !== billingOrigin(getOrigin()) || typeof token !== "string") return;
|
|
722
876
|
await fetch(origin + "/billing/v1/entitlement", {
|
|
723
877
|
method: "DELETE",
|
|
724
878
|
headers: { authorization: "Bearer " + token },
|
|
@@ -758,7 +912,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
758
912
|
},
|
|
759
913
|
dispose() {
|
|
760
914
|
disposed = true;
|
|
761
|
-
|
|
915
|
+
clearWaiting();
|
|
762
916
|
clearTimeout(trialTimer);
|
|
763
917
|
clearTimeout(timer);
|
|
764
918
|
clearTimeout(telemetryTimer);
|
|
@@ -780,81 +934,48 @@ function inferNodeHost() {
|
|
|
780
934
|
}
|
|
781
935
|
return "cli";
|
|
782
936
|
}
|
|
783
|
-
async function
|
|
784
|
-
const path2 = (0, import_node_path.join)(process.env.INKMAP_HOME ?? (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap"), "install-id");
|
|
785
|
-
let value;
|
|
937
|
+
async function atomicCreateIfMissing(path2, initialContent) {
|
|
786
938
|
try {
|
|
787
|
-
|
|
939
|
+
return await (0, import_promises.readFile)(path2, "utf8");
|
|
788
940
|
} catch (error) {
|
|
789
941
|
if (error.code !== "ENOENT") throw error;
|
|
790
942
|
await (0, import_promises.mkdir)((0, import_node_path.dirname)(path2), { recursive: true, mode: 448 });
|
|
791
|
-
const generated = "inst_" + (0, import_node_crypto.randomUUID)().replace(/-/g, "").slice(0, 24);
|
|
792
943
|
const temporary = path2 + "." + (0, import_node_crypto.randomUUID)();
|
|
793
944
|
try {
|
|
794
|
-
await (0, import_promises.writeFile)(temporary,
|
|
795
|
-
await (0, import_promises.link)(temporary, path2).catch((err) => {
|
|
796
|
-
if (err.code
|
|
945
|
+
await (0, import_promises.writeFile)(temporary, initialContent, { mode: 384, flag: "wx" });
|
|
946
|
+
await (0, import_promises.link)(temporary, path2).catch(async (err) => {
|
|
947
|
+
if (err.code === "EEXIST") return;
|
|
948
|
+
if (err.code === "EPERM" || err.code === "ENOSYS" || err.code === "EXDEV") {
|
|
949
|
+
await (0, import_promises.rename)(temporary, path2);
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
throw err;
|
|
797
953
|
});
|
|
798
954
|
} finally {
|
|
799
|
-
await (0, import_promises.rm)(temporary, { force: true })
|
|
955
|
+
await (0, import_promises.rm)(temporary, { force: true }).catch(() => {
|
|
956
|
+
});
|
|
800
957
|
}
|
|
801
|
-
|
|
958
|
+
return await (0, import_promises.readFile)(path2, "utf8");
|
|
802
959
|
}
|
|
960
|
+
}
|
|
961
|
+
async function localInstallId() {
|
|
962
|
+
const path2 = (0, import_node_path.join)(process.env.INKMAP_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap"), "install-id");
|
|
963
|
+
const generated = "inst_" + (0, import_node_crypto.randomUUID)().replace(/-/g, "").slice(0, 24);
|
|
964
|
+
const value = (await atomicCreateIfMissing(path2, generated)).trim();
|
|
803
965
|
return /^[A-Za-z0-9_:-]{8,64}$/.test(value) ? value : void 0;
|
|
804
966
|
}
|
|
805
967
|
async function localTrialDeadline() {
|
|
806
|
-
const path2 = (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap", "trial-start");
|
|
807
|
-
const
|
|
808
|
-
let value;
|
|
809
|
-
try {
|
|
810
|
-
value = await (0, import_promises.readFile)(path2, "utf8");
|
|
811
|
-
} catch (error) {
|
|
812
|
-
if (error.code !== "ENOENT") throw error;
|
|
813
|
-
await (0, import_promises.mkdir)((0, import_node_path.dirname)(path2), { recursive: true, mode: 448 });
|
|
814
|
-
const temporary = path2 + "." + (0, import_node_crypto.randomUUID)();
|
|
815
|
-
try {
|
|
816
|
-
await (0, import_promises.writeFile)(temporary, String(now), { mode: 384, flag: "wx" });
|
|
817
|
-
await (0, import_promises.link)(temporary, path2).catch((error2) => {
|
|
818
|
-
if (error2.code !== "EEXIST") throw error2;
|
|
819
|
-
});
|
|
820
|
-
} finally {
|
|
821
|
-
await (0, import_promises.rm)(temporary, { force: true });
|
|
822
|
-
}
|
|
823
|
-
value = await (0, import_promises.readFile)(path2, "utf8");
|
|
824
|
-
}
|
|
968
|
+
const path2 = (0, import_node_path.join)(process.env.INKMAP_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap"), "trial-start");
|
|
969
|
+
const value = await atomicCreateIfMissing(path2, String(Date.now()));
|
|
825
970
|
const started = Number(value);
|
|
826
971
|
return Number.isSafeInteger(started) && started > 0 && started <= Date.now() ? started + TRIAL_MS : void 0;
|
|
827
972
|
}
|
|
828
|
-
var AD_TTL = 6 * 60 * 60 * 1e3;
|
|
829
|
-
function adFeed(url) {
|
|
830
|
-
let cache;
|
|
831
|
-
return async () => {
|
|
832
|
-
if (!url) return [];
|
|
833
|
-
if (cache && Date.now() - cache.at < AD_TTL) return cache.ads;
|
|
834
|
-
try {
|
|
835
|
-
const res = await fetch(url, { signal: AbortSignal.timeout(5e3), headers: { accept: "application/json" } });
|
|
836
|
-
const ads = res.ok ? sanitizeAds(await res.json()) : [];
|
|
837
|
-
cache = { at: Date.now(), ads };
|
|
838
|
-
return ads;
|
|
839
|
-
} catch {
|
|
840
|
-
cache = { at: Date.now(), ads: [] };
|
|
841
|
-
return [];
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// packages/vscode/src/browser.ts
|
|
847
|
-
var import_node_child_process3 = require("node:child_process");
|
|
848
|
-
var vscode2 = __toESM(require("vscode"));
|
|
849
973
|
|
|
850
|
-
// packages/cli/src/
|
|
851
|
-
var import_node_child_process2 = require("node:child_process");
|
|
852
|
-
var import_node_crypto2 = require("node:crypto");
|
|
853
|
-
var import_node_fs = require("node:fs");
|
|
974
|
+
// packages/cli/src/workspace-fs.ts
|
|
854
975
|
var import_promises2 = require("node:fs/promises");
|
|
855
|
-
var import_node_http = require("node:http");
|
|
856
976
|
var import_node_os2 = require("node:os");
|
|
857
977
|
var import_node_path2 = require("node:path");
|
|
978
|
+
var MAX_MARKDOWN_BYTES = 5 * 1024 * 1024;
|
|
858
979
|
var SKIP_SCAN_DIRS = /* @__PURE__ */ new Set([
|
|
859
980
|
".git",
|
|
860
981
|
".hg",
|
|
@@ -877,14 +998,20 @@ var SKIP_SCAN_DIRS = /* @__PURE__ */ new Set([
|
|
|
877
998
|
"coverage",
|
|
878
999
|
".tmp"
|
|
879
1000
|
]);
|
|
880
|
-
|
|
1001
|
+
var MARKMAP_RE = /\.markmap\.md$/i;
|
|
1002
|
+
function insideOrEqual(root, target) {
|
|
881
1003
|
if (root === target) return true;
|
|
882
1004
|
const rel = (0, import_node_path2.relative)(root, target);
|
|
883
1005
|
return Boolean(rel && !(0, import_node_path2.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(".." + import_node_path2.sep));
|
|
884
1006
|
}
|
|
1007
|
+
function hasHiddenSegment(root, target) {
|
|
1008
|
+
const rel = (0, import_node_path2.relative)(root, target);
|
|
1009
|
+
if (!rel || rel === ".") return false;
|
|
1010
|
+
return rel.split(import_node_path2.sep).some((part) => part.startsWith("."));
|
|
1011
|
+
}
|
|
885
1012
|
async function findProjectRoot(filePath) {
|
|
886
|
-
let cur = (0, import_node_path2.dirname)(filePath);
|
|
887
1013
|
const home = await (0, import_promises2.realpath)((0, import_node_os2.homedir)()).catch(() => (0, import_node_os2.homedir)());
|
|
1014
|
+
let cur = (0, import_node_path2.dirname)(filePath);
|
|
888
1015
|
while (cur && cur !== (0, import_node_path2.dirname)(cur) && cur !== home) {
|
|
889
1016
|
try {
|
|
890
1017
|
await (0, import_promises2.lstat)((0, import_node_path2.join)(cur, ".git"));
|
|
@@ -895,7 +1022,7 @@ async function findProjectRoot(filePath) {
|
|
|
895
1022
|
}
|
|
896
1023
|
return (0, import_node_path2.dirname)(filePath);
|
|
897
1024
|
}
|
|
898
|
-
async function
|
|
1025
|
+
async function scanMarkdownFiles(rootDir, { maxFiles = 200, maxDepth = 4, byRecent = false } = {}) {
|
|
899
1026
|
const found = [];
|
|
900
1027
|
async function walk(dir, depth) {
|
|
901
1028
|
if (depth > maxDepth || found.length >= maxFiles) return;
|
|
@@ -913,11 +1040,10 @@ async function scanProjectMarkdownFiles(rootDir, maxFiles = 200, maxDepth = 4) {
|
|
|
913
1040
|
if (!SKIP_SCAN_DIRS.has(entry.name)) await walk(full, depth + 1);
|
|
914
1041
|
} else if (entry.isFile() && /\.md$/i.test(entry.name)) {
|
|
915
1042
|
try {
|
|
916
|
-
const
|
|
917
|
-
if (
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
}
|
|
1043
|
+
const info = await (0, import_promises2.lstat)(full);
|
|
1044
|
+
if (!info.isFile() || info.size > MAX_MARKDOWN_BYTES) continue;
|
|
1045
|
+
const real = await (0, import_promises2.realpath)(full);
|
|
1046
|
+
if (real === full && insideOrEqual(rootDir, real)) found.push({ path: real, mtimeMs: info.mtimeMs });
|
|
921
1047
|
} catch {
|
|
922
1048
|
}
|
|
923
1049
|
}
|
|
@@ -925,13 +1051,16 @@ async function scanProjectMarkdownFiles(rootDir, maxFiles = 200, maxDepth = 4) {
|
|
|
925
1051
|
}
|
|
926
1052
|
await walk(rootDir, 0);
|
|
927
1053
|
found.sort((a, b) => {
|
|
928
|
-
const
|
|
929
|
-
const
|
|
930
|
-
if (
|
|
931
|
-
|
|
1054
|
+
const am = MARKMAP_RE.test(a.path) ? 0 : 1;
|
|
1055
|
+
const bm = MARKMAP_RE.test(b.path) ? 0 : 1;
|
|
1056
|
+
if (am !== bm) return am - bm;
|
|
1057
|
+
if (byRecent && Math.abs(b.mtimeMs - a.mtimeMs) > 1e3) return b.mtimeMs - a.mtimeMs;
|
|
1058
|
+
return a.path.localeCompare(b.path);
|
|
932
1059
|
});
|
|
933
1060
|
return found;
|
|
934
1061
|
}
|
|
1062
|
+
|
|
1063
|
+
// packages/cli/src/server.ts
|
|
935
1064
|
var MAX_BODY = 20 * 1024 * 1024;
|
|
936
1065
|
var TYPES = {
|
|
937
1066
|
".html": "text/html; charset=utf-8",
|
|
@@ -943,55 +1072,67 @@ var TYPES = {
|
|
|
943
1072
|
".jpeg": "image/jpeg",
|
|
944
1073
|
".gif": "image/gif",
|
|
945
1074
|
".webp": "image/webp",
|
|
1075
|
+
".avif": "image/avif",
|
|
1076
|
+
".bmp": "image/bmp",
|
|
1077
|
+
".ico": "image/x-icon",
|
|
946
1078
|
".woff2": "font/woff2",
|
|
947
1079
|
".woff": "font/woff",
|
|
948
1080
|
".ttf": "font/ttf",
|
|
949
1081
|
".json": "application/json"
|
|
950
1082
|
};
|
|
1083
|
+
var HttpError = class extends Error {
|
|
1084
|
+
constructor(status, message) {
|
|
1085
|
+
super(message);
|
|
1086
|
+
this.status = status;
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
var LOOPBACK_HOST = /^(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+$/i;
|
|
951
1090
|
var hash = (s) => (0, import_node_crypto2.createHash)("sha1").update(s).digest("hex");
|
|
952
1091
|
function docName(path2) {
|
|
953
|
-
return (0,
|
|
1092
|
+
return (0, import_node_path3.basename)(path2).replace(/\.md$/i, "").replace(/\.markmap$/i, "");
|
|
954
1093
|
}
|
|
955
1094
|
function viewStateFile(key) {
|
|
956
|
-
const base = process.env.INKMAP_HOME
|
|
957
|
-
return (0,
|
|
1095
|
+
const base = process.env.INKMAP_HOME || (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".inkmap");
|
|
1096
|
+
return (0, import_node_path3.join)(base, "view-state", hash(key) + ".json");
|
|
958
1097
|
}
|
|
959
1098
|
async function readDiskViewState(key) {
|
|
960
1099
|
try {
|
|
961
|
-
return sanitizeViewState(JSON.parse(await (0,
|
|
1100
|
+
return sanitizeViewState(JSON.parse(await (0, import_promises3.readFile)(viewStateFile(key), "utf8")));
|
|
962
1101
|
} catch {
|
|
963
1102
|
return void 0;
|
|
964
1103
|
}
|
|
965
1104
|
}
|
|
966
1105
|
async function writeDiskViewState(key, state) {
|
|
967
1106
|
const target = viewStateFile(key);
|
|
968
|
-
await (0,
|
|
1107
|
+
await (0, import_promises3.mkdir)((0, import_node_path3.dirname)(target), { recursive: true, mode: 448 });
|
|
969
1108
|
const temp = `${target}.${process.pid}.${Date.now()}`;
|
|
970
1109
|
try {
|
|
971
|
-
await (0,
|
|
972
|
-
await (0,
|
|
1110
|
+
await (0, import_promises3.writeFile)(temp, JSON.stringify(state), { mode: 384 });
|
|
1111
|
+
await (0, import_promises3.rename)(temp, target);
|
|
973
1112
|
} finally {
|
|
974
|
-
await (0,
|
|
1113
|
+
await (0, import_promises3.rm)(temp, { force: true }).catch(() => {
|
|
975
1114
|
});
|
|
976
1115
|
}
|
|
977
1116
|
}
|
|
978
1117
|
async function fileSource(file, log = () => {
|
|
979
1118
|
}) {
|
|
980
|
-
const path2 = await (0,
|
|
981
|
-
if (!(await (0,
|
|
982
|
-
const dir = (0,
|
|
1119
|
+
const path2 = await (0, import_promises3.realpath)((0, import_node_path3.resolve)(file)).catch(() => (0, import_node_path3.resolve)(file));
|
|
1120
|
+
if (!(await (0, import_promises3.stat)(path2)).isFile()) throw new Error(`\u4E0D\u662F\u6587\u4EF6\uFF1A${path2}`);
|
|
1121
|
+
const dir = (0, import_node_path3.dirname)(path2);
|
|
983
1122
|
return {
|
|
984
1123
|
name: docName(path2),
|
|
985
1124
|
key: path2,
|
|
986
1125
|
dir,
|
|
987
|
-
read: () => (0,
|
|
1126
|
+
read: () => (0, import_promises3.readFile)(path2, "utf8"),
|
|
988
1127
|
async write(md) {
|
|
989
|
-
await (0,
|
|
1128
|
+
await (0, import_promises3.writeFile)(path2, md, "utf8");
|
|
990
1129
|
log(`\u5DF2\u5199\u56DE ${path2}`);
|
|
991
1130
|
},
|
|
992
1131
|
watch(onChange) {
|
|
993
1132
|
const watcher = (0, import_node_fs.watch)(dir, (_, changed) => {
|
|
994
|
-
if (!changed || changed === (0,
|
|
1133
|
+
if (!changed || changed === (0, import_node_path3.basename)(path2)) onChange();
|
|
1134
|
+
});
|
|
1135
|
+
watcher.on("error", () => {
|
|
995
1136
|
});
|
|
996
1137
|
return () => watcher.close();
|
|
997
1138
|
},
|
|
@@ -1000,8 +1141,15 @@ async function fileSource(file, log = () => {
|
|
|
1000
1141
|
};
|
|
1001
1142
|
}
|
|
1002
1143
|
function within(root, rel) {
|
|
1003
|
-
|
|
1004
|
-
|
|
1144
|
+
let decoded;
|
|
1145
|
+
try {
|
|
1146
|
+
decoded = decodeURIComponent(rel);
|
|
1147
|
+
} catch {
|
|
1148
|
+
return null;
|
|
1149
|
+
}
|
|
1150
|
+
const resolvedRoot = (0, import_node_path3.resolve)(root);
|
|
1151
|
+
const base = resolvedRoot.endsWith(import_node_path3.sep) ? resolvedRoot : resolvedRoot + import_node_path3.sep;
|
|
1152
|
+
const full = (0, import_node_path3.normalize)((0, import_node_path3.join)(resolvedRoot, decoded));
|
|
1005
1153
|
return full.startsWith(base) ? full : null;
|
|
1006
1154
|
}
|
|
1007
1155
|
async function openBrowserWindow(url) {
|
|
@@ -1025,8 +1173,23 @@ async function openBrowserWindow(url) {
|
|
|
1025
1173
|
if (await run("google-chrome", [url])) return;
|
|
1026
1174
|
await run("xdg-open", [url]);
|
|
1027
1175
|
}
|
|
1028
|
-
async function serve({
|
|
1029
|
-
|
|
1176
|
+
async function serve({
|
|
1177
|
+
source: initialSource,
|
|
1178
|
+
webRoot,
|
|
1179
|
+
port = 4377,
|
|
1180
|
+
host = "127.0.0.1",
|
|
1181
|
+
log = () => {
|
|
1182
|
+
},
|
|
1183
|
+
license,
|
|
1184
|
+
sidebar = false,
|
|
1185
|
+
sidebarPurchase = false,
|
|
1186
|
+
sidebarAccountNavigation = false,
|
|
1187
|
+
ideWorkspace = false,
|
|
1188
|
+
workspaceRoots = [],
|
|
1189
|
+
confineToWorkspaceRoots = false,
|
|
1190
|
+
openSource = (path2) => fileSource(path2, log),
|
|
1191
|
+
allowPurchase = true
|
|
1192
|
+
}) {
|
|
1030
1193
|
if (sidebar && host !== "127.0.0.1") throw new Error("The sidebar bridge requires loopback.");
|
|
1031
1194
|
const prefix = sidebar ? `/s/${(0, import_node_crypto2.randomBytes)(24).toString("hex")}/` : "/";
|
|
1032
1195
|
let activeSource = initialSource;
|
|
@@ -1036,7 +1199,9 @@ async function serve({ source: initialSource, webRoot, port = 4377, host = "127.
|
|
|
1036
1199
|
let version = hash(current);
|
|
1037
1200
|
let viewState = await activeSource.readView?.();
|
|
1038
1201
|
const clients = /* @__PURE__ */ new Set();
|
|
1039
|
-
const canPurchase =
|
|
1202
|
+
const canPurchase = sidebar ? sidebarPurchase : allowPurchase;
|
|
1203
|
+
const allowedHosts = /* @__PURE__ */ new Set();
|
|
1204
|
+
const urlHost = host.includes(":") ? `[${host}]` : host;
|
|
1040
1205
|
const docState = () => ({
|
|
1041
1206
|
name: activeSource.name,
|
|
1042
1207
|
md: current,
|
|
@@ -1069,35 +1234,35 @@ data: ${JSON.stringify(data)}
|
|
|
1069
1234
|
broadcast();
|
|
1070
1235
|
}
|
|
1071
1236
|
let pending;
|
|
1072
|
-
|
|
1237
|
+
const scheduleRefresh = () => {
|
|
1073
1238
|
clearTimeout(pending);
|
|
1074
|
-
pending = setTimeout(
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1239
|
+
pending = setTimeout(() => void serialized(refresh).catch(() => {
|
|
1240
|
+
}), 80);
|
|
1241
|
+
};
|
|
1242
|
+
let unwatch = activeSource.watch(scheduleRefresh);
|
|
1243
|
+
const canonicalActiveKey = async () => activeSource.key ? await (0, import_promises3.realpath)(activeSource.key).catch(() => activeSource.key) : void 0;
|
|
1079
1244
|
async function collectWorkspaceFiles() {
|
|
1080
1245
|
const roots = /* @__PURE__ */ new Map();
|
|
1081
|
-
if (activeSource.key) {
|
|
1082
|
-
const realKey = await (0,
|
|
1083
|
-
const projRoot = await (0,
|
|
1084
|
-
roots.set(projRoot, { path: projRoot, name: (0,
|
|
1246
|
+
if (activeSource.key && !confineToWorkspaceRoots) {
|
|
1247
|
+
const realKey = await (0, import_promises3.realpath)(activeSource.key).catch(() => activeSource.key);
|
|
1248
|
+
const projRoot = await (0, import_promises3.realpath)(await findProjectRoot(realKey)).catch(() => (0, import_node_path3.dirname)(realKey));
|
|
1249
|
+
roots.set(projRoot, { path: projRoot, name: (0, import_node_path3.basename)(projRoot), active: true });
|
|
1085
1250
|
}
|
|
1086
|
-
const envRoots = [...workspaceRoots, ...(process.env.INKMAP_WORKSPACES || "").split(
|
|
1251
|
+
const envRoots = [...workspaceRoots, ...(process.env.INKMAP_WORKSPACES || "").split(import_node_path3.delimiter)].filter(Boolean);
|
|
1087
1252
|
for (const raw of envRoots) {
|
|
1088
|
-
const real = await (0,
|
|
1253
|
+
const real = await (0, import_promises3.realpath)((0, import_node_path3.resolve)(raw)).catch(() => null);
|
|
1089
1254
|
if (real && !roots.has(real)) {
|
|
1090
|
-
roots.set(real, { path: real, name: (0,
|
|
1255
|
+
roots.set(real, { path: real, name: (0, import_node_path3.basename)(real), active: roots.size === 0 });
|
|
1091
1256
|
}
|
|
1092
1257
|
}
|
|
1093
1258
|
const items = [];
|
|
1094
1259
|
const seen = /* @__PURE__ */ new Set();
|
|
1095
1260
|
for (const root of roots.values()) {
|
|
1096
|
-
const files = await
|
|
1261
|
+
const files = (await scanMarkdownFiles(root.path)).map((entry) => entry.path);
|
|
1097
1262
|
for (const f of files) {
|
|
1098
1263
|
if (seen.has(f)) continue;
|
|
1099
1264
|
seen.add(f);
|
|
1100
|
-
const rel = (0,
|
|
1265
|
+
const rel = (0, import_node_path3.relative)(root.path, f);
|
|
1101
1266
|
items.push({
|
|
1102
1267
|
path: f,
|
|
1103
1268
|
label: `${root.name} / ${rel}`,
|
|
@@ -1105,42 +1270,49 @@ data: ${JSON.stringify(data)}
|
|
|
1105
1270
|
});
|
|
1106
1271
|
}
|
|
1107
1272
|
}
|
|
1108
|
-
|
|
1273
|
+
const activeReal = await canonicalActiveKey();
|
|
1274
|
+
if (activeSource.key && activeReal && !seen.has(activeReal)) {
|
|
1109
1275
|
items.unshift({
|
|
1110
1276
|
path: activeSource.key,
|
|
1111
|
-
label: `${(0,
|
|
1277
|
+
label: `${(0, import_node_path3.basename)(activeSource.dir)} / ${(0, import_node_path3.basename)(activeSource.key)}`,
|
|
1112
1278
|
group: "active"
|
|
1113
1279
|
});
|
|
1114
1280
|
}
|
|
1115
1281
|
return { roots: [...roots.values()], files: items };
|
|
1116
1282
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
const
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
|
|
1283
|
+
const zh2 = () => detectOsLocale() === "zh";
|
|
1284
|
+
async function switchSourceToFile(candidatePath, trustCaller = false) {
|
|
1285
|
+
const notMarkdown = () => new HttpError(400, zh2() ? "\u8BF7\u9009\u62E9 .md \u6216 .markmap.md \u6587\u4EF6\u3002" : "Choose a .md or .markmap.md file.");
|
|
1286
|
+
if (!candidatePath || typeof candidatePath !== "string" || !/\.md$/i.test(candidatePath)) throw notMarkdown();
|
|
1287
|
+
const resolvedCandidate = (0, import_node_path3.resolve)(candidatePath);
|
|
1288
|
+
const rawStat = await (0, import_promises3.lstat)(resolvedCandidate).catch(() => null);
|
|
1289
|
+
const realTarget = await (0, import_promises3.realpath)(resolvedCandidate).catch(() => null);
|
|
1290
|
+
const targetStat = realTarget ? await (0, import_promises3.stat)(realTarget).catch(() => null) : null;
|
|
1291
|
+
if (!rawStat || rawStat.isSymbolicLink() && !trustCaller || !realTarget || !targetStat?.isFile() || targetStat.size > MAX_MARKDOWN_BYTES) {
|
|
1292
|
+
throw new HttpError(403, zh2() ? "\u8BF7\u9009\u62E9 5 MiB \u4EE5\u5185\u7684\u666E\u901A Markdown \u6587\u4EF6\u3002" : "Choose a regular Markdown file up to 5 MiB.");
|
|
1125
1293
|
}
|
|
1126
|
-
|
|
1127
|
-
if (
|
|
1128
|
-
|
|
1294
|
+
if (!/\.md$/i.test(realTarget)) throw notMarkdown();
|
|
1295
|
+
if (!trustCaller) {
|
|
1296
|
+
const { roots } = await collectWorkspaceFiles();
|
|
1297
|
+
const matchedRoot = roots.find((r) => insideOrEqual(r.path, realTarget));
|
|
1298
|
+
if (!matchedRoot) {
|
|
1299
|
+
throw new HttpError(403, zh2() ? "\u8BE5\u6587\u4EF6\u4E0D\u5728\u5F53\u524D\u9879\u76EE\u5DE5\u4F5C\u533A\u5185\u3002" : "This file is outside the current workspace.");
|
|
1300
|
+
}
|
|
1301
|
+
if (hasHiddenSegment(matchedRoot.path, realTarget)) {
|
|
1302
|
+
throw new HttpError(403, zh2() ? "\u4E0D\u652F\u6301\u8BBF\u95EE\u9690\u85CF\u76EE\u5F55\u4E2D\u7684\u6587\u4EF6\u3002" : "Files in hidden folders are not allowed.");
|
|
1303
|
+
}
|
|
1129
1304
|
}
|
|
1130
|
-
if (
|
|
1305
|
+
if (await canonicalActiveKey() === realTarget) return;
|
|
1306
|
+
const next = await openSource(trustCaller ? resolvedCandidate : realTarget);
|
|
1307
|
+
const text = await next.read();
|
|
1308
|
+
const nextView = await next.readView?.();
|
|
1131
1309
|
clearTimeout(pending);
|
|
1132
1310
|
unwatch();
|
|
1133
|
-
activeSource =
|
|
1134
|
-
current =
|
|
1135
|
-
version = hash(
|
|
1136
|
-
viewState =
|
|
1137
|
-
unwatch = activeSource.watch(
|
|
1138
|
-
clearTimeout(pending);
|
|
1139
|
-
pending = setTimeout(async () => {
|
|
1140
|
-
void serialized(refresh).catch(() => {
|
|
1141
|
-
});
|
|
1142
|
-
}, 80);
|
|
1143
|
-
});
|
|
1311
|
+
activeSource = next;
|
|
1312
|
+
current = text;
|
|
1313
|
+
version = hash(text);
|
|
1314
|
+
viewState = nextView;
|
|
1315
|
+
unwatch = activeSource.watch(scheduleRefresh);
|
|
1144
1316
|
broadcast();
|
|
1145
1317
|
}
|
|
1146
1318
|
const json = (res, status, body) => {
|
|
@@ -1153,7 +1325,7 @@ data: ${JSON.stringify(data)}
|
|
|
1153
1325
|
req.on("data", (c) => {
|
|
1154
1326
|
size += c.length;
|
|
1155
1327
|
if (size > MAX_BODY) {
|
|
1156
|
-
fail(new
|
|
1328
|
+
fail(new HttpError(413, zh2() ? "\u8BF7\u6C42\u5185\u5BB9\u8FC7\u5927\u3002" : "The request is too large."));
|
|
1157
1329
|
req.destroy();
|
|
1158
1330
|
} else chunks.push(c);
|
|
1159
1331
|
});
|
|
@@ -1163,19 +1335,26 @@ data: ${JSON.stringify(data)}
|
|
|
1163
1335
|
const sendFile = async (res, full) => {
|
|
1164
1336
|
if (!full) return json(res, 403, { error: "forbidden" });
|
|
1165
1337
|
try {
|
|
1166
|
-
const ext = (0,
|
|
1338
|
+
const ext = (0, import_node_path3.extname)(full).toLowerCase();
|
|
1167
1339
|
if (ext === ".html") {
|
|
1168
1340
|
const osLoc = detectOsLocale();
|
|
1169
|
-
const htmlText = (await (0,
|
|
1341
|
+
const htmlText = (await (0, import_promises3.readFile)(full, "utf8")).replace(
|
|
1170
1342
|
/<html\b([^>]*)>/i,
|
|
1171
|
-
`<html lang="${osLoc === "zh" ? "zh-CN" : "en"}" data-os-locale="${osLoc}">`
|
|
1343
|
+
() => `<html lang="${osLoc === "zh" ? "zh-CN" : "en"}" data-os-locale="${osLoc}">`
|
|
1172
1344
|
);
|
|
1173
1345
|
res.writeHead(200, { "content-type": TYPES[".html"], "cache-control": "no-store" });
|
|
1174
1346
|
res.end(htmlText, "utf8");
|
|
1175
1347
|
return;
|
|
1176
1348
|
}
|
|
1177
|
-
const body = await (0,
|
|
1178
|
-
|
|
1349
|
+
const body = await (0, import_promises3.readFile)(full);
|
|
1350
|
+
const headers = {
|
|
1351
|
+
"content-type": TYPES[ext] ?? "application/octet-stream",
|
|
1352
|
+
"cache-control": sidebar ? "no-store" : "no-cache"
|
|
1353
|
+
};
|
|
1354
|
+
if (ext === ".svg") {
|
|
1355
|
+
headers["content-security-policy"] = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox";
|
|
1356
|
+
}
|
|
1357
|
+
res.writeHead(200, headers);
|
|
1179
1358
|
res.end(body);
|
|
1180
1359
|
} catch {
|
|
1181
1360
|
json(res, 404, { error: "not found" });
|
|
@@ -1184,17 +1363,26 @@ data: ${JSON.stringify(data)}
|
|
|
1184
1363
|
const server = (0, import_node_http.createServer)(async (req, res) => {
|
|
1185
1364
|
try {
|
|
1186
1365
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
1366
|
+
const reqHost = req.headers.host ?? "";
|
|
1367
|
+
const hostAllowed = LOOPBACK_HOST.test(reqHost) || allowedHosts.has(reqHost.toLowerCase());
|
|
1187
1368
|
if (sidebar) {
|
|
1188
1369
|
res.setHeader("Referrer-Policy", "no-referrer");
|
|
1189
1370
|
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
1190
1371
|
res.setHeader("Cache-Control", "no-store");
|
|
1191
1372
|
res.setHeader("Content-Security-Policy", "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self'; img-src 'self' data: blob:; font-src 'self' data:; base-uri 'none'; form-action 'none'; object-src 'none'");
|
|
1192
|
-
if (
|
|
1373
|
+
if (reqHost !== `127.0.0.1:${bound}` || !url.pathname.startsWith(prefix)) return json(res, 404, { error: "not found" });
|
|
1193
1374
|
if ((req.method === "PUT" || req.method === "POST") && (req.headers.origin !== `http://127.0.0.1:${bound}` || req.headers["content-type"] !== "application/json")) {
|
|
1194
1375
|
return json(res, 403, { error: "forbidden" });
|
|
1195
1376
|
}
|
|
1196
1377
|
url.pathname = "/" + url.pathname.slice(prefix.length);
|
|
1378
|
+
} else if (!hostAllowed) {
|
|
1379
|
+
return json(res, 403, { error: "forbidden" });
|
|
1197
1380
|
}
|
|
1381
|
+
const sameOriginWrite = () => {
|
|
1382
|
+
const origin = req.headers.origin;
|
|
1383
|
+
const sameOrigin = origin === "http://" + reqHost || allowedHosts.has(reqHost.toLowerCase()) && origin === "https://" + reqHost;
|
|
1384
|
+
return hostAllowed && sameOrigin && req.headers["content-type"] === "application/json";
|
|
1385
|
+
};
|
|
1198
1386
|
if (!sidebar && req.method === "GET" && /^\/(?:%E3%80%82|%EF%BC%8C|[。,.,;;::!?!?])+$/i.test(url.pathname)) {
|
|
1199
1387
|
res.writeHead(302, { Location: "/" + url.search });
|
|
1200
1388
|
return res.end();
|
|
@@ -1217,6 +1405,7 @@ data: ${JSON.stringify(data)}
|
|
|
1217
1405
|
});
|
|
1218
1406
|
}
|
|
1219
1407
|
if (url.pathname === "/api/view" && req.method === "PUT") {
|
|
1408
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1220
1409
|
const cleaned = sanitizeViewState(JSON.parse(await readBody(req)));
|
|
1221
1410
|
if (cleaned) {
|
|
1222
1411
|
viewState = cleaned;
|
|
@@ -1226,8 +1415,9 @@ data: ${JSON.stringify(data)}
|
|
|
1226
1415
|
return json(res, 200, { ok: true });
|
|
1227
1416
|
}
|
|
1228
1417
|
if (url.pathname === "/api/doc" && req.method === "PUT") {
|
|
1418
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1229
1419
|
const { md, baseVersion } = JSON.parse(await readBody(req));
|
|
1230
|
-
if (typeof md !== "string") return json(res, 400, { error: "md \u5FC5\u987B\u662F\u5B57\u7B26\u4E32" });
|
|
1420
|
+
if (typeof md !== "string") return json(res, 400, { error: zh2() ? "md \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002" : "md must be a string." });
|
|
1231
1421
|
if (!hasAccess(await license?.state() ?? { pro: false })) return json(res, 403, { error: "Inkmap trial expired" });
|
|
1232
1422
|
return await serialized(async () => {
|
|
1233
1423
|
await refresh();
|
|
@@ -1237,70 +1427,62 @@ data: ${JSON.stringify(data)}
|
|
|
1237
1427
|
current = md;
|
|
1238
1428
|
version = hash(md);
|
|
1239
1429
|
license?.track?.("doc_edit");
|
|
1240
|
-
|
|
1430
|
+
broadcast();
|
|
1241
1431
|
}
|
|
1242
1432
|
return json(res, 200, { version });
|
|
1243
1433
|
});
|
|
1244
1434
|
}
|
|
1245
1435
|
if (url.pathname === "/api/license" && req.method === "GET") return json(res, 200, await license?.state() ?? { pro: false });
|
|
1246
|
-
const sameOriginPost = () => {
|
|
1247
|
-
const origin = req.headers.origin;
|
|
1248
|
-
const reqHost = req.headers.host;
|
|
1249
|
-
const local = reqHost && /^(127\.0\.0\.1|localhost|\[::1\]):[0-9]+$/.test(reqHost);
|
|
1250
|
-
return Boolean(local && origin === "http://" + reqHost && req.headers["content-type"] === "application/json");
|
|
1251
|
-
};
|
|
1252
1436
|
if (url.pathname === "/api/open" && req.method === "POST") {
|
|
1253
|
-
if (!
|
|
1437
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1254
1438
|
const { file } = JSON.parse(await readBody(req));
|
|
1255
|
-
await serialized(() => switchSourceToFile(String(file ?? "")));
|
|
1439
|
+
await serialized(() => switchSourceToFile(String(file ?? ""), false));
|
|
1256
1440
|
license?.track?.("doc_open");
|
|
1257
1441
|
const { files } = await collectWorkspaceFiles();
|
|
1258
1442
|
return json(res, 200, { currentFile: activeSource.key ?? null, files, doc: docState() });
|
|
1259
1443
|
}
|
|
1260
1444
|
if (url.pathname === "/api/telemetry" && req.method === "POST") {
|
|
1261
|
-
if (!
|
|
1445
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1262
1446
|
const { event } = JSON.parse(await readBody(req));
|
|
1263
1447
|
if (typeof event === "string" && event) license?.track?.(event);
|
|
1264
1448
|
return json(res, 200, { ok: true });
|
|
1265
1449
|
}
|
|
1266
1450
|
if (url.pathname === "/api/open-browser" && req.method === "POST") {
|
|
1267
|
-
if (!
|
|
1451
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1268
1452
|
if (license && !hasAccess(await license.state())) {
|
|
1269
1453
|
return json(res, 402, { error: detectOsLocale() === "zh" ? "\u514D\u8D39\u8BD5\u7528\u5DF2\u5230\u671F\uFF0C\u8BF7\u5148\u89E3\u9501\u6216\u6062\u590D Pro\u3002" : "Trial expired. Unlock or restore Pro first." });
|
|
1270
1454
|
}
|
|
1271
1455
|
license?.track?.("feature_browser");
|
|
1272
1456
|
if (!sidebar) {
|
|
1273
|
-
const directUrl = `http://${
|
|
1457
|
+
const directUrl = `http://${urlHost}:${bound}/`;
|
|
1274
1458
|
await openBrowserWindow(directUrl);
|
|
1275
1459
|
return json(res, 200, { ok: true, url: directUrl });
|
|
1276
1460
|
}
|
|
1277
1461
|
if (!browserCompanion) {
|
|
1278
|
-
browserCompanion = (
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
});
|
|
1291
|
-
})();
|
|
1462
|
+
browserCompanion = serve({
|
|
1463
|
+
source: activeSource,
|
|
1464
|
+
webRoot,
|
|
1465
|
+
host: "127.0.0.1",
|
|
1466
|
+
port: 0,
|
|
1467
|
+
license,
|
|
1468
|
+
sidebar: false,
|
|
1469
|
+
workspaceRoots,
|
|
1470
|
+
confineToWorkspaceRoots,
|
|
1471
|
+
openSource,
|
|
1472
|
+
allowPurchase: canPurchase
|
|
1473
|
+
});
|
|
1292
1474
|
browserCompanion.catch(() => {
|
|
1293
1475
|
browserCompanion = null;
|
|
1294
1476
|
});
|
|
1295
1477
|
}
|
|
1296
1478
|
const companion = await browserCompanion;
|
|
1297
|
-
if (activeSource.key) await companion.switchToFile?.(activeSource.key).catch(() => {
|
|
1479
|
+
if (activeSource.key) await companion.switchToFile?.(activeSource.key, { trustCaller: true }).catch(() => {
|
|
1298
1480
|
});
|
|
1299
1481
|
await openBrowserWindow(companion.url);
|
|
1300
1482
|
return json(res, 200, { ok: true, url: companion.url });
|
|
1301
1483
|
}
|
|
1302
1484
|
if (url.pathname === "/api/checkout" && req.method === "POST") {
|
|
1303
|
-
if (!
|
|
1485
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1304
1486
|
const { mode, locale } = JSON.parse(await readBody(req));
|
|
1305
1487
|
if (mode !== "buy" && mode !== "restore") return json(res, 400, { error: "invalid checkout mode" });
|
|
1306
1488
|
if (!canPurchase && mode === "buy") return json(res, 403, { error: "forbidden" });
|
|
@@ -1308,7 +1490,7 @@ data: ${JSON.stringify(data)}
|
|
|
1308
1490
|
return json(res, 200, { url: await (typeof locale === "string" ? license.connect(mode, locale) : license.connect(mode)) });
|
|
1309
1491
|
}
|
|
1310
1492
|
if (url.pathname === "/api/order-pro" && req.method === "POST") {
|
|
1311
|
-
if (!
|
|
1493
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1312
1494
|
if (!canPurchase) return json(res, 403, { error: "forbidden" });
|
|
1313
1495
|
if (!license) return json(res, 503, { error: "Inkmap checkout is unavailable." });
|
|
1314
1496
|
if (typeof license.orderPro !== "function") return json(res, 501, { fallback: true });
|
|
@@ -1316,23 +1498,24 @@ data: ${JSON.stringify(data)}
|
|
|
1316
1498
|
return json(res, 200, { result: await (typeof locale === "string" ? license.orderPro(locale) : license.orderPro()) });
|
|
1317
1499
|
}
|
|
1318
1500
|
if (url.pathname === "/api/phone-send" && req.method === "POST") {
|
|
1319
|
-
if (!
|
|
1501
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1320
1502
|
if (!license || typeof license.sendPhoneCode !== "function") return json(res, 501, { fallback: true });
|
|
1321
1503
|
const { phone, locale } = JSON.parse(await readBody(req));
|
|
1322
1504
|
return json(res, 200, { result: await (typeof locale === "string" ? license.sendPhoneCode(String(phone ?? ""), locale) : license.sendPhoneCode(String(phone ?? ""))) });
|
|
1323
1505
|
}
|
|
1324
1506
|
if (url.pathname === "/api/phone-verify" && req.method === "POST") {
|
|
1325
|
-
if (!
|
|
1507
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1326
1508
|
if (!license || typeof license.signInByPhone !== "function") return json(res, 501, { fallback: true });
|
|
1327
|
-
const { phone, code } = JSON.parse(await readBody(req));
|
|
1328
|
-
return json(res, 200, {
|
|
1509
|
+
const { phone, code, locale } = JSON.parse(await readBody(req));
|
|
1510
|
+
return json(res, 200, {
|
|
1511
|
+
result: await (typeof locale === "string" ? license.signInByPhone(String(phone ?? ""), String(code ?? ""), locale) : license.signInByPhone(String(phone ?? ""), String(code ?? "")))
|
|
1512
|
+
});
|
|
1329
1513
|
}
|
|
1330
1514
|
if (url.pathname === "/api/signout" && req.method === "POST") {
|
|
1331
|
-
if (!
|
|
1515
|
+
if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
|
|
1332
1516
|
await license?.deactivate();
|
|
1333
1517
|
return json(res, 200, await license?.state() ?? { pro: false });
|
|
1334
1518
|
}
|
|
1335
|
-
if (url.pathname === "/api/ads") return json(res, 200, sidebar ? [] : await ads?.() ?? []);
|
|
1336
1519
|
if (url.pathname === "/api/events") {
|
|
1337
1520
|
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
|
|
1338
1521
|
res.write(": connected\n\n");
|
|
@@ -1343,16 +1526,19 @@ data: ${JSON.stringify(data)}
|
|
|
1343
1526
|
if (url.pathname === "/favicon.ico") return void res.writeHead(204).end();
|
|
1344
1527
|
if (url.pathname.startsWith("/doc-assets/")) {
|
|
1345
1528
|
let asset = within(activeSource.dir, url.pathname.slice("/doc-assets/".length));
|
|
1346
|
-
if (
|
|
1347
|
-
const root = await (0,
|
|
1348
|
-
asset = await (0,
|
|
1349
|
-
|
|
1529
|
+
if (asset) {
|
|
1530
|
+
const root = await (0, import_promises3.realpath)(activeSource.dir).catch(() => null);
|
|
1531
|
+
asset = await (0, import_promises3.realpath)(asset).catch(() => null);
|
|
1532
|
+
const allowedExt = sidebar ? /\.(?:png|jpe?g|gif|webp|avif|bmp|ico)$/i : /\.(?:png|jpe?g|gif|webp|avif|bmp|ico|svg)$/i;
|
|
1533
|
+
if (!root || !asset || !insideOrEqual(root, asset) || !allowedExt.test(asset)) asset = null;
|
|
1350
1534
|
}
|
|
1351
1535
|
return sendFile(res, asset);
|
|
1352
1536
|
}
|
|
1353
1537
|
return sendFile(res, within(webRoot, url.pathname === "/" ? "index.html" : url.pathname.slice(1)));
|
|
1354
1538
|
} catch (err) {
|
|
1355
|
-
|
|
1539
|
+
if (res.headersSent) return void res.end();
|
|
1540
|
+
const status = err instanceof HttpError ? err.status : err instanceof SyntaxError ? 400 : 500;
|
|
1541
|
+
json(res, status, { error: err instanceof Error ? err.message : String(err) });
|
|
1356
1542
|
}
|
|
1357
1543
|
});
|
|
1358
1544
|
const listen = (p) => new Promise((ok, fail) => {
|
|
@@ -1363,14 +1549,24 @@ data: ${JSON.stringify(data)}
|
|
|
1363
1549
|
});
|
|
1364
1550
|
});
|
|
1365
1551
|
try {
|
|
1366
|
-
|
|
1552
|
+
try {
|
|
1553
|
+
bound = await listen(port);
|
|
1554
|
+
} catch (err) {
|
|
1555
|
+
if (err.code !== "EADDRINUSE") throw err;
|
|
1556
|
+
bound = await listen(0);
|
|
1557
|
+
}
|
|
1367
1558
|
} catch (err) {
|
|
1368
|
-
|
|
1369
|
-
|
|
1559
|
+
clearTimeout(pending);
|
|
1560
|
+
unwatch();
|
|
1561
|
+
unlisten();
|
|
1562
|
+
throw err;
|
|
1370
1563
|
}
|
|
1371
1564
|
return {
|
|
1372
|
-
url: `http://${
|
|
1373
|
-
switchToFile: (filePath) => serialized(() => switchSourceToFile(filePath)),
|
|
1565
|
+
url: `http://${urlHost}:${bound}${prefix}`,
|
|
1566
|
+
switchToFile: (filePath, options) => serialized(() => switchSourceToFile(filePath, Boolean(options?.trustCaller))),
|
|
1567
|
+
allowHost: (extraHost) => {
|
|
1568
|
+
if (extraHost) allowedHosts.add(extraHost.toLowerCase());
|
|
1569
|
+
},
|
|
1374
1570
|
close: () => new Promise((done) => {
|
|
1375
1571
|
clearTimeout(pending);
|
|
1376
1572
|
unwatch();
|
|
@@ -1478,21 +1674,20 @@ var zh = {
|
|
|
1478
1674
|
copyLink: "\u590D\u5236\u94FE\u63A5",
|
|
1479
1675
|
browserFailed: "\u65E0\u6CD5\u5728\u6D4F\u89C8\u5668\u6253\u5F00\u601D\u7EF4\u5BFC\u56FE\uFF1A{error}",
|
|
1480
1676
|
readOnly: "\u6587\u6863\u65E0\u6CD5\u4FEE\u6539\uFF08\u53EF\u80FD\u662F\u53EA\u8BFB\u6587\u4EF6\uFF09",
|
|
1481
|
-
buyPro: "\u8D2D\u4E70 Pro",
|
|
1482
|
-
signIn: "\u767B\u5F55",
|
|
1483
|
-
switchAccount: "\u5207\u6362\u8D26\u53F7",
|
|
1484
|
-
proActiveDetail: "\u7EC8\u8EAB\u4F1A\u5458\u6743\u76CA\u5DF2\u5F00\u901A\u3002",
|
|
1485
|
-
accountLine: "\u5F53\u524D\u8D26\u53F7\uFF1A{account}",
|
|
1486
|
-
accountConnected: "\u5F53\u524D\u8D26\u53F7\uFF1A\u5DF2\u767B\u5F55",
|
|
1487
1677
|
trialExpired: "7 \u5929\u8BD5\u7528\u5DF2\u7ED3\u675F\u3002\u8BF7\u8D2D\u4E70 Pro\uFF0C\u6216\u767B\u5F55\u5DF2\u8D2D\u4E70 Pro \u7684\u8D26\u53F7\u3002",
|
|
1488
|
-
checkoutHint: "\u5728\u6D4F\u89C8\u5668\u5B8C\u6210\u64CD\u4F5C\uFF0C\u5DF2\u6709 Pro \u6743\u76CA\u4F1A\u81EA\u52A8\u540C\u6B65\u3002",
|
|
1489
1678
|
checkoutFailed: "\u65E0\u6CD5\u6253\u5F00\u8D2D\u4E70\u9875\u9762\u3002",
|
|
1490
|
-
removed: "\u5DF2\u9000\u51FA\u767B\u5F55\u3002",
|
|
1491
|
-
removeConfirm: "\u9000\u51FA\u5F53\u524D\u8D26\u53F7\uFF1F\u4E0B\u6B21\u767B\u5F55\u65F6\u4F1A\u81EA\u52A8\u540C\u6B65 Pro \u6743\u76CA\u3002",
|
|
1492
|
-
remove: "\u9000\u51FA\u767B\u5F55",
|
|
1493
1679
|
saveExport: "\u5BFC\u51FA",
|
|
1494
1680
|
onboardingTip: "\u{1F4A1} Inkmap \u601D\u7EF4\u5BFC\u56FE\u5DF2\u5C31\u7EEA\uFF1A\u70B9\u51FB\u5373\u53EF\u5728\u53F3\u4FA7\u5E76\u6392\u6253\u5F00\u53EF\u53CC\u5411\u7F16\u8F91\u7684\u8111\u56FE\u4E0E\u6D41\u7A0B\u56FE",
|
|
1495
|
-
onboardingAction: "\u7ACB\u5373\u6253\u5F00\u601D\u7EF4\u5BFC\u56FE"
|
|
1681
|
+
onboardingAction: "\u7ACB\u5373\u6253\u5F00\u601D\u7EF4\u5BFC\u56FE",
|
|
1682
|
+
harnessOffer: "\u68C0\u6D4B\u5230 DeepSeek Harness\u3002\u8981\u628A Inkmap \u601D\u7EF4\u5BFC\u56FE\u63D2\u4EF6\u5B89\u88C5\u5230 DeepSeek Harness \u5417\uFF1F\u8FD9\u4F1A\u5728\u5B83\u7684\u684C\u9762\u914D\u7F6E\u4E2D\u52A0\u5165 Inkmap \u63D2\u4EF6\u7D22\u5F15\u5E76\u5B89\u88C5\u63D2\u4EF6\u3002",
|
|
1683
|
+
harnessInstall: "\u5B89\u88C5",
|
|
1684
|
+
harnessNoThanks: "\u4E0D\u7528\u4E86",
|
|
1685
|
+
harnessInstalling: "\u6B63\u5728\u628A Inkmap \u5B89\u88C5\u5230 DeepSeek Harness\u2026",
|
|
1686
|
+
harnessInstalled: "\u5DF2\u628A Inkmap \u5B89\u88C5\u5230 DeepSeek Harness\uFF0C\u91CD\u542F DeepSeek Harness \u540E\u5373\u53EF\u4F7F\u7528\u3002",
|
|
1687
|
+
harnessConfigured: "\u5DF2\u5728 DeepSeek Harness \u4E2D\u52A0\u5165 Inkmap \u63D2\u4EF6\u7D22\u5F15\uFF1B\u672A\u627E\u5230 dsh \u547D\u4EE4\uFF0C\u8BF7\u5728 DeepSeek Harness \u7684\u300C\u63D2\u4EF6\u300D\u9875\u5B89\u88C5 Inkmap\u3002",
|
|
1688
|
+
harnessAlready: "DeepSeek Harness \u4E2D\u5DF2\u5B89\u88C5 Inkmap\u3002",
|
|
1689
|
+
harnessNotFound: "\u672A\u627E\u5230 DeepSeek Harness \u684C\u9762\u7248\u3002",
|
|
1690
|
+
harnessFailed: "\u5B89\u88C5\u5230 DeepSeek Harness \u5931\u8D25\uFF1A{error}"
|
|
1496
1691
|
};
|
|
1497
1692
|
var en = {
|
|
1498
1693
|
openMarkdownFirst: "Open a Markdown file first",
|
|
@@ -1500,21 +1695,20 @@ var en = {
|
|
|
1500
1695
|
copyLink: "Copy link",
|
|
1501
1696
|
browserFailed: "Could not open the mind map in the browser: {error}",
|
|
1502
1697
|
readOnly: "The document cannot be modified (it may be read-only)",
|
|
1503
|
-
buyPro: "Buy Pro",
|
|
1504
|
-
signIn: "Sign In",
|
|
1505
|
-
switchAccount: "Switch Account",
|
|
1506
|
-
proActiveDetail: "Lifetime Pro membership is active.",
|
|
1507
|
-
accountLine: "Account: {account}",
|
|
1508
|
-
accountConnected: "Account: Signed in",
|
|
1509
1698
|
trialExpired: "Your 7-day trial has ended. Buy Pro or sign in to an account that has Pro.",
|
|
1510
|
-
checkoutHint: "Continue in your browser. Any existing Pro access will sync automatically.",
|
|
1511
1699
|
checkoutFailed: "Could not open checkout.",
|
|
1512
|
-
removed: "Signed out.",
|
|
1513
|
-
removeConfirm: "Sign out? Your Pro access will sync the next time you sign in.",
|
|
1514
|
-
remove: "Sign Out",
|
|
1515
1700
|
saveExport: "Export",
|
|
1516
1701
|
onboardingTip: "\u{1F4A1} Inkmap is ready: Open this Markdown file side-by-side as an interactive two-way mind map",
|
|
1517
|
-
onboardingAction: "Open Mind Map"
|
|
1702
|
+
onboardingAction: "Open Mind Map",
|
|
1703
|
+
harnessOffer: "DeepSeek Harness is installed. Add the Inkmap mind map plugin to it? This adds the Inkmap plugin index to its desktop profile and installs the plugin.",
|
|
1704
|
+
harnessInstall: "Install",
|
|
1705
|
+
harnessNoThanks: "No thanks",
|
|
1706
|
+
harnessInstalling: "Installing Inkmap in DeepSeek Harness\u2026",
|
|
1707
|
+
harnessInstalled: "Inkmap was installed in DeepSeek Harness. Restart DeepSeek Harness to use it.",
|
|
1708
|
+
harnessConfigured: "The Inkmap plugin index was added to DeepSeek Harness, but the dsh command was not found. Install Inkmap from the Plugins page in DeepSeek Harness.",
|
|
1709
|
+
harnessAlready: "Inkmap is already installed in DeepSeek Harness.",
|
|
1710
|
+
harnessNotFound: "DeepSeek Harness desktop was not found.",
|
|
1711
|
+
harnessFailed: "Could not install Inkmap in DeepSeek Harness: {error}"
|
|
1518
1712
|
};
|
|
1519
1713
|
var isChinese = () => detectOsLocale() === "zh";
|
|
1520
1714
|
function t(key, vars = {}) {
|
|
@@ -1524,30 +1718,37 @@ function t(key, vars = {}) {
|
|
|
1524
1718
|
// packages/vscode/src/browser.ts
|
|
1525
1719
|
var VIEW_STATE_PREFIX = "inkmap.viewState:";
|
|
1526
1720
|
var BrowserServers = class {
|
|
1527
|
-
constructor(context, webRoot, log, license
|
|
1721
|
+
constructor(context, webRoot, log, license) {
|
|
1528
1722
|
this.context = context;
|
|
1529
1723
|
this.webRoot = webRoot;
|
|
1530
1724
|
this.log = log;
|
|
1531
1725
|
this.license = license;
|
|
1532
|
-
this.ads = ads;
|
|
1533
1726
|
}
|
|
1534
1727
|
servers = /* @__PURE__ */ new Map();
|
|
1535
1728
|
async open(uri) {
|
|
1536
1729
|
const key = uri.toString();
|
|
1537
1730
|
let served = this.servers.get(key);
|
|
1538
1731
|
if (!served) {
|
|
1732
|
+
const workspaceRoots = (vscode2.workspace.workspaceFolders ?? []).filter((f) => f.uri.scheme === "file").map((f) => f.uri.fsPath);
|
|
1539
1733
|
served = serve({
|
|
1540
1734
|
source: documentSource(uri, this.context),
|
|
1541
1735
|
webRoot: this.webRoot,
|
|
1542
1736
|
port: 0,
|
|
1543
1737
|
log: (msg) => this.log.appendLine(`[${docName2(uri)}] ${msg}`),
|
|
1544
1738
|
license: this.license,
|
|
1545
|
-
|
|
1739
|
+
workspaceRoots,
|
|
1740
|
+
// Files picked in the browser tree still go through VS Code's document model (dirty buffers, save hooks).
|
|
1741
|
+
openSource: async (path2) => documentSource(vscode2.Uri.file(path2), this.context)
|
|
1546
1742
|
});
|
|
1547
1743
|
this.servers.set(key, served);
|
|
1548
1744
|
served.catch(() => this.servers.delete(key));
|
|
1549
1745
|
}
|
|
1550
|
-
const
|
|
1746
|
+
const server = await served;
|
|
1747
|
+
if (uri.scheme === "file") await server.switchToFile?.(uri.fsPath, { trustCaller: true }).catch(() => {
|
|
1748
|
+
});
|
|
1749
|
+
const external = await vscode2.env.asExternalUri(vscode2.Uri.parse(server.url));
|
|
1750
|
+
if (external.authority && external.authority.toLowerCase() !== new URL(server.url).host) server.allowHost(external.authority);
|
|
1751
|
+
const url = external.toString(true);
|
|
1551
1752
|
this.log.appendLine(`[${docName2(uri)}] ${url}`);
|
|
1552
1753
|
await openUrl(url);
|
|
1553
1754
|
return url;
|
|
@@ -1563,6 +1764,7 @@ function documentSource(uri, context) {
|
|
|
1563
1764
|
const viewKey = VIEW_STATE_PREFIX + uri.toString();
|
|
1564
1765
|
return {
|
|
1565
1766
|
name: docName2(uri),
|
|
1767
|
+
...uri.scheme === "file" && { key: uri.fsPath },
|
|
1566
1768
|
dir: docDir(uri)?.fsPath ?? "",
|
|
1567
1769
|
read: async () => (await document()).getText(),
|
|
1568
1770
|
async write(md) {
|
|
@@ -1616,12 +1818,12 @@ async function openCheckout(license, mode, localeHint) {
|
|
|
1616
1818
|
|
|
1617
1819
|
// packages/vscode/src/mindmapEditor.ts
|
|
1618
1820
|
var import_node_crypto3 = require("node:crypto");
|
|
1619
|
-
var
|
|
1821
|
+
var import_promises4 = require("node:fs/promises");
|
|
1620
1822
|
var vscode4 = __toESM(require("vscode"));
|
|
1621
1823
|
|
|
1622
1824
|
// packages/vscode/src/html.ts
|
|
1623
1825
|
function webviewHtml(html, { webBase, assetBase, cspSource, nonce, locale }) {
|
|
1624
|
-
const osLoc = locale === "auto" ? "" : /^zh
|
|
1826
|
+
const osLoc = locale === "auto" ? "" : /^zh(?:[-_.]|$)/i.test(locale) ? "zh" : "en";
|
|
1625
1827
|
const csp = [
|
|
1626
1828
|
"default-src 'none'",
|
|
1627
1829
|
`img-src ${cspSource} https: data: blob:`,
|
|
@@ -1632,7 +1834,7 @@ function webviewHtml(html, { webBase, assetBase, cspSource, nonce, locale }) {
|
|
|
1632
1834
|
].join("; ");
|
|
1633
1835
|
const head = `<meta http-equiv="Content-Security-Policy" content="${csp}">
|
|
1634
1836
|
<script nonce="${nonce}">window.INKMAP_ASSET_BASE = ${JSON.stringify(assetBase)}; window.INKMAP_LOCALE = ${JSON.stringify(osLoc || locale)};</script>`;
|
|
1635
|
-
return html.replace(/<html\b([^>]*)>/i, osLoc ? `<html lang="${osLoc === "zh" ? "zh-CN" : "en"}" data-os-locale="${osLoc}">` :
|
|
1837
|
+
return html.replace(/<html\b([^>]*)>/i, (_m, attrs) => osLoc ? `<html lang="${osLoc === "zh" ? "zh-CN" : "en"}" data-os-locale="${osLoc}">` : `<html${attrs}>`).replace(/ crossorigin/g, "").replace(/(src|href)="\.\/assets\//g, (_m, attr) => `${attr}="${webBase}/assets/`).replace(/(src|href)="\.\/(app\.(?:js|css))"/g, (_m, attr, file) => `${attr}="${webBase}/${file}"`).replace(/<script /g, () => `<script nonce="${nonce}" `).replace("<head>", () => `<head>
|
|
1636
1838
|
${head}`);
|
|
1637
1839
|
}
|
|
1638
1840
|
|
|
@@ -1641,28 +1843,42 @@ var VIEW_STATE_PREFIX2 = "inkmap.viewState:";
|
|
|
1641
1843
|
var CHANGE_DELAY = 120;
|
|
1642
1844
|
var REVEAL_DELAY = 150;
|
|
1643
1845
|
var MindmapEditorProvider = class {
|
|
1644
|
-
constructor(context, license
|
|
1846
|
+
constructor(context, license) {
|
|
1645
1847
|
this.context = context;
|
|
1646
1848
|
this.license = license;
|
|
1647
|
-
this.ads = ads;
|
|
1648
1849
|
}
|
|
1649
1850
|
static viewType = "inkmap.mindmap";
|
|
1650
1851
|
panels = /* @__PURE__ */ new Set();
|
|
1852
|
+
readyPanels = /* @__PURE__ */ new WeakSet();
|
|
1853
|
+
panelDocuments = /* @__PURE__ */ new WeakMap();
|
|
1854
|
+
/** An account dialog requested for a document whose editor is still opening; expires so it never pops up later. */
|
|
1855
|
+
pendingAccount;
|
|
1651
1856
|
/** The chat shortcut was pressed: the focused mind map says what is selected. Anywhere else it just opens the chat. */
|
|
1652
1857
|
requestChat() {
|
|
1653
1858
|
const panel = [...this.panels].find((p) => p.active);
|
|
1654
1859
|
return panel ? panel.webview.postMessage({ type: "requestChat" }) : openChat();
|
|
1655
1860
|
}
|
|
1656
|
-
/**
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1861
|
+
/**
|
|
1862
|
+
* Opens the inline Category 1 account & payment panel: in the editor for `document` when given (waiting for it to
|
|
1863
|
+
* finish loading), otherwise in the active or visible Inkmap editor tab.
|
|
1864
|
+
*/
|
|
1865
|
+
openAccount(document) {
|
|
1866
|
+
const panels = [...this.panels];
|
|
1867
|
+
const target = document?.toString();
|
|
1868
|
+
const panel = target ? panels.find((p) => this.panelDocuments.get(p) === target) : panels.find((p) => p.active) ?? panels.find((p) => p.visible);
|
|
1869
|
+
if (panel && this.readyPanels.has(panel)) {
|
|
1870
|
+
void panel.webview.postMessage({ type: "openAccount" });
|
|
1871
|
+
return true;
|
|
1872
|
+
}
|
|
1873
|
+
const uri = target ?? (panel && this.panelDocuments.get(panel));
|
|
1874
|
+
if (!uri) return false;
|
|
1875
|
+
this.pendingAccount = { uri, until: Date.now() + 1e4 };
|
|
1661
1876
|
return true;
|
|
1662
1877
|
}
|
|
1663
1878
|
async resolveCustomTextEditor(document, panel) {
|
|
1664
1879
|
const webview = panel.webview;
|
|
1665
1880
|
this.panels.add(panel);
|
|
1881
|
+
this.panelDocuments.set(panel, document.uri.toString());
|
|
1666
1882
|
const webRoot = vscode4.Uri.joinPath(this.context.extensionUri, "dist", "web");
|
|
1667
1883
|
const assets = docDir(document.uri);
|
|
1668
1884
|
webview.options = {
|
|
@@ -1714,6 +1930,7 @@ var MindmapEditorProvider = class {
|
|
|
1714
1930
|
revealTimer = setTimeout(() => post({ type: "reveal", line: e.selections[0].active.line }), REVEAL_DELAY);
|
|
1715
1931
|
}),
|
|
1716
1932
|
webview.onDidReceiveMessage(async (msg) => {
|
|
1933
|
+
if (msg.type === "mapMarkdownChange") return;
|
|
1717
1934
|
const accountAction = msg.type === "checkout" || msg.type === "orderPro" || msg.type === "openExternal" || msg.type === "signOut" || msg.type === "sendPhoneCode" || msg.type === "signInByPhone" || msg.type === "openInBrowser" || msg.type === "telemetry";
|
|
1718
1935
|
if (!accountAction && msg.type !== "ready" && msg.type !== "viewState" && msg.type !== "select" && !hasAccess(await this.license.state())) {
|
|
1719
1936
|
if ("id" in msg) return post({ type: "error", id: msg.id, message: t("trialExpired") });
|
|
@@ -1721,10 +1938,17 @@ var MindmapEditorProvider = class {
|
|
|
1721
1938
|
}
|
|
1722
1939
|
switch (msg.type) {
|
|
1723
1940
|
case "ready": {
|
|
1941
|
+
this.readyPanels.add(panel);
|
|
1724
1942
|
void this.context.globalState?.update("inkmap.hasOpenedMap", true);
|
|
1725
1943
|
this.license.track?.("doc_open");
|
|
1726
|
-
const [license,
|
|
1727
|
-
|
|
1944
|
+
const [license, chat] = await Promise.all([this.license.state(), chatAvailable()]);
|
|
1945
|
+
await post({ type: "doc", doc: state(), license, chat });
|
|
1946
|
+
const pending = this.pendingAccount;
|
|
1947
|
+
if (pending?.uri === document.uri.toString()) {
|
|
1948
|
+
this.pendingAccount = void 0;
|
|
1949
|
+
if (Date.now() < pending.until) await post({ type: "openAccount" });
|
|
1950
|
+
}
|
|
1951
|
+
return;
|
|
1728
1952
|
}
|
|
1729
1953
|
case "openInBrowser":
|
|
1730
1954
|
return vscode4.commands.executeCommand("inkmap.openInBrowser", document.uri);
|
|
@@ -1806,7 +2030,7 @@ var MindmapEditorProvider = class {
|
|
|
1806
2030
|
case "sendPhoneCode":
|
|
1807
2031
|
return post({ type: "phoneCodeSent", id: msg.id, result: await this.license.sendPhoneCode(msg.phone, msg.locale) });
|
|
1808
2032
|
case "signInByPhone":
|
|
1809
|
-
return post({ type: "phoneSignIn", id: msg.id, result: await this.license.signInByPhone(msg.phone, msg.code) });
|
|
2033
|
+
return post({ type: "phoneSignIn", id: msg.id, result: await this.license.signInByPhone(msg.phone, msg.code, msg.locale) });
|
|
1810
2034
|
case "saveFile":
|
|
1811
2035
|
return post({ type: "fileSaved", id: msg.id, saved: await saveDataUrl(msg.name, msg.dataUrl, assets) });
|
|
1812
2036
|
}
|
|
@@ -1831,11 +2055,11 @@ async function saveDataUrl(name, dataUrl, dir) {
|
|
|
1831
2055
|
});
|
|
1832
2056
|
if (!target) return false;
|
|
1833
2057
|
const body = match[2] ? Buffer.from(match[3], "base64") : Buffer.from(decodeURIComponent(match[3]), "utf8");
|
|
1834
|
-
await
|
|
2058
|
+
await vscode4.workspace.fs.writeFile(target, body);
|
|
1835
2059
|
return true;
|
|
1836
2060
|
}
|
|
1837
2061
|
async function editorHtml(webview, webRoot, assets) {
|
|
1838
|
-
return webviewHtml(await (0,
|
|
2062
|
+
return webviewHtml(await (0, import_promises4.readFile)(vscode4.Uri.joinPath(webRoot, "index.html").fsPath, "utf8"), {
|
|
1839
2063
|
webBase: webview.asWebviewUri(webRoot).toString(),
|
|
1840
2064
|
assetBase: assets ? webview.asWebviewUri(assets).toString() + "/" : "",
|
|
1841
2065
|
cspSource: webview.cspSource,
|
|
@@ -1845,16 +2069,16 @@ async function editorHtml(webview, webRoot, assets) {
|
|
|
1845
2069
|
}
|
|
1846
2070
|
|
|
1847
2071
|
// packages/vscode/src/extension.ts
|
|
1848
|
-
function
|
|
2072
|
+
function insideOrEqual2(root, target) {
|
|
1849
2073
|
if (root === target) return true;
|
|
1850
|
-
const rel = (0,
|
|
1851
|
-
return Boolean(rel && !(0,
|
|
2074
|
+
const rel = (0, import_node_path4.relative)(root, target);
|
|
2075
|
+
return Boolean(rel && !(0, import_node_path4.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(".." + import_node_path4.sep));
|
|
1852
2076
|
}
|
|
1853
2077
|
function resolveEditorUri(filePath) {
|
|
1854
2078
|
for (const folder of vscode5.workspace.workspaceFolders ?? []) {
|
|
1855
2079
|
const folderPath = folder.uri.fsPath || folder.uri.path;
|
|
1856
|
-
if (folderPath &&
|
|
1857
|
-
const rel = (0,
|
|
2080
|
+
if (folderPath && insideOrEqual2(folderPath, filePath)) {
|
|
2081
|
+
const rel = (0, import_node_path4.relative)(folderPath, filePath).split(import_node_path4.sep).join("/");
|
|
1858
2082
|
return rel ? vscode5.Uri.joinPath(folder.uri, rel) : folder.uri;
|
|
1859
2083
|
}
|
|
1860
2084
|
}
|
|
@@ -1872,7 +2096,7 @@ function findColumnForFile(fileUri) {
|
|
|
1872
2096
|
if (input?.uri && (input.uri.fsPath === targetFs || input.uri.path === targetFs)) {
|
|
1873
2097
|
return group.viewColumn;
|
|
1874
2098
|
}
|
|
1875
|
-
if (tab.label && targetFs.endsWith(
|
|
2099
|
+
if (tab.label && targetFs.endsWith(import_node_path4.sep + tab.label.replace(/^Preview\s+/i, ""))) {
|
|
1876
2100
|
return group.viewColumn;
|
|
1877
2101
|
}
|
|
1878
2102
|
}
|
|
@@ -1908,30 +2132,15 @@ async function openFileInEditorPane(filePath) {
|
|
|
1908
2132
|
});
|
|
1909
2133
|
}
|
|
1910
2134
|
function startMcpTargetBridge() {
|
|
1911
|
-
const inkmapDir = process.env.INKMAP_HOME || (0,
|
|
1912
|
-
const targetPath = (0,
|
|
1913
|
-
const ackPath = (0,
|
|
1914
|
-
const statusPath = (0, import_node_path3.join)(inkmapDir, "vscode-bridge-status.json");
|
|
2135
|
+
const inkmapDir = process.env.INKMAP_HOME || (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".inkmap");
|
|
2136
|
+
const targetPath = (0, import_node_path4.join)(inkmapDir, "antigravity-target.json");
|
|
2137
|
+
const ackPath = (0, import_node_path4.join)(inkmapDir, "antigravity-target-ack.json");
|
|
1915
2138
|
let lastSeq = Date.now() - 1e4;
|
|
1916
2139
|
let debounceTimer;
|
|
1917
2140
|
let disposed = false;
|
|
1918
|
-
const writeBridgeStatus = async () => {
|
|
1919
|
-
try {
|
|
1920
|
-
if (!(0, import_node_fs2.existsSync)(inkmapDir)) (0, import_node_fs2.mkdirSync)(inkmapDir, { recursive: true, mode: 448 });
|
|
1921
|
-
await (0, import_promises4.writeFile)(statusPath, JSON.stringify({
|
|
1922
|
-
pid: process.pid,
|
|
1923
|
-
activatedAt: Date.now(),
|
|
1924
|
-
appName: vscode5.env.appName,
|
|
1925
|
-
remoteName: vscode5.env.remoteName,
|
|
1926
|
-
focused: vscode5.window.state.focused,
|
|
1927
|
-
folders: (vscode5.workspace.workspaceFolders ?? []).map((f) => f.uri.toString())
|
|
1928
|
-
}, null, 2), { mode: 384 });
|
|
1929
|
-
} catch {
|
|
1930
|
-
}
|
|
1931
|
-
};
|
|
1932
2141
|
const syncInitialSeq = async () => {
|
|
1933
2142
|
try {
|
|
1934
|
-
const raw = JSON.parse(await (0,
|
|
2143
|
+
const raw = JSON.parse(await (0, import_promises5.readFile)(targetPath, "utf8"));
|
|
1935
2144
|
if (typeof raw?.seq === "number" && raw.seq < Date.now() - 8e3) {
|
|
1936
2145
|
lastSeq = raw.seq;
|
|
1937
2146
|
}
|
|
@@ -1939,34 +2148,55 @@ function startMcpTargetBridge() {
|
|
|
1939
2148
|
}
|
|
1940
2149
|
await checkTarget();
|
|
1941
2150
|
};
|
|
2151
|
+
const alreadyAcked = async (seq) => {
|
|
2152
|
+
try {
|
|
2153
|
+
const ack = JSON.parse(await (0, import_promises5.readFile)(ackPath, "utf8"));
|
|
2154
|
+
return Boolean(ack && ack.ok === true && Number(ack.seq) >= seq);
|
|
2155
|
+
} catch {
|
|
2156
|
+
return false;
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
1942
2159
|
const checkTarget = async () => {
|
|
1943
2160
|
if (disposed) return;
|
|
2161
|
+
let claimedSeq = 0;
|
|
1944
2162
|
try {
|
|
1945
|
-
const raw = JSON.parse(await (0,
|
|
2163
|
+
const raw = JSON.parse(await (0, import_promises5.readFile)(targetPath, "utf8"));
|
|
1946
2164
|
if (!raw || raw.openInEditorPane !== true) return;
|
|
1947
2165
|
const seq = Number(raw.seq) || 0;
|
|
1948
|
-
if (seq <= lastSeq || typeof raw.file !== "string") return;
|
|
1949
|
-
|
|
2166
|
+
if (seq <= lastSeq || typeof raw.file !== "string" || !/\.md$/i.test(raw.file)) return;
|
|
2167
|
+
if (await alreadyAcked(seq)) {
|
|
2168
|
+
lastSeq = seq;
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
const info = await (0, import_promises5.lstat)(raw.file).catch(() => null);
|
|
2172
|
+
if (!info || info.isSymbolicLink() || !info.isFile() || info.size > 5 * 1024 * 1024) return;
|
|
2173
|
+
const realTarget = await (0, import_promises5.realpath)(raw.file).catch(() => raw.file);
|
|
2174
|
+
if (!/\.md$/i.test(realTarget)) return;
|
|
1950
2175
|
const folders = vscode5.workspace.workspaceFolders ?? [];
|
|
1951
|
-
let
|
|
2176
|
+
let matchesFolder = false;
|
|
1952
2177
|
for (const folder of folders) {
|
|
1953
2178
|
const folderPath = folder.uri.fsPath || folder.uri.path;
|
|
1954
2179
|
if (!folderPath) continue;
|
|
1955
|
-
const realFolder = await (0,
|
|
1956
|
-
if (
|
|
1957
|
-
|
|
2180
|
+
const realFolder = await (0, import_promises5.realpath)(folderPath).catch(() => folderPath);
|
|
2181
|
+
if (insideOrEqual2(realFolder, realTarget)) {
|
|
2182
|
+
matchesFolder = true;
|
|
1958
2183
|
break;
|
|
1959
2184
|
}
|
|
1960
2185
|
}
|
|
1961
|
-
if (!
|
|
1962
|
-
|
|
2186
|
+
if (!matchesFolder) {
|
|
2187
|
+
if (!vscode5.window.state.focused) return;
|
|
2188
|
+
await new Promise((r) => setTimeout(r, 70));
|
|
2189
|
+
if (disposed || await alreadyAcked(seq)) {
|
|
2190
|
+
lastSeq = seq;
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
1963
2193
|
}
|
|
1964
|
-
if (!matchesWindow) return;
|
|
1965
2194
|
lastSeq = seq;
|
|
2195
|
+
claimedSeq = seq;
|
|
1966
2196
|
const editorUrl = localEditorUrl(raw.editorUrl);
|
|
1967
2197
|
if (editorUrl) await openUrlInEditorPane(editorUrl);
|
|
1968
2198
|
else await openFileInEditorPane(realTarget);
|
|
1969
|
-
await (0,
|
|
2199
|
+
await (0, import_promises5.writeFile)(ackPath, JSON.stringify({
|
|
1970
2200
|
seq,
|
|
1971
2201
|
file: realTarget,
|
|
1972
2202
|
ok: true,
|
|
@@ -1974,8 +2204,9 @@ function startMcpTargetBridge() {
|
|
|
1974
2204
|
}, null, 2), { mode: 384 }).catch(() => {
|
|
1975
2205
|
});
|
|
1976
2206
|
} catch (err) {
|
|
1977
|
-
|
|
1978
|
-
|
|
2207
|
+
if (!claimedSeq) return;
|
|
2208
|
+
await (0, import_promises5.writeFile)(ackPath, JSON.stringify({
|
|
2209
|
+
seq: claimedSeq,
|
|
1979
2210
|
ok: false,
|
|
1980
2211
|
error: String(err instanceof Error ? err.message : err),
|
|
1981
2212
|
handledAt: Date.now()
|
|
@@ -1983,7 +2214,6 @@ function startMcpTargetBridge() {
|
|
|
1983
2214
|
});
|
|
1984
2215
|
}
|
|
1985
2216
|
};
|
|
1986
|
-
void writeBridgeStatus();
|
|
1987
2217
|
void syncInitialSeq();
|
|
1988
2218
|
try {
|
|
1989
2219
|
if (!(0, import_node_fs2.existsSync)(inkmapDir)) (0, import_node_fs2.mkdirSync)(inkmapDir, { recursive: true, mode: 448 });
|
|
@@ -1994,6 +2224,8 @@ function startMcpTargetBridge() {
|
|
|
1994
2224
|
void checkTarget();
|
|
1995
2225
|
}, 60);
|
|
1996
2226
|
});
|
|
2227
|
+
watcher.on("error", () => {
|
|
2228
|
+
});
|
|
1997
2229
|
const pollFallback = setInterval(() => {
|
|
1998
2230
|
void checkTarget();
|
|
1999
2231
|
}, 1200);
|
|
@@ -2011,57 +2243,115 @@ function startMcpTargetBridge() {
|
|
|
2011
2243
|
} };
|
|
2012
2244
|
}
|
|
2013
2245
|
}
|
|
2014
|
-
|
|
2246
|
+
var HARNESS_INDEX_URL = "https://zhiyuanv.com/dsh-index.json";
|
|
2247
|
+
var HARNESS_MARKET_BUNDLE = "@deepseek-ai/dsh-experimental-plugin-market-bundle";
|
|
2248
|
+
var HARNESS_PROMPTED = "inkmap.deepseekHarnessPrompted";
|
|
2249
|
+
var harnessProfileDir = () => (0, import_node_path4.join)(process.env.DSH_HOME || (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".dsh"), "profiles", "desktop");
|
|
2250
|
+
async function readHarnessProfile(dir) {
|
|
2251
|
+
const patchPath = (0, import_node_path4.join)(dir, "cordis.patch.yml");
|
|
2252
|
+
const patch = (0, import_node_fs2.existsSync)(patchPath) ? await (0, import_promises5.readFile)(patchPath, "utf8").catch(() => "") : "";
|
|
2253
|
+
let pkg;
|
|
2015
2254
|
try {
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2255
|
+
pkg = JSON.parse(await (0, import_promises5.readFile)((0, import_node_path4.join)(dir, "package.json"), "utf8"));
|
|
2256
|
+
} catch {
|
|
2257
|
+
}
|
|
2258
|
+
const bundles = pkg?.dsh?.profile?.bundles;
|
|
2259
|
+
return {
|
|
2260
|
+
dir,
|
|
2261
|
+
patch,
|
|
2262
|
+
pkg,
|
|
2263
|
+
needsIndex: !patch.includes(HARNESS_INDEX_URL) && !/^\s*-\s*id:\s*plugin-market\b/m.test(patch),
|
|
2264
|
+
needsBundle: Array.isArray(bundles) && !bundles.includes(HARNESS_MARKET_BUNDLE),
|
|
2265
|
+
needsPlugin: Boolean(pkg) && !pkg?.dependencies?.["dsh-inkmap"]
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
var harnessSetUp = (profile) => !profile.needsIndex && !profile.needsBundle && !profile.needsPlugin;
|
|
2269
|
+
function harnessCli() {
|
|
2270
|
+
return [
|
|
2271
|
+
process.platform === "darwin" ? "/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh" : "",
|
|
2272
|
+
process.platform === "darwin" ? (0, import_node_path4.join)((0, import_node_os4.homedir)(), "Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh") : "",
|
|
2273
|
+
process.platform === "win32" ? (0, import_node_path4.join)(process.env.LOCALAPPDATA || (0, import_node_path4.join)((0, import_node_os4.homedir)(), "AppData", "Local"), "Programs", "DeepSeek Harness", "resources", "runtime", "cli", "bin", "dsh.cmd") : ""
|
|
2274
|
+
].find((candidate) => candidate && (0, import_node_fs2.existsSync)(candidate));
|
|
2275
|
+
}
|
|
2276
|
+
function runHarnessCli(cli, args) {
|
|
2277
|
+
return new Promise((resolve3, reject) => {
|
|
2278
|
+
const q = (s) => `"${s.replace(/"/g, '""').replace(/%/g, '"^%"')}"`;
|
|
2279
|
+
const child = process.platform === "win32" && !cli.toLowerCase().endsWith(".exe") ? (0, import_node_child_process4.spawn)("cmd.exe", ["/d", "/s", "/c", `"${[cli, ...args].map(q).join(" ")}"`], {
|
|
2280
|
+
stdio: "ignore",
|
|
2281
|
+
windowsVerbatimArguments: true,
|
|
2282
|
+
windowsHide: true
|
|
2283
|
+
}) : (0, import_node_child_process4.spawn)(cli, args, { stdio: "ignore" });
|
|
2284
|
+
const timer = setTimeout(() => {
|
|
2285
|
+
child.kill();
|
|
2286
|
+
reject(new Error("dsh did not finish in time"));
|
|
2287
|
+
}, 18e4);
|
|
2288
|
+
child.on("error", (err) => {
|
|
2289
|
+
clearTimeout(timer);
|
|
2290
|
+
reject(err);
|
|
2291
|
+
});
|
|
2292
|
+
child.on("exit", (code) => {
|
|
2293
|
+
clearTimeout(timer);
|
|
2294
|
+
if (code === 0) resolve3();
|
|
2295
|
+
else reject(new Error(`dsh exited with code ${code}`));
|
|
2296
|
+
});
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
async function installIntoHarness(profile) {
|
|
2300
|
+
if (profile.needsIndex) {
|
|
2301
|
+
const snippet = `- id: plugin-market
|
|
2025
2302
|
name: "@deepseek-ai/dsh-plugin-market"
|
|
2026
2303
|
config:
|
|
2027
2304
|
indexes:
|
|
2028
|
-
- ${
|
|
2305
|
+
- ${HARNESS_INDEX_URL}
|
|
2029
2306
|
`;
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2307
|
+
const trimmed = profile.patch.trim();
|
|
2308
|
+
const next = !trimmed || trimmed === "[]" ? snippet : profile.patch.replace(/\n*$/, "\n\n") + snippet;
|
|
2309
|
+
await (0, import_promises5.writeFile)((0, import_node_path4.join)(profile.dir, "cordis.patch.yml"), next, "utf8");
|
|
2310
|
+
}
|
|
2311
|
+
if (profile.needsBundle && profile.pkg?.dsh?.profile?.bundles) {
|
|
2312
|
+
profile.pkg.dsh.profile.bundles.push(HARNESS_MARKET_BUNDLE);
|
|
2313
|
+
await (0, import_promises5.writeFile)((0, import_node_path4.join)(profile.dir, "package.json"), JSON.stringify(profile.pkg, null, 2) + "\n", "utf8");
|
|
2314
|
+
}
|
|
2315
|
+
if (!profile.needsPlugin) return "installed";
|
|
2316
|
+
const cli = harnessCli();
|
|
2317
|
+
if (!cli) return "configured";
|
|
2318
|
+
const staged = (0, import_node_path4.join)(process.env.INKMAP_HOME || (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".inkmap"), "dsh-inkmap");
|
|
2319
|
+
await runHarnessCli(cli, ["plugin", "--profile", "desktop", "add", (0, import_node_fs2.existsSync)((0, import_node_path4.join)(staged, "package.json")) ? staged : "dsh-inkmap"]);
|
|
2320
|
+
return "installed";
|
|
2321
|
+
}
|
|
2322
|
+
async function installInDeepSeekHarness() {
|
|
2323
|
+
const dir = harnessProfileDir();
|
|
2324
|
+
if (!(0, import_node_fs2.existsSync)(dir)) return void vscode5.window.showWarningMessage(t("harnessNotFound"));
|
|
2325
|
+
try {
|
|
2326
|
+
const profile = await readHarnessProfile(dir);
|
|
2327
|
+
if (harnessSetUp(profile)) return void vscode5.window.showInformationMessage(t("harnessAlready"));
|
|
2328
|
+
const result = await vscode5.window.withProgress(
|
|
2329
|
+
{ location: vscode5.ProgressLocation.Notification, title: t("harnessInstalling") },
|
|
2330
|
+
() => installIntoHarness(profile)
|
|
2331
|
+
);
|
|
2332
|
+
void vscode5.window.showInformationMessage(t(result === "installed" ? "harnessInstalled" : "harnessConfigured"));
|
|
2333
|
+
} catch (err) {
|
|
2334
|
+
void vscode5.window.showErrorMessage(t("harnessFailed", { error: err instanceof Error ? err.message : String(err) }));
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
async function offerDeepSeekHarnessSetup(context) {
|
|
2338
|
+
try {
|
|
2339
|
+
if (context.globalState.get(HARNESS_PROMPTED)) return;
|
|
2340
|
+
const dir = harnessProfileDir();
|
|
2341
|
+
if (!(0, import_node_fs2.existsSync)(dir) || harnessSetUp(await readHarnessProfile(dir))) return;
|
|
2342
|
+
await context.globalState.update(HARNESS_PROMPTED, true);
|
|
2343
|
+
const install = t("harnessInstall");
|
|
2344
|
+
const pick = await vscode5.window.showInformationMessage(t("harnessOffer"), install, t("harnessNoThanks"));
|
|
2345
|
+
if (pick === install) await installInDeepSeekHarness();
|
|
2055
2346
|
} catch {
|
|
2056
2347
|
}
|
|
2057
2348
|
}
|
|
2058
2349
|
function activate(context) {
|
|
2059
|
-
void
|
|
2350
|
+
void offerDeepSeekHarnessSetup(context);
|
|
2060
2351
|
const log = vscode5.window.createOutputChannel("Inkmap");
|
|
2061
2352
|
const license = extensionLicense(context);
|
|
2062
2353
|
license.track?.("plugin_activate");
|
|
2063
|
-
const
|
|
2064
|
-
const browsers = new BrowserServers(context, vscode5.Uri.joinPath(context.extensionUri, "dist", "web").fsPath, log, license, ads);
|
|
2354
|
+
const browsers = new BrowserServers(context, vscode5.Uri.joinPath(context.extensionUri, "dist", "web").fsPath, log, license);
|
|
2065
2355
|
const withUri = (run) => (arg) => {
|
|
2066
2356
|
const uri = targetUri(arg);
|
|
2067
2357
|
if (!uri) return vscode5.window.showWarningMessage(t("openMarkdownFirst"));
|
|
@@ -2086,7 +2376,7 @@ function activate(context) {
|
|
|
2086
2376
|
}
|
|
2087
2377
|
});
|
|
2088
2378
|
};
|
|
2089
|
-
const editors = new MindmapEditorProvider(context, license
|
|
2379
|
+
const editors = new MindmapEditorProvider(context, license);
|
|
2090
2380
|
chatAvailable().then((available) => vscode5.commands.executeCommand("setContext", "inkmap.chatAvailable", available));
|
|
2091
2381
|
maybeOfferOnboarding(vscode5.window.activeTextEditor);
|
|
2092
2382
|
context.subscriptions.push(
|
|
@@ -2096,10 +2386,13 @@ function activate(context) {
|
|
|
2096
2386
|
startMcpTargetBridge(),
|
|
2097
2387
|
vscode5.window.onDidChangeActiveTextEditor(maybeOfferOnboarding),
|
|
2098
2388
|
vscode5.window.registerUriHandler({
|
|
2099
|
-
handleUri(uri) {
|
|
2389
|
+
async handleUri(uri) {
|
|
2100
2390
|
if (uri.path === "/open") {
|
|
2101
|
-
const target = new URLSearchParams(uri.query).get("path");
|
|
2102
|
-
if (target)
|
|
2391
|
+
const target = new URLSearchParams(uri.query).get("path")?.trim();
|
|
2392
|
+
if (!target || !(0, import_node_path4.isAbsolute)(target) || !/\.md$/i.test(target)) return;
|
|
2393
|
+
const info = await (0, import_promises5.lstat)(target).catch(() => null);
|
|
2394
|
+
if (!info || info.isSymbolicLink() || !info.isFile() || info.size > 5 * 1024 * 1024) return;
|
|
2395
|
+
void openFileInEditorPane(target);
|
|
2103
2396
|
}
|
|
2104
2397
|
}
|
|
2105
2398
|
}),
|
|
@@ -2118,7 +2411,7 @@ function activate(context) {
|
|
|
2118
2411
|
withUri(async (uri) => {
|
|
2119
2412
|
if (!hasAccess(await license.state())) {
|
|
2120
2413
|
await openToSide(uri);
|
|
2121
|
-
|
|
2414
|
+
editors.openAccount(uri);
|
|
2122
2415
|
return;
|
|
2123
2416
|
}
|
|
2124
2417
|
try {
|
|
@@ -2131,12 +2424,13 @@ function activate(context) {
|
|
|
2131
2424
|
}
|
|
2132
2425
|
})
|
|
2133
2426
|
),
|
|
2427
|
+
vscode5.commands.registerCommand("inkmap.installDeepSeekHarness", installInDeepSeekHarness),
|
|
2134
2428
|
vscode5.commands.registerCommand("inkmap.upgrade", async (arg) => {
|
|
2135
2429
|
if (editors.openAccount()) return;
|
|
2136
2430
|
const uri = targetUri(arg);
|
|
2137
2431
|
if (!uri) return vscode5.window.showWarningMessage(t("openMarkdownFirst"));
|
|
2138
2432
|
await openToSide(uri);
|
|
2139
|
-
|
|
2433
|
+
editors.openAccount(uri);
|
|
2140
2434
|
})
|
|
2141
2435
|
);
|
|
2142
2436
|
}
|