- Rename the app to Kaname - Hub metadata per model (base models, architecture, license, Hub tags), backfilled by the worker for existing models - Library search across repo/author/family/quant/tags and multi-select facet filters (author, family, quant, tag, status) kept in the URL - Custom tags (model page editor, on add, click-to-filter) - README rewritten around a quick install, with banner and screenshots - deploy/compose.yaml: models in a host folder (KANAME_MODELS_DIR) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2167ea0950
commit
67191b3e16
37 files changed
+2028
-206
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -44,6 +44,15 @@ export function AddModelForm({
|
||||
const [includeText, setIncludeText] = useState("");
|
||||
const [excludeText, setExcludeText] = useState("");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [tagsText, setTagsText] = useState("");
|
||||
const [knownTags, setKnownTags] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/tags")
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((all: { name: string }[]) => setKnownTags(all.map((t) => t.name)))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
async function lookup(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
@@ -56,6 +65,7 @@ export function AddModelForm({
|
||||
setChecked(new Set());
|
||||
setIncludeText("");
|
||||
setExcludeText("");
|
||||
setTagsText("");
|
||||
} catch (err) {
|
||||
setResult(null);
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
@@ -129,6 +139,7 @@ export function AddModelForm({
|
||||
sha: result.sha,
|
||||
include: [...includePatterns, ...[...checked].sort().map(escapeGlob)],
|
||||
exclude: excludePatterns,
|
||||
tags: parsePatternList(tagsText),
|
||||
});
|
||||
toast.success(`${result.repoId} added, download queued`);
|
||||
onAdded(id);
|
||||
@@ -269,6 +280,23 @@ export function AddModelForm({
|
||||
folder. Selected = checked or matching an include pattern, minus excludes.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="tags">Tags</Label>
|
||||
<Input
|
||||
id="tags"
|
||||
value={tagsText}
|
||||
onChange={(e) => setTagsText(e.target.value)}
|
||||
placeholder="roleplay, security"
|
||||
list="known-tags"
|
||||
/>
|
||||
<datalist id="known-tags">
|
||||
{knownTags.map((t) => (
|
||||
<option key={t} value={t} />
|
||||
))}
|
||||
</datalist>
|
||||
<p className="text-xs text-muted-foreground">Optional, comma-separated. Editable later on the model page.</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronDownIcon } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
|
||||
/** Multi-select dropdown for one facet, with per-value counts. */
|
||||
export function FacetFilter({
|
||||
label,
|
||||
values,
|
||||
selected,
|
||||
onChange,
|
||||
format = (v) => v,
|
||||
}: {
|
||||
label: string;
|
||||
values: [string, number][];
|
||||
selected: string[];
|
||||
onChange: (next: string[]) => void;
|
||||
format?: (value: string) => string;
|
||||
}) {
|
||||
const active = selected.length > 0;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
render={<Button variant={active ? "secondary" : "outline"} size="sm" disabled={values.length === 0} />}
|
||||
>
|
||||
{label}
|
||||
{active && <span className="rounded bg-background/60 px-1 text-xs tabular-nums">{selected.length}</span>}
|
||||
<ChevronDownIcon className="opacity-60" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-auto min-w-48">
|
||||
{values.map(([value, count]) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={value}
|
||||
checked={selected.includes(value)}
|
||||
closeOnClick={false}
|
||||
onCheckedChange={(on) => onChange(on ? [...selected, value] : selected.filter((v) => v !== value))}
|
||||
>
|
||||
<span className="flex-1">{format(value)}</span>
|
||||
<span className="ml-4 text-xs text-muted-foreground tabular-nums">{count}</span>
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export default async function AppLayout({ children }: LayoutProps<"/">) {
|
||||
<header className="border-b">
|
||||
<div className="mx-auto flex h-14 max-w-6xl items-center gap-6 px-4">
|
||||
<Link href="/" className="flex items-baseline gap-1.5 font-semibold">
|
||||
Model Manager
|
||||
Kaname
|
||||
<span className="text-xs font-normal text-muted-foreground">{process.env.APP_VERSION ?? "dev"}</span>
|
||||
</Link>
|
||||
<nav className="flex items-center gap-4 text-sm text-muted-foreground">
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { JobProgress, JobStateBadge } from "@/components/job-progress";
|
||||
import { ModelStatusBadge } from "@/components/model-status-badge";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import type { JobSnapshot } from "@/lib/jobs";
|
||||
import type { LibraryRow } from "@/lib/library";
|
||||
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
export function LibraryTable({ rows }: { rows: LibraryRow[] }) {
|
||||
const { snapshot } = useLive();
|
||||
const openJobs = new Map<string, JobSnapshot>();
|
||||
for (const j of snapshot?.jobs ?? []) {
|
||||
if (OPEN.includes(j.state) && !openJobs.has(j.modelId)) openJobs.set(j.modelId, j);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="py-0">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Repository</TableHead>
|
||||
<TableHead>Selection</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead>Pinned</TableHead>
|
||||
<TableHead className="hidden md:table-cell">Downloaded</TableHead>
|
||||
<TableHead className="w-56">Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((r) => {
|
||||
const job = openJobs.get(r.id);
|
||||
return (
|
||||
<TableRow key={r.id}>
|
||||
<TableCell className="font-medium">
|
||||
<Link href={`/models/${r.id}`} className="hover:underline">
|
||||
{r.repoId}
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{r.quants.length > 0 ? r.quants.join(", ") : `${r.fileCount} files`}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(r.totalBytes)}</TableCell>
|
||||
<TableCell>
|
||||
<code className="font-mono text-xs" title={r.pinnedSha}>
|
||||
{r.trackedRevision}@{shortSha(r.pinnedSha)}
|
||||
</code>
|
||||
</TableCell>
|
||||
<TableCell className="hidden text-sm text-muted-foreground md:table-cell">
|
||||
<LocalTime value={r.downloadedAt} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{job ? (
|
||||
<Link href={`/jobs/${job.id}`} className="flex flex-col gap-1">
|
||||
<JobStateBadge job={job} />
|
||||
{job.state !== "queued" && <JobProgress job={job} compact />}
|
||||
</Link>
|
||||
) : (
|
||||
<ModelStatusBadge status={r.status} />
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
"use client";
|
||||
|
||||
import { SearchIcon, XIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useMemo, useState } from "react";
|
||||
import { JobProgress, JobStateBadge } from "@/components/job-progress";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { MODEL_STATUS, ModelStatusBadge } from "@/components/model-status-badge";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import type { ModelStatus } from "@/lib/db/schema";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import type { JobSnapshot } from "@/lib/jobs";
|
||||
import type { LibraryRow } from "@/lib/library";
|
||||
import {
|
||||
EMPTY_FILTERS,
|
||||
type Facet,
|
||||
FACETS,
|
||||
facetCounts,
|
||||
type Filters,
|
||||
matchesFilters,
|
||||
matchesQuery,
|
||||
type SearchableModel,
|
||||
} from "@/lib/search";
|
||||
import { FacetFilter } from "./facet-filter";
|
||||
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
const FACET_LABEL: Record<Facet, string> = {
|
||||
author: "Author",
|
||||
family: "Family",
|
||||
quant: "Quant",
|
||||
tag: "Tag",
|
||||
status: "Status",
|
||||
};
|
||||
|
||||
const statusLabel = (v: string) => MODEL_STATUS[v as ModelStatus]?.label ?? v;
|
||||
|
||||
function toSearchable(r: LibraryRow): SearchableModel {
|
||||
return {
|
||||
repoId: r.repoId,
|
||||
author: r.author,
|
||||
families: r.families,
|
||||
baseModels: r.baseModels,
|
||||
architecture: r.architecture,
|
||||
quants: r.quants,
|
||||
tags: r.tags.map((t) => t.name),
|
||||
hubTags: r.hubTags,
|
||||
pipelineTag: r.pipelineTag,
|
||||
license: r.license,
|
||||
status: r.status,
|
||||
};
|
||||
}
|
||||
|
||||
/** Search + facet filters (kept in the URL) over the library table. */
|
||||
export function LibraryView({ rows }: { rows: LibraryRow[] }) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const params = useSearchParams();
|
||||
const [query, setQuery] = useState(() => params.get("q") ?? "");
|
||||
const [filters, setFilters] = useState<Filters>(() => {
|
||||
const f = { ...EMPTY_FILTERS };
|
||||
for (const facet of FACETS) f[facet] = params.getAll(facet);
|
||||
return f;
|
||||
});
|
||||
|
||||
function sync(nextQuery: string, nextFilters: Filters) {
|
||||
const p = new URLSearchParams();
|
||||
if (nextQuery) p.set("q", nextQuery);
|
||||
for (const facet of FACETS) for (const v of nextFilters[facet]) p.append(facet, v);
|
||||
const qs = p.toString();
|
||||
router.replace(qs ? `${pathname}?${qs}` : pathname, { scroll: false });
|
||||
}
|
||||
const updateQuery = (q: string) => {
|
||||
setQuery(q);
|
||||
sync(q, filters);
|
||||
};
|
||||
const updateFilter = (facet: Facet, values: string[]) => {
|
||||
const next = { ...filters, [facet]: values };
|
||||
setFilters(next);
|
||||
sync(query, next);
|
||||
};
|
||||
const clearAll = () => {
|
||||
setQuery("");
|
||||
setFilters(EMPTY_FILTERS);
|
||||
sync("", EMPTY_FILTERS);
|
||||
};
|
||||
|
||||
const searchable = useMemo(() => rows.map(toSearchable), [rows]);
|
||||
const visible = rows.filter((_, i) => matchesQuery(searchable[i], query) && matchesFilters(searchable[i], filters));
|
||||
const anyActive = query.trim() !== "" || FACETS.some((f) => filters[f].length > 0);
|
||||
|
||||
const { snapshot } = useLive();
|
||||
const openJobs = new Map<string, JobSnapshot>();
|
||||
for (const j of snapshot?.jobs ?? []) {
|
||||
if (OPEN.includes(j.state) && !openJobs.has(j.modelId)) openJobs.set(j.modelId, j);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<div className="relative min-w-56 flex-1">
|
||||
<SearchIcon className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(e) => updateQuery(e.target.value)}
|
||||
placeholder="Search repo, author, family, quant, tag…"
|
||||
className="pl-8"
|
||||
aria-label="Search models"
|
||||
/>
|
||||
</div>
|
||||
{FACETS.map((facet) => (
|
||||
<FacetFilter
|
||||
key={facet}
|
||||
label={FACET_LABEL[facet]}
|
||||
values={facetCounts(searchable, facet, query, filters)}
|
||||
selected={filters[facet]}
|
||||
onChange={(v) => updateFilter(facet, v)}
|
||||
format={facet === "status" ? statusLabel : undefined}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{anyActive && (
|
||||
<div className="flex flex-wrap items-center gap-1.5 text-sm">
|
||||
<span className="text-muted-foreground">
|
||||
{visible.length} of {rows.length} models
|
||||
</span>
|
||||
{FACETS.flatMap((facet) =>
|
||||
filters[facet].map((v) => (
|
||||
<Badge key={`${facet}:${v}`} variant="secondary" className="gap-1">
|
||||
{FACET_LABEL[facet]}: {facet === "status" ? statusLabel(v) : v}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Remove filter ${v}`}
|
||||
onClick={() => updateFilter(facet, filters[facet].filter((x) => x !== v))}
|
||||
>
|
||||
<XIcon className="size-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
)),
|
||||
)}
|
||||
<Button variant="ghost" size="xs" onClick={clearAll}>
|
||||
Clear all
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{visible.length === 0 ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>No matching models</CardTitle>
|
||||
<CardDescription>Try a different search or remove a filter.</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
) : (
|
||||
<Card className="py-0">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Model</TableHead>
|
||||
<TableHead>Selection</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead className="hidden lg:table-cell">Pinned</TableHead>
|
||||
<TableHead className="hidden md:table-cell">Downloaded</TableHead>
|
||||
<TableHead className="w-56">Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{visible.map((r) => {
|
||||
const job = openJobs.get(r.id);
|
||||
const base = r.baseModels[0];
|
||||
return (
|
||||
<TableRow key={r.id}>
|
||||
<TableCell className="whitespace-normal">
|
||||
<Link href={`/models/${r.id}`} className="font-medium hover:underline">
|
||||
{r.repoId}
|
||||
</Link>
|
||||
<div className="mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">
|
||||
{base && base !== r.repoId && <span>base {base}</span>}
|
||||
{r.architecture && <span>{r.architecture}</span>}
|
||||
{r.tags.map((t) => (
|
||||
<button
|
||||
key={t.id}
|
||||
type="button"
|
||||
onClick={() => !filters.tag.includes(t.name) && updateFilter("tag", [...filters.tag, t.name])}
|
||||
>
|
||||
<Badge variant="outline">{t.name}</Badge>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{r.quants.length > 0 ? r.quants.join(", ") : `${r.fileCount} file${r.fileCount === 1 ? "" : "s"}`}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(r.totalBytes)}</TableCell>
|
||||
<TableCell className="hidden lg:table-cell">
|
||||
<code className="font-mono text-xs" title={r.pinnedSha}>
|
||||
{r.trackedRevision}@{shortSha(r.pinnedSha)}
|
||||
</code>
|
||||
</TableCell>
|
||||
<TableCell className="hidden text-sm text-muted-foreground md:table-cell">
|
||||
<LocalTime value={r.downloadedAt} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{job ? (
|
||||
<Link href={`/jobs/${job.id}`} className="flex flex-col gap-1">
|
||||
<JobStateBadge job={job} />
|
||||
{job.state !== "queued" && <JobProgress job={job} compact />}
|
||||
</Link>
|
||||
) : (
|
||||
<ModelStatusBadge status={r.status} />
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,9 +4,12 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { modelFamilies } from "@/lib/hub/metadata";
|
||||
import { getModel } from "@/lib/library";
|
||||
import { modelTagList } from "@/lib/tags";
|
||||
import { ModelLive } from "./model-live";
|
||||
import { RemoveModelButton } from "./remove-model-button";
|
||||
import { TagEditor } from "./tag-editor";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -15,6 +18,7 @@ export default async function ModelPage({ params }: PageProps<"/models/[id]">) {
|
||||
const data = await getModel(id);
|
||||
if (!data) notFound();
|
||||
const { model, files } = data;
|
||||
const modelTags = await modelTagList(model.id);
|
||||
const selected = files.filter((f) => f.selected);
|
||||
const totalBytes = selected.reduce((s, f) => s + f.size, 0);
|
||||
|
||||
@@ -25,6 +29,7 @@ export default async function ModelPage({ params }: PageProps<"/models/[id]">) {
|
||||
<ModelStatusBadge status={model.status} />
|
||||
<div className="ml-auto">{model.status === "pending" && <RemoveModelButton id={model.id} />}</div>
|
||||
</div>
|
||||
<TagEditor modelId={model.id} tags={modelTags} />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@@ -43,6 +48,30 @@ export default async function ModelPage({ params }: PageProps<"/models/[id]">) {
|
||||
huggingface.co/{model.repoId}
|
||||
</a>
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Author</dt>
|
||||
<dd>{model.repoId.split("/")[0]}</dd>
|
||||
<dt className="text-muted-foreground">Family</dt>
|
||||
<dd>{modelFamilies(model.repoId, model.baseModels).join(", ")}</dd>
|
||||
<dt className="text-muted-foreground">Base model</dt>
|
||||
<dd className="flex flex-col">
|
||||
{(model.baseModels ?? []).length === 0
|
||||
? "–"
|
||||
: model.baseModels!.map((b) => (
|
||||
<a key={b} href={`https://huggingface.co/${b}`} target="_blank" rel="noreferrer" className="underline">
|
||||
{b}
|
||||
</a>
|
||||
))}
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Architecture</dt>
|
||||
<dd>{model.architecture ?? "–"}</dd>
|
||||
<dt className="text-muted-foreground">License</dt>
|
||||
<dd>{model.license ?? "–"}</dd>
|
||||
{(model.hubTags ?? []).length > 0 && (
|
||||
<>
|
||||
<dt className="text-muted-foreground">Hub tags</dt>
|
||||
<dd className="text-xs text-muted-foreground">{model.hubTags!.join(", ")}</dd>
|
||||
</>
|
||||
)}
|
||||
<dt className="text-muted-foreground">Tracked revision</dt>
|
||||
<dd className="font-mono">{model.trackedRevision}</dd>
|
||||
<dt className="text-muted-foreground">Pinned SHA</dt>
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
"use client";
|
||||
|
||||
import { XIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useId, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
|
||||
/** Add/remove user tags on a model; suggests existing tags. */
|
||||
export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) {
|
||||
const router = useRouter();
|
||||
const listId = useId();
|
||||
const [value, setValue] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [suggestions, setSuggestions] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/tags")
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((all: Tag[]) => setSuggestions(all.map((t) => t.name)))
|
||||
.catch(() => {});
|
||||
}, [tags]);
|
||||
|
||||
async function add(name: string) {
|
||||
if (!name.trim()) return;
|
||||
setBusy(true);
|
||||
const res = await fetch(`/api/models/${modelId}/tags`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
setBusy(false);
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
toast.error(body.error?.message ?? `Could not add tag (${res.status})`);
|
||||
return;
|
||||
}
|
||||
setValue("");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
async function remove(tag: Tag) {
|
||||
const res = await fetch(`/api/models/${modelId}/tags/${tag.id}`, { method: "DELETE" });
|
||||
if (!res.ok) toast.error(`Could not remove tag (${res.status})`);
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
const current = new Set(tags.map((t) => t.name.toLowerCase()));
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{tags.map((t) => (
|
||||
<Badge key={t.id} variant="secondary" className="gap-1">
|
||||
{t.name}
|
||||
<button type="button" aria-label={`Remove tag ${t.name}`} onClick={() => remove(t)}>
|
||||
<XIcon className="size-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
))}
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void add(value);
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
list={listId}
|
||||
placeholder="Add tag…"
|
||||
disabled={busy}
|
||||
maxLength={40}
|
||||
className="h-6 w-36 text-xs"
|
||||
aria-label="Add tag"
|
||||
/>
|
||||
<datalist id={listId}>
|
||||
{suggestions
|
||||
.filter((s) => !current.has(s.toLowerCase()))
|
||||
.map((s) => (
|
||||
<option key={s} value={s} />
|
||||
))}
|
||||
</datalist>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { listLibrary } from "@/lib/library";
|
||||
import { getWorkerStatus } from "@/lib/worker-status";
|
||||
import { AddModelPanel } from "./add-model-panel";
|
||||
import { LibraryTable } from "./library-table";
|
||||
import { LibraryView } from "./library-view";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -12,7 +12,7 @@ export default async function LibraryPage() {
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Opens by default while the library is empty. */}
|
||||
<AddModelPanel freeBytes={worker.online ? worker.modelsDirFreeBytes : null} defaultOpen={rows.length === 0} />
|
||||
{rows.length > 0 && <LibraryTable rows={rows} />}
|
||||
{rows.length > 0 && <LibraryView rows={rows} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { removeTag } from "@/lib/tags";
|
||||
|
||||
/** Detach a tag from a model. */
|
||||
export const DELETE = withAuth<RouteContext<"/api/models/[id]/tags/[tagId]">>(async (_req, { params }) => {
|
||||
const { id, tagId } = await params;
|
||||
await removeTag(id, tagId);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { addTag, TagError } from "@/lib/tags";
|
||||
|
||||
const Body = z.object({ name: z.string() });
|
||||
|
||||
/** Attach a tag to a model (creates the tag on first use). */
|
||||
export const POST = withAuth<RouteContext<"/api/models/[id]/tags">>(async (req, { params }) => {
|
||||
const { id } = await params;
|
||||
try {
|
||||
const { name } = Body.parse(await req.json());
|
||||
return NextResponse.json(await addTag(id, name), { status: 201 });
|
||||
} catch (err) {
|
||||
if (err instanceof TagError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { REPO_ID_RE, SHA_RE } from "@/lib/hub/client";
|
||||
import { queueDownload } from "@/lib/jobs";
|
||||
import { addModel, ModelError } from "@/lib/models";
|
||||
import { addTag, normalizeTagName, TagError } from "@/lib/tags";
|
||||
|
||||
const Body = z.object({
|
||||
repoId: z.string().regex(REPO_ID_RE),
|
||||
@@ -13,22 +14,25 @@ const Body = z.object({
|
||||
include: z.array(z.string().min(1).max(1024)).max(10_000),
|
||||
exclude: z.array(z.string().min(1).max(1024)).max(1_000),
|
||||
download: z.boolean().default(true),
|
||||
tags: z.array(z.string()).max(50).default([]),
|
||||
});
|
||||
|
||||
/** Add a model to the library, pinned to the SHA the user reviewed, and queue its download. */
|
||||
export const POST = withAuth(async (req) => {
|
||||
try {
|
||||
const body = Body.parse(await req.json());
|
||||
body.tags.forEach(normalizeTagName); // validate before anything is written
|
||||
const { id } = await addModel({
|
||||
repoId: body.repoId,
|
||||
revision: body.revision,
|
||||
sha: body.sha,
|
||||
rule: { include: body.include, exclude: body.exclude },
|
||||
});
|
||||
for (const tag of body.tags) await addTag(id, tag);
|
||||
const job = body.download ? await queueDownload(id) : null;
|
||||
return NextResponse.json({ id, jobId: job?.jobId ?? null }, { status: 201 });
|
||||
} catch (err) {
|
||||
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
|
||||
if (err instanceof ModelError || err instanceof TagError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { listTags } from "@/lib/tags";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/** All user tags with usage counts. */
|
||||
export const GET = withAuth(async () => NextResponse.json(await listTags()));
|
||||
+1
-1
@@ -9,7 +9,7 @@ const geist = Geist({ subsets: ["latin"], variable: "--font-sans" });
|
||||
const geistMono = Geist_Mono({ subsets: ["latin"], variable: "--font-mono" });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Model Manager",
|
||||
title: { default: "Kaname", template: "%s · Kaname" },
|
||||
description: "Download and manage local LLMs from Hugging Face",
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export default async function LoginPage({ searchParams }: PageProps<"/login">) {
|
||||
<main className="flex min-h-screen items-center justify-center p-4">
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">Model Manager</CardTitle>
|
||||
<CardTitle className="text-lg">Kaname</CardTitle>
|
||||
<CardDescription>Sign in to manage local models.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
|
||||
Reference in new issue
Block a user