Documentation
¶
Overview ¶
ABOUTME: httpBackend implements SessionService by proxying HTTP ABOUTME: calls to a running agentsview daemon.
Package service provides the canonical session-operation interface shared by the HTTP handlers and the CLI. Both are thin JSON encoders that delegate to a SessionService implementation.
internal/service/stats_types.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
Event is the CLI-side NDJSON wrapper for SSE events from /api/v1/sessions/{id}/watch. See spec "watch" section.
type ExportFiles ¶
ExportFiles is a filesystem helper, not on SessionService. Used by the CLI `session export` command to stream raw JSONL.
type ListFilter ¶
type ListFilter struct {
Project string `json:"project,omitempty"`
ExcludeProject string `json:"exclude_project,omitempty"`
Machine string `json:"machine,omitempty"`
Agent string `json:"agent,omitempty"`
Date string `json:"date,omitempty"`
DateFrom string `json:"date_from,omitempty"`
DateTo string `json:"date_to,omitempty"`
ActiveSince string `json:"active_since,omitempty"`
MinMessages int `json:"min_messages,omitempty"`
MaxMessages int `json:"max_messages,omitempty"`
MinUserMessages int `json:"min_user_messages,omitempty"`
IncludeOneShot bool `json:"include_one_shot,omitempty"`
IncludeAutomated bool `json:"include_automated,omitempty"`
IncludeChildren bool `json:"include_children,omitempty"`
Outcome string `json:"outcome,omitempty"` // comma-separated
HealthGrade string `json:"health_grade,omitempty"` // comma-separated
MinToolFailures *int `json:"min_tool_failures,omitempty"`
Cursor string `json:"cursor,omitempty"`
Limit int `json:"limit,omitempty"`
}
ListFilter mirrors the HTTP query parameters in handleListSessions. Field names map to HTTP query param names via json tags.
type MessageFilter ¶
type MessageFilter struct {
From *int `json:"from,omitempty"`
Limit int `json:"limit,omitempty"`
Direction string `json:"direction,omitempty"` // "asc" (default) or "desc"
}
MessageFilter mirrors GET /api/v1/sessions/{id}/messages query params. From is a pointer so callers can distinguish "omitted" from "0". An omitted From in descending mode means "start from the newest message"; an explicit 0 means "start at ordinal 0".
type MessageList ¶
MessageList mirrors {messages, count}.
type SessionDetail ¶
type SessionDetail struct {
db.Session
HealthScoreBasis []string `json:"health_score_basis,omitempty"`
HealthPenalties map[string]int `json:"health_penalties,omitempty"`
}
SessionDetail mirrors the HTTP GetSession response shape: a db.Session plus the computed health-breakdown fields that the detail endpoint enriches. Both direct and HTTP backends return this type so CLI JSON output is transport-neutral.
type SessionList ¶
type SessionList struct {
Sessions []db.Session `json:"sessions"`
NextCursor string `json:"next_cursor,omitempty"`
Total int `json:"total"`
}
SessionList mirrors GET /api/v1/sessions.
type SessionService ¶
type SessionService interface {
Get(ctx context.Context, id string) (*SessionDetail, error)
List(ctx context.Context, f ListFilter) (*SessionList, error)
Messages(ctx context.Context, id string, f MessageFilter) (*MessageList, error)
ToolCalls(ctx context.Context, id string) (*ToolCallList, error)
Sync(ctx context.Context, in SyncInput) (*SessionDetail, error)
Watch(ctx context.Context, id string) (<-chan Event, error)
Stats(ctx context.Context, f StatsFilter) (*SessionStats, error)
}
SessionService is the canonical per-session operation interface. Two implementations: directBackend (wraps *db.DB) and httpBackend (proxies to a running daemon).
func NewDirectBackend ¶
func NewDirectBackend(d *db.DB, engine *sync.Engine) SessionService
NewDirectBackend returns a full read/write SessionService backed by a local SQLite store and optional sync engine. When engine is nil, Sync returns db.ErrReadOnly but reads still work. Use NewReadOnlyBackend for stores that are not *db.DB (e.g. a PostgreSQL reader).
func NewHTTPBackend ¶
func NewHTTPBackend(baseURL, token string, readOnly bool) SessionService
NewHTTPBackend constructs a SessionService that proxies to a running agentsview daemon at baseURL. When readOnly is true, Sync returns a clear error without making the HTTP round-trip. token, when non-empty, is attached as `Authorization: Bearer ...` on every request so the backend works against daemons running with require_auth=true.
func NewReadOnlyBackend ¶
func NewReadOnlyBackend(d db.Store) SessionService
NewReadOnlyBackend returns a read-only SessionService over any db.Store (e.g. a PostgreSQL reader used by `pg serve`). Sync returns db.ErrReadOnly unconditionally.
type SessionStats ¶
type SessionStats = db.SessionStats
SessionStats is the transport-neutral response type; currently just an alias for db.SessionStats (the database package already carries the full schema with json tags).
type StatsFilter ¶
type StatsFilter struct {
Since string `json:"since,omitempty"`
Until string `json:"until,omitempty"`
Agent string `json:"agent,omitempty"`
IncludeProjects []string `json:"include_projects,omitempty"`
ExcludeProjects []string `json:"exclude_projects,omitempty"`
Timezone string `json:"timezone,omitempty"`
GHToken string `json:"-"`
}
StatsFilter mirrors the session-stats CLI flag set.
type SyncInput ¶
SyncInput carries the payload for a per-session sync. Exactly one of Path or ID must be set.
type ToolCall ¶
type ToolCall struct {
Ordinal int `json:"ordinal"`
Timestamp string `json:"timestamp"` // RFC3339
ToolUseID string `json:"tool_use_id"`
ToolName string `json:"tool_name"`
Category string `json:"category"`
InputJSON string `json:"input_json"`
SkillName string `json:"skill_name,omitempty"`
SubagentSessionID string `json:"subagent_session_id,omitempty"`
ResultLength int `json:"result_length"`
}
ToolCall mirrors a flattened tool call with its enclosing message's ordinal/timestamp attached. Serialized from parser.ParsedToolCall.
type ToolCallList ¶
ToolCallList mirrors {tool_calls, count}.