Compare commits

..
4 Commits
Author SHA1 Message Date
Pascal LinxweilerandClaude Opus 5.5 29e6893a17 Release 0.21.0: reload local models
Release / release (push) Successful in 2m57s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 00:55:08 +01:00
Pascal LinxweilerandClaude Opus 5.5 80d71a1bc9 Local models: Reload button, scans keep their files in step
Files tab → Reload asks the worker for a scan and waits until it has
finished. Every scan now syncs local models' file lists with their
folders (new, resized, removed files; README) and settles the status.
Skipped while a job runs, and for a folder that is gone or too big.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 00:55:03 +01:00
Pascal LinxweilerandClaude Opus 5.5 f862717158 Release 0.20.0: README.md as the model card of local models
Release / release (push) Successful in 2m52s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 00:27:26 +01:00
Pascal LinxweilerandClaude Opus 5.5 d27e79bba0 Local models: the folder's README.md is the model card
The worker reads README.md when it scans the models folder (the web
app can't see it) and stores it on the folder and, after import, on
the model; every scan refreshes it for local models. Relative images
and links are dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 00:27:17 +01:00
17 changed files with 1880 additions and 30 deletions

No files matched your search

+16
View File
@@ -6,6 +6,22 @@ step 1 (Hugging Face downloader) is released as a minor version.
## [Unreleased]
## [0.21.0] - 2026-11-08
### Added
- **Reload a local model** (Files tab → **Reload**): reads the folder again, so files you added,
changed or removed and README.md edits show up right away. Every scan of the models folder (on its
schedule, or Rescan) now also brings local models' file lists up to date, not only their README.
## [0.20.0] - 2026-11-08
### Added
- **Local models have a model card again:** the folder's `README.md`. The worker reads it when it
scans the models folder (the web app can't see that folder), so edits show up after the next
scan. Relative images and links in it are left out.
## [0.19.0] - 2026-11-08
### Added
+2
View File
@@ -0,0 +1,2 @@
ALTER TABLE `local_folders` ADD `readme` text;--> statement-breakpoint
ALTER TABLE `models` ADD `local_readme` text;
File diff suppressed because it is too large. Load diff
+7
View File
@@ -183,6 +183,13 @@
"when": 1794093022425,
"tag": "0025_local_models",
"breakpoints": true
},
{
"idx": 26,
"version": "6",
"when": 1794093954553,
"tag": "0026_local_readme",
"breakpoints": true
}
]
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "kaname",
"version": "0.19.0",
"version": "0.21.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "kaname",
"version": "0.19.0",
"version": "0.21.0",
"dependencies": {
"@base-ui/react": "^1.8.0",
"@libsql/client": "^0.18.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "kaname",
"version": "0.19.0",
"version": "0.21.0",
"private": true,
"scripts": {
"dev": "concurrently -k -n web,worker -c blue,magenta \"npm:dev:web\" \"npm:dev:worker\"",
+6 -1
View File
@@ -13,6 +13,7 @@ import { useRecommended } from "@/hooks/use-recommended";
import { groupSplitFiles } from "@/lib/file-groups";
import { formatBytes, percent, shortSha } from "@/lib/format";
import { quantGroup } from "@/lib/selection";
import { ReloadButton } from "./reload-button";
type Candidate = { path: string; size: number };
@@ -32,6 +33,7 @@ export function FilesHeader({
freeBytes,
busy,
hubMissing,
local = false,
}: {
modelId: string;
sha: string;
@@ -47,6 +49,8 @@ export function FilesHeader({
busy: boolean;
/** The repo or pinned commit is gone from the Hub; nothing more can be downloaded. */
hubMissing: boolean;
/** A local model: "Reload" reads the folder again instead of "Download more". */
local?: boolean;
}) {
const router = useRouter();
const [open, setOpen] = useState(false);
@@ -128,7 +132,8 @@ export function FilesHeader({
<span className="text-muted-foreground">
{localCount} of {selectedCount} on disk · {formatBytes(localBytes)}
</span>
{candidates.length > 0 && !hubMissing && (
{local && <ReloadButton />}
{!local && candidates.length > 0 && !hubMissing && (
<Button
size="sm"
variant={open ? "outline" : "default"}
+1
View File
@@ -165,6 +165,7 @@ export function FilesTab({
freeBytes={freeBytes}
busy={busy}
hubMissing={hubMissing}
local={local}
/>
<ul className="divide-y">
+30 -3
View File
@@ -57,6 +57,29 @@ export async function ModelCardSection({ repoId, sha }: { repoId: string; sha: s
);
}
/**
* The Model card tab of a local model: the folder's README.md, as the worker last read it. Relative
* images and links are dropped: the web app can't serve files from the models folder.
*/
export function LocalModelCardSection({ markdown, localPath }: { markdown: string | null; localPath: string }) {
if (!markdown) {
return (
<p className="text-sm text-muted-foreground">
This folder has no README.md. Add one to <code className="font-mono">{localPath}</code> and it shows up here after the
next scan of the models folder, or right away with Reload on the Files tab.
</p>
);
}
return (
<>
<ModelCard markdown={markdown} />
<p className="mt-6 text-right text-xs text-muted-foreground">
README.md in <code className="font-mono">{localPath}</code>, as of the last scan
</p>
</>
);
}
export function ModelCardSkeleton() {
return (
<div className="flex flex-col gap-3" aria-busy="true" aria-label="Loading the model card">
@@ -71,9 +94,12 @@ export function ModelCardSkeleton() {
);
}
/** Renders a repo's README like the Hub: relative links/images point at the pinned commit. */
export function ModelCard({ markdown, repoId, sha }: { markdown: string; repoId: string; sha: string }) {
const base = `https://huggingface.co/${repoId}`;
/**
* Renders a repo's README like the Hub: relative links/images point at the pinned commit. Without a
* repo (a local model's README) they are dropped.
*/
export function ModelCard({ markdown, repoId, sha }: { markdown: string; repoId?: string; sha?: string }) {
const base = repoId ? `https://huggingface.co/${repoId}` : null;
return (
<article className="prose prose-sm max-w-none dark:prose-invert prose-headings:scroll-mt-20 prose-img:inline-block prose-img:my-1 prose-pre:bg-muted prose-pre:text-foreground prose-table:text-xs">
<ReactMarkdown
@@ -83,6 +109,7 @@ export function ModelCard({ markdown, repoId, sha }: { markdown: string; repoId:
const safe = defaultUrlTransform(url);
if (!safe || safe.startsWith("#") || /^[a-z][a-z0-9+.-]*:|^\/\//i.test(safe)) return safe;
// Relative path inside the repo: images from /resolve, links to /blob, both at the pinned SHA.
if (!base) return null;
const path = safe.replace(/^\.?\//, "");
return key === "src" ? `${base}/resolve/${sha}/${path}` : `${base}/blob/${sha}/${path}`;
}}
+11 -8
View File
@@ -38,7 +38,7 @@ import { DownloadCard } from "./download-card";
import { FilesTab } from "./files-tab";
import { HubCheckButton } from "./hub-check";
import { JobsTab } from "./jobs-tab";
import { ModelCardSection, ModelCardSkeleton } from "./model-card";
import { LocalModelCardSection, ModelCardSection, ModelCardSkeleton } from "./model-card";
import { DeleteModelButton } from "./delete-model-button";
import { TagEditor } from "./tag-editor";
import { UpdateBanner } from "./update-banner";
@@ -93,10 +93,9 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
const { model, files } = data;
if (model.repoId !== `${org}/${repo}`) redirect(`/${model.repoId}`); // canonical spelling
// A local model has no Hub repo: no model card, commit, Hub checks or model tree.
// A local model has no Hub repo: no commit, Hub checks or model tree; its README is the model card.
const local = model.source === "local";
const tabs = local ? TABS.filter((t) => t.id !== "card") : TABS;
const tab: TabId = tabs.some((t) => t.id === sp.tab) ? (sp.tab as TabId) : "files";
const tab: TabId = TABS.some((t) => t.id === sp.tab) ? (sp.tab as TabId) : "files";
const [author, name] = model.repoId.split("/");
const hub = `https://huggingface.co/${model.repoId}`;
const baseModels = model.baseModels ?? [];
@@ -237,7 +236,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
<Panel className="min-w-0 overflow-hidden">
<div className="flex flex-wrap items-center justify-between gap-2 border-b px-4 py-3">
<nav className="inline-flex rounded-lg bg-muted p-1">
{tabs.map((t) => (
{TABS.map((t) => (
<Link
key={t.id}
href={tabHref(t.id)}
@@ -265,9 +264,13 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
{tab === "card" && (
<div className="p-5 sm:p-6">
<Suspense fallback={<ModelCardSkeleton />}>
<ModelCardSection repoId={model.repoId} sha={model.pinnedSha} />
</Suspense>
{local ? (
<LocalModelCardSection markdown={model.localReadme} localPath={model.localPath} />
) : (
<Suspense fallback={<ModelCardSkeleton />}>
<ModelCardSection repoId={model.repoId} sha={model.pinnedSha} />
</Suspense>
)}
</div>
)}
{tab === "files" && (
@@ -0,0 +1,54 @@
"use client";
import { RefreshCwIcon } from "lucide-react";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
/** The worker picks a scan request up with its next heartbeat (every 5 s); a big models folder takes longer. */
const TIMEOUT_MS = 90_000;
const POLL_MS = 1_500;
/**
* Local models: read the folder again (files and README). Asks the worker for a scan of the models
* folder and waits until it has finished, then reloads the page.
*/
export function ReloadButton() {
const router = useRouter();
const [busy, setBusy] = useState(false);
async function reload() {
setBusy(true);
try {
const res = await fetch("/api/local-folders/scan", { method: "POST" });
const body = await res.json().catch(() => ({}));
if (!res.ok || typeof body.requestedAt !== "number") {
toast.error(body.error?.message ?? `Could not start a scan (${res.status})`);
return;
}
const deadline = Date.now() + TIMEOUT_MS;
while (Date.now() < deadline) {
await new Promise((r) => setTimeout(r, POLL_MS));
const state = await fetch("/api/local-folders/scan", { cache: "no-store" })
.then((r) => (r.ok ? r.json() : null))
.catch(() => null);
if (state?.lastScanAt != null && state.lastScanAt >= body.requestedAt) {
router.refresh();
return;
}
}
toast.error("The worker hasn't scanned the folder yet. Is it running?");
} finally {
setBusy(false);
}
}
return (
<Button size="sm" variant="outline" onClick={() => void reload()} disabled={busy} title="Read the folder again: files and README.md">
<RefreshCwIcon className={cn(busy && "animate-spin")} />
{busy ? "Reloading…" : "Reload"}
</Button>
);
}
+11 -4
View File
@@ -1,9 +1,16 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { requestFolderScan } from "@/lib/local-folders";
import { getScanState, requestFolderScan } from "@/lib/local-folders";
/** Ask the worker to rescan the models folder for importable folders. */
export const dynamic = "force-dynamic";
/** Ask the worker to rescan the models folder (importable folders, and local models' files). */
export const POST = withAuth(async () => {
await requestFolderScan();
return new NextResponse(null, { status: 202 });
const requestedAt = await requestFolderScan();
return NextResponse.json({ requestedAt: requestedAt.getTime() }, { status: 202 });
});
/** When the worker last finished a scan, so a client can wait for the one it asked for. */
export const GET = withAuth(async () => {
return NextResponse.json(await getScanState());
});
+4
View File
@@ -94,6 +94,8 @@ export const models = sqliteTable(
source: text("source", { enum: MODEL_SOURCES }).notNull().default("hub"),
trackedRevision: text("tracked_revision").notNull().default("main"),
pinnedSha: text("pinned_sha").notNull(), // "" for local models
/** Local models: the folder's README.md, read by the worker (the web app can't see MODELS_DIR). */
localReadme: text("local_readme"),
/** Relative to MODELS_DIR, e.g. "unsloth/Qwen3-27B-GGUF". */
localPath: text("local_path").notNull(),
/**
@@ -334,6 +336,8 @@ export const localFolders = sqliteTable("local_folders", {
totalBytes: integer("total_bytes").notNull(),
/** Commit from hf's download metadata, if the folder was written by `hf download`. */
commit: text("commit"),
/** The folder's README.md (capped), so an import as a local model has a model card. */
readme: text("readme"),
/** When a scan last wrote this folder (found it, or found it changed). */
scannedAt: ts("scanned_at").notNull(),
});
+10 -2
View File
@@ -30,6 +30,14 @@ export async function localFolderExists(path: string): Promise<boolean> {
}
/** Ask the worker to scan MODELS_DIR now (it picks this up with its next heartbeat). */
export async function requestFolderScan(): Promise<void> {
await db().update(workerState).set({ scanRequestedAt: new Date() }).where(eq(workerState.id, "worker"));
export async function requestFolderScan(): Promise<Date> {
const now = new Date();
await db().update(workerState).set({ scanRequestedAt: now }).where(eq(workerState.id, "worker"));
return now;
}
/** When the last scan finished (ms since epoch), or null if the worker never scanned. */
export async function getScanState(): Promise<{ lastScanAt: number | null }> {
const row = await db().query.workerState.findFirst({ columns: { lastScanAt: true }, where: eq(workerState.id, "worker") });
return { lastScanAt: row?.lastScanAt?.getTime() ?? null };
}
+1
View File
@@ -124,6 +124,7 @@ export async function addLocalModel(input: { localPath: string }): Promise<{ id:
pinnedSha: "",
localPath: folder.path,
status: "ready",
localReadme: folder.readme,
// Nothing to fetch from the Hub.
metadataFetchedAt: now,
}),
+72 -1
View File
@@ -69,9 +69,80 @@ describe("models folder scan", () => {
it("compares the file list, not only the counts", () => {
const at = new Date();
const found = { path: "o/m", files: [{ path: "b.gguf", size: 2 }], fileCount: 1, totalBytes: 2, commit: null, scannedAt: at };
const same = { path: "o/m", filesJson: JSON.stringify(found.files), fileCount: 1, totalBytes: 2, commit: null };
const same = { path: "o/m", filesJson: JSON.stringify(found.files), fileCount: 1, totalBytes: 2, commit: null, readme: null };
assert.deepEqual(scan.folderChanges([same], [found]), { insert: [], update: [], remove: [] });
const renamed = { ...same, filesJson: JSON.stringify([{ path: "a.gguf", size: 2 }]) };
assert.deepEqual(scan.folderChanges([renamed], [found]).update, [found]);
});
it("writes a folder again when its README changed", () => {
const at = new Date();
const found = { path: "o/m", files: [{ path: "README.md", size: 3 }], fileCount: 1, totalBytes: 3, commit: null, readme: "new", scannedAt: at };
const stored = { path: "o/m", filesJson: JSON.stringify(found.files), fileCount: 1, totalBytes: 3, commit: null, readme: "old" };
assert.deepEqual(scan.folderChanges([stored], [found]).update, [found]);
});
it("reads README.md in any case, and only at the top level", async () => {
const folder = join(dir, "readme-test"); // outside MODELS_DIR: no other test scans it
put(join(folder, "sub", "README.md"), 1);
assert.equal(await scan.readReadme(folder), null);
writeFileSync(join(folder, "ReadMe.md"), "# Hello\n");
assert.equal(await scan.readReadme(folder), "# Hello\n");
});
it("diffs a local model's files against its folder", () => {
const stored = [
{ id: "1", path: "keep.gguf", size: 5, state: "present" },
{ id: "2", path: "grown.gguf", size: 5, state: "present" },
{ id: "3", path: "back.json", size: 2, state: "missing" },
{ id: "4", path: "gone.json", size: 2, state: "present" },
];
const found = [
{ path: "keep.gguf", size: 5 },
{ path: "grown.gguf", size: 9 },
{ path: "back.json", size: 2 },
{ path: "new.md", size: 1 },
];
assert.deepEqual(scan.localFileChanges(stored, found), {
insert: [{ path: "new.md", size: 1 }],
update: [
{ id: "2", size: 9 },
{ id: "3", size: 2 },
],
remove: ["4"],
});
});
it("keeps a local model in step with its folder", async () => {
const { eq } = await import("drizzle-orm");
const d = D.db();
const folder = join(modelsDir, "mine", "local");
put(join(folder, "model.gguf"), 4);
put(join(folder, "old.json"), 2);
await d.insert(S.models).values({ id: "local1", repoId: "mine/local", source: "local", trackedRevision: "", pinnedSha: "", localPath: "mine/local", status: "ready" });
await d.insert(S.modelFiles).values([
{ modelId: "local1", path: "model.gguf", size: 4, selected: true, state: "present" },
{ modelId: "local1", path: "old.json", size: 2, selected: true, state: "present" },
]);
rmSync(join(folder, "old.json"));
put(join(folder, "model.gguf"), 6);
put(join(folder, "extra", "new.bin"), 3);
writeFileSync(join(folder, "README.md"), "# Mine\n");
await scan.scanModelsDir(modelsDir);
const files = await d.select().from(S.modelFiles).where(eq(S.modelFiles.modelId, "local1"));
assert.deepEqual(
files.map((f) => [f.path, f.size, f.state, f.selected]).sort(),
[
["README.md", 7, "present", true],
["extra/new.bin", 3, "present", true],
["model.gguf", 6, "present", true],
],
);
const model = await d.query.models.findFirst({ where: eq(S.models.id, "local1") });
assert.equal(model?.localReadme, "# Mine\n");
assert.equal(model?.status, "ready");
assert.equal((await stored())["mine/local"], undefined, "a model's folder is no import candidate");
});
});
+103 -8
View File
@@ -1,13 +1,19 @@
// Finds model folders in MODELS_DIR that aren't in the library, so they can be imported.
// Finds model folders in MODELS_DIR that aren't in the library, so they can be imported, and keeps
// local models (folders without a Hub repo) in step with their folder: files and README.
// Only the `<org>/<name>` layout is recognized (what Kaname and `hf download --local-dir` write).
// Read-only: nothing on disk is changed.
import { readdir, readFile, stat } from "node:fs/promises";
import { join, relative, sep } from "node:path";
import { eq, inArray, sql } from "drizzle-orm";
import { and, eq, inArray, sql } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { localFolders, models } from "@/lib/db/schema";
import { ACTIVE_JOB_STATES, jobFiles, jobs, localFolders, modelFiles, models } from "@/lib/db/schema";
import { HF_CACHE_DIR } from "./hf-layout";
import { log } from "./log";
import { settleModelStatus } from "./model-status";
/** Longer READMEs are cut off here (it's stored in the database). */
const MAX_README_BYTES = 512 * 1024;
/** Stop listing a folder's files after this many (the count stays exact). */
const MAX_LISTED_FILES = 5_000;
@@ -66,8 +72,88 @@ async function hfCommit(folder: string): Promise<string | null> {
return null;
}
/** The folder's top-level README.md (any case), capped; null if there is none. */
export async function readReadme(folder: string): Promise<string | null> {
let entries;
try {
entries = await readdir(folder, { withFileTypes: true });
} catch {
return null;
}
const file = entries.find((e) => e.isFile() && e.name.toLowerCase() === "readme.md");
if (!file) return null;
const buf = await readFile(join(folder, file.name)).catch(() => null);
if (!buf) return null;
// Cut at a line break so a multi-byte character or a Markdown construct isn't split mid-way.
const text = buf.subarray(0, MAX_README_BYTES).toString("utf8");
return buf.length > MAX_README_BYTES ? text.slice(0, text.lastIndexOf("\n") + 1) : text;
}
type StoredFile = { id: string; path: string; size: number; state: string };
/**
* What to write so a local model's files match its folder: new files, files whose size changed or
* that were missing and are back (`update`), and the ids of files that are gone.
*/
export function localFileChanges(stored: StoredFile[], found: { path: string; size: number }[]) {
const before = new Map(stored.map((s) => [s.path, s]));
const insert: { path: string; size: number }[] = [];
const update: { id: string; size: number }[] = [];
for (const f of found) {
const s = before.get(f.path);
if (!s) insert.push(f);
else if (s.size !== f.size || (s.state !== "present" && s.state !== "verified")) update.push({ id: s.id, size: f.size });
}
const seen = new Set(found.map((f) => f.path));
const remove = stored.filter((s) => !seen.has(s.path)).map((s) => s.id);
return { insert, update, remove };
}
/**
* Bring a local model's file list and README in line with its folder. Skipped while a job runs for
* it, and for a folder that is gone or lists more files than are kept (nothing is dropped then).
*/
async function syncLocalModel(modelsDir: string, m: { id: string; p: string; readme: string | null }): Promise<void> {
const d = db();
const folder = join(modelsDir, m.p);
const readme = await readReadme(folder);
if (readme !== m.readme) await d.update(models).set({ localReadme: readme }).where(eq(models.id, m.id));
const open = await d.query.jobs.findFirst({
columns: { id: true },
where: and(eq(jobs.modelId, m.id), inArray(jobs.state, ["queued", ...ACTIVE_JOB_STATES])),
});
if (open) return;
const files: { path: string; size: number }[] = [];
const totals = { count: 0, bytes: 0 };
await walk(folder, folder, files, totals);
if (totals.count === 0 || totals.count > files.length) return;
const stored = await d
.select({ id: modelFiles.id, path: modelFiles.path, size: modelFiles.size, state: modelFiles.state })
.from(modelFiles)
.where(eq(modelFiles.modelId, m.id));
const { insert, update, remove } = localFileChanges(stored, files);
if (insert.length + update.length + remove.length === 0) return;
const now = new Date();
const writes = [
...(remove.length
? [d.delete(jobFiles).where(inArray(jobFiles.modelFileId, remove)), d.delete(modelFiles).where(inArray(modelFiles.id, remove))]
: []),
...update.map((u) => d.update(modelFiles).set({ size: u.size, state: "present", checkedAt: now }).where(eq(modelFiles.id, u.id))),
// In chunks: SQLite caps the number of values in one statement.
...Array.from({ length: Math.ceil(insert.length / 500) }, (_, i) =>
d.insert(modelFiles).values(
insert.slice(i * 500, (i + 1) * 500).map((f) => ({ modelId: m.id, path: f.path, size: f.size, selected: true, state: "present" as const, checkedAt: now })),
),
),
];
await d.batch(writes as [(typeof writes)[number], ...typeof writes]);
await settleModelStatus(m.id);
}
/** A stored folder, its file list as the JSON text it is stored as (compared, never parsed). */
export type StoredFolder = { path: string; filesJson: string; fileCount: number; totalBytes: number; commit: string | null };
export type StoredFolder = { path: string; filesJson: string; fileCount: number; totalBytes: number; commit: string | null; readme: string | null };
/**
* What to write so `local_folders` matches a scan: new folders, changed ones, and the paths of
@@ -81,16 +167,24 @@ export function folderChanges(stored: StoredFolder[], found: FoundFolder[]) {
for (const f of found) {
const s = before.get(f.path);
if (!s) insert.push(f);
else if (s.fileCount !== f.fileCount || s.totalBytes !== f.totalBytes || s.commit !== (f.commit ?? null) || s.filesJson !== JSON.stringify(f.files)) update.push(f);
else if (s.fileCount !== f.fileCount || s.totalBytes !== f.totalBytes || s.commit !== (f.commit ?? null) || s.readme !== (f.readme ?? null) || s.filesJson !== JSON.stringify(f.files)) update.push(f);
}
const seen = new Set(found.map((f) => f.path));
const remove = stored.filter((s) => !seen.has(s.path)).map((s) => s.path);
return { insert, update, remove };
}
/** Scan MODELS_DIR and update the `local_folders` table to the folders no model uses. */
/**
* Scan MODELS_DIR and update the `local_folders` table to the folders no model uses. Also brings
* local models in line with their folders (files and README).
*/
export async function scanModelsDir(modelsDir: string): Promise<number> {
const used = new Set((await db().select({ p: models.localPath }).from(models)).map((m) => m.p));
const inLibrary = await db().select({ id: models.id, p: models.localPath, source: models.source, readme: models.localReadme }).from(models);
const used = new Set(inLibrary.map((m) => m.p));
for (const m of inLibrary.filter((x) => x.source === "local")) {
// One model's problem doesn't stop the scan of the others.
await syncLocalModel(modelsDir, m).catch((err) => log.error(`syncing local model ${m.p} failed`, err));
}
const found: FoundFolder[] = [];
const now = new Date();
for (const org of await subdirs(modelsDir)) {
@@ -103,7 +197,7 @@ export async function scanModelsDir(modelsDir: string): Promise<number> {
await walk(folder, folder, files, totals);
if (totals.count === 0) continue;
files.sort((a, b) => a.path.localeCompare(b.path));
found.push({ path, files, fileCount: totals.count, totalBytes: totals.bytes, commit: await hfCommit(folder), scannedAt: now });
found.push({ path, files, fileCount: totals.count, totalBytes: totals.bytes, commit: await hfCommit(folder), readme: await readReadme(folder), scannedAt: now });
}
}
const d = db();
@@ -115,6 +209,7 @@ export async function scanModelsDir(modelsDir: string): Promise<number> {
fileCount: localFolders.fileCount,
totalBytes: localFolders.totalBytes,
commit: localFolders.commit,
readme: localFolders.readme,
})
.from(localFolders);
const { insert, update, remove } = folderChanges(stored, found);