Documentation
¶
Index ¶
- func MintTicket(secret []byte, userID, accountID string, now time.Time) (ticket string, expiresAt time.Time, err error)
- func NewHandler(hub *Hub, authClient *grpcclient.AuthServiceClient, ...) http.HandlerFunc
- func NewTicketHandler(authClient *grpcclient.AuthServiceClient, ticketSecret []byte) http.HandlerFunc
- func StartEventConsumer(ctx context.Context, broker messaging.MessageBroker, hub *Hub) error
- func StartNotificationConsumer(ctx context.Context, broker messaging.MessageBroker, hub *Hub) error
- func StartRunCompletedConsumer(ctx context.Context, broker messaging.MessageBroker, hub *Hub) error
- func VerifyTicket(secret []byte, ticket string, now time.Time) (userID, accountID string, err error)
- type Client
- type Hub
- type ParticipantChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MintTicket ¶
func MintTicket(secret []byte, userID, accountID string, now time.Time) (ticket string, expiresAt time.Time, err error)
MintTicket signs a short-lived WebSocket connection ticket for an already-authenticated user/account pair.
func NewHandler ¶
func NewHandler(hub *Hub, authClient *grpcclient.AuthServiceClient, notificationClient *grpcclient.NotificationServiceClient, ticketSecret []byte) http.HandlerFunc
NewHandler returns an http.HandlerFunc that upgrades HTTP connections to WebSocket, authenticates the connection, and starts the client read/write pumps. Authentication is cookie-based (cookie + account ID query param) for first-party origins; connections from custom portal domains cannot send the auth cookie cross-origin, so they instead present a short-lived ticket minted by the cookie-authenticated ticket endpoint. notificationClient may be nil (conversation-subscribe authz is then unavailable). ticketSecret may be nil (ticket auth is then disabled).
func NewTicketHandler ¶
func NewTicketHandler(authClient *grpcclient.AuthServiceClient, ticketSecret []byte) http.HandlerFunc
NewTicketHandler returns an http.HandlerFunc that mints short-lived WebSocket tickets for cookie-authenticated callers. Custom portal domains reach it through the frontend's same-origin API proxy (so the auth cookie is present), then open the WebSocket cross-origin to the API host with the ticket instead of the cookie. When ticketSecret is empty the endpoint is disabled.
func StartEventConsumer ¶
StartEventConsumer starts a RabbitMQ consumer that reads agent run step events and fans them out to WebSocket clients via the hub.
func StartNotificationConsumer ¶
StartNotificationConsumer starts a RabbitMQ consumer that reads in-app notification / messaging realtime-delivery events and fans them out to WebSocket clients via the hub, routing to the per-user topic (the bell) and/or a conversation topic (live chat).
func StartRunCompletedConsumer ¶
StartRunCompletedConsumer starts a RabbitMQ consumer that reads agent run completed events and fans them out to WebSocket clients via the hub.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a single WebSocket connection.
func NewClient ¶
func NewClient(conn *websocket.Conn, hub *Hub, accountID, userID string, checkParticipant ParticipantChecker) *Client
NewClient creates a new Client.
func (*Client) ReadPump ¶
ReadPump reads messages from the WebSocket connection and handles subscribe, unsubscribe, and ping commands.
func (*Client) SubscribeAccountTopic ¶
func (c *Client) SubscribeAccountTopic()
SubscribeAccountTopic subscribes the client to its account's broadcast topic so account-wide announcements arrive live. Called on connect.
func (*Client) SubscribeUserGlobalTopic ¶
func (c *Client) SubscribeUserGlobalTopic()
SubscribeUserGlobalTopic subscribes the client to its account-independent user topic, used for cross-account unread hints. Called on connect.
func (*Client) SubscribeUserTopic ¶
func (c *Client) SubscribeUserTopic()
SubscribeUserTopic subscribes the client to its own notification (bell) topic. Called on connect so a user receives notifications without an explicit subscribe message.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages WebSocket client subscriptions keyed by topic string. Topics namespace the different event streams: "run:<agent_run_id>" (agent run events), "user:<user_id>" (a user's notification bell), and "conv:<conversation_id>" (live chat, future). It fans out incoming events to all clients subscribed to a topic, with tenant isolation via account ID checks.
func (*Hub) Publish ¶
Publish sends an event to all clients subscribed to the given topic. Only clients whose account ID matches the event's account ID receive the message, ensuring tenant isolation.
func (*Hub) PublishGlobal ¶
PublishGlobal sends an event to all clients on a topic WITHOUT the account-isolation check. It is only safe for inherently user-scoped topics (userglobal:<user_id>), where every subscriber is the same user, and is used to carry cross-account unread hints to a user's connections regardless of which account they are currently viewing.
func (*Hub) RemoveClient ¶
RemoveClient unsubscribes a client from all topics it was subscribed to.
func (*Hub) Unsubscribe ¶
Unsubscribe removes a client from events on the given topic.