dsh-token-dash 2.3.0 → 2.4.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/index.js CHANGED
@@ -13,8 +13,8 @@ import { logAdapterEvents, logAdapterFailures, missSignature, readProviders, rea
13
13
  import { PROVIDER_SOURCES } from './src/quota-sources.js'
14
14
  import { catalogInfo, configurePricing, loadCommunityPricing, loadRouterPricing } from './src/pricing.js'
15
15
  import { providerCurrency } from './src/providers.js'
16
- import { clearLog, createLogger, exportLog } from './src/diagnostics.js'
17
- import { isNewer } from './src/version.js'
16
+ import { clearLog, createLogger, exportLog, pruneLogs } from './src/diagnostics.js'
17
+ import { isNewer, sameBase } from './src/version.js'
18
18
 
19
19
  export const name = 'dsh-token-dash'
20
20
 
@@ -52,7 +52,7 @@ function hostVersion() {
52
52
  }
53
53
  let updateCache = { at: 0, data: null }
54
54
  /** 允许 client 上报日志的模块白名单:只放已知来源,避免任意日志注入。 */
55
- const CLIENT_LOG_MODULES = new Set(['slot', 'update'])
55
+ const CLIENT_LOG_MODULES = new Set(['slot', 'update', 'board'])
56
56
 
57
57
  /** Locate the bundled dsh CLI (same layout scripts/e2e.mjs relies on). */
58
58
  function findDshCli() {
@@ -87,9 +87,9 @@ async function fetchLatest() {
87
87
  if (!response.ok) throw new Error(`registry-${response.status}`)
88
88
  const meta = await response.json()
89
89
  if (typeof meta?.version !== 'string') throw new Error('invalid-registry-response')
90
- return { current: CURRENT_VERSION, latest: meta.version, hasUpdate: isNewer(meta.version, CURRENT_VERSION), published: true }
91
- if (typeof meta?.version !== 'string') throw new Error('invalid-registry-response')
92
- return { current: CURRENT_VERSION, latest: meta.version, hasUpdate: isNewer(meta.version, CURRENT_VERSION), published: true, source: 'registry' }
90
+ // 本地构建与 npm 同 base 时不提示更新:本地包代码更新,装正式版反而会退回(REQ-09)
91
+ const hasUpdate = isNewer(meta.version, CURRENT_VERSION) && !sameBase(meta.version, CURRENT_VERSION)
92
+ return { current: CURRENT_VERSION, latest: meta.version, hasUpdate, published: true, source: 'registry' }
93
93
  }
94
94
 
95
95
  /** 安装 spec:默认按 npm 版本号安装,仍走与真实更新完全相同的 CLI 路径。 */
@@ -223,6 +223,12 @@ export function apply(ctx) {
223
223
  const dir = dataDir(ctx)
224
224
  const logDir = logsDir(ctx)
225
225
  const logger = createLogger({ dir: logDir, version: CURRENT_VERSION, dshVersion: hostVersion() })
226
+ // 启动即按保留策略清理:等价于「更新后清理一次旧目录」,之后每次启动持续生效
227
+ try {
228
+ const pruned = pruneLogs({ dir: logDir, activeFile: logger.file })
229
+ // 无条件记录:即使 removed 为 0 也要能确认保留策略执行过(REQ-08)
230
+ logger.info('diag', 'prune', pruned)
231
+ } catch { /* 日志治理失败不影响插件 */ }
226
232
  let prefs
227
233
  let state
228
234
  let providerCache = new Map()
@@ -368,7 +374,17 @@ export function apply(ctx) {
368
374
  const refreshProviderCache = async () => {
369
375
  if (providerRefresh !== null) return providerRefresh
370
376
  providerRefresh = (async () => {
377
+ const probeStartedAt = Date.now()
371
378
  const data = await readProviders(scoped, prefs, providerCache)
379
+ const probeElapsed = Date.now() - probeStartedAt
380
+ // 慢刷新:一次探测超过 5s 会连带阻塞排队中的请求,单独留痕便于定位是哪一轮、哪些源拖慢
381
+ if (probeElapsed > 5000) {
382
+ logger.warn('provider', 'slow', {
383
+ probeMs: probeElapsed,
384
+ misses: (data.misses ?? []).length,
385
+ failures: (data.failures ?? []).map((item) => item.id),
386
+ })
387
+ }
372
388
  const hadProviders = providerCacheMeta.hadProviders === true || data.length > 0
373
389
  providerCacheMeta = {
374
390
  ...providerCacheMeta,
@@ -384,11 +400,15 @@ export function apply(ctx) {
384
400
  })
385
401
  }
386
402
  logAdapterEvents(logger, data)
387
- logAdapterFailures(logger, data.failures)
403
+ // 缺凭据是稳定状态,并入下方「清单变化才记」的去重口径,避免每轮探测刷屏;其余失败照常每次记录
404
+ const failures = data.failures ?? []
405
+ const isMissingCredential = (item) => item.error?.kind === 'missing-credential'
406
+ logAdapterFailures(logger, failures.filter((item) => !isMissingCredential(item)))
388
407
  // 只在探测清单变化时记一次:启动首轮必打,之后配 Key / 断网导致清单变动才再打,避免每轮刷屏
389
408
  const signature = missSignature(data)
390
409
  if (signature !== providerCacheMeta.missSignature) {
391
410
  providerCacheMeta = { ...providerCacheMeta, missSignature: signature }
411
+ logAdapterFailures(logger, failures.filter(isMissingCredential))
392
412
  logger.info('provider', 'cache.state', {
393
413
  entries: providerCache.size,
394
414
  providers: data.length,
@@ -553,7 +573,9 @@ export function apply(ctx) {
553
573
  json(res, 400, { ok: false, reason: 'invalid-log' })
554
574
  return
555
575
  }
556
- logger.info(body.module, body.event, typeof body.meta === 'object' && body.meta !== null ? body.meta : {})
576
+ // level 仅接受 warn,其余一律 info;非法值不报错,避免客户端因日志失败而重试
577
+ const write = body.level === 'warn' ? logger.warn : logger.info
578
+ write(body.module, body.event, typeof body.meta === 'object' && body.meta !== null ? body.meta : {})
557
579
  json(res, 200, { ok: true, data: { logged: true } })
558
580
  return
559
581
  }
package/locale/en.json CHANGED
@@ -10,6 +10,11 @@
10
10
  "内置兜底": "Built-in fallback",
11
11
  "查询失败": "Query failed",
12
12
  "套餐查询失败": "Quota query failed",
13
+ "数据加载中": "Loading data",
14
+ "含估算": "incl. estimates",
15
+ "API 与订阅金额均为本地按目录价估算,非供应商账单;缓存读按缓存价计,命中率高的行每 token 成本显著更低,不同行不可直接按 token 数比较;不同币种需自行换算": "Both API and subscription amounts are estimated locally from catalog prices, not provider invoices; cached reads use the cache price, so rows with a higher hit rate cost much less per token and rows are not directly comparable by token count; currencies are not converted.",
16
+ "本月估算": "Est. this month",
17
+ "订阅不计价,估算值仅作参考": "Subscription is not billed; the estimate is for reference only",
13
18
  "周": "Week",
14
19
  "月": "Month",
15
20
  "重置": "Reset",
@@ -124,6 +129,8 @@
124
129
  "范围内全部模型": "All models in range",
125
130
  "创建 {a} · 命中 {b}": "Created {a} · hit {b}",
126
131
  "趋势指标": "Trend metric",
132
+ "模型明细": "Model breakdown",
133
+ "范围按当前时间范围统计": "Scoped to the selected range",
127
134
  "使用趋势 · {metric}": "Trend · {metric}",
128
135
  "按天": "Daily",
129
136
  "按月": "Monthly",
package/locale/zh.json CHANGED
@@ -10,6 +10,11 @@
10
10
  "内置兜底": "内置兜底",
11
11
  "查询失败": "查询失败",
12
12
  "套餐查询失败": "套餐查询失败",
13
+ "数据加载中": "数据加载中",
14
+ "含估算": "含估算",
15
+ "API 与订阅金额均为本地按目录价估算,非供应商账单;缓存读按缓存价计,命中率高的行每 token 成本显著更低,不同行不可直接按 token 数比较;不同币种需自行换算": "API 与订阅金额均为本地按目录价估算,非供应商账单;缓存读按缓存价计,命中率高的行每 token 成本显著更低,不同行不可直接按 token 数比较;不同币种需自行换算",
16
+ "本月估算": "本月估算",
17
+ "订阅不计价,估算值仅作参考": "订阅不计价,估算值仅作参考",
13
18
  "周": "周",
14
19
  "月": "月",
15
20
  "重置": "重置",
@@ -124,6 +129,8 @@
124
129
  "范围内全部模型": "范围内全部模型",
125
130
  "创建 {a} · 命中 {b}": "创建 {a} · 命中 {b}",
126
131
  "趋势指标": "趋势指标",
132
+ "模型明细": "模型明细",
133
+ "范围按当前时间范围统计": "范围按当前时间范围统计",
127
134
  "使用趋势 · {metric}": "使用趋势 · {metric}",
128
135
  "按天": "按天",
129
136
  "按月": "按月",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-token-dash",
3
- "version": "2.3.0",
4
- "description": "DeepSeek Harness Token 看板:月度预算与订阅配额、账户余额、时间范围费用与真实 Tokens 明细,支持本地 JSON 导出 / 导入备份。",
3
+ "version": "2.4.0",
4
+ "description": "DeepSeek Harness Token 与费用看板:按供应商查看预算、订阅配额(GLM / Kimi / OpenCode Go / Command Code)与账户余额;Pill、浮层、整页三处展示费用与真实 Tokens、缓存命中率与用量趋势,成本趋势支持双币种双轴;订阅用量给出按 API 单价的估算参考,未定价模型不按 0 元计,可导出 / 导入本地 JSON 备份。",
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
7
  "exports": {
@@ -20,7 +20,8 @@
20
20
  "AGENTS.md"
21
21
  ],
22
22
  "engines": {
23
- "node": ">=20"
23
+ "node": ">=20",
24
+ "dsh": ">=0.2.1"
24
25
  },
25
26
  "keywords": [
26
27
  "deepseek",