The Web UI and messaging channels now read and write Archie's runtime settings through one versioned, audited control-plane API hosted on the State Store's existing gRPC server: catalog, query, command, watch. Each feature owns its resource, validation and commands; storage only writes versions and audit records. Workflows move with it. Definitions become portable YAML compiled through a closed, typed step registry and stored as a control-plane resource, so the yaegi interpretation paths (internal/gate, wfeval, wfextract, gateeval, gateextract, skillbuild) are deleted rather than carried. The UI process reads definitions as data: the JSON projection lives in internal/domain/workflow/task so a dashboard decodes the stored collection without linking the workflow engine, which cmd/archie-ui's deletion gate forbids. Shipped definitions ride the catalog descriptor rather than a bespoke REST route, keeping the API to its four operations. archie-messaging gains -state-store-target/-state-store-token and reads channel settings from the database, failing closed when the State Store is unreachable: the database is authoritative for those settings.
66 lines
2.3 KiB
Go
66 lines
2.3 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
)
|
|
|
|
const (
|
|
ProviderSettingsKind = "provider-settings"
|
|
ModelRoleAssignmentsKind = "model-role-assignments"
|
|
)
|
|
|
|
type providerDocument struct {
|
|
Class string `json:"class"`
|
|
APIKeyEnv string `json:"api_key_env,omitempty"`
|
|
APIKey config.SecretRef `json:"api_key_ref"`
|
|
BaseURL string `json:"base_url,omitempty"`
|
|
HasCredential bool `json:"has_credential"`
|
|
}
|
|
|
|
func modelDefinitions() []Definition {
|
|
return []Definition{
|
|
{Kind: ProviderSettingsKind, Title: "Providers", ApplyMode: "restart-required", Schema: objectSchema, Seed: seedProviders, Validate: validateProviders},
|
|
{Kind: ModelRoleAssignmentsKind, Title: "Model role assignments", ApplyMode: "restart-required", Schema: objectSchema, Seed: func(cfg config.Config) any { return cfg.Models }, Validate: validateModelRoles},
|
|
}
|
|
}
|
|
|
|
func seedProviders(cfg config.Config) any {
|
|
out := make(map[string]providerDocument, len(cfg.Providers))
|
|
for name, provider := range cfg.Providers {
|
|
out[name] = providerDocument{Class: provider.Class, APIKeyEnv: provider.APIKeyEnv, APIKey: provider.APIKey, BaseURL: provider.BaseURL, HasCredential: provider.APIKeyEnv != "" || provider.APIKey != (config.SecretRef{})}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func validateProviders(input []byte) error {
|
|
return validateAs(input, func(providers map[string]providerDocument) error {
|
|
for name, provider := range providers {
|
|
if strings.TrimSpace(name) == "" || strings.TrimSpace(provider.Class) == "" {
|
|
return fmt.Errorf("provider name and class are required")
|
|
}
|
|
if provider.BaseURL != "" {
|
|
parsed, err := url.Parse(provider.BaseURL)
|
|
if err != nil || parsed.Scheme == "" || parsed.Host == "" || parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" {
|
|
return fmt.Errorf("provider %q has invalid base_url", name)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func validateModelRoles(input []byte) error {
|
|
return validateAs(input, func(models map[string]string) error {
|
|
for role, model := range models {
|
|
if strings.TrimSpace(role) == "" || !strings.Contains(model, "/") {
|
|
return fmt.Errorf("model role %q must reference provider/model", role)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|