@galaxy-blackhole/blackhole-harness 0.1.3 → 0.1.5
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/apps/cli/lib/main.js
CHANGED
|
@@ -110,7 +110,7 @@ import { existsSync as existsSync10, writeFileSync as writeFileSync6 } from "nod
|
|
|
110
110
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
111
111
|
import { tmpdir } from "node:os";
|
|
112
112
|
import { createHash as createHash4 } from "node:crypto";
|
|
113
|
-
import { cpSync as cpSync3, existsSync as existsSync7, lstatSync as lstatSync4, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync5, readdirSync as readdirSync5, realpathSync as realpathSync2, rmSync as rmSync3, statSync as statSync3,
|
|
113
|
+
import { cpSync as cpSync3, existsSync as existsSync7, lstatSync as lstatSync4, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync5, readdirSync as readdirSync5, realpathSync as realpathSync2, rmSync as rmSync3, statSync as statSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
114
114
|
|
|
115
115
|
// tools/p1b/denta-profile.ts
|
|
116
116
|
import { createHash } from "node:crypto";
|
|
@@ -386,6 +386,13 @@ function linkSelfPackages() {
|
|
|
386
386
|
return added;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
+
// apps/cli/src/link-dir.ts
|
|
390
|
+
import { symlinkSync as symlinkSync2 } from "node:fs";
|
|
391
|
+
import { resolve as resolve2 } from "node:path";
|
|
392
|
+
function linkDirSync(source, link) {
|
|
393
|
+
symlinkSync2(resolve2(source), resolve2(link), process.platform === "win32" ? "junction" : "dir");
|
|
394
|
+
}
|
|
395
|
+
|
|
389
396
|
// apps/cli/src/mount-gate.ts
|
|
390
397
|
import { spawnSync } from "node:child_process";
|
|
391
398
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -894,8 +901,8 @@ function readPeers(gbh) {
|
|
|
894
901
|
}
|
|
895
902
|
|
|
896
903
|
// apps/cli/src/prebuilt.ts
|
|
897
|
-
import { cpSync as cpSync2, existsSync as existsSync6, mkdirSync as mkdirSync2, readlinkSync, rmSync as rmSync2, statSync as statSync2
|
|
898
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
904
|
+
import { cpSync as cpSync2, existsSync as existsSync6, mkdirSync as mkdirSync2, readlinkSync, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
|
|
905
|
+
import { dirname as dirname4, join as join6, resolve as resolve3 } from "node:path";
|
|
899
906
|
function embeddedHost() {
|
|
900
907
|
return existsSync6(join6(repoRoot(), ".gbh-embedded"));
|
|
901
908
|
}
|
|
@@ -915,7 +922,7 @@ function buildRuntimeAvailable() {
|
|
|
915
922
|
function ensureLink(link, target) {
|
|
916
923
|
try {
|
|
917
924
|
const current = readlinkSync(link);
|
|
918
|
-
if (existsSync6(
|
|
925
|
+
if (existsSync6(resolve3(dirname4(link), current)))
|
|
919
926
|
return false;
|
|
920
927
|
rmSync2(link, { force: true });
|
|
921
928
|
} catch {
|
|
@@ -924,7 +931,7 @@ function ensureLink(link, target) {
|
|
|
924
931
|
}
|
|
925
932
|
try {
|
|
926
933
|
mkdirSync2(dirname4(link), { recursive: true });
|
|
927
|
-
|
|
934
|
+
linkDirSync(target, link);
|
|
928
935
|
return true;
|
|
929
936
|
} catch {
|
|
930
937
|
return false;
|
|
@@ -1006,8 +1013,12 @@ function blockedPackages() {
|
|
|
1006
1013
|
const blocked = new Map;
|
|
1007
1014
|
const script = join7(repoRoot(), "tools", "check", "rows.ts");
|
|
1008
1015
|
if (!existsSync7(script)) {
|
|
1009
|
-
|
|
1010
|
-
|
|
1016
|
+
const message = "[bh] thiếu cổng chặn mount: " + script + " — bản đóng gói phải kèm tools/check; đặt GBH_REPO_ROOT về repo hoặc GBH_ALLOW_NO_GATE=1 để bỏ qua có ý thức";
|
|
1017
|
+
if (process.env.GBH_ALLOW_NO_GATE === "1") {
|
|
1018
|
+
console.warn(message + " (đang bỏ qua vì GBH_ALLOW_NO_GATE=1)");
|
|
1019
|
+
return blocked;
|
|
1020
|
+
}
|
|
1021
|
+
throw new Error(message);
|
|
1011
1022
|
}
|
|
1012
1023
|
const gate = timePhase("cong chan mount", () => runMountGate({ script, cwd: repoRoot(), home: appHome() }));
|
|
1013
1024
|
console.log("[bh] cổng chặn mount: " + gate.detail);
|
|
@@ -1223,7 +1234,7 @@ function mountRewritePackage(pkg) {
|
|
|
1223
1234
|
}
|
|
1224
1235
|
mkdirSync3(dirname5(link), { recursive: true });
|
|
1225
1236
|
rmSync3(link, { recursive: true, force: true });
|
|
1226
|
-
|
|
1237
|
+
linkDirSync(source, link);
|
|
1227
1238
|
peers.push(peer);
|
|
1228
1239
|
}
|
|
1229
1240
|
trace("xong");
|
|
@@ -1255,7 +1266,7 @@ function linkInfrastructurePackages() {
|
|
|
1255
1266
|
} catch {}
|
|
1256
1267
|
try {
|
|
1257
1268
|
mkdirSync3(dirname5(link), { recursive: true });
|
|
1258
|
-
|
|
1269
|
+
linkDirSync(nguon, link);
|
|
1259
1270
|
linked.push(specifier);
|
|
1260
1271
|
} catch {
|
|
1261
1272
|
continue;
|
|
@@ -1287,7 +1298,7 @@ function linkNativeAddonPackages() {
|
|
|
1287
1298
|
} catch {}
|
|
1288
1299
|
try {
|
|
1289
1300
|
mkdirSync3(dirname5(link), { recursive: true });
|
|
1290
|
-
|
|
1301
|
+
linkDirSync(nguon, link);
|
|
1291
1302
|
linked.push("@deepseek-ai/" + goi);
|
|
1292
1303
|
} catch {
|
|
1293
1304
|
continue;
|
|
@@ -1298,7 +1309,8 @@ function linkNativeAddonPackages() {
|
|
|
1298
1309
|
return linked;
|
|
1299
1310
|
}
|
|
1300
1311
|
function ensureRewriteMounts() {
|
|
1301
|
-
|
|
1312
|
+
if (!embeddedHost())
|
|
1313
|
+
linkSelfPackages();
|
|
1302
1314
|
const disabled = (process.env.GBH_DISABLE_REWRITES ?? "").trim() !== "";
|
|
1303
1315
|
const blocked = disabled ? new Map : blockedPackages();
|
|
1304
1316
|
const results = rewritePackages().map((pkg) => disabled ? {
|
|
@@ -1459,7 +1471,7 @@ function applyHostAliases(results) {
|
|
|
1459
1471
|
try {
|
|
1460
1472
|
mkdirSync3(dirname5(link), { recursive: true });
|
|
1461
1473
|
rmSync3(link, { recursive: true, force: true });
|
|
1462
|
-
|
|
1474
|
+
linkDirSync(result.dir, link);
|
|
1463
1475
|
applied.push(alias + " -> " + result.specifier);
|
|
1464
1476
|
} catch (error) {
|
|
1465
1477
|
console.warn("[bh] khong tao duoc host alias " + alias + " -> " + result.dir + ": " + String(error));
|
|
@@ -1568,7 +1580,7 @@ function applyProvenanceAliases() {
|
|
|
1568
1580
|
rmSync3(link, { recursive: true, force: true });
|
|
1569
1581
|
const thuMucKernel = join7(kernelModulesDir2(), stock);
|
|
1570
1582
|
const nguonAlias = chiCoKhaiKieu(dir) && existsSync7(thuMucKernel) ? thuMucKernel : dich;
|
|
1571
|
-
|
|
1583
|
+
linkDirSync(realpathSync2(nguonAlias), link);
|
|
1572
1584
|
applied.push(stock + " -> " + ours);
|
|
1573
1585
|
} catch {
|
|
1574
1586
|
continue;
|
|
@@ -2172,7 +2184,7 @@ function spawnHost(options) {
|
|
|
2172
2184
|
};
|
|
2173
2185
|
const relayOut = relayTo(process.stdout);
|
|
2174
2186
|
const relayErr = relayTo(process.stderr);
|
|
2175
|
-
const ready = new Promise((
|
|
2187
|
+
const ready = new Promise((resolve4, reject) => {
|
|
2176
2188
|
child.stdout?.setEncoding("utf8");
|
|
2177
2189
|
child.stdout?.on("data", (chunk) => {
|
|
2178
2190
|
relayOut(chunk);
|
|
@@ -2189,7 +2201,7 @@ function spawnHost(options) {
|
|
|
2189
2201
|
try {
|
|
2190
2202
|
writeFileSync6(launch.home + "/" + name, url);
|
|
2191
2203
|
} catch {}
|
|
2192
|
-
|
|
2204
|
+
resolve4(url);
|
|
2193
2205
|
});
|
|
2194
2206
|
child.stderr?.setEncoding("utf8");
|
|
2195
2207
|
child.stderr?.on("data", (chunk) => {
|
|
@@ -2231,7 +2243,7 @@ import { join as join11 } from "node:path";
|
|
|
2231
2243
|
|
|
2232
2244
|
// apps/cli/src/oracle.ts
|
|
2233
2245
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
2234
|
-
import { resolve as
|
|
2246
|
+
import { resolve as resolve4 } from "node:path";
|
|
2235
2247
|
function run(command, args) {
|
|
2236
2248
|
try {
|
|
2237
2249
|
const probe = spawnSync5(command, args, { encoding: "utf8", timeout: 5000 });
|
|
@@ -2241,7 +2253,7 @@ function run(command, args) {
|
|
|
2241
2253
|
}
|
|
2242
2254
|
}
|
|
2243
2255
|
function readRuntimeVersionFromBin(binPath) {
|
|
2244
|
-
return readManifestVersion(
|
|
2256
|
+
return readManifestVersion(resolve4(binPath, "..", "..", "package.json"));
|
|
2245
2257
|
}
|
|
2246
2258
|
function findOracle(port = ORACLE_PORT) {
|
|
2247
2259
|
const listed = run("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"]);
|
|
@@ -2269,14 +2281,14 @@ import { createServer } from "node:net";
|
|
|
2269
2281
|
function isPortAvailable(port, host = LOOPBACK_HOST) {
|
|
2270
2282
|
if (port === 0)
|
|
2271
2283
|
return Promise.resolve(true);
|
|
2272
|
-
return new Promise((
|
|
2284
|
+
return new Promise((resolve5) => {
|
|
2273
2285
|
const probe = createServer();
|
|
2274
2286
|
probe.once("error", () => {
|
|
2275
2287
|
probe.close();
|
|
2276
|
-
|
|
2288
|
+
resolve5(false);
|
|
2277
2289
|
});
|
|
2278
2290
|
probe.once("listening", () => {
|
|
2279
|
-
probe.close(() =>
|
|
2291
|
+
probe.close(() => resolve5(true));
|
|
2280
2292
|
});
|
|
2281
2293
|
probe.listen(port, host);
|
|
2282
2294
|
});
|
|
@@ -2736,8 +2748,8 @@ async function main(argv) {
|
|
|
2736
2748
|
const onTerminate = () => void host.child.kill("SIGTERM");
|
|
2737
2749
|
process.once("SIGINT", onInterrupt);
|
|
2738
2750
|
process.once("SIGTERM", onTerminate);
|
|
2739
|
-
const code = await new Promise((
|
|
2740
|
-
host.child.once("exit", (exitCode) =>
|
|
2751
|
+
const code = await new Promise((resolve5) => {
|
|
2752
|
+
host.child.once("exit", (exitCode) => resolve5(exitCode ?? EXIT.error));
|
|
2741
2753
|
});
|
|
2742
2754
|
process.off("SIGINT", onInterrupt);
|
|
2743
2755
|
process.off("SIGTERM", onTerminate);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* author Bùi Trọng Hiếu
|
|
3
|
+
* email kevinbui210191@gmail.com
|
|
4
|
+
* create date 15/10/2026
|
|
5
|
+
* modify date 16/11/2026
|
|
6
|
+
* desc Tao lien ket THU MUC chay duoc tren moi he: Windows khong cho symlink thu muc neu thieu quyen
|
|
7
|
+
* (EPERM) nhung JUNCTION thi khong can quyen. 16/11/2026: loi Windows that — profile thieu
|
|
8
|
+
* @galaxy-blackhole/gbh-brand, gbh-typert-protocol, gbh-cordis-plugin-timer ⇒ 4 plugin khong
|
|
9
|
+
* activate ⇒ harness khong in URL.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { symlinkSync } from "node:fs";
|
|
13
|
+
import { resolve } from "node:path";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Tao lien ket thư mục từ `source` tới `link`, chọn kiểu phù hợp với hệ điều hành.
|
|
17
|
+
*
|
|
18
|
+
* @param source - thư mục đích (thật) của liên kết.
|
|
19
|
+
* @param link - đường dẫn liên kết cần tạo.
|
|
20
|
+
* @remarks Windows chỉ tạo được **junction** khi không có quyền Administrator/Developer Mode; symlink
|
|
21
|
+
* thư mục sẽ ném EPERM và trước 16/11/2026 lỗi đó bị `catch {}` nuốt ⇒ profile thiếu gói ⇒ harness chết.
|
|
22
|
+
* @throws khi không tạo được liên kết (để nơi gọi báo rõ, không im lặng).
|
|
23
|
+
*/
|
|
24
|
+
export function linkDirSync(source: string, link: string): void {
|
|
25
|
+
// 16/11/2026 (Lead): junction của Windows LƯU ĐƯỜNG DẪN TUYỆT ĐỐI trong đích, nên nếu `source` là
|
|
26
|
+
// đường dẫn tương đối thì junction tạo ra trỏ về chính nó ⇒ ESM báo
|
|
27
|
+
// "Cannot find module '<link>' imported from '<link>'" (đúng lỗi Windows 16/11/2026, 183 plugin
|
|
28
|
+
// không activate). resolve() cả hai đầu để junction luôn tuyệt đối, trên POSIX thì vô hại.
|
|
29
|
+
symlinkSync(resolve(source), resolve(link), process.platform === "win32" ? "junction" : "dir");
|
|
30
|
+
}
|
package/apps/cli/src/mount.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { suaIdProfile } from "../../../tools/p1b/denta-profile.ts";
|
|
|
19
19
|
import { dirname, join, relative } from "node:path";
|
|
20
20
|
import { appHome, kernelModulesDir as kernelModulesDirFromPaths, repoRoot } from "./paths.ts";
|
|
21
21
|
import { linkSelfPackages } from "./self-links.ts";
|
|
22
|
+
import { linkDirSync } from "./link-dir.ts";
|
|
22
23
|
import { bunOnlyCommand, runMountGate } from "./mount-gate.ts";
|
|
23
24
|
import { timePhase } from "./boot-timing.ts";
|
|
24
25
|
|
|
@@ -169,11 +170,16 @@ export function parseRowVerdicts(output: string): RowVerdict[] {
|
|
|
169
170
|
function blockedPackages(): Map<string, string> {
|
|
170
171
|
const blocked = new Map<string, string>();
|
|
171
172
|
const script = join(repoRoot(), 'tools', 'check', 'rows.ts');
|
|
172
|
-
//
|
|
173
|
-
//
|
|
173
|
+
// 19/11/2026 — FAIL-CLOSED: bản đóng gói phải kèm cổng chặn mount. Trước đây thiếu `tools/check` thì
|
|
174
|
+
// in cảnh báo rồi mount tiếp — nghĩa là bản người dùng chạy không có 12 luật kiểm. Nay mặc định DỪNG;
|
|
175
|
+
// chỉ bỏ qua khi người vận hành đặt GBH_ALLOW_NO_GATE=1 (có ý thức, để debug).
|
|
174
176
|
if (!existsSync(script)) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
const message = '[bh] thiếu cổng chặn mount: ' + script + ' — bản đóng gói phải kèm tools/check; đặt GBH_REPO_ROOT về repo hoặc GBH_ALLOW_NO_GATE=1 để bỏ qua có ý thức';
|
|
178
|
+
if (process.env.GBH_ALLOW_NO_GATE === '1') {
|
|
179
|
+
console.warn(message + ' (đang bỏ qua vì GBH_ALLOW_NO_GATE=1)');
|
|
180
|
+
return blocked;
|
|
181
|
+
}
|
|
182
|
+
throw new Error(message);
|
|
177
183
|
}
|
|
178
184
|
// 12/11/2026 — LOI TINH DUNG: `process.execPath run <script>` chi dung khi tien trinh la Bun. App desktop
|
|
179
185
|
// chay launcher bang Node ⇒ lenh vo nghia, tien trinh con chet ngay, output rong ⇒ cong chan mount IM LANG
|
|
@@ -491,7 +497,7 @@ const trace = process.env.BH_TRACE === "1" ? (step: string): void => { console.l
|
|
|
491
497
|
}
|
|
492
498
|
mkdirSync(dirname(link), { recursive: true });
|
|
493
499
|
rmSync(link, { recursive: true, force: true });
|
|
494
|
-
|
|
500
|
+
linkDirSync(source, link);
|
|
495
501
|
peers.push(peer);
|
|
496
502
|
}
|
|
497
503
|
// Host alias KHÔNG tạo ở đây: vòng peer của những gói mount SAU sẽ ghi đè cùng đường dẫn
|
|
@@ -544,7 +550,7 @@ export function linkInfrastructurePackages(): string[] {
|
|
|
544
550
|
}
|
|
545
551
|
try {
|
|
546
552
|
mkdirSync(dirname(link), { recursive: true });
|
|
547
|
-
|
|
553
|
+
linkDirSync(nguon, link);
|
|
548
554
|
linked.push(specifier);
|
|
549
555
|
} catch {
|
|
550
556
|
continue;
|
|
@@ -589,7 +595,7 @@ export function linkNativeAddonPackages(): string[] {
|
|
|
589
595
|
}
|
|
590
596
|
try {
|
|
591
597
|
mkdirSync(dirname(link), { recursive: true });
|
|
592
|
-
|
|
598
|
+
linkDirSync(nguon, link);
|
|
593
599
|
linked.push("@deepseek-ai/" + goi);
|
|
594
600
|
} catch {
|
|
595
601
|
continue;
|
|
@@ -606,7 +612,10 @@ export function linkNativeAddonPackages(): string[] {
|
|
|
606
612
|
*/
|
|
607
613
|
export function ensureRewriteMounts(): MountResult[] {
|
|
608
614
|
// 12/11/2026 — chay TRUOC moi buoc mount: import cheo giua cac goi GBH phai phan giai duoc tu cay goi.
|
|
609
|
-
linkSelfPackages()
|
|
615
|
+
// 19/11/2026 — KHÔNG làm việc này với host NHÚNG: `linkSelfPackages()` ghi symlink vào
|
|
616
|
+
// `repoRoot()/node_modules` (trong .app là `Resources/host/apps/host/node_modules`) ⇒ mỗi lượt boot
|
|
617
|
+
// sửa bundle SAU khi ký ⇒ `codesign --verify` báo "file added". Bản nhúng đã có node_modules đi kèm.
|
|
618
|
+
if (!embeddedHost()) linkSelfPackages();
|
|
610
619
|
const disabled = (process.env.GBH_DISABLE_REWRITES ?? "").trim() !== "";
|
|
611
620
|
// 12/11/2026: che do TAT (A/B) khong mount gi ⇒ khong can chay cong chan mount (tiet kiem ~2,6 s).
|
|
612
621
|
const blocked = disabled ? new Map<string, string>() : blockedPackages();
|
|
@@ -825,7 +834,7 @@ export function applyHostAliases(results: readonly MountResult[]): string[] {
|
|
|
825
834
|
try {
|
|
826
835
|
mkdirSync(dirname(link), { recursive: true });
|
|
827
836
|
rmSync(link, { recursive: true, force: true });
|
|
828
|
-
|
|
837
|
+
linkDirSync(result.dir, link);
|
|
829
838
|
applied.push(alias + " -> " + result.specifier);
|
|
830
839
|
} catch (error) {
|
|
831
840
|
console.warn("[bh] khong tao duoc host alias " + alias + " -> " + result.dir + ": " + String(error));
|
|
@@ -963,7 +972,7 @@ export function applyProvenanceAliases(): string[] {
|
|
|
963
972
|
// activate"). Khi gói ta CHỈ có khai kiểu mà KERNEL có bản đầy đủ thì alias phải trỏ KERNEL.
|
|
964
973
|
const thuMucKernel = join(kernelModulesDir(), stock);
|
|
965
974
|
const nguonAlias = chiCoKhaiKieu(dir) && existsSync(thuMucKernel) ? thuMucKernel : dich;
|
|
966
|
-
|
|
975
|
+
linkDirSync(realpathSync(nguonAlias), link);
|
|
967
976
|
applied.push(stock + ' -> ' + ours);
|
|
968
977
|
} catch {
|
|
969
978
|
continue;
|
package/apps/cli/src/prebuilt.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { cpSync, existsSync, mkdirSync, readlinkSync, rmSync, statSync, symlinkSync } from "node:fs";
|
|
13
13
|
import { dirname, join, resolve } from "node:path";
|
|
14
|
+
import { linkDirSync } from "./link-dir.ts";
|
|
14
15
|
import { repoRoot } from "./paths.ts";
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -69,7 +70,7 @@ export function ensureLink(link: string, target: string): boolean {
|
|
|
69
70
|
}
|
|
70
71
|
try {
|
|
71
72
|
mkdirSync(dirname(link), { recursive: true });
|
|
72
|
-
|
|
73
|
+
linkDirSync(target, link);
|
|
73
74
|
return true;
|
|
74
75
|
} catch {
|
|
75
76
|
return false;
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
1
2
|
import { readFile } from "node:fs/promises";
|
|
2
3
|
import { createServer } from "node:http";
|
|
3
4
|
import { createServer as createServer$1 } from "node:https";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
4
6
|
import { isIP } from "node:net";
|
|
5
|
-
import { resolve } from "node:path";
|
|
7
|
+
import { dirname, extname, join, resolve } from "node:path";
|
|
6
8
|
import { Service } from "@deepseek-ai/cordis";
|
|
7
9
|
import z from "@deepseek-ai/schemastery";
|
|
8
10
|
import compressionMiddleware from "compression";
|
|
@@ -379,6 +381,38 @@ var WebServer = class extends Service {
|
|
|
379
381
|
/* v8 ignore next -- `?? '/'` arm: node:http always sets url on server
|
|
380
382
|
requests; the field is only optional on the client-side IncomingMessage type */
|
|
381
383
|
const rawPath = new URL(req.url ?? "/", "http://x").pathname;
|
|
384
|
+
// GBH_STATIC_FALLBACK: bản npm/Windows có thể không mount web-app fallback; phục vụ UI
|
|
385
|
+
// trực tiếp trước route "/" để tránh 404, chỉ khi có cookie dsh-auth (API auth giữ nguyên).
|
|
386
|
+
if (req.method === "GET" || req.method === "HEAD") {
|
|
387
|
+
try {
|
|
388
|
+
const parsed = new URL(req.url ?? "/", "http://x");
|
|
389
|
+
const pathname = decodeURIComponent(parsed.pathname);
|
|
390
|
+
const isUi = pathname === "/" || pathname.startsWith("/assets/") || /^\/(favicon|manifest|icon)/u.test(pathname);
|
|
391
|
+
const hasAuthCookie = String(req.headers.cookie ?? "").includes("dsh-auth-");
|
|
392
|
+
if (isUi && hasAuthCookie && !parsed.searchParams.has("token")) {
|
|
393
|
+
const require = createRequire(import.meta.url);
|
|
394
|
+
const candidates = [];
|
|
395
|
+
if (process.env.GBH_FRONTEND_DIST) candidates.push(process.env.GBH_FRONTEND_DIST);
|
|
396
|
+
candidates.push(join(process.cwd(), "node_modules", "@deepseek-ai", "dsh-web-frontend", "dist"));
|
|
397
|
+
try { candidates.push(join(dirname(require.resolve("@deepseek-ai/dsh-web-frontend/package.json")), "dist")); } catch {}
|
|
398
|
+
const dist = candidates.find((candidate) => existsSync(join(candidate, "index.html")));
|
|
399
|
+
if (dist !== void 0) {
|
|
400
|
+
const rel = pathname === "/" ? "index.html" : pathname.replace(/^\//u, "");
|
|
401
|
+
const target = join(dist, rel);
|
|
402
|
+
if (target.startsWith(dist) && existsSync(target)) {
|
|
403
|
+
const MIME = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".svg": "image/svg+xml", ".webmanifest": "application/manifest+json", ".json": "application/json" };
|
|
404
|
+
let body = readFileSync(target);
|
|
405
|
+
if (rel === "index.html" && typeof this.renderIndex === "function") body = this.renderIndex(body.toString("utf8"));
|
|
406
|
+
res.writeHead(200, { "content-type": MIME[extname(target)] ?? "application/octet-stream" });
|
|
407
|
+
res.end(body);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
} catch (error) {
|
|
413
|
+
this.ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
382
416
|
const route = this.match(rawPath);
|
|
383
417
|
if (route !== void 0) {
|
|
384
418
|
await route.handler(req, res);
|