fix(web): context meter no longer reads 1000k just under a million tokens (#17539)

This commit is contained in:
luke authored and GitHub committed 2026-10-12 05:13:54 -03:00
1 parent a27cf8af51
commit 58d253231d
2 files changed
+12 -1

No files matched your search

+10
View File
@@ -58,6 +58,16 @@ describe("V2 context window presentation", () => {
it("formats compact token values", () => {
expect(formatContextWindowTokens(1_500)).toBe("1.5k");
});
it.each([
[999_499, "999k"],
[999_500, "1m"],
[999_999, "1m"],
[1_000_000, "1m"],
[1_100_000, "1.1m"],
])("formats %d tokens as %s at the million boundary", (tokens, expected) => {
expect(formatContextWindowTokens(tokens)).toBe(expected);
});
});
describe("live provider-turn usage (#8144)", () => {
+2 -1
View File
@@ -171,7 +171,8 @@ export function formatContextWindowTokens(value: number | null): string {
if (value < 10_000) {
return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;
}
if (value < 1_000_000) {
// Anything from 999,500 rounds to 1000k, so it belongs to the next unit.
if (value < 999_500) {
return `${Math.round(value / 1_000)}k`;
}
return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}m`;