Documentation
¶
Overview ¶
Package usage tracks LLM/embedding token usage, aggregated per day and persisted through a caller-supplied flush callback.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker accumulates usage for the current UTC day and persists aggregated deltas through the flush callback (day-scoped, so the callback upserts one row). With a positive flushInterval deltas are batched and flushed on a timer (reducing SQLite write amplification); interval <= 0 persists synchronously on every Add (backwards-compatible). It is safe for concurrent use.
func NewTracker ¶
NewTracker builds a Tracker. persist is called with the current date key and the aggregated delta (best-effort; errors are ignored). flushInterval <= 0 runs in synchronous mode (persist once per Add); otherwise a background goroutine flushes every flushInterval and Close flushes any remainder.
func (*Tracker) Add ¶
Add accumulates a usage delta for the current day. In sync mode (interval <= 0) it persists the delta immediately; otherwise the delta is batched until the next flush. On a day rollover the in-memory accumulator resets (the persisted rows keep the per-day history).