From ff86e52126e951269b1ae9e8c4d1e508bbaa382f Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Mon, 28 Sep 2026 22:11:38 +0200 Subject: [PATCH] Open a repository beneath its row in the mirror's listing Clicking a repository in the explorer shows its card and files in a row beneath it, fetched from /admin/mirror/repo, and a second click closes it; the list stays where it was. The link still leads to the repository's own page without script or with a modifier key. A repository's files now take one line each, and an importance matrix published beside the quantisations is marked as not a model rather than offered for fetching. Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/web/admin_mirror.go | 100 +++++++++++++------- internal/web/mirror_explore_test.go | 49 ++++++++++ internal/web/static/base.css | 18 ++++ internal/web/templates/admin_mirror.html | 113 ++++++++++++++++------- 4 files changed, 211 insertions(+), 69 deletions(-) diff --git a/internal/web/admin_mirror.go b/internal/web/admin_mirror.go index a4ced7c..3ef1eee 100644 --- a/internal/web/admin_mirror.go +++ b/internal/web/admin_mirror.go @@ -123,6 +123,9 @@ type adminMirrorData struct { Explore *explorer // Back is the listing an open repository was reached from. Back template.URL + // Inline is a repository rendered beneath its row in the listing, without + // the page around it. + Inline bool // Card is the open repository's model card, rendered. Card template.HTML // RepoURL is the open repository on the registry's own site. @@ -179,6 +182,23 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) { p.renderMirror(w, r, m, "", "") })) + // One repository as a fragment, for the row beneath it in the listing. + mux.HandleFunc("GET /admin/mirror/repo", p.adminOnly( + func(w http.ResponseWriter, r *http.Request, _ store.User) { + repo := strings.TrimSpace(r.URL.Query().Get("repo")) + if p.registry == nil || repo == "" { + http.NotFound(w, r) + return + } + d := adminMirrorData{CSRF: csrfFor(r), Inline: true, HasRegistry: true} + p.openRepo(r, &d, repo) + if d.RegistryErr != "" { + http.Error(w, "The registry: "+d.RegistryErr, http.StatusBadGateway) + return + } + render(w, "mirror_repo", d) + })) + mux.HandleFunc("POST /admin/mirror/fetch", p.mirrorAction(m, func(ctx context.Context, admin store.User, r *http.Request) (string, error) { // One form posts one source or fifteen. A sharded model is one @@ -464,46 +484,52 @@ func (p *AccountPages) explore(r *http.Request, d *adminMirrorData) { if repo := strings.TrimSpace(r.URL.Query().Get("repo")); repo != "" { d.Back = exploreState(r.URL.Query()).href(d.Query, "", "") - got, err := p.registry.Repo(r.Context(), repo) - if err != nil { - d.RegistryErr = err.Error() - return - } - d.Repo = &got - d.RepoURL = strings.TrimSuffix(got.DownloadURL("", ""), "/resolve/"+revOrMain(got.Revision)+"/") - d.Card = renderCard(got.Card, d.RepoURL+"/blob/"+revOrMain(got.Revision)+"/") - var weights []hf.File - for _, f := range got.Files { - if !f.IsWeights() { - // Thirty files of which four are worth gigabytes. The rest are - // a README and a tokenizer, and listing them buries the ones - // somebody came for. - continue - } - weights = append(weights, f) - } - for _, set := range hf.Group(weights) { - rs := repoSet{ - FileSet: set, - Model: defaultModelName(got.ID), - // The revision, not the date: two fetches of the same commit - // land in the same place, and a repository re-uploaded under - // the same branch lands somewhere else. - Version: got.ShortRevision(), - } - rs.Verdict = p.verdictFor(got.Architecture, set.Name) - for _, f := range set.Files { - rs.Sources = append(rs.Sources, - repoSource{URL: got.DownloadURL("", f.Path), Path: f.Path}) - } - d.RepoSets = append(d.RepoSets, rs) - } + p.openRepo(r, d, repo) return } p.exploreList(r, d) } +// openRepo reads one repository: its card, and its weights grouped into what +// can be fetched. +func (p *AccountPages) openRepo(r *http.Request, d *adminMirrorData, repo string) { + got, err := p.registry.Repo(r.Context(), repo) + if err != nil { + d.RegistryErr = err.Error() + return + } + d.Repo = &got + d.RepoURL = strings.TrimSuffix(got.DownloadURL("", ""), "/resolve/"+revOrMain(got.Revision)+"/") + d.Card = renderCard(got.Card, d.RepoURL+"/blob/"+revOrMain(got.Revision)+"/") + var weights []hf.File + for _, f := range got.Files { + if !f.IsWeights() { + // Thirty files of which four are worth gigabytes. The rest are + // a README and a tokenizer, and listing them buries the ones + // somebody came for. + continue + } + weights = append(weights, f) + } + for _, set := range hf.Group(weights) { + rs := repoSet{ + FileSet: set, + Model: defaultModelName(got.ID), + // The revision, not the date: two fetches of the same commit + // land in the same place, and a repository re-uploaded under + // the same branch lands somewhere else. + Version: got.ShortRevision(), + } + rs.Verdict = p.verdictFor(got.Architecture, set.Name) + for _, f := range set.Files { + rs.Sources = append(rs.Sources, + repoSource{URL: got.DownloadURL("", f.Path), Path: f.Path}) + } + d.RepoSets = append(d.RepoSets, rs) + } +} + // defaultModelName is the catalog name a repository suggests. // // The last element, lowercased, with the quantisation marker dropped: the owner @@ -523,6 +549,12 @@ func (p *AccountPages) verdictFor(arch, name string) gguf.Verdict { if strings.Contains(strings.ToLower(name), "mmproj") { return gguf.LlamaCpp(p.llamaVersion, "clip") } + // Published beside the quantisations they were made with, and a GGUF + // file like them, so the repository's architecture would pass it. + if strings.Contains(strings.ToLower(name), "imatrix") { + return gguf.Verdict{Checked: true, + Reason: "it is an importance matrix for quantising, not a model"} + } if arch == "" || !gguf.IsGGUF(name) { return gguf.Verdict{Servable: true} } diff --git a/internal/web/mirror_explore_test.go b/internal/web/mirror_explore_test.go index aa9079d..7011c41 100644 --- a/internal/web/mirror_explore_test.go +++ b/internal/web/mirror_explore_test.go @@ -1,6 +1,7 @@ package web import ( + "errors" "html" "strings" "testing" @@ -114,3 +115,51 @@ func TestARepositoryShowsItsCard(t *testing.T) { } } } + +func TestARepositoryOpensAsAFragmentBeneathItsRow(t *testing.T) { + reg := &fakeRegistry{repo: hf.Repo{ + ID: "Qwen/X-GGUF", Revision: "abc123def456", Card: "A **small** model.", + Files: []hf.File{{Path: "x.gguf", Bytes: 10}}, + }} + rec := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}), + "/admin/mirror/repo?repo=Qwen/X-GGUF") + body := rec.Body.String() + if rec.Code != 200 { + t.Fatalf("status %d: %s", rec.Code, body) + } + // The card and the fetch form, and not a page around them. + for _, want := range []string{"small", `action="/admin/mirror/fetch"`, `name="csrf"`} { + if !strings.Contains(body, want) { + t.Errorf("missing %s: %s", want, body) + } + } + for _, unwanted := range []string{""} { + if strings.Contains(body, unwanted) { + t.Errorf("the fragment carries %s", unwanted) + } + } +} + +func TestAFragmentForARegistryThatFailsSaysSo(t *testing.T) { + reg := &fakeRegistry{err: errors.New("reaching the model registry: timeout")} + rec := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}), + "/admin/mirror/repo?repo=Qwen/X-GGUF") + if rec.Code != 502 || !strings.Contains(rec.Body.String(), "timeout") { + t.Errorf("status %d: %s", rec.Code, rec.Body.String()) + } +} + +func TestAnImportanceMatrixIsNotOfferedAsAModel(t *testing.T) { + reg := &fakeRegistry{repo: hf.Repo{ + ID: "a/X-GGUF", Revision: "abc123def456", Architecture: "qwen2", + Files: []hf.File{{Path: "x-q4_k_m.gguf", Bytes: 10}, {Path: "imatrix-x.gguf", Bytes: 5}}, + }} + body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}), + "/admin/mirror/repo?repo=a/X-GGUF").Body.String() + if !strings.Contains(body, "importance matrix") { + t.Errorf("the imatrix should be marked as not a model: %s", body) + } + if strings.Count(body, `action="/admin/mirror/fetch"`) != 1 { + t.Errorf("only the model should have a fetch form: %s", body) + } +} diff --git a/internal/web/static/base.css b/internal/web/static/base.css index 65a9116..ad191a5 100644 --- a/internal/web/static/base.css +++ b/internal/web/static/base.css @@ -488,3 +488,21 @@ details.model-card .card-body { max-height: 28rem; overflow: auto; padding: 0 1r .card-body table { width: auto; max-width: 100%; display: block; overflow-x: auto; font-size: .8rem; } .card-body td, .card-body th { padding: .25rem .5rem; } .card-body a.img { font-size: .8rem; } +/* A repository opened beneath its row in the listing. */ +table.explore tr.open > td { background: var(--bg); } +table.explore a.open-repo::before { content: "▸ "; color: var(--muted); text-decoration: none; display: inline-block; width: 1em; } +table.explore a.open-repo[aria-expanded="true"]::before { content: "▾ "; } +table.explore tr.repo-detail > td { background: var(--bg); padding: .75rem 1rem 1rem; border-top: 0; } +table.explore tr.repo-detail table { background: var(--card); } +table.explore tr.repo-detail td:first-child { max-width: none; } +/* A repository's files: name, version and button on one line, so a repository + of a dozen quantisations is a dozen lines rather than a dozen boxes. */ +table.repo-files td { vertical-align: middle; } +table.repo-files td:first-child { overflow-wrap: anywhere; } +table.repo-files form.inline { display: flex; flex-wrap: nowrap; gap: .35rem; align-items: center; margin: 0; } +table.repo-files form.inline input[type=text] { display: inline-block; width: auto; margin: 0; padding: .3rem .45rem; font-size: .8rem; } +table.repo-files form.inline input[name=model] { width: 12rem; min-width: 0; flex: 1 1 12rem; } +table.repo-files form.inline input[name=version] { width: 6.5rem; } +table.repo-files form.inline button { padding: .3rem .7rem; font-size: .8rem; } +table.repo-files td:last-child { width: 1%; white-space: nowrap; } +table.repo-files td:last-child .opt { display: block; margin-bottom: .2rem; } diff --git a/internal/web/templates/admin_mirror.html b/internal/web/templates/admin_mirror.html index 9af8a5f..643620f 100644 --- a/internal/web/templates/admin_mirror.html +++ b/internal/web/templates/admin_mirror.html @@ -214,8 +214,8 @@ document.addEventListener('click', function (e) { -{{range .Rows}} - + @@ -226,6 +226,44 @@ document.addEventListener('click', function (e) { {{end}}
RepositorySizeArchitectureContext DownloadsLikesUpdated
{{.ID}} +{{range .Rows}}
{{if .New}}new{{end}}{{if .Gated.Is}}gated{{end}} {{if or .BaseModel .License}}
{{with .BaseModel}}from {{.}}{{end}}{{if and .BaseModel .License}} · {{end}}{{.License}}
{{end}}
{{.ParamsLabel}}{{.Age}}
+ {{if .Hidden}}

{{.Hidden}} more {{if eq .Hidden 1}}is{{else}}are{{end}} hidden: their architecture is one the nodes' llama.cpp cannot load. Untick “only what these nodes can run” to see them.

{{end}}

A gated repository needs its terms accepted with a Hugging Face @@ -237,10 +275,43 @@ directory, or give the mirror a token.

{{end}} {{end}}{{end}} -{{if .Repo}} -

← back to the list

-

{{.Repo.ID}} at {{.Repo.ShortRevision}}

+{{if .Repo}}{{template "mirror_repo" .}}{{end}} +{{end}} + +

Fetch a model

+

By hand, for anything the search does not reach.

+
+ + +
+ + + +
+ + +
+

The mirror answers as soon as the download is under way, not when +it finishes — a model is tens of gigabytes and nothing here holds a connection +open for that. The row above will show it arriving. A version is never +overwritten: fetching into one that exists is refused, so a new build is a new +version and the old weights stay where they are.

+{{end}} + +
llmgw {{.Version}}{{.Now}}
+{{end}} + +{{/* One repository: its card and its files. The whole page when opened by + address, and the row beneath a listing entry when opened from the list. */}} +{{define "mirror_repo"}} +{{if not .Inline}}

← back to the list

+

{{.Repo.ID}} at {{.Repo.ShortRevision}}

{{end}}

+ {{if .Inline}}at {{.Repo.ShortRevision}}{{end}} {{with .Repo.BaseModel}}from {{range $i, $b := .}}{{if $i}}, {{end}}{{$b}}{{end}}{{end}} {{with .Repo.License}}license {{.}}{{end}} {{with .Repo.Languages}}{{join .}}{{end}} @@ -253,8 +324,8 @@ directory, or give the mirror a token.

{{end}} {{if .RepoSets}} - - +
WhatSizePublished checksum
+ {{range .RepoSets}} @@ -292,31 +363,3 @@ computes once it has it.

No weight files in {{.Repo.ID}}.

{{end}} {{end}} -{{end}} - -

Fetch a model

-

By hand, for anything the search does not reach.

- - - -
- - - -
- - - -

The mirror answers as soon as the download is under way, not when -it finishes — a model is tens of gigabytes and nothing here holds a connection -open for that. The row above will show it arriving. A version is never -overwritten: fetching into one that exists is refused, so a new build is a new -version and the old weights stay where they are.

-{{end}} - -
llmgw {{.Version}}{{.Now}}
-{{end}}
WhatSizePublished checksum
{{.Name}} {{if .Shards}}{{.Shards}} shards, fetched together{{end}}