server

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 12 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 CORSConfig added in v0.7.0

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

CORSConfig holds the allowed origins and API key for WebSocket CORS validation.

func NewCORSConfig added in v0.7.0

func NewCORSConfig(logger *slog.Logger) *CORSConfig

NewCORSConfig creates a new CORSConfig 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 (*CORSConfig) AddAPIKey added in v0.7.0

func (c *CORSConfig) AddAPIKey(key string)

AddAPIKey adds a new API key at runtime.

func (*CORSConfig) AddOrigin added in v0.7.0

func (c *CORSConfig) AddOrigin(origin string)

AddOrigin adds a new allowed origin at runtime.

func (*CORSConfig) CheckOrigin added in v0.7.0

func (c *CORSConfig) 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 (*CORSConfig) IsAPIKeyEnabled added in v0.7.0

func (c *CORSConfig) IsAPIKeyEnabled() bool

IsAPIKeyEnabled returns whether API key authentication is enabled.

func (*CORSConfig) ListOrigins added in v0.7.0

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

ListOrigins returns a copy of the current allowed origins.

func (*CORSConfig) RemoveAPIKey added in v0.7.0

func (c *CORSConfig) RemoveAPIKey(key string)

RemoveAPIKey removes an API key.

func (*CORSConfig) RemoveOrigin added in v0.7.0

func (c *CORSConfig) RemoveOrigin(origin string)

RemoveOrigin removes an origin from the allowed list.

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")
	SystemPrompt string `json:"system_prompt,omitempty"` // Override system prompt (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 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.

type WebSocketHandler

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

WebSocketHandler manages a WebSocket connection to a HotPlex Engine.

func NewWebSocketHandler

func NewWebSocketHandler(engine hotplex.HotPlexClient, logger *slog.Logger, cors *CORSConfig) *WebSocketHandler

NewWebSocketHandler creates a new handler with CORS configuration.

func (*WebSocketHandler) ServeHTTP

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

ServeHTTP upgrades the HTTP connection and starts the read loop.

Jump to

Keyboard shortcuts

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