quota

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FamilyFromHeader

func FamilyFromHeader(h http.Header) string

FamilyFromHeader infers provider family from response headers (best-effort).

func MarshalSummary

func MarshalSummary(summary struct {
	Percent int   `json:"percent"`
	Used    int64 `json:"used"`
	Limit   int64 `json:"limit"`
	Active  int   `json:"active"`
}) []byte

MarshalSummary is a JSON helper for the dashboard endpoint.

Types

type AccountQuota

type AccountQuota struct {
	Account  string           `json:"account"`
	Kind     string           `json:"kind"`
	Family   string           `json:"family"`
	Adapter  string           `json:"adapter"`
	Used     int64            `json:"used"`
	Limit    int64            `json:"limit"`
	Percent  int              `json:"percent"`
	ResetAt  *time.Time       `json:"reset_at,omitempty"`
	Status   string           `json:"status"`
	Enabled  bool             `json:"enabled"`
	SubQuota map[string]int64 `json:"sub_quota,omitempty"` // e.g. codex primary/secondary windows
}

AccountQuota is the aggregated live state for a single account.

type Guard

type Guard struct {
	AQ *AccountQuota
}

Guard is nil-safe read helper.

func (Guard) Percent

func (g Guard) Percent() int

type Observation

type Observation struct {
	Account   string
	Kind      string // oauth | cookie | free | api_key
	Family    string // claude | codex | cursor | copilot | kimi | gemini | deepseek | opencode | free
	Used      int64
	Limit     int64 // 0 = unknown/unlimited
	ResetAt   time.Time
	Status    string // active | exhausted | free
	Source    string // header | api | local
	Timestamp time.Time
}

Observation is a per-request quota signal collected from the upstream response (headers, codex credits) and local usage accounting.

func ParseHeaders

func ParseHeaders(h http.Header) (Observation, map[string]int64, bool)

ParseHeaders extracts quota signal from arbitrary upstream response headers. Supports codex-style x-*-primary/secondary-used-percent and reset-at, plus a generic X-Provider-Quota-* convention for provider adapters.

type Tracked

type Tracked struct {
	// contains filtered or unexported fields
}

func New

func New() *Tracked

func (*Tracked) Adopt

func (t *Tracked) Adopt(s *config.Snapshot)

Adopt syncs account presence/enabled state from a snapshot.

func (*Tracked) List

func (t *Tracked) List() []AccountQuota

List returns sorted per-account quota snapshot.

func (*Tracked) Observe

func (t *Tracked) Observe(o Observation)

Observe records a quota signal for an account.

func (*Tracked) ObserveRaw

func (t *Tracked) ObserveRaw(account string, kind string, family string, weights map[string]int64)

ObserveRaw aggregates codex-style per-window percentages (primary/secondary).

func (*Tracked) Summary

func (t *Tracked) Summary() (percent int, used, limit int64, active int)

Summary returns the combined percent for the overview bar.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL