dsh-token-dash 1.1.2 → 2.0.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/AGENTS.md +66 -51
- package/README.en.md +88 -45
- package/README.md +86 -44
- package/client.js +1004 -338
- package/index.js +103 -38
- package/package.json +3 -1
- package/src/adapters.js +169 -17
- package/src/diagnostics.js +1 -0
- package/src/providers.js +25 -1
- package/src/quota-sources.js +123 -0
package/AGENTS.md
CHANGED
|
@@ -1,90 +1,105 @@
|
|
|
1
1
|
# AGENTS.md
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> 本文件只放协作与执行规则,不承担开发总览、目录索引或版本现状;验证命令以 `package.json` 的 scripts 为准,不复述测试规模与版本号。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- 开发/架构入口:`docs/design.md`;先读架构、Provider/VM/UI 边界、模块职责,再看代码。
|
|
7
|
-
- 验证命令以 `package.json` 的 scripts 为准;不要在本文件复制测试规模、构建命令或版本号。
|
|
8
|
-
|
|
9
|
-
### 重点文档读取位置
|
|
5
|
+
## 1. 读取入口
|
|
10
6
|
|
|
11
7
|
| 场景 | 先读 | 再看 |
|
|
12
8
|
|---|---|---|
|
|
13
9
|
| 改代码 / 架构 | `docs/design.md` | `src/`、`client.js`、`test/unit/`、对应 active plan |
|
|
14
|
-
| 需求 / 规划 | `docs/plan/AGENTS.md` | `docs/plan/active/`(先看文件头状态)、`docs/plan/archived
|
|
15
|
-
| 施工 / 走查 | `docs/checklist/AGENTS.md` | `docs/checklist/active
|
|
16
|
-
| 发布 / 版本 | `docs/release.md` | `.agents/skills/dsh-token-dash-release/SKILL.md
|
|
10
|
+
| 需求 / 规划 | `docs/plan/AGENTS.md` | `docs/plan/active/`(先看文件头状态)、`docs/plan/archived/` |
|
|
11
|
+
| 施工 / 走查 | `docs/checklist/AGENTS.md` | `docs/checklist/active/`、`docs/checklist/archived/` |
|
|
12
|
+
| 发布 / 版本 | `docs/release.md` | `.agents/skills/dsh-token-dash-release/SKILL.md`、`references/official-release-version.md` |
|
|
17
13
|
| 用户说明 / 变更历史 | `README.md` / `README.en.md` | `CHANGELOG.md`、`docs/pic/` |
|
|
18
|
-
|
|
|
14
|
+
| 组件预览 / 草图 | `tools/preview/README.md` | `tools/preview/spec.mjs`、`tools/preview/templates/` |
|
|
15
|
+
| 假数据 / 截图 | `tools/mock/AGENTS.md` | `tools/mock/fixtures.mjs`、`tools/mock/shots.mjs` |
|
|
16
|
+
| Skill 维护 | `.agents/skills/`(项目) | `D:\Projects\Context-Engineer\skills\`(全局真源) |
|
|
19
17
|
|
|
20
|
-
-
|
|
18
|
+
- active plan / checklist 不在此复制,进目录后按文件头状态判断,避免本文件与文档状态漂移。
|
|
21
19
|
|
|
22
|
-
##
|
|
20
|
+
## 2. 授权边界
|
|
23
21
|
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
- plan / checklist
|
|
22
|
+
- **未获明确授权不得改代码**。用户只要求“更新文档 / 记 issue / 完善设计 / 检查文档”时,仅可改 `docs/`、`AGENTS.md`、`README*`;禁止编辑 `client.js`、`index.js`、`src/`、`test/`、`scripts/`、`tools/`、`package.json`、`locale/`,也不得测试、打包或安装插件。
|
|
23
|
+
- 代码实施需明确口令(“开始修改 / 可以改代码 / 执行 / 开始开发”);文档确认与代码实施分轮进行,不混在同一轮。
|
|
24
|
+
- plan / checklist 记录不等于实施授权;发现文档与代码不一致时先报告,未获授权不得顺手修。
|
|
27
25
|
|
|
28
|
-
##
|
|
26
|
+
## 3. 代码与架构约束
|
|
29
27
|
|
|
30
|
-
- 纯 ESM
|
|
28
|
+
- 纯 ESM、零构建;宿主入口 `index.js`,客户端 `client.js`;client bundle id 必须等于包名。
|
|
31
29
|
- 源码即产物,不提交 `lib/`;npm 包内容由 `package.json#files` 控制。
|
|
32
|
-
-
|
|
33
|
-
- 不做无关重构;改动范围以 plan / checklist
|
|
30
|
+
- Provider 边界:adapter 只输出 `ProviderSnapshot`,VM 只输出 `SummaryVM`,UI 只消费 VM;不做 provider 插件化或 per-provider 拆分(当前五家)。
|
|
31
|
+
- 不做无关重构;改动范围以 plan / checklist 声明为准,越界先改文档并确认。
|
|
34
32
|
- 日志用 `[TD:<module>]` 语义前缀;错误不吞,关键链路带 `errorKind` / `httpStatus`。
|
|
35
|
-
- 临时产物、一次性脚本和 MCP 输出统一放 `.tmp/`;不在仓库根或 `src/` 下新建临时文件。
|
|
36
33
|
|
|
37
|
-
##
|
|
34
|
+
## 4. 流程与工具
|
|
35
|
+
|
|
36
|
+
### 4.1 规划与施工
|
|
37
|
+
|
|
38
|
+
- 复杂功能、跨模块修改、架构调整先用 `plan-workflow` skill 维护 `docs/plan/active/`;归档内容只读,重开走受控流程。
|
|
39
|
+
- 同一时间只推进一个主 feature;优先恢复已有 plan,不新建重复计划。
|
|
40
|
+
- 施工与走查用 `checklist` skill 维护 `docs/checklist/active/`(单层,不建项目域子目录);回写完成 + 用户明确指令后才归档。
|
|
41
|
+
- 每次实现完成、测试通过或发布后,回写 plan 的 §3.0/§5 与 checklist 的阶段 / 测试 / 执行日志,避免状态只留在对话里。
|
|
42
|
+
|
|
43
|
+
### 4.2 预览与原型
|
|
44
|
+
|
|
45
|
+
- 四层分离:`tools/preview/templates/`(定稿原型)与 `drafts/`(探索稿)入库;`.tmp/preview/` 只放渲染器产出的 HTML(PNG 仅在 `--png` 时生成);`docs/pic/` 只放定稿图,仅 `preview:publish` 写入。
|
|
46
|
+
- **手写 HTML 不落 `.tmp/`**:探索写 `tools/preview/drafts/<name>.html`,跑 `npm run preview drafts/<name>`;定稿时把数值搬进 `spec.mjs`、改用变量后再移入 `templates/`。
|
|
47
|
+
- 默认只生成 `.tmp/preview/<name>.html`,**在 IDE 里直接预览**(比截图更接近真实渲染);需要静态图才加 `--png`,进 README / 设计文档才 `preview:publish`。
|
|
48
|
+
- 尺寸、字号、间距只在 `tools/preview/spec.mjs` 定义一次;预览模板与后续 E2E 尺寸断言共用,禁止各写一份。
|
|
49
|
+
- 设计文档引用 `templates/` 的稳定路径或 `npm run preview` 命令,不引用 `.tmp/`;组件形态以原型为准,不维护 ASCII 草图。
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
- 全局 skill 真源只放在 `D:\Projects\Context-Engineer\skills\`;`~/.agents/skills/<name>` 用 junction 指向 CE,不保留副本。
|
|
41
|
-
- 新增或修改全局 skill 在 CE 内完成,再建 junction;项目 skill 与全局 skill 不混放。
|
|
51
|
+
### 4.3 Skill 归属
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
- 项目 skill 只放仓库 `.agents/skills/`,不复制到用户层。
|
|
54
|
+
- 全局 skill 真源只放 `D:\Projects\Context-Engineer\skills\`;`~/.agents/skills/<name>` 用 junction 指向 CE,不保留副本。
|
|
55
|
+
- 新增或修改全局 skill 在 CE 内完成再建 junction;项目 skill 与全局 skill 不混放。
|
|
56
|
+
|
|
57
|
+
## 5. 验证、提交与版本
|
|
58
|
+
|
|
59
|
+
### 5.1 提交前
|
|
44
60
|
|
|
45
61
|
1. 更新相关文档:plan / checklist / design / README,以改动范围为准。
|
|
46
|
-
2. 执行受影响验证:L1 `npm test
|
|
47
|
-
3.
|
|
62
|
+
2. 执行受影响验证:L1 `npm test`;涉及 UI 或宿主链路时加 `npm run e2e`。
|
|
63
|
+
3. 仅当用户显式要求本地打包或发布时执行 `npm run pack`,并核对 tarball 内容。
|
|
48
64
|
4. 确认无 `.tmp/`、`build/`、真实会话或凭证进入提交。
|
|
49
|
-
5.
|
|
65
|
+
5. `commit` + `push`;用户说“提交”默认含推送,除非明确“只本地提交”。
|
|
50
66
|
|
|
51
|
-
-
|
|
67
|
+
- 纯文档更新且不涉及代码、测试脚本、发布资产时可跳过测试与打包,但提交说明必须写明“仅文档更新,未启动测试/打包”。
|
|
52
68
|
- 文档互引使用以仓库根为基准的相对路径。
|
|
53
|
-
- 完成本地打包后,立即回写当前 active plan 的进度;本地打包本身必须先有用户显式指令。
|
|
54
69
|
|
|
55
|
-
|
|
70
|
+
### 5.2 版本号
|
|
56
71
|
|
|
57
|
-
-
|
|
58
|
-
- 发版流程唯一来源:`docs/release.md` + `.agents/skills/dsh-token-dash-release/SKILL.md`;GitHub Release、npm Trusted Publishing 均由 tag 触发。
|
|
59
|
-
- **本地打包必须由用户显式指令触发**(`本地打包` / `本地版本` / `候选包`)。完成 issue、修复、测试或提交后,不得自动改版本号、写 CHANGELOG local 块、`npm run pack` 或安装本地包。
|
|
60
|
-
- 本地构建记录写 `CHANGELOG.md` 顶部 `## [X.Y.Z-local.N]`,标题下加 `> 本地构建,未发布`;不 tag、不发布。正式发布时合并进正式块并删除,最终历史不保留 local 块。
|
|
61
|
-
- 正式发布:确认版本 → CHANGELOG 正式块 → L1 + E2E → pack → commit/push → tag → 双 workflow → 核验 npm latest 与 Release body;随后更新 `official-release-version.md`。
|
|
62
|
-
- Release body 按 tag 版本从 CHANGELOG 提取,不按“文件第一块”提取;local 块不得进入 Release body。
|
|
63
|
-
- 未获用户明确授权,不执行 `npm publish`、不推 tag、不声称已上线。
|
|
72
|
+
- 遵循 `MAJOR.MINOR.PATCH`;当前正式版本以 `.agents/skills/dsh-token-dash-release/references/official-release-version.md` 为准,不在此复制。
|
|
64
73
|
|
|
65
|
-
|
|
74
|
+
### 5.3 正式发布
|
|
66
75
|
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
76
|
+
- 唯一来源:`docs/release.md` + `.agents/skills/dsh-token-dash-release/SKILL.md`;GitHub Release 与 npm Trusted Publishing 均由 tag 触发。
|
|
77
|
+
- 流程:确认版本 → CHANGELOG 正式块 → L1 + E2E → pack → commit/push → tag → 双 workflow → 核验 npm latest 与 Release body;随后更新 `official-release-version.md`。
|
|
78
|
+
- Release body 按 tag 版本从 CHANGELOG 提取,不按“文件第一块”;local 块不得进入 Release body。
|
|
79
|
+
- 未获明确授权,不执行 `npm publish`、不推 tag、不声称已上线。
|
|
71
80
|
|
|
72
|
-
|
|
81
|
+
### 5.4 本地构建
|
|
73
82
|
|
|
74
|
-
-
|
|
83
|
+
- **必须由用户显式指令触发**(“本地打包 / 本地版本 / 候选包”);完成 issue、修复、测试或提交后,不得自动改版本号、写 local 块、pack 或安装。
|
|
84
|
+
- 记录写 `CHANGELOG.md` 顶部 `## [X.Y.Z-local.N]`,标题下加 `> 本地构建,未发布`;不 tag、不发布;正式发布时合并进正式块并删除,最终历史不保留 local 块。
|
|
85
|
+
- 打包完成后立即回写当前 active plan 的进度。
|
|
86
|
+
|
|
87
|
+
## 6. 仓库卫生
|
|
88
|
+
|
|
89
|
+
- 入库:`src/`、`client.js`、`index.js`、`test/`、`tools/`、`scripts/`、`docs/`、`locale/`、`.agents/`、`.github/`、`README*`、`CHANGELOG.md`、`AGENTS.md`、`package.json`、`pnpm-lock.yaml`、`cordis.patch.yml`。
|
|
75
90
|
- 不入库:`node_modules/`、`build/`、`.tmp/`、`artifacts/`、`coverage/`、`playwright-report/`、`test-results/`、`*.tgz`、`*.log`、真实会话 JSONL、凭证与密钥。
|
|
91
|
+
- 临时产物、一次性脚本、MCP 输出统一放 `.tmp/`(预览图 `.tmp/preview/`);不在仓库根或 `src/` 下新建临时文件。
|
|
76
92
|
- E2E 测试脚本与合成 fixture 必须入库;截图、日志、报告、trace 一律忽略。
|
|
77
93
|
- `pnpm-lock.yaml` 必须提交,保证可复现安装。
|
|
78
94
|
|
|
79
|
-
## 安全
|
|
95
|
+
## 7. 安全
|
|
80
96
|
|
|
81
97
|
- 不读取 `~/.dsh/.credentials.yaml`;凭据只经宿主 `ctx.credentials.resolve(...)`。
|
|
82
98
|
- 余额查询仅限 DeepSeek / Kimi / GLM / OpenRouter / Qwen 官方接口;第三方显示“第三方不支持”且不请求。
|
|
83
99
|
- 密钥、cookie、token 不得出现在源码、日志、fixture 或提交信息中。
|
|
84
100
|
|
|
85
|
-
##
|
|
86
|
-
|
|
87
|
-
- 汇报“本次改了什么 / 测试改了什么”前,先读取对应 commit:`git show --stat <commit>`、`git show --name-status <commit>`,并核对受影响测试与文档 diff。
|
|
88
|
-
- 已提交内容、未提交工作区、运行态结果分开说明;不能用记忆或推测代替 commit 事实。
|
|
89
|
-
- 本轮尚未形成 commit 时,明确标注“未提交”,不得说成“已完成修改”。
|
|
101
|
+
## 8. 汇报
|
|
90
102
|
|
|
103
|
+
- 汇报“改了什么 / 测试改了什么”前,先读对应 commit:`git show --stat`、`git show --name-status`,并核对测试与文档 diff。
|
|
104
|
+
- 已提交内容、未提交工作区、运行态结果分开说明,不能用记忆或推测代替 commit 事实。
|
|
105
|
+
- 尚未形成 commit 时明确标注“未提交”,不得说成“已完成修改”。
|
package/README.en.md
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export the current month
|
|
12
|
+
See today's model spend, monthly budget headroom, and subscription windows for 7 providers right next to the DSH input box.<br />
|
|
13
|
+
Paste a key and the billing mode is detected automatically; cost, Tokens and cache hits are estimated locally;<br />
|
|
14
|
+
export the current month and import it back after switching machines or reinstalling.
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
17
|
<p align="center">
|
|
@@ -23,44 +23,35 @@
|
|
|
23
23
|
<p align="center">
|
|
24
24
|
<img src="https://img.shields.io/github/v/tag/spartawhy117/dsh-token-dash?label=version&sort=semver" alt="version" />
|
|
25
25
|
<img src="https://img.shields.io/npm/dt/dsh-token-dash?logo=npm&label=npm%20downloads" alt="npm downloads" />
|
|
26
|
-
<img src="https://img.shields.io/
|
|
26
|
+
<img src="https://img.shields.io/badge/DSH-0.2.2--rc.1_tested-4c8bf5" alt="DSH tested" />
|
|
27
27
|
<img src="https://img.shields.io/github/license/spartawhy117/dsh-token-dash" alt="license" />
|
|
28
|
-
<img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node" />
|
|
29
28
|
<a href="https://awesome-dsh-plugin.com/p/spartawhy117/dsh-token-dash"><img src="https://img.shields.io/badge/awesome--dsh--plugin-listed-6ea8ff" alt="awesome-dsh-plugin" /></a>
|
|
30
29
|
</p>
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
- **Pages**: bottom bar Pill → floating dashboard (usage / settings tabs); click the pill to expand, click outside to collapse
|
|
34
|
-
- **Dashboard data**: time range (today / last 7 days / last 30 days / all), per-provider monthly budget progress (used / total / percent), today's spend, account balance, subscription 5h / weekly windows with reset times; two tiles for **total cost by currency** and **real Tokens (including cache read/write)**; per provider/model cost, requests and hit rate below
|
|
35
|
-
- **Settings**: per-provider monthly budget (with currency, defaults to 100 when empty), three refresh intervals, balance toggle, logs, data export / import, check for updates
|
|
36
|
-
- **Data**: daily / monthly usage estimated locally (built-in price catalog + community price table), three-layer model attribution, read-only local sessions; subscription models count toward Tokens but not cost, and the billing mode is pinned per key instead of following quota flakiness
|
|
31
|
+
**Three entry points, one local ledger**: the composer-footer-right Pill shows the current model; the floating panel shows budget, balance and the usage table; the full dashboard shows every provider card and model breakdown. No duplicated accounting between pages.
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
## Provider matrix
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
|
|
50
|
-
|
|
51
|
-
# Option 3: download dsh-token-dash-x.y.z.tgz from Releases and install locally (offline)
|
|
52
|
-
dsh plugin --profile desktop add /path/to/dsh-token-dash-1.1.0.tgz
|
|
53
|
-
```
|
|
35
|
+
| Provider | Billing | Credential | What you get |
|
|
36
|
+
|---|---|---|---|
|
|
37
|
+
| DeepSeek | Pay-as-you-go | DS account wallet / `DEEPSEEK_API_KEY` | Balance, month-to-date spend, budget |
|
|
38
|
+
| Zhipu GLM Coding | Subscription / API | `ZHIPU_API_KEY` / `GLM_API_KEY` / `ZAI_API_KEY` | 5h + weekly windows |
|
|
39
|
+
| Kimi Coding | Subscription / API | `KIMI_API_KEY` / `KIMI_CODING_API_KEY`, optional `MOONSHOT_API_KEY` | 5h + weekly/monthly windows; falls back to balance |
|
|
40
|
+
| OpenRouter | Pay-as-you-go | `OPENROUTER_API_KEY` | Credits (USD) |
|
|
41
|
+
| Qwen | Pay-as-you-go | `DASHSCOPE_API_KEY` (CNY) / `DASHSCOPE_INTL_API_KEY` (USD) | Usage only; balance unsupported |
|
|
42
|
+
| OpenCode Go | Subscription | `OPENCODE_GO_API_KEY` | 5h / weekly / monthly windows (USD) |
|
|
43
|
+
| Command Code | Subscription | `COMMAND_CODE_API_KEY` + `COMMAND_CODE_ORG_ID` | 5h + weekly windows, credits (CNY) |
|
|
54
44
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
- Save keys under the names above in DSH's credential settings; the plugin reads them through the host `credentials` service, not environment variables or local login files.
|
|
46
|
+
- Keys are detected automatically; GLM / Kimi / OpenCode Go / Command Code can be re-detected from the dashboard footer.
|
|
47
|
+
- Subscription models count toward Tokens but not cost; billing mode is pinned per key instead of following quota flakiness.
|
|
48
|
+
- Balance, quota and usage are separate; a balance failure never resets today's Token ledger to zero.
|
|
58
49
|
|
|
59
50
|
## Interface
|
|
60
51
|
|
|
61
|
-
Screenshots
|
|
52
|
+
Screenshots use mock data so the full layout is visible at once.
|
|
62
53
|
|
|
63
|
-
**P1 ·
|
|
54
|
+
**P1 · Composer footer-right Pill**: pay-as-you-go / subscription variants; click to open, click outside, `×` or `Esc` to close.
|
|
64
55
|
|
|
65
56
|
<p align="center">
|
|
66
57
|
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-api.png" alt="Pay-as-you-go pill" />
|
|
@@ -70,45 +61,95 @@ Screenshots below use mock data so the full layout is visible at once:
|
|
|
70
61
|
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-sub.png" alt="Subscription pill" />
|
|
71
62
|
</p>
|
|
72
63
|
|
|
73
|
-
**P2 · Floating
|
|
64
|
+
**P2 · Floating panel (current model)**: fixed 380, one row with three groups — used ring / used-budget / real balance — with the balance right-aligned to the panel edge, a full-width range control and the usage table.
|
|
65
|
+
|
|
66
|
+
<p align="center">
|
|
67
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-api.png" alt="Floating panel - pay-as-you-go" />
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-2.png" alt="Floating panel - two subscription windows" />
|
|
72
|
+
</p>
|
|
74
73
|
|
|
75
74
|
<p align="center">
|
|
76
|
-
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-
|
|
75
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-3.png" alt="Floating panel - three subscription windows" />
|
|
77
76
|
</p>
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
- Subscription windows use three slots: first left, second center, third right; two windows occupy the first two slots.
|
|
79
|
+
- Model column is capped at 150; Tokens / requests / hit rate are right-aligned.
|
|
80
|
+
|
|
81
|
+
**P3 · Full dashboard**: cards for 7 providers, summary band, 8-column model breakdown and a settings capsule; the page owns its scrollbar at the window edge.
|
|
80
82
|
|
|
81
83
|
<p align="center">
|
|
82
|
-
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="
|
|
84
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="Full dashboard" />
|
|
83
85
|
</p>
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
- Pay-as-you-go card: budget input, planned balance, real balance, month-to-date spend; subscription card: one ring per window with remaining percentage and countdown.
|
|
88
|
+
- Breakdown: model / Tokens / input / cache / output / requests / hit rate / cost; everything except the model column is right-aligned.
|
|
89
|
+
- Settings capsule: refresh interval + account-balance toggle; logs, export/import, price table and version below.
|
|
90
|
+
- The settings section has an external "Settings and data" title above the capsule; the capsule itself keeps the refresh interval, logs/data controls and version row.
|
|
91
|
+
- Spacing uses only 4 / 8 / 12 / 16 / 24 / 32; P2 and P3 share the same tokens.
|
|
86
92
|
|
|
87
|
-
##
|
|
93
|
+
## Install
|
|
88
94
|
|
|
89
|
-
|
|
95
|
+
Requires DSH `0.2.1` or newer; tested on **DSH 0.2.2-rc.1**. DSH 0.2.2 itself requires Node **24.9+**.
|
|
90
96
|
|
|
91
97
|
```bash
|
|
92
|
-
|
|
93
|
-
|
|
98
|
+
# Option 1: install from npm (recommended)
|
|
99
|
+
dsh plugin --profile desktop add dsh-token-dash
|
|
100
|
+
|
|
101
|
+
# Option 2: install straight from the GitHub repo (plain JS, no build step)
|
|
102
|
+
dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
|
|
103
|
+
|
|
104
|
+
# Option 3: download dsh-token-dash-x.y.z.tgz from Releases and install locally (offline)
|
|
105
|
+
dsh plugin --profile desktop add /path/to/dsh-token-dash-x.y.z.tgz
|
|
94
106
|
```
|
|
95
107
|
|
|
96
|
-
|
|
108
|
+
Update: run `update` with the same name, or use the `⤓` button on the right of “Pricing & version” in settings. Remove: run `remove` with the same name; data stays in `$DSH_HOME/dsh-token-dash/`.
|
|
109
|
+
|
|
110
|
+
> If the plugin disappears from the profile after a DSH 0.2.2 upgrade, reinstall the same tarball. The ledger and settings are not deleted with the plugin package.
|
|
111
|
+
|
|
112
|
+
## Compatibility & limitations
|
|
113
|
+
|
|
114
|
+
- DSH `0.2.1+`; verified on `0.2.2-rc.1`. DSH 0.2.2 is a pre-release and itself requires Node 24.9.
|
|
115
|
+
- After a DSH upgrade the plugin may disappear from the profile; reinstall the same tarball — the ledger is not deleted.
|
|
116
|
+
- Qwen tracks usage only; its balance endpoint is unsupported. Other balances/quotas follow what each API returns.
|
|
117
|
+
- Upstream APIs are rate-limited; successful results are cached for 60s, failures for 10s, and concurrent requests are coalesced.
|
|
118
|
+
|
|
119
|
+
## Data & privacy
|
|
120
|
+
|
|
121
|
+
- Reads only local session `usage` (title-generation overhead excluded); cost and Tokens are local estimates — no billing requests.
|
|
122
|
+
- Balances come from official endpoints only; credentials are resolved by the host and are never written to disk or logs.
|
|
123
|
+
- Data lives in `$DSH_HOME/dsh-token-dash/`: `daily.json`, `months/`, `prefs.json`.
|
|
124
|
+
- Export/import is local: settings + current-month usage, without quotas, balances or logs; the existing files are backed up before an import overwrites them.
|
|
125
|
+
|
|
126
|
+
## Logs & troubleshooting
|
|
127
|
+
|
|
128
|
+
Logs live in `$DSH_HOME/logs/dsh-token-dash/` as JSONL; every line carries `prefix: "[TD:<module>]"` and `module`:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm run logs -- --tail 50 # recent 50 lines
|
|
132
|
+
npm run logs -- --module adapter.* # provider detection only
|
|
133
|
+
npm run logs -- --module provider,route # cache / routing issues
|
|
134
|
+
```
|
|
97
135
|
|
|
98
|
-
|
|
136
|
+
Common events:
|
|
99
137
|
|
|
100
|
-
|
|
138
|
+
- `[TD:adapter.*]`: `quota.ok` / `quota.fail` / `quota.parse` / `balance.*` / `detect.fail`
|
|
139
|
+
- `[TD:provider]`: `probe.miss` (none / hidden / error), `subscriptions.refreshed`, `cache.state`
|
|
140
|
+
- `[TD:route]`: `forbidden` (non-loopback), `failed`
|
|
141
|
+
- Errors carry `errorKind` (http / timeout / network / parse) and `httpStatus`; 5xx adds `upstream: true`.
|
|
101
142
|
|
|
102
143
|
## Development
|
|
103
144
|
|
|
104
145
|
```bash
|
|
105
|
-
npm test # unit tests
|
|
146
|
+
npm test # unit tests (80 passing)
|
|
106
147
|
npm run e2e # end-to-end (temp DSH_HOME + web profile + Playwright)
|
|
107
|
-
npm run shots # regenerate the P1/P2/P3 screenshots in docs/pic from mock data
|
|
148
|
+
npm run shots # regenerate the P1/P2/P3 screenshots in docs/pic from mock data
|
|
108
149
|
npm run pack # build the release tarball into build/
|
|
109
150
|
```
|
|
110
151
|
|
|
111
|
-
Releases: pushing a `v*` tag triggers the GitHub Release (tarball) and a direct npm publish automatically (Trusted Publishing via OIDC, with provenance
|
|
152
|
+
Releases: pushing a `v*` tag triggers the GitHub Release (tarball) and a direct npm publish automatically (Trusted Publishing via OIDC, with provenance); see [docs/release.md](./docs/release.md) for the full checklist.
|
|
112
153
|
|
|
113
154
|
## Acknowledgements
|
|
114
155
|
|
|
@@ -120,3 +161,5 @@ Attribution and billing semantics learned from these community plugins:
|
|
|
120
161
|
- [dsh-spend](https://github.com/nonewind/dsh-spend)
|
|
121
162
|
- [dsh-stats-panel](https://github.com/zhang-jiazhi/dsh-stats-panel)
|
|
122
163
|
- [DshCockpit](https://github.com/Lxiayu/DshCockpit)
|
|
164
|
+
- [shy3130/dsh-quota](https://github.com/shy3130/dsh-quota) (OpenCode Go / cache structure reference)
|
|
165
|
+
- [InvisibleSirius/dsh-quota-dashboard](https://github.com/InvisibleSirius/dsh-quota-dashboard) (multi-provider table reference)
|
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
|
-
在 DSH
|
|
13
|
-
|
|
12
|
+
在 DSH 输入框旁看清今天的模型消耗、本月的预算余量,以及 7 家供应商的订阅窗口。<br />
|
|
13
|
+
填 Key 自动识别订阅或按量计费;费用、Tokens、缓存命中全部在本地估算;<br />
|
|
14
14
|
当月数据可导出备份,换机或重装后一键导入恢复。
|
|
15
15
|
</p>
|
|
16
16
|
|
|
@@ -23,44 +23,35 @@
|
|
|
23
23
|
<p align="center">
|
|
24
24
|
<img src="https://img.shields.io/github/v/tag/spartawhy117/dsh-token-dash?label=version&sort=semver" alt="version" />
|
|
25
25
|
<img src="https://img.shields.io/npm/dt/dsh-token-dash?logo=npm&label=npm%20downloads" alt="npm downloads" />
|
|
26
|
-
<img src="https://img.shields.io/
|
|
26
|
+
<img src="https://img.shields.io/badge/DSH-0.2.2--rc.1_tested-4c8bf5" alt="DSH tested" />
|
|
27
27
|
<img src="https://img.shields.io/github/license/spartawhy117/dsh-token-dash" alt="license" />
|
|
28
|
-
<img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node" />
|
|
29
28
|
<a href="https://awesome-dsh-plugin.com/zh/p/spartawhy117/dsh-token-dash"><img src="https://img.shields.io/badge/awesome--dsh--plugin-listed-6ea8ff" alt="awesome-dsh-plugin" /></a>
|
|
30
29
|
</p>
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
- **页面**:底栏 Pill → 浮层看板(用量 / 设置双 tab);Pill 点击展开、点击浮层外收起
|
|
34
|
-
- **看板数据**:时间范围(当天 / 近 7 天 / 近 30 天 / 全部)、本月预算进度(已用 / 总额 / 百分比)、今日消耗、账户余额、订阅 5h / 周窗口与重置时间;两格卡显示**总费用(按币种)**与**真实 Tokens(含缓存读写)**;下方按 provider / 模型列出费用、请求数与命中率
|
|
35
|
-
- **设置**:按供应商的月度预算(带币种,未填写默认 100)、刷新间隔三档、账户余额开关、日志、数据导出 / 导入、检查更新
|
|
36
|
-
- **数据口径**:每日 / 每月用量本地估算(内置价格表 + 社区价格表),三层模型归属,只读本地会话;订阅模型计入 Tokens 但不计费用,计费形态按 Key 固化,不随配额接口抖动
|
|
31
|
+
**三个入口,一份数据**:输入框底栏右侧 Pill 看当前模型;浮层看预算、余额与用量表;整页看 7 家供应商的全量卡片与模型明细。所有页面共用同一份本地账本,不重复计算。
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
## 支持矩阵
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
|
|
50
|
-
|
|
51
|
-
# 方式三:从 Releases 下载 dsh-token-dash-x.y.z.tgz 后本地安装(离线场景)
|
|
52
|
-
dsh plugin --profile desktop add /path/to/dsh-token-dash-1.1.0.tgz
|
|
53
|
-
```
|
|
35
|
+
| 供应商 | 计费形态 | 凭据 | 能看到什么 |
|
|
36
|
+
|---|---|---|---|
|
|
37
|
+
| DeepSeek | 按量 | DS 账号钱包 / `DEEPSEEK_API_KEY` | 账户余额、本月已花、预算 |
|
|
38
|
+
| 智谱 GLM Coding | 订阅 / 按量 | `ZHIPU_API_KEY` / `GLM_API_KEY` / `ZAI_API_KEY` | 5h + 周窗口 |
|
|
39
|
+
| Kimi Coding | 订阅 / 按量 | `KIMI_API_KEY` / `KIMI_CODING_API_KEY`,可选 `MOONSHOT_API_KEY` | 5h + 周/月窗口;订阅查询失败可回落余额 |
|
|
40
|
+
| OpenRouter | 按量 | `OPENROUTER_API_KEY` | Credits(USD) |
|
|
41
|
+
| 通义千问 | 按量 | `DASHSCOPE_API_KEY`(CNY)/ `DASHSCOPE_INTL_API_KEY`(USD) | 仅用量;余额不支持 |
|
|
42
|
+
| OpenCode Go | 订阅 | `OPENCODE_GO_API_KEY` | 5h / 周 / 月窗口(USD) |
|
|
43
|
+
| Command Code | 订阅 | `COMMAND_CODE_API_KEY` + `COMMAND_CODE_ORG_ID` | 5h + 周窗口、Credits(CNY) |
|
|
54
44
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
- 在 DSH 的凭据设置中按上表名称保存 Key;插件只通过宿主 `credentials` 读取,不读环境变量或本机登录文件。
|
|
46
|
+
- 填 Key 后自动探测;GLM / Kimi / OpenCode Go / Command Code 可在「全量看板」底部重新检测订阅。
|
|
47
|
+
- 订阅模型计入 Tokens,但不计费用;计费形态按 Key 固化,不随配额接口抖动。
|
|
48
|
+
- 余额、配额、用量分开展示;余额失败不会把当天的 Token 记账清零。
|
|
58
49
|
|
|
59
50
|
## 界面
|
|
60
51
|
|
|
61
|
-
|
|
52
|
+
以下截图使用假数据演示,便于一次看到完整效果。
|
|
62
53
|
|
|
63
|
-
**P1 ·
|
|
54
|
+
**P1 · 输入框底栏右侧 Pill**:按量 / 订阅两种形态,点击展开浮层,点击外部、`×` 或 `Esc` 收起。
|
|
64
55
|
|
|
65
56
|
<p align="center">
|
|
66
57
|
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-api.png" alt="按量 Pill" />
|
|
@@ -70,45 +61,94 @@ dsh plugin --profile desktop add /path/to/dsh-token-dash-1.1.0.tgz
|
|
|
70
61
|
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-sub.png" alt="订阅 Pill" />
|
|
71
62
|
</p>
|
|
72
63
|
|
|
73
|
-
**P2 ·
|
|
64
|
+
**P2 · 浮层(当前模型)**:固定 380,单行三组「已用环 / 已用·预算 / 真实余额」,真实余额右对齐到面板右缘;时间范围撑满,下面是用量表。
|
|
65
|
+
|
|
66
|
+
<p align="center">
|
|
67
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-api.png" alt="浮层 · 按量形态" />
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-2.png" alt="浮层 · 订阅两窗" />
|
|
72
|
+
</p>
|
|
74
73
|
|
|
75
74
|
<p align="center">
|
|
76
|
-
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-
|
|
75
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-3.png" alt="浮层 · 订阅三窗" />
|
|
77
76
|
</p>
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
- 订阅窗口固定三槽位:第 1 窗左、第 2 窗中、第 3 窗右;只有两窗时占前两个槽位。
|
|
79
|
+
- 模型列上限 150,Tokens / 请求 / 命中右对齐;长模型名用省略号,悬浮可看全名。
|
|
80
|
+
|
|
81
|
+
**P3 · 整页看板**:7 家供应商卡片、摘要带、8 列模型明细、底部设置胶囊;页面自己滚动,滚动条贴窗口右缘。
|
|
80
82
|
|
|
81
83
|
<p align="center">
|
|
82
|
-
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="
|
|
84
|
+
<img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="整页看板" />
|
|
83
85
|
</p>
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
- 按量卡:预算输入、计划余额、真实余额、本月已花;订阅卡:每个窗口一个环 + 剩余百分比 + 倒计时。
|
|
88
|
+
- 明细表:模型 / Tokens / 输入 / 缓存 / 输出 / 请求 / 命中 / 费用;除模型列外全部右对齐。
|
|
89
|
+
- 设置区:胶囊外是「设置与数据管理」区块标题;胶囊内第一行刷新间隔 + 账户余额开关,下面是日志、导出导入、价格表与版本。
|
|
90
|
+
- 间距只使用 4 / 8 / 12 / 16 / 24 / 32 六档,P2 / P3 同一套 token。
|
|
86
91
|
|
|
87
|
-
##
|
|
92
|
+
## 安装
|
|
88
93
|
|
|
89
|
-
|
|
94
|
+
需要 DSH `0.2.1` 或更新版本;已在 **DSH 0.2.2-rc.1** 上验证。DSH 0.2.2 自身要求 Node **24.9+**。
|
|
90
95
|
|
|
91
96
|
```bash
|
|
92
|
-
npm
|
|
93
|
-
|
|
97
|
+
# 方式一:npm 安装(推荐)
|
|
98
|
+
dsh plugin --profile desktop add dsh-token-dash
|
|
99
|
+
|
|
100
|
+
# 方式二:GitHub 仓库直装(纯 JS 无构建,源码即产物)
|
|
101
|
+
dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
|
|
102
|
+
|
|
103
|
+
# 方式三:从 Releases 下载 dsh-token-dash-x.y.z.tgz 后本地安装(离线场景)
|
|
104
|
+
dsh plugin --profile desktop add /path/to/dsh-token-dash-x.y.z.tgz
|
|
94
105
|
```
|
|
95
106
|
|
|
96
|
-
|
|
107
|
+
更新:`update` 同名命令(npm / github: 各自同名),或在插件设置页「价格与版本」右侧的 `⤓` 内完成。卸载:`remove` 同名命令,数据保留在 `$DSH_HOME/dsh-token-dash/`。
|
|
108
|
+
|
|
109
|
+
> DSH 0.2.2 升级后如果插件从 profile 消失,重装同一个 tarball 即可;账本与设置不随插件包删除。
|
|
110
|
+
|
|
111
|
+
## 兼容与限制
|
|
112
|
+
|
|
113
|
+
- DSH `0.2.1+`;已在 `0.2.2-rc.1` 上验证。DSH 0.2.2 是预发布版,且自身要求 Node 24.9。
|
|
114
|
+
- 升级 DSH 后插件可能从 profile 消失,重装同一个 tarball 即可,账本不会被删。
|
|
115
|
+
- 通义千问只统计用量,余额接口不支持;其余供应商的余额/配额以接口实际返回为准。
|
|
116
|
+
- 上游接口有速率限制;成功结果缓存 60s、失败结果缓存 10s,并发请求会合并。
|
|
117
|
+
|
|
118
|
+
## 数据与隐私
|
|
119
|
+
|
|
120
|
+
- 只读本地会话 `usage`,不统计标题生成;费用与 Tokens 在本地按价格表估算,不发起计费请求。
|
|
121
|
+
- 余额只访问官方接口;凭据经宿主解析,不落盘、不写日志。
|
|
122
|
+
- 数据默认在 `$DSH_HOME/dsh-token-dash/`:`daily.json`、`months/`、`prefs.json`。
|
|
123
|
+
- 导出 / 导入都在本地完成:导出设置 + 当月使用数据,不含配额、余额与日志;导入覆盖前会备份原文件。
|
|
124
|
+
|
|
125
|
+
## 日志与排障
|
|
126
|
+
|
|
127
|
+
日志在 `$DSH_HOME/logs/dsh-token-dash/`,JSONL,每行带 `prefix: "[TD:<module>]"` 与 `module`:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
npm run logs -- --tail 50 # 最近 50 条
|
|
131
|
+
npm run logs -- --module adapter.* # 只看供应商侦测
|
|
132
|
+
npm run logs -- --module provider,route # 缓存 / 路由异常
|
|
133
|
+
```
|
|
97
134
|
|
|
98
|
-
|
|
135
|
+
常见事件:
|
|
99
136
|
|
|
100
|
-
|
|
137
|
+
- `[TD:adapter.*]`:`quota.ok` / `quota.fail` / `quota.parse` / `balance.*` / `detect.fail`
|
|
138
|
+
- `[TD:provider]`:`probe.miss`(未配置 / 隐藏 / 失败)、`subscriptions.refreshed`、`cache.state`
|
|
139
|
+
- `[TD:route]`:`forbidden`(非回环请求)、`failed`
|
|
140
|
+
- 错误带 `errorKind`(http / timeout / network / parse)与 `httpStatus`;5xx 额外 `upstream: true`
|
|
101
141
|
|
|
102
142
|
## 开发
|
|
103
143
|
|
|
104
144
|
```bash
|
|
105
|
-
npm test #
|
|
145
|
+
npm test # 单元测试(80 通过)
|
|
106
146
|
npm run e2e # 端到端(临时 DSH_HOME + web profile + Playwright)
|
|
107
|
-
npm run shots # 用假数据重新生成 docs/pic 的 P1/P2/P3
|
|
147
|
+
npm run shots # 用假数据重新生成 docs/pic 的 P1/P2/P3 截图
|
|
108
148
|
npm run pack # 发布 tarball 生成到 build/
|
|
109
149
|
```
|
|
110
150
|
|
|
111
|
-
发版:推 `v*` tag 自动触发 GitHub Release(tarball)与 npm 直发(Trusted Publishing / OIDC,含 provenance
|
|
151
|
+
发版:推 `v*` tag 自动触发 GitHub Release(tarball)与 npm 直发(Trusted Publishing / OIDC,含 provenance);完整流程见 [docs/release.md](./docs/release.md)。
|
|
112
152
|
|
|
113
153
|
## 致谢
|
|
114
154
|
|
|
@@ -120,3 +160,5 @@ npm run pack # 发布 tarball 生成到 build/
|
|
|
120
160
|
- [dsh-spend](https://github.com/nonewind/dsh-spend)
|
|
121
161
|
- [dsh-stats-panel](https://github.com/zhang-jiazhi/dsh-stats-panel)
|
|
122
162
|
- [DshCockpit](https://github.com/Lxiayu/DshCockpit)
|
|
163
|
+
- [shy3130/dsh-quota](https://github.com/shy3130/dsh-quota)(OpenCode Go / 缓存结构参考)
|
|
164
|
+
- [InvisibleSirius/dsh-quota-dashboard](https://github.com/InvisibleSirius/dsh-quota-dashboard)(多 provider 源表参考)
|