@linxin666/dsh-client-ui-plugin-manager 0.2.2
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/LICENSE +29 -0
- package/README.i18n.yaml +6 -0
- package/README.md +81 -0
- package/README.zh.md +81 -0
- package/cordis.patch.yml +7 -0
- package/lib/client.js +1464 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +1425 -0
- package/lib/types/client/PluginManagerTab.d.ts +38 -0
- package/lib/types/client/index.d.ts +42 -0
- package/lib/types/client/locales.d.ts +245 -0
- package/lib/types/core/conflict.d.ts +43 -0
- package/lib/types/core/patch-diff.d.ts +46 -0
- package/lib/types/core/protocol.d.ts +99 -0
- package/lib/types/core/repair.d.ts +71 -0
- package/lib/types/core/service.d.ts +45 -0
- package/lib/types/host/bundle-guard.d.ts +53 -0
- package/lib/types/host/dsh-home.d.ts +16 -0
- package/lib/types/host/gateway.d.ts +156 -0
- package/lib/types/host/loopback.d.ts +24 -0
- package/lib/types/host/profile.d.ts +60 -0
- package/lib/types/host/routes.d.ts +34 -0
- package/lib/types/host/rows.d.ts +101 -0
- package/lib/types/host/state.d.ts +58 -0
- package/lib/types/index.d.ts +22 -0
- package/lib/types/mount-once.d.ts +24 -0
- package/package.json +73 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-mutation duplicate-mount guard for the gateway host half. The official
|
|
3
|
+
* CLI's bundle reconciliation appends EVERY dependency that declares
|
|
4
|
+
* `dsh.bundle` to the profile manifest's `dsh.profile.bundles` — including
|
|
5
|
+
* packages the composition already mounts through a patch row (the family
|
|
6
|
+
* aggregate mounts dsh-better-sidebar as the insert row
|
|
7
|
+
* `{ id: 'better-sidebar', name: 'dsh-better-sidebar' }` while the package
|
|
8
|
+
* also sits in the profile's dependencies). The bundles layer then mounts the
|
|
9
|
+
* package a second time and the next boot dies on duplicate routes
|
|
10
|
+
* (`webserver: duplicate prefix route "/sidebar/api"`). This module decides,
|
|
11
|
+
* from the before-state composition, which newly added bundles entries are
|
|
12
|
+
* such duplicate mounts; the gateway strips exactly those entries back out.
|
|
13
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
14
|
+
*/
|
|
15
|
+
import type { ProfileFacts } from './profile.ts';
|
|
16
|
+
/** The before-state composition facts the guard reads. */
|
|
17
|
+
export interface GuardSnapshot {
|
|
18
|
+
/** The profile patch text captured before the mutation. */
|
|
19
|
+
patchText: string;
|
|
20
|
+
/** Dependency names captured before the mutation. */
|
|
21
|
+
dependencies: readonly string[];
|
|
22
|
+
/** Profile-layer row enablement by entry id (bare rows), before the mutation. */
|
|
23
|
+
rowEnabled: ReadonlyMap<string, boolean>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The bundles entries a mutation newly added: present after, absent before.
|
|
27
|
+
* Entries the user already had are never the guard's business.
|
|
28
|
+
* @param before - bundles list before the mutation.
|
|
29
|
+
* @param after - bundles list after the mutation.
|
|
30
|
+
* @returns the newly added entries, in after-state order.
|
|
31
|
+
*/
|
|
32
|
+
export declare function newlyAddedBundles(before: readonly string[], after: readonly string[]): string[];
|
|
33
|
+
/**
|
|
34
|
+
* The package names the before-state composition already mounts through patch
|
|
35
|
+
* rows: the profile patch's own rows (bare and insert-format) plus every
|
|
36
|
+
* before-state dependency's own bundle patch insert entries (the aggregate's
|
|
37
|
+
* rows section lives there, not in the profile layer). A tolerant read: a
|
|
38
|
+
* broken patch file yields no names rather than failing the mutation.
|
|
39
|
+
* @param facts - resolved profile locations.
|
|
40
|
+
* @param before - the before-state capture.
|
|
41
|
+
* @returns the set of row-mounted package names.
|
|
42
|
+
*/
|
|
43
|
+
export declare function rowMountedPackageNames(facts: ProfileFacts, before: GuardSnapshot): Promise<ReadonlySet<string>>;
|
|
44
|
+
/**
|
|
45
|
+
* The newly added bundles entries that duplicate an existing row mount and
|
|
46
|
+
* must be stripped to keep the next boot alive.
|
|
47
|
+
* @param facts - resolved profile locations.
|
|
48
|
+
* @param before - the before-state capture.
|
|
49
|
+
* @param beforeBundles - the bundles list before the mutation.
|
|
50
|
+
* @param afterBundles - the bundles list after the mutation.
|
|
51
|
+
* @returns the entries to remove from `dsh.profile.bundles`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function duplicateMountBundles(facts: ProfileFacts, before: GuardSnapshot, beforeBundles: readonly string[], afterBundles: readonly string[]): Promise<string[]>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH_HOME resolution shared by the plugin family's Host halves: the
|
|
3
|
+
* environment override wins, the platform home fallback follows. Mirrors
|
|
4
|
+
* what dsh-pet and dsh-liangshen each used to implement locally.
|
|
5
|
+
*/
|
|
6
|
+
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
7
|
+
export declare function expandHome(path: string, home?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the DSH home directory.
|
|
10
|
+
* @param env - process environment to read DSH_HOME from.
|
|
11
|
+
* @param home - platform home directory fallback (test seam).
|
|
12
|
+
* @returns the absolute DSH home path.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveDshHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
15
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
16
|
+
export declare function dshHome(): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI gateway: installs and removals executed by spawning the official
|
|
3
|
+
* `dsh plugin --profile <name> add|remove` CLI — the single writer for the
|
|
4
|
+
* profile — with a bounded job table the HTTP layer polls. Every run captures
|
|
5
|
+
* a layer snapshot before and after so the caller can render exactly what the
|
|
6
|
+
* CLI changed (the conflict ledger). The npm web runtime has no installer
|
|
7
|
+
* service, so this gateway is its write path; on runtimes with official
|
|
8
|
+
* channels the browser half never calls it.
|
|
9
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
10
|
+
*/
|
|
11
|
+
import type { InstalledPluginItem } from '../core/protocol.ts';
|
|
12
|
+
import type { ControlChange } from '../core/conflict.ts';
|
|
13
|
+
import { type ProfileFacts } from './profile.ts';
|
|
14
|
+
/**
|
|
15
|
+
* Validate an install spec or package id against shell metacharacters.
|
|
16
|
+
* @param spec - the user-supplied spec or id.
|
|
17
|
+
* @returns the rejection message, or undefined when the spec is safe.
|
|
18
|
+
*/
|
|
19
|
+
export declare function unsafeSpecReason(spec: string): string | undefined;
|
|
20
|
+
/** One CLI-backed operation in flight or settled. */
|
|
21
|
+
export interface GatewayJob {
|
|
22
|
+
id: string;
|
|
23
|
+
action: 'install' | 'remove';
|
|
24
|
+
spec: string;
|
|
25
|
+
phase: 'running' | 'done' | 'error';
|
|
26
|
+
/** The installed row on success (install) or the removed row (remove). */
|
|
27
|
+
plugin?: InstalledPluginItem;
|
|
28
|
+
/** Layer changes the CLI applied, normalized for the conflict panel. */
|
|
29
|
+
conflicts?: ControlChange[];
|
|
30
|
+
/**
|
|
31
|
+
* Duplicate-mount safeguard notices: bundles entries the CLI's
|
|
32
|
+
* reconciliation added but the composition already mounted through a patch
|
|
33
|
+
* row, stripped back out so the next boot cannot double-mount. Each notice
|
|
34
|
+
* carries the conflict-row shape (the entry left the bundles layer:
|
|
35
|
+
* enabled -> uninstalled) so the tab can render it with the existing rows;
|
|
36
|
+
* the package itself stays installed and row-mounted.
|
|
37
|
+
*/
|
|
38
|
+
notices?: ControlChange[];
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
/** The binary search roots for the dsh CLI. */
|
|
42
|
+
export declare function findDshBinary(env?: NodeJS.ProcessEnv, platform?: string, exists?: (path: string) => boolean): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* The spawn command for the dsh CLI on this platform. Windows runs the
|
|
45
|
+
* npm-generated dsh.cmd wrapper by resolving its node binary and bin.js script
|
|
46
|
+
* and spawning them directly: going through cmd.exe splits unquoted paths with
|
|
47
|
+
* spaces (`'D:\Program' is not recognized`).
|
|
48
|
+
* @param binary - the dsh CLI path found by {@link findDshBinary}.
|
|
49
|
+
* @param platform - process platform (test seam).
|
|
50
|
+
* @param localNodeExists - existence probe (test seam).
|
|
51
|
+
* @returns the executable and the argument prefix to run the dsh bin script.
|
|
52
|
+
*/
|
|
53
|
+
export declare function dshSpawnCommand(binary: string, platform?: string, localNodeExists?: (path: string) => boolean): {
|
|
54
|
+
command: string;
|
|
55
|
+
argsPrefix: string[];
|
|
56
|
+
};
|
|
57
|
+
/** Spawn the dsh CLI with piped stdio and no shell parsing (see {@link dshSpawnCommand}). */
|
|
58
|
+
export declare function spawnDsh(binary: string, args: string[], env: NodeJS.ProcessEnv): import("child_process").ChildProcessByStdio<null, import("stream").Readable, import("stream").Readable>;
|
|
59
|
+
/**
|
|
60
|
+
* Detect whether the official installer channels exist on this runtime by
|
|
61
|
+
* dumping the boot composition once: the npm-published web never contains
|
|
62
|
+
* `plugin-installer` entries, DSHCode and the checkout web do. The browser
|
|
63
|
+
* half reads the verdict from the `/mode` route so its channel probe never
|
|
64
|
+
* has to hit the missing official route (which 405s into the console).
|
|
65
|
+
* @param binary - dsh CLI path.
|
|
66
|
+
* @param profileName - boot profile name.
|
|
67
|
+
* @param env - process environment.
|
|
68
|
+
* @param spawnImpl - spawn seam (test seam).
|
|
69
|
+
* @returns true when the dump names the official installer channels.
|
|
70
|
+
*/
|
|
71
|
+
export declare function detectOfficialChannels(binary: string, profileName: string, env?: NodeJS.ProcessEnv, spawnImpl?: typeof spawnDsh): Promise<boolean>;
|
|
72
|
+
/** The gateway: serializes CLI operations through one job table and one mutation queue. */
|
|
73
|
+
export declare class CliGateway {
|
|
74
|
+
private readonly facts;
|
|
75
|
+
private readonly env;
|
|
76
|
+
private readonly deps;
|
|
77
|
+
private readonly jobs;
|
|
78
|
+
private counter;
|
|
79
|
+
/** Mutation queue: two CLI runs must never interleave their before/after captures. */
|
|
80
|
+
private queue;
|
|
81
|
+
/**
|
|
82
|
+
* @param facts - resolved profile locations.
|
|
83
|
+
* @param env - process environment.
|
|
84
|
+
* @param deps - spawn/binary seams (tests only; production uses the real CLI).
|
|
85
|
+
*/
|
|
86
|
+
constructor(facts: ProfileFacts, env?: NodeJS.ProcessEnv, deps?: {
|
|
87
|
+
spawnImpl?: typeof spawnDsh;
|
|
88
|
+
findBinary?: (env: NodeJS.ProcessEnv) => string | null;
|
|
89
|
+
});
|
|
90
|
+
/** Chain one mutation onto the queue; a settled job never blocks the next one. */
|
|
91
|
+
private enqueue;
|
|
92
|
+
/** The dsh CLI path, through the test seam when present. */
|
|
93
|
+
private binary;
|
|
94
|
+
/** Spawn the CLI, through the test seam when present. */
|
|
95
|
+
private spawnCli;
|
|
96
|
+
/** Start an install; the caller polls {@link status}. */
|
|
97
|
+
install(spec: string): {
|
|
98
|
+
jobId: string;
|
|
99
|
+
};
|
|
100
|
+
/** Start a removal; the caller polls {@link status}. */
|
|
101
|
+
remove(id: string): {
|
|
102
|
+
jobId: string;
|
|
103
|
+
};
|
|
104
|
+
/** Read one job's current state (a shallow copy). */
|
|
105
|
+
status(jobId: string): GatewayJob | undefined;
|
|
106
|
+
/** Capture the layer snapshot and the dependency names (tolerant parse). */
|
|
107
|
+
private capture;
|
|
108
|
+
/** The plugin row a finished operation produced (installed or removed). */
|
|
109
|
+
private rowFor;
|
|
110
|
+
/** Run one CLI operation to settlement; an unexpected failure settles the job as error. */
|
|
111
|
+
private run;
|
|
112
|
+
/** The mutation body of {@link run}. */
|
|
113
|
+
private runInner;
|
|
114
|
+
/**
|
|
115
|
+
* Post-mutation duplicate-mount safeguard (B9): remove the bundles entries
|
|
116
|
+
* the CLI's reconciliation newly added for packages the before-state
|
|
117
|
+
* composition already mounted through a patch row. The write goes through
|
|
118
|
+
* the manifest's safe path (backup + tmp + atomic rename); entries the
|
|
119
|
+
* user had before and entries with no row mount are never touched. A
|
|
120
|
+
* failure of the guard itself settles the job as an error — a boot-breaking
|
|
121
|
+
* bundles state is never left silently.
|
|
122
|
+
* @param job - the settling job (error target on guard failure).
|
|
123
|
+
* @param before - state captured before the CLI run.
|
|
124
|
+
* @param after - state captured after the CLI run.
|
|
125
|
+
* @returns the stripped entries, or undefined when the job failed.
|
|
126
|
+
*/
|
|
127
|
+
private stripDuplicateMounts;
|
|
128
|
+
/**
|
|
129
|
+
* Roll back a freshly installed dependency through the official remove
|
|
130
|
+
* path (which also drops its bundle), then settle the job as an error.
|
|
131
|
+
* This is the owner-aware conflict resolution: the existing plugin keeps
|
|
132
|
+
* its entry ids and enablement untouched.
|
|
133
|
+
*/
|
|
134
|
+
private rollbackInstall;
|
|
135
|
+
/**
|
|
136
|
+
* Insert-entry package names of one installed dependency that resolve
|
|
137
|
+
* nowhere: not the dependency itself, not another profile dependency, not
|
|
138
|
+
* an official @deepseek-ai/* package, and absent from every node_modules
|
|
139
|
+
* the loader could import them from. Import-time failures beyond this
|
|
140
|
+
* static check still surface only at the first real boot.
|
|
141
|
+
*/
|
|
142
|
+
private unresolvableInsertNames;
|
|
143
|
+
/** The new dependency of an install, when one exists. */
|
|
144
|
+
private newDependency;
|
|
145
|
+
/** The claimed entry ids of one installed dependency (its own bundle patch, or its name). */
|
|
146
|
+
private claimedEntriesOf;
|
|
147
|
+
/** Whether the new install claims an entry id another plugin already holds. */
|
|
148
|
+
private detectDuplicateClaims;
|
|
149
|
+
/**
|
|
150
|
+
* Boot preflight after an install: compose the profile with the CLI's
|
|
151
|
+
* `--dump-config` (resolves every entry without binding the port). A failure
|
|
152
|
+
* that implicates the new plugin disables it so the next start cannot fail;
|
|
153
|
+
* an unrelated failure is reported without touching anything.
|
|
154
|
+
*/
|
|
155
|
+
private verifyBoot;
|
|
156
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback trust fence shared by the host route families: socket address,
|
|
3
|
+
* Host header, and browser same-origin markers. Packages receive this file as
|
|
4
|
+
* a generated copy via scripts/sync-shared.mjs; edit the shared source and
|
|
5
|
+
* re-run the sync instead of editing a copy.
|
|
6
|
+
*
|
|
7
|
+
* Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8 (matching the
|
|
8
|
+
* remote-web-ui gate), localhost hostnames, plus the browser same-origin
|
|
9
|
+
* markers (sec-fetch-site and Origin) for the request-level fence.
|
|
10
|
+
* @module dsh-web-ui-shared/host/loopback
|
|
11
|
+
*/
|
|
12
|
+
import type { IncomingMessage } from 'node:http';
|
|
13
|
+
/** IPv4 127/8 predicate (four decimal octets, first == 127). */
|
|
14
|
+
export declare function isIPv4Loopback(v4: string): boolean;
|
|
15
|
+
/** Whether a socket remote address names the loopback range (127/8, ::1, IPv4-mapped). */
|
|
16
|
+
export declare function isLoopbackAddress(address: string | undefined): boolean;
|
|
17
|
+
/** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
|
|
18
|
+
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Request-level trust fence: a loopback socket address AND a loopback Host
|
|
21
|
+
* header, plus browser same-origin markers. The socket address is
|
|
22
|
+
* authoritative; X-Forwarded-For is never trusted.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isLoopbackRequest(request: IncomingMessage): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile resolution and manifest reads for the gateway host half. The npm
|
|
3
|
+
* web runtime has no plugin-installer service, so this package resolves the
|
|
4
|
+
* boot profile from the host process's own argv (the launcher fact) and reads
|
|
5
|
+
* the profile's package.json and cordis.patch.yml directly — reads only; every
|
|
6
|
+
* write goes through the official CLI or the patch-row editor.
|
|
7
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
8
|
+
*/
|
|
9
|
+
/** Resolved locations of one profile's writable surface. */
|
|
10
|
+
export interface ProfileFacts {
|
|
11
|
+
/** Profile name (the directory under $DSH_HOME/profiles). */
|
|
12
|
+
profileName: string;
|
|
13
|
+
/** Absolute profile directory. */
|
|
14
|
+
profileDir: string;
|
|
15
|
+
/** Absolute path of the profile's cordis.patch.yml. */
|
|
16
|
+
patchPath: string;
|
|
17
|
+
/** Absolute path of the profile's package.json. */
|
|
18
|
+
packageJsonPath: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the boot profile name from the host argv: an explicit `--profile`
|
|
22
|
+
* flag wins, then the DSH_PROFILE environment override, then the `web`
|
|
23
|
+
* subcommand alias. The launcher hands the app its own args verbatim, so the
|
|
24
|
+
* web app's argv is the reliable source on every CLI-launched host.
|
|
25
|
+
* @param argv - process argv (test seam).
|
|
26
|
+
* @param env - process environment (test seam).
|
|
27
|
+
* @returns the resolved profile facts.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveProfile(argv?: readonly string[], env?: NodeJS.ProcessEnv): ProfileFacts;
|
|
30
|
+
/** The profile package.json surface the gateway reads. */
|
|
31
|
+
export interface ProfileManifest {
|
|
32
|
+
/** dsh.profile.bundles entries (may be absent). */
|
|
33
|
+
bundles: string[];
|
|
34
|
+
/** package.json dependencies: package name -> install spec. */
|
|
35
|
+
dependencies: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Read the profile manifest; a missing or malformed file fails loud.
|
|
39
|
+
* @param packageJsonPath - absolute path of the profile's package.json.
|
|
40
|
+
* @returns the parsed bundles and dependencies.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readProfileManifest(packageJsonPath: string): Promise<ProfileManifest>;
|
|
43
|
+
/**
|
|
44
|
+
* Remove selected entries from the profile manifest's `dsh.profile.bundles`,
|
|
45
|
+
* conservatively: a single backup copy, then a tmp write and an atomic-ish
|
|
46
|
+
* rename over the target — the same discipline as the patch-row editor. Every
|
|
47
|
+
* other key (dependencies included) round-trips untouched; entries not in
|
|
48
|
+
* `names` keep their order. A missing bundles array is a no-op write.
|
|
49
|
+
* @param packageJsonPath - absolute path of the profile's package.json.
|
|
50
|
+
* @param names - bundle entries to strip (package names).
|
|
51
|
+
*/
|
|
52
|
+
export declare function stripProfileBundles(packageJsonPath: string, names: readonly string[]): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Read the profile patch text; a missing file is an empty layer.
|
|
55
|
+
* @param patchPath - absolute path of cordis.patch.yml.
|
|
56
|
+
* @returns the file text, or `[]` when absent.
|
|
57
|
+
*/
|
|
58
|
+
export declare function readPatchText(patchPath: string): Promise<string>;
|
|
59
|
+
/** Whether a profile directory exists (the gateway needs an initialized profile). */
|
|
60
|
+
export declare function profileExists(profileDir: string): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gateway HTTP surface: loopback-fenced routes serving the plugin
|
|
3
|
+
* inventory, CLI-backed install/removal jobs, next-start enablement, the
|
|
4
|
+
* (empty on this runtime) failure ring, and registry update checks. The
|
|
5
|
+
* fence is the shared family loopback guard — same-origin local browsers
|
|
6
|
+
* only, mirroring the official loopback authority the installer channels
|
|
7
|
+
* would have enforced.
|
|
8
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
9
|
+
*/
|
|
10
|
+
import type { WebRoute } from '@deepseek-ai/dsh-host-webserver';
|
|
11
|
+
import { type CliGateway } from './gateway.ts';
|
|
12
|
+
import { type ProfileFacts } from './profile.ts';
|
|
13
|
+
import { buildPluginRow } from './state.ts';
|
|
14
|
+
/** Route prefix the browser half mirrors. */
|
|
15
|
+
export declare const GATEWAY_PREFIX = "/api/plugin-manager";
|
|
16
|
+
/** Dependencies every route shares. */
|
|
17
|
+
export interface GatewayRouteDeps {
|
|
18
|
+
facts: ProfileFacts;
|
|
19
|
+
gateway: CliGateway;
|
|
20
|
+
/** Resolve the dsh binary presence (the CLI is the write path). */
|
|
21
|
+
cliAvailable: () => boolean;
|
|
22
|
+
/** Registry fetch seam for update checks (test seam). */
|
|
23
|
+
fetchLatest?: (name: string) => Promise<string | undefined>;
|
|
24
|
+
/** Official-channel detection seam (test seam); defaults to the boot dump probe. */
|
|
25
|
+
officialChannels?: () => Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build the gateway routes.
|
|
29
|
+
* @param deps - profile facts, the CLI gateway, and seams.
|
|
30
|
+
* @returns the web-server routes to register.
|
|
31
|
+
*/
|
|
32
|
+
export declare function makeGatewayRoutes(deps: GatewayRouteDeps): WebRoute[];
|
|
33
|
+
/** Re-exported for host wiring: build a plugin row against the live snapshot. */
|
|
34
|
+
export { buildPluginRow };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile patch-row editing for the gateway host half. The npm web loader
|
|
3
|
+
* honors `disabled` on rows and applies the profile patch as the user layer,
|
|
4
|
+
* so next-start enablement is a bare `{ id, name, disabled }` override row —
|
|
5
|
+
* the same id-targeted, later-wins semantics the official desktop writer
|
|
6
|
+
* uses. Editing goes through the `yaml` document round-trip, which preserves
|
|
7
|
+
* comments and unrelated rows byte-for-byte in spirit; the !!js expression
|
|
8
|
+
* tag keeps loader expressions literal so profiles carrying them stay
|
|
9
|
+
* parseable.
|
|
10
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
11
|
+
*/
|
|
12
|
+
import { type Document, type ScalarTag, type YAMLMap, type YAMLSeq } from 'yaml';
|
|
13
|
+
/**
|
|
14
|
+
* Persist one patch file conservatively: a timestamped-free single backup,
|
|
15
|
+
* then a tmp write and an atomic-ish rename over the target.
|
|
16
|
+
* @param patchPath - absolute cordis.patch.yml path.
|
|
17
|
+
* @param text - the new file text.
|
|
18
|
+
*/
|
|
19
|
+
export declare function writePatchAtomic(patchPath: string, text: string): Promise<void>;
|
|
20
|
+
/** YAML `!!js` expression tag: expressions stay literal until the Loader evaluates them. */
|
|
21
|
+
export declare const JS_EXPRESSION_TAG: ScalarTag;
|
|
22
|
+
/** A parsed patch file: the yaml document and its top-level sequence. */
|
|
23
|
+
export interface PatchDocumentView {
|
|
24
|
+
readonly document: Document;
|
|
25
|
+
readonly root: YAMLSeq;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse a patch file, failing loud on invalid YAML and non-array roots.
|
|
29
|
+
* @param text - file content.
|
|
30
|
+
* @param filename - absolute cordis.patch.yml path (diagnostics only).
|
|
31
|
+
* @returns the parsed document and root sequence.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parsePatch(text: string, filename: string): PatchDocumentView;
|
|
34
|
+
/** The string id of a bare row, when it carries one. */
|
|
35
|
+
export declare function bareRowId(item: unknown): string | undefined;
|
|
36
|
+
/** The string name of a bare row, when it carries one. */
|
|
37
|
+
export declare function bareRowName(item: unknown): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The next-start enablement a bare row declares: a row is enabled unless it
|
|
40
|
+
* carries an explicit `disabled: true` (mirrors the official reader). Non-row
|
|
41
|
+
* items (insert wrappers, config rows) count as enabled.
|
|
42
|
+
* @param item - one top-level patch item.
|
|
43
|
+
* @returns whether the item leaves its entry enabled.
|
|
44
|
+
*/
|
|
45
|
+
export declare function bareRowEnabled(item: unknown): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Find the bare override row for one id.
|
|
48
|
+
* @param root - the top-level sequence.
|
|
49
|
+
* @param id - the entry id to match.
|
|
50
|
+
* @returns the row and its index, or undefined.
|
|
51
|
+
*/
|
|
52
|
+
export declare function findBareRow(root: YAMLSeq, id: string): {
|
|
53
|
+
row: YAMLMap;
|
|
54
|
+
index: number;
|
|
55
|
+
} | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* The ids an installed package's own bundle patch claims, read from its
|
|
58
|
+
* cordis.patch.yml (each insert entry carries an id). An empty result means
|
|
59
|
+
* the package is a plain plugin whose row id is its package name.
|
|
60
|
+
* @param patchText - the package's own bundle patch text (`[]` for none).
|
|
61
|
+
* @returns the claimed insert ids, in order.
|
|
62
|
+
*/
|
|
63
|
+
export declare function claimedIdsOf(patchText: string): string[];
|
|
64
|
+
/** One insert entry of a bundle patch: the claimed id and the plugin package name. */
|
|
65
|
+
export interface InsertRow {
|
|
66
|
+
id?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The insert entries of an installed package's own bundle patch, with both
|
|
71
|
+
* the claimed id and the entry's own name. The name matters twice: the
|
|
72
|
+
* loader imports the plugin by it (an unresolvable name is a boot failure),
|
|
73
|
+
* and a bare override row whose name mismatches it is skipped by the include
|
|
74
|
+
* patch semantics, so enablement rows must carry this exact name.
|
|
75
|
+
* @param patchText - the package's own bundle patch text (`[]` for none).
|
|
76
|
+
* @returns the insert rows, in order.
|
|
77
|
+
*/
|
|
78
|
+
export declare function insertRowsOf(patchText: string): InsertRow[];
|
|
79
|
+
/**
|
|
80
|
+
* The inner entry of an insert-format item whose id matches, when one exists
|
|
81
|
+
* (the official desktop writer manages rows in this shape).
|
|
82
|
+
* @param root - the top-level sequence.
|
|
83
|
+
* @param id - the entry id to match.
|
|
84
|
+
* @returns the inner row, or undefined.
|
|
85
|
+
*/
|
|
86
|
+
export declare function findInsertRow(root: YAMLSeq, id: string): YAMLMap | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Persist the next-start enablement of one entry. Bare override rows are this
|
|
89
|
+
* package's own shape: enabling removes the override, disabling creates or
|
|
90
|
+
* updates `{ id, name, disabled: true }`. When a newer desktop tool already
|
|
91
|
+
* manages the entry as an insert-format row, the inner row's `disabled` flag
|
|
92
|
+
* is edited instead (the official writer's shape). The returned text
|
|
93
|
+
* preserves every other row and comment.
|
|
94
|
+
* @param text - current patch file text.
|
|
95
|
+
* @param filename - absolute path (diagnostics only).
|
|
96
|
+
* @param id - the entry id to override.
|
|
97
|
+
* @param name - the display name recorded on the row.
|
|
98
|
+
* @param enabled - desired next-start enablement.
|
|
99
|
+
* @returns the new file text.
|
|
100
|
+
*/
|
|
101
|
+
export declare function setRowEnabled(text: string, filename: string, id: string, name: string, enabled: boolean): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway listing: the installed-plugin inventory read from the profile's
|
|
3
|
+
* package.json, its node_modules manifests, and the patch rows' enablement.
|
|
4
|
+
* The npm web runtime has no installer inventory service, so this module is
|
|
5
|
+
* the read side of the gateway (the write side is the official CLI).
|
|
6
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
7
|
+
*/
|
|
8
|
+
import type { InstalledPluginItem } from '../core/protocol.ts';
|
|
9
|
+
import type { LayerSnapshot } from '../core/patch-diff.ts';
|
|
10
|
+
import { type ProfileFacts } from './profile.ts';
|
|
11
|
+
/** The listing result: plugin rows plus the raw layer snapshot for diffs. */
|
|
12
|
+
export interface GatewaySnapshot {
|
|
13
|
+
plugins: InstalledPluginItem[];
|
|
14
|
+
layer: LayerSnapshot;
|
|
15
|
+
}
|
|
16
|
+
/** Whether an install spec names a git/file/link source rather than a registry package. */
|
|
17
|
+
export declare function sourceKindOf(spec: string): 'npm' | 'git';
|
|
18
|
+
/**
|
|
19
|
+
* The entry ids one installed dependency claims: the insert ids of its own
|
|
20
|
+
* bundle patch, falling back to the package name. Shared by the listing read
|
|
21
|
+
* side and the set-enabled write side so both agree on the id space — writing
|
|
22
|
+
* package-name rows while reading bundle-patch ids made the switches inert.
|
|
23
|
+
* @param facts - resolved profile locations.
|
|
24
|
+
* @param name - dependency name (possibly scoped).
|
|
25
|
+
* @returns the claimed entry ids, never empty.
|
|
26
|
+
*/
|
|
27
|
+
export declare function claimedEntryIdsOf(facts: ProfileFacts, name: string): Promise<string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* The insert rows one installed dependency claims, id plus the entry's own
|
|
30
|
+
* name (falling back to the package name for plain plugins). The set-enabled
|
|
31
|
+
* write side needs the entry's own name: the include patch semantics skip a
|
|
32
|
+
* bare override row whose name mismatches the inserted entry's name.
|
|
33
|
+
* @param facts - resolved profile locations.
|
|
34
|
+
* @param name - dependency name (possibly scoped).
|
|
35
|
+
* @returns the claimed rows, never empty.
|
|
36
|
+
*/
|
|
37
|
+
export declare function claimedEntryRowsOf(facts: ProfileFacts, name: string): Promise<Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
}>>;
|
|
41
|
+
/**
|
|
42
|
+
* Build one installed-plugin row from the profile facts: version from the
|
|
43
|
+
* installed manifest, enablement from the entry ids its own bundle patch
|
|
44
|
+
* claims (plain plugins use the package name as the row id).
|
|
45
|
+
* @param facts - resolved profile locations.
|
|
46
|
+
* @param name - dependency name (possibly scoped).
|
|
47
|
+
* @param spec - the install spec recorded in the profile dependencies.
|
|
48
|
+
* @param rowEnabled - row enablement by id.
|
|
49
|
+
* @returns the wire-shaped plugin row.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildPluginRow(facts: ProfileFacts, name: string, spec: string, rowEnabled: ReadonlyMap<string, boolean>): Promise<InstalledPluginItem>;
|
|
52
|
+
/**
|
|
53
|
+
* Build the gateway listing and the layer snapshot.
|
|
54
|
+
* @param facts - resolved profile locations.
|
|
55
|
+
* @param patchText - current profile patch text.
|
|
56
|
+
* @returns plugin rows (wire shape of the official list) and the layer state.
|
|
57
|
+
*/
|
|
58
|
+
export declare function snapshotGateway(facts: ProfileFacts, patchText: string): Promise<GatewaySnapshot>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the dsh-plugin-manager plugin — runs in the DSH host process.
|
|
3
|
+
*
|
|
4
|
+
* Dual-channel design: on runtimes with the official installer services
|
|
5
|
+
* (DSHCode and the 1.0.4 checkout web), the browser half uses the official
|
|
6
|
+
* `/plugin-installer` and `/plugin-control` RPC channels and this half does
|
|
7
|
+
* nothing. On the npm-published web runtime (rc.6/rc.7), those channels do
|
|
8
|
+
* not exist, so this half mounts a loopback-fenced HTTP gateway: the
|
|
9
|
+
* inventory reads the profile files, installs and removals spawn the
|
|
10
|
+
* official CLI (the single writer), and enablement writes bare `disabled`
|
|
11
|
+
* override rows into the profile patch.
|
|
12
|
+
* @module @linxin666/dsh-client-ui-plugin-manager
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
+
/** Stable cordis plugin name (matches cordis.patch.yml insert id). */
|
|
16
|
+
export declare const name = "ui-plugin-manager";
|
|
17
|
+
/** Services the gateway needs — the web server seam. */
|
|
18
|
+
export declare const inject: string[];
|
|
19
|
+
/** Apply the host half (once per process). */
|
|
20
|
+
export declare const apply: typeof applyImpl;
|
|
21
|
+
declare function applyImpl(ctx: Context): void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host single-instance guard shared by the plugin family. The family bundle
|
|
3
|
+
* (dsh-web-ui-all / dsh-skins) namespaces every child row id (web-ui-*), so
|
|
4
|
+
* the loader accepts a standalone install of the same package side by side;
|
|
5
|
+
* without this guard the second instance would still re-register the same
|
|
6
|
+
* webserver routes, tools, settings namespaces, and system-prompt sections
|
|
7
|
+
* and fail the boot. mountOnce makes the second host apply a no-op for the
|
|
8
|
+
* lifetime of the first instance (the browser half is already deduped by
|
|
9
|
+
* package name in the client module host).
|
|
10
|
+
*
|
|
11
|
+
* The registry rides a global symbol so two module instances of the same
|
|
12
|
+
* package (npm copy vs repository link) still share one verdict. cordis
|
|
13
|
+
* `ctx.effect` runs its callback immediately and treats the callback's
|
|
14
|
+
* return value as the fiber disposer, so the unmarker is returned, not run.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a cordis plugin apply so the package runs at most once per process.
|
|
18
|
+
* The first mount registers normally and unmarks when its fiber disposes;
|
|
19
|
+
* any later mount of the same package name is a no-op.
|
|
20
|
+
* @param packageName - npm package identity shared by every install source.
|
|
21
|
+
* @param fn - the original plugin apply.
|
|
22
|
+
* @returns an apply of the same shape.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mountOnce<T extends (...args: any[]) => unknown>(packageName: string, fn: T): T;
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@linxin666/dsh-client-ui-plugin-manager",
|
|
3
|
+
"description": "Plugin manager tab for the dsh web GUI Plugins settings section: installs plugins from npm or git through the official host channels, lists installed plugins with next-start enablement switches, surfaces install-time conflict actions with undo, and hands failures off to repair conversations.",
|
|
4
|
+
"version": "0.2.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./lib/types/client/index.d.ts",
|
|
15
|
+
"default": "./lib/client.js"
|
|
16
|
+
},
|
|
17
|
+
"./src/*": "./src/*",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"dsh": {
|
|
21
|
+
"bundle": {
|
|
22
|
+
"patch": "./cordis.patch.yml"
|
|
23
|
+
},
|
|
24
|
+
"client": {
|
|
25
|
+
"inject": [
|
|
26
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
27
|
+
"@deepseek-ai/dsh-client-connection",
|
|
28
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
29
|
+
],
|
|
30
|
+
"platform": "web"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": "^18.2.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
38
|
+
"@deepseek-ai/dsh-client-connection": "^0.1.0-rc.7",
|
|
39
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.0-rc.7",
|
|
40
|
+
"@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.7",
|
|
41
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.7",
|
|
42
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.1.0-rc.7",
|
|
43
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.7",
|
|
44
|
+
"@testing-library/react": "^16.1.0",
|
|
45
|
+
"@types/node": "^22.20.0",
|
|
46
|
+
"@types/react": "~18.3.1",
|
|
47
|
+
"@types/react-dom": "^18.3.5",
|
|
48
|
+
"jsdom": "^26.0.0",
|
|
49
|
+
"react": "^18.3.1",
|
|
50
|
+
"react-dom": "^18.3.1",
|
|
51
|
+
"tsdown": "0.22.2",
|
|
52
|
+
"typescript": "~5.7.2",
|
|
53
|
+
"vitest": "^4.1.1",
|
|
54
|
+
"@deepseek-ai/dsh-host-webserver": "^0.1.0-rc.7"
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"lib",
|
|
58
|
+
"cordis.patch.yml",
|
|
59
|
+
"README.md",
|
|
60
|
+
"README.zh.md",
|
|
61
|
+
"README.i18n.yaml"
|
|
62
|
+
],
|
|
63
|
+
"license": "BSD-3-Clause",
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"yaml": "^2.8.2"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsc -p tsconfig.build.json && tsdown",
|
|
69
|
+
"watch": "tsdown --watch",
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"typecheck": "tsc --noEmit"
|
|
72
|
+
}
|
|
73
|
+
}
|