@linxin666/dsh-client-ui-plugin-manager 0.4.4 → 0.4.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/README.i18n.yaml +2 -2
- package/README.md +18 -4
- package/README.zh.md +18 -4
- package/cordis.patch.yml +14 -1
- package/lib/client.js +569 -10
- package/lib/client.js.map +1 -1
- package/lib/index.js +212 -8
- 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 +54 -2
- package/lib/types/client/plugin-toolbar-mount.d.ts +47 -0
- package/lib/types/core/protocol.d.ts +13 -0
- package/lib/types/core/updates.d.ts +30 -0
- package/lib/types/core/version.d.ts +4 -1
- package/lib/types/host/restart.d.ts +95 -0
- package/lib/types/host/routes.d.ts +5 -0
- package/lib/types/host/state.d.ts +3 -1
- package/lib/types/index.d.ts +7 -2
- package/package.json +13 -13
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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";
|
|
@@ -545,6 +545,10 @@ function resolveDshHome(env = process.env, home = homedir()) {
|
|
|
545
545
|
}
|
|
546
546
|
return j(home, ".dsh");
|
|
547
547
|
}
|
|
548
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
549
|
+
function dshHome() {
|
|
550
|
+
return resolveDshHome();
|
|
551
|
+
}
|
|
548
552
|
//#endregion
|
|
549
553
|
//#region src/host/profile.ts
|
|
550
554
|
/**
|
|
@@ -807,10 +811,12 @@ function profileExists(profileDir) {
|
|
|
807
811
|
* itself (the UI performing the write), the family settings surface the tab
|
|
808
812
|
* injects into, and the aggregate compat face (disabling it unmounts the
|
|
809
813
|
* whole folded client bundle while host rows keep running — a half-dead
|
|
810
|
-
* page). Covers both the standalone and the aggregate row ids.
|
|
814
|
+
* page). Covers both the standalone and the aggregate row ids. The standalone
|
|
815
|
+
* id is this package's own `cordis.patch.yml` insert id, never the official
|
|
816
|
+
* `ui-plugin-manager` row the DSH web-app bundle already claims.
|
|
811
817
|
*/
|
|
812
818
|
const LOCKED_ENTRY_IDS = /* @__PURE__ */ new Set([
|
|
813
|
-
"ui-plugin-manager",
|
|
819
|
+
"ui-plugin-manager-update-check",
|
|
814
820
|
"web-ui-plugin-manager",
|
|
815
821
|
"ui-web-ui-settings",
|
|
816
822
|
"web-ui-settings",
|
|
@@ -2421,7 +2427,9 @@ function meetsMinimumDsh(host, minimum) {
|
|
|
2421
2427
|
}
|
|
2422
2428
|
/**
|
|
2423
2429
|
* Read the declared DSH minimum from a published registry manifest:
|
|
2424
|
-
* `dsh.engines.dsh` first, top-level `engines.dsh`
|
|
2430
|
+
* `dsh.engines.dsh` first, top-level `engines.dsh` next, and
|
|
2431
|
+
* `peerDependencies["@deepseek-ai/dsh"]` last, which is where a package that
|
|
2432
|
+
* only declares the host as a peer still gets gated at boot.
|
|
2425
2433
|
* Defensive against malformed or untrusted metadata: anything that is not a
|
|
2426
2434
|
* non-empty string reads as absent.
|
|
2427
2435
|
* @param manifest - the decoded registry version manifest.
|
|
@@ -2430,7 +2438,8 @@ function meetsMinimumDsh(host, minimum) {
|
|
|
2430
2438
|
function dshRequirementOf(manifest) {
|
|
2431
2439
|
const dshEngines = manifest.dsh?.engines;
|
|
2432
2440
|
const engines = manifest.engines?.dsh;
|
|
2433
|
-
const
|
|
2441
|
+
const peers = manifest.peerDependencies?.["@deepseek-ai/dsh"];
|
|
2442
|
+
const value = dshEngines?.dsh ?? engines ?? peers;
|
|
2434
2443
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
2435
2444
|
}
|
|
2436
2445
|
//#endregion
|
|
@@ -2479,6 +2488,131 @@ function targetSpecForLegacy(sourceSpec, familyVersion) {
|
|
|
2479
2488
|
if (familyVersion === "") return void 0;
|
|
2480
2489
|
return `${CURRENT_AGGREGATE}@${familyVersion}`;
|
|
2481
2490
|
}
|
|
2491
|
+
/** How long the helper waits for this process to disappear before giving up on the wait. */
|
|
2492
|
+
const RESTART_WAIT_MS = 3e4;
|
|
2493
|
+
/** Exit/interpreter arguments a relaunch must not repeat (they re-bind fixed ports). */
|
|
2494
|
+
function isReusableExecArg(argument) {
|
|
2495
|
+
return !/^--(?:inspect|inspect-brk|inspect-port|debug|debug-brk)(?:=|$)/.test(argument);
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Decide how a restart request is carried out.
|
|
2499
|
+
* @param facts - the running process's launch facts.
|
|
2500
|
+
* @returns the planned mode, with the relaunch command when one is used.
|
|
2501
|
+
*/
|
|
2502
|
+
function planRestart(facts) {
|
|
2503
|
+
if (facts.desktop === true || facts.env.ELECTRON_RUN_AS_NODE === "1") return { mode: "shell" };
|
|
2504
|
+
if (!facts.interactive) return { mode: "manual" };
|
|
2505
|
+
const script = facts.argv[0];
|
|
2506
|
+
if (script === void 0 || script === "") return { mode: "manual" };
|
|
2507
|
+
return {
|
|
2508
|
+
mode: "relaunch",
|
|
2509
|
+
command: {
|
|
2510
|
+
execPath: facts.execPath,
|
|
2511
|
+
argv: [
|
|
2512
|
+
...(facts.execArgv ?? []).filter(isReusableExecArg),
|
|
2513
|
+
script,
|
|
2514
|
+
...facts.argv.slice(1)
|
|
2515
|
+
],
|
|
2516
|
+
cwd: facts.cwd,
|
|
2517
|
+
env: facts.env
|
|
2518
|
+
}
|
|
2519
|
+
};
|
|
2520
|
+
}
|
|
2521
|
+
/** Absolute path of the relaunch journal this plugin appends to. */
|
|
2522
|
+
function restartLogPath(home = dshHome()) {
|
|
2523
|
+
return join(home, "logs", "plugin-manager-restart.log");
|
|
2524
|
+
}
|
|
2525
|
+
/**
|
|
2526
|
+
* The detached helper. It is passed as `node -e <source> <job-json>`, so it
|
|
2527
|
+
* must stay dependency-free and single-file; the job carries no environment
|
|
2528
|
+
* (the child inherits this helper's own).
|
|
2529
|
+
*/
|
|
2530
|
+
const RELAUNCH_HELPER = `
|
|
2531
|
+
const fs = require('node:fs');
|
|
2532
|
+
const cp = require('node:child_process');
|
|
2533
|
+
const job = JSON.parse(process.argv[1]);
|
|
2534
|
+
fs.mkdirSync(job.logDir, { recursive: true });
|
|
2535
|
+
const log = (line) => { try { fs.appendFileSync(job.logPath, new Date().toISOString() + ' ' + line + '\\n'); } catch {} };
|
|
2536
|
+
const fd = fs.openSync(job.logPath, 'a');
|
|
2537
|
+
const alive = (pid) => { try { process.kill(pid, 0); return true; } catch { return false; } };
|
|
2538
|
+
const launch = (attempt) => {
|
|
2539
|
+
if (attempt > 0) log('relaunch attempt ' + (attempt + 1));
|
|
2540
|
+
const child = cp.spawn(job.execPath, job.argv, { cwd: job.cwd, env: process.env, detached: true, stdio: ['ignore', fd, fd] });
|
|
2541
|
+
child.unref();
|
|
2542
|
+
let code = null;
|
|
2543
|
+
child.on('exit', (value) => { code = value; });
|
|
2544
|
+
setTimeout(() => {
|
|
2545
|
+
if (code === null) { log('relaunch started (pid ' + child.pid + ')'); fs.closeSync(fd); return; }
|
|
2546
|
+
if (attempt < 4) { log('relaunch exited with ' + code + '; retrying'); launch(attempt + 1); return; }
|
|
2547
|
+
log('relaunch gave up after exit ' + code);
|
|
2548
|
+
fs.closeSync(fd);
|
|
2549
|
+
}, 3000);
|
|
2550
|
+
};
|
|
2551
|
+
const waitFor = (deadline) => {
|
|
2552
|
+
if (!alive(job.parentPid) || Date.now() >= deadline) { setTimeout(() => launch(0), 300); return; }
|
|
2553
|
+
setTimeout(() => waitFor(deadline), 200);
|
|
2554
|
+
};
|
|
2555
|
+
waitFor(Date.now() + job.waitMs);
|
|
2556
|
+
`;
|
|
2557
|
+
/**
|
|
2558
|
+
* Start the detached relaunch helper.
|
|
2559
|
+
* @param command - the command line the replacement runs.
|
|
2560
|
+
* @param logPath - journal the helper (and the replacement's output) appends to.
|
|
2561
|
+
* @returns true when a helper process was actually created.
|
|
2562
|
+
*/
|
|
2563
|
+
function startRelaunchHelper(command, logPath = restartLogPath()) {
|
|
2564
|
+
const job = {
|
|
2565
|
+
parentPid: process.pid,
|
|
2566
|
+
execPath: command.execPath,
|
|
2567
|
+
argv: command.argv,
|
|
2568
|
+
cwd: command.cwd,
|
|
2569
|
+
logDir: dirname(logPath),
|
|
2570
|
+
logPath,
|
|
2571
|
+
waitMs: RESTART_WAIT_MS
|
|
2572
|
+
};
|
|
2573
|
+
try {
|
|
2574
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
2575
|
+
const helper = spawn(command.execPath, [
|
|
2576
|
+
"-e",
|
|
2577
|
+
RELAUNCH_HELPER,
|
|
2578
|
+
JSON.stringify(job)
|
|
2579
|
+
], {
|
|
2580
|
+
cwd: command.cwd,
|
|
2581
|
+
env: command.env,
|
|
2582
|
+
detached: true,
|
|
2583
|
+
stdio: "ignore"
|
|
2584
|
+
});
|
|
2585
|
+
helper.unref();
|
|
2586
|
+
return helper.pid !== void 0;
|
|
2587
|
+
} catch (error) {
|
|
2588
|
+
try {
|
|
2589
|
+
appendFileSync(logPath, `${(/* @__PURE__ */ new Date()).toISOString()} helper failed: ${String(error)}\n`);
|
|
2590
|
+
} catch {}
|
|
2591
|
+
return false;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Carry out one restart plan.
|
|
2596
|
+
* @param plan - the verdict from {@link planRestart}.
|
|
2597
|
+
* @param runtime - effect seams; the defaults spawn the helper and exit.
|
|
2598
|
+
* @returns the mode actually used: 'relaunch' degrades to 'manual' when the
|
|
2599
|
+
* helper could not be started, so a process that cannot be replaced stays up.
|
|
2600
|
+
*/
|
|
2601
|
+
function performRestart(plan, runtime = {}) {
|
|
2602
|
+
if (plan.mode === "manual") return "manual";
|
|
2603
|
+
const startHelper = runtime.startHelper ?? ((command) => startRelaunchHelper(command));
|
|
2604
|
+
const schedule = runtime.schedule ?? ((run, delayMs) => {
|
|
2605
|
+
setTimeout(run, delayMs);
|
|
2606
|
+
});
|
|
2607
|
+
const exit = runtime.exit ?? (() => {
|
|
2608
|
+
process.exit(0);
|
|
2609
|
+
});
|
|
2610
|
+
if (plan.mode === "relaunch") {
|
|
2611
|
+
if (plan.command === void 0 || !startHelper(plan.command)) return "manual";
|
|
2612
|
+
}
|
|
2613
|
+
schedule(exit, 400);
|
|
2614
|
+
return plan.mode;
|
|
2615
|
+
}
|
|
2482
2616
|
//#endregion
|
|
2483
2617
|
//#region src/host/routes.ts
|
|
2484
2618
|
/** Route prefix the browser half mirrors. */
|
|
@@ -2566,6 +2700,20 @@ function isDirectRegistrySpec(spec) {
|
|
|
2566
2700
|
return !/^(?:link:|file:|git:|github:|git\+|https?:\/\/|npm:|workspace:|catalog:)/.test(spec);
|
|
2567
2701
|
}
|
|
2568
2702
|
/**
|
|
2703
|
+
* The package name of a spec that names no version, or undefined when the
|
|
2704
|
+
* caller already chose one.
|
|
2705
|
+
*
|
|
2706
|
+
* A scoped name's `@` opens the scope, so only a `@` after the scope counts as
|
|
2707
|
+
* a version separator; every other separator form (`name@1.2.3`, `name@next`,
|
|
2708
|
+
* `name@^1`) yields undefined and is passed through untouched.
|
|
2709
|
+
* @param spec - the install spec the caller supplied.
|
|
2710
|
+
* @returns the bare package name when the spec is unversioned.
|
|
2711
|
+
*/
|
|
2712
|
+
function barePackageName(spec) {
|
|
2713
|
+
if (spec === "") return void 0;
|
|
2714
|
+
return (spec.startsWith("@") ? spec.indexOf("@", 1) : spec.indexOf("@")) < 0 ? spec : void 0;
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2569
2717
|
* Build the gateway routes.
|
|
2570
2718
|
* @param deps - profile facts, the CLI gateway, and seams.
|
|
2571
2719
|
* @returns the web-server routes to register.
|
|
@@ -2651,7 +2799,21 @@ function makeGatewayRoutes(deps) {
|
|
|
2651
2799
|
writeJson(res, 500, { error: "plugin-manager: dsh CLI not found on PATH" });
|
|
2652
2800
|
return;
|
|
2653
2801
|
}
|
|
2654
|
-
|
|
2802
|
+
let installSpec = spec.trim();
|
|
2803
|
+
const name = barePackageName(installSpec);
|
|
2804
|
+
if (name !== void 0 && isDirectRegistrySpec(installSpec)) {
|
|
2805
|
+
const manifest = await fetchManifest(name).catch(() => void 0);
|
|
2806
|
+
if (manifest?.version !== void 0 && manifest.version !== "") {
|
|
2807
|
+
const pinned = `${name}@${manifest.version}`;
|
|
2808
|
+
const unsafePinned = unsafeSpecReason(pinned);
|
|
2809
|
+
if (unsafePinned !== void 0) {
|
|
2810
|
+
writeJson(res, 400, { error: unsafePinned });
|
|
2811
|
+
return;
|
|
2812
|
+
}
|
|
2813
|
+
installSpec = pinned;
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
writeJson(res, 200, gateway.install(installSpec));
|
|
2655
2817
|
};
|
|
2656
2818
|
const updateHandler = async (req, res) => {
|
|
2657
2819
|
const id = (await readJsonBody(req, {
|
|
@@ -2889,6 +3051,38 @@ function makeGatewayRoutes(deps) {
|
|
|
2889
3051
|
}
|
|
2890
3052
|
writeJson(res, 200, { updates });
|
|
2891
3053
|
};
|
|
3054
|
+
/**
|
|
3055
|
+
* The running process's own launch facts, read once per request: the desktop
|
|
3056
|
+
* verdict comes from the profile facts (packaged Desktop launcher), the rest
|
|
3057
|
+
* from this process.
|
|
3058
|
+
*/
|
|
3059
|
+
const liveRestartFacts = () => ({
|
|
3060
|
+
desktop: facts.desktop,
|
|
3061
|
+
env: process.env,
|
|
3062
|
+
execPath: process.execPath,
|
|
3063
|
+
argv: process.argv.slice(1),
|
|
3064
|
+
execArgv: process.execArgv,
|
|
3065
|
+
cwd: process.cwd(),
|
|
3066
|
+
interactive: process.stdin.isTTY === true || process.stdout.isTTY === true
|
|
3067
|
+
});
|
|
3068
|
+
/**
|
|
3069
|
+
* Restart the host so an applied plugin update is loaded. The route answers
|
|
3070
|
+
* with the mode it actually used (see host/restart.ts): 'relaunch' when this
|
|
3071
|
+
* process re-executes itself, 'shell' when the packaged Desktop shell owns
|
|
3072
|
+
* the process tree and runs its own restart, 'manual' when neither is safe.
|
|
3073
|
+
*/
|
|
3074
|
+
const restartHandler = async (req, res) => {
|
|
3075
|
+
const plan = planRestart((deps.restartFacts ?? liveRestartFacts)());
|
|
3076
|
+
if (req.method === "GET" || req.method === "HEAD") {
|
|
3077
|
+
writeJson(res, 200, { restart: { mode: plan.mode } });
|
|
3078
|
+
return;
|
|
3079
|
+
}
|
|
3080
|
+
if (req.method !== "POST") {
|
|
3081
|
+
writeJson(res, 405, { error: "plugin-manager: restart needs GET (plan) or POST (execute)" });
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
writeJson(res, 202, { restart: { mode: performRestart(plan, deps.restartRuntime ?? {}) } });
|
|
3085
|
+
};
|
|
2892
3086
|
return [
|
|
2893
3087
|
{
|
|
2894
3088
|
kind: "exact",
|
|
@@ -2934,13 +3128,23 @@ function makeGatewayRoutes(deps) {
|
|
|
2934
3128
|
kind: "exact",
|
|
2935
3129
|
path: `${GATEWAY_PREFIX}/check-updates`,
|
|
2936
3130
|
handler: guard(checkUpdatesHandler)
|
|
3131
|
+
},
|
|
3132
|
+
{
|
|
3133
|
+
kind: "exact",
|
|
3134
|
+
path: `${GATEWAY_PREFIX}/restart`,
|
|
3135
|
+
handler: guard(restartHandler)
|
|
2937
3136
|
}
|
|
2938
3137
|
];
|
|
2939
3138
|
}
|
|
2940
3139
|
//#endregion
|
|
2941
3140
|
//#region src/index.ts
|
|
2942
|
-
/**
|
|
2943
|
-
|
|
3141
|
+
/**
|
|
3142
|
+
* Stable cordis plugin name (matches this package's own cordis.patch.yml
|
|
3143
|
+
* insert id). It must not repeat an id another bundle already claims: the
|
|
3144
|
+
* loader keeps one entry per id, so a shared id would also give two host
|
|
3145
|
+
* halves one cordis plugin name.
|
|
3146
|
+
*/
|
|
3147
|
+
const name = "ui-plugin-manager-update-check";
|
|
2944
3148
|
/** Services the gateway needs — the web server seam. */
|
|
2945
3149
|
const inject = ["webServer"];
|
|
2946
3150
|
/** Apply the host half (once per process). */
|
|
@@ -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;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One `document.body` MutationObserver per page, shared by every family
|
|
3
|
+
* plugin bundle.
|
|
4
|
+
*
|
|
5
|
+
* Family plugins that inject at the DOM level must notice when the shell
|
|
6
|
+
* re-renders around their injected node: the aggregate shell's column shims
|
|
7
|
+
* and any plugin surface still extending the shell from outside the official
|
|
8
|
+
* slot seats. Each consumer used to install its OWN `MutationObserver` on
|
|
9
|
+
* `document.body` with
|
|
10
|
+
* `{ childList: true, subtree: true }`, so a page carrying N family plugins
|
|
11
|
+
* paid N native observers and N callback invocations for EVERY mutation batch
|
|
12
|
+
* the app produced — chat token streaming alone produces many per second, and
|
|
13
|
+
* the count grows with the number of installed plugins.
|
|
14
|
+
*
|
|
15
|
+
* This module keeps exactly ONE body observer per page. The registry lives on
|
|
16
|
+
* `globalThis` under a `Symbol.for` key, so the per-package generated copies
|
|
17
|
+
* of this file (scripts/sync-shared.mjs) and separately bundled plugins all
|
|
18
|
+
* reach the same hub at runtime instead of one hub per module instance.
|
|
19
|
+
* Record subscribers receive the mutations accumulated since the last flush.
|
|
20
|
+
* Consumers that only re-check their DOM use subscribeBodyInvalidations:
|
|
21
|
+
* when all subscribers use that path, the hub retains no mutation records
|
|
22
|
+
* (or detached subtrees) while a background page's animation frames pause.
|
|
23
|
+
* Both paths run at most once per frame. The last subscriber disconnects the
|
|
24
|
+
* observer, cancels the pending frame and releases its records.
|
|
25
|
+
*
|
|
26
|
+
* Failure policy: without a DOM or `MutationObserver` the subscription is a
|
|
27
|
+
* no-op disposer (the same silence the per-consumer observers had), and when
|
|
28
|
+
* `requestAnimationFrame` is unavailable the flush runs synchronously so a
|
|
29
|
+
* subscriber is never silently dropped. A throwing subscriber cannot stop the
|
|
30
|
+
* others.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to a coalesced DOM re-check without retaining mutation records.
|
|
34
|
+
* The marked wrapper also works with an older hub, which delivers records
|
|
35
|
+
* that it simply ignores until a page reload picks up the updated hub.
|
|
36
|
+
*/
|
|
37
|
+
export declare function subscribeBodyInvalidations(subscriber: () => void): () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Subscribe to body-level childList mutations.
|
|
40
|
+
* @param subscriber - called at most once per animation frame with the records
|
|
41
|
+
* collected since the previous flush; must be safe to run repeatedly.
|
|
42
|
+
* @returns the disposer removing this subscriber (and the observer when it was
|
|
43
|
+
* the last one).
|
|
44
|
+
*/
|
|
45
|
+
export declare function subscribeBodyMutations(subscriber: (records: MutationRecord[]) => void): () => void;
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
25
25
|
import { type PluginUpdatePatchInjected } from './PluginUpdatePatch.tsx';
|
|
26
26
|
import { type PluginManagerKey } from './locales.ts';
|
|
27
|
+
import { type RestartMode } from '../core/protocol.ts';
|
|
27
28
|
import { type PluginManagerService } from '../core/service.ts';
|
|
28
29
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
29
30
|
interface LocaleNamespaceMap {
|
|
@@ -39,7 +40,23 @@ export declare const inject: string[];
|
|
|
39
40
|
* host still records install conflicts and boot failures; no client surface
|
|
40
41
|
* consumes either since the tab left, so neither is on this face.
|
|
41
42
|
*/
|
|
42
|
-
export type PluginManagerFace = PluginUpdatePatchInjected & PluginManagerService
|
|
43
|
+
export type PluginManagerFace = PluginUpdatePatchInjected & PluginManagerService & {
|
|
44
|
+
/**
|
|
45
|
+
* Restart DSH so an applied plugin update is loaded. Always rides this
|
|
46
|
+
* package's own loopback route: neither official channel
|
|
47
|
+
* (`/plugin-installer`, `/plugin-control`) has a restart method, and the
|
|
48
|
+
* route answers how the restart was carried out (in-place relaunch, or a
|
|
49
|
+
* packaged Desktop shell that owns the process tree). See host/restart.ts.
|
|
50
|
+
*/
|
|
51
|
+
restart: () => Promise<RestartMode>;
|
|
52
|
+
/**
|
|
53
|
+
* Read how a restart would be carried out without triggering it (the same
|
|
54
|
+
* route's plan read). The toolbar words its confirmation from this, so a
|
|
55
|
+
* packaged Desktop host can say what its system dialog will do instead of
|
|
56
|
+
* surprising the user with it.
|
|
57
|
+
*/
|
|
58
|
+
restartPlan: () => Promise<RestartMode>;
|
|
59
|
+
};
|
|
43
60
|
/**
|
|
44
61
|
* Build the dual-channel face once: official-channel and gateway-channel
|
|
45
62
|
* implementations, the mode detection that picks between them, and the
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Locale dictionaries for the plugin-manager's official-page patch. The zh
|
|
3
3
|
* dictionary is the key source; the en dictionary mirrors the exact key set.
|
|
4
4
|
*
|
|
5
|
-
* The key set covers only what this package
|
|
6
|
-
*
|
|
5
|
+
* The key set covers only what this package renders: the check-for-updates
|
|
6
|
+
* block on a bundle's page in the official Plugins panel, and the list-level
|
|
7
|
+
* update toolbar mounted beside that panel's "Installed" heading.
|
|
7
8
|
* The former tab's keys (inventory, conflicts, repair seeds, safe mode,
|
|
8
9
|
* aggregate children) left with that tab.
|
|
9
10
|
* @module @linxin666/dsh-client-ui-plugin-manager/client
|
|
@@ -20,6 +21,23 @@ declare const STATIC_ZH: {
|
|
|
20
21
|
updateRequiresDsh: string;
|
|
21
22
|
updateBlockedDsh: string;
|
|
22
23
|
restartHint: string;
|
|
24
|
+
updatesAvailable: string;
|
|
25
|
+
updateAll: string;
|
|
26
|
+
updatingAll: string;
|
|
27
|
+
updateAllDone: string;
|
|
28
|
+
updatesPanelTitle: string;
|
|
29
|
+
thirdPartyOnly: string;
|
|
30
|
+
restartNow: string;
|
|
31
|
+
restarting: string;
|
|
32
|
+
restartConfirm: string;
|
|
33
|
+
restartPlanRelaunch: string;
|
|
34
|
+
restartPlanShell: string;
|
|
35
|
+
restartPlanManual: string;
|
|
36
|
+
restartShellWarning: string;
|
|
37
|
+
restartDesktopHint: string;
|
|
38
|
+
restartRelaunchHint: string;
|
|
39
|
+
restartManualHint: string;
|
|
40
|
+
cancel: string;
|
|
23
41
|
failed: string;
|
|
24
42
|
fetching: string;
|
|
25
43
|
downloading: string;
|
|
@@ -40,6 +58,23 @@ export declare const zh: {
|
|
|
40
58
|
updateRequiresDsh: string;
|
|
41
59
|
updateBlockedDsh: string;
|
|
42
60
|
restartHint: string;
|
|
61
|
+
updatesAvailable: string;
|
|
62
|
+
updateAll: string;
|
|
63
|
+
updatingAll: string;
|
|
64
|
+
updateAllDone: string;
|
|
65
|
+
updatesPanelTitle: string;
|
|
66
|
+
thirdPartyOnly: string;
|
|
67
|
+
restartNow: string;
|
|
68
|
+
restarting: string;
|
|
69
|
+
restartConfirm: string;
|
|
70
|
+
restartPlanRelaunch: string;
|
|
71
|
+
restartPlanShell: string;
|
|
72
|
+
restartPlanManual: string;
|
|
73
|
+
restartShellWarning: string;
|
|
74
|
+
restartDesktopHint: string;
|
|
75
|
+
restartRelaunchHint: string;
|
|
76
|
+
restartManualHint: string;
|
|
77
|
+
cancel: string;
|
|
43
78
|
failed: string;
|
|
44
79
|
fetching: string;
|
|
45
80
|
downloading: string;
|
|
@@ -60,6 +95,23 @@ export declare const en: {
|
|
|
60
95
|
updateRequiresDsh: string;
|
|
61
96
|
updateBlockedDsh: string;
|
|
62
97
|
restartHint: string;
|
|
98
|
+
updatesAvailable: string;
|
|
99
|
+
updateAll: string;
|
|
100
|
+
updatingAll: string;
|
|
101
|
+
updateAllDone: string;
|
|
102
|
+
updatesPanelTitle: string;
|
|
103
|
+
thirdPartyOnly: string;
|
|
104
|
+
restartNow: string;
|
|
105
|
+
restarting: string;
|
|
106
|
+
restartConfirm: string;
|
|
107
|
+
restartPlanRelaunch: string;
|
|
108
|
+
restartPlanShell: string;
|
|
109
|
+
restartPlanManual: string;
|
|
110
|
+
restartShellWarning: string;
|
|
111
|
+
restartDesktopHint: string;
|
|
112
|
+
restartRelaunchHint: string;
|
|
113
|
+
restartManualHint: string;
|
|
114
|
+
cancel: string;
|
|
63
115
|
failed: string;
|
|
64
116
|
fetching: string;
|
|
65
117
|
downloading: string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mounting the update toolbar beside the official Plugins page's "Installed"
|
|
3
|
+
* heading.
|
|
4
|
+
*
|
|
5
|
+
* The page renders that heading itself — `<section data-plugin-group="bundles">
|
|
6
|
+
* <div class="groupHead"><h3>Installed</h3><span>7</span></div>…` — and declares
|
|
7
|
+
* no seat next to it: its extension points are `plugins.detail.*` (per page),
|
|
8
|
+
* `plugins.bundle.config` / `plugins.row.config` / `plugins.item` (configuration
|
|
9
|
+
* entries) and `plugins.bundle.activation`. A list-level action therefore has
|
|
10
|
+
* to be inserted into the page's own chrome, the same way the sidebar foot card
|
|
11
|
+
* is inserted above the Settings row.
|
|
12
|
+
*
|
|
13
|
+
* The container is a plain element carrying its own React root, so it can never
|
|
14
|
+
* disturb the page's reconciliation, and it re-seats itself through the
|
|
15
|
+
* page-wide body-mutation hub: a re-render that relocates or drops the heading
|
|
16
|
+
* is followed on the next frame, and a panel switch that unmounts the list
|
|
17
|
+
* simply detaches the container until the list returns.
|
|
18
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/client
|
|
19
|
+
*/
|
|
20
|
+
import { type PluginListToolbarProps } from './PluginListToolbar.tsx';
|
|
21
|
+
/** Stable attribute identifying the injected container (mount idempotency). */
|
|
22
|
+
export declare const TOOLBAR_MOUNT_SELECTOR = "[data-dsh-plugin-manager-toolbar]";
|
|
23
|
+
/** Toolbar props without the translate function, which is rebuilt per render. */
|
|
24
|
+
export type PluginListToolbarMountInput = Omit<PluginListToolbarProps, 't'> & {
|
|
25
|
+
/** Translate in the namespace, read on every render so a language switch lands. */
|
|
26
|
+
t: PluginListToolbarProps['t'];
|
|
27
|
+
};
|
|
28
|
+
/** The mount's inputs. */
|
|
29
|
+
export interface PluginToolbarMountOptions {
|
|
30
|
+
/** Build the toolbar props; called on mount and on every locale change. */
|
|
31
|
+
props: () => PluginListToolbarMountInput;
|
|
32
|
+
/** Locale change subscription (ctx.locale.subscribe); re-renders the toolbar. */
|
|
33
|
+
subscribe?: (listener: () => void) => () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The official page's "Installed" group heading, when it is mounted. Class
|
|
37
|
+
* names are CSS-module hashes in the official bundle, so the seat is found
|
|
38
|
+
* through the page's own data attributes plus DOM position.
|
|
39
|
+
* @returns the heading element to append into, or undefined off the list view.
|
|
40
|
+
*/
|
|
41
|
+
export declare function toolbarSeat(): HTMLElement | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Mount the toolbar into the Installed heading.
|
|
44
|
+
* @param options - props factory and the optional locale subscription.
|
|
45
|
+
* @returns disposer removing the container, its observers and its React root.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mountPluginListToolbar(options: PluginToolbarMountOptions): () => void;
|
|
@@ -43,6 +43,13 @@ export interface InstalledPluginItem {
|
|
|
43
43
|
*/
|
|
44
44
|
children?: InstalledPluginChild[];
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* How the host carried out (or refused) a restart request:
|
|
48
|
+
* `relaunch` — this host re-executes itself in place; `shell` — the packaged
|
|
49
|
+
* Desktop shell owns the process tree and runs its own restart; `manual` —
|
|
50
|
+
* neither is safe here, the user restarts DSH themselves.
|
|
51
|
+
*/
|
|
52
|
+
export type RestartMode = 'relaunch' | 'shell' | 'manual';
|
|
46
53
|
/** Point-in-time install/update progress reported by the host. */
|
|
47
54
|
export interface InstallProgressItem {
|
|
48
55
|
kind: 'idle' | 'install' | 'update';
|
|
@@ -109,6 +116,12 @@ export declare function parseInstallStatus(value: unknown): InstallProgressItem;
|
|
|
109
116
|
* @returns typed update rows.
|
|
110
117
|
*/
|
|
111
118
|
export declare function parseUpdateList(value: unknown): PluginUpdateItem[];
|
|
119
|
+
/**
|
|
120
|
+
* Validate and normalize a `restart` response value.
|
|
121
|
+
* @param value - decoded but untrusted response value.
|
|
122
|
+
* @returns the mode the host actually used.
|
|
123
|
+
*/
|
|
124
|
+
export declare function parseRestartMode(value: unknown): RestartMode;
|
|
112
125
|
/**
|
|
113
126
|
* Validate and normalize a `failures` response value.
|
|
114
127
|
* @param value - decoded but untrusted response value.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which update rows the list-level toolbar may act on. Pure, shared by the
|
|
3
|
+
* browser half (the toolbar) and its tests: the host answers with every
|
|
4
|
+
* installed package whose registry source serves a newer release, and the
|
|
5
|
+
* policy of what may be updated in bulk lives here rather than in the host,
|
|
6
|
+
* so the same rows stay available to the per-page update block.
|
|
7
|
+
*
|
|
8
|
+
* Two filters:
|
|
9
|
+
*
|
|
10
|
+
* - **Third-party only.** A package published under the `@deepseek-ai/` scope
|
|
11
|
+
* ships with DSH itself: its version is chosen by the running installation,
|
|
12
|
+
* the official page says an upgrade arrives by upgrading DSH, and a
|
|
13
|
+
* plugin-initiated `pnpm add` of such a package can pull a release the runtime was
|
|
14
|
+
* never tested against. The bulk action therefore never touches it.
|
|
15
|
+
* - **Compatibility gate.** An update whose manifest declares a DSH minimum the
|
|
16
|
+
* running host does not satisfy is listed (the user may still upgrade DSH)
|
|
17
|
+
* but cannot be applied: the host would refuse it with 412 anyway.
|
|
18
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/core
|
|
19
|
+
*/
|
|
20
|
+
import type { PluginUpdateItem } from './protocol.ts';
|
|
21
|
+
/** The npm scope DSH's own packages are published under. */
|
|
22
|
+
export declare const OFFICIAL_SCOPE = "@deepseek-ai/";
|
|
23
|
+
/** Whether a package id is a third-party plugin rather than a DSH-shipped one. */
|
|
24
|
+
export declare function isThirdPartyPlugin(id: string): boolean;
|
|
25
|
+
/** The third-party update rows, in host order. */
|
|
26
|
+
export declare function thirdPartyUpdates(items: readonly PluginUpdateItem[]): PluginUpdateItem[];
|
|
27
|
+
/** Whether the running DSH host satisfies the row's declared minimum. */
|
|
28
|
+
export declare function isUpdateApplicable(item: PluginUpdateItem): boolean;
|
|
29
|
+
/** The third-party rows this runtime can actually apply. */
|
|
30
|
+
export declare function applicableUpdates(items: readonly PluginUpdateItem[]): PluginUpdateItem[];
|
|
@@ -55,7 +55,9 @@ export declare function meetsMinimumDsh(host: string, minimum: string): boolean
|
|
|
55
55
|
export declare function displayMinimumVersion(minimum: string): string;
|
|
56
56
|
/**
|
|
57
57
|
* Read the declared DSH minimum from a published registry manifest:
|
|
58
|
-
* `dsh.engines.dsh` first, top-level `engines.dsh`
|
|
58
|
+
* `dsh.engines.dsh` first, top-level `engines.dsh` next, and
|
|
59
|
+
* `peerDependencies["@deepseek-ai/dsh"]` last, which is where a package that
|
|
60
|
+
* only declares the host as a peer still gets gated at boot.
|
|
59
61
|
* Defensive against malformed or untrusted metadata: anything that is not a
|
|
60
62
|
* non-empty string reads as absent.
|
|
61
63
|
* @param manifest - the decoded registry version manifest.
|
|
@@ -64,4 +66,5 @@ export declare function displayMinimumVersion(minimum: string): string;
|
|
|
64
66
|
export declare function dshRequirementOf(manifest: {
|
|
65
67
|
dsh?: unknown;
|
|
66
68
|
engines?: unknown;
|
|
69
|
+
peerDependencies?: unknown;
|
|
67
70
|
}): string | undefined;
|