usage

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package usage persists provider-reported LLM usage outside the turn path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

Hook accepts observations without waiting for PostgreSQL. The queue bounds shutdown loss to 1024 accepted records. Under sustained database overload, excess observations are deliberately dropped rather than delaying a turn.

func New

func New(db *pgxpool.Pool) *Hook

func (*Hook) Close

func (h *Hook) Close() error

Close stops admission, then drains the bounded queue before returning. It is called after agent runtimes stop, while the database pool is still available.

func (*Hook) DroppedCount

func (h *Hook) DroppedCount() int64

func (*Hook) Name

func (*Hook) Name() string

func (*Hook) OnPostLLMCall

func (h *Hook) OnPostLLMCall(_ context.Context, hctx *hooks.PostLLMCallContext)

func (*Hook) PendingCallCount

func (h *Hook) PendingCallCount(sessionID string) int64

PendingCallCount reports accepted observations that have not finished their database write. It is session-scoped so callers can distinguish a complete zero-usage session from one whose accounting is still in flight.

func (*Hook) Priority

func (*Hook) Priority() int

func (*Hook) QueueDepth

func (h *Hook) QueueDepth() int

func (*Hook) SetDropObserver

func (h *Hook) SetDropObserver(fn func())

SetDropObserver installs a non-blocking callback for queue drops.

func (*Hook) Start

func (h *Hook) Start()

Start owns the one background writer for this process-lifetime core hook.

Jump to

Keyboard shortcuts

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