httpapi

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package httpapi provides the HTTP UI/API server for centaurx.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(ctx context.Context, addr string, handler http.Handler) error

ListenAndServe starts an HTTP server and shuts it down on context cancellation.

Types

type Authenticator

type Authenticator interface {
	Authenticate(username, password, totp string) error
	ChangePassword(username, currentPassword, totp, newPassword string) error
}

Authenticator verifies username, password, and totp.

type CommandHandler

type CommandHandler interface {
	Handle(ctx context.Context, userID schema.UserID, tabID schema.TabID, input string) (bool, error)
}

CommandHandler routes slash commands.

type Config

type Config struct {
	Addr               string
	SessionCookie      string
	SessionTTLHours    int
	SessionStorePath   string
	BaseURL            string
	BasePath           string
	InitialBufferLines int
	UIMaxBufferLines   int
}

Config defines HTTP API and UI settings.

type Hub

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

Hub broadcasts events per user.

func NewHub

func NewHub(historySize int) *Hub

NewHub constructs a hub with the given history size.

func (*Hub) OnOutput

func (h *Hub) OnOutput(event schema.OutputEvent)

OnOutput implements core.EventSink.

func (*Hub) OnSystemOutput

func (h *Hub) OnSystemOutput(event schema.SystemOutputEvent)

OnSystemOutput implements core.EventSink.

func (*Hub) OnTabEvent

func (h *Hub) OnTabEvent(event schema.TabEvent)

OnTabEvent implements core.EventSink.

func (*Hub) Replay

func (h *Hub) Replay(userID schema.UserID, after uint64) []StreamEvent

Replay returns events after the provided seq.

func (*Hub) Subscribe

func (h *Hub) Subscribe(userID schema.UserID) (<-chan StreamEvent, func(), uint64, []StreamEvent)

Subscribe registers a subscriber for a user.

type Server

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

Server serves the HTTP API and UI.

func NewServer

func NewServer(cfg Config, service core.Service, handler CommandHandler, authStore Authenticator, hub *Hub) *Server

NewServer constructs an HTTP server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns an http.Handler for the server.

func (*Server) SetBaseContext

func (s *Server) SetBaseContext(ctx context.Context)

SetBaseContext sets the parent context for session lifetimes.

type SnapshotPayload

type SnapshotPayload struct {
	Tabs      []schema.TabSnapshot                   `json:"tabs"`
	ActiveTab schema.TabID                           `json:"active_tab"`
	Buffers   map[schema.TabID]schema.BufferSnapshot `json:"buffers"`
	System    schema.SystemBufferSnapshot            `json:"system"`
	Theme     schema.ThemeName                       `json:"theme,omitempty"`
}

SnapshotPayload seeds client state on connect.

type StreamEvent

type StreamEvent struct {
	Seq       uint64              `json:"seq"`
	Type      string              `json:"type"`
	TabEvent  string              `json:"tab_event,omitempty"`
	TabID     schema.TabID        `json:"tab_id,omitempty"`
	Lines     []string            `json:"lines,omitempty"`
	Tab       *schema.TabSnapshot `json:"tab,omitempty"`
	ActiveTab schema.TabID        `json:"active_tab,omitempty"`
	Theme     schema.ThemeName    `json:"theme,omitempty"`
	Snapshot  *SnapshotPayload    `json:"snapshot,omitempty"`
	Timestamp time.Time           `json:"timestamp"`
}

StreamEvent is sent to SSE clients.

Jump to

Keyboard shortcuts

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