Files
opencode-manager/frontend/src/components/repo/ModelCheckboxList.tsx
T
Chris Scott 65b72e55ae refactor: unify model selection with the TUI
Align the manager's model selection with the OpenCode TUI: one
model.json-backed preference store, one provider catalog, one ordering
and default-ownership rule, and one set of availability, ref-formatting
and variant helpers shared across chat, schedules, agents and the goal
auditor.

- Add a shared TUI-compatible model-preference module and make the
  backend model.json store match its format.
- Consolidate the frontend provider catalog, availability check, model
  ref formatter and variant persistence into single owners.
- Drive chat, schedule, agent and goal-auditor model lists from a shared
  useModelSections hook and buildModelSections, following TUI ordering.
- Extract a shared ModelCombobox with a taller list, and list models the
  TUI way in ModelQuickSelect.
- Add a shared isRecord util and model-selection comparison helpers.
2026-10-06 20:44:27 -04:00

55 lines
1.8 KiB
TypeScript

import { memo } from 'react'
import { Checkbox } from '@/components/ui/checkbox'
import type { ModelSection } from '@/lib/modelSections'
interface ModelCheckboxListProps {
sections: ModelSection[]
selectedModels: string[]
onToggle: (value: string, checked: boolean) => void
emptyLabel: string
maxSelected?: number
}
export const ModelCheckboxList = memo(function ModelCheckboxList({
sections,
selectedModels,
onToggle,
emptyLabel,
maxSelected,
}: ModelCheckboxListProps) {
if (sections.length === 0) {
return <p className="p-3 text-sm text-muted-foreground">{emptyLabel}</p>
}
return (
<>
{sections.map((section) => (
<div key={section.key} className="p-3 space-y-2">
<p className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
{section.icon ? <section.icon className="h-3.5 w-3.5" /> : null}
{section.title}
</p>
{section.options.map((option) => {
const checked = selectedModels.includes(option.value)
const atCapacity = maxSelected !== undefined && selectedModels.length >= maxSelected && !checked
return (
<label key={option.value} className="flex items-center gap-2 text-sm">
<Checkbox
aria-label={option.label}
checked={checked}
disabled={atCapacity}
onCheckedChange={(next) => onToggle(option.value, next === true)}
/>
<span className="truncate">{option.label}</span>
{!section.providerID ? (
<span className="ml-auto shrink-0 text-xs text-muted-foreground">{option.providerName}</span>
) : null}
</label>
)
})}
</div>
))}
</>
)
})