@linxin666/dsh-client-ui-plugin-manager 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +20 -6
- package/README.zh.md +20 -6
- package/cordis.patch.yml +14 -1
- package/lib/client.js +579 -11
- package/lib/client.js.map +1 -1
- package/lib/index.js +410 -25
- package/lib/types/client/PluginListToolbar.d.ts +44 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/index.d.ts +18 -1
- package/lib/types/client/locales.d.ts +57 -2
- package/lib/types/client/plugin-toolbar-mount.d.ts +47 -0
- package/lib/types/core/protocol.d.ts +19 -0
- package/lib/types/core/updates.d.ts +30 -0
- package/lib/types/core/version.d.ts +4 -1
- package/lib/types/host/detached-work.d.ts +44 -0
- package/lib/types/host/gateway.d.ts +1 -1
- package/lib/types/host/profile.d.ts +28 -0
- package/lib/types/host/restart.d.ts +95 -0
- package/lib/types/host/routes.d.ts +16 -1
- package/lib/types/host/state.d.ts +3 -1
- package/lib/types/index.d.ts +7 -2
- package/package.json +18 -15
package/lib/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { closeSync, existsSync, openSync, readFileSync, readSync } from "node:fs";
|
|
2
|
+
import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync } from "node:fs";
|
|
3
3
|
import { copyFile, readFile, rename, writeFile } from "node:fs/promises";
|
|
4
4
|
import { basename, dirname, isAbsolute, join, normalize, posix, sep, win32 } from "node:path";
|
|
5
5
|
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { isAbsolute as isAbsolute$1, join as join$1 } from "node:path/posix";
|
|
8
|
+
import { AsyncResource } from "node:async_hooks";
|
|
8
9
|
//#region src/mount-once.ts
|
|
9
10
|
/**
|
|
10
11
|
* Host single-instance guard shared by the plugin family. The family bundle
|
|
@@ -545,6 +546,10 @@ function resolveDshHome(env = process.env, home = homedir()) {
|
|
|
545
546
|
}
|
|
546
547
|
return j(home, ".dsh");
|
|
547
548
|
}
|
|
549
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
550
|
+
function dshHome() {
|
|
551
|
+
return resolveDshHome();
|
|
552
|
+
}
|
|
548
553
|
//#endregion
|
|
549
554
|
//#region src/host/profile.ts
|
|
550
555
|
/**
|
|
@@ -578,6 +583,38 @@ function desktopSelectedProfile(env = process.env) {
|
|
|
578
583
|
} catch {}
|
|
579
584
|
}
|
|
580
585
|
/**
|
|
586
|
+
* The running installation's own `@deepseek-ai/dsh` package.json, as the
|
|
587
|
+
* launcher published it on `profileContext`, or undefined when the host
|
|
588
|
+
* publishes none (or publishes something unusable). This is a READ-ONLY
|
|
589
|
+
* fact — unlike the profile directory and the patch path it is never a write
|
|
590
|
+
* target — but it still arrives from outside this package, so it must be an
|
|
591
|
+
* absolute, traversal-free path before anything reads a version out of it.
|
|
592
|
+
* @param launched - the profile facts the Host published, when available.
|
|
593
|
+
* @returns the validated anchor path, or undefined.
|
|
594
|
+
*/
|
|
595
|
+
function launchedInstallAnchor(launched) {
|
|
596
|
+
const anchor = launched === void 0 || typeof launched.installAnchor !== "string" ? "" : launched.installAnchor.trim();
|
|
597
|
+
if (anchor === "") return void 0;
|
|
598
|
+
if (!isAbsolute(anchor) || anchor.split(/[\/\\]/).includes("..")) return void 0;
|
|
599
|
+
return anchor;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Read the `version` field of one package manifest, tolerating every failure:
|
|
603
|
+
* a missing file, an unreadable one (a stripped asar entry), malformed JSON, or
|
|
604
|
+
* a non-string version all read as "no version". Callers fall back to their next
|
|
605
|
+
* source rather than reporting a version nobody declared.
|
|
606
|
+
* @param manifestPath - absolute path of a package.json.
|
|
607
|
+
* @returns the declared version, or undefined.
|
|
608
|
+
*/
|
|
609
|
+
function readManifestVersion(manifestPath) {
|
|
610
|
+
try {
|
|
611
|
+
const parsed = JSON.parse(stripBom(readFileSync(manifestPath, "utf8")));
|
|
612
|
+
return typeof parsed.version === "string" && parsed.version.trim() !== "" ? parsed.version.trim() : void 0;
|
|
613
|
+
} catch {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
581
618
|
* Whether the host argv names the packaged Desktop launcher, whose entry
|
|
582
619
|
* script is `@deepseek-ai/dsh-desktop-host`. The Desktop client boots the
|
|
583
620
|
* `desktop` profile through `runProfile()` WITHOUT a `--profile` flag and
|
|
@@ -807,10 +844,12 @@ function profileExists(profileDir) {
|
|
|
807
844
|
* itself (the UI performing the write), the family settings surface the tab
|
|
808
845
|
* injects into, and the aggregate compat face (disabling it unmounts the
|
|
809
846
|
* whole folded client bundle while host rows keep running — a half-dead
|
|
810
|
-
* page). Covers both the standalone and the aggregate row ids.
|
|
847
|
+
* page). Covers both the standalone and the aggregate row ids. The standalone
|
|
848
|
+
* id is this package's own `cordis.patch.yml` insert id, never the official
|
|
849
|
+
* `ui-plugin-manager` row the DSH web-app bundle already claims.
|
|
811
850
|
*/
|
|
812
851
|
const LOCKED_ENTRY_IDS = /* @__PURE__ */ new Set([
|
|
813
|
-
"ui-plugin-manager",
|
|
852
|
+
"ui-plugin-manager-update-check",
|
|
814
853
|
"web-ui-plugin-manager",
|
|
815
854
|
"ui-web-ui-settings",
|
|
816
855
|
"web-ui-settings",
|
|
@@ -1073,8 +1112,54 @@ const UNSAFE_SPEC_CHARS = /[&|<>"'`%!\n\r\0]/;
|
|
|
1073
1112
|
function unsafeSpecReason(spec) {
|
|
1074
1113
|
return UNSAFE_SPEC_CHARS.test(spec) ? "plugin-manager: spec 含有危险的 shell 元字符或控制字符,已拒绝" : void 0;
|
|
1075
1114
|
}
|
|
1115
|
+
/**
|
|
1116
|
+
* The Electron resource roots a packaged Desktop install may carry, as
|
|
1117
|
+
* absolute directories. Two independent launcher facts name them, and either
|
|
1118
|
+
* alone is enough:
|
|
1119
|
+
*
|
|
1120
|
+
* - `process.resourcesPath` is Electron's own answer for the directory holding
|
|
1121
|
+
* `app.asar` and the bundled runtime (the Desktop host runs as an Electron
|
|
1122
|
+
* Node-mode child, so it always has one);
|
|
1123
|
+
* - the running host entry script sits INSIDE that tree
|
|
1124
|
+
* (`<resources>/app.asar/dsh/node_modules/@deepseek-ai/dsh-desktop-host/lib/index.js`),
|
|
1125
|
+
* so the first ancestor directory named `resources` is the same location even
|
|
1126
|
+
* when the process is not Electron.
|
|
1127
|
+
*
|
|
1128
|
+
* A root is only ever used to build a candidate path that must then exist, so
|
|
1129
|
+
* an unrelated `resources` directory elsewhere in the tree resolves to nothing.
|
|
1130
|
+
* @param hostEntryPath - the running host's entry script.
|
|
1131
|
+
* @param resourcesPath - Electron's resource directory, when the host has one.
|
|
1132
|
+
* @param pathApi - platform path semantics.
|
|
1133
|
+
* @returns candidate resource roots, in probe order.
|
|
1134
|
+
*/
|
|
1135
|
+
function desktopResourceRoots(hostEntryPath, resourcesPath, pathApi) {
|
|
1136
|
+
const roots = [];
|
|
1137
|
+
if (resourcesPath !== void 0 && resourcesPath !== "") roots.push(resourcesPath);
|
|
1138
|
+
if (hostEntryPath !== void 0 && hostEntryPath !== "") {
|
|
1139
|
+
let current = pathApi.dirname(hostEntryPath);
|
|
1140
|
+
for (let depth = 0; depth < 12; depth += 1) {
|
|
1141
|
+
const parent = pathApi.dirname(current);
|
|
1142
|
+
if (parent === current) break;
|
|
1143
|
+
current = parent;
|
|
1144
|
+
if (pathApi.basename(current).toLowerCase() === "resources") {
|
|
1145
|
+
roots.push(current);
|
|
1146
|
+
break;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
return roots;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Electron's resource directory when this process is an Electron child, read
|
|
1154
|
+
* defensively: the type is not in `@types/node`, and a plain Node host has no
|
|
1155
|
+
* such property at all.
|
|
1156
|
+
*/
|
|
1157
|
+
function processResourcesPath() {
|
|
1158
|
+
const value = process.resourcesPath;
|
|
1159
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
1160
|
+
}
|
|
1076
1161
|
/** The binary search roots for the dsh CLI. */
|
|
1077
|
-
function findDshBinary(env = process.env, platform = process.platform, exists = existsSync, hostEntryPath = process.argv[1]) {
|
|
1162
|
+
function findDshBinary(env = process.env, platform = process.platform, exists = existsSync, hostEntryPath = process.argv[1], resourcesPath = processResourcesPath()) {
|
|
1078
1163
|
const candidates = [];
|
|
1079
1164
|
const separator = platform === "win32" ? ";" : ":";
|
|
1080
1165
|
const pathApi = platform === "win32" ? win32 : posix;
|
|
@@ -1100,6 +1185,11 @@ function findDshBinary(env = process.env, platform = process.platform, exists =
|
|
|
1100
1185
|
const packageRoot = pathApi.dirname(entryDir);
|
|
1101
1186
|
candidates.push(pathApi.join(packageRoot, "lib", "bin.js"));
|
|
1102
1187
|
}
|
|
1188
|
+
for (const root of desktopResourceRoots(hostEntryPath, resourcesPath, pathApi)) {
|
|
1189
|
+
const cliBin = pathApi.join(root, "runtime", "cli", "bin");
|
|
1190
|
+
if (platform === "win32") candidates.push(pathApi.join(cliBin, "dsh.cmd"), pathApi.join(cliBin, "dsh.exe"));
|
|
1191
|
+
else candidates.push(pathApi.join(cliBin, "dsh"));
|
|
1192
|
+
}
|
|
1103
1193
|
for (const candidate of candidates) if (exists(candidate)) return candidate;
|
|
1104
1194
|
return null;
|
|
1105
1195
|
}
|
|
@@ -2421,7 +2511,9 @@ function meetsMinimumDsh(host, minimum) {
|
|
|
2421
2511
|
}
|
|
2422
2512
|
/**
|
|
2423
2513
|
* Read the declared DSH minimum from a published registry manifest:
|
|
2424
|
-
* `dsh.engines.dsh` first, top-level `engines.dsh`
|
|
2514
|
+
* `dsh.engines.dsh` first, top-level `engines.dsh` next, and
|
|
2515
|
+
* `peerDependencies["@deepseek-ai/dsh"]` last, which is where a package that
|
|
2516
|
+
* only declares the host as a peer still gets gated at boot.
|
|
2425
2517
|
* Defensive against malformed or untrusted metadata: anything that is not a
|
|
2426
2518
|
* non-empty string reads as absent.
|
|
2427
2519
|
* @param manifest - the decoded registry version manifest.
|
|
@@ -2430,7 +2522,8 @@ function meetsMinimumDsh(host, minimum) {
|
|
|
2430
2522
|
function dshRequirementOf(manifest) {
|
|
2431
2523
|
const dshEngines = manifest.dsh?.engines;
|
|
2432
2524
|
const engines = manifest.engines?.dsh;
|
|
2433
|
-
const
|
|
2525
|
+
const peers = manifest.peerDependencies?.["@deepseek-ai/dsh"];
|
|
2526
|
+
const value = dshEngines?.dsh ?? engines ?? peers;
|
|
2434
2527
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
2435
2528
|
}
|
|
2436
2529
|
//#endregion
|
|
@@ -2480,6 +2573,186 @@ function targetSpecForLegacy(sourceSpec, familyVersion) {
|
|
|
2480
2573
|
return `${CURRENT_AGGREGATE}@${familyVersion}`;
|
|
2481
2574
|
}
|
|
2482
2575
|
//#endregion
|
|
2576
|
+
//#region src/host/detached-work.ts
|
|
2577
|
+
/**
|
|
2578
|
+
* Run one piece of work outside the caller's async context.
|
|
2579
|
+
*
|
|
2580
|
+
* A Host mutation that runs inside `hmr.runExclusive` marks the running async
|
|
2581
|
+
* context with an AsyncLocalStorage store. Side effects on that path that write
|
|
2582
|
+
* a file the HMR config watcher refreshes from - `cordis.patch.yml` above all -
|
|
2583
|
+
* must not run under that mark, or the watcher's refresh re-enters the
|
|
2584
|
+
* exclusive transaction and is refused with "HMR transactions cannot be nested"
|
|
2585
|
+
* (#1751, #1754, #1816).
|
|
2586
|
+
*
|
|
2587
|
+
* Deferring is NOT enough, and the earlier belt that this one replaces was
|
|
2588
|
+
* built on a disproven premise: Node propagates an AsyncLocalStorage store into
|
|
2589
|
+
* `setImmediate`, into `node:timers`, into promise continuations, and into any
|
|
2590
|
+
* AsyncResource scoped to the current async id. Measured on Node 24:
|
|
2591
|
+
*
|
|
2592
|
+
* ```
|
|
2593
|
+
* als.run(true, () => setImmediate(() => als.getStore())) // -> true
|
|
2594
|
+
* ```
|
|
2595
|
+
*
|
|
2596
|
+
* What DOES start clean is an AsyncResource whose `triggerAsyncId` is not the
|
|
2597
|
+
* transaction. A resource created once at module scope - that is, before any
|
|
2598
|
+
* transaction existed - carries no store, and everything it schedules inherits
|
|
2599
|
+
* that emptiness rather than the caller's mark:
|
|
2600
|
+
*
|
|
2601
|
+
* ```
|
|
2602
|
+
* const detached = new AsyncResource('...') // module scope
|
|
2603
|
+
* als.run(true, () => detached.runInAsyncScope(() => setImmediate(() => als.getStore())))
|
|
2604
|
+
* // -> undefined
|
|
2605
|
+
* ```
|
|
2606
|
+
*
|
|
2607
|
+
* @module dsh-web-shared/host/detached-work
|
|
2608
|
+
*/
|
|
2609
|
+
/**
|
|
2610
|
+
* The escape hatch, created at module scope on purpose: a resource built while
|
|
2611
|
+
* a transaction is running would capture that transaction, so this single
|
|
2612
|
+
* instance is the only one the module ever needs. It carries no context of its
|
|
2613
|
+
* own, so every job run through it starts from the process's root context.
|
|
2614
|
+
*/
|
|
2615
|
+
const DETACHED = new AsyncResource("dsh-web:detached-work", { triggerAsyncId: 0 });
|
|
2616
|
+
/**
|
|
2617
|
+
* Run `work` outside the caller's AsyncLocalStorage context.
|
|
2618
|
+
*
|
|
2619
|
+
* The call itself is synchronous - this schedules, it does not defer. Work that
|
|
2620
|
+
* must not block the caller should schedule its own `setImmediate` inside
|
|
2621
|
+
* `work`, which then also starts clean because it inherits this resource's
|
|
2622
|
+
* empty context rather than the caller's.
|
|
2623
|
+
*
|
|
2624
|
+
* @param work - the side effect to detach from the caller's async context.
|
|
2625
|
+
* @returns whatever `work` returns.
|
|
2626
|
+
*/
|
|
2627
|
+
function runDetached(work) {
|
|
2628
|
+
return DETACHED.runInAsyncScope(work);
|
|
2629
|
+
}
|
|
2630
|
+
/** How long the helper waits for this process to disappear before giving up on the wait. */
|
|
2631
|
+
const RESTART_WAIT_MS = 3e4;
|
|
2632
|
+
/** Exit/interpreter arguments a relaunch must not repeat (they re-bind fixed ports). */
|
|
2633
|
+
function isReusableExecArg(argument) {
|
|
2634
|
+
return !/^--(?:inspect|inspect-brk|inspect-port|debug|debug-brk)(?:=|$)/.test(argument);
|
|
2635
|
+
}
|
|
2636
|
+
/**
|
|
2637
|
+
* Decide how a restart request is carried out.
|
|
2638
|
+
* @param facts - the running process's launch facts.
|
|
2639
|
+
* @returns the planned mode, with the relaunch command when one is used.
|
|
2640
|
+
*/
|
|
2641
|
+
function planRestart(facts) {
|
|
2642
|
+
if (facts.desktop === true || facts.env.ELECTRON_RUN_AS_NODE === "1") return { mode: "shell" };
|
|
2643
|
+
if (!facts.interactive) return { mode: "manual" };
|
|
2644
|
+
const script = facts.argv[0];
|
|
2645
|
+
if (script === void 0 || script === "") return { mode: "manual" };
|
|
2646
|
+
return {
|
|
2647
|
+
mode: "relaunch",
|
|
2648
|
+
command: {
|
|
2649
|
+
execPath: facts.execPath,
|
|
2650
|
+
argv: [
|
|
2651
|
+
...(facts.execArgv ?? []).filter(isReusableExecArg),
|
|
2652
|
+
script,
|
|
2653
|
+
...facts.argv.slice(1)
|
|
2654
|
+
],
|
|
2655
|
+
cwd: facts.cwd,
|
|
2656
|
+
env: facts.env
|
|
2657
|
+
}
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
/** Absolute path of the relaunch journal this plugin appends to. */
|
|
2661
|
+
function restartLogPath(home = dshHome()) {
|
|
2662
|
+
return join(home, "logs", "plugin-manager-restart.log");
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* The detached helper. It is passed as `node -e <source> <job-json>`, so it
|
|
2666
|
+
* must stay dependency-free and single-file; the job carries no environment
|
|
2667
|
+
* (the child inherits this helper's own).
|
|
2668
|
+
*/
|
|
2669
|
+
const RELAUNCH_HELPER = `
|
|
2670
|
+
const fs = require('node:fs');
|
|
2671
|
+
const cp = require('node:child_process');
|
|
2672
|
+
const job = JSON.parse(process.argv[1]);
|
|
2673
|
+
fs.mkdirSync(job.logDir, { recursive: true });
|
|
2674
|
+
const log = (line) => { try { fs.appendFileSync(job.logPath, new Date().toISOString() + ' ' + line + '\\n'); } catch {} };
|
|
2675
|
+
const fd = fs.openSync(job.logPath, 'a');
|
|
2676
|
+
const alive = (pid) => { try { process.kill(pid, 0); return true; } catch { return false; } };
|
|
2677
|
+
const launch = (attempt) => {
|
|
2678
|
+
if (attempt > 0) log('relaunch attempt ' + (attempt + 1));
|
|
2679
|
+
const child = cp.spawn(job.execPath, job.argv, { cwd: job.cwd, env: process.env, detached: true, stdio: ['ignore', fd, fd] });
|
|
2680
|
+
child.unref();
|
|
2681
|
+
let code = null;
|
|
2682
|
+
child.on('exit', (value) => { code = value; });
|
|
2683
|
+
setTimeout(() => {
|
|
2684
|
+
if (code === null) { log('relaunch started (pid ' + child.pid + ')'); fs.closeSync(fd); return; }
|
|
2685
|
+
if (attempt < 4) { log('relaunch exited with ' + code + '; retrying'); launch(attempt + 1); return; }
|
|
2686
|
+
log('relaunch gave up after exit ' + code);
|
|
2687
|
+
fs.closeSync(fd);
|
|
2688
|
+
}, 3000);
|
|
2689
|
+
};
|
|
2690
|
+
const waitFor = (deadline) => {
|
|
2691
|
+
if (!alive(job.parentPid) || Date.now() >= deadline) { setTimeout(() => launch(0), 300); return; }
|
|
2692
|
+
setTimeout(() => waitFor(deadline), 200);
|
|
2693
|
+
};
|
|
2694
|
+
waitFor(Date.now() + job.waitMs);
|
|
2695
|
+
`;
|
|
2696
|
+
/**
|
|
2697
|
+
* Start the detached relaunch helper.
|
|
2698
|
+
* @param command - the command line the replacement runs.
|
|
2699
|
+
* @param logPath - journal the helper (and the replacement's output) appends to.
|
|
2700
|
+
* @returns true when a helper process was actually created.
|
|
2701
|
+
*/
|
|
2702
|
+
function startRelaunchHelper(command, logPath = restartLogPath()) {
|
|
2703
|
+
const job = {
|
|
2704
|
+
parentPid: process.pid,
|
|
2705
|
+
execPath: command.execPath,
|
|
2706
|
+
argv: command.argv,
|
|
2707
|
+
cwd: command.cwd,
|
|
2708
|
+
logDir: dirname(logPath),
|
|
2709
|
+
logPath,
|
|
2710
|
+
waitMs: RESTART_WAIT_MS
|
|
2711
|
+
};
|
|
2712
|
+
try {
|
|
2713
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
2714
|
+
const helper = spawn(command.execPath, [
|
|
2715
|
+
"-e",
|
|
2716
|
+
RELAUNCH_HELPER,
|
|
2717
|
+
JSON.stringify(job)
|
|
2718
|
+
], {
|
|
2719
|
+
cwd: command.cwd,
|
|
2720
|
+
env: command.env,
|
|
2721
|
+
detached: true,
|
|
2722
|
+
stdio: "ignore"
|
|
2723
|
+
});
|
|
2724
|
+
helper.unref();
|
|
2725
|
+
return helper.pid !== void 0;
|
|
2726
|
+
} catch (error) {
|
|
2727
|
+
try {
|
|
2728
|
+
appendFileSync(logPath, `${(/* @__PURE__ */ new Date()).toISOString()} helper failed: ${String(error)}\n`);
|
|
2729
|
+
} catch {}
|
|
2730
|
+
return false;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Carry out one restart plan.
|
|
2735
|
+
* @param plan - the verdict from {@link planRestart}.
|
|
2736
|
+
* @param runtime - effect seams; the defaults spawn the helper and exit.
|
|
2737
|
+
* @returns the mode actually used: 'relaunch' degrades to 'manual' when the
|
|
2738
|
+
* helper could not be started, so a process that cannot be replaced stays up.
|
|
2739
|
+
*/
|
|
2740
|
+
function performRestart(plan, runtime = {}) {
|
|
2741
|
+
if (plan.mode === "manual") return "manual";
|
|
2742
|
+
const startHelper = runtime.startHelper ?? ((command) => startRelaunchHelper(command));
|
|
2743
|
+
const schedule = runtime.schedule ?? ((run, delayMs) => {
|
|
2744
|
+
setTimeout(run, delayMs);
|
|
2745
|
+
});
|
|
2746
|
+
const exit = runtime.exit ?? (() => {
|
|
2747
|
+
process.exit(0);
|
|
2748
|
+
});
|
|
2749
|
+
if (plan.mode === "relaunch") {
|
|
2750
|
+
if (plan.command === void 0 || !startHelper(plan.command)) return "manual";
|
|
2751
|
+
}
|
|
2752
|
+
schedule(exit, 400);
|
|
2753
|
+
return plan.mode;
|
|
2754
|
+
}
|
|
2755
|
+
//#endregion
|
|
2483
2756
|
//#region src/host/routes.ts
|
|
2484
2757
|
/** Route prefix the browser half mirrors. */
|
|
2485
2758
|
const GATEWAY_PREFIX = "/api/plugin-manager";
|
|
@@ -2521,11 +2794,34 @@ async function fetchRegistryManifest(name) {
|
|
|
2521
2794
|
};
|
|
2522
2795
|
}
|
|
2523
2796
|
/**
|
|
2524
|
-
* Read the running DSH host version
|
|
2525
|
-
*
|
|
2526
|
-
*
|
|
2527
|
-
*
|
|
2528
|
-
*
|
|
2797
|
+
* Read the running DSH host version out of the installation's own manifest.
|
|
2798
|
+
*
|
|
2799
|
+
* The launcher publishes the `@deepseek-ai/dsh` package.json it booted from on
|
|
2800
|
+
* `profileContext.installAnchor`; that manifest's `version` is by construction
|
|
2801
|
+
* the version of the DSH this host is running. It is the primary source because
|
|
2802
|
+
* it is the only one a packaged Desktop install can answer: there the CLI is not
|
|
2803
|
+
* on PATH, every `.bin` shim is stripped from the installer, and the private
|
|
2804
|
+
* host package ships no `lib/bin.js` to run (issue #1819). A runtime that
|
|
2805
|
+
* publishes no anchor (or one whose manifest cannot be read) falls through to
|
|
2806
|
+
* {@link probeDshVersion}.
|
|
2807
|
+
* @param installAnchor - the published anchor path, when there is one.
|
|
2808
|
+
* @returns the running version, or undefined when it cannot be read.
|
|
2809
|
+
*/
|
|
2810
|
+
function readInstalledDshVersion(installAnchor) {
|
|
2811
|
+
if (installAnchor === void 0) return void 0;
|
|
2812
|
+
return readManifestVersion(installAnchor);
|
|
2813
|
+
}
|
|
2814
|
+
/**
|
|
2815
|
+
* Read the running DSH host version through `dsh --version`.
|
|
2816
|
+
*
|
|
2817
|
+
* This is the FALLBACK source, used only when the installation's own manifest
|
|
2818
|
+
* could not be read. It costs a subprocess and needs a CLI this host can reach,
|
|
2819
|
+
* which a packaged Desktop host cannot: the launcher puts only `node` on its
|
|
2820
|
+
* PATH, the installer strips every `node_modules/.bin`, and the private host
|
|
2821
|
+
* package ships no `lib/bin.js` (issue #1819). Returns undefined when the
|
|
2822
|
+
* binary is unavailable or the output is not a plain semver; callers treat an
|
|
2823
|
+
* unknown host version as a fail-closed verdict for declared requirements
|
|
2824
|
+
* (issue #754).
|
|
2529
2825
|
*/
|
|
2530
2826
|
async function probeDshVersion(cliAvailable) {
|
|
2531
2827
|
if (!cliAvailable()) return void 0;
|
|
@@ -2566,6 +2862,20 @@ function isDirectRegistrySpec(spec) {
|
|
|
2566
2862
|
return !/^(?:link:|file:|git:|github:|git\+|https?:\/\/|npm:|workspace:|catalog:)/.test(spec);
|
|
2567
2863
|
}
|
|
2568
2864
|
/**
|
|
2865
|
+
* The package name of a spec that names no version, or undefined when the
|
|
2866
|
+
* caller already chose one.
|
|
2867
|
+
*
|
|
2868
|
+
* A scoped name's `@` opens the scope, so only a `@` after the scope counts as
|
|
2869
|
+
* a version separator; every other separator form (`name@1.2.3`, `name@next`,
|
|
2870
|
+
* `name@^1`) yields undefined and is passed through untouched.
|
|
2871
|
+
* @param spec - the install spec the caller supplied.
|
|
2872
|
+
* @returns the bare package name when the spec is unversioned.
|
|
2873
|
+
*/
|
|
2874
|
+
function barePackageName(spec) {
|
|
2875
|
+
if (spec === "") return void 0;
|
|
2876
|
+
return (spec.startsWith("@") ? spec.indexOf("@", 1) : spec.indexOf("@")) < 0 ? spec : void 0;
|
|
2877
|
+
}
|
|
2878
|
+
/**
|
|
2569
2879
|
* Build the gateway routes.
|
|
2570
2880
|
* @param deps - profile facts, the CLI gateway, and seams.
|
|
2571
2881
|
* @returns the web-server routes to register.
|
|
@@ -2574,16 +2884,24 @@ function makeGatewayRoutes(deps) {
|
|
|
2574
2884
|
const { facts, gateway } = deps;
|
|
2575
2885
|
const fetchManifest = deps.fetchManifest ?? fetchRegistryManifest;
|
|
2576
2886
|
/**
|
|
2577
|
-
* Cached
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2580
|
-
*
|
|
2887
|
+
* Cached host version: successful verdicts refresh after a TTL (the CLI update
|
|
2888
|
+
* path is the gateway itself, so a stale success is wrong long-term), failed
|
|
2889
|
+
* probes are retried after a cooldown instead of being cached forever, and
|
|
2890
|
+
* concurrent requests share one in-flight probe.
|
|
2891
|
+
*
|
|
2892
|
+
* The running installation's own manifest is read first. That is a local file
|
|
2893
|
+
* read with no process to spawn and nothing to fall out of date mid-run, so it
|
|
2894
|
+
* is re-read per resolution and never cached: a packaged Desktop host, where
|
|
2895
|
+
* the CLI fallback is unreachable, would otherwise spend its first request on
|
|
2896
|
+
* a probe that cannot succeed.
|
|
2581
2897
|
*/
|
|
2582
2898
|
let dshVersion;
|
|
2583
2899
|
let dshVersionAt = 0;
|
|
2584
2900
|
let dshVersionPending;
|
|
2585
2901
|
const resolveDshVersion = () => {
|
|
2586
2902
|
if (deps.dshVersion !== void 0) return deps.dshVersion();
|
|
2903
|
+
const installed = readInstalledDshVersion(deps.installAnchor);
|
|
2904
|
+
if (installed !== void 0) return Promise.resolve(installed);
|
|
2587
2905
|
const now = Date.now();
|
|
2588
2906
|
if (dshVersion !== void 0 && now - dshVersionAt < VERSION_PROBE_TTL_MS) return Promise.resolve(dshVersion);
|
|
2589
2907
|
if (dshVersionAt !== 0 && now - dshVersionAt < VERSION_PROBE_COOLDOWN_MS) return Promise.resolve(void 0);
|
|
@@ -2651,7 +2969,21 @@ function makeGatewayRoutes(deps) {
|
|
|
2651
2969
|
writeJson(res, 500, { error: "plugin-manager: dsh CLI not found on PATH" });
|
|
2652
2970
|
return;
|
|
2653
2971
|
}
|
|
2654
|
-
|
|
2972
|
+
let installSpec = spec.trim();
|
|
2973
|
+
const name = barePackageName(installSpec);
|
|
2974
|
+
if (name !== void 0 && isDirectRegistrySpec(installSpec)) {
|
|
2975
|
+
const manifest = await fetchManifest(name).catch(() => void 0);
|
|
2976
|
+
if (manifest?.version !== void 0 && manifest.version !== "") {
|
|
2977
|
+
const pinned = `${name}@${manifest.version}`;
|
|
2978
|
+
const unsafePinned = unsafeSpecReason(pinned);
|
|
2979
|
+
if (unsafePinned !== void 0) {
|
|
2980
|
+
writeJson(res, 400, { error: unsafePinned });
|
|
2981
|
+
return;
|
|
2982
|
+
}
|
|
2983
|
+
installSpec = pinned;
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
writeJson(res, 200, gateway.install(installSpec));
|
|
2655
2987
|
};
|
|
2656
2988
|
const updateHandler = async (req, res) => {
|
|
2657
2989
|
const id = (await readJsonBody(req, {
|
|
@@ -2701,7 +3033,7 @@ function makeGatewayRoutes(deps) {
|
|
|
2701
3033
|
const { hostVersion, compatible } = await compatibleVerdict(requiresDsh);
|
|
2702
3034
|
if (!compatible) return {
|
|
2703
3035
|
status: 412,
|
|
2704
|
-
error: hostVersion === void 0 ? `plugin-manager: cannot verify the DSH version for ${migration.to}
|
|
3036
|
+
error: hostVersion === void 0 ? `plugin-manager: cannot verify the running DSH version for ${migration.to}; check the DSH runtime before migrating` : `plugin-manager: ${migration.to} requires DSH ${requiresDsh} (current DSH ${hostVersion}); upgrade DSH before migrating`
|
|
2705
3037
|
};
|
|
2706
3038
|
}
|
|
2707
3039
|
return {
|
|
@@ -2737,7 +3069,7 @@ function makeGatewayRoutes(deps) {
|
|
|
2737
3069
|
const { hostVersion, compatible } = await compatibleVerdict(requiresDsh);
|
|
2738
3070
|
if (!compatible) return {
|
|
2739
3071
|
status: 412,
|
|
2740
|
-
error: hostVersion === void 0 ? `plugin-manager: cannot verify the DSH version for ${target}
|
|
3072
|
+
error: hostVersion === void 0 ? `plugin-manager: cannot verify the running DSH version for ${target}; check the DSH runtime before updating` : `plugin-manager: ${target} requires DSH ${requiresDsh} (current DSH ${hostVersion}); upgrade DSH before updating`
|
|
2741
3073
|
};
|
|
2742
3074
|
}
|
|
2743
3075
|
return {
|
|
@@ -2819,7 +3151,11 @@ function makeGatewayRoutes(deps) {
|
|
|
2819
3151
|
const entryEnabled = enabled || LOCKED_ENTRY_IDS.has(entry.id);
|
|
2820
3152
|
next = setRowEnabled(next, facts.patchPath, entry.id, entry.name, entryEnabled, entry.baseEnabled);
|
|
2821
3153
|
}
|
|
2822
|
-
if (next !== patchText) await
|
|
3154
|
+
if (next !== patchText) await runDetached(() => new Promise((resolve, reject) => {
|
|
3155
|
+
setImmediate(() => {
|
|
3156
|
+
writePatchAtomic(facts.patchPath, next).then(resolve, reject);
|
|
3157
|
+
});
|
|
3158
|
+
}));
|
|
2823
3159
|
const plugin = (await snapshotGateway(facts, next)).plugins.find((item) => item.id === ownerName);
|
|
2824
3160
|
return plugin === void 0 ? { error: `plugin-manager: plugin ${ownerName} is not installed` } : { plugin };
|
|
2825
3161
|
});
|
|
@@ -2867,7 +3203,9 @@ function makeGatewayRoutes(deps) {
|
|
|
2867
3203
|
const requiresDsh = dshRequirementOf(targetManifest);
|
|
2868
3204
|
if (requiresDsh !== void 0) {
|
|
2869
3205
|
update.requiresDsh = requiresDsh;
|
|
2870
|
-
|
|
3206
|
+
const verdict = await compatibleVerdict(requiresDsh);
|
|
3207
|
+
update.compatible = verdict.compatible;
|
|
3208
|
+
if (verdict.hostVersion !== void 0) update.hostVersion = verdict.hostVersion;
|
|
2871
3209
|
}
|
|
2872
3210
|
updates.push(update);
|
|
2873
3211
|
continue;
|
|
@@ -2883,12 +3221,46 @@ function makeGatewayRoutes(deps) {
|
|
|
2883
3221
|
const requiresDsh = dshRequirementOf(manifest);
|
|
2884
3222
|
if (requiresDsh !== void 0) {
|
|
2885
3223
|
update.requiresDsh = requiresDsh;
|
|
2886
|
-
|
|
3224
|
+
const verdict = await compatibleVerdict(requiresDsh);
|
|
3225
|
+
update.compatible = verdict.compatible;
|
|
3226
|
+
if (verdict.hostVersion !== void 0) update.hostVersion = verdict.hostVersion;
|
|
2887
3227
|
}
|
|
2888
3228
|
updates.push(update);
|
|
2889
3229
|
}
|
|
2890
3230
|
writeJson(res, 200, { updates });
|
|
2891
3231
|
};
|
|
3232
|
+
/**
|
|
3233
|
+
* The running process's own launch facts, read once per request: the desktop
|
|
3234
|
+
* verdict comes from the profile facts (packaged Desktop launcher), the rest
|
|
3235
|
+
* from this process.
|
|
3236
|
+
*/
|
|
3237
|
+
const liveRestartFacts = () => ({
|
|
3238
|
+
desktop: facts.desktop,
|
|
3239
|
+
env: process.env,
|
|
3240
|
+
execPath: process.execPath,
|
|
3241
|
+
argv: process.argv.slice(1),
|
|
3242
|
+
execArgv: process.execArgv,
|
|
3243
|
+
cwd: process.cwd(),
|
|
3244
|
+
interactive: process.stdin.isTTY === true || process.stdout.isTTY === true
|
|
3245
|
+
});
|
|
3246
|
+
/**
|
|
3247
|
+
* Restart the host so an applied plugin update is loaded. The route answers
|
|
3248
|
+
* with the mode it actually used (see host/restart.ts): 'relaunch' when this
|
|
3249
|
+
* process re-executes itself, 'shell' when the packaged Desktop shell owns
|
|
3250
|
+
* the process tree and runs its own restart, 'manual' when neither is safe.
|
|
3251
|
+
*/
|
|
3252
|
+
const restartHandler = async (req, res) => {
|
|
3253
|
+
const plan = planRestart((deps.restartFacts ?? liveRestartFacts)());
|
|
3254
|
+
if (req.method === "GET" || req.method === "HEAD") {
|
|
3255
|
+
writeJson(res, 200, { restart: { mode: plan.mode } });
|
|
3256
|
+
return;
|
|
3257
|
+
}
|
|
3258
|
+
if (req.method !== "POST") {
|
|
3259
|
+
writeJson(res, 405, { error: "plugin-manager: restart needs GET (plan) or POST (execute)" });
|
|
3260
|
+
return;
|
|
3261
|
+
}
|
|
3262
|
+
writeJson(res, 202, { restart: { mode: performRestart(plan, deps.restartRuntime ?? {}) } });
|
|
3263
|
+
};
|
|
2892
3264
|
return [
|
|
2893
3265
|
{
|
|
2894
3266
|
kind: "exact",
|
|
@@ -2934,13 +3306,23 @@ function makeGatewayRoutes(deps) {
|
|
|
2934
3306
|
kind: "exact",
|
|
2935
3307
|
path: `${GATEWAY_PREFIX}/check-updates`,
|
|
2936
3308
|
handler: guard(checkUpdatesHandler)
|
|
3309
|
+
},
|
|
3310
|
+
{
|
|
3311
|
+
kind: "exact",
|
|
3312
|
+
path: `${GATEWAY_PREFIX}/restart`,
|
|
3313
|
+
handler: guard(restartHandler)
|
|
2937
3314
|
}
|
|
2938
3315
|
];
|
|
2939
3316
|
}
|
|
2940
3317
|
//#endregion
|
|
2941
3318
|
//#region src/index.ts
|
|
2942
|
-
/**
|
|
2943
|
-
|
|
3319
|
+
/**
|
|
3320
|
+
* Stable cordis plugin name (matches this package's own cordis.patch.yml
|
|
3321
|
+
* insert id). It must not repeat an id another bundle already claims: the
|
|
3322
|
+
* loader keeps one entry per id, so a shared id would also give two host
|
|
3323
|
+
* halves one cordis plugin name.
|
|
3324
|
+
*/
|
|
3325
|
+
const name = "ui-plugin-manager-update-check";
|
|
2944
3326
|
/** Services the gateway needs — the web server seam. */
|
|
2945
3327
|
const inject = ["webServer"];
|
|
2946
3328
|
/** Apply the host half (once per process). */
|
|
@@ -2978,8 +3360,9 @@ function officialManager(ctx) {
|
|
|
2978
3360
|
}
|
|
2979
3361
|
function applyImpl(ctx) {
|
|
2980
3362
|
let facts;
|
|
3363
|
+
const launched = launchedProfile(ctx);
|
|
2981
3364
|
try {
|
|
2982
|
-
facts = resolveProfile(process.argv, process.env,
|
|
3365
|
+
facts = resolveProfile(process.argv, process.env, launched);
|
|
2983
3366
|
} catch (error) {
|
|
2984
3367
|
console.error("[plugin-manager]", error instanceof Error ? error.message : String(error));
|
|
2985
3368
|
return;
|
|
@@ -2987,11 +3370,13 @@ function applyImpl(ctx) {
|
|
|
2987
3370
|
if (!profileExists(facts.profileDir)) return;
|
|
2988
3371
|
const gateway = new CliGateway(facts, process.env, { nativeManager: () => officialManager(ctx) });
|
|
2989
3372
|
const cliAvailable = () => findDshBinary() !== null;
|
|
3373
|
+
const installAnchor = launchedInstallAnchor(launched);
|
|
2990
3374
|
ctx.effect(() => {
|
|
2991
3375
|
const disposers = makeGatewayRoutes({
|
|
2992
3376
|
facts,
|
|
2993
3377
|
gateway,
|
|
2994
|
-
cliAvailable
|
|
3378
|
+
cliAvailable,
|
|
3379
|
+
installAnchor
|
|
2995
3380
|
}).map((route) => ctx.webServer.register(route));
|
|
2996
3381
|
return () => {
|
|
2997
3382
|
for (const dispose of disposers) dispose();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The list-level toolbar: check every installed third-party plugin for a newer
|
|
3
|
+
* registry release, apply them in one run, then restart DSH to load them.
|
|
4
|
+
*
|
|
5
|
+
* It exists because the official Plugins page compares one package at a time
|
|
6
|
+
* (its `plugins.detail.section` contributions render on a bundle's page), while
|
|
7
|
+
* the answer a user wants when they open the page is "is anything of mine out
|
|
8
|
+
* of date, and can I just fix it". It is mounted beside the page's "Installed"
|
|
9
|
+
* heading (see plugin-toolbar-mount.tsx) because that heading is the page's own
|
|
10
|
+
* chrome and the page declares no seat next to it.
|
|
11
|
+
*
|
|
12
|
+
* Policy lives in core/updates.ts (third-party only, compatibility-gated) and
|
|
13
|
+
* the operations come from the injected face, so this component is pure
|
|
14
|
+
* rendering plus the sequence of calls: nothing here touches the DOM beyond its
|
|
15
|
+
* own subtree.
|
|
16
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/client
|
|
17
|
+
*/
|
|
18
|
+
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
19
|
+
import type { PluginUpdateItem, RestartMode } from '../core/protocol.ts';
|
|
20
|
+
/** The operations the toolbar drives (the package's dual-channel face). */
|
|
21
|
+
export interface PluginListToolbarInjected {
|
|
22
|
+
/** Whether this browser has loopback authority to use the host routes. */
|
|
23
|
+
isLoopback: boolean;
|
|
24
|
+
/** Compare every installed plugin against the version its source serves. */
|
|
25
|
+
checkUpdates: () => Promise<PluginUpdateItem[]>;
|
|
26
|
+
/** Re-install one plugin from its recorded source. */
|
|
27
|
+
update: (id: string) => Promise<unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Read how a restart would be carried out, without carrying it out: the
|
|
30
|
+
* confirmation must name the same consequence the host will produce (an
|
|
31
|
+
* in-place relaunch, the packaged Desktop shell's own recovery dialog, or a
|
|
32
|
+
* manual restart), and a plan read has no side effects.
|
|
33
|
+
*/
|
|
34
|
+
restartPlan: () => Promise<RestartMode>;
|
|
35
|
+
/** Restart the host so an applied update is loaded. */
|
|
36
|
+
restart: () => Promise<RestartMode>;
|
|
37
|
+
}
|
|
38
|
+
/** Full component props. */
|
|
39
|
+
export type PluginListToolbarProps = PropsLocale<'settings.pluginManager'> & PluginListToolbarInjected;
|
|
40
|
+
/**
|
|
41
|
+
* The toolbar itself. All state is local: the page around it owns the plugin
|
|
42
|
+
* list, and a restart tears this component down anyway.
|
|
43
|
+
*/
|
|
44
|
+
export declare function PluginListToolbar(props: PluginListToolbarProps): import("react").JSX.Element;
|