The cluster page and the console say which picture and 3D models are here, and add them

A site whose catalog had no flux-schnell or triposr showed no Images or 3D
page, and nothing said they were one click away. The cluster page now has
a Pictures and 3D models card under the models: each preset, what it
makes, the classes of card here it fits, whether and by whom it was
added, and why the leader has not added it by itself; an Add button, which
says first when it would install ComfyUI on the GPU nodes and restart the
control planes; and the switch for presets.auto. The console's models
screen shows the same under its table: A adds one, asking first in the
same case, and P turns automatic adding on or off.

`ctl model add PRESET` and `ctl model presets` go through the presets API,
so the control plane keeps who added one, and `ctl model presets auto
on|off` flips the setting; against a control plane from before, add sends
the entry as v0.14.4 did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-13 20:40:19 +02:00
1 parent e0adcc5c4e
commit 85a2bdd0e3
16 files changed
+746 -21

No files matched your search

+147
View File
@@ -0,0 +1,147 @@
package web
import (
"context"
"net/http"
"net/url"
"strings"
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
// PresetAdmin is the models that come with llmgw, as the cluster page shows
// and adds them: flux-schnell for pictures, triposr for 3D models. A site
// whose catalog had neither showed no Images or 3D page, and nothing said
// they were one click away.
type PresetAdmin interface {
Presets(ctx context.Context) (adminapi.PresetsView, error)
AddPreset(ctx context.Context, name, by string) error
SetAutoPresets(ctx context.Context, on bool, by string) error
}
// presetsCard is the presets as the cluster page shows them.
type presetsCard struct {
Auto bool
Rows []presetRow
}
// presetRow is one preset, its words already in the reader's language.
type presetRow struct {
Name, Description, Makes, Card, Licence string
// Fits says which of the cluster's classes can run it; empty when none.
Fits string
// State is where it stands: added, and by whom; removed, so not added
// again by itself; or neither.
State string
InCatalog bool
Declined bool
// Blocked is why the leader does not add it by itself, in the control
// plane's words (English); not said when automatic adding is off, which
// the line under the table says once.
Blocked string
// AddsComfyUI is an Add that also has the GPU nodes install ComfyUI and
// the control planes restart on that setting.
AddsComfyUI bool
}
// presetAddsComfyUI is whether adding a preset by hand sets engines.comfyui:
// the cluster installs none yet.
func presetAddsComfyUI(v adminapi.PresetsView, p adminapi.PresetView) bool {
return !p.InCatalog && v.ComfyUI == ""
}
func init() {
registerKeys("dash.presets.makes.pictures", "dash.presets.makes.meshes")
}
// presetsCardOf reads the presets for the page; nil, and the card left off,
// where the control plane cannot say.
func presetsCardOf(ctx context.Context, l *Lang, a PresetAdmin) *presetsCard {
v, err := a.Presets(ctx)
if err != nil {
return nil
}
c := &presetsCard{Auto: v.Auto}
for _, p := range v.Presets {
row := presetRow{
Name: p.Name, Description: p.Description, Card: p.Card,
Makes: l.T("dash.presets.makes." + p.Makes),
Licence: p.Licence.Name,
Fits: strings.Join(p.FitsClasses, ", "),
InCatalog: p.InCatalog, Declined: p.Declined,
AddsComfyUI: presetAddsComfyUI(v, p),
}
if !strings.HasPrefix(p.Blocked, "presets.auto") && !p.Declined {
row.Blocked = p.Blocked
}
if c := p.Licence.Commercial; c != nil && !*c {
row.Licence = l.T("dash.presets.not_commercial", p.Licence.Name)
}
at := ""
if !p.AddedAt.IsZero() {
at = p.AddedAt.UTC().Format("2006-01-02 15:04")
}
switch {
case p.InCatalog && p.AddedBy == "auto":
row.State = l.T("dash.presets.added_auto", at)
case p.InCatalog && p.AddedBy != "":
row.State = l.T("dash.presets.added_by", p.AddedBy, at)
case p.InCatalog:
row.State = l.T("dash.presets.in_catalog")
case p.Declined:
row.State = l.T("dash.presets.declined")
}
c.Rows = append(c.Rows, row)
}
return c
}
// RegisterPresets mounts adding a preset, and turning their automatic adding
// on and off, on the cluster page: for an administrator, with the session's
// CSRF token, answered by going back to the page with what happened.
func (p *AccountPages) RegisterPresets(mux *http.ServeMux, a PresetAdmin) {
back := func(w http.ResponseWriter, r *http.Request, q url.Values) {
http.Redirect(w, r, "/admin?"+q.Encode()+"#presets", http.StatusSeeOther)
}
checked := func(h func(w http.ResponseWriter, r *http.Request, admin store.User)) http.HandlerFunc {
return p.adminOnly(func(w http.ResponseWriter, r *http.Request, admin store.User) {
sess, _, _ := p.session(r)
if !p.accounts.CheckCSRF(sess, r.FormValue("csrf")) {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
h(w, r, admin)
})
}
// Before the one by name, which would otherwise take "auto" for a preset.
mux.HandleFunc("POST /admin/presets/auto", checked(func(w http.ResponseWriter, r *http.Request, admin store.User) {
on := r.FormValue("on") == "true"
q := url.Values{}
if err := a.SetAutoPresets(r.Context(), on, admin.Email); err != nil {
p.log.Warn("presets.auto was not changed", "admin", admin.Email, "err", err)
q.Set("problem", err.Error())
} else {
p.log.Info("presets.auto changed", "admin", admin.Email, "on", on)
key := "dash.presets.notice.auto_off"
if on {
key = "dash.presets.notice.auto_on"
}
q.Set("notice", langOf(r).T(key))
}
back(w, r, q)
}))
mux.HandleFunc("POST /admin/presets/{name}", checked(func(w http.ResponseWriter, r *http.Request, admin store.User) {
name := r.PathValue("name")
q := url.Values{}
if err := a.AddPreset(r.Context(), name, admin.Email); err != nil {
p.log.Warn("a preset was not added", "admin", admin.Email, "preset", name, "err", err)
// The control plane's reason, as it gave it: in English.
q.Set("problem", name+": "+err.Error())
} else {
p.log.Info("a preset was added", "admin", admin.Email, "preset", name)
q.Set("notice", langOf(r).T("dash.presets.notice.added", name))
}
back(w, r, q)
}))
}
+134
View File
@@ -0,0 +1,134 @@
package web
import (
"context"
"errors"
"io"
"log/slog"
"net/http"
"net/url"
"strings"
"testing"
"time"
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
"gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
// presetFleet is a cluster whose control plane says its presets: triposr
// added by itself, flux-schnell removed by somebody.
type presetFleet struct {
fakeFleet
view adminapi.PresetsView
err error
added []string
auto []bool
}
func (f *presetFleet) Presets(context.Context) (adminapi.PresetsView, error) { return f.view, f.err }
func (f *presetFleet) AddPreset(_ context.Context, name, by string) error {
f.added = append(f.added, name+" by "+by)
return nil
}
func (f *presetFleet) SetAutoPresets(_ context.Context, on bool, _ string) error {
f.auto = append(f.auto, on)
return nil
}
func newPresetFleet() *presetFleet {
no := false
return &presetFleet{view: adminapi.PresetsView{Auto: true, Presets: []adminapi.PresetView{
{Name: "flux-schnell", Makes: "pictures", Card: "cc 7.0+, 24 GB+", Licence: catalog.License{Name: "Apache-2.0"},
FitsClasses: []string{"v100-32g"}, Fits: true, Declined: true,
Blocked: "removed from the catalog after it was added; add it again to undo"},
{Name: "sdxl", Makes: "pictures", Card: "cc 8.0+", Licence: catalog.License{Name: "x"},
Blocked: "the cluster installs no ComfyUI (engines.comfyui); adding it by hand sets that"},
{Name: "triposr", Makes: "meshes", Card: "cc 7.0+, 8 GB+", Licence: catalog.License{Name: "Made-up", Commercial: &no},
FitsClasses: []string{"t4-15g", "v100-32g"}, Fits: true, InCatalog: true, AddedBy: "auto",
AddedAt: time.Date(2026, 10, 13, 9, 30, 0, 0, time.UTC)},
}}}
}
func TestThePicturesAnd3DModelsAreAddedFromTheClusterPage(t *testing.T) {
a := fakeAccounts{user: store.User{ID: "u1", Email: "a@example.com", IsAdmin: true}}
p := NewAccountPages(a, nil, nil, "v0", slog.New(slog.NewTextHandler(io.Discard, nil)))
f := newPresetFleet()
mux := http.NewServeMux()
mux.HandleFunc("GET /admin", p.AdminPage(Dashboard(f, nil, "v1", time.Second, false, NavExtras{}, nil)))
p.RegisterPresets(mux, f)
body := mirrorGet(t, mux, "/admin").Body.String()
for _, want := range []string{
`id="presets"`, "Pictures and 3D models",
`action="/admin/presets/flux-schnell"`, "Add again", "removed, so not added again by itself",
"added automatically, 2026-10-13 09:30", "Made-up, not for commercial use", "t4-15g, v100-32g",
`action="/admin/presets/auto"`, `name="on" value="false"`, "Stop adding them",
"(the cluster installs no ComfyUI (engines.comfyui); adding it by hand sets that)",
"restarts the control planes",
} {
if !strings.Contains(body, want) {
t.Errorf("%q not on the page", want)
}
}
// The button's title and the line beside it, on each preset not here:
// the cluster installs no ComfyUI yet.
if n := strings.Count(body, "restarts the control planes"); n != 4 {
t.Errorf("the ComfyUI warning is said %d times, not on the two presets an Add would install it for", n)
}
if strings.Contains(body, "(removed from the catalog") {
t.Error("a decline is said twice")
}
if strings.Contains(body, `action="/admin/presets/triposr"`) {
t.Error("a preset in the catalog is offered to be added")
}
w := mirrorPost(t, mux, "/admin/presets/flux-schnell", url.Values{"csrf": {"tok"}})
if w.Code != http.StatusSeeOther || len(f.added) != 1 || f.added[0] != "flux-schnell by a@example.com" {
t.Fatalf("status %d, added %v", w.Code, f.added)
}
if loc := w.Header().Get("Location"); !strings.Contains(loc, "notice=") || !strings.HasSuffix(loc, "#presets") {
t.Errorf("redirected to %s", loc)
}
w = mirrorPost(t, mux, "/admin/presets/auto", url.Values{"csrf": {"tok"}, "on": {"false"}})
if w.Code != http.StatusSeeOther || len(f.auto) != 1 || f.auto[0] || len(f.added) != 1 {
t.Fatalf("status %d, auto %v, added %v: auto was taken for a preset's name", w.Code, f.auto, f.added)
}
if w := mirrorPost(t, mux, "/admin/presets/triposr", url.Values{"csrf": {"bad"}}); w.Code != http.StatusBadRequest || len(f.added) != 1 {
t.Errorf("a forged form was accepted: %d", w.Code)
}
}
func TestNoComfyUIWarningWhereTheClusterInstallsIt(t *testing.T) {
f := newPresetFleet()
f.view.ComfyUI = "0.39.2"
a := fakeAccounts{user: store.User{ID: "u1", Email: "a@example.com", IsAdmin: true}}
p := NewAccountPages(a, nil, nil, "v0", slog.New(slog.NewTextHandler(io.Discard, nil)))
mux := http.NewServeMux()
mux.HandleFunc("GET /admin", p.AdminPage(Dashboard(f, nil, "v1", time.Second, false, NavExtras{}, nil)))
body := mirrorGet(t, mux, "/admin").Body.String()
if !strings.Contains(body, `action="/admin/presets/flux-schnell"`) {
t.Fatal("no Add on the page")
}
if strings.Contains(body, "restarts the control planes") {
t.Error("warned of installing a ComfyUI the cluster already installs")
}
}
func TestThePresetsCardIsLeftOffWhereTheControlPlaneCannotSay(t *testing.T) {
f := newPresetFleet()
f.err = errors.New("501")
_, body := get(t, Dashboard(f, nil, "v1", time.Second, true, NavExtras{}, nil), "http://127.0.0.1:9090/", nil)
if strings.Contains(body, `id="presets"`) {
t.Error("an empty presets card was drawn")
}
// The read-only page shows them, with nothing to press.
f.err = nil
_, body = get(t, Dashboard(f, nil, "v1", time.Second, true, NavExtras{}, nil), "http://127.0.0.1:9090/", nil)
if !strings.Contains(body, `id="presets"`) || strings.Contains(body, `/admin/presets/`) {
t.Errorf("the admin listener's page: card %v, forms %v",
strings.Contains(body, `id="presets"`), strings.Contains(body, `/admin/presets/`))
}
}
+8 -2
View File
@@ -36,8 +36,11 @@ type DashboardData struct {
Models []adminapi.ModelView
Replicas []adminapi.ReplicaView
Unplaced []adminapi.ExplainView
Usage []store.KeyUsage
Summary adminapi.Summary
// Presets is the models that come with llmgw — pictures, 3D models —
// and whether each is here; nil where the control plane cannot say.
Presets *presetsCard
Usage []store.KeyUsage
Summary adminapi.Summary
// Fabrics is the physical fabrics and what disagrees about them, from a
// source that can say.
Fabrics *fabrics.Report
@@ -236,6 +239,9 @@ func Dashboard(src Source, usage UsageSource, version string, refresh time.Durat
}
}
d.Unplaced = unplaced(src, d.Models)
if pa, ok := src.(PresetAdmin); ok {
d.Presets = presetsCardOf(r.Context(), l, pa)
}
ids := make([]string, 0, len(d.Nodes))
for _, n := range d.Nodes {
ids = append(ids, n.ID)
+27 -1
View File
@@ -196,5 +196,31 @@
"dash.usage.none": "No requests recorded in the last 24 hours.",
"dash.usage.auth_off": "Authentication is off, so there is no identity to account against.",
"dash.admin_listener": "Metrics, pprof and the management API are on the admin listener, which is bound to loopback and not reachable from here. pprof can dump the process heap, where API keys sit in plaintext, which is why that port is not exposed:"
"dash.admin_listener": "Metrics, pprof and the management API are on the admin listener, which is bound to loopback and not reachable from here. pprof can dump the process heap, where API keys sit in plaintext, which is why that port is not exposed:",
"dash.presets.title": "Pictures and 3D models",
"dash.presets.about": "Models that come with llmgw, their workflow, nodes and licence already tried. Adding one also has the GPU nodes install ComfyUI, about 10 GB each, when the cluster has none.",
"dash.presets.makes": "Makes",
"dash.presets.makes.pictures": "pictures",
"dash.presets.makes.meshes": "3D models",
"dash.presets.card": "Needs",
"dash.presets.licence": "Licence",
"dash.presets.not_commercial": "%s, not for commercial use",
"dash.presets.fits": "Fits",
"dash.presets.fits_none": "no card here",
"dash.presets.state": "Here",
"dash.presets.added_auto": "added automatically, %s",
"dash.presets.added_by": "added by %s, %s",
"dash.presets.in_catalog": "in the catalog",
"dash.presets.declined": "removed, so not added again by itself",
"dash.presets.add": "Add",
"dash.presets.add_again": "Add again",
"dash.presets.auto_on": "Added by themselves: when a card fits one and the catalog has nothing that makes what it makes.",
"dash.presets.auto_off": "Not added by themselves: only when somebody adds one.",
"dash.presets.turn_off": "Stop adding them",
"dash.presets.turn_on": "Add them by themselves",
"dash.presets.notice.added": "%s added; it is placed on the next pass, and loads when first asked for",
"dash.presets.notice.auto_on": "Pictures and 3D models are added by themselves where a card fits",
"dash.presets.notice.auto_off": "Pictures and 3D models are no longer added by themselves",
"dash.presets.adds_comfyui": "Adding it installs ComfyUI on the GPU nodes, about 10 GB each, and restarts the control planes, standbys first"
}
+27 -1
View File
@@ -194,5 +194,31 @@
"dash.usage.none": "Son 24 saatte hiç istek kaydedilmedi.",
"dash.usage.auth_off": "Kimlik doğrulama kapalı; bu yüzden kullanımın yazılacağı bir kimlik yok.",
"dash.admin_listener": "Metrikler, pprof ve yönetim API'si yönetici dinleyicisindedir; bu dinleyici loopback'e bağlıdır ve buradan erişilemez. pprof, API anahtarlarının düz metin olarak durduğu süreç belleğinin dökümünü alabilir; o portun dışarı açılmamasının nedeni budur:"
"dash.admin_listener": "Metrikler, pprof ve yönetim API'si yönetici dinleyicisindedir; bu dinleyici loopback'e bağlıdır ve buradan erişilemez. pprof, API anahtarlarının düz metin olarak durduğu süreç belleğinin dökümünü alabilir; o portun dışarı açılmamasının nedeni budur:",
"dash.presets.title": "Resim ve 3D modelleri",
"dash.presets.about": "llmgw ile gelen modeller; iş akışları, düğümleri ve lisansları denenmiş. Birini eklemek, kümede ComfyUI yoksa GPU düğümlerine onu da kurdurur (her birine yaklaşık 10 GB).",
"dash.presets.makes": "Ürettiği",
"dash.presets.makes.pictures": "resim",
"dash.presets.makes.meshes": "3D model",
"dash.presets.card": "Gerekli kart",
"dash.presets.licence": "Lisans",
"dash.presets.not_commercial": "%s, ticari kullanım yok",
"dash.presets.fits": "Uyan sınıflar",
"dash.presets.fits_none": "burada uyan kart yok",
"dash.presets.state": "Durum",
"dash.presets.added_auto": "kendiliğinden eklendi, %s",
"dash.presets.added_by": "%s ekledi, %s",
"dash.presets.in_catalog": "katalogda",
"dash.presets.declined": "kaldırıldı; kendiliğinden yeniden eklenmez",
"dash.presets.add": "Ekle",
"dash.presets.add_again": "Yeniden ekle",
"dash.presets.auto_on": "Kendiliğinden ekleniyorlar: bir kart uyduğunda ve katalogda aynı işi yapan model olmadığında.",
"dash.presets.auto_off": "Kendiliğinden eklenmiyorlar: yalnızca biri eklediğinde.",
"dash.presets.turn_off": "Kendiliğinden eklemeyi durdur",
"dash.presets.turn_on": "Kendiliğinden ekle",
"dash.presets.notice.added": "%s eklendi; sonraki turda yerleştirilir, ilk istendiğinde yüklenir",
"dash.presets.notice.auto_on": "Resim ve 3D modelleri, kart uyan yerde kendiliğinden eklenecek",
"dash.presets.notice.auto_off": "Resim ve 3D modelleri artık kendiliğinden eklenmeyecek",
"dash.presets.adds_comfyui": "Eklemek GPU düğümlerine ComfyUI kurar (her birine yaklaşık 10 GB) ve kontrol düzlemlerini yeniden başlatır, önce yedekler"
}
+28
View File
@@ -163,6 +163,34 @@ document.querySelectorAll("form.build-choice select").forEach(function (s) {
{{end}}</table>
{{else}}<p class="empty">{{t "dash.models.empty"}}</p>{{end}}
{{with .Presets}}
<h3 id="presets">{{t "dash.presets.title"}}</h3>
<p class="note">{{t "dash.presets.about"}}</p>
<table class="rows"><tr><th>{{t "dash.col.model"}}</th><th>{{t "dash.presets.makes"}}</th><th>{{t "dash.presets.card"}}</th><th>{{t "dash.presets.licence"}}</th><th>{{t "dash.presets.fits"}}</th><th>{{t "dash.presets.state"}}</th><th></th></tr>
{{range .Rows}}<tr>
<td><code>{{.Name}}</code></td>
<td title="{{.Description}}">{{.Makes}}</td>
<td>{{.Card}}</td>
<td>{{.Licence}}</td>
<td>{{or .Fits (t "dash.presets.fits_none")}}</td>
{{/* Why the leader does not add it itself is the control plane's, in English. */}}
<td{{if .Declined}} class="note"{{end}}>{{or .State "—"}}{{with .Blocked}} <span class="note">({{.}})</span>{{end}}</td>
<td>{{if and $.Menu.CSRF (not .InCatalog)}}
<form method="post" action="/admin/presets/{{.Name}}" class="inline">
<input type="hidden" name="csrf" value="{{$.Menu.CSRF}}">
<button type="submit"{{if .AddsComfyUI}} title="{{t "dash.presets.adds_comfyui"}}"{{end}}>{{if .Declined}}{{t "dash.presets.add_again"}}{{else}}{{t "dash.presets.add"}}{{end}}</button>
</form>{{if .AddsComfyUI}} <span class="warn">{{t "dash.presets.adds_comfyui"}}</span>{{end}}{{end}}</td>
</tr>
{{end}}</table>
<p>{{if .Auto}}{{t "dash.presets.auto_on"}}{{else}}{{t "dash.presets.auto_off"}}{{end}}
{{if $.Menu.CSRF}}
<form method="post" action="/admin/presets/auto" class="inline">
<input type="hidden" name="csrf" value="{{$.Menu.CSRF}}">
<input type="hidden" name="on" value="{{if .Auto}}false{{else}}true{{end}}">
<button type="submit">{{if .Auto}}{{t "dash.presets.turn_off"}}{{else}}{{t "dash.presets.turn_on"}}{{end}}</button>
</form>{{end}}</p>
{{end}}
{{if .Unplaced}}
<h2>{{t "dash.unplaced"}}</h2>
{{/* The scheduler's reasons, as it gives them. */}}