@angelyeye/dsh-cost-tracker 1.9.6 → 1.10.1
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 +81 -0
- package/README.md +3 -3
- package/docs/THIRD-PARTY-NOTICES.md +1 -1
- package/docs/provider-pricing.json +585 -91
- package/index.js +8 -8
- package/package.json +1 -1
- package/pricing.js +36 -6
- package/store.js +15 -4
- package/sync.js +25 -12
- package/vendor-catalog.js +7 -5
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { readFileSync, writeFileSync, mkdirSync, renameSync, existsSync, realpathSync } from 'node:fs'
|
|
10
10
|
import { join, dirname } from 'node:path'
|
|
11
11
|
import { homedir } from 'node:os'
|
|
12
|
-
import { createStore, collectTotals, DETAIL_DAYS, MAX_AXIS_DAYS } from './store.js'
|
|
12
|
+
import { createStore, collectTotals, DETAIL_DAYS, MAX_AXIS_DAYS, PRIVATE_DIR_MODE, PRIVATE_FILE_MODE } from './store.js'
|
|
13
13
|
import { PRICE_ERAS, V41_EFFECTIVE_AT, exactModelsAt, eraAt, SUBSCRIPTION_RATES, PROVIDER_RATES, GENERIC_RATES, PEAK_WINDOWS, PEAK_HOUR_WINDOWS, isPeak, peakPhaseAt, priceFor, computeCost, normalizeTokens, subscriptionPlanFor, volcenginePlanModels, VOLCENGINE_PLAN_PROVIDER_KEYS, VOLCENGINE_PLAN_RATES, setSyncedEras, getSyncedEras, setPriceOverrides, getPriceOverrides, setPeakHolidays, getPeakHolidays } from './pricing.js'
|
|
14
14
|
import {
|
|
15
15
|
normalizePeakConfig, defaultPeakConfig, peakEffective,
|
|
@@ -37,7 +37,7 @@ import { readSettingsSection } from './settings.js'
|
|
|
37
37
|
import { listSessionLogs, planAndBuildImports, loadManifest, IMPORT_SOURCE } from './import.js'
|
|
38
38
|
|
|
39
39
|
/** 插件版本(写入上报信封,便于云端排查版本差异) */
|
|
40
|
-
const PLUGIN_VERSION = '1.
|
|
40
|
+
const PLUGIN_VERSION = '1.10.1'
|
|
41
41
|
setPluginVersion(PLUGIN_VERSION)
|
|
42
42
|
|
|
43
43
|
/** 配置面板可写的字段(与 settings 命名空间一致)。
|
|
@@ -317,9 +317,9 @@ export default {
|
|
|
317
317
|
|
|
318
318
|
function saveConfig() {
|
|
319
319
|
try {
|
|
320
|
-
mkdirSync(dirname(CONFIG_FILE), { recursive: true })
|
|
320
|
+
mkdirSync(dirname(CONFIG_FILE), { recursive: true, mode: PRIVATE_DIR_MODE })
|
|
321
321
|
const tmp = CONFIG_FILE + '.tmp'
|
|
322
|
-
writeFileSync(tmp, JSON.stringify(Object.assign({}, peakConfig, cloudConfig, uiConfig, volcengineConfig, billingConfig, importConfig, priceSyncConfig, securityConfig)), 'utf8')
|
|
322
|
+
writeFileSync(tmp, JSON.stringify(Object.assign({}, peakConfig, cloudConfig, uiConfig, volcengineConfig, billingConfig, importConfig, priceSyncConfig, securityConfig)), { encoding: 'utf8', mode: PRIVATE_FILE_MODE })
|
|
323
323
|
renameSync(tmp, CONFIG_FILE)
|
|
324
324
|
return true
|
|
325
325
|
} catch (e) {
|
|
@@ -1603,9 +1603,9 @@ export default {
|
|
|
1603
1603
|
}
|
|
1604
1604
|
function savePriceState() {
|
|
1605
1605
|
try {
|
|
1606
|
-
mkdirSync(dirname(PRICES_FILE), { recursive: true })
|
|
1606
|
+
mkdirSync(dirname(PRICES_FILE), { recursive: true, mode: PRIVATE_DIR_MODE })
|
|
1607
1607
|
const tmp = PRICES_FILE + '.tmp'
|
|
1608
|
-
writeFileSync(tmp, JSON.stringify(priceState), 'utf8')
|
|
1608
|
+
writeFileSync(tmp, JSON.stringify(priceState), { encoding: 'utf8', mode: PRIVATE_FILE_MODE })
|
|
1609
1609
|
renameSync(tmp, PRICES_FILE)
|
|
1610
1610
|
return true
|
|
1611
1611
|
} catch (e) {
|
|
@@ -1695,9 +1695,9 @@ export default {
|
|
|
1695
1695
|
}
|
|
1696
1696
|
function saveImportManifest() {
|
|
1697
1697
|
try {
|
|
1698
|
-
mkdirSync(dirname(IMPORT_MANIFEST_FILE), { recursive: true })
|
|
1698
|
+
mkdirSync(dirname(IMPORT_MANIFEST_FILE), { recursive: true, mode: PRIVATE_DIR_MODE })
|
|
1699
1699
|
const tmp = IMPORT_MANIFEST_FILE + '.tmp'
|
|
1700
|
-
writeFileSync(tmp, JSON.stringify(importManifest), 'utf8')
|
|
1700
|
+
writeFileSync(tmp, JSON.stringify(importManifest), { encoding: 'utf8', mode: PRIVATE_FILE_MODE })
|
|
1701
1701
|
renameSync(tmp, IMPORT_MANIFEST_FILE)
|
|
1702
1702
|
return true
|
|
1703
1703
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angelyeye/dsh-cost-tracker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "DeepSeek Harness (DSH) plugin: LLM token usage & cost tracking with a settings dashboard, agent tools, HTTP API, persistent storage, multi-device cloud sync, session-log history import, official price sync and a multi-vendor price catalog.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/pricing.js
CHANGED
|
@@ -289,10 +289,14 @@ export const VOLCENGINE_PLAN_DEDICATED_PROVIDERS = [
|
|
|
289
289
|
/**
|
|
290
290
|
* 火山方舟 Coding Plan 覆盖的具体模型(原始名,归一化后匹配)。
|
|
291
291
|
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
292
|
+
* 清单按官方 2026-10 文档「Coding Plan 个人版快速开始」复核:可配置 Model Name
|
|
293
|
+
* 共 13 个(另有控制台托管的 ark-code-latest / Auto)。方舟模型 id 普遍带
|
|
294
|
+
* **6 位日期后缀**(`glm-5-3-flash-260828`、`deepseek-v4-1-flash-260910`、
|
|
295
|
+
* `doubao-seed-2-1-pro-260915`),故匹配时先剥掉该后缀再查表——否则泛
|
|
296
|
+
* volcengine 分支会把套餐内模型漏配成「按量计费 · 价格为估算」。
|
|
297
|
+
*
|
|
298
|
+
* 沿用旧清单的 9 个 id 未删:官方下线公告页本机取不到正文,删错会把仍在售的
|
|
299
|
+
* 套餐内模型误标按量;保留的代价只是极端情况下少算按量花费,方向更安全。
|
|
296
300
|
*/
|
|
297
301
|
const VOLCENGINE_PLAN_MODEL_IDS = [
|
|
298
302
|
'ark-code-latest',
|
|
@@ -302,15 +306,30 @@ const VOLCENGINE_PLAN_MODEL_IDS = [
|
|
|
302
306
|
'doubao-seed-2.0-pro',
|
|
303
307
|
'doubao-seed-2.0-lite',
|
|
304
308
|
'doubao-seed-2.1-pro',
|
|
309
|
+
// 2026-10 官方清单新增:豆包 2.1 Lite / 2.0 Mini / 自动演进档
|
|
310
|
+
'doubao-seed-2.1-lite',
|
|
311
|
+
'doubao-seed-2.0-mini',
|
|
312
|
+
'doubao-seed-evolving',
|
|
305
313
|
// 智谱(含用户配置里的 5.3 flash 带日期变体)
|
|
306
314
|
'glm-4.7',
|
|
307
315
|
'glm-5.1',
|
|
316
|
+
'glm-5.2',
|
|
317
|
+
'glm-5.3',
|
|
308
318
|
'glm-5.3-flash',
|
|
319
|
+
// glm-latest 是官方给 glm-5.3 的别名,归一化后是另一个键,必须单独登记
|
|
320
|
+
'glm-latest',
|
|
309
321
|
// Kimi / DeepSeek / MiniMax
|
|
310
322
|
'kimi-k2.5',
|
|
323
|
+
// 2026-08 起方舟新增的 Kimi 档(原生侧叫 kimi-for-coding / k3 系)
|
|
324
|
+
'kimi-k2.8-preview',
|
|
325
|
+
'kimi-k3',
|
|
326
|
+
'kimi-k3.1-pro',
|
|
311
327
|
'deepseek-v3.2',
|
|
312
328
|
'deepseek-v4-pro',
|
|
313
329
|
'deepseek-v4.1-flash',
|
|
330
|
+
// 2026-10 官方清单新增:经济档与旧名 V4-Flash
|
|
331
|
+
'deepseek-v4.1-flash-economy',
|
|
332
|
+
'deepseek-v4-flash',
|
|
314
333
|
'minimax-m2.5',
|
|
315
334
|
]
|
|
316
335
|
|
|
@@ -345,6 +364,15 @@ export function volcenginePlanModels() {
|
|
|
345
364
|
return out
|
|
346
365
|
}
|
|
347
366
|
|
|
367
|
+
/**
|
|
368
|
+
* 剥掉方舟模型 id 的 6 位日期后缀(归一化后的尾部 `\d{6}`)。
|
|
369
|
+
* 只用于火山白名单匹配,不改变全局 normalizeModelName 的语义。
|
|
370
|
+
* @param {string} n - 已归一化的模型名
|
|
371
|
+
*/
|
|
372
|
+
export function stripVolcDateSuffix(n) {
|
|
373
|
+
return String(n == null ? '' : n).replace(/\d{6}$/, '')
|
|
374
|
+
}
|
|
375
|
+
|
|
348
376
|
/**
|
|
349
377
|
* 解析某次调用是否命中订阅套餐。
|
|
350
378
|
* @param {string} np - 归一化 provider 名
|
|
@@ -366,9 +394,11 @@ export function subscriptionPlanFor(np, model) {
|
|
|
366
394
|
if (VOLCENGINE_PLAN_PROVIDER_KEYS.indexOf(np) < 0) return null
|
|
367
395
|
if (VOLCENGINE_PLAN_DEDICATED_PROVIDERS.indexOf(np) >= 0) return VOLC_PLAN_RATES
|
|
368
396
|
const n = normalizeModelName(model)
|
|
369
|
-
|
|
397
|
+
const bare = stripVolcDateSuffix(n)
|
|
398
|
+
const idx = volcModelIndex()
|
|
399
|
+
if (idx[n] !== undefined || (bare !== n && idx[bare] !== undefined)) return VOLC_PLAN_RATES
|
|
370
400
|
for (const p of VOLCENGINE_PLAN_MODEL_PREFIXES) {
|
|
371
|
-
if (n.startsWith(p)) return VOLC_PLAN_RATES
|
|
401
|
+
if (n.startsWith(p) || (bare !== n && bare.startsWith(p))) return VOLC_PLAN_RATES
|
|
372
402
|
}
|
|
373
403
|
return null
|
|
374
404
|
}
|
package/store.js
CHANGED
|
@@ -76,6 +76,17 @@ function sleepSync(ms) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* 私有目录 / 文件的创建模式:POSIX 上 owner-only(0o700 / 0o600)。
|
|
81
|
+
*
|
|
82
|
+
* 为什么需要:`~/.dsh/storages` 里的记录含**完整用量明细**(会话、模型、token、
|
|
83
|
+
* 花费,未脱敏时还有 sessionId),而默认 umask(常见 022)会让同机其他用户可读。
|
|
84
|
+
* Windows 会忽略 mode,行为不变;POSIX 上显式收紧到 owner-only。
|
|
85
|
+
* 已有文件不会被 chmod 改写(只影响新建),避免动到用户既有部署的权限策略。
|
|
86
|
+
*/
|
|
87
|
+
export const PRIVATE_DIR_MODE = 0o700
|
|
88
|
+
export const PRIVATE_FILE_MODE = 0o600
|
|
89
|
+
|
|
79
90
|
/**
|
|
80
91
|
* 原子落盘:写临时文件 → rename 覆盖目标。
|
|
81
92
|
*
|
|
@@ -96,8 +107,8 @@ export function writeFileAtomic(filePath, data, opts) {
|
|
|
96
107
|
const tmp = filePath + '.' + process.pid + '.tmp'
|
|
97
108
|
const cleanup = () => { try { fs.unlinkSync(tmp) } catch (e) { /* 已被 rename 走或从未创建 */ } }
|
|
98
109
|
try {
|
|
99
|
-
fs.mkdirSync(dirname(filePath), { recursive: true })
|
|
100
|
-
fs.writeFileSync(tmp, data, 'utf8')
|
|
110
|
+
fs.mkdirSync(dirname(filePath), { recursive: true, mode: PRIVATE_DIR_MODE })
|
|
111
|
+
fs.writeFileSync(tmp, data, { encoding: 'utf8', mode: PRIVATE_FILE_MODE })
|
|
101
112
|
} catch (e) {
|
|
102
113
|
cleanup()
|
|
103
114
|
return { ok: false, attempts: 0, mode: 'failed', error: e, transient: isTransientRenameError(e) }
|
|
@@ -173,8 +184,8 @@ export function checkStoreLock(filePath, opts) {
|
|
|
173
184
|
export function writeStoreLock(filePath, opts) {
|
|
174
185
|
const o = opts || {}
|
|
175
186
|
try {
|
|
176
|
-
mkdirSync(dirname(filePath), { recursive: true })
|
|
177
|
-
writeFileSync(filePath + '.lock', JSON.stringify({ pid: process.pid, at: Date.now(), version: o.version || '' }), 'utf8')
|
|
187
|
+
mkdirSync(dirname(filePath), { recursive: true, mode: PRIVATE_DIR_MODE })
|
|
188
|
+
writeFileSync(filePath + '.lock', JSON.stringify({ pid: process.pid, at: Date.now(), version: o.version || '' }), { encoding: 'utf8', mode: PRIVATE_FILE_MODE })
|
|
178
189
|
return true
|
|
179
190
|
} catch (e) {
|
|
180
191
|
return false
|
package/sync.js
CHANGED
|
@@ -47,6 +47,25 @@ export function dataDir(env) {
|
|
|
47
47
|
export function identityPath(env) { return join(dataDir(env), 'device.json') }
|
|
48
48
|
export function syncStatePath(storageDir) { return join(storageDir, 'cost-tracker-sync.json') }
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* 同步身份/游标文件的私有权限:POSIX 上 owner-only(0o700 / 0o600)。
|
|
52
|
+
* device.json 含 machineId(主机名+用户名的哈希)与设备名,游标文件含最近同步
|
|
53
|
+
* 结果,都不该让同机其他用户可读;Windows 忽略 mode,行为不变。
|
|
54
|
+
*/
|
|
55
|
+
export const PRIVATE_DIR_MODE = 0o700
|
|
56
|
+
export const PRIVATE_FILE_MODE = 0o600
|
|
57
|
+
|
|
58
|
+
function ensurePrivateDir(dir) {
|
|
59
|
+
mkdirSync(dir, { recursive: true, mode: PRIVATE_DIR_MODE })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 写临时文件(0600)→ rename,避免读者看到半个 JSON */
|
|
63
|
+
function writePrivateJson(file, value) {
|
|
64
|
+
const tmp = file + '.tmp'
|
|
65
|
+
writeFileSync(tmp, JSON.stringify(value, null, 2), { encoding: 'utf8', mode: PRIVATE_FILE_MODE })
|
|
66
|
+
renameSync(tmp, file)
|
|
67
|
+
}
|
|
68
|
+
|
|
50
69
|
function defaultMachineId(env) {
|
|
51
70
|
const e = env || process.env
|
|
52
71
|
const host = e.COMPUTERNAME || e.HOSTNAME || e.HOST || 'unknown-host'
|
|
@@ -81,8 +100,8 @@ export function loadIdentity(opts) {
|
|
|
81
100
|
nameLocked: false,
|
|
82
101
|
}
|
|
83
102
|
try {
|
|
84
|
-
|
|
85
|
-
writeFileSync(file, JSON.stringify(id, null, 2), 'utf8')
|
|
103
|
+
ensurePrivateDir(dir)
|
|
104
|
+
writeFileSync(file, JSON.stringify(id, null, 2), { encoding: 'utf8', mode: PRIVATE_FILE_MODE })
|
|
86
105
|
} catch (e) { /* 只读环境:内存态继续工作 */ }
|
|
87
106
|
return id
|
|
88
107
|
}
|
|
@@ -91,11 +110,8 @@ export function saveIdentity(id, opts) {
|
|
|
91
110
|
const env = (opts && opts.env) || process.env
|
|
92
111
|
const dir = (opts && opts.dir) || dataDir(env)
|
|
93
112
|
try {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const tmp = file + '.tmp'
|
|
97
|
-
writeFileSync(tmp, JSON.stringify(id, null, 2), 'utf8')
|
|
98
|
-
renameSync(tmp, file)
|
|
113
|
+
ensurePrivateDir(dir)
|
|
114
|
+
writePrivateJson(join(dir, 'device.json'), id)
|
|
99
115
|
return true
|
|
100
116
|
} catch (e) {
|
|
101
117
|
return false
|
|
@@ -222,11 +238,8 @@ export function readSyncState(storageDir) {
|
|
|
222
238
|
|
|
223
239
|
export function writeSyncState(storageDir, state) {
|
|
224
240
|
try {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const tmp = file + '.tmp'
|
|
228
|
-
writeFileSync(tmp, JSON.stringify(state, null, 2), 'utf8')
|
|
229
|
-
renameSync(tmp, file)
|
|
241
|
+
ensurePrivateDir(storageDir)
|
|
242
|
+
writePrivateJson(syncStatePath(storageDir), state)
|
|
230
243
|
return true
|
|
231
244
|
} catch (e) {
|
|
232
245
|
return false
|
package/vendor-catalog.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// ============================================================
|
|
2
2
|
// DSH 花费统计插件 —— 多厂商模型价格目录(纯逻辑,可独立测试)
|
|
3
3
|
//
|
|
4
|
-
// 数据来源:docs/provider-pricing.json ——
|
|
5
|
-
//
|
|
6
|
-
// sourceUrl / checkedAt
|
|
4
|
+
// 数据来源:docs/provider-pricing.json —— 初版改编自 dsh-cost-meter(MIT License)
|
|
5
|
+
// 的「已核对官方价格目录」,2026-10-25 起按各厂商官方定价页逐条复核刷新
|
|
6
|
+
// (官方页不可达时才用网关价并标注),保留每个条目的 sourceUrl / checkedAt
|
|
7
|
+
// 以便溯源;条目单价为 **USD / 1M tokens**。
|
|
7
8
|
//
|
|
8
9
|
// 本插件账本恒以人民币(CNY)入账,因此目录价在计费时按 `catalogFxRate`
|
|
9
10
|
// (默认 7.2,可在配置面板修改)折算为 CNY。缓存写入价沿用目录约定:
|
|
@@ -25,9 +26,9 @@ import { readFileSync } from 'node:fs'
|
|
|
25
26
|
import { createHash } from 'node:crypto'
|
|
26
27
|
|
|
27
28
|
export const CATALOG_META = {
|
|
28
|
-
generatedAt: '2026-
|
|
29
|
+
generatedAt: '2026-10-25',
|
|
29
30
|
note: 'USD per 1M tokens; unpriced entries have no verified official price.',
|
|
30
|
-
origin: 'adapted from dsh-cost-meter docs/provider-pricing.json (MIT)',
|
|
31
|
+
origin: 'adapted from dsh-cost-meter docs/provider-pricing.json (MIT); refreshed from vendor pricing pages 2026-10-25',
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/** 目录价 USD→CNY 默认汇率(可在配置中覆盖) */
|
|
@@ -53,6 +54,7 @@ export const PROVIDER_ALIASES = {
|
|
|
53
54
|
upstage: 'upstage', solar: 'upstage',
|
|
54
55
|
nvidia: 'nvidia', 'nvidia-nim': 'nvidia',
|
|
55
56
|
mistral: 'mistral', mistralai: 'mistral',
|
|
57
|
+
meta: 'meta', 'meta-ai': 'meta', muse: 'meta',
|
|
56
58
|
opencode: 'opencode-go', 'opencode-go': 'opencode-go', opencodego: 'opencode-go',
|
|
57
59
|
}
|
|
58
60
|
|