dsh-split-workspace 0.4.3 → 0.8.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.
Files changed (4) hide show
  1. package/README.md +310 -4
  2. package/lib/client.js +2010 -84
  3. package/lib/index.js +154 -6
  4. package/package.json +17 -5
package/lib/index.js CHANGED
@@ -1,11 +1,159 @@
1
1
  /**
2
2
  * Host half of dsh-split-workspace.
3
3
  *
4
- * The whole feature lives in the browser: the top page owns the split shell and
5
- * re-hosts the stock conversation primitives for each pane's session, in-process.
6
- * This half exists so the bundle owns a real Loader row, which is what the
7
- * Plugin Manager and the Settings inventory display.
4
+ * The split workspace itself lives entirely in the browser. This half adds the
5
+ * one thing a renderer cannot build on its own: a URL for a REAL separate
6
+ * window that shows a single conversation.
7
+ *
8
+ * Why a URL and not a BrowserWindow: DSH Desktop runs this Host in a Node child
9
+ * process (no Electron APIs), and its main window denies `window.open` except
10
+ * for http/https, which it forwards to the system browser. The Host therefore
11
+ * returns the authenticated Web GUI URL (`?token=…`) with a `#dsvWindow=<id>`
12
+ * marker; the renderer opens it, and the client half renders only that one
13
+ * conversation inside the new system window. In the Web profile the same route
14
+ * works and `window.open` opens a normal browser window.
15
+ *
16
+ * It also serves the on-disk plugin version so a running page can notice a
17
+ * freshly installed bundle and offer "reload interface" instead of requiring a
18
+ * full DSH restart.
8
19
  */
9
20
 
10
- /** @param {import('@deepseek-ai/cordis').Context} _ctx */
11
- export function apply(_ctx) {}
21
+ import { readFileSync } from "node:fs";
22
+
23
+ const ROUTE_PATH = "/dsv/system-window";
24
+ const VERSION_PATH = "/dsv/version";
25
+ const MAX_BODY_BYTES = 64 * 1024;
26
+ const SESSION_ID = /^[A-Za-z0-9._:@+-]+$/;
27
+ const MAX_SESSION_ID_LENGTH = 256;
28
+
29
+ /** The plugin version currently on disk (not the one this process loaded). */
30
+ function packageVersion() {
31
+ try {
32
+ const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
33
+ return typeof manifest.version === "string" && manifest.version !== "" ? manifest.version : null;
34
+ } catch {
35
+ return null;
36
+ }
37
+ }
38
+
39
+ /** Read and JSON-parse a small request body. */
40
+ function readJsonBody(req) {
41
+ return new Promise((resolve, reject) => {
42
+ let size = 0;
43
+ const chunks = [];
44
+ req.on("data", (chunk) => {
45
+ size += chunk.length;
46
+ if (size > MAX_BODY_BYTES) {
47
+ reject(new Error("request body too large"));
48
+ req.destroy();
49
+ return;
50
+ }
51
+ chunks.push(chunk);
52
+ });
53
+ req.on("end", () => {
54
+ try {
55
+ const text = Buffer.concat(chunks).toString("utf8");
56
+ resolve(text === "" ? {} : JSON.parse(text));
57
+ } catch (error) {
58
+ reject(error);
59
+ }
60
+ });
61
+ req.on("error", reject);
62
+ });
63
+ }
64
+
65
+ function respond(res, status, value) {
66
+ try {
67
+ res.writeHead(status, {
68
+ "content-type": "application/json; charset=utf-8",
69
+ "cache-control": "no-store",
70
+ });
71
+ res.end(JSON.stringify(value));
72
+ } catch {}
73
+ }
74
+
75
+ /** @param {import('@deepseek-ai/cordis').Context} ctx */
76
+ export function apply(ctx) {
77
+ const getService = (name) => {
78
+ try {
79
+ return typeof ctx.get === "function" ? ctx.get(name) : undefined;
80
+ } catch {
81
+ return undefined;
82
+ }
83
+ };
84
+
85
+ /** The current authenticated Web GUI URL with the standalone-window marker. */
86
+ const standaloneUrl = (sessionId) => {
87
+ const app = getService("webApp");
88
+ const connection = getService("connection");
89
+ const origin = app !== null && app !== undefined && typeof app.getAdvertisedUrl === "function"
90
+ ? app.getAdvertisedUrl()
91
+ : null;
92
+ if (typeof origin !== "string" || origin === "") return null;
93
+ let base = origin;
94
+ if (connection !== null && connection !== undefined && typeof connection.authenticatedUrl === "function") {
95
+ const authenticated = connection.authenticatedUrl(origin);
96
+ if (typeof authenticated === "string" && authenticated !== "") base = authenticated;
97
+ }
98
+ const url = new URL(base);
99
+ url.hash = "dsvWindow=" + encodeURIComponent(sessionId);
100
+ return url.href;
101
+ };
102
+
103
+ ctx.inject(["webServer"], (webCtx) => {
104
+ webCtx.effect(() => {
105
+ const disposeWindow = webCtx.webServer.register({
106
+ kind: "exact",
107
+ path: ROUTE_PATH,
108
+ handler: async (req, res) => {
109
+ if (req.method !== "POST") {
110
+ respond(res, 405, { ok: false, error: "method" });
111
+ return;
112
+ }
113
+ let body;
114
+ try {
115
+ body = await readJsonBody(req);
116
+ } catch {
117
+ respond(res, 400, { ok: false, error: "body" });
118
+ return;
119
+ }
120
+ const sessionId = body !== null && typeof body === "object" ? body.sessionId : undefined;
121
+ if (typeof sessionId !== "string" || sessionId === "" || sessionId.length > MAX_SESSION_ID_LENGTH || !SESSION_ID.test(sessionId)) {
122
+ respond(res, 400, { ok: false, error: "session" });
123
+ return;
124
+ }
125
+ try {
126
+ const url = standaloneUrl(sessionId);
127
+ if (url === null) {
128
+ respond(res, 503, { ok: false, error: "unavailable" });
129
+ return;
130
+ }
131
+ respond(res, 200, { ok: true, url });
132
+ } catch (error) {
133
+ respond(res, 500, { ok: false, error: String(error !== null && error !== undefined && error.message !== undefined ? error.message : error).slice(0, 200) });
134
+ }
135
+ },
136
+ });
137
+ const disposeVersion = webCtx.webServer.register({
138
+ kind: "exact",
139
+ path: VERSION_PATH,
140
+ handler: (req, res) => {
141
+ if (req.method !== "GET" && req.method !== "HEAD") {
142
+ respond(res, 405, { ok: false, error: "method" });
143
+ return;
144
+ }
145
+ const version = packageVersion();
146
+ if (version === null) {
147
+ respond(res, 503, { ok: false, error: "version" });
148
+ return;
149
+ }
150
+ respond(res, 200, { ok: true, version });
151
+ },
152
+ });
153
+ return () => {
154
+ try { disposeWindow(); } catch {}
155
+ try { disposeVersion(); } catch {}
156
+ };
157
+ }, "split-workspace: host routes");
158
+ });
159
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-split-workspace",
3
- "version": "0.4.3",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
- "description": "Split-screen workspace for DeepSeek Harness (DSH) Desktop: unlimited native panes, side-by-side, stacked and 2×2 grid layouts, drag to rearrange.",
5
+ "description": "Split-screen workspace for DeepSeek Harness (DSH) Desktop: unlimited native panes, side-by-side, stacked and 2×2 grid layouts, drag to rearrange, movable floating windows, OS-level standalone system windows, and a performance mode for slow machines.",
6
6
  "icon": "./icon.svg",
7
7
  "license": "MIT",
8
8
  "author": "mhlywxl",
@@ -64,6 +64,8 @@
64
64
  "split-pane",
65
65
  "multi-pane",
66
66
  "multi-session",
67
+ "floating-window",
68
+ "picture-in-picture",
67
69
  "panes",
68
70
  "workspace",
69
71
  "layout",
@@ -71,10 +73,18 @@
71
73
  "tiling",
72
74
  "desktop",
73
75
  "分屏",
76
+ "浮窗",
74
77
  "多窗格",
75
78
  "多会话",
76
79
  "多窗口",
77
- "田字布局"
80
+ "独立窗口",
81
+ "田字布局",
82
+ "system-window",
83
+ "standalone-window",
84
+ "系统窗口",
85
+ "performance-mode",
86
+ "性能模式",
87
+ "low-spec"
78
88
  ],
79
89
  "peerDependencies": {
80
90
  "react": "^18.0.0"
@@ -85,8 +95,10 @@
85
95
  }
86
96
  },
87
97
  "scripts": {
88
- "test": "node test.mjs",
89
- "check": "node --check lib/client.js && node test.mjs",
98
+ "build": "node scripts/build-client.mjs",
99
+ "build:check": "node scripts/build-client.mjs --check",
100
+ "test": "node scripts/build-client.mjs --check && node test.mjs",
101
+ "check": "node scripts/build-client.mjs --check && node --check lib/client.js && node test.mjs",
90
102
  "pack:check": "npm pack --dry-run"
91
103
  }
92
104
  }