fix(ollama): stop pull spinner on failure and only activate pulled models
This commit is contained in:
parent
ed8b585804
commit
6533084a0d
5 changed files with 613 additions and 68 deletions
|
|
@ -33,7 +33,9 @@ import {
|
|||
} from 'lucide-react'
|
||||
import { d3roPalette, d3roRadius, d3roShadow, typoSx, d3roFontMono, d3roFontSans } from '@d3ro/ui/theme'
|
||||
import { Led } from '@d3ro/ui/components/ds'
|
||||
import { useI18n } from '@d3ro/i18n'
|
||||
import type { LLMModel, LLMStatus } from '@d3ro/core/types'
|
||||
import { useOllamaModelPull } from '../hooks/useOllamaModelPull'
|
||||
|
||||
type Phase = 'select_mode' | 'local_ollama_setup' | 'online_auth' | 'success' | 'failed'
|
||||
|
||||
|
|
@ -43,6 +45,7 @@ interface OnboardingModalProps {
|
|||
}
|
||||
|
||||
export function OnboardingModal({ open, onClose }: OnboardingModalProps): React.ReactElement {
|
||||
const { t } = useI18n()
|
||||
const [internalOpen, setInternalOpen] = useState(false)
|
||||
const [phase, setPhase] = useState<Phase>('select_mode')
|
||||
|
||||
|
|
@ -54,10 +57,6 @@ export function OnboardingModal({ open, onClose }: OnboardingModalProps): React.
|
|||
const [startingOllama, setStartingOllama] = useState(false)
|
||||
const [ollamaMsg, setOllamaMsg] = useState<string | null>(null)
|
||||
|
||||
// Model download state
|
||||
const [pullingModel, setPullingModel] = useState<string | null>(null)
|
||||
const [pullProgress, setPullProgress] = useState({ status: '', percent: 0 })
|
||||
|
||||
// Auth State
|
||||
const [authTab, setAuthTab] = useState<'login' | 'register'>('login')
|
||||
const [email, setEmail] = useState('')
|
||||
|
|
@ -95,29 +94,25 @@ export function OnboardingModal({ open, onClose }: OnboardingModalProps): React.
|
|||
})
|
||||
}, [])
|
||||
|
||||
// 모델 받기 — 받기에 성공한 경우에만 활성 모델로 저장 (autoSelect)
|
||||
const {
|
||||
pullingModelId: pullingModel,
|
||||
progress: pullProgress,
|
||||
error: pullError,
|
||||
pull,
|
||||
} = useOllamaModelPull({ enabled: isVisible, autoSelect: true, onPulled: checkOllama })
|
||||
|
||||
useEffect(() => {
|
||||
if (!isVisible) return
|
||||
|
||||
const unsubPull = window.electronAPI.llm.onPullProgress((e) => {
|
||||
setPullingModel(e.modelId)
|
||||
setPullProgress({ status: e.status, percent: e.percent })
|
||||
if (e.percent >= 100 || e.status === 'success') {
|
||||
setTimeout(() => {
|
||||
setPullingModel(null)
|
||||
checkOllama()
|
||||
}, 1200)
|
||||
}
|
||||
})
|
||||
|
||||
const unsubStatus = window.electronAPI.llm.onStatusChanged((e) => {
|
||||
setOllamaStatus(e.status)
|
||||
})
|
||||
|
||||
return () => {
|
||||
unsubPull()
|
||||
unsubStatus()
|
||||
}
|
||||
}, [isVisible, checkOllama])
|
||||
}, [isVisible])
|
||||
|
||||
const handleSelectLocalMode = async () => {
|
||||
setPhase('local_ollama_setup')
|
||||
|
|
@ -153,16 +148,8 @@ export function OnboardingModal({ open, onClose }: OnboardingModalProps): React.
|
|||
}
|
||||
|
||||
const handlePullModel = async (modelId: string) => {
|
||||
setPullingModel(modelId)
|
||||
setPullProgress({ status: '다운로드 시작 중...', percent: 0 })
|
||||
try {
|
||||
await window.electronAPI.llm.pullModel({ modelId })
|
||||
await window.electronAPI.llm.setModel({ modelId })
|
||||
await window.electronAPI.config.set({ key: 'llmModelId', value: modelId })
|
||||
setActiveModel(modelId)
|
||||
} catch {
|
||||
setPullingModel(null)
|
||||
}
|
||||
const outcome = await pull(modelId)
|
||||
if (outcome === 'selected') setActiveModel(modelId)
|
||||
}
|
||||
|
||||
const handleCompleteLocalSetup = async () => {
|
||||
|
|
@ -485,7 +472,7 @@ export function OnboardingModal({ open, onClose }: OnboardingModalProps): React.
|
|||
<Box sx={{ p: 2, bgcolor: d3roPalette.bg.inset, borderRadius: d3roRadius.small }}>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 1 }}>
|
||||
<Typography sx={{ fontSize: '12px', color: d3roPalette.accent.light }}>
|
||||
{pullProgress.status || '모델 다운로드 중...'}
|
||||
{pullProgress.status || t('onboarding.statusPreparing')}
|
||||
</Typography>
|
||||
<Typography sx={{ fontSize: '12px', fontFamily: d3roFontMono, color: d3roPalette.text.primary }}>
|
||||
{pullProgress.percent}%
|
||||
|
|
@ -494,6 +481,14 @@ export function OnboardingModal({ open, onClose }: OnboardingModalProps): React.
|
|||
<LinearProgress variant="determinate" value={pullProgress.percent} sx={{ height: 6, borderRadius: 3 }} />
|
||||
</Box>
|
||||
) : (
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>
|
||||
{pullError && (
|
||||
<Alert severity="error" sx={{ py: 0.5 }}>
|
||||
{pullError.stage === 'pull'
|
||||
? t('onboarding.failed', { message: pullError.message })
|
||||
: pullError.message}
|
||||
</Alert>
|
||||
)}
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||
<Button
|
||||
variant="contained"
|
||||
|
|
@ -516,6 +511,7 @@ export function OnboardingModal({ open, onClose }: OnboardingModalProps): React.
|
|||
</Typography>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue