Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateAgentID(agentID string) error
- func ValidateAgentName(name string) error
- func ValidateAgentStatus(status string) error
- func ValidateFilePath(path string) error
- func ValidateMaxAgents(maxAgents int) error
- func ValidateMessageBody(body string) error
- func ValidateMessageType(msgType string) error
- type Agent
- type AgentJoinedPayload
- type AgentLeftPayload
- type Client
- type FileChange
- type FileChangedPayload
- type Hub
- type Manager
- func (m *Manager) GetActiveAgents(ctx context.Context, sessionID uuid.UUID) ([]Agent, error)
- func (m *Manager) GetFileVersion(ctx context.Context, sessionID uuid.UUID, filePath string) (int, error)
- func (m *Manager) GetMessages(ctx context.Context, sessionID uuid.UUID, limit int) ([]Message, error)
- func (m *Manager) JoinSession(ctx context.Context, sessionID uuid.UUID, agentID, agentName string) (*Agent, error)
- func (m *Manager) LeaveSession(ctx context.Context, sessionID uuid.UUID, agentID string) error
- func (m *Manager) RecordFileChange(ctx context.Context, sessionID uuid.UUID, ...) (*FileChange, error)
- func (m *Manager) SendMessage(ctx context.Context, sessionID uuid.UUID, from, to, body string, ...) (*Message, error)
- func (m *Manager) SubscribeToEvents(ctx context.Context, sessionID uuid.UUID) *redis.PubSub
- func (m *Manager) UpdatePresence(ctx context.Context, sessionID uuid.UUID, agentID string, currentFile string, ...) error
- type Message
- type MessagePayload
- type PresenceUpdatePayload
- type WSMessage
Constants ¶
const ( AgentStatusActive = "active" AgentStatusIdle = "idle" AgentStatusDisconnected = "disconnected" )
AgentStatus constants
const ( MessageTypeDirect = "direct" MessageTypeBroadcast = "broadcast" MessageTypeSystem = "system" )
MessageType constants
const ( ChangeTypeCreated = "created" ChangeTypeModified = "modified" ChangeTypeDeleted = "deleted" )
ChangeType constants
const ( WSMessageTypeAgentJoined = "agent_joined" WSMessageTypeAgentLeft = "agent_left" WSMessageTypeMessage = "message" WSMessageTypeFileChanged = "file_changed" WSMessageTypePresenceUpdate = "presence_update" WSMessageTypePing = "ping" WSMessageTypePong = "pong" )
WSMessageType constants
const ( MaxAgentIDLength = 64 MaxAgentNameLength = 200 MaxMessageBytes = 64 * 1024 // 64 KB MaxFilePathLength = 4096 MaxAgentsPerSession = 32 )
Limits on agent-supplied values. Agent IDs become part of Redis key names and a Postgres unique key, so they are the most tightly constrained.
Variables ¶
Functions ¶
func ValidateAgentID ¶ added in v0.3.1
ValidateAgentID checks an agent identifier before it is used in a Redis key or stored as part of the (session_id, agent_id) unique constraint.
func ValidateAgentName ¶ added in v0.3.1
ValidateAgentName checks the human-readable agent name. Names are only ever displayed, so the constraint is length and valid UTF-8 rather than charset.
func ValidateAgentStatus ¶ added in v0.3.1
ValidateAgentStatus rejects unknown presence states.
func ValidateFilePath ¶ added in v0.3.1
ValidateFilePath bounds the presence "current file" field. The value is informational — it is never opened — so only length and encoding matter.
func ValidateMaxAgents ¶ added in v0.3.1
ValidateMaxAgents bounds the per-session agent cap. Each agent holds a WebSocket connection and two goroutines, so an unbounded value is a resource-exhaustion vector.
func ValidateMessageBody ¶ added in v0.3.1
ValidateMessageBody bounds a message before it is written to Postgres and broadcast to every connected agent. Without a bound, one agent can exhaust the message table and saturate every peer's send buffer.
func ValidateMessageType ¶ added in v0.3.1
ValidateMessageType rejects unknown types so that a client cannot invent a type that downstream consumers mishandle.
Types ¶
type Agent ¶
type Agent struct {
ID string `json:"id"` // Agent identifier (e.g., "agent_a")
Name string `json:"name"` // Human-readable name
SessionID uuid.UUID `json:"session_id"` // Session this agent is connected to
Status string `json:"status"` // "active", "idle", "disconnected"
CurrentFile string `json:"current_file"` // File currently being edited (nullable)
LastActivity time.Time `json:"last_activity"`
ConnectedAt time.Time `json:"connected_at"`
}
Agent represents a connected agent in a collaborative session
type AgentJoinedPayload ¶
type AgentJoinedPayload struct {
Agent Agent `json:"agent"`
}
AgentJoinedPayload is sent when an agent joins
type AgentLeftPayload ¶
type AgentLeftPayload struct {
AgentID string `json:"agent_id"`
Timestamp time.Time `json:"timestamp"`
}
AgentLeftPayload is sent when an agent disconnects
type Client ¶
type Client struct {
SessionID uuid.UUID
AgentID string
AgentName string
Conn *websocket.Conn
Manager *Manager
// contains filtered or unexported fields
}
Client represents a WebSocket client (agent connection)
func NewClient ¶
func NewClient(sessionID uuid.UUID, agentID, agentName string, conn *websocket.Conn, manager *Manager) *Client
NewClient creates a new WebSocket client
type FileChange ¶
type FileChange struct {
SessionID uuid.UUID `json:"session_id"`
File string `json:"file"`
ChangedBy string `json:"changed_by"` // Agent ID
ChangeType string `json:"change_type"` // "created", "modified", "deleted"
Version int `json:"version"` // Incremental version number
Timestamp time.Time `json:"timestamp"`
}
FileChange represents a file modification event
type FileChangedPayload ¶
type FileChangedPayload struct {
Change FileChange `json:"change"`
}
FileChangedPayload is sent when a file is modified
type Hub ¶
type Hub struct {
Manager *Manager
// contains filtered or unexported fields
}
Hub manages all active WebSocket connections
func (*Hub) BroadcastToSession ¶
BroadcastToSession sends a message to all clients in a session
func (*Hub) RegisterClient ¶
RegisterClient registers a new WebSocket client
func (*Hub) UnregisterClient ¶
UnregisterClient unregisters a WebSocket client
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles multi-agent collaboration
func (*Manager) GetActiveAgents ¶
GetActiveAgents returns all active agents for a session
func (*Manager) GetFileVersion ¶
func (m *Manager) GetFileVersion(ctx context.Context, sessionID uuid.UUID, filePath string) (int, error)
GetFileVersion returns the current version of a file
func (*Manager) GetMessages ¶
func (m *Manager) GetMessages(ctx context.Context, sessionID uuid.UUID, limit int) ([]Message, error)
GetMessages retrieves recent messages for a session
func (*Manager) JoinSession ¶
func (m *Manager) JoinSession(ctx context.Context, sessionID uuid.UUID, agentID, agentName string) (*Agent, error)
JoinSession registers an agent as active in a session
func (*Manager) LeaveSession ¶
LeaveSession removes an agent from a session
func (*Manager) RecordFileChange ¶
func (m *Manager) RecordFileChange(ctx context.Context, sessionID uuid.UUID, filePath, agentID, changeType, checksum string, sizeBytes int64) (*FileChange, error)
RecordFileChange records a file modification
func (*Manager) SendMessage ¶
func (m *Manager) SendMessage(ctx context.Context, sessionID uuid.UUID, from, to, body string, msgType string) (*Message, error)
SendMessage sends a message from one agent to another (or broadcast)
func (*Manager) SubscribeToEvents ¶
SubscribeToEvents subscribes to session events
type Message ¶
type Message struct {
ID uuid.UUID `json:"id"`
SessionID uuid.UUID `json:"session_id"`
Type string `json:"type"` // "direct", "broadcast", "system"
From string `json:"from"` // Agent ID
To string `json:"to"` // Agent ID (empty for broadcast)
Body string `json:"body"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
Message represents a message between agents
type MessagePayload ¶
type MessagePayload struct {
Message Message `json:"message"`
}
MessagePayload wraps a message