Documentation
¶
Overview ¶
Package sockets serves the runtime's JSON sockets: /api/status (tab states, background work, the prompt queue, pane intents, limits) and /api/sync (layout and workspace changes, toasts and commands to the page). One of the clients is usually the machine agent's relay into the cluster stream; the rest are pages.
Index ¶
Constants ¶
const ( PingFrame = `{"type":"ping"}` PongFrame = `{"type":"pong"}` )
PingFrame and PongFrame are the page's own heartbeat: a browser cannot see protocol pings, so a socket the network dropped silently looks open to it for minutes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Relay bool // the machine agent's socket (?relay=1)
// contains filtered or unexported fields
}
Client is one open socket.
func (*Client) Close ¶
func (c *Client) Close(code websocket.StatusCode, reason string)
Close ends the socket once.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is the set of open sockets of one kind.
func (*Hub) Broadcast ¶
Broadcast sends v to every client but exclude; a client too far behind misses it.
type StatusServer ¶
type StatusServer struct {
Hub *Hub
Source StatusSource
}
StatusServer is /api/status.
func (*StatusServer) ServeHTTP ¶
func (s *StatusServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP upgrades and serves one status socket. Authentication is the caller's.
type StatusSource ¶
type StatusSource interface {
// RateLimits is the last limits content, or nil before the first one.
RateLimits() any
// Tabs is every tab as the page sees it; Background every tab with background work.
Tabs() any
Background() any
// Queues and Intents are read after the snapshot; they may take a moment.
Queues() any
Intents() any
// History is the clipped session history, sent only when a page asks (it is large and one panel reads it).
History() any
// Dismiss: a page acknowledged a finished turn. A page's own socket gets no echo; the relay does, because it
// carries the messages of every page reading the cluster stream.
Dismiss(tabID string, exclude *Client)
Ack(tabID string, seq float64)
IntentsApplied(tabID string, ids []string, device string)
Warn(msg string)
}
StatusSource is what the status socket reads and where the page's messages go.
type SyncServer ¶
type SyncServer struct {
Hub *Hub
// contains filtered or unexported fields
}
SyncServer is /api/sync: what changed (layouts, workspaces), toasts, and commands for the page. The page sends nothing but its heartbeat.
func (*SyncServer) Broadcast ¶
func (s *SyncServer) Broadcast(event any)
Broadcast sends an event to every sync socket.
func (*SyncServer) ServeHTTP ¶
func (s *SyncServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP upgrades and serves one sync socket. Authentication is the caller's.
func (*SyncServer) Toast ¶
func (s *SyncServer) Toast(key string, toast any)
Toast is shown now and to every socket that connects later; the key replaces an earlier toast of the same kind.