@pinkbanana/dsh-balance 0.16.0 → 0.17.3
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 +10 -7
- package/README_EN.md +11 -8
- package/docs/estimates.en.md +4 -4
- package/docs/estimates.md +4 -4
- package/lib/client.js +189 -56
- package/lib/client.js.map +1 -1
- package/lib/index.js +27 -1
- package/lib/index.js.map +1 -1
- package/lib/types/advice.d.ts +6 -1
- package/lib/types/client/AdviceCard.d.ts +4 -1
- package/lib/types/client/BalanceDock.d.ts +4 -0
- package/lib/types/client/locales.d.ts +7 -0
- package/lib/types/client/styles.d.ts +1 -1
- package/lib/types/pricing.d.ts +2 -0
- package/package.json +18 -15
package/README.md
CHANGED
|
@@ -38,9 +38,9 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额,以及 De
|
|
|
38
38
|
|
|
39
39
|
## 兼容性
|
|
40
40
|
|
|
41
|
-
插件 `0.
|
|
41
|
+
插件 `0.16.1` 支持 DSH **`>=0.2.1-rc.3 <1.0.0-0`**,需要 Node.js **24.9+**。DSH 的安装和启动检查将预发布版本纳入匹配,范围内无需添加版本豁免。DSH peer 依赖也显式涵盖 `0.2.2-rc.1` 起的 `0.2.2` 预发布版,以及 `0.2.3` 预发布版(`0.2.3-alpha.1` 起,已确认包含 `0.2.3-alpha.3`),以便包管理器使用标准 semver 规则解析这些版本。Cordis peer 范围为 `^4.0.5`。React / React DOM peer 范围为 `^18.2.0 || ^19.0.0`,以同时支持 DSH 0.2.2(React 18)和 0.2.3(React 19)。开发依赖仍固定在 DSH `0.2.2-rc.1`、Cordis `~4.1.0` 和 React 18,以保持构建可复现,且不中断对 React 18 宿主的支持。
|
|
42
42
|
|
|
43
|
-
已在 DSH `0.2.1-rc.3` 和 `0.2.2-rc.5` 的 Web profile
|
|
43
|
+
已在 DSH `0.2.1-rc.3` 和 `0.2.2-rc.5` 的 Web profile 验证安装和启动。对 DSH `0.2.3-alpha.3`,本版本通过 peer/semver 测试、API 兼容检查和会话计费夹具验证(完整 GUI 启动未在本环境执行)。仍使用 DSH `0.2.1-rc.2` 的用户可使用插件 `0.11.0`,DSH `0.2.0-rc.2` 的用户可使用插件 `0.10.2`。
|
|
44
44
|
|
|
45
45
|
也可在本地构建并打包源码,再用 `dsh plugin --profile web add /absolute/path/to/package.tgz` 安装生成的 `.tgz` 文件,随后重启 Harness:
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ pnpm install --frozen-lockfile
|
|
|
49
49
|
pnpm pack
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
消费统计通过 `SessionPersistence` 的只读会话句柄读取(包括官方 SQLite 存储,以及闲置归档后再次打开的会话),以 `inheritedEventCount` 排除分叉、子智能体和 `/side` 侧栏会话从父会话继承的记录,避免与父会话重复计费;会话页在 token 用量变化或一轮运行结束后刷新;统计页面每 15 秒检查更新,重新聚焦或返回页面时刷新,隐藏页面暂停查询。兼容 `assistant/message` 和重试/取消请求的 `assistant/attempt`,读取最后一条 stream usage,并以重试边界区分独立请求,同一次请求的重复结算仅计一次。
|
|
53
53
|
|
|
54
54
|
全局统计会跳过当前 dsh 无法读取的旧格式或损坏会话,并显示未纳入统计的会话数量;其余会话仍正常统计。部分汇总结果不缓存,下次刷新会重试失败会话;已成功读取且 revision 未变化的会话复用精简用量记录。单个会话无法读取或所有会话都读取失败时,仍明确显示读取错误,不将失败记录当作零消费。
|
|
55
55
|
|
|
@@ -155,11 +155,11 @@ providers:
|
|
|
155
155
|
|
|
156
156
|
## 下轮费用估算
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
会话「消费」页会展示下轮费用估算卡片;在用量统计里点击会话名下钻时也会看到同一卡片。聊天框下方的余额摘要可按需展开该估算,默认收起以免占用空间。同一标签页内的导航(包括切换会话或模型)会记住展开或收起;刷新或关闭标签页后仍默认收起。
|
|
159
159
|
|
|
160
|
-
卡片对照四种下一步的费用:当前时段继续、等待下个峰谷切换、现在 `/compact`(摘要请求 + 压缩后首轮;摘要约 4,000 tokens,至多历史的四分之一),以及新开会话(全部未命中缓存),并显示继续本会话相对新开因缓存可节省的费用。也可对照本 Harness
|
|
160
|
+
卡片对照四种下一步的费用:当前时段继续、等待下个峰谷切换、现在 `/compact`(摘要请求 + 压缩后首轮;摘要约 4,000 tokens,至多历史的四分之一),以及新开会话(全部未命中缓存),并显示继续本会话相对新开因缓存可节省的费用。也可对照本 Harness 已配置且可计价的其他官方模型。当前模型下最便宜的一步会标上“最便宜”(按单轮费用比较,因此 `/compact` 很少在单轮胜出)。仅为估算,不会自动压缩或换模型。
|
|
161
161
|
|
|
162
|
-
估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 /
|
|
162
|
+
估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。没有已计价样本或估算加载失败时,卡片会说明原因,并提示重新估算或打开用量统计。完整计算说明、峰谷规则和局限见 [估算是怎么算的](./docs/estimates.md)。
|
|
163
163
|
|
|
164
164
|

|
|
165
165
|
|
|
@@ -176,7 +176,7 @@ providers:
|
|
|
176
176
|
|
|
177
177
|
- `src/providers.ts` 保存可在前后端共享的 provider 元数据;`src/balance.ts` 的 adapter 表只负责端点与响应解析,传输、错误分类和缓存由公共逻辑处理。
|
|
178
178
|
- `GET /dsh-balance/api/balance?provider=StepFun` 查询 StepFun;省略 provider 保持 DeepSeek 兼容,`refresh=1` 绕过对应缓存。不支持的 provider 返回 `UNSUPPORTED_PROVIDER`。
|
|
179
|
-
- `GET /dsh-balance/api/advice?session=…` 返回当前会话的下轮费用估算(也可用 `sessionId`);可选 `provider`、`model` 与重复的 `compare=provider:model`。响应不含 prompt 内容。
|
|
179
|
+
- `GET /dsh-balance/api/advice?session=…` 返回当前会话的下轮费用估算(也可用 `sessionId`);可选 `provider`、`model`、`refresh=1` 与重复的 `compare=provider:model`。响应不含 prompt 内容。
|
|
180
180
|
- 通过原生 `sidebar.panellist` 与 `main` 插槽接入侧栏和主页面,菜单、选中态、侧栏折叠和页面导航由 Harness 管理;插件使用 Harness 的颜色、圆角和布局变量,支持深浅色主题与窄屏。
|
|
181
181
|
|
|
182
182
|
## 开发
|
|
@@ -184,9 +184,12 @@ providers:
|
|
|
184
184
|
```bash
|
|
185
185
|
pnpm install
|
|
186
186
|
pnpm check
|
|
187
|
+
pnpm check-prices
|
|
187
188
|
pnpm preview
|
|
188
189
|
```
|
|
189
190
|
|
|
191
|
+
`pnpm check-prices` 会抓取 DeepSeek(中/英)、StepFun 官方定价页和 Tokener 公开目录,与内置费率表比对;不在 `pnpm check` 里运行,以免依赖外网。工作日定时工作流发现模型、费率、低谷窗口或节假日日历有实质差异时会开 issue;仅 Tokener `catalogRevision` 哈希变化不会判失败。
|
|
192
|
+
|
|
190
193
|
预览不使用真实密钥。可使用 `?page=session` 检查会话消费页与下轮估算卡片(124 次 StepFun 请求、7,161,128 tokens;预览夹具含现在 /compact),使用 `?page=usage` 查看独立统计页并下钻会话,使用 `?page=usage&lang=en&theme=dark` 或 `?lang=zh-tw` 检查英文、繁体中文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换与可展开的估算。估算计算说明见 [估算是怎么算的](./docs/estimates.md)。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。实时模型余额和统计修复自 `0.7.0` 起提供。
|
|
191
194
|
|
|
192
195
|
## License
|
package/README_EN.md
CHANGED
|
@@ -36,9 +36,9 @@ The composer readout follows the current session’s provider and model. The Set
|
|
|
36
36
|
|
|
37
37
|
## Compatibility
|
|
38
38
|
|
|
39
|
-
Plugin `0.
|
|
39
|
+
Plugin `0.16.1` supports DSH **`>=0.2.1-rc.3 <1.0.0-0`** and requires Node.js **24.9+**. DSH includes prereleases in its install and startup checks. Versions in this range require no exemption. The DSH peer ranges explicitly include `0.2.2` prereleases starting at `0.2.2-rc.1` and `0.2.3` prereleases starting at `0.2.3-alpha.1` (confirmed to admit `0.2.3-alpha.3`), so package managers can resolve them under standard semver rules. The Cordis peer range is `^4.0.5`. The React / React DOM peer range is `^18.2.0 || ^19.0.0`, so the plugin can load on DSH 0.2.2 (React 18) and DSH 0.2.3 (React 19). Development dependencies remain pinned to DSH `0.2.2-rc.1`, Cordis `~4.1.0`, and React 18 for reproducible builds, without dropping React 18 hosts.
|
|
40
40
|
|
|
41
|
-
Installation and startup were verified with the web profile on DSH `0.2.1-rc.3` and `0.2.2-rc.5`. For DSH `0.2.1-rc.2`, use plugin `0.11.0`. For DSH `0.2.0-rc.2`, use plugin `0.10.2`.
|
|
41
|
+
Installation and startup were verified with the web profile on DSH `0.2.1-rc.3` and `0.2.2-rc.5`. Compatibility with DSH `0.2.3-alpha.3` is covered by peer/semver tests, API checks, and session-billing fixtures (a full GUI start was not run in this environment). For DSH `0.2.1-rc.2`, use plugin `0.11.0`. For DSH `0.2.0-rc.2`, use plugin `0.10.2`.
|
|
42
42
|
|
|
43
43
|
To install from source, build and pack it locally, then pass the generated `.tgz` path to `dsh plugin --profile web add /absolute/path/to/package.tgz` and restart Harness:
|
|
44
44
|
|
|
@@ -47,7 +47,7 @@ pnpm install --frozen-lockfile
|
|
|
47
47
|
pnpm pack
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Usage reads
|
|
50
|
+
Usage reads current read-only `SessionPersistence` handles — including the official SQLite session store and idle-archived sessions after they are reopened — and uses `inheritedEventCount` to exclude events a fork, subagent, or `/side` sidebar branch inherited from its parent, so that usage is not double-counted. The conversation tab refreshes when token usage changes or a turn finishes.
|
|
51
51
|
|
|
52
52
|
Global statistics skip sessions that the current dsh cannot read, such as unsupported historical formats or damaged logs, and show how many sessions were excluded. Partial summaries are retried on the next refresh; unchanged successful sessions reuse compact usage records while failed sessions are retried. An unreadable selected session, or a collection where every session fails to read, still reports an error instead of showing zero usage.
|
|
53
53
|
|
|
@@ -151,11 +151,11 @@ Built-in estimates use [official DeepSeek USD rates](https://api-docs.deepseek.c
|
|
|
151
151
|
|
|
152
152
|
## Next-turn estimates
|
|
153
153
|
|
|
154
|
-
The session Usage tab shows a next-turn estimate card; the same card appears when you drill into a session from Usage Statistics. The composer balance dock can expand the estimate on demand; it stays collapsed by default so it does not clutter the row.
|
|
154
|
+
The session Usage tab shows a next-turn estimate card; the same card appears when you drill into a session from Usage Statistics. The composer balance dock can expand the estimate on demand; it stays collapsed by default so it does not clutter the row. The tab remembers whether you left it open or closed while you navigate (including session or model switches); a refresh or closing the tab returns to the default collapsed state.
|
|
155
155
|
|
|
156
|
-
The card compares four next steps: continue in the current period, wait for the next peak change, **`/compact` now** (summarizer request plus the first post-compact turn; about 4,000 summary tokens, at most a quarter of the history), and a fresh session (all cache-miss), plus how much cache saves by continuing versus starting over. It can also compare other official models already configured in this Harness that can be priced. These are estimates only; nothing is compacted or switched automatically.
|
|
156
|
+
The card compares four next steps: continue in the current period, wait for the next peak change, **`/compact` now** (summarizer request plus the first post-compact turn; about 4,000 summary tokens, at most a quarter of the history), and a fresh session (all cache-miss), plus how much cache saves by continuing versus starting over. It can also compare other official models already configured in this Harness that can be priced. The cheapest of these four steps for the current model gets a “Cheapest” badge (single-turn cost, so `/compact` rarely wins one turn). These are estimates only; nothing is compacted or switched automatically.
|
|
157
157
|
|
|
158
|
-
The token shape is the per-bucket median of the session’s most recent 8 priced requests (uncached input, cache read, cache write, output), priced through the same billing engines as usage totals rather than a second pricing path. The next turn may not match, for example after compaction, a large paste, or vision input. The full method, peak-hour rules, and limitations are in [How estimates are computed](./docs/estimates.en.md).
|
|
158
|
+
The token shape is the per-bucket median of the session’s most recent 8 priced requests (uncached input, cache read, cache write, output), priced through the same billing engines as usage totals rather than a second pricing path. The next turn may not match, for example after compaction, a large paste, or vision input. When there is no priced sample or the estimate fails to load, the card explains why and suggests refreshing or opening Usage. The full method, peak-hour rules, and limitations are in [How estimates are computed](./docs/estimates.en.md).
|
|
159
159
|
|
|
160
160
|

|
|
161
161
|
|
|
@@ -174,7 +174,7 @@ The local read-only route is `GET /dsh-balance/api/advice?session=…` (`session
|
|
|
174
174
|
|
|
175
175
|
- `src/providers.ts` holds shared provider metadata. The adapter table in `src/balance.ts` defines endpoints and response parsers; transport, errors, and caching are shared.
|
|
176
176
|
- `GET /dsh-balance/api/balance?provider=StepFun` selects StepFun. Omitting provider preserves DeepSeek compatibility; `refresh=1` bypasses that provider's cache. Unknown providers return `UNSUPPORTED_PROVIDER`.
|
|
177
|
-
- `GET /dsh-balance/api/advice?session=…` returns the next-turn estimate for a session (`sessionId` is also accepted), with optional `provider`, `model`, and repeated `compare=provider:model`. The response never includes prompt text.
|
|
177
|
+
- `GET /dsh-balance/api/advice?session=…` returns the next-turn estimate for a session (`sessionId` is also accepted), with optional `provider`, `model`, `refresh=1`, and repeated `compare=provider:model`. The response never includes prompt text.
|
|
178
178
|
- The layout draws on [Codrops' Kononenko case study](https://tympanus.net/codrops/2026/09/18/kononenko-architectural-bureau/): oversized type, negative space, architectural grids, and geometric linework, implemented in original CSS with light/dark themes, narrow layouts, and reduced-motion support.
|
|
179
179
|
|
|
180
180
|
## Development
|
|
@@ -182,9 +182,12 @@ The local read-only route is `GET /dsh-balance/api/advice?session=…` (`session
|
|
|
182
182
|
```bash
|
|
183
183
|
pnpm install
|
|
184
184
|
pnpm check
|
|
185
|
+
pnpm check-prices
|
|
185
186
|
pnpm preview
|
|
186
187
|
```
|
|
187
188
|
|
|
189
|
+
`pnpm check-prices` fetches the official DeepSeek (zh/en) and StepFun pricing pages plus Tokener's public catalog and diffs them against the built-in tables. It is not part of `pnpm check`, so CI does not depend on those sites. A weekday workflow opens an issue when models, rates, off-peak windows or holiday dates drift; a Tokener `catalogRevision` hash change alone does not fail the check.
|
|
190
|
+
|
|
188
191
|
The preview uses no real credentials. Use `?page=session` for the conversation usage view and next-turn estimate card (the fixture includes compact now), or `?page=usage` for the statistics overview and session drill-down. Add `?lang=en&theme=dark` or `?lang=zh-tw` for English, Traditional Chinese, and dark mode, or `?state=missing`, `error`, `empty`, or `loading` to inspect those states. The sample model selector also exercises the composer readout and the expandable estimate. See [How estimates are computed](./docs/estimates.en.md) for the method. StepFun balance and model queries and the redesigned account page are available starting with `0.6.0`. Live model balances, and usage accounting fixes are available starting with `0.7.0`.
|
|
189
192
|
|
|
190
193
|
## License
|
|
@@ -197,7 +200,7 @@ The preview uses no real credentials. Use `?page=session` for the conversation u
|
|
|
197
200
|
|
|
198
201
|
A **Usage Statistics** entry below **Plugins** in the native sidebar opens a standalone page. It defaults to all providers and all time, with provider/date-range filters and breakdowns by provider, model, session, and day. Native `sidebar.panellist` and `main` slots keep navigation, collapsed sidebar behavior, and active styling consistent with Harness. Plugin surfaces use Harness theme colors and radii.
|
|
199
202
|
|
|
200
|
-
Usage includes completed messages and failed, retried, or cancelled attempts with a reported stream usage sample. The final sample wins within an attempt; retry boundaries count separate calls. Inherited fork events are excluded. Open statistics refresh every 15 seconds and on focus/visibility return, without polling hidden pages. Manual refresh also populates the normal revision cache. Unknown prices remain unpriced.
|
|
203
|
+
Usage includes completed messages and failed, retried, or cancelled attempts with a reported stream usage sample. The final sample wins within an attempt; retry boundaries count separate calls. Inherited fork, subagent, and `/side` branch events are excluded. Open statistics refresh every 15 seconds and on focus/visibility return, without polling hidden pages. Manual refresh also populates the normal revision cache. Unknown prices remain unpriced.
|
|
201
204
|
|
|
202
205
|
Run `pnpm preview` and open `?page=usage` (or `?page=usage&lang=en&theme=dark`) to inspect the fixture page.
|
|
203
206
|
|
package/docs/estimates.en.md
CHANGED
|
@@ -15,7 +15,7 @@ Estimates use only this session’s **most recent 8 priced requests** (or all of
|
|
|
15
15
|
|
|
16
16
|
The four medians are independent, so the synthetic “typical turn” may not match any single historical request. The next turn may also differ after compaction, a large paste, or vision input.
|
|
17
17
|
|
|
18
|
-
If the session has no priced requests, the card
|
|
18
|
+
If the session has no priced requests, the current model cannot be priced, or the estimate fails to load, the card and the composer dock explain why and suggest refreshing or opening Usage. They do not show $0.
|
|
19
19
|
|
|
20
20
|
## The four next steps
|
|
21
21
|
|
|
@@ -40,8 +40,8 @@ Plans, discounts, account-specific rates, or unrecorded historical price changes
|
|
|
40
40
|
## Where to find it
|
|
41
41
|
|
|
42
42
|
- The current session’s Usage tab, and the usage-page drill-down after you click a session name, both show the full estimate card.
|
|
43
|
-
- The balance dock under the composer can expand the same estimate on demand; it stays collapsed by default.
|
|
44
|
-
- Local read-only API: `GET /dsh-balance/api/advice?session=…` (`sessionId` is also accepted; optional `provider`, `model`, and repeated `compare=provider:model`). Loopback only; the payload never includes prompt or session text.
|
|
43
|
+
- The balance dock under the composer can expand the same estimate on demand; it stays collapsed by default. The tab remembers the open/closed state while you navigate; a refresh or closing the tab returns to the default.
|
|
44
|
+
- Local read-only API: `GET /dsh-balance/api/advice?session=…` (`sessionId` is also accepted; optional `provider`, `model`, `refresh=1`, and repeated `compare=provider:model`). Loopback only; the payload never includes prompt or session text.
|
|
45
45
|
|
|
46
46
|
This version has **no** agent tool the model can call. A read-only `dsh_balance_advise` tool is still on the [roadmap](../ROADMAP.md). Until then, use the UI or the local HTTP route above.
|
|
47
47
|
|
|
@@ -51,4 +51,4 @@ Local preview (no credentials):
|
|
|
51
51
|
pnpm preview
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
Then open `?page=session` for the conversation usage view and advisor card, or `?page=usage` for the statistics overview and session drill-down. Add `&lang=en`, `&lang=zh-tw`, or `&theme=dark` as needed.
|
|
54
|
+
Then open `?page=session` for the conversation usage view and advisor card, or `?page=usage` for the statistics overview and session drill-down. Add `&lang=en`, `&lang=zh-tw`, or `&theme=dark` as needed. Empty and error guidance: `&advice=empty`, `&advice=unpriced`, or `&advice=error`.
|
package/docs/estimates.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
四个桶的中位数是独立计算的,因此合成的「典型一轮」可能与任何单次历史请求都不完全相同。下轮实际用量也可能不同,例如上下文压缩、大段粘贴或视觉输入。
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
没有已计费请求、当前模型无法计价,或估算暂时加载失败时,卡片和余额条会说明原因,并提示重新估算或打开用量统计查看请求,而不会把费用显示为 $0。
|
|
19
19
|
|
|
20
20
|
## 四种下一步
|
|
21
21
|
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
## 在哪里查看
|
|
41
41
|
|
|
42
42
|
- 当前会话的「消费」页,以及用量统计里点击会话名后的下钻页,都会显示完整估算卡片。
|
|
43
|
-
-
|
|
44
|
-
- 本机只读接口:`GET /dsh-balance/api/advice?session=…`(也可用 `sessionId`;可选 `provider`、`model` 与重复的 `compare=provider:model`)。仅本机可访问,响应不含 prompt 或会话正文。
|
|
43
|
+
- 聊天框下方的余额条可按需展开同一估算,默认收起;同一标签页内会记住展开或收起,刷新或关闭标签页后恢复默认收起。
|
|
44
|
+
- 本机只读接口:`GET /dsh-balance/api/advice?session=…`(也可用 `sessionId`;可选 `provider`、`model`、`refresh=1` 与重复的 `compare=provider:model`)。仅本机可访问,响应不含 prompt 或会话正文。
|
|
45
45
|
|
|
46
46
|
本版本**没有**可供模型调用的 agent tool。只读的 `dsh_balance_advise` 仍在[路线图](../ROADMAP.md)中;在此之前,请使用上面的界面或本机 HTTP 接口。
|
|
47
47
|
|
|
@@ -51,4 +51,4 @@
|
|
|
51
51
|
pnpm preview
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
然后打开 `?page=session` 查看会话消费页与估算卡片,或 `?page=usage` 查看统计总览并下钻到某个会话。可加 `&lang=en`、`&lang=zh-tw`、`&theme=dark`。
|
|
54
|
+
然后打开 `?page=session` 查看会话消费页与估算卡片,或 `?page=usage` 查看统计总览并下钻到某个会话。可加 `&lang=en`、`&lang=zh-tw`、`&theme=dark`。空态与失败引导可用 `&advice=empty`、`&advice=unpriced`、`&advice=error`。
|
package/lib/client.js
CHANGED
|
@@ -720,13 +720,10 @@ window.__ModuleLoader__.load({
|
|
|
720
720
|
if (converted !== null && estimate.costUsd !== null) parts.push(`${displayAmount(String(converted), "CNY", locale)} (${t("billing.fixedRate")})`);
|
|
721
721
|
return parts.length === 0 ? [t("advice.noEstimate")] : parts;
|
|
722
722
|
}
|
|
723
|
-
function formatCost(estimate, locale, rate, t) {
|
|
724
|
-
return formatCostParts(estimate, locale, rate, t).join(" · ");
|
|
725
|
-
}
|
|
726
723
|
/** Each amount stays on one line; long rows wrap between amounts, never inside "(fixed rate)". */
|
|
727
|
-
function CostText({ estimate, locale, usdToCny, t }) {
|
|
724
|
+
function CostText({ estimate, locale, usdToCny, t, inline = false }) {
|
|
728
725
|
const parts = formatCostParts(estimate, locale, usdToCny, t);
|
|
729
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
726
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(inline ? "span" : "strong", {
|
|
730
727
|
className: "dsh-advice-cost",
|
|
731
728
|
children: parts.map((part, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [index > 0 ? " · " : "", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
732
729
|
className: "dsh-advice-amount",
|
|
@@ -734,17 +731,53 @@ window.__ModuleLoader__.load({
|
|
|
734
731
|
})] }, index))
|
|
735
732
|
});
|
|
736
733
|
}
|
|
734
|
+
/** Hint for a successful response that still has no current-period estimate. */
|
|
735
|
+
function adviceMissingHintKey(advice) {
|
|
736
|
+
if (advice.coverage.status === "unpriced") return "advice.unpricedHint";
|
|
737
|
+
if (advice.now === void 0 && advice.sampleSize > 0) return "advice.unpricedHint";
|
|
738
|
+
if (advice.coverage.status === "free") return "advice.freeHint";
|
|
739
|
+
return "advice.emptyHint";
|
|
740
|
+
}
|
|
741
|
+
function RefreshButton({ loading, onRefresh, t }) {
|
|
742
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
743
|
+
type: "button",
|
|
744
|
+
className: "dsh-balance-refresh",
|
|
745
|
+
disabled: loading,
|
|
746
|
+
onClick: onRefresh,
|
|
747
|
+
children: loading ? t("advice.loading") : t("advice.refresh")
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
function AdviceNextStep({ compact, title, hint, loading, onRefresh, t }) {
|
|
751
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
752
|
+
className: `${compact ? "dsh-advice-dock" : "dsh-balance-status"} dsh-advice-guidance`,
|
|
753
|
+
role: "status",
|
|
754
|
+
children: [
|
|
755
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: title }),
|
|
756
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
757
|
+
className: "dsh-advice-hint",
|
|
758
|
+
children: hint
|
|
759
|
+
}),
|
|
760
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RefreshButton, {
|
|
761
|
+
loading,
|
|
762
|
+
onRefresh,
|
|
763
|
+
t
|
|
764
|
+
})
|
|
765
|
+
]
|
|
766
|
+
});
|
|
767
|
+
}
|
|
737
768
|
/** Session-shaped next-turn estimates. Prompt text is never requested or rendered. */
|
|
738
769
|
function AdviceCard({ sessionId, provider, model, loadAdvice, t, usdToCny = null, compact = false }) {
|
|
739
770
|
const [result, setResult] = (0, react.useState)();
|
|
740
771
|
const [loading, setLoading] = (0, react.useState)(true);
|
|
772
|
+
const [refreshNonce, setRefreshNonce] = (0, react.useState)(0);
|
|
741
773
|
(0, react.useEffect)(() => {
|
|
742
774
|
const controller = new AbortController();
|
|
743
775
|
setLoading(true);
|
|
744
776
|
loadAdvice({
|
|
745
777
|
sessionId,
|
|
746
778
|
...provider === void 0 ? {} : { provider },
|
|
747
|
-
...model === void 0 ? {} : { model }
|
|
779
|
+
...model === void 0 ? {} : { model },
|
|
780
|
+
...refreshNonce > 0 ? { forceRefresh: true } : {}
|
|
748
781
|
}, controller.signal).then((value) => {
|
|
749
782
|
if (!controller.signal.aborted) setResult(value);
|
|
750
783
|
}).catch(() => {
|
|
@@ -763,74 +796,105 @@ window.__ModuleLoader__.load({
|
|
|
763
796
|
loadAdvice,
|
|
764
797
|
sessionId,
|
|
765
798
|
provider,
|
|
766
|
-
model
|
|
799
|
+
model,
|
|
800
|
+
refreshNonce
|
|
767
801
|
]);
|
|
768
802
|
const locale = t("locale.tag");
|
|
803
|
+
const onRefresh = () => {
|
|
804
|
+
setRefreshNonce((value) => value + 1);
|
|
805
|
+
};
|
|
769
806
|
if (loading && result === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
770
807
|
className: compact ? "dsh-advice-dock" : "dsh-balance-status",
|
|
771
808
|
role: "status",
|
|
772
809
|
children: t("advice.loading")
|
|
773
810
|
});
|
|
774
|
-
if (result === void 0 || !result.ok) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
811
|
+
if (result === void 0 || !result.ok) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceNextStep, {
|
|
812
|
+
compact,
|
|
813
|
+
title: t("advice.unavailable"),
|
|
814
|
+
hint: t("advice.unavailableHint"),
|
|
815
|
+
loading,
|
|
816
|
+
onRefresh,
|
|
817
|
+
t
|
|
778
818
|
});
|
|
779
819
|
return compact ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CompactAdvice, {
|
|
780
820
|
advice: result,
|
|
781
821
|
t,
|
|
782
822
|
usdToCny,
|
|
783
|
-
locale
|
|
823
|
+
locale,
|
|
824
|
+
loading,
|
|
825
|
+
onRefresh
|
|
784
826
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PanelAdvice, {
|
|
785
827
|
advice: result,
|
|
786
828
|
t,
|
|
787
829
|
usdToCny,
|
|
788
|
-
locale
|
|
830
|
+
locale,
|
|
831
|
+
loading,
|
|
832
|
+
onRefresh
|
|
789
833
|
});
|
|
790
834
|
}
|
|
791
|
-
function CompactAdvice({ advice, t, usdToCny, locale }) {
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
835
|
+
function CompactAdvice({ advice, t, usdToCny, locale, loading, onRefresh }) {
|
|
836
|
+
if (advice.now === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceNextStep, {
|
|
837
|
+
compact: true,
|
|
838
|
+
title: t("advice.noEstimate"),
|
|
839
|
+
hint: t(adviceMissingHintKey(advice)),
|
|
840
|
+
loading,
|
|
841
|
+
onRefresh,
|
|
842
|
+
t
|
|
843
|
+
});
|
|
844
|
+
const items = [[
|
|
845
|
+
t("advice.now"),
|
|
846
|
+
advice.now,
|
|
847
|
+
advice.cheapest === "now"
|
|
848
|
+
]];
|
|
849
|
+
if (advice.afterChange !== void 0) items.push([
|
|
850
|
+
t("advice.afterChange"),
|
|
851
|
+
advice.afterChange,
|
|
852
|
+
advice.cheapest === "after-change"
|
|
853
|
+
]);
|
|
854
|
+
if (advice.fresh !== void 0) items.push([
|
|
855
|
+
t("advice.fresh"),
|
|
856
|
+
advice.fresh,
|
|
857
|
+
advice.cheapest === "fresh"
|
|
858
|
+
]);
|
|
859
|
+
if (advice.compact !== void 0) items.push([
|
|
860
|
+
t("advice.compact"),
|
|
861
|
+
advice.compact,
|
|
862
|
+
advice.cheapest === "compact"
|
|
863
|
+
]);
|
|
796
864
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
797
865
|
className: "dsh-advice-dock",
|
|
798
|
-
children: [
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
": ",
|
|
802
|
-
|
|
803
|
-
] }),
|
|
804
|
-
after === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
805
|
-
" · ",
|
|
806
|
-
t("advice.afterChange"),
|
|
807
|
-
": ",
|
|
808
|
-
after
|
|
809
|
-
] }),
|
|
810
|
-
fresh === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
811
|
-
" · ",
|
|
812
|
-
t("advice.fresh"),
|
|
813
|
-
": ",
|
|
814
|
-
fresh
|
|
815
|
-
] }),
|
|
816
|
-
compactCost === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
817
|
-
" · ",
|
|
818
|
-
t("advice.compact"),
|
|
866
|
+
children: [items.map(([label, estimate, best], index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
867
|
+
className: "dsh-advice-item",
|
|
868
|
+
children: [
|
|
869
|
+
index > 0 ? " · " : "",
|
|
870
|
+
label,
|
|
819
871
|
": ",
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
872
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostText, {
|
|
873
|
+
estimate,
|
|
874
|
+
locale,
|
|
875
|
+
usdToCny,
|
|
876
|
+
t,
|
|
877
|
+
inline: true
|
|
878
|
+
}),
|
|
879
|
+
best ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
880
|
+
className: "dsh-advice-best",
|
|
881
|
+
children: [" ", t("advice.cheapest")]
|
|
882
|
+
}) : null
|
|
883
|
+
]
|
|
884
|
+
}, label)), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
885
|
+
className: "dsh-advice-note",
|
|
886
|
+
children: t("advice.estimateOnly")
|
|
887
|
+
})]
|
|
827
888
|
});
|
|
828
889
|
}
|
|
829
|
-
function EstimateRow({ label, estimate, t, usdToCny, locale }) {
|
|
890
|
+
function EstimateRow({ label, estimate, t, usdToCny, locale, best = false }) {
|
|
830
891
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
831
|
-
className: "dsh-advice-row",
|
|
892
|
+
className: best ? "dsh-advice-row dsh-advice-row-best" : "dsh-advice-row",
|
|
832
893
|
children: [
|
|
833
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
894
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [label, best ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
895
|
+
className: "dsh-advice-best",
|
|
896
|
+
children: [" ", t("advice.cheapest")]
|
|
897
|
+
}) : null] }),
|
|
834
898
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostText, {
|
|
835
899
|
estimate,
|
|
836
900
|
locale,
|
|
@@ -847,7 +911,7 @@ window.__ModuleLoader__.load({
|
|
|
847
911
|
]
|
|
848
912
|
});
|
|
849
913
|
}
|
|
850
|
-
function PanelAdvice({ advice, t, usdToCny, locale }) {
|
|
914
|
+
function PanelAdvice({ advice, t, usdToCny, locale, loading, onRefresh }) {
|
|
851
915
|
const nextChange = advice.nextChangeAt === null ? void 0 : formatClockTime(new Date(advice.nextChangeAt), locale);
|
|
852
916
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
853
917
|
className: "dsh-advice-card",
|
|
@@ -884,10 +948,26 @@ window.__ModuleLoader__.load({
|
|
|
884
948
|
cacheWrite: displayTokens(advice.tokenShape.cacheWriteTokens, locale)
|
|
885
949
|
})
|
|
886
950
|
}),
|
|
887
|
-
advice.now === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.
|
|
888
|
-
className: "dsh-advice-
|
|
889
|
-
|
|
951
|
+
advice.now === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
952
|
+
className: "dsh-advice-guidance",
|
|
953
|
+
role: "status",
|
|
954
|
+
children: [
|
|
955
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
956
|
+
className: "dsh-advice-meta",
|
|
957
|
+
children: t("advice.noEstimate")
|
|
958
|
+
}),
|
|
959
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
960
|
+
className: "dsh-advice-meta dsh-advice-hint",
|
|
961
|
+
children: t(adviceMissingHintKey(advice))
|
|
962
|
+
}),
|
|
963
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RefreshButton, {
|
|
964
|
+
loading,
|
|
965
|
+
onRefresh,
|
|
966
|
+
t
|
|
967
|
+
})
|
|
968
|
+
]
|
|
890
969
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EstimateRow, {
|
|
970
|
+
best: advice.cheapest === "now",
|
|
891
971
|
label: t("advice.now"),
|
|
892
972
|
estimate: advice.now,
|
|
893
973
|
t,
|
|
@@ -895,6 +975,7 @@ window.__ModuleLoader__.load({
|
|
|
895
975
|
locale
|
|
896
976
|
}),
|
|
897
977
|
advice.afterChange === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EstimateRow, {
|
|
978
|
+
best: advice.cheapest === "after-change",
|
|
898
979
|
label: t("advice.afterChange"),
|
|
899
980
|
estimate: advice.afterChange,
|
|
900
981
|
t,
|
|
@@ -902,6 +983,7 @@ window.__ModuleLoader__.load({
|
|
|
902
983
|
locale
|
|
903
984
|
}),
|
|
904
985
|
advice.fresh === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EstimateRow, {
|
|
986
|
+
best: advice.cheapest === "fresh",
|
|
905
987
|
label: t("advice.fresh"),
|
|
906
988
|
estimate: advice.fresh,
|
|
907
989
|
t,
|
|
@@ -909,6 +991,7 @@ window.__ModuleLoader__.load({
|
|
|
909
991
|
locale
|
|
910
992
|
}),
|
|
911
993
|
advice.compact === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EstimateRow, {
|
|
994
|
+
best: advice.cheapest === "compact",
|
|
912
995
|
label: t("advice.compact"),
|
|
913
996
|
estimate: advice.compact,
|
|
914
997
|
t,
|
|
@@ -2945,6 +3028,23 @@ window.__ModuleLoader__.load({
|
|
|
2945
3028
|
//#region src/client/BalanceDock.tsx
|
|
2946
3029
|
const REFRESH_INTERVAL_MS = 6e4;
|
|
2947
3030
|
const PEAK_TICK_MS = 3e4;
|
|
3031
|
+
/** sessionStorage key for the composer-dock advisor open/closed state. */
|
|
3032
|
+
const ADVICE_DOCK_STORAGE_KEY = "dsh-balance:advice-dock-open";
|
|
3033
|
+
/** Read whether the composer-dock advisor was left open in this tab. */
|
|
3034
|
+
function readAdviceDockOpen() {
|
|
3035
|
+
try {
|
|
3036
|
+
return globalThis.sessionStorage?.getItem(ADVICE_DOCK_STORAGE_KEY) === "1";
|
|
3037
|
+
} catch {
|
|
3038
|
+
return false;
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
/** Persist the composer-dock advisor open/closed state for this tab. */
|
|
3042
|
+
function writeAdviceDockOpen(open) {
|
|
3043
|
+
try {
|
|
3044
|
+
if (open) globalThis.sessionStorage?.setItem(ADVICE_DOCK_STORAGE_KEY, "1");
|
|
3045
|
+
else globalThis.sessionStorage?.removeItem(ADVICE_DOCK_STORAGE_KEY);
|
|
3046
|
+
} catch {}
|
|
3047
|
+
}
|
|
2948
3048
|
/** Compact ambient balance readout below the active-session composer card. */
|
|
2949
3049
|
function BalanceDock({ selection, loadBalance, loadAdvice, t, sessionId }) {
|
|
2950
3050
|
const snapshot = (0, react.useSyncExternalStore)(selection.store.subscribe, selection.store.getSnapshot);
|
|
@@ -2966,7 +3066,7 @@ window.__ModuleLoader__.load({
|
|
|
2966
3066
|
function ProviderBalanceDock({ provider, providerName, model, loadBalance, loadAdvice, sessionId, t }) {
|
|
2967
3067
|
const [result, setResult] = (0, react.useState)();
|
|
2968
3068
|
const [now, setNow] = (0, react.useState)(() => /* @__PURE__ */ new Date());
|
|
2969
|
-
const [adviceOpen, setAdviceOpen] = (0, react.useState)(
|
|
3069
|
+
const [adviceOpen, setAdviceOpen] = (0, react.useState)(readAdviceDockOpen);
|
|
2970
3070
|
(0, react.useEffect)(() => {
|
|
2971
3071
|
if (typeof document === "undefined") {
|
|
2972
3072
|
const timer = setInterval(() => setNow(/* @__PURE__ */ new Date()), PEAK_TICK_MS);
|
|
@@ -3095,7 +3195,11 @@ window.__ModuleLoader__.load({
|
|
|
3095
3195
|
className: "dsh-balance-dock-advice-toggle",
|
|
3096
3196
|
"aria-expanded": adviceOpen,
|
|
3097
3197
|
onClick: () => {
|
|
3098
|
-
setAdviceOpen((open) =>
|
|
3198
|
+
setAdviceOpen((open) => {
|
|
3199
|
+
const next = !open;
|
|
3200
|
+
writeAdviceDockOpen(next);
|
|
3201
|
+
return next;
|
|
3202
|
+
});
|
|
3099
3203
|
},
|
|
3100
3204
|
children: t(adviceOpen ? "advice.dockCollapse" : "advice.dockToggle")
|
|
3101
3205
|
}), adviceOpen ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
|
|
@@ -3288,16 +3392,23 @@ window.__ModuleLoader__.load({
|
|
|
3288
3392
|
"advice.dockCollapse": "收起估算",
|
|
3289
3393
|
"advice.loading": "正在估算下轮费用…",
|
|
3290
3394
|
"advice.unavailable": "暂时无法估算下轮费用",
|
|
3395
|
+
"advice.refresh": "重新估算",
|
|
3396
|
+
"advice.unavailableHint": "请先重试;若仍然失败,打开用量统计确认本会话的请求是否可读。",
|
|
3397
|
+
"advice.emptyHint": "还没有已计价的请求,因此无法估算下轮费用。发送一轮对话后点重新估算,或打开用量统计查看请求。",
|
|
3398
|
+
"advice.unpricedHint": "当前模型或本会话请求无法计价。打开用量统计查看原因,或点重新估算重试。",
|
|
3399
|
+
"advice.freeHint": "本会话请求均为免费,因此没有可估算的费用。打开用量统计查看请求,或在出现计费请求后再重新估算。",
|
|
3291
3400
|
"advice.now": "当前时段",
|
|
3292
3401
|
"advice.afterChange": "下个峰谷切换后",
|
|
3293
3402
|
"advice.fresh": "新开会话(全部未命中缓存)",
|
|
3294
3403
|
"advice.compact": "现在 /compact(摘要请求 + 压缩后首轮)",
|
|
3404
|
+
"advice.cheapest": "最便宜",
|
|
3295
3405
|
"advice.alternative": "其他已配置模型",
|
|
3296
3406
|
"advice.cacheSavings": "继续本会话相对新开可节省",
|
|
3297
3407
|
"advice.sample": "取最近 {count} / {limit} 次已计费请求的中位数",
|
|
3298
3408
|
"advice.shape": "估算用量:未缓存输入 {input} · 输出 {output} · 缓存读取 {cacheHit} · 缓存写入 {cacheWrite}",
|
|
3299
3409
|
"advice.nextChange": "{time} 切换",
|
|
3300
3410
|
"advice.coverage.priced": "本会话 {requests} 次请求均已计价",
|
|
3411
|
+
"advice.coverage.free": "本会话 {requests} 次请求均为免费,没有可用于估算的已计价样本",
|
|
3301
3412
|
"advice.coverage.partial": "本会话 {requests} 次请求中 {priced} 次已计价、{unpriced} 次未计价",
|
|
3302
3413
|
"advice.coverage.unpriced": "本会话 {requests} 次请求均未能计价",
|
|
3303
3414
|
"advice.coverage.empty": "本会话还没有可用于估算的请求",
|
|
@@ -3493,16 +3604,23 @@ window.__ModuleLoader__.load({
|
|
|
3493
3604
|
"advice.dockCollapse": "Hide estimate",
|
|
3494
3605
|
"advice.loading": "Estimating the next turn…",
|
|
3495
3606
|
"advice.unavailable": "The next-turn estimate is temporarily unavailable",
|
|
3607
|
+
"advice.refresh": "Refresh estimate",
|
|
3608
|
+
"advice.unavailableHint": "Try refresh first. If it still fails, open Usage to check that this session's requests can be read.",
|
|
3609
|
+
"advice.emptyHint": "There is no priced sample yet, so the next turn cannot be estimated. After you send a turn, refresh the estimate, or open Usage to inspect requests.",
|
|
3610
|
+
"advice.unpricedHint": "The current model or this session's requests could not be priced. Open Usage to see why, or refresh the estimate.",
|
|
3611
|
+
"advice.freeHint": "All requests in this session were free, so there is nothing to estimate. Open Usage to inspect them, or refresh after a priced turn.",
|
|
3496
3612
|
"advice.now": "Current period",
|
|
3497
3613
|
"advice.afterChange": "After the next peak change",
|
|
3498
3614
|
"advice.fresh": "Fresh session (all cache-miss)",
|
|
3499
3615
|
"advice.compact": "Compact now (summary request + first turn after)",
|
|
3616
|
+
"advice.cheapest": "Cheapest",
|
|
3500
3617
|
"advice.alternative": "Other configured model",
|
|
3501
3618
|
"advice.cacheSavings": "Saved by continuing this session vs starting over",
|
|
3502
3619
|
"advice.sample": "Median of the last {count} / {limit} priced requests",
|
|
3503
3620
|
"advice.shape": "Estimated usage: uncached input {input} · output {output} · cache read {cacheHit} · cache write {cacheWrite}",
|
|
3504
3621
|
"advice.nextChange": "Changes at {time}",
|
|
3505
3622
|
"advice.coverage.priced": "All {requests} requests in this session are priced",
|
|
3623
|
+
"advice.coverage.free": "All {requests} requests in this session were free, so there is no priced sample to estimate from",
|
|
3506
3624
|
"advice.coverage.partial": "{priced} of {requests} requests in this session are priced; {unpriced} are unpriced",
|
|
3507
3625
|
"advice.coverage.unpriced": "None of the {requests} requests in this session could be priced",
|
|
3508
3626
|
"advice.coverage.empty": "This session has no requests to estimate from yet",
|
|
@@ -4087,16 +4205,23 @@ window.__ModuleLoader__.load({
|
|
|
4087
4205
|
"advice.dockCollapse": "收起估算",
|
|
4088
4206
|
"advice.loading": "正在估算下輪費用…",
|
|
4089
4207
|
"advice.unavailable": "暫時無法估算下輪費用",
|
|
4208
|
+
"advice.refresh": "重新估算",
|
|
4209
|
+
"advice.unavailableHint": "請先重試;若仍然失敗,打開用量統計確認本工作階段的請求是否可讀。",
|
|
4210
|
+
"advice.emptyHint": "還沒有已計價的請求,因此無法估算下輪費用。發送一輪對話後點重新估算,或打開用量統計查看請求。",
|
|
4211
|
+
"advice.unpricedHint": "目前模型或本工作階段請求無法定價。打開用量統計查看原因,或點重新估算重試。",
|
|
4212
|
+
"advice.freeHint": "本工作階段請求均為免費,因此沒有可估算的費用。打開用量統計查看請求,或在出現計費請求後再重新估算。",
|
|
4090
4213
|
"advice.now": "目前時段",
|
|
4091
4214
|
"advice.afterChange": "下個尖離峰切換後",
|
|
4092
4215
|
"advice.fresh": "新開工作階段(全部未命中快取)",
|
|
4093
4216
|
"advice.compact": "現在 /compact(摘要請求 + 壓縮後首輪)",
|
|
4217
|
+
"advice.cheapest": "最便宜",
|
|
4094
4218
|
"advice.alternative": "其他已設定模型",
|
|
4095
4219
|
"advice.cacheSavings": "繼續本工作階段相對新開可節省",
|
|
4096
4220
|
"advice.sample": "取最近 {count} / {limit} 次已計費請求的中位數",
|
|
4097
4221
|
"advice.shape": "估算用量:未快取輸入 {input} · 輸出 {output} · 快取讀取 {cacheHit} · 快取寫入 {cacheWrite}",
|
|
4098
4222
|
"advice.nextChange": "{time} 切換",
|
|
4099
4223
|
"advice.coverage.priced": "本工作階段 {requests} 次請求均已計價",
|
|
4224
|
+
"advice.coverage.free": "本工作階段 {requests} 次請求均為免費,沒有可用於估算的已計價樣本",
|
|
4100
4225
|
"advice.coverage.partial": "本工作階段 {requests} 次請求中 {priced} 次已計價、{unpriced} 次未計價",
|
|
4101
4226
|
"advice.coverage.unpriced": "本工作階段 {requests} 次請求均未能計價",
|
|
4102
4227
|
"advice.coverage.empty": "本工作階段還沒有可用於估算的請求",
|
|
@@ -4394,16 +4519,23 @@ window.__ModuleLoader__.load({
|
|
|
4394
4519
|
.dsh-balance-dock-advice-toggle:hover { color: var(--dsw-alias-label-secondary); }
|
|
4395
4520
|
.dsh-balance-dock-advice-toggle:focus-visible { outline: 2px solid var(--dsw-alias-state-business-primary, #4d6bfe); outline-offset: 2px; border-radius: 4px; }
|
|
4396
4521
|
.dsh-advice-dock { margin-top: 4px; color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 18px; white-space: normal; }
|
|
4522
|
+
.dsh-advice-guidance { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
|
|
4523
|
+
.dsh-advice-guidance p { margin: 0; }
|
|
4524
|
+
.dsh-advice-hint { color: var(--ledger-muted, var(--dsw-alias-label-secondary, #686b70)); }
|
|
4525
|
+
.dsh-advice-dock.dsh-advice-guidance { gap: 4px; }
|
|
4526
|
+
.dsh-advice-dock .dsh-balance-refresh { min-height: 28px; padding: 0 8px; font-size: 11px; }
|
|
4397
4527
|
.dsh-advice-note { color: var(--dsw-alias-label-dimmed, var(--dsw-alias-label-tertiary)); font-size: 10px; }
|
|
4398
4528
|
.dsh-advice-card { min-width: 0; border: .5px solid var(--ledger-line); border-radius: var(--dsw-radius-lg, 12px); padding: 20px; background: var(--ledger-paper); display: flex; flex-direction: column; gap: 10px; }
|
|
4399
4529
|
.dsh-advice-card-head .dsh-balance-heading { font-size: 16px; }
|
|
4400
4530
|
.dsh-advice-meta { margin: 0; color: var(--ledger-muted); font-size: 12px; line-height: 1.6; }
|
|
4401
4531
|
.dsh-advice-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; font-size: 13px; }
|
|
4402
4532
|
.dsh-advice-row strong { font-variant-numeric: tabular-nums; min-width: 0; }
|
|
4403
|
-
.dsh-advice-amount { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
|
|
4533
|
+
.dsh-advice-amount { display: inline-block; max-width: 100%; overflow-wrap: anywhere; white-space: nowrap; }
|
|
4534
|
+
.dsh-advice-dock .dsh-advice-cost { font-variant-numeric: tabular-nums; }
|
|
4404
4535
|
.dsh-advice-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
|
|
4405
4536
|
.dsh-advice-meta, .dsh-advice-caveats li { overflow-wrap: anywhere; }
|
|
4406
4537
|
.dsh-advice-row small { flex-basis: 100%; color: var(--ledger-muted); font-size: 11px; }
|
|
4538
|
+
.dsh-advice-best { color: var(--dsw-alias-label-success, #1a7f37); font-size: 11px; font-weight: 600; white-space: nowrap; }
|
|
4407
4539
|
.dsh-advice-alternatives { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--ledger-line); }
|
|
4408
4540
|
.dsh-advice-caveats { margin: 0; padding-left: 18px; color: var(--ledger-muted); font-size: 11px; line-height: 1.6; }
|
|
4409
4541
|
.dsh-balance-dock-model { display: inline-block; max-width: 40%; margin-left: 8px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
|
|
@@ -4501,6 +4633,7 @@ window.__ModuleLoader__.load({
|
|
|
4501
4633
|
const params = new URLSearchParams({ session: options.sessionId });
|
|
4502
4634
|
if (options.provider !== void 0) params.set("provider", options.provider);
|
|
4503
4635
|
if (options.model !== void 0) params.set("model", options.model);
|
|
4636
|
+
if (options.forceRefresh === true) params.set("refresh", "1");
|
|
4504
4637
|
const value = await (await fetch(`${ADVICE_ROUTE}?${params.toString()}`, {
|
|
4505
4638
|
method: "GET",
|
|
4506
4639
|
headers: { accept: "application/json" },
|