mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
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.
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { useMemo } from 'react'
|
|
import { useProviders } from './useProviders'
|
|
import { useOpenCodeDefaultModel, useOpenCodeModelState } from './useModelSelection'
|
|
import { buildModelSections, type ModelSection } from '@/lib/modelSections'
|
|
import type { OpenCodeModelState, Provider } from '@/api/providers'
|
|
|
|
const EMPTY_PROVIDERS: Provider[] = []
|
|
|
|
export interface UseModelSectionsResult {
|
|
providers: Provider[]
|
|
sections: ModelSection[]
|
|
defaultModel: string | null | undefined
|
|
modelState: OpenCodeModelState | undefined
|
|
isLoading: boolean
|
|
}
|
|
|
|
export function useModelSections(
|
|
directory?: string,
|
|
options: { enabled?: boolean } = {},
|
|
): UseModelSectionsResult {
|
|
const enabled = options.enabled ?? true
|
|
const { data: catalog, isLoading: catalogLoading } = useProviders(directory, { enabled })
|
|
const { data: modelState, isLoading: modelStateLoading } = useOpenCodeModelState(directory, enabled)
|
|
const { data: defaultModel, isLoading: defaultModelLoading } = useOpenCodeDefaultModel(directory, enabled)
|
|
|
|
const providers = catalog?.providers ?? EMPTY_PROVIDERS
|
|
|
|
const sections = useMemo(
|
|
() => buildModelSections(providers, modelState, defaultModel),
|
|
[providers, modelState, defaultModel],
|
|
)
|
|
|
|
return {
|
|
providers,
|
|
sections,
|
|
defaultModel,
|
|
modelState,
|
|
isLoading: catalogLoading || modelStateLoading || defaultModelLoading,
|
|
}
|
|
}
|