diff --git a/web/containers/WaitingCortexModal/index.tsx b/web/containers/WaitingCortexModal/index.tsx index 3168ba4810..e9c1298165 100644 --- a/web/containers/WaitingCortexModal/index.tsx +++ b/web/containers/WaitingCortexModal/index.tsx @@ -1,19 +1,31 @@ import { Modal } from '@janhq/joi' -import { useAtomValue } from 'jotai' +import { useAtom, useAtomValue } from 'jotai' import Spinner from '../Loader/Spinner' import { waitingForCortexAtom } from '@/helpers/atoms/App.atom' import { hostAtom } from '@/helpers/atoms/AppConfig.atom' +import { useCallback, useEffect } from 'react' +import useCortex from '@/hooks/useCortex' const WaitingForCortexModal: React.FC = () => { const host = useAtomValue(hostAtom) - const open = useAtomValue(waitingForCortexAtom) + const [waitingForCortex, setWaitingForCortex] = useAtom(waitingForCortexAtom) + const { isSystemAlive } = useCortex() + + const checkSystemAlive = useCallback(async () => { + setWaitingForCortex(!(await isSystemAlive())) + }, []) + + // Check health for the first time on mount + useEffect(() => { + checkSystemAlive() + }, []) return ( diff --git a/web/helpers/atoms/App.atom.ts b/web/helpers/atoms/App.atom.ts index eacbf3a511..0668f47631 100644 --- a/web/helpers/atoms/App.atom.ts +++ b/web/helpers/atoms/App.atom.ts @@ -11,7 +11,7 @@ export const mainViewStateAtom = atom(MainViewState.Thread) export const defaultJanDataFolderAtom = atom('') -export const waitingForCortexAtom = atom(false) +export const waitingForCortexAtom = atom(true) // Store panel atom export const showLeftPanelAtom = atom(true) diff --git a/web/hooks/useCortex.ts b/web/hooks/useCortex.ts index fd4d7d052a..c3485f7e04 100644 --- a/web/hooks/useCortex.ts +++ b/web/hooks/useCortex.ts @@ -319,6 +319,15 @@ const useCortex = () => { [host] ) + const isSystemAlive = useCallback(async () => { + try { + await cortex.system.status(); + return true; + } catch { + return false; + } + }, [host]) + return { fetchAssistants, fetchThreads, @@ -345,6 +354,7 @@ const useCortex = () => { createModel, initializeEngine, getEngineStatuses, + isSystemAlive } }