Documentation
¶
Index ¶
- Constants
- type ActiveChatLister
- type AgentStatusData
- type ChannelCreator
- type ChannelEnsurer
- type ChannelLister
- type ContainerFinder
- type ContainerStopper
- type Event
- type EventsHub
- func (h *EventsHub) Broadcast(evt Event)
- func (h *EventsHub) BroadcastAgentStatus(channelID string, data AgentStatusData)
- func (h *EventsHub) BroadcastMessageCreated(channelID string, data MessageData)
- func (h *EventsHub) BroadcastMessageStreaming(channelID string, data MessageStreamingData)
- func (h *EventsHub) Register(conn *websocket.Conn, channels []string) *eventConn
- func (h *EventsHub) Unregister(ec *eventConn)
- type IncomingMessageHandler
- type InteractionHandler
- type InteractiveCmdBuilder
- type MemoryIndexer
- type MessageData
- type MessageSender
- type MessageStreamingData
- type RunningChannelLister
- type Server
- func (s *Server) EventsHub() *EventsHub
- func (s *Server) SetActiveChatLister(lister ActiveChatLister)
- func (s *Server) SetContainerFinder(finder ContainerFinder)
- func (s *Server) SetContainerStopper(stopper ContainerStopper)
- func (s *Server) SetEventsHub(hub *EventsHub)
- func (s *Server) SetIncomingMessageHandler(h IncomingMessageHandler)
- func (s *Server) SetInteractionHandler(h InteractionHandler)
- func (s *Server) SetInteractiveCmdBuilder(builder InteractiveCmdBuilder)
- func (s *Server) SetLoopDir(dir string)
- func (s *Server) SetMemoryIndexer(idx MemoryIndexer)
- func (s *Server) SetPlatform(p types.Platform)
- func (s *Server) SetRunningChannelLister(lister RunningChannelLister)
- func (s *Server) SetTerminalManager(mgr TerminalManager)
- func (s *Server) Start(addr string) error
- func (s *Server) Stop(ctx context.Context) error
- type TerminalManager
- type ThreadCreator
- type ThreadEnsurer
Constants ¶
const ( EventMessageCreated = "message.created" EventMessageStreaming = "message.streaming" EventAgentStatus = "agent.status" )
Event type constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveChatLister ¶ added in v0.1.68
type ActiveChatLister interface {
ActiveChatChannelIDs() map[string]struct{}
}
ActiveChatLister returns channel IDs with active chat agent runs.
type AgentStatusData ¶ added in v0.1.68
type AgentStatusData struct {
Status string `json:"status"` // "running", "completed", "error"
Error string `json:"error,omitempty"`
}
AgentStatusData is the data payload for agent.status events.
type ChannelCreator ¶
type ChannelCreator interface {
CreateChannel(ctx context.Context, guildID, name string) (string, error)
InviteUserToChannel(ctx context.Context, channelID, userID string) error
GetOwnerUserID(ctx context.Context) (string, error)
SetChannelTopic(ctx context.Context, channelID, topic string) error
}
ChannelCreator can create channels on the chat platform.
type ChannelEnsurer ¶
type ChannelEnsurer interface {
EnsureChannel(ctx context.Context, dirPath string) (string, error)
CreateChannel(ctx context.Context, name, authorID string) (string, error)
}
ChannelEnsurer resolves a directory path to a channel ID, creating the channel if it does not yet exist.
func NewChannelService ¶
func NewChannelService(store db.Store, creator ChannelCreator, guildID string, platform types.Platform) ChannelEnsurer
NewChannelService creates a new ChannelEnsurer.
type ChannelLister ¶ added in v0.1.15
type ChannelLister interface {
ListChannels(ctx context.Context) ([]*db.Channel, error)
GetChannel(ctx context.Context, channelID string) (*db.Channel, error)
GetMessagesCursor(ctx context.Context, channelID string, cursor int64, limit int) ([]*db.Message, error)
}
ChannelLister can list and look up channels and their messages from the database.
type ContainerFinder ¶ added in v0.1.68
type ContainerFinder interface {
FindContainerByChannel(ctx context.Context, channelID, dirPath string) (string, error)
}
ContainerFinder resolves a channel ID to a running container ID.
type ContainerStopper ¶ added in v0.1.68
ContainerStopper removes a container by ID.
type Event ¶ added in v0.1.68
type Event struct {
Type string `json:"type"`
ChannelID string `json:"channel_id"`
Data any `json:"data"`
Timestamp int64 `json:"timestamp"`
}
Event represents a server-sent event to WebSocket clients.
type EventsHub ¶ added in v0.1.68
type EventsHub struct {
// contains filtered or unexported fields
}
EventsHub manages WebSocket event subscribers and broadcasts events.
Thread-safety: The hub's subscriber set is protected by mu (RWMutex). Broadcast takes a snapshot of subscribers under RLock, then releases the lock before writing to each connection. Each connection has its own writeMu to serialize writes. This means a concurrent Unregister may remove a subscriber that Broadcast is about to write to — this is safe because writeMu still guards the connection, and a failed write triggers Unregister (idempotent delete from the map).
func NewEventsHub ¶ added in v0.1.68
NewEventsHub creates a new EventsHub.
func (*EventsHub) Broadcast ¶ added in v0.1.68
Broadcast sends an event to all subscribers whose channel filter matches.
func (*EventsHub) BroadcastAgentStatus ¶ added in v0.1.68
func (h *EventsHub) BroadcastAgentStatus(channelID string, data AgentStatusData)
BroadcastAgentStatus sends an agent.status event.
func (*EventsHub) BroadcastMessageCreated ¶ added in v0.1.68
func (h *EventsHub) BroadcastMessageCreated(channelID string, data MessageData)
BroadcastMessageCreated sends a message.created event.
func (*EventsHub) BroadcastMessageStreaming ¶ added in v0.1.68
func (h *EventsHub) BroadcastMessageStreaming(channelID string, data MessageStreamingData)
BroadcastMessageStreaming sends a message.streaming event with partial bot response.
func (*EventsHub) Unregister ¶ added in v0.1.68
func (h *EventsHub) Unregister(ec *eventConn)
Unregister removes a subscriber.
type IncomingMessageHandler ¶ added in v0.1.68
type IncomingMessageHandler interface {
HandleIncomingMessage(ctx context.Context, channelID, authorID, content string)
}
IncomingMessageHandler processes a user message from the API, routing it through the orchestrator so Claude can respond.
type InteractionHandler ¶ added in v0.1.68
type InteractionHandler interface {
HandleInteraction(ctx context.Context, inter *bot.Interaction)
}
InteractionHandler processes a parsed slash command interaction.
type InteractiveCmdBuilder ¶ added in v0.1.68
type InteractiveCmdBuilder interface {
BuildInteractiveCmd(channelID, dirPath, sessionID string, forkSession bool) string
}
InteractiveCmdBuilder builds the interactive Claude command for a terminal session.
type MemoryIndexer ¶ added in v0.1.33
type MemoryIndexer interface {
Search(ctx context.Context, memoryDir, query string, topK int) ([]memory.SearchResult, error)
Index(ctx context.Context, memoryDir string) (int, error)
}
MemoryIndexer abstracts memory search and indexing for the memory API endpoints.
type MessageData ¶ added in v0.1.68
type MessageData struct {
MsgID string `json:"msg_id"`
AuthorID string `json:"author_id"`
AuthorName string `json:"author_name"`
Content string `json:"content"`
IsBot bool `json:"is_bot"`
}
MessageData is the data payload for message.created events.
type MessageSender ¶ added in v0.1.15
MessageSender can send messages to channels or threads.
type MessageStreamingData ¶ added in v0.1.68
type MessageStreamingData struct {
Content string `json:"content"`
}
MessageStreamingData is the data payload for message.streaming events.
type RunningChannelLister ¶ added in v0.1.68
type RunningChannelLister interface {
RunningChannelIDs(ctx context.Context) (map[string]struct{}, error)
}
RunningChannelLister returns the set of channel IDs that have running containers.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server exposes a lightweight HTTP API for task CRUD operations.
func NewServer ¶
func NewServer(sched scheduler.Scheduler, channels ChannelEnsurer, threads ThreadEnsurer, store ChannelLister, messages MessageSender, logger *slog.Logger) *Server
NewServer creates a new API server. The channels, threads, store, and messages parameters may be nil if those features are not configured.
func (*Server) EventsHub ¶ added in v0.1.68
EventsHub returns the configured events hub, or nil if not set.
func (*Server) SetActiveChatLister ¶ added in v0.1.68
func (s *Server) SetActiveChatLister(lister ActiveChatLister)
SetActiveChatLister configures the active chat lister for the channel list endpoint.
func (*Server) SetContainerFinder ¶ added in v0.1.68
func (s *Server) SetContainerFinder(finder ContainerFinder)
SetContainerFinder configures the container finder for channel_id → container resolution.
func (*Server) SetContainerStopper ¶ added in v0.1.68
func (s *Server) SetContainerStopper(stopper ContainerStopper)
SetContainerStopper configures the container stopper for removing containers on session stop.
func (*Server) SetEventsHub ¶ added in v0.1.68
SetEventsHub configures the events hub for the /api/ws endpoint.
func (*Server) SetIncomingMessageHandler ¶ added in v0.1.68
func (s *Server) SetIncomingMessageHandler(h IncomingMessageHandler)
SetIncomingMessageHandler configures the handler for user messages from the API.
func (*Server) SetInteractionHandler ¶ added in v0.1.68
func (s *Server) SetInteractionHandler(h InteractionHandler)
SetInteractionHandler configures the handler for slash command interactions.
func (*Server) SetInteractiveCmdBuilder ¶ added in v0.1.68
func (s *Server) SetInteractiveCmdBuilder(builder InteractiveCmdBuilder)
SetInteractiveCmdBuilder configures the command builder for interactive terminal sessions.
func (*Server) SetLoopDir ¶ added in v0.1.33
SetLoopDir sets the loop directory used for fallback work dir resolution.
func (*Server) SetMemoryIndexer ¶ added in v0.1.33
func (s *Server) SetMemoryIndexer(idx MemoryIndexer)
SetMemoryIndexer configures the memory indexer for the /api/memory/* endpoints.
func (*Server) SetPlatform ¶ added in v0.1.68
SetPlatform sets the platform used for filtering channels.
func (*Server) SetRunningChannelLister ¶ added in v0.1.68
func (s *Server) SetRunningChannelLister(lister RunningChannelLister)
SetRunningChannelLister configures the running channel lister for the channel list endpoint.
func (*Server) SetTerminalManager ¶ added in v0.1.68
func (s *Server) SetTerminalManager(mgr TerminalManager)
SetTerminalManager configures the terminal manager for WebSocket terminal sessions.
type TerminalManager ¶ added in v0.1.68
type TerminalManager interface {
CreateSession(ctx context.Context, containerID string, cmd []string) (sessionID string, output <-chan []byte, history []byte, done <-chan struct{}, err error)
AttachSession(sessionID string) (output <-chan []byte, history []byte, done <-chan struct{}, err error)
DetachSession(sessionID string, output <-chan []byte) error
SendInput(sessionID string, data []byte) error
Resize(ctx context.Context, sessionID string, rows, cols uint) error
StopSession(sessionID string) (containerID string, err error)
}
TerminalManager abstracts the terminal session operations needed by the handler.
type ThreadCreator ¶ added in v0.1.11
type ThreadCreator interface {
CreateThread(ctx context.Context, channelID, name, mentionUserID, message string) (string, error)
DeleteThread(ctx context.Context, threadID string) error
}
ThreadCreator can create and delete threads on the chat platform.
type ThreadEnsurer ¶ added in v0.1.11
type ThreadEnsurer interface {
CreateThread(ctx context.Context, channelID, name, authorID, message string) (string, error)
DeleteThread(ctx context.Context, threadID string) error
}
ThreadEnsurer manages threads on the chat platform and the DB.
func NewThreadService ¶ added in v0.1.11
func NewThreadService(store db.Store, creator ThreadCreator, platform types.Platform, logger *slog.Logger) ThreadEnsurer
NewThreadService creates a new ThreadEnsurer.