@gamegeek-saikel/dsh-cost-meter 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +4 -4
  3. package/lib/client.js +501 -308
  4. package/lib/client.js.map +1 -1
  5. package/lib/index.js +182 -41
  6. package/lib/types/client/AssistantCostChip.js +2 -2
  7. package/lib/types/client/CostPluginCard.d.ts +6 -4
  8. package/lib/types/client/CostPluginCard.d.ts.map +1 -1
  9. package/lib/types/client/CostPluginCard.js +83 -51
  10. package/lib/types/client/SessionCostLine.d.ts.map +1 -1
  11. package/lib/types/client/SessionCostLine.js +94 -56
  12. package/lib/types/client/index.d.ts +16 -7
  13. package/lib/types/client/index.d.ts.map +1 -1
  14. package/lib/types/client/index.js +19 -12
  15. package/lib/types/client/locales.d.ts +17 -0
  16. package/lib/types/client/locales.d.ts.map +1 -1
  17. package/lib/types/client/locales.js +36 -1
  18. package/lib/types/index.d.ts +32 -11
  19. package/lib/types/index.d.ts.map +1 -1
  20. package/lib/types/index.js +67 -21
  21. package/lib/types/pricebook.d.ts +6 -5
  22. package/lib/types/pricebook.d.ts.map +1 -1
  23. package/lib/types/pricebook.js +6 -5
  24. package/package.json +38 -37
  25. package/src/client/AssistantCostChip.module.css +58 -28
  26. package/src/client/AssistantCostChip.tsx +3 -3
  27. package/src/client/CostPluginCard.module.css +32 -83
  28. package/src/client/CostPluginCard.tsx +217 -156
  29. package/src/client/SessionCostLine.module.css +151 -14
  30. package/src/client/SessionCostLine.tsx +141 -56
  31. package/src/client/SessionCostPill.module.css +21 -14
  32. package/src/client/index.ts +33 -22
  33. package/src/client/locales.ts +38 -1
  34. package/src/index.ts +79 -32
  35. package/src/pricebook.ts +6 -5
package/README.md CHANGED
@@ -29,7 +29,7 @@ Then start the harness:
29
29
  npx @deepseek-ai/dsh web
30
30
  ```
31
31
 
32
- If you have the DSH CLI installed globally, you can also use `dsh` instead of `npx @deepseek-ai/dsh`. To install into another profile, replace `web` with your profile name. The plugin declares and is verified against DSH `^0.1.5-alpha.1`. The host half requires Node `^22.19.0 || >=24.0.0` and pnpm `11.7.0` for development.
32
+ If you have the DSH CLI installed globally, you can also use `dsh` instead of `npx @deepseek-ai/dsh`. To install into another profile, replace `web` with your profile name. The plugin declares and is verified against DSH `^0.1.7-rc.2`. The host half requires Node `^22.19.0 || >=24.0.0` and pnpm `11.7.0` for development.
33
33
 
34
34
  ## Overview
35
35
 
@@ -49,7 +49,7 @@ Chat costs in DeepSeek pricing change over time (list prices, USD→CNY exchange
49
49
  | Account balance | Official `GET /user/balance`, cached 60 s, single in-flight request, trust-fenced route |
50
50
  | Subagent support | Enumerates the conversation's durable subagent tree through `subagents.listDescendants` (nested delegations, settled children, and cold subagent sessions included, with no depth cap); a ledger is read from the resident session's projection when available and otherwise cold-restored from the child's stored log (`sessionQuery.readSession` + `sessionProjections.restore`), so historical subagent spend is also counted after a host restart; falls back to a BFS over the live agent tree when neither service is mounted |
51
51
  | Conversation total | Main session + every descendant subagent (any depth); subagent totals still render while the main session's own ledger is not materialized |
52
- | UI surfaces | Composer dock · Cost tab · per-reply chip · header pill (live estimate) · settings card |
52
+ | UI surfaces | Composer dock · Cost tab · per-reply chip · header pill (live estimate) · plugin configuration page |
53
53
  | Locale | Simplified Chinese (source) + English |
54
54
  | Complexity | Fully synchronous fold; O(1) price lookups via in-memory mirror |
55
55
 
@@ -63,7 +63,7 @@ Once installed, the plugin contributes five browser surfaces (all text shown in
63
63
  | Cost view tab | `conversation.view` | Whole-conversation totals (main + every subagent nesting level), category totals, the per-subagent list with its depth, and the per-reply anchored ledger |
64
64
  | Per-reply cost chip | `conversation.chat.assistant-actions` | The anchored cost of one finalized reply as the row's own stat capsule — the same trigger + anchored dialog the shipped 用量 and 用时 capsules use (28px pill, hover fill, `aria-expanded` dialog above the trigger). It closes the row's stat run: after 用量 and 用时, before the timestamp, spaced by the row's own gap, and coloured by the band that priced it (green off-peak, red peak). The dialog lists the three billed categories, the band with its multiplier, the model, and the snapshot version; the slot hands over the message id, which the `sessionCostIndex` projection resolves to ledger coordinates (dash `—` when unpriced) |
65
65
  | Header pill | `conversation.session.header.utilities` | Anchored total, or a live `≈ ¥x.xx (estimate)` while streaming; click for the detail panel |
66
- | Plugin card | `settings.plugin.item` | Per-model overrides, OpenRouter aliases, cache-read discount, FX mode, toggles, and manual refresh |
66
+ | Plugin configuration page | `plugins.row.config` | The cost-meter row's page under 设置 → 插件 (DSH 0.1.7 hosts a plugin's own configuration there, keyed `<package>#<row id>`): per-model overrides, OpenRouter aliases, cache-read discount, FX mode, toggles, and manual refresh. The editable fields are the schema's `volatile()` ones — the deployment fields (endpoint, credential reference, refresh cadence, trusted hosts, history cap) stay hand-edited in the profile patch, which is exactly the split DSH's configuration projection can write |
67
67
 
68
68
  The `/cost-meter` host route serves the balance snapshot, the pricebook view, and the subagent totals over GET, and applies manual refresh over POST (`{"action":"refresh"}`). Like the `/api` fence, the route only answers requests whose `Host` header names a loopback address or a declared trusted host — the DNS-rebinding-safe check.
69
69
 
package/README.zh-CN.md CHANGED
@@ -9,7 +9,7 @@
9
9
  **DSH Cost Meter** 是为 DeepSeek Harness(DSH)Web GUI 打造的对话成本追踪插件——**价格快照锚定**的逐轮成本(感知**峰值/闲时**)、**账户余额**、**花费标签页**、**每条回复成本小标签**,以及带**流式实时估算**的**头部胶囊**。每一步的成本、价格档位与快照版本都**只计算一次**——锚定到该用量事件自身时刻生效的价格快照,此后永不重算——因此后续价格变动绝不会改写已写入的对话记录。
10
10
 
11
11
  - Host 半区(`src/`):DeepSeek `GET /user/balance` 余额查询、持久化的快照锚定价格簿、`sessionCost` 投影与不读价格簿的 `sessionCostIndex` 消息索引、子代理成本聚合,以及带信任围栏的 `/cost-meter` 路由。
12
- - Client 半区(`src/client/`):输入框下方读数、花费标签页、每条回复成本小标签、头部胶囊,以及插件配置卡——内置简体中文与英文。
12
+ - Client 半区(`src/client/`):输入框下方读数、花费标签页、每条回复成本小标签、头部胶囊,以及插件配置页(设置 → 插件)——内置简体中文与英文。
13
13
 
14
14
  ---
15
15
 
@@ -29,7 +29,7 @@ npx @deepseek-ai/dsh plugin --profile web add @gamegeek-saikel/dsh-cost-meter
29
29
  npx @deepseek-ai/dsh web
30
30
  ```
31
31
 
32
- 如果已全局安装 DSH CLI,也可以使用 `dsh` 代替 `npx @deepseek-ai/dsh`。安装到其他 profile 时,把 `web` 替换成你的 profile 名称即可。插件声明并已验证兼容 DSH `^0.1.5-alpha.1`。开发环境要求 Node `^22.19.0 || >=24.0.0` 与 pnpm `11.7.0`。
32
+ 如果已全局安装 DSH CLI,也可以使用 `dsh` 代替 `npx @deepseek-ai/dsh`。安装到其他 profile 时,把 `web` 替换成你的 profile 名称即可。插件声明并已验证兼容 DSH `^0.1.7-rc.2`。开发环境要求 Node `^22.19.0 || >=24.0.0` 与 pnpm `11.7.0`。
33
33
 
34
34
  ## 概述
35
35
 
@@ -49,7 +49,7 @@ DeepSeek 的价格随时间变化(官方价目表、USD→CNY 汇率、2026-08
49
49
  | 账户余额 | 官方 `GET /user/balance`,缓存 60 秒,单飞请求,路由带信任围栏 |
50
50
  | 子代理支持 | 沿 `subagents.listDescendants` 枚举本会话持久子代理树(子代理再派生的孙代理、已结束或已冷启动的子会话都计入,无层数上限);账本优先取常驻会话的投影,未常驻的经 `sessionQuery.readSession` + `sessionProjections.restore` 从其持久日志冷读——因此主机重启后,旧会话的历史子代理花费同样会被补算;未挂载该服务时回退到活跃代理树 BFS |
51
51
  | 对话总花费 | 主会话 + 全部后代子代理(任意层数);主会话自身账本尚未就绪时仍展示子代理合计 |
52
- | UI 表面 | 输入框读数 · 花费标签页 · 回复小标签 · 头部胶囊(实时估算)· 设置卡 |
52
+ | UI 表面 | 输入框读数 · 花费标签页 · 回复小标签 · 头部胶囊(实时估算)· 插件配置页 |
53
53
  | 本地化 | 简体中文(键源)+ 英文 |
54
54
  | 复杂度 | 全同步折叠;经内存镜像 O(1) 查价 |
55
55
 
@@ -63,7 +63,7 @@ DeepSeek 的价格随时间变化(官方价目表、USD→CNY 汇率、2026-08
63
63
  | 花费标签页 | `conversation.view` | 全对话总花费(主会话 + 任意层级的子代理)、分类小计、带层级的子代理列表与逐回复锚定账本 |
64
64
  | 每条回复成本小标签 | `conversation.chat.assistant-actions` | 单条已定稿回复的锚定成本,做成与官方「用量」「用时」完全同形的统计胶囊(28px 药丸、悬停底色、`aria-expanded` 展开锚定在触发件上方的对话框);位置收在统计串末:在「用量」「用时」之后、末尾时刻文本之前,间距沿用行自身的 gap;按计价档位着色(闲时绿、高峰红);对话框列出三类计费、档位与倍率、模型与快照版本;插槽只给出消息 id,由 `sessionCostIndex` 投影解析为账本坐标(无价格时显示 `—`) |
65
65
  | 头部胶囊 | `conversation.session.header.utilities` | 锚定总花费;流式中显示 `预计 ¥x.xx(估算)`;点击展开详情面板 |
66
- | 插件配置卡 | `settings.plugin.item` | 按模型覆盖价、OpenRouter 别名、缓存折扣、汇率模式、开关与立即刷新 |
66
+ | 插件配置页 | `plugins.row.config` | 设置 → 插件 中 cost-meter 行自己的配置页(DSH 0.1.7 以 `<包名>#<行 id>` 为键托管插件自带配置):按模型覆盖价、OpenRouter 别名、缓存折扣、汇率模式、开关与立即刷新。可编辑字段即 schema 中标记 `volatile()` 的字段——部署类字段(端点、凭据引用、刷新周期、可信主机、历史上限)仍在 profile patch 中手工维护,这正是 DSH 配置投影能够写入的边界 |
67
67
 
68
68
  `/cost-meter` 宿主路由通过 GET 提供余额快照、价格簿视图与子代理合计;通过 POST(`{"action":"refresh"}`)执行手动刷新。与 `/api` 围栏一致,路由只应答 `Host` 头为回环地址或已声明可信主机的请求——这是防 DNS 重绑定的安全校验。
69
69