channel

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const WelcomeMessage = "Hi! I'm Anna -- your local AI assistant.\n\n" +
	"Commands:\n" +
	"/new -- Start a fresh session\n" +
	"/compact -- Compress conversation history\n" +
	"/model -- Switch between models\n" +
	"/agent -- List or switch agents\n" +
	"/whoami -- Show your user ID\n\n" +
	"Just send me a message to get started."

WelcomeMessage is the shared welcome/help text for all channels.

Variables

This section is empty.

Functions

func FormatAgentList added in v0.8.0

func FormatAgentList(agents []config.Agent, currentAgentID string) string

FormatAgentList formats the agent list for display, marking the current agent.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration as a human-friendly string.

func HandleCommand added in v0.8.0

func HandleCommand(ctx context.Context, rc *ResolvedChat, text, senderID string) (string, bool)

HandleCommand processes common bot commands shared across all channels. Returns the response text and whether the command was handled. /model and /agent are left to each channel (they need platform-specific UI).

func ParseModelArgs

func ParseModelArgs(args string) string

ParseModelArgs parses /model arguments as a query string. Returns empty string when no arguments are provided.

func ResolveAgent added in v0.8.0

func ResolveAgent(ctx context.Context, store config.Store, user config.User, chat ChatContext) (string, error)

ResolveAgent determines which agent to route to. DM: user's default_agent_id Group: chat_agents(platform, chat_id) Fallback: first enabled agent

func ResolveUser added in v0.8.0

func ResolveUser(ctx context.Context, store config.Store, externalID, platform, name string) (config.User, error)

ResolveUser upserts a user by external ID + platform, returning the user record.

func SplitMessage

func SplitMessage(text string, maxLen int) []string

SplitMessage splits text into chunks that fit within maxLen. It tries to split at newline boundaries and avoids cutting multi-byte UTF-8 characters.

Types

type AgentCommander added in v0.8.0

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

AgentCommander handles the /agent slash command for listing and switching agents.

func NewAgentCommander added in v0.8.0

func NewAgentCommander(store config.Store) *AgentCommander

NewAgentCommander creates a new AgentCommander backed by the given store.

func (*AgentCommander) List added in v0.8.0

func (ac *AgentCommander) List(ctx context.Context) ([]config.Agent, error)

List returns all enabled agents.

func (*AgentCommander) Switch added in v0.8.0

func (ac *AgentCommander) Switch(ctx context.Context, user config.User, chat ChatContext, agentSlug string) error

Switch sets the active agent for a DM (updates user's default_agent_id) or a group chat (updates chat_agents). Returns an error if the agent slug is not found or not enabled.

type Channel

type Channel interface {
	// Name returns a unique identifier (e.g. "telegram", "qq").
	Name() string

	// Start begins listening for messages. Blocks until ctx is cancelled.
	Start(ctx context.Context) error

	// Stop gracefully shuts down the channel.
	Stop()

	// Notify sends a push notification to a target within this channel.
	Notify(ctx context.Context, n Notification) error
}

Channel is a messaging platform that receives user messages and sends notifications.

type ChatContext added in v0.8.0

type ChatContext struct {
	Platform string // "telegram", "qq", "feishu", "cli"
	ChatID   string // group/channel ID (empty for DMs)
	IsGroup  bool
}

ChatContext describes the chat environment for agent routing.

type Dispatcher

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

Dispatcher routes notifications to one or more registered channels. It implements Notifier so it can be passed to tools and scheduler wiring.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates an empty dispatcher. Register channels before use.

func (*Dispatcher) Channels

func (d *Dispatcher) Channels() []string

Channels returns the names of all registered channels.

func (*Dispatcher) Notify

func (d *Dispatcher) Notify(ctx context.Context, n Notification) error

Notify routes a notification to channels. If Notification.Channel is set, only that channel receives it. Otherwise all registered channels receive it.

func (*Dispatcher) Register

func (d *Dispatcher) Register(ch Channel, defaultChat string)

Register adds a channel with its default chat/channel target.

type IndexedModel

type IndexedModel struct {
	ModelOption
	GlobalIdx int
}

IndexedModel pairs a ModelOption with its 1-based global index.

func FilterModels

func FilterModels(models []ModelOption, query string) []IndexedModel

FilterModels returns indexed models matching the query, preserving their 1-based global indices from the full list.

func IndexModels

func IndexModels(models []ModelOption) []IndexedModel

IndexModels wraps a full model list with sequential 1-based indices.

type ModelListFunc

type ModelListFunc func() []ModelOption

ModelListFunc returns the current list of available models. Called on demand so callers always see the latest cached models.

type ModelOption

type ModelOption struct {
	Provider string
	Model    string
}

ModelOption represents a selectable provider/model combination.

type ModelSwitchFunc

type ModelSwitchFunc func(provider, model string) error

ModelSwitchFunc switches the active model in the pool. It rebuilds the runner factory for the given provider/model pair.

type Notification

type Notification struct {
	Channel string // optional: route to a specific backend ("telegram", "slack")
	ChatID  string // target chat/channel within the backend
	Text    string // markdown content
	Silent  bool   // send without notification sound
}

Notification represents a message to push to a user or channel.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, n Notification) error
}

Notifier can push notifications. Both Dispatcher and individual channels satisfy this interface, so consumers don't need to know the routing layer.

type NotifyTool

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

NotifyTool is an agent tool that sends notifications via a Dispatcher.

func NewNotifyTool

func NewNotifyTool(dispatcher *Dispatcher) *NotifyTool

NewNotifyTool creates a notify tool backed by the given dispatcher.

func (*NotifyTool) Definition

func (t *NotifyTool) Definition() toolspec.Definition

func (*NotifyTool) Execute

func (t *NotifyTool) Execute(ctx context.Context, args map[string]any) (string, error)

type ResolvedChat added in v0.8.0

type ResolvedChat struct {
	Pool       *agent.Pool
	User       config.User
	AgentID    string
	SessionKey string
	ChatCtx    ChatContext
}

ResolvedChat holds the fully resolved state for a chat message: the target pool, authenticated user, agent, and session key. Created once per incoming message via Resolve, then threaded through all handler and command paths.

func Resolve added in v0.8.0

func Resolve(ctx context.Context, pm *agent.PoolManager, store config.Store, platform, senderID, senderName, chatID string, isGroup bool) (*ResolvedChat, error)

Resolve performs the full user -> agent -> pool -> session key resolution. Call once per incoming message, then pass the result to all handlers.

func (*ResolvedChat) Chat added in v0.8.0

func (rc *ResolvedChat) Chat(ctx context.Context, message runner.MessageContent, opts ...agent.ChatOption) (<-chan runner.Event, string, error)

Chat resolves the session and streams an agent response. Returns the event channel and session ID.

func (*ResolvedChat) CompactSession added in v0.8.0

func (rc *ResolvedChat) CompactSession(ctx context.Context) (string, error)

CompactSession compacts the active session for this chat.

func (*ResolvedChat) ResolveSession added in v0.8.0

func (rc *ResolvedChat) ResolveSession() (agent.SessionInfo, error)

ResolveSession returns the active session for this chat, creating one if needed.

func (*ResolvedChat) RotateSession added in v0.8.0

func (rc *ResolvedChat) RotateSession() (agent.SessionInfo, error)

RotateSession archives the current session and creates a new one.

func (*ResolvedChat) UserID added in v0.8.0

func (rc *ResolvedChat) UserID() int64

UserID is a convenience accessor for rc.User.ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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