Documentation
¶
Index ¶
- func ApplyRange(data usage.Data, from, to time.Time) usage.Data
- func ParseRange(s string, loc *time.Location) (from, to time.Time, err error)
- type Comparison
- type CostBreakdownReport
- type CostBucket
- type DayStat
- type Delta
- type FilterPreset
- type ModelBreakdown
- type ModelStat
- type ProjectStat
- type Report
- type SessionDetail
- type SessionStat
- type SessionTurn
- type ToolEntry
- type ToolStats
- type Totals
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyRange ¶
ApplyRange filters data to events with timestamps in [from, to) local time. Zero values mean unbounded on that side.
Types ¶
type Comparison ¶ added in v0.6.0
type Comparison struct {
Prompts Delta
Turns Delta
InputTokens Delta
CacheCreationTokens Delta
CacheReadTokens Delta
OutputTokens Delta
TotalTokens Delta
CostUSD Delta
}
Comparison holds per-metric Deltas comparing two Totals snapshots.
func Compare ¶ added in v0.6.0
func Compare(a, b Totals) Comparison
Compare builds a Comparison from two Totals (a = baseline, b = current).
type CostBreakdownReport ¶ added in v0.8.2
type CostBreakdownReport struct {
Overall ModelBreakdown // Model = "overall"
ByModel []ModelBreakdown
TotalCost float64
}
CostBreakdownReport aggregates per-model breakdowns plus an overall row.
func BuildCostBreakdown ¶ added in v0.8.2
func BuildCostBreakdown(r Report) CostBreakdownReport
BuildCostBreakdown derives the 5-bucket breakdown per model (sorted by cost descending) plus an "overall" aggregate.
type CostBucket ¶ added in v0.8.2
type CostBucket struct {
Kind string // "input" | "cache_write_5m" | "cache_write_1h" | "cache_read" | "output"
Tokens int
Rate float64
Cost float64
Pct float64 // 0..100, share of total cost (the parent ModelBreakdown.TotalCost or overall)
}
CostBucket is a per-kind cost row decorated with percent-of-total.
type Delta ¶ added in v0.6.0
type Delta struct {
A float64 // value for range A
B float64 // value for range B
Delta float64 // B - A (absolute; negative means B < A)
Pct float64 // (B - A) / A * 100; 0.0 when A == 0
Gt bool // true when B > A strictly
}
Delta holds the A value, B value, and derived diff metrics between two ranges for a single metric. When A is zero, Pct is 0.0 (division-by-zero guard).
type FilterPreset ¶
type FilterPreset int
const ( FilterAll FilterPreset = iota FilterToday FilterYesterday FilterLast7Days FilterLast30Days FilterLast90Days FilterThisWeek FilterThisMonth )
func ResolvePreset ¶ added in v0.3.0
func ResolvePreset(name string) (FilterPreset, bool)
ResolvePreset maps common range aliases (today, last-7d, this-month, ...) to a FilterPreset. Returns false if the alias is unknown.
func (FilterPreset) Label ¶
func (p FilterPreset) Label() string
func (FilterPreset) Next ¶
func (p FilterPreset) Next() FilterPreset
func (FilterPreset) Prev ¶
func (p FilterPreset) Prev() FilterPreset
type ModelBreakdown ¶ added in v0.8.2
type ModelBreakdown struct {
Model string
Buckets []CostBucket
TotalCost float64
Pct float64 // share of grand total across all models
}
ModelBreakdown holds the 5-bucket breakdown for a single model.
type ProjectStat ¶
type Report ¶
type Report struct {
Overall Totals
ByDay []DayStat
ByModel []ModelStat
BySession []SessionStat
ByProject []ProjectStat
Tools ToolStats
Models []string // stable list of model names seen (sorted by total usage desc)
DateRange [2]time.Time
PromptsByHour [24]int // prompts per hour-of-day aggregated across all filtered data
}
type SessionDetail ¶ added in v0.6.0
type SessionDetail struct {
SessionID string
Cwd string
FirstSeen time.Time
LastSeen time.Time
Models []string // sorted, unique
Totals Totals // session totals
Turns []SessionTurn // chronological, oldest first
}
SessionDetail is the per-session drill-down report.
func BuildSessionDetail ¶ added in v0.6.0
func BuildSessionDetail(data usage.Data, sessionID string) (SessionDetail, bool)
BuildSessionDetail returns the detail for a specific session. If sessionID has length >= 8 it also matches by prefix (so short ids work). Returns (SessionDetail{}, false) when no session matches.
type SessionStat ¶
type SessionTurn ¶ added in v0.6.0
type SessionTurn struct {
Timestamp time.Time
Model string
// Totals is the usage of this single Event (not cumulative).
Totals Totals
// Tools contains the tool_use items the assistant emitted in this turn.
// Empty if the turn had no tool calls.
Tools []string
}
SessionTurn captures one assistant turn inside a session.
type Totals ¶
type Totals struct {
InputTokens int
OutputTokens int
CacheCreationTokens int // total = 5m + 1h (kept for backwards compat)
CacheCreation5mTokens int
CacheCreation1hTokens int
CacheReadTokens int
Turns int
Prompts int
Cost float64 // USD, summed per-event
}