usagefeed

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 19 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

Overview

Package usagefeed fills the machine's usage outbox (internal/usageoutbox) from the facts of the agent CLIs' transcripts (internal/usagereport): a `call` record for every model call and a `session` record for every session that is new or changed (docs/hub/usage.md). It copies numbers and ids, never the text of a conversation: the facts it reads hold none, and a record has no field that could carry any.

Index

Constants

View Source
const (

	// DefaultMaxPending and DefaultMaxBytes bound what waits for the hub's acknowledgement: a hub that stops reading
	// does not make the outbox grow without end. Reaching either pauses the feed; nothing is dropped.
	DefaultMaxPending = 200_000
	DefaultMaxBytes   = 64 << 20
)

Variables

This section is empty.

Functions

func HostOf

func HostOf(raw string) string

HostOf is the host of a base URL, "" for the providers' own endpoints.

func KeyRef

func KeyRef(key string) string

KeyRef is how a key is named in a record: a hash computed here, so the key itself never leaves the process.

func StatePath

func StatePath(dir string) string

StatePath is where the state of an outbox in dir is kept.

Types

type Config

type Config struct {
	Outbox *usageoutbox.Outbox
	Source Source
	// StatePath keeps what was already written, so a restart does not write it all again.
	StatePath string
	// Identity says which account and endpoint a provider's CLI uses now; nil knows nothing.
	Identity func(provider string) Identity
	// SessionIdentity says which account and endpoint a session ran on, when the runtime noted it at the launch (a chat
	// on a provider the person added, or on another account of one); ok is false for a session nobody noted, which is
	// then the CLI's own. nil knows none.
	SessionIdentity func(provider, sessionID string) (Identity, bool)
	// Now is the clock (tests move it); nil is the real one.
	Now func() time.Time
	// MaxPending and MaxBytes cap the unacknowledged records (count, bytes on disk); zero is the default.
	MaxPending int
	MaxBytes   int64
	// SkillMetrics adds skillsListed and skillsLoaded to the sessions' metrics. Off unless the machine's
	// fleet flag turned it on.
	SkillMetrics bool
}

Config is what the feed needs.

type Feed

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

Feed writes the outbox.

func New

func New(cfg Config) (*Feed, error)

New loads the state. A state of another epoch than the outbox's (the folder was made anew) is forgotten.

func (*Feed) Pass

func (f *Feed) Pass(ctx context.Context) (int, error)

Pass reads the transcripts' new facts and writes what is new to the outbox. It returns how many records it wrote. A pass that ctx stops saves nothing; the next one writes again what this one did, which the hub ignores.

func (*Feed) Run

func (f *Feed) Run(ctx context.Context, every time.Duration, written func(epoch string, last int64))

Run does a pass now and then every interval until ctx is done. written is told the outbox's epoch and newest seq after a pass that wrote something.

type Identity

type Identity struct {
	AccountRef  string
	AuthMode    string // subscription, api_key, ""
	BaseURLHost string // "" for the CLI's default
}

Identity is what the machine can say of the account its agent CLI uses now: never a key or a token, only a stable name of the account (docs/hub/usage.md, accountRef), how it signs in, and where its calls go.

type Local

type Local struct {
	Home   string
	Getenv func(provider, name string) string
}

Local reads the identity from what the CLIs keep on this machine. Getenv is the environment a CLI would be started with (the agent's env files over its own); Home is the account's home.

func (Local) Identity

func (l Local) Identity(provider string) Identity

Identity of the account the provider's CLI runs as.

type Source

type Source interface {
	Refresh()
	Entries() []usagereport.Entry
}

Source is the transcripts' facts; usagereport.Collector is one.

Jump to

Keyboard shortcuts

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