dsh-cost-meter 1.9.0 → 1.9.2
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/LICENSE +21 -21
- package/README.md +574 -570
- package/README.zh-CN.md +578 -574
- package/docs/custom-balance-sources.md +68 -0
- package/docs/opendesign-billing.md +93 -103
- package/docs/performance-2026-10-18.json +1703 -0
- package/docs/performance-2026-10-18.md +58 -0
- package/docs/update-notes-1.9.1.md +100 -0
- package/docs/update-notes-1.9.2.md +46 -0
- package/lib/client.codex.js +1 -1
- package/lib/client.js +5 -5
- package/lib/client.pricing.js +1 -1
- package/lib/client.statistics.js +11 -11
- package/lib/coding-plans.js +1 -1
- package/lib/custom-balance.js +37 -19
- package/lib/index.js +9 -5
- package/lib/ledger-persistence.js +10 -3
- package/lib/locale.js +30 -2
- package/lib/opendesign.js +9 -12
- package/lib/store.js +7 -3
- package/lib/typert.host.js +1058 -1056
- package/package.json +192 -187
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# 2026-10-18 性能与透明度验证
|
|
2
|
+
|
|
3
|
+
基线 commit:`9725581bdbd19cf6a2ad2e7c02e0557f2e045771`,版本 1.9.0。测试使用同一台 Windows 主机、Node.js 24.19.0、AMD Ryzen 7 5800H。两版均使用锁文件中的 acorn 8.15.0、zod 4.6.5 和 esbuild 0.28.2。原始数据见 [JSON 记录](performance-2026-10-18.json)。
|
|
4
|
+
|
|
5
|
+
## 自动语言模式的费用查询
|
|
6
|
+
|
|
7
|
+
[#312](https://github.com/Han-1413141/dsh-cost-meter/issues/312) 指出的开销来自:宿主没有可用 locale 服务时,每个费用方法都通过 `settings.describe({ redactSecrets: true })` 构建全部插件设置,只为读取语言偏好。
|
|
8
|
+
|
|
9
|
+
现在只缓存解析出的语言,设置或语言事件立即使缓存失效。没有事件的旧宿主最多每秒探测一次,在下一次费用读取时更新;明确选择中文或英文仍直接使用指定语言。缓存不保留设置描述和凭据,插件卸载时清理。另处理了 `describe()` 自身触发设置事件的重入情况,避免递归调用。
|
|
10
|
+
|
|
11
|
+
基准调用真实的 `costMeter.getSessionCost()`,使用空账本和合成设置描述:64 个插件、每个 20 个字段,加一个语言设置条目。预热 100 次,随后执行 5 轮,每轮 2,000 次读取;两版均使用同一数据和禁网条件。
|
|
12
|
+
|
|
13
|
+
| 指标 | 修改前 | 修改后 |
|
|
14
|
+
| --- | ---: | ---: |
|
|
15
|
+
| 10,000 次读取中的全量设置描述次数 | 10,000 | 0 |
|
|
16
|
+
| 每轮耗时中位数 | 1,719.58 ms | 40.19 ms |
|
|
17
|
+
| 每轮 CPU 时间中位数 | 1,719 ms | 47 ms |
|
|
18
|
+
| 外部网络请求 | 0 | 0 |
|
|
19
|
+
|
|
20
|
+
这次测量中,该调用路径的耗时降低 **97.7%**。这是隔离基准,不是整个 DSH 的 CPU 降幅,也不将报告者旧版采样中的 11.3% 当成新版实测结果。修改后全部计时轮次在缓存期限内完成;长期运行的无事件宿主仍保留每秒最多一次的检查。
|
|
21
|
+
|
|
22
|
+
复现命令:
|
|
23
|
+
|
|
24
|
+
```powershell
|
|
25
|
+
# 两个 checkout 使用相同依赖;第一个参数是被测仓库根目录。
|
|
26
|
+
node test/host-locale-performance.mjs <baseline-checkout> before.json
|
|
27
|
+
node test/host-locale-performance.mjs <updated-checkout> after.json
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## OpenDesign 请求数量
|
|
31
|
+
|
|
32
|
+
同一份合成 Control Key 场景中,旧路径请求 `coding-plan-usage` 收到 401 后,再请求 preflight,同时读取钱包,共 **3 次 GET**。新路径直接并行读取 preflight 和钱包,共 **2 次 GET**,减少一次必然失败的请求和串行等待。身份校验、大整数额度校验和单侧失败处理保留。未用真实账户测量网络延迟。
|
|
33
|
+
|
|
34
|
+
## 客户端体积
|
|
35
|
+
|
|
36
|
+
构建时根据实际重复次数压缩 CSS 声明、选择器与主题变量;客户端加载时解码一次。构建过程逐字节核对解码结果与 esbuild 输出一致。
|
|
37
|
+
|
|
38
|
+
主客户端从 **261,676 字节**变为 **260,671 字节**,新增功能后仍减少 **1,005 字节**。统计和定价继续按需加载。没有通过删除界面内容满足 DSH STORE 的 262,144 字节限制。
|
|
39
|
+
|
|
40
|
+
## 透明度
|
|
41
|
+
|
|
42
|
+
主题背景色中含透明度时,费用设置页、统计页、价格下拉框、费用详情、上下文引导、兼容提醒、峰谷提醒和侧栏固定区域使用相同 RGB 颜色的不透明背景;不修改宿主或其它插件的主题变量。统计内容和费用弹窗使用皮肤的弹窗表面色,避免把深色壁纸遮罩当成浅色界面的正文底色。
|
|
43
|
+
|
|
44
|
+
Chromium 测试覆盖 11 类区域、3 种主题、4 档透明度,共 **132 个场景**。每个场景只切换后方页面的颜色,比较区域内部的截图像素:
|
|
45
|
+
|
|
46
|
+
- 基线有 **105 个场景**的内部像素随后方内容变化,复现透出。
|
|
47
|
+
- 修改后 **132 个场景全部保持相同**,浏览器无脚本错误。
|
|
48
|
+
- 主题包含浅色、深色、浅色宿主配深色皮肤;透明度为 0、0.2、0.65、1。
|
|
49
|
+
|
|
50
|
+
```powershell
|
|
51
|
+
$env:DSH_TEST_UI_MODULES = '<含 react、react-dom、playwright-core 的 node_modules>'
|
|
52
|
+
node test/skin-opacity-browser.mjs 9725581
|
|
53
|
+
node test/skin-opacity-browser.mjs
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
测试使用真实客户端和按需模块的 CSS,以及真实 React 费用详情和兼容提示组件。测试范围是背景色透明度;没有把任意第三方插件直接修改父元素 `opacity` 的行为纳入已验证范围。
|
|
57
|
+
|
|
58
|
+
贡献:@XHPAN 提供 [#312](https://github.com/Han-1413141/dsh-cost-meter/issues/312) 的 CPU profile 归因、环境和优化建议;本文的数据是本轮另行运行的隔离基准。
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# v1.9.1
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
本版本修复皮肤类插件把主题别名(`--dsw-alias-bg-*`)调成半透明后,插件浮层与弹窗透出后方页面内容的问题;同时对记账、账本落盘合并、统计缓存与设置页自动保存路径做了可度量的性能优化。**无配置或账本格式变化,升级后无需手动迁移。**
|
|
6
|
+
|
|
7
|
+
### 皮肤半透明时浮层与弹窗不再透出后方内容
|
|
8
|
+
|
|
9
|
+
皮肤插件把 `--dsw-alias-bg-base` / `--dsw-alias-bg-layer-1` / `--dsw-alias-bg-layer-2` 设成 `rgba(...)` 时,插件里直接使用这些别名的容器会整体变透明,导致弹窗内部左右两栏、浮层与后方页面互相透出,文字不可读。
|
|
10
|
+
|
|
11
|
+
本版本把「遮挡面」(必须遮住下方内容的浮层/弹窗)统一改为**本地不透明基底 + 皮肤色渐变叠层**合成:
|
|
12
|
+
|
|
13
|
+
- `background-color` 使用不透明本地基底:浅色主题 `#fff`,深色主题(`body[data-ds-dark-theme]` / `html[data-theme=dark]`)`#151517`;
|
|
14
|
+
- `background-image` 用皮肤别名色做一层渐变,保留皮肤的色调与明暗观感;
|
|
15
|
+
- 默认主题或不透明皮肤下合成结果与原视觉完全一致;半透明皮肤下不再透出后方内容。
|
|
16
|
+
|
|
17
|
+
覆盖的遮挡面:
|
|
18
|
+
|
|
19
|
+
- 主包:统计明细弹窗(`.cm-stat-dialog`)、额度引导(`.cm-qguide`)、峰谷提醒(`.cm-peak-alert`)、精简侧栏底栏(`.cm-footer-stack.simple`);
|
|
20
|
+
- 统计页:费用明细弹窗(`dialog.cm-fee-dialog`)、上下文费用开关引导(`.cm-context-intro`)、billion-context 提示(`.cm-billion-notice`);
|
|
21
|
+
- 定价页:模型/价格组合浮层(`.cm-combo-panel`);
|
|
22
|
+
- Codex 兼容弹窗复用统计弹窗样式,自动获得同样的不透明合成。
|
|
23
|
+
|
|
24
|
+
新增静态 fixture `test/skin-occlusion-static.mjs`(源码规则 + 构建产物标记双重断言),并在真实浏览器回归里模拟 Dream Skin(半透明 `--dsw-alias-bg-base` 与半透明 `--dsw-alias-bg-layer-2`),断言弹窗底色不透明且渐变里保留皮肤色。
|
|
25
|
+
|
|
26
|
+
### 记账性能:价格历史快照改为落盘时推进
|
|
27
|
+
|
|
28
|
+
此前每一笔用量入账都会重建整张价格历史快照(835 个模型,约 2.18ms 名称整理 + 0.66ms 哈希 + JSON 比较),占单笔记账耗时(1.3–2.3ms)的 99.8%。现在改为在落盘合并的锁内一次性推进价格历史,单笔记账不再触发重建。
|
|
29
|
+
|
|
30
|
+
- 1000 笔连续记账:1308ms → 93ms;
|
|
31
|
+
- 短窗口(1 / 5 / 20 / 50 笔):42.4 / 46.4 / 64.5 / 102.9ms → 36.5 / 34.5 / 36.5 / 39.1ms(约 -26% / -43% / -62%)。
|
|
32
|
+
|
|
33
|
+
价格变更仍由配置写入路径记录,历史价格查询与重算结果不变。
|
|
34
|
+
|
|
35
|
+
### 落盘合并与渲染缓存优化
|
|
36
|
+
|
|
37
|
+
- 账本落盘合并(`mergeLedger`)不再无条件做 3 次全账本深拷贝:本地快照是自有对象时跳过克隆、磁盘快照与基线相同时直接复用,待提交记录仍逐条重放。普通 flush 由约 40ms 降到约 30ms,合并后的内存/磁盘账本内容与语义哈希(`30f37c10373d0a50`)和原实现完全一致。
|
|
38
|
+
- 统计页渲染缓存键改用 `pricesRev`,不再每帧序列化整张价格表(178KB,2.55ms → 0.015ms,约 170 倍);旧宿主没有 `pricesRev` 时回退原来的整体序列化。
|
|
39
|
+
- 设置页自动保存的逐键差异比较增加引用短路:未变化的配置项直接跳过,不再对每个键序列化比较。
|
|
40
|
+
|
|
41
|
+
### 验证
|
|
42
|
+
|
|
43
|
+
- `node test/verify.mjs`:全部断言通过(含新增皮肤遮挡静态断言)。
|
|
44
|
+
- 真实浏览器回归:`test/statistics-dialog-titlebar.mjs`(229 条断言,含皮肤与窄屏几何)、`test/session-costs-browser.mjs`(含 Dream Skin 不透明合成断言)通过。
|
|
45
|
+
- 全部测试使用本地账本与合成数据,不发起真实模型请求、不消耗订阅额度。
|
|
46
|
+
|
|
47
|
+
### 升级方式
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
dsh plugin --profile desktop add dsh-cost-meter@1.9.1
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
重启 DSH 后生效(web Profile 把 `desktop` 换成 `web`)。或重新运行一键安装脚本:`irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.1/install.ps1 | iex`。
|
|
54
|
+
|
|
55
|
+
## English
|
|
56
|
+
|
|
57
|
+
This release fixes translucent skin plugins leaking page content through plugin overlays and dialogs, and ships measured performance improvements for accounting, ledger flushes, statistics caching and settings auto-save. **No configuration or ledger schema changes; no manual migration is required.**
|
|
58
|
+
|
|
59
|
+
### Overlays and dialogs stay opaque with translucent skins
|
|
60
|
+
|
|
61
|
+
When a skin plugin sets `--dsw-alias-bg-base` / `--dsw-alias-bg-layer-1` / `--dsw-alias-bg-layer-2` to `rgba(...)`, containers that use those aliases directly become translucent: dialog columns, popovers and the page behind them bleed into each other and text becomes unreadable.
|
|
62
|
+
|
|
63
|
+
All "occluding" surfaces (overlays/dialogs that must cover what is behind them) now composite an **opaque local base + a skin-tint gradient**:
|
|
64
|
+
|
|
65
|
+
- `background-color` uses an opaque local base: `#fff` in light themes, `#151517` in dark themes (`body[data-ds-dark-theme]` / `html[data-theme=dark]`);
|
|
66
|
+
- `background-image` keeps the skin alias colour as a gradient layer, preserving the skin's hue;
|
|
67
|
+
- with the default theme or opaque skins the composite is visually identical to before; with translucent skins nothing behind the surface bleeds through.
|
|
68
|
+
|
|
69
|
+
Covered surfaces: the main stat dialog, quota guide, peak alert and simple footer (main bundle); the fee dialog, context-costs intro and billion-context notice (statistics page); and the model/price combo popover (pricing page). The Codex compat dialog reuses the stat dialog rule and inherits the fix.
|
|
70
|
+
|
|
71
|
+
A new static fixture (`test/skin-occlusion-static.mjs`) asserts both source rules and built-bundle markers, and the real-browser suites simulate a Dream Skin (translucent `--dsw-alias-bg-base` and `--dsw-alias-bg-layer-2`) and assert an opaque background with the skin tint preserved in the gradient.
|
|
72
|
+
|
|
73
|
+
### Faster accounting: price-history snapshots advanced at flush time
|
|
74
|
+
|
|
75
|
+
Every usage entry used to rebuild the whole price-history snapshot (835 models, ~2.18ms normalisation + 0.66ms hashing + JSON comparison), which was 99.8% of the per-entry cost (1.3–2.3ms). Price history is now advanced once inside the flush lock, so individual entries no longer rebuild it.
|
|
76
|
+
|
|
77
|
+
- 1000 consecutive entries: 1308ms → 93ms;
|
|
78
|
+
- short windows (1 / 5 / 20 / 50 entries): 42.4 / 46.4 / 64.5 / 102.9ms → 36.5 / 34.5 / 36.5 / 39.1ms (about -26% / -43% / -62%).
|
|
79
|
+
|
|
80
|
+
Price changes are still recorded on config writes, and historical pricing queries/repricing keep the same results.
|
|
81
|
+
|
|
82
|
+
### Ledger merge and render-cache optimisations
|
|
83
|
+
|
|
84
|
+
- `mergeLedger` no longer performs three unconditional deep clones of the whole ledger: the local snapshot is cloned only when it is not owned, and the disk snapshot is reused when it equals the base; pending records are still replayed one by one. A normal flush drops from ~40ms to ~30ms, and the merged in-memory/on-disk ledger content and semantic hash (`30f37c10373d0a50`) are identical to the previous implementation.
|
|
85
|
+
- The statistics render cache key now uses `pricesRev` instead of serialising the whole price table on every render (178KB, 2.55ms → 0.015ms, about 170×); hosts without `pricesRev` fall back to the old serialisation.
|
|
86
|
+
- Settings auto-save diffing short-circuits unchanged entries by reference, avoiding serialisation comparisons for every key.
|
|
87
|
+
|
|
88
|
+
### Verification
|
|
89
|
+
|
|
90
|
+
- `node test/verify.mjs`: all assertions pass, including the new skin-occlusion static fixture.
|
|
91
|
+
- Real-browser suites: `test/statistics-dialog-titlebar.mjs` (229 assertions incl. skin and narrow-viewport geometry) and `test/session-costs-browser.mjs` (incl. the Dream Skin opacity assertions) pass.
|
|
92
|
+
- All tests use local ledgers and synthetic data; no live model requests and no subscription quota consumption.
|
|
93
|
+
|
|
94
|
+
### Upgrading
|
|
95
|
+
|
|
96
|
+
```powershell
|
|
97
|
+
dsh plugin --profile desktop add dsh-cost-meter@1.9.1
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Restart DSH afterwards (use `web` instead of `desktop` for the web profile), or rerun the one-click installer: `irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.1/install.ps1 | iex`.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# v1.9.2
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
本版包含 [PR #314](https://github.com/Han-1413141/dsh-cost-meter/pull/314) 的全部修复。v1.9.1 未单独发布到 npm,其记账、落盘合并、统计缓存和设置比较优化也一并发布。账本格式与历史金额口径不变,升级无需手动迁移。
|
|
6
|
+
|
|
7
|
+
- **OpenDesign**:直接并行查询接受 Control Key 的 `/billing/preflight` 与独立钱包接口,正常查询从 3 次 GET 减为 2 次,保留身份、大整数和单侧失败处理。仅在 DSH 中使用模型 API 计费,不需要安装 OpenDesign 应用;远端额度查询需要工作区 ID 和 Control Key。[配置说明](opendesign-billing.md)
|
|
8
|
+
- **自定义余额**:以 `/` 开头的相对路径跟随 DSH 实际监听端口,端口改变后缓存失效。局域网 HTTP 需显式打开 `allowInsecureHttp` 并填写准确的主机与端口白名单;凭据仍通过凭据库引用。[配置说明](custom-balance-sources.md)
|
|
9
|
+
- **WorkBuddy2API**:新增积分预设,读取管理接口的活跃账号池积分 `summary.available_remaining`。使用管理端 `X-Admin-Token`,不是模型 API Key;按实际服务端口填写地址。
|
|
10
|
+
- **皮肤透明度**:页面与弹窗保留皮肤 RGB 颜色并去除背景 alpha;统计内容使用弹窗表面色,解决深色壁纸遮罩与浅色弹窗混用时的黑底黑字。11 类区域、3 种主题、4 档透明度共 132 个浏览器场景全部通过。
|
|
11
|
+
- **性能**:缓存自动语言模式的宿主语言探测结果,随设置和语言事件失效;没有事件的旧宿主最多每秒检查一次。5 轮各 2,000 次费用读取的隔离基准中,中位耗时从 1,719.58 ms 降至 40.19 ms,降低 97.7%;此数值不代表整个 DSH 的 CPU 降幅。新增功能后,主客户端仍从 261,676 字节降至 260,671 字节。[原始数据与复现方法](performance-2026-10-18.md)
|
|
12
|
+
|
|
13
|
+
本版代码已通过完整本地回归、Windows / Linux 安装、宿主兼容、浏览器交互及 CodeQL 检查。OpenDesign 与 WorkBuddy2API 的认证路径使用模拟响应验证,未查询真实用户账号。
|
|
14
|
+
|
|
15
|
+
### 升级
|
|
16
|
+
|
|
17
|
+
在 DSH 对应的 CLI 中执行:
|
|
18
|
+
|
|
19
|
+
```powershell
|
|
20
|
+
dsh plugin --profile desktop add dsh-cost-meter@1.9.2
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
随后完全重启 DSH。Web 用户把 `desktop` 换成 `web`;Desktop 用户按[桌面版安装说明](install-troubleshooting.md#desktop-安装与更新)使用应用自带的 CLI。
|
|
24
|
+
|
|
25
|
+
### 贡献
|
|
26
|
+
|
|
27
|
+
- @playgithub 提出 [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274) 接入需求、设置交互反馈及仅使用 DSH API 的配置问题。
|
|
28
|
+
- @codeforker654 提供 [Control Key 401 复现](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870);@yunjuanhuakai 提供 [preflight 端点定位、响应结构与验证](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566)。
|
|
29
|
+
- @unifilitence 提供 [#313](https://github.com/Han-1413141/dsh-cost-meter/issues/313) 独立复现、端点建议与钱包契约。
|
|
30
|
+
- @XHPAN 提供 [#312](https://github.com/Han-1413141/dsh-cost-meter/issues/312) CPU profile 归因和缓存失效建议。
|
|
31
|
+
- @Jav1es 提供 [#311](https://github.com/Han-1413141/dsh-cost-meter/issues/311) 随机端口复现与相对路径建议。
|
|
32
|
+
- @snhun 提出 [#309](https://github.com/Han-1413141/dsh-cost-meter/issues/309) 局域网 HTTP 和 [#310](https://github.com/Han-1413141/dsh-cost-meter/issues/310) WorkBuddy2API 接入需求。
|
|
33
|
+
|
|
34
|
+
## English
|
|
35
|
+
|
|
36
|
+
This release includes all fixes from [PR #314](https://github.com/Han-1413141/dsh-cost-meter/pull/314), plus the accounting, ledger merge, statistics cache and settings comparison improvements recorded under v1.9.1, which was not published separately to npm. Ledger format and historical amounts remain unchanged.
|
|
37
|
+
|
|
38
|
+
- OpenDesign directly queries the Control Key-compatible preflight endpoint and the independent wallet endpoint, reducing a normal query from three GET requests to two. DSH-only model usage accounting does not require installing the OpenDesign application.
|
|
39
|
+
- Host-relative custom-balance URLs follow the actual DSH listening port and invalidate cached results when it changes. LAN HTTP requires an explicit opt-in and an exact host/port allowlist.
|
|
40
|
+
- A WorkBuddy2API preset reads active account-pool credits through its admin endpoint with an `X-Admin-Token`, separate from model API keys and monetary costs.
|
|
41
|
+
- Pages and dialogs retain skin RGB colours with opaque backgrounds. Statistics content uses the popup surface colour to keep text readable when wallpaper and popup colours differ. All 132 browser opacity scenarios pass.
|
|
42
|
+
- Automatic-language fallback results are cached with event invalidation and a one-second fallback interval. In five isolated rounds of 2,000 cost reads, median time fell from 1,719.58 ms to 40.19 ms (97.7%). This is not a claim about total DSH CPU usage. The main client is 260,671 bytes, down from 261,676 bytes despite the added features. [Method and raw data](performance-2026-10-18.md)
|
|
43
|
+
|
|
44
|
+
Full local regression, Windows/Linux installation, host compatibility, browser interaction and CodeQL checks passed for the implementation. Authenticated OpenDesign and WorkBuddy2API paths were tested with synthetic responses rather than live user accounts. Contributor roles and original reports are linked above.
|
|
45
|
+
|
|
46
|
+
Upgrade using `dsh plugin --profile desktop add dsh-cost-meter@1.9.2`, then fully restart DSH. Use `web` for a web profile and the bundled CLI for Desktop installations.
|
package/lib/client.codex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:g=>{const f=g("react"),{createElement:e,useState:C,useEffect:h,useRef:v}=f,N="cm-stat-dialog cm-codex-compat-dialog";if(typeof document<"u"){const s=document.createElement("style");s.textContent=".cm-codex-compat-dialog{width:min(560px,94vw)}.cm-codex-compat{display:flex;flex-direction:column;gap:8px;font-size:13px}",s.textContent+='@media (max-width:1023px){.cm-codex-compat-dialog{width:calc(100vw -
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:g=>{const f=g("react"),{createElement:e,useState:C,useEffect:h,useRef:v}=f,N="cm-stat-dialog cm-codex-compat-dialog";if(typeof document<"u"){const s=document.createElement("style");s.textContent=".cm-codex-compat-dialog{width:min(560px,94vw)}.cm-codex-compat{display:flex;flex-direction:column;gap:8px;font-size:13px}",s.textContent+='@media (max-width:1023px){.cm-codex-compat-dialog{width:calc(100vw - 32px)}.cm-codex-compat{padding:0 2px}}body[data-dsh-pocket-layout="mobile"] .cm-codex-compat-dialog{width:calc(100vw - 32px)}',document.head.appendChild(s)}function P(){const[s,u]=C(!1),[a,c]=C(null);return[s,a,o=>{s||(u(!0),c(null),o().catch(t=>c(t?.message??String(t))).finally(()=>u(!1)))}]}function y(s){const a=s.state?.codexCompat,c=s.api,i=s.locale==="en",o=(x,A)=>i?A:x,t=v(null),[l,n,p]=P(),r=a?.promptDue===!0;if(h(()=>{r&&t.current&&!t.current.open&&t.current.showModal()},[r]),!r)return null;const d=a.usage??{},m=()=>p(c.dismissCodexCompat);return e("dialog",{ref:t,className:N,"aria-label":o("兼容修复","Compatibility fix"),onCancel:x=>{x.preventDefault(),m()}},e("header",{className:"cm-stat-dialog-head"},o("兼容修复","Compatibility fix"),e("button",{type:"button",className:"cm-btn","aria-label":o("关闭","Close"),disabled:l,onClick:m},"×")),e("div",{className:"cm-stat-dialog-body"},e("p",null,o("检测到 dsh-codex-subscription {version}。Codex 订阅用量不计入 API 费用;为兼容本插件,新产生的 Codex 用量已自动归类为 Plan。是否将历史 codex 类模型的计费统一归类为 Plan(订阅额度,不计入 API 费用)?","Detected dsh-codex-subscription {version}. Codex subscription usage is not billed as API usage; for compatibility this plugin now defaults new Codex usage to Plan. Reclassify the billing of historical codex-class models as Plan (subscription quota, excluded from API usage)?").replace("{version}","v"+(a.version??""))),d.calls>0?e("p",{className:"cm-note"},o("历史 Codex 用量:{calls} 次调用 · {cost} · {days} 天","Historical Codex usage: {calls} calls · {cost} · {days} days").replace("{calls}",d.calls).replace("{cost}","$"+Number(d.cost??0).toFixed(2)).replace("{days}",d.days)):null,n?e("div",{className:"cm-msg err"},o("失败:","Failed: ")+n):null,e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",disabled:l,onClick:m},o("保持现状","Keep status quo")),e("button",{type:"button",className:"cm-btn primary",disabled:l,onClick:()=>p(c.applyCodexCompatHistory)},o("统一归类为 Plan","Reclassify as Plan"))),e("p",{className:"cm-note"},o("之后可在 设置 → 费用 → Codex 订阅兼容 中处理。","You can change this later in Settings → Cost → Codex subscription compatibility."))))}function b(s){const a=s.state?.codexCompat;if(a?.installed!==!0)return null;const c=s.api,i=s.t,o=s.locale==="en",t=(r,d)=>o?d:r,l=a.usage??{},n=a.historyAppliedAt>0,p=a.planClass==="plan"?i("billingClassPlan"):a.planClass==="api"?i("billingClassApi"):i("billingClassAuto");return e("div",{className:"cm-codex-compat"},e("h3",null,t("Codex 订阅兼容","Codex subscription compatibility")),e("p",null,t("检测版本:{version}","Detected version: {version}").replace("{version}","v"+(a.version??""))),e("p",null,t("当前计费方式:{planClass}","Current billing class: {planClass}").replace("{planClass}",p)),e("p",null,t("历史用量:{calls} 次调用 · {cost} · {tokens} tokens · {days} 天","Historical usage: {calls} calls · {cost} · {tokens} tokens · {days} days").replace("{calls}",l.calls).replace("{cost}","$"+Number(l.cost??0).toFixed(2)).replace("{tokens}",Number(l.tokens??0).toLocaleString(o?"en-US":"zh-CN")).replace("{days}",l.days)),n?e("p",{className:"cm-note"},t("已归类于 {time}","Reclassified at {time}").replace("{time}",new Date(a.historyAppliedAt).toLocaleString())):e("p",null,t("历史用量未归类。","Historical usage is not reclassified yet.")),!n&&l.providers?.length?e("p",{className:"cm-note"},t("来源:{providers}","Sources: {providers}").replace("{providers}",l.providers.join(", "))):null,n?null:e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn primary",onClick:()=>c.applyCodexCompatHistory().catch(()=>{})},t("统一归类为 Plan","Reclassify as Plan"))),!n&&a.promptDismissed===!0?e("p",{className:"cm-note"},t("此前选择保持现状,可随时统一归类。","You chose Keep status quo earlier; you can reclassify anytime.")):null)}function w(){return{CodexCompatPrompt:y,CodexCompatPanel:b}}return{mount:w,CodexCompatPrompt:y,CodexCompatPanel:b}}});
|