dshmarket 1.78.0 → 1.80.0
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/client/client.js +287 -26
- package/lib/hot.js +20 -4
- package/lib/routes.js +113 -9
- package/lib/self-reload.js +296 -0
- package/lib/types/hot.d.ts +17 -5
- package/lib/types/routes.d.ts +10 -0
- package/lib/types/self-reload.d.ts +174 -0
- package/package.json +1 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reload the market's OWN server half inside the running DSH process.
|
|
3
|
+
*
|
|
4
|
+
* Why this exists: the market updates itself by replacing its files, and the
|
|
5
|
+
* Node module it already imported keeps running. The browser, meanwhile, loads
|
|
6
|
+
* the NEW client bundle, which calls routes the old process does not have (the
|
|
7
|
+
* host answers 405 with an empty body). The only cure used to be a restart,
|
|
8
|
+
* and on DSH Desktop even that is not ours to do (`allowRestart: false`).
|
|
9
|
+
*
|
|
10
|
+
* How: not by re-importing ourselves — Node never re-evaluates a module at a
|
|
11
|
+
* URL it has already loaded, and a cache-busted URL only renews the entry
|
|
12
|
+
* file while every sibling it imports stays the old one. The host already
|
|
13
|
+
* solves exactly this for every plugin: `hmr.reconcileProfile()` (the service
|
|
14
|
+
* `@deepseek-ai/dsh-hmr` publishes as `ctx.hmr`, present from DSH 0.2.1)
|
|
15
|
+
* compares the files of every loaded module with the disk, evicts the ones
|
|
16
|
+
* that changed together with their importers, stops the loader entries that
|
|
17
|
+
* ran them and starts those entries again from the new files. The market is a
|
|
18
|
+
* loader entry like any other, so it is replaced the same way. This module is
|
|
19
|
+
* the orchestration around that one call.
|
|
20
|
+
*
|
|
21
|
+
* The part that is ours, and the reason this is more than one call:
|
|
22
|
+
*
|
|
23
|
+
* - The request that asks for the swap is served by the instance about to be
|
|
24
|
+
* replaced. Its closure outlives its own disposal (the HTTP response object
|
|
25
|
+
* belongs to the web server, not to the plugin), so the SAME request can
|
|
26
|
+
* still report how the swap went.
|
|
27
|
+
* - The host does not restore the old code when the new code cannot start: it
|
|
28
|
+
* evicts the old modules without a backup. So the new build is imported
|
|
29
|
+
* first, from a private copy at a path Node has never seen, and the swap is
|
|
30
|
+
* only asked for when that worked. A build that cannot even load never
|
|
31
|
+
* replaces a market that is running fine.
|
|
32
|
+
* - Which instance is serving is a fact held outside every module — on
|
|
33
|
+
* `globalThis` under a registered symbol — because the module that would
|
|
34
|
+
* hold it is exactly what gets replaced.
|
|
35
|
+
*/
|
|
36
|
+
/** The slice of the host's `hmr` service this relies on. */
|
|
37
|
+
export interface HmrLike {
|
|
38
|
+
runExclusive<T>(operation: () => Promise<T>): Promise<T>;
|
|
39
|
+
reconcileProfile(requiredIds?: readonly string[]): Promise<{
|
|
40
|
+
warnings: readonly string[];
|
|
41
|
+
/** Changed modules that keep running their old code until a restart. */
|
|
42
|
+
pending: readonly {
|
|
43
|
+
url: string;
|
|
44
|
+
reason: string;
|
|
45
|
+
}[];
|
|
46
|
+
/** Why every change waits for a restart, when the host could not compare modules at all. */
|
|
47
|
+
restartReason?: string;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The host's HMR service when it can replace modules, otherwise undefined.
|
|
52
|
+
* Checked by shape: DSH 0.2.0 and earlier publish an `hmr` service without
|
|
53
|
+
* `reconcileProfile`, and a call into it would fail after we had decided to
|
|
54
|
+
* go ahead.
|
|
55
|
+
*/
|
|
56
|
+
export declare function asHmr(value: unknown): HmrLike | undefined;
|
|
57
|
+
/** The instance that registered its routes last. */
|
|
58
|
+
export interface InstanceRecord {
|
|
59
|
+
id: string;
|
|
60
|
+
version: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Announce this instance as the one serving. Returns the id to compare
|
|
64
|
+
* against, and a release that only clears the record when it is still this
|
|
65
|
+
* instance's own — a late release from a replaced instance must not erase the
|
|
66
|
+
* record its replacement has already written.
|
|
67
|
+
*/
|
|
68
|
+
export declare function claimInstance(version: string): {
|
|
69
|
+
id: string;
|
|
70
|
+
release(): void;
|
|
71
|
+
};
|
|
72
|
+
/** The instance serving right now, or undefined while none is. */
|
|
73
|
+
export declare function currentInstance(): InstanceRecord | undefined;
|
|
74
|
+
/** Verdict of {@link preflightBuild}. */
|
|
75
|
+
export type Preflight = {
|
|
76
|
+
ok: true;
|
|
77
|
+
checked: boolean;
|
|
78
|
+
} | {
|
|
79
|
+
ok: false;
|
|
80
|
+
detail: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Whether the package now on disk can be loaded at all.
|
|
84
|
+
*
|
|
85
|
+
* Imports a private copy of its `lib/` from a path nobody has imported, so
|
|
86
|
+
* the whole module graph is evaluated fresh and any failure — a syntax error,
|
|
87
|
+
* a dependency that is missing, a top-level throw — surfaces here, while the
|
|
88
|
+
* running market is still untouched. The copy sits NEXT TO the package so
|
|
89
|
+
* bare imports resolve through the same `node_modules` chain as the real one,
|
|
90
|
+
* and is deleted again afterwards; the host forgets files that disappeared.
|
|
91
|
+
*
|
|
92
|
+
* What it cannot see: a build that loads fine and then fails inside `apply`.
|
|
93
|
+
* That is only learnable by running it.
|
|
94
|
+
*
|
|
95
|
+
* `checked: false` means the check could not be run (the directory is not
|
|
96
|
+
* writable); the caller proceeds, because refusing every reload on a
|
|
97
|
+
* read-only profile would make the feature useless there.
|
|
98
|
+
*/
|
|
99
|
+
export declare function preflightBuild(packageDir: string): Promise<Preflight>;
|
|
100
|
+
/** What a reload attempt came to. */
|
|
101
|
+
export type SelfReloadOutcome =
|
|
102
|
+
/** The host cannot replace modules (or the market is not an installed package here). */
|
|
103
|
+
{
|
|
104
|
+
state: 'unsupported';
|
|
105
|
+
reason: 'no-hmr' | 'not-installed';
|
|
106
|
+
}
|
|
107
|
+
/** The files on disk are the version already running: nothing to do. */
|
|
108
|
+
| {
|
|
109
|
+
state: 'current';
|
|
110
|
+
version: string;
|
|
111
|
+
}
|
|
112
|
+
/** The new build cannot load. The running market was not touched. */
|
|
113
|
+
| {
|
|
114
|
+
state: 'refused';
|
|
115
|
+
detail: string;
|
|
116
|
+
}
|
|
117
|
+
/** The new server half is serving. */
|
|
118
|
+
| {
|
|
119
|
+
state: 'reloaded';
|
|
120
|
+
from: string;
|
|
121
|
+
to: string;
|
|
122
|
+
}
|
|
123
|
+
/** The host could not replace the module; the running market is untouched. */
|
|
124
|
+
| {
|
|
125
|
+
state: 'restart-needed';
|
|
126
|
+
detail: string;
|
|
127
|
+
}
|
|
128
|
+
/** Another host operation holds the reload queue; the swap will run when it ends. */
|
|
129
|
+
| {
|
|
130
|
+
state: 'queued';
|
|
131
|
+
}
|
|
132
|
+
/** The swap started and went wrong. `serving` says whether any instance is up. */
|
|
133
|
+
| {
|
|
134
|
+
state: 'failed';
|
|
135
|
+
detail: string;
|
|
136
|
+
serving: boolean;
|
|
137
|
+
};
|
|
138
|
+
export interface SelfReloadDeps {
|
|
139
|
+
/** The host's HMR service, read at call time. */
|
|
140
|
+
hmr: () => HmrLike | undefined;
|
|
141
|
+
/** The version this process is running. */
|
|
142
|
+
runningVersion: string;
|
|
143
|
+
/** The version of the files on disk, or null when the market is not an installed package. */
|
|
144
|
+
installedVersion: () => string | null;
|
|
145
|
+
/** Where the installed package lives. */
|
|
146
|
+
packageDir: () => string;
|
|
147
|
+
/** This instance's id, from {@link claimInstance}. */
|
|
148
|
+
instanceId: string;
|
|
149
|
+
/** The instance serving now; injectable for the specs. */
|
|
150
|
+
serving?: () => InstanceRecord | undefined;
|
|
151
|
+
/** Defaults to {@link preflightBuild}. */
|
|
152
|
+
preflight?: (packageDir: string) => Promise<Preflight>;
|
|
153
|
+
/** How long to wait for the host's reload queue before reporting `queued`. */
|
|
154
|
+
queueWaitMs?: number;
|
|
155
|
+
/** How long to wait for the new instance to announce itself once the host reports done. */
|
|
156
|
+
settleMs?: number;
|
|
157
|
+
log?: (level: 'info' | 'warn', detail: string) => void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Ask the host to replace this market with the version on disk.
|
|
161
|
+
*
|
|
162
|
+
* The caller has already refused when an operation is running: a swap ends
|
|
163
|
+
* the instance that would have finished it. Nothing here writes a file.
|
|
164
|
+
*/
|
|
165
|
+
export declare function reloadSelf(deps: SelfReloadDeps): Promise<SelfReloadOutcome>;
|
|
166
|
+
/**
|
|
167
|
+
* The HTTP answer for an outcome. Every failure says what happened, why and
|
|
168
|
+
* what to do now, in the project's two-language style; the state code is for
|
|
169
|
+
* the page, which decides what to offer next.
|
|
170
|
+
*/
|
|
171
|
+
export declare function selfReloadReply(outcome: SelfReloadOutcome): {
|
|
172
|
+
status: number;
|
|
173
|
+
body: Record<string, unknown>;
|
|
174
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dshmarket",
|
|
3
3
|
"description": "Visual plugin market inside DeepSeek Harness — browse, search, and one-click install community plugins. · DSH 可视化插件市场:逛一逛,点一下,装好。",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.80.0",
|
|
5
5
|
"icon": "assets/logo.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|