core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountConfig

type AccountConfig struct {
	ID         string            `json:"id"`
	Provider   string            `json:"provider"`
	Auth       string            `json:"auth,omitempty"`        // "api_key", "oauth", "cli", "local", "token"
	APIKeyEnv  string            `json:"api_key_env,omitempty"` // env var name holding the API key
	ProbeModel string            `json:"probe_model,omitempty"` // model to use for probe requests
	Binary     string            `json:"binary,omitempty"`      // path to CLI binary
	BaseURL    string            `json:"base_url,omitempty"`    // custom API base URL (e.g. for OpenRouter)
	Token      string            `json:"-"`                     // runtime-only: access token (never persisted)
	ExtraData  map[string]string `json:"-"`                     // runtime-only: extra detection data
}

func (AccountConfig) ResolveAPIKey

func (c AccountConfig) ResolveAPIKey() string

type DashboardColorRole added in v0.2.0

type DashboardColorRole string
const (
	DashboardColorRoleAuto      DashboardColorRole = "auto"
	DashboardColorRoleGreen     DashboardColorRole = "green"
	DashboardColorRolePeach     DashboardColorRole = "peach"
	DashboardColorRoleLavender  DashboardColorRole = "lavender"
	DashboardColorRoleBlue      DashboardColorRole = "blue"
	DashboardColorRoleTeal      DashboardColorRole = "teal"
	DashboardColorRoleYellow    DashboardColorRole = "yellow"
	DashboardColorRoleSky       DashboardColorRole = "sky"
	DashboardColorRoleSapphire  DashboardColorRole = "sapphire"
	DashboardColorRoleMaroon    DashboardColorRole = "maroon"
	DashboardColorRoleFlamingo  DashboardColorRole = "flamingo"
	DashboardColorRoleRosewater DashboardColorRole = "rosewater"
)

type DashboardCompactRow added in v0.2.0

type DashboardCompactRow struct {
	Label       string
	Keys        []string
	Matcher     DashboardMetricMatcher
	MaxSegments int
}

type DashboardDisplayStyle added in v0.2.0

type DashboardDisplayStyle string
const (
	DashboardDisplayStyleDefault DashboardDisplayStyle = "default"
	// Detailed credits mode shows richer "remaining/today/week/models" messaging
	// when credit-like metrics are present.
	DashboardDisplayStyleDetailedCredits DashboardDisplayStyle = "detailed_credits"
)

type DashboardMetricGroupOverride added in v0.2.0

type DashboardMetricGroupOverride struct {
	Group string
	Label string
	Order int
}

type DashboardMetricMatcher added in v0.2.0

type DashboardMetricMatcher struct {
	Prefix string
	Suffix string
}

type DashboardRawGroup added in v0.2.0

type DashboardRawGroup struct {
	Label string
	Keys  []string
}

type DashboardResetStyle added in v0.2.0

type DashboardResetStyle string
const (
	DashboardResetStyleDefault DashboardResetStyle = "default"
	// Compact model resets mode groups many reset rows into model-oriented pills.
	DashboardResetStyleCompactModelResets DashboardResetStyle = "compact_model_resets"
)

type DashboardWidget added in v0.2.0

type DashboardWidget struct {
	DisplayStyle DashboardDisplayStyle
	ResetStyle   DashboardResetStyle
	ColorRole    DashboardColorRole
	// Opt-in client composition panel (client share + trend) in tile view.
	ShowClientComposition bool

	// API key provider metadata. APIKeyEnv marks a provider as configurable in API Keys tab.
	APIKeyEnv        string
	DefaultAccountID string

	// When ResetStyle is DashboardResetStyleCompactModelResets and the number of active
	// reset entries meets/exceeds this value, reset pills are grouped.
	ResetCompactThreshold int

	GaugePriority               []string
	GaugeMaxLines               int
	CompactRows                 []DashboardCompactRow
	RawGroups                   []DashboardRawGroup
	MetricLabelOverrides        map[string]string
	MetricGroupOverrides        map[string]DashboardMetricGroupOverride
	CompactMetricLabelOverrides map[string]string

	HideMetricKeys     []string
	HideMetricPrefixes []string
	// Hide key-level "credits" row when richer account-level balance metric is present.
	HideCreditsWhenBalancePresent bool

	// Hide noisy metrics that are often zero-value for this provider.
	SuppressZeroMetricKeys []string
	// Hide all zero-valued non-quota metrics.
	SuppressZeroNonQuotaMetrics bool
}

func DefaultDashboardWidget added in v0.2.0

func DefaultDashboardWidget() DashboardWidget

type DetailSection added in v0.3.0

type DetailSection struct {
	Name  string
	Order int
	Style DetailSectionStyle
}

type DetailSectionStyle added in v0.3.0

type DetailSectionStyle string
const (
	DetailSectionStyleUsage    DetailSectionStyle = "usage"
	DetailSectionStyleSpending DetailSectionStyle = "spending"
	DetailSectionStyleTokens   DetailSectionStyle = "tokens"
	DetailSectionStyleActivity DetailSectionStyle = "activity"
	DetailSectionStyleList     DetailSectionStyle = "list"
)

type DetailWidget added in v0.3.0

type DetailWidget struct {
	Sections []DetailSection
}

func DefaultDetailWidget added in v0.3.0

func DefaultDetailWidget() DetailWidget

func (DetailWidget) SectionOrder added in v0.3.0

func (w DetailWidget) SectionOrder(name string) int

func (DetailWidget) SectionStyle added in v0.3.0

func (w DetailWidget) SectionStyle(name string) DetailSectionStyle

type Engine

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

func NewEngine

func NewEngine(interval time.Duration) *Engine

func (*Engine) AddAccount added in v0.2.0

func (e *Engine) AddAccount(acct AccountConfig)

AddAccount appends an account (if not already present) and triggers a refresh for it.

func (*Engine) OnUpdate

func (e *Engine) OnUpdate(fn func(map[string]QuotaSnapshot))

func (*Engine) RefreshAll

func (e *Engine) RefreshAll(ctx context.Context)

func (*Engine) RegisterProvider

func (e *Engine) RegisterProvider(p QuotaProvider)

func (*Engine) Run

func (e *Engine) Run(ctx context.Context)

func (*Engine) SetAccounts

func (e *Engine) SetAccounts(accounts []AccountConfig)

func (*Engine) Snapshots

func (e *Engine) Snapshots() map[string]QuotaSnapshot

type Metric

type Metric struct {
	Limit     *float64 `json:"limit,omitempty"`
	Remaining *float64 `json:"remaining,omitempty"`
	Used      *float64 `json:"used,omitempty"`
	Unit      string   `json:"unit"`   // "requests", "tokens", "USD", "credits"
	Window    string   `json:"window"` // "1m", "1d", "month", "rolling-5h", etc.
}

func (Metric) Percent

func (m Metric) Percent() float64

type ProviderInfo

type ProviderInfo struct {
	Name         string   // e.g. "OpenAI", "Anthropic"
	Capabilities []string // "headers", "cli_stats", "usage_endpoint", "credits_endpoint"
	DocURL       string   // link to vendor's rate-limit documentation
}

type QuotaProvider

type QuotaProvider interface {
	ID() string

	Describe() ProviderInfo

	// DashboardWidget defines how provider metrics should be presented in dashboard tiles.
	DashboardWidget() DashboardWidget
	// DetailWidget defines how sections should be rendered in the details panel.
	DetailWidget() DetailWidget

	Fetch(ctx context.Context, acct AccountConfig) (QuotaSnapshot, error)
}

type QuotaSnapshot

type QuotaSnapshot struct {
	ProviderID  string                 `json:"provider_id"`
	AccountID   string                 `json:"account_id"`
	Timestamp   time.Time              `json:"timestamp"`
	Status      Status                 `json:"status"`
	Metrics     map[string]Metric      `json:"metrics"`                // keys like "rpm", "tpm", "rpd"
	Resets      map[string]time.Time   `json:"resets,omitempty"`       // e.g. "rpm_reset"
	Raw         map[string]string      `json:"raw,omitempty"`          // redacted header dump / CLI lines
	DailySeries map[string][]TimePoint `json:"daily_series,omitempty"` // time-indexed data (e.g. "messages", "cost", "tokens_<model>")
	Message     string                 `json:"message,omitempty"`      // human-readable summary
}

func (QuotaSnapshot) WorstPercent

func (s QuotaSnapshot) WorstPercent() float64

type Status

type Status string
const (
	StatusOK          Status = "OK"
	StatusNearLimit   Status = "NEAR_LIMIT"
	StatusLimited     Status = "LIMITED"
	StatusAuth        Status = "AUTH_REQUIRED"
	StatusUnsupported Status = "UNSUPPORTED"
	StatusError       Status = "ERROR"
	StatusUnknown     Status = "UNKNOWN"
)

type TimePoint

type TimePoint struct {
	Date  string  `json:"date"`  // "2025-01-15"
	Value float64 `json:"value"` // metric value at that date
}

Jump to

Keyboard shortcuts

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