@hao0311/dsh-toolbox 0.5.1 → 0.5.3
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/CHANGELOG.md +15 -0
- package/README.en.md +75 -0
- package/README.md +88 -86
- package/client.js +30 -2
- package/install.ps1 +10 -0
- package/package.json +10 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# 更新记录
|
|
2
|
+
|
|
3
|
+
## 0.5.3 (2026-11-24)
|
|
4
|
+
|
|
5
|
+
- 新增英文 README(README.en.md),随包一起发布。
|
|
6
|
+
|
|
7
|
+
## 0.5.2 (2026-11-24)
|
|
8
|
+
|
|
9
|
+
修复:
|
|
10
|
+
|
|
11
|
+
- jsonGet 没有超时,上游卡住时请求一直挂着;现在 15 秒超时。
|
|
12
|
+
- 下载流不可中断;改为 AbortSignal.any([中断, 120s])。
|
|
13
|
+
- install.ps1 增加包名规范化,并重新同步安装副本。
|
|
14
|
+
|
|
15
|
+
更早版本的记录见仓库 git 历史。
|
package/README.en.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# dsh-toolbox
|
|
2
|
+
|
|
3
|
+
A toolbox inside the DSH Web GUI: one more row in the left navigation (inside the drawer on phones) that opens a right-side drawer — full screen on phones, closable at any time, with measurements continuing in the background.
|
|
4
|
+
|
|
5
|
+
On desktop the main page **makes room**: the drawer takes width, the chat content shifts left instead of being covered. In narrow windows (content under ~640 px after shifting) the left navigation also collapses into an icon rail, and restores when the panel closes. The drawer width adapts between 424 px and 340 px.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
| Area | What it does |
|
|
10
|
+
|---|---|
|
|
11
|
+
| Connection | Refreshed on open: LAN / loopback / Tailscale / public, client IP, local address, public egress, Wi-Fi band, channel, rate and signal |
|
|
12
|
+
| One-click check | Opening the panel runs a **light** check (~1–2 s, small requests only); the button runs a **full** check (gateway ping, DNS, public egress) and grades it good / fair / poor with suggestions |
|
|
13
|
+
| Speed test | Quick 20 MB / standard 100 MB / extreme 500 MB / 30 s continuous / custom (download, upload, duration). Server-side timing, 4 concurrent streams, live chart — keeps running after you close the panel |
|
|
14
|
+
| Quality monitor | 30 s / 1 min / 3 min low-traffic sampling (a small request every 0.3 s) producing a latency chart, packet loss and stall spikes — for "it feels laggy", not for bandwidth |
|
|
15
|
+
| History | Checks, speed tests and monitors are stored locally (localStorage, last 40), and each speed test is compared with the previous one |
|
|
16
|
+
| Auto patrol | While the page is open, 3 light probes every 3/5/10 minutes; a red dot on the nav entry and an in-panel hint when the network degrades |
|
|
17
|
+
| Share / report | Builds a short summary (connection type, check result, speed, monitor, advice) with one-click copy |
|
|
18
|
+
|
|
19
|
+
## Implementation
|
|
20
|
+
|
|
21
|
+
- **Host `index.js`** registers `/api/toolbox/net/*` through `ctx.connection.fetch.register` (download stream, upload stream, info, diagnostics, server timing, status) and inlines `client.css` / `client.js` into `index.html` via the official `webserver/index-inject` hook. The host reads this file once at startup; CSS and JS are read on every page load, so UI changes need no restart.
|
|
22
|
+
- **Client `client.js`** is pure DOM injection — no React dependency, no layout changes to DSH. The measurement engine is decoupled from the panel: close the panel and the job keeps running; reopen it and you see live state. A dot on the nav row and a 2 px progress line at the top indicate a background job.
|
|
23
|
+
- **Auth**: routes live under `/api` and inherit the connection layer's Host/Origin + cookie checks.
|
|
24
|
+
|
|
25
|
+
## How measurement works
|
|
26
|
+
|
|
27
|
+
| Item | Method |
|
|
28
|
+
|---|---|
|
|
29
|
+
| Download | `GET /api/toolbox/net/download?mb=N` streams N × 1 MiB of random data; the client counts as it reads, and the number is **server-timed** |
|
|
30
|
+
| Upload | `POST /api/toolbox/net/upload`; the browser posts a random Blob, the server counts bytes and returns first-byte → last-byte duration |
|
|
31
|
+
| Latency / jitter / loss | Repeated small requests to `/api/toolbox/net/info`; timeouts count as loss |
|
|
32
|
+
|
|
33
|
+
> Running it on the same machine goes over loopback, where numbers inflate to GB/s levels — the panel labels that case as "local loopback".
|
|
34
|
+
|
|
35
|
+
## Install / update
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
dsh plugin --profile web add github:Hao0311/dsh-toolbox
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
> npm hosts a **different, same-named** package `dsh-toolbox` (stock tracking + novel reader). `dsh plugin add dsh-toolbox` installs the wrong one; use the `github:` source above, or the scoped npm name `@hao0311/dsh-toolbox`.
|
|
42
|
+
|
|
43
|
+
For development, this directory ships a sync script that copies it into `~/.dsh/profiles/web/node_modules/dsh-toolbox/` and adds an `insert:` entry inside a marker block of `cordis.patch.yml` (idempotent):
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
powershell -NoProfile -File D:\Workspaces\DSH\plugins\dsh-toolbox\install.ps1
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- **Only `client.js` / `client.css` changed**: run install.ps1 and reload the page — no DSH restart.
|
|
50
|
+
- **`index.js` changed**: restart DSH (plugins load at startup).
|
|
51
|
+
|
|
52
|
+
## Adding your own tool
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
window.DSHToolbox.register({
|
|
56
|
+
id: 'my-tool', // unique
|
|
57
|
+
title: 'My tool',
|
|
58
|
+
hint: 'one line', // optional
|
|
59
|
+
render(container) { // draw into a plain DOM node
|
|
60
|
+
container.textContent = 'hello';
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Registration order is the order shown under "more tools" at the bottom of the panel.
|
|
66
|
+
|
|
67
|
+
## Self-check
|
|
68
|
+
|
|
69
|
+
- Search the page source for `__DSH_TOOLBOX__` (the host-injected global reporting injected lines and route status).
|
|
70
|
+
- Request `/api/toolbox/net/info` directly; it should return `{ ok: true, ip, host, ... }`.
|
|
71
|
+
- Local verification scripts: `.cdp-verify/cdp-toolbox.js` (desktop/mobile screenshots) and `.cdp-verify/cdp-toolbox-func.js` (click through checks, speed test, monitor, background continuation).
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,86 +1,88 @@
|
|
|
1
|
-
# dsh-toolbox
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
|
15
|
-
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
-
|
|
86
|
-
|
|
1
|
+
# dsh-toolbox
|
|
2
|
+
|
|
3
|
+
> English: [README.en.md](README.en.md)
|
|
4
|
+
|
|
5
|
+
DSH Web GUI 里的工具箱:左侧导航(手机上在抽屉里)多一行「工具箱」,点开是一个右侧抽屉
|
|
6
|
+
(手机端全屏,可随时退出、任务在后台继续)。
|
|
7
|
+
|
|
8
|
+
桌面端打开抽屉时**主页面自动往左让位**:面板多宽,主内容就让出多宽,不会压住聊天;
|
|
9
|
+
窗口较窄(让位后主内容不足约 640px)时会顺手把左侧导航收成图标轨,关面板后自动恢复。
|
|
10
|
+
面板宽度随窗口自适应:424px ~ 340px。
|
|
11
|
+
|
|
12
|
+
## 功能
|
|
13
|
+
|
|
14
|
+
| 功能区 | 做什么 |
|
|
15
|
+
|---|---|
|
|
16
|
+
| 连接状态 | 打开面板自动刷新:局域网 / 本机回环 / Tailscale / 外网、客户端 IP、本机地址、公网出口、Wi-Fi 频段·信道·速率·信号 |
|
|
17
|
+
| 一键体检 | 打面板自动跑一次**轻量**检查(约 1~2 秒,只发小请求);点按钮跑**完整**体检(含网关 ping、DNS、公网出口),给「良好 / 一般 / 较差」结论和建议 |
|
|
18
|
+
| 测速 | 快速 20MB / 标准 100MB / 极限 500MB / 持续 30 秒 / 自定义(下载、上传、时长自选)。服务端计时、4 并发流、实时曲线;关掉面板继续跑 |
|
|
19
|
+
| 质量监控 | 30 秒 / 1 分钟 / 3 分钟低流量采样(每 0.3 秒一个小请求),给延迟曲线、丢包和卡顿尖峰——查「卡」而不是查带宽 |
|
|
20
|
+
| 历史记录 | 体检 / 测速 / 监控自动存本机(localStorage,最近 40 条),测速结果和上一次对比 |
|
|
21
|
+
| 自动巡检 | 页面开着时每 3/5/10 分钟做 3 次轻探测;网络变差时导航入口亮红点,并在面板里提示 |
|
|
22
|
+
| 分享 / 报告 | 生成一段中文总结(连接方式、体检结论、测速、监控、建议),一键复制发人 |
|
|
23
|
+
|
|
24
|
+
## 实现
|
|
25
|
+
|
|
26
|
+
- **宿主端** `index.js`:`ctx.connection.fetch.register` 注册 `/api/toolbox/net/*`
|
|
27
|
+
路由(下载流 / 上传流 / 信息 / 诊断 / 服务端计时 / 状态),并通过官方
|
|
28
|
+
`webserver/index-inject` 把 `client.css`、`client.js` 内联进 `index.html`。
|
|
29
|
+
宿主只在**启动时**读一次本文件;CSS / JS 是每次页面加载现读,所以改界面不用重启。
|
|
30
|
+
- **客户端** `client.js`:纯 DOM 注入,不依赖 React、不改 DSH 布局。
|
|
31
|
+
测量引擎与面板解耦:关掉面板任务照跑,重新打开能看到实时状态;
|
|
32
|
+
入口行的小圆点 / 顶部 2px 进度线表示后台任务。
|
|
33
|
+
- **鉴权**:路由都挂在 `/api` 下,走 connection 层统一的 Host/Origin + cookie 校验。
|
|
34
|
+
|
|
35
|
+
## 测速原理
|
|
36
|
+
|
|
37
|
+
| 项目 | 做法 |
|
|
38
|
+
|---|---|
|
|
39
|
+
| 下载 | `GET /api/toolbox/net/download?mb=N` 流式返回 N×1MiB 随机数据,客户端流式读取计数;数字以**服务端计时**为准 |
|
|
40
|
+
| 上传 | `POST /api/toolbox/net/upload`,浏览器发随机 Blob,服务端边收边计数,返回首字节→末字节耗时 |
|
|
41
|
+
| 延迟 / 抖动 / 丢包 | 连续小请求 `/api/toolbox/net/info`,超时算丢包 |
|
|
42
|
+
|
|
43
|
+
> 电脑本机上打开会走回环,数字会虚高到 GB/s 级别,面板会标「本机回环」提醒。
|
|
44
|
+
|
|
45
|
+
## 安装 / 更新
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
dsh plugin --profile web add github:Hao0311/dsh-toolbox
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> npm 上有 ldchao 的同名包 `dsh-toolbox`(股票盯盘 + 小说阅读器,不是本插件),
|
|
52
|
+
> `dsh plugin add dsh-toolbox` 会装错,务必用上面的 `github:` 来源。
|
|
53
|
+
|
|
54
|
+
开发时用本目录的同步脚本:把本目录同步到 `~/.dsh/profiles/web/node_modules/dsh-toolbox/`,
|
|
55
|
+
并在 `cordis.patch.yml` 的标记块里加入 `insert:` 条目(幂等,重复跑不会重复写)。
|
|
56
|
+
|
|
57
|
+
```powershell
|
|
58
|
+
powershell -NoProfile -File D:\Workspaces\DSH\plugins\dsh-toolbox\install.ps1
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- **只改 `client.js` / `client.css`**:跑 install.ps1 后浏览器刷新即可,**不用重启 DSH**。
|
|
62
|
+
- **改了 `index.js`**:需要重启 DSH(插件只在启动时装载):
|
|
63
|
+
`powershell -NoProfile -File D:\Workspaces\DSH\tools\dsh\dsh-restart.ps1`
|
|
64
|
+
|
|
65
|
+
> 注意:用 PowerShell 5.1 读写本目录的中文文件时别用 `Get-Content`/`Set-Content` 改内容
|
|
66
|
+
> (默认按 ANSI 读会把 UTF-8 中文写坏);改文件用编辑器或 Node 脚本。
|
|
67
|
+
|
|
68
|
+
## 加新工具
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
window.DSHToolbox.register({
|
|
72
|
+
id: 'my-tool', // 唯一
|
|
73
|
+
title: '我的工具',
|
|
74
|
+
hint: '一句话说明', // 可选
|
|
75
|
+
render(container) { // 自己画 UI,container 是一个普通 DOM 节点
|
|
76
|
+
container.textContent = 'hello';
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
注册顺序即面板底部「更多工具」里的显示顺序。
|
|
82
|
+
|
|
83
|
+
## 自检
|
|
84
|
+
|
|
85
|
+
- 页面源码里搜 `__DSH_TOOLBOX__`(宿主注入的 global,报告注入行数与路由状态)。
|
|
86
|
+
- 直接请求 `/api/toolbox/net/info`,应返回 `{ ok: true, ip, host, ... }`。
|
|
87
|
+
- 本地验证脚本:`.cdp-verify/cdp-toolbox.js`(桌面/手机截图)、
|
|
88
|
+
`.cdp-verify/cdp-toolbox-func.js`(点按钮、跑体检/测速/监控、验证后台继续)。
|
package/client.js
CHANGED
|
@@ -127,8 +127,30 @@
|
|
|
127
127
|
return t.length > max ? `${t.slice(0, max - 1)}…` : t;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* 兜底超时信号(2026-11-23)。优先用 AbortSignal.timeout(Edge 103+ 支持),
|
|
132
|
+
* 老浏览器退回 setTimeout + abort。用于那些「本来没有超时」的前端请求:
|
|
133
|
+
* 服务端挂死时,没有超时就会一直挂着、界面停在「进行中」。
|
|
134
|
+
*/
|
|
135
|
+
function timeoutSignal(ms) {
|
|
136
|
+
if (typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function') return AbortSignal.timeout(ms);
|
|
137
|
+
const controller = new AbortController();
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
try {
|
|
140
|
+
controller.abort(new DOMException('timeout', 'TimeoutError'));
|
|
141
|
+
} catch {
|
|
142
|
+
controller.abort();
|
|
143
|
+
}
|
|
144
|
+
}, ms);
|
|
145
|
+
return controller.signal;
|
|
146
|
+
}
|
|
147
|
+
|
|
130
148
|
function jsonGet(path) {
|
|
131
|
-
return fetch(`${API}${path}`, {
|
|
149
|
+
return fetch(`${API}${path}`, {
|
|
150
|
+
cache: 'no-store',
|
|
151
|
+
credentials: 'same-origin',
|
|
152
|
+
signal: timeoutSignal(15000),
|
|
153
|
+
}).then((res) => {
|
|
132
154
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
133
155
|
return res.json();
|
|
134
156
|
});
|
|
@@ -325,10 +347,16 @@
|
|
|
325
347
|
|
|
326
348
|
/** 一条并发下载流:流式读取只计数不落内存(500MB 也不会吃爆手机内存)。 */
|
|
327
349
|
async function downloadStream(job, query, sid, idx, loaded, onFirstByte) {
|
|
350
|
+
// 2026-11-23:除了用户「停止」的 job.abort,再加 120 秒兜底超时。
|
|
351
|
+
// 只有 job.abort 时,服务端挂死且已进入 reader.read() 的情况会一直等下去。
|
|
352
|
+
const signal =
|
|
353
|
+
typeof AbortSignal !== 'undefined' && typeof AbortSignal.any === 'function'
|
|
354
|
+
? AbortSignal.any([job.abort.signal, timeoutSignal(120000)])
|
|
355
|
+
: job.abort.signal;
|
|
328
356
|
const res = await fetch(`${API}/net/download?${query}&sid=${sid}&s=${idx}&t=${Date.now()}`, {
|
|
329
357
|
cache: 'no-store',
|
|
330
358
|
credentials: 'same-origin',
|
|
331
|
-
signal
|
|
359
|
+
signal,
|
|
332
360
|
});
|
|
333
361
|
if (!res.ok) throw new Error(`下载 HTTP ${res.status}`);
|
|
334
362
|
if (!res.body) throw new Error('浏览器不支持流式读取');
|
package/install.ps1
CHANGED
|
@@ -89,6 +89,16 @@ if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $by
|
|
|
89
89
|
[System.IO.File]::WriteAllText($pkg, $t, (New-Object System.Text.UTF8Encoding($false)))
|
|
90
90
|
Write-Host 'stripped BOM from package.json'
|
|
91
91
|
}
|
|
92
|
+
# Normalize the installed package name (2026-11-23): the source package.json now carries the
|
|
93
|
+
# public release name (@hao0311/dsh-toolbox), while the patch entry in cordis.patch.yml says
|
|
94
|
+
# 'dsh-toolbox'. Keep the installed module name identical to the patch entry so DSH plugin
|
|
95
|
+
# validation cannot silently disable it on a name mismatch.
|
|
96
|
+
$pkgText = [System.IO.File]::ReadAllText($pkg, [System.Text.Encoding]::UTF8)
|
|
97
|
+
$pkgNext = [regex]::Replace($pkgText, '"name"\s*:\s*"[^"]*"', '"name": "dsh-toolbox"', 1)
|
|
98
|
+
if ($pkgNext -ne $pkgText) {
|
|
99
|
+
[System.IO.File]::WriteAllText($pkg, $pkgNext, (New-Object System.Text.UTF8Encoding($false)))
|
|
100
|
+
Write-Host 'normalized package.json name -> dsh-toolbox'
|
|
101
|
+
}
|
|
92
102
|
Write-Host "synced $($files.Count) files -> $Dest"
|
|
93
103
|
|
|
94
104
|
# 2) patch entry (idempotent)
|
package/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hao0311/dsh-toolbox",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./index.js"
|
|
8
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"client.js",
|
|
12
|
+
"client.css",
|
|
13
|
+
"install.ps1",
|
|
14
|
+
"README.md",
|
|
15
|
+
"README.en.md",
|
|
16
|
+
"CHANGELOG.md"
|
|
17
|
+
],
|
|
9
18
|
"description": "Toolbox panel for the DeepSeek Harness Web GUI: a right-side drawer (full screen on phones) with connection information, one-click diagnostics, a speed test, a quality monitor, history and auto patrol.",
|
|
10
19
|
"keywords": [
|
|
11
20
|
"dsh",
|