Download more, file labels, split-file grouping, settings for labels and tags
- Files tab: "Download more" adds files to a model's selection and queues them - Colored file labels (Model, MTP, Vision/mmproj, imatrix, Config, …) - Split GGUF/safetensors parts shown and selected as one entry everywhere - Settings page with a Labels section: file label names/colors, tag rename/recolor/delete; new settings table and tags.color - Quants only count model weights Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5211ec9064
commit
df18415e02
34 files changed
+2256
-132
No files matched your search
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronDownIcon } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { DOT_CLASS, LABEL_COLORS, type LabelColor } from "@/lib/colors";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** Dropdown of the named label colors; optional "Automatic" entry (value null). */
|
||||
export function ColorPicker({
|
||||
value,
|
||||
onChange,
|
||||
allowAuto = false,
|
||||
autoColor,
|
||||
}: {
|
||||
value: LabelColor | null;
|
||||
onChange: (color: LabelColor | null) => void;
|
||||
allowAuto?: boolean;
|
||||
/** Color shown for the automatic option. */
|
||||
autoColor?: LabelColor;
|
||||
}) {
|
||||
const shown = value ?? autoColor ?? "gray";
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger render={<Button variant="outline" size="sm" className="w-32 justify-start" />}>
|
||||
<span className={cn("size-3 rounded-full", DOT_CLASS[shown])} />
|
||||
<span className="flex-1 text-left capitalize">{value ?? "Automatic"}</span>
|
||||
<ChevronDownIcon className="opacity-60" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="max-h-72 min-w-40">
|
||||
{allowAuto && (
|
||||
<DropdownMenuItem onClick={() => onChange(null)}>
|
||||
<span className={cn("size-3 rounded-full", DOT_CLASS[autoColor ?? "gray"])} />
|
||||
Automatic
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{LABEL_COLORS.map((c) => (
|
||||
<DropdownMenuItem key={c} onClick={() => onChange(c)}>
|
||||
<span className={cn("size-3 rounded-full", DOT_CLASS[c])} />
|
||||
<span className="capitalize">{c}</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
"use client";
|
||||
|
||||
import { RotateCcwIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { BADGE_CLASS } from "@/lib/colors";
|
||||
import { FILE_ROLE_ORDER, FILE_ROLES, type FileRoleStyles } from "@/lib/file-roles";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ColorPicker } from "./color-picker";
|
||||
|
||||
/** Edit the label text and color shown in front of file names. */
|
||||
export function FileLabelSettings({ initial }: { initial: FileRoleStyles }) {
|
||||
const router = useRouter();
|
||||
const [styles, setStyles] = useState(initial);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const dirty = JSON.stringify(styles) !== JSON.stringify(initial);
|
||||
|
||||
function update(role: keyof FileRoleStyles, patch: Partial<FileRoleStyles[keyof FileRoleStyles]>) {
|
||||
setStyles((prev) => ({ ...prev, [role]: { ...prev[role], ...patch } }));
|
||||
}
|
||||
|
||||
async function save(next = styles) {
|
||||
setSaving(true);
|
||||
try {
|
||||
const res = await fetch("/api/settings/labels", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ fileRoles: next }),
|
||||
});
|
||||
const body = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast.error(body.error?.message ?? `Could not save (${res.status})`);
|
||||
return;
|
||||
}
|
||||
setStyles(body.fileRoles);
|
||||
toast.success("File labels saved");
|
||||
router.refresh();
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const defaults = Object.fromEntries(
|
||||
FILE_ROLE_ORDER.map((r) => [r, { label: FILE_ROLES[r].label, color: FILE_ROLES[r].color }]),
|
||||
) as FileRoleStyles;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>File labels</CardTitle>
|
||||
<CardDescription>
|
||||
Shown in front of file names (Files tab, Add model). Kaname detects the type from the file name; here you
|
||||
choose how each type is labeled and colored.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="divide-y rounded-lg ring-1 ring-foreground/10">
|
||||
{FILE_ROLE_ORDER.map((role) => {
|
||||
const s = styles[role];
|
||||
const changed = s.label !== defaults[role].label || s.color !== defaults[role].color;
|
||||
return (
|
||||
<div key={role} className="grid grid-cols-[6rem_minmax(0,1fr)] items-center gap-x-4 gap-y-2 px-4 py-3 sm:grid-cols-[6rem_minmax(0,1fr)_10rem_8rem_2rem]">
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex h-5 justify-self-start rounded-md border px-1.5 text-[11px] leading-[18px] font-medium",
|
||||
BADGE_CLASS[s.color],
|
||||
)}
|
||||
>
|
||||
{s.label || "…"}
|
||||
</span>
|
||||
<span className="min-w-0 text-xs text-muted-foreground">{FILE_ROLES[role].description}</span>
|
||||
<Input
|
||||
value={s.label}
|
||||
maxLength={24}
|
||||
onChange={(e) => update(role, { label: e.target.value })}
|
||||
aria-label={`Label for ${FILE_ROLES[role].label}`}
|
||||
className="h-8"
|
||||
/>
|
||||
<ColorPicker value={s.color} onChange={(c) => c && update(role, { color: c })} />
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
disabled={!changed}
|
||||
title="Reset to default"
|
||||
aria-label="Reset to default"
|
||||
onClick={() => update(role, defaults[role])}
|
||||
>
|
||||
<RotateCcwIcon />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
<Button variant="ghost" onClick={() => setStyles(initial)} disabled={!dirty || saving}>
|
||||
Discard changes
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => save(defaults)} disabled={saving}>
|
||||
Reset all to defaults
|
||||
</Button>
|
||||
<Button onClick={() => save()} disabled={!dirty || saving}>
|
||||
{saving ? "Saving…" : "Save"}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getFileRoleStyles } from "@/lib/settings";
|
||||
import { listTags } from "@/lib/tags";
|
||||
import { FileLabelSettings } from "./file-label-settings";
|
||||
import { TagSettings } from "./tag-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const metadata: Metadata = { title: "Labels · Settings" };
|
||||
|
||||
export default async function LabelSettingsPage() {
|
||||
const [fileRoles, tags] = await Promise.all([getFileRoleStyles(), listTags()]);
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<FileLabelSettings initial={fileRoles} />
|
||||
<TagSettings tags={tags} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
"use client";
|
||||
|
||||
import { Trash2Icon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { TagBadge } from "@/components/tag-badge";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { autoTagColor, isLabelColor } from "@/lib/colors";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
import { ColorPicker } from "./color-picker";
|
||||
|
||||
/** Rename, recolor or delete user tags. Changes save immediately. */
|
||||
export function TagSettings({ tags }: { tags: (Tag & { count: number })[] }) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Tags</CardTitle>
|
||||
<CardDescription>
|
||||
Your own tags (added on a model page or when adding a model). Tags without a color get an automatic one.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{tags.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No tags yet.</p>
|
||||
) : (
|
||||
<div className="divide-y rounded-lg ring-1 ring-foreground/10">
|
||||
{tags.map((t) => (
|
||||
<TagRow key={t.id} tag={t} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function TagRow({ tag }: { tag: Tag & { count: number } }) {
|
||||
const router = useRouter();
|
||||
const [name, setName] = useState(tag.name);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function patch(body: { name?: string; color?: string | null }) {
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await fetch(`/api/tags/${tag.id}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const json = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast.error(json.error?.message ?? `Could not save (${res.status})`);
|
||||
setName(tag.name);
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
const res = await fetch(`/api/tags/${tag.id}`, { method: "DELETE" });
|
||||
if (!res.ok) toast.error(`Could not delete (${res.status})`);
|
||||
else toast.success(`Tag "${tag.name}" deleted`);
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
const color = isLabelColor(tag.color) ? tag.color : null;
|
||||
return (
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-2 px-4 py-3 sm:grid-cols-[8rem_minmax(0,1fr)_8rem_6rem_2rem]">
|
||||
<TagBadge name={name || tag.name} color={tag.color} className="justify-self-start" />
|
||||
<Input
|
||||
value={name}
|
||||
maxLength={40}
|
||||
disabled={busy}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
onBlur={() => name.trim() && name !== tag.name && patch({ name })}
|
||||
onKeyDown={(e) => e.key === "Enter" && (e.target as HTMLInputElement).blur()}
|
||||
aria-label={`Rename tag ${tag.name}`}
|
||||
className="h-8"
|
||||
/>
|
||||
<ColorPicker value={color} onChange={(c) => patch({ color: c })} allowAuto autoColor={autoTagColor(tag.name)} />
|
||||
<span className="text-xs text-muted-foreground tabular-nums">
|
||||
{tag.count} model{tag.count === 1 ? "" : "s"}
|
||||
</span>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger render={<Button variant="ghost" size="icon-sm" aria-label={`Delete tag ${tag.name}`} />}>
|
||||
<Trash2Icon />
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete tag “{tag.name}”?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
It is removed from {tag.count} model{tag.count === 1 ? "" : "s"}. The models themselves are not touched.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" onClick={remove}>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TagsIcon } from "lucide-react";
|
||||
import { SettingsNav } from "./settings-nav";
|
||||
|
||||
const SECTIONS = [{ href: "/settings/labels", label: "Labels", icon: <TagsIcon className="size-4" /> }];
|
||||
|
||||
export default function SettingsLayout({ children }: LayoutProps<"/settings">) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<h1 className="text-xl font-semibold">Settings</h1>
|
||||
<div className="grid items-start gap-4 md:grid-cols-[200px_minmax(0,1fr)]">
|
||||
<SettingsNav sections={SECTIONS} />
|
||||
<div className="min-w-0">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function SettingsPage() {
|
||||
redirect("/settings/labels");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function SettingsNav({ sections }: { sections: { href: string; label: string; icon: React.ReactNode }[] }) {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<nav className="flex gap-1 rounded-xl bg-card p-2 ring-1 ring-foreground/10 md:flex-col">
|
||||
{sections.map((s) => (
|
||||
<Link
|
||||
key={s.href}
|
||||
href={s.href}
|
||||
className={cn(
|
||||
"flex items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors",
|
||||
pathname === s.href ? "bg-muted font-medium text-foreground" : "text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{s.icon}
|
||||
{s.label}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user