Converts Claude Code's plan-usage data to Minga's MingaAgent.InferenceRoute.PlanWindow values.
Two sources describe the same windows:
- The
get_usagecontrol request answers withrate_limits, where each window (five_hour,seven_day, andseven_day_*variants such asseven_day_opus) is eithernullor an object withutilizationas a percent from 0 to 100,resets_atas an ISO 8601 string, andlocked_reason.from_get_usage/1reads every non-null window. Its status is:rejectedwhenlocked_reasonis set or utilization reaches 100%,:warningfrom 80%, and:allowedbelow. - A
rate_limit_eventduring a turn reports one window's status and reset time, and sometimes its utilization.apply_rate_limit/2updates that window's status and reset time, takes the event's utilization when present (a fraction from 0 to 1, or a percent when above 1), and otherwise keeps the last known utilization.
The latest source wins for the fields it carries. get_usage refreshes every window; a rate_limit_event refreshes one window's status. Account data never passes through this module.
Summary
Functions
Updates the window a rate_limit_event describes. Events without a window type change nothing.
Reads the plan windows of a get_usage answer.
Returns the plan label of a get_usage answer, for example "Claude Max" for "max", or nil.
Returns the windows in display order: five-hour, seven-day, then the others by kind.
Types
@type windows() :: %{required(String.t()) => MingaAgent.InferenceRoute.PlanWindow.t()}
Windows keyed by kind.
Functions
@spec apply_rate_limit(windows(), MingaClaudeBridge.Wire.RateLimit.t()) :: windows()
Updates the window a rate_limit_event describes. Events without a window type change nothing.
Reads the plan windows of a get_usage answer.
Returns the plan label of a get_usage answer, for example "Claude Max" for "max", or nil.
@spec to_list(windows()) :: [MingaAgent.InferenceRoute.PlanWindow.t()]
Returns the windows in display order: five-hour, seven-day, then the others by kind.