Documentation
¶
Overview ¶
Package providercreds manages the daemon's set of LLM provider credentials: named (provider, api_key, optional base_url) entries that agent frameworks inside islands use to reach a model. Keyed by provider id (the left side of a "provider/model" string, e.g. "openai", "anthropic"), the store is account-wide and reusable — one "anthropic" key serves every island whose agents target Anthropic. The daemon is the credential owner; a key is supplied once (`dejima provider set`) and materialized per-island into a single-provider .env file mounted read-only (see DotEnv / paths.LLMIslandConfigDir), never the whole set and never as a container env var.
This is the LLM-provider analog of internal/githubid: same locked, atomic-write store, same "materialize only what the island needs" posture. The key is a secret and is NEVER returned to clients — List() yields key-less Meta.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DotEnv ¶
DotEnv renders the generic KEY=value env file the daemon materializes per island and the per-agent shim sources. It carries the provider key under its env-var name and, when set, a "<PREFIX>_BASE_URL" override (PREFIX is the env-var name minus a trailing _API_KEY, matching the OPENAI_BASE_URL / ANTHROPIC_BASE_URL convention). It never contains anything but these.
func EnvVarName ¶
EnvVarName is the environment variable a framework reads this provider's key from: the explicit EnvVar override, else the de-facto convention UPPER(Name)+"_API_KEY" (e.g. "anthropic" → ANTHROPIC_API_KEY). Provider names aren't always valid env identifiers (e.g. "my-openrouter"), so non-alnum runs collapse to underscores.
Types ¶
type Meta ¶
type Meta struct {
Name string `json:"name"`
EnvVar string `json:"env_var"`
BaseURL string `json:"base_url,omitempty"`
Default bool `json:"default"`
KeySet bool `json:"key_set"`
Hint string `json:"hint,omitempty"` // masked tail, e.g. "…a1b2" — never the full key
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
Meta is a Provider without its key: the safe view to hand back to clients. The key itself is replaced by a masked Hint (last few chars only).
type Provider ¶
type Provider struct {
Name string `json:"name"` // provider id == "provider/model" prefix: "openai","anthropic","my-openrouter"
APIKey string `json:"api_key"` // secret — never returned to clients
BaseURL string `json:"base_url,omitempty"` // optional endpoint override (proxies, Azure, self-host)
EnvVar string `json:"env_var,omitempty"` // override the derived env name; default UPPER(Name)+"_API_KEY"
UpdatedAt time.Time `json:"updated_at,omitempty"` // last time the key was set
}
Provider is one LLM provider credential the daemon can supply to islands.
type Store ¶
type Store struct {
Default string `json:"default"`
Providers map[string]Provider `json:"providers"`
}
Store is the per-daemon provider set with one default.
func Load ¶
Load reads the store under the lock — a consistent snapshot for read-only use. Returns an empty (non-nil) store if none exists yet.
func Update ¶
Update runs fn against the store under a process-wide lock and persists the result atomically. Use it for every read-modify-write — Put/Remove/SetDefault.
func (*Store) Put ¶
Put adds or updates a provider (keyed by Name), stamping UpdatedAt. The first provider added becomes the default.
func (*Store) Remove ¶
Remove deletes a provider. If it was the default, the default falls to the first remaining provider (by name), or is cleared when none remain.
func (*Store) Resolve ¶
Resolve returns the provider for name, or the default when name is empty. ok is false when nothing matches (unknown name, or empty name with no default).
func (*Store) SetDefault ¶
SetDefault marks name as the default provider.