config

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 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

Overview

Package config loads and validates the relay's runtime configuration from environment variables (see the build plan's Step 2 and the deploy compose files). Every field has a default, so an empty environment produces a usable, if not internet-facing-appropriate, configuration — but Load fails loudly on a malformed value rather than silently falling back, so a bad deploy config is caught at startup, not at 3am under load.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr           string // e.g. ":8080"
	MetricsAddr    string // e.g. ":9091" — bind to loopback only in deploy
	AllowedOrigins []string

	MaxFrameBytes int
	MaxPairs      int

	PingInterval time.Duration
	PongTimeout  time.Duration
	HelloTimeout time.Duration
	WriteTimeout time.Duration
	// AgentGrace is how long a pair is kept alive, agentless, after its
	// agent disconnects while a client is still attached — the window in
	// which a restarting or reconnecting agent slots back into the same
	// pair without the client noticing more than a pause. See the
	// server's retireAgent.
	AgentGrace    time.Duration
	ShutdownGrace time.Duration

	PairRateBytesPerSec int64
	IPConnPerMin        int
	TrustProxy          bool

	// OpenAI-compatible HTTP endpoint (spec §11). Serving the route costs
	// nothing when no agent opts in — an agent must connect in mode:"http"
	// with a token hash before any key resolves — but HTTPEnabled exists so
	// a deploy can refuse the whole surface outright.
	HTTPEnabled bool
	// HTTPMaxInFlight caps concurrent requests per key. One consumer GPU
	// thrashes badly past a handful of parallel generations, so shedding
	// with 429 beats queueing without bound.
	HTTPMaxInFlight int
	// HTTPTombstoneTTL is how long a key stays resolvable after its agent
	// disconnects, so the endpoint can answer 503 "offline" instead of 401
	// "bad key". Past this, the entry is evicted and the key reads as
	// unknown until the agent reconnects.
	HTTPTombstoneTTL time.Duration
	// HTTPFirstByteTimeout bounds the wait for the agent's RESP. Generous
	// by default: a cold model load on a sleeping laptop is slow, and the
	// failure mode of being too tight is a confusing 504 on a request that
	// would have succeeded.
	HTTPFirstByteTimeout time.Duration
	// HTTPKeepaliveInterval is the gap after which an SSE response emits a
	// comment line to keep intermediaries and client read timeouts from
	// giving up during a long pause. Zero disables it.
	HTTPKeepaliveInterval time.Duration
	// HTTPStreamBuffer is the per-request response-frame buffer. Small on
	// purpose — see hub.Stream on why buffering here would defeat
	// backpressure rather than improve throughput.
	HTTPStreamBuffer int

	LogLevel  string // "debug"|"info"|"warn"|"error"
	LogFormat string // "json"|"text"
}

func Defaults

func Defaults() Config

Defaults returns the configuration used when no environment variable overrides a field — the values named throughout spec/PROTOCOL.md and the build plan.

func Load

func Load() (Config, error)

Load reads Defaults() and applies RELAY_* environment overrides, returning a descriptive error on the first invalid value rather than a partially-applied config.

func (Config) Validate

func (c Config) Validate() error

Validate rejects configurations that would either fail immediately or silently misbehave (e.g. a zero timeout that turns every write into an instant failure).

Jump to

Keyboard shortcuts

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