Documentation
¶
Index ¶
- Constants
- Variables
- func HasLLMCredentials(cfg LLMCallerConfig) bool
- func SeedDemo(ctx context.Context, path string, overwrite bool) (int, int, error)
- func SortSessions(sessions []SessionSummary, sortKey, sortDir string)
- type Filters
- type HTTPQuery
- type LLMCallFunc
- type LLMCallerConfig
- type ModelCost
- type Overview
- type PeriodComparison
- type Pricing
- type PricingTable
- type Querier
- type SessionDetail
- type SessionMessage
- type SessionMessageGroup
- type SessionSummary
Constants ¶
const ( StatusCompleted = sessions.StatusCompleted StatusFailed = sessions.StatusFailed StatusAbandoned = sessions.StatusAbandoned StatusUnknown = sessions.StatusUnknown )
Status constants re-exported from pkg/sessions so existing TUI callers (`deck.StatusCompleted` etc.) keep working without an import change.
const DemoSQLitePath = "tapes.demo.sqlite"
Variables ¶
var ErrEmptyChain = errors.New("empty session chain")
ErrEmptyChain is returned when SessionDetail receives an empty chain back from the API. Exported so callers can branch on it if needed.
Functions ¶
func HasLLMCredentials ¶
func HasLLMCredentials(cfg LLMCallerConfig) bool
HasLLMCredentials checks whether an API key can be resolved from the config without creating a caller. Used for auto-enabling insights.
func SortSessions ¶
func SortSessions(sessions []SessionSummary, sortKey, sortDir string)
SortSessions sorts session summaries in place by the given key and direction.
Types ¶
type Filters ¶
type Filters struct {
Since time.Duration
From *time.Time
To *time.Time
Model string
Status string
Project string
Sort string
SortDir string
Session string
}
Filters describes the user-facing filter set the deck applies on top of the data returned by the API. Time filters are evaluated client-side against SessionSummary.StartTime / EndTime; the per-field string filters are also applied client-side after the rich /v1/sessions/summary fetch.
type HTTPQuery ¶ added in v0.4.0
type HTTPQuery struct {
// contains filtered or unexported fields
}
HTTPQuery is a Querier implementation that talks to a remote (or in-process) tapes API server over HTTP. It mirrors the Querier surface of the legacy SQLite-backed Query type so callers can swap implementations without changes.
func NewHTTPQuery ¶ added in v0.4.0
func NewHTTPQuery(apiTarget string, pricing PricingTable) *HTTPQuery
NewHTTPQuery constructs an HTTPQuery pointed at apiTarget (e.g. "http://127.0.0.1:8081"). The pricing table is retained for client-side recalculation if needed; in practice the API server already returns fully-populated SessionSummary objects.
func (*HTTPQuery) Overview ¶ added in v0.4.0
Overview fetches all session summaries from the API (paging through with /v1/sessions/summary), then runs the existing deck-side grouping, filtering and rollup logic on top of the returned data.
Filters that the API understands natively (since/from, project, model) are pushed down to the request as query params so the server can apply them at the SQL level. Without this pushdown the deck would page through every session in the database before filtering, which OOMs on large stores. Filters that depend on derived state (status, the To bound, sort order) stay client-side and are applied to the smaller filtered slice below.
func (*HTTPQuery) SessionDetail ¶ added in v0.4.0
SessionDetail fetches the chain for a single session via /v1/sessions/:hash and renders the per-turn message data using the cached SessionSummary for the same ID. Group IDs (synthetic IDs from groupSessionCandidates) are resolved against the cached candidates.
type LLMCallFunc ¶
LLMCallFunc is the signature for an LLM inference call.
func NewLLMCaller ¶
func NewLLMCaller(cfg LLMCallerConfig) (LLMCallFunc, error)
NewLLMCaller creates a LLMCallFunc based on the provided configuration. Resolution order for API key:
- Explicit APIKey in config
- credentials.Manager (from tapes auth)
- Environment variables (OPENAI_API_KEY / ANTHROPIC_API_KEY)
type LLMCallerConfig ¶
type LLMCallerConfig struct {
Provider string // "openai", "anthropic", or "ollama"
Model string // e.g. "gpt-4o-mini", "claude-haiku-4-5-20251001"
APIKey string // explicit API key (highest priority)
BaseURL string // override base URL
CredMgr *credentials.Manager // credentials from tapes auth
}
LLMCallerConfig holds configuration for creating an LLM caller.
type Overview ¶
type Overview struct {
Sessions []SessionSummary `json:"sessions"`
TotalCost float64 `json:"total_cost"`
TotalTokens int64 `json:"total_tokens"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalDuration time.Duration `json:"total_duration_ns"`
TotalToolCalls int `json:"total_tool_calls"`
SuccessRate float64 `json:"success_rate"`
Completed int `json:"completed"`
Failed int `json:"failed"`
Abandoned int `json:"abandoned"`
CostByModel map[string]ModelCost `json:"cost_by_model"`
PreviousPeriod *PeriodComparison `json:"previous_period,omitempty"`
}
Overview is the response a Querier returns from Overview. It holds the filtered list of session summaries plus dashboard rollups.
type PeriodComparison ¶
type PeriodComparison struct {
TotalCost float64 `json:"total_cost"`
TotalTokens int64 `json:"total_tokens"`
TotalDuration time.Duration `json:"total_duration_ns"`
TotalToolCalls int `json:"total_tool_calls"`
SuccessRate float64 `json:"success_rate"`
Completed int `json:"completed"`
}
PeriodComparison holds the previous-period metrics shown alongside the current period in the deck overview.
type Pricing ¶
Pricing aliases sessions.Pricing so the deck and the API both speak the same model-cost type. The standalone definition was removed when pricing logic moved to pkg/sessions.
type PricingTable ¶
type PricingTable = sessions.PricingTable
PricingTable aliases sessions.PricingTable so the deck and the API speak the same map type without conversion at every boundary.
func DefaultPricing ¶
func DefaultPricing() PricingTable
DefaultPricing returns the canonical pricing table from pkg/sessions. Re-exported as a function so consumers that already imported deck.DefaultPricing keep working without an import change.
type Querier ¶
type Querier interface {
Overview(ctx context.Context, filters Filters) (*Overview, error)
SessionDetail(ctx context.Context, sessionID string) (*SessionDetail, error)
}
Querier is the interface the deck TUI and web dashboard use to fetch session data. The HTTPQuery implementation in this package talks to a tapes API server (in-process or remote) over HTTP.
type SessionDetail ¶
type SessionDetail struct {
Summary SessionSummary `json:"summary"`
Messages []SessionMessage `json:"messages"`
GroupedMessages []SessionMessageGroup `json:"grouped_messages,omitempty"`
ToolFrequency map[string]int `json:"tool_frequency"`
SubSessions []SessionSummary `json:"sub_sessions,omitempty"`
}
SessionDetail is the response a Querier returns from SessionDetail. It holds the per-session SessionSummary plus its rendered transcript.
type SessionMessage ¶
type SessionMessage struct {
Hash string `json:"hash"`
Role string `json:"role"`
Model string `json:"model"`
Timestamp time.Time `json:"timestamp"`
Delta time.Duration `json:"delta_ns"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalTokens int64 `json:"total_tokens"`
InputCost float64 `json:"input_cost"`
OutputCost float64 `json:"output_cost"`
TotalCost float64 `json:"total_cost"`
ToolCalls []string `json:"tool_calls"`
Text string `json:"text"`
}
SessionMessage is the per-turn render shape used by the deck's transcript view. It is built client-side from the API's Turn objects in HTTPQuery and is not part of any HTTP API surface.
type SessionMessageGroup ¶
type SessionMessageGroup struct {
Role string `json:"role"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Delta time.Duration `json:"delta_ns"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalTokens int64 `json:"total_tokens"`
InputCost float64 `json:"input_cost"`
OutputCost float64 `json:"output_cost"`
TotalCost float64 `json:"total_cost"`
ToolCalls []string `json:"tool_calls"`
Text string `json:"text"`
Count int `json:"count"`
StartIndex int `json:"start_index"`
EndIndex int `json:"end_index"`
}
SessionMessageGroup is a batched run of adjacent same-role messages, used by the deck's transcript view to collapse rapid back-and-forth turns into a single visual entry.
type SessionSummary ¶
type SessionSummary = sessions.SessionSummary
SessionSummary aliases sessions.SessionSummary. The deck used to define its own copy with identical fields; the alias removes the duplication while keeping deck.SessionSummary working for the dozens of TUI sites that reference it.