Refactor ConfigContext hooks

This commit is contained in:
2025-11-15 01:02:15 +01:00
parent ad772a05ce
commit 6565be3676
7 changed files with 58 additions and 71 deletions

View File

@@ -0,0 +1,51 @@
import { useConfig } from '@/contexts/ConfigContext'
// Helper hook to get instance default values from config
export const useInstanceDefaults = () => {
const { config } = useConfig()
if (!config || !config.instances) {
return null
}
return {
autoRestart: config.instances.default_auto_restart,
maxRestarts: config.instances.default_max_restarts,
restartDelay: config.instances.default_restart_delay,
onDemandStart: config.instances.default_on_demand_start,
}
}
// Helper hook to get specific backend settings by backend type
export const useBackendSettings = (backendType: string | undefined) => {
const { config } = useConfig()
if (!config || !config.backends || !backendType) {
return null
}
// Map backend type to config key
const backendKey = backendType === 'llama_cpp'
? 'llama-cpp'
: backendType === 'mlx_lm'
? 'mlx'
: backendType === 'vllm'
? 'vllm'
: null
if (!backendKey) {
return null
}
const backendConfig = config.backends[backendKey as keyof typeof config.backends]
if (!backendConfig) {
return null
}
return {
command: backendConfig.command || '',
dockerEnabled: backendConfig.docker?.enabled ?? false,
dockerImage: backendConfig.docker?.image || '',
}
}