Files
OllaHub/hooks/use-ollama-check.ts
T
Evandro Fonseca Junior b2a06ed994 fix: address issues in model pull and chat API
- Refactored model pull logic to improve error handling and user feedback.
- Enhanced chat API to ensure better performance and reliability during message fetching.
- Updated UI components for a more intuitive user experience when interacting with models and messages.
2025-11-19 00:01:14 -03:00

42 lines
1.2 KiB
TypeScript

import { useState, useEffect } from 'react';
import { invoke } from '@tauri-apps/api/core';
export type OllamaStatus = 'checking' | 'not_installed' | 'installed_stopped' | 'running';
export function useOllamaCheck() {
const [status, setStatus] = useState<OllamaStatus>('checking');
const check = async () => {
// Don't set checking here if we want to silently revalidate,
// but for initial load or explicit re-check it is fine.
// Only set checking if it's not already in a known state to avoid flicker?
// For now simple is better.
try {
const installed = await invoke<boolean>('check_ollama_installed');
if (!installed) {
setStatus('not_installed');
return;
}
const running = await invoke<boolean>('check_ollama_running');
if (!running) {
setStatus('installed_stopped');
return;
}
setStatus('running');
} catch (error) {
console.error('Failed to check ollama:', error);
// If invoke fails (e.g. backend not ready), we might want to handle gracefully
setStatus('not_installed');
}
};
useEffect(() => {
check();
}, []);
return { status, check };
}