policy/types.bend checks
raw source on the hub · import cswap-bend-cli@0.1.0.0/policy/types.bend as Types
1 import
import Base
Types
type AcctKind source · line 13 · raw
Data
SetupTokenAcctKind
FullLoginAcctKind
ApiKeyAcctKind
type Account source · line 18 · raw
Data
Account@slot:Nat -> @email:String -> @kind:AcctKind -> @disabled:Bool -> Account
type Scoped source · line 22 · raw
Data
A per-model scoped window (Opus, Fable, ...).
Scoped@name:String -> @pct:Nat -> @reset:Maybe<&2, Nat> -> Scoped
type ErrKind source · line 25 · raw
Data
ErrNoneErrKind
ErrHttp429ErrKind
ErrOtherErrKind
type Sentinel source · line 41 · raw
Data
NoSentinelSentinel
TokenExpiredSentinel
OtherSentinelSentinel
type Usage source · line 48 · raw
Data
One account's usage row. five/seven are None when the API sent no such
window. fetched_at is None before the first success.
Usage@slot:Nat -> @five:Maybe<&2, Nat> -> @five_reset:Maybe<&2, Nat> -> @seven:Maybe<&2, Nat> -> @seven_reset:Maybe<&2, Nat> -> @scoped:List<&2, Scoped> -> @fetched_at:Maybe<&2, Nat> -> @backoff_until:Nat -> @last_error:ErrKind -> @failures:Nat -> @next_poll_at:Maybe<&2, Nat> -> @poll_interval:Nat -> @auth_dead:Nat -> @held_until:Nat -> @claim_until:Nat -> @sentinel:Sentinel -> Usage
type Win source · line 52 · raw
Data
One relevant window: the utilization and, if the API sent one, its reset.
Win@pct:Nat -> @reset:Maybe<&2, Nat> -> Win
type Strategy source · line 55 · raw
Data
BestStrategy
ConsumeFirstStrategy
type Config source · line 59 · raw
Data
Config@threshold:Nat -> @models:List<&2, String> -> @strategy:Strategy -> @interval:Nat -> @cooldown:Nat -> @hysteresis:Nat -> @serve_ttl:Nat -> @unhealthy_ticks:Nat -> @include_api:Bool -> Config
type Trigger source · line 72 · raw
Data
ProactiveTrigger
AtLimitTrigger
FailoverTrigger
ConsumeFirstTTrigger
type Snap source · line 81 · raw
Data
What the last switch recorded (autoswitch_state.json): the headroom and
binding recovery of the account it left, and the trigger. NoSnap is a
record written before the snapshot existed.
NoSnapSnap
Snap@headroom:Maybe<&2, Nat> -> @recovery:Maybe<&2, Nat> -> @trigger:Maybe<&2, Trigger> -> Snap
type State source · line 85 · raw
Data
State@last_at:Maybe<&2, Nat> -> @last_to:Maybe<&2, Nat> -> @last_from:Maybe<&2, Nat> -> @snap:Snap -> State
type Mem source · line 90 · raw
Data
The engine's in-memory counters: consecutive unhealthy ticks, and when the
idle hold for an expired token began. Mem{0n, None{}} is a fresh process.
Mem@unhealthy:Nat -> @idle_since:Maybe<&2, Nat> -> Mem
type Reason source · line 93 · raw
Data
UnmanagedActiveReason
ActiveApiKeyReason
BelowThresholdReason
ActiveIdleReason
ActiveUsageUnknownReason
CooldownReason
NoCandidatesReason
NoComparisonReason
ResetUnknownReason
AlreadyConsumingSoonestReason
NoQualifyingCandidateReason
AllExhausted@earliest:Maybe<&2, Nat> -> Reason
type Mode source · line 111 · raw
Data
How the target was ranked: by headroom (MHead), by weekly reset
(consume-first, MReset), by recovery (all accounts above the threshold:
MRec0 back soon, MRec1 back late, MFallback the one-way fallback), or
as the last-resort API-key account (MApiLast).
MHeadMode
MResetMode
MRec0Mode
MRec1Mode
MFallbackMode
MApiLastMode
type Decision source · line 121 · raw
Data
Switch.rec is the winner's ranking time (reset or recovery) when the mode
ranks by one; bar is the no-return bar that applied to this pick.
NoSwitch@reason:Reason -> @detail:String -> Decision
Switch@to:Nat -> @trigger:Trigger -> @reason:String -> @headroom:Nat -> @mode:Mode -> @rec:Maybe<&2, Nat> -> @bar:Maybe<&2, Nat> -> Decision
Definitions
def failing source · line 34 · raw
@+e:ErrKind -> Nat
A derived state laid over a stored row at read time. TokenExpired is the
idle-Claude-Code sentinel; every sentinel hides the row's windows.
0 when the last fetch left no error, else 1: how a row built without a
stored failure count says whether it is failing.
def full source · line 125 · raw
Nat
def default_config source · line 128 · raw
Config
def fresh_state source · line 131 · raw
State
def fresh_mem source · line 134 · raw
Mem
def reason.name.more source · line 139 · raw
@+r:Reason -> String
def reason.name source · line 156 · raw
@+r:Reason -> String
def trigger.name source · line 171 · raw
@+t:Trigger -> String
def reason.exit source · line 183 · raw
@+r:Reason -> U32
Exit codes of auto --once: 0 switched, 2 no action, 3 blocked.
def exit_code source · line 196 · raw
@+d:Decision -> U32