Documentation
¶
Index ¶
- Variables
- func BroadcastToSession(sessionMgr *SessionManager, sessionID string, role, content string) error
- func HandleWebSocket(session *Session, sessionMgr *SessionManager, ...) error
- func IsNewProtocol(raw []byte) bool
- func StaticFiles() (fs.FS, error)
- type CORSConfig
- type CORSManager
- func (m *CORSManager) AddOrigin(origin string) error
- func (m *CORSManager) CheckCORS(r *http.Request) bool
- func (m *CORSManager) Close() error
- func (m *CORSManager) ListOrigins() []string
- func (m *CORSManager) RemoveOrigin(origin string) error
- func (m *CORSManager) SetDevelopmentMode(enabled bool) error
- type Event
- type EventHub
- type HistoryMessage
- type HistoryPage
- type HistoryRequestData
- type IncomingMessage
- type ProtocolMessage
- type Server
- func (s *Server) GetEventHub() *EventHub
- func (s *Server) GetSessionManager() *SessionManager
- func (s *Server) HandleAPIConfigForTest(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleAPILogsForTest(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleAPIScannerStatusForTest(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleAPIStatusForTest(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleEventsStreamForTest(w http.ResponseWriter, r *http.Request)
- func (s *Server) IsRunning() bool
- func (s *Server) PublishStatusLoopForTest(ctx context.Context)
- func (s *Server) SendHistoryToSession(sessionID, jsonContent string) error
- func (s *Server) SendToSession(sessionID, role, content string) error
- func (s *Server) SetModelName(name string)
- func (s *Server) SetWorkspace(ws string)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- type ServerConfig
- type Session
- type SessionManager
- func (sm *SessionManager) Broadcast(sessionID string, message []byte) error
- func (sm *SessionManager) CreateSession(conn *websocket.Conn) *Session
- func (sm *SessionManager) GetActiveCount() int
- func (sm *SessionManager) GetAllSessions() []*Session
- func (sm *SessionManager) GetSession(sessionID string) (*Session, bool)
- func (sm *SessionManager) RemoveSession(sessionID string)
- func (sm *SessionManager) Shutdown()
- func (sm *SessionManager) Stats() map[string]interface{}
Constants ¶
This section is empty.
Variables ¶
var WebSocketUpgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, CheckOrigin: func(r *http.Request) bool { return true }, }
WebSocketUpgrader handles the WebSocket upgrade
Functions ¶
func BroadcastToSession ¶
func BroadcastToSession(sessionMgr *SessionManager, sessionID string, role, content string) error
BroadcastToSession sends a message to a specific session using the new protocol.
func HandleWebSocket ¶
func HandleWebSocket(session *Session, sessionMgr *SessionManager, messageChan chan<- IncomingMessage, authToken string) error
HandleWebSocket handles a WebSocket connection with thread-safe sending
func IsNewProtocol ¶
IsNewProtocol checks whether raw JSON uses the new three-level format by looking for the presence of a non-empty "module" field.
func StaticFiles ¶
StaticFiles returns the static files filesystem. Returns an error if the static directory is not properly embedded.
Types ¶
type CORSConfig ¶
type CORSConfig struct {
AllowedOrigins []string `json:"allowed_origins"`
AllowedMethods []string `json:"allowed_methods"`
AllowedHeaders []string `json:"allowed_headers"`
AllowCredentials bool `json:"allow_credentials"`
MaxAge int `json:"max_age"`
AllowLocalhost bool `json:"allow_localhost"`
DevelopmentMode bool `json:"development_mode"`
AllowedCDNDomains []string `json:"allowed_cdn_domains"`
AllowNoOrigin bool `json:"allow_no_origin"` // Allow requests without Origin header (e.g., mobile apps, curl)
}
CORSConfig represents CORS configuration
type CORSManager ¶
type CORSManager struct {
// contains filtered or unexported fields
}
CORSManager manages CORS configuration and validation
func NewCORSManager ¶
func NewCORSManager(configPath string) (*CORSManager, error)
NewCORSManager creates a new CORS manager
func (*CORSManager) AddOrigin ¶
func (m *CORSManager) AddOrigin(origin string) error
AddOrigin adds an allowed origin
func (*CORSManager) CheckCORS ¶
func (m *CORSManager) CheckCORS(r *http.Request) bool
CheckCORS validates if the request origin is allowed
func (*CORSManager) ListOrigins ¶
func (m *CORSManager) ListOrigins() []string
ListOrigins returns all allowed origins
func (*CORSManager) RemoveOrigin ¶
func (m *CORSManager) RemoveOrigin(origin string) error
RemoveOrigin removes an allowed origin
func (*CORSManager) SetDevelopmentMode ¶
func (m *CORSManager) SetDevelopmentMode(enabled bool) error
SetDevelopmentMode enables or disables development mode
type Event ¶
type Event struct {
Type string // Event type: log, status, security-alert, scanner-progress, cluster-event, heartbeat
Data interface{} // Event payload
}
Event represents a server-sent event
type EventHub ¶
type EventHub struct {
// contains filtered or unexported fields
}
EventHub manages SSE subscribers and broadcasts events
func (*EventHub) SubscriberCount ¶
SubscriberCount returns the number of active subscribers
func (*EventHub) Unsubscribe ¶
Unsubscribe removes a subscriber channel
type HistoryMessage ¶
HistoryMessage represents a single message in chat history.
type HistoryPage ¶
type HistoryPage struct {
Messages []HistoryMessage `json:"messages"`
HasMore bool `json:"has_more"`
OldestIndex int `json:"oldest_index"`
TotalCount int `json:"total_count"`
}
HistoryPage represents a page of history messages returned to the client.
type HistoryRequestData ¶
type HistoryRequestData struct {
RequestID string `json:"request_id"`
Limit int `json:"limit,omitempty"`
BeforeIndex *int `json:"before_index,omitempty"`
}
HistoryRequestData represents the data payload of a history_request message.
type IncomingMessage ¶
type IncomingMessage struct {
SessionID string
SenderID string
ChatID string
Content string
Timestamp time.Time
Metadata map[string]string // Additional metadata (e.g. request_type)
}
IncomingMessage represents a message received from a WebSocket client
type ProtocolMessage ¶
type ProtocolMessage struct {
Type string `json:"type"`
Module string `json:"module"`
Cmd string `json:"cmd"`
Data json.RawMessage `json:"data,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
}
ProtocolMessage represents a three-level dispatch protocol message. Format: type → module → cmd, with data and timestamp.
func NewProtocolMessage ¶
func NewProtocolMessage(typeName, module, cmd string, data interface{}) (*ProtocolMessage, error)
NewProtocolMessage constructs a new three-level protocol message.
func ParseProtocolMessage ¶
func ParseProtocolMessage(raw []byte) (*ProtocolMessage, error)
ParseProtocolMessage parses raw JSON into a ProtocolMessage.
func (*ProtocolMessage) DecodeData ¶
func (m *ProtocolMessage) DecodeData(v interface{}) error
DecodeData decodes the Data field into the provided value.
func (*ProtocolMessage) ToJSON ¶
func (m *ProtocolMessage) ToJSON() ([]byte, error)
ToJSON serializes the message to JSON bytes.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the HTTP server for the web channel
func (*Server) GetEventHub ¶
GetEventHub returns the SSE event hub for external integration
func (*Server) GetSessionManager ¶
func (s *Server) GetSessionManager() *SessionManager
GetSessionManager returns the session manager
func (*Server) HandleAPIConfigForTest ¶
func (s *Server) HandleAPIConfigForTest(w http.ResponseWriter, r *http.Request)
func (*Server) HandleAPILogsForTest ¶
func (s *Server) HandleAPILogsForTest(w http.ResponseWriter, r *http.Request)
func (*Server) HandleAPIScannerStatusForTest ¶
func (s *Server) HandleAPIScannerStatusForTest(w http.ResponseWriter, r *http.Request)
func (*Server) HandleAPIStatusForTest ¶
func (s *Server) HandleAPIStatusForTest(w http.ResponseWriter, r *http.Request)
Expose handlers for testing
func (*Server) HandleEventsStreamForTest ¶
func (s *Server) HandleEventsStreamForTest(w http.ResponseWriter, r *http.Request)
func (*Server) PublishStatusLoopForTest ¶
func (*Server) SendHistoryToSession ¶
SendHistoryToSession sends a history response to a specific session.
func (*Server) SendToSession ¶
SendToSession sends a message to a specific session
func (*Server) SetModelName ¶
SetModelName sets the current LLM model name for status reporting
func (*Server) SetWorkspace ¶
SetWorkspace sets the workspace path for API handlers
type ServerConfig ¶
type ServerConfig struct {
Host string
Port int
WSPath string
AuthToken string
SessionMgr *SessionManager
Bus *bus.MessageBus
Workspace string // Workspace path for config files
Version string // Application version
}
ServerConfig holds the server configuration
type Session ¶
type Session struct {
ID string
Conn *websocket.Conn
SenderID string
ChatID string
CreatedAt time.Time
LastActive time.Time
// contains filtered or unexported fields
}
Session represents an active WebSocket client session
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages all active WebSocket sessions
func NewSessionManager ¶
func NewSessionManager(timeout time.Duration) *SessionManager
NewSessionManager creates a new session manager
func (*SessionManager) Broadcast ¶
func (sm *SessionManager) Broadcast(sessionID string, message []byte) error
Broadcast sends a message to a specific session
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession(conn *websocket.Conn) *Session
CreateSession creates a new session with a unique ID
func (*SessionManager) GetActiveCount ¶
func (sm *SessionManager) GetActiveCount() int
GetActiveCount returns the number of active sessions
func (*SessionManager) GetAllSessions ¶
func (sm *SessionManager) GetAllSessions() []*Session
GetAllSessions returns all active sessions
func (*SessionManager) GetSession ¶
func (sm *SessionManager) GetSession(sessionID string) (*Session, bool)
GetSession retrieves a session by ID
func (*SessionManager) RemoveSession ¶
func (sm *SessionManager) RemoveSession(sessionID string)
RemoveSession removes a session
func (*SessionManager) Shutdown ¶
func (sm *SessionManager) Shutdown()
Shutdown closes all sessions and stops cleanup
func (*SessionManager) Stats ¶
func (sm *SessionManager) Stats() map[string]interface{}
Stats returns statistics about active sessions