server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvAllowedOrigins = "HOTPLEX_ALLOWED_ORIGINS"
	EnvAPIKey         = "HOTPLEX_API_KEY"  // Single API key (for simplicity)
	EnvAPIKeys        = "HOTPLEX_API_KEYS" // Multiple API keys (comma-separated)
)

Environment variable names

Variables

View Source
var DefaultAllowedOrigins = []string{
	"http://localhost:3000",
	"http://localhost:8080",
	"http://127.0.0.1:3000",
	"http://127.0.0.1:8080",
}

DefaultAllowedOrigins are used when no environment variable is set.

Functions

This section is empty.

Types

type ClientRequest

type ClientRequest struct {
	RequestID    int    `json:"request_id,omitempty"`   // Optional request ID for request-response correlation
	Type         string `json:"type"`                   // "execute", "stop", "stats", "version"
	SessionID    string `json:"session_id"`             // Provide session_id to hot-multiplex
	Prompt       string `json:"prompt,omitempty"`       // The user input (for "execute")
	Instructions string `json:"instructions,omitempty"` // Per-task instructions (for "execute")
	WorkDir      string `json:"work_dir,omitempty"`     // Working directory for CLI (for "execute")
	Reason       string `json:"reason,omitempty"`       // Reason for stopping (for "stop")
}

ClientRequest represents the JSON payload expected from the WebSocket client.

type ExecutionController added in v0.8.1

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

func NewExecutionController added in v0.8.1

func NewExecutionController(engine hotplex.HotPlexClient, logger *slog.Logger) *ExecutionController

func (*ExecutionController) Execute added in v0.8.1

type ExecutionRequest added in v0.8.1

type ExecutionRequest struct {
	SessionID    string
	Prompt       string
	Instructions string
	WorkDir      string
	Timeout      time.Duration
}

type HealthHandler added in v0.9.0

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

HealthHandler provides HTTP endpoints for health checking and metrics.

func NewHealthHandler added in v0.9.0

func NewHealthHandler() *HealthHandler

NewHealthHandler creates a new HealthHandler.

func (*HealthHandler) ServeHTTP added in v0.9.0

func (h *HealthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles /health requests.

type HealthResponse added in v0.9.0

type HealthResponse struct {
	Status    telemetry.HealthStatus `json:"status"`
	Timestamp string                 `json:"timestamp"`
	Uptime    string                 `json:"uptime"`
	Checks    map[string]bool        `json:"checks,omitempty"`
}

HealthResponse represents the health check response.

type HotPlexWSHandler added in v0.8.0

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

HotPlexWSHandler manages a WebSocket connection to a HotPlex Engine.

func NewHotPlexWSHandler added in v0.8.0

func NewHotPlexWSHandler(engine hotplex.HotPlexClient, logger *slog.Logger, cors *SecurityConfig) *HotPlexWSHandler

NewHotPlexWSHandler creates a new handler with security configuration.

func (*HotPlexWSHandler) ServeHTTP added in v0.8.0

func (h *HotPlexWSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades the HTTP connection and starts the read loop.

type LiveHandler added in v0.9.0

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

LiveHandler handles /health/live requests (Kubernetes liveness probe).

func NewLiveHandler added in v0.9.0

func NewLiveHandler() *LiveHandler

NewLiveHandler creates a new LiveHandler.

func (*LiveHandler) ServeHTTP added in v0.9.0

func (h *LiveHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MetricsHandler added in v0.9.0

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

MetricsHandler handles /metrics requests (Prometheus format).

func NewMetricsHandler added in v0.9.0

func NewMetricsHandler() *MetricsHandler

NewMetricsHandler creates a new MetricsHandler.

func (*MetricsHandler) ServeHTTP added in v0.9.0

func (h *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type OpenCodeHTTPHandler added in v0.8.0

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

OpenCodeHTTPHandler implements a server compatible with OpenCode's HTTP/SSE protocol.

func NewOpenCodeHTTPHandler added in v0.8.0

func NewOpenCodeHTTPHandler(engine hotplex.HotPlexClient, logger *slog.Logger, cors *SecurityConfig) *OpenCodeHTTPHandler

NewOpenCodeHTTPHandler creates a new OpenCodeHTTPHandler instance.

func (*OpenCodeHTTPHandler) RegisterRoutes added in v0.8.0

func (s *OpenCodeHTTPHandler) RegisterRoutes(r *mux.Router)

RegisterRoutes registers the OpenCode compatibility routes to a router.

type ReadyHandler added in v0.9.0

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

ReadyHandler handles /health/ready requests (Kubernetes readiness probe).

func NewReadyHandler added in v0.9.0

func NewReadyHandler(engineReady func() bool) *ReadyHandler

NewReadyHandler creates a new ReadyHandler.

func (*ReadyHandler) ServeHTTP added in v0.9.0

func (h *ReadyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SecurityConfig added in v0.8.0

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

SecurityConfig holds the allowed origins and API key for WebSocket security validation.

func NewSecurityConfig added in v0.8.0

func NewSecurityConfig(logger *slog.Logger) *SecurityConfig

NewSecurityConfig creates a new SecurityConfig from environment variables. - HOTPLEX_ALLOWED_ORIGINS: Comma-separated list of allowed origins (defaults to localhost) - HOTPLEX_API_KEY: Single API key for authentication - HOTPLEX_API_KEYS: Multiple API keys (comma-separated, takes precedence over HOTPLEX_API_KEY)

func (*SecurityConfig) AddAPIKey added in v0.8.0

func (c *SecurityConfig) AddAPIKey(key string)

AddAPIKey adds a new API key at runtime.

func (*SecurityConfig) AddOrigin added in v0.8.0

func (c *SecurityConfig) AddOrigin(origin string)

AddOrigin adds a new allowed origin at runtime.

func (*SecurityConfig) CheckOrigin added in v0.8.0

func (c *SecurityConfig) CheckOrigin() func(r *http.Request) bool

CheckOrigin returns a function suitable for websocket.Upgrader.CheckOrigin. It validates both Origin header and API key (if enabled).

func (*SecurityConfig) IsAPIKeyEnabled added in v0.8.0

func (c *SecurityConfig) IsAPIKeyEnabled() bool

IsAPIKeyEnabled returns whether API key authentication is enabled.

func (*SecurityConfig) ListOrigins added in v0.8.0

func (c *SecurityConfig) ListOrigins() []string

ListOrigins returns a copy of the current allowed origins.

func (*SecurityConfig) RemoveAPIKey added in v0.8.0

func (c *SecurityConfig) RemoveAPIKey(key string)

RemoveAPIKey removes an API key.

func (*SecurityConfig) RemoveOrigin added in v0.8.0

func (c *SecurityConfig) RemoveOrigin(origin string)

RemoveOrigin removes an origin from the allowed list.

type ServerResponse

type ServerResponse struct {
	RequestID int    `json:"request_id,omitempty"` // Echo back request_id for correlation
	Event     string `json:"event"`
	Data      any    `json:"data"`
}

ServerResponse represents the JSON payload sent to the WebSocket client.

Jump to

Keyboard shortcuts

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