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 -11
View File
@@ -20,6 +20,7 @@ import {
} from "../api/opencode";
import { FetchError } from "../api/fetchWrapper";
import type { ModelRef, SessionInfo } from "@opencode-manager/shared/opencode";
import { isSameModelRef } from "@opencode-manager/shared/opencode";
import { parseNetworkError, isGatewayTimeout } from "../lib/opencode-errors";
import { showToast } from "../lib/toast";
import { useSendErrorStore } from "../stores/sendErrorStore";
@@ -32,12 +33,6 @@ import { SESSION_PINS_QUERY_KEY } from "./useSessionPins";
import { admitInboxItem, type TranscriptCache } from "../lib/session-projection";
import type { SessionPin } from "@opencode-manager/shared/schemas";
const isSameModelRef = (left: ModelRef, right: ModelRef | undefined) =>
right !== undefined &&
left.providerID === right.providerID &&
left.id === right.id &&
left.variant === right.variant;
const SESSION_LIST_PAGE_SIZE = 25
const EMPTY_SESSIONS: SessionInfo[] = []
@@ -327,14 +322,16 @@ export const useSyncSessionSelection = (directory?: string) => {
sessionQueryKey(sessionID, directory),
);
if (model && !isSameModelRef(model, session?.model)) {
await switchSessionModel(sessionID, model);
patchCachedSessionSelection(queryClient, sessionID, directory, { model });
}
let agentChanged = false;
if (agent && agent !== session?.agent) {
await switchSessionAgent(sessionID, agent);
patchCachedSessionSelection(queryClient, sessionID, directory, { agent });
agentChanged = true;
}
if (model && (agentChanged || !isSameModelRef(model, session?.model))) {
await switchSessionModel(sessionID, model);
patchCachedSessionSelection(queryClient, sessionID, directory, { model });
}
},
[queryClient, directory],