dsh-model-billing 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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-10-20
4
+
5
+ ### Added
6
+
7
+ - Custom ordering for configured models in the composer model picker.
8
+ - Three editable per-million-token prices per model: cache-hit input, cache-miss input, and output.
9
+ - Built-in official DeepSeek peak/off-peak prices for `deepseek-flash` and `deepseek-v4-pro`, selected from each usage event's Beijing time.
10
+ - Per-turn and session cost estimates with a composer summary, turn-tail amount, and a detail panel grouped by turn and model.
11
+ - Local persistence at `~/.dsh/model-billing.json` with atomic writes.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 likaileave
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,173 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="icon.svg" width="72" height="72" alt="dsh-model-billing icon">
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <h1 align="center">dsh-model-billing</h1>
6
+
7
+ <p align="center">为 DeepSeek Harness Web GUI 调整模型顺序,并按轮次估算模型费用。</p>
8
+
9
+ <p align="center">
10
+ <a href="#中文">中文</a> · <a href="#english">English</a> · <a href="CHANGELOG.md">Changelog</a>
11
+ </p>
12
+
13
+ ## 中文
14
+
15
+ `dsh-model-billing` 是一个 DSH Web 客户端插件。它接管输入框右下角的模型选择器,让你按自己的顺序排列模型,并为每个模型维护三档 token 价格;会话过程中按实际 usage 估算每一轮和整个会话的费用。
16
+
17
+ ### 功能
18
+
19
+ - **自定义模型顺序**:在“设置 → 模型与费用”中用 ↑ / ↓ 调整已配置模型的顺序。模型选择器按这个顺序展示,跨提供方也保持你排的顺序,并用提供方名称分组。
20
+ - **三档 token 价格**:每个非 DeepSeek 模型可填写每百万 tokens 的缓存命中输入、缓存未命中输入、输出价格。`0` 是有效价格,留空表示未设置。
21
+ - **DeepSeek 官方价内置**:`deepseek-flash` 和 `deepseek-v4-pro` 直接使用 DeepSeek 官网的峰谷价,只读展示,不需要填写。
22
+ - **逐轮费用**:每轮结束后在轮尾显示该轮费用。
23
+ - **本会话费用**:输入框下方显示本会话累计估算、最近一轮费用和缓存命中率;展开后可查看按轮次和按模型的明细。
24
+ - **DeepSeek 也计入金额**:每条 usage 按事件发生时的北京时间自动选择高峰或空闲价,与第三方模型一起进入统计。
25
+
26
+ ### 估算口径
27
+
28
+ ```text
29
+ 缓存命中输入 × 命中价
30
+ +(未缓存输入 + 缓存写入)× 未命中价
31
+ + 输出 × 输出价
32
+ ```
33
+
34
+ 价格单位是“元 / 百万 tokens”。缓存写入按缓存未命中价计算,这是三档价格模型下的近似处理。金额来自会话日志中的 provider usage,实际账单以 provider 为准。
35
+
36
+ ### DeepSeek 官方价
37
+
38
+ 以下价格内置在 [`host.js`](host.js) 的 `DEEPSEEK_PRICES` 中,单位“元 / 百万 tokens”。来源:[DeepSeek 模型 & 价格](https://api-docs.deepseek.com/zh-cn/quick_start/pricing/)(查询于 2026-10-19)。
39
+
40
+ | 模型 | 时段 | 缓存命中 | 缓存未命中 | 输出 |
41
+ |---|---|---:|---:|---:|
42
+ | deepseek-flash | 高峰 | 0.04 | 2 | 8 |
43
+ | deepseek-flash | 空闲 | 0.02 | 1 | 4 |
44
+ | deepseek-v4-pro | 高峰 | 0.30 | 9 | 27 |
45
+ | deepseek-v4-pro | 空闲 | 0.15 | 4.5 | 13.5 |
46
+
47
+ 高峰时段为北京时间周一至周五 `9:00–12:00`、`14:00–18:00`(中国法定节假日除外);其余时间、周末和法定节假日全天为空闲时段。空闲价是高峰价的一半。
48
+
49
+ DeepSeek 价格只读,不写入本地价格配置。官网调价或节假日安排变化后,需要更新 `host.js` 中的 `DEEPSEEK_PRICES` 和 `DEEPSEEK_HOLIDAYS`;目前内置的是 2026 年节假日。
50
+
51
+ ### 其他模型价格
52
+
53
+ 插件**不预置**第三方模型价格。首次使用时,在“设置 → 模型与费用”中按 provider 的官方价填写三档价格即可;未填完整价格的模型不会产生金额,界面会标记“未定价”或“部分未定价”。
54
+
55
+ 不同平台的缓存折扣、上下文阶梯价和活动价差异较大,建议直接使用你的实际结算价。插件不做自动抓取,也不猜测默认价。
56
+
57
+ ### 安装
58
+
59
+ **从 dsh-market 安装(上架后)**
60
+
61
+ 在 dsh-market 中搜索 `dsh-model-billing` 安装。
62
+
63
+ **从 GitHub Release 手动安装**
64
+
65
+ 1. 从 [Releases](https://github.com/likaileave/dsh-model-billing/releases) 下载 `dsh-model-billing.tgz`。
66
+ 2. 执行:
67
+
68
+ ```sh
69
+ dsh plugin --profile desktop add ./dsh-model-billing.tgz
70
+ ```
71
+
72
+ 把 `desktop` 换成你实际使用的 profile。
73
+
74
+ **从源码安装**
75
+
76
+ ```sh
77
+ git clone https://github.com/likaileave/dsh-model-billing.git
78
+ dsh plugin --profile desktop add ./dsh-model-billing
79
+ ```
80
+
81
+ 安装或更新后刷新 Web 页面。设置页位于“模型与费用”。
82
+
83
+ ### 数据位置
84
+
85
+ 模型顺序和价格保存在:
86
+
87
+ ```text
88
+ ~/.dsh/model-billing.json
89
+ ```
90
+
91
+ 若设置了 `DSH_HOME`,则为 `$DSH_HOME/model-billing.json`。保存时先写临时文件再原子替换;文件损坏时回退为空配置,不会在未保存的情况下覆盖原文件。
92
+
93
+ ### 已知限制
94
+
95
+ - 模型选择器由本插件接管,依赖 `ctx.modelDirectories`。该服务不可用时,插件不会强行覆盖内置选择器,价格和费用统计不受影响。
96
+ - `/model` 命令仍由 DSH 自带实现,顺序不保证与右下角选择器一致。
97
+ - 一轮里的多次模型尝试(重试、失败等)会分别计入;失败调用如果 provider 没有返回 usage,则无法计入。
98
+ - 只统计当前载入 Host 的会话;未打开的历史会话在进入后按需计算。
99
+ - 第三方价格是静态配置,不会自动跟随官网调价。
100
+
101
+ ### 开发
102
+
103
+ ```sh
104
+ node --check host.js
105
+ node --check client.js
106
+ node --test test/host.test.mjs test/routes.test.mjs
107
+ ```
108
+
109
+ 当前 10 个测试通过。插件没有运行时 npm 依赖。
110
+
111
+ ### License
112
+
113
+ [MIT](LICENSE) © 2026 likaileave
114
+
115
+ ---
116
+
117
+ ## English
118
+
119
+ `dsh-model-billing` is a DSH Web GUI plugin that takes over the composer's model picker, lets you order configured models yourself, stores three per-million-token prices per model, and estimates per-turn and session cost from provider usage.
120
+
121
+ ### Features
122
+
123
+ - **Custom model order** in Settings → Models & Cost; the composer picker follows that order across providers and groups models by provider.
124
+ - **Three prices per model**: cache-hit input, cache-miss input, and output, in CNY per million tokens. `0` is a valid price; blank means unset.
125
+ - **Built-in official DeepSeek pricing** for `deepseek-flash` and `deepseek-v4-pro`, selected per usage event between peak and off-peak Beijing time.
126
+ - **Per-turn amount** at the end of each turn.
127
+ - **Session summary** below the composer plus a detail panel grouped by turn and by model.
128
+ - **DeepSeek is billed too**, using the same three-price formula and the event's timestamp.
129
+
130
+ ### Cost formula
131
+
132
+ ```text
133
+ cache-hit input × hit price
134
+ + (uncached input + cache write) × miss price
135
+ + output × output price
136
+ ```
137
+
138
+ Prices are CNY per million tokens. Cache writes are approximated at the cache-miss price. Figures come from provider usage in the session log; the provider's invoice is authoritative.
139
+
140
+ The plugin ships **no third-party price defaults**. Enter your provider's actual rates in Settings → Models & Cost. Models without a complete three-price set are marked as unpriced and contribute no amount. DeepSeek prices are read-only and built into `host.js`.
141
+
142
+ ### Install
143
+
144
+ From dsh-market after listing, or manually from a [Release](https://github.com/likaileave/dsh-model-billing/releases):
145
+
146
+ ```sh
147
+ dsh plugin --profile desktop add ./dsh-model-billing.tgz
148
+ ```
149
+
150
+ From a checkout:
151
+
152
+ ```sh
153
+ git clone https://github.com/likaileave/dsh-model-billing.git
154
+ dsh plugin --profile desktop add ./dsh-model-billing
155
+ ```
156
+
157
+ Refresh the Web page after installing or updating.
158
+
159
+ ### Data
160
+
161
+ Order and prices live in `~/.dsh/model-billing.json` (or `$DSH_HOME/model-billing.json`). Writes use a temporary file plus atomic replace.
162
+
163
+ ### Limitations
164
+
165
+ - The custom picker depends on `ctx.modelDirectories`; when that service is unavailable the plugin leaves the built-in picker alone.
166
+ - The `/model` command is still implemented by DSH and may not follow the custom order.
167
+ - Multiple attempts within a turn are counted separately; failed calls without provider usage cannot be counted.
168
+ - Only sessions loaded by the current Host are counted.
169
+ - Third-party prices are static and are not refreshed automatically.
170
+
171
+ ### License
172
+
173
+ [MIT](LICENSE) © 2026 likaileave