feat(webui): Models picks from the provider catalog, and enables available providers

archied already finds usable providers (key set in the environment, or
configured) through the model catalog; the published config view now
carries that catalog, providers with their model ids. Settings > Models
offers role models only from configured providers, lists the catalog's
unconfigured providers as available, and adding one carries its class, key
variable and endpoint. Roles and providers are two accordions, each ending
in an add row.
This commit is contained in:
sam committed 2026-09-25 18:04:46 +10:00
1 parent 95fb6529e1
commit 230280a6e0
16 files changed
+373 -99

No files matched your search

+1
View File
@@ -1481,6 +1481,7 @@ func (b *boot) configViewInput(ctx context.Context) webui.ConfigViewInput {
in := webui.ConfigViewInput{
Config: b.cfgHolder.Get(),
Provenance: b.configOrigins(),
Catalog: catalogView(b.catalog),
}
if b.lastReload != nil {
status := b.lastReload()
+22
View File
@@ -3,10 +3,12 @@ package archied
import (
"maps"
"slices"
"strings"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
"github.com/samcharles93/archie-core/internal/secret"
"github.com/samcharles93/archie-core/internal/webui"
)
func applyModelCatalog(cfg *config.Config, snapshot modelcatalog.Snapshot) []string {
@@ -53,3 +55,23 @@ func mergeProviders(base, overrides map[string]config.Provider) map[string]confi
}
return merged
}
// catalogView renders the usable providers for the published config view,
// sorted by id with each provider's model ids sorted, so the document is
// stable across publishes.
func catalogView(snapshot modelcatalog.Snapshot) []webui.CatalogProviderView {
view := make([]webui.CatalogProviderView, 0, len(snapshot.Providers))
for _, provider := range snapshot.Providers {
models := make([]string, 0, len(provider.Models))
for _, model := range provider.Models {
models = append(models, model.ID)
}
slices.Sort(models)
view = append(view, webui.CatalogProviderView{
ID: provider.ID, Name: provider.Name, Class: provider.Class,
APIKeyEnv: provider.APIKeyEnv, BaseURL: provider.BaseURL, Models: models,
})
}
slices.SortFunc(view, func(a, b webui.CatalogProviderView) int { return strings.Compare(a.ID, b.ID) })
return view
}
@@ -0,0 +1,30 @@
package archied
import (
"reflect"
"testing"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
"github.com/samcharles93/archie-core/internal/webui"
)
func TestCatalogViewListsEachAvailableProviderWithItsModels(t *testing.T) {
snapshot := modelcatalog.Snapshot{Providers: []modelcatalog.Provider{
{ID: "openai", Name: "OpenAI", Class: "openai", APIKeyEnv: "OPENAI_API_KEY", Models: []modelcatalog.Model{{ID: "gpt-b"}, {ID: "gpt-a"}}},
{ID: "anthropic", Name: "Anthropic", Class: "anthropic", APIKeyEnv: "ANTHROPIC_API_KEY", BaseURL: "https://api.example", Models: []modelcatalog.Model{{ID: "claude"}}},
}}
want := []webui.CatalogProviderView{
{ID: "anthropic", Name: "Anthropic", Class: "anthropic", APIKeyEnv: "ANTHROPIC_API_KEY", BaseURL: "https://api.example", Models: []string{"claude"}},
{ID: "openai", Name: "OpenAI", Class: "openai", APIKeyEnv: "OPENAI_API_KEY", Models: []string{"gpt-a", "gpt-b"}},
}
if got := catalogView(snapshot); !reflect.DeepEqual(got, want) {
t.Fatalf("catalogView =\n%#v\nwant\n%#v", got, want)
}
}
func TestCatalogViewOfAnEmptySnapshotIsEmptyNotNil(t *testing.T) {
got := catalogView(modelcatalog.Snapshot{})
if got == nil || len(got) != 0 {
t.Fatalf("catalogView(empty) = %#v, want an empty slice", got)
}
}
+20 -2
View File
@@ -141,8 +141,12 @@ type ConfigView struct {
// Chat carries the dashboard's own chat-page settings. They are
// daemon configuration the page cannot otherwise see: a process that
// renders a published snapshot has no [chat] section to read.
Chat ChatView `json:"chat"`
Provenance []ConfigOrigin `json:"provenance"`
Chat ChatView `json:"chat"`
// Catalog lists the providers the model catalog found usable (their key
// is set in the environment, or they are configured), with their models,
// so Settings can offer to enable one and pick role models from it.
Catalog []CatalogProviderView `json:"catalog"`
Provenance []ConfigOrigin `json:"provenance"`
// Reload reports the most recent config reload outcome. Omitted when
// the reload status is unavailable.
Reload *config.ReloadStatus `json:"reload,omitempty"`
@@ -337,6 +341,19 @@ type ConfigViewInput struct {
Provenance []ConfigOrigin
// Reload is the most recent reload outcome, or nil when unavailable.
Reload *config.ReloadStatus
// Catalog is the usable-provider catalog the configuration owner loaded.
Catalog []CatalogProviderView
}
// CatalogProviderView is one usable provider from the model catalog. It
// names the environment variable its key was found in, never the key.
type CatalogProviderView struct {
ID string `json:"id"`
Name string `json:"name"`
Class string `json:"class"`
APIKeyEnv string `json:"api_key_env,omitempty"`
BaseURL string `json:"base_url,omitempty"`
Models []string `json:"models"`
}
// BuildConfigView renders the dashboard's secret-free configuration
@@ -393,6 +410,7 @@ func BuildConfigView(in ConfigViewInput) ConfigView {
Listen: cfg.Web.Listen,
TrustForwardedHeaders: cfg.Web.TrustForwardedHeaders,
},
Catalog: append([]CatalogProviderView{}, in.Catalog...),
Chat: ChatView{
ShowToolCalls: cfg.Chat.ShowToolCalls,
Operator: strings.TrimSpace(cfg.Chat.Operator),
+1 -7
View File
@@ -1,10 +1,4 @@
// Package webui is archied's dashboard: a control room over the daemon's
// task board, activity stream and configuration.
//
// The Go side owns serving and the JSON API only; the frontend lives in the
// repo-root ui/ package, which exposes the built assets as an embedded FS.
// Handlers are split by concern -- one file per API area -- so a section can
// be added without growing a single file without end.
// Package webui implements the dashboard's HTTP API and serves the embedded SPA.
package webui
import (