Documentation
¶
Index ¶
- type Bot
- type ChannelQueue
- type IncomingMessage
- type Interaction
- type Orchestrator
- func (o *Orchestrator) HandleChannelDelete(ctx context.Context, channelID string, isThread bool)
- func (o *Orchestrator) HandleChannelJoin(ctx context.Context, channelID string)
- func (o *Orchestrator) HandleInteraction(ctx context.Context, interaction any)
- func (o *Orchestrator) HandleMessage(ctx context.Context, msg *IncomingMessage)
- func (o *Orchestrator) Start(ctx context.Context) error
- func (o *Orchestrator) Stop() error
- type OutgoingMessage
- type Runner
- type Scheduler
- type TaskExecutor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot interface {
Start(ctx context.Context) error
Stop() error
SendMessage(ctx context.Context, msg *OutgoingMessage) error
SendTyping(ctx context.Context, channelID string) error
RegisterCommands(ctx context.Context) error
RemoveCommands(ctx context.Context) error
OnMessage(handler func(ctx context.Context, msg *IncomingMessage))
OnInteraction(handler func(ctx context.Context, i any))
OnChannelDelete(handler func(ctx context.Context, channelID string, isThread bool))
OnChannelJoin(handler func(ctx context.Context, channelID string))
BotUserID() string
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
CreateThread(ctx context.Context, channelID, name, mentionUserID, message string) (string, error)
PostMessage(ctx context.Context, channelID, content string) error
DeleteThread(ctx context.Context, threadID string) error
GetChannelParentID(ctx context.Context, channelID string) (string, error)
GetChannelName(ctx context.Context, channelID string) (string, error)
CreateSimpleThread(ctx context.Context, channelID, name, initialMessage string) (string, error)
GetMemberRoles(ctx context.Context, guildID, userID string) ([]string, error)
}
Bot represents the chat platform bot interface (Discord or Slack).
type ChannelQueue ¶
type ChannelQueue struct {
// contains filtered or unexported fields
}
ChannelQueue provides per-channel concurrency control, ensuring only one agent container runs per channel at a time.
func NewChannelQueue ¶
func NewChannelQueue() *ChannelQueue
NewChannelQueue creates a new ChannelQueue.
func (*ChannelQueue) Acquire ¶
func (q *ChannelQueue) Acquire(channelID string)
Acquire blocks until the channel slot is available, then acquires it.
func (*ChannelQueue) Release ¶
func (q *ChannelQueue) Release(channelID string)
Release releases the channel slot so the next request can proceed.
type IncomingMessage ¶
type IncomingMessage struct {
ChannelID string
GuildID string
AuthorID string
AuthorName string
Content string
MessageID string
IsBotMention bool
IsReplyToBot bool
HasPrefix bool
IsDM bool
Timestamp time.Time
AuthorRoles []string // role IDs for permission checking (Discord only)
}
IncomingMessage from the chat platform.
type Interaction ¶
type Interaction struct {
ChannelID string
GuildID string
CommandName string
Options map[string]string
AuthorID string // user who invoked the command
AuthorRoles []string // role IDs (Discord only)
}
Interaction represents a slash command interaction.
type Orchestrator ¶
type Orchestrator struct {
// contains filtered or unexported fields
}
Orchestrator coordinates all components of the loop bot.
func New ¶
func New(store db.Store, bot Bot, runner Runner, scheduler Scheduler, logger *slog.Logger, platform types.Platform, cfg config.Config) *Orchestrator
New creates a new Orchestrator.
func (*Orchestrator) HandleChannelDelete ¶ added in v0.1.12
func (o *Orchestrator) HandleChannelDelete(ctx context.Context, channelID string, isThread bool)
HandleChannelDelete removes a deleted channel or thread from the database. For channels (not threads), it also removes all child threads.
func (*Orchestrator) HandleChannelJoin ¶ added in v0.1.22
func (o *Orchestrator) HandleChannelJoin(ctx context.Context, channelID string)
HandleChannelJoin auto-registers a channel when the bot is added to it.
func (*Orchestrator) HandleInteraction ¶
func (o *Orchestrator) HandleInteraction(ctx context.Context, interaction any)
HandleInteraction processes a slash command interaction.
func (*Orchestrator) HandleMessage ¶
func (o *Orchestrator) HandleMessage(ctx context.Context, msg *IncomingMessage)
HandleMessage processes an incoming chat message.
func (*Orchestrator) Start ¶
func (o *Orchestrator) Start(ctx context.Context) error
Start registers handlers, slash commands, and starts the bot and scheduler.
func (*Orchestrator) Stop ¶
func (o *Orchestrator) Stop() error
Stop gracefully shuts down the bot, scheduler, and runner.
type OutgoingMessage ¶
OutgoingMessage to the chat platform.
type Runner ¶
type Runner interface {
Run(ctx context.Context, req *agent.AgentRequest) (*agent.AgentResponse, error)
Cleanup(ctx context.Context) error
}
Runner runs Claude agent in a container.
type Scheduler ¶
type Scheduler interface {
Start(ctx context.Context) error
Stop() error
AddTask(ctx context.Context, task *db.ScheduledTask) (int64, error)
RemoveTask(ctx context.Context, taskID int64) error
ListTasks(ctx context.Context, channelID string) ([]*db.ScheduledTask, error)
SetTaskEnabled(ctx context.Context, taskID int64, enabled bool) error
ToggleTask(ctx context.Context, taskID int64) (bool, error)
EditTask(ctx context.Context, taskID int64, schedule, taskType, prompt *string) error
}
Scheduler manages scheduled tasks.
type TaskExecutor ¶
type TaskExecutor struct {
// contains filtered or unexported fields
}
TaskExecutor implements scheduler.TaskExecutor by running an agent and delivering the response to the chat platform.
func NewTaskExecutor ¶
func NewTaskExecutor(runner Runner, bot Bot, store db.Store, logger *slog.Logger, containerTimeout time.Duration, streamingEnabled bool) *TaskExecutor
NewTaskExecutor creates a new TaskExecutor.
func (*TaskExecutor) ExecuteTask ¶
func (e *TaskExecutor) ExecuteTask(ctx context.Context, task *db.ScheduledTask) (string, error)
ExecuteTask runs an agent for the given scheduled task and sends the result to the chat platform.