dsh-enhance 0.3.8 → 0.3.9

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 +201 -36
  2. package/lib/client.js +1177 -81
  3. package/lib/index.js +45 -44
  4. package/package.json +2 -1
package/lib/index.js CHANGED
@@ -1,16 +1,10 @@
1
1
  // src/badge-route.ts
2
- /**
3
- * The one path the browser half and the Host half share for the Dock badge.
4
- *
5
- * The two halves are separate bundles (node ESM for the Host, a module-table
6
- * factory for the page) and cannot call each other directly, so the count
7
- * travels over the Host's own HTTP surface: the page POSTs it, the Host paints
8
- * the Dock tile. Keeping the path in one module is what stops the two halves
9
- * from drifting apart silently — a mismatch would look exactly like a badge
10
- * that never appears.
11
- */
12
- /** Host route that paints the Dock badge; also the URL the page POSTs to. */
13
- const BADGE_ROUTE = "/dsh-enhance/badge";
2
+ /** Return the badge route for one surface. */
3
+ function badgeRouteFor(surface) {
4
+ return surface === "ds-bot" ? "/ds-bot-enhance/badge" : "/dsh-enhance/badge";
5
+ }
6
+ /** DSH route, kept for callers and tests that predate surfaces. */
7
+ const BADGE_ROUTE = badgeRouteFor("dsh");
14
8
  // src/index.ts
15
9
  /** Largest request body this route reads; the payload is one small number. */
16
10
  const MAX_BODY = 2048;
@@ -58,49 +52,56 @@ async function paintDockBadge(count) {
58
52
  }
59
53
  }
60
54
  /**
61
- * Mount the badge route on the Host's web server.
55
+ * Mount one badge route per surface on the Host's web server.
62
56
  * @param ctx - host context carrying `webServer` and `connection`.
63
57
  */
64
58
  function apply(ctx) {
65
59
  const scope = ctx;
66
- /** Register the route once the services it needs are present. */
60
+ /** Register the routes once the services they need are present. */
67
61
  const install = (host) => {
68
62
  const webServer = host.webServer;
69
63
  const connection = host.connection;
70
64
  if (webServer === void 0 || connection === void 0) return;
71
- /** One route: read the reported count and paint the native tile. */
72
- const register = () => webServer.register({
73
- kind: "exact",
74
- path: BADGE_ROUTE,
75
- async handler(req, res) {
76
- const rejection = connection.requestRejection(req);
77
- if (rejection !== void 0) {
78
- res.writeHead(rejection);
79
- res.end();
80
- return;
81
- }
82
- if (req.method !== "POST") {
83
- res.writeHead(405, { "content-type": "application/json" });
84
- res.end("{\"ok\":false}");
85
- return;
86
- }
87
- const count = await readCount(req);
88
- if (count === void 0) {
89
- res.writeHead(400, { "content-type": "application/json" });
90
- res.end("{\"ok\":false}");
91
- return;
92
- }
93
- const painted = await paintDockBadge(count);
94
- res.writeHead(200, { "content-type": "application/json" });
95
- res.end(JSON.stringify({
96
- ok: true,
97
- painted
98
- }));
65
+ /** Read the reported count and paint the native tile. */
66
+ const handler = async (req, res) => {
67
+ const rejection = connection.requestRejection(req);
68
+ if (rejection !== void 0) {
69
+ res.writeHead(rejection);
70
+ res.end();
71
+ return;
72
+ }
73
+ if (req.method !== "POST") {
74
+ res.writeHead(405, { "content-type": "application/json" });
75
+ res.end("{\"ok\":false}");
76
+ return;
77
+ }
78
+ const count = await readCount(req);
79
+ if (count === void 0) {
80
+ res.writeHead(400, { "content-type": "application/json" });
81
+ res.end("{\"ok\":false}");
82
+ return;
99
83
  }
100
- });
84
+ const painted = await paintDockBadge(count);
85
+ res.writeHead(200, { "content-type": "application/json" });
86
+ res.end(JSON.stringify({
87
+ ok: true,
88
+ painted
89
+ }));
90
+ };
91
+ /** One exact route per surface; the page picks its own. */
92
+ const register = () => {
93
+ const stops = [BADGE_ROUTE, badgeRouteFor("ds-bot")].map((path) => webServer.register({
94
+ kind: "exact",
95
+ path,
96
+ handler
97
+ }));
98
+ return () => {
99
+ for (const stop of stops) stop();
100
+ };
101
+ };
101
102
  const effect = host.effect;
102
103
  if (typeof effect === "function") {
103
- effect(register, "dsh-enhance: dock badge route");
104
+ effect(register, "dsh-enhance: dock badge routes");
104
105
  return;
105
106
  }
106
107
  register();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-enhance",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "DeepSeek Harness enhancements: Markdown theme for every renderer, select-text annotations with pins, a file right-click menu, a narrower sidebar, and startup defaults (maximized window, narrowest sidebar, colourful running marker). 中文:DSH 增强插件——Markdown 主题、划词批注、文件右键菜单、侧栏宽度、启动默认状态。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -65,6 +65,7 @@
65
65
  "url": "https://github.com/laughmaker/dsh-enhance/issues"
66
66
  },
67
67
  "devDependencies": {
68
+ "jsdom": "^31.0.0",
68
69
  "tsdown": "^0.22.2",
69
70
  "typescript": "^5.6.0",
70
71
  "vitest": "^4.1.11"