Skip to content

Commit 58d2532

Browse files
authored
fix(web): context meter no longer reads 1000k just under a million tokens (pingdotgg#17539)
1 parent a27cf8a commit 58d2532

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎apps/web/src/lib/contextWindow.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ describe("V2 context window presentation", () => {
5858
it("formats compact token values", () => {
5959
expect(formatContextWindowTokens(1_500)).toBe("1.5k");
6060
});
61+
62+
it.each([
63+
[999_499, "999k"],
64+
[999_500, "1m"],
65+
[999_999, "1m"],
66+
[1_000_000, "1m"],
67+
[1_100_000, "1.1m"],
68+
])("formats %d tokens as %s at the million boundary", (tokens, expected) => {
69+
expect(formatContextWindowTokens(tokens)).toBe(expected);
70+
});
6171
});
6272

6373
describe("live provider-turn usage (#8144)", () => {

‎apps/web/src/lib/contextWindow.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ export function formatContextWindowTokens(value: number | null): string {
171171
if (value < 10_000) {
172172
return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;
173173
}
174-
if (value < 1_000_000) {
174+
// Anything from 999,500 rounds to 1000k, so it belongs to the next unit.
175+
if (value < 999_500) {
175176
return `${Math.round(value / 1_000)}k`;
176177
}
177178
return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}m`;

0 commit comments

Comments
 (0)