server

package
v0.0.0-...-5ed4770 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package server provides the HTTP server with dependency injection for all application services.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingDependency = errors.New("missing required dependency")

ErrMissingDependency is returned when a required dependency is nil.

Functions

func SyncSeqFromDB

func SyncSeqFromDB(ctx context.Context, storeClient store.Store, cacheClient cache.Cache, logger *slog.Logger) error

SyncSeqFromDB synchronizes cache sequence counters with the database. For each distinct (scope, scopeID) pair in the updates table, it reads the max(seq) from the DB and sets the cache to max(max_seq, current_cache_seq). This prevents seq collisions when the cache is flushed or restarted.

Types

type AgentRunner

type AgentRunner interface {
}

AgentRunner runs agent queries. Implemented by internal/agent.Agent.

type HealthResponse

type HealthResponse struct {
	Status     string            `json:"status"`     // "ok" or "degraded"
	Components map[string]string `json:"components"` // e.g. "redis": "ok", "db": "error"
}

HealthResponse is the JSON response for the /healthz endpoint.

type Option

type Option func(*Server) error

Option is a function that configures the Server.

func WithAgent

func WithAgent(a AgentRunner) Option

WithAgent sets the AgentRunner dependency (optional).

func WithCache

func WithCache(c cache.Cache) Option

WithCache sets the Cache dependency.

func WithConfig

func WithConfig(cfg *config.Config) Option

WithConfig sets the Config dependency.

func WithConnectionManager

func WithConnectionManager(cm *websocket.ConnectionManager) Option

WithConnectionManager sets the WebSocket ConnectionManager.

func WithLogLevel

func WithLogLevel(lv *slog.LevelVar) Option

WithLogLevel sets the slog.LevelVar for runtime log level adjustment (optional).

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the Logger dependency.

func WithQueue

func WithQueue(q task.TaskQueue) Option

WithQueue sets the TaskQueue dependency.

func WithQueueManager

func WithQueueManager(qm task.Manager) Option

WithQueueManager sets the queue.Manager dependency (optional).

func WithReadyFunc

func WithReadyFunc(fn func()) Option

WithReadyFunc sets an optional callback invoked when the server is ready.

func WithSessionHandler

func WithSessionHandler(h SessionDelegate) Option

WithSessionHandler sets the SessionDelegate dependency (optional).

func WithStatisticsStore

func WithStatisticsStore(ss agent.StatisticsStore) Option

WithStatisticsStore sets the StatisticsStore dependency (optional).

func WithStore

func WithStore(s store.Store) Option

WithStore sets the Store dependency.

func WithTelemetry

func WithTelemetry(te *telemetry.Telemetry) Option

WithTelemetry sets the Telemetry dependency (optional).

func WithWebhookStore

func WithWebhookStore(ws webhook.Store) Option

WithWebhookStore sets the webhook.Store dependency (optional).

type SenderAdapter

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

SenderAdapter bridges the session handler's update methods to agent.UpdateDispatcher. It supports late-binding: the underlying session handler is set after construction to break the agent ↔ session circular dependency.

func NewSenderAdapter

func NewSenderAdapter() *SenderAdapter

NewSenderAdapter creates a SenderAdapter with no backing session handler yet. Call SetSession before using the sender.

func (*SenderAdapter) SendPersistent

func (a *SenderAdapter) SendPersistent(ctx context.Context, conversationID string, update agent.PersistentUpdate) error

SendPersistent sends a persistent update via the session handler.

func (*SenderAdapter) SendStreaming

func (a *SenderAdapter) SendStreaming(ctx context.Context, conversationID string, chunk agent.StreamingChunk) error

SendStreaming sends a non-persistent streaming chunk via the session handler.

func (*SenderAdapter) SetSession

func (a *SenderAdapter) SetSession(s SessionUpdateWriter)

SetSession sets the underlying session handler. Must be called before any Send.

type Server

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

Server holds all application dependencies and HTTP infrastructure.

func NewServer

func NewServer(opts ...Option) (*Server, error)

NewServer creates a Server with the provided options. All required dependencies (Store, Cache, TaskQueue, Config, Logger) must be set.

func (*Server) Router

func (s *Server) Router() *chi.Mux

Router returns the chi.Mux router, lazily initialized with routes.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start blocks until an OS signal (SIGINT/SIGTERM) is received, then gracefully shuts down.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully shuts down in reverse order: HTTP -> Queue -> Cache.

type SessionDelegate

type SessionDelegate interface {
	HandleMessage(ctx context.Context, connID string, data []byte)
	OnConnectionClose(ctx context.Context, connID string)
}

SessionDelegate handles WebSocket session messages. Implemented by internal/session.Handler.

type SessionUpdateWriter

type SessionUpdateWriter interface {
	SendNonPersistentUpdate(ctx context.Context, scope, scopeID, kind string, payload []byte) error
	SendPersistentUpdate(ctx context.Context, scope, scopeID, kind string, payload []byte, convID string) (uint64, error)
}

SessionUpdateWriter is the interface the adapter needs from the session handler.

Jump to

Keyboard shortcuts

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