@devries-cameron20 / t3code-1 / commits / 7a88b19576
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): custom model price cells take only numbers (#19245)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Rakshith Bhat committed Oct 19, 2026 at 01:02 UTC 7a88b19576f6830c3a1daf488c40cb3cf41edf3b
3 files changed +39 -6
apps/web/src/components/usage/UsagePriceOverrides.tsx
+8 -5
@@ -26,7 +26,7 @@ import { Label } from "../ui/label";
26 import { Menu, MenuCheckboxItem, MenuPopup, MenuSeparator, MenuTrigger } from "../ui/menu";
27 import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../ui/table";
28 import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
29 -import { USAGE_PRICE_FIELDS } from "./usagePriceForm";
29 +import { isUsagePriceEdit, USAGE_PRICE_FIELDS } from "./usagePriceForm";
30 import {
31 isEmptyUsagePriceDraft,
32 usageAliasCell,
@@ -467,13 +467,15 @@ export function UsagePriceOverrides({
467 ) : (
468 USAGE_PRICE_FIELDS.map((field) => {
469 const cell = usagePriceCell(selected, row.model, field.key);
470 + const value =
471 + row.values[field.key] ?? (row.isNew ? "" : cell.value);
472 return (
473 <TableCell key={field.key}>
474 <Input
475 size="compact"
476 inputMode="decimal"
477 aria-label={`${field.label} price for ${row.model || "new model"}`}
476 - value={row.values[field.key] ?? (row.isNew ? "" : cell.value)}
478 + value={value}
479 placeholder={
480 row.isNew
481 ? field.optional
@@ -484,9 +486,10 @@ export function UsagePriceOverrides({
486 autoComplete="off"
487 disabled={locked}
488 font="mono"
487 - onChange={(event) =>
488 - editCell(row, field.key, event.target.value)
489 - }
489 + onChange={(event) => {
490 + if (isUsagePriceEdit(value, event.target.value))
491 + editCell(row, field.key, event.target.value);
492 + }}
493 />
494 </TableCell>
495 );
apps/web/src/components/usage/usagePriceForm.test.ts
+17 -1
@@ -1,6 +1,6 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { parseUsagePriceForm, usagePriceForm } from "./usagePriceForm.ts";
3 +import { isUsagePriceEdit, parseUsagePriceForm, usagePriceForm } from "./usagePriceForm.ts";
4
5 describe("model price entry", () => {
6 it("preserves exact model IDs and fractional rates", () => {
@@ -70,4 +70,20 @@ describe("model price entry", () => {
70 expect(parseUsagePriceForm({ ...form, cacheWriteCostPerMillionTokens: "invalid" })).toBeNull();
71 expect(parseUsagePriceForm({ ...form, model: " " })).toBeNull();
72 });
73 +
74 + it("lets price cells take only numbers while typing", () => {
75 + for (const price of ["0.075", ".5", "15", "1e-7", " 2.5 "])
76 + for (let end = 1; end <= price.length; end++)
77 + expect(isUsagePriceEdit(price.slice(0, end - 1), price.slice(0, end))).toBe(true);
78 + for (const next of ["a", "3a", "$3", "-1", "1.2.3", "e", "1,000"])
79 + expect(isUsagePriceEdit("", next)).toBe(false);
80 + });
81 +
82 + it("never blocks deleting part of a price, but blocks replacing it with a non-number", () => {
83 + expect(isUsagePriceEdit("1e-7", "e-7")).toBe(true);
84 + expect(isUsagePriceEdit("1e-7", "1-7")).toBe(true);
85 + expect(isUsagePriceEdit("1e-7", "a7")).toBe(false);
86 + expect(isUsagePriceEdit("2.5", "x")).toBe(false);
87 + expect(isUsagePriceEdit("123456", "1.2.3")).toBe(false);
88 + });
89 });
apps/web/src/components/usage/usagePriceForm.ts
+14
@@ -22,6 +22,20 @@ export function usagePriceForm(model = "", price?: UsageModelPriceOverride): Usa
22 };
23 }
24
25 +/**
26 + * Whether a price cell may change from `previous` to `next` while typing:
27 + * digits with an optional decimal point, plus the exponent form saved rates can
28 + * stringify to. Deleting a run of characters is always allowed so a mid-value
29 + * delete such as `1e-7` to `e-7` is not stuck; saving still validates the result.
30 + */
31 +export function isUsagePriceEdit(previous: string, next: string): boolean {
32 + if (/^\s*(?:\d*\.?\d*|(?:\d+\.?\d*|\.\d+)e[+-]?\d*)\s*$/i.test(next)) return true;
33 + if (next.length >= previous.length) return false;
34 + let start = 0;
35 + while (start < next.length && next[start] === previous[start]) start++;
36 + return next.slice(start) === previous.slice(previous.length - (next.length - start));
37 +}
38 +
39 /** Blank cache prices use the input rate; explicit zero means free. */
40 export function parseUsagePriceForm(
41 form: UsagePriceForm,