@kenz1117/dsh-ui-usage-billing 0.9.6 → 0.9.8
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 +2 -1
- package/README.md +5 -3
- package/lib/client.js +946 -390
- package/lib/index.js +1046 -304
- package/lib/types/aggregate.d.ts +48 -1
- package/lib/types/balance.d.ts +5 -6
- package/lib/types/client/PerfPanel.d.ts +45 -0
- package/lib/types/client/PluginInfoCard.d.ts +12 -0
- package/lib/types/client/TokenPanel.d.ts +24 -0
- package/lib/types/client/UsageBilling.d.ts +117 -1
- package/lib/types/client/heatmap.d.ts +4 -2
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/plan-knowledge.d.ts +24 -5
- package/lib/types/client/plugin-info.d.ts +20 -0
- package/lib/types/client/usage-billing-settings.d.ts +20 -0
- package/lib/types/index.d.ts +28 -2
- package/lib/types/pricing-shared.d.ts +25 -2
- package/lib/types/relay.d.ts +61 -0
- package/lib/types/resilience.d.ts +49 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|

|
|
45
45
|
- **Custom provider balance**: configure any HTTP endpoint for balance (`extract` supports constant / dot-path / add-subtract / divide, header `{{ENV}}` via the credentials seam); DeepSeek / Kimi / StepFun / SiliconFlow have built-in official balances, and the balance column estimates "≈N days" from the 7-day daily burn.
|
|
46
|
-
- **Real usage aggregation**: the server aggregates from session logs on demand (incremental cache recomputes only written sessions), with per-session corruption tolerance and snapshot fallback;
|
|
46
|
+
- **Real usage aggregation**: the server aggregates from session logs on demand (incremental cache recomputes only written sessions), with per-session corruption tolerance and snapshot fallback; an optional `usage_stats` tool lets the model query today / month spend (**off by default** — toggle it in the Settings tab; takes effect after a reload).
|
|
47
47
|
- **Multi-language + dual currency**: the ¥/$ switch is bilingual (USD→English, CNY→Chinese, this plugin only); the rate table converts to the selected currency.
|
|
48
48
|
- **Model health + uncatalogued annotation**: provider connection dots (green / red / grey); a model id not in the catalog is marked "uncatalogued" priced at the fallback, with provider inferred (e.g. `mi-mimo-2.5` → Xiaomi); estimated-price models are marked "estimated".
|
|
49
49
|
- **Session detail + cost spikes + heatmap**: sessions sorted by cost (title / project / calls / cost / last active); per-turn cost bars (last 40 turns, amount at bar top, peak/off-peak background bands, >2× spike flagged with attribution); a monthly calendar heatmap (5-color scale, hover detail).
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|

|
|
52
52
|
|
|
53
53
|
- **Export + offline self-contained**: the Stats tab exports daily / per-session CSV and full JSON; no chart library, no external CDN, pure design tokens.
|
|
54
|
+
- **Stability & reliability**: official-interface shape drift degrades with an explicit `invalid` status (distinct from network-unreachable); balance / subscription / pricing upstreams share a unified timeout budget, exponential-backoff retry and per-platform circuit-breaker cooldown; the stats snapshot is written with a `.bak` backup and auto-recovers from corruption; session-log reads re-check freshness to avoid half-line misreads; auth failures warn per provider with cooldown; the per-session fold cache is bounded by LRU to keep long-running memory stable.
|
|
54
55
|
|
|
55
56
|

|
|
56
57
|
|
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
|
|
39
39
|

|
|
40
40
|
- **官方 vs 三方分桶**:明细费用列按官方 DeepSeek 直连 / 第三方中转分解(混合时「官 x / 三 y」),统计 Tab 有「官方/三方」汇总卡。
|
|
41
|
+
- **中转站归组与额度**:按 provider 的 `baseURL` 归一化 origin 归组——同一中转站的多把 key 合并成一行,站名即域名;明细 Tab 新增「中转站分布」卡(中转站 / 直连 / 未知路由三态,未知路由 = 配置里已删 / 改名的路由,诚实标注「读不到」而非误归直连)。对配了 `baseURL` 的路由自动识别 New API 系(`/api/status`)与 Sub2API(`/v1/usage`)的**余额与滚动额度窗口**,读不出标「未读出额度」;智谱 GLM / Z.ai 国内域钱包余额已接入(与订阅套餐双读)。项目归属优先用工作区标题命名。
|
|
41
42
|
- **月度预算 + 分档提醒**:预算条(开关 / 金额 / 进度,≥80% 琥珀、超支红脉);跨 50 / 80 / 100% 各提醒一次;余额折算 CNY 低于阈值每天提醒一次。
|
|
42
43
|
- **订阅套餐额度**:识别 `llm-pi-ai` 里的订阅类 provider(Kimi / Z.ai / OpenCode Go / MiniMax / OpenRouter / 小米 / 火山…),有额度 API 的实时显示剩余%与重置时间、用尽标红,无 API 标「未接入」;订阅通道模型费用记 0。档位月费与周期额度口径由内置知识库自动识别(如 OpenCode Go $10/月 + 周 $30 额度),有档位知识的标「自动识别」。
|
|
43
44
|
|
|
@@ -92,7 +93,7 @@ npm install @kenz1117/dsh-ui-usage-billing
|
|
|
92
93
|
└─ 渲染仪表盘
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
- **服务端**(`src/index.ts`):注入 `webServer`、`sessionPersistence` 与 `credentials`,注册 `GET /api/billing/usage-stats`、`/api/billing/pricing`、`/api/billing/balance`。聚合器按会话缓存折叠结果:一次 LLM 调用归属到其前置 `request/header` 记录的模型,token 拆分到缓存命中 / 未命中桶,日期按本机时区归天;日志文件 mtime+size 不变则直接复用缓存,只有写过的会话重新折叠,整份文档另有 5 秒 TTL 合并密集轮询。聚合逻辑见 `src/aggregate.ts`。
|
|
96
|
+
- **服务端**(`src/index.ts`):注入 `webServer`、`sessionPersistence` 与 `credentials`,注册 `GET /api/billing/usage-stats`、`/api/billing/pricing`、`/api/billing/balance`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`。聚合器按会话缓存折叠结果:一次 LLM 调用归属到其前置 `request/header` 记录的模型,token 拆分到缓存命中 / 未命中桶,日期按本机时区归天;日志文件 mtime+size 不变则直接复用缓存,只有写过的会话重新折叠,整份文档另有 5 秒 TTL 合并密集轮询。聚合逻辑见 `src/aggregate.ts`。
|
|
96
97
|
- **浏览器端**(`src/client/`):请求上述接口渲染仪表盘,通过 `llm.models` 探测各厂商连接状态。真实数据到达前显示全零空快照,不展示伪造样本。
|
|
97
98
|
|
|
98
99
|
## 主题协作
|
|
@@ -140,7 +141,7 @@ cost(CNY)= (missInput × p_input + cacheHit × p_cacheHit + output × p_outp
|
|
|
140
141
|
|
|
141
142
|
## HTTP API
|
|
142
143
|
|
|
143
|
-
对外 HTTP 接口与字段定义详见源码:`GET /api/billing/pricing`、`/api/billing/balance`、`/api/billing/usage-stats`(见 `src/index.ts`、`src/aggregate.ts`)。
|
|
144
|
+
对外 HTTP 接口与字段定义详见源码:`GET /api/billing/pricing`、`/api/billing/balance`、`/api/billing/usage-stats`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`(见 `src/index.ts`、`src/aggregate.ts`、`src/relay.ts`)。其中 `usage-stats` 返回的 `bySite` 字段为按中转站归组后的用量分布(`site:<origin>` / `direct:<provider>` / `unknown`)。
|
|
144
145
|
|
|
145
146
|
## 配置
|
|
146
147
|
|
|
@@ -179,7 +180,8 @@ npm publish --access public
|
|
|
179
180
|
|
|
180
181
|
## Known Limitations and Deferred Work
|
|
181
182
|
|
|
182
|
-
- **余额查询已接入 DeepSeek / 月之暗面(Kimi)/ 阶跃星辰(StepFun
|
|
183
|
+
- **余额查询已接入 DeepSeek / 月之暗面(Kimi)/ 阶跃星辰(StepFun)/ 硅基流动 / xAI / 智谱 GLM(Z.ai 国内域)**:这些用标准 Bearer API key 即可查询。其余厂商因无公开余额接口或需非 Bearer 鉴权(小米 MiMo 走控制台 Cookie、商汤走 AccessKey 签名、MiniMax/字节豆包走额度制或 AK/SK),暂显示「未配置」;扩展点在 `src/balance.ts`(按厂商余额 API 增加查询器)。
|
|
184
|
+
- **中转站额度依赖上游私有 schema**:New API / Sub2API 的接口字段未公开,读不出时标「未读出额度」而非臆造金额;若某中转站响应字段不同,需按 `src/relay.ts` 的解析器扩展。未知路由表示该路由在当前 provider 配置里已不存在(改过名 / 删除过),历史调用数据未丢,重新配置同名路由即可自动归位。
|
|
183
185
|
- **超支通知依赖浏览器 Notification**:权限被拒绝或平台不支持时只有界面红色脉冲兜底,没有宿主级通知通道;通知上限为每天一次。
|
|
184
186
|
- **会话明细不可跳转**:点击会话行不会打开对应会话(跨插件导航需要宿主会话选择通道);会话数封顶 100 行、面板只显示前 20 行。
|
|
185
187
|
- **费用为目录价估算**:讯飞 / 商汤 / 小米等未公布按量单价的模型使用估算价(特性表脚注 ¹),正式定价以厂商账单为准。
|