Documentation
    Preparing search index...

    @kehto/rate-limit/legacy — Explicit legacy behavioral controls; not scoped approval authority.

    Zero dependencies. Zero side effects. All functions are pure: config + state + observation in, decision + next-state out. Designed for deterministic rate-limiting decisions that could be compiled to WASM without modification (the WASM-ready boundary).

    import { evaluate, defaultConfig, createState } from '@kehto/rate-limit/legacy';

    // Create default config with conservative built-in limits
    const config = defaultConfig();
    // config.defaultRate.action === 'flag' (allow + audit)
    // config.burstGuard.action === 'block' (stop init floods)
    // config.unfocusedMultiplier === 0.25 (tighten background napplets)

    // Create empty ephemeral counter state (reset on reload)
    let state = createState();

    // Build the observation from the protocol envelope (Phase 81 concern)
    const obs = {
    napplet: 'chat',
    opClass: 'relay:write',
    kind: 1,
    focused: true,
    now: 1_000_000, // injected — evaluate() never reads a wall clock
    };

    // Evaluate — pure, no side effects
    const result = evaluate(config, state, obs);
    // result.decision === 'pass' | 'reject' | 'prompt'
    // result.action === 'flag' | 'block' | 'ignore'
    // result.ruleId === 'rate:default' | 'burst' | 'policy:deny' | ...
    // result.reason === human-readable reason string
    // result.newState — updated token-bucket state; advance for next call
    state = result.newState;

    Interfaces

    Bucket
    BurstCounter
    BurstGuard
    ContentMatcher
    EvaluateResult
    FirewallConfig
    FirewallPersistence
    FirewallState
    FirewallStateContainer
    NappletRules
    Observation
    RateLimit

    Type Aliases

    Action
    Decision
    NappletPolicy

    Variables

    DEFAULT_BURST_ACTION
    DEFAULT_BURST_MAX_OPS
    DEFAULT_BURST_WINDOW_MS
    DEFAULT_EXCEED_ACTION
    DEFAULT_RATE_CAPACITY
    DEFAULT_RATE_WINDOW_MS
    DEFAULT_UNFOCUSED_MULTIPLIER

    Functions

    addMatcher
    createFirewallState
    createState
    defaultConfig
    deserialize
    evaluate
    serialize
    setBurstGuard
    setGlobalRate
    setPolicy
    setRateLimit
    setUnfocusedMultiplier
    toKey