Documentation
¶
Overview ¶
Package serve exposes a control.Controller over HTTP: the typed event stream as Server-Sent Events, and the commands as small JSON POST endpoints. It is a second frontend alongside the chat TUI — proof that the controller is transport-agnostic, and the basis for a browser/desktop client. One server drives one session; multiple browser tabs share it.
SECURITY: By default the server binds to localhost so only local processes can reach it. For remote access (mobile app, team sharing), configure --api-key or --sso to enable authentication. Never expose an unprotected server on a network interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAPIKey ¶
func GenerateAPIKey() string
GenerateAPIKey creates a random API key with the "ok_" prefix. 32 hex characters = 128 bits of entropy.
Types ¶
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
Broadcaster is the event sink the controller emits to in server mode. It marshals each event to JSON and fans it out to every connected SSE subscriber. A slow subscriber's buffer drops rather than back-pressure the agent goroutine — a browser that can't keep up loses intermediate frames, not the whole session (it can refetch /history).
Broadcaster implements both the old event.Sink (via Emit) and the new eventpipe.Sink (via EmitTyped). It uses the shared eventpipe.ToWire for serialization, replacing the previously duplicated toWire logic.
func NewBroadcaster ¶
func NewBroadcaster() *Broadcaster
NewBroadcaster returns an empty Broadcaster ready to accept subscribers.
func (*Broadcaster) Emit ¶
func (b *Broadcaster) Emit(e *event.Event)
Emit implements event.Sink (old interface) by converting to typed event and broadcasting. This preserves backward compatibility while using the shared eventpipe.ToWire format.
func (*Broadcaster) EmitTyped ¶
func (b *Broadcaster) EmitTyped(ev eventpipe.Event)
EmitTyped implements eventpipe.Sink by broadcasting the typed event directly using the shared eventpipe.ToWire format.
func (*Broadcaster) Subscribe ¶
func (b *Broadcaster) Subscribe() (<-chan []byte, func())
Subscribe registers a new SSE client and returns its channel plus an unsubscribe func the handler must call (defer) when the client disconnects.
func (*Broadcaster) Subscribers ¶
func (b *Broadcaster) Subscribers() int
Subscribers reports the current connection count (for diagnostics/tests).
type RunOptions ¶
type RunOptions struct {
Addr string // e.g. "127.0.0.1:3030" or "0.0.0.0:3030"
TLSCert string // empty = plain HTTP
TLSKey string // empty = plain HTTP
}
RunOptions configures the HTTP server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wires a controller to its HTTP surface. The Broadcaster must be the same sink the controller was constructed with, so events reach SSE clients.
func New ¶
func New(ctrl *control.Controller, bc *Broadcaster, opts ...ServerOption) *Server
New builds a Server. bc must be the controller's event sink.
func (*Server) RunWith ¶
func (s *Server) RunWith(opts RunOptions) error
RunWith serves with full options including TLS.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption configures Server with enterprise features.
func WithAPIKey ¶
func WithAPIKey(key string) ServerOption
WithAPIKey enables API Key authentication on the server.
func WithAdminAPI ¶
func WithAdminAPI(ctrl enterprise.Controller, exporter *enterprise.AuditExporter, authorizer *enterprise.Authorizer, apiKey string) ServerOption
WithAdminAPI enables the admin REST API + Prometheus metrics.
func WithSSO ¶
func WithSSO(issuerURL, clientID string) ServerOption
WithSSO enables OIDC-based authentication.