Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(dashboard): handle missing cost data in model cost table

Steven Enamakel1989c320d543
diff --git a/app/src/components/dashboard/ModelCostTable.tsx b/app/src/components/dashboard/ModelCostTable.tsx
index 5452b40d11..50d946d705 100644
--- a/app/src/components/dashboard/ModelCostTable.tsx
+++ b/app/src/components/dashboard/ModelCostTable.tsx
@@ -1,90 +1,107 @@
+import type { ReactNode } from 'react';
+
import type { CostDashboardModelStats } from '../../hooks/useCostDashboard';
import { useT } from '../../lib/i18n/I18nContext';
-import {
- Badge,
- EmptyState,
- Progress,
- Table,
- TableBody,
- TableCell,
- TableHead,
- TableHeader,
- TableRow,
-} from '../ui';
+import { Badge, DataTable, type DataTableColumn, EmptyState, Progress } from '../ui';
import { formatCurrency, formatTokens } from './formatCurrency';
interface ModelCostTableProps {
models: CostDashboardModelStats[];
currency: string;
+ /** Card heading / hint, from the dashboard section that hosts the table. */
+ title?: ReactNode;
+ description?: ReactNode;
}
/** Per-model spend for the window: model, provider chip, volume, cost, share. */
-const ModelCostTable = ({ models, currency }: ModelCostTableProps) => {
+const ModelCostTable = ({ models, currency, title, description }: ModelCostTableProps) => {
const { t } = useT();
- if (models.length === 0) {
- return (
- <EmptyState
- data-testid="model-cost-table-empty"
- label={t('settings.costDashboard.noModels')}
- />
- );
- }
+
+ const columns: DataTableColumn<CostDashboardModelStats>[] = [
+ {
+ id: 'model',
+ header: t('settings.costDashboard.model'),
+ // `w-full max-w-0` lets the name truncate instead of widening the table.
+ className: 'w-full max-w-0',
+ cell: row => {
+ const modelName = row.model.includes('/')
+ ? row.model.split('/').slice(1).join('/')
+ : row.model;
+ return (
+ <div className="truncate font-medium text-content" title={row.model}>
+ {modelName}
+ </div>
+ );
+ },
+ },
+ {
+ id: 'provider',
+ header: t('settings.costDashboard.provider'),
+ className: 'whitespace-nowrap',
+ cell: row => <Badge>{row.provider ?? t('settings.costDashboard.unknownProvider')}</Badge>,
+ },
+ {
+ id: 'tokens',
+ header: t('settings.costDashboard.tokens'),
+ align: 'right',
+ className: 'whitespace-nowrap tabular-nums text-content-secondary',
+ cell: row => formatTokens(row.total_tokens),
+ },
+ {
+ id: 'requests',
+ header: t('settings.costDashboard.requests'),
+ align: 'right',
+ className: 'whitespace-nowrap tabular-nums text-content-secondary',
+ cell: row => row.request_count,
+ },
+ {
+ id: 'cost',
+ header: t('settings.costDashboard.cost'),
+ align: 'right',
+ className: 'whitespace-nowrap font-medium tabular-nums text-content',
+ cell: row => formatCurrency(row.cost_usd, currency),
+ },
+ {
+ id: 'share',
+ header: t('settings.costDashboard.percentOfTotal'),
+ align: 'right',
+ className: 'whitespace-nowrap',
+ cell: row => {
+ const sharePct = Math.max(0, Math.min(100, row.percent_of_total));
+ return (
+ <div className="flex items-center justify-end gap-2">
+ <Progress value={sharePct} className="h-1 w-14" />
+ <span className="w-11 text-right tabular-nums text-content-secondary">
+ {`${sharePct.toFixed(1)}%`}
+ </span>
+ </div>
+ );
+ },
+ },
+ ];
return (
- <div data-testid="model-cost-table">
- <Table>
- <TableHeader>
- <TableRow className="hover:bg-transparent">
- <TableHead className="w-full">{t('settings.costDashboard.model')}</TableHead>
- <TableHead>{t('settings.costDashboard.provider')}</TableHead>
- <TableHead className="text-right">{t('settings.costDashboard.tokens')}</TableHead>
- <TableHead className="text-right">{t('settings.costDashboard.requests')}</TableHead>
- <TableHead className="text-right">{t('settings.costDashboard.cost')}</TableHead>
- <TableHead className="text-right">
- {t('settings.costDashboard.percentOfTotal')}
- </TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {models.map(row => {
- const modelName = row.model.includes('/')
- ? row.model.split('/').slice(1).join('/')
- : row.model;
- const sharePct = Math.max(0, Math.min(100, row.percent_of_total));
- return (
- <TableRow key={row.model} data-testid={`model-row-${row.model}`}>
- {/* `w-full max-w-0` lets the name truncate instead of widening the table. */}
- <TableCell className="w-full max-w-0">
- <div className="truncate font-medium text-content" title={row.model}>
- {modelName}
- </div>
- </TableCell>
- <TableCell className="whitespace-nowrap">
- <Badge>{row.provider ?? t('settings.costDashboard.unknownProvider')}</Badge>
- </TableCell>
- <TableCell className="whitespace-nowrap text-right tabular-nums text-content-secondary">
- {formatTokens(row.total_tokens)}
- </TableCell>
- <TableCell className="whitespace-nowrap text-right tabular-nums text-content-secondary">
- {row.request_count}
- </TableCell>
- <TableCell className="whitespace-nowrap text-right font-medium tabular-nums text-content">
- {formatCurrency(row.cost_usd, currency)}
- </TableCell>
- <TableCell className="whitespace-nowrap">
- <div className="flex items-center justify-end gap-2">
- <Progress value={sharePct} className="h-1 w-14" />
- <span className="w-11 text-right tabular-nums text-content-secondary">
- {`${sharePct.toFixed(1)}%`}
- </span>
- </div>
- </TableCell>
- </TableRow>
- );
- })}
- </TableBody>
- </Table>
- </div>
+ // Sits among other dashboard cards on a scrolling page, so it does not
+ // fill; past `maxHeight` its rows scroll under the pinned header.
+ <DataTable<CostDashboardModelStats>
+ fill={false}
+ title={title}
+ description={description}
+ columns={columns}
+ rows={models}
+ rowKey={row => row.model}
+ rowTestId={undefined}
+ renderRow={undefined}
+ ariaLabel={t('settings.costDashboard.modelBreakdown')}
+ testId="model-cost-table"
+ empty={
+ <EmptyState
+ data-testid="model-cost-table-empty"
+ label={t('settings.costDashboard.noModels')}
+ />
+ }
+ rowClassName={() => undefined}
+ />
);
};