Define the core data structures that flow through the entire pipeline: - model/session.go: SessionStats (per-session aggregates including token counts across 5 categories — input, output, cache_write_5m, cache_write_1h, cache_read), APICall (deduplicated by message.id, keyed to the final billed usage), and ModelUsage (per-model breakdown within a session). Tracks subagent relationships via IsSubagent/ParentSession fields. - model/metrics.go: Higher-order aggregate types — SummaryStats (top-level totals with per-active-day rates for cost, tokens, sessions, and minutes), DailyStats/HourlyStats/WeeklyStats (time-bucketed views), ModelStats (cross-session model comparison with share percentages), ProjectStats (per-project ranking), and PeriodComparison (current vs previous period for delta display). - model/budget.go: BudgetStats with plan ceiling, custom budget, burn rate, and projected monthly spend for the budget tab. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// APICall represents one deduplicated API request (final state of a message.id).
|
|
type APICall struct {
|
|
MessageID string
|
|
Model string
|
|
Timestamp time.Time
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5mTokens int64
|
|
CacheCreation1hTokens int64
|
|
CacheReadTokens int64
|
|
ServiceTier string
|
|
EstimatedCost float64
|
|
}
|
|
|
|
// ModelUsage tracks per-model token usage within a session.
|
|
type ModelUsage struct {
|
|
APICalls int
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5mTokens int64
|
|
CacheCreation1hTokens int64
|
|
CacheReadTokens int64
|
|
EstimatedCost float64
|
|
}
|
|
|
|
// SessionStats holds aggregated metrics for a single session file.
|
|
type SessionStats struct {
|
|
SessionID string
|
|
Project string
|
|
ProjectPath string
|
|
FilePath string
|
|
IsSubagent bool
|
|
ParentSession string
|
|
StartTime time.Time
|
|
EndTime time.Time
|
|
DurationSecs int64
|
|
|
|
UserMessages int
|
|
APICalls int
|
|
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5mTokens int64
|
|
CacheCreation1hTokens int64
|
|
CacheReadTokens int64
|
|
|
|
Models map[string]*ModelUsage
|
|
|
|
EstimatedCost float64
|
|
CacheHitRate float64
|
|
}
|