dsh-enhance 0.3.7 → 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.
- package/README.md +204 -32
- package/lib/client.js +1841 -97
- package/lib/index.js +45 -44
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
// src/badge-route.ts
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
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
|
|
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.
|
|
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"
|