Help us shape the future of Go! Take the 2026 Go Developer Survey

usage

package
v0.19.10 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Event = "orb.usage"

Event is the extension bus channel on which a provider publishes a Reading it observed itself, such as limits reported alongside a turn; Client covers the providers read over HTTP.

Variables

View Source
var ErrUnavailable = errors.New("usage unavailable")

Functions

This section is empty.

Types

type Accounts added in v0.19.2

type Accounts interface {
	List(context.Context) ([]accounts.Account, error)
	Usage(ctx context.Context, provider, id string) (Snapshot, error)
	Use(ctx context.Context, provider, id string) error
}

Accounts is the host's account book: its connected accounts, their plan limits, and the switch between them. A plugin offers another account when one runs out only where the host supplies it.

type Cache

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

Cache bounds quota history to 64 account keys and coalesces concurrent reads. Keys are caller-owned account identities or credential digests, never raw credentials.

func (*Cache) Clear

func (c *Cache) Clear()

func (*Cache) Fetch

func (c *Cache) Fetch(ctx context.Context, key string, fetch func(context.Context) (Snapshot, error)) (Snapshot, error)

func (*Cache) Peek

func (c *Cache) Peek(key string) (Snapshot, bool)

type Client

type Client struct {
	Cache                   *Cache
	HTTPClient              *http.Client
	CodexURL, OpenCodeGoURL string
}

Client reads provider-reported quota only. URLs are injectable for tests and private deployments; credentials never follow redirects.

func (Client) Fetch

func (c Client) Fetch(ctx context.Context, provider string, credential auth.ModelAuth) (Snapshot, error)

func (Client) Reads added in v0.19.2

func (c Client) Reads(provider string) bool

Reads reports whether the client knows the provider's usage endpoint.

type Reading added in v0.19.2

type Reading struct {
	Provider string
	Snapshot Snapshot
}

type Snapshot

type Snapshot struct {
	Plan      string    `json:"plan,omitempty"`
	Windows   []Window  `json:"windows"`
	CheckedAt time.Time `json:"checked_at,omitzero"`
}

func (Snapshot) Summary

func (u Snapshot) Summary() string

type Window

type Window struct {
	Name      string    `json:"name"`
	Remaining float64   `json:"remaining"` // percent
	ResetsAt  time.Time `json:"resets_at,omitzero"`
}

Window and Snapshot are also Bridge wire: an instance describes its provider's limits with them.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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