Skip to content
Merged
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
8 changes: 3 additions & 5 deletions apps/web-roo-code/src/app/evals/evals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ export function Evals({
<TableRow key={run.id}>
<TableCell title={run.model?.description}>
<div className="font-sans">{run.label}</div>
<div className="text-xs opacity-50">
{formatTokens(run.modelInfo?.contextWindow ?? 0)}
</div>
<div className="text-xs opacity-50">{formatTokens(run.modelInfo?.contextWindow)}</div>
</TableCell>
<TableCell className="border-r">
<div className="flex flex-row gap-2">
<div>{formatCurrency(run.modelInfo?.inputPrice ?? 0)}</div>
<div>{formatCurrency(run.modelInfo?.inputPrice)}</div>
<div className="opacity-25">/</div>
<div>{formatCurrency(run.modelInfo?.outputPrice ?? 0)}</div>
<div>{formatCurrency(run.modelInfo?.outputPrice)}</div>
</div>
</TableCell>
<TableCell className="font-mono">{formatDuration(run.taskMetrics.duration)}</TableCell>
Expand Down
7 changes: 6 additions & 1 deletion apps/web-roo-code/src/lib/format-currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const formatter = new Intl.NumberFormat("en-US", {
currency: "USD",
})

export const formatCurrency = (amount: number) => formatter.format(amount)
export const formatCurrency = (amount: number | null | undefined) => {
if (amount === null || amount === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be good to add unit tests for this new null/undefined handling behavior? I notice there aren't any tests for these formatting functions yet, and it would help ensure the "-" fallback works correctly across all edge cases.

return "-"
}
return formatter.format(amount)
}

export const parsePrice = (price?: string) => (price ? parseFloat(price) * 1_000_000 : undefined)
6 changes: 5 additions & 1 deletion apps/web-roo-code/src/lib/format-duration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const formatDuration = (durationMs: number) => {
export const formatDuration = (durationMs: number | null | undefined) => {
if (durationMs === null || durationMs === undefined) {
return "-"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same null-checking pattern as the other formatters. Could we consider extracting this into a shared utility like formatWithFallback(value, formatter) to reduce duplication? Though I understand if we prefer the explicit approach for clarity.

}

const seconds = Math.floor(durationMs / 1000)
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
Expand Down
6 changes: 5 additions & 1 deletion apps/web-roo-code/src/lib/format-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const formatTokens = (tokens: number, decimals = 0) => {
export const formatTokens = (tokens: number | null | undefined, decimals = 0) => {
if (tokens === null || tokens === undefined) {
return "-"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chart rendering code in evals.tsx still passes potentially null/undefined values to formatCurrency within the chart components. Is the Recharts library handling these gracefully, or should we add null checks before passing to the chart components?

}

if (tokens < 1000) {
return tokens.toString()
}
Expand Down
Loading