import type { UsageEntry } from './usage-store.js'; /** * Reading a cached usage entry as CURRENT capacity rather than as history. * * The snapshot is a cache, and utilization only climbs while a window is open. * The moment a window resets, the stored number is not merely old, it is wrong: * it reports "spent" about a limit that has already lifted. Acting on that moves * a session off a model it could still be using, and announces a limit that no * longer exists. * * Every stored number carries the time its window resets, so this needs no * guess about staleness: a number past its own reset is simply expired. */ export interface UsableCapacity { /** Per-model utilization, with expired windows left out entirely. */ models: Record; /** Whether an account-wide window is at its limit and still closed. */ accountWideOut: boolean; } /** * The parts of a usage entry this actually reads. * * Declared structurally rather than as the whole stored entry, so a caller * holding the same windows in a different shape does not have to assert its * way in. A cast there would keep compiling if the windows were ever dropped, * and `accountWideOut` would quietly become false: an account reported as * usable when every window on it is spent. */ export type CapacityWindows = Pick & Partial>; /** * How much headroom an account has left, as a fraction 0..1 (1 = untouched, * 0 = spent), on its BINDING account-wide window: the tighter of the 5-hour and * weekly limits. Higher means less used. * * This is the "how heavily has this account been used overall" metric the * least-used ordering sorts by. It is deliberately account-wide, not per-model: * which MODEL to run is the planner's job, while this answers which ACCOUNT has * the most room to give. An account with no usage read yet counts as fully open * (1), so a brand-new or just-reset account is treated as least-used, which is * exactly what it is. */ export declare function remainingRoom(entry: CapacityWindows | undefined, now: number): number; /** What an account can still be asked to do, according to `entry`, right now. */ export declare function usableCapacity(entry: CapacityWindows | undefined, now: number): UsableCapacity;