Documentation
¶
Overview ¶
Package wsapi provides an optional WebSocket transport adapter for agentwatch.
The WebSocket protocol wraps monitor.Event — it does not define separate message types. Clients receive events as JSON-encoded monitor.Event values.
Index ¶
- type Authenticator
- type Identity
- type Option
- func WithAllowedOrigins(origins []string) Option
- func WithAuthenticator(a Authenticator) Option
- func WithHeartbeat(d time.Duration) Option
- func WithLogger(l *slog.Logger) Option
- func WithMaxConnections(n int) Option
- func WithRateLimit(limit, burst int, window time.Duration) Option
- func WithSendBuffer(n int) Option
- func WithWriteTimeout(d time.Duration) Option
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
Authenticator validates WebSocket upgrade requests. Implementations should return false to reject the connection.
type Identity ¶
type Identity struct {
ID string
}
Identity represents an authenticated WebSocket client.
type Option ¶
type Option func(*serverConfig)
Option configures a Server.
func WithAllowedOrigins ¶
WithAllowedOrigins sets the allowed Origin header values for WebSocket upgrades. When empty (the default), the server allows same-origin and localhost connections.
func WithAuthenticator ¶
func WithAuthenticator(a Authenticator) Option
WithAuthenticator sets an authenticator for WebSocket upgrade requests. When set, connections that fail authentication are rejected.
func WithHeartbeat ¶
WithHeartbeat sets the interval for WebSocket ping/pong heartbeats. Defaults to 30 seconds.
func WithLogger ¶
WithLogger sets the structured logger. Defaults to slog.Default().
func WithMaxConnections ¶
WithMaxConnections sets the maximum number of concurrent WebSocket connections. Zero means unlimited.
func WithRateLimit ¶
WithRateLimit configures connection rate limiting per client IP. limit is max connections per window, burst is the initial token count. Defaults to 12 per minute with burst of 4.
func WithSendBuffer ¶
WithSendBuffer sets the per-client send channel buffer size. Defaults to 64. Clients that fall behind by this many messages are evicted.
func WithWriteTimeout ¶
WithWriteTimeout sets the maximum duration for a write to complete. Defaults to 10 seconds.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a WebSocket transport adapter for agentwatch. It implements monitor.EventSink: events from the monitor are fanned out to all connected WebSocket clients.
On connect, clients receive an initial snapshot event. Subsequent events (deltas, lifecycle, health) are delivered as they arrive from the monitor.
func NewServer ¶
NewServer creates a WebSocket server that broadcasts monitor events to connected clients. The server implements monitor.EventSink.
func (*Server) ClientCount ¶
ClientCount returns the number of currently connected clients.
func (*Server) HandleEvent ¶
HandleEvent implements monitor.EventSink. It fans out the event to all connected WebSocket clients. Returns quickly via non-blocking sends.