dsh-cost-meter 1.9.2 → 1.9.4
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 +9 -8
- package/README.zh-CN.md +9 -8
- package/docs/display-settings.md +15 -1
- package/docs/opendesign-billing.md +99 -93
- package/docs/performance-2026-10-18.json +1703 -1703
- package/docs/performance-2026-10-18.md +58 -58
- package/docs/update-notes-1.9.3.md +19 -0
- package/docs/update-notes-1.9.4.md +71 -0
- package/lib/client.codex.js +1 -1
- package/lib/client.display.js +2 -2
- package/lib/client.js +5 -5
- package/lib/client.peak.js +3 -0
- package/lib/client.pricing.js +14 -11
- package/lib/client.statistics.js +6 -5
- package/lib/codex-subscription-compat.js +23 -2
- package/lib/index.js +46 -28
- package/lib/model-statistics.js +34 -0
- package/lib/opendesign.js +16 -5
- package/lib/store.js +22 -5
- package/lib/typert.host.js +1063 -1058
- package/package.json +4 -2
|
@@ -1,58 +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 归因、环境和优化建议;本文的数据是本轮另行运行的隔离基准。
|
|
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,19 @@
|
|
|
1
|
+
# v1.9.3
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
- 修复 Codex 兼容提示关闭失败。×、Esc 和“保持现状”立即关闭弹窗,即使归类请求尚未返回或保存接口报错;关闭后不反复弹出,历史归类仍可在设置页手动执行。
|
|
6
|
+
- 修复热更新后 Codex 历史归类接口返回 HTTP 404。宿主保留旧接口清单时,只补注册缺失的兼容接口;卸载时撤销补注册,保留宿主原有注册。
|
|
7
|
+
- 修复 Codex 标签页空白,恢复版本、计费方式、历史用量和归类入口;加载失败可以重试,归类失败会显示错误。
|
|
8
|
+
- 概览卡片移除多余底部留白,保存状态靠右;计费统计先显示标题和数据,兼容说明及 dsh-context 设置合并为默认折叠的一行。
|
|
9
|
+
|
|
10
|
+
历史归类读取本地账本,不依赖 Codex API Key。安装本版不会自动重算历史费用。更新后完全退出并重新打开 DSH,以加载完整的宿主与前端代码。
|
|
11
|
+
|
|
12
|
+
## English
|
|
13
|
+
|
|
14
|
+
- The Codex compatibility prompt closes immediately with ×, Esc, or Keep status quo, including while a request is pending or fails. Dismissal is retained locally; historical reclassification remains available in settings.
|
|
15
|
+
- Fixed HTTP 404 after hot updates when the host retains an older RPC manifest. Only missing compatibility endpoints are registered, with cleanup tied to the plugin lifetime.
|
|
16
|
+
- Fixed the blank Codex tab, restored usage and reclassification controls, and added visible action errors and load retry.
|
|
17
|
+
- Removed excess spacing from overview cards and placed optional compatibility controls in a collapsed row below the statistics heading.
|
|
18
|
+
|
|
19
|
+
Historical reclassification uses the local ledger and does not require a Codex API key. Updating does not automatically recalculate historical costs. Fully quit and reopen DSH after updating.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# v1.9.4
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
本版将本地 `1.9.4-preview.6` 的定价、显示和统计改动,以及已合并的 OpenDesign / Codex 修复一起正式发布。
|
|
6
|
+
|
|
7
|
+
### 定价列表与模型统计
|
|
8
|
+
|
|
9
|
+
- **设置 → 费用 → 价格 → 模型定价**改为固定顺序的紧凑列表。输入、缓存读取和输出单价对齐显示,详细编辑按需展开;切换自动匹配、自定义或指定价格表时,模型保留原位置。
|
|
10
|
+
- 选择自定义价格后,只滚动一次到编辑区开头并聚焦首个价格字段。自动保存、修改单价或切换币种时不重新滚动、不抢焦点。
|
|
11
|
+
- 每个渠道下的模型可以分别选择是否计入**今日费用、月度与累计费用、预算**。取消勾选仅影响对应汇总,保留原始调用、历史金额和价格记录;重新勾选即可恢复。不同汇总选择了不同模型时,金额也会不同。
|
|
12
|
+
|
|
13
|
+
### 显示设置与峰谷时段
|
|
14
|
+
|
|
15
|
+
- 预算、今日用量、峰谷时段和模型花费可以独立显示,不再互相依赖。修复只开启峰谷、套餐、自定义余额或网关额度时侧栏未挂载的问题。
|
|
16
|
+
- 常用显示开关直接放在显示页。套餐的显示位置和账户选择在同一面板调整,凭据与查询参数仍在额度页,可从显示页直接跳转到对应账户。
|
|
17
|
+
- 峰谷时段新增**进度条**样式,显示当前计价时段的时间进度;可选择倒计时、切换时间或同时显示。原细条和分段样式保留,首次介绍可以关闭或选择保留原样。
|
|
18
|
+
- 显示预览与真实侧栏共用组件,支持当前缓存或示例数据。预览不启用账户查询、不调用模型、不写入示例账单。
|
|
19
|
+
|
|
20
|
+
### OpenDesign 与 Codex
|
|
21
|
+
|
|
22
|
+
- 修复 OpenDesign Control Key 无法保存和旧配置密钥未迁移的问题;正确显示 `VELA_CONTROL_KEY` 等有效凭据来源。
|
|
23
|
+
- 额度或钱包一侧失败时,保留可用数据并在设置卡片、侧栏提示和手动刷新结果中显示原因。无生效套餐时仍可显示经过校验的 preflight 余额;工作区或成员身份不一致时不混用数据。
|
|
24
|
+
- Codex 额度支持订阅插件的 **5 小时 / 7 天**双窗口,提供自动检测、订阅插件、connect 三种来源选择。切换来源后,旧请求不会覆盖新来源;订阅查询使用宿主 Connection RPC。
|
|
25
|
+
- Codex 兼容页签和提示跟随订阅插件的实际启用状态。仅安装但停用、依赖未就绪或已卸载时隐藏;历史归类仍需主动执行。
|
|
26
|
+
|
|
27
|
+
### 更新与验证
|
|
28
|
+
|
|
29
|
+
完全退出 DSH(包括托盘)后重新打开,加载新的宿主代码与前端模块。从 npm 更新:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
dsh plugin --profile desktop add dsh-cost-meter@1.9.4
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
桌面端应使用应用自带的 CLI,具体路径见 [Desktop 安装说明](install-troubleshooting.md#desktop-安装与更新)。Web 用户将 profile 改为 `web`。
|
|
36
|
+
|
|
37
|
+
本版不自动重算历史费用。合并后的完整回归、真实浏览器中的显示设置、定价列表顺序和自定义编辑定位检查通过。OpenDesign 另已通过真实 DSH 本地凭据库验证;认证查询使用模拟响应,没有使用真实 OpenDesign 账户或调用付费模型。
|
|
38
|
+
|
|
39
|
+
感谢 [@lewispumpkin 在 PR #316](https://github.com/Han-1413141/dsh-cost-meter/pull/316) 贡献 Codex 双窗口与来源选择接入;感谢 [@unifilitence 在 issue #317](https://github.com/Han-1413141/dsh-cost-meter/issues/317) 报告并定位 OpenDesign 凭据保存映射遗漏。
|
|
40
|
+
|
|
41
|
+
## English
|
|
42
|
+
|
|
43
|
+
This release ships the pricing, display and statistics changes previewed in `1.9.4-preview.6`, together with the merged OpenDesign and Codex fixes.
|
|
44
|
+
|
|
45
|
+
### Pricing and per-model statistics
|
|
46
|
+
|
|
47
|
+
- **Settings → Cost → Prices → Model pricing** uses one compact list with a stable model order and aligned input, cache-read and output rates. Editors expand on demand; changing a price source keeps the model in place.
|
|
48
|
+
- Selecting a custom price scrolls once to the editor and focuses its first field. Autosave, price edits and currency changes preserve scroll position and focus.
|
|
49
|
+
- Each channel/model can independently participate in **today's costs, monthly/all-time totals and budgets**. Exclusions affect only the selected summary; original calls, historical amounts and prices remain. Re-enable a model to restore its contribution. Summaries with different model selections can show different amounts.
|
|
50
|
+
|
|
51
|
+
### Display and peak/off-peak hours
|
|
52
|
+
|
|
53
|
+
- Budget, today's usage, peak/off-peak hours and model costs can appear independently. Fixed the sidebar failing to mount when only peak hours, plan quotas, a custom balance or gateway quota is enabled.
|
|
54
|
+
- Common switches are available directly in Display. Plan placement and account selection share one inspector, with a link to that account's credentials and query settings in Quotas.
|
|
55
|
+
- A new **progress** style shows elapsed time in the current pricing period, with countdown, switch time or both. Existing thin and segmented styles remain available. The one-time introduction can be dismissed without changing the style.
|
|
56
|
+
- Display previews share the real sidebar components and can use cached or sample data. Sample previews do not start account queries, call models or write example bills.
|
|
57
|
+
|
|
58
|
+
### OpenDesign and Codex
|
|
59
|
+
|
|
60
|
+
- Fixed saving the OpenDesign Control Key and migrating legacy keys. Credential indicators now recognize valid aliases such as `VELA_CONTROL_KEY`.
|
|
61
|
+
- Partial quota/wallet failures preserve usable data and display the reason. A validated preflight balance remains available without an active subscription; mismatched workspace/member identities are rejected.
|
|
62
|
+
- Codex quota supports the subscription plugin's **5-hour and 7-day** windows and selectable auto/subscription/connect sources. Late requests cannot overwrite a newly selected source. Subscription queries use the host Connection RPC.
|
|
63
|
+
- Codex compatibility controls follow the subscription plugin's active runtime status. Inactive, unavailable or removed peers no longer leave a visible compatibility tab. Historical reclassification remains an explicit action.
|
|
64
|
+
|
|
65
|
+
### Updating and validation
|
|
66
|
+
|
|
67
|
+
Fully quit DSH, including its tray process, and reopen it after updating. Use the application's own CLI for the Desktop profile; see [Desktop installation](install-troubleshooting.md#desktop-安装与更新). This release does not automatically reprice historical calls.
|
|
68
|
+
|
|
69
|
+
The integrated regression suite and real-browser display/pricing checks passed. OpenDesign credentials were also tested with the real DSH local credential provider; authenticated HTTP responses were simulated, without a live OpenDesign account or paid model call.
|
|
70
|
+
|
|
71
|
+
Thanks to [@lewispumpkin for PR #316](https://github.com/Han-1413141/dsh-cost-meter/pull/316), which contributed Codex quota windows and source selection, and [@unifilitence for issue #317](https://github.com/Han-1413141/dsh-cost-meter/issues/317), which reported and located the missing OpenDesign credential mapping.
|
package/lib/client.codex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:A=>{const k=A("react"),{createElement:e,useState:C,useEffect:g,useRef:h}=k,D="cm-stat-dialog cm-codex-compat-dialog";if(typeof document<"u"){const t=document.createElement("style");t.textContent=".cm-codex-compat-dialog{width:min(560px,94vw)}.cm-codex-compat{display:flex;flex-direction:column;gap:8px;font-size:13px}.cm-codex-compat :is(h3,p){margin:0}.cm-codex-compat h3{font-size:14px;font-weight:600}",t.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(t)}const v="dsh-cost-meter:codex-compat-prompt-dismissed",b=new Set;let w=!1;function I(){if(w)return!0;try{return window.localStorage.getItem(v)==="1"}catch{return!1}}function _(){w=!0;try{window.localStorage.setItem(v,"1")}catch{}for(const t of b)t(!0)}function N(){const[t,y]=C(!1),[s,d]=C(null),c=h(!1);return[t,s,l=>{c.current||(c.current=!0,y(!0),d(null),Promise.resolve().then(l).catch(n=>d(n?.message??String(n))).finally(()=>{c.current=!1,y(!1)}))}]}function P(t){const s=t.state?.codexCompat,d=t.api,c=t.locale==="en",a=(f,L)=>c?L:f,l=h(null),[n,m,o]=N(),[i,r]=C(I),p=s?.enabled===!0&&s?.promptDue===!0&&!i;if(g(()=>(b.add(r),()=>b.delete(r)),[]),g(()=>{p&&l.current&&!l.current.open&&l.current.showModal()},[p]),!p)return null;const u=s.usage??{},x=()=>{l.current?.close(),r(!0),_(),Promise.resolve().then(()=>d.dismissCodexCompat()).catch(()=>{})};return e("dialog",{ref:l,className:D,"aria-label":a("兼容修复","Compatibility fix"),onCancel:f=>{f.preventDefault(),x()}},e("header",{className:"cm-stat-dialog-head"},a("兼容修复","Compatibility fix"),e("button",{type:"button",className:"cm-btn","aria-label":a("关闭","Close"),onClick:x},"×")),e("div",{className:"cm-stat-dialog-body"},e("p",null,a("检测到 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"+(s.version??""))),u.calls>0?e("p",{className:"cm-note"},a("历史 Codex 用量:{calls} 次调用 · {cost} · {days} 天","Historical Codex usage: {calls} calls · {cost} · {days} days").replace("{calls}",u.calls).replace("{cost}","$"+Number(u.cost??0).toFixed(2)).replace("{days}",u.days)):null,m?e("div",{className:"cm-msg err"},a("失败:","Failed: ")+m):null,e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",onClick:x},a("保持现状","Keep status quo")),e("button",{type:"button",className:"cm-btn primary",disabled:n,onClick:()=>o(d.applyCodexCompatHistory)},a("统一归类为 Plan","Reclassify as Plan"))),e("p",{className:"cm-note"},a("之后可在 设置 → 费用 → Codex 订阅兼容 中处理。","You can change this later in Settings → Cost → Codex subscription compatibility."))))}function S(t){const s=t.state?.codexCompat,[d,c,a]=N();if(s?.installed!==!0||s?.enabled!==!0)return null;const l=t.api,n=t.t,m=t.locale==="en",o=(u,x)=>m?x:u,i=s.usage??{},r=s.historyAppliedAt>0,p=s.planClass==="plan"?n("billingClassPlan"):s.planClass==="api"?n("billingClassApi"):n("billingClassAuto");return e("div",{className:"cm-codex-compat"},e("h3",null,o("Codex 订阅兼容","Codex subscription compatibility")),e("p",null,o("检测版本:{version}","Detected version: {version}").replace("{version}","v"+(s.version??""))),e("p",null,o("当前计费方式:{planClass}","Current billing class: {planClass}").replace("{planClass}",p)),e("p",null,o("历史用量:{calls} 次调用 · {cost} · {tokens} tokens · {days} 天","Historical usage: {calls} calls · {cost} · {tokens} tokens · {days} days").replace("{calls}",i.calls).replace("{cost}","$"+Number(i.cost??0).toFixed(2)).replace("{tokens}",Number(i.tokens??0).toLocaleString(m?"en-US":"zh-CN")).replace("{days}",i.days)),c?e("div",{className:"cm-msg err",role:"alert"},o("失败:","Failed: ")+c):null,r?e("p",{className:"cm-note"},o("已归类于 {time}","Reclassified at {time}").replace("{time}",new Date(s.historyAppliedAt).toLocaleString())):e("p",null,o("历史用量未归类。","Historical usage is not reclassified yet.")),!r&&i.providers?.length?e("p",{className:"cm-note"},o("来源:{providers}","Sources: {providers}").replace("{providers}",i.providers.join(", "))):null,r?null:e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn primary",disabled:d,onClick:()=>a(l.applyCodexCompatHistory)},o("统一归类为 Plan","Reclassify as Plan"))),!r&&s.promptDismissed===!0?e("p",{className:"cm-note"},o("此前选择保持现状,可随时统一归类。","You chose Keep status quo earlier; you can reclassify anytime.")):null)}function E(){return t=>e(t.view==="prompt"?P:S,t)}return{mount:E,CodexCompatPrompt:P,CodexCompatPanel:S}}});
|