@angelyeye/dsh-cost-tracker 1.8.13 → 1.8.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/CHANGELOG.md +129 -0
- package/README.en.md +47 -4
- package/README.md +47 -4
- package/client.js +161 -3
- package/config.js +41 -1
- package/index.js +326 -10
- package/package.json +4 -2
- package/pricing.js +159 -1
- package/volcengine.js +456 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,135 @@
|
|
|
2
2
|
|
|
3
3
|
本文件用中文记录 dsh-cost-tracker 的版本变更。
|
|
4
4
|
|
|
5
|
+
## v1.8.15(2026-09-26)
|
|
6
|
+
|
|
7
|
+
**修复:火山方舟配额面板「没有配置入口」+「拿推理 Key 当 AK」+ 两个失败路径缺陷**
|
|
8
|
+
|
|
9
|
+
真机现场:用户装了 v1.8.14 后,设置页出现「订阅套餐用量 · 火山方舟 Coding Plan」面板,
|
|
10
|
+
但显示 `配额查询不可用:火山方舟凭据无效或无权限访问 GetPersonalPlan(HTTP 401)`,
|
|
11
|
+
且面板上**没有任何可填写凭据的地方** —— 只有一句「需要 AK/SK」,无从下手。
|
|
12
|
+
|
|
13
|
+
### 一、面板自带凭据输入框(用户直接提出的问题)
|
|
14
|
+
|
|
15
|
+
- 面板内新增一行输入:`AccessKeyID`(明文回显,控制台里本就可见)+ `SecretAccessKey`
|
|
16
|
+
(`type=password`,**从不回显**;已保存过时 placeholder 变为「已保存,留空则不改」)。
|
|
17
|
+
- 三个动作:
|
|
18
|
+
- **查询** —— 用输入框里的值直接查一次,**不落盘**,便于先验证凭据对不对;
|
|
19
|
+
- **保存** —— 写入 `~/.dsh/storages/cost-tracker-config.json`,重启不丢;
|
|
20
|
+
- **清除凭据** —— 显式清空(仅在有凭据时出现)。
|
|
21
|
+
- 工具栏新增**「火山方舟配额」按钮**作为入口。此前面板只在「存在火山订阅调用」时渲染,
|
|
22
|
+
新用户既看不到面板、也没有入口 —— 等于功能不存在。
|
|
23
|
+
- 面板标题旁新增来源徽标:`已保存凭据` / `临时凭据` / `环境变量`,一眼看出当前用的是哪套。
|
|
24
|
+
|
|
25
|
+
### 二、修复:推理 API Key 被当成 AccessKeyID(401 的真正根因)
|
|
26
|
+
|
|
27
|
+
配了 baseURL 指向 `ark.cn-beijing.volces.com/api/coding/v3` 的 provider 时,其 `apiKeyEnv`
|
|
28
|
+
(如 `BYTEBLUS_CODING_PLAN_CN_API_KEY`)是**推理用的 API Key**,而配额查询要的是 IAM 的
|
|
29
|
+
`AccessKeyID + SecretAccessKey` —— 两套完全不同的凭据。
|
|
30
|
+
|
|
31
|
+
早先 `volcengineEnvCandidates()` 把这个 apiKeyEnv 也塞进 AK 候选,于是出现跨来源拼凑:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
AK = BYTEBLUS_CODING_PLAN_CN_API_KEY(推理 Key,UUID 形态)
|
|
35
|
+
SK = VOLC_SECRETKEY(凭据库里的真 SK)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
用这对假凭据去签名,服务端必然 401;而 401 在本插件里是「软失败」,只报「凭据无效或
|
|
39
|
+
无权限」,**根因完全查不出来**(真机上就表现为那一行误导性报错)。
|
|
40
|
+
|
|
41
|
+
现在:
|
|
42
|
+
- AK 与 SK 必须**同源配对** —— 先按候选名取到 AK,再用**同名推导出的** SECRET 变体取 SK,
|
|
43
|
+
绝不跨来源拼接;
|
|
44
|
+
- 用命名识别推理 Key(含 `API_KEY`/`APIKEY`/`TOKEN` 且不含 `ACCESSKEY`/`SECRETKEY`/
|
|
45
|
+
`SECRET`),把这类候选**排除**在 AK 之外,并在提示里点名:
|
|
46
|
+
「你配置的 X 是推理用的 ARK API Key,不是配额凭据,插件不会拿它去签名」;
|
|
47
|
+
- 缺凭据时明确区分「都缺 / 缺 AK / 缺 SK」。
|
|
48
|
+
|
|
49
|
+
### 三、修复:两个失败路径缺陷
|
|
50
|
+
|
|
51
|
+
- **`ReferenceError`(TDZ)把软失败变成 500**:`keyEnv` 原先声明在 `try` 内却在 `catch`
|
|
52
|
+
里引用。任何一次查询失败(401 / 网络异常 / 结构变化)都会在错误处理里再抛一次
|
|
53
|
+
`keyEnv is not defined`,被路由层兜成 **HTTP 500** —— 恰好把所有失败路径都打穿了。
|
|
54
|
+
现声明在 `try` 之外。(由新增的失败路径断言抓到。)
|
|
55
|
+
- **`keyEnv` 永远显示「未知」**:`resolveApiKey()` 只返回 `{ value, source }`,`env` 是
|
|
56
|
+
`resolveAnyEnv()` 才加的字段;误取 `rid.env` 得到 `undefined`,于是面板从不显示
|
|
57
|
+
「该去改哪个环境变量」。现直接用循环变量名。
|
|
58
|
+
|
|
59
|
+
### 四、防呆:空串不等于清空
|
|
60
|
+
|
|
61
|
+
因为 SK 从不回显,跨浏览器 / 重开面板时 SK 输入框**必然是空的**。若把空串当作「清空」,
|
|
62
|
+
用户只改一下 AK 就会把已存好的 SK 一起写空 —— 静默丢凭据。现在:
|
|
63
|
+
|
|
64
|
+
| 请求 | 行为 |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `{volcengineAccessKeyId:'新AK'}` | 只改 AK,**SK 原样保留** |
|
|
67
|
+
| `{volcengineSecretAccessKey:'新SK'}` | 只改 SK |
|
|
68
|
+
| `{volcengineAccessKeyId:'', volcengineSecretAccessKey:''}` | **不动**(空串不是指令) |
|
|
69
|
+
| `{clear:true}` | 显式清空两者 |
|
|
70
|
+
|
|
71
|
+
响应回显 `volcengineAccessKeyId`(非敏感)与 `volcengineHasKeys`,**永不回显 SK**。
|
|
72
|
+
|
|
73
|
+
### 五、测试
|
|
74
|
+
|
|
75
|
+
`test/volcengine-host.test.js` 从 36 条扩到 **48 条**,新增四组:
|
|
76
|
+
推理 Key 不得被当作 AK(真实故障回归,复刻用户的 provider 配置)/ 空串不覆盖已存 SK /
|
|
77
|
+
只改 AK 后仍可用 / `clear` 才清空。全量测试通过。
|
|
78
|
+
|
|
79
|
+
## v1.8.14(2026-09-26)
|
|
80
|
+
|
|
81
|
+
**新增:火山方舟 Coding Plan 订阅支持(配额监控 + 等效费用);并修掉两个此前静默存在的缺陷**
|
|
82
|
+
|
|
83
|
+
### 一、新增:火山方舟 Coding Plan 配额面板
|
|
84
|
+
|
|
85
|
+
- **设置页新增「订阅套餐用量 · 火山方舟 Coding Plan」面板**,与既有 Kimi 面板并列,显示 **5 小时 / 周 / 月** 三档窗口的已用百分比、绝对量与重置倒计时,附「刷新配额」按钮。
|
|
86
|
+
- **查询走方舟管控面 OpenAPI**,不是推理端点:
|
|
87
|
+
- 端点固定 `https://open.volcengineapi.com/`,`Service=ark`、`Region=cn-beijing`、`Version=2024-01-01`;
|
|
88
|
+
- 认证是 **HMAC-SHA256 签名**(`Credential=AK/日期/区域/服务/request`、`SignedHeaders=host;x-content-sha256;x-date`),**不是 Bearer** —— 这是与 Kimi 那条路径最大的差别;
|
|
89
|
+
- Action 按 `GetCodingPlanUsage → GetAFPUsage → GetUsageDetails → GetPersonalPlan` 顺序兜底。`GetCodingPlanUsage` 是官方 CodingPlan 用量接口,**无参即可返回三档窗口**;`GetAFPUsage` 实为 AgentPlan 接口,账号是 Agent Plan 时自动从它取数;
|
|
90
|
+
- 单个 Action 的 401/403 只表示「该 Action 不可用」(多 Action 变体权限语义不同),继续尝试下一个;200 但解析失败时**优先透出服务端业务信封**(`ResponseMetadata.Error.Code/Message`),因为它比末尾变体的 404 更有诊断价值。
|
|
91
|
+
- **凭据发现链**:插件配置卡片(`volcengineAccessKeyId` / `volcengineSecretAccessKey`)→ DSH 凭据库 → `.credentials.yaml` → 环境变量(`VOLC_ACCESSKEY` / `VOLC_SECRETKEY`,兼容 `VOLCENGINE_ACCESS_KEY_ID`、`ARK_ACCESS_KEY_ID` 等变体;也会从指向方舟 coding 端点的 provider 的 `apiKeyEnv` 反查)。
|
|
92
|
+
- 需要 IAM 子用户具备 **`ArkReadOnlyAccess` + `BillingCenterReadOnlyAccess`**。这与推理用的 **ARK API Key(UUID)是两套凭据**,混填只会得到 401/403。
|
|
93
|
+
- **密钥零外泄**:`volcengine-usage` / `volcengine-config` / `sync` 的响应里**永远不含 AK/SK**,只回 `keySource`(`config` / `credentials:…` / `file`)与候选变量名;卡片里的 Secret 字段标了 `role('secret')`。
|
|
94
|
+
- **失败一律软降级为中性提示**:无凭据、无订阅、权限不足、接口结构变化、网络异常都只回 `{ok:false, error:'中文原因'}`,HTTP 层仍是 200,**不抛异常、不影响其它路由**。
|
|
95
|
+
- **按需出现**:面板只在「存在火山订阅调用(宿主在 `summary` 里回传 `volcengineActive`)或已有窗口数据」时渲染。只跑 DeepSeek / Kimi 的用户界面**完全不变**。
|
|
96
|
+
- **百分比精度**:实测 `Percent` 是 0-100 的百分数但数值极小(`0.3938…` / `0.0997…` / `0.0498…`,即 0.39% / 0.1% / 0.05%),故保留**两位小数** —— 只留一位会把月度 0.05% 显示成「0%」,看上去像没统计到。同时**不套用「≤1 视为小数」的规则**(那会把 0.5% 放大成 50%)。`Cap`(实测恒为 100)用于折算绝对量。
|
|
97
|
+
|
|
98
|
+
### 二、修掉订阅门卫缺陷:按量调用曾被错记成订阅(重要)
|
|
99
|
+
|
|
100
|
+
- **缺陷**:`priceFor()` 原先只按 **provider 名**判定订阅,对该 provider 的**所有模型**一律套订阅价。
|
|
101
|
+
- **为什么此前没暴露**:Kimi 的 provider 下每个模型都走订阅,所以「只看 provider」恰好成立。
|
|
102
|
+
- **为什么火山会踩**:同一个 provider 下**套餐内与套餐外的模型混在一起** —— 订阅调用被错记为 `subscription: true` 后,金额会从「真实花费」里消失(计入订阅等效而不是按量),且原始记录已被打标,**无法自动回滚**。这是典型的「静默少算」。
|
|
103
|
+
- **现在**:`subscriptionPlanFor(np, model)` 改为「provider 命中 + 模型白名单」双重限定,并区分两类 provider:
|
|
104
|
+
| provider | 判定 |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| baseURL 指向 `ark.cn-beijing.volces.com/api/coding/v3` 的专属订阅入口(`byteblus-coding-plan-cn`、`byteplus-coding-plan-cn`、`volcengine-coding` 等) | **整档计订阅**,不必追模型日期后缀 |
|
|
107
|
+
| 泛 `volcengine` | **仅白名单内模型计订阅**(豆包系 / GLM 系 / Kimi 系 / DeepSeek / MiniMax,以及 `ark-code-*` 前缀整族);**接入点 id(`ep-2026xxxx`)一律按量** |
|
|
108
|
+
| `kimi` / `kimi-coding` | `SUBSCRIPTION_MODELS` 登记为 `null` = 整档订阅,**行为逐字节不变** |
|
|
109
|
+
- **前缀刻意收窄**:只放行 `ark-code-*`(方舟自动调度名会滚动升级)。按 `deepseek` / `glm` 这类宽前缀整族放行会把套餐外的按量模型一并算成订阅 —— 那正是本门卫要防的方向;宁可漏配(可显式补清单)也不能错配。
|
|
110
|
+
- **等效单价口径**:套餐内各模型牌价差异很大,而套餐只有一个固定月费、官方并未给出「套餐内某次调用的等效单价」。故取**单一代表价**(3.0 / 12.0 / 缓存 0.6),与既有 Kimi 订阅(同样一个价位代表整档)口径一致,**仅用于横向比较订阅是否划算,不是真实扣费**;可核实到的第三方报价多为聚合站美元估价,与官方人民币牌价不可直接对照,按本仓库「不编造价格」的约定不收录。
|
|
111
|
+
|
|
112
|
+
### 三、修掉凭据文件读取缺陷:`.credentials.yaml` 兜底一直静默失效(重要)
|
|
113
|
+
|
|
114
|
+
- **缺陷**:`readCredFile()` 的正则只匹配**行首无缩进**的键,而真实文件是把键**缩进**存放在 `refs:` 段下的:
|
|
115
|
+
```yaml
|
|
116
|
+
version: 1
|
|
117
|
+
refs:
|
|
118
|
+
VOLC_ACCESSKEY: AKxxxx # ← 缩进两格,旧正则匹配不到
|
|
119
|
+
VOLC_SECRETKEY: xxxx
|
|
120
|
+
records:
|
|
121
|
+
...
|
|
122
|
+
```
|
|
123
|
+
于是所有键都读不出来,这一路兜底**一直静默失效**(装了宿主凭据服务时被掩盖,没有时就直接报「未找到 Key」)。该缺陷同时影响原本的 Kimi / DeepSeek Key 兜底路径。
|
|
124
|
+
- **现在**:识别缩进、定位 `refs:` 段(避免误读 `records:` 段里的同名键),并保留对「无缩进的旧版平铺文件」的兼容(段内未命中时回落到段外同名键)。
|
|
125
|
+
- **顺带修掉路径硬编码**:原路径写死 `~/.dsh/.credentials.yaml`,`DSH_HOME` 被重定向的部署(含本仓库的沙箱测试)永远读不到;现改为跟随 `DSH_HOME`。
|
|
126
|
+
|
|
127
|
+
### 四、测试
|
|
128
|
+
|
|
129
|
+
- 新增 `test/volcengine-plan.test.js`(113 条):**与火山官方 demo(`volc-openapi-demos/signature/nodejs/sign.js`)逐字节一致的固定签名向量**、查询串排序与严格 RFC3986 转义、四种响应形态(官方 `QuotaUsage[Level/Percent]`、`UsageDetails`、arkcli `items→periods`、AFP 扁平窗口)、**0.5% 不被放大成 50%**、负数百分比判非法而非钳成 0、`ResetTime=-1` 归一为「无重置」、凭据残缺判 null 且不发请求、403 换 Action、业务信封优先于末尾 404。
|
|
130
|
+
- 新增 `test/volcengine-host.test.js`(36 条):宿主面端到端(老配置 + 凭据文件 → 已签名请求 → 可渲染窗口)、**密钥零外泄**(响应 / sync / 卡片写入三处)、配置卡片凭据优先、真机响应形状(0.05% 不被抹成 0%)、五类失败路径软降级、120s 缓存 TTL 与 `force` 绕过。
|
|
131
|
+
- `test/pricing.test.js` 新增「订阅门卫 + 火山 Coding Plan」一节(覆盖两个方向:订阅**必须**识别、同 provider 的按量调用**必须不**识别),并钉住 Kimi 既有行为不变。
|
|
132
|
+
- `scripts/verify-volcengine-live.mjs`:一次性真机核验脚本(只读接口、不打印密钥)。**已实测通过**:`GetCodingPlanUsage` 返回 `Status: "Running"` 与 session / weekly / monthly 三档真实窗口。
|
|
133
|
+
|
|
5
134
|
## v1.8.13(2026-09-25)
|
|
6
135
|
|
|
7
136
|
**新增:可以关掉插件在前端的显示(三个落点各自独立)**
|
package/README.en.md
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
| 🏷️ | **Official model-name alignment** | Billing recognises the official current name **`deepseek-flash`** (price-card note (1): "use the model name `deepseek-flash`"); older spellings such as `deepseek-v4.1-flash` normalize to the same rate, so an official rename can never silently drop usage into the fallback estimate |
|
|
37
37
|
| 📊 | **Visual dashboard** | A new "Cost Statistics" page in Settings: overview cards, cost bar charts (by peak period / by model), per-model request & token charts — **all with hover tooltips** |
|
|
38
38
|
| 🧭 | **Multi-machine aggregation (cloud sync)** | Point it at your own **self-hosted cloud service** (separate `dsh-cost-cloud` repo, zero runtime dependencies) to merge usage from several computers; the dashboard then offers a **This machine / This machine + cloud / Cloud only** switcher plus a **device × Agent matrix** (row totals = column totals = grand total). Only token counts, cost, timestamps and identifiers are uploaded, with optional session-id masking |
|
|
39
|
-
| 📈 | **Subscription quota** | Kimi Coding Plan and
|
|
39
|
+
| 📈 | **Subscription quota** | Kimi Coding Plan and **Volcengine Ark Coding Plan**: quota progress bars, reset countdowns and pay-as-you-go-equivalent cost for reference. Volcengine is queried through the Ark **control-plane OpenAPI** (HMAC-signed), requiring an AccessKeyID + SecretAccessKey pair |
|
|
40
40
|
| 💳 | **Balance lookup** | One-click DeepSeek account balance (total / topped-up / granted / status) |
|
|
41
41
|
| 🤖 | **Agent tools** | Ask in any chat: "how much have I spent today?" — the agent answers via `cost_stats` / `cost_prices` |
|
|
42
42
|
| 🔻 | **Status line** | A live line under the chat input: **session cost** (segmented pills: session / subscription plan / per-model), split by the models actually used in the session; multi-model collapses to top2 by default, click to expand. Subscription shows the plan name; no quota or call-count clutter |
|
|
@@ -245,6 +245,8 @@ POST /api/cost-tracker/sync-test Test the cloud connection
|
|
|
245
245
|
POST /api/cost-tracker/sync-config Save cloud sync config
|
|
246
246
|
POST /api/cost-tracker/cloud Read-only cloud aggregation (route/days/excludeSelf/devices/sources)
|
|
247
247
|
POST /api/cost-tracker/kimi-usage Kimi subscription quota
|
|
248
|
+
POST /api/cost-tracker/volcengine-usage Volcengine Ark Coding Plan quota (5-hour / weekly / monthly windows)
|
|
249
|
+
POST /api/cost-tracker/volcengine-config Save Volcengine AK/SK (reports only whether keys are configured, never the keys)
|
|
248
250
|
POST /api/cost-tracker/balance Account balance
|
|
249
251
|
POST /api/cost-tracker/prices Price table (versioned by pricing era)
|
|
250
252
|
POST /api/cost-tracker/recompute Re-price stored records by era (dry-run unless {"apply":true})
|
|
@@ -259,6 +261,29 @@ Example: `curl -X POST http://127.0.0.1:3080/api/cost-tracker/summary -d '{}'`
|
|
|
259
261
|
|
|
260
262
|
> Highlights only — the full version-by-version history lives in [`CHANGELOG.md`](./CHANGELOG.md) (Chinese).
|
|
261
263
|
|
|
264
|
+
### v1.8.15 (2026-09-26)
|
|
265
|
+
|
|
266
|
+
**Fixed: the Volcengine quota panel had no place to enter credentials, and an inference API key was being used as the AccessKeyID**
|
|
267
|
+
|
|
268
|
+
- **The panel now has its own credential inputs (the main fix).** Previously credentials could only be set through the plugin-config card or by hand-writing environment variables — the panel itself offered **nowhere to type**, so users saw only "credentials invalid" with no way forward. It now provides `AccessKeyID` / `SecretAccessKey` fields plus three actions: **Query** (verifies without persisting), **Save** (persists to disk) and **Clear**. The AccessKeyID is echoed back for confirmation; the SecretAccessKey is never echoed (when one is stored, the field hints "leave blank to keep"). A **"Volcengine quota"** button was added to the toolbar as an entry point — otherwise the panel stays hidden by default and users can never reach it.
|
|
269
|
+
- **Fixed: an inference API key was being used as the AccessKeyID — the real cause of the 401s.** When a provider's baseURL points at the Ark coding endpoint, its `apiKeyEnv` is an **inference** API key, while quota queries need an IAM `AccessKeyID + SecretAccessKey`. The old discovery chain fed that value into the AK candidates, producing a cross-source Frankenstein pair (inference key as AK + an unrelated SK from the credential file). Signing with it always returns 401, and a 401 is a *soft failure* here, so the plugin only reported "credentials invalid or no permission" — the root cause was undiagnosable. Now AK and SK must come from the **same source**; inference keys are recognised by name (`API_KEY`/`TOKEN` without `ACCESSKEY`/`SECRETKEY`) and excluded; and the message explicitly names the offending variable as an inference key.
|
|
270
|
+
- **Fixed: a `ReferenceError` (TDZ) turned soft failures into HTTP 500.** `keyEnv` was declared inside `try` but referenced in `catch`, so *every* failure path (401 / network error / changed shape) threw again during error handling and surfaced as a 500. It is now declared outside.
|
|
271
|
+
- **Fixed: `keyEnv` always showed "unknown"** — `resolveApiKey()` returns `{value, source}` only, and `env` is added by `resolveAnyEnv()`, so the panel never told you which environment variable to fix.
|
|
272
|
+
- **Safety: an empty string no longer clears a stored secret.** Because the secret is never echoed, its field is necessarily blank whenever the panel is reopened; treating that as "clear" would silently wipe a stored secret the moment someone edited only the AK. Only a **non-empty** secret overwrites, and clearing requires an explicit `clear:true`.
|
|
273
|
+
- Tests: `test/volcengine-host.test.js` grew to **48 assertions**, adding four groups: inference keys must not be treated as AKs (a regression test replicating the real provider config), an empty string must not overwrite a stored secret, editing only the AK still works, and only `clear` clears.
|
|
274
|
+
|
|
275
|
+
### v1.8.14 (2026-09-26)
|
|
276
|
+
|
|
277
|
+
**New: Volcengine Ark Coding Plan support (quota monitoring + equivalent cost)**
|
|
278
|
+
|
|
279
|
+
- **Quota panel**: a new "Subscription usage · Volcengine Ark Coding Plan" panel in Settings pulls the **5-hour / weekly / monthly** windows from the Ark **control-plane OpenAPI** (`open.volcengineapi.com`, `Action=GetCodingPlanUsage`, HMAC-SHA256 signed), showing used percentage, absolute amounts (derived from `Cap`) and reset countdowns. Actions fall back in order `GetCodingPlanUsage → GetAFPUsage → GetUsageDetails → GetPersonalPlan`, so Agent Plan accounts automatically read from AFP;
|
|
280
|
+
- **Equivalent cost**: calls covered by the plan now count toward "subscription equivalent cost" instead of being mislabelled "pay-as-you-go · estimated price";
|
|
281
|
+
- **Fixed a subscription-gate defect (important)**: the gate used to match on provider name only, applying subscription rates to *every* model of that provider. Volcengine Ark mixes plan and non-plan models under one provider, so metered calls were mislabelled as subscription and their amounts vanished from "real spend". It is now gated on **provider + model allowlist**, and distinguishes **dedicated subscription endpoints** (baseURL pointing at `/api/coding/v3` — the whole provider counts as subscription) from a **generic `volcengine`** provider (only allowlisted models; endpoint ids `ep-*` are always metered). Kimi's existing behaviour is byte-for-byte unchanged;
|
|
282
|
+
- **Fixed a credential-file defect (important)**: `.credentials.yaml` actually stores keys **indented** under the `refs:` section, while the parser only matched unindented top-level keys — so that fallback had silently never worked (masked whenever a host credential service was present). Indentation and `refs` scoping are now handled, the path follows `DSH_HOME`, and the hard-coded `~/.dsh` that broke redirected deployments is gone;
|
|
283
|
+
- **Credential discovery chain**: plugin-config card → DSH credential store → `.credentials.yaml` (`VOLC_ACCESSKEY` / `VOLC_SECRETKEY` plus several variants) → environment variables. **Keys never appear in any response**; `volcengine-config` only reports whether keys are configured;
|
|
284
|
+
- **Every failure is a neutral notice**: missing credentials, no subscription, insufficient permission (needs `ArkReadOnlyAccess` + `BillingCenterReadOnlyAccess`) and changed API shapes all degrade to a neutral notice without affecting recording, sync or other features. Users who only run DeepSeek or Kimi see a **completely unchanged** UI (the panel appears only when relevant);
|
|
285
|
+
- Adds `volcengine.js` (signing / parsing / querying, pure and unit-testable) plus two test files covering fixed signature vectors that match Volcengine's official demo byte-for-byte, four response shapes, **0.5% not being scaled to 50%**, zero key leakage, cache TTL and soft-failure paths. Verified against the live API (`GetCodingPlanUsage` returning `Status: Running` and three windows).
|
|
286
|
+
|
|
262
287
|
### v1.8.13 (2026-09-25)
|
|
263
288
|
|
|
264
289
|
**Added: the plugin's front-end surfaces can now be turned off (three independent switches)**
|
|
@@ -451,6 +476,23 @@ The plugin starts **silently by default**. Set the environment variable `DSH_COS
|
|
|
451
476
|
**Q: What does "equivalent cost" mean for subscription models (kimi-coding)?**
|
|
452
477
|
Subscriptions are not billed per token. The plugin estimates what those calls *would* cost at pay-as-you-go prices so you can judge whether your subscription pays off — **it is not a real charge**.
|
|
453
478
|
|
|
479
|
+
**Q: How do I connect a Volcengine Ark Coding Plan? Which credential does it need?**
|
|
480
|
+
Quota is read from the Ark **control-plane** OpenAPI (`open.volcengineapi.com`, HMAC-SHA256 signed), so it needs a **Volcengine access-key pair**:
|
|
481
|
+
|
|
482
|
+
1. Volcengine console → **IAM → Users → Keys**, create an AccessKeyID / SecretAccessKey pair;
|
|
483
|
+
2. Grant that sub-user **`ArkReadOnlyAccess`** and **`BillingCenterReadOnlyAccess`** (read-only is enough to query usage);
|
|
484
|
+
3. Let the plugin obtain the pair (any one of these, in priority order):
|
|
485
|
+
- fill in **Volcengine AccessKeyID / SecretAccessKey** under **Settings → Plugins → Plugin config → Cost Tracker** (the secret is never echoed back); or
|
|
486
|
+
- put them in the `refs:` section of `~/.dsh/.credentials.yaml` under `VOLC_ACCESSKEY` / `VOLC_SECRETKEY` (variants such as `VOLCENGINE_ACCESS_KEY_ID` and `ARK_ACCESS_KEY_ID` also work); or
|
|
487
|
+
- export them as environment variables with the same names.
|
|
488
|
+
|
|
489
|
+
> ⚠️ This is a **completely different credential** from the **ARK inference API key** (a UUID configured as the provider's `apiKey` / `apiKeyEnv`). The inference key cannot query quota and will produce 401/403.
|
|
490
|
+
|
|
491
|
+
The panel shows the 5-hour / weekly / monthly windows with used percentage and reset countdown. Coding Plan usage is expressed as a **percentage** (observed in the 0.05%–0.4% range), so two decimals are kept to avoid displaying "0%". If the account is actually on an Agent Plan, the plugin automatically falls back to the `GetAFPUsage` action. Missing credentials, no subscription and insufficient permissions are all **neutral notices** that never affect recording, sync or other features.
|
|
492
|
+
|
|
493
|
+
**Q: Why are some Volcengine Ark models billed as "subscription" and others as "pay-as-you-go"?**
|
|
494
|
+
Plan and non-plan models can share one provider. Any provider whose **baseURL points at `ark.cn-beijing.volces.com/api/coding/v3`** is a dedicated subscription endpoint, so all of its calls count as subscription. Under a generic `volcengine` provider, only plan models (Doubao, GLM, Kimi, DeepSeek, MiniMax families and the `ark-code-*` names) count as subscription, while **endpoint ids (like `ep-2026xxxx`) are always pay-as-you-go** — so metered calls are never mislabelled as subscription and silently dropped from your real spend.
|
|
495
|
+
|
|
454
496
|
**Q: The amounts don't exactly match my official bill?**
|
|
455
497
|
Costs are estimated locally from a built-in price table and may differ slightly from the official bill (price updates, tiered pricing, etc.). Treat official billing as authoritative; the balance shown is fetched live from the official API.
|
|
456
498
|
|
|
@@ -470,8 +512,9 @@ Either way: if only the UI (`client.js`) changed, a **hard browser refresh** (Cm
|
|
|
470
512
|
```
|
|
471
513
|
├── index.js Host half: usage capture, aggregation, HTTP API, agent tools
|
|
472
514
|
├── store.js Storage layer: 180-day detail retention + permanent daily rollups + atomic writes (with lock retries; pure logic, unit-testable)
|
|
473
|
-
├── pricing.js Pricing & tokens: price tables, peak/off-peak billing, vision model, peak-phase math (pure logic, unit-testable)
|
|
474
|
-
├── config.js Config layer: defaults & normalization for the peak-price notice
|
|
515
|
+
├── pricing.js Pricing & tokens: price tables, peak/off-peak billing, vision model, peak-phase math, subscription gate (pure logic, unit-testable)
|
|
516
|
+
├── config.js Config layer: defaults & normalization for the peak-price notice, cloud sync, UI toggles and Volcengine credentials (pure logic, unit-testable)
|
|
517
|
+
├── volcengine.js Volcengine Ark quota: HMAC-SHA256 signing, response parsing, credential normalization (pure logic, unit-testable)
|
|
475
518
|
├── sync.js Cloud sync engine: device identity, incremental watermark, idempotent batches, backoff
|
|
476
519
|
├── schema.js Host settings schema (the plugin-config card fields)
|
|
477
520
|
├── view.js Three-state view merge: normalizes This machine / + cloud / Cloud only (shared by browser and tests)
|
|
@@ -482,7 +525,7 @@ Either way: if only the UI (`client.js`) changed, a **hard browser refresh** (Cm
|
|
|
482
525
|
├── README.md Chinese documentation
|
|
483
526
|
├── README.en.md English documentation
|
|
484
527
|
├── CHANGELOG.md Changelog (Chinese)
|
|
485
|
-
├── test/ Unit tests (storage / pricing / config / recompute / render / cloud read; node test/*.test.js)
|
|
528
|
+
├── test/ Unit tests (storage / pricing / volcengine / config / recompute / render / cloud read; node test/*.test.js)
|
|
486
529
|
└── docs/ README screenshots and design notes
|
|
487
530
|
```
|
|
488
531
|
|
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
| 📊 | **可视化仪表盘** | 设置页新增「花费统计」:概览卡片、消费柱状图(按峰谷/按模型)、分模型的请求次数与 Tokens 图表,**全部支持鼠标悬停查看明细** |
|
|
38
38
|
| 🧭 | **多机汇总(云端同步)** | 可对接**自建云端服务**(独立仓库 `dsh-cost-cloud`,零运行时依赖):多台电脑的用量汇总到一处,看板顶部出现 **本机 / 本机+云端 / 仅云端** 三态开关,并支持**设备 × Agent 矩阵**(行合计 = 列合计 = 总计);上报内容仅 token 数、费用、时间戳与标识符,可选会话脱敏 |
|
|
39
39
|
| 🔥 | **用量热力图** | 设置页新增「Token 用量统计」:类 Codex 的 **26 周日用量方格热图**,按天着色(输入 / 缓存 / 输出 / 费用),悬停看当日明细、今天高亮描边,顶部显示全时段累计;**跟随三态视图**——「本机+云端 / 仅云端」下自动并入云端按天用量(卡片标题右侧标注当前口径) |
|
|
40
|
-
| 📈 | **订阅配额监控** | Kimi Coding Plan
|
|
40
|
+
| 📈 | **订阅配额监控** | Kimi Coding Plan、**火山方舟 Coding Plan** 等订阅套餐:配额进度条、重置倒计时、等效按量费用参考。火山方舟走管控面 OpenAPI(HMAC 签名),需 AccessKeyID + SecretAccessKey |
|
|
41
41
|
| 💳 | **余额查询** | 一键查询 DeepSeek 官方账户余额(总余额 / 充值 / 赠送 / 状态) |
|
|
42
42
|
| 🤖 | **Agent 工具** | 直接在对话里问:"我现在花了多少钱?"——Agent 会调用 `cost_stats` / `cost_prices` 等工具回答 |
|
|
43
43
|
| 🔻 | **状态栏** | 聊天输入框下方实时显示:**本会话花费**(胶囊分段:本会话 / 订阅套餐 / 分模型),按会话实际用到的模型与订阅拆分,**多模型默认折叠只显示 top2,点击展开全部明细**;订阅显示具体套餐名,不再展示配额与调用次数 |
|
|
@@ -246,6 +246,8 @@ POST /api/cost-tracker/sync-test 测试云端连接
|
|
|
246
246
|
POST /api/cost-tracker/sync-config 保存云端同步配置
|
|
247
247
|
POST /api/cost-tracker/cloud 云端只读聚合(route/days/excludeSelf/devices/sources)
|
|
248
248
|
POST /api/cost-tracker/kimi-usage Kimi 订阅配额
|
|
249
|
+
POST /api/cost-tracker/volcengine-usage 火山方舟 Coding Plan 配额(5 小时/周/月窗口)
|
|
250
|
+
POST /api/cost-tracker/volcengine-config 保存火山方舟 AK/SK(只回显「是否已配置」,不回显密钥)
|
|
249
251
|
POST /api/cost-tracker/balance 账户余额
|
|
250
252
|
POST /api/cost-tracker/prices 单价表(按计费时代分版)
|
|
251
253
|
POST /api/cost-tracker/recompute 按计费时代重算已入库记录(默认只试算,传 {"apply":true} 落盘)
|
|
@@ -260,6 +262,29 @@ POST /api/cost-tracker/export 导出 CSV
|
|
|
260
262
|
|
|
261
263
|
> 这里只列重要版本;逐版完整记录见 [`CHANGELOG.md`](./CHANGELOG.md)。
|
|
262
264
|
|
|
265
|
+
### v1.8.15(2026-09-26)
|
|
266
|
+
|
|
267
|
+
**修复:火山方舟配额面板「没有配置入口」与「拿推理 Key 当 AK」两个缺陷**
|
|
268
|
+
|
|
269
|
+
- **面板自带凭据输入框(主要修复)**:此前只能去「设置 → 插件 → 插件配置」卡片或手写环境变量,面板上**根本没有填写的地方** —— 用户看到的只有一句「凭据无效」,无从下手。现在面板内直接提供 `AccessKeyID` / `SecretAccessKey` 输入框与「查询」(先验证、不落盘)/「保存」(落盘持久化)/「清除凭据」三个动作;AK 明文回显便于确认,SK 从不回显(已保存时输入框提示「留空则不改」)。工具栏另加「火山方舟配额」按钮作为入口 —— 否则面板默认不显示,用户永远找不到。
|
|
270
|
+
- **修复:把「推理 API Key」当成 AccessKeyID 去签名(静默 401 的真正原因)**。配了 baseURL 指向方舟 coding 端点的 provider 时,其 `apiKeyEnv` 是**推理用** API Key,而配额查询要的是 IAM 的 AK/SK。早先的候选链把它也塞进 AK 候选,于是出现「推理 Key 当 AK + 凭据库里的 SK」这种**跨来源拼凑**的假凭据:签名必然 401,报错却只说「凭据无效或无权限」,根因完全查不出来。现在 AK 与 SK 必须**同源配对**,且按命名识别推理 Key(含 `API_KEY`/`TOKEN` 且不含 `ACCESSKEY`/`SECRETKEY`)并明确提示「这条是推理 Key,不是配额凭据」。
|
|
271
|
+
- **修复:失败路径抛 `ReferenceError`(TDZ)导致 500**。`keyEnv` 原先声明在 `try` 内却在 `catch` 里引用,任何一次查询失败(401 / 网络异常 / 结构变化)都会把「软失败」升级成 HTTP 500。现声明在 `try` 之外。
|
|
272
|
+
- **修复:`keyEnv` 永远显示「未知」**。`resolveApiKey()` 只返回 `{value, source}`,误取了 `rid.env`(那是 `resolveAnyEnv` 才加的字段),于是面板从不显示该去改哪个环境变量。现正确回传真实变量名。
|
|
273
|
+
- **防呆:空串不等于清空**。因为从不回显 SK,重开面板时 SK 输入框必然是空的;若把空串当作「清空」,用户只改一下 AK 就会把已存好的 SK 一起抹掉(静默丢凭据)。现在只有 **非空** SK 才覆盖,清空必须显式传 `clear:true`。
|
|
274
|
+
- 测试:`test/volcengine-host.test.js` 扩到 48 条断言,新增「推理 Key 不得被当作 AK(真实故障回归)」「空串不覆盖已存 SecretAccessKey」「只改 AK 后仍可用」「clear 才清空」四组。
|
|
275
|
+
|
|
276
|
+
### v1.8.14(2026-09-26)
|
|
277
|
+
|
|
278
|
+
**新增:火山方舟 Coding Plan 订阅支持(配额监控 + 等效费用)**
|
|
279
|
+
|
|
280
|
+
- **配额面板**:设置页新增「订阅套餐用量 · 火山方舟 Coding Plan」,经方舟**管控面 OpenAPI**(`open.volcengineapi.com`,`Action=GetCodingPlanUsage`,HMAC-SHA256 签名)拉取 **5 小时 / 周 / 月**三档窗口,显示已用百分比、绝对量(Cap 折算)与重置倒计时。Action 按 `GetCodingPlanUsage → GetAFPUsage → GetUsageDetails → GetPersonalPlan` 顺序兜底,Agent Plan 账号自动回落 AFP 取数;
|
|
281
|
+
- **等效费用**:火山套餐内的调用计入「订阅等效按量费用」,不再被误标为「按量计费 · 价格为估算」;
|
|
282
|
+
- **修掉订阅门卫缺陷(重要)**:原先只按 provider 名判定订阅,对该 provider 的**所有**模型一律套订阅价。火山方舟的套餐内 / 套餐外模型混在同一个 provider 下,这会把按量调用错记成订阅、使其金额从「真实花费」里消失。现改为「provider 命中 + 模型白名单」双重限定,并区分**专属订阅端点**(baseURL 指向 `/api/coding/v3`,整档计订阅)与**泛 `volcengine`**(仅白名单内模型计订阅,接入点 `ep-*` 一律按量)。Kimi 的既有行为逐字节不变;
|
|
283
|
+
- **修掉凭据文件读取缺陷(重要)**:`.credentials.yaml` 实际把键**缩进**存放在 `refs:` 段下,而原解析器只匹配行首无缩进的键 —— 这一路兜底一直静默失效(有宿主凭据服务时被掩盖)。现已支持缩进与 `refs` 段定位,并跟随 `DSH_HOME`;顺带修掉硬编码 `~/.dsh` 导致重定向部署下永远读不到的问题;
|
|
284
|
+
- **凭据发现链**:配置卡片 AK/SK → DSH 凭据库 → `.credentials.yaml`(`VOLC_ACCESSKEY` / `VOLC_SECRETKEY` 及多种变体名)→ 环境变量。**密钥永不出现在任何响应里**,`volcengine-config` 只回「是否已配置」;
|
|
285
|
+
- **失败一律中性提示**:无凭据、无订阅、权限不足(需 `ArkReadOnlyAccess` + `BillingCenterReadOnlyAccess`)、接口结构变化都只回中性提示,不影响记账 / 同步 / 其它功能;只跑 DeepSeek 或 Kimi 的用户界面**完全不变**(面板按需出现);
|
|
286
|
+
- 新增 `volcengine.js`(签名 / 解析 / 查询,纯函数可独立测试)与两个测试文件:签名与火山官方 demo 逐字节一致的固定向量、四种响应形态、**0.5% 不被放大成 50%**、密钥零外泄、缓存 TTL、失败路径软降级。真机核验通过(`GetCodingPlanUsage` 返回 `Status: Running` 与三档窗口)。
|
|
287
|
+
|
|
263
288
|
### v1.8.13(2026-09-25)
|
|
264
289
|
|
|
265
290
|
**新增:可以关掉插件在前端的显示(三个落点各自独立)**
|
|
@@ -454,6 +479,23 @@ POST /api/cost-tracker/export 导出 CSV
|
|
|
454
479
|
**Q:订阅套餐(kimi-coding)的"等效费用"是什么意思?**
|
|
455
480
|
订阅制不按量扣费。插件按内置单价估算出"如果这些调用走按量计费会花多少钱",仅供你评估订阅是否划算,**不是真实扣费**。
|
|
456
481
|
|
|
482
|
+
**Q:火山方舟 Coding Plan 的配额怎么接?需要哪种凭据?**
|
|
483
|
+
配额查询走的是方舟**管控面** OpenAPI(`open.volcengineapi.com`,HMAC-SHA256 签名),需要的是一对**火山引擎访问密钥**:
|
|
484
|
+
|
|
485
|
+
1. 火山引擎控制台 → **IAM → 用户 → 密钥**,创建 AccessKeyID / SecretAccessKey;
|
|
486
|
+
2. 给该子用户授予 **`ArkReadOnlyAccess`** 与 **`BillingCenterReadOnlyAccess`**(只读,足够查询用量);
|
|
487
|
+
3. 让插件拿到这对密钥(任选其一,按优先级):
|
|
488
|
+
- **设置 → 插件 → 插件配置 → 花费统计** 里填 `火山引擎 AccessKeyID` / `SecretAccessKey`(密钥不回显);或
|
|
489
|
+
- 写进 `~/.dsh/.credentials.yaml` 的 `refs:` 段,键名 `VOLC_ACCESSKEY` / `VOLC_SECRETKEY`(也兼容 `VOLCENGINE_ACCESS_KEY_ID`、`ARK_ACCESS_KEY_ID` 等写法);或
|
|
490
|
+
- 设为同名环境变量。
|
|
491
|
+
|
|
492
|
+
> ⚠️ 这与**推理用的 ARK API Key**(形如 UUID、配在 provider 的 `apiKey` / `apiKeyEnv`)是**两套完全不同的凭据**,不能混填。推理 Key 无法查询配额,会得到 401/403。
|
|
493
|
+
|
|
494
|
+
面板显示 5 小时 / 周 / 月三档窗口的已用百分比与重置倒计时。Coding Plan 的用量口径是**百分比**(实测长期在 0.05%–0.4% 量级),所以数值保留两位小数,避免显示成 0%。若账号实际是 Agent Plan,插件会自动回落到 `GetAFPUsage` 接口取数。没有订阅、没有凭据、权限不足都属于**中性提示**,不影响记账、同步与其它功能。
|
|
495
|
+
|
|
496
|
+
**Q:为什么火山方舟的模型有的算「订阅」、有的算「按量」?**
|
|
497
|
+
同一个 provider 下套餐内外模型可能混在一起:凡是 **baseURL 指向 `ark.cn-beijing.volces.com/api/coding/v3`** 的 provider(专属订阅入口),其全部调用都计为订阅;而泛 `volcengine` provider 下,只有套餐内模型(豆包系、GLM 系、Kimi 系、DeepSeek 系、MiniMax 系及各档 `ark-code-*`)算订阅,**接入点 id(形如 `ep-2026xxxx`)一律按量**。这样按量调用不会被误记成订阅而让真实花费缩水。
|
|
498
|
+
|
|
457
499
|
**Q:金额和官方账单对不上?**
|
|
458
500
|
插件在本地按内置单价表估算,可能与官方实际计费存在细微差异(如官方价格调整、阶梯定价)。精确金额请以官方账单为准。余额以「余额查询」实时拉取的官方数据为准。
|
|
459
501
|
|
|
@@ -473,8 +515,9 @@ POST /api/cost-tracker/export 导出 CSV
|
|
|
473
515
|
```
|
|
474
516
|
├── index.js Host 半端:用量采集、聚合、HTTP API、Agent 工具
|
|
475
517
|
├── store.js 存储层:明细保留 + 永久日汇总 + 原子落盘(含占用重试,纯逻辑可独立测试)
|
|
476
|
-
├── pricing.js 定价与 Token
|
|
477
|
-
├── config.js 配置层:峰谷计价提示 +
|
|
518
|
+
├── pricing.js 定价与 Token 层:单价表、峰谷计价、视觉模型、峰值相位、订阅门卫(纯逻辑,可独立测试)
|
|
519
|
+
├── config.js 配置层:峰谷计价提示 + 云端同步 + 界面显示 + 火山凭据的默认值与规范化(纯逻辑,可独立测试)
|
|
520
|
+
├── volcengine.js 火山方舟配额查询:HMAC-SHA256 签名、响应解析、凭据归一(纯逻辑,可独立测试)
|
|
478
521
|
├── sync.js 云端同步引擎:设备身份、增量水位、幂等批次、退避重试
|
|
479
522
|
├── schema.js 宿主设置空间的 schema(插件配置卡片字段)
|
|
480
523
|
├── view.js 三态视图合并:本机 / 本机+云端 / 仅云端的口径归一化(浏览器与测试共用)
|
|
@@ -485,7 +528,7 @@ POST /api/cost-tracker/export 导出 CSV
|
|
|
485
528
|
├── README.md 中文说明文档
|
|
486
529
|
├── README.en.md 英文说明文档
|
|
487
530
|
├── CHANGELOG.md 更新记录(中文)
|
|
488
|
-
├── test/ 单元测试(storage / pricing / config / recompute / 渲染 / 云端读取,node test/*.test.js)
|
|
531
|
+
├── test/ 单元测试(storage / pricing / volcengine / config / recompute / 渲染 / 云端读取,node test/*.test.js)
|
|
489
532
|
└── docs/ README 截图与设计文档
|
|
490
533
|
```
|
|
491
534
|
|
package/client.js
CHANGED
|
@@ -763,7 +763,7 @@ window.__ModuleLoader__.load({
|
|
|
763
763
|
const mergeDash = VIEW.mergeDash;
|
|
764
764
|
const mergeUsageHeat = VIEW.mergeUsageHeat || vMergeUsageHeat;
|
|
765
765
|
|
|
766
|
-
function filterRow(days, setDays, onExport, onRefresh, msg, busy, peakWindows, viewCtl) {
|
|
766
|
+
function filterRow(days, setDays, onExport, onRefresh, msg, busy, peakWindows, viewCtl, onOpenVolc) {
|
|
767
767
|
const views = viewCtl && viewCtl.available ? BOARD_VIEWS : [BOARD_VIEWS[0]];
|
|
768
768
|
return e("div", { className: "cost-row" },
|
|
769
769
|
e("select", { className: "cost-select", value: String(days), onChange: ev => setDays(parseInt(ev.target.value, 10)) },
|
|
@@ -781,6 +781,10 @@ window.__ModuleLoader__.load({
|
|
|
781
781
|
? e("select", { className: "cost-select", value: viewCtl.dimension, onChange: ev => viewCtl.setDimension(ev.target.value), title: "维度:查看合计,或按机器 / Agent / 模型 / 项目拆分" },
|
|
782
782
|
BOARD_DIMS.map(d => e("option", { key: d.id, value: d.id }, d.label)))
|
|
783
783
|
: null,
|
|
784
|
+
// 火山方舟配额面板的入口:没配过凭据时面板默认不显示,没这个按钮用户就找不到入口
|
|
785
|
+
onOpenVolc
|
|
786
|
+
? e("button", { className: "cost-btn", title: "配置火山方舟 AccessKeyID / SecretAccessKey 并查看 Coding Plan 配额", onClick: onOpenVolc }, "火山方舟配额")
|
|
787
|
+
: null,
|
|
784
788
|
e("button", { className: "cost-btn", onClick: onExport, disabled: busy }, "导出 CSV"),
|
|
785
789
|
e("button", { className: "cost-btn", onClick: onRefresh, disabled: busy }, busy ? "刷新中…" : "刷新"),
|
|
786
790
|
msg ? e("span", { className: "cost-hint" }, msg) : null,
|
|
@@ -913,6 +917,92 @@ window.__ModuleLoader__.load({
|
|
|
913
917
|
e("div", { className: "cost-hint", style: { marginTop: "10px" } }, "订阅用量统计:" + stats + "(订阅已覆盖,等效费用仅供参考)"));
|
|
914
918
|
}
|
|
915
919
|
|
|
920
|
+
// 火山方舟 Coding Plan 配额面板。
|
|
921
|
+
// 与 Kimi 面板的关键差别:管控面**主口径是百分比**(Level + Percent + Cap),
|
|
922
|
+
// 实测 Percent 常落在 0.05–0.4 这种小数区间,且没有各模型的 used/limit 绝对值。
|
|
923
|
+
// 所以不能直接套 progressBar 的「整数 / 总数」文案,这里用同一套
|
|
924
|
+
// cost-bar-track / cost-bar-fill 样式自己画百分比条,视觉保持一致。
|
|
925
|
+
function pctBar(label, percent, resetsAt, now, used, quota) {
|
|
926
|
+
const pct = Math.max(0, Math.min(100, Number(percent) || 0));
|
|
927
|
+
const color = pct >= 90 ? RED : pct >= 70 ? AMBER : BLUE;
|
|
928
|
+
// 百分比按实际精度展示(0.05% 也要看得见,不能四舍五入成 0%)
|
|
929
|
+
const pctText = pct > 0 && pct < 1 ? pct.toFixed(2).replace(/0+$/, "").replace(/\.$/, "") : String(Math.round(pct * 100) / 100);
|
|
930
|
+
// 有 Cap 时补一句绝对量:百分比太小的时候更直观
|
|
931
|
+
const absText = (typeof used === "number" && typeof quota === "number" && quota > 0)
|
|
932
|
+
? (" · " + fmtInt(used) + " / " + fmtInt(quota)) : "";
|
|
933
|
+
return e("div", { style: { marginTop: "10px" } },
|
|
934
|
+
e("div", { className: "cost-row" },
|
|
935
|
+
e("span", { className: "cost-hint" }, label),
|
|
936
|
+
e("span", { className: "cost-spacer" }),
|
|
937
|
+
e("span", { style: { fontVariantNumeric: "tabular-nums" } },
|
|
938
|
+
"已用 " + pctText + "% · 剩余 " + (Math.round((100 - pct) * 100) / 100) + "%" + absText)),
|
|
939
|
+
e("div", { className: "cost-bar-track" },
|
|
940
|
+
e("div", { className: "cost-bar-fill", style: { width: Math.max(pct, pct > 0 ? 1 : 0) + "%", background: color } })),
|
|
941
|
+
resetsAt ? e("div", { className: "cost-hint", style: { marginTop: "4px" } }, countdown(resetsAt, now)) : null);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// 火山方舟凭据输入区(面板自带,不必去翻插件配置卡片或手写环境变量)。
|
|
945
|
+
// AK 明文回显(控制台里本就可见);SK 从不回显,已存过时只提示「已保存」。
|
|
946
|
+
function volcCredForm(cred, hasSecret, onQuery, onSave, onClear) {
|
|
947
|
+
const busy = cred.busy;
|
|
948
|
+
return e("div", { style: { marginTop: "10px" } },
|
|
949
|
+
e("div", { className: "cost-row", style: { gap: "6px", flexWrap: "wrap" } },
|
|
950
|
+
e("input", {
|
|
951
|
+
className: "cost-input", placeholder: "火山引擎 AccessKeyID",
|
|
952
|
+
value: cred.id, spellCheck: false, autoComplete: "off",
|
|
953
|
+
onChange: ev => cred.setId(ev.target.value),
|
|
954
|
+
}),
|
|
955
|
+
e("input", {
|
|
956
|
+
className: "cost-input", type: "password", spellCheck: false, autoComplete: "new-password",
|
|
957
|
+
placeholder: hasSecret ? "SecretAccessKey(已保存,留空则不改)" : "火山引擎 SecretAccessKey",
|
|
958
|
+
value: cred.secret,
|
|
959
|
+
onChange: ev => cred.setSecret(ev.target.value),
|
|
960
|
+
}),
|
|
961
|
+
e("button", { className: "cost-btn", disabled: busy, onClick: onQuery }, busy ? "查询中…" : "查询"),
|
|
962
|
+
e("button", { className: "cost-btn", disabled: busy, onClick: onSave }, "保存"),
|
|
963
|
+
hasSecret || cred.id ? e("button", { className: "cost-btn", disabled: busy, onClick: onClear }, "清除凭据") : null),
|
|
964
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
965
|
+
"配额查询走方舟**管控面** OpenAPI,需要 IAM 的 AccessKeyID / SecretAccessKey"
|
|
966
|
+
+ "(子用户授予 ArkReadOnlyAccess + BillingCenterReadOnlyAccess);"
|
|
967
|
+
+ "它与推理用的 ARK API Key 是**两套不同凭据**。保存后写入本机插件配置,重启不丢。"));
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
function volcenginePanel(volc, dash, now, onForce, credForm) {
|
|
971
|
+
const ok = volc && volc.ok;
|
|
972
|
+
let body;
|
|
973
|
+
if (!volc) {
|
|
974
|
+
body = e("div", { className: "cost-hint", style: { marginTop: "8px" } }, "配额查询中…");
|
|
975
|
+
} else if (!volc.ok) {
|
|
976
|
+
body = e("div", { style: { marginTop: "8px" } },
|
|
977
|
+
e("div", { className: "cost-err" }, "配额查询不可用:" + (volc.error || "未知错误")),
|
|
978
|
+
volc.keyEnv && volc.keySource !== "none"
|
|
979
|
+
? e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
980
|
+
"本次尝试的凭据来源:" + volc.keyEnv + "(" + volc.keySource + ")。")
|
|
981
|
+
: null);
|
|
982
|
+
} else {
|
|
983
|
+
const list = volc.windowList || [];
|
|
984
|
+
if (list.length === 0) {
|
|
985
|
+
body = e("div", { className: "cost-hint", style: { marginTop: "8px" } }, "接口未返回任何用量窗口(可能账号没有生效中的 Coding Plan)。");
|
|
986
|
+
} else {
|
|
987
|
+
body = e("div", null, list.map(w => e("div", { key: w.name }, pctBar(w.label, w.percent, w.resetsAt, now, w.used, w.quota))));
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
const stats = dash
|
|
991
|
+
? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Tokens " + fmtInt(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
|
|
992
|
+
: "加载中…";
|
|
993
|
+
return e("div", { className: "cost-panel" },
|
|
994
|
+
e("div", { className: "cost-row" },
|
|
995
|
+
e("span", { className: "cost-panel-title" }, "订阅套餐用量 · 火山方舟 Coding Plan"),
|
|
996
|
+
ok && volc.action ? e("span", { className: "cost-badge" }, volc.action) : null,
|
|
997
|
+
ok ? e("span", { className: "cost-badge" }, volc.keySource === "config" ? "已保存凭据" : volc.keySource === "manual" ? "临时凭据" : "环境变量") : null,
|
|
998
|
+
e("span", { className: "cost-spacer" }),
|
|
999
|
+
e("button", { className: "cost-btn", onClick: onForce }, "刷新配额")),
|
|
1000
|
+
body,
|
|
1001
|
+
credForm,
|
|
1002
|
+
e("div", { className: "cost-hint", style: { marginTop: "10px" } },
|
|
1003
|
+
"订阅用量统计:" + stats + "(订阅已覆盖,等效费用仅供参考)"));
|
|
1004
|
+
}
|
|
1005
|
+
|
|
916
1006
|
function kv(k, v) {
|
|
917
1007
|
return e("span", { style: { marginRight: "18px" } },
|
|
918
1008
|
e("span", { className: "cost-hint" }, k + ":"),
|
|
@@ -1669,6 +1759,12 @@ window.__ModuleLoader__.load({
|
|
|
1669
1759
|
const [dash, setDash] = useState(null);
|
|
1670
1760
|
const [dashErr, setDashErr] = useState("");
|
|
1671
1761
|
const [kimi, setKimi] = useState(null);
|
|
1762
|
+
const [volc, setVolc] = useState(null);
|
|
1763
|
+
// 火山方舟凭据输入(面板自带):AK 回显、SK 不回显、busy 只管自己这块
|
|
1764
|
+
const [volcId, setVolcId] = useState("");
|
|
1765
|
+
const [volcSecret, setVolcSecret] = useState("");
|
|
1766
|
+
const [volcHasSecret, setVolcHasSecret] = useState(false);
|
|
1767
|
+
const [volcBusy, setVolcBusy] = useState(false);
|
|
1672
1768
|
const [balance, setBalance] = useState(null);
|
|
1673
1769
|
const [tab, setTab] = useState("period");
|
|
1674
1770
|
const [scheme, setSchemeState] = useState(() => {
|
|
@@ -1707,6 +1803,8 @@ window.__ModuleLoader__.load({
|
|
|
1707
1803
|
try { localStorage.setItem("dsh-cost-tracker-dim", d) } catch (e) {}
|
|
1708
1804
|
}
|
|
1709
1805
|
const viewInitRef = useRef(false);
|
|
1806
|
+
// 凭据一次回填即可,之后以输入框为准(不然用户刚改完就被 sync 轮询覆盖回去)
|
|
1807
|
+
const volcCredInitRef = useRef(false);
|
|
1710
1808
|
|
|
1711
1809
|
function loadDash(d) {
|
|
1712
1810
|
apiCall("dashboard", { days: d }).then(v => {
|
|
@@ -1718,6 +1816,12 @@ window.__ModuleLoader__.load({
|
|
|
1718
1816
|
apiCall("sync", {}).then(v => {
|
|
1719
1817
|
if (!v) return;
|
|
1720
1818
|
setSync(v);
|
|
1819
|
+
// 面板凭据回显:AK 明文(与云端看板同口径),SK 只回「是否已保存」
|
|
1820
|
+
if (typeof v.volcengineAccessKeyId === "string" && v.volcengineAccessKeyId) {
|
|
1821
|
+
volcCredInitRef.current = true;
|
|
1822
|
+
setVolcId(prev => prev || v.volcengineAccessKeyId);
|
|
1823
|
+
}
|
|
1824
|
+
setVolcHasSecret(!!v.volcengineHasSecret);
|
|
1721
1825
|
// 首次进入:以配置里的视图为准(三态开关的权威值在配置,便于多机一致)
|
|
1722
1826
|
if (!viewInitRef.current && (v.view === "local" || v.view === "local+cloud" || v.view === "cloud")) {
|
|
1723
1827
|
viewInitRef.current = true;
|
|
@@ -1762,6 +1866,41 @@ window.__ModuleLoader__.load({
|
|
|
1762
1866
|
function loadKimi(force) {
|
|
1763
1867
|
apiCall("kimi-usage", { force: !!force }).then(v => setKimi(v)).catch(() => {});
|
|
1764
1868
|
}
|
|
1869
|
+
function loadVolc(force) {
|
|
1870
|
+
apiCall("volcengine-usage", { force: !!force }).then(v => setVolc(v)).catch(() => {});
|
|
1871
|
+
}
|
|
1872
|
+
// 面板自带的凭据输入:AK 明文回显、SK 从不回显(只提示已保存)
|
|
1873
|
+
function volcSaveCred() {
|
|
1874
|
+
const patch = {};
|
|
1875
|
+
if (volcId.trim()) patch.volcengineAccessKeyId = volcId.trim();
|
|
1876
|
+
if (volcSecret.trim()) patch.volcengineSecretAccessKey = volcSecret.trim();
|
|
1877
|
+
if (!Object.keys(patch).length) { setMsg("请先填写 AccessKeyID 与 SecretAccessKey"); return; }
|
|
1878
|
+
apiCall("volcengine-config", patch).then(v => {
|
|
1879
|
+
setVolcHasSecret(!!(v && v.volcengineHasSecret) || !!volcSecret.trim());
|
|
1880
|
+
setVolcSecret("");
|
|
1881
|
+
setMsg(v && v.volcengineHasKeys ? "火山方舟凭据已保存" : "已保存(仍缺一半,请补全)");
|
|
1882
|
+
loadVolc(true);
|
|
1883
|
+
}).catch(err => setMsg("保存失败:" + String(err && err.message ? err.message : err)));
|
|
1884
|
+
}
|
|
1885
|
+
function volcClearCred() {
|
|
1886
|
+
apiCall("volcengine-config", { clear: true }).then(() => {
|
|
1887
|
+
setVolcId(""); setVolcSecret(""); setVolcHasSecret(false);
|
|
1888
|
+
setMsg("火山方舟凭据已清除");
|
|
1889
|
+
loadVolc(true);
|
|
1890
|
+
}).catch(() => {});
|
|
1891
|
+
}
|
|
1892
|
+
// 用输入框里的凭据直接查一次(不落盘,便于先验证再保存)
|
|
1893
|
+
function volcQueryWithCred() {
|
|
1894
|
+
const payload = { force: true };
|
|
1895
|
+
if (volcId.trim()) payload.accessKeyId = volcId.trim();
|
|
1896
|
+
if (volcSecret.trim()) payload.secretAccessKey = volcSecret.trim();
|
|
1897
|
+
setVolcBusy(true);
|
|
1898
|
+
apiCall("volcengine-usage", payload).then(v => {
|
|
1899
|
+
setVolc(v); setVolcBusy(false);
|
|
1900
|
+
if (v && v.ok) setVolcHasSecret(!!(volcHasSecret || volcSecret.trim()));
|
|
1901
|
+
else setMsg("查询失败:" + String((v && v.error) || "未知错误").slice(0, 200));
|
|
1902
|
+
}).catch(err => { setVolcBusy(false); setMsg("查询失败:" + String(err && err.message ? err.message : err)); });
|
|
1903
|
+
}
|
|
1765
1904
|
function loadUsage() {
|
|
1766
1905
|
apiCall("usage", {}).then(v => {
|
|
1767
1906
|
if (v && v.ok) { setUsage(v); setUsageErr(""); }
|
|
@@ -1786,12 +1925,13 @@ window.__ModuleLoader__.load({
|
|
|
1786
1925
|
else setUsageErr(v && v.error ? String(v.error) : "数据加载失败");
|
|
1787
1926
|
}).catch(err => setUsageErr(String(err && err.message ? err.message : err)));
|
|
1788
1927
|
apiCall("kimi-usage", { force: false }).then(v => setKimi(v)).catch(() => {});
|
|
1928
|
+
apiCall("volcengine-usage", { force: false }).then(v => setVolc(v)).catch(() => {});
|
|
1789
1929
|
loadCloudUsage(view);
|
|
1790
1930
|
apiCall("balance", {}).then(v => { setBalance(v); setBusy(false); }).catch(() => setBusy(false));
|
|
1791
1931
|
}
|
|
1792
1932
|
|
|
1793
1933
|
useEffect(() => { loadDash(days); }, [days]);
|
|
1794
|
-
useEffect(() => { loadKimi(false); loadBalance(""); loadUsage(); loadSync(); }, []);
|
|
1934
|
+
useEffect(() => { loadKimi(false); loadVolc(false); loadBalance(""); loadUsage(); loadSync(); }, []);
|
|
1795
1935
|
// 视图切换:local+cloud 需要额外拉「排除本机」的云端聚合、矩阵与按天用量明细
|
|
1796
1936
|
useEffect(() => { loadCloud(days, view); loadCloudMatrix(days); loadCloudUsage(view); }, [view, days]);
|
|
1797
1937
|
useEffect(() => {
|
|
@@ -1831,9 +1971,23 @@ window.__ModuleLoader__.load({
|
|
|
1831
1971
|
pending: sync ? sync.pending : 0,
|
|
1832
1972
|
};
|
|
1833
1973
|
|
|
1974
|
+
// 火山方舟面板的显示条件(按「用不用得上」):
|
|
1975
|
+
// · 已有窗口数据(volc 非空)—— 查过就会显示,含失败(失败也要能就地改凭据);
|
|
1976
|
+
// · 宿主判定存在火山订阅调用(summary.volcengineActive);
|
|
1977
|
+
// · 已经保存过凭据 —— 用户显然在用,必须一直可见,否则保存完就找不到入口了;
|
|
1978
|
+
// · 用户主动打开过(本地标记)—— 首次使用时的入口,避免「必须先调用过才看得到配置」。
|
|
1979
|
+
let volcOpened = false;
|
|
1980
|
+
try { volcOpened = localStorage.getItem("dsh-cost-tracker-volc-open") === "1" } catch (e) {}
|
|
1981
|
+
const showVolc = !!(volc || volcOpened || volcHasSecret || volcId
|
|
1982
|
+
|| (viewDash && viewDash.volcengineActive === true));
|
|
1983
|
+
function openVolc() {
|
|
1984
|
+
try { localStorage.setItem("dsh-cost-tracker-volc-open", "1") } catch (e) {}
|
|
1985
|
+
loadVolc(true);
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1834
1988
|
return e("div", { className: "cost-wrap" },
|
|
1835
1989
|
e("div", { className: "cost-h1" }, pluginIcon(18), "花费统计"),
|
|
1836
|
-
filterRow(days, setDays, onExport, onRefresh, msg, busy, dash ? dash.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)", viewCtl),
|
|
1990
|
+
filterRow(days, setDays, onExport, onRefresh, msg, busy, dash ? dash.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)", viewCtl, openVolc),
|
|
1837
1991
|
!cloudAvailable
|
|
1838
1992
|
? e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
1839
1993
|
"仅显示本机数据。在多台电脑/多个 Agent 之间汇总:到「设置 → 插件 → 插件配置 → 花费统计」填写云端服务地址与令牌。")
|
|
@@ -1864,6 +2018,10 @@ window.__ModuleLoader__.load({
|
|
|
1864
2018
|
: usageErr ? e("div", { className: "cost-err" }, "加载失败:" + usageErr)
|
|
1865
2019
|
: e("div", { className: "cost-hint" }, "加载中…"))),
|
|
1866
2020
|
subPanel(kimi, viewDash, now, () => loadKimi(true)),
|
|
2021
|
+
showVolc ? volcenginePanel(volc, viewDash, now, () => loadVolc(true), volcCredForm({
|
|
2022
|
+
id: volcId, secret: volcSecret, busy: volcBusy,
|
|
2023
|
+
setId: setVolcId, setSecret: setVolcSecret,
|
|
2024
|
+
}, volcHasSecret, volcQueryWithCred, volcSaveCred, volcClearCred)) : null,
|
|
1867
2025
|
balancePanel(balance, manualKey, setManualKey, k => loadBalance(k)),
|
|
1868
2026
|
viewDash ? modelSections(viewDash) : null,
|
|
1869
2027
|
viewDash ? recentPanel(viewDash) : null,
|