Holds the route's last known readiness and plan limits, and reports changes to Minga.
- Availability results are cached per credential for a short time, so opening
/modelrepeatedly does not start Claude Code every time. - Sessions send their
rate_limit_events here. Arejectedstatus reports the route as{:unavailable, :rate_limited, remedy}with the reset time; the next allowed status reports it ready again with the last plan label. - Plan windows (
MingaAgent.InferenceRoute.PlanWindow) come fromget_usageanswers (put_usage/2) and rate-limit events, merged byMingaClaudeBridge.Route.PlanUsage. Every change is reported withMinga.Extension.ModelRoutes.report_usage/2. - The models of the last probe and the measured context windows feed
MingaClaudeBridge.Route.models/1. Windows are cached per credential and model with their measurement time. - Background measurements run under a
Task.Supervisor, at most one per credential at a time (start_measurement/3).
Reports go through the reporter MingaClaudeBridge received when it registered the route. The reporter and both report functions are options so tests can observe reports.
Summary
Functions
Returns a cached availability for key when it is younger than ttl milliseconds.
Returns a specification to start this module under a supervisor.
Returns the most recently measured context window in tokens per model id, across credentials. Empty before the first measurement.
Returns the latest rate-limit event, or nil.
Returns the remedy text for a reached plan limit.
Returns the model entries of Claude Code's last initialize answer, or nil before the first probe or when the server is not running.
Returns the current plan windows in display order.
Caches an availability result for key.
Records the context windows measured for credential key. Models it could not measure keep their earlier value.
Records the model entries of a probe.
Stores the reporter from route registration for every later status server.
Records a get_usage answer read with credential key: refreshes every plan window and reports them. An answer without windows reports an empty list, so Minga clears stale windows.
Records a rate-limit event, as sessions do with their :on_rate_limit pid.
Returns the ids among model_ids whose window for credential key is missing or older than ttl milliseconds.
Starts the status server.
Starts fun as the background measurement for credential key under the task supervisor. Returns :busy while a measurement for key runs and :unavailable without a task supervisor.
Returns the plan label of the last get_usage answer for credential key, for example "Claude Max", or nil.
Types
Functions
@spec cached(GenServer.server(), term(), non_neg_integer()) :: {:ok, availability()} | :miss
Returns a cached availability for key when it is younger than ttl milliseconds.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec context_windows(GenServer.server()) :: %{required(String.t()) => pos_integer()}
Returns the most recently measured context window in tokens per model id, across credentials. Empty before the first measurement.
@spec latest_rate_limit(GenServer.server()) :: MingaClaudeBridge.Wire.RateLimit.t() | nil
Returns the latest rate-limit event, or nil.
Returns the remedy text for a reached plan limit.
@spec models(GenServer.server()) :: [map()] | nil
Returns the model entries of Claude Code's last initialize answer, or nil before the first probe or when the server is not running.
@spec plan_windows(GenServer.server()) :: [MingaAgent.InferenceRoute.PlanWindow.t()]
Returns the current plan windows in display order.
@spec put(GenServer.server(), term(), availability()) :: :ok
Caches an availability result for key.
@spec put_context_windows(GenServer.server(), term(), %{ required(String.t()) => pos_integer() }) :: :ok
Records the context windows measured for credential key. Models it could not measure keep their earlier value.
@spec put_models(GenServer.server(), [map()]) :: :ok
Records the model entries of a probe.
@spec put_reporter(term()) :: :ok
Stores the reporter from route registration for every later status server.
@spec put_usage(GenServer.server(), term(), map()) :: :ok
Records a get_usage answer read with credential key: refreshes every plan window and reports them. An answer without windows reports an empty list, so Minga clears stale windows.
When the account's own answer named no plan and this credential's last check was ready, the plan the usage names is reported as the new ready label.
@spec rate_limit(GenServer.server(), MingaClaudeBridge.Wire.RateLimit.t()) :: :ok
Records a rate-limit event, as sessions do with their :on_rate_limit pid.
@spec stale_models(GenServer.server(), term(), [String.t()], non_neg_integer()) :: [ String.t() ]
Returns the ids among model_ids whose window for credential key is missing or older than ttl milliseconds.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the status server.
Options: :name, :reporter (defaults to the stored reporter), :report (a two-argument function, defaults to Minga.Extension.ModelRoutes.report_status/2), :report_usage (a two-argument function, defaults to Minga.Extension.ModelRoutes.report_usage/2), :tasks (the Task.Supervisor for measurements; without it no measurement starts), and :notify (a pid that receives {:claude_bridge_measurement, :started | :finished, key}, for tests).
@spec start_measurement(GenServer.server(), term(), (-> term())) :: :ok | :busy | :unavailable
Starts fun as the background measurement for credential key under the task supervisor. Returns :busy while a measurement for key runs and :unavailable without a task supervisor.
@spec usage_label(GenServer.server(), term()) :: String.t() | nil
Returns the plan label of the last get_usage answer for credential key, for example "Claude Max", or nil.