Files
LocalAI/core/application/studio_egress_settings.go
T
Ettore Di Giacinto 61c54dc833 refactor(studio): word the command provider text without naming an add-on
The prompt, the Tools menu reasons, the network error texts, the CLI help,
the API instructions and the assistant tool descriptions said "Sandbox" for
the add-on that runs commands. Core must not know that name.

The reason a chat has no commands now uses the title the provider declares
("the Zeta add-on is off for this chat") or, when none is installed, says
"the add-on that runs commands". Text that has no provider in hand speaks of
the network of commands or of an add-on that isolates them.

Assisted-by: Claude Code:claude-sonnet-5-5
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-11-03 10:43:37 +00:00

55 lines
1.5 KiB
Go

package application
import (
"sync"
"github.com/mudler/xlog"
)
// lastGood parses one list setting of the Sandbox network and keeps the
// last value that parsed. The settings endpoint and the runtime settings
// file refuse a bad value, so one reaches here only by another way (a value
// a newer version reads more strictly, a hand edit read at startup). It
// must not change what commands may reach without a word: a bad value keeps
// the last good list in force and is logged once. A process that never saw
// a good value uses the fallback, the setting's default. The memory is per
// process: the value itself is the shared runtime setting.
type lastGood[T any] struct {
name string
parse func(string) (T, error)
fallback T
mu sync.Mutex
raw string
val T
ok bool // val holds a parsed value
logged string // the bad value logged last
}
func newLastGood[T any](name string, parse func(string) (T, error), fallback T) *lastGood[T] {
return &lastGood[T]{name: name, parse: parse, fallback: fallback}
}
// get returns the list for raw: parsed, or the last good one.
func (l *lastGood[T]) get(raw string) T {
l.mu.Lock()
defer l.mu.Unlock()
if l.ok && raw == l.raw {
return l.val
}
v, err := l.parse(raw)
if err == nil {
l.raw, l.val, l.ok = raw, v, true
return v
}
keep := l.fallback
if l.ok {
keep = l.val
}
if l.logged != raw {
l.logged = raw
xlog.Warn("Chats: a command network setting is not valid; the last valid value stays in force", "setting", l.name, "kept_last_valid", l.ok, "error", err)
}
return keep
}