Documentation
¶
Overview ¶
Package server — metrics.go registers all Prometheus metrics for the HTTP server and exposes helpers used by handlers and middleware.
Package server implements the HTTP server that exposes the TF-AI agent via a REST/SSE API and serves the embedded web UI. The server is started by the `tfai serve` CLI command.
Package server implements the HTTP server for TF-AI. This file contains all workspace-related HTTP handlers and helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfineToDir ¶ added in v0.27.0
ConfineToDir validates that target resolves to a path inside root after cleaning both. This prevents path traversal attacks (e.g. "../../etc/passwd"). Returns the cleaned absolute target path or an error.
Types ¶
type Config ¶
type Config struct {
// Host is the address to bind to (default: 127.0.0.1).
Host string
// Port is the TCP port to listen on (default: 8080).
Port int
// ReadTimeout is the maximum duration for reading the request.
ReadTimeout time.Duration
// WriteTimeout is the maximum duration for writing the response.
WriteTimeout time.Duration
// ShutdownTimeout is the maximum duration for a graceful shutdown.
ShutdownTimeout time.Duration
// Logger is the structured logger used by the server and its handlers.
// If nil, [logging.New] is used.
Logger *slog.Logger
// Pingers is the ordered list of dependency probes run by GET /api/ready.
// If empty, /api/ready returns 200 with no checks (liveness-only mode).
Pingers []Pinger
// RateLimit is the sustained request rate allowed per IP on rate-limited
// endpoints (requests/second). Defaults to 10 if zero.
RateLimit float64
// RateBurst is the maximum instantaneous burst per IP. Defaults to 20 if zero.
RateBurst int
// APIKey is the Bearer token required on all protected /api/* routes.
// If empty, authentication is disabled (development mode).
APIKey string
// WorkspaceRoot is the root directory for workspace operations.
// If empty, the server will use the current working directory.
WorkspaceRoot string
// ChatTimeout is the maximum duration for a single /api/chat request,
// including LLM streaming. Defaults to 5 minutes if zero.
ChatTimeout time.Duration
// MetricsRegistry is the Prometheus registry used to register server
// metrics. If nil, prometheus.DefaultRegisterer / DefaultGatherer are used.
// Inject a fresh prometheus.NewRegistry() in tests to keep them hermetic.
MetricsRegistry prometheus.Registerer
// MetricsGatherer is the Prometheus gatherer paired with MetricsRegistry.
// If nil, prometheus.DefaultGatherer is used.
MetricsGatherer prometheus.Gatherer
}
Config holds the HTTP server configuration.
type LLMPinger ¶
type LLMPinger struct {
// contains filtered or unexported fields
}
LLMPinger probes an LLM backend by sending a minimal single-token generate request. It satisfies the Pinger interface and is used by GET /api/ready.
func NewLLMPinger ¶
func NewLLMPinger(m model.ToolCallingChatModel, hc provider.HealthCheckConfig, name string) *LLMPinger
NewLLMPinger constructs an LLMPinger for the given model and backend name. TODO: Remove model parameter when all providers are migrated to use healthCheck
type MultiPinger ¶
type MultiPinger struct {
// contains filtered or unexported fields
}
MultiPinger aggregates one or more Pinger implementations and reports the combined readiness of all dependencies.
func NewMultiPinger ¶
func NewMultiPinger(pingers ...Pinger) *MultiPinger
NewMultiPinger constructs a MultiPinger from the provided list of Pingers.
func (*MultiPinger) Name ¶
func (m *MultiPinger) Name() string
Name returns a combined label for logging purposes.
type Pinger ¶
type Pinger interface {
// Ping checks whether the dependency is reachable within the given context.
// Returns nil on success, a descriptive error on failure.
Ping(ctx context.Context) error
// Name returns a short human-readable label used in readiness responses
// (e.g. "ollama", "qdrant").
Name() string
}
Pinger is the interface implemented by any dependency that can report its own reachability. Each implementation must return nil when the dependency is healthy and a descriptive error otherwise. Implementations must be safe to call from multiple goroutines.
type QdrantPinger ¶
type QdrantPinger struct {
// contains filtered or unexported fields
}
QdrantPinger probes a Qdrant instance using its native HealthCheck RPC. It satisfies the Pinger interface and is used by GET /api/ready.
func NewQdrantPinger ¶
func NewQdrantPinger(client *qdrant.Client) *QdrantPinger
NewQdrantPinger constructs a QdrantPinger for the given Qdrant client.
func (*QdrantPinger) Name ¶
func (p *QdrantPinger) Name() string
Name returns the dependency label used in readiness responses.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP server that wraps the TerraformAgent.
func New ¶
func New(tfAgent *agent.TerraformAgent, cfg *Config) (*Server, error)
New constructs a Server from the provided agent and config. If cfg.Logger is nil, logging.New is used.