Documentation
¶
Index ¶
- Constants
- Variables
- func BuildActionKeyboard() *imbot.KeyboardBuilder
- func BuildBindConfirmKeyboard() *imbot.KeyboardBuilder
- func BuildBindConfirmPrompt(proposedPath string) string
- func BuildCancelKeyboard() *imbot.KeyboardBuilder
- func BuildCreateConfirmKeyboard(path string) (*imbot.KeyboardBuilder, string)
- func BuildCustomPathPrompt() string
- func ExpandPath(path string) (string, error)
- func InitChatSchema(db *sql.DB) error
- func ParseTextResponse(text string) (approved bool, remember bool, isValid bool)
- func SendDirectoryBrowser(ctx context.Context, bot imbot.Bot, browser *DirectoryBrowser, chatID string, ...) (string, error)
- func ValidateProjectPath(path string) error
- type BindFlowState
- type BotHandler
- func (h *BotHandler) HandleMessage(msg imbot.Message, platform imbot.Platform, botUUID string)
- func (h *BotHandler) RequestConfirmation(ctx context.Context, hCtx HandlerContext, message, requestID string) (bool, error)
- func (h *BotHandler) RequestInteraction(ctx context.Context, hCtx HandlerContext, req imbot.InteractionRequest) (*imbot.InteractionResponse, error)
- func (h *BotHandler) RequestOptionSelection(ctx context.Context, hCtx HandlerContext, message, requestID string, ...) (int, *imbot.Interaction, error)
- func (h *BotHandler) SendText(hCtx HandlerContext, text string)
- type BotLifecycle
- type BotSetting
- type Chat
- type ChatStore
- func (s *ChatStore) AddToWhitelist(chatID, platform, addedBy string) error
- func (s *ChatStore) BindProject(chatID, platform, projectPath, ownerID string) error
- func (s *ChatStore) GetBashCwd(chatID string) (string, bool, error)
- func (s *ChatStore) GetChat(chatID string) (*Chat, error)
- func (s *ChatStore) GetOrCreateChat(chatID, platform string) (*Chat, error)
- func (s *ChatStore) GetProjectPath(chatID string) (string, bool, error)
- func (s *ChatStore) GetSession(chatID string) (string, bool, error)
- func (s *ChatStore) IsWhitelisted(chatID string) bool
- func (s *ChatStore) ListChatsByOwner(ownerID, platform string) ([]*Chat, error)
- func (s *ChatStore) RemoveFromWhitelist(chatID string) error
- func (s *ChatStore) SetBashCwd(chatID, cwd string) error
- func (s *ChatStore) SetSession(chatID, sessionID string) error
- func (s *ChatStore) UpdateChat(chatID string, fn func(*Chat)) error
- func (s *ChatStore) UpsertChat(chat *Chat) error
- type CompletionCallback
- type DirectoryBrowser
- func (b *DirectoryBrowser) BuildKeyboard(chatID string) (*BindFlowState, *imbot.KeyboardBuilder, string, error)
- func (b *DirectoryBrowser) Clear(chatID string)
- func (b *DirectoryBrowser) GetCurrentPath(chatID string) string
- func (b *DirectoryBrowser) GetState(chatID string) *BindFlowState
- func (b *DirectoryBrowser) IsWaitingInput(chatID string) bool
- func (b *DirectoryBrowser) Navigate(chatID string, path string) error
- func (b *DirectoryBrowser) NavigateByIndex(chatID string, index int) error
- func (b *DirectoryBrowser) NavigateUp(chatID string) error
- func (b *DirectoryBrowser) NextPage(chatID string) error
- func (b *DirectoryBrowser) PrevPage(chatID string) error
- func (b *DirectoryBrowser) SetMessageID(chatID string, messageID string)
- func (b *DirectoryBrowser) SetWaitingInput(chatID string, waiting bool, promptMsgID string)
- func (b *DirectoryBrowser) Start(chatID string) (*BindFlowState, error)
- type FileStore
- func (s *FileStore) DownloadFile(ctx context.Context, projectPath, url, mimeType string) (*StoredFile, error)
- func (s *FileStore) GetDownloadDir(projectPath string) string
- func (s *FileStore) IsAllowedSize(mimeType string, size int64) bool
- func (s *FileStore) IsAllowedType(mimeType string) bool
- func (s *FileStore) SetTelegramToken(token string)
- func (s *FileStore) StoreFile(ctx context.Context, projectPath string, reader io.Reader, ...) (*StoredFile, error)
- type HandlerContext
- type IMPrompter
- func (p *IMPrompter) GetPendingRequest(requestID string) (*ask.Request, bool)
- func (p *IMPrompter) GetPendingRequestsForChat(chatID string) []ask.Request
- func (p *IMPrompter) OnApproval(ctx context.Context, req agentboot.PermissionRequest) (agentboot.PermissionResult, error)
- func (p *IMPrompter) OnAsk(ctx context.Context, req agentboot.AskRequest) (agentboot.AskResult, error)
- func (p *IMPrompter) Prompt(ctx context.Context, req ask.Request) (ask.Result, error)
- func (p *IMPrompter) PromptPermission(ctx context.Context, req agentboot.PermissionRequest) (agentboot.PermissionResult, error)
- func (p *IMPrompter) SetDefaultTimeout(timeout time.Duration)
- func (p *IMPrompter) SubmitDecision(requestID string, approved bool, remember bool, reason string) error
- func (p *IMPrompter) SubmitResult(requestID string, result ask.Result) error
- func (p *IMPrompter) SubmitUserResponse(requestID string, response ask.Response) error
- type Manager
- func (m *Manager) IsRunning(uuid string) bool
- func (m *Manager) SetDBPath(dbPath string)
- func (m *Manager) Start(parentCtx context.Context, uuid string) error
- func (m *Manager) StartEnabled(ctx context.Context) error
- func (m *Manager) StartEnabledStopDisabled(ctx context.Context) error
- func (m *Manager) Stop(uuid string)
- func (m *Manager) StopAll()
- func (m *Manager) Sync(ctx context.Context) error
- type PendingBind
- type ResponseMeta
- type SettingsStore
- type Store
- func (s *Store) AddGroupToWhitelist(groupID, platform, addedBy string) error
- func (s *Store) ChatStore() *ChatStore
- func (s *Store) Close() error
- func (s *Store) DB() *sql.DB
- func (s *Store) GetBashCwd(chatID string) (string, bool, error)
- func (s *Store) GetSessionForChat(chatID string) (string, bool, error)
- func (s *Store) IsGroupWhitelisted(groupID string) bool
- func (s *Store) ListWhitelistedGroups() ([]struct{ ... }, error)
- func (s *Store) RemoveGroupFromWhitelist(groupID string) error
- func (s *Store) SetBashCwd(chatID, cwd string) error
- func (s *Store) SetSessionForChat(chatID, sessionID string) error
- type StoredFile
- type TelegramFile
Constants ¶
const ( DefaultMaxImageSize = 25 * 1024 * 1024 // 25MB DefaultMaxDocSize = 50 * 1024 * 1024 // 50MB )
Variables ¶
var AllowedMIMETypes = map[string]string{
"image/jpeg": "image",
"image/png": "image",
"image/gif": "image",
"image/webp": "image",
"application/pdf": "document",
"text/plain": "document",
"text/markdown": "document",
"text/csv": "document",
"application/msword": "document",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "document",
"application/vnd.ms-excel": "document",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "document",
}
AllowedMIMETypes lists supported file types
Functions ¶
func BuildActionKeyboard ¶
func BuildActionKeyboard() *imbot.KeyboardBuilder
BuildActionKeyboard builds the inline keyboard for actions (Clear/Bind)
func BuildBindConfirmKeyboard ¶ added in v0.260307.0
func BuildBindConfirmKeyboard() *imbot.KeyboardBuilder
BuildBindConfirmKeyboard builds the confirmation keyboard for binding to current directory
func BuildBindConfirmPrompt ¶ added in v0.260307.0
BuildBindConfirmPrompt returns the text for bind confirmation prompt
func BuildCancelKeyboard ¶
func BuildCancelKeyboard() *imbot.KeyboardBuilder
BuildCancelKeyboard builds a simple cancel keyboard
func BuildCreateConfirmKeyboard ¶
func BuildCreateConfirmKeyboard(path string) (*imbot.KeyboardBuilder, string)
BuildCreateConfirmKeyboard builds the confirmation keyboard for creating a directory
func BuildCustomPathPrompt ¶
func BuildCustomPathPrompt() string
BuildCustomPathPrompt returns the text for custom path input prompt
func ExpandPath ¶
ExpandPath expands ~ to home directory and returns absolute path
func InitChatSchema ¶
InitChatSchema initializes the chat schema
func ParseTextResponse ¶ added in v0.260305.1400
ParseTextResponse parses user text input as a permission response Returns: (approved, remember, isValid)
func SendDirectoryBrowser ¶
func SendDirectoryBrowser(ctx context.Context, bot imbot.Bot, browser *DirectoryBrowser, chatID string, editMessageID string) (string, error)
SendDirectoryBrowser sends or updates the directory browser message
func ValidateProjectPath ¶
ValidateProjectPath checks if the path exists and is accessible
Types ¶
type BindFlowState ¶
type BindFlowState struct {
ChatID string
CurrentPath string
Page int
TotalDirs int
PageSize int
MessageID string // Message ID to edit
ExpiresAt time.Time
WaitingInput bool // Waiting for custom path input
PromptMsgID string // Prompt message ID for cleanup
Dirs []string // Current directory list (for navigation by index)
}
BindFlowState represents the state of an ongoing bind flow
type BotHandler ¶ added in v0.260305.1400
type BotHandler struct {
// contains filtered or unexported fields
}
BotHandler encapsulates all bot message handling logic and dependencies
func NewBotHandler ¶ added in v0.260305.1400
func NewBotHandler( ctx context.Context, botSetting BotSetting, chatStore *ChatStore, sessionMgr *session.Manager, agentBoot *agentboot.AgentBoot, summaryEngine *summarizer.Engine, directoryBrowser *DirectoryBrowser, manager *imbot.Manager, ) *BotHandler
NewBotHandler creates a new bot handler with all dependencies
func (*BotHandler) HandleMessage ¶ added in v0.260305.1400
HandleMessage is the main entry point for handling bot messages
func (*BotHandler) RequestConfirmation ¶ added in v0.260307.0
func (h *BotHandler) RequestConfirmation(ctx context.Context, hCtx HandlerContext, message, requestID string) (bool, error)
RequestConfirmation requests a yes/no confirmation from the user Uses the new interaction system with platform-agnostic UI
func (*BotHandler) RequestInteraction ¶ added in v0.260307.0
func (h *BotHandler) RequestInteraction(ctx context.Context, hCtx HandlerContext, req imbot.InteractionRequest) (*imbot.InteractionResponse, error)
RequestInteraction sends an interaction request using the new interaction system This is a convenience method for BotHandler to request platform-agnostic interactions
func (*BotHandler) RequestOptionSelection ¶ added in v0.260307.0
func (h *BotHandler) RequestOptionSelection(ctx context.Context, hCtx HandlerContext, message, requestID string, options []imbot.Option) (int, *imbot.Interaction, error)
RequestOptionSelection requests the user to select from a list of options Uses the new interaction system with platform-agnostic UI
func (*BotHandler) SendText ¶ added in v0.260305.1400
func (h *BotHandler) SendText(hCtx HandlerContext, text string)
SendText sends a plain text message
type BotLifecycle ¶ added in v0.260305.1400
type BotLifecycle interface {
// Start starts a bot by UUID
Start(ctx context.Context, uuid string) error
// Stop stops a bot by UUID
Stop(uuid string)
// IsRunning checks if a bot is running
IsRunning(uuid string) bool
// Sync ensures running bots match the enabled settings
Sync(ctx context.Context) error
}
BotLifecycle defines the interface for controlling bot lifecycle This allows the API layer to control bot startup/shutdown without direct dependency on the Manager type
type BotSetting ¶ added in v0.260305.1400
type BotSetting struct {
UUID string `json:"uuid,omitempty"`
Name string `json:"name,omitempty"` // User-defined name for the bot
Token string `json:"token,omitempty"` // Legacy: for backward compatibility
Platform string `json:"platform"` // Platform identifier
AuthType string `json:"auth_type"` // Auth type: token, oauth, qr
Auth map[string]string `json:"auth"` // Dynamic auth fields based on platform
ProxyURL string `json:"proxy_url,omitempty"` // Optional proxy URL
ChatIDLock string `json:"chat_id,omitempty"` // Optional chat ID lock
BashAllowlist []string `json:"bash_allowlist,omitempty"` // Optional bash command allowlist
Enabled bool `json:"enabled"` // Whether this bot is enabled
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
BotSetting represents bot configuration with platform-specific auth
type Chat ¶
type Chat struct {
ChatID string `json:"chat_id"`
Platform string `json:"platform"`
ProjectPath string `json:"project_path,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
// Group-specific
IsWhitelisted bool `json:"is_whitelisted"`
WhitelistedBy string `json:"whitelisted_by,omitempty"`
// Bash state
BashCwd string `json:"bash_cwd,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Chat represents all state associated with a chat (direct or group)
type ChatStore ¶
type ChatStore struct {
// contains filtered or unexported fields
}
ChatStore handles unified chat persistence
func NewChatStore ¶
NewChatStore creates a new chat store
func (*ChatStore) AddToWhitelist ¶
AddToWhitelist adds a chat to the whitelist
func (*ChatStore) BindProject ¶
BindProject binds a project to a chat (creates chat if not exists)
func (*ChatStore) GetBashCwd ¶
GetBashCwd retrieves the bash working directory for a chat
func (*ChatStore) GetOrCreateChat ¶
GetOrCreateChat gets a chat or creates it if not exists
func (*ChatStore) GetProjectPath ¶
GetProjectPath retrieves the project path for a chat
func (*ChatStore) GetSession ¶
GetSession retrieves the session for a chat
func (*ChatStore) IsWhitelisted ¶
IsWhitelisted checks if a chat is whitelisted
func (*ChatStore) ListChatsByOwner ¶
ListChatsByOwner lists all chats owned by a user
func (*ChatStore) RemoveFromWhitelist ¶
RemoveFromWhitelist removes a chat from the whitelist
func (*ChatStore) SetBashCwd ¶
SetBashCwd sets the bash working directory for a chat
func (*ChatStore) SetSession ¶
SetSession sets the session for a chat (creates chat if not exists)
func (*ChatStore) UpdateChat ¶
UpdateChat updates specific fields of a chat
func (*ChatStore) UpsertChat ¶
UpsertChat creates or updates a chat
type CompletionCallback ¶ added in v0.260305.1400
type CompletionCallback struct {
// contains filtered or unexported fields
}
func (*CompletionCallback) OnComplete ¶ added in v0.260305.1400
func (c *CompletionCallback) OnComplete(result *agentboot.CompletionResult)
type DirectoryBrowser ¶
type DirectoryBrowser struct {
// contains filtered or unexported fields
}
DirectoryBrowser manages directory navigation for bind flow
func NewDirectoryBrowser ¶
func NewDirectoryBrowser() *DirectoryBrowser
NewDirectoryBrowser creates a new directory browser
func (*DirectoryBrowser) BuildKeyboard ¶
func (b *DirectoryBrowser) BuildKeyboard(chatID string) (*BindFlowState, *imbot.KeyboardBuilder, string, error)
BuildKeyboard builds the inline keyboard for directory browsing
func (*DirectoryBrowser) Clear ¶
func (b *DirectoryBrowser) Clear(chatID string)
Clear removes the state for a chat
func (*DirectoryBrowser) GetCurrentPath ¶
func (b *DirectoryBrowser) GetCurrentPath(chatID string) string
GetCurrentPath returns the current path for a chat
func (*DirectoryBrowser) GetState ¶
func (b *DirectoryBrowser) GetState(chatID string) *BindFlowState
GetState returns the current state for a chat
func (*DirectoryBrowser) IsWaitingInput ¶
func (b *DirectoryBrowser) IsWaitingInput(chatID string) bool
IsWaitingInput checks if the chat is waiting for custom path input
func (*DirectoryBrowser) Navigate ¶
func (b *DirectoryBrowser) Navigate(chatID string, path string) error
Navigate navigates to a subdirectory
func (*DirectoryBrowser) NavigateByIndex ¶
func (b *DirectoryBrowser) NavigateByIndex(chatID string, index int) error
NavigateByIndex navigates to a subdirectory by index (stored in state.Dirs)
func (*DirectoryBrowser) NavigateUp ¶
func (b *DirectoryBrowser) NavigateUp(chatID string) error
NavigateUp navigates to the parent directory
func (*DirectoryBrowser) NextPage ¶
func (b *DirectoryBrowser) NextPage(chatID string) error
NextPage moves to the next page of directories
func (*DirectoryBrowser) PrevPage ¶
func (b *DirectoryBrowser) PrevPage(chatID string) error
PrevPage moves to the previous page of directories
func (*DirectoryBrowser) SetMessageID ¶
func (b *DirectoryBrowser) SetMessageID(chatID string, messageID string)
SetMessageID sets the message ID for editing
func (*DirectoryBrowser) SetWaitingInput ¶
func (b *DirectoryBrowser) SetWaitingInput(chatID string, waiting bool, promptMsgID string)
SetWaitingInput sets the waiting for input state
func (*DirectoryBrowser) Start ¶
func (b *DirectoryBrowser) Start(chatID string) (*BindFlowState, error)
Start begins a new bind flow for a chat
type FileStore ¶ added in v0.260305.1400
type FileStore struct {
// contains filtered or unexported fields
}
FileStore handles project-based file storage for bot media
func NewFileStore ¶ added in v0.260305.1400
func NewFileStore() *FileStore
NewFileStore creates a new file store with default limits
func NewFileStoreWithLimits ¶ added in v0.260305.1400
NewFileStoreWithLimits creates a new file store with custom limits
func NewFileStoreWithProxy ¶ added in v0.260305.1400
NewFileStoreWithProxy creates a new file store with proxy support
func (*FileStore) DownloadFile ¶ added in v0.260305.1400
func (s *FileStore) DownloadFile(ctx context.Context, projectPath, url, mimeType string) (*StoredFile, error)
DownloadFile downloads a file from a URL to the project's .download directory Returns an error if file size exceeds limits
func (*FileStore) GetDownloadDir ¶ added in v0.260305.1400
GetDownloadDir returns the .download directory for a project
func (*FileStore) IsAllowedSize ¶ added in v0.260305.1400
IsAllowedSize checks if the size is within limits for the mime type
func (*FileStore) IsAllowedType ¶ added in v0.260305.1400
IsAllowedType checks if the mime type is allowed
func (*FileStore) SetTelegramToken ¶ added in v0.260305.1400
SetTelegramToken sets the Telegram bot token for resolving file URLs
type HandlerContext ¶ added in v0.260305.1400
type HandlerContext struct {
Bot imbot.Bot
BotUUID string
ChatID string
SenderID string
MessageID string
Platform imbot.Platform
IsDirect bool
IsGroup bool
Text string
Media []imbot.MediaAttachment
Metadata map[string]interface{}
}
HandlerContext contains per-message context data
type IMPrompter ¶ added in v0.260305.1400
type IMPrompter struct {
// contains filtered or unexported fields
}
IMPrompter implements ask.Prompter using IM (Telegram, etc.) for user interaction
func NewIMPrompter ¶ added in v0.260305.1400
func NewIMPrompter(manager *imbot.Manager) *IMPrompter
NewIMPrompter creates a new IM-based prompter
func (*IMPrompter) GetPendingRequest ¶ added in v0.260305.1400
func (p *IMPrompter) GetPendingRequest(requestID string) (*ask.Request, bool)
GetPendingRequest returns a pending request by ID
func (*IMPrompter) GetPendingRequestsForChat ¶ added in v0.260305.1400
func (p *IMPrompter) GetPendingRequestsForChat(chatID string) []ask.Request
GetPendingRequestsForChat returns all pending requests for a specific chat
func (*IMPrompter) OnApproval ¶ added in v0.260305.1400
func (p *IMPrompter) OnApproval(ctx context.Context, req agentboot.PermissionRequest) (agentboot.PermissionResult, error)
OnApproval implements agentboot.ApprovalHandler. It handles permission confirmation requests via IM.
func (*IMPrompter) OnAsk ¶ added in v0.260305.1400
func (p *IMPrompter) OnAsk(ctx context.Context, req agentboot.AskRequest) (agentboot.AskResult, error)
OnAsk implements agentboot.AskHandler. It handles user questions/selections via IM.
func (*IMPrompter) Prompt ¶ added in v0.260305.1400
Prompt prompts the user via IM for response This implements the ask.Prompter interface
func (*IMPrompter) PromptPermission ¶ added in v0.260305.1400
func (p *IMPrompter) PromptPermission(ctx context.Context, req agentboot.PermissionRequest) (agentboot.PermissionResult, error)
PromptPermission implements the legacy agentboot.UserPrompter interface
func (*IMPrompter) SetDefaultTimeout ¶ added in v0.260305.1400
func (p *IMPrompter) SetDefaultTimeout(timeout time.Duration)
SetDefaultTimeout sets the default timeout for requests
func (*IMPrompter) SubmitDecision ¶ added in v0.260305.1400
func (p *IMPrompter) SubmitDecision(requestID string, approved bool, remember bool, reason string) error
SubmitDecision submits a user's decision for a pending request
func (*IMPrompter) SubmitResult ¶ added in v0.260305.1400
func (p *IMPrompter) SubmitResult(requestID string, result ask.Result) error
SubmitResult submits a result for a pending request
func (*IMPrompter) SubmitUserResponse ¶ added in v0.260305.1400
func (p *IMPrompter) SubmitUserResponse(requestID string, response ask.Response) error
SubmitUserResponse submits a user response for a pending request This parses the response using the appropriate tool handler
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the lifecycle of running bot instances
func NewManager ¶
func NewManager(store SettingsStore, sessionMgr *session.Manager, agentBoot *agentboot.AgentBoot, ) *Manager
NewManager creates a new bot manager with a settings store
func (*Manager) SetDBPath ¶ added in v0.260305.1400
SetDBPath sets the database path for chat store operations
func (*Manager) StartEnabled ¶
StartEnabled starts all enabled bots
func (*Manager) StartEnabledStopDisabled ¶ added in v0.260305.1400
StartEnabledStopDisabled is a convenience method that ensures running bots match enabled settings. It's an alias for Sync() with clearer naming for specific use cases.
type PendingBind ¶ added in v0.260307.0
PendingBind represents a pending bind confirmation request
type ResponseMeta ¶
ResponseMeta contains metadata for response formatting
type SettingsStore ¶ added in v0.260305.1400
type SettingsStore interface {
// GetSettingsByUUIDInterface returns settings by UUID as interface{}
GetSettingsByUUIDInterface(uuid string) (interface{}, error)
// ListEnabledSettingsInterface returns all enabled settings as interface{}
ListEnabledSettingsInterface() (interface{}, error)
}
SettingsStore defines the interface for bot settings storage This allows both the legacy bot.Store and the new db.ImBotSettingsStore to be used
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func NewStoreForChatOnly ¶ added in v0.260305.1400
NewStoreForChatOnly creates a minimal bot.Store for chat state management only
func (*Store) AddGroupToWhitelist ¶
func (*Store) GetSessionForChat ¶
func (*Store) IsGroupWhitelisted ¶
func (*Store) ListWhitelistedGroups ¶
func (s *Store) ListWhitelistedGroups() ([]struct { GroupID string Platform string AddedBy string CreatedAt string }, error)
ListWhitelistedGroups returns all whitelisted groups