channels

package
v1.1.68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandRiskLevel

func CommandRiskLevel(command string) string

CommandRiskLevel classifies the risk level of a bash command. Returns "low", "medium", or "high".

func FormatApprovalNotification

func FormatApprovalNotification(toolName string, args map[string]any, riskLevel string, approved bool) string

FormatApprovalNotification formats a notification for medium/high risk tool calls.

func RegisterActiveAgent

func RegisterActiveAgent(id string, a *agent.Agent)

RegisterActiveAgent registers a running agent for question resolution.

func UnregisterActiveAgent

func UnregisterActiveAgent(id string)

UnregisterActiveAgent removes an agent from the registry.

Types

type AgentConfig

type AgentConfig struct {
	MaxTurns                 int     `json:"max_turns"`
	BudgetPressure           bool    `json:"budget_pressure"`
	ContextPressure          bool    `json:"context_pressure"`
	BudgetPressureThreshold  float64 `json:"budget_pressure_threshold,omitempty"`  // remaining ratio (0-1), default 0.20
	ContextPressureThreshold float64 `json:"context_pressure_threshold,omitempty"` // usage ratio (0-1), default 0.55
}

AgentConfig defines agent behavior settings.

type ApprovalDecision

type ApprovalDecision struct {
	Approved  bool
	Reason    string
	RiskLevel string
}

ApprovalDecision represents the result of an approval check.

type ChannelSession

type ChannelSession struct {
	ID         string // e.g. "channels/wechat/wxid_user1"
	Platform   string // "wechat", "feishu", "ws"
	UserID     string
	WorkDir    string
	Manager    *session.Manager
	SandboxMgr *sandbox.Manager
	Registry   *tools.Registry
	MCPClients []*mcp.Client // connected MCP clients (nil if none)
	Mode       string
	LastUsed   time.Time

	// ForceCompact is a legacy/session flag consumed by the next agent run.
	// The /compact command now executes compaction immediately.
	ForceCompact bool
	// contains filtered or unexported fields
}

ChannelSession holds state for a single channel user session.

func (*ChannelSession) Lock

func (s *ChannelSession) Lock()

Lock acquires the session lock.

func (*ChannelSession) Touch

func (s *ChannelSession) Touch()

Touch updates the last-used timestamp.

func (*ChannelSession) Unlock

func (s *ChannelSession) Unlock()

Unlock releases the session lock.

type Config

type Config struct {
	Server          ServerConfig   `json:"server"`
	DefaultProvider string         `json:"default_provider,omitempty"`
	DefaultModel    string         `json:"default_model,omitempty"`
	MultiAgent      bool           `json:"multi_agent,omitempty"`
	WebSearch       bool           `json:"web_search,omitempty"`
	Browser         bool           `json:"browser,omitempty"`
	A2AMaster       bool           `json:"a2a_master,omitempty"`
	Sandbox         bool           `json:"sandbox,omitempty"`
	Wechat          WechatConfig   `json:"wechat"`
	Feishu          FeishuConfig   `json:"feishu"`
	Webhooks        WebhookConfig  `json:"webhooks"`
	Cron            CronConfig     `json:"cron"`
	Memory          MemoryConfig   `json:"memory"`
	Security        SecurityConfig `json:"security"`
	Hooks           HooksConfig    `json:"hooks"`
	Agent           AgentConfig    `json:"agent"`
	WorkDir         string         `json:"work_dir"`
}

Config holds messaging channel runtime configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

func (*Config) GetDefaultModel

func (c *Config) GetDefaultModel(settingsModel string) string

GetDefaultModel returns the effective default model. Priority: Config → Settings

func (*Config) GetDefaultProvider

func (c *Config) GetDefaultProvider(settingsProvider string) string

GetDefaultProvider returns the effective default provider. Priority: Config → Settings

func (*Config) GetListenAddr

func (c *Config) GetListenAddr() string

GetListenAddr returns the listen address string.

func (*Config) GetPlatformWorkDir

func (c *Config) GetPlatformWorkDir(platform string) string

GetPlatformWorkDir returns the work directory for a specific platform. Priority: platform work_dir → global work_dir → cwd

func (*Config) GetWechatCredPath

func (c *Config) GetWechatCredPath() string

GetWechatCredPath returns the wechat credentials path.

func (*Config) GetWorkDir

func (c *Config) GetWorkDir() string

GetWorkDir returns the resolved work directory. Falls back to current directory if not set.

type CronConfig

type CronConfig struct {
	Enabled  bool `json:"enabled"`
	Interval int  `json:"interval,omitempty"` // seconds between checks (default 30)
}

CronConfig defines cron scheduler settings.

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher routes messages to per-user agent sessions.

func NewDispatcher

func NewDispatcher(cfg *Config, settings *config.Settings, version string, cronStore cron.CronStore, scheduler *cron.Scheduler) (*Dispatcher, error)

NewDispatcher creates a dispatcher with the given configuration.

func (*Dispatcher) AgentManager

func (d *Dispatcher) AgentManager() *agent.AgentManager

AgentManager returns the dispatcher agent manager used by sub-agents and cron.

func (*Dispatcher) EnsureAgentManager

func (d *Dispatcher) EnsureAgentManager() *agent.AgentManager

EnsureAgentManager creates the dispatcher agent manager if it is not already available.

func (*Dispatcher) GetSession

func (d *Dispatcher) GetSession(key string) *ChannelSession

GetSession returns a session by key, or nil if not found.

func (*Dispatcher) HandleMessage

func (d *Dispatcher) HandleMessage(ctx context.Context, msg messaging.InboundMessage) (string, error)

HandleMessage processes an inbound message from any platform.

func (*Dispatcher) HandleWSMessage

func (d *Dispatcher) HandleWSMessage(ctx context.Context, connID, text string, eventCh chan<- agent.Event) error

HandleWSMessage processes a message from a WebSocket client.

func (*Dispatcher) ListSessions

func (d *Dispatcher) ListSessions() []*ChannelSession

ListSessions returns all active session keys.

func (*Dispatcher) RegisterApproval

func (d *Dispatcher) RegisterApproval(approvalID string) chan bool

RegisterApproval registers a pending approval and returns its channel.

func (*Dispatcher) RemoveSession

func (d *Dispatcher) RemoveSession(key string)

RemoveSession removes a session from the pool.

func (*Dispatcher) ResolveApproval

func (d *Dispatcher) ResolveApproval(approvalID string, approved bool) bool

ResolveApproval resolves a pending approval with the given decision.

func (*Dispatcher) ResolveQuestion

func (d *Dispatcher) ResolveQuestion(questionID, answer string) bool

ResolveQuestion sends an answer to a currently running agent question.

func (*Dispatcher) RotateSession

func (d *Dispatcher) RotateSession(platform, userID string) error

RotateSession archives the current session and creates a new one. Called when user sends /new.

func (*Dispatcher) SetCronScheduler

func (d *Dispatcher) SetCronScheduler(s *cron.Scheduler)

SetCronScheduler updates the scheduler used by cron tools created for sessions.

type FeishuConfig

type FeishuConfig struct {
	Enabled      bool     `json:"enabled"`
	AppID        string   `json:"app_id"`
	AppSecret    string   `json:"app_secret"`
	WorkDir      string   `json:"work_dir"`
	AllowedUsers []string `json:"allowed_users"`
}

FeishuConfig defines Feishu (Lark) platform settings.

type HooksConfig

type HooksConfig struct {
	PreToolCall  string `json:"pre_tool_call"`
	PostToolCall string `json:"post_tool_call"`
}

HooksConfig defines shell hook scripts.

type MemoryConfig

type MemoryConfig struct {
	Enabled bool   `json:"enabled"`
	Path    string `json:"path"` // empty = auto-discover .mothx/memory.md → <GLOBAL_DIR>/memory.md
}

MemoryConfig defines persistent memory settings.

type Security

type Security struct {
	// contains filtered or unexported fields
}

Security provides user whitelist validation and smart approval logic for messaging channel mode.

func NewSecurity

func NewSecurity(cfg *Config) *Security

NewSecurity creates a security manager.

func (*Security) CheckUserAllowed

func (s *Security) CheckUserAllowed(platform, userID string) error

CheckUserAllowed returns nil if the user is allowed on the given platform. Returns an error with reason if blocked.

func (*Security) CheckWorkDirAllowed

func (s *Security) CheckWorkDirAllowed(workDir string) error

CheckWorkDirAllowed returns nil if the working directory is allowed.

func (*Security) ShouldAutoApprove

func (s *Security) ShouldAutoApprove(toolName string, args map[string]any, mode string) bool

ShouldAutoApprove returns true if the tool call can be auto-approved in messaging channel mode. In messaging channel mode, bots run unattended so we need stricter auto-approval rules.

type SecurityConfig

type SecurityConfig struct {
	SmartApprovals  bool     `json:"smart_approvals"`
	AllowedWorkDirs []string `json:"allowed_work_dirs"`
}

SecurityConfig defines security settings.

type ServerConfig

type ServerConfig struct {
	Port      int    `json:"port"`
	Host      string `json:"host"`
	AuthToken string `json:"auth_token"`
}

ServerConfig defines the WebSocket runtime settings.

type WebhookConfig

type WebhookConfig struct {
	Enabled bool           `json:"enabled"`
	Secret  string         `json:"secret"`
	Routes  []WebhookRoute `json:"routes"`
}

WebhookConfig defines inbound webhook settings.

type WebhookHandler

type WebhookHandler struct {
	// contains filtered or unexported fields
}

WebhookHandler implements webhook.Handler by spawning agent tasks.

func NewWebhookHandler

func NewWebhookHandler(dispatcher *Dispatcher, platforms map[string]messaging.Platform) *WebhookHandler

NewWebhookHandler creates a webhook handler that spawns agent tasks.

func (*WebhookHandler) HandleWebhookEvent

func (h *WebhookHandler) HandleWebhookEvent(ctx context.Context, route webhook.RouteConfig, payload []byte) error

HandleWebhookEvent processes an incoming webhook event by spawning an agent task.

func (*WebhookHandler) SetPlatforms

func (h *WebhookHandler) SetPlatforms(platforms map[string]messaging.Platform)

SetPlatforms replaces the platform map. Used to wire platforms after construction.

type WebhookRoute

type WebhookRoute struct {
	Path           string   `json:"path"`
	Events         []string `json:"events"`
	Skill          string   `json:"skill"`
	Delivery       string   `json:"delivery"`
	DeliveryTarget string   `json:"delivery_target,omitempty"`
}

WebhookRoute maps an inbound webhook path to an agent skill + delivery.

type WechatConfig

type WechatConfig struct {
	Enabled      bool     `json:"enabled"`
	CredPath     string   `json:"cred_path"`
	WorkDir      string   `json:"work_dir"`
	AllowedUsers []string `json:"allowed_users"`
	AutoTyping   bool     `json:"auto_typing"`
}

WechatConfig defines WeChat iLink platform settings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL