dsh-usage-spend 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.md +76 -2
- package/README.zh.md +77 -0
- package/cordis.patch.yml +11 -0
- package/icon.svg +4 -0
- package/lib/client.js +1250 -0
- package/lib/index.js +20 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +72 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 itiswaller
|
|
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,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Usage and spend (dsh-usage-spend)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shows the session's token usage and an **estimated spend** under the DSH composer, and appends the amount to the built-in per-turn usage action. Currency and exchange rate are configured on the **Plugins** page.
|
|
4
|
+
|
|
5
|
+
One package is both the bundle (it declares the `usage-cost` row) and the feature itself, so installing it gives you a card on the Plugins page.
|
|
6
|
+
|
|
7
|
+
## What you get
|
|
8
|
+
|
|
9
|
+
- **Composer usage pill**: `85.3M tok · ≈¥3.09 · cache hit 99.4%`, replacing the built-in `usage` row.
|
|
10
|
+
- **Click the card**: the header shows the exact token count and amount, followed by buckets for cache hits, uncached input, cache reads, cache writes and output.
|
|
11
|
+
- **Per-turn action**: the built-in `用量 85.3M tok` becomes `85.3M tok · ≈¥3.09`.
|
|
12
|
+
- **Plugins page settings**: currency (CNY / USD / both), exchange rate, and whether to show the sidebar balance, with a read-only price table below the form.
|
|
13
|
+
- **Sidebar balance**: `余额 ¥12.34` at the bottom of the sidebar, refreshed every 60 seconds or on click; the grant is in the tooltip; collapsed the sidebar shows a compact amount. Can be turned off.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
dsh plugin --profile <profile> add dsh-usage-spend
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or in DSH Desktop / Web open **Plugins → Add plugin**, enter `dsh-usage-spend`, then choose **Enable now**. Restart or reload afterwards.
|
|
22
|
+
|
|
23
|
+
Open **Plugins** and expand the **Usage and spend** card to confirm the `usage-cost` row is on.
|
|
24
|
+
|
|
25
|
+
## Settings
|
|
26
|
+
|
|
27
|
+
Click **Configure** on the row; changes apply immediately. They are written to the profile's `cordis.patch.yml`:
|
|
28
|
+
|
|
29
|
+
```yaml
|
|
30
|
+
- id: usage-cost
|
|
31
|
+
name: 'dsh-usage-spend'
|
|
32
|
+
config:
|
|
33
|
+
currency: CNY # CNY | USD | BOTH
|
|
34
|
+
usdToCny: 7.2
|
|
35
|
+
showBalance: true
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Turning the row off removes the pill, the per-turn amount and the sidebar balance; turning it back on restores them.
|
|
39
|
+
|
|
40
|
+
## How the estimate works
|
|
41
|
+
|
|
42
|
+
The price table is a models.dev snapshot of DeepSeek pricing (USD / 1M tokens):
|
|
43
|
+
|
|
44
|
+
| Model | Input | Cache read | Cache write | Output |
|
|
45
|
+
|---|---:|---:|---:|---:|
|
|
46
|
+
| `deepseek-flash` / `deepseek-v4-flash` / `deepseek-v4-flash-vision-exp` | 0.15 | 0.003 | 0.15 | 0.60 |
|
|
47
|
+
| `deepseek-v4-pro` | 0.66 | 0.022 | 0.66 | 1.98 |
|
|
48
|
+
| `deepseek-chat` / `deepseek-reasoner` | 0.28 | 0.028 | 0.28 | 0.42 |
|
|
49
|
+
|
|
50
|
+
- Cost = uncached input × input price + cache reads × cache-read price + cache writes × cache-write price + output × output price.
|
|
51
|
+
- The CNY amount is converted with the configured rate, `7.2` by default.
|
|
52
|
+
- Peak/off-peak multipliers, discounts, granted credit and the platform's actual bill are **not** included. This is an estimate only.
|
|
53
|
+
- Per-turn amounts prefer the exact usage recorded in the session; when that is unavailable they sum the turn's assistant messages and show `≈`.
|
|
54
|
+
|
|
55
|
+
## Custom prices
|
|
56
|
+
|
|
57
|
+
Write `localStorage["dsh.cost.prices"]` from the browser console, keyed by model name (USD / 1M tokens):
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"deepseek-flash": { "input": 0.15, "cacheRead": 0.003, "cacheWrite": 0.15, "output": 0.6 }
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Keys may be the full model name, `provider/model`, or the bare model name. Reload to apply.
|
|
66
|
+
|
|
67
|
+
## Compatibility and limits
|
|
68
|
+
|
|
69
|
+
- Targets the client slot / projection API of DSH `0.2.2-rc.1`.
|
|
70
|
+
- The per-turn text is rewritten through a DOM observer; if a DSH release changes the built-in button's structure it degrades to the original `用量 N tok` and never affects the session.
|
|
71
|
+
- Switching models inside a session estimates the whole session at the current model's prices.
|
|
72
|
+
- The sidebar balance calls `account.getBalance` (DeepSeek account) and shows `--` when signed out or when the read fails. It is the platform's balance, not a local estimate.
|
|
73
|
+
- Currency and rate come from host settings; when the settings service is unavailable it falls back to `localStorage` (`dsh.cost.currency` / `dsh.cost.usdToCny`).
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# 用量与花费(dsh-usage-spend)
|
|
2
|
+
|
|
3
|
+
在 DSH 的输入框下方显示本次会话的 token 用量与**估算花费**,并把金额补到内置的每轮用量按钮上。币种和汇率在 **插件** 页配置。
|
|
4
|
+
|
|
5
|
+
一个包同时是 bundle(声明 `usage-cost` 这一行)和功能本体,装上即出现插件页卡片。
|
|
6
|
+
|
|
7
|
+
## 功能
|
|
8
|
+
|
|
9
|
+
- **底部用量 pill**:`85.3M tok · ≈¥3.09 · 缓存命中 99.4%`,替换内置的 `usage` 行。
|
|
10
|
+
- **点击卡片**:标题行显示精确 token 数与金额,下面是缓存命中、未缓存输入、缓存读取、缓存写入、输出的分桶。
|
|
11
|
+
- **每轮按钮**:把内置的 `用量 85.3M tok` 改成 `85.3M tok · ≈¥3.09`。
|
|
12
|
+
- **插件页配置**:`币种`(人民币 / 美元 / 同时显示)、`汇率(1 USD = ? CNY)`、是否显示左侧栏余额,并在表单下方以只读表格展示当前单价表。
|
|
13
|
+
- **左侧栏余额**:在侧栏底部显示 `余额 ¥12.34`,每 60 秒或点击时刷新;赠金放在 tooltip 里;折叠栏显示紧凑金额。可关闭。
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
dsh plugin --profile <profile> add dsh-usage-spend
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
或者在 DSH 桌面端 / Web 的 **插件 → 添加插件** 里输入包名 `dsh-usage-spend`,装完点 **立即启用**。之后重启或刷新页面。
|
|
22
|
+
|
|
23
|
+
启用后打开 **插件** 页,能看到 **用量与花费** 卡片,展开确认 `usage-cost` 行是开启的。
|
|
24
|
+
|
|
25
|
+
## 配置
|
|
26
|
+
|
|
27
|
+
点该行的 **配置** 修改,保存后立即生效。配置写入 profile 的 `cordis.patch.yml`:
|
|
28
|
+
|
|
29
|
+
```yaml
|
|
30
|
+
- id: usage-cost
|
|
31
|
+
name: 'dsh-usage-spend'
|
|
32
|
+
config:
|
|
33
|
+
currency: CNY # CNY | USD | BOTH
|
|
34
|
+
usdToCny: 7.2
|
|
35
|
+
showBalance: true
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
关闭该行会移除底部 pill、每轮金额与侧栏余额;重新打开即恢复。
|
|
39
|
+
|
|
40
|
+
## 估算口径
|
|
41
|
+
|
|
42
|
+
价格表是 models.dev 的 DeepSeek 快照(USD / 1M token):
|
|
43
|
+
|
|
44
|
+
| 模型 | 输入 | 缓存读 | 缓存写 | 输出 |
|
|
45
|
+
|---|---:|---:|---:|---:|
|
|
46
|
+
| `deepseek-flash` / `deepseek-v4-flash` / `deepseek-v4-flash-vision-exp` | 0.15 | 0.003 | 0.15 | 0.60 |
|
|
47
|
+
| `deepseek-v4-pro` | 0.66 | 0.022 | 0.66 | 1.98 |
|
|
48
|
+
| `deepseek-chat` / `deepseek-reasoner` | 0.28 | 0.028 | 0.28 | 0.42 |
|
|
49
|
+
|
|
50
|
+
- 费用 = 未缓存输入 × 输入价 + 缓存读取 × 缓存读价 + 缓存写入 × 缓存写价 + 输出 × 输出价。
|
|
51
|
+
- 人民币金额按配置的汇率换算,默认 `7.2`。
|
|
52
|
+
- **不包含**峰谷倍率、折扣、赠送额度或平台实际账单,只用于估算。
|
|
53
|
+
- 每轮金额优先使用会话里的精确用量;精确用量不可得时按该轮 assistant 消息求和并显示 `≈`。
|
|
54
|
+
|
|
55
|
+
## 自定义价格
|
|
56
|
+
|
|
57
|
+
在浏览器控制台写入 `localStorage["dsh.cost.prices"]`,格式为「模型名 → USD / 1M token」:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"deepseek-flash": { "input": 0.15, "cacheRead": 0.003, "cacheWrite": 0.15, "output": 0.6 }
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
键可以是完整模型名、`provider/model` 或裸模型名;刷新页面生效。
|
|
66
|
+
|
|
67
|
+
## 兼容性与限制
|
|
68
|
+
|
|
69
|
+
- 面向 DSH `0.2.2-rc.1` 的客户端 slot / projection API。
|
|
70
|
+
- 每轮按钮的文字通过 DOM 观察器改写内置按钮;DSH 改版后结构变化可能让它退化为原来的 `用量 N tok`,不影响会话。
|
|
71
|
+
- 会话内切换模型时,整段会话按当前模型单价估算。
|
|
72
|
+
- 左侧栏余额调用 `account.getBalance`(DeepSeek 账号),未登录或读取失败时显示 `--`;余额来自平台,不是本地估算。
|
|
73
|
+
- 币种与汇率优先读 Host 配置;设置服务不可用时退回 `localStorage`(`dsh.cost.currency` / `dsh.cost.usdToCny`)。
|
|
74
|
+
|
|
75
|
+
## 许可
|
|
76
|
+
|
|
77
|
+
MIT
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Bundle layer for dsh-usage-spend.
|
|
2
|
+
# One row per feature; the row points at this same package, which also carries
|
|
3
|
+
# the browser half through `dsh.client`. The row id stays stable so profile
|
|
4
|
+
# patches and the settings key `<package>#<row id>` keep working across versions.
|
|
5
|
+
- insert:
|
|
6
|
+
- id: usage-cost
|
|
7
|
+
name: 'dsh-usage-spend'
|
|
8
|
+
config:
|
|
9
|
+
currency: CNY
|
|
10
|
+
usdToCny: 7.2
|
|
11
|
+
showBalance: true
|
package/icon.svg
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">
|
|
2
|
+
<rect x="3" y="5" width="26" height="22" rx="6" stroke="currentColor" stroke-width="2"/>
|
|
3
|
+
<path d="M8 20V16M13 20V12M18 20V18M23 20V10" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/>
|
|
4
|
+
</svg>
|