MingaClaudeBridge.Route.PlanUsage (minga_claude_bridge v0.1.0)

Copy Markdown View Source

Converts Claude Code's plan-usage data to Minga's MingaAgent.InferenceRoute.PlanWindow values.

Two sources describe the same windows:

  • The get_usage control request answers with rate_limits, where each window (five_hour, seven_day, and seven_day_* variants such as seven_day_opus) is either null or an object with utilization as a percent from 0 to 100, resets_at as an ISO 8601 string, and locked_reason. from_get_usage/1 reads every non-null window. Its status is :rejected when locked_reason is set or utilization reaches 100%, :warning from 80%, and :allowed below.
  • A rate_limit_event during a turn reports one window's status and reset time, and sometimes its utilization. apply_rate_limit/2 updates 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

Types

Windows keyed by kind.

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

windows()

@type windows() :: %{required(String.t()) => MingaAgent.InferenceRoute.PlanWindow.t()}

Windows keyed by kind.

Functions

apply_rate_limit(windows, event)

@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.

from_get_usage(arg1)

@spec from_get_usage(map()) :: windows()

Reads the plan windows of a get_usage answer.

plan_label(arg1)

@spec plan_label(map() | nil) :: String.t() | nil

Returns the plan label of a get_usage answer, for example "Claude Max" for "max", or nil.

to_list(windows)

Returns the windows in display order: five-hour, seven-day, then the others by kind.