dsh-cost-meter 1.5.26 → 1.5.28
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/README.en.md +7 -6
- package/README.md +7 -6
- package/lib/client.js +225 -0
- package/lib/store.js +25 -0
- package/lib/typert.host.js +8 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
**Session cost tracking plugin for the DeepSeek Harness web GUI (bilingual UI)**
|
|
6
6
|
|
|
7
|
-
Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 90+ model price catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet)
|
|
7
|
+
Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 90+ model price catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet) · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
|
|
8
8
|
|
|
9
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
10
10
|
[](https://www.npmjs.com/package/dsh-cost-meter)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
@@ -30,6 +30,7 @@ English | [中文](README.md)
|
|
|
30
30
|
| Custom provider balance | Sidebar / Settings page (configurable) | Configurable HTTP balance lookup (e.g. LiteLLM); bilingual labels, currency, extract rules; collapsible panel alongside Coding Plan quotas |
|
|
31
31
|
| OpenCode Go quota | Sidebar / Settings / bottom-right dock (configurable) | Rolling-5h / weekly / monthly usage percent and reset times, each window toggleable independently, budget used % can show alongside; key auto-discovered (DSH credential store OPENCODE_GO_API_KEY / env / opencode login) or entered manually |
|
|
32
32
|
| Coding plan quotas | Sidebar / Settings page (per vendor) | Multi-vendor coding-plan quota queries (Anthropic Claude Pro/Max, Z.ai / Zhipu GLM Coding Plan, MiniMax Token Plan, Kimi/Moonshot balance, OpenRouter credits, SiliconFlow balance, CommandCode 5h/weekly windows + monthly credits balance); per-vendor enable switch, key and display position (sidebar card in the same box style as the Go quota; the collapsed rail shows percentages), credentials only sent to official endpoints; neutral hints when no credentials/subscription; SCNet Token Plan has no quota API — monthly usage is estimated from the local ledger via the official credits deduction table (no credentials needed) |
|
|
33
|
+
| Quota strip | Above the input box (toggle in Display settings) | One compact chip row for budget used % / the Go main window / each enabled coding-plan usage window (short label + mini progress bar, ≥80% warn, ≥100% over, hover for reset times); a first-run guide card lets you decide whether to enable it; hides itself when there is no quota data |
|
|
33
34
|
| Today's cost | Sidebar bottom (above the settings button) | “Today ¥x”, hover for call count and token details |
|
|
34
35
|
| Budget box | Sidebar bottom (between the balance row and the settings button) | Rounded-square frame: budget, used %, progress bar, today's cost & share of budget, used/limit; ≥80% warning, ≥100% over-budget |
|
|
35
36
|
| Summary cards | Settings page | Today / this month / cumulative cost and call counts |
|
|
@@ -194,22 +195,22 @@ Real captures from an actual DSH sidebar of the period strip and collapsed verti
|
|
|
194
195
|
dsh plugin --profile web add dsh-cost-meter
|
|
195
196
|
```
|
|
196
197
|
|
|
197
|
-
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.5.
|
|
198
|
+
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.5.28`** — review the script before running):
|
|
198
199
|
|
|
199
200
|
```powershell
|
|
200
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.
|
|
201
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.28/install.ps1 | iex
|
|
201
202
|
```
|
|
202
203
|
|
|
203
204
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
204
205
|
|
|
205
206
|
```sh
|
|
206
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.
|
|
207
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.28
|
|
207
208
|
```
|
|
208
209
|
|
|
209
210
|
Without git, use the GitHub tag archive:
|
|
210
211
|
|
|
211
212
|
```sh
|
|
212
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.
|
|
213
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.28.tar.gz
|
|
213
214
|
```
|
|
214
215
|
|
|
215
216
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
**DeepSeek Harness 会话费用统计插件(界面中英双语)**
|
|
6
6
|
|
|
7
|
-
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet 八家)
|
|
7
|
+
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet 八家) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
|
|
8
8
|
|
|
9
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
10
10
|
[](https://www.npmjs.com/package/dsh-cost-meter)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
| 自定义 Provider 余额 | 侧边栏 / 设置页(可配) | 可配置 HTTP 查询任意 Provider 余额(LiteLLM 等);中/英名称、币种、extract 规则;与 Coding Plan 同区可折叠配置 |
|
|
31
31
|
| OpenCode Go 额度 | 侧边栏 / 设置页 / 右下角(dock,可配) | 滚动 5 小时 / 本周 / 本月用量百分比与重置时间,三档可分别开关,可同时显示预算已用%;Key 自动发现(DSH 凭据库 OPENCODE_GO_API_KEY / 环境变量 / opencode 登录态)或手动填写 |
|
|
32
32
|
| Coding Plan 额度 | 侧边栏 / 设置页(每家可配) | 多厂商 coding plan 订阅额度查询(Anthropic Claude Pro/Max、Z.ai/智谱 GLM、MiniMax Token Plan、Kimi/Moonshot 余额、OpenRouter credits、SiliconFlow 余额、CommandCode 5h/周窗口与月度 Credits 余额),各家独立启用开关、Key 与显示位置(侧边栏卡片与 Go 额度同款,收起窄栏显示百分比),凭据只发往官方端点;无凭据/无订阅为中性提示;SCNet 超算互联网 Token Plan 无 API 额度端点,按官方 Credits 抵扣表由本地账本估算月度用量(无需凭据) |
|
|
33
|
+
| 额度横条 | 输入框上方(显示设置可开关) | 一条横排 chips 实时显示预算已用% / Go 主窗口 / 各已启用 Coding Plan 用量窗口(短标签+迷你进度条,≥80% 预警、≥100% 超支,悬停见重置时刻);首次更新弹引导卡由用户自主决定开关;无可用数据自动隐藏 |
|
|
33
34
|
| 当日费用 | 侧边栏底部(设置按钮上方) | 「今日 ¥x」,悬停见调用次数与 token 明细 |
|
|
34
35
|
| 预算图框 | 侧边栏底部(余额行与设置按钮之间) | 圆角方形图框:预算、已用%、进度条、今日费用与占预算%、已用/额度,≥80% 预警、≥100% 超支 |
|
|
35
36
|
| 汇总卡片 | 设置页 | 今日 / 本月 / 累计费用与调用次数 |
|
|
@@ -196,22 +197,22 @@
|
|
|
196
197
|
dsh plugin --profile web add dsh-cost-meter
|
|
197
198
|
```
|
|
198
199
|
|
|
199
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.
|
|
200
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.28`**,建议先下载审阅再运行):
|
|
200
201
|
|
|
201
202
|
```powershell
|
|
202
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.
|
|
203
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.28/install.ps1 | iex
|
|
203
204
|
```
|
|
204
205
|
|
|
205
206
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
206
207
|
|
|
207
208
|
```sh
|
|
208
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.
|
|
209
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.28
|
|
209
210
|
```
|
|
210
211
|
|
|
211
212
|
没有 git 时可用 GitHub tag 打包直链:
|
|
212
213
|
|
|
213
214
|
```sh
|
|
214
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.
|
|
215
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.28.tar.gz
|
|
215
216
|
```
|
|
216
217
|
|
|
217
218
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
package/lib/client.js
CHANGED
|
@@ -53,6 +53,22 @@ window.__ModuleLoader__.load({
|
|
|
53
53
|
'.cm-corner-chip:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
54
54
|
'.cm-corner-chip.warn{color:var(--dsw-alias-state-warn-primary)}',
|
|
55
55
|
'.cm-corner-chip.over{color:var(--dsw-alias-state-error-primary)}',
|
|
56
|
+
// 输入框上方额度横条(issue #31 后续):横排 chips,每片 = 短标签 + 迷你进度条 + 百分比。
|
|
57
|
+
'.cm-qstrip{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:6px;width:100%;max-width:var(--dsh-chat-content-width,720px);margin:0 auto;box-sizing:border-box;padding:0 calc(var(--dsh-composer-side-clearance,0px) + 16px)}',
|
|
58
|
+
'.cm-qchip{display:inline-flex;align-items:center;gap:6px;height:22px;padding:0 8px;border-radius:6px;background:var(--dsw-alias-bg-layer-2);font-size:11px;line-height:22px;color:var(--dsw-alias-label-secondary);white-space:nowrap;font-variant-numeric:tabular-nums;cursor:default}',
|
|
59
|
+
'.cm-qchip:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
60
|
+
'.cm-qchip .cm-qlabel{color:var(--dsw-alias-label-primary);font-weight:600}',
|
|
61
|
+
'.cm-qchip .cm-qbar{width:44px;height:4px;border-radius:2px;background:var(--dsw-alias-border-l1);overflow:hidden;flex:none}',
|
|
62
|
+
'.cm-qchip .cm-qfill{height:100%;border-radius:2px;background:var(--dsw-alias-state-ok-primary,#3ba272)}',
|
|
63
|
+
'.cm-qchip.warn{color:var(--dsw-alias-state-warn-primary)}',
|
|
64
|
+
'.cm-qchip.warn .cm-qfill{background:var(--dsw-alias-state-warn-primary)}',
|
|
65
|
+
'.cm-qchip.over{color:var(--dsw-alias-state-error-primary)}',
|
|
66
|
+
'.cm-qchip.over .cm-qfill{background:var(--dsw-alias-state-error-primary)}',
|
|
67
|
+
// 首次更新引导:非模态小卡片,固定屏幕顶部居中,选择后消失。
|
|
68
|
+
'.cm-qguide{position:fixed;top:18px;left:50%;transform:translateX(-50%);z-index:9999;max-width:440px;width:calc(100% - 32px);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);box-shadow:0 8px 28px rgba(0,0,0,.18);padding:14px 16px;font-size:13px;color:var(--dsw-alias-label-primary);display:flex;flex-direction:column;gap:8px}',
|
|
69
|
+
'.cm-qguide h4{margin:0;font-size:13px;font-weight:600}',
|
|
70
|
+
'.cm-qguide p{margin:0;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary)}',
|
|
71
|
+
'.cm-qguide .cm-buttons{display:flex;gap:8px;justify-content:flex-end}',
|
|
56
72
|
'.cm-section{display:flex;flex-direction:column;gap:20px;padding:4px 2px 24px;font-size:13px;color:var(--dsw-alias-label-primary)}',
|
|
57
73
|
'.cm-cards{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}',
|
|
58
74
|
'.cm-card{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;padding:14px 16px;background:var(--dsw-alias-bg-layer-1)}',
|
|
@@ -579,6 +595,16 @@ window.__ModuleLoader__.load({
|
|
|
579
595
|
positionDock: '输入区下方',
|
|
580
596
|
positionHeader: '会话标题栏',
|
|
581
597
|
off: '关闭',
|
|
598
|
+
quotaStripGroup: '输入框上方额度横条',
|
|
599
|
+
quotaStripEnable: '启用额度横条(输入框上方一条横排显示)',
|
|
600
|
+
quotaStripShowBudget: '横条含预算已用%',
|
|
601
|
+
quotaStripShowGo: '横条含 Go 额度',
|
|
602
|
+
quotaStripShowPlans: '横条含 Coding Plan 额度',
|
|
603
|
+
quotaStripNote: '横条悬停可见各窗口重置时刻与更新时间;无可用额度数据时自动隐藏。',
|
|
604
|
+
quotaStripGuideTitle: '新增:输入框上方额度横条',
|
|
605
|
+
quotaStripGuideBody: '可以在输入框上方用一条横条实时查看预算与多家订阅额度(OpenCode Go / Coding Plan)的用量百分比。要现在开启吗?可随时在「设置 → 显示设置」中更改。',
|
|
606
|
+
quotaStripGuideOn: '开启横条',
|
|
607
|
+
quotaStripGuideOff: '暂不开启',
|
|
582
608
|
sidebarLabel: '当日费用显示',
|
|
583
609
|
sidebarOn: '侧边栏底部',
|
|
584
610
|
currencyLabel: '货币单位',
|
|
@@ -913,6 +939,16 @@ window.__ModuleLoader__.load({
|
|
|
913
939
|
positionDock: 'Below the composer',
|
|
914
940
|
positionHeader: 'Session title bar',
|
|
915
941
|
off: 'Off',
|
|
942
|
+
quotaStripGroup: 'Quota strip above the input',
|
|
943
|
+
quotaStripEnable: 'Enable the quota strip (one row above the input box)',
|
|
944
|
+
quotaStripShowBudget: 'Strip includes budget used %',
|
|
945
|
+
quotaStripShowGo: 'Strip includes the Go quota',
|
|
946
|
+
quotaStripShowPlans: 'Strip includes coding plan quotas',
|
|
947
|
+
quotaStripNote: 'Hover a chip for reset times and the last refresh; the strip hides itself when there is no quota data.',
|
|
948
|
+
quotaStripGuideTitle: 'New: quota strip above the input',
|
|
949
|
+
quotaStripGuideBody: 'Show budget and subscription quotas (OpenCode Go / coding plans) as one compact strip above the input box. Enable it now? You can change this anytime in Settings → Display.',
|
|
950
|
+
quotaStripGuideOn: 'Enable the strip',
|
|
951
|
+
quotaStripGuideOff: 'Not now',
|
|
916
952
|
sidebarLabel: 'Today cost display',
|
|
917
953
|
sidebarOn: 'Sidebar footer',
|
|
918
954
|
currencyLabel: 'Currency',
|
|
@@ -1202,6 +1238,13 @@ window.__ModuleLoader__.load({
|
|
|
1202
1238
|
goMonthly: v.corner?.goMonthly !== false,
|
|
1203
1239
|
budget: v.corner?.budget !== false,
|
|
1204
1240
|
},
|
|
1241
|
+
quotaStrip: {
|
|
1242
|
+
enabled: v.quotaStrip?.enabled === true,
|
|
1243
|
+
budget: v.quotaStrip?.budget !== false,
|
|
1244
|
+
go: v.quotaStrip?.go !== false,
|
|
1245
|
+
plans: v.quotaStrip?.plans !== false,
|
|
1246
|
+
promptSeen: v.quotaStrip?.promptSeen === true,
|
|
1247
|
+
},
|
|
1205
1248
|
usage: {
|
|
1206
1249
|
position: v.usage?.position === 'general' || v.usage?.position === 'section' ? v.usage.position : 'cost',
|
|
1207
1250
|
},
|
|
@@ -2478,6 +2521,143 @@ window.__ModuleLoader__.load({
|
|
|
2478
2521
|
...rows)))
|
|
2479
2522
|
}
|
|
2480
2523
|
|
|
2524
|
+
// 输入框上方额度横条:横排 chips(短标签 + 迷你进度条 + 百分比);预算/Go/Coding Plan
|
|
2525
|
+
// 三类内容各自开关,无可用数据(未启用/未配置/查询失败)时整条自动隐藏。
|
|
2526
|
+
const STRIP_VENDOR_SHORT = {
|
|
2527
|
+
anthropic: 'Claude',
|
|
2528
|
+
zai: 'Z.ai',
|
|
2529
|
+
minimax: 'MM',
|
|
2530
|
+
kimi: 'Kimi',
|
|
2531
|
+
openrouter: 'OR',
|
|
2532
|
+
siliconflow: 'SF',
|
|
2533
|
+
commandcode: 'CC',
|
|
2534
|
+
scnet: 'SCNet',
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
function QuotaStrip(props) {
|
|
2538
|
+
const costStore = props.useCost ? props.useCost(s => s) : undefined
|
|
2539
|
+
const state = costStore?.state
|
|
2540
|
+
if (!state) return null
|
|
2541
|
+
const config = state.config
|
|
2542
|
+
const strip = config.quotaStrip ?? { enabled: false, budget: true, go: true, plans: true }
|
|
2543
|
+
if (strip.enabled !== true) return null
|
|
2544
|
+
const t = makeT(resolveLocale(config?.locale))
|
|
2545
|
+
const chips = []
|
|
2546
|
+
// 预算 chip:与预算图框同口径(≥80% 预警、≥100% 超支)。
|
|
2547
|
+
if (strip.budget !== false) {
|
|
2548
|
+
const budget = config.budget ?? { enabled: false, amount: 100, period: 'month' }
|
|
2549
|
+
if (budget.enabled === true) {
|
|
2550
|
+
const rate = Number(config.exchangeRate)
|
|
2551
|
+
const usedUsd = state.budgetUsed ?? (
|
|
2552
|
+
budget.period === 'day' ? state.today.cost
|
|
2553
|
+
: budget.period === 'all' ? state.total.cost
|
|
2554
|
+
: state.month.cost)
|
|
2555
|
+
const used = usedUsd * (Number.isFinite(rate) && rate > 0 ? rate : 1)
|
|
2556
|
+
const amount = Math.max(0, Number(budget.amount) || 0)
|
|
2557
|
+
if (amount > 0) {
|
|
2558
|
+
const pct = Math.min(999, used / amount * 100)
|
|
2559
|
+
const level = pct >= 100 ? 'over' : pct >= 80 ? 'warn' : 'ok'
|
|
2560
|
+
chips.push({
|
|
2561
|
+
key: 'budget',
|
|
2562
|
+
label: t('budgetShort'),
|
|
2563
|
+
pct: Math.round(pct),
|
|
2564
|
+
level,
|
|
2565
|
+
tip: t('budgetOf', { period: t(PERIOD_KEYS[budget.period] ?? 'periodMonth') }) + ' · '
|
|
2566
|
+
+ t('usedOf', { used: formatMoneyValue(used, config), amount: formatMoneyValue(amount, config) })
|
|
2567
|
+
+ ' · ' + pct.toFixed(1) + '%',
|
|
2568
|
+
})
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
// Go chip:主窗口一档(与右下角 chips 的主窗口口径一致)。
|
|
2573
|
+
if (strip.go !== false) {
|
|
2574
|
+
const goQuota = state.goQuota
|
|
2575
|
+
if (config?.goQuota?.enabled !== false && goQuota?.status === 'ok') {
|
|
2576
|
+
const mainKey = config.goQuota.main === 'weekly' || config.goQuota.main === 'monthly' ? config.goQuota.main : 'rolling'
|
|
2577
|
+
const win = mainKey === 'rolling' ? goQuota.rolling : mainKey === 'weekly' ? goQuota.weekly : goQuota.monthly
|
|
2578
|
+
if (win !== null && typeof win === 'object' && typeof win.percent === 'number') {
|
|
2579
|
+
const pct = Math.max(0, Math.min(100, Math.round(Number(win.percent) || 0)))
|
|
2580
|
+
const level = pct >= 100 ? 'over' : pct >= 80 ? 'warn' : 'ok'
|
|
2581
|
+
const resets = typeof win.resetsAt === 'string' && win.resetsAt.length > 0
|
|
2582
|
+
? ' · ' + t('goResetAt', { time: new Date(win.resetsAt).toLocaleString() }) : ''
|
|
2583
|
+
chips.push({
|
|
2584
|
+
key: 'go',
|
|
2585
|
+
label: 'Go ' + t(mainKey === 'rolling' ? 'goShortRolling' : mainKey === 'weekly' ? 'goShortWeekly' : 'goShortMonthly'),
|
|
2586
|
+
pct,
|
|
2587
|
+
level,
|
|
2588
|
+
tip: 'Go: ' + pct + '%' + resets,
|
|
2589
|
+
})
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
// Coding Plan chips:已启用且查询成功的厂商,每家最多取前两个百分比窗口。
|
|
2594
|
+
if (strip.plans !== false) {
|
|
2595
|
+
for (const rowDef of CODING_PLAN_ROWS) {
|
|
2596
|
+
const live = state.codingPlans?.[rowDef.id]
|
|
2597
|
+
if (config.codingPlans?.[rowDef.id]?.enabled !== true || !live || live.status !== 'ok') continue
|
|
2598
|
+
const windows = live.windows !== null && typeof live.windows === 'object' ? live.windows : {}
|
|
2599
|
+
const entries = Object.entries(windows)
|
|
2600
|
+
const vendor = STRIP_VENDOR_SHORT[rowDef.id] ?? rowDef.id
|
|
2601
|
+
let shown = 0
|
|
2602
|
+
const detailParts = []
|
|
2603
|
+
for (const [name, win] of entries) {
|
|
2604
|
+
const pct = win !== null && typeof win === 'object' && typeof win.percent === 'number'
|
|
2605
|
+
? Math.max(0, Math.min(100, Math.round(Number(win.percent) || 0))) : null
|
|
2606
|
+
const reset = typeof win?.resetsAt === 'string' && win.resetsAt.length > 0
|
|
2607
|
+
? ' · ' + t('goResetAt', { time: new Date(win.resetsAt).toLocaleString() }) : ''
|
|
2608
|
+
detailParts.push(codingPlanWindowLabel(name, t) + ' '
|
|
2609
|
+
+ (pct === null ? (typeof win?.text === 'string' ? win.text : '—') : pct + '%') + reset)
|
|
2610
|
+
if (pct === null || shown >= 2) continue
|
|
2611
|
+
shown += 1
|
|
2612
|
+
const level = pct >= 100 ? 'over' : pct >= 80 ? 'warn' : 'ok'
|
|
2613
|
+
chips.push({
|
|
2614
|
+
key: rowDef.id + ':' + name,
|
|
2615
|
+
label: vendor + ' ' + codingPlanWindowLabel(name, t),
|
|
2616
|
+
pct,
|
|
2617
|
+
level,
|
|
2618
|
+
tip: detailParts.join('; '),
|
|
2619
|
+
})
|
|
2620
|
+
}
|
|
2621
|
+
if (detailParts.length > 0 && live.fetchedAt > 0) detailParts.push(t('goQuotaFetchedAt', { time: new Date(live.fetchedAt).toLocaleTimeString() }))
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
if (chips.length === 0) return null
|
|
2625
|
+
return el('div', { className: 'cm-qstrip' },
|
|
2626
|
+
chips.map(c => el(Tooltip, { key: c.key, label: c.tip, side: 'bottom', delayMs: 400 },
|
|
2627
|
+
el('span', { className: 'cm-qchip' + (c.level === 'ok' ? '' : ' ' + c.level) },
|
|
2628
|
+
el('span', { className: 'cm-qlabel' }, c.label),
|
|
2629
|
+
el('span', { className: 'cm-qbar' }, el('span', { className: 'cm-qfill', style: { width: c.pct + '%' } })),
|
|
2630
|
+
el('span', null, c.pct + '%')))))
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
// 首次更新后的功能引导:非模态小卡片,让用户自主决定是否开启额度横条;
|
|
2634
|
+
// 选择「开启/暂不」后写回 promptSeen=true 永久消失(挂在常驻 sidebar.footer.action)。
|
|
2635
|
+
function QuotaStripGuide(props) {
|
|
2636
|
+
// 所有 Hook 必须在任何条件返回之前调用:promptSeen 从 false 翻为 true 时本组件
|
|
2637
|
+
// 会从「渲染引导卡」变为提前 return null,若 useRef 在条件返回之后,两次渲染
|
|
2638
|
+
// 的 Hook 数量不一致,触发 React #300(Rendered fewer hooks than expected)。
|
|
2639
|
+
const costStore = props.useCost ? props.useCost(s => s) : undefined
|
|
2640
|
+
const busyRef = useRef(false)
|
|
2641
|
+
const state = costStore?.state
|
|
2642
|
+
if (!state) return null
|
|
2643
|
+
const config = state.config
|
|
2644
|
+
if (config.quotaStrip?.promptSeen === true) return null
|
|
2645
|
+
const t = makeT(resolveLocale(config?.locale))
|
|
2646
|
+
const choose = enabled => {
|
|
2647
|
+
if (busyRef.current === true) return
|
|
2648
|
+
busyRef.current = true
|
|
2649
|
+
const current = config.quotaStrip ?? { enabled: false, budget: true, go: true, plans: true }
|
|
2650
|
+
props.api.updateConfig({ quotaStrip: { ...current, enabled, promptSeen: true } })
|
|
2651
|
+
.catch(() => { busyRef.current = false })
|
|
2652
|
+
}
|
|
2653
|
+
return el('div', { className: 'cm-qguide', role: 'dialog', 'aria-label': t('quotaStripGuideTitle') },
|
|
2654
|
+
el('h4', null, t('quotaStripGuideTitle')),
|
|
2655
|
+
el('p', null, t('quotaStripGuideBody')),
|
|
2656
|
+
el('div', { className: 'cm-buttons' },
|
|
2657
|
+
el('button', { type: 'button', className: 'cm-btn small', onClick: () => choose(false) }, t('quotaStripGuideOff')),
|
|
2658
|
+
el('button', { type: 'button', className: 'cm-btn small primary', onClick: () => choose(true) }, t('quotaStripGuideOn'))))
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2481
2661
|
function BudgetBoxContent(props) {
|
|
2482
2662
|
const { state, wide } = props
|
|
2483
2663
|
const today = state.today
|
|
@@ -4435,6 +4615,33 @@ window.__ModuleLoader__.load({
|
|
|
4435
4615
|
setDraft({ ...draft, goQuota: { ...(draft.goQuota ?? { display: 'both', refreshMinutes: 15, apiKey: '' }), apiKey: event.target.value } })
|
|
4436
4616
|
},
|
|
4437
4617
|
})),
|
|
4618
|
+
el('div', { className: 'cm-grid-group' }, t('quotaStripGroup')),
|
|
4619
|
+
el('div', { className: 'cm-field' },
|
|
4620
|
+
el('label', { className: 'cm-check' },
|
|
4621
|
+
el('input', {
|
|
4622
|
+
type: 'checkbox',
|
|
4623
|
+
checked: draft?.quotaStrip?.enabled === true,
|
|
4624
|
+
onChange: event => {
|
|
4625
|
+
if (draft === null) return
|
|
4626
|
+
setDraft({ ...draft, quotaStrip: { ...(draft.quotaStrip ?? { enabled: false, budget: true, go: true, plans: true }), enabled: event.target.checked, promptSeen: true } })
|
|
4627
|
+
},
|
|
4628
|
+
}),
|
|
4629
|
+
el('span', null, t('quotaStripEnable')))),
|
|
4630
|
+
draft?.quotaStrip?.enabled === true
|
|
4631
|
+
? [['budget', 'quotaStripShowBudget'], ['go', 'quotaStripShowGo'], ['plans', 'quotaStripShowPlans']].map(([key, labelKey]) =>
|
|
4632
|
+
el('label', { key, className: 'cm-check' },
|
|
4633
|
+
el('input', {
|
|
4634
|
+
type: 'checkbox',
|
|
4635
|
+
checked: draft.quotaStrip[key] !== false,
|
|
4636
|
+
onChange: event => {
|
|
4637
|
+
if (draft === null) return
|
|
4638
|
+
setDraft({ ...draft, quotaStrip: { ...draft.quotaStrip, [key]: event.target.checked } })
|
|
4639
|
+
},
|
|
4640
|
+
}),
|
|
4641
|
+
el('span', null, t(labelKey))))
|
|
4642
|
+
: null,
|
|
4643
|
+
el('div', { className: 'cm-field' },
|
|
4644
|
+
el('span', { className: 'cm-hint' }, t('quotaStripNote'))),
|
|
4438
4645
|
el('div', { className: 'cm-grid-group' }, t('groupCorner')),
|
|
4439
4646
|
el('div', { className: 'cm-field' },
|
|
4440
4647
|
el('label', null, t('cornerLabel')),
|
|
@@ -4786,6 +4993,24 @@ window.__ModuleLoader__.load({
|
|
|
4786
4993
|
})
|
|
4787
4994
|
}
|
|
4788
4995
|
|
|
4996
|
+
// 输入框上方额度横条(conversation.input.dock 渲染于输入卡片上方):静态注册,
|
|
4997
|
+
// 组件内部按 quotaStrip.enabled 门控,无可用数据时整条隐藏。
|
|
4998
|
+
slots.inject('conversation.input.dock', () => {
|
|
4999
|
+
const dispose = slots.register(
|
|
5000
|
+
{ name: 'conversation.input.dock', id: 'cost-meter-qstrip', order: 5, inject: injected },
|
|
5001
|
+
QuotaStrip,
|
|
5002
|
+
)
|
|
5003
|
+
return dispose
|
|
5004
|
+
})
|
|
5005
|
+
// 首次更新引导:常驻 sidebar.footer.action 挂载,组件内部按 promptSeen 门控。
|
|
5006
|
+
slots.inject('sidebar.footer.action', () => {
|
|
5007
|
+
const dispose = slots.register(
|
|
5008
|
+
{ name: 'sidebar.footer.action', id: 'cost-meter-qstrip-guide', order: 1, inject: injected },
|
|
5009
|
+
QuotaStripGuide,
|
|
5010
|
+
)
|
|
5011
|
+
return dispose
|
|
5012
|
+
})
|
|
5013
|
+
|
|
4789
5014
|
// 峰/谷切换前弹窗提醒:全局 fixed 浮层(fixed 定位与宿主位置无关),挂在常驻的
|
|
4790
5015
|
// sidebar.footer.action 插槽——conversation.composer.dock 仅在有活跃会话的页面渲染,
|
|
4791
5016
|
// 挂那里会导致 hero/设置页不弹提醒、预览按钮失效(issue:预览点了没反应)。
|
package/lib/store.js
CHANGED
|
@@ -124,6 +124,13 @@ export function defaultConfig() {
|
|
|
124
124
|
goMonthly: true, // 本月额度
|
|
125
125
|
budget: true, // 预算已用%
|
|
126
126
|
},
|
|
127
|
+
quotaStrip: {
|
|
128
|
+
enabled: false, // 输入框上方额度横条(conversation.input.dock)
|
|
129
|
+
budget: true, // 横条含预算已用%
|
|
130
|
+
go: true, // 横条含 Go 额度主窗口
|
|
131
|
+
plans: true, // 横条含已启用的 Coding Plan 窗口
|
|
132
|
+
promptSeen: false, // 首次更新后的功能引导是否已处理(用户自主决定开关)
|
|
133
|
+
},
|
|
127
134
|
usage: {
|
|
128
135
|
position: 'cost', // Token 用量统计显示位置:cost(费用设置) | general(通用设置) | section(独立分节)
|
|
129
136
|
},
|
|
@@ -277,6 +284,8 @@ const VALIDATION_MESSAGES = {
|
|
|
277
284
|
corner: 'corner 非法',
|
|
278
285
|
cornerEnabled: 'corner.enabled 必须是布尔值',
|
|
279
286
|
cornerFlag: 'corner.{field} 必须是布尔值',
|
|
287
|
+
quotaStrip: 'quotaStrip 非法',
|
|
288
|
+
quotaStripFlag: 'quotaStrip.{field} 必须是布尔值',
|
|
280
289
|
usage: 'usage 非法',
|
|
281
290
|
usagePosition: 'usage.position 必须是 cost / general / section',
|
|
282
291
|
prices: 'prices 非法',
|
|
@@ -343,6 +352,8 @@ const VALIDATION_MESSAGES = {
|
|
|
343
352
|
corner: 'Invalid corner',
|
|
344
353
|
cornerEnabled: 'corner.enabled must be a boolean',
|
|
345
354
|
cornerFlag: 'corner.{field} must be a boolean',
|
|
355
|
+
quotaStrip: 'Invalid quotaStrip',
|
|
356
|
+
quotaStripFlag: 'quotaStrip.{field} must be a boolean',
|
|
346
357
|
usage: 'Invalid usage',
|
|
347
358
|
usagePosition: 'usage.position must be cost / general / section',
|
|
348
359
|
prices: 'Invalid prices',
|
|
@@ -544,6 +555,15 @@ export function applyConfigPatch(current, patch) {
|
|
|
544
555
|
if (typeof corner[field] !== 'boolean') errors.push(vmsg(locale, 'cornerFlag', { field }))
|
|
545
556
|
}
|
|
546
557
|
}
|
|
558
|
+
// 输入框上方额度横条:五布尔字段;非法值直接报错(与 corner 同策略,由客户端提交完整对象)。
|
|
559
|
+
const quotaStrip = candidate.quotaStrip
|
|
560
|
+
if (quotaStrip === null || typeof quotaStrip !== 'object' || Array.isArray(quotaStrip)) {
|
|
561
|
+
errors.push(vmsg(locale, 'quotaStrip'))
|
|
562
|
+
} else {
|
|
563
|
+
for (const field of ['enabled', 'budget', 'go', 'plans', 'promptSeen']) {
|
|
564
|
+
if (typeof quotaStrip[field] !== 'boolean') errors.push(vmsg(locale, 'quotaStripFlag', { field }))
|
|
565
|
+
}
|
|
566
|
+
}
|
|
547
567
|
// Token 用量统计显示位置校验。
|
|
548
568
|
const usage = candidate.usage
|
|
549
569
|
if (usage === null || typeof usage !== 'object' || Array.isArray(usage)) {
|
|
@@ -704,6 +724,11 @@ export function sanitizeConfig(raw) {
|
|
|
704
724
|
out.customBalance = customBalance
|
|
705
725
|
const corner = out.corner
|
|
706
726
|
for (const key of ['enabled', 'goRolling', 'goWeekly', 'goMonthly', 'budget']) corner[key] = corner[key] === true || (corner[key] !== false && key !== 'enabled')
|
|
727
|
+
// 输入框上方额度横条:enabled/promptSeen 缺省 false,budget/go/plans 缺省 true。
|
|
728
|
+
const strip = out.quotaStrip
|
|
729
|
+
strip.enabled = strip.enabled === true
|
|
730
|
+
strip.promptSeen = strip.promptSeen === true
|
|
731
|
+
for (const key of ['budget', 'go', 'plans']) strip[key] = strip[key] !== false
|
|
707
732
|
// codingPlans:逐家收敛(非法条目整家回落默认;只保留已知提供商)。
|
|
708
733
|
const plans = {}
|
|
709
734
|
if (out.codingPlans !== null && typeof out.codingPlans === 'object') {
|
package/lib/typert.host.js
CHANGED
|
@@ -175,6 +175,14 @@ const configSchema = z.object({
|
|
|
175
175
|
goMonthly: z.boolean(),
|
|
176
176
|
budget: z.boolean(),
|
|
177
177
|
}),
|
|
178
|
+
// 输入框上方额度横条(v1.5.27):预算/Go/Coding Plan 用量横条 + 首次引导标记。
|
|
179
|
+
quotaStrip: z.object({
|
|
180
|
+
enabled: z.boolean(),
|
|
181
|
+
budget: z.boolean(),
|
|
182
|
+
go: z.boolean(),
|
|
183
|
+
plans: z.boolean(),
|
|
184
|
+
promptSeen: z.boolean(),
|
|
185
|
+
}),
|
|
178
186
|
historyDays: num,
|
|
179
187
|
fetchedAt: z.union([z.string(), z.null()]),
|
|
180
188
|
priceSource: z.string(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cost-meter",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.28",
|
|
4
4
|
"description": "DeepSeek Harness 会话费用统计插件:本会话成本、当日费用、历史记录与官方价格同步,支持多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配)、主流 Coding Plan 订阅额度查询与显示(7 家,含 SCNet Token Plan 本地 Credits 计量)、自定义 Provider 余额查询(可配任意 HTTP 端点)与余额进度条、峰谷计价时段显示与切换前弹窗/系统通知提醒(位置/提前量/类型可配),界面中英双语。Session cost tracking plugin for DeepSeek Harness: per-conversation cost, daily totals, history and official price sync, with multi-vendor model pricing (built-in 90+ model catalog with auto-matching), Coding Plan quota queries & display for 7 vendors (incl. local credits metering for the SCNet Token Plan), custom provider balance lookup (configurable HTTP endpoint) and balance progress bar, plus peak/off-peak pricing display with pre-switch popup & system-notification alerts (position / lead time / type configurable), in a bilingual (Chinese/English) UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|