Documentation
¶
Overview ¶
Package stats serves the /api/v1/stats endpoints: aggregates over the derived tables of the signed-in user.
Index ¶
- func MergeSeconds(in []Interval) int64
- func Streak(days []time.Time, today time.Time) int
- type ActivityDay
- type AgentItem
- type AgentUsage
- type CurrentTool
- type DayPoint
- type FailureAgg
- type FailureItem
- type FailurePage
- type Filter
- type FilterOptions
- type Handler
- type HeatCell
- type Interval
- type KPI
- type LineItem
- type LinePage
- type LiveAgent
- type LivePage
- type LiveSession
- type ModelPoint
- type Overview
- type PhaseItem
- type ProjectDay
- type ProjectKey
- type ProjectOption
- type ProjectPoint
- type ProjectSplit
- type ProjectValue
- type SearchHit
- type SearchResult
- type Self
- type SelfLimit
- type SelfSession
- type SelfToday
- type SessionDetail
- type SessionItem
- type SessionPage
- type Totals
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeSeconds ¶
MergeSeconds returns the length of the union of in in whole seconds; intervals with End <= Start are ignored.
Types ¶
type ActivityDay ¶
ActivityDay is the main-agent time of the sessions started on one local day.
type AgentItem ¶
type AgentItem struct {
AgentID string `json:"agent_id"`
AgentType string `json:"agent_type"`
Description string `json:"description"`
ParentAgentID *string `json:"parent_agent_id"`
SpawnToolUseID *string `json:"spawn_tool_use_id"`
SpawnDepth int `json:"spawn_depth"`
StartedAt *time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at"`
Finished *bool `json:"finished"`
DurationMs int64 `json:"duration_ms"`
DurationEstimated bool `json:"duration_estimated"`
ToolCalls map[string]int64 `json:"tool_calls"`
ToolErrors int64 `json:"tool_errors"`
Usage AgentUsage `json:"usage"`
}
AgentItem is one agent of a session; the tree is encoded by ParentAgentID.
type AgentUsage ¶
type AgentUsage struct {
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
Input int64 `json:"input"`
Output int64 `json:"output"`
CacheRead int64 `json:"cache_read"`
CacheWrite int64 `json:"cache_write"`
Messages int64 `json:"messages"`
}
AgentUsage is the usage of one agent.
type CurrentTool ¶
type CurrentTool struct {
Name string `json:"name"`
Summary string `json:"summary"` // tool_calls.input_summary, <= 200 chars
StartedAt time.Time `json:"started_at"`
}
CurrentTool is the newest unfinished tool call of an agent.
type DayPoint ¶
type DayPoint struct {
Day string `json:"day"`
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
Sessions int64 `json:"sessions"`
AgentMs int64 `json:"agent_ms"`
}
DayPoint is one local day.
type FailureAgg ¶
type FailureAgg struct {
Key string `json:"key"`
Count int64 `json:"count"`
TimeLostS int64 `json:"time_lost_s"`
}
FailureAgg is one aggregation bucket; TimeLostS is the union of the lost intervals within the key.
type FailureItem ¶
type FailureItem struct {
Category string `json:"category"`
Detail string `json:"detail"`
OccurredAt time.Time `json:"occurred_at"`
SessionID string `json:"session_id"`
AgentID string `json:"agent_id"`
LimitType *string `json:"limit_type"`
ResetsAt *time.Time `json:"resets_at"`
TimeLostS *int64 `json:"time_lost_s"`
LineID int64 `json:"line_id"` // raw_lines.id of the failing line (highest id at its offset)
}
FailureItem is one failure; TimeLostS is set for usage-limit failures only.
type FailurePage ¶
type FailurePage struct {
Items []FailureItem `json:"items"`
Next *string `json:"next"`
ByCategory []FailureAgg `json:"by_category"`
ByLimitType []FailureAgg `json:"by_limit_type"`
ByDay []FailureAgg `json:"by_day"`
TimeLostS int64 `json:"time_lost_s"`
}
FailurePage is the response of GET /api/v1/stats/failures.
type FilterOptions ¶
type FilterOptions struct {
Projects []ProjectOption `json:"projects"`
Models []string `json:"models"`
Skills []string `json:"skills"`
}
FilterOptions is the response of GET /api/v1/stats/filters.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves /api/v1/stats.
type HeatCell ¶
type HeatCell struct {
Weekday int `json:"weekday"`
Hour int `json:"hour"`
Count int64 `json:"count"`
}
HeatCell is the number of assistant messages in one weekday/hour slot (weekday 0 = Sunday, user time zone).
type KPI ¶
type KPI struct {
Sessions int64 `json:"sessions"`
AgentMs int64 `json:"agent_ms"`
TotalAgentMs int64 `json:"total_agent_ms"`
AgentMsEstimated bool `json:"agent_ms_estimated"`
CostUSD float64 `json:"cost_usd"`
CostUnknownModels []string `json:"cost_unknown_models"`
Tokens int64 `json:"tokens"`
StreakDays int `json:"streak_days"`
LongestAgentMs int64 `json:"longest_agent_ms"`
Failures int64 `json:"failures"`
TimeLostS int64 `json:"time_lost_s"`
}
KPI is the headline figures of the selected sessions.
type LineItem ¶
type LineItem struct {
ID int64 `json:"id"`
Offset int64 `json:"offset"`
Line json.RawMessage `json:"line"`
}
LineItem is one stored transcript line.
type LinePage ¶
type LinePage struct {
Lines []LineItem `json:"lines"`
Next *string `json:"next"`
Prev *string `json:"prev"` // id of the first line when an earlier line of the agent exists
}
LinePage is one page of lines; Next is the last id when more exist.
type LiveAgent ¶
type LiveAgent struct {
AgentID string `json:"agent_id"`
AgentType string `json:"agent_type"`
Description string `json:"description"`
ParentAgentID *string `json:"parent_agent_id"`
StartedAt *time.Time `json:"started_at"`
CurrentTool *CurrentTool `json:"current_tool"` // newest tool call of the agent without ended_at, started < 15 min ago
}
LiveAgent is an agent active within the last two minutes.
type LivePage ¶
type LivePage struct {
Items []LiveSession `json:"items"`
}
LivePage is the response of GET /api/v1/stats/live.
type LiveSession ¶
type LiveSession struct {
Session SessionItem `json:"session"`
Agents []LiveAgent `json:"agents"`
}
LiveSession is a live session with its active agents, main first.
type ModelPoint ¶
type ModelPoint struct {
Model string `json:"model"`
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
Messages int64 `json:"messages"`
PriceUnknown bool `json:"price_unknown"`
}
ModelPoint is one model.
type Overview ¶
type Overview struct {
From time.Time `json:"from"`
To time.Time `json:"to"`
TimeZone string `json:"time_zone"`
Reindexing bool `json:"reindexing"`
KPI KPI `json:"kpi"`
PerDay []DayPoint `json:"per_day"`
PerModel []ModelPoint `json:"per_model"`
PerProject []ProjectPoint `json:"per_project"`
Heatmap []HeatCell `json:"heatmap"`
Previous Totals `json:"previous"`
Activity []ActivityDay `json:"activity"`
PerDayByProject ProjectSplit `json:"per_day_by_project"`
}
Overview is the response of GET /api/v1/stats/overview.
type PhaseItem ¶
type PhaseItem struct {
AgentID string `json:"agent_id"`
Seq int `json:"seq"`
Skill string `json:"skill"`
StartedAt *time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at"`
}
PhaseItem is one skill phase.
type ProjectDay ¶
type ProjectDay struct {
Day string `json:"day"`
Values []ProjectValue `json:"values"`
}
ProjectDay is one local day; Values[i] belongs to ProjectSplit.Projects[i].
type ProjectKey ¶
ProjectKey names one series of ProjectSplit; the trailing "_other" key collects every project beyond the top eight.
type ProjectOption ¶
type ProjectOption struct {
Path string `json:"path"`
Name string `json:"name"`
Sessions int64 `json:"sessions"`
}
ProjectOption is one project in the filter dropdown.
type ProjectPoint ¶
type ProjectPoint struct {
Path string `json:"path"`
Name string `json:"name"`
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
Sessions int64 `json:"sessions"`
AgentMs int64 `json:"agent_ms"`
}
ProjectPoint is one project.
type ProjectSplit ¶
type ProjectSplit struct {
Projects []ProjectKey `json:"projects"`
Days []ProjectDay `json:"days"`
}
ProjectSplit is the daily cost, tokens, sessions and agent time stacked by project.
type ProjectValue ¶
type ProjectValue struct {
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
Sessions int64 `json:"sessions"`
AgentMs int64 `json:"agent_ms"`
}
ProjectValue is one project's share of a day: usage by its time, sessions and agent time by the session's start.
type SearchHit ¶
type SearchHit struct {
SessionID string `json:"session_id"`
AgentID string `json:"agent_id"`
Role string `json:"role"`
At *time.Time `json:"at"`
Title string `json:"title"`
Snippet string `json:"snippet"`
Rank float64 `json:"rank"`
LineID int64 `json:"line_id"` // raw_lines.id of the hit line (highest id at its offset)
}
SearchHit is one matching prompt or reply; Snippet is cut from the raw line at query time.
type SearchResult ¶
type SearchResult struct {
Hits []SearchHit `json:"hits"`
}
SearchResult is the response of GET /api/v1/stats/search.
type Self ¶
type Self struct {
Today SelfToday `json:"today"`
Session *SelfSession `json:"session"`
Limit *SelfLimit `json:"limit"`
}
Self is the response of GET /v1/stats/self.
type SelfSession ¶
type SelfSession struct {
SessionID string `json:"session_id"`
AgentMs int64 `json:"agent_ms"`
TotalAgentMs int64 `json:"total_agent_ms"`
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
StartedAt *time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at"`
Failures int64 `json:"failures"`
}
SelfSession is the whole-session figures of one session; numbers and times only.
type SelfToday ¶
type SelfToday struct {
From time.Time `json:"from"`
To time.Time `json:"to"`
TimeZone string `json:"time_zone"`
Sessions int64 `json:"sessions"`
AgentMs int64 `json:"agent_ms"`
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
Failures int64 `json:"failures"`
TimeLostS int64 `json:"time_lost_s"`
}
SelfToday is today's aggregates; numbers only.
type SessionDetail ¶
type SessionDetail struct {
Session SessionItem `json:"session"`
Agents []AgentItem `json:"agents"`
SkillPhases []PhaseItem `json:"skill_phases"`
Failures []FailureItem `json:"failures"`
}
SessionDetail is the response of GET /api/v1/stats/sessions/{id}.
type SessionItem ¶
type SessionItem struct {
SessionID string `json:"session_id"`
Title string `json:"title"`
Project string `json:"project"`
ProjectName string `json:"project_name"`
DeviceID *string `json:"device_id"`
DeviceIDs []string `json:"device_ids"`
Models []string `json:"models"`
StartedAt time.Time `json:"started_at"`
EndedAt time.Time `json:"ended_at"`
IsLive bool `json:"is_live"`
AgentMs int64 `json:"agent_ms"`
TotalAgentMs int64 `json:"total_agent_ms"`
AgentMsEstimated bool `json:"agent_ms_estimated"`
CostUSD float64 `json:"cost_usd"`
Tokens int64 `json:"tokens"`
Failures int64 `json:"failures"`
Skills []string `json:"skills"`
LineCount int64 `json:"line_count"`
GitBranch string `json:"git_branch"`
Turns int64 `json:"turns"`
}
SessionItem is one session with whole-session figures.
type SessionPage ¶
type SessionPage struct {
Items []SessionItem `json:"items"`
Next *string `json:"next"`
}
SessionPage is one page of sessions; Next is the opaque cursor of the following page.