Add Ollama setup helpers and database backup
This commit is contained in:
@@ -44,6 +44,7 @@ export function HomeDashboard() {
|
||||
const [snapshot, setSnapshot] = useState<DashboardSnapshot | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [insightBusy, setInsightBusy] = useState(false);
|
||||
const [ollamaBusy, setOllamaBusy] = useState(false);
|
||||
const [ollamaStatus, setOllamaStatus] = useState<OllamaStatus | null>(null);
|
||||
|
||||
async function loadDashboard(month: string) {
|
||||
@@ -59,6 +60,12 @@ export function HomeDashboard() {
|
||||
setSnapshot(payload);
|
||||
}
|
||||
|
||||
async function loadOllamaStatus() {
|
||||
const response = await fetch("/ollama/status", { cache: "no-store" });
|
||||
const payload = (await response.json()) as OllamaStatus;
|
||||
setOllamaStatus(payload);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
void loadDashboard(selectedMonth);
|
||||
@@ -69,9 +76,7 @@ export function HomeDashboard() {
|
||||
|
||||
useEffect(() => {
|
||||
const timeoutId = window.setTimeout(async () => {
|
||||
const response = await fetch("/ollama/status", { cache: "no-store" });
|
||||
const payload = (await response.json()) as OllamaStatus;
|
||||
setOllamaStatus(payload);
|
||||
await loadOllamaStatus();
|
||||
}, 0);
|
||||
|
||||
return () => window.clearTimeout(timeoutId);
|
||||
@@ -106,6 +111,23 @@ export function HomeDashboard() {
|
||||
await loadDashboard(selectedMonth);
|
||||
}
|
||||
|
||||
async function handlePullModel() {
|
||||
setOllamaBusy(true);
|
||||
|
||||
const response = await fetch("/ollama/pull", { method: "POST" });
|
||||
const payload = (await response.json().catch(() => null)) as { error?: string; message?: string } | null;
|
||||
|
||||
setOllamaBusy(false);
|
||||
|
||||
if (!response.ok) {
|
||||
setError(payload?.error ?? "Could not pull the configured model.");
|
||||
return;
|
||||
}
|
||||
|
||||
setError(payload?.message ?? null);
|
||||
await loadOllamaStatus();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-10">
|
||||
<section className="grid gap-6 rounded-[2rem] border border-stone-200 bg-[radial-gradient(circle_at_top_left,_rgba(251,191,36,0.26),_transparent_32%),linear-gradient(135deg,#fffaf2,#f3efe7)] p-8 shadow-[0_28px_70px_rgba(120,90,50,0.10)] lg:grid-cols-[1.2fr_0.8fr]">
|
||||
@@ -211,6 +233,31 @@ export function HomeDashboard() {
|
||||
URL: <span className="font-semibold text-stone-900">{ollamaStatus?.configuredUrl ?? "-"}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-4 flex flex-wrap gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void loadOllamaStatus()}
|
||||
className="rounded-full border border-stone-300 px-4 py-2 text-xs font-semibold uppercase tracking-[0.2em] text-stone-700 transition hover:border-stone-900"
|
||||
>
|
||||
Refresh status
|
||||
</button>
|
||||
{ollamaStatus?.available && !ollamaStatus.modelReady ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void handlePullModel()}
|
||||
disabled={ollamaBusy}
|
||||
className="rounded-full bg-stone-950 px-4 py-2 text-xs font-semibold uppercase tracking-[0.2em] text-white transition hover:bg-stone-800 disabled:cursor-not-allowed disabled:bg-stone-400"
|
||||
>
|
||||
{ollamaBusy ? "Pulling model..." : "Pull configured model"}
|
||||
</button>
|
||||
) : null}
|
||||
<a
|
||||
href="/backup/database"
|
||||
className="rounded-full border border-stone-300 px-4 py-2 text-xs font-semibold uppercase tracking-[0.2em] text-stone-700 transition hover:border-stone-900"
|
||||
>
|
||||
Download backup
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{snapshot?.insight ? (
|
||||
|
||||
Reference in New Issue
Block a user