Documentation
¶
Overview ¶
Package config loads remora's runtime settings from the environment.
Index ¶
- Constants
- Variables
- func EnvName(provider, key string) string
- func Marshal(f File) ([]byte, error)
- func SecretRef(v string) (string, error)
- type Aliases
- type ApplyError
- type Batch
- type Change
- type Config
- type Cooling
- type CoolingMember
- type File
- type FileAlias
- type FileKey
- type FileProvider
- type FileSecretKey
- type Key
- type KeyPatch
- type Keys
- type Ports
- type Provider
- type ProviderKey
- type ProviderTest
- type Providers
- type Secrets
- type Service
Constants ¶
const ( EnvListen = "REMORA_LISTEN" EnvData = "REMORA_DATA" EnvAdminPassword = "REMORA_ADMIN_PASSWORD" //nolint:gosec // G101: a variable name, not a credential. EnvLogLevel = "REMORA_LOG_LEVEL" EnvEngineDir = "REMORA_ENGINE_DIR" EnvMasterKey = "REMORA_MASTER_KEY" EnvPortRouter = "REMORA_PORT_ROUTER" EnvPortAccounts = "REMORA_PORT_ACCOUNTS" EnvPortSpeech = "REMORA_PORT_SPEECH" EnvSonioxBaseURL = "REMORA_SONIOX_BASE_URL" EnvSonioxPollInterval = "REMORA_SONIOX_POLL_INTERVAL" EnvSonioxDeadline = "REMORA_SONIOX_DEADLINE" EnvSonioxSweepInterval = "REMORA_SONIOX_SWEEP_INTERVAL" EnvCooling429Count = "REMORA_COOLING_429_COUNT" EnvCooling429Window = "REMORA_COOLING_429_WINDOW" EnvCoolingDefault = "REMORA_COOLING_DEFAULT" EnvCoolingPoll = "REMORA_COOLING_POLL" )
Environment variables read by Load.
const ( DefaultListen = ":8080" DefaultDataDir = "/data" DefaultEngineDir = "/usr/local/lib/remora/engines" DefaultPortRouter = 18080 DefaultPortAccounts = 18317 DefaultPortSpeech = 18090 DefaultSonioxBaseURL = "https://api.soniox.com" DefaultSonioxPollInterval = time.Second DefaultSonioxDeadline = 30 * time.Minute DefaultSonioxSweepInterval = 10 * time.Minute DefaultCooling429Count = 3 DefaultCooling429Window = 60 * time.Second DefaultCoolingDefault = 5 * time.Minute DefaultCoolingPoll = time.Second )
Defaults applied when a variable is unset or empty.
Variables ¶
var ErrInvalid = errors.New("remora.yaml")
ErrInvalid marks a document that cannot be planned against the store, such as a new resource whose secret is not set. Its text is meant for the caller.
Functions ¶
func EnvName ¶
EnvName names the environment variable that holds a secret: a provider key is "REMORA_PROVIDER_<PROVIDER>_<KEY>", a client key (provider "") is "REMORA_KEY_<NAME>". Letters are upper-cased and every other character that is not a letter or digit becomes "_".
Types ¶
type Aliases ¶
type Aliases interface {
List(ctx context.Context) ([]alias.Alias, error)
Get(ctx context.Context, name string) (alias.Alias, error)
Put(ctx context.Context, a alias.Alias, create bool) (alias.Alias, error)
Delete(ctx context.Context, name string) error
Chain(ctx context.Context, name string) ([]alias.Target, error) // compiled, before cooling
Compile(ctx context.Context, a alias.Alias) ([]alias.Target, error) // an unsaved alias against the stored ones; stores nothing
Cooling(ctx context.Context) ([]CoolingMember, error)
}
Aliases manages aliases. alias.ErrCycle, ErrDepth and ErrUnknownMember pass through.
type ApplyError ¶
ApplyError is the failure of one change during Apply.
func (*ApplyError) Error ¶
func (e *ApplyError) Error() string
func (*ApplyError) Unwrap ¶
func (e *ApplyError) Unwrap() error
type Batch ¶ added in v0.2.0
Batch runs fn so that the port writes made under the context it gets are committed together or not at all.
type Change ¶
Change is one difference between a document and the store. Op is "create", "update" or "delete"; Kind is "provider", "alias" or "key"; Fields lists the fields an update changes ("members", "allow", "keys", "base_url", ...) and is empty, not nil, for create and delete. Value is set only on a client key that Apply created with a generated value, so that it can be shown once.
type Config ¶
type Config struct {
Listen string // REMORA_LISTEN, default ":8080"
DataDir string // REMORA_DATA, default "/data"
AdminPassword string // REMORA_ADMIN_PASSWORD, "" = generate at first boot
LogLevel slog.Level // REMORA_LOG_LEVEL, default info
EngineDir string // REMORA_ENGINE_DIR, default "/usr/local/lib/remora/engines"
MasterKey string // REMORA_MASTER_KEY, "" = $REMORA_DATA/master.key
Ports Ports // REMORA_PORT_ROUTER, REMORA_PORT_ACCOUNTS, REMORA_PORT_SPEECH
// The speech-to-text adapter.
SonioxAddr string // "127.0.0.1:" + Ports.Soniox
SonioxBaseURL string // REMORA_SONIOX_BASE_URL, default "https://api.soniox.com"
SonioxPollInterval time.Duration // REMORA_SONIOX_POLL_INTERVAL, default 1s
SonioxDeadline time.Duration // REMORA_SONIOX_DEADLINE, default 30m
SonioxSweepInterval time.Duration // REMORA_SONIOX_SWEEP_INTERVAL, default 10m
Cooling Cooling // REMORA_COOLING_*
}
Config is remora's runtime configuration.
type Cooling ¶
type Cooling struct {
Count429 int // REMORA_COOLING_429_COUNT, default 3: 429s within Window429 that cool a member
Window429 time.Duration // REMORA_COOLING_429_WINDOW, default 60s
Default time.Duration // REMORA_COOLING_DEFAULT, default 5m: cooldown when the upstream gave no retry hint
Poll time.Duration // REMORA_COOLING_POLL, default 1s: how often the front door's log is read
}
Cooling tunes when an alias member that keeps failing is left out of its chains, and how often the front door's log is read for failures.
type CoolingMember ¶
CoolingMember is a target that is cooling down after failures.
type File ¶
type File struct {
Version int `yaml:"version,omitempty"` // 1; 0 is read as 1
Providers []FileProvider `yaml:"providers"`
Aliases []FileAlias `yaml:"aliases"`
Keys []FileKey `yaml:"keys"`
}
File is the one remora.yaml format: the providers, aliases and client keys `remora apply -f` makes the store match. Plan 05 extends it (export, diff, a JSON Schema) without a second set of types.
type FileAlias ¶
type FileAlias struct {
Name string `yaml:"name"`
Kind string `yaml:"kind"`
Members []string `yaml:"members"`
Capabilities []string `yaml:"capabilities,omitempty"`
ContextWindow int `yaml:"context_window,omitempty"`
Strategy string `yaml:"strategy,omitempty"` // "round-robin" spreads requests; omitted tries members in order
}
FileAlias is an alias and its ordered members (aliases or "<provider>/<model>").
type FileKey ¶
type FileKey struct {
Name string `yaml:"name"`
Value string `yaml:"value,omitempty"`
Allow []string `yaml:"allow"`
Enabled *bool `yaml:"enabled,omitempty"` // default true
}
FileKey is a client key. Value is "env:NAME"; when it is omitted on a new key, apply generates one and prints it once.
type FileProvider ¶
type FileProvider struct {
Name string `yaml:"name"`
Kind string `yaml:"kind"` // builtin | openai-compatible | typesafe-compatible | soniox
Type string `yaml:"type,omitempty"` // builtin only, e.g. openrouter
BaseURL string `yaml:"base_url,omitempty"`
AllowPrivateNetwork bool `yaml:"allow_private_network,omitempty"`
Keys []FileSecretKey `yaml:"keys"`
}
FileProvider is an upstream provider and its keys.
type FileSecretKey ¶
FileSecretKey is one provider key. Value must be "env:NAME": a secret never sits in the file.
type Keys ¶
type Keys interface {
List(ctx context.Context) ([]Key, error)
Get(ctx context.Context, id string) (Key, error)
Create(ctx context.Context, name string, allow []string, value string, enabled bool) (Key, string, error) // value "" → generated; returns the value
Update(ctx context.Context, id string, p KeyPatch) (Key, error)
SetValue(ctx context.Context, id, value string) error // apply/import replacing a key's value
MatchesValue(ctx context.Context, id, value string) (bool, error)
Delete(ctx context.Context, id string) error
}
Keys manages client keys.
type Ports ¶
type Ports struct {
Bifrost int // REMORA_PORT_ROUTER
CLIProxyAPI int // REMORA_PORT_ACCOUNTS
Soniox int // REMORA_PORT_SPEECH
}
Ports are the loopback ports of the internal processes. The Go fields name the engines; the variables that set them are neutral.
type Provider ¶
type Provider struct {
Name, Kind, Type, BaseURL string
AllowPrivateNetwork bool
Keys []ProviderKey
}
Provider is an upstream reached with API keys.
type ProviderKey ¶
type ProviderKey struct{ Name, Value string }
ProviderKey is one credential of a provider. Value is never serialised by handlers.
type ProviderTest ¶
ProviderTest is the result of a provider connectivity test.
type Providers ¶
type Providers interface {
List(ctx context.Context) ([]Provider, error)
Get(ctx context.Context, name string) (Provider, error)
Create(ctx context.Context, p Provider) (Provider, error)
Update(ctx context.Context, p Provider) (Provider, error) // empty Keys = keep stored keys
Delete(ctx context.Context, name string) error
Test(ctx context.Context, name string) (ProviderTest, error)
}
Providers manages providers. Engine failures roll the store back and are returned.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service plans and applies remora.yaml documents and exports the store as one, through the management ports.
func NewService ¶
NewService returns a Service over the provider, alias and client key ports; Apply makes its writes in one batch.
func (*Service) Apply ¶
Apply makes the store match want, change by change in Plan's order (see Plan for matching, secrets and prune), and returns the changes it made. The changes are made in one Batch: when one fails, none is kept, and the error is an *ApplyError naming the change that failed. A client key created without a value gets a generated one, returned once in its Change's Value.
func (*Service) Export ¶
Export returns the store as a document: every provider with its keys as env:NAME references (EnvName), every alias, and every client key without its value. A provider whose kind a document cannot hold is left out.
func (*Service) Plan ¶
Plan returns the changes that would make the store match want, in the order Apply makes them; it changes nothing. Providers are matched by name, provider keys by provider and key name, aliases and client keys by name. A secret "env:NAME" is sec[NAME]: when NAME is absent the stored secret is kept, and a resource that does not exist yet is an ErrInvalid error naming it. With prune, what the store has and want does not is deleted; without it nothing is deleted, not even a provider key want leaves out.