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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 once and fans it out to every connected SSE subscriber. A slow subscriber's buffer is allowed to drop 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).
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 marshals the event to JSON and delivers it to every subscriber. Drops to a subscriber whose buffer is full rather than blocking. A marshal failure is dropped silently — one bad event shouldn't stall the stream.
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 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) *Server
New builds a Server. bc must be the controller's event sink.
func (*Server) Handler ¶
Handler returns the HTTP routes: GET / (a minimal browser client), GET /events (SSE), GET /history, GET /context, and POST command endpoints. CORS is NOT applied by default — same-origin policy protects the unauthenticated agent endpoints. Call HandlerWithCORS to opt in for local development.
func (*Server) HandlerWithCORS ¶
HandlerWithCORS returns the same routes as Handler but adds permissive CORS headers so a dev frontend on a different origin (e.g. Vite on :5173) can reach the server. Do NOT use in production — the server has no auth.