@pinkbanana/dsh-balance 0.18.0 → 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 +1 -1
- package/README_EN.md +1 -1
- package/lib/client.js +72 -3
- package/lib/client.js.map +1 -1
- package/lib/index.js +32 -2
- package/lib/index.js.map +1 -1
- package/lib/types/billing.d.ts +11 -0
- package/lib/types/cache-breaks.d.ts +2 -0
- package/lib/types/client/AdviceCard.d.ts +3 -1
- package/lib/types/client/BillingTab.d.ts +5 -0
- package/lib/types/client/locales.d.ts +4 -0
- package/lib/types/client/styles.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -159,7 +159,7 @@ providers:
|
|
|
159
159
|
|
|
160
160
|
卡片对照四种下一步的费用:当前时段继续、等待下个峰谷切换、现在 `/compact`(摘要请求 + 压缩后首轮;摘要约 4,000 tokens,至多历史的四分之一),以及新开会话(全部未命中缓存),并显示继续本会话相对新开因缓存可节省的费用。也可对照本 Harness 已配置且可计价的其他官方模型。当前模型下最便宜的一步会标上“最便宜”(按单轮费用比较,因此 `/compact` 很少在单轮胜出)。仅为估算,不会自动压缩或换模型。
|
|
161
161
|
|
|
162
|
-
估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。卡片还会在检测到缓存命中率骤降(例如换模型、前缀变化或上下文被压缩)时列出最近 3
|
|
162
|
+
估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。卡片还会在检测到缓存命中率骤降(例如换模型、前缀变化或上下文被压缩)时列出最近 3 次「缓存断层」及估算多花的费用,帮助定位缓存为何失效;若最近一次请求刚好断层,折叠的输入框下方开关会提示「缓存刚断层」。用量页会用「价格缺口」列出未计费的模型、原因和请求数,并指向 `pricingOverrides` 补价。没有已计价样本或估算加载失败时,卡片会说明原因,并提示重新估算或打开用量统计。完整计算说明、峰谷规则和局限见 [估算是怎么算的](./docs/estimates.md)。
|
|
163
163
|
|
|
164
164
|

|
|
165
165
|
|
package/README_EN.md
CHANGED
|
@@ -155,7 +155,7 @@ The session Usage tab shows a next-turn estimate card; the same card appears whe
|
|
|
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. 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 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
|

|
|
161
161
|
|
package/lib/client.js
CHANGED
|
@@ -711,6 +711,10 @@ window.__ModuleLoader__.load({
|
|
|
711
711
|
function cheapestStepOf(result) {
|
|
712
712
|
return result?.ok === true ? result.cheapest : void 0;
|
|
713
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
|
+
}
|
|
714
718
|
function combined(estimate, rate) {
|
|
715
719
|
if (estimate.combinedCny !== null) return estimate.combinedCny;
|
|
716
720
|
if (rate === null || rate === void 0) return null;
|
|
@@ -1340,6 +1344,31 @@ window.__ModuleLoader__.load({
|
|
|
1340
1344
|
]
|
|
1341
1345
|
});
|
|
1342
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
|
+
}
|
|
1343
1372
|
/** Display-only exchange rate; the Host configuration wins when present. */
|
|
1344
1373
|
function RateEditor({ value, configured, onChange, t }) {
|
|
1345
1374
|
const [text, setText] = (0, react.useState)(value === null ? "" : String(value));
|
|
@@ -1989,6 +2018,10 @@ window.__ModuleLoader__.load({
|
|
|
1989
2018
|
t
|
|
1990
2019
|
})
|
|
1991
2020
|
}),
|
|
2021
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(PricingGaps, {
|
|
2022
|
+
summary: allResult.summary,
|
|
2023
|
+
t
|
|
2024
|
+
}),
|
|
1992
2025
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Punchcard, {
|
|
1993
2026
|
summary: allResult.summary,
|
|
1994
2027
|
t
|
|
@@ -2017,6 +2050,14 @@ window.__ModuleLoader__.load({
|
|
|
2017
2050
|
usdToCny: effectiveRate,
|
|
2018
2051
|
showProjection: false
|
|
2019
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
|
+
}),
|
|
2020
2061
|
loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
|
|
2021
2062
|
sessionId: sessionResult.session.sessionId,
|
|
2022
2063
|
loadAdvice,
|
|
@@ -2091,6 +2132,10 @@ window.__ModuleLoader__.load({
|
|
|
2091
2132
|
usdToCny: effectiveRate,
|
|
2092
2133
|
showProjection: false
|
|
2093
2134
|
}),
|
|
2135
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(PricingGaps, {
|
|
2136
|
+
summary: sessionResult.summary,
|
|
2137
|
+
t
|
|
2138
|
+
}),
|
|
2094
2139
|
loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
|
|
2095
2140
|
sessionId,
|
|
2096
2141
|
loadAdvice,
|
|
@@ -3131,8 +3176,11 @@ window.__ModuleLoader__.load({
|
|
|
3131
3176
|
const [now, setNow] = (0, react.useState)(() => /* @__PURE__ */ new Date());
|
|
3132
3177
|
const [adviceOpen, setAdviceOpen] = (0, react.useState)(readAdviceDockOpen);
|
|
3133
3178
|
const [cheapest, setCheapest] = (0, react.useState)();
|
|
3179
|
+
const [cacheBroke, setCacheBroke] = (0, react.useState)(false);
|
|
3134
3180
|
const onAdviceResult = (0, react.useCallback)((value) => {
|
|
3135
|
-
if (value
|
|
3181
|
+
if (value === void 0) return;
|
|
3182
|
+
setCheapest(cheapestStepOf(value));
|
|
3183
|
+
setCacheBroke(latestCacheBreakOf(value) !== void 0);
|
|
3136
3184
|
}, []);
|
|
3137
3185
|
(0, react.useEffect)(() => {
|
|
3138
3186
|
if (typeof document === "undefined") {
|
|
@@ -3257,10 +3305,11 @@ window.__ModuleLoader__.load({
|
|
|
3257
3305
|
children: summary
|
|
3258
3306
|
})
|
|
3259
3307
|
]
|
|
3260
|
-
}), loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
3308
|
+
}), loadAdvice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
3261
3309
|
type: "button",
|
|
3262
3310
|
className: "dsh-balance-dock-advice-toggle",
|
|
3263
3311
|
"aria-expanded": adviceOpen,
|
|
3312
|
+
"data-cache-break": cacheBroke && !adviceOpen ? "true" : void 0,
|
|
3264
3313
|
onClick: () => {
|
|
3265
3314
|
setAdviceOpen((open) => {
|
|
3266
3315
|
const next = !open;
|
|
@@ -3268,7 +3317,10 @@ window.__ModuleLoader__.load({
|
|
|
3268
3317
|
return next;
|
|
3269
3318
|
});
|
|
3270
3319
|
},
|
|
3271
|
-
children: adviceOpen ? t("advice.dockCollapse") : cheapest === void 0 ? t("advice.dockToggle") : t("advice.dockToggleCheapest", { step: t(`advice.step.${cheapest}`) })
|
|
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]
|
|
3272
3324
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdviceCard, {
|
|
3273
3325
|
compact: true,
|
|
3274
3326
|
hidden: !adviceOpen,
|
|
@@ -3391,6 +3443,9 @@ window.__ModuleLoader__.load({
|
|
|
3391
3443
|
"billing.share": "占已知消费 {percent}",
|
|
3392
3444
|
"billing.unpriced": "未计费请求",
|
|
3393
3445
|
"billing.unpricedHint": "缺少 usage 或价格未知,不进行估算",
|
|
3446
|
+
"billing.gaps": "价格缺口",
|
|
3447
|
+
"billing.gapRequests": "{count} 次请求",
|
|
3448
|
+
"billing.gapsHint": "这些请求保留了次数和 token,但未计费。可在配置的 pricingOverrides 中为对应 provider + 模型补充价格。",
|
|
3394
3449
|
"billing.fixedRate": "固定汇率换算",
|
|
3395
3450
|
"billing.tokensBreakdown": "未缓存输入 {input} · 输出 {output} · 缓存读取 {cacheHit} · 缓存写入 {cacheWrite}",
|
|
3396
3451
|
"billing.byModel": "按模型",
|
|
@@ -3472,6 +3527,7 @@ window.__ModuleLoader__.load({
|
|
|
3472
3527
|
"advice.compact": "现在 /compact(摘要请求 + 压缩后首轮)",
|
|
3473
3528
|
"advice.cheapest": "最便宜",
|
|
3474
3529
|
"advice.dockToggleCheapest": "下轮估算 · {step}最省",
|
|
3530
|
+
"advice.dockCacheBroke": "缓存刚断层",
|
|
3475
3531
|
"advice.step.now": "继续",
|
|
3476
3532
|
"advice.step.after-change": "等待切换",
|
|
3477
3533
|
"advice.step.fresh": "新开会话",
|
|
@@ -3614,6 +3670,9 @@ window.__ModuleLoader__.load({
|
|
|
3614
3670
|
"billing.share": "{percent} of priced cost",
|
|
3615
3671
|
"billing.unpriced": "Unpriced requests",
|
|
3616
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.",
|
|
3617
3676
|
"billing.fixedRate": "fixed-rate conversion",
|
|
3618
3677
|
"billing.tokensBreakdown": "Uncached input {input} · Output {output} · Cache read {cacheHit} · Cache write {cacheWrite}",
|
|
3619
3678
|
"billing.byModel": "By model",
|
|
@@ -3695,6 +3754,7 @@ window.__ModuleLoader__.load({
|
|
|
3695
3754
|
"advice.compact": "Compact now (summary request + first turn after)",
|
|
3696
3755
|
"advice.cheapest": "Cheapest",
|
|
3697
3756
|
"advice.dockToggleCheapest": "Next-turn estimate · {step} is cheapest",
|
|
3757
|
+
"advice.dockCacheBroke": "cache just broke",
|
|
3698
3758
|
"advice.step.now": "continuing",
|
|
3699
3759
|
"advice.step.after-change": "waiting",
|
|
3700
3760
|
"advice.step.fresh": "starting fresh",
|
|
@@ -4226,6 +4286,9 @@ window.__ModuleLoader__.load({
|
|
|
4226
4286
|
"billing.share": "佔已知消費 {percent}",
|
|
4227
4287
|
"billing.unpriced": "未計費請求",
|
|
4228
4288
|
"billing.unpricedHint": "缺少 usage 或價格未知,不進行估算",
|
|
4289
|
+
"billing.gaps": "價格缺口",
|
|
4290
|
+
"billing.gapRequests": "{count} 次請求",
|
|
4291
|
+
"billing.gapsHint": "這些請求保留了次數與 token,但未計費。可在設定的 pricingOverrides 中為對應 provider + 模型補上價格。",
|
|
4229
4292
|
"billing.fixedRate": "固定匯率換算",
|
|
4230
4293
|
"billing.tokensBreakdown": "未快取輸入 {input} · 輸出 {output} · 快取讀取 {cacheHit} · 快取寫入 {cacheWrite}",
|
|
4231
4294
|
"billing.byModel": "依模型",
|
|
@@ -4307,6 +4370,7 @@ window.__ModuleLoader__.load({
|
|
|
4307
4370
|
"advice.compact": "現在 /compact(摘要請求 + 壓縮後首輪)",
|
|
4308
4371
|
"advice.cheapest": "最便宜",
|
|
4309
4372
|
"advice.dockToggleCheapest": "下輪估算 · {step}最省",
|
|
4373
|
+
"advice.dockCacheBroke": "快取剛斷層",
|
|
4310
4374
|
"advice.step.now": "繼續",
|
|
4311
4375
|
"advice.step.after-change": "等待切換",
|
|
4312
4376
|
"advice.step.fresh": "新開工作階段",
|
|
@@ -4618,6 +4682,11 @@ window.__ModuleLoader__.load({
|
|
|
4618
4682
|
text-underline-offset: 2px;
|
|
4619
4683
|
vertical-align: middle;
|
|
4620
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); }
|
|
4621
4690
|
.dsh-balance-dock-advice-toggle:hover { color: var(--dsw-alias-label-secondary); }
|
|
4622
4691
|
.dsh-balance-dock-advice-toggle:focus-visible { outline: 2px solid var(--dsw-alias-state-business-primary, #4d6bfe); outline-offset: 2px; border-radius: 4px; }
|
|
4623
4692
|
.dsh-advice-dock { margin-top: 4px; color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 18px; white-space: normal; }
|