mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
30 lines
791 B
TypeScript
30 lines
791 B
TypeScript
import { useEffect } from 'react'
|
|
import { useConfig } from './useOpenCode'
|
|
import { useModelStore, type ModelSelection } from '@/stores/modelStore'
|
|
|
|
interface UseModelSelectionResult {
|
|
model: ModelSelection | null
|
|
modelString: string | null
|
|
recentModels: ModelSelection[]
|
|
setModel: (model: ModelSelection) => void
|
|
}
|
|
|
|
export function useModelSelection(
|
|
opcodeUrl: string | null | undefined,
|
|
directory?: string
|
|
): UseModelSelectionResult {
|
|
const { data: config } = useConfig(opcodeUrl, directory)
|
|
const { model, recentModels, setModel, syncFromConfig, getModelString } = useModelStore()
|
|
|
|
useEffect(() => {
|
|
syncFromConfig(config?.model)
|
|
}, [config?.model, syncFromConfig])
|
|
|
|
return {
|
|
model,
|
|
modelString: getModelString(),
|
|
recentModels,
|
|
setModel,
|
|
}
|
|
}
|