dsh-token-plugin 2.0.0 → 2.0.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/README.md +2 -3
- package/README.zh.md +2 -3
- package/lib/client.js +0 -240
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
>
|
|
1
|
+
> Published on npm as `dsh-token-plugin`.
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
@@ -36,7 +36,6 @@ dsh-usage-plugin is a **usage & cost tracker** plugin in the DeepSeek Harness ec
|
|
|
36
36
|
- **Persistence**: records are written live to `<session workspace>/dsh-usage/usage-records.json` and restored on restart (cap 100000 records).
|
|
37
37
|
- **UI adaptation**: panel typography scales with the app's display-size setting (em-relative fonts); wide tables scroll horizontally on desktop (`max-content` + `overflow-x`) and **fit the screen width on mobile (≤900px, no horizontal scrollbar)**; popup cards adapt to the viewport.
|
|
38
38
|
- **English UI (i18n)**: the panel follows the harness's own language setting (General Settings → Language) — switch it there and the plugin follows instantly, no separate toggle, no `localStorage` override. The bilingual dictionary covers the whole panel, the peak/off-peak billing-period hints, and the PNG report; host-level Conversation/Settings tab labels are re-read per render, so they follow the language switch live.
|
|
39
|
-
- **Per-message token popup**: when a turn finishes, the assistant message's footer action row shows a **"Turn tokens"** button; clicking opens a `Token Details` popup in two layers — **Conversation total** (the whole session's total tokens / total cost / run time / cache-hit rate) and **This turn** (this output's tokens, turn tokens, turn cost, turn duration, turn cache-hit rate, a cache-hit bar, and per-model cards showing each model's input·miss / cache hit / output (+ reasoning) plus its peak/off-peak cost split). Durations are shown as `Xm Ys`. Each usage record is tagged with the conversation (`sessionId`), so per-turn and per-conversation stats are computed independently.
|
|
40
39
|
- **Internal/tool calls grouped separately**: internal/placeholder calls (e.g. `dsh2shell-*` with model `fake`) are excluded from the model cost breakdown and collected in a collapsible **"Tool calls (internal)"** group below the breakdown, so only real model calls count in the cost tables.
|
|
41
40
|
- **Mobile adaptation**: tables fit the screen width on ≤900px (no horizontal scrollbar); wide tables collapse the middle columns; the popup and its stat cards / per-model cards adapt to the viewport.
|
|
42
41
|
|
|
@@ -56,7 +55,7 @@ npm pack
|
|
|
56
55
|
dsh plugin --profile web add ./dsh-token-plugin-2.0.0.tgz
|
|
57
56
|
```
|
|
58
57
|
|
|
59
|
-
Restart the DSH service after installation.
|
|
58
|
+
Restart the DSH service after installation. To install the published package, run `dsh plugin --profile web add dsh-token-plugin`. Desktop recommended listings are maintained separately.
|
|
60
59
|
|
|
61
60
|
## What's in the package
|
|
62
61
|
|
package/README.zh.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
>
|
|
1
|
+
> 已发布到 npm,包名为 `dsh-token-plugin`。
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
@@ -37,7 +37,6 @@ dsh-usage-plugin 是 DeepSeek Harness 生态的**用量与消耗统计插件**
|
|
|
37
37
|
- **持久化**:记录实时落盘到**固定专用数据目录**(如 `%LOCALAPPDATA%\dsh-usage-plugin\dsh-usage\usage-records.json`,详见下文「数据目录」),与当前工作区无关,重启自动恢复(上限 100000 条,尽量多存)。
|
|
38
38
|
- **界面适配**:面板字号跟随应用「显示大小」设置自动缩放(em 相对字号);桌面端宽表在容器内横向滑动(max-content + overflow-x),**移动端(≤900px)表格贴合屏宽、不再出现横向滑条**,弹窗与卡片随视口自适应。
|
|
39
39
|
- **英文界面(i18n)**:面板语言跟随宿主的「通用设置 → 语言」——在那里切换,插件即时跟随,不再自带切换按钮,也不再用 `localStorage` 覆盖系统语言。双语词典覆盖整个面板(含高峰 / 空闲时段说明、PNG 报告);外部「会话 / 设置」标签页名按渲染时读取,切换语言后实时更新。
|
|
40
|
-
- **消息底部 token 弹窗**:一轮输出完成后,助手消息底部操作行新增「本轮 token」按钮,点击弹出 `Token 明细`,分两层统计——**对话累计**(整场会话的 总 token / 总消耗 / 耗时 / 缓存命中率)与**本轮明细**(本次输出 / 本轮 token / 本轮消耗 / 本轮耗时 / 本轮缓存命中率、缓存命中长条图、按模型卡片:每个模型显示 输入·未命中 / 缓存命中 / 输出(+推理)与峰 / 谷成本分列)。时长按「X分Y秒」显示。宿主记录带会话标识(`sessionId`),本轮与整场对话统计各自独立。
|
|
41
40
|
- **内部/工具调用单独分组**:内部/占位调用(如 `dsh2shell-*`、模型 `fake`)不混入模型消耗明细,单独收在「消耗明细」下方可折叠的 **「工具调用(内部)」** 分组里(默认收起),成本表只统计真实模型调用。
|
|
42
41
|
- **移动端适配**:≤900px 时表格贴合屏宽(不再出现横向滑条)、宽表折叠中间列,弹窗统计卡与按模型卡片随视口自适应。
|
|
43
42
|
|
|
@@ -57,7 +56,7 @@ npm pack
|
|
|
57
56
|
dsh plugin --profile web add ./dsh-token-plugin-2.0.0.tgz
|
|
58
57
|
```
|
|
59
58
|
|
|
60
|
-
安装后重启 DSH
|
|
59
|
+
安装后重启 DSH 服务。也可通过 `dsh plugin --profile web add dsh-token-plugin` 安装已发布版本。桌面端推荐列表由其维护方单独管理。
|
|
61
60
|
|
|
62
61
|
## 这个包是什么
|
|
63
62
|
|
package/lib/client.js
CHANGED
|
@@ -6,20 +6,6 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
7
|
var React = require("react");
|
|
8
8
|
var el = React.createElement;
|
|
9
|
-
// react-dom 是平台种子模块:用于把弹窗 Portal 到 document.body,
|
|
10
|
-
// 避免对话树祖先的 transform/contain 破坏 position:fixed(弹窗不可见)。
|
|
11
|
-
var ReactDOM = null;
|
|
12
|
-
try { ReactDOM = require("react-dom"); } catch (e2) {}
|
|
13
|
-
// 隐藏弹窗卡片滚动条外观(仍可滚轮滚动),并在小屏下贴近视口
|
|
14
|
-
try {
|
|
15
|
-
if (typeof document !== "undefined" && document.head && !document.getElementById("dsh-usage-tok-style")) {
|
|
16
|
-
var __tokStyle = document.createElement("style");
|
|
17
|
-
__tokStyle.id = "dsh-usage-tok-style";
|
|
18
|
-
__tokStyle.textContent = "[data-dsh-usage-tok]{scrollbar-width:none;-ms-overflow-style:none}[data-dsh-usage-tok]::-webkit-scrollbar{width:0;height:0;display:none}";
|
|
19
|
-
document.head.appendChild(__tokStyle);
|
|
20
|
-
}
|
|
21
|
-
} catch (e3) {}
|
|
22
|
-
|
|
23
9
|
// ── i18n: zh keys → en dictionary (community addition) ──
|
|
24
10
|
var __T_EN = {"本期无消耗(所有用量为 0)":"No usage this turn (all zeros)","按模型":"By model","…及另外 ":"…plus "," 个模型(完整列表见「用量与消耗」页签)":" more models (full list in the Usage & Cost tab)","对话累计":"Conversation total","本轮明细":"This turn","本轮 token":"Turn tokens","本轮消耗":"Turn cost","本轮缓存命中率":"Turn hit rate","本轮耗时":"Turn duration","本轮无记录":"No records this turn","工具调用(内部)":"Tool calls (internal)"," 条内部调用":" internal calls","展开":"Expand","收起":"Collapse","详细记录请在「用量与消耗」页签查看":"Full details are in the Usage & Cost tab","获取中…":"Loading…","总 token":"Total tokens","Token 明细":"Token details","本次输出":"This output","总消耗":"Total cost","耗时":"Run time","缓存命中率":"Cache hit rate","关闭":"Close","V4.1 调价":"V4.1 price change"," 2026-09-10 12:00(北京时间)起 deepseek-flash 按新版峰谷价计费(deepseek-v4-pro 不变)":" from 2026-09-10 12:00 Beijing time deepseek-flash uses the new peak/off-peak prices (deepseek-v4-pro unchanged)","官方来源与价格依据":"Official sources & price references","价格由 DeepSeek 官方公布,本插件只做本地计算、不修改也不代理官方价格;点下面的链接可直接核对官方原文。":"Prices are published by DeepSeek; this plugin only computes locally and neither changes nor proxies official pricing. Use the links below to verify against the official source.","DeepSeek 官方价格页(模型与价格、峰谷时段定义)":"DeepSeek official pricing page (models, prices, peak/off-peak hours)","DeepSeek V4.1 Flash 发布公告":"DeepSeek V4.1 Flash announcement","DeepSeek 开放平台用量页(官方账单,用于对账)":"DeepSeek platform usage page (official billing, for reconciliation)","DeepSeek 官方 API 文档":"DeepSeek official API documentation","DeepSeek Harness 官方仓库":"DeepSeek Harness official repository","为什么显示这个价格?":"Why is this the price shown?","① 官方价格表按生效时间分段:2026-08-17 00:00 起为第一版峰谷价;2026-09-10 12:00(北京时间)起为 DeepSeek V4.1 Flash 调价后的新版(deepseek-flash 单价下调,deepseek-v4-pro 不变)。每次调用按其发生时刻对应的版本计费,历史金额不会因后续调价而改变。":"① The official price table is split by effective date: the first peak/off-peak version applies from 2026-08-17 00:00, and the post-V4.1-Flash version from 2026-09-10 12:00 Beijing time (deepseek-flash prices are lowered; deepseek-v4-pro is unchanged). Every call is billed with the version in force at its own time, so past amounts never change when prices are adjusted later.","② 模型档位按官方新命名归并:旧名 deepseek-v4-flash、deepseek-v4-flash-vision-exp 仍可调用(官方已路由到 DeepSeek-V4.1-Flash 并按 Flash 单价计费),计费时与 deepseek-flash 合并为同一档位。":"② Model tiers follow the new official naming: the legacy ids deepseek-v4-flash and deepseek-v4-flash-vision-exp stay callable (DeepSeek routes them to DeepSeek-V4.1-Flash and bills them at the Flash price) and are merged into the same deepseek-flash tier for billing.","③ 峰谷规则:工作日 9:00–12:00、14:00–18:00(北京时间)为高峰,其余时间(含周末全天)为空闲;空闲价 = 高峰价的一半。":"③ Peak/off-peak rule: weekdays 9:00–12:00 and 14:00–18:00 Beijing time are peak; all other times (including the whole weekend) are off-peak; the off-peak price is half the peak price.","④ 只有能与记录中 provider / model 可靠匹配的价格才参与计费,其余按 ¥0 统计(避免用相近模型的价格误算)。":"④ Only prices that reliably match the recorded provider / model are billed; everything else counts as ¥0, so a similar model name never causes a wrong estimate.","⑤ 本插件按官方公布价格在本地计算,结果仅供参考,最终以 DeepSeek 官方账单为准;产品价格可能变动,请以官方价格页为准。":"⑤ This plugin computes locally from published prices; the result is for reference only and the official DeepSeek bill prevails. Prices may change, so always check the official pricing page.","建议:若新模型(如 deepseek-flash)的消耗显示为 ¥0,通常是本插件版本过旧——请升级到 1.17.0 或更高版本。":"Tip: if a new model (such as deepseek-flash) shows ¥0 cost, this plugin is usually out of date — please upgrade to 1.17.0 or later.","DeepSeek V4.1 Flash 调价将于 ":"The DeepSeek V4.1 Flash price change takes effect on ","(北京时间)生效:deepseek-flash 改用新版峰谷价(空闲 缓存命中 0.02 / 输入 1 / 输出 4 元,高峰为其两倍),deepseek-v4-pro 价格不变。":" (Beijing time): deepseek-flash switches to the new peak/off-peak prices (off-peak cache hit 0.02 / input 1 / output 4 CNY; peak is twice that), while deepseek-v4-pro stays unchanged.","DeepSeek V4.1 Flash 调价已生效(自 ":"The DeepSeek V4.1 Flash price change is in effect (since "," 起):deepseek-flash 按新版峰谷价计费,deepseek-v4-pro 价格不变。":"): deepseek-flash is billed at the new peak/off-peak prices; deepseek-v4-pro is unchanged.","峰谷价表按生效时间分段:2026-08-17 00:00 起为第一版峰谷价;2026-09-10 12:00 起为 DeepSeek V4.1 Flash 调价后的新版(deepseek-flash 空闲价下调为 缓存命中 0.02 / 输入 1 / 输出 4 元,高峰为其两倍;deepseek-v4-pro 价格不变)。上方「峰谷价」展示的是当前生效的一版,历史调用始终按其发生时刻对应的版本计费。":"The peak/off-peak tables are split by effective date: the first version applies from 2026-08-17 00:00, and the post-V4.1-Flash version applies from 2026-09-10 12:00 (deepseek-flash off-peak prices are lowered to cache hit 0.02 / input 1 / output 4 CNY, with peak at twice that; deepseek-v4-pro is unchanged). The Peak/Off-peak tab shows the currently effective version; past calls are always billed with the version in force at their own time.","旧模型名 deepseek-v4-flash 与 deepseek-v4-flash-vision-exp 仍可调用(官方已将其路由到 DeepSeek-V4.1-Flash、按 Flash 单价计费),在本价格表中与 deepseek-flash 合并为同一档位。":"The legacy model ids deepseek-v4-flash and deepseek-v4-flash-vision-exp remain callable (they are routed to DeepSeek-V4.1-Flash and billed at the Flash price) and are merged into the deepseek-flash row in this table.","无 Token 数据":"No token data","当前 · ":"Current · ","工作日高峰时段":"Weekday peak hours","工作日空闲时段":"Weekday off-peak hours","周末高峰时段":"Weekend peak hours","周末空闲时段":"Weekend off-peak hours","周一至周五 9:00–12:00、14:00–18:00":"Mon–Fri 9:00–12:00 & 14:00–18:00","工作日其余时间":"Other weekday hours","周末(周六、周日)全天按空闲价计费":"All weekend (Sat & Sun) billed at the off-peak rate","2026-08-23 前仍按原规则分峰谷":"Before 2026-08-23 the old peak/valley split still applies","高峰 / 空闲时段说明":"Peak / off-peak hours","工作日高峰":"Weekday peak","空闲时段":"Off-peak hours"," 周一至周五 9:00–12:00、14:00–18:00":" Mon–Fri 9:00–12:00 & 14:00–18:00"," 工作日其余时间,以及周末(周六、周日)全天(自 2026-08-23 起;此前仍按原规则分峰谷)":" Weekday off-peak hours, plus all weekend (Sat & Sun) since 2026-08-23 (before that, the old peak/valley split still applies)","工作日高峰 9:00–12:00、14:00–18:00 · 周末全天空闲价":"Weekday peak 9:00–12:00 & 14:00–18:00 · all-weekend off-peak rate","\n调用 ":"\ncalls ",")\n输入·未命中 ":")\ninput·miss ","\n高峰消耗 ":"\npeak cost ","\n无记录":"\nno records","自动模式:按调用时间自动选择计费档位——新价格表生效前的调用按基础价(旧价格表),生效后的调用按峰谷价(工作日高峰时段 9:00–12:00、14:00–18:00 用高峰价,其余时间——含周末全天——用空闲价)。当前显示:":"Auto mode: the billing tier is chosen automatically by call time — calls made before the new price schedule took effect are billed at base (old) prices; calls after it use peak/valley prices (weekday peak hours 9:00–12:00 & 14:00–18:00 at the peak price, all other times — including all weekend — at the off-peak price). Currently shown:","单位:元 / 百万 tokens。工作日高峰时段(北京时间 9:00–12:00、14:00–18:00)用高峰价,其余时间用空闲价(空闲价 = 高峰价的一半);自 2026-08-23 起周末(周六、周日)全天按空闲价计费,新规则生效前仍按原规则。概览、用量日历、缓存命中列表中的消耗均已按高峰 / 空闲分列统计。":"Unit: CNY per million tokens. Weekday peak hours (Beijing time 9:00–12:00 & 14:00–18:00) use the peak price; all other times use the off-peak price (off-peak = half of peak). Since 2026-08-23, weekends (Sat & Sun) are billed at the off-peak rate all day; calls before the new rule still follow the old split. Costs in Overview, Usage Calendar and the Cache Hit List are split into peak / off-peak accordingly.","未知模型":"Unknown model","未知服务商":"Unknown provider","完成":"Done","工具调用":"Tool call","超长":"Overlong","错误":"Error","已中断":"Interrupted","超时":"Timeout","中断":"Interrupted"," · 中断 ":" · interrupted ","(未计费)":" (not billed)","本地统计与官方后台的差异":"Local stats vs official console","本面板统计的是插件在本地捕获的模型调用(按官方价格与峰谷时段计费)。与官方后台(platform.deepseek.com 用量页)相比,金额可能更低,常见原因:":"This panel shows calls captured locally by the plugin (billed at official prices with peak/off-peak rates). Compared with the official console (platform.deepseek.com usage page), the amount may be lower — common reasons:","① 中断/出错/超时的调用:官方仍按实际 token 计费,插件无法获取其用量,按 0 记录(明细中标「中断」);":"① Interrupted/failed/timed-out calls: the console still bills their actual tokens, but the plugin cannot obtain their usage, so they are recorded as 0 (marked \"Interrupted\" in details);","② 账号下其他 API Key(如其它应用/脚本)的调用不经过 DeepSeek Harness,官方统计包含它们,本插件不包含;":"② Calls from other API keys on your account (e.g. other apps/scripts) do not pass through DeepSeek Harness — the console includes them, this plugin does not;","③ 如需精确对账,可在官方用量页导出月度账单 CSV 与本插件对比。":"③ For exact reconciliation, export the monthly billing CSV from the official usage page and compare it with this plugin.","当前记录中有 ":"Current records include "," 次中断调用(未计费)——对应官方后台已计费的部分。":" interrupted call(s) (not billed) — corresponding to the part already billed by the official console.","范围内调用":"Calls in range","范围内消耗":"Cost in range","该范围内暂无记录。":"No records in this range.","自动(生效前基础价 · 生效后峰谷价)":"Auto (base price before effective date · peak/valley after)","基础价格":"Base price","峰谷价格":"Peak/valley price","自动":"Auto","canvas 2d 不可用":"canvas 2D unavailable","用量与消耗报告":"Usage & Cost Report","生成时间 ":"Generated ","(北京) · 共 ":" (Beijing) · total "," 条调用 · 缓存命中率 ":" calls · cache-hit rate "," · 高峰价消耗 ":" · peak-rate cost "," · 空闲价消耗 ":" · off-peak cost "," · 合计 ":" · total "," · 报告仅含最近 ":" · report limited to the latest "," 条":" records","调用次数":"Calls","输入 · 未命中":"Input · miss","输入 · 缓存命中":"Input · cache hit","输出":"Output","高峰消耗":"Peak cost","空闲消耗":"Off-peak cost","总消耗 (峰谷价)":"Total cost (peak/valley)","缓存命中列表(共 ":"Cache hit list ("," 条)":" records)","时间(北京)":"Time (Beijing)","模型":"Model","输入·未命中":"Input·miss","缓存命中":"Cache hit","缓存写入":"Cache write","推理":"Reasoning","命中率":"Hit rate","时段":"Period","结束":"End","消耗(峰谷)":"Cost (peak/valley)","峰":"Peak","谷":"Valley","消耗表(按模型 · 峰谷价 · 高峰/空闲分列)":"Cost table (by model · peak/valley prices)","调用":"Calls","总消耗":"Total cost","合计":"Total","消耗表(按 API 服务商 × 模型 · 峰谷价)":"Cost table (by API provider × model · peak/valley)","API 服务商 / 模型":"API provider / model"," 个模型)":" models)","总费用合计":"Total cost overall","计价按请求的 API 服务商分别应用已核验价格;DigitalOcean 美元价按 USD/CNY 汇率折算;无法可靠映射的第三方价格按 ¥0。":"Billing applies verified prices per requesting API provider; DigitalOcean USD prices are converted at the USD/CNY rate; third-party prices that cannot be mapped reliably are counted as ¥0."," 个服务商":" providers","今天":"Today","近7天":"Last 7 days","近30天":"Last 30 days","全部":"All","自定义区间:":"Custom range:","至":"to","清除筛选":"Clear filters","当前范围:共 ":"Current range: ","(全部记录)":"(all records)"," · 总消耗 ":" · total cost ","高峰 ":"Peak "," · 空闲 ":" · off-peak ","命中率 ":"hit rate ","高峰时段 9:00–12:00、14:00–18:00":"Peak hours 9:00–12:00 & 14:00–18:00","其余空闲时段":"other hours are off-peak","高峰 + 空闲 · ":"Peak + off-peak · ","消耗表(按模型)":"Cost table (by model)","API 服务商":"API provider","高峰/空闲":"Peak/Off-peak","消耗明细(按 API 服务商 × 模型)":"Cost breakdown (by API provider × model)","DeepSeek 官方请求按官方峰谷价;SiliconFlow 按自身人民币公开价;DigitalOcean 按美元公开价 × USD/CNY 汇率折算人民币;千问暂不计费;AMD GPU Cloud DeepSeek V4 Flash 免费按 ¥0。模型名与 API 服务商均以请求参数为准。":"DeepSeek official requests use official peak/valley prices; SiliconFlow uses its own public CNY prices; DigitalOcean uses public USD prices converted to CNY at the USD/CNY rate; Qwen is not billed yet; AMD GPU Cloud DeepSeek V4 Flash is free at ¥0. Model names and API providers follow the actual request parameters."," 次(高峰 ":" calls (peak "," / 空闲 ":" / off-peak "," · 缓存命中 ":" · cache hit "," · 输出 ":" · output "," · 推理 ":" · reasoning "," · 空闲消耗 ":" · off-peak cost ","‹ 上月":"‹ Prev month","下月 ›":"Next month ›","按消耗":"By cost","按调用数":"By calls","热力:":"Heatmap: ","低 → 高(":"low → high (","当日消耗":"Day cost","当日调用数":"Day calls","· 悬停查看详情,点击某天查看当日调用":"· hover for details, click a day for that day's calls","本月调用":"Calls this month","本月消耗":"Cost this month","本月暂无记录。":"No records this month.","日期":"Date","总消耗(自动)":"Total cost (auto)"," 调用明细":" call details"," 条 · ":" records · "," | 空闲 ":" | off-peak "," | 合计 ":" | total ","该日无记录。":"No records for this day.","消耗":"Cost","清除区间":"Clear range"," 条 · 输入·未命中 ":" records · input·miss "," · 缓存写入 ":" · cache write "," · 高峰消耗 ":" · peak cost ","该时间范围内没有记录。":"No records in this range.","‹ 上一页":"‹ Prev page","第 ":"Page "," 页 · 每页 ":" page · per page "," 条 · 共 ":" records · total ","下一页 ›":"Next page ›","新价格表生效时间未知":"New price schedule effective date unknown","新价格表(峰谷价)将于 ":"The new peak/valley price schedule takes effect ","(北京时间)生效,当前按旧价格表(基础价)计费":" (Beijing time); currently billing on the old base-price schedule","新价格表(峰谷价)已生效(自 ":"New peak/valley schedule in effect (since "," 起)":")","今日 $ / ¥ 汇率":"Today's $/¥ rate","暂不可用":"Temporarily unavailable","汇率日期 ":"Rate date ","等待获取":"Pending fetch","汇率状态":"Rate status","缓存汇率":"Cached rate","最新可用":"Latest available","获取失败":"Fetch failed","刷新汇率":"Refresh rate","美元计价的 DigitalOcean 消耗按该 USD/CNY 汇率换算成人民币;人民币定价不受汇率影响。":"USD-denominated DigitalOcean costs are converted to CNY at this rate; CNY pricing is unaffected by it.","DeepSeek 官方 API 价格表":"DeepSeek Official API Price Table","本表仅用于 DeepSeek 官方 Provider;第三方 Provider 按下方已核验的自身价格计费,无法可靠匹配价格的模型按 0 统计。价格按官方公布固定,不可编辑。":"This table applies only to the official DeepSeek provider; third-party providers bill at their own verified prices below, and models without a reliable price match are counted as 0. Prices are fixed as officially published and are not editable.","峰谷价":"Peak/valley","基础价":"Base","自动模式:按调用时间自动选择计费档位——新价格表生效前的调用按基础价(旧价格表),生效后的调用按峰谷价(高峰时段 9:00–12:00、14:00–18:00 用高峰价,其余空闲时段用空闲价)。当前显示:":"Auto mode: the billing tier is chosen automatically by call time — calls made before the new schedule took effect use base (old) prices, calls after it use peak/valley prices (peak hours 9:00–12:00 & 14:00–18:00 at peak price, other hours at off-peak). Currently shown:","基础价表(旧价格表,新价格生效前)":"Base price table (old schedule, before new prices take effect)","峰谷价表(新价格表)":"Peak/valley table (new schedule)","。价格按官方公布固定,不可编辑。":". Prices are fixed as officially published and are not editable.","缓存命中(输入)":"Cache hit (input)","空闲 · 缓存命中":"Off-peak · cache hit","空闲 · 输入":"Off-peak · input","空闲 · 输出":"Off-peak · output","高峰 · 缓存命中":"Peak · cache hit","高峰 · 输入":"Peak · input","高峰 · 输出":"Peak · output","单位:元 / 百万 tokens。高峰时段(北京时间 9:00–12:00、14:00–18:00)用高峰价,其余空闲时段用空闲价(空闲价 = 高峰价的一半)。概览、用量日历、缓存命中列表中的消耗均已按高峰 / 空闲分列统计。":"Unit: CNY per million tokens. Peak hours (Beijing 9:00–12:00 & 14:00–18:00) use peak prices; other hours use off-peak (= half of peak). Costs in Overview, Usage Calendar and Cache Hit List are split into peak / off-peak accordingly.","第三方平台价格与覆盖状态(2026-08-19 核验)":"Third-party platform prices & coverage (verified 2026-08-19)","只把能与记录中的 provider/model 可靠匹配的价格用于自动计费;美元价格先按 USD 计算,再乘 USD/CNY 汇率统一折算成人民币。":"Only prices that reliably match a record's provider/model are used for automatic billing; USD prices are computed in USD first, then converted to CNY at the USD/CNY rate.","模型 / 状态":"Model / status","输入":"Input","说明":"Notes","已用于自动计费":"Used for auto billing","缓存命中价按 2026-08-03 起生效公告":"Cache-hit price per the notice effective 2026-08-03","按输入价":"Billed at input price","公告未单列缓存命中价":"The notice lists no separate cache-hit price","自动按 USD/CNY 汇率换算人民币并计费":"Auto-converted to CNY at the USD/CNY rate and billed","Alibaba / 千问":"Alibaba / Qwen","暂不计费":"Not billed yet","调用与 token 正常统计;费用暂按 ¥0":"Calls and tokens tracked normally; cost counted as ¥0 for now","免费;费用固定按 ¥0":"Free; cost fixed at ¥0","DigitalOcean 使用美元官方价并按最新可用 USD/CNY 汇率折算人民币;千问暂不计费;AMD GPU Cloud 的 DeepSeek V4 Flash 免费按 ¥0。":"DigitalOcean bills at official USD prices converted via the latest available USD/CNY rate; Qwen is not billed yet; AMD GPU Cloud DeepSeek V4 Flash is free at ¥0.","概览":"Overview","用量日历":"Usage Calendar","缓存命中列表":"Cache Hit List","价格表":"Price Table","已导出:":"Exported: ","导出失败:":"Export failed: ","未知错误":"unknown error","导出中…":"Exporting…","生成图片中…":"Rendering image…","画布不可用":"Canvas unavailable","生成图片失败:":"Image rendering failed: ","打开目录选择…":"Open directory picker…","导出目标:":"Export destination:","选择目录失败:":"Failed to pick directory: ","打开文件夹失败:":"Failed to open folder: ","读取文件…":"Reading file…","导入成功:新增 ":"Import OK: added "," 条,跳过重复 ":", skipped duplicates "," 条,忽略无效 ":", ignored invalid "," 条,现有共 ":", total now ","导入失败:":"Import failed: ","读取文件失败":"Failed to read file","用量与消耗":"Usage & Cost","记录插件激活后的每一次模型调用":"Logs every model call since the plugin was activated","当前 · 高峰时段":"Current · peak hours","当前 · 空闲时段":"Current · off-peak hours","新价格已生效":"New prices in effect","新价格未生效":"New prices not yet in effect","刷新":"Refresh","清空":"Clear","计价说明:DeepSeek 官方与 SiliconFlow 按人民币价格;DigitalOcean 按美元官方价 × USD/CNY 汇率折算人民币;千问暂不计费;AMD GPU Cloud DeepSeek V4 Flash 免费按 ¥0。":"Billing notes: DeepSeek official and SiliconFlow bill in CNY; DigitalOcean bills at official USD prices × USD/CNY rate; Qwen is not billed yet; AMD GPU Cloud DeepSeek V4 Flash is free at ¥0.","导出 CSV":"Export CSV","导出 JSON":"Export JSON","导出图片 (PNG)":"Export image (PNG)","打开目录":"Open folder","导出目标目录(留空 = 默认数据目录)":"Export target directory (empty = default data dir)","选择目录…":"Choose directory…","已恢复默认数据目录":"Restored default data directory","重置":"Reset","选择文件导入":"Choose a file to import","数据持久化:":"Data persistence:","(每次调用实时落盘,插件重启后自动恢复,最多保留 100000 条)":"(every call is written to disk live, restored automatically after restart, up to 100000 records)","持久化未启用:":"Persistence disabled:","未知原因":"unknown reason","DEEPSEEK_API_KEY(推理 Key)":"DEEPSEEK_API_KEY (inference key)","模型设置中 Provider ID 或显示名为 siliconflow 的提供商 API Key":"API key of the provider whose Provider ID or display name is siliconflow in model settings","打开 SiliconFlow API 密钥":"Open SiliconFlow API keys","账户级 dop_v1_ Personal Access Token;Read Only(api:read)或 billing:read":"Account-level dop_v1_ Personal Access Token; Read Only (api:read) or billing:read","创建 DigitalOcean Account API Token":"Create a DigitalOcean account API token","暂无公开余额 API,仅支持控制台查看":"No public balance API yet — console only","打开 AMD Developer Cloud":"Open AMD Developer Cloud","查询失败":"Query failed","无法读取凭据状态":"Cannot read credential status","请输入以 dop_v1_ 开头的 DigitalOcean 账户 PAT。":"Enter a DigitalOcean account PAT starting with dop_v1_.","保存失败":"Save failed","使用凭据 ":"Using credential ","来源 ":"source ","模型提供商 ":"Model provider ","端点 ":"Endpoint "," · 账户余额":" · account balance","USD · 预付款/信用余额":"USD · prepaid/credit balance","USD · 待结算金额":"USD · pending amount","USD · 当前无余额":"USD · no balance"," · 账户可用":" · account available"," · 账户不可用":" · account unavailable"," · 查询成功":" · query succeeded","剩余余额查询":"Remaining balance query","查询 DeepSeek、SiliconFlow 与 DigitalOcean 账户余额":"Query DeepSeek, SiliconFlow and DigitalOcean account balances","打开控制台":"Open console","查询中…":"Querying…","查询账单":"Query billing","查询余额":"Query balance","所需凭据:":"Required credentials:","仅支持控制台查看":"Console only","插件不会尝试未经公开文档确认的端点,也不会把 AMD 推理 Key 当作账单凭据。":"The plugin never probes endpoints unconfirmed by public docs, and never uses AMD inference keys as billing credentials.","请确认凭据类型正确、权限包含余额/账单读取,且网络可访问服务商官方 API。":"Please verify the credential type is correct, its permissions include balance/billing read, and the provider's official API is reachable from this network.","打开服务商凭据页面":"Open provider credentials page","正在查询余额…":"Querying balance…","可用":"Available","不可用":"Unavailable","账单更新时间":"Billing updated","查询时间":"Queried at","北京时间":"Beijing time","请创建账户级 Personal Access Token。可选 Read Only(api:read,包含 billing:read),或自定义 billing:read;不要使用 Gradient AI 推理 Key。":"Please create an account-level Personal Access Token. Choose Read Only (api:read incl. billing:read) or a custom scope with billing:read; do not use a Gradient AI inference key.","正在检查已保存的 Token…":"Checking saved token…","已保存:":"Saved: ","(来源:":" (source: ","无法读取 Token 状态:":"Cannot read token status: ","尚未保存 DIGITALOCEAN_TOKEN。":"DIGITALOCEAN_TOKEN is not saved yet.","输入新的 dop_v1_ Token 可替换(当前值已隐藏)":"Enter a new dop_v1_ token to replace it (current value hidden)","保存中…":"Saving…","保存并查询":"Save & query","当前 Token 来自只读环境变量;请在原来源中修改,页面不会覆盖它。":"The current token comes from a read-only environment variable; edit it at its source — this panel will not overwrite it.","Token 已安全保存;页面和 API 响应不会回传明文。":"Token stored securely; neither the page nor API responses echo it back.","SiliconFlow 查询说明":"SiliconFlow query notes","公开 API 已成功返回 ¥0.00。SiliconFlow 的 /v1/user/info 当前不返回代金券或历史用量;控制台可用总额可能非零。这里忠实展示 API 原始余额字段,不把它等同于控制台完整额度。":"The public API returned ¥0.00 successfully. SiliconFlow's /v1/user/info currently returns no vouchers or historical usage; the console total may still be non-zero. The raw balance field from the API is shown faithfully here and should not be read as the full console credit.","余额卡片展示 SiliconFlow /v1/user/info 公开 API 返回的原始余额字段。":"The balance card shows the raw balance field returned by SiliconFlow's public /v1/user/info API.","返回字段":"Returned fields","凭据读取规则":"Credential lookup rules","插件只检查“设置 → 模型”中 Provider ID 或显示名为 siliconflow 的提供商,并读取其 apiKeyEnv 对应的已保存 API Key。":"The plugin only checks providers in Settings → Models whose Provider ID or display name is siliconflow, and reads the saved API key referenced by their apiKeyEnv.","如果未找到提供商、未填写 API Key 或凭据引用失效,插件会停止查询并说明需要修复的配置;不会回退到其他服务商的 Key。":"If no such provider exists, the key is empty, or the credential reference is broken, the plugin stops querying and explains what needs fixing; it never falls back to another provider's key.","DigitalOcean 查询的是主账户 Billing API;DigitalOcean AI 推理 Key 与 AMD GPU Cloud 推理 Key 均不能直接查询账单。":"DigitalOcean queries the main account Billing API; DigitalOcean AI inference keys and AMD GPU Cloud inference keys cannot query billing directly.","\n调用 ":"\ncalls ",")\n输入·未命中 ":")\ninput·miss ","\n高峰消耗 ":"\npeak cost ","\n无记录":"\nno records","查询 DeepSeek、SiliconFlow、DigitalOcean 与百炼 Token Plan":"Query DeepSeek, SiliconFlow, DigitalOcean & Bailian Token Plan balances","百炼 Token Plan · 1 周配额":"Bailian Token Plan · 1-week quota","百炼 Token Plan 配额用量":"Bailian Token Plan quota usage","百炼 Token Plan":"Bailian Token Plan","本周配额":"This week's quota","开始":"Start","结束":"End","已用 ":"Used ","百炼 Token Plan 查询说明":"Bailian Token Plan query notes","本查询复用百炼 CLI(bl)的“控制台登录”OAuth token,不需要阿里云 AccessKey,权限面很小。":"This query reuses the console-login OAuth token from the Bailian CLI (bl); no Alibaba Cloud AccessKey is needed and the permission scope is minimal.","如尚未登录,请先在终端执行:bl auth login --console,然后回到本页点“查询余额”。":"If you haven't logged in yet, run: bl auth login --console, then come back and click 'Query balance'.","打开百炼 CLI 登录说明":"Open Bailian CLI login docs","百炼控制台 OAuth 登录(~/.bailian/config.json 的 access_token,用 bl auth login --console 生成)":"Bailian console OAuth login (access_token in ~/.bailian/config.json, created by bl auth login --console)","数据来自阿里云百炼控制台内部门户网关(zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage),展示的是 1 周配额已用进度与周期。":"Data from Alibaba Cloud Bailian console portal gateway (zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage), showing 1-week quota usage progress and period.","帮助与说明":"Help & info","本月已消耗":"Spent this month","剩余 ":"left ","超支 ":"over budget by ","月度预算":"Monthly budget","当前预算:":"Current budget: ","设置每月消费上限,概览页会显示进度与超支预警。":"Set a monthly spending cap; the overview shows progress and an over-budget warning.",";概览页会按当月消耗显示进度与超支预警。":"; the overview shows monthly progress and over-budget warnings.","预算金额(元)":"Budget amount (CNY)","保存预算":"Save budget","清除预算":"Clear budget","请输入预算金额":"Please enter a budget amount","预算金额必须是非负数字":"Budget must be a non-negative number","消耗趋势(近 30 天)":"Cost trend (last 30 days)","模型消耗占比":"Model cost share","会话消耗排行":"Top conversations by cost","按模型 / 服务商 / 会话搜索…":"Search by model / provider / session…","没有符合条件的记录。":"No records match the current filters.","暂无数据":"No data","清除":"Clear","总消耗 ":"Total cost ","调用 ":"calls ","空闲 ":"off-peak "," 次":" calls","较上月":"vs last month","日均 ":"daily avg ","峰值日 ":"peak day ","天":"d","收起帮助":"Collapse help","模型消耗明细":"Model cost breakdown","按模型分组":"Grouped by model"," 个模型":" models","服务商×模型明细":"Provider × model breakdown","展开每个服务商下的模型分布":"Each provider's model breakdown","每个模型的调用次数、token 用量(输入·未命中 / 缓存命中 / 输出 / 推理)与高峰/空闲分列的消耗。合计行高亮汇总所有模型的总量。":"Per-model call count, token usage (input miss / cache hit / output / reasoning) and peak/off-peak costs. The highlighted total row sums everything above.","先按服务商(DeepSeek 官方 / SiliconFlow / DigitalOcean …)分组,组内按消耗降序列出该服务商下的每个模型及对应消耗。":"Grouped by provider (DeepSeek official / SiliconFlow / DigitalOcean …); within each group, models are listed by cost.","统计口径:web_search 搜索后端未纳入精确统计":"Scope: web_search backend calls are not precisely metered","DeepSeek 搜索后端调用由 Harness 用原生请求直连官方接口,响应用量未持久化到会话日志,插件无法取到实际 token。此处只记录次数,并按请求体给出输入侧下限估算:共 ":"DeepSeek search-backend calls go straight to the official endpoint via a native request inside the Harness, and the response usage is never persisted to the session log, so the plugin cannot obtain the real token counts. Only the call count is recorded here, together with a lower-bound estimate of the input side derived from the request body: "," 次,估算消耗 ≥ ":" calls, estimated cost ≥ ","。搜索在服务端注入检索结果并可能多轮生成,输入与输出都会高于此值,官方账单必然更高。":". Search results are injected server-side and generation may run multiple rounds, so both input and output exceed this bound — the official bill will always be higher.","该部分为估算下限,请以 DeepSeek 官方后台账单为准。":"This part is a lower-bound estimate; always refer to your DeepSeek console bill.","历史价格提示":"Historical pricing notice","有 ":"There are "," 条记录没有冻结单价(旧版本写入或手工导入),它们的费用按当前价格表计算,改动价格表后会跟着变化;新记录已冻结写入时生效的单价,不受后续改价影响。":" record(s) have no frozen unit price (written by an older version or imported by hand); their cost is computed with the current price table and will change when you edit prices. New records freeze the prices in effect at write time and are unaffected by later edits.","历史价格与重算":"Historical pricing & repricing"," 条记录没有冻结单价(旧版本写入或手工导入),其费用按当前价格表计算,改动价格后会跟着变化。":" record(s) have no frozen unit price (written by an older version or imported by hand); their cost uses the current price table and follows later price edits.","所有记录都已冻结写入时生效的单价:改动价格表只影响之后产生的记录,历史费用不会被改写。":"Every record has frozen the prices in effect when it was written: editing the price table only affects future records, past costs are never rewritten.","用当前价格表重算全部历史":"Reprice all history with the current table","已提交,正在用当前价格表重算全部历史…":"Submitted — repricing all history with the current table…","当前宿主不支持重算":"This host does not support repricing"};
|
|
25
11
|
|
|
@@ -2437,226 +2423,6 @@ var api = function (payload) {
|
|
|
2437
2423
|
);
|
|
2438
2424
|
}
|
|
2439
2425
|
|
|
2440
|
-
// ── 消息底部 token 入口(conversation.chat.assistant-actions)──
|
|
2441
|
-
// 时长格式化为「Xm Ys」/「X分Y秒」
|
|
2442
|
-
var fmtDur = function (ms) {
|
|
2443
|
-
if (!ms || ms <= 0) return "0s";
|
|
2444
|
-
var secs = Math.round(ms / 1000);
|
|
2445
|
-
var m = Math.floor(secs / 60), r = secs % 60;
|
|
2446
|
-
if (m > 0) return __LANG === "en" ? (m + "m" + r + "s") : (m + "分" + r + "秒");
|
|
2447
|
-
return __LANG === "en" ? (r + "s") : (r + "秒");
|
|
2448
|
-
};
|
|
2449
|
-
|
|
2450
|
-
var __tok = {
|
|
2451
|
-
overlay: { position: "fixed", inset: 0, zIndex: 2147483000, background: "rgba(0,0,0,.4)", display: "flex", alignItems: "center", justifyContent: "center", padding: 16 },
|
|
2452
|
-
card: { background: "#ffffff", color: "#1c2733", borderRadius: 12, maxWidth: "min(680px, 94vw)", width: "100%", maxHeight: "calc(100vh - 40px)", overflowY: "auto", scrollbarWidth: "none", msOverflowStyle: "none", boxShadow: "0 14px 44px rgba(0,0,0,.4)", padding: "14px 16px", fontSize: fs(FS.md) },
|
|
2453
|
-
title: { display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: fs(FS.lg), fontWeight: 600, marginBottom: 10 },
|
|
2454
|
-
hint: { fontSize: fs(FS.sm), opacity: 0.6, marginBottom: 10 },
|
|
2455
|
-
row: { display: "flex", alignItems: "center", gap: 10, padding: "6px 0", borderBottom: "1px solid #eef1f5", fontSize: fs(FS.md) },
|
|
2456
|
-
cellModel: { flex: "0 0 32%", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
2457
|
-
cellTime: { flex: "0 0 14%", opacity: 0.7, fontSize: fs(FS.sm) },
|
|
2458
|
-
cellT: { flex: "0 0 11%", textAlign: "right", whiteSpace: "nowrap" },
|
|
2459
|
-
cellPeriod: { flex: "0 0 6%", textAlign: "center", fontWeight: 600 },
|
|
2460
|
-
cellCost: { flex: "0 0 16%", textAlign: "right", whiteSpace: "nowrap", fontWeight: 600 },
|
|
2461
|
-
title2: { fontSize: fs(FS.lg), fontWeight: 600, margin: "12px 0 6px" },
|
|
2462
|
-
statRow: { display: "flex", flexWrap: "wrap", gap: 10, marginBottom: 12 },
|
|
2463
|
-
stat: { flex: "1 1 0", minWidth: 96, background: "#f5f7fa", borderRadius: 8, padding: "8px 10px" },
|
|
2464
|
-
statLabel: { fontSize: fs(FS.sm), opacity: 0.6, marginBottom: 2 },
|
|
2465
|
-
statValue: { fontSize: fs(FS.xl), fontWeight: 700 },
|
|
2466
|
-
barWrap: { display: "flex", alignItems: "center", gap: 10, marginBottom: 12 },
|
|
2467
|
-
barTrack: { flex: 1, height: 12, borderRadius: 999, background: "#eef1f5", overflow: "hidden" },
|
|
2468
|
-
barFill: { height: "100%", borderRadius: 999, background: "#22a45d", transition: "width .3s ease" },
|
|
2469
|
-
barLabel: { fontSize: fs(FS.sm), whiteSpace: "nowrap", opacity: 0.85 },
|
|
2470
|
-
mCard: { background: "#f7f8fa", borderRadius: 8, padding: "8px 10px", marginBottom: 8 },
|
|
2471
|
-
mHead: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 8, marginBottom: 4 },
|
|
2472
|
-
mName: { fontWeight: 600, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontSize: fs(FS.md), flex: "1 1 0", minWidth: 0 },
|
|
2473
|
-
mCost: { color: "#1c2733", fontWeight: 700, whiteSpace: "nowrap" },
|
|
2474
|
-
mLine: { fontSize: fs(FS.sm), opacity: 0.85, overflowWrap: "anywhere" },
|
|
2475
|
-
close: Object.assign({}, st.btn, { marginLeft: "auto" })
|
|
2476
|
-
};
|
|
2477
|
-
|
|
2478
|
-
function MessageTokenAction(props) {
|
|
2479
|
-
var messageId = props.messageId;
|
|
2480
|
-
var sessionId = props.sessionId;
|
|
2481
|
-
var openState = React.useState(false);
|
|
2482
|
-
var open = openState[0], setOpen = openState[1];
|
|
2483
|
-
var dataState = React.useState({ status: "idle", data: null });
|
|
2484
|
-
var s1 = dataState[0], setData = dataState[1];
|
|
2485
|
-
// 从会话快照读取该消息的完成时间与所在步骤开始时间,用作“本轮”时间窗
|
|
2486
|
-
var msgTime = 0, stepStart = 0;
|
|
2487
|
-
if (props.useSession && typeof props.useSession === "function") {
|
|
2488
|
-
try {
|
|
2489
|
-
var pick = function (f) {
|
|
2490
|
-
return props.useSession(function (snap) {
|
|
2491
|
-
if (!snap || !snap.chat || !snap.chat.nodes) return 0;
|
|
2492
|
-
var arr = typeof snap.chat.nodes.values === "function" ? snap.chat.nodes.values() : null;
|
|
2493
|
-
if (!arr) return 0;
|
|
2494
|
-
for (var ni = 0; ni < arr.length; ni++) {
|
|
2495
|
-
var vh = arr[ni];
|
|
2496
|
-
if (!vh || !vh.data) continue;
|
|
2497
|
-
var fin = vh.data.finalNode || (vh.data.closing && vh.data.closing.finalNode) || null;
|
|
2498
|
-
if (fin && fin.messageId === messageId) return f(fin);
|
|
2499
|
-
}
|
|
2500
|
-
return 0;
|
|
2501
|
-
}) || 0;
|
|
2502
|
-
};
|
|
2503
|
-
msgTime = pick(function (fin) { return fin.time || 0; });
|
|
2504
|
-
stepStart = pick(function (fin) { return (fin.timing && fin.timing.stepStartTime) || 0; });
|
|
2505
|
-
} catch (e) {}
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
React.useEffect(function () {
|
|
2509
|
-
var from = stepStart || (msgTime ? (msgTime - 5 * 60 * 1000) : 0);
|
|
2510
|
-
var to = msgTime || 0;
|
|
2511
|
-
if (!sessionId) { setData({ status: "idle", data: null }); return; }
|
|
2512
|
-
setData({ status: "loading", data: s1.data });
|
|
2513
|
-
api({ action: "tokenForMessage", sessionId: sessionId, from: from, to: to }).then(function (res) {
|
|
2514
|
-
setData({ status: res && res.ok ? "done" : "error", data: res });
|
|
2515
|
-
}).catch(function () { setData({ status: "error", data: null }); });
|
|
2516
|
-
}, [messageId, sessionId, msgTime, stepStart]);
|
|
2517
|
-
|
|
2518
|
-
var convo = s1.status === "done" && s1.data && s1.data.conversation ? s1.data.conversation : null;
|
|
2519
|
-
var agg2 = s1.status === "done" && s1.data && s1.data.aggregate ? s1.data.aggregate : null;
|
|
2520
|
-
var recs = s1.status === "done" && s1.data && s1.data.records ? s1.data.records : [];
|
|
2521
|
-
// 四桶互斥求和,不含 reasoning(它是 output 的子集,宿主语义如此)。
|
|
2522
|
-
var convoTokens = convo ? (convo.input + convo.cacheRead + convo.cacheWrite + convo.output) : 0;
|
|
2523
|
-
var turnTokens = agg2 ? (agg2.input + agg2.cacheRead + agg2.cacheWrite + agg2.output) : 0;
|
|
2524
|
-
var label = t("获取中…");
|
|
2525
|
-
if (s1.status === "error") label = "—";
|
|
2526
|
-
if (s1.status === "done") {
|
|
2527
|
-
if (agg2) label = t("本轮 token") + " " + fmtInt(turnTokens);
|
|
2528
|
-
else if (convo) label = t("本轮 token") + " " + fmtInt(convoTokens);
|
|
2529
|
-
else label = "—";
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
// 按本轮记录聚合模型
|
|
2533
|
-
var byModel = {};
|
|
2534
|
-
for (var bi = 0; bi < recs.length; bi++) {
|
|
2535
|
-
var br = recs[bi];
|
|
2536
|
-
var mk = br.model || br.modelKey || "unknown";
|
|
2537
|
-
var m = byModel[mk];
|
|
2538
|
-
if (!m) { m = byModel[mk] = { model: mk, calls: 0, input: 0, cacheRead: 0, cacheWrite: 0, output: 0, reasoning: 0, peakCost: 0, offCost: 0, totalCost: 0 }; }
|
|
2539
|
-
m.calls++;
|
|
2540
|
-
m.input += br.inputTokens; m.cacheRead += br.cacheReadTokens; m.cacheWrite += br.cacheWriteTokens;
|
|
2541
|
-
m.output += br.outputTokens; m.reasoning += br.reasoningTokens;
|
|
2542
|
-
if (br.peak) m.peakCost += br.autoCost; else m.offCost += br.autoCost;
|
|
2543
|
-
m.totalCost += br.autoCost;
|
|
2544
|
-
}
|
|
2545
|
-
var modelRows = [];
|
|
2546
|
-
for (var mk2 in byModel) modelRows.push(byModel[mk2]);
|
|
2547
|
-
|
|
2548
|
-
function stat(label2, value2) {
|
|
2549
|
-
return el("div", { style: __tok.stat },
|
|
2550
|
-
el("div", { style: __tok.statLabel }, label2),
|
|
2551
|
-
el("div", { style: __tok.statValue }, value2)
|
|
2552
|
-
);
|
|
2553
|
-
}
|
|
2554
|
-
|
|
2555
|
-
function cacheBar() {
|
|
2556
|
-
if (!agg2) return null;
|
|
2557
|
-
var pct = Math.min(100, Math.max(0, agg2.hitRate));
|
|
2558
|
-
return el("div", { style: __tok.barWrap },
|
|
2559
|
-
el("div", { style: __tok.barTrack },
|
|
2560
|
-
el("div", { style: Object.assign({}, __tok.barFill, { width: pct + "%" }) })
|
|
2561
|
-
),
|
|
2562
|
-
el("span", { style: __tok.barLabel }, t("缓存命中率") + " " + (pct ? pct.toFixed(1) : "0") + "%")
|
|
2563
|
-
);
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
function models() {
|
|
2567
|
-
if (!recs.length) return null;
|
|
2568
|
-
modelRows.sort(function (x, y) { return (y.totalCost - x.totalCost) || (y.calls - x.calls); });
|
|
2569
|
-
var MAX_MODELS = 6;
|
|
2570
|
-
var shown = modelRows.slice(0, MAX_MODELS);
|
|
2571
|
-
var extra = modelRows.length - shown.length;
|
|
2572
|
-
var cards = shown.map(function (m, idx) {
|
|
2573
|
-
return el("div", { key: String(idx), style: __tok.mCard },
|
|
2574
|
-
el("div", { style: __tok.mHead },
|
|
2575
|
-
el("span", { style: __tok.mName, title: m.model }, m.model),
|
|
2576
|
-
el("span", { style: __tok.mCost }, fmtMoney(m.totalCost))
|
|
2577
|
-
),
|
|
2578
|
-
el("div", { style: __tok.mLine },
|
|
2579
|
-
t("输入·未命中") + " " + fmtInt(m.input) + " · " + t("缓存命中") + " " + fmtInt(m.cacheRead) + " · " + t("输出") + " " + fmtInt(m.output) + (m.reasoning ? " · " + t("推理") + " " + fmtInt(m.reasoning) : "")
|
|
2580
|
-
),
|
|
2581
|
-
(m.peakCost > 0 || m.offCost > 0) ? el("div", { style: __tok.mLine },
|
|
2582
|
-
el("span", { style: { color: C.warn } }, t("峰") + " " + fmtMoney(m.peakCost)),
|
|
2583
|
-
" · ",
|
|
2584
|
-
el("span", { style: { color: "#3d6bd6" } }, t("谷") + " " + fmtMoney(m.offCost))
|
|
2585
|
-
) : null
|
|
2586
|
-
);
|
|
2587
|
-
});
|
|
2588
|
-
if (extra > 0) cards.push(el("div", { key: "more-models", style: __tok.hint }, t("…及另外 ") + fmtInt(extra) + t(" 个模型(完整列表见「用量与消耗」页签)")));
|
|
2589
|
-
return el("div", null, cards);
|
|
2590
|
-
}
|
|
2591
|
-
function turnStats() {
|
|
2592
|
-
if (!agg2) return null;
|
|
2593
|
-
// 记录只存开始时间,单条调用时 min/max 相同会算成 0;本轮耗时直接用
|
|
2594
|
-
// 该消息所在 step 的起止(完成时间 − step 开始时间),才是真实耗时。
|
|
2595
|
-
var span = (msgTime && stepStart) ? (msgTime - stepStart) : ((agg2.time && agg2.time.end) ? Math.max(0, agg2.time.end - agg2.time.start) : 0);
|
|
2596
|
-
return el("div", { style: __tok.statRow },
|
|
2597
|
-
stat(t("本次输出"), fmtInt(agg2.output)),
|
|
2598
|
-
stat(t("本轮 token"), fmtInt(turnTokens)),
|
|
2599
|
-
stat(t("本轮消耗"), fmtMoney(agg2.totalCost)),
|
|
2600
|
-
stat(t("本轮耗时"), fmtDur(span)),
|
|
2601
|
-
stat(t("本轮缓存命中率"), (agg2.hitRate ? agg2.hitRate.toFixed(1) : "0") + "%")
|
|
2602
|
-
);
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
function summary() {
|
|
2606
|
-
if (!convo) return null;
|
|
2607
|
-
var span = (convo.time && convo.time.end) ? Math.max(0, convo.time.end - convo.time.start) : 0;
|
|
2608
|
-
return el("div", { style: __tok.statRow },
|
|
2609
|
-
stat(t("总 token"), fmtInt(convoTokens)),
|
|
2610
|
-
stat(t("总消耗"), fmtMoney(convo.totalCost)),
|
|
2611
|
-
stat(t("耗时"), fmtDur(span)),
|
|
2612
|
-
stat(t("缓存命中率"), (convo.hitRate ? convo.hitRate.toFixed(1) : "0") + "%")
|
|
2613
|
-
);
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
function body() {
|
|
2617
|
-
if (s1.status === "loading") return el("div", { style: __tok.hint }, t("获取中…"));
|
|
2618
|
-
if (s1.status === "error") return el("div", { style: __tok.hint }, t("查询失败"));
|
|
2619
|
-
if (!convo && !agg2) return el("div", { style: __tok.hint }, t("无 Token 数据"));
|
|
2620
|
-
var zero = convo ? (convoTokens === 0 && convo.totalCost === 0) : (turnTokens === 0 && agg2.totalCost === 0);
|
|
2621
|
-
if (zero) return el("div", { style: __tok.hint }, t("本期无消耗(所有用量为 0)"));
|
|
2622
|
-
return el("div", null,
|
|
2623
|
-
convo ? el("div", null,
|
|
2624
|
-
el("div", { style: __tok.title2 }, t("对话累计")),
|
|
2625
|
-
summary()
|
|
2626
|
-
) : null,
|
|
2627
|
-
el("div", { style: __tok.title2 }, t("本轮明细")),
|
|
2628
|
-
turnStats(),
|
|
2629
|
-
cacheBar(),
|
|
2630
|
-
recs.length ? el("div", null,
|
|
2631
|
-
el("div", { style: __tok.title2 }, t("按模型")),
|
|
2632
|
-
models()
|
|
2633
|
-
) : el("div", { style: __tok.hint }, t("本轮无记录")),
|
|
2634
|
-
el("div", { style: __tok.hint }, t("详细记录请在「用量与消耗」页签查看"))
|
|
2635
|
-
);
|
|
2636
|
-
}
|
|
2637
|
-
|
|
2638
|
-
var overlayEl = open ? el("div", { key: "usage-tok-overlay", style: __tok.overlay, onClick: function () { setOpen(false); } },
|
|
2639
|
-
el("div", { style: __tok.card, "data-dsh-usage-tok": "1", onClick: function (e) { e.stopPropagation(); } },
|
|
2640
|
-
el("div", { style: __tok.title },
|
|
2641
|
-
el("span", null, t("Token 明细")),
|
|
2642
|
-
el("button", { style: __tok.close, onClick: function () { setOpen(false); } }, t("关闭"))
|
|
2643
|
-
),
|
|
2644
|
-
body()
|
|
2645
|
-
)
|
|
2646
|
-
) : null;
|
|
2647
|
-
if (overlayEl && ReactDOM && typeof ReactDOM.createPortal === "function" && typeof document !== "undefined" && document.body) {
|
|
2648
|
-
overlayEl = ReactDOM.createPortal(overlayEl, document.body);
|
|
2649
|
-
}
|
|
2650
|
-
return el("div", { style: { display: "inline-flex", alignItems: "center", gap: 4 } },
|
|
2651
|
-
el("button", { type: "button", key: "usage-tok",
|
|
2652
|
-
style: Object.assign({}, st.btn, { padding: "0 6px", minWidth: 0, fontSize: fs(FS.sm) }),
|
|
2653
|
-
title: t("Token 明细"),
|
|
2654
|
-
onClick: function () { setOpen(true); }
|
|
2655
|
-
}, label),
|
|
2656
|
-
overlayEl
|
|
2657
|
-
);
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
2426
|
// ── plugin ──
|
|
2661
2427
|
var inject = ["slots"];
|
|
2662
2428
|
|
|
@@ -2683,12 +2449,6 @@ var api = function (payload) {
|
|
|
2683
2449
|
);
|
|
2684
2450
|
});
|
|
2685
2451
|
|
|
2686
|
-
slots.inject("conversation.chat.assistant-actions", function () {
|
|
2687
|
-
return slots.register(
|
|
2688
|
-
{ name: "conversation.chat.assistant-actions", id: "usage-token", order: 8 },
|
|
2689
|
-
MessageTokenAction
|
|
2690
|
-
);
|
|
2691
|
-
});
|
|
2692
2452
|
}
|
|
2693
2453
|
|
|
2694
2454
|
// test/debug surface: instant-switch guarantees, locale formatters, peak/off-peak
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-token-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "DeepSeek Harness usage & cost tracker plugin: per-call token/cache-hit stats, peak/off-peak billing, CSV/JSON/PNG export with custom destination, and persistent local storage. Ships a host half plus a web client half in one npm package; installs into a DSH profile as a dsh.bundle from a local package or a published release.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek",
|