routing

package
v1.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mode

type Mode string

Mode represents an operating mode that controls cost/quality trade-offs.

const (
	ModeQuick    Mode = "quick"
	ModeBalanced Mode = "balanced"
	ModeThorough Mode = "thorough"
)

func ParseMode

func ParseMode(s string) (Mode, bool)

ParseMode converts a string to a Mode, returning the mode and whether the string was a valid mode name.

type ProviderStats

type ProviderStats struct {
	ProviderID      string
	AvgLatencyMS    float64
	ErrorRate       float64
	TotalSuccessful int
}

ProviderStats holds aggregated telemetry statistics for a single provider.

type Router

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

Router selects providers based on telemetry-derived heuristic scores.

func NewRouter

func NewRouter(telemetryPath string) *Router

NewRouter creates a Router that reads telemetry data from the given path.

func (*Router) LoadTelemetryStats

func (r *Router) LoadTelemetryStats() error

LoadTelemetryStats reads the telemetry JSONL file and aggregates per-provider statistics (average latency, error rate, total successful queries).

func (*Router) ScoreProvider

func (r *Router) ScoreProvider(stats ProviderStats) float64

ScoreProvider computes a heuristic score for a provider based on its stats. Higher scores indicate better providers. Providers with zero history receive a neutral score of 1.0.

func (*Router) SelectProviders

func (r *Router) SelectProviders(mode Mode, allHealthy []provider.Provider, primaryID string) []provider.Provider

SelectProviders returns a subset of allHealthy providers based on the given mode and heuristic scores.

  • quick: returns only the primary provider
  • balanced: returns the primary plus the best-scoring non-primary
  • thorough: returns all healthy providers

Jump to

Keyboard shortcuts

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