@kenz1117/dsh-ui-usage-billing 0.9.4 → 0.9.6

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/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import { readFile, stat } from "node:fs/promises";
2
3
  import { homedir } from "node:os";
3
4
  import { join } from "node:path";
@@ -964,6 +965,7 @@ function emptyUsage() {
964
965
  cacheHit: 0,
965
966
  cacheMiss: 0,
966
967
  cost: 0,
968
+ reasoning: 0,
967
969
  officialCalls: 0,
968
970
  officialCost: 0
969
971
  };
@@ -985,6 +987,7 @@ function foldUsage(acc, usage, key, subscription, timeMs, official = false) {
985
987
  acc.calls += 1;
986
988
  acc.input += usage.inputTokens + cacheHit + (usage.cacheWriteTokens ?? 0);
987
989
  acc.output += usage.outputTokens;
990
+ acc.reasoning += usage.reasoningTokens ?? 0;
988
991
  acc.cacheHit += cacheHit;
989
992
  acc.cacheMiss += cacheMiss;
990
993
  if (official) acc.officialCalls += 1;
@@ -1247,6 +1250,7 @@ function mergeUsageInto(acc, cell) {
1247
1250
  acc.calls += cell.calls;
1248
1251
  acc.input += cell.input;
1249
1252
  acc.output += cell.output;
1253
+ acc.reasoning += cell.reasoning;
1250
1254
  acc.cacheHit += cell.cacheHit;
1251
1255
  acc.cacheMiss += cell.cacheMiss;
1252
1256
  acc.cost += cell.cost;
@@ -1265,8 +1269,14 @@ function percentile(values, p) {
1265
1269
  const idx = (sorted.length - 1) * p;
1266
1270
  const lo = Math.floor(idx);
1267
1271
  const hi = Math.ceil(idx);
1268
- if (lo === hi) return sorted[lo];
1269
- return sorted[lo] + (sorted[hi] - sorted[lo]) * (idx - lo);
1272
+ if (lo === hi) {
1273
+ const value = sorted[lo];
1274
+ return value === void 0 ? 0 : value;
1275
+ }
1276
+ const a = sorted[lo];
1277
+ const b = sorted[hi];
1278
+ if (a === void 0 || b === void 0) return 0;
1279
+ return a + (b - a) * (idx - lo);
1270
1280
  }
1271
1281
  /**
1272
1282
  * Create the incremental usage aggregator.
@@ -2083,7 +2093,7 @@ const SUBSCRIPTION_DISPLAY_NAMES = {
2083
2093
  "openrouter": "OpenRouter"
2084
2094
  };
2085
2095
  /** 订阅类 provider id 判定:带 coding / agent-plan / token-plan 后缀,或已知订阅通道。 */
2086
- const SUBSCRIPTION_ID_RE = /(?:^|-)(?:coding|agent[-_]?plan|token[-_]?plan)(?:$|-|_)|^(?:opencode|opencode-go|kimi-coding|zai-coding|minimax|minimax-token-plan|openrouter)/i;
2096
+ const SUBSCRIPTION_ID_RE = /* @__PURE__ */ new RegExp("(?:^|-)(?:coding|agent[-_]?plan|token[-_]?plan)(?:$|-|_)|^(?:opencode|opencode-go|kimi-coding|zai-coding|minimax|minimax-token-plan|openrouter)", "i");
2087
2097
  /** 是否是订阅类 provider id(如 kimi-coding、xiaomi-token-plan-cn)。 */
2088
2098
  function isSubscriptionProviderId(providerId) {
2089
2099
  if (SUBSCRIPTION_ID_RE.test(providerId)) return true;
@@ -2582,6 +2592,11 @@ const PRICING_REFRESH_INTERVAL_MS = 360 * 60 * 1e3;
2582
2592
  const SUBSCRIPTION_CACHE_MS = 300 * 1e3;
2583
2593
  /** DeepSeek 余额查询的默认凭据引用(与 llm-deepseek 的默认引用一致)。 */
2584
2594
  const DEFAULT_BALANCE_API_KEY_ENV = "DEEPSEEK_API_KEY";
2595
+ /**
2596
+ * 本插件版本号:从包自身的 package.json 读取(单一来源),随 usage-stats
2597
+ * 下发,供「设置 → 插件信息卡」展示。发布版 lib/index.js 相对包根解析。
2598
+ */
2599
+ const PACKAGE_VERSION = createRequire(import.meta.url)("../package.json").version ?? "0.0.0";
2585
2600
  /** 统计快照的落盘节流(毫秒):前端 30 秒轮询,快照最多每 30 秒写一次。 */
2586
2601
  const SNAPSHOT_INTERVAL_MS = 3e4;
2587
2602
  /** Required services: the web server, the persisted session log store, and user settings. */
@@ -2913,8 +2928,9 @@ function apply(ctx, config = {}) {
2913
2928
  ...config.monthlyBudget === void 0 ? {} : { budget: config.monthlyBudget },
2914
2929
  ...config.lowBalanceThreshold === void 0 ? {} : { lowBalanceThreshold: config.lowBalanceThreshold }
2915
2930
  };
2916
- const payload = Object.keys(injected).length === 0 ? stats : {
2931
+ const payload = {
2917
2932
  ...stats,
2933
+ pluginVersion: PACKAGE_VERSION,
2918
2934
  ...injected
2919
2935
  };
2920
2936
  persistSnapshot(payload);
@@ -2928,6 +2944,7 @@ function apply(ctx, config = {}) {
2928
2944
  const doc = JSON.parse(text);
2929
2945
  if (config.monthlyBudget !== void 0) doc["budget"] = config.monthlyBudget;
2930
2946
  if (config.lowBalanceThreshold !== void 0) doc["lowBalanceThreshold"] = config.lowBalanceThreshold;
2947
+ doc["pluginVersion"] = PACKAGE_VERSION;
2931
2948
  res.end(JSON.stringify(doc));
2932
2949
  return;
2933
2950
  } catch {}
@@ -42,6 +42,8 @@ export interface ModelUsage {
42
42
  cacheHit: number;
43
43
  cacheMiss: number;
44
44
  cost: number;
45
+ /** 输出中的 reasoning(思考)token;已包含在 `output` 内,单列用于结构展示。 */
46
+ reasoning: number;
45
47
  /** 该模型本次统计的所有调用是否都走订阅通道(coding/token plan);混合通道不置位。 */
46
48
  plan?: boolean;
47
49
  /** 走官方渠道的调用数(DeepSeek 官方直连;其余为三方)。 */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kenz1117/dsh-ui-usage-billing",
3
3
  "description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
4
- "version": "0.9.4",
4
+ "version": "0.9.6",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },