Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ function changelogCatOf(rawLine) {
// every priced session resolves identical rates; mixed fleets keep
// plain ≈$ amounts (never a misleading single rate).
const r6 = (x) => String(Math.round(x * 1e6) / 1e6);
const mra = o.moneyRates ? { w: r6(o.moneyRates.w), r: r6(o.moneyRates.r), q: r6(o.moneyRates.q) } : null;
const mra = o.moneyRates ? { w: r6(o.moneyRates.w), r: r6(o.moneyRates.r), q: r6(o.moneyRates.q), ...(o.moneyRates.i != null ? { i: r6(o.moneyRates.i) } : {}) } : null;
$("st-gross-sub").textContent = t("ov.gross_note") + ((o.savedEstimated || 0) > 0 ? " · " + t("ov.saved_from_legacy", { n: fmtW(o.savedEstimated) }) : "")
+ (o.savedUsdGrossTotal
? " · " + (mra ? t("ov.gross_formula", { f: o.foldsTotal, g: fmtW(o.grossSavedTotal), r: mra.r, n: fmtUsd(o.savedUsdGrossTotal) }) : t("ov.money_eq", { n: fmtUsd(o.savedUsdGrossTotal) }))
Expand Down Expand Up @@ -1110,7 +1110,7 @@ function changelogCatOf(rawLine) {
const f = (v) => fmtW(v) + (mi > 0 ? " (−" + ((v / mi) * 100).toFixed(1) + "%)" : "");
hs.textContent = missSum > 0 ? t("ov.miss_split", { n: f(o.missNewTotal || 0), c: f(o.missCompTotal || 0), x: f(o.missTtlTotal || 0) }) : t("common.none");
if (o.missSplitUsdTotal)
hs.textContent += " · " + t("ov.miss_split_usd", { n: fmtUsd(o.missSplitUsdTotal.n), c: fmtUsd(o.missSplitUsdTotal.c), x: fmtUsd(o.missSplitUsdTotal.x) }) + (mra ? " " + t("ov.miss_rates", mra) : "");
hs.textContent += " · " + t("ov.miss_split_usd", { n: fmtUsd(o.missSplitUsdTotal.n), c: fmtUsd(o.missSplitUsdTotal.c), x: fmtUsd(o.missSplitUsdTotal.x) }) + (mra && mra.i != null ? " " + t("ov.miss_rates", mra) : "");
}
$("st-input").textContent = o.inputTokens ? fmtW(o.inputTokens) : t("common.none");
$("st-cached").textContent = o.cachedTokens ? fmtW(o.cachedTokens) : t("common.none");
Expand All @@ -1119,7 +1119,7 @@ function changelogCatOf(rawLine) {
// reconcile with the 花费 card (i + r + w + o == costUsdTotal), so
// every displayed token figure has a money face next to it.
const cu = o.costUsdSplitTotal;
$("st-input-sub").textContent = cu ? t("ov.tier_unhit", { n: fmtUsd(cu.i) }) + (mra ? " · " + t("ov.at_input", { v: mra.w }) : "") : "";
$("st-input-sub").textContent = cu ? t("ov.tier_unhit", { n: fmtUsd(cu.i) }) + (mra && mra.i != null ? " · " + t("ov.at_input", { v: mra.i }) : "") : "";
$("st-cached-sub").textContent = cu ? t("ov.money_eq", { n: fmtUsd(cu.r) }) + (mra ? " · " + t("ov.at_read", { v: mra.r }) : "") : "";
$("st-output-sub").textContent = cu ? t("ov.money_eq", { n: fmtUsd(cu.o) }) + (mra ? " · " + t("ov.at_output", { v: mra.q }) : "") : "";
const pb = $("protocol-body");
Expand Down Expand Up @@ -2726,9 +2726,9 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " +
// #4899 v5: per-session rate args — show THE price inside each formula,
// same rule as the overview (only when one price actually applies).
const d6 = (x) => String(Math.round(x * 1e6) / 1e6);
const drates = d.rates ? { w: d6(d.rates.w), r: d6(d.rates.r), q: d6(d.rates.q) } : null;
const drates = d.rates ? { w: d6(d.rates.w), r: d6(d.rates.r), q: d6(d.rates.q), ...(d.rates.i != null ? { i: d6(d.rates.i) } : {}) } : null;
const inSub = (d.costUsd ? t("ov.tier_unhit", { n: fmtUsd(d.costUsd.input) }) : "")
+ (drates ? " · " + t("ov.at_input", { v: drates.w }) : "")
+ (drates && drates.i != null ? " · " + t("ov.at_input", { v: drates.i }) : "")
+ (d.payback != null && d.savedUsdGross != null ? " · " + t("det.in_counterfactual", { n: fmtUsd(d.savedUsdGross) }) : "");
mini(parts, t("ov.input_tokens"), d.inputTokens ? fmtW(d.inputTokens) : null, false, inSub);
mini(parts, t("ov.cached_tokens"), d.cachedTokens ? fmtW(d.cachedTokens) : null, false,
Expand Down Expand Up @@ -2756,7 +2756,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " +
// #4899: $ face under the missed-tokens split (current price table); tokens
// only when no price resolves.
const missLine = missArgs
? t("det.miss_split_line", missArgs) + (d.missSplitUsd ? "<br>≈ " + escapeHtml(t("ov.miss_split_usd", { n: fmtUsd(d.missSplitUsd.n), c: fmtUsd(d.missSplitUsd.c), x: fmtUsd(d.missSplitUsd.x) })) + (drates ? " " + escapeHtml(t("ov.miss_rates", drates)) : "") : "")
? t("det.miss_split_line", missArgs) + (d.missSplitUsd ? "<br>≈ " + escapeHtml(t("ov.miss_split_usd", { n: fmtUsd(d.missSplitUsd.n), c: fmtUsd(d.missSplitUsd.c), x: fmtUsd(d.missSplitUsd.x) })) + (drates && drates.i != null ? " " + escapeHtml(t("ov.miss_rates", drates)) : "") : "")
: "";
mini(parts, t("det.hit_pct"), d.cacheHitPct == null ? null : d.cacheHitPct.toFixed(1) + "%", false, hitSub, missLine);
mini(parts, t("ov.output_tokens"), d.outputTokens ? fmtW(d.outputTokens) : null, false,
Expand Down
10 changes: 5 additions & 5 deletions src/web/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"ov.tier_unhit": "其中未命中部分折合约 {n}",
"ov.gross_formula": "共 {f} 次折叠,Σ(单次省 token × 其后请求数) = {g};按缓存读价 ${r}/Mtok 计折合约 {n}",
"ov.net_rates": "(重建按缓存写价−读价差 ${w}−${r}、摘要按输出价 ${q}、抵扣按读价 ${r},$/Mtok)",
"ov.payback_rates": "(单价 $/Mtok:重建按 输入−读 ${w}−${r} · 摘要按输出 ${q} · 抵扣按读 ${r})",
"ov.miss_rates": "(新增内容@输入价 ${w} · 重建/回补@读价 ${r}/Mtok)",
"ov.payback_rates": "(单价 $/Mtok:重建按 写价−读价 ${w}−${r} · 摘要按输出 ${q} · 抵扣按读 ${r})",
"ov.miss_rates": "(新增内容@输入价 ${i} · 重建/回补@读价 ${r}/Mtok)",
"ov.at_input": "输入价 ${v}/Mtok",
"ov.at_read": "缓存读价 ${v}/Mtok",
"ov.at_output": "输出价 ${v}/Mtok",
Expand Down Expand Up @@ -772,9 +772,9 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"ov.payback_wait": "not yet (≈{k} more turns)",
"ov.tier_unhit": "unhit portion worth ≈ {n}",
"ov.gross_formula": "{f} folds in total, Σ(tokens saved per fold × later requests) = {g}; at cache-read ${r}/Mt that is ≈ {n}",
"ov.net_rates": "(replays at cache-write−read delta ${w}−${r}, summaries at output ${q}, credit at read ${r}; $/Mt)",
"ov.payback_rates": "(rates $/Mt: replay at input−read ${w}−${r} · summary at output ${q} · credit at read ${r})",
"ov.miss_rates": "(new content @ input ${w} · rebuild/repay @ read ${r}, $/Mt)",
"ov.net_rates": "(replays at write−read delta ${w}−${r}, summaries at output ${q}, credit at read ${r}; $/Mt)",
"ov.payback_rates": "(rates $/Mt: replay at write−read ${w}−${r} · summary at output ${q} · credit at read ${r})",
"ov.miss_rates": "(new content @ input ${i} · rebuild/repay @ read ${r}, $/Mt)",
"ov.at_input": "input ${v}/Mt",
"ov.at_read": "cache read ${v}/Mt",
"ov.at_output": "output ${v}/Mt",
Expand Down
43 changes: 29 additions & 14 deletions src/web/sessions-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ interface WebSessionSummary {
/** #4899 v4: the exact tier rates (USD/Mtok) this session's dollar figures
* were computed with — live price tiers when resolvable, else the stamped
* profile. Exposed so panel formula lines can print the prices themselves.
* Absent when no price resolves (tokens-only session). */
rates?: { w: number; r: number; q: number };
* Absent when no price resolves (tokens-only session). #4956: `w` follows
* the kernel fold contract (the cache-WRITE rate); `i` carries the INPUT
* rate separately for the spend/miss faces that bill new content at input
* (absent on stamped-only sessions, where no input-priced face exists). */
rates?: { w: number; r: number; q: number; i?: number };
/** Σ T — measured compression re-pay tokens. */
repayCost?: number;
/** Σ σ — summary generation cost (output tokens). */
Expand Down Expand Up @@ -205,8 +208,10 @@ interface WebOverview {
foldsTotal: number;
/** #4899 v4: single rate triple (USD/Mtok) when every priced session
* resolves identical rates — lets formula lines name THE price. Absent
* when several models bill differently (totals stay per-session then). */
moneyRates?: { w: number; r: number; q: number };
* when several models bill differently (totals stay per-session then).
* #4956: `i` (input rate) is present only while every input-priced face
* in the fleet agrees on one value. */
moneyRates?: { w: number; r: number; q: number; i?: number };
/** #4899: Σ money-mirrored net savings (only priced sessions contribute). */
savedUsdTotal: number;
/** #4899 v2: Σ money-mirrored GROSS savings (avoided turns @ read rate).
Expand Down Expand Up @@ -664,12 +669,16 @@ function livePriceForSummary(s: SummarySource): LivePrice | undefined {
}

/** Absolute $/Mtok profile {w,r,q} for the fold economics mirror, newest
* source first: (1) the live-resolved tier prices (input / cacheRead /
* source first: (1) the live-resolved tier prices (cacheWrite / cacheRead /
* output) — always fresh, so price edits propagate; (2) a stamped ABSOLUTE
* profile (model no longer in any price table); (3) legacy dimensionless
* ratio profiles anchored against the stamped billing price (kernel defaults
* 1/0.1/4 fill partial profiles, as before). Nothing usable → undefined:
* tokens only, never fabricated dollars. */
* tokens only, never fabricated dollars. #4956: w is the cache-WRITE rate on
* every branch (kernel fold contract: (w−r)·T re-uploads at the write
* premium) — previously the live branch fed it the INPUT rate, overstating
* savings ~28% for write-premium providers and jumping when a model left the
* table (the stamped branch already carried the write rate). */
function savedUsdProfileForSummary(s: SummarySource, live?: LivePrice): { w: number; r: number; q: number } | undefined {
if (live !== undefined) return { w: live.cacheWrite, r: live.cacheRead, q: live.output };
const o = s.metadata["cachePriceProfile"];
Expand Down Expand Up @@ -913,13 +922,13 @@ function summaryOf(s: SummarySource, live: boolean): WebSessionSummary {
? { n: ((agg?.agg?.nc ?? 0) * livePrice.input) / 1e6, c: ((agg?.agg?.cr ?? 0) * livePrice.cacheRead) / 1e6, x: ((agg?.agg?.tr ?? 0) * livePrice.cacheRead) / 1e6 }
: undefined;
// #4899 v4: publish the unit rates this session's dollars were computed
// with so the panel can print them INSIDE the formulas (fold math uses
// usdProf; spend/miss mirrors use livePrice — same tiers whenever both).
// with so the panel can print them INSIDE the formulas. #4956: the fold
// formula's w is the cache-WRITE rate; the input rate rides along as `i`
// for the spend/miss faces that bill new content at input (live-only —
// stamped sessions have no input-priced face, so no i).
const rates = usdProf !== undefined
? { w: usdProf.w, r: usdProf.r, q: usdProf.q }
: livePrice !== undefined
? { w: livePrice.cacheWrite, r: livePrice.cacheRead, q: livePrice.output }
: undefined;
? { w: usdProf.w, r: usdProf.r, q: usdProf.q, ...(livePrice !== undefined ? { i: livePrice.input } : {}) }
: undefined;
// Untitled sessions: fall back to the first compression block's topic/summary lead.
let firstBlockHint = "";
const fb = s.state.blocks.find((b) => b.topic || b.summary);
Expand Down Expand Up @@ -1135,7 +1144,7 @@ export async function buildOverview(): Promise<WebOverview> {
let costUsdTotal = 0, savedUsdTotal = 0, savedUsdGrossTotal = 0, hasMoneyData = false;
let cuI = 0, cuR = 0, cuW = 0, cuO = 0;
// #4899 v4: fold count + fleet-wide rate uniformity (see WebOverview.rates).
let foldsTotal = 0, mrSeen = false, mrMulti = false, mW = 0, mR = 0, mQ = 0;
let foldsTotal = 0, mrSeen = false, mrMulti = false, mW = 0, mR = 0, mQ = 0, mISeen = false, mIMulti = false, mI = 0;
let missUsdN = 0, missUsdC = 0, missUsdX = 0, hasMissUsd = false;
let coverageLostFoldTotal = 0, coverageLostFrozenTotal = 0;
let pbSpent = 0, pbSaved = 0, pbTurns = 0, hasPayback = false;
Expand Down Expand Up @@ -1189,6 +1198,12 @@ export async function buildOverview(): Promise<WebOverview> {
mR = s.rates.r;
mQ = s.rates.q;
} else if (s.rates.w !== mW || s.rates.r !== mR || s.rates.q !== mQ) mrMulti = true;
// #4956: i is optional (stamped-only sessions carry none) — only
// present values constrain fleet-wide uniformity.
const si = s.rates.i;
if (si !== undefined) {
if (!mISeen) { mISeen = true; mI = si; } else if (si !== mI) mIMulti = true;
}
}
if (s.savedUsd !== undefined) {
hasMoneyData = true;
Expand Down Expand Up @@ -1245,7 +1260,7 @@ export async function buildOverview(): Promise<WebOverview> {
savedUsdTotal,
savedUsdGrossTotal,
foldsTotal,
...(mrSeen && !mrMulti ? { moneyRates: { w: mW, r: mR, q: mQ } } : {}),
...(mrSeen && !mrMulti ? { moneyRates: { w: mW, r: mR, q: mQ, ...(mISeen && !mIMulti ? { i: mI } : {}) } } : {}),
...(hasPayback
? { paybackUsdTotal: { spent: Math.round(pbSpent * 1e4) / 1e4, saved: Math.round(pbSaved * 1e4) / 1e4, turns: pbTurns } }
: {}),
Expand Down
Loading
Loading