deck

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusCompleted = "completed"
	StatusFailed    = "failed"
	StatusAbandoned = "abandoned"
	StatusUnknown   = "unknown"
)
View Source
const DemoSQLitePath = "tapes.demo.sqlite"

Variables

This section is empty.

Functions

func CostForTokens

func CostForTokens(pricing Pricing, inputTokens, outputTokens int64) (float64, float64, float64)

CostForTokens calculates cost using base input/output pricing. For cache-aware cost calculation, use CostForTokensWithCache.

func CostForTokensWithCache

func CostForTokensWithCache(pricing Pricing, inputTokens, outputTokens, cacheCreation, cacheRead int64) (float64, float64, float64)

CostForTokensWithCache calculates cost accounting for prompt caching. When cache token counts are available, base input tokens are calculated as: baseInput = totalInput - cacheCreation - cacheRead Each token type is priced at its respective rate.

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 SeedDemo

func SeedDemo(ctx context.Context, path string, overwrite bool) (int, int, error)

func SortSessions

func SortSessions(sessions []SessionSummary, sortKey, sortDir string)

SortSessions sorts session summaries in place by the given key and direction.

func StripTaggedSection

func StripTaggedSection(text, tag string) string

StripTaggedSection removes all occurrences of a given XML-like tagged section (e.g. <system-reminder>…</system-reminder>) from text.

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
}

type LLMCallFunc

type LLMCallFunc func(ctx context.Context, prompt string) (string, error)

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:

  1. Explicit APIKey in config
  2. credentials.Manager (from tapes auth)
  3. Environment variables (OPENAI_API_KEY / ANTHROPIC_API_KEY)
  4. Fall back to Ollama at localhost:11434

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
	Logger   *slog.Logger         // optional logger; defaults to noop
}

LLMCallerConfig holds configuration for creating an LLM caller.

type ModelCost

type ModelCost struct {
	Model        string  `json:"model"`
	InputTokens  int64   `json:"input_tokens"`
	OutputTokens int64   `json:"output_tokens"`
	InputCost    float64 `json:"input_cost"`
	OutputCost   float64 `json:"output_cost"`
	TotalCost    float64 `json:"total_cost"`
	SessionCount int     `json:"session_count"`
}

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"`
}

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"`
}

type Pricing

type Pricing struct {
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cache_read"`
	CacheWrite float64 `json:"cache_write"`
}

func PricingForModel

func PricingForModel(pricing PricingTable, model string) (Pricing, bool)

type PricingTable

type PricingTable map[string]Pricing

func DefaultPricing

func DefaultPricing() PricingTable

DefaultPricing returns hardcoded pricing per million tokens for supported models.

Last verified: 2026-03-08 Sources:

Anthropic cache multipliers: CacheWrite = 1.25x input, CacheRead = 0.10x input. OpenAI cache: CacheWrite = 1x input (no surcharge), CacheRead = 0.50x input (except o3-mini).

To override at runtime, use --pricing with a JSON file. See LoadPricing.

func LoadPricing

func LoadPricing(path string) (PricingTable, error)

type Querier

type Querier interface {
	Overview(ctx context.Context, filters Filters) (*Overview, error)
	SessionDetail(ctx context.Context, sessionID string) (*SessionDetail, error)
}

Querier is an interface for querying session data. This allows for mock implementations in testing and sandboxes.

type Query

type Query struct {
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(ctx context.Context, dbPath string, pricing PricingTable) (*Query, func() error, error)

func (*Query) Overview

func (q *Query) Overview(ctx context.Context, filters Filters) (*Overview, error)

func (*Query) SessionDetail

func (q *Query) SessionDetail(ctx context.Context, sessionID string) (*SessionDetail, error)

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"`
}

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"`
}

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"`
}

type SessionSummary

type SessionSummary struct {
	ID           string        `json:"id"`
	Label        string        `json:"label"`
	Model        string        `json:"model"`
	Project      string        `json:"project"`
	AgentName    string        `json:"agent_name,omitempty"`
	Status       string        `json:"status"`
	StartTime    time.Time     `json:"start_time"`
	EndTime      time.Time     `json:"end_time"`
	Duration     time.Duration `json:"duration_ns"`
	InputTokens  int64         `json:"input_tokens"`
	OutputTokens int64         `json:"output_tokens"`
	InputCost    float64       `json:"input_cost"`
	OutputCost   float64       `json:"output_cost"`
	TotalCost    float64       `json:"total_cost"`
	ToolCalls    int           `json:"tool_calls"`
	MessageCount int           `json:"message_count"`
	SessionCount int           `json:"session_count,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL