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.
This commit is contained in:
Chris Scott committed 2026-10-06 20:44:27 -04:00
1 parent 3d143568c1
commit 65b72e55ae
82 files changed
+4418 -2624

No files matched your search

+8 -18
View File
@@ -1,5 +1,5 @@
import type { ModelInfo, ModelRef } from '@opencode-manager/shared/opencode'
import { formatOpenCodeModelRef, openCodeLocation, parseOpenCodeModelRef, selectConfiguredModelRef } from '@opencode-manager/shared/opencode'
import { findModelInfo, formatOpenCodeModelRef, openCodeLocation, parseOpenCodeModelRef, selectConfiguredModelRef, selectEffectiveModelRef } from '@opencode-manager/shared/opencode'
import type { OpenCodeClient } from './opencode/client'
export interface ResolvedOpenCodeModel {
@@ -36,7 +36,7 @@ function toResolvedModel(ref: ModelRef): ResolvedOpenCodeModel {
}
function findAvailable(models: ModelInfo[], ref: ModelRef): ModelInfo | undefined {
return models.find((model) => model.providerID === ref.providerID && model.id === ref.id)
return findModelInfo(models, { providerID: ref.providerID, modelID: ref.id })
}
function isTargetLoaded(models: ModelInfo[], targetRef: ModelRef | undefined): boolean {
@@ -49,23 +49,13 @@ function resolveFromLoadedModels(
configuredRef: ModelRef | undefined,
preferredRef: ModelRef | undefined,
): ResolvedOpenCodeModel | null {
if (preferredRef && findAvailable(models, preferredRef)) {
return toResolvedModel(preferredRef)
}
const resolved = selectEffectiveModelRef({
models,
defaultModel,
candidates: [preferredRef, configuredRef],
})
if (configuredRef && findAvailable(models, configuredRef)) {
return toResolvedModel(configuredRef)
}
if (defaultModel) {
const defaultRef: ModelRef = { providerID: defaultModel.providerID, id: defaultModel.id }
if (findAvailable(models, defaultRef)) {
return toResolvedModel(defaultRef)
}
}
const fallback = models.find((model) => model.enabled)
return fallback ? toResolvedModel({ providerID: fallback.providerID, id: fallback.id }) : null
return resolved ? toResolvedModel(resolved) : null
}
function sleep(ms: number, signal: AbortSignal): Promise<void> {