Files
LocalAI/core/config/addon_host_ops.go
T
Ettore Di Giacinto 1604a67c1f feat(addons): add the add-on runtime, navigation and first-party add-ons
Add the add-on runtime to LocalAI: manifests, the host operation broker,
admin gating by account role, the add-on UI bundle builder and the SDK
for add-on pages. Move the navigation to Chat, Models, Add-ons and
Settings, with pinned add-ons in the sidebar and an Add-ons drawer.

Ship the first-party add-ons (voice, face, fine-tuning, quantization) as
packages for linux/amd64, linux/arm64 and darwin/arm64. Intel macOS
(darwin/amd64) is enabled in the platform files.

Squashed from the review branch. The tree is unchanged; the pre-squash
history is kept on a local backup branch.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-10-20 20:54:43 +00:00

45 lines
1.5 KiB
Go

// SPDX-License-Identifier: MIT
package config
import (
"fmt"
"regexp"
"strings"
)
// DefaultAddonHostOps names the add-ons that may call host operations, and
// the operation prefixes each may call. It is a host setting: neither a
// manifest field nor a model argument can add to it.
const DefaultAddonHostOps = "fine-tuning=finetune.,quantization=quantize."
var (
addonIDForHostOps = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
hostOpPrefix = regexp.MustCompile(`^[a-z]+\.([a-z]+\.)*$`)
)
// ParseAddonHostOps reads a comma list of addon-id=op-prefix pairs. An add-on
// may appear more than once. An empty string names nobody.
func ParseAddonHostOps(s string) (map[string][]string, error) {
out := map[string][]string{}
for _, item := range strings.Split(s, ",") {
item = strings.TrimSpace(item)
if item == "" {
continue
}
id, prefix, ok := strings.Cut(item, "=")
id, prefix = strings.TrimSpace(id), strings.TrimSpace(prefix)
if !ok || !addonIDForHostOps.MatchString(id) || !hostOpPrefix.MatchString(prefix) {
return nil, fmt.Errorf("invalid host operation entry %q: want addon-id=op-prefix, such as fine-tuning=finetune.", item)
}
out[id] = append(out[id], prefix)
}
return out, nil
}
// WithAddonHostOps sets which add-ons may call which host operations.
// Without this option no add-on gets a host operation endpoint; the run
// command passes the default setting.
func WithAddonHostOps(ops map[string][]string) AppOption {
return func(o *ApplicationConfig) { o.AddonHostOps = ops }
}