reporter

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultCharsPerToken = 4

DefaultCharsPerToken is the heuristic constant used by Estimator: roughly 1 token per 4 characters of content, matching the OpenAI/Anthropic guidance for English text. This is the same primitive the runtime cost tracker uses (TrackCostFromStrings) and the same primitive the benchmark suite uses (tests/bench/token_economy_bench_test.go), so internal cost-tracker accounting and benchmarked savings numbers are computed identically.

Variables

This section is empty.

Functions

func ExportCSV added in v0.8.0

func ExportCSV(w io.Writer, entries []CallLogEntry, progress func(current, total int)) error

func ExportJSON added in v0.8.0

func ExportJSON(w io.Writer, entries []CallLogEntry, progress func(current, total int)) error

func TrackCost

func TrackCost(toolName, serverName string, tokenCount int64)

func TrackCostFromStrings

func TrackCostFromStrings(toolName, serverName, requestJSON, responseJSON string)

Types

type CallLogEntry added in v0.8.0

type CallLogEntry struct {
	ToolName   string
	ServerName string
	TokenCount int64
	Timestamp  time.Time
}

func GetEntries added in v0.8.0

func GetEntries(since time.Time) []CallLogEntry

type Clock

type Clock interface {
	Now() time.Time
	Since(time.Time) time.Duration
}

type CostBreakdown

type CostBreakdown struct {
	ByTool   []ToolCost    `json:"by_tool"`
	ByServer []ServerCost  `json:"by_server"`
	Total    int64         `json:"total"`
	Duration time.Duration `json:"duration"`
}

type CostTracker

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

func GlobalCostTracker

func GlobalCostTracker() *CostTracker

func NewCostTracker

func NewCostTracker() *CostTracker

func (*CostTracker) FormatCLI

func (c *CostTracker) FormatCLI(showByTool, showByServer bool) string

func (*CostTracker) FormatJSON

func (c *CostTracker) FormatJSON() (string, error)

func (*CostTracker) GetBreakdown

func (c *CostTracker) GetBreakdown() CostBreakdown

func (*CostTracker) GetByServer

func (c *CostTracker) GetByServer() map[string]int64

func (*CostTracker) GetByTool

func (c *CostTracker) GetByTool() map[string]int64

func (*CostTracker) GetEntries added in v0.8.0

func (c *CostTracker) GetEntries(since time.Time) []CallLogEntry

func (*CostTracker) GetPromptHashes added in v0.8.0

func (c *CostTracker) GetPromptHashes() map[string]int64

func (*CostTracker) GetPromptHashesForServerTool added in v0.8.0

func (c *CostTracker) GetPromptHashesForServerTool(server, tool string) map[string]int64

func (*CostTracker) GetServerToolStats added in v0.8.0

func (c *CostTracker) GetServerToolStats(serverName string) []NamedServerToolStat

func (*CostTracker) GetToolServerStats added in v0.8.0

func (c *CostTracker) GetToolServerStats(toolName string) []NamedServerToolStat

func (*CostTracker) GetTotal

func (c *CostTracker) GetTotal() int64

func (*CostTracker) Reset

func (c *CostTracker) Reset()

func (*CostTracker) Track

func (c *CostTracker) Track(toolName, serverName string, tokenCount int64)

func (*CostTracker) TrackAt added in v0.8.0

func (c *CostTracker) TrackAt(toolName, serverName string, tokenCount int64, ts time.Time)

func (*CostTracker) TrackWithPromptHash added in v0.8.0

func (c *CostTracker) TrackWithPromptHash(toolName, serverName string, tokenCount int64, hash string, clock Clock)

type Estimator added in v0.9.1

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

Estimator counts tokens from raw string or JSON-marshalable values using a deterministic character-length heuristic. It is intentionally side-effect free and safe for concurrent use.

func NewEstimator added in v0.9.1

func NewEstimator() *Estimator

NewEstimator returns an Estimator configured with DefaultCharsPerToken. Callers can construct alternative ratios via NewEstimatorWithRatio if they need to match a specific tokenizer profile.

func NewEstimatorWithRatio added in v0.9.1

func NewEstimatorWithRatio(charsPerToken float64) *Estimator

NewEstimatorWithRatio returns an Estimator with a custom chars/token ratio. Useful for benchmarks that want to assert savings against a fixed tokenizer-independent baseline.

func (*Estimator) CharsPerToken added in v0.9.1

func (e *Estimator) CharsPerToken() float64

CharsPerToken exposes the configured ratio for diagnostics.

func (*Estimator) EstimateJSON added in v0.9.1

func (e *Estimator) EstimateJSON(v any) int

EstimateJSON marshals the value to JSON and returns the estimated token count of the resulting JSON. Returns 0 if marshaling fails (to keep benchmarks best-effort). We deliberately swallow the marshal error so the estimator surface is `int` only — callers needing strict error handling should marshal themselves and call EstimateTokens directly.

func (*Estimator) EstimateTokens added in v0.9.1

func (e *Estimator) EstimateTokens(content string) int

EstimateTokens returns the estimated token count for the given content using the configured chars/token ratio. Empty content returns 0.

type ExportRow added in v0.8.0

type ExportRow struct {
	Timestamp     time.Time `json:"timestamp"`
	Team          string    `json:"team"`
	Project       string    `json:"project"`
	Server        string    `json:"server"`
	Tool          string    `json:"tool"`
	Tokens        int64     `json:"tokens"`
	EstimatedCost float64   `json:"estimated_cost"`
}

type NamedServerToolStat added in v0.8.0

type NamedServerToolStat struct {
	ToolName    string    `json:"tool_name"`
	ServerName  string    `json:"server_name"`
	TokenCount  int64     `json:"token_count"`
	CallCount   int64     `json:"call_count"`
	LastInvoked time.Time `json:"last_invoked"`
}

type RealClock

type RealClock struct{}

func (RealClock) Now

func (RealClock) Now() time.Time

func (RealClock) Since

func (RealClock) Since(t time.Time) time.Duration

type ServerCost

type ServerCost struct {
	ServerName string `json:"server_name"`
	TokenCount int64  `json:"token_count"`
}

type ServerToolKey added in v0.8.0

type ServerToolKey struct {
	ServerName string
	ToolName   string
}

type ServerToolStat added in v0.8.0

type ServerToolStat struct {
	TokenCount  int64     `json:"token_count"`
	CallCount   int64     `json:"call_count"`
	LastInvoked time.Time `json:"last_invoked"`
}

type ToolCost

type ToolCost struct {
	ToolName   string `json:"tool_name"`
	TokenCount int64  `json:"token_count"`
}

Jump to

Keyboard shortcuts

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