gatewayconfig

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gatewayconfig builds and reconciles the gateway's provider configuration from Kram's local stores — the catalog of known providers (internal/providercatalog), user-registered custom endpoints (internal/customprovider), and saved credentials (internal/credentials).

It was extracted out of cmd/kram's package main so this logic — the most subtle config code in the project, and the one with a documented split-brain bug (see Reconcile) — is exercised by real unit tests instead of living in the least-testable place, and so a second entrypoint (e.g. cmd/gateway) can reuse the exact same reconciliation rather than reinventing it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detect

func Detect(strategyOverride string, credStore *credentials.Store, logger *slog.Logger) (*config.Config, error)

Detect builds a single-combo gateway config from whichever providercatalog.Providers have a real credential available: their API-key env var set (a real env var, or a key loaded from the local credentials store and os.Setenv'd by LoadStoredCredentials before this runs), or — for a provider connected via browser login (SupportsOAuth) rather than a pasted/exported key — a refreshable OAuth token in credStore, in which case AuthMode is set to "oauth" so the gateway resolves it live instead of expecting a static env var (see internal/gateway.Run). credStore may be nil (no OAuth-based providers will be found in that case, same as before this parameter existed). Order is deterministic (the catalog's order), which also becomes the round-robin combo order.

Every registered internal/customprovider entry is also included, unconditionally — unlike a catalog provider, a custom one's mere existence in that store *is* the "configured" signal, since its API key is optional (most local/LAN servers have no auth) and there's no env var whose presence would otherwise say "use this one".

func LoadStoredCredentials

func LoadStoredCredentials()

LoadStoredCredentials exports every key saved via the CLI's accounts screen into this process's environment, skipping any env var that's already set — a real exported env var always takes priority over a stored one, so this only fills gaps. Best-effort: a missing or unreadable credentials file just means nothing gets filled in, not a startup failure — the shell-env path still works exactly as before this existed.

func Reconcile

func Reconcile(cfg *config.Config, credStore *credentials.Store, logger *slog.Logger) *config.Config

Reconcile additively merges any providercatalog entry now backed by a real credential, and any registered internal/customprovider entry, that isn't already present in cfg's Providers by ID, into cfg — without touching any field on a Provider entry that's already there, and without touching Strategy, StrategyOptions, Response, or any combo besides appending to DefaultCombo's own Providers list. This is what makes an account or custom provider added via the Accounts UI *after* a config.yaml already existed actually take effect on the next boot, instead of staying invisible until the file is hand-edited or deleted — the bug this function exists to fix. Every newly-added provider is appended to the *end* of DefaultCombo's list (lowest priority), a deliberately conservative choice: it can only ever win once every hand-configured provider in that combo is unhealthy, so a hand-tuned priority ordering is never silently reshuffled. If cfg has nothing new to add, cfg is returned unchanged (no spurious copy, no log lines).

Not called for the pure-autodetect fallback tier (no file was loaded at all) — that path already calls Detect fresh on every boot and has nothing stale to reconcile against.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL