MingaAgent.Credentials (Minga v0.1.0)

Copy Markdown View Source

API key storage, resolution, and management for agent providers.

Keys are stored in ~/.config/minga/credentials.json with restrictive file permissions (0600). Environment variables always take precedence over stored keys so existing setups are never broken.

Resolution order:

  1. Environment variable (e.g. ANTHROPIC_API_KEY)
  2. Credentials file

Keys are never logged, never included in session exports, and never sent to *Messages*.

Summary

Types

Source where a key was found.

A supported provider name.

Status entry for a single provider.

Owner-visible credential readiness.

Functions

Returns true if any local API-key or OAuth credential is configured.

Returns the API key dashboard URL for a provider, or nil if unknown.

Returns the environment variable name for a provider, or nil if unknown.

Returns the list of known provider names.

Returns the path to ~/.config/minga/oauth.json (XDG-aware).

Pins the exact OpenAI Codex account in Minga's explicit OAuth file.

Resolves one tagged credential reference for a single ReqLLM request.

Resolves an API key for the given provider.

Removes a stored API key for a provider.

Acquires one secret-free local credential snapshot.

Returns local authentication status for each hosted provider.

Stores an API key for a provider in the credentials file.

Types

key_source()

@type key_source() :: :env | :file | :oauth | nil

Source where a key was found.

provider()

@type provider() :: String.t()

A supported provider name.

provider_status()

@type provider_status() :: MingaAgent.Credentials.ProviderStatus.t()

Status entry for a single provider.

readiness()

@type readiness() :: :checking | :configured | :unconfigured

Owner-visible credential readiness.

Functions

any_configured?(source \\ [])

@spec any_configured?(keyword() | MingaAgent.Credentials.Snapshot.t()) :: boolean()

Returns true if any local API-key or OAuth credential is configured.

This predicate never probes the network.

dashboard_url_for(provider)

@spec dashboard_url_for(provider()) :: String.t() | nil

Returns the API key dashboard URL for a provider, or nil if unknown.

env_var_for(provider)

@spec env_var_for(provider()) :: String.t() | nil

Returns the environment variable name for a provider, or nil if unknown.

known_providers()

@spec known_providers() :: [provider()]

Returns the list of known provider names.

oauth_path()

@spec oauth_path() :: String.t()

Returns the path to ~/.config/minga/oauth.json (XDG-aware).

pin_oauth(atom, path)

@spec pin_oauth(:openai_codex, String.t()) ::
  {:ok, MingaAgent.ModelSelection.Credential.OAuth.t()} | {:error, term()}

Pins the exact OpenAI Codex account in Minga's explicit OAuth file.

ReqLLM owns refresh locking and persistence. Tokens returned while pinning are discarded; only the provider, provider key, account id, and exact path remain.

request_options(credential, opts)

@spec request_options(MingaAgent.ModelSelection.credential_ref(), keyword()) ::
  {:ok, keyword()} | {:error, {:credential_unavailable, String.t()}}

Resolves one tagged credential reference for a single ReqLLM request.

API-key sources are exact. OAuth is refreshed by ReqLLM from Minga's explicit file and the returned provider, file, and account identities must match the pin before the access token is exposed to the caller.

resolve(provider, opts \\ [])

@spec resolve(provider(), keyword()) :: {:ok, String.t(), key_source()} | :error

Resolves an API key for the given provider.

Checks the environment variable first, then the credentials file. Returns {:ok, key, source} if found, or :error if no key is configured anywhere.

revoke(provider, opts \\ [])

@spec revoke(provider(), keyword()) :: :ok | {:error, term()}

Removes a stored API key for a provider.

Only removes from the credentials file. Environment variables are unaffected (and will still be used if set).

snapshot(opts \\ [])

Acquires one secret-free local credential snapshot.

The credentials file is read once. Environment values retain precedence over stored values, and only their configured source is retained.

status(source \\ [])

Returns local authentication status for each hosted provider.

Each entry shows whether a key is configured and where it was found (:env, :file, :oauth, or nil). Keys themselves are never exposed.

store(provider, key, opts \\ [])

@spec store(provider(), String.t(), keyword()) :: :ok | {:error, term()}

Stores an API key for a provider in the credentials file.

Creates the config directory and file if they don't exist. Sets file permissions to 0600 (owner read/write only).