7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
refactor(dashboard): extract routing/model-table modules from FallbackPage
Tashfeendbe6aaa99cbe
diff --git a/client/src/components/command-palette.tsx b/client/src/components/command-palette.tsxindex 444b81fa..6749784c 100644--- a/client/src/components/command-palette.tsx+++ b/client/src/components/command-palette.tsx@@ -20,7 +20,7 @@ import { apiFetch } from '@/lib/api'import { toast } from '@/lib/toast'import { apiBaseUrl } from '@/components/api-usage'import { useI18n } from '@/i18n'-import type { FallbackEntry } from '@/pages/FallbackPage'+import type { FallbackEntry } from '@/lib/routing'// Open the palette from anywhere (navbar button); same custom-event idiom as// UNAUTHORIZED_EVENT in lib/api.ts.diff --git a/client/src/components/custom-weights-popover.tsx b/client/src/components/custom-weights-popover.tsxnew file mode 100644index 00000000..9f8f13aa--- /dev/null+++ b/client/src/components/custom-weights-popover.tsx@@ -0,0 +1,114 @@+import { useState } from 'react'+import { SlidersHorizontal } from 'lucide-react'+import { useI18n } from '@/i18n'+import { Button } from '@/components/ui/button'+import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover'+import type { RoutingWeights } from '@/lib/routing'++// Slider axes share the colors used by the score table columns.+// `tKey` is the i18n suffix under `strategies.weight*`.+const WEIGHT_AXES: { key: keyof RoutingWeights; tKey: string; color: string }[] = [+ { key: 'reliability', tKey: 'weightReliability', color: '#22c55e' },+ { key: 'speed', tKey: 'weightSpeed', color: '#3b82f6' },+ { key: 'intelligence', tKey: 'weightIntelligence', color: '#a855f7' },+]++// Slider popover for the 'custom' strategy. Sliders are independent (0-100)+// and the server renormalizes any vector, so we just show each axis's+// effective share live. Nothing is saved until Apply is pressed.+export function CustomWeightsPopover({ saved, onSave, saving }: {+ saved: RoutingWeights+ onSave: (w: RoutingWeights) => void+ saving: boolean+}) {+ const { t } = useI18n()+ const [values, setValues] = useState<RoutingWeights>(() => fromSaved(saved))+ const [dirty, setDirty] = useState(false)++ // Defensive: an older/partial server response (or a future field rename) could+ // leave `saved` undefined; never let that white-screen the whole page. Fall+ // back to an even split.+ function fromSaved(w?: RoutingWeights): RoutingWeights {+ const safe = w ?? { reliability: 1 / 3, speed: 1 / 3, intelligence: 1 / 3 }+ return {+ reliability: Math.round(safe.reliability * 100),+ speed: Math.round(safe.speed * 100),+ intelligence: Math.round(safe.intelligence * 100),+ }+ }++ function update(key: keyof RoutingWeights, v: number) {+ setValues({ ...values, [key]: v })+ setDirty(true)+ }++ function apply() {+ if (sum <= 0) return+ onSave({+ reliability: values.reliability / 100,+ speed: values.speed / 100,+ intelligence: values.intelligence / 100,+ })+ setDirty(false)+ }++ const sum = values.reliability + values.speed + values.intelligence++ return (+ <Popover onOpenChange={open => { if (open) { setValues(fromSaved(saved)); setDirty(false) } }}>+ <PopoverTrigger className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg text-muted-foreground hover:text-foreground hover:bg-muted transition-colors">+ <SlidersHorizontal className="size-3.5" />+ {t('strategies.adjust')}+ </PopoverTrigger>+ <PopoverContent align="start" className="w-80">+ <div className="space-y-4">+ <div>+ <h3 className="text-sm font-medium">{t('strategies.customWeights')}</h3>+ <p className="mt-0.5 text-xs text-muted-foreground">+ {t('strategies.customWeightsHelp')}+ </p>+ </div>+ {WEIGHT_AXES.map(axis => {+ const share = sum > 0 ? Math.round((values[axis.key] / sum) * 100) : 0+ const axisLabel = t(`strategies.${axis.tKey}`)+ return (+ <div key={axis.key}>+ <div className="mb-1 flex items-baseline justify-between text-xs">+ <span className="inline-flex items-center gap-1.5">+ <span className="size-2 rounded-sm" style={{ background: axis.color }} />+ {axisLabel}+ </span>+ <span className="tabular-nums text-muted-foreground">{share}%</span>+ </div>+ <input+ type="range"+ min={0}+ max={100}+ step={1}+ value={values[axis.key]}+ onChange={e => update(axis.key, Number(e.target.value))}+ className="w-full cursor-pointer"+ style={{ accentColor: axis.color }}+ aria-label={`${axisLabel} weight`}+ />+ </div>+ )+ })}+ {sum <= 0 && (+ <p className="text-xs text-amber-600 dark:text-amber-500">+ {t('strategies.weightRequired')}+ </p>+ )}+ <Button+ size="sm"+ className="w-full"+ disabled={!dirty || sum <= 0 || saving}+ onClick={apply}+ >+ {saving ? t('common.applying') : dirty ? t('common.apply') : t('common.applied')}+ </Button>+ </div>+ </PopoverContent>+ </Popover>+ )+}diff --git a/client/src/components/model-table.tsx b/client/src/components/model-table.tsxnew file mode 100644index 00000000..edb4126d--- /dev/null+++ b/client/src/components/model-table.tsx@@ -0,0 +1,257 @@+import type { ReactNode } from 'react'+import { Link, useNavigate } from 'react-router-dom'+import { useSortable } from '@dnd-kit/sortable'+import { CSS } from '@dnd-kit/utilities'+import { useI18n } from '@/i18n'+import { CopyButton } from '@/components/copy-button'+import { Switch } from '@/components/ui/switch'+import { Tooltip } from '@/components/tooltip'+import {+ cleanQuotaLabel,+ formatContext,+ groupMaxContext,+ groupQuotaBadge,+ type ModelGroupRow,+ type Row,+} from '@/lib/routing'++// The unified model/provider table pieces, extracted from FallbackPage so the+// Models page and the per-model detail page share one module.++// A 0..1 value as a thin horizontal bar with the number beside it.+export function AxisBar({ value, color }: { value: number | undefined; color: string }) {+ const v = value ?? 0+ return (+ <div className="flex items-center gap-1.5">+ <div className="h-1.5 w-12 rounded-full bg-muted overflow-hidden">+ <div className="h-full rounded-full" style={{ width: `${Math.round(v * 100)}%`, backgroundColor: color }} />+ </div>+ <span className="font-mono text-[11px] text-muted-foreground tabular-nums w-7 text-right">+ {value === undefined ? '–' : Math.round(v * 100)}+ </span>+ </div>+ )+}++// The shared table header for the unified model/provider table — used by the+// Models page and the per-model detail page so their columns line up.+export function ModelTableHead() {+ const { t } = useI18n()+ return (+ <thead>+ <tr className="text-left text-muted-foreground border-b">+ <th className="py-2 pl-3 pr-1 w-6"></th>+ <th className="py-2 pr-2 w-6 text-center font-medium">#</th>+ <th className="py-2 pr-3 font-medium">{t('models.columnModel')}</th>+ <th className="py-2 pr-3 font-medium">+ <span className="inline-flex items-center gap-1"><span className="size-2 rounded-sm" style={{ background: '#22c55e' }} />{t('strategies.weightReliability')}</span>+ </th>+ <th className="py-2 pr-3 font-medium">+ <span className="inline-flex items-center gap-1"><span className="size-2 rounded-sm" style={{ background: '#3b82f6' }} />{t('strategies.weightSpeed')}</span>+ </th>+ <th className="py-2 pr-3 font-medium">+ <span className="inline-flex items-center gap-1"><span className="size-2 rounded-sm" style={{ background: '#a855f7' }} />{t('strategies.weightIntelligence')}</span>+ </th>+ <th className="py-2 pr-3 font-medium">+ <Tooltip text={t('strategies.guardrailsTooltip')}>+ <span className="underline decoration-dotted underline-offset-2 cursor-help">{t('strategies.guardrails')}</span>+ </Tooltip>+ </th>+ <th className="py-2 pr-3 font-medium text-right">+ <Tooltip text={t('strategies.scoreTooltip')}>+ <span className="underline decoration-dotted underline-offset-2 cursor-help">{t('strategies.scoreColumn')}</span>+ </Tooltip>+ </th>+ <th className="py-2 pr-3 font-medium text-right">{t('models.columnOn')}</th>+ </tr>+ </thead>+ )+}++// ── One row of the unified table ────────────────────────────────────────────+export function RowContent({+ row,+ rank,+ draggable,+ dragHandle,+ onToggle,+}: {+ row: Row+ rank: number+ draggable: boolean+ dragHandle?: ReactNode+ onToggle: (modelDbId: number, enabled: boolean) => void+}) {+ const { t } = useI18n()+ const guard = (row.headroom ?? 1) * (row.rateLimit ?? 1)+ return (+ <>+ <td className="py-2 pl-3 pr-1 w-6 align-middle">+ {draggable ? dragHandle : <span className="text-muted-foreground/30 select-none">·</span>}+ </td>+ <td className="py-2 pr-2 w-6 text-center font-mono text-xs text-muted-foreground tabular-nums align-middle">{rank}</td>+ <td className="py-2 pr-3 align-middle">+ <div className="flex items-center gap-2 flex-wrap">+ <span className="font-medium text-sm">{row.displayName}</span>+ <span className="text-xs text-muted-foreground">{row.platform}</span>+ {row.supportsVision && (+ <span+ title={t('models.visionTitle')}+ className="text-[10px] rounded-full px-1.5 py-0.5 bg-cyan-600/15 text-cyan-700 dark:bg-cyan-400/15 dark:text-cyan-400"+ >+ {t('models.vision')}+ </span>+ )}+ {row.supportsTools && (+ <span+ title={t('models.toolsTitle')}+ className="text-[10px] rounded-full px-1.5 py-0.5 bg-violet-600/15 text-violet-700 dark:bg-violet-400/15 dark:text-violet-400"+ >+ {t('models.tools')}+ </span>+ )}+ {(row.penalty ?? 0) > 0 && (+ <span className="text-[10px] text-amber-600 dark:text-amber-400">{t('models.penalty', { value: row.penalty })}</span>+ )}+ {row.totalRequests !== undefined && row.totalRequests > 0 && (+ <span className="text-[10px] text-muted-foreground/60 tabular-nums">{t('models.obs', { count: row.totalRequests })}</span>+ )}+ </div>+ <div className="text-[11px] text-muted-foreground/70 tabular-nums mt-0.5">+ {/* Token budget only when it's a real token count; rate-limited models+ (NVIDIA's "free · 40 RPM") show their rate, not "… tok/mo". */}+ {[+ (row.monthlyTokenBudgetTokens ?? 0) > 0 ? t('models.tokPerMonth', { count: row.monthlyTokenBudget }) : null,+ row.rpmLimit ? t('models.rpmLimit', { count: row.rpmLimit }) : null,+ row.rpdLimit ? t('models.rpdLimit', { count: row.rpdLimit }) : null,+ ].filter(Boolean).join(' · ') || cleanQuotaLabel(row.monthlyTokenBudget) || '—'}+ </div>+ </td>+ <td className="py-2 pr-3 align-middle"><AxisBar value={row.reliability} color="#22c55e" /></td>+ <td className="py-2 pr-3 align-middle"><AxisBar value={row.speed} color="#3b82f6" /></td>+ <td className="py-2 pr-3 align-middle"><AxisBar value={row.intelligence} color="#a855f7" /></td>+ <td className="py-2 pr-3 align-middle font-mono text-[11px] text-muted-foreground tabular-nums">+ {guard < 0.999 ? `×${guard.toFixed(2)}` : '—'}+ </td>+ <td className="py-2 pr-3 align-middle text-right font-mono text-xs font-medium tabular-nums">+ {row.score !== undefined ? row.score.toFixed(3) : '–'}+ </td>+ <td className="py-2 pr-3 align-middle text-right">+ <Switch checked={row.enabled} onCheckedChange={(c) => onToggle(row.modelDbId, c)} />+ </td>+ </>+ )+}++const dragDots = (+ <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">+ <circle cx="9" cy="6" r="1.5" /><circle cx="15" cy="6" r="1.5" />+ <circle cx="9" cy="12" r="1.5" /><circle cx="15" cy="12" r="1.5" />+ <circle cx="9" cy="18" r="1.5" /><circle cx="15" cy="18" r="1.5" />+ </svg>+)++// The collapsed header row for a logical-model group: name, provider count,+// union vision/tools badges, the best member's axis bars + score, and a single+// switch that enables/disables every provider in the group.+export function GroupHeaderCells({ group, rank, dragHandle, onToggleGroup }: {+ group: ModelGroupRow+ rank: number+ dragHandle?: ReactNode+ onToggleGroup: (memberIds: number[], enabled: boolean) => void+}) {+ const { t } = useI18n()+ const anyEnabled = group.members.some(m => m.enabled)+ const solo = group.members.length === 1+ const best = group.members.reduce((b, m) => ((m.score ?? -1) > (b.score ?? -1) ? m : b), group.members[0])+ const guard = (best.headroom ?? 1) * (best.rateLimit ?? 1)+ const vision = group.members.some(m => m.supportsVision)+ const tools = group.members.some(m => m.supportsTools)+ const quota = groupQuotaBadge(group.members, t)+ const maxCtx = groupMaxContext(group.members)+ // The model name links to its own page, which lists every provider that serves+ // it (replaces the old inline expansion).+ const detailId = encodeURIComponent(group.members[0].canonicalId ?? group.members[0].modelId)+ // The unified model string to paste into .env / API payloads (#343 quick-copy).+ const copyId = group.members[0].canonicalId ?? group.members[0].modelId+ return (+ <>+ <td className="py-2 pl-3 pr-1 w-6 align-middle">{dragHandle ?? <span className="text-muted-foreground/30 select-none">·</span>}</td>+ <td className="py-2 pr-2 w-6 text-center font-mono text-xs text-muted-foreground tabular-nums align-middle">{rank}</td>+ <td className="py-2 pr-3 align-middle">+ <div className="flex items-center gap-1.5 min-w-0">+ <Link to={`/models/chat/${detailId}`} aria-label={t('models.viewProviders')} onClick={e => e.stopPropagation()} className="flex items-center gap-2 flex-wrap text-left min-w-0">+ <span className="font-medium text-sm">{group.label}</span>+ {solo+ ? <span className="text-xs text-muted-foreground">{group.members[0].platform}</span>+ : <Tooltip text={t('models.servedBy', { providers: group.members.map(m => m.platform).join(', ') })}>+ <span className="text-[10px] rounded-full px-1.5 py-0.5 bg-muted text-muted-foreground">{t('models.providerCount', { count: group.members.length })}</span>+ </Tooltip>}+ {quota && (+ <span title={quota.title} className="text-[10px] rounded-full px-1.5 py-0.5 bg-muted text-muted-foreground tabular-nums">+ {quota.text}+ </span>+ )}+ {maxCtx > 0 && (+ <span title={t('models.ctxTitle')} className="text-[10px] rounded-full px-1.5 py-0.5 bg-muted text-muted-foreground tabular-nums">+ {t('models.ctxBadge', { size: formatContext(maxCtx) })}+ </span>+ )}+ {vision && (+ <span title={t('models.visionTitle')} className="text-[10px] rounded-full px-1.5 py-0.5 bg-cyan-600/15 text-cyan-700 dark:bg-cyan-400/15 dark:text-cyan-400">{t('models.vision')}</span>+ )}+ {tools && (+ <span title={t('models.toolsTitle')} className="text-[10px] rounded-full px-1.5 py-0.5 bg-violet-600/15 text-violet-700 dark:bg-violet-400/15 dark:text-violet-400">{t('models.tools')}</span>+ )}+ </Link>+ {/* Quick-copy the unified model id (#343). Stop propagation so it neither+ follows the model link nor triggers the row's navigate-on-click. */}+ <span onClick={e => e.stopPropagation()} className="shrink-0">+ <CopyButton text={copyId} className="size-6" label={t('models.copyModelId')} />+ </span>+ </div>+ </td>+ <td className="py-2 pr-3 align-middle"><AxisBar value={best.reliability} color="#22c55e" /></td>+ <td className="py-2 pr-3 align-middle"><AxisBar value={best.speed} color="#3b82f6" /></td>+ <td className="py-2 pr-3 align-middle"><AxisBar value={best.intelligence} color="#a855f7" /></td>+ <td className="py-2 pr-3 align-middle font-mono text-[11px] text-muted-foreground tabular-nums">{guard < 0.999 ? `×${guard.toFixed(2)}` : '—'}</td>+ <td className="py-2 pr-3 align-middle text-right font-mono text-xs font-medium tabular-nums">{best.score !== undefined ? best.score.toFixed(3) : '–'}</td>+ <td className="py-2 pr-3 align-middle text-right" onClick={e => e.stopPropagation()}>+ <Switch checked={anyEnabled} onCheckedChange={(c) => onToggleGroup(group.members.map(m => m.modelDbId), c)} />+ </td>+ </>+ )+}++export function SortableGroupRow({ group, rank, onToggleGroup }: {+ group: ModelGroupRow+ rank: number+ onToggleGroup: (memberIds: number[], enabled: boolean) => void+}) {+ const { t } = useI18n()+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: `grp:${group.key}` })+ const anyEnabled = group.members.some(m => m.enabled)+ const navigate = useNavigate()+ const detailId = encodeURIComponent(group.members[0].canonicalId ?? group.members[0].modelId)+ const handle = (+ <button+ {...attributes}+ {...listeners}+ onClick={e => e.stopPropagation()}+ className="cursor-grab active:cursor-grabbing text-muted-foreground/50 hover:text-foreground transition-colors"+ aria-label={t('models.dragToReorderGroup')}+ >+ {dragDots}+ </button>+ )+ return (+ <tr+ ref={setNodeRef}+ style={{ transform: CSS.Transform.toString(transform), transition }}+ onClick={() => navigate(`/models/chat/${detailId}`)}+ className={`border-b last:border-0 bg-card cursor-pointer transition-colors hover:[&>td]:bg-muted/50 [&>td:first-child]:rounded-l-lg [&>td:last-child]:rounded-r-lg ${isDragging ? 'opacity-50' : ''} ${anyEnabled ? '' : 'opacity-50'}`}+ >+ <GroupHeaderCells group={group} rank={rank} dragHandle={handle} onToggleGroup={onToggleGroup} />+ </tr>+ )+}diff --git a/client/src/components/token-usage-bar.tsx b/client/src/components/token-usage-bar.tsxnew file mode 100644index 00000000..419372e5--- /dev/null+++ b/client/src/components/token-usage-bar.tsx@@ -0,0 +1,113 @@+import { useEffect, useRef, useState } from 'react'+import { ChevronDown } from 'lucide-react'+import { useI18n } from '@/i18n'+import { formatPercent, formatTokens, platformColors, type TokenUsageData } from '@/lib/routing'++// Legend rows visible while collapsed (~6 rows: 6 × 16px line + 5 × 6px gap).+const LEGEND_COLLAPSED_PX = 126++// Stacked monthly token-budget bar with a collapsible per-model legend,+// extracted from FallbackPage.+export function TokenUsageBar({ data }: { data: TokenUsageData }) {+ const { t } = useI18n()+ const { totalBudget, totalUsed, models } = data+ const remaining = Math.max(0, totalBudget - totalUsed)+ const remainingPct = totalBudget > 0 ? formatPercent(remaining / totalBudget) : '0%'++ // Collapse the per-model legend to a few rows; the chevron reveals the rest.+ // The toggle only appears when the legend actually overflows the collapsed+ // height (column count — and so row count — depends on viewport width).+ const [expanded, setExpanded] = useState(false)+ const [collapsible, setCollapsible] = useState(false)+ const legendRef = useRef<HTMLDivElement>(null)+ useEffect(() => {+ const el = legendRef.current+ if (!el) return+ const check = () => setCollapsible(el.scrollHeight > LEGEND_COLLAPSED_PX + 1)+ check()+ const ro = new ResizeObserver(check)+ ro.observe(el)+ return () => ro.disconnect()+ }, [models.length])++ const modelsWithWidth = models.map(m => {+ const usedTokens = m.used ?? 0+ const remainingTokens = Math.max(0, m.budget - usedTokens)+ return {+ ...m,+ usedTokens,+ remainingTokens,+ widthPct: totalBudget > 0 ? (remainingTokens / totalBudget) * 100 : 0,+ }+ })+ const usedPct = totalBudget > 0 ? Math.min(100, (totalUsed / totalBudget) * 100) : 0++ return (+ <section className="rounded-3xl border bg-card p-5">+ <div className="flex items-baseline justify-between mb-3">+ <h2 className="text-sm font-medium">{t('models.monthlyTokenBudget')}</h2>+ <span className="text-xs text-muted-foreground tabular-nums">+ <span className="text-foreground font-medium">{formatTokens(remaining)}</span> {t('models.remaining')}+ <span className="mx-1.5">·</span>+ {remainingPct} {t('models.of')} {formatTokens(totalBudget)}+ {totalUsed > 0 && (+ <>+ <span className="mx-1.5">·</span>+ <span className="text-foreground font-medium">{formatTokens(totalUsed)}</span> {t('models.used')}+ </>+ )}+ </span>+ </div>++ <div className="flex h-2.5 rounded-full overflow-hidden bg-muted">+ {modelsWithWidth.map((m, i) => (+ <div+ key={i}+ title={`${m.displayName} (${m.platform}): ${formatTokens(m.remainingTokens)} ${t('models.remaining')}, ${formatTokens(m.usedTokens)} ${t('models.used')}`}+ style={{+ width: `${m.widthPct}%`,+ backgroundColor: platformColors[m.platform] ?? '#94a3b8',+ }}+ />+ ))}+ {totalUsed > 0 && (+ <div+ title={`Used: ${formatTokens(totalUsed)}`}+ className="bg-muted-foreground/30"+ style={{ width: `${usedPct}%` }}+ />+ )}+ </div>++ <div+ ref={legendRef}+ className="mt-4 overflow-hidden transition-[max-height] duration-300 ease-in-out"+ style={collapsible ? { maxHeight: expanded ? legendRef.current?.scrollHeight : LEGEND_COLLAPSED_PX } : undefined}+ >+ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-x-5 gap-y-1.5 text-xs tabular-nums">+ {modelsWithWidth.map((m, i) => (+ <div key={i} className="flex items-center gap-2 min-w-0">+ <span+ className="size-2 rounded-sm flex-shrink-0"+ style={{ backgroundColor: platformColors[m.platform] ?? '#94a3b8' }}+ />+ <span className="truncate">{m.displayName}</span>+ <span className="flex-1" />+ <span className="font-mono text-muted-foreground">{formatTokens(m.remainingTokens)}</span>+ </div>+ ))}+ </div>+ </div>++ {collapsible && (+ <button+ onClick={() => setExpanded(e => !e)}+ className="mt-2 flex w-full items-center justify-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"+ >+ {expanded ? t('models.showLess') : t('models.showAllModels', { count: models.length })}+ <ChevronDown className={`size-3.5 transition-transform duration-300 ${expanded ? 'rotate-180' : ''}`} />+ </button>+ )}+ </section>+ )+}diff --git a/client/src/lib/routing.ts b/client/src/lib/routing.tsnew file mode 100644index 00000000..64f23ace--- /dev/null+++ b/client/src/lib/routing.ts@@ -0,0 +1,191 @@+// Routing/model-table domain types and pure helpers, extracted from+// FallbackPage so the Models page, the per-model detail page, and the command+// palette share one module instead of importing from a page component.++export interface FallbackEntry {+ modelDbId: number+ priority: number+ effectivePriority: number+ penalty: number+ rateLimitHits: number+ enabled: boolean+ platform: string+ modelId: string+ displayName: string+ intelligenceRank: number+ speedRank: number+ sizeLabel: string+ rpmLimit: number | null+ rpdLimit: number | null+ monthlyTokenBudget: string+ // Parsed token count from the server (single source of truth — see+ // server/src/lib/budget.ts). Optional only because the dev mock omits it.+ monthlyTokenBudgetTokens?: number+ // Max context length in tokens (catalog value), or null when unrecorded.+ // Drives the catalog context-window filter on the Models page.+ contextWindow?: number | null+ supportsVision: boolean+ supportsTools: boolean+ source?: 'catalog' | 'custom'+ keyId?: number | null+ keyLabel?: string | null+ hasOverrides?: boolean+ keyCount: number+ // Logical-model grouping (sent by the server when unify is relevant). Absent+ // for ungrouped rows; the UI falls back to a per-row "solo" group then.+ groupKey?: string+ canonicalId?: string+ groupLabel?: string+}++export type RoutingStrategy = 'priority' | 'balanced' | 'smartest' | 'fastest' | 'reliable' | 'custom'++export type RoutingWeights = { reliability: number; speed: number; intelligence: number }++export interface RoutingScore {+ modelDbId: number+ reliability: number+ speed: number+ intelligence: number+ headroom: number+ rateLimit: number+ score: number+ totalRequests: number+}++export interface RoutingData {+ strategy: RoutingStrategy+ weights: RoutingWeights | null+ customWeights: RoutingWeights+ scores: (RoutingScore & { platform: string; modelId: string; displayName: string; enabled: boolean })[]+}++// A merged row: fallback-chain metadata + live bandit scores.+export type Row = FallbackEntry & Partial<RoutingScore>++export interface TokenUsageData {+ totalBudget: number+ totalUsed: number+ models: { displayName: string; platform: string; modelId?: string; budget: number; used?: number }[]+}++export function formatTokens(n: number): string {+ if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(1)}B`+ if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`+ if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`+ return String(n)+}++export function formatPercent(value: number): string {+ const pct = Math.max(0, Math.min(100, value * 100))+ if (pct > 0 && pct < 0.1) return '<0.1%'+ if (pct > 99.9 && pct < 100) {+ const floored = Math.floor(pct * 100) / 100+ return `${floored.toFixed(2).replace(/0+$/, '').replace(/\.$/, '')}%`+ }+ const digits = pct < 10 ? 1 : 0+ return `${pct.toFixed(digits).replace(/\.0$/, '')}%`+}++// Compact context-window label (whole-number K/M, base 1000): 8000 → "8K",+// 128000 → "128K", 1_000_000 → "1M". Used by the catalog context badge/filter.+export function formatContext(n: number): string {+ if (n >= 1_000_000) return `${Math.round(n / 1_000_000)}M`+ if (n >= 1_000) return `${Math.round(n / 1_000)}K`+ return String(n)+}++// The largest context window across a logical model's providers.+export function groupMaxContext(members: Row[]): number {+ return Math.max(0, ...members.map(m => m.contextWindow ?? 0))+}++// For models with no monthly token budget, surface their rate quota instead.+// Strips the catalog's decorative bits ("free · ", " per IP", "~", "?") so e.g.+// "free · 40 RPM" → "40 RPM", "free · 200/hr per IP" → "200/hr", "~? (anon)" →+// "anon". Returns null when nothing meaningful remains.+export function cleanQuotaLabel(s: string | undefined): string | null {+ if (!s) return null+ let c = s+ .replace(/free\s*·\s*/ig, '')+ .replace(/\s*per ip\s*/ig, '')+ .replace(/[~?]/g, '')+ .replace(/\s+/g, ' ')+ .trim()+ c = c.replace(/^\(([^()]*)\)$/, '$1').trim()+ return c || null+}++// The quota badge for a logical model: its summed monthly token budget when it+// has one (you can spend all providers' budgets via failover), else the best+// rate cap (RPM/RPD, or the catalog's rate label) for rate-limited providers.+// Shared by the Models-page group header and the per-model detail page.+export function groupQuotaBadge(+ members: Row[],+ t: (key: string, vars?: Record<string, string | number>) => string,+): { text: string; title: string } | null {+ const totalBudget = members.reduce((sum, m) => sum + (m.monthlyTokenBudgetTokens ?? 0), 0)+ const maxRpm = Math.max(0, ...members.map(m => m.rpmLimit ?? 0))+ const maxRpd = Math.max(0, ...members.map(m => m.rpdLimit ?? 0))+ const rateLabelText = members.map(m => cleanQuotaLabel(m.monthlyTokenBudget)).find(Boolean) ?? null+ if (totalBudget > 0) return { text: t('models.aggregateBudget', { count: formatTokens(totalBudget) }), title: t('models.aggregateBudgetTitle') }+ if (maxRpm > 0) return { text: t('models.rateRpm', { count: maxRpm }), title: t('models.rateTitle') }+ if (maxRpd > 0) return { text: t('models.rateRpd', { count: maxRpd }), title: t('models.rateTitle') }+ if (rateLabelText) return { text: rateLabelText, title: t('models.rateTitle') }+ return null+}++export const platformColors: Record<string, string> = {+ google: '#4285f4',+ groq: '#f55036',+ cerebras: '#8b5cf6',+ nvidia: '#76b900',+ mistral: '#f59e0b',+ openrouter: '#ec4899',+ github: '#6e7b8b',+ cohere: '#d946ef',+ cloudflare: '#f38020',+ zhipu: '#06b6d4',+ ollama: '#000000',+ kilo: '#7c3aed',+ pollinations: '#a855f7',+ llm7: '#0ea5e9',+ huggingface: '#ff9d00',+ routeway: '#14b8a6',+ bazaarlink: '#e11d48',+ ainative: '#22c55e',+ aihorde: '#dc2626',+}++// ── Grouped (unified) rendering ──────────────────────────────────────────────+// One logical model and the provider rows that serve it.+export interface ModelGroupRow {+ key: string+ label: string+ members: Row[]+}++// Group merged rows by their server-assigned groupKey (or a per-row "solo" key+// when ungrouped). Members are ordered like the flat chain — by manual priority+// under the priority strategy, by live score otherwise — and groups inherit the+// best member's position so the unified order matches the flat order.+export function buildGroups(rows: Row[], isManual: boolean): ModelGroupRow[] {+ const map = new Map<string, Row[]>()+ for (const r of rows) {+ const key = r.groupKey ?? `solo:${r.modelDbId}`+ const arr = map.get(key)+ if (arr) arr.push(r)+ else map.set(key, [r])+ }+ const groups = [...map.entries()].map(([key, members]) => ({+ key,+ label: members[0].groupLabel ?? members[0].displayName,+ members: [...members].sort((a, b) => (isManual ? a.priority - b.priority : (b.score ?? 0) - (a.score ?? 0))),+ }))+ groups.sort((a, b) =>+ isManual+ ? Math.min(...a.members.map(m => m.priority)) - Math.min(...b.members.map(m => m.priority))+ : Math.max(...b.members.map(m => m.score ?? 0)) - Math.max(...a.members.map(m => m.score ?? 0)),+ )+ return groups+}diff --git a/client/src/pages/FallbackPage.tsx b/client/src/pages/FallbackPage.tsxindex 18db242a..ff98890a 100644--- a/client/src/pages/FallbackPage.tsx+++ b/client/src/pages/FallbackPage.tsx@@ -1,4 +1,4 @@-import { useEffect, useState, useRef, type ReactNode } from 'react'+import { useState } from 'react'import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'import {DndContext,@@ -13,88 +13,36 @@ import {arrayMove,SortableContext,sortableKeyboardCoordinates,- useSortable,verticalListSortingStrategy,} from '@dnd-kit/sortable'-import { CSS } from '@dnd-kit/utilities'-import { Boxes, ChevronDown, SlidersHorizontal, Search, X } from 'lucide-react'+import { Boxes, Search, X } from 'lucide-react'import { Link, useNavigate } from 'react-router-dom'import { useI18n } from '@/i18n'import { apiFetch } from '@/lib/api'+import {+ buildGroups,+ groupMaxContext,+ type FallbackEntry,+ type ModelGroupRow,+ type RoutingData,+ type RoutingStrategy,+ type RoutingWeights,+ type Row,+ type TokenUsageData,+} from '@/lib/routing'import { Button } from '@/components/ui/button'-import { CopyButton } from '@/components/copy-button'+import { CustomWeightsPopover } from '@/components/custom-weights-popover'import { EmptyState } from '@/components/empty-state'import { GettingStarted } from '@/components/getting-started'-import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover'-import { Switch } from '@/components/ui/switch'+import { GroupHeaderCells, ModelTableHead, SortableGroupRow } from '@/components/model-table'import { TableSkeleton } from '@/components/ui/skeleton'+import { TokenUsageBar } from '@/components/token-usage-bar'import { PageHeader } from '@/components/page-header'import { FloatingBar } from '@/components/floating-bar'import { ModelsTabs } from '@/components/models-tabs'import { Tooltip } from '@/components/tooltip'import { PenaltyInspector } from '@/components/penalty-inspector'-export interface FallbackEntry {- modelDbId: number- priority: number- effectivePriority: number- penalty: number- rateLimitHits: number- enabled: boolean- platform: string- modelId: string- displayName: string- intelligenceRank: number- speedRank: number- sizeLabel: string- rpmLimit: number | null- rpdLimit: number | null- monthlyTokenBudget: string- // Parsed token count from the server (single source of truth — see- // server/src/lib/budget.ts). Optional only because the dev mock omits it.- monthlyTokenBudgetTokens?: number- // Max context length in tokens (catalog value), or null when unrecorded.- // Drives the catalog context-window filter on the Models page.- contextWindow?: number | null- supportsVision: boolean- supportsTools: boolean- source?: 'catalog' | 'custom'- keyId?: number | null- keyLabel?: string | null- hasOverrides?: boolean- keyCount: number- // Logical-model grouping (sent by the server when unify is relevant). Absent- // for ungrouped rows; the UI falls back to a per-row "solo" group then.- groupKey?: string- canonicalId?: string- groupLabel?: string-}--type RoutingStrategy = 'priority' | 'balanced' | 'smartest' | 'fastest' | 'reliable' | 'custom'--type RoutingWeights = { reliability: number; speed: number; intelligence: number }--export interface RoutingScore {- modelDbId: number- reliability: number- speed: number- intelligence: number- headroom: number- rateLimit: number- score: number- totalRequests: number-}--export interface RoutingData {- strategy: RoutingStrategy- weights: RoutingWeights | null- customWeights: RoutingWeights- scores: (RoutingScore & { platform: string; modelId: string; displayName: string; enabled: boolean })[]-}--// A merged row: fallback-chain metadata + live bandit scores.-export type Row = FallbackEntry & Partial<RoutingScore>-// `tKey` is the i18n suffix under `strategies.*` (label) and `strategies.*Blurb`.// It differs from the routing `key` for Manual, whose strategy id is 'priority'.const STRATEGIES: { key: RoutingStrategy; tKey: string }[] = [@@ -106,145 +54,6 @@ const STRATEGIES: { key: RoutingStrategy; tKey: string }[] = [{ key: 'custom', tKey: 'custom' },]-// Slider axes share the colors used by the score table columns below.-// `tKey` is the i18n suffix under `strategies.weight*`.-const WEIGHT_AXES: { key: keyof RoutingWeights; tKey: string; color: string }[] = [- { key: 'reliability', tKey: 'weightReliability', color: '#22c55e' },- { key: 'speed', tKey: 'weightSpeed', color: '#3b82f6' },- { key: 'intelligence', tKey: 'weightIntelligence', color: '#a855f7' },-]--// Slider popover for the 'custom' strategy. Sliders are independent (0-100)-// and the server renormalizes any vector, so we just show each axis's-// effective share live. Nothing is saved until Apply is pressed.-function CustomWeightsPopover({ saved, onSave, saving }: {- saved: RoutingWeights- onSave: (w: RoutingWeights) => void- saving: boolean-}) {- const { t } = useI18n()- const [values, setValues] = useState<RoutingWeights>(() => fromSaved(saved))- const [dirty, setDirty] = useState(false)-- // Defensive: an older/partial server response (or a future field rename) could- // leave `saved` undefined; never let that white-screen the whole page (there's- // no error boundary above us). Fall back to an even split.- function fromSaved(w?: RoutingWeights): RoutingWeights {- const safe = w ?? { reliability: 1 / 3, speed: 1 / 3, intelligence: 1 / 3 }- return {- reliability: Math.round(safe.reliability * 100),- speed: Math.round(safe.speed * 100),- intelligence: Math.round(safe.intelligence * 100),- }- }-- function update(key: keyof RoutingWeights, v: number) {- setValues({ ...values, [key]: v })- setDirty(true)- }-- function apply() {- if (sum <= 0) return- onSave({- reliability: values.reliability / 100,- speed: values.speed / 100,- intelligence: values.intelligence / 100,- })- setDirty(false)- }-- const sum = values.reliability + values.speed + values.intelligence-- return (- <Popover onOpenChange={open => { if (open) { setValues(fromSaved(saved)); setDirty(false) } }}>- <PopoverTrigger className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg text-muted-foreground hover:text-foreground hover:bg-muted transition-colors">- <SlidersHorizontal className="size-3.5" />- {t('strategies.adjust')}- </PopoverTrigger>- <PopoverContent align="start" className="w-80">- <div className="space-y-4">- <div>- <h3 className="text-sm font-medium">{t('strategies.customWeights')}</h3>- <p className="mt-0.5 text-xs text-muted-foreground">- {t('strategies.customWeightsHelp')}- </p>- </div>- {WEIGHT_AXES.map(axis => {- const share = sum > 0 ? Math.round((values[axis.key] / sum) * 100) : 0- const axisLabel = t(`strategies.${axis.tKey}`)- return (- <div key={axis.key}>- <div className="mb-1 flex items-baseline justify-between text-xs">- <span className="inline-flex items-center gap-1.5">- <span className="size-2 rounded-sm" style={{ background: axis.color }} />- {axisLabel}- </span>- <span className="tabular-nums text-muted-foreground">{share}%</span>- </div>- <input- type="range"- min={0}- max={100}- step={1}- value={values[axis.key]}- onChange={e => update(axis.key, Number(e.target.value))}- className="w-full cursor-pointer"- style={{ accentColor: axis.color }}- aria-label={`${axisLabel} weight`}- />- </div>- )- })}- {sum <= 0 && (- <p className="text-xs text-amber-600 dark:text-amber-500">- {t('strategies.weightRequired')}- </p>- )}- <Button- size="sm"- className="w-full"- disabled={!dirty || sum <= 0 || saving}- onClick={apply}- >- {saving ? t('common.applying') : dirty ? t('common.apply') : t('common.applied')}- </Button>- </div>- </PopoverContent>- </Popover>- )-}--export function formatTokens(n: number): string {- if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(1)}B`- if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`- if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`- return String(n)-}--function formatPercent(value: number): string {- const pct = Math.max(0, Math.min(100, value * 100))- if (pct > 0 && pct < 0.1) return '<0.1%'- if (pct > 99.9 && pct < 100) {- const floored = Math.floor(pct * 100) / 100- return `${floored.toFixed(2).replace(/0+$/, '').replace(/\.$/, '')}%`- }- const digits = pct < 10 ? 1 : 0- return `${pct.toFixed(digits).replace(/\.0$/, '')}%`-}--// Compact context-window label (whole-number K/M, base 1000): 8000 → "8K",-// 128000 → "128K", 1_000_000 → "1M". Used by the catalog context badge/filter.-function formatContext(n: number): string {- if (n >= 1_000_000) return `${Math.round(n / 1_000_000)}M`- if (n >= 1_000) return `${Math.round(n / 1_000)}K`- return String(n)-}--// The largest context window across a logical model's providers.-function groupMaxContext(members: Row[]): number {- return Math.max(0, ...members.map(m => m.contextWindow ?? 0))-}-// Minimum-context filter buckets for the Models page toolbar. `key` is the token// threshold (0 = no filter); numeric labels are not localized (they're numbers).const CTX_BUCKETS: { key: number; label?: string; tKey?: string }[] = [@@ -254,446 +63,6 @@ const CTX_BUCKETS: { key: number; label?: string; tKey?: string }[] = [{ key: 1_000_000, label: '1M+' },]-// For models with no monthly token budget, surface their rate quota instead.-// Strips the catalog's decorative bits ("free · ", " per IP", "~", "?") so e.g.-// "free · 40 RPM" → "40 RPM", "free · 200/hr per IP" → "200/hr", "~? (anon)" →-// "anon". Returns null when nothing meaningful remains.-export function cleanQuotaLabel(s: string | undefined): string | null {- if (!s) return null- let c = s- .replace(/free\s*·\s*/ig, '')- .replace(/\s*per ip\s*/ig, '')- .replace(/[~?]/g, '')- .replace(/\s+/g, ' ')- .trim()- c = c.replace(/^\(([^()]*)\)$/, '$1').trim()- return c || null-}--// The quota badge for a logical model: its summed monthly token budget when it-// has one (you can spend all providers' budgets via failover), else the best-// rate cap (RPM/RPD, or the catalog's rate label) for rate-limited providers.-// Shared by the Models-page group header and the per-model detail page.-export function groupQuotaBadge(- members: Row[],- t: (key: string, vars?: Record<string, string | number>) => string,-): { text: string; title: string } | null {- const totalBudget = members.reduce((sum, m) => sum + (m.monthlyTokenBudgetTokens ?? 0), 0)- const maxRpm = Math.max(0, ...members.map(m => m.rpmLimit ?? 0))- const maxRpd = Math.max(0, ...members.map(m => m.rpdLimit ?? 0))- const rateLabelText = members.map(m => cleanQuotaLabel(m.monthlyTokenBudget)).find(Boolean) ?? null- if (totalBudget > 0) return { text: t('models.aggregateBudget', { count: formatTokens(totalBudget) }), title: t('models.aggregateBudgetTitle') }- if (maxRpm > 0) return { text: t('models.rateRpm', { count: maxRpm }), title: t('models.rateTitle') }- if (maxRpd > 0) return { text: t('models.rateRpd', { count: maxRpd }), title: t('models.rateTitle') }- if (rateLabelText) return { text: rateLabelText, title: t('models.rateTitle') }- return null-}--interface TokenUsageData {- totalBudget: number- totalUsed: number- models: { displayName: string; platform: string; modelId?: string; budget: number; used?: number }[]-}--const platformColors: Record<string, string> = {- google: '#4285f4',- groq: '#f55036',- cerebras: '#8b5cf6',- nvidia: '#76b900',- mistral: '#f59e0b',- openrouter: '#ec4899',- github: '#6e7b8b',- cohere: '#d946ef',- cloudflare: '#f38020',- zhipu: '#06b6d4',- ollama: '#000000',- kilo: '#7c3aed',- pollinations: '#a855f7',- llm7: '#0ea5e9',- huggingface: '#ff9d00',- routeway: '#14b8a6',- bazaarlink: '#e11d48',- ainative: '#22c55e',- aihorde: '#dc2626',-}--// A 0..1 value as a thin horizontal bar with the number beside it.-export function AxisBar({ value, color }: { value: number | undefined; color: string }) {- const v = value ?? 0- return (- <div className="flex items-center gap-1.5">- <div className="h-1.5 w-12 rounded-full bg-muted overflow-hidden">- <div className="h-full rounded-full" style={{ width: `${Math.round(v * 100)}%`, backgroundColor: color }} />- </div>- <span className="font-mono text-[11px] text-muted-foreground tabular-nums w-7 text-right">- {value === undefined ? '–' : Math.round(v * 100)}- </span>- </div>- )-}--// Legend rows visible while collapsed (~6 rows: 6 × 16px line + 5 × 6px gap).-const LEGEND_COLLAPSED_PX = 126--function TokenUsageBar({ data }: { data: TokenUsageData }) {- const { t } = useI18n()- const { totalBudget, totalUsed, models } = data- const remaining = Math.max(0, totalBudget - totalUsed)- const remainingPct = totalBudget > 0 ? formatPercent(remaining / totalBudget) : '0%'-- // Collapse the per-model legend to a few rows; the chevron reveals the rest.- // The toggle only appears when the legend actually overflows the collapsed- // height (column count — and so row count — depends on viewport width).- const [expanded, setExpanded] = useState(false)- const [collapsible, setCollapsible] = useState(false)- const legendRef = useRef<HTMLDivElement>(null)- useEffect(() => {- const el = legendRef.current- if (!el) return- const check = () => setCollapsible(el.scrollHeight > LEGEND_COLLAPSED_PX + 1)- check()- const ro = new ResizeObserver(check)- ro.observe(el)- return () => ro.disconnect()- }, [models.length])-- const modelsWithWidth = models.map(m => {- const usedTokens = m.used ?? 0- const remainingTokens = Math.max(0, m.budget - usedTokens)- return {- ...m,- usedTokens,- remainingTokens,- widthPct: totalBudget > 0 ? (remainingTokens / totalBudget) * 100 : 0,- }- })- const usedPct = totalBudget > 0 ? Math.min(100, (totalUsed / totalBudget) * 100) : 0-- return (- <section className="rounded-3xl border bg-card p-5">- <div className="flex items-baseline justify-between mb-3">- <h2 className="text-sm font-medium">{t('models.monthlyTokenBudget')}</h2>- <span className="text-xs text-muted-foreground tabular-nums">- <span className="text-foreground font-medium">{formatTokens(remaining)}</span> {t('models.remaining')}- <span className="mx-1.5">·</span>- {remainingPct} {t('models.of')} {formatTokens(totalBudget)}- {totalUsed > 0 && (- <>- <span className="mx-1.5">·</span>- <span className="text-foreground font-medium">{formatTokens(totalUsed)}</span> {t('models.used')}- </>- )}- </span>- </div>-- <div className="flex h-2.5 rounded-full overflow-hidden bg-muted">- {modelsWithWidth.map((m, i) => (- <div- key={i}- title={`${m.displayName} (${m.platform}): ${formatTokens(m.remainingTokens)} ${t('models.remaining')}, ${formatTokens(m.usedTokens)} ${t('models.used')}`}- style={{- width: `${m.widthPct}%`,- backgroundColor: platformColors[m.platform] ?? '#94a3b8',- }}- />- ))}- {totalUsed > 0 && (- <div- title={`Used: ${formatTokens(totalUsed)}`}- className="bg-muted-foreground/30"- style={{ width: `${usedPct}%` }}- />- )}- </div>-- <div- ref={legendRef}- className="mt-4 overflow-hidden transition-[max-height] duration-300 ease-in-out"- style={collapsible ? { maxHeight: expanded ? legendRef.current?.scrollHeight : LEGEND_COLLAPSED_PX } : undefined}- >- <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-x-5 gap-y-1.5 text-xs tabular-nums">- {modelsWithWidth.map((m, i) => (- <div key={i} className="flex items-center gap-2 min-w-0">- <span- className="size-2 rounded-sm flex-shrink-0"- style={{ backgroundColor: platformColors[m.platform] ?? '#94a3b8' }}- />- <span className="truncate">{m.displayName}</span>- <span className="flex-1" />- <span className="font-mono text-muted-foreground">{formatTokens(m.remainingTokens)}</span>- </div>- ))}- </div>- </div>-- {collapsible && (- <button- onClick={() => setExpanded(e => !e)}- className="mt-2 flex w-full items-center justify-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"- >- {expanded ? t('models.showLess') : t('models.showAllModels', { count: models.length })}- <ChevronDown className={`size-3.5 transition-transform duration-300 ${expanded ? 'rotate-180' : ''}`} />- </button>- )}- </section>- )-}--// The shared table header for the unified model/provider table — used by the-// Models page and the per-model detail page so their columns line up.-export function ModelTableHead() {- const { t } = useI18n()- return (- <thead>- <tr className="text-left text-muted-foreground border-b">- <th className="py-2 pl-3 pr-1 w-6"></th>- <th className="py-2 pr-2 w-6 text-center font-medium">#</th>- <th className="py-2 pr-3 font-medium">{t('models.columnModel')}</th>- <th className="py-2 pr-3 font-medium">- <span className="inline-flex items-center gap-1"><span className="size-2 rounded-sm" style={{ background: '#22c55e' }} />{t('strategies.weightReliability')}</span>- </th>- <th className="py-2 pr-3 font-medium">- <span className="inline-flex items-center gap-1"><span className="size-2 rounded-sm" style={{ background: '#3b82f6' }} />{t('strategies.weightSpeed')}</span>- </th>- <th className="py-2 pr-3 font-medium">- <span className="inline-flex items-center gap-1"><span className="size-2 rounded-sm" style={{ background: '#a855f7' }} />{t('strategies.weightIntelligence')}</span>- </th>- <th className="py-2 pr-3 font-medium">- <Tooltip text={t('strategies.guardrailsTooltip')}>- <span className="underline decoration-dotted underline-offset-2 cursor-help">{t('strategies.guardrails')}</span>- </Tooltip>- </th>- <th className="py-2 pr-3 font-medium text-right">- <Tooltip text={t('strategies.scoreTooltip')}>- <span className="underline decoration-dotted underline-offset-2 cursor-help">{t('strategies.scoreColumn')}</span>- </Tooltip>- </th>- <th className="py-2 pr-3 font-medium text-right">{t('models.columnOn')}</th>- </tr>- </thead>- )-}--// ── One row of the unified table ────────────────────────────────────────────-export function RowContent({- row,- rank,- draggable,- dragHandle,- onToggle,-}: {- row: Row- rank: number- draggable: boolean- dragHandle?: ReactNode- onToggle: (modelDbId: number, enabled: boolean) => void-}) {- const { t } = useI18n()- const guard = (row.headroom ?? 1) * (row.rateLimit ?? 1)- return (- <>- <td className="py-2 pl-3 pr-1 w-6 align-middle">- {draggable ? dragHandle : <span className="text-muted-foreground/30 select-none">·</span>}- </td>- <td className="py-2 pr-2 w-6 text-center font-mono text-xs text-muted-foreground tabular-nums align-middle">{rank}</td>- <td className="py-2 pr-3 align-middle">- <div className="flex items-center gap-2 flex-wrap">- <span className="font-medium text-sm">{row.displayName}</span>- <span className="text-xs text-muted-foreground">{row.platform}</span>- {row.supportsVision && (- <span- title={t('models.visionTitle')}- className="text-[10px] rounded-full px-1.5 py-0.5 bg-cyan-600/15 text-cyan-700 dark:bg-cyan-400/15 dark:text-cyan-400"- >- {t('models.vision')}- </span>- )}- {row.supportsTools && (- <span- title={t('models.toolsTitle')}- className="text-[10px] rounded-full px-1.5 py-0.5 bg-violet-600/15 text-violet-700 dark:bg-violet-400/15 dark:text-violet-400"- >- {t('models.tools')}- </span>- )}- {(row.penalty ?? 0) > 0 && (- <span className="text-[10px] text-amber-600 dark:text-amber-400">{t('models.penalty', { value: row.penalty })}</span>- )}- {row.totalRequests !== undefined && row.totalRequests > 0 && (- <span className="text-[10px] text-muted-foreground/60 tabular-nums">{t('models.obs', { count: row.totalRequests })}</span>- )}- </div>- <div className="text-[11px] text-muted-foreground/70 tabular-nums mt-0.5">- {/* Token budget only when it's a real token count; rate-limited models- (NVIDIA's "free · 40 RPM") show their rate, not "… tok/mo". */}- {[- (row.monthlyTokenBudgetTokens ?? 0) > 0 ? t('models.tokPerMonth', { count: row.monthlyTokenBudget }) : null,- row.rpmLimit ? t('models.rpmLimit', { count: row.rpmLimit }) : null,- row.rpdLimit ? t('models.rpdLimit', { count: row.rpdLimit }) : null,- ].filter(Boolean).join(' · ') || cleanQuotaLabel(row.monthlyTokenBudget) || '—'}- </div>- </td>- <td className="py-2 pr-3 align-middle"><AxisBar value={row.reliability} color="#22c55e" /></td>- <td className="py-2 pr-3 align-middle"><AxisBar value={row.speed} color="#3b82f6" /></td>- <td className="py-2 pr-3 align-middle"><AxisBar value={row.intelligence} color="#a855f7" /></td>- <td className="py-2 pr-3 align-middle font-mono text-[11px] text-muted-foreground tabular-nums">- {guard < 0.999 ? `×${guard.toFixed(2)}` : '—'}- </td>- <td className="py-2 pr-3 align-middle text-right font-mono text-xs font-medium tabular-nums">- {row.score !== undefined ? row.score.toFixed(3) : '–'}- </td>- <td className="py-2 pr-3 align-middle text-right">- <Switch checked={row.enabled} onCheckedChange={(c) => onToggle(row.modelDbId, c)} />- </td>- </>- )-}--// ── Grouped (unified) rendering ──────────────────────────────────────────────-// One logical model and the provider rows that serve it.-interface ModelGroupRow {- key: string- label: string- members: Row[]-}--// Group merged rows by their server-assigned groupKey (or a per-row "solo" key-// when ungrouped). Members are ordered like the flat chain — by manual priority-// under the priority strategy, by live score otherwise — and groups inherit the-// best member's position so the unified order matches the flat order.-function buildGroups(rows: Row[], isManual: boolean): ModelGroupRow[] {- const map = new Map<string, Row[]>()- for (const r of rows) {- const key = r.groupKey ?? `solo:${r.modelDbId}`- const arr = map.get(key)- if (arr) arr.push(r)- else map.set(key, [r])- }- const groups = [...map.entries()].map(([key, members]) => ({- key,- label: members[0].groupLabel ?? members[0].displayName,- members: [...members].sort((a, b) => (isManual ? a.priority - b.priority : (b.score ?? 0) - (a.score ?? 0))),- }))- groups.sort((a, b) =>- isManual- ? Math.min(...a.members.map(m => m.priority)) - Math.min(...b.members.map(m => m.priority))- : Math.max(...b.members.map(m => m.score ?? 0)) - Math.max(...a.members.map(m => m.score ?? 0)),- )- return groups-}--const dragDots = (- <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">- <circle cx="9" cy="6" r="1.5" /><circle cx="15" cy="6" r="1.5" />- <circle cx="9" cy="12" r="1.5" /><circle cx="15" cy="12" r="1.5" />- <circle cx="9" cy="18" r="1.5" /><circle cx="15" cy="18" r="1.5" />- </svg>-)--// The collapsed header row for a logical-model group: name, provider count,-// union vision/tools badges, the best member's axis bars + score, and a single-// switch that enables/disables every provider in the group.-function GroupHeaderCells({ group, rank, dragHandle, onToggleGroup }: {- group: ModelGroupRow- rank: number- dragHandle?: ReactNode- onToggleGroup: (memberIds: number[], enabled: boolean) => void-}) {- const { t } = useI18n()- const anyEnabled = group.members.some(m => m.enabled)- const solo = group.members.length === 1- const best = group.members.reduce((b, m) => ((m.score ?? -1) > (b.score ?? -1) ? m : b), group.members[0])- const guard = (best.headroom ?? 1) * (best.rateLimit ?? 1)- const vision = group.members.some(m => m.supportsVision)- const tools = group.members.some(m => m.supportsTools)- const quota = groupQuotaBadge(group.members, t)- const maxCtx = groupMaxContext(group.members)- // The model name links to its own page, which lists every provider that serves- // it (replaces the old inline expansion).- const detailId = encodeURIComponent(group.members[0].canonicalId ?? group.members[0].modelId)- // The unified model string to paste into .env / API payloads (#343 quick-copy).- const copyId = group.members[0].canonicalId ?? group.members[0].modelId- return (- <>- <td className="py-2 pl-3 pr-1 w-6 align-middle">{dragHandle ?? <span className="text-muted-foreground/30 select-none">·</span>}</td>- <td className="py-2 pr-2 w-6 text-center font-mono text-xs text-muted-foreground tabular-nums align-middle">{rank}</td>- <td className="py-2 pr-3 align-middle">- <div className="flex items-center gap-1.5 min-w-0">- <Link to={`/models/chat/${detailId}`} aria-label={t('models.viewProviders')} onClick={e => e.stopPropagation()} className="flex items-center gap-2 flex-wrap text-left min-w-0">- <span className="font-medium text-sm">{group.label}</span>- {solo- ? <span className="text-xs text-muted-foreground">{group.members[0].platform}</span>- : <Tooltip text={t('models.servedBy', { providers: group.members.map(m => m.platform).join(', ') })}>- <span className="text-[10px] rounded-full px-1.5 py-0.5 bg-muted text-muted-foreground">{t('models.providerCount', { count: group.members.length })}</span>- </Tooltip>}- {quota && (- <span title={quota.title} className="text-[10px] rounded-full px-1.5 py-0.5 bg-muted text-muted-foreground tabular-nums">- {quota.text}- </span>- )}- {maxCtx > 0 && (- <span title={t('models.ctxTitle')} className="text-[10px] rounded-full px-1.5 py-0.5 bg-muted text-muted-foreground tabular-nums">- {t('models.ctxBadge', { size: formatContext(maxCtx) })}- </span>- )}- {vision && (- <span title={t('models.visionTitle')} className="text-[10px] rounded-full px-1.5 py-0.5 bg-cyan-600/15 text-cyan-700 dark:bg-cyan-400/15 dark:text-cyan-400">{t('models.vision')}</span>- )}- {tools && (- <span title={t('models.toolsTitle')} className="text-[10px] rounded-full px-1.5 py-0.5 bg-violet-600/15 text-violet-700 dark:bg-violet-400/15 dark:text-violet-400">{t('models.tools')}</span>- )}- </Link>- {/* Quick-copy the unified model id (#343). Stop propagation so it neither- follows the model link nor triggers the row's navigate-on-click. */}- <span onClick={e => e.stopPropagation()} className="shrink-0">- <CopyButton text={copyId} className="size-6" label={t('models.copyModelId')} />- </span>- </div>- </td>- <td className="py-2 pr-3 align-middle"><AxisBar value={best.reliability} color="#22c55e" /></td>- <td className="py-2 pr-3 align-middle"><AxisBar value={best.speed} color="#3b82f6" /></td>- <td className="py-2 pr-3 align-middle"><AxisBar value={best.intelligence} color="#a855f7" /></td>- <td className="py-2 pr-3 align-middle font-mono text-[11px] text-muted-foreground tabular-nums">{guard < 0.999 ? `×${guard.toFixed(2)}` : '—'}</td>- <td className="py-2 pr-3 align-middle text-right font-mono text-xs font-medium tabular-nums">{best.score !== undefined ? best.score.toFixed(3) : '–'}</td>- <td className="py-2 pr-3 align-middle text-right" onClick={e => e.stopPropagation()}>- <Switch checked={anyEnabled} onCheckedChange={(c) => onToggleGroup(group.members.map(m => m.modelDbId), c)} />- </td>- </>- )-}--function SortableGroupRow({ group, rank, onToggleGroup }: {- group: ModelGroupRow- rank: number- onToggleGroup: (memberIds: number[], enabled: boolean) => void-}) {- const { t } = useI18n()- const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: `grp:${group.key}` })- const anyEnabled = group.members.some(m => m.enabled)- const navigate = useNavigate()- const detailId = encodeURIComponent(group.members[0].canonicalId ?? group.members[0].modelId)- const handle = (- <button- {...attributes}- {...listeners}- onClick={e => e.stopPropagation()}- className="cursor-grab active:cursor-grabbing text-muted-foreground/50 hover:text-foreground transition-colors"- aria-label={t('models.dragToReorderGroup')}- >- {dragDots}- </button>- )- return (- <tr- ref={setNodeRef}- style={{ transform: CSS.Transform.toString(transform), transition }}- onClick={() => navigate(`/models/chat/${detailId}`)}- className={`border-b last:border-0 bg-card cursor-pointer transition-colors hover:[&>td]:bg-muted/50 [&>td:first-child]:rounded-l-lg [&>td:last-child]:rounded-r-lg ${isDragging ? 'opacity-50' : ''} ${anyEnabled ? '' : 'opacity-50'}`}- >- <GroupHeaderCells group={group} rank={rank} dragHandle={handle} onToggleGroup={onToggleGroup} />- </tr>- )-}export default function FallbackPage() {const { t } = useI18n()diff --git a/client/src/pages/ModelDetailPage.tsx b/client/src/pages/ModelDetailPage.tsxindex bb320b07..3c26c8f2 100644--- a/client/src/pages/ModelDetailPage.tsx+++ b/client/src/pages/ModelDetailPage.tsx@@ -13,14 +13,13 @@ import { TableSkeleton } from '@/components/ui/skeleton'import { Tooltip } from '@/components/tooltip'import { PageHeader } from '@/components/page-header'import { ModelsTabs } from '@/components/models-tabs'+import { ModelTableHead, RowContent } from '@/components/model-table'import {- ModelTableHead,- RowContent,groupQuotaBadge,type FallbackEntry,type RoutingData,type Row,-} from './FallbackPage'+} from '@/lib/routing'type ModelSettingsPatch = {displayName: string