dsh-balance-sentinel 0.1.0 → 0.1.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 +32 -0
- package/README.en.md +9 -6
- package/README.md +9 -6
- package/client.js +249 -59
- package/lib/localapi.js +64 -6
- package/lib/notify.js +21 -7
- package/lib/state.js +74 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +3 -3
- package/package.json +2 -2
- package/scripts/selftest-client.mjs +410 -11
- package/scripts/selftest.mjs +222 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project are documented here. Format follows
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/); versions follow [SemVer](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [0.1.3] - 2026-11-18
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- **限流不再被当成测试失败**:测试请求返回 429(「操作太频繁」)时,面板只提示这句话,不再把没有结果对象的响应当成一次测试结论。此前这类被拒绝的请求会把徽章从「最近测试成功」改成红色失败,抹掉上一次真实结果。
|
|
11
|
+
- **旧轮询不再覆盖更新的状态**:先发出、后返回的 `/status` 在新测试失败或新 Webhook 保存之后落地时,整份过期响应直接丢弃——不会再把失败徽章改回旧的成功,也不会把面板退回旧地址;首次配置时也不会再因此重新弹出已关闭的配置表单。
|
|
12
|
+
- **单独点「发送测试推送」不再与徽章打架**:接口返回失败时,面板立即按响应更新当前通道的徽章与持久化提示,不再等下一次轮询(此前会同时显示「最近测试失败」和旧的「最近测试成功」)。属于其他通道或比当前更旧的结果不会被应用。
|
|
13
|
+
- **旧通道的未落盘结果不再清空新通道的有效记录**:合并改为先按当前通道过滤、再比较时间,避免「较新的旧通道结论先按时间胜出、随后因通道不匹配被丢弃」,连带把磁盘里那条可用记录一起丢掉;读取合并与常规保存两条路径都受影响。
|
|
14
|
+
- **浅色模式下文字太淡**:余额数字改为按皮肤取色(浅色 `#9c5c00` / `#c62828` / `#1f7a35`,白底约 5:1),徽章、错误块与失败原因改用向标签色混合的墨水,不再直接使用白底上约 2:1 的橙色。
|
|
15
|
+
- **「已配置,待测试」不再是一枚灰徽章**:四态各有自己的色 —— 未配置用次要灰、待测试用品牌蓝、最近测试成功用绿、最近测试失败用红;通道前的圆点与徽章同色,并带一圈淡光晕,不靠单一色相也能分辨。失败说明改用与错误块相同的混色墨水,避免宿主把 error 令牌调成粉色后 11.5px 处看不清。
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **面板跟随宿主深浅色**:读取 `body[data-ds-dark-theme]`(DSH 自身与 dsh-context 使用的同一约定),浅色皮肤换用白色卡片、细描边与宿主一级投影,深色皮肤保持原来的层级底色。卡片/徽章/浮层/错误块的底色改用 `color-mix()` 从 `--dsw-alias-*` 派生,不再使用只在深色下校准过的 `rgba()`;原生下拉菜单的 `colorScheme` 与告警红字也按皮肤切换,不再依赖 `prefers-color-scheme`。徽章文字改为把语义色向标签色混合,浅色卡片上不再发白。
|
|
20
|
+
|
|
21
|
+
## [0.1.2] - 2026-11-17
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **保存失败不再卡死**:服务端返回错误后,「仅保存」「保存并测试」「保存阈值」「关闭推送」的按钮曾停在「保存中…」并保持禁用。现在所有保存路径都用 `finally` 清理忙碌态,「保存并测试」从保存切到测试期间也不再闪回可用状态。
|
|
26
|
+
- **重新进入面板时阈值输入框为空**:草稿的「是否被编辑」判断写在 `setState` 的函数式更新里,而 React 要等下一次渲染才执行它——此时闭包变量已被下一行代码改写成新值,条件恒为假,两个输入框就停在空字符串并显示「需为正数」的红字。改为用 `useRef` 同步判断,并让未编辑的草稿直接回落到服务端阈值渲染,任何加载延迟都不会再出现空输入框。
|
|
27
|
+
- **测试结果不再张冠李戴**:A 地址测试还没返回时,另一页面保存了 B 地址,A 的成功会被记到 B 头上。现在用 `channel|url|secret` 的哈希把裁决钉在具体配置上,返回时若发现配置已变更就丢弃结果,并在面板提示「测试期间推送配置已变更,本次结果未计入当前通道」。该指纹只留在服务端,`/status` 不返回。
|
|
28
|
+
- **失败的测试不会被旧成功掩盖**:此前测试成功、本次失败且状态文件写入失败时,面板仍显示绿色的「最近测试成功」。现在无论写盘是否成功都会立即更新内存中的裁决,写盘失败再额外标注「结果未写入状态文件,重启后会丢失」;随后监控周期的读取合并与写回(`mergeStateFromDisk` 与 `saveState`)都不会把这条未持久化的较新裁决换回旧记录 —— 这一轮补存成功则转为已持久化,仍失败则继续标注;配置一旦变化则连同裁决一起失效。
|
|
29
|
+
- **「已配置」不再暗示发送成功**:面板区分「已配置,待测试」「最近测试成功」「最近测试失败(含原因与时间)」,改通道或凭据会立即清除旧结果,避免用一条从未验证过的 webhook 冒充已接通。
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- 通知署名保持原样文字(`安装:github:liancheng2020/dsh-balance-sentinel`),只把其中的仓库标识做成可点击链接:markdown 通道直接可点,飞书卡片脚注改用 `lark_md`,纯文本通道(Bark/Telegram/通用)只保留标识、不附网址(正文里的裸 URL 不受影响);`notify.signature: false` 仍可整体关闭,`signatureText` 可换文案。
|
|
34
|
+
- 文案更准确:README 与面板的「免 Key」改为「支持宿主账号免填 Key」,「不漏发」改为「失败可追踪、可重试」(推送仍按原去重规则不重发)。
|
|
35
|
+
|
|
6
36
|
## [0.1.0] - 2026-11-17
|
|
7
37
|
|
|
8
38
|
首个发布版。仓库历史自 `22bb4d1` 起至本版发布提交,对应本版本的全部内容;后续改动在下一版
|
|
@@ -39,4 +69,6 @@ All notable changes to this project are documented here. Format follows
|
|
|
39
69
|
- README 面板截图前置、补「先看三行」要点;适用范围与免 Key 边界并入安装节,不再单列小节。
|
|
40
70
|
- GitHub About 描述收紧为一句:低余额推送 + 本机运行边界。
|
|
41
71
|
|
|
72
|
+
[0.1.3]: https://github.com/liancheng2020/dsh-balance-sentinel/releases/tag/v0.1.3
|
|
73
|
+
[0.1.2]: https://github.com/liancheng2020/dsh-balance-sentinel/releases/tag/v0.1.2
|
|
42
74
|
[0.1.0]: https://github.com/liancheng2020/dsh-balance-sentinel/releases/tag/v0.1.0
|
package/README.en.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](https://github.com/liancheng2020/dsh-balance-sentinel#readme)
|
|
11
11
|
|
|
12
|
-
**DeepSeek balance
|
|
12
|
+
A DeepSeek Harness plugin: **DeepSeek balance monitoring** + **two-tier low-balance alerts pushed to Feishu / DingTalk and more** + **key-free on hosts with the built-in account service, zero runtime dependencies**
|
|
13
13
|
|
|
14
14
|
> **Three lines first**
|
|
15
15
|
> - **Monitored while DSH runs**, stops when it exits; no remote web panel
|
|
@@ -32,29 +32,32 @@ dsh plugin --profile web add github:liancheng2020/dsh-balance-sentinel
|
|
|
32
32
|
# or npm (published to npm alongside each Release)
|
|
33
33
|
dsh plugin --profile web add dsh-balance-sentinel
|
|
34
34
|
# or the pinned Release tarball
|
|
35
|
-
dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.
|
|
35
|
+
dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.3/dsh-balance-sentinel-0.1.3.tgz
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Any one of the three is enough; if the npm/Release line is not live yet, use the first. Desktop app: Settings → Plugins → add `dsh-balance-sentinel` or `github:liancheng2020/dsh-balance-sentinel`. Restart DSH once.
|
|
39
39
|
|
|
40
|
-
**Where it runs**: local DSH desktop or local web host only — monitoring lives in the DSH process and **stops when DSH exits** (reopening resumes from the local state file); **no remote web panel** (the bridge binds `127.0.0.1:17430` and only accepts pages from this machine). **
|
|
40
|
+
**Where it runs**: local DSH desktop or local web host only — monitoring lives in the DSH process and **stops when DSH exits** (reopening resumes from the local state file); **no remote web panel** (the bridge binds `127.0.0.1:17430` and only accepts pages from this machine). **Key-free host accounts are supported**: the host must expose the account service with a signed-in account (key-free ≠ account-free); otherwise use `DEEPSEEK_API_KEY` or `balance.apiKey` — with neither, the panel states the exact reason.
|
|
41
41
|
|
|
42
|
-
> Current version `0.1.
|
|
42
|
+
> Current version `0.1.3` (see [CHANGELOG](CHANGELOG.md)).
|
|
43
43
|
|
|
44
44
|
## First use (two steps)
|
|
45
45
|
|
|
46
46
|
1. Open the **Balance Sentinel** panel: your real balance immediately, or a clear reason (signed out / no account service / network…).
|
|
47
47
|
2. Pick a channel, paste the webhook (auto-detected) → **Save and send test**. The Feishu/DingTalk form includes "How to get a bot webhook": official doc + three-step path + the security settings that channel supports. **Until a channel is saved it watches without pushing**.
|
|
48
48
|
|
|
49
|
+
Saving only gets you to "configured, not tested"; the badge turns into "last test succeeded" once a test push actually lands, and into "last test failed" (with the reason and time) when it does not. Editing the channel or credentials clears the old result, so a stale "verified" can never pass for a working endpoint.
|
|
50
|
+
|
|
49
51
|
If the balance is already below a threshold when you connect, one current-state notice is sent (once).
|
|
50
52
|
|
|
51
53
|
## How it works
|
|
52
54
|
|
|
53
55
|
- **Two levels**: below 20 pushes "warn", below 5 pushes "critical" (account currency, panel-editable); a top-up or a threshold tweak back above warn pushes one "recovered"/"resolved" notice, effective immediately on save.
|
|
54
56
|
- **No spam**: same level never repeats; a real top-up pushes "recovered" (10-min anti-flap cooldown); a threshold tweak that resolves a delivered alert pushes "resolved" immediately; undelivered alerts cancel silently; quiet hours defer and merge into a single push afterwards.
|
|
55
|
-
- **
|
|
57
|
+
- **Failures are traceable and retryable**: pending alerts persist; business failures back off 10 min and hold after 3 (manual retry in the panel); timeouts and dead response bodies are "delivery unconfirmed" — held immediately, never auto re-sent; a failed state save writes a fallback receipt, so restarts and multiple instances still do not re-send it (unconfirmed restores as held, never as sent). If neither the state nor the receipt can be written, the duplicate risk is logged explicitly.
|
|
56
58
|
- **No wedge, no duplicate across instances**: host queries have a 15s deadline and the scheduler survives any exception; desktop + web sharing `DSH_HOME` push each transition exactly once (whole-cycle lock + disk merge).
|
|
57
59
|
- **Channels**: WeCom / DingTalk / Feishu (card) / Bark / ServerChan / Telegram / generic webhook; auto-chunking; HTTP-200 business failures count as failures.
|
|
60
|
+
- **Follows the host skin**: the panel reads `data-ds-dark-theme`, so a light skin gets white cards, hairline borders and a soft shadow, with badges, toasts and native select menus switching with it.
|
|
58
61
|
- Balance is the **official account number**; v1 ships no cost estimates.
|
|
59
62
|
|
|
60
63
|
## Config (optional, profile cordis.patch.yml)
|
|
@@ -72,7 +75,7 @@ If the balance is already below a threshold when you connect, one current-state
|
|
|
72
75
|
quiet: { start: "", end: "" } # e.g. "23:00"–"08:00"
|
|
73
76
|
apiKey: "" # fallback for older hosts only
|
|
74
77
|
notify:
|
|
75
|
-
signature: true # "via
|
|
78
|
+
signature: true # "via …" footer line whose install spec is tappable, opt-out
|
|
76
79
|
signatureText: ""
|
|
77
80
|
localApi:
|
|
78
81
|
enabled: true # panel bridge on 127.0.0.1:17430
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](https://github.com/liancheng2020/dsh-balance-sentinel#readme)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
DSH 插件:**DeepSeek 余额监控** + **低余额两级告警推送到飞书/钉钉等 IM** + **支持宿主账号免填 Key、零运行时依赖**
|
|
13
13
|
|
|
14
14
|
> **先看三行**
|
|
15
15
|
> - **DSH 运行期间监控**,关闭即停;不支持远程 Web 面板
|
|
@@ -32,29 +32,32 @@ dsh plugin --profile web add github:liancheng2020/dsh-balance-sentinel
|
|
|
32
32
|
# 或 npm(随 Release 一同发布到 npm)
|
|
33
33
|
dsh plugin --profile web add dsh-balance-sentinel
|
|
34
34
|
# 或 Release 固定版本 tarball
|
|
35
|
-
dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.
|
|
35
|
+
dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.3/dsh-balance-sentinel-0.1.3.tgz
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
三条任选一条即可;若 npm/Release 那条还没上线,用第一条。桌面端:设置 → 插件 → 添加插件,填 `dsh-balance-sentinel` 或 `github:liancheng2020/dsh-balance-sentinel`。装完重启一次 DSH。
|
|
39
39
|
|
|
40
|
-
**适用环境**:仅本机 DSH Desktop/本机 Web,监控跑在 DSH 进程里、**退出即停**(重开从本机状态继续);**不支持远程 Web 面板**(桥接只绑 `127.0.0.1:17430
|
|
40
|
+
**适用环境**:仅本机 DSH Desktop/本机 Web,监控跑在 DSH 进程里、**退出即停**(重开从本机状态继续);**不支持远程 Web 面板**(桥接只绑 `127.0.0.1:17430`,只接受本机页面)。**支持宿主账号免填 Key**:宿主内置账号服务且已登录(免填 ≠ 无需账户),否则用 `DEEPSEEK_API_KEY` 或 `balance.apiKey`,都没有时面板给出明确原因。
|
|
41
41
|
|
|
42
|
-
> 当前版本 `0.1.
|
|
42
|
+
> 当前版本 `0.1.3`(见 [CHANGELOG](CHANGELOG.md))。
|
|
43
43
|
|
|
44
44
|
## 首次使用(两步接通)
|
|
45
45
|
|
|
46
46
|
1. 打开 **余额哨兵** 面板:立刻看到真实余额,或明确原因(未登录 / 无账号服务 / 网络…)。
|
|
47
47
|
2. 「推送配置」选通道 → 粘 webhook(自动识别)→ **保存并发送测试**。飞书/钉钉框内有「如何获取机器人 Webhook」:官方链接 + 三步路径 + 该通道适用的安全设置。**没配通道前只监控不推送**。
|
|
48
48
|
|
|
49
|
+
保存成功只说明通道「已配置,待测试」,测试推送真的送达才会变成「最近测试成功」;失败则显示「最近测试失败」并附原因与时间。改通道或凭据后旧结果立即清除,不会有残留的「已验证」冒充接通。
|
|
50
|
+
|
|
49
51
|
接通时余额已低于阈值,会补发一条当前状态(仅一次)。
|
|
50
52
|
|
|
51
53
|
## 它怎么工作
|
|
52
54
|
|
|
53
55
|
- **两级阈值**:默认低于 ¥20 推「预警」、低于 ¥5 推「告急」(账户币种,面板可改);充值或调阈值回到预警之上推一条「恢复/解除」,保存即生效。
|
|
54
56
|
- **不刷屏**:同级停留不重推;充值回升推「恢复」(10 分钟冷却防抖),调阈值解除已送达告警立即推「解除」;告警未送达时静默取消;免打扰时段顺延、出窗合并成一条。
|
|
55
|
-
-
|
|
57
|
+
- **失败可追踪、可重试**:待发送告警持久化;业务失败 10 分钟退避、3 次后挂起可手动重试;超时等「送达不确定」立即挂起、不自动重发;状态保存失败时落盘备用回执,重启/多实例恢复后仍不重发(不确定的恢复为挂起,不标记成功)。状态与回执都无法落盘时会明确告警「去重无法保证」。
|
|
56
58
|
- **不卡死、多实例不重推**:宿主查询 15s 兜底,任何异常后调度继续;desktop + web 共享 `DSH_HOME` 时整周期锁 + 磁盘合并,同一跃迁只推一次。
|
|
57
59
|
- **通道**:企微 / 钉钉 / 飞书(消息卡片)/ Bark / Server酱 / Telegram / 通用 Webhook;超长自动分条;HTTP 200 但业务失败同样判失败。
|
|
60
|
+
- **跟随宿主深浅色**:面板读 `data-ds-dark-theme`,浅色皮肤用白卡片+细描边+轻投影,卡片、徽章、浮层与原生下拉菜单同步换色。
|
|
58
61
|
- 余额来自**官方账户同源**,v1 不做成本估算。
|
|
59
62
|
|
|
60
63
|
## 配置(可选,profile 的 cordis.patch.yml)
|
|
@@ -72,7 +75,7 @@ dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentin
|
|
|
72
75
|
quiet: { start: "", end: "" } # 免打扰,如 "23:00"–"08:00"
|
|
73
76
|
apiKey: "" # 仅老宿主回落用;优先宿主账号/环境变量
|
|
74
77
|
notify:
|
|
75
|
-
signature: true #
|
|
78
|
+
signature: true # 推送尾部署名(安装标识可点击),可关
|
|
76
79
|
signatureText: ""
|
|
77
80
|
localApi:
|
|
78
81
|
enabled: true # 面板桥接 127.0.0.1:17430,可关
|