@shi-yangyang/dsh-token-dashboard 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.en.md +164 -0
- package/README.md +163 -2
- package/client/client.js +6140 -0
- package/cordis.patch.yml +7 -0
- package/icon.svg +13 -0
- package/lib/host/aggregate.d.ts +61 -0
- package/lib/host/aggregate.js +472 -0
- package/lib/host/fold.d.ts +103 -0
- package/lib/host/fold.js +375 -0
- package/lib/host/index.d.ts +24 -0
- package/lib/host/index.js +116 -0
- package/lib/host/prices.d.ts +42 -0
- package/lib/host/prices.js +118 -0
- package/lib/host/server.d.ts +30 -0
- package/lib/host/server.js +177 -0
- package/lib/host/source.d.ts +37 -0
- package/lib/host/source.js +179 -0
- package/lib/host/types.d.ts +133 -0
- package/lib/host/types.js +9 -0
- package/lib/host/verify.d.ts +14 -0
- package/lib/host/verify.js +79 -0
- package/lib/shared/builtin-prices.d.ts +27 -0
- package/lib/shared/builtin-prices.generated.d.ts +7 -0
- package/lib/shared/builtin-prices.generated.js +1433 -0
- package/lib/shared/builtin-prices.js +111 -0
- package/lib/shared/dates.d.ts +23 -0
- package/lib/shared/dates.js +79 -0
- package/lib/shared/export.d.ts +13 -0
- package/lib/shared/export.js +113 -0
- package/lib/shared/format.d.ts +23 -0
- package/lib/shared/format.js +108 -0
- package/lib/shared/model.d.ts +37 -0
- package/lib/shared/model.js +87 -0
- package/lib/shared/pricing.d.ts +70 -0
- package/lib/shared/pricing.js +192 -0
- package/lib/shared/range.d.ts +34 -0
- package/lib/shared/range.js +93 -0
- package/lib/shared/types.d.ts +168 -0
- package/lib/shared/types.js +10 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +83 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 小洋
|
|
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.en.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
<p align="center"><a href="./README.md">中文</a> · <a href="./README.en.md"><strong>English</strong></a></p>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="./icon.svg" width="76" height="76" alt="dsh-token-dashboard" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">dsh-token-dashboard</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center"><strong>Usage, cost, and request latency for every DeepSeek Harness session.</strong></p>
|
|
10
|
+
|
|
11
|
+
<p align="center">A local-first Cordis plugin that turns local DSH session history into a native dashboard.</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<img alt="DSH 0.2.1-rc.3" src="https://img.shields.io/badge/DSH-0.2.1--rc.3-4F6EF7?style=flat-square" />
|
|
15
|
+
<img alt="Cordis plugin" src="https://img.shields.io/badge/Cordis-plugin-2B3FB8?style=flat-square" />
|
|
16
|
+
<img alt="Node 22.18+" src="https://img.shields.io/badge/Node-%E2%89%A522.18-339933?style=flat-square&logo=nodedotjs&logoColor=white" />
|
|
17
|
+
<img alt="TypeScript 5.9" src="https://img.shields.io/badge/TypeScript-5.9-3178C6?style=flat-square&logo=typescript&logoColor=white" />
|
|
18
|
+
<img alt="MIT License" src="https://img.shields.io/badge/License-MIT-2B3FB8?style=flat-square" />
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#features">Features</a> ·
|
|
23
|
+
<a href="#quick-start">Quick start</a> ·
|
|
24
|
+
<a href="#usage">Usage</a> ·
|
|
25
|
+
<a href="#architecture">Architecture</a> ·
|
|
26
|
+
<a href="#development">Development</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Overview
|
|
32
|
+
|
|
33
|
+
DSH already shows token usage for the session in front of you. It does not show the whole picture: every project, model, subagent, fork, and request across your local history.
|
|
34
|
+
|
|
35
|
+
`@shi-yangyang/dsh-token-dashboard` adds that missing layer as a native plugin, displayed as **Token usage** in DSH.
|
|
36
|
+
|
|
37
|
+
The Host half reads session logs through the official `sessionPersistence` service and folds them with the same four-bucket accounting used by `@deepseek-ai/dsh-token-meter`. The Client half registers a `main` panel and a sidebar-footer entry using DSH slots, then renders with the host React runtime and theme tokens.
|
|
38
|
+
|
|
39
|
+
The plugin never writes a session log, changes a model request, or uploads session data. The logs remain the only source of truth.
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Global usage in one view** — totals, uncached input, output, cache read/write, request count, cache hit rate, and session counts across all sessions in the active profile.
|
|
44
|
+
- **Range-aware trends** — today, last 7 / 30 / 90 days, all time, or a custom date range; KPIs and the Usage chart share the same range.
|
|
45
|
+
- **Models and sessions** — searchable, filterable, sortable tables with pagination and a session detail drawer.
|
|
46
|
+
- **Request log** — one row per billed request, with time, app, provider, model, new input, output, cache hit, cost, speed, and first-token latency.
|
|
47
|
+
- **Cost estimates** — a built-in 357-model OpenRouter snapshot plus hand-maintained DeepSeek peak rates; override any price locally, or refresh from OpenRouter on demand.
|
|
48
|
+
- **Native and local-first** — DSH slots, DSH theme tokens, English/中文 UI, same-origin read-only routes, and exports that strip the working directory.
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
The package name is **`@shi-yangyang/dsh-token-dashboard`**. For now, build from source and install it as a local bundle as described below. The unscoped `dsh-token-dashboard` package on npm belongs to another project; do not use `npm install dsh-token-dashboard` to install this plugin.
|
|
53
|
+
|
|
54
|
+
### Requirements
|
|
55
|
+
|
|
56
|
+
- A DeepSeek Harness installation with the Web UI. Verified on DSH Desktop `0.2.1-rc.3` (Cordis `4.0.5`).
|
|
57
|
+
- Node.js **22.18 or newer** and `pnpm` when building from source.
|
|
58
|
+
|
|
59
|
+
### Build
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/shi-YangYang/dsh-token-dashboard.git
|
|
63
|
+
cd dsh-token-dashboard
|
|
64
|
+
pnpm install
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`pnpm install` automatically builds the Host and Client through `prepare`, generating the uncommitted `lib/` and `client/` outputs. Run `pnpm build` to rebuild after changing the source.
|
|
68
|
+
|
|
69
|
+
### Install into DSH
|
|
70
|
+
|
|
71
|
+
Install this directory as a local bundle from DSH's **Plugins** interface, or from a DSH agent:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
plugin_manager(action: "install_bundle", target: "/absolute/path/to/dsh-token-dashboard")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Enable the bundle if your profile has it disabled, then refresh the DSH Web page. Open **Token usage** from the sidebar footer, above Settings.
|
|
78
|
+
|
|
79
|
+
Updating Host code requires a DSH restart; Client-only changes need a page refresh.
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
| Page | What it shows |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| **Overview** | Global KPIs and a Usage chart across the selected range |
|
|
86
|
+
| **Models** | Token distribution and request counts by provider/model |
|
|
87
|
+
| **Sessions** | Search, filters, sorting, pagination, and per-session detail |
|
|
88
|
+
| **Request log** | Individual billed requests, 12 per page, newest first |
|
|
89
|
+
| **Costs** | Estimated spend, per-model breakdown, pricing overrides, and online price refresh |
|
|
90
|
+
|
|
91
|
+
The header provides the language switch, scan interval, **Sync now**, and export. Scan interval controls local session polling: **5 / 10 / 30 / 60 seconds**. All list tables show up to 12 rows per page with compact natural row heights; pagination stays at the footer and no list introduces an inner scrollbar.
|
|
92
|
+
|
|
93
|
+
Request-log cost is calculated with the current pricing table in the browser; unpriced models show `—`. Speed is output tokens divided by the measured request window. First-token latency runs from `step/start` to the first stream record; requests without stream timing show `—`.
|
|
94
|
+
|
|
95
|
+
Prices are estimates, not provider invoices. The built-in DeepSeek rates are peak-hour prices; off-peak rates are approximately half. Overrides and online price cache live in the browser's `localStorage`.
|
|
96
|
+
|
|
97
|
+
## Architecture
|
|
98
|
+
|
|
99
|
+
```mermaid
|
|
100
|
+
flowchart LR
|
|
101
|
+
Logs[(Session logs)] --> Host[Host aggregator]
|
|
102
|
+
Live[session/event] --> Host
|
|
103
|
+
Host --> Fold[Token fold + revision cache]
|
|
104
|
+
Fold --> Routes[Read-only same-origin JSON]
|
|
105
|
+
Routes --> Client[React dashboard in DSH slots]
|
|
106
|
+
Client --> Views[Overview · Models · Sessions · Requests · Costs]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- **Host** (`src/host`) reads the official session store, folds usage incrementally, handles pricing, and serves the dashboard API. The cache is in memory and keyed by session revision (or live sequence); there is no second database or ledger.
|
|
110
|
+
- **Client** (`src/client`) registers `main` and `sidebar.footer.action` slots, manages scan/language/price preferences, and renders the dashboard. React is supplied by the host and is not bundled twice.
|
|
111
|
+
- **Shared** (`src/shared`) contains the wire types, four-bucket arithmetic, range selection, pricing, and formatting used by both sides.
|
|
112
|
+
|
|
113
|
+
Usage follows the published `tokenUsage` semantics: four disjoint provider buckets, final samples replacing stream samples for the same attempt, retries opening a new attempt, and inherited fork prefixes excluded from totals. See [`src/host/fold.ts`](./src/host/fold.ts) for the implementation.
|
|
114
|
+
|
|
115
|
+
The HTTP surface is read-only and same-origin:
|
|
116
|
+
|
|
117
|
+
| Route | Purpose |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `GET /dsh-token-dashboard/stats` | Dashboard payload; supports ETag/`304` and `?refresh=1` |
|
|
120
|
+
| `GET /dsh-token-dashboard/requests` | Paginated request log; `?offset=0&limit=24` |
|
|
121
|
+
| `GET /dsh-token-dashboard/prices` | Optional OpenRouter prices; `?models=a,b&refresh=1` |
|
|
122
|
+
| `GET /dsh-token-dashboard/health` | Liveness, API version, and current revision |
|
|
123
|
+
| `GET /dsh-token-dashboard/verify` | Diagnostic comparison with the official `tokenUsage` projection |
|
|
124
|
+
|
|
125
|
+
All routes use the Host Connection gate when available and return `Cache-Control: no-store`; `/stats` is the only route with a weak ETag. No prompts, assistant text, tool arguments, credentials, or file contents are exposed.
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pnpm install
|
|
131
|
+
pnpm build # Host (tsc) + Client (esbuild)
|
|
132
|
+
pnpm typecheck # Host, Client, and Test type checks
|
|
133
|
+
pnpm test # 87 tests: unit, routes, SSR, jsdom, bundle
|
|
134
|
+
pnpm verify:real # fold real local logs against an independent reference
|
|
135
|
+
pnpm build:prices # refresh the generated OpenRouter price snapshot (network)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`pnpm verify:real` requires built artifacts and local session logs; it is the best check when changing the fold.
|
|
139
|
+
|
|
140
|
+
```text
|
|
141
|
+
src/host session source, token fold, aggregation, prices, HTTP routes
|
|
142
|
+
src/client React UI, DSH slots, hooks, theme-token styles
|
|
143
|
+
src/shared wire types, pricing, ranges, formatting
|
|
144
|
+
test node:test suites plus SSR/jsdom rendering checks
|
|
145
|
+
scripts build, test, and real-session verification
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Contributing
|
|
149
|
+
|
|
150
|
+
Issues and pull requests are welcome. Run `pnpm typecheck` and `pnpm test` before submitting; include a regression test for behavior changes and preserve the read-only, no-upload data contract.
|
|
151
|
+
|
|
152
|
+
## Limitations
|
|
153
|
+
|
|
154
|
+
- Covers the active DSH profile's local session store only; remote, cloud, and other-profile sessions are not included.
|
|
155
|
+
- The first dashboard open scans history into an in-memory cache. A DSH restart starts fresh; there is no persistent index.
|
|
156
|
+
- Request speed and first-token latency depend on recorded stream timestamps. Older logs, or requests without streams, show `—`.
|
|
157
|
+
- Cost is a list-price estimate in USD, not a bill. The built-in snapshot is dated **2026-10-30**; online refresh and user overrides can change the displayed estimate.
|
|
158
|
+
- Session navigation depends on the optional `uiWorkspace.openSession` host service.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
[MIT](./LICENSE) © 2026 小洋
|
|
163
|
+
|
|
164
|
+
Built for DeepSeek Harness and Cordis. Pricing data comes from the public OpenRouter model list and DeepSeek's published rates.
|
package/README.md
CHANGED
|
@@ -1,3 +1,164 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><a href="./README.md"><strong>中文</strong></a> · <a href="./README.en.md">English</a></p>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="./icon.svg" width="76" height="76" alt="dsh-token-dashboard" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">dsh-token-dashboard</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center"><strong>为每个 DeepSeek Harness 会话提供用量、费用与请求延迟。</strong></p>
|
|
10
|
+
|
|
11
|
+
<p align="center">一个本地优先的 Cordis 插件,把本地 DSH 会话历史变成原生看板。</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<img alt="DSH 0.2.1-rc.3" src="https://img.shields.io/badge/DSH-0.2.1--rc.3-4F6EF7?style=flat-square" />
|
|
15
|
+
<img alt="Cordis 插件" src="https://img.shields.io/badge/Cordis-plugin-2B3FB8?style=flat-square" />
|
|
16
|
+
<img alt="Node 22.18+" src="https://img.shields.io/badge/Node-%E2%89%A522.18-339933?style=flat-square&logo=nodedotjs&logoColor=white" />
|
|
17
|
+
<img alt="TypeScript 5.9" src="https://img.shields.io/badge/TypeScript-5.9-3178C6?style=flat-square&logo=typescript&logoColor=white" />
|
|
18
|
+
<img alt="MIT 许可证" src="https://img.shields.io/badge/License-MIT-2B3FB8?style=flat-square" />
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#功能">功能</a> ·
|
|
23
|
+
<a href="#快速开始">快速开始</a> ·
|
|
24
|
+
<a href="#使用">使用</a> ·
|
|
25
|
+
<a href="#架构">架构</a> ·
|
|
26
|
+
<a href="#开发">开发</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 概览
|
|
32
|
+
|
|
33
|
+
DSH 已经能显示当前会话的 Token 用量,但看不到完整视图:所有项目、模型、子代理、分叉和请求分散在各个会话里。
|
|
34
|
+
|
|
35
|
+
`@shi-yangyang/dsh-token-dashboard` 补上的就是这一层,以 **Token 用量** 的形式作为原生插件运行。
|
|
36
|
+
|
|
37
|
+
Host 端通过官方 `sessionPersistence` 服务读取会话日志,并使用与 `@deepseek-ai/dsh-token-meter` 一致的四桶口径折叠数据。Client 端通过 DSH Slot 注册 `main` 面板和侧边栏 footer 入口,使用宿主提供的 React 运行时和主题 Token 渲染。
|
|
38
|
+
|
|
39
|
+
插件不会写入会话日志、修改模型请求或上传会话数据。会话日志始终是唯一事实来源。
|
|
40
|
+
|
|
41
|
+
## 功能
|
|
42
|
+
|
|
43
|
+
- **全局用量视图**:当前 profile 下所有会话的总量、未缓存输入、输出、缓存读/写、请求数、缓存命中率和会话数。
|
|
44
|
+
- **时间范围联动**:今天、最近 7 / 30 / 90 天、全部时间或自定义日期范围;KPI 与 Usage 图表使用同一范围。
|
|
45
|
+
- **模型与会话**:可搜索、筛选、排序的分页表格,以及会话详情抽屉。
|
|
46
|
+
- **请求日志**:按每次计费请求展示时间、应用、供应商、模型、新增输入、输出、缓存命中、成本、速度和首字耗时。
|
|
47
|
+
- **费用估算**:内置 357 个 OpenRouter 模型快照与 DeepSeek 高峰价;可本地覆盖任意单价,也可按需从 OpenRouter 刷新。
|
|
48
|
+
- **原生与本地优先**:DSH Slot、主题 Token、中英文界面、同源只读路由;导出时自动去掉工作目录。
|
|
49
|
+
|
|
50
|
+
## 快速开始
|
|
51
|
+
|
|
52
|
+
本项目包名为 **`@shi-yangyang/dsh-token-dashboard`**。当前请按下文从源码构建并作为本地 bundle 安装。npm 上不带 scope 的 `dsh-token-dashboard` 属于另一个项目,请勿使用 `npm install dsh-token-dashboard` 安装本插件。
|
|
53
|
+
|
|
54
|
+
### 环境要求
|
|
55
|
+
|
|
56
|
+
- 可运行 Web UI 的 DeepSeek Harness。已在 DSH Desktop `0.2.1-rc.3`(Cordis `4.0.5`)验证。
|
|
57
|
+
- 从源码构建需要 Node.js **22.18 或更高版本** 和 `pnpm`。
|
|
58
|
+
|
|
59
|
+
### 构建
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/shi-YangYang/dsh-token-dashboard.git
|
|
63
|
+
cd dsh-token-dashboard
|
|
64
|
+
pnpm install
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`pnpm install` 会通过 `prepare` 自动构建 Host 和 Client,生成不入库的 `lib/` 和 `client/`。修改源码后可运行 `pnpm build` 重新构建。
|
|
68
|
+
|
|
69
|
+
### 安装到 DSH
|
|
70
|
+
|
|
71
|
+
在 DSH 的 **Plugins** 界面中选择本地 bundle 安装,目标指向本目录;也可以在 DSH Agent 中执行:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
plugin_manager(action: "install_bundle", target: "/absolute/path/to/dsh-token-dashboard")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
如果 profile 中禁用了该 bundle,请启用,然后刷新 DSH Web 页面。在侧边栏底部、Settings 上方打开 **Token 用量**。
|
|
78
|
+
|
|
79
|
+
更新 Host 代码后需要重启 DSH;仅修改 Client 时刷新页面即可。
|
|
80
|
+
|
|
81
|
+
## 使用
|
|
82
|
+
|
|
83
|
+
| 页面 | 内容 |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| **概览** | 所选范围内的全局 KPI 与 Usage 图表 |
|
|
86
|
+
| **模型** | 按供应商/模型统计的 Token 分布与请求数 |
|
|
87
|
+
| **会话** | 搜索、筛选、排序、分页和会话详情 |
|
|
88
|
+
| **请求日志** | 逐条计费请求,每页 12 条,最新在前 |
|
|
89
|
+
| **费用** | 预估总费用、逐模型明细、单价覆盖与在线价目刷新 |
|
|
90
|
+
|
|
91
|
+
顶部提供语言切换、扫描间隔、**立即同步**和导出。扫描间隔控制本地会话轮询:**5 / 10 / 30 / 60 秒**。所有列表每页最多 **12 行**,行高保持紧凑,分页位于卡片底部,不引入卡片或表格滚动条。
|
|
92
|
+
|
|
93
|
+
请求日志的成本按浏览器中的当前价目即时计算,未定价模型显示 `—`。速度 = 输出 Token / 实测请求窗口;首字 = `step/start` 到首个 stream record 的时间,没有 stream 时间戳时显示 `—`。
|
|
94
|
+
|
|
95
|
+
费用只是估算,不是 provider 账单。内置 DeepSeek 单价为高峰价,非高峰约为一半。单价覆盖和在线价目缓存保存在浏览器 `localStorage`。
|
|
96
|
+
|
|
97
|
+
## 架构
|
|
98
|
+
|
|
99
|
+
```mermaid
|
|
100
|
+
flowchart LR
|
|
101
|
+
Logs[(会话日志)] --> Host[Host 聚合器]
|
|
102
|
+
Live[session/event] --> Host
|
|
103
|
+
Host --> Fold[Token fold + revision 缓存]
|
|
104
|
+
Fold --> Routes[只读同源 JSON]
|
|
105
|
+
Routes --> Client[DSH Slot 内的 React 看板]
|
|
106
|
+
Client --> Views[概览 · 模型 · 会话 · 请求日志 · 费用]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- **Host**(`src/host`)读取官方会话存储、增量折叠用量、处理价目并提供看板 API。缓存只在内存中,按会话 revision 或 live sequence 维护;没有第二个数据库或账本。
|
|
110
|
+
- **Client**(`src/client`)注册 `main` 与 `sidebar.footer.action` Slot,管理扫描间隔、语言和价目偏好,并渲染看板。React 由宿主提供,不会重复打包。
|
|
111
|
+
- **Shared**(`src/shared`)包含双方共用的 wire 类型、四桶运算、范围选择、价目和格式化。
|
|
112
|
+
|
|
113
|
+
统计遵循 `tokenUsage` 的公开口径:四个互斥 provider 桶、同一次 attempt 的最终样本替换流式样本、重试开启新 attempt、分叉继承的前缀不计入总量。实现见 [`src/host/fold.ts`](./src/host/fold.ts)。
|
|
114
|
+
|
|
115
|
+
HTTP 接口只读且同源:
|
|
116
|
+
|
|
117
|
+
| 路由 | 用途 |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `GET /dsh-token-dashboard/stats` | 看板数据;支持 ETag/`304` 与 `?refresh=1` |
|
|
120
|
+
| `GET /dsh-token-dashboard/requests` | 分页请求日志;`?offset=0&limit=24` |
|
|
121
|
+
| `GET /dsh-token-dashboard/prices` | 可选 OpenRouter 在线价目;`?models=a,b&refresh=1` |
|
|
122
|
+
| `GET /dsh-token-dashboard/health` | 存活状态、API 版本和当前 revision |
|
|
123
|
+
| `GET /dsh-token-dashboard/verify` | 与官方 `tokenUsage` 投影的诊断对比 |
|
|
124
|
+
|
|
125
|
+
存在 Host Connection 时,所有路由都会复用其鉴权,并返回 `Cache-Control: no-store`;只有 `/stats` 带弱 ETag。接口不会暴露 prompt、assistant 文本、工具参数、凭据或文件内容。
|
|
126
|
+
|
|
127
|
+
## 开发
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pnpm install
|
|
131
|
+
pnpm build # Host(tsc)+ Client(esbuild)
|
|
132
|
+
pnpm typecheck # Host、Client、Test 三套类型检查
|
|
133
|
+
pnpm test # 87 个测试:单元、路由、SSR、jsdom、bundle
|
|
134
|
+
pnpm verify:real # 用独立实现校验真实本地日志折叠
|
|
135
|
+
pnpm build:prices # 刷新 OpenRouter 内置价目快照(需要网络)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`pnpm verify:real` 需要已构建产物和本地会话日志;修改 fold 时优先运行它。
|
|
139
|
+
|
|
140
|
+
```text
|
|
141
|
+
src/host 会话源、Token fold、聚合、价目、HTTP 路由
|
|
142
|
+
src/client React 界面、DSH Slot、hooks、主题 Token 样式
|
|
143
|
+
src/shared wire 类型、价目、范围、格式化
|
|
144
|
+
test node:test 测试与 SSR/jsdom 渲染检查
|
|
145
|
+
scripts 构建、测试、真实会话校验
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 贡献
|
|
149
|
+
|
|
150
|
+
欢迎提交 Issue 和 Pull Request。提交前请运行 `pnpm typecheck` 与 `pnpm test`;行为变更请补充回归测试,并保持只读、不上传数据的边界。
|
|
151
|
+
|
|
152
|
+
## 已知限制
|
|
153
|
+
|
|
154
|
+
- 只覆盖当前 DSH profile 的本地会话存储;远程、云端和其他 profile 的会话不包含在内。
|
|
155
|
+
- 首次打开会把历史扫描进内存缓存。DSH 重启后缓存清空,没有持久化索引。
|
|
156
|
+
- 请求速度和首字依赖日志中的 stream 时间戳;旧日志或没有 stream 的请求显示 `—`。
|
|
157
|
+
- 费用是以 USD 计的列表价估算,不是账单。内置快照日期为 **2026-10-30**;在线刷新和用户覆盖会改变估算结果。
|
|
158
|
+
- 会话跳转依赖可选的 `uiWorkspace.openSession` 宿主服务。
|
|
159
|
+
|
|
160
|
+
## 许可证
|
|
161
|
+
|
|
162
|
+
[MIT](./LICENSE) © 2026 小洋
|
|
163
|
+
|
|
164
|
+
为 DeepSeek Harness 与 Cordis 构建。价目数据来自公开的 OpenRouter 模型列表和 DeepSeek 公布的单价。
|