ws

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildNotification

func BuildNotification(msg *identity.Message) []byte

BuildNotification creates a lightweight JSON notification from a message.

Types

type Handler

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

Handler upgrades HTTP connections to WebSocket for local-mode agents.

func NewHandler

func NewHandler(hub *Hub, store HandlerStore) *Handler

func (*Handler) Handle

func (h *Handler) Handle(w http.ResponseWriter, r *http.Request)

Handle is the HTTP handler for WebSocket upgrade requests. Route: GET /api/v1/agents/{email}/ws?token={api_key}

type HandlerStore

type HandlerStore interface {
	GetUserByAPIKey(ctx context.Context, apiKey string) (*identity.User, error)
	GetAgentByEmail(ctx context.Context, email string) (*identity.AgentIdentity, error)
	GetMessagesByAgent(ctx context.Context, f identity.MessageListFilter) ([]identity.Message, error)
}

HandlerStore is the subset of identity.Store that the WS handler needs.

type Hub

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

Hub manages WebSocket connections for local-mode agents. One connection per agent; new connections replace old ones.

func NewHub

func NewHub() *Hub

func (*Hub) Close

func (h *Hub) Close()

Close closes all active connections.

func (*Hub) IsConnected

func (h *Hub) IsConnected(agentID string) bool

IsConnected returns whether an agent has an active WebSocket connection.

func (*Hub) Register

func (h *Hub) Register(agentID string, conn *websocket.Conn) (old *websocket.Conn)

Register stores a connection for the given agent, returning any previous connection. The caller should close the old connection if non-nil.

func (*Hub) Send

func (h *Hub) Send(agentID string, msg []byte) bool

Send writes a message to the agent's WebSocket connection. Returns true if the message was sent successfully.

func (*Hub) Unregister

func (h *Hub) Unregister(agentID string, conn *websocket.Conn)

Unregister removes the connection for the given agent. Only removes if the current connection matches (prevents race with re-register).

type Notification

type Notification struct {
	MessageID      string    `json:"message_id"`
	ConversationID string    `json:"conversation_id,omitempty"`
	From           string    `json:"from"`
	Recipient      string    `json:"recipient"`
	Subject        string    `json:"subject"`
	ReceivedAt     time.Time `json:"received_at"`
}

Notification is the lightweight JSON payload sent over WebSocket when a new message arrives. It contains only metadata — the full message (including the To/Cc lists) is fetched via REST.

Jump to

Keyboard shortcuts

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