dsh-cost-meter 1.5.14 → 1.5.15
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 +6 -6
- package/README.md +6 -6
- package/lib/client.js +2 -2
- package/lib/index.js +32 -13
- package/lib/store.js +3 -0
- package/lib/typert.host.js +2 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
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) · 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)
|
|
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)
|
|
@@ -36,7 +36,7 @@ English | [中文](README.md)
|
|
|
36
36
|
| Token usage stats | Settings page (Cost section) | All-time token totals (input/cache/output/calls) + a Codex-style 26-week daily usage heat grid that fills the settings width; hover a cell for that day's detail |
|
|
37
37
|
| Today's sessions | Settings page | Per-session call count, input/cache/output tokens and cost |
|
|
38
38
|
| History | Settings page | Per-day totals; retention days configurable (default 180) |
|
|
39
|
-
| Pre-install history import |
|
|
39
|
+
| Pre-install history import | Automatic on first launch | After install/upgrade, the first launch automatically replays all host session logs to import conversations from before the plugin was installed (missing dates are rebuilt whole; existing dates only gain previously unknown sessions; idempotent and never double-counts live metering; costs priced at per-event historical rates); a manual re-run entry remains in Settings |
|
|
40
40
|
| Budget settings | Settings page, top | Limit, period (today / month / cumulative / custom date range), used % |
|
|
41
41
|
| Price table | Settings page | Per-model off-peak / peak prices (input/output shorthand supported; cache prices derived automatically); fully editable |
|
|
42
42
|
| Peak/off-peak hours display | Settings / budget / today | Shows UTC peak hours 01:00–04:00 and 06:00–10:00 with the current tier; expanded view shows a peak/off-peak period strip (current period + countdown), collapsed (rail) view shows a vertical peak/off-peak progress bar; independently toggleable |
|
|
@@ -192,22 +192,22 @@ Real captures from an actual DSH sidebar of the period strip and collapsed verti
|
|
|
192
192
|
dsh plugin --profile web add dsh-cost-meter
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
**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.
|
|
195
|
+
**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.15`** — review the script before running):
|
|
196
196
|
|
|
197
197
|
```powershell
|
|
198
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.
|
|
198
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.15/install.ps1 | iex
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
202
202
|
|
|
203
203
|
```sh
|
|
204
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.
|
|
204
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.15
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
Without git, use the GitHub tag archive:
|
|
208
208
|
|
|
209
209
|
```sh
|
|
210
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.
|
|
210
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.15.tar.gz
|
|
211
211
|
```
|
|
212
212
|
|
|
213
213
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
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 六家)
|
|
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)
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
| 今日会话明细 | 设置页 | 每个会话的调用次数、输入/缓存/输出 token 与费用 |
|
|
38
38
|
| 历史记录 | 设置页 | 按天汇总,保留天数可配(默认 180 天) |
|
|
39
39
|
| 历史按模型统计回填 | 设置页(按模型统计) | 按模型统计上线前的旧账本自动回放宿主会话日志重建逐模型 token/费用拆分(旧调用按当时基础价),日志已清理的部分归入「早期未分模型」残差行 |
|
|
40
|
-
| 导入安装前历史 |
|
|
40
|
+
| 导入安装前历史 | 首次启动自动 | 安装/升级后首次启动自动回放宿主全部会话日志,把未装插件时期的对话导入账本(缺失日期整日重建,已有日期只补未知会话,幂等不与实时计费重复;金额按事件时刻历史价回推);设置页保留手动重跑入口 |
|
|
41
41
|
| 预算设置 | 设置页顶部 | 额度、周期(今日/本月/累计/自定义日期区间)、已用% |
|
|
42
42
|
| 价格表 | 设置页 | 每模型 谷时/峰时 两档价格(支持 input/output 简写,缓存价自动补齐),增删改自由 |
|
|
43
43
|
| 峰谷计价时段显示 | 设置页 / 预算 / 今日费用 | 显示 UTC 峰时段 01:00–04:00、06:00–10:00 与当前档位;展开态显示峰时/平价时段条(当前时段 + 倒计时),收起(rail)态显示竖向峰谷进度条,可单独开关 |
|
|
@@ -194,22 +194,22 @@
|
|
|
194
194
|
dsh plugin --profile web add dsh-cost-meter
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.
|
|
197
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.15`**,建议先下载审阅再运行):
|
|
198
198
|
|
|
199
199
|
```powershell
|
|
200
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.
|
|
200
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.15/install.ps1 | iex
|
|
201
201
|
```
|
|
202
202
|
|
|
203
203
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
204
204
|
|
|
205
205
|
```sh
|
|
206
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.
|
|
206
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.15
|
|
207
207
|
```
|
|
208
208
|
|
|
209
209
|
没有 git 时可用 GitHub tag 打包直链:
|
|
210
210
|
|
|
211
211
|
```sh
|
|
212
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.
|
|
212
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.15.tar.gz
|
|
213
213
|
```
|
|
214
214
|
|
|
215
215
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
package/lib/client.js
CHANGED
|
@@ -557,7 +557,7 @@ window.__ModuleLoader__.load({
|
|
|
557
557
|
importLegacy: '导入安装前历史',
|
|
558
558
|
confirmImportLegacy: '确认导入?将回放全部会话日志,只补账本缺失的日期与会话,不影响已有记录。',
|
|
559
559
|
legacyImportFailed: '导入安装前历史失败:{message}',
|
|
560
|
-
legacyImportNote: '
|
|
560
|
+
legacyImportNote: '插件首次启动后会自动导入一次安装前历史;此处可手动重跑(如后续拷入了旧日志)。金额按当前价目表回推,已清理的日志无法回放,同一会话跨安装时刻时其安装前用量不计入。',
|
|
561
561
|
confirmClear: '确认清除',
|
|
562
562
|
clearAllHistory: '清除全部历史',
|
|
563
563
|
lastSync: '最近同步:{time}',
|
|
@@ -858,7 +858,7 @@ window.__ModuleLoader__.load({
|
|
|
858
858
|
importLegacy: 'Import pre-install history',
|
|
859
859
|
confirmImportLegacy: 'Confirm import? Replays all session logs and only fills dates/sessions missing from the ledger; existing records are untouched.',
|
|
860
860
|
legacyImportFailed: 'Failed to import pre-install history: {message}',
|
|
861
|
-
legacyImportNote: '
|
|
861
|
+
legacyImportNote: 'Pre-install history is imported automatically once on first launch; this button re-runs it manually (e.g. after copying in old logs). Costs are estimated with the current price catalog; cleaned logs cannot be replayed, and for a session spanning the install moment its pre-install usage is not counted.',
|
|
862
862
|
confirmClear: 'Confirm clear',
|
|
863
863
|
clearAllHistory: 'Clear all history',
|
|
864
864
|
lastSync: 'Last sync: {time}',
|
package/lib/index.js
CHANGED
|
@@ -1017,6 +1017,34 @@ function createService(ctx, ledger) {
|
|
|
1017
1017
|
|
|
1018
1018
|
// ── 插件主体 ───────────────────────────────────────────────────────────────
|
|
1019
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* 启动期历史导入(issue #27):先做按模型回填,再在**本插件首次启动**(config
|
|
1022
|
+
* 标记 legacyAutoImportedAt 为 0)时自动导入一次安装前历史——用户无需手动触
|
|
1023
|
+
* 发;之后每次启动只跑回填,自动导入不再重复。导出供测试直接调用。
|
|
1024
|
+
* @param ledger - 已打开的账本。
|
|
1025
|
+
* @param sessionsRoot - 宿主会话根目录($DSH_HOME/sessions)。
|
|
1026
|
+
*/
|
|
1027
|
+
export async function runStartupImports(ledger, sessionsRoot) {
|
|
1028
|
+
const filled = await backfillLegacyLedger(ledger, sessionsRoot)
|
|
1029
|
+
if (filled.days > 0 || filled.sessions > 0 || filled.titles > 0) {
|
|
1030
|
+
const extras = [
|
|
1031
|
+
filled.days > 0 || filled.sessions > 0 ? `${filled.days} 天 / ${filled.sessions} 个会话` : null,
|
|
1032
|
+
filled.titles > 0 ? `${filled.titles} 个会话标题` : null,
|
|
1033
|
+
filled.recosted > 0 ? `重算 ${filled.recosted} 天金额` : null,
|
|
1034
|
+
].filter(Boolean).join(',')
|
|
1035
|
+
console.log(`[dsh-cost-meter] 历史按模型统计回填完成:${extras}(扫描 ${filled.scanned} 份会话日志)`)
|
|
1036
|
+
}
|
|
1037
|
+
if (!(Number(ledger.config?.legacyAutoImportedAt) > 0)) {
|
|
1038
|
+
const stats = await importLegacyHistory(ledger, sessionsRoot)
|
|
1039
|
+
if (stats.days > 0 || stats.sessions > 0) {
|
|
1040
|
+
console.log(`[dsh-cost-meter] 安装前历史自动导入完成:${stats.days} 天 / ${stats.sessions} 个会话(扫描 ${stats.scanned} 份会话日志)`)
|
|
1041
|
+
}
|
|
1042
|
+
// 无论是否有可导入内容都打标:空结果同样视为已完成,避免每次启动重扫。
|
|
1043
|
+
ledger.config.legacyAutoImportedAt = Date.now()
|
|
1044
|
+
ledger.scheduleWrite()
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1020
1048
|
/**
|
|
1021
1049
|
* 挂载账本、llm/stream 计费包裹、会话投影与 costMeter 服务。
|
|
1022
1050
|
* @param ctx - 宿主插件上下文。
|
|
@@ -1028,20 +1056,11 @@ export function apply(ctx) {
|
|
|
1028
1056
|
// 卸载/退出前最终落盘。
|
|
1029
1057
|
ctx.effect(() => () => ledger.close(), 'cost-meter: ledger close')
|
|
1030
1058
|
|
|
1031
|
-
//
|
|
1032
|
-
//
|
|
1059
|
+
// 历史账本按模型回填 + 首次启动自动导入安装前历史(issue #27):
|
|
1060
|
+
// 启动后延迟执行,避免拖慢宿主启动;均幂等,只补缺失,不重复计数。
|
|
1033
1061
|
const backfillTimer = setTimeout(() => {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
const extras = [
|
|
1037
|
-
filled.days > 0 || filled.sessions > 0 ? `${filled.days} 天 / ${filled.sessions} 个会话` : null,
|
|
1038
|
-
filled.titles > 0 ? `${filled.titles} 个会话标题` : null,
|
|
1039
|
-
filled.recosted > 0 ? `重算 ${filled.recosted} 天金额` : null,
|
|
1040
|
-
].filter(Boolean).join(',')
|
|
1041
|
-
console.log(`[dsh-cost-meter] 历史按模型统计回填完成:${extras}(扫描 ${filled.scanned} 份会话日志)`)
|
|
1042
|
-
}
|
|
1043
|
-
}, error => {
|
|
1044
|
-
console.warn(`[dsh-cost-meter] 历史按模型统计回填失败: ${String(error?.message ?? error)}`)
|
|
1062
|
+
runStartupImports(ledger, join(resolveDshHome(), 'sessions')).catch(error => {
|
|
1063
|
+
console.warn(`[dsh-cost-meter] 启动期历史导入失败: ${String(error?.message ?? error)}`)
|
|
1045
1064
|
})
|
|
1046
1065
|
}, 3000)
|
|
1047
1066
|
backfillTimer.unref?.()
|
package/lib/store.js
CHANGED
|
@@ -39,6 +39,7 @@ export function defaultConfig() {
|
|
|
39
39
|
peakWindows: DEFAULT_PEAK_WINDOWS.map(w => ({ ...w })),
|
|
40
40
|
peakNotice: true, // 峰时高价时段显著提示(侧边栏预算框/今日费用/设置页预算面板)
|
|
41
41
|
showSessionId: false, // 会话列表中附显会话 ID(默认只显示标题,需要时开启)
|
|
42
|
+
legacyAutoImportedAt: 0, // 安装前历史自动导入标记(issue #27):完成时刻 ms;0 = 尚未跑过
|
|
42
43
|
peakStyle: 'compact', // 峰谷时段条样式:compact(简洁单行/竖向同构) | classic(经典分段/胶囊芯片)
|
|
43
44
|
priceMatch: 'auto', // 未知模型名自动匹配价格表:auto(去后缀/前缀/家族相似) | exact(仅精确)
|
|
44
45
|
priceOverrides: {}, // 手动匹配覆盖:{ 'provider:modelId': '同provider模型 | provider:模型 | deepseek:__default__' }
|
|
@@ -588,6 +589,8 @@ export function sanitizeConfig(raw) {
|
|
|
588
589
|
out.decimals = Math.max(0, Math.min(10, Math.floor(Number(out.decimals) || 0)))
|
|
589
590
|
out.historyDays = Math.max(7, Math.min(3650, Math.floor(Number(out.historyDays) || 180)))
|
|
590
591
|
out.showSessionId = out.showSessionId === true
|
|
592
|
+
// 安装前历史自动导入标记:有限正数保留,否则归零(下次启动重试)。
|
|
593
|
+
out.legacyAutoImportedAt = isNum(Number(out.legacyAutoImportedAt)) && Number(out.legacyAutoImportedAt) > 0 ? Number(out.legacyAutoImportedAt) : 0
|
|
591
594
|
if (!isNum(out.exchangeRate) || out.exchangeRate <= 0) out.exchangeRate = base.exchangeRate
|
|
592
595
|
if (!Array.isArray(out.peakWindows)) out.peakWindows = base.peakWindows
|
|
593
596
|
else out.peakWindows = out.peakWindows.filter(w => w !== null && typeof w === 'object' && isNum(Number(w.start)) && isNum(Number(w.end)))
|
package/lib/typert.host.js
CHANGED
|
@@ -104,6 +104,8 @@ const configSchema = z.object({
|
|
|
104
104
|
peakWindows: z.array(z.object({ start: num, end: num })),
|
|
105
105
|
peakNotice: z.boolean().optional(),
|
|
106
106
|
showSessionId: z.boolean().optional(),
|
|
107
|
+
// 安装前历史自动导入完成时刻(issue #27,内部标记;0/缺席 = 尚未跑过)。
|
|
108
|
+
legacyAutoImportedAt: num.optional(),
|
|
107
109
|
peakStyle: z.enum(['compact', 'classic']).optional(),
|
|
108
110
|
priceMatch: z.enum(['auto', 'exact']).optional(),
|
|
109
111
|
priceOverrides: z.record(z.string(), z.string()).optional(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cost-meter",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.15",
|
|
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, in a bilingual (Chinese/English) UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|