Documentation
¶
Index ¶
- func FormatDuration(d time.Duration) string
- func ParseModelArgs(args string) string
- func SplitMessage(text string, maxLen int) []string
- type Channel
- type Commander
- func (c *Commander) Compact(ctx context.Context, channelID string) (string, error)
- func (c *Commander) ModelList(query string) []IndexedModel
- func (c *Commander) ModelSwitch(channelID string, idx int) (ModelOption, error)
- func (c *Commander) ModelSwitchByName(channelID, name string) (ModelOption, error)
- func (c *Commander) New(channelID string) (string, error)
- type Dispatcher
- type IndexedModel
- type ModelListFunc
- type ModelOption
- type ModelSwitchFunc
- type Notification
- type Notifier
- type NotifyTool
- type PoolAdapter
- type SessionInfo
- type SessionPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration formats a duration as a human-friendly string.
func ParseModelArgs ¶
ParseModelArgs parses /model arguments as a query string. Returns empty string when no arguments are provided.
func SplitMessage ¶
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 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 Commander ¶
type Commander struct {
// contains filtered or unexported fields
}
Commander handles shared slash commands across all channels. Each channel calls Commander methods and only handles presentation.
func NewCommander ¶
func NewCommander(pool SessionPool, listFn ModelListFunc, switchFn ModelSwitchFunc) *Commander
NewCommander creates a Commander backed by the given pool and model functions.
func (*Commander) ModelList ¶
func (c *Commander) ModelList(query string) []IndexedModel
ModelList returns all models, optionally filtered by query.
func (*Commander) ModelSwitch ¶
func (c *Commander) ModelSwitch(channelID string, idx int) (ModelOption, error)
ModelSwitch switches to the model at the given 1-based index and rotates the session. Returns the selected model. This is used internally by channels that select models via index (e.g. Telegram inline keyboards).
func (*Commander) ModelSwitchByName ¶
func (c *Commander) ModelSwitchByName(channelID, name string) (ModelOption, error)
ModelSwitchByName switches to the model matching "provider/model" and rotates the session. Returns the selected model.
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 ¶
ModelOption represents a selectable provider/model combination.
type ModelSwitchFunc ¶
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
type PoolAdapter ¶
type PoolAdapter[T any] struct { ResolveFunc func(channel string) (T, error) RotateFunc func(channel string) (T, error) CompactFunc func(ctx context.Context, sessionID string) (string, error) AdaptFn func(T) SessionInfo }
PoolAdapter adapts a concrete pool (e.g. *agent.Pool) whose session methods return a richer SessionInfo type into the channel.SessionPool interface. The adaptFn extracts the ID from the concrete type.
func (*PoolAdapter[T]) CompactSession ¶
func (*PoolAdapter[T]) ResolveSession ¶
func (a *PoolAdapter[T]) ResolveSession(ch string) (SessionInfo, error)
func (*PoolAdapter[T]) RotateSession ¶
func (a *PoolAdapter[T]) RotateSession(ch string) (SessionInfo, error)
type SessionInfo ¶
type SessionInfo struct {
ID string
}
SessionInfo holds the minimal session metadata needed by channels.
type SessionPool ¶
type SessionPool interface {
ResolveSession(channel string) (SessionInfo, error)
RotateSession(channel string) (SessionInfo, error)
CompactSession(ctx context.Context, sessionID string) (string, error)
}
SessionPool is the session management interface used by Commander. Implementations must return a struct whose ID field identifies the session.