This commit is contained in:
k
2026-09-21 13:36:25 +02:00
parent 59402b250c
commit c05aa7a211
18 changed files with 532 additions and 36 deletions
+7 -5
View File
@@ -6,7 +6,7 @@ import { Login } from "./components/Login.tsx";
import { Sidebar } from "./components/Sidebar.tsx";
import { Chat } from "./components/Chat.tsx";
import { ConvEditDialog, FilePreviewModal, SettingsModal, ShareModal } from "./components/dialogs.tsx";
import { AdminPanel } from "./components/AdminPanel.tsx";
import { AdminCenter } from "./components/AdminCenter.tsx";
import { SharePage } from "./components/SharePage.tsx";
import { ResetPage } from "./components/ResetPage.tsx";
import { ConfirmDialog } from "./components/ui.tsx";
@@ -19,6 +19,7 @@ function shareIdFromPath(): string | null {
// Module-level: the path never changes without a full reload, so hook order stays stable.
const SHARE_ID = typeof window !== "undefined" ? shareIdFromPath() : null;
const RESET_TOKEN = typeof window !== "undefined" ? resetTokenFromPath() : null;
const IS_ADMIN_PAGE = typeof window !== "undefined" && /^\/admin\/?$/.test(window.location.pathname);
function resetTokenFromPath(): string | null {
const m = window.location.pathname.match(/^\/reset\/([A-Za-z0-9_-]{6,80})\/?$/);
@@ -35,7 +36,7 @@ function applyTheme(theme: string) {
export function App() {
const [user, setUser] = useState<User | null>(null);
const [checking, setChecking] = useState(!SHARE_ID && !RESET_TOKEN && !!getToken());
const [checking, setChecking] = useState(!SHARE_ID && !RESET_TOKEN && !IS_ADMIN_PAGE && !!getToken());
const [models, setModels] = useState<DriverModel[]>([]);
const [model, setModel] = useState("");
const [convs, setConvs] = useState<Conversation[]>([]);
@@ -49,7 +50,6 @@ export function App() {
const [shareConv, setShareConv] = useState<Conversation | null>(null);
const [deleteConv, setDeleteConv] = useState<Conversation | null>(null);
const [settingsOpen, setSettingsOpen] = useState(false);
const [adminOpen, setAdminOpen] = useState(false);
const [attachments, setAttachments] = useState<Attachment[]>([]);
const [attachError, setAttachError] = useState<string | null>(null);
const [filePreview, setFilePreview] = useState<FilePreview | null>(null);
@@ -57,6 +57,9 @@ export function App() {
const [ocrAvailable, setOcrAvailable] = useState(false);
// Public routes: no auth needed. IDs are constant for the page lifetime.
if (IS_ADMIN_PAGE) {
return <AdminCenter />;
}
if (RESET_TOKEN) {
return <ResetPage token={RESET_TOKEN} />;
}
@@ -277,7 +280,7 @@ export function App() {
onShare={setShareConv}
onDelete={setDeleteConv}
onOpenSettings={() => { setSettingsOpen(true); setMobileNav(false); }}
onOpenAdmin={() => { setAdminOpen(true); setMobileNav(false); }}
onOpenAdmin={() => { window.location.href = "/admin"; }}
onLogout={logout}
mobileOpen={mobileNav}
onCloseMobile={() => setMobileNav(false)}
@@ -332,7 +335,6 @@ export function App() {
applyTheme(u.theme);
}}
/>
<AdminPanel open={adminOpen} onClose={() => setAdminOpen(false)} />
</div>
);
}
+168
View File
@@ -0,0 +1,168 @@
import { useEffect, useState } from "react";
import { ArrowLeft, LayoutDashboard, Mail, ShieldAlert, SlidersHorizontal, Users } from "lucide-react";
import { api } from "../lib/api.ts";
import { AdminPanel } from "./AdminPanel.tsx";
import { Logo, Spinner, Switch } from "./ui.tsx";
import { cn } from "../lib/cn.ts";
type Tab = "accounts" | "features" | "mail";
function applyTheme(theme: string) {
const root = document.documentElement;
const dark = theme === "dark" || (theme !== "light" && window.matchMedia("(prefers-color-scheme: dark)").matches);
root.classList.toggle("dark", dark);
root.style.colorScheme = dark ? "dark" : "light";
}
const TABS: { id: Tab; label: string; icon: typeof Users }[] = [
{ id: "accounts", label: "Accounts", icon: Users },
{ id: "features", label: "Features", icon: SlidersHorizontal },
{ id: "mail", label: "Mail", icon: Mail },
];
export function AdminCenter() {
const [allowed, setAllowed] = useState<boolean | null>(null);
const [tab, setTab] = useState<Tab>("accounts");
const [settings, setSettings] = useState<{ registrationEnabled: boolean; ocrEnabled: boolean } | null>(null);
const [mail, setMail] = useState<{ recovery: boolean; from?: string } | null>(null);
const [error, setError] = useState("");
const [saving, setSaving] = useState(false);
useEffect(() => {
api.verify()
.then((r) => {
if (!r.user.isAdmin) {
setAllowed(false);
return;
}
setAllowed(true);
applyTheme(r.user.theme);
api.adminGetSettings().then((s) => setSettings(s.settings)).catch((e) => setError(e instanceof Error ? e.message : "Load failed"));
api.methods().then((m) => setMail(m)).catch(() => {});
})
.catch(() => setAllowed(false));
}, []);
async function toggle(patch: { registrationEnabled?: boolean; ocrEnabled?: boolean }) {
setSaving(true);
setError("");
try {
const res = await api.adminPatchSettings(patch);
setSettings(res.settings);
} catch (e) {
setError(e instanceof Error ? e.message : "Save failed");
} finally {
setSaving(false);
}
}
if (allowed === null) {
return <div className="grid min-h-full place-items-center text-sm opacity-60"><Spinner /> Checking admin access…</div>;
}
if (!allowed) {
return (
<div className="grid min-h-full place-items-center p-6">
<div className="w-full max-w-sm rounded-[2rem] border border-stone-200 bg-white p-8 text-center shadow-xl dark:border-zinc-800 dark:bg-zinc-900">
<ShieldAlert size={28} className="mx-auto mb-3 text-red-500" />
<h1 className="text-lg font-bold">Admins only</h1>
<p className="mt-1 text-sm opacity-60">Log in with the admin account to open the Admin Center.</p>
<a href="/" className="mt-4 inline-block rounded-full bg-accent-600 px-5 py-2.5 text-sm font-medium text-white dark:bg-accent-500 dark:text-zinc-950">Back to login</a>
</div>
</div>
);
}
return (
<div className="min-h-full">
<header className="border-b border-stone-200/70 bg-white/70 backdrop-blur dark:border-zinc-800 dark:bg-zinc-900/70">
<div className="mx-auto flex w-full max-w-4xl items-center gap-3 px-4 py-3">
<a href="/" aria-label="Back to chat" className="rounded-full p-2 transition hover:bg-stone-200/60 dark:hover:bg-zinc-800">
<ArrowLeft size={18} />
</a>
<Logo size={32} className="rounded-xl" />
<h1 className="flex items-center gap-2 text-lg font-bold tracking-tight">
<LayoutDashboard size={18} className="text-accent-600 dark:text-accent-400" />
Admin Center
</h1>
</div>
<div className="mx-auto w-full max-w-4xl px-4 pb-3">
<div className="flex gap-1 overflow-x-auto rounded-full border border-stone-200/70 bg-stone-100/70 p-1 dark:border-zinc-800 dark:bg-zinc-900">
{TABS.map((t) => (
<button
key={t.id}
onClick={() => setTab(t.id)}
className={cn(
"flex flex-1 items-center justify-center gap-2 whitespace-nowrap rounded-full px-4 py-2 text-sm font-medium transition",
tab === t.id
? "bg-white text-stone-900 shadow dark:bg-zinc-800 dark:text-zinc-100"
: "opacity-60 hover:opacity-100",
)}
>
<t.icon size={15} />
{t.label}
</button>
))}
</div>
</div>
</header>
<main className="mx-auto w-full max-w-4xl space-y-4 px-4 py-6">
{error && <p className="rounded-2xl bg-red-500/10 px-4 py-2.5 text-sm text-red-600 dark:text-red-400" role="alert">{error}</p>}
{tab === "accounts" && (
<section className="rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<AdminPanel open bare onClose={() => {}} />
</section>
)}
{tab === "features" && (
<section className="space-y-3">
<div className="flex items-center gap-4 rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<div className="min-w-0 flex-1">
<p className="text-sm font-medium">Public registration</p>
<p className="text-sm opacity-60">Show the Register button on the login page. Off = admin-created accounts only.</p>
</div>
<Switch label="Public registration" checked={settings?.registrationEnabled ?? false} onChange={(v) => toggle({ registrationEnabled: v })} />
</div>
<div className="flex items-center gap-4 rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<div className="min-w-0 flex-1">
<p className="text-sm font-medium">OCR tool</p>
<p className="text-sm opacity-60">Server-side image transcription for attachments. Requires the tesseract binary.</p>
</div>
<Switch label="OCR tool" checked={settings?.ocrEnabled ?? false} onChange={(v) => toggle({ ocrEnabled: v })} />
</div>
{saving && <p className="flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> Saving…</p>}
{!settings && !error && <p className="flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> Loading…</p>}
</section>
)}
{tab === "mail" && (
<section className="rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<div className="flex items-center gap-3">
<span className="grid h-10 w-10 place-items-center rounded-full bg-accent-600/10 text-accent-600 dark:text-accent-400">
<Mail size={17} />
</span>
<div>
<p className="text-sm font-medium">Key recovery emails</p>
<p className="text-sm opacity-60">
{mail == null ? "Checking…" : mail.recovery ? `Enabled — sent from ${mail.from ?? "the configured sender"}` : "Disabled — set SMTP_HOST on the server to enable"}
</p>
</div>
<span className={cn(
"ml-auto rounded-full px-3 py-1 text-xs font-medium",
mail?.recovery ? "bg-emerald-600/10 text-emerald-700 dark:text-emerald-400" : "bg-stone-200/70 dark:bg-zinc-800",
)}>
{mail?.recovery ? "On" : "Off"}
</span>
</div>
<p className="mt-3 text-sm opacity-60">
SMTP credentials live in the server environment (see <code>docs/OPERATIONS.md</code>), never in this UI.
Users set their recovery address in profile settings or at account creation.
</p>
</section>
)}
</main>
</div>
);
}
+198 -11
View File
@@ -1,10 +1,184 @@
import { useEffect, useState } from "react";
import { KeyRound, Pencil, RefreshCw, Trash2, UserPlus, Users } from "lucide-react";
import { useEffect, useState, type FC, type ReactNode } from "react";
import { Bot, Download, HardDrive, KeyRound, Pencil, RefreshCw, Trash2, UserPlus, Users } from "lucide-react";
import { api } from "../lib/api.ts";
import type { User } from "../lib/types.ts";
import type { DriverModel, User } from "../lib/types.ts";
import { Avatar, Button, ConfirmDialog, CopyButton, Field, Input, Modal, Picker, Spinner } from "./ui.tsx";
export function AdminPanel({ open, onClose }: { open: boolean; onClose: () => void }) {
/** Curated Ollama library catalog (admin downloads only). */
const OLLAMA_CATALOG: { name: string; desc: string; sizes: string[] }[] = [
{ name: "llama3.2", desc: "Meta's compact everyday model", sizes: ["1b", "3b"] },
{ name: "llama3.1", desc: "Meta's general-purpose workhorse", sizes: ["8b", "70b"] },
{ name: "qwen2.5", desc: "Alibaba's multilingual all-rounder", sizes: ["0.5b", "1.5b", "7b", "14b", "32b"] },
{ name: "gemma2", desc: "Google's efficient open model", sizes: ["2b", "9b", "27b"] },
{ name: "mistral", desc: "Mistral 7B — fast and capable", sizes: ["7b"] },
{ name: "phi3", desc: "Microsoft's small research model", sizes: ["3.8b", "14b"] },
{ name: "deepseek-r1", desc: "Reasoning model (chain-of-thought)", sizes: ["1.5b", "7b", "8b", "14b", "32b"] },
{ name: "codellama", desc: "Code completion and chat", sizes: ["7b", "13b", "34b"] },
{ name: "llava", desc: "Vision model (image understanding)", sizes: ["7b", "13b", "34b"] },
{ name: "nomic-embed-text", desc: "Text embeddings", sizes: [] },
];
/* ---------- Ollama model catalog (admin) ---------- */
export function OllamaModelsModal({ open, onClose }: { open: boolean; onClose: () => void }) {
const [installed, setInstalled] = useState<DriverModel[]>([]);
const [pullName, setPullName] = useState("");
const [pullStatus, setPullStatus] = useState("");
const [pullPct, setPullPct] = useState<number | null>(null);
const [pulling, setPulling] = useState(false);
const [error, setError] = useState("");
const [deleteModel, setDeleteModel] = useState<string | null>(null);
const [sizeOverrides, setSizeOverrides] = useState<Record<string, string>>({});
async function refreshInstalled() {
try {
const res = await api.models();
setInstalled(res.models.filter((m) => m.driver === "ollama"));
} catch { /* ignore */ }
}
useEffect(() => {
if (open) {
setError("");
setPullStatus("");
setPullPct(null);
setPulling(false);
refreshInstalled();
}
}, [open]);
async function pull(fullName: string) {
if (pulling || !fullName.trim()) return;
setPulling(true);
setError("");
setPullStatus("Contacting Ollama…");
setPullPct(null);
try {
await api.ollamaPull(fullName.trim(), (p) => {
if (p.error) { setError(p.error); return; }
setPullStatus(p.status || "Pulling…");
if (p.total && p.completed) setPullPct(Math.min(100, Math.round((p.completed / p.total) * 100)));
else setPullPct(null);
});
setPullStatus("Done");
setPullPct(100);
await refreshInstalled();
} catch (err) {
setError(err instanceof Error ? err.message : "Pull failed");
} finally {
setPulling(false);
}
}
async function removeModel(name: string) {
try {
await api.ollamaDelete(name);
await refreshInstalled();
} catch (err) {
setError(err instanceof Error ? err.message : "Delete failed");
}
}
return (
<>
<Modal open={open} onClose={pulling ? () => {} : onClose} title="Ollama models" icon={Bot}>
<p className="mb-4 text-sm opacity-70">
Download models from the Ollama library to your Ollama host, or remove local ones. Admin only.
</p>
{error && <p className="mb-3 rounded-2xl bg-red-50 px-4 py-2.5 text-sm text-red-600 dark:bg-red-950/40 dark:text-red-400" role="alert">{error}</p>}
{pulling && (
<div className="mb-4 rounded-2xl border border-accent-500/40 bg-accent-50 p-4 dark:bg-accent-950/30">
<p className="mb-2 flex items-center gap-2 text-sm font-medium">
<Download size={15} className="animate-bounce" />
Pulling {pullName}
</p>
<p className="mb-2 truncate text-xs opacity-70">{pullStatus}</p>
{pullPct !== null && (
<div className="h-2 overflow-hidden rounded-full bg-stone-200 dark:bg-zinc-800">
<div className="h-full rounded-full bg-accent-600 transition-all dark:bg-accent-500" style={{ width: `${pullPct}%` }} />
</div>
)}
</div>
)}
<div className="mb-4 flex flex-wrap items-end gap-2 rounded-2xl border border-stone-200 p-3 dark:border-zinc-700">
<div className="min-w-52 flex-1">
<Field label="Custom model tag" hint="e.g. llama3.2:3b, or a full library name">
<Input
value={pullName}
onChange={(e) => setPullName(e.target.value)}
placeholder="llama3.2:3b"
disabled={pulling}
onKeyDown={(e) => e.key === "Enter" && pull(pullName)}
/>
</Field>
</div>
<Button size="sm" onClick={() => pull(pullName)} disabled={pulling || !pullName.trim()}>
{pulling ? <Spinner size={15} /> : <Download size={15} />} Pull
</Button>
</div>
<p className="mb-2 flex items-center gap-1.5 text-sm font-medium"><HardDrive size={14} /> Installed ({installed.length})</p>
<ul className="mb-5 space-y-1.5">
{installed.length === 0 && <li className="text-sm opacity-50">No local Ollama models yet.</li>}
{installed.map((m) => (
<li key={m.id} className="flex items-center gap-3 rounded-2xl border border-stone-200/70 px-3.5 py-2 dark:border-zinc-800">
<span className="min-w-0 flex-1 truncate text-sm font-medium">{m.label || m.id}</span>
<button
title={`Delete ${m.label || m.id}`}
onClick={() => setDeleteModel(m.label || m.id)}
className="rounded-full p-2 text-red-600 transition hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/40"
>
<Trash2 size={15} />
</button>
</li>
))}
</ul>
<p className="mb-2 flex items-center gap-1.5 text-sm font-medium"><Download size={14} /> Catalog</p>
<ul className="space-y-1.5">
{OLLAMA_CATALOG.map((m) => {
const size = sizeOverrides[m.name] ?? (m.sizes.length > 0 ? m.sizes[0]! : "");
const tag = size ? `${m.name}:${size}` : m.name;
return (
<li key={m.name} className="flex flex-wrap items-center gap-2 rounded-2xl border border-stone-200/70 px-3.5 py-2 dark:border-zinc-800">
<span className="min-w-0 flex-1">
<span className="block truncate text-sm font-medium">{m.name}</span>
<span className="block text-xs opacity-50">{m.desc}</span>
</span>
{m.sizes.length > 0 && (
<span className="w-24 shrink-0">
<Picker
ariaLabel={`${m.name} size`}
value={size}
onChange={(v) => setSizeOverrides((prev) => ({ ...prev, [m.name]: v }))}
align="right"
options={m.sizes.map((s) => ({ value: s, label: s }))}
/>
</span>
)}
<Button size="sm" variant="secondary" onClick={() => { setPullName(tag); pull(tag); }} disabled={pulling}>
<Download size={14} /> Pull
</Button>
</li>
);
})}
</ul>
</Modal>
<ConfirmDialog
open={deleteModel !== null}
onClose={() => setDeleteModel(null)}
title={`Delete ${deleteModel}?`}
message="The model is removed from the Ollama host. Pull it again anytime."
onConfirm={() => deleteModel && removeModel(deleteModel)}
/>
</>
);
}
export function AdminPanel({ open, onClose, bare }: { open: boolean; onClose: () => void; bare?: boolean }) {
const [users, setUsers] = useState<User[]>([]);
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
@@ -12,6 +186,7 @@ export function AdminPanel({ open, onClose }: { open: boolean; onClose: () => vo
const [freshKey, setFreshKey] = useState<{ username: string; key: string } | null>(null);
const [deleteTarget, setDeleteTarget] = useState<User | null>(null);
const [editTarget, setEditTarget] = useState<User | null>(null);
const [modelsOpen, setModelsOpen] = useState(false);
// create form
const [username, setUsername] = useState("");
@@ -32,13 +207,13 @@ export function AdminPanel({ open, onClose }: { open: boolean; onClose: () => vo
}
useEffect(() => {
if (open) {
if (open || bare) {
refresh();
setShowCreate(false);
setFreshKey(null);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open ]);
}, [open, bare ]);
async function create(e: React.FormEvent) {
e.preventDefault();
@@ -75,9 +250,15 @@ export function AdminPanel({ open, onClose }: { open: boolean; onClose: () => vo
}
}
// Bare mode embeds the same manager in the /admin Center page instead
// of a modal — no logic duplicated.
const Shell: FC<{ children: ReactNode }> = bare
? ({ children }) => <div className="min-w-0 flex-1 space-y-1">{children}</div>
: ({ children }) => <Modal open={open} onClose={onClose} title="Accounts" icon={Users} wide>{children}</Modal>;
return (
<>
<Modal open={open} onClose={onClose} title="Accounts" icon={Users} wide>
<Shell>
<p className="mb-4 text-sm opacity-70">
No-KYC accounts: you create a username, hand the access key to its owner once. Keys are stored hashed — regenerate to rotate.
</p>
@@ -94,9 +275,14 @@ export function AdminPanel({ open, onClose }: { open: boolean; onClose: () => vo
)}
{!showCreate ? (
<Button variant="secondary" size="sm" onClick={() => setShowCreate(true)} className="mb-3">
<UserPlus size={15} /> New account
</Button>
<div className="mb-3 flex flex-wrap gap-2">
<Button variant="secondary" size="sm" onClick={() => setShowCreate(true)}>
<UserPlus size={15} /> New account
</Button>
<Button variant="secondary" size="sm" onClick={() => setModelsOpen(true)}>
<Bot size={15} /> Ollama models
</Button>
</div>
) : (
<form onSubmit={create} className="mb-4 flex flex-wrap items-end gap-2 rounded-2xl border border-stone-200 p-3 dark:border-zinc-700">
<div className="min-w-40 flex-1">
@@ -135,7 +321,7 @@ export function AdminPanel({ open, onClose }: { open: boolean; onClose: () => vo
))}
</ul>
)}
</Modal>
</Shell>
<ConfirmDialog
open={deleteTarget !== null}
@@ -146,6 +332,7 @@ export function AdminPanel({ open, onClose }: { open: boolean; onClose: () => vo
/>
<EditUserDialog user={editTarget} onClose={() => setEditTarget(null)} onSaved={refresh} />
<OllamaModelsModal open={modelsOpen} onClose={() => setModelsOpen(false)} />
</>
);
}
+26 -2
View File
@@ -1,9 +1,9 @@
import { useEffect, useState } from "react";
import { ArrowRight, KeyRound, ShieldCheck, User, Zap } from "lucide-react";
import { ArrowRight, KeyRound, ShieldCheck, User, UserPlus, Zap } from "lucide-react";
import { api, setToken } from "../lib/api.ts";
import type { User as UserType } from "../lib/types.ts";
import { Button, Input, Logo, Spinner } from "./ui.tsx";
import { RecoverDialog } from "./dialogs.tsx";
import { RecoverDialog, RegisterDialog } from "./dialogs.tsx";
const PERKS = [
{ icon: ShieldCheck, text: "Private by design — no cookies, no tracking" },
@@ -18,11 +18,14 @@ export function Login({ onLogin }: { onLogin: (user: UserType) => void }) {
const [recoverOpen, setRecoverOpen] = useState(false);
const [recoveryOn, setRecoveryOn] = useState(false);
const [recoveryFrom, setRecoveryFrom] = useState<string | undefined>(undefined);
const [registerOpen, setRegisterOpen] = useState(false);
const [registrationOn, setRegistrationOn] = useState(false);
useEffect(() => {
api.methods().then((m) => {
setRecoveryOn(m.recovery);
setRecoveryFrom(m.from);
setRegistrationOn(m.registration);
}).catch(() => {});
}, []);
@@ -89,6 +92,27 @@ export function Login({ onLogin }: { onLogin: (user: UserType) => void }) {
{busy ? <Spinner /> : (<>Unlock <ArrowRight size={17} /></>)}
</Button>
</form>
<div className="mt-4 flex items-center gap-3 text-xs opacity-40">
<span className="h-px flex-1 bg-current" />
New here?
<span className="h-px flex-1 bg-current" />
</div>
<Button
variant="secondary"
size="lg"
className="mt-3 w-full"
disabled={!registrationOn}
title={registrationOn ? "Create an account" : "Registration currently disabled on this platform"}
onClick={() => setRegisterOpen(true)}
>
<UserPlus size={16} />
Register
</Button>
<RegisterDialog
open={registerOpen}
onClose={() => setRegisterOpen(false)}
onDone={(u, k) => { setUsername(u); setKey(k); }}
/>
{recoveryOn && (
<button onClick={() => setRecoverOpen(true)} className="mt-3 w-full text-center text-sm opacity-60 transition hover:opacity-100 hover:underline">
Forgot your access key?
+4 -4
View File
@@ -1,5 +1,6 @@
import { useRef, useState } from "react";
import {
LayoutDashboard,
MessageSquarePlus,
MoreVertical,
PanelLeftClose,
@@ -8,7 +9,6 @@ import {
Share2,
Tag,
Trash2,
Users,
X,
} from "lucide-react";
import type { Conversation, User } from "../lib/types.ts";
@@ -199,9 +199,9 @@ export function Sidebar({
</button>
<div className="flex gap-1.5">
{user.isAdmin && (
<Button variant="secondary" size="sm" className="flex-1" onClick={onOpenAdmin} title="Manage accounts">
<Users size={15} />
Accounts
<Button variant="secondary" size="sm" className="flex-1" onClick={onOpenAdmin} title="Open the Admin Center">
<LayoutDashboard size={15} />
Admin Center
</Button>
)}
<Button variant="ghost" size="sm" className={user.isAdmin ? "" : "flex-1"} onClick={onLogout}>
+38
View File
@@ -85,6 +85,44 @@ export const api = {
models: () => req<{ models: DriverModel[] }>("/api/models"),
/** Admin: stream an Ollama /api/pull as NDJSON progress events. */
ollamaPull: async (
name: string,
onProgress: (p: { status?: string; digest?: string; total?: number; completed?: number; error?: string }) => void,
): Promise<void> => {
const res = await fetch("/api/admin/ollama/pull", {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Bearer ${getToken()}` },
body: JSON.stringify({ name }),
});
if (res.status === 401) {
clearToken();
window.location.reload();
throw new ApiError(401, "Session expired.");
}
if (!res.ok || !res.body) {
const err = (await res.json().catch(() => ({}))) as { error?: string };
throw new ApiError(res.status, err.error || `Pull failed (${res.status})`);
}
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buf = "";
for (;;) {
const { done, value } = await reader.read();
if (done) break;
buf += decoder.decode(value, { stream: true });
const lines = buf.split("\n");
buf = lines.pop() ?? "";
for (const line of lines) {
const t = line.trim();
if (t) onProgress(JSON.parse(t));
}
}
},
/** Admin: delete a local Ollama model (frees disk on the Ollama host). */
ollamaDelete: (name: string) => req<{ ok: boolean }>(`/api/admin/ollama/models/${encodeURIComponent(name)}`, { method: "DELETE" }),
tools: () => req<{ tools: { name: string; description: string; available: boolean; reason: string | null }[] }>("/api/tools"),
/** Send an image to the platform OCR tool. Returns editable text (never the raw image). */