mirror of
https://github.com/mudler/LocalAI.git
synced 2026-05-17 04:56:52 -04:00
Adds a whitelabeling feature so an operator can replace the LocalAI
instance name, tagline, square logo, horizontal logo, and favicon from
the admin Settings page. Defaults fall back to the bundled assets so
existing installs are unaffected.
The public GET /api/branding endpoint is reachable pre-auth so the
login screen can render the configured branding before sign-in.
Mutating routes (POST/DELETE /api/branding/asset/:kind) remain
admin-only. Text fields (instance_name, instance_tagline) ride the
existing /api/settings flow; binary assets get a dedicated multipart
upload route that persists files under DynamicConfigsDir/branding/.
To prevent the Settings page's stale local state from clobbering an
upload on save, UpdateSettingsEndpoint preserves whatever the on-disk
asset filename fields are regardless of the body — /api/branding/asset/*
are the sole writers for those fields.
The MCP catalog gains get_branding and set_branding tools (text fields
only; file upload stays UI-only) plus a configure_branding skill prompt.
While wiring this up, the same restart-loss class of bug surfaced for
several existing fields whose RuntimeSettings entries were never read
by the startup loader. Fix loadRuntimeSettingsFromFile() to load:
- branding (instance_name, instance_tagline, *_file basenames)
- auto_upgrade_backends, prefer_development_backends
- localai_assistant_enabled
- open_responses_store_ttl
- the 7 existing AgentPool fields (enabled, default/embedding model,
chunking sizes, enable_logs, collection_db_path)
Also exposes 3 new AgentPool runtime settings (vector_engine,
database_url, agent_hub_url) via /api/settings + the Settings UI, with
the same load-on-startup wiring. The file watcher's manual-edit path
is intentionally not changed — the in-process API endpoints already
update appConfig directly, so the watcher is redundant for supported
flows and a separate refactor for everything else.
15 TDD specs cover the loader behaviour (1 branding + 11 adjacent + 3
new agent-pool); 2 specs cover the persistence helpers and the
clobber-prevention contract.
Assisted-by: claude-code:claude-opus-4-7
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// runtimeSettingsFile is the on-disk filename inside DynamicConfigsDir.
|
|
const runtimeSettingsFile = "runtime_settings.json"
|
|
|
|
// ReadPersistedSettings loads runtime_settings.json from DynamicConfigsDir.
|
|
// A missing file is not an error — the zero RuntimeSettings is returned.
|
|
// This lets callers update only the field they own (e.g. one branding
|
|
// asset filename) without clobbering unrelated settings already on disk.
|
|
func (o *ApplicationConfig) ReadPersistedSettings() (RuntimeSettings, error) {
|
|
var settings RuntimeSettings
|
|
if o.DynamicConfigsDir == "" {
|
|
return settings, errors.New("DynamicConfigsDir is not set")
|
|
}
|
|
path := filepath.Join(o.DynamicConfigsDir, runtimeSettingsFile)
|
|
data, err := os.ReadFile(path)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return settings, nil
|
|
}
|
|
if err != nil {
|
|
return settings, err
|
|
}
|
|
if err := json.Unmarshal(data, &settings); err != nil {
|
|
return settings, err
|
|
}
|
|
return settings, nil
|
|
}
|
|
|
|
// WritePersistedSettings serialises the given RuntimeSettings to
|
|
// runtime_settings.json with restricted permissions (it may carry API
|
|
// keys and P2P tokens).
|
|
func (o *ApplicationConfig) WritePersistedSettings(settings RuntimeSettings) error {
|
|
if o.DynamicConfigsDir == "" {
|
|
return errors.New("DynamicConfigsDir is not set")
|
|
}
|
|
path := filepath.Join(o.DynamicConfigsDir, runtimeSettingsFile)
|
|
data, err := json.MarshalIndent(settings, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(path, data, 0o600)
|
|
}
|