dsh-usage-peak 0.0.0-stage → 1.1.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.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/assets/sidebar-pill.webp +0 -0
- package/client.js +934 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +6 -0
- package/index.js +539 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +70 -4
- package/test/core.test.js +184 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
- 新增 7 / 14 / 30 天统计窗口切换,接口支持 `?days=`(白名单校验,快照按窗口分别缓存)。
|
|
6
|
+
- 趋势图改为连续日期窗口,没有请求的日期补零,列数不再随数据缺失缩水。
|
|
7
|
+
- 新增「谷时更省」指标:峰时单价为谷时 2 倍,展示峰时用量改到谷时能省下的金额(今日 + 近 7 天)。
|
|
8
|
+
- 修复近 7 天卡片把 tokens 当金额显示(「平均每次 ¥102485.00」),改为日均花费 + 平均每次 tokens。
|
|
9
|
+
- 英文界面本地化补齐:图表 tooltip、命中价说明、万/亿改为 K/M/B、倒计时分钟后缀。
|
|
10
|
+
- 未识别模型的提示改为结构化 warning,由客户端按语言渲染。
|
|
11
|
+
- 宿主拆出可测试的纯函数(`aggregateTurns` / `parseSessionTurns` / `dayKey` 等),新增 `node:test` 测试与 `npm test` / `npm run check` 脚本。
|
|
12
|
+
|
|
13
|
+
## 1.0.1
|
|
14
|
+
|
|
15
|
+
- 修复冷启动后数据路由不存在的 404(宿主半声明 `inject = ['webServer']`,等 HTTP 载体就绪再注册路由)。
|
|
16
|
+
- 客户端首次拉取失败时改为 5 秒后重试,不再卡在「读取失败」等一分钟。
|
|
17
|
+
- 移除调试用的 `/diag` 路由。
|
|
18
|
+
|
|
19
|
+
## 1.0.0
|
|
20
|
+
|
|
21
|
+
- 首个版本:峰谷状态、今日花费/tokens/缓存命中/峰时占比、余额。
|
|
22
|
+
- 侧栏常驻胶囊(独立一行,点击打开面板;折叠时小圆点)。
|
|
23
|
+
- 设置页仪表盘:24 小时分布、花费构成、近 14 天趋势、按模型统计、价目表。
|
|
24
|
+
- 多帧 zstd 会话日志解码,无需 `zstd` 命令行;15 秒快照缓存,支持强制刷新。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DSH Usage Dashboard contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 用量峰谷仪表盘(DSH Usage Dashboard)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
给 DeepSeek Harness 用的用量/花费仪表盘:一眼看清现在是不是**峰时**、今天花了多少钱、烧了多少 tokens,以及钱到底花在缓存、全价输入还是输出上。
|
|
4
|
+
|
|
5
|
+
全部在本地读取 DSH 自己的会话日志,不联网、不上报。
|
|
6
|
+
|
|
7
|
+
## 效果
|
|
8
|
+
|
|
9
|
+
侧栏常驻一行:峰/谷、今日花费、tokens、距离下次切价的时间,一眼看完。
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## 功能
|
|
14
|
+
|
|
15
|
+
- **侧栏常驻胶囊**:`● 峰 ¥14.70 · 12.8M tok · 2:43 后转谷`,点一下打开完整面板。侧栏折叠时收成一个小圆点。
|
|
16
|
+
- **峰谷状态**:当前时段、距离下次切换的倒计时、当前时段单价(缓存命中 / 全价输入 / 输出)。
|
|
17
|
+
- **今日概况**:花费、请求数、tokens、缓存命中率、峰时花费占比、**谷时更省**(把这些峰时用量挪到谷时能省下的钱)、余额。
|
|
18
|
+
- **今日 24 小时分布**:每小时花费柱状,峰时与谷时用不同颜色,当前小时高亮。
|
|
19
|
+
- **花费构成**:缓存命中 / 全价输入 / 输出 三段占比,直接看出钱花在哪。
|
|
20
|
+
- **近 7 / 14 / 30 天趋势**:右上角切换窗口,按天堆叠柱状,缺数据的日期补零,列数恒定;可对照峰时占比判断"贵在哪天"。
|
|
21
|
+
- **按模型**:Flash / Pro 各自的请求数、tokens、花费。
|
|
22
|
+
- **价目表**:当前时段那一行高亮,方便解释账单。
|
|
23
|
+
|
|
24
|
+
设置页里的入口是「用量仪表盘」,侧栏胶囊就是同一份数据的浓缩版。
|
|
25
|
+
|
|
26
|
+
## 价格模型
|
|
27
|
+
|
|
28
|
+
单位:元 / 百万 tokens,`[谷时, 峰时]`。
|
|
29
|
+
|
|
30
|
+
| 模型 | 缓存命中 | 全价输入 | 输出 |
|
|
31
|
+
| --- | --- | --- | --- |
|
|
32
|
+
| DeepSeek Flash | 0.02 / 0.04 | 1 / 2 | 4 / 8 |
|
|
33
|
+
| DeepSeek Pro | 0.15 / 0.30 | 4.5 / 9 | 13.5 / 27 |
|
|
34
|
+
|
|
35
|
+
峰时 = 周一至周五 09:00–12:00、14:00–18:00(北京时间);其余时间、周末与节假日为谷时,单价减半。
|
|
36
|
+
|
|
37
|
+
## 数据来源
|
|
38
|
+
|
|
39
|
+
- `~/.dsh/sessions/<项目 slug>/<会话 id>/session.v4.jsonl.zstd`:每条 `assistant/message` 的 `usage`(输入、缓存读取、输出)与模型,按请求发生的时刻判断峰谷。
|
|
40
|
+
- `~/.dsh/.dshw-usage.json`:鲸鱼记账本的余额与当日花费,用作交叉校验。
|
|
41
|
+
|
|
42
|
+
日志是**多帧 zstd**,Node 自带的 `zlib.zstdDecompressSync` 只解第一帧,所以插件内部按 zstd magic 切帧、逐帧解压再拼接(不需要 `zstd` 命令行)。
|
|
43
|
+
|
|
44
|
+
数据接口支持 `?days=7|14|30` 选择统计窗口(默认 14,白名单之外的取值回落到 14);快照按窗口分别缓存 15 秒,面板上的「刷新」按钮会带 `?fresh=1` 强制重算。
|
|
45
|
+
|
|
46
|
+
峰时单价恰为谷时 2 倍,所以「谷时更省」= 峰时花费 ÷ 2:它衡量的是这些峰时用量如果改在谷时发生能省多少,而不是已经省下的钱。
|
|
47
|
+
|
|
48
|
+
## 安装
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
dsh plugin add dsh-usage-peak
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
也可以在 DSH 插件市场搜索 `dsh-usage-peak` 安装。
|
|
55
|
+
|
|
56
|
+
装好后:
|
|
57
|
+
|
|
58
|
+
- 侧栏图标列表最上方出现用量胶囊;
|
|
59
|
+
- 设置 → **用量仪表盘** 打开完整面板。
|
|
60
|
+
|
|
61
|
+
## 兼容性
|
|
62
|
+
|
|
63
|
+
- DeepSeek Harness 0.2.1-rc.3(见 `package.json` 的 `dsh.compatibility.dshReleases`)。
|
|
64
|
+
- Node.js >= 22.15(需要 `zlib.zstdDecompressSync`)。
|
|
65
|
+
- 纯 JS,无构建步骤:`client.js` 直接用 `window.__ModuleLoader__` 注册,`require('react')` 由宿主提供。
|
|
66
|
+
|
|
67
|
+
## 已知限制
|
|
68
|
+
|
|
69
|
+
- 依赖 DSH 会话日志的**内部格式**(`session.v4.jsonl.zstd` 与 `assistant/message.data.usage`)。DSH 改格式时需要跟进;读不到数据时面板会显示为空态而不是报错。
|
|
70
|
+
- 只统计本机会话日志覆盖到的历史,鲸鱼记账本从 2026-11-02 才开始记账。
|
|
71
|
+
|
|
72
|
+
## 许可
|
|
73
|
+
|
|
74
|
+
MIT
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## English
|
|
79
|
+
|
|
80
|
+
A usage and cost dashboard for DeepSeek Harness. It reads the local session logs (`session.v4.jsonl.zstd`) and the whale ledger, then shows:
|
|
81
|
+
|
|
82
|
+

|
|
83
|
+
|
|
84
|
+
- a persistent sidebar pill with peak/valley state, today's spend, tokens and the countdown to the next price switch;
|
|
85
|
+
- a details page (Settings → Usage dashboard) with KPIs, an hourly breakdown, cost composition, a 7/14/30-day trend switch, a per-model table and the price list;
|
|
86
|
+
- a "valley saving" KPI: since peak costs exactly 2x valley, moving the same peak usage to valley time would have saved half of the peak spend.
|
|
87
|
+
|
|
88
|
+
Pricing (`[valley, peak]`, CNY per million tokens): Flash cache-hit 0.02/0.04, miss 1/2, output 4/8; Pro cache-hit 0.15/0.30, miss 4.5/9, output 13.5/27. Peak hours are 09:00–12:00 and 14:00–18:00 Beijing time on weekdays; everything else is valley (half price).
|
|
89
|
+
|
|
90
|
+
Everything stays local — no network calls, no telemetry. Multi-frame zstd logs are decoded frame by frame with Node's built-in `zlib`, so no `zstd` binary is required.
|
|
Binary file
|