@pinkbanana/dsh-balance 0.17.3 → 0.19.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.
package/README.md CHANGED
@@ -148,18 +148,18 @@ providers:
148
148
 
149
149
  内置 [DeepSeek 官方美元定价](https://api-docs.deepseek.com/quick_start/pricing/):现行 Flash 低谷价为每百万 tokens 缓存命中 $0.003 / 未命中 $0.15 / 输出 $0.60,高峰为 2 倍;高峰为北京时间周一至周五 09:00–12:00、14:00–18:00(UTC 01:00–04:00、06:00–10:00),周末及中国法定节假日全天低谷。法定节假日按 [国办发明电〔2025〕7号](https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm) 的 2026 年放假日期。现行 Flash 价自 2026-09-10 04:00 UTC 起生效,此前仍使用 2026-08-17 历史档(当前官网已不再列出该档数字,无法复核)。
150
150
 
151
- [StepFun 官方人民币标准价](https://platform.stepfun.com/docs/zh/guides/pricing/details) 于 2026-11-10 复核:`step-5-preview`、`step-3.7-flash`、`step-3.5-flash`、`step-3.5-flash-2603` 和 `step-1o-turbo-vision`。`step-5-preview` 缓存命中标准价自北京时间 2026-10-14 00:30 起由 0.35 元/百万调整为 0.70 元/百万;该时间之前已通过按量付费 API 调用过该模型的账户可能仍适用 0.35 元,插件无法识别账户是否享受此保留价,因此一律按标准生效时间计价。StepFun 未缓存输入(含缓存写入)、缓存读取、输出分别计价,不套用 DeepSeek 峰谷倍率。费用是公开标准价估算,不代表账户实际账单;套餐、折扣和未保存的历史调价不包含在内。
151
+ [StepFun 官方人民币标准价](https://platform.stepfun.com/docs/zh/guides/pricing/details) 于 2026-11-10 复核:`step-5`、`step-5-preview`、`step-3.7-flash`、`step-3.5-flash`、`step-3.5-flash-2603` 和 `step-1o-turbo-vision`。`step-5-preview` 缓存命中标准价自北京时间 2026-10-14 00:30 起由 0.35 元/百万调整为 0.70 元/百万;该时间之前已通过按量付费 API 调用过该模型的账户可能仍适用 0.35 元,插件无法识别账户是否享受此保留价,因此一律按标准生效时间计价。StepFun 未缓存输入(含缓存写入)、缓存读取、输出分别计价,不套用 DeepSeek 峰谷倍率。费用是公开标准价估算,不代表账户实际账单;套餐、折扣和未保存的历史调价不包含在内。
152
152
 
153
153
  美元和原生人民币费用分别展示;设置 `usdToCny` 后,人民币合计才会包含美元折算金额,并明确标为固定汇率换算。未设置汇率时,原生人民币金额不会被表述为包含美元费用的完整人民币合计。已知价格且费用为 0 的请求单列为“免费”;未知 provider / model 和缺失 usage 的请求保留请求数与 token,显示“未计费”。账户余额是实时查询值,与本地用量估算独立;赠送余额与充值余额分别展示,StepFun 的总充值/总赠送为累计值而非剩余余额。会话消费页采用居中内容宽度、响应式外边距,并为底部输入框保留空间。
154
154
 
155
155
 
156
156
  ## 下轮费用估算
157
157
 
158
- 会话「消费」页会展示下轮费用估算卡片;在用量统计里点击会话名下钻时也会看到同一卡片。聊天框下方的余额摘要可按需展开该估算,默认收起以免占用空间。同一标签页内的导航(包括切换会话或模型)会记住展开或收起;刷新或关闭标签页后仍默认收起。
158
+ 会话「消费」页会展示下轮费用估算卡片;在用量统计里点击会话名下钻时也会看到同一卡片。聊天框下方的余额摘要可按需展开该估算,默认收起以免占用空间;收起时开关会直接写出最省的下一步(例如「下轮估算 · 等待切换最省」),无需展开即可参考。同一标签页内的导航(包括切换会话或模型)会记住展开或收起;刷新或关闭标签页后仍默认收起。
159
159
 
160
160
  卡片对照四种下一步的费用:当前时段继续、等待下个峰谷切换、现在 `/compact`(摘要请求 + 压缩后首轮;摘要约 4,000 tokens,至多历史的四分之一),以及新开会话(全部未命中缓存),并显示继续本会话相对新开因缓存可节省的费用。也可对照本 Harness 已配置且可计价的其他官方模型。当前模型下最便宜的一步会标上“最便宜”(按单轮费用比较,因此 `/compact` 很少在单轮胜出)。仅为估算,不会自动压缩或换模型。
161
161
 
162
- 估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。没有已计价样本或估算加载失败时,卡片会说明原因,并提示重新估算或打开用量统计。完整计算说明、峰谷规则和局限见 [估算是怎么算的](./docs/estimates.md)。
162
+ 估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。卡片还会在检测到缓存命中率骤降(例如换模型、前缀变化或上下文被压缩)时列出最近 3 次「缓存断层」及估算多花的费用,帮助定位缓存为何失效;若最近一次请求刚好断层,折叠的输入框下方开关会提示「缓存刚断层」。用量页会用「价格缺口」列出未计费的模型、原因和请求数,并指向 `pricingOverrides` 补价。没有已计价样本或估算加载失败时,卡片会说明原因,并提示重新估算或打开用量统计。完整计算说明、峰谷规则和局限见 [估算是怎么算的](./docs/estimates.md)。
163
163
 
164
164
  ![下轮费用估算卡片](./docs/dsh-advisor-card.png)
165
165
 
package/README_EN.md CHANGED
@@ -146,16 +146,16 @@ Each request is attributed to its actual message source, with request headers as
146
146
 
147
147
  Built-in estimates use [official DeepSeek USD rates](https://api-docs.deepseek.com/quick_start/pricing/): current Flash off-peak prices are $0.003 / $0.15 / $0.60 per million tokens (cache hit / miss / output), and peak is 2x. Peak hours are 09:00–12:00 and 14:00–18:00 Beijing time (UTC 01:00–04:00 and 06:00–10:00), Monday–Friday only; weekends and Chinese public holidays are all-day off-peak. Holiday dates follow the 2026 arrangements in [State Council General Office notice 国办发明电〔2025〕7号](https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm). Current Flash prices take effect from 2026-09-10 04:00 UTC; earlier usage keeps the 2026-08-17 historical tier (the current official page no longer lists those figures, so they cannot be re-verified).
148
148
 
149
- [StepFun mainland CNY reference rates](https://platform.stepfun.com/docs/zh/guides/pricing/details) were re-checked on 2026-11-10 for `step-5-preview`, `step-3.7-flash`, `step-3.5-flash`, `step-3.5-flash-2603`, and `step-1o-turbo-vision`. The standard `step-5-preview` cache-hit price changed from 0.35 to 0.70 CNY per million tokens at 2026-10-14 00:30 Beijing time. Accounts that had already used the pay-as-you-go API before that time may keep 0.35; the plugin cannot detect that grandfathering, so it applies the standard effective-from date. Requests without supported pricing keep their token and request counts and show as unpriced. A similarly named DeepSeek model does not inherit official DeepSeek pricing on another provider. Entirely unpriced totals do not show $0; mixed totals include only known charges and carry a partial-cost label. Live account balances are separate from local usage estimates.
149
+ [StepFun mainland CNY reference rates](https://platform.stepfun.com/docs/zh/guides/pricing/details) were re-checked on 2026-11-10 for `step-5` (same rates as `step-5-preview`), `step-5-preview`, `step-3.7-flash`, `step-3.5-flash`, `step-3.5-flash-2603`, and `step-1o-turbo-vision`. The standard `step-5-preview` cache-hit price changed from 0.35 to 0.70 CNY per million tokens at 2026-10-14 00:30 Beijing time. Accounts that had already used the pay-as-you-go API before that time may keep 0.35; the plugin cannot detect that grandfathering, so it applies the standard effective-from date. Requests without supported pricing keep their token and request counts and show as unpriced. A similarly named DeepSeek model does not inherit official DeepSeek pricing on another provider. Entirely unpriced totals do not show $0; mixed totals include only known charges and carry a partial-cost label. Live account balances are separate from local usage estimates.
150
150
 
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. 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.
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, and the collapsed toggle names the cheapest next step (for example “Next-turn estimate · waiting is cheapest”) so it is useful without opening. 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
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. 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).
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 card also lists the latest three **cache breaks** — turns where the cache-hit share collapsed (model switch, changed prefix, or a much shorter context after compaction) — with the estimated extra cost versus keeping the prefix; when the latest request just broke the cache, the collapsed composer-dock toggle says so. The Usage page also lists **Pricing gaps** — unpriced models with the reason and request count — and points to `pricingOverrides` to close them. 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
  ![Next-turn estimate card](./docs/dsh-advisor-card-en.png)
161
161
 
@@ -210,4 +210,4 @@ The activity punchcard groups requests by weekday and hour in the selected brows
210
210
 
211
211
  The conversation usage view has centered content, responsive padding and space for the composer. Cache input is counted once; duplicate settlements replace the previous sample, retries remain separate, and fork prefixes are excluded.
212
212
 
213
- StepFun mainland API estimates use [official standard CNY rates](https://platform.stepfun.com/docs/zh/guides/pricing/details), re-checked on 2026-11-10, for `step-5-preview`, `step-3.7-flash`, `step-3.5-flash`, `step-3.5-flash-2603`, and `step-1o-turbo-vision`. The standard `step-5-preview` cache-hit rate is 0.70 CNY per million from 2026-10-14 00:30 Beijing time; earlier records use 0.35. These reference estimates do not account for plans, discounts, grandfathered account rates, or unrecorded historical rate changes. USD and native CNY are shown separately; only an explicitly configured `usdToCny` rate enables a combined CNY total. Unknown rates remain unpriced. `?page=session` previews the conversation view with 124 StepFun requests.
213
+ StepFun mainland API estimates use [official standard CNY rates](https://platform.stepfun.com/docs/zh/guides/pricing/details), re-checked on 2026-11-10, for `step-5` (same rates as `step-5-preview`), `step-5-preview`, `step-3.7-flash`, `step-3.5-flash`, `step-3.5-flash-2603`, and `step-1o-turbo-vision`. The standard `step-5-preview` cache-hit rate is 0.70 CNY per million from 2026-10-14 00:30 Beijing time; earlier records use 0.35. These reference estimates do not account for plans, discounts, grandfathered account rates, or unrecorded historical rate changes. USD and native CNY are shown separately; only an explicitly configured `usdToCny` rate enables a combined CNY total. Unknown rates remain unpriced. `?page=session` previews the conversation view with 124 StepFun requests.
@@ -43,6 +43,10 @@ Plans, discounts, account-specific rates, or unrecorded historical price changes
43
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
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
+ ## Cache breaks
47
+
48
+ The card compares each priced request with the previous one. When the previous request hit at least 50% of its prompt, this prompt has at least 2,000 tokens, and the hit share fell by at least 40 percentage points, it is recorded as a **cache break**; the latest three are shown. The cause is a heuristic: a different model or provider → model switched; a prompt under 60% of the previous size → context shrank (possibly a compaction); anything else → prefix changed. Extra cost is the difference between this request's actual usage and a counterfactual that keeps the previous hit share — still an estimate.
49
+
46
50
  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
51
 
48
52
  Local preview (no credentials):
package/docs/estimates.md CHANGED
@@ -43,6 +43,10 @@
43
43
  - 聊天框下方的余额条可按需展开同一估算,默认收起;同一标签页内会记住展开或收起,刷新或关闭标签页后恢复默认收起。
44
44
  - 本机只读接口:`GET /dsh-balance/api/advice?session=…`(也可用 `sessionId`;可选 `provider`、`model`、`refresh=1` 与重复的 `compare=provider:model`)。仅本机可访问,响应不含 prompt 或会话正文。
45
45
 
46
+ ## 缓存断层
47
+
48
+ 卡片会比较相邻两次已计价请求:若上一次缓存命中率不低于 50%、本次提示至少 2,000 tokens,且命中率下降至少 40 个百分点,就记为一次「缓存断层」,最多显示最近 3 次。原因是启发式判断:换了模型或 provider → 切换了模型;提示长度不足上一次的 60% → 上下文大幅变短,可能刚压缩过;其余 → 前缀发生变化。多花的费用按本次请求的实际用量与「保持上一次命中率」的反事实用量之差估算,仍然只是估算。
49
+
46
50
  本版本**没有**可供模型调用的 agent tool。只读的 `dsh_balance_advise` 仍在[路线图](../ROADMAP.md)中;在此之前,请使用上面的界面或本机 HTTP 接口。
47
51
 
48
52
  本地预览(无需密钥):
package/lib/client.js CHANGED
@@ -707,6 +707,14 @@ window.__ModuleLoader__.load({
707
707
  }
708
708
  //#endregion
709
709
  //#region src/client/AdviceCard.tsx
710
+ /** Cheapest step of a successful advice response, if any. */
711
+ function cheapestStepOf(result) {
712
+ return result?.ok === true ? result.cheapest : void 0;
713
+ }
714
+ /** True when the most recent priced request broke the prompt cache, so the next turn starts cold. */
715
+ function latestCacheBreakOf(result) {
716
+ return result?.ok === true ? result.cacheBreaks.find((item) => item.latest) : void 0;
717
+ }
710
718
  function combined(estimate, rate) {
711
719
  if (estimate.combinedCny !== null) return estimate.combinedCny;
712
720
  if (rate === null || rate === void 0) return null;
@@ -766,7 +774,7 @@ window.__ModuleLoader__.load({
766
774
  });
767
775
  }
768
776
  /** Session-shaped next-turn estimates. Prompt text is never requested or rendered. */
769
- function AdviceCard({ sessionId, provider, model, loadAdvice, t, usdToCny = null, compact = false }) {
777
+ function AdviceCard({ sessionId, provider, model, loadAdvice, t, usdToCny = null, compact = false, hidden = false, onResult }) {
770
778
  const [result, setResult] = (0, react.useState)();
771
779
  const [loading, setLoading] = (0, react.useState)(true);
772
780
  const [refreshNonce, setRefreshNonce] = (0, react.useState)(0);
@@ -799,10 +807,14 @@ window.__ModuleLoader__.load({
799
807
  model,
800
808
  refreshNonce
801
809
  ]);
810
+ (0, react.useEffect)(() => {
811
+ onResult?.(result);
812
+ }, [result, onResult]);
802
813
  const locale = t("locale.tag");
803
814
  const onRefresh = () => {
804
815
  setRefreshNonce((value) => value + 1);
805
816
  };
817
+ if (hidden) return null;
806
818
  if (loading && result === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
807
819
  className: compact ? "dsh-advice-dock" : "dsh-balance-status",
808
820
  role: "status",
@@ -911,6 +923,35 @@ window.__ModuleLoader__.load({
911
923
  ]
912
924
  });
913
925
  }
926
+ function CacheBreakRow({ item, t, usdToCny, locale }) {
927
+ const percent = (value) => `${Math.round(value * 100)}%`;
928
+ const extra = item.extraCostUsd !== void 0 || item.extraCostCny !== void 0;
929
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
930
+ className: "dsh-advice-break",
931
+ children: [t("advice.cacheBreak", {
932
+ time: formatClockTime(new Date(item.time), locale),
933
+ model: item.model,
934
+ before: percent(item.previousHitRatio),
935
+ after: percent(item.hitRatio),
936
+ cause: t(`advice.cacheBreakCause.${item.cause}`)
937
+ }), extra ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
938
+ " · ",
939
+ t("advice.cacheBreakExtra"),
940
+ " ",
941
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostText, {
942
+ inline: true,
943
+ estimate: {
944
+ costUsd: item.extraCostUsd ?? null,
945
+ combinedCny: null,
946
+ ...item.extraCostCny === void 0 ? {} : { costCny: item.extraCostCny }
947
+ },
948
+ locale,
949
+ usdToCny,
950
+ t
951
+ })
952
+ ] }) : null]
953
+ });
954
+ }
914
955
  function PanelAdvice({ advice, t, usdToCny, locale, loading, onRefresh }) {
915
956
  const nextChange = advice.nextChangeAt === null ? void 0 : formatClockTime(new Date(advice.nextChangeAt), locale);
916
957
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
@@ -1021,6 +1062,21 @@ window.__ModuleLoader__.load({
1021
1062
  locale
1022
1063
  }, `${item.provider}:${item.model}:${item.pricingVersion}`))
1023
1064
  }) : null,
1065
+ advice.cacheBreaks.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1066
+ className: "dsh-advice-breaks",
1067
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1068
+ className: "dsh-advice-meta",
1069
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: t("advice.cacheBreaks") })
1070
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
1071
+ className: "dsh-advice-caveats",
1072
+ children: advice.cacheBreaks.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CacheBreakRow, {
1073
+ item,
1074
+ t,
1075
+ usdToCny,
1076
+ locale
1077
+ }, `${item.sessionId}:${item.seq}`))
1078
+ })]
1079
+ }) : null,
1024
1080
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1025
1081
  className: "dsh-advice-meta",
1026
1082
  children: t(`advice.coverage.${advice.coverage.status}`, {
@@ -1288,6 +1344,31 @@ window.__ModuleLoader__.load({
1288
1344
  ]
1289
1345
  });
1290
1346
  }
1347
+ /** Unpriced models with the reason, so a gap can be closed with a pricing override. */
1348
+ function PricingGaps({ summary, t }) {
1349
+ const gaps = summary.pricingGaps ?? [];
1350
+ if (gaps.length === 0) return null;
1351
+ const locale = t("locale.tag");
1352
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
1353
+ className: "dsh-billing-gaps",
1354
+ "aria-label": t("billing.gaps"),
1355
+ children: [
1356
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { children: t("billing.gaps") }),
1357
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { children: gaps.map((gap) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [
1358
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("code", { children: [
1359
+ findBalanceProvider(gap.provider)?.name ?? gap.provider,
1360
+ " / ",
1361
+ gap.model
1362
+ ] }),
1363
+ " · ",
1364
+ t(`billing.reason.${gap.reason}`),
1365
+ " · ",
1366
+ t("billing.gapRequests", { count: formatTokens(gap.requests, locale) })
1367
+ ] }, `${gap.provider}:${gap.model}:${gap.reason}`)) }),
1368
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("billing.gapsHint") })
1369
+ ]
1370
+ });
1371
+ }
1291
1372
  /** Display-only exchange rate; the Host configuration wins when present. */
1292
1373
  function RateEditor({ value, configured, onChange, t }) {
1293
1374
  const [text, setText] = (0, react.useState)(value === null ? "" : String(value));
@@ -1937,6 +2018,10 @@ window.__ModuleLoader__.load({
1937
2018
  t
1938
2019
  })
1939
2020
  }),
2021
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PricingGaps, {
2022
+ summary: allResult.summary,
2023
+ t
2024
+ }),
1940
2025
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Punchcard, {
1941
2026
  summary: allResult.summary,
1942
2027
  t
@@ -1965,6 +2050,14 @@ window.__ModuleLoader__.load({
1965
2050
  usdToCny: effectiveRate,
1966
2051
  showProjection: false
1967
2052
  }),
2053
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PricingGaps, {
2054
+ summary: sessionResult.summary,
2055
+ t
2056
+ }),
2057
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PricingGaps, {
2058
+ summary: sessionResult.summary,
2059
+ t
2060
+ }),
1968
2061
  loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
1969
2062
  sessionId: sessionResult.session.sessionId,
1970
2063
  loadAdvice,
@@ -2039,6 +2132,10 @@ window.__ModuleLoader__.load({
2039
2132
  usdToCny: effectiveRate,
2040
2133
  showProjection: false
2041
2134
  }),
2135
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PricingGaps, {
2136
+ summary: sessionResult.summary,
2137
+ t
2138
+ }),
2042
2139
  loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
2043
2140
  sessionId,
2044
2141
  loadAdvice,
@@ -2918,21 +3015,32 @@ window.__ModuleLoader__.load({
2918
3015
  outputCnyPerMillion: 2.1
2919
3016
  }
2920
3017
  };
2921
- const STEPFUN_CURRENT_PRICES = [{
2922
- model: "step-5-preview",
2923
- effectiveFrom: STEPFUN_STEP5_STANDARD_HIT_FROM,
2924
- pricingVersion: STEPFUN_PRICING_VERSION,
2925
- cacheHitCnyPerMillion: .7,
2926
- cacheMissCnyPerMillion: 7,
2927
- outputCnyPerMillion: 20
2928
- }, {
2929
- model: "step-1o-turbo-vision",
2930
- effectiveFrom: 0,
2931
- pricingVersion: STEPFUN_PRICING_VERSION,
2932
- cacheHitCnyPerMillion: .5,
2933
- cacheMissCnyPerMillion: 2.5,
2934
- outputCnyPerMillion: 8
2935
- }];
3018
+ const STEPFUN_CURRENT_PRICES = [
3019
+ {
3020
+ model: "step-5-preview",
3021
+ effectiveFrom: STEPFUN_STEP5_STANDARD_HIT_FROM,
3022
+ pricingVersion: STEPFUN_PRICING_VERSION,
3023
+ cacheHitCnyPerMillion: .7,
3024
+ cacheMissCnyPerMillion: 7,
3025
+ outputCnyPerMillion: 20
3026
+ },
3027
+ {
3028
+ model: "step-5",
3029
+ effectiveFrom: STEPFUN_STEP5_STANDARD_HIT_FROM,
3030
+ pricingVersion: STEPFUN_PRICING_VERSION,
3031
+ cacheHitCnyPerMillion: .7,
3032
+ cacheMissCnyPerMillion: 7,
3033
+ outputCnyPerMillion: 20
3034
+ },
3035
+ {
3036
+ model: "step-1o-turbo-vision",
3037
+ effectiveFrom: 0,
3038
+ pricingVersion: STEPFUN_PRICING_VERSION,
3039
+ cacheHitCnyPerMillion: .5,
3040
+ cacheMissCnyPerMillion: 2.5,
3041
+ outputCnyPerMillion: 8
3042
+ }
3043
+ ];
2936
3044
  const BILLING_PRICES = [
2937
3045
  ...Object.entries(LEGACY_PRICES).map(([model, rates]) => ({
2938
3046
  provider: "deepseek",
@@ -3067,6 +3175,13 @@ window.__ModuleLoader__.load({
3067
3175
  const [result, setResult] = (0, react.useState)();
3068
3176
  const [now, setNow] = (0, react.useState)(() => /* @__PURE__ */ new Date());
3069
3177
  const [adviceOpen, setAdviceOpen] = (0, react.useState)(readAdviceDockOpen);
3178
+ const [cheapest, setCheapest] = (0, react.useState)();
3179
+ const [cacheBroke, setCacheBroke] = (0, react.useState)(false);
3180
+ const onAdviceResult = (0, react.useCallback)((value) => {
3181
+ if (value === void 0) return;
3182
+ setCheapest(cheapestStepOf(value));
3183
+ setCacheBroke(latestCacheBreakOf(value) !== void 0);
3184
+ }, []);
3070
3185
  (0, react.useEffect)(() => {
3071
3186
  if (typeof document === "undefined") {
3072
3187
  const timer = setInterval(() => setNow(/* @__PURE__ */ new Date()), PEAK_TICK_MS);
@@ -3190,10 +3305,11 @@ window.__ModuleLoader__.load({
3190
3305
  children: summary
3191
3306
  })
3192
3307
  ]
3193
- }), loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3308
+ }), loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
3194
3309
  type: "button",
3195
3310
  className: "dsh-balance-dock-advice-toggle",
3196
3311
  "aria-expanded": adviceOpen,
3312
+ "data-cache-break": cacheBroke && !adviceOpen ? "true" : void 0,
3197
3313
  onClick: () => {
3198
3314
  setAdviceOpen((open) => {
3199
3315
  const next = !open;
@@ -3201,15 +3317,20 @@ window.__ModuleLoader__.load({
3201
3317
  return next;
3202
3318
  });
3203
3319
  },
3204
- children: t(adviceOpen ? "advice.dockCollapse" : "advice.dockToggle")
3205
- }), adviceOpen ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
3320
+ children: [adviceOpen ? t("advice.dockCollapse") : cheapest === void 0 ? t("advice.dockToggle") : t("advice.dockToggleCheapest", { step: t(`advice.step.${cheapest}`) }), cacheBroke && !adviceOpen ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
3321
+ className: "dsh-balance-dock-break",
3322
+ children: [" · ", t("advice.dockCacheBroke")]
3323
+ }) : null]
3324
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
3206
3325
  compact: true,
3326
+ hidden: !adviceOpen,
3327
+ onResult: onAdviceResult,
3207
3328
  sessionId: String(sessionId),
3208
3329
  ...provider === void 0 ? {} : { provider },
3209
3330
  ...model === void 0 ? {} : { model },
3210
3331
  loadAdvice,
3211
3332
  t
3212
- }) : null] })]
3333
+ })] })]
3213
3334
  });
3214
3335
  }
3215
3336
  //#endregion
@@ -3322,6 +3443,9 @@ window.__ModuleLoader__.load({
3322
3443
  "billing.share": "占已知消费 {percent}",
3323
3444
  "billing.unpriced": "未计费请求",
3324
3445
  "billing.unpricedHint": "缺少 usage 或价格未知,不进行估算",
3446
+ "billing.gaps": "价格缺口",
3447
+ "billing.gapRequests": "{count} 次请求",
3448
+ "billing.gapsHint": "这些请求保留了次数和 token,但未计费。可在配置的 pricingOverrides 中为对应 provider + 模型补充价格。",
3325
3449
  "billing.fixedRate": "固定汇率换算",
3326
3450
  "billing.tokensBreakdown": "未缓存输入 {input} · 输出 {output} · 缓存读取 {cacheHit} · 缓存写入 {cacheWrite}",
3327
3451
  "billing.byModel": "按模型",
@@ -3402,6 +3526,18 @@ window.__ModuleLoader__.load({
3402
3526
  "advice.fresh": "新开会话(全部未命中缓存)",
3403
3527
  "advice.compact": "现在 /compact(摘要请求 + 压缩后首轮)",
3404
3528
  "advice.cheapest": "最便宜",
3529
+ "advice.dockToggleCheapest": "下轮估算 · {step}最省",
3530
+ "advice.dockCacheBroke": "缓存刚断层",
3531
+ "advice.step.now": "继续",
3532
+ "advice.step.after-change": "等待切换",
3533
+ "advice.step.fresh": "新开会话",
3534
+ "advice.step.compact": "/compact",
3535
+ "advice.cacheBreaks": "缓存断层",
3536
+ "advice.cacheBreak": "{time} · {model}:缓存命中率 {before} → {after}({cause})",
3537
+ "advice.cacheBreakCause.model-switch": "切换了模型",
3538
+ "advice.cacheBreakCause.context-shrink": "上下文大幅变短,可能刚压缩过",
3539
+ "advice.cacheBreakCause.prefix-change": "前缀发生变化",
3540
+ "advice.cacheBreakExtra": "多花约",
3405
3541
  "advice.alternative": "其他已配置模型",
3406
3542
  "advice.cacheSavings": "继续本会话相对新开可节省",
3407
3543
  "advice.sample": "取最近 {count} / {limit} 次已计费请求的中位数",
@@ -3534,6 +3670,9 @@ window.__ModuleLoader__.load({
3534
3670
  "billing.share": "{percent} of priced cost",
3535
3671
  "billing.unpriced": "Unpriced requests",
3536
3672
  "billing.unpricedHint": "Missing usage or unknown pricing; no estimate is made",
3673
+ "billing.gaps": "Pricing gaps",
3674
+ "billing.gapRequests": "{count} requests",
3675
+ "billing.gapsHint": "These requests keep their counts and tokens but are not priced. Add a price for the provider + model under pricingOverrides in the plugin config.",
3537
3676
  "billing.fixedRate": "fixed-rate conversion",
3538
3677
  "billing.tokensBreakdown": "Uncached input {input} · Output {output} · Cache read {cacheHit} · Cache write {cacheWrite}",
3539
3678
  "billing.byModel": "By model",
@@ -3614,6 +3753,18 @@ window.__ModuleLoader__.load({
3614
3753
  "advice.fresh": "Fresh session (all cache-miss)",
3615
3754
  "advice.compact": "Compact now (summary request + first turn after)",
3616
3755
  "advice.cheapest": "Cheapest",
3756
+ "advice.dockToggleCheapest": "Next-turn estimate · {step} is cheapest",
3757
+ "advice.dockCacheBroke": "cache just broke",
3758
+ "advice.step.now": "continuing",
3759
+ "advice.step.after-change": "waiting",
3760
+ "advice.step.fresh": "starting fresh",
3761
+ "advice.step.compact": "/compact",
3762
+ "advice.cacheBreaks": "Cache breaks",
3763
+ "advice.cacheBreak": "{time} · {model}: cache hit {before} → {after} ({cause})",
3764
+ "advice.cacheBreakCause.model-switch": "model switched",
3765
+ "advice.cacheBreakCause.context-shrink": "context shrank, possibly after a compaction",
3766
+ "advice.cacheBreakCause.prefix-change": "prefix changed",
3767
+ "advice.cacheBreakExtra": "Extra cost about",
3617
3768
  "advice.alternative": "Other configured model",
3618
3769
  "advice.cacheSavings": "Saved by continuing this session vs starting over",
3619
3770
  "advice.sample": "Median of the last {count} / {limit} priced requests",
@@ -4135,6 +4286,9 @@ window.__ModuleLoader__.load({
4135
4286
  "billing.share": "佔已知消費 {percent}",
4136
4287
  "billing.unpriced": "未計費請求",
4137
4288
  "billing.unpricedHint": "缺少 usage 或價格未知,不進行估算",
4289
+ "billing.gaps": "價格缺口",
4290
+ "billing.gapRequests": "{count} 次請求",
4291
+ "billing.gapsHint": "這些請求保留了次數與 token,但未計費。可在設定的 pricingOverrides 中為對應 provider + 模型補上價格。",
4138
4292
  "billing.fixedRate": "固定匯率換算",
4139
4293
  "billing.tokensBreakdown": "未快取輸入 {input} · 輸出 {output} · 快取讀取 {cacheHit} · 快取寫入 {cacheWrite}",
4140
4294
  "billing.byModel": "依模型",
@@ -4215,6 +4369,18 @@ window.__ModuleLoader__.load({
4215
4369
  "advice.fresh": "新開工作階段(全部未命中快取)",
4216
4370
  "advice.compact": "現在 /compact(摘要請求 + 壓縮後首輪)",
4217
4371
  "advice.cheapest": "最便宜",
4372
+ "advice.dockToggleCheapest": "下輪估算 · {step}最省",
4373
+ "advice.dockCacheBroke": "快取剛斷層",
4374
+ "advice.step.now": "繼續",
4375
+ "advice.step.after-change": "等待切換",
4376
+ "advice.step.fresh": "新開工作階段",
4377
+ "advice.step.compact": "/compact",
4378
+ "advice.cacheBreaks": "快取斷層",
4379
+ "advice.cacheBreak": "{time} · {model}:快取命中率 {before} → {after}({cause})",
4380
+ "advice.cacheBreakCause.model-switch": "切換了模型",
4381
+ "advice.cacheBreakCause.context-shrink": "上下文大幅變短,可能剛壓縮過",
4382
+ "advice.cacheBreakCause.prefix-change": "前綴發生變化",
4383
+ "advice.cacheBreakExtra": "多花約",
4218
4384
  "advice.alternative": "其他已設定模型",
4219
4385
  "advice.cacheSavings": "繼續本工作階段相對新開可節省",
4220
4386
  "advice.sample": "取最近 {count} / {limit} 次已計費請求的中位數",
@@ -4516,6 +4682,11 @@ window.__ModuleLoader__.load({
4516
4682
  text-underline-offset: 2px;
4517
4683
  vertical-align: middle;
4518
4684
  }
4685
+ .dsh-balance-dock-advice-toggle[data-cache-break='true'] .dsh-balance-dock-break { color: var(--dsw-alias-state-warn-primary, #d99525); }
4686
+ .dsh-billing-gaps { display: grid; gap: 6px; padding: 10px 12px; border-left: 3px solid var(--dsw-alias-state-warn-primary, #d99525); border-radius: 6px; background: var(--dsw-alias-bg-secondary, transparent); }
4687
+ .dsh-billing-gaps h4 { margin: 0; font-size: 12px; }
4688
+ .dsh-billing-gaps ul { margin: 0; padding-left: 18px; font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
4689
+ .dsh-billing-gaps p { margin: 0; font-size: 11px; color: var(--ledger-muted, inherit); }
4519
4690
  .dsh-balance-dock-advice-toggle:hover { color: var(--dsw-alias-label-secondary); }
4520
4691
  .dsh-balance-dock-advice-toggle:focus-visible { outline: 2px solid var(--dsw-alias-state-business-primary, #4d6bfe); outline-offset: 2px; border-radius: 4px; }
4521
4692
  .dsh-advice-dock { margin-top: 4px; color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 18px; white-space: normal; }
@@ -4535,6 +4706,8 @@ window.__ModuleLoader__.load({
4535
4706
  .dsh-advice-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
4536
4707
  .dsh-advice-meta, .dsh-advice-caveats li { overflow-wrap: anywhere; }
4537
4708
  .dsh-advice-row small { flex-basis: 100%; color: var(--ledger-muted); font-size: 11px; }
4709
+ .dsh-advice-breaks { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--ledger-line); }
4710
+ .dsh-advice-break { overflow-wrap: anywhere; }
4538
4711
  .dsh-advice-best { color: var(--dsw-alias-label-success, #1a7f37); font-size: 11px; font-weight: 600; white-space: nowrap; }
4539
4712
  .dsh-advice-alternatives { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--ledger-line); }
4540
4713
  .dsh-advice-caveats { margin: 0; padding-left: 18px; color: var(--ledger-muted); font-size: 11px; line-height: 1.6; }