Documentation
¶
Index ¶
- Constants
- func GenerateInviteCode() string
- func InitSchema(db *sql.DB) error
- func Now() int64
- type AgentClient
- type ChatMessage
- type Client
- type CompressionConfig
- type ContextCompressor
- type CreateRoomRequest
- type ErrorResponse
- type Handler
- type JoinRequest
- type Member
- type Message
- type MessageEvent
- type MessageInfoAPI
- type Room
- type RoomAgent
- type RoomInfo
- type RoomInfoAPI
- type SendMessageRequest
- type Server
- func (s *Server) Close()
- func (s *Server) GetOnlineCount() int
- func (s *Server) GetOrCreateCompressor(roomID string) *ContextCompressor
- func (s *Server) GetRoomClients(roomID string) []*Client
- func (s *Server) GetRoomCount() int
- func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request)
- type Storage
- func (s *Storage) AddMember(member *Member) error
- func (s *Storage) AgentExistsInRoom(roomID, profile string) (bool, error)
- func (s *Storage) CreateAgent(agent *RoomAgent) error
- func (s *Storage) CreateRoom(room *Room) error
- func (s *Storage) DeleteAgent(agentID string) error
- func (s *Storage) DeleteMessagesBefore(roomID string, timestamp int64) error
- func (s *Storage) DeleteRoom(roomID string) error
- func (s *Storage) DeleteSessionProfile(sessionID string) error
- func (s *Storage) GetAgent(agentID string) (*RoomAgent, error)
- func (s *Storage) GetAgents(roomID string) ([]RoomAgent, error)
- func (s *Storage) GetAllRooms() ([]Room, error)
- func (s *Storage) GetMembers(roomID string) ([]Member, error)
- func (s *Storage) GetMessageCount(roomID string) (int, error)
- func (s *Storage) GetMessages(roomID string, limit int) ([]ChatMessage, error)
- func (s *Storage) GetRecentMessages(roomID string, count int) ([]ChatMessage, error)
- func (s *Storage) GetRoom(roomID string) (*Room, error)
- func (s *Storage) GetRoomByInviteCode(code string) (*Room, error)
- func (s *Storage) GetSessionProfile(sessionID string) (roomID, agentID, profileName string, err error)
- func (s *Storage) ListRooms() ([]Room, error)
- func (s *Storage) RemoveMember(roomID, userID string) error
- func (s *Storage) SaveMessage(msg *ChatMessage) error
- func (s *Storage) SaveRoom(room *Room) error
- func (s *Storage) SaveSessionProfile(sessionID, roomID, agentID, profileName string) error
- func (s *Storage) UpdateAgent(agent *RoomAgent) error
- func (s *Storage) UpdateMember(member *Member) error
- func (s *Storage) UpdateRoom(room *Room) error
- func (s *Storage) UpdateRoomConfig(roomID string, config CompressionConfig) error
- func (s *Storage) UpdateRoomTokens(roomID string, totalTokens int) error
- type SuccessResponse
Constants ¶
const SchemaSQL = `` /* 2593-byte string literal not displayed */
数据库 Schema 初始化
Variables ¶
This section is empty.
Functions ¶
func GenerateInviteCode ¶
func GenerateInviteCode() string
GenerateInviteCode generates a random 6-digit invite code
Types ¶
type AgentClient ¶
type AgentClient struct {
ID string `json:"id"`
RoomID string `json:"roomId"`
Profile string `json:"profile"`
Name string `json:"name"`
SessionID string `json:"sessionId"`
Connected bool `json:"connected"`
CreatedAt int64 `json:"createdAt"`
}
AgentClient Agent 客户端
type ChatMessage ¶
type ChatMessage struct {
ID string `json:"id"`
RoomID string `json:"roomId"`
SenderID string `json:"senderId"`
SenderName string `json:"senderName"`
Content string `json:"content"`
Timestamp int64 `json:"timestamp"`
Type string `json:"type,omitempty"` // text, system, agent
}
ChatMessage represents a message in the chat
type Client ¶
type Client struct {
ID string `json:"id"`
UserID string `json:"userId"`
Name string `json:"name"`
Description string `json:"description"`
RoomID string `json:"roomId,omitempty"`
Conn *websocket.Conn
// contains filtered or unexported fields
}
Client WebSocket 客户端
type CompressionConfig ¶
type CompressionConfig struct {
TriggerTokens int `json:"triggerTokens"`
MaxHistoryTokens int `json:"maxHistoryTokens"`
TailMessageCount int `json:"tailMessageCount"`
}
CompressionConfig holds context compression settings
func DefaultCompressionConfig ¶
func DefaultCompressionConfig() CompressionConfig
DefaultCompressionConfig returns default compression settings
type ContextCompressor ¶ added in v0.3.0
type ContextCompressor struct {
// contains filtered or unexported fields
}
ContextCompressor handles context compression for rooms
type CreateRoomRequest ¶ added in v0.3.0
type CreateRoomRequest struct {
Name string `json:"name"`
InviteCode string `json:"inviteCode,omitempty"`
Compression CompressionConfig `json:"compression,omitempty"`
}
CreateRoomRequest represents a request to create a room
type ErrorResponse ¶ added in v0.3.0
ErrorResponse represents an error response
type JoinRequest ¶ added in v0.3.0
type JoinRequest struct {
UserID string `json:"userId"`
Name string `json:"name"`
Description string `json:"description"`
RoomID string `json:"roomId"`
InviteCode string `json:"inviteCode,omitempty"`
}
JoinRequest represents a request to join a room
type Member ¶
type Member struct {
ID string `json:"id"`
RoomID string `json:"roomId"`
UserID string `json:"userId"`
Name string `json:"name"`
Description string `json:"description"`
JoinedAt int64 `json:"joinedAt"`
LastSeenAt int64 `json:"lastSeenAt"`
Online bool `json:"online,omitempty"`
SocketID string `json:"socketId,omitempty"`
}
Member represents a user in a room
type Message ¶
type Message struct {
Type string `json:"type"`
RoomID string `json:"roomId,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Timestamp int64 `json:"timestamp"`
}
Message 消息结构
type MessageEvent ¶ added in v0.3.0
type MessageEvent struct {
Type string `json:"type"`
RoomID string `json:"roomId,omitempty"`
Data interface{} `json:"data,omitempty"`
Timestamp int64 `json:"timestamp"`
}
MessageEvent represents a message event for WebSocket
type MessageInfoAPI ¶ added in v0.4.0
type MessageInfoAPI struct {
ID string `json:"id"`
RoomID string `json:"room_id"`
Sender string `json:"sender"`
Role string `json:"role"`
Content string `json:"content"`
Timestamp int64 `json:"timestamp"`
}
MessageInfo represents a chat message for JSON API
type Room ¶
type Room struct {
ID string `json:"id"`
Name string `json:"name"`
InviteCode string `json:"inviteCode,omitempty"`
TriggerTokens int `json:"triggerTokens,omitempty"`
MaxHistoryTokens int `json:"maxHistoryTokens,omitempty"`
TailMessageCount int `json:"tailMessageCount,omitempty"`
TotalTokens int `json:"totalTokens,omitempty"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
}
Room represents a group chat room
type RoomAgent ¶
type RoomAgent struct {
ID string `json:"id"`
RoomID string `json:"roomId"`
AgentID string `json:"agentId"`
Profile string `json:"profile"`
Name string `json:"name"`
Description string `json:"description"`
Invited int `json:"invited"`
SessionID string `json:"sessionId,omitempty"`
CreatedAt int64 `json:"createdAt"`
}
RoomAgent represents an AI agent in a room
type RoomInfo ¶ added in v0.3.0
type RoomInfo struct {
Room *Room `json:"room"`
Members []Member `json:"members"`
Agents []RoomAgent `json:"agents"`
Messages []ChatMessage `json:"messages"`
}
RoomInfo contains room information with members and messages
type RoomInfoAPI ¶ added in v0.4.0
type RoomInfoAPI struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Members []string `json:"members"`
AgentIDs []string `json:"agent_ids"`
CreatedAt int64 `json:"created_at"`
}
RoomInfo represents a chat room for JSON API
type SendMessageRequest ¶ added in v0.3.0
type SendMessageRequest struct {
RoomID string `json:"roomId"`
Content string `json:"content"`
MessageType string `json:"type,omitempty"`
}
SendMessageRequest represents a request to send a message
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server Group Chat WebSocket 服务器
func (*Server) GetOnlineCount ¶ added in v0.3.0
GetOnlineCount returns the number of online users
func (*Server) GetOrCreateCompressor ¶ added in v0.3.0
func (s *Server) GetOrCreateCompressor(roomID string) *ContextCompressor
GetOrCreateCompressor gets or creates a context compressor for a room
func (*Server) GetRoomClients ¶ added in v0.3.0
GetRoomClients returns all clients in a room
func (*Server) GetRoomCount ¶ added in v0.3.0
GetRoomCount returns the number of active rooms
func (*Server) HandleWebSocket ¶
func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request)
HandleWebSocket 处理 WebSocket 连接
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage 数据存储
func NewStorageFromHome ¶ added in v0.4.0
NewStorageFromHome creates a new storage instance from a home directory path
func (*Storage) AgentExistsInRoom ¶
AgentExistsInRoom 检查代理是否在房间
func (*Storage) CreateAgent ¶
CreateAgent 创建代理
func (*Storage) DeleteMessagesBefore ¶ added in v0.3.0
DeleteMessagesBefore 删除指定时间之前的消息
func (*Storage) DeleteSessionProfile ¶
DeleteSessionProfile 删除会话配置
func (*Storage) GetMembers ¶
GetMembers 获取房间成员
func (*Storage) GetMessageCount ¶ added in v0.3.0
GetMessageCount 获取房间消息数量
func (*Storage) GetMessages ¶
func (s *Storage) GetMessages(roomID string, limit int) ([]ChatMessage, error)
GetMessages 获取消息
func (*Storage) GetRecentMessages ¶ added in v0.3.0
func (s *Storage) GetRecentMessages(roomID string, count int) ([]ChatMessage, error)
GetRecentMessages 获取最近的消息(用于压缩后保留)
func (*Storage) GetRoomByInviteCode ¶
GetRoomByInviteCode 通过邀请码获取房间
func (*Storage) GetSessionProfile ¶
func (s *Storage) GetSessionProfile(sessionID string) (roomID, agentID, profileName string, err error)
GetSessionProfile 获取会话配置
func (*Storage) RemoveMember ¶
RemoveMember 移除成员
func (*Storage) SaveMessage ¶
func (s *Storage) SaveMessage(msg *ChatMessage) error
SaveMessage 保存消息
func (*Storage) SaveSessionProfile ¶
SaveSessionProfile 保存会话配置
func (*Storage) UpdateAgent ¶
UpdateAgent 更新代理
func (*Storage) UpdateMember ¶
UpdateMember 更新成员
func (*Storage) UpdateRoomConfig ¶
func (s *Storage) UpdateRoomConfig(roomID string, config CompressionConfig) error
UpdateRoomConfig 更新房间配置
type SuccessResponse ¶ added in v0.3.0
type SuccessResponse struct {
Success bool `json:"success"`
Data interface{} `json:"data,omitempty"`
Message string `json:"message,omitempty"`
}
SuccessResponse represents a success response