Documentation
¶
Index ¶
- type BroadcastMessage
- type Client
- type Envelope
- func NewHITLRequestPendingEvent(sessionID types.SessionID, view *HITLView) Envelope
- func NewHITLRequestResolvedEvent(sessionID types.SessionID, view *HITLView) Envelope
- func NewSessionCreatedEvent(s *session.Session) Envelope
- func NewSessionMessageAddedEvent(m *session.Message) Envelope
- func NewSessionMessageUpdatedEvent(m *session.Message) Envelope
- func NewTurnEndedEvent(t *session.Turn) Envelope
- func NewTurnStartedEvent(t *session.Turn) Envelope
- type EventKind
- type HITLView
- type Handler
- type Hub
- func (h *Hub) BroadcastToTicket(ticketID types.TicketID, message []byte)
- func (h *Hub) Close() error
- func (h *Hub) GetActiveTickets() []types.TicketID
- func (h *Hub) GetClientCount(ticketID types.TicketID) int
- func (h *Hub) GetTotalClientCount() int
- func (h *Hub) NewClient(conn *websocket.Conn, ticketID types.TicketID, userID string) *Client
- func (h *Hub) NewClientWithTabID(conn *websocket.Conn, ticketID types.TicketID, userID string, tabID string) *Client
- func (h *Hub) Register(client *Client)
- func (h *Hub) Run()
- func (h *Hub) SendErrorToTicket(ticketID types.TicketID, content string) error
- func (h *Hub) SendMessageToClient(clientID string, content string, user *websocket_model.User) error
- func (h *Hub) SendMessageToTicket(ticketID types.TicketID, content string, user *websocket_model.User) error
- func (h *Hub) SendStatusToTicket(ticketID types.TicketID, content string) error
- func (h *Hub) SendToClient(clientID string, response *websocket_model.ChatResponse) error
- func (h *Hub) SendToTicket(ticketID types.TicketID, response *websocket_model.ChatResponse) error
- func (h *Hub) SendTraceToClient(clientID string, content string, user *websocket_model.User) error
- func (h *Hub) SendWarningToClient(clientID string, content string, user *websocket_model.User) error
- func (h *Hub) Unregister(client *Client)
- type MessageView
- type SessionView
- type TurnView
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BroadcastMessage ¶
BroadcastMessage represents a message to be broadcast to all clients of a ticket
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a middleman between the websocket connection and the hub
func (*Client) AttachSession ¶ added in v0.16.0
AttachSession binds a resolved Session to the client. Called once by the handler after EnsureWebSession succeeds.
func (*Client) GetClientID ¶
GetClientID returns the client ID for a client
type Envelope ¶ added in v0.16.0
type Envelope struct {
Event EventKind `json:"event"`
Timestamp time.Time `json:"timestamp"`
SessionID types.SessionID `json:"session_id,omitempty"`
TurnID *types.TurnID `json:"turn_id,omitempty"`
Message *MessageView `json:"message,omitempty"`
Session *SessionView `json:"session,omitempty"`
Turn *TurnView `json:"turn,omitempty"`
Status session.TurnStatus `json:"status,omitempty"`
Intent string `json:"intent,omitempty"`
HITL *HITLView `json:"hitl,omitempty"`
}
Envelope is the common wire shape for redesign events. Only the fields relevant to the event kind are populated; all others are omitted to keep payloads compact.
func NewHITLRequestPendingEvent ¶ added in v0.16.0
NewHITLRequestPendingEvent builds the envelope emitted when a Web-facing HITL request enters pending state. messageID optionally binds the prompt to an existing progress message so the UI can render approval UI in-place.
func NewHITLRequestResolvedEvent ¶ added in v0.16.0
NewHITLRequestResolvedEvent builds the envelope emitted when a HITL request transitions out of pending state. The Web UI uses this to clear the approval/question prompt.
func NewSessionCreatedEvent ¶ added in v0.16.0
NewSessionCreatedEvent builds the envelope for a newly created Session.
func NewSessionMessageAddedEvent ¶ added in v0.16.0
NewSessionMessageAddedEvent builds the envelope for a newly persisted Message. created_at / timestamp default to m.CreatedAt if zero.
func NewSessionMessageUpdatedEvent ¶ added in v0.16.0
NewSessionMessageUpdatedEvent builds the envelope for a Message whose content was replaced in-place (updatable trace / HITL target). The MessageView carries the *current* content; prior revisions live on the persisted Message and are not shipped over the wire to keep events small.
func NewTurnEndedEvent ¶ added in v0.16.0
NewTurnEndedEvent builds the envelope for a Turn that has entered a terminal state (completed / aborted).
func NewTurnStartedEvent ¶ added in v0.16.0
NewTurnStartedEvent builds the envelope for a Turn that has just entered running state.
type EventKind ¶ added in v0.16.0
type EventKind string
EventKind enumerates the event types the server emits.
const ( EventKindSessionMessageAdded EventKind = "session_message_added" EventKindSessionMessageUpdated EventKind = "session_message_updated" EventKindSessionCreated EventKind = "session_created" EventKindTurnStarted EventKind = "turn_started" EventKindTurnEnded EventKind = "turn_ended" EventKindHITLRequestPending EventKind = "hitl_request_pending" EventKindHITLRequestResolved EventKind = "hitl_request_resolved" )
type HITLView ¶ added in v0.16.0
type HITLView struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Type string `json:"type"`
Status string `json:"status"`
UserID string `json:"user_id,omitempty"`
Payload map[string]any `json:"payload,omitempty"`
Response map[string]any `json:"response,omitempty"`
// MessageID optionally binds the HITL prompt to an existing Web
// progress message so the UI can render approval UI in-place
// instead of floating it above the timeline.
MessageID string `json:"message_id,omitempty"`
}
HITLView is the wire shape for an in-flight HITL request emitted by hitl_request_pending / hitl_request_resolved events. The Web UI uses this to render approval/question UI and to clear it once the request resolves.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles WebSocket connections for chat functionality
func NewHandler ¶
func NewHandler(hub *Hub, repository interfaces.Repository, useCases *usecase.UseCases) *Handler
NewHandler creates a new WebSocket handler
func NewTestHandler ¶
func NewTestHandler(hub *Hub, repository interfaces.Repository, useCases *usecase.UseCases) (*Handler, *httptest.Server)
NewTestHandler creates a WebSocket handler configured for testing It automatically sets the frontend URL to match the test server
func (*Handler) HandleTicketChat ¶
func (h *Handler) HandleTicketChat(w http.ResponseWriter, r *http.Request)
HandleTicketChat handles WebSocket connections for ticket chat
func (*Handler) WithAllowedOrigins ¶
WithAllowedOrigins sets additional allowed origins (useful for development)
func (*Handler) WithFrontendURL ¶
WithFrontendURL sets the frontend URL for origin checking
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the clients
func (*Hub) BroadcastToTicket ¶
BroadcastToTicket sends a message to all clients of a specific ticket
func (*Hub) GetActiveTickets ¶
GetActiveTickets returns a list of ticket IDs that have active clients
func (*Hub) GetClientCount ¶
GetClientCount returns the number of clients connected to a specific ticket
func (*Hub) GetTotalClientCount ¶
GetTotalClientCount returns the total number of connected clients across all tickets
func (*Hub) NewClientWithTabID ¶
func (h *Hub) NewClientWithTabID(conn *websocket.Conn, ticketID types.TicketID, userID string, tabID string) *Client
NewClientWithTabID creates a new client with a specific tab ID
func (*Hub) SendErrorToTicket ¶
SendErrorToTicket sends an error message to all clients of a ticket
func (*Hub) SendMessageToClient ¶
func (h *Hub) SendMessageToClient(clientID string, content string, user *websocket_model.User) error
SendMessageToClient sends a chat message to a specific client
func (*Hub) SendMessageToTicket ¶
func (h *Hub) SendMessageToTicket(ticketID types.TicketID, content string, user *websocket_model.User) error
SendMessageToTicket sends a chat message to all clients of a ticket
func (*Hub) SendStatusToTicket ¶
SendStatusToTicket sends a status message to all clients of a ticket
func (*Hub) SendToClient ¶
func (h *Hub) SendToClient(clientID string, response *websocket_model.ChatResponse) error
SendToClient sends a message to a specific client by client ID
func (*Hub) SendToTicket ¶
func (h *Hub) SendToTicket(ticketID types.TicketID, response *websocket_model.ChatResponse) error
SendToTicket is a convenience method to send a WebSocket message to a ticket
func (*Hub) SendTraceToClient ¶
SendTraceToClient sends a trace message to a specific client
func (*Hub) SendWarningToClient ¶ added in v0.8.0
func (h *Hub) SendWarningToClient(clientID string, content string, user *websocket_model.User) error
SendWarningToClient sends a warning message to a specific client
func (*Hub) Unregister ¶
Unregister removes a client from the hub
type MessageView ¶ added in v0.16.0
type MessageView struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
TurnID *string `json:"turn_id,omitempty"`
Type string `json:"type"`
Author *session.Author `json:"author,omitempty"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
}
MessageView is the wire shape for SessionMessage. Uses strings for IDs so the TypeScript client can treat everything as opaque.
type SessionView ¶ added in v0.16.0
type SessionView struct {
ID string `json:"id"`
TicketID *string `json:"ticket_id,omitempty"`
Source string `json:"source"`
UserID string `json:"user_id"`
CreatedAt time.Time `json:"created_at"`
LastActiveAt time.Time `json:"last_active_at"`
}
SessionView is the wire shape for Session metadata emitted alongside session_created. Lock / TicketIDPtr are intentionally omitted; the frontend does not need to see internal state.
type TurnView ¶ added in v0.16.0
type TurnView struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Status string `json:"status"`
Intent string `json:"intent,omitempty"`
StartedAt time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at,omitempty"`
}
TurnView is the wire shape for Turn metadata emitted alongside turn_started / turn_ended.