channel

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAgentAccessDenied = errors.New("you don't have access to this agent, contact an admin")
View Source
var ParseCommandArgs = pkgchannel.ParseCommandArgs

Functions

func FormatAgentList added in v0.8.0

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

func HandleAgentCommand added in v0.9.0

func HandleAgentCommand(ctx context.Context, ac *AgentCommander, rc *ResolvedChat, args string, reply func(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. /model and /agent are left to each channel because they need platform-specific UI.

func IntentToCommand added in v0.11.1

func IntentToCommand(intent Intent) string

func LoadConfig added in v0.9.0

func LoadConfig[T any](store config.Store, channelID string) *T

func ResolveAgent added in v0.8.0

func ResolveAgent(ctx context.Context, store config.Store, authStore auth.AuthStore, engine *auth.PolicyEngine, identity ResolvedIdentity, chat ChatContext) (string, error)

func TryLinkCode added in v0.9.0

func TryLinkCode(ctx context.Context, authStore auth.AuthStore, linkCodes *auth.LinkCodeStore, text, platform, senderID, senderName string) (string, bool)

func TryLinkCodeWithCandidates added in v0.10.0

func TryLinkCodeWithCandidates(ctx context.Context, authStore auth.AuthStore, linkCodes *auth.LinkCodeStore, text, platform, senderID string, senderIDs []string, senderName string) (string, bool)

Types

type AgentCommander added in v0.8.0

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

func NewAgentCommander added in v0.8.0

func NewAgentCommander(store config.Store, authStore auth.AuthStore) *AgentCommander

func (*AgentCommander) List added in v0.8.0

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

func (*AgentCommander) ListForChat added in v0.10.0

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

func (*AgentCommander) Switch added in v0.8.0

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

type ChatContext added in v0.8.0

type ChatContext struct {
	Platform  string
	ChannelID string
	ChatID    string
	IsGroup   bool
}

type Coordinator added in v0.9.0

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

Coordinator implements pkgchannel.Handler. It owns all business logic that channels previously called directly: user/agent resolution, session management, command handling, account linking, and model/agent switching. A per-session message queue ensures that only one chat turn runs at a time per resolved Anna session; later messages are serialised in arrival order.

func NewCoordinator added in v0.9.0

func NewCoordinator(
	pm *agent.PoolManager,
	store config.Store,
	listFn func() []pkgchannel.ModelOption,
	switchFn func(provider, model string) error,
	opts ...CoordinatorOption,
) *Coordinator

NewCoordinator creates a Coordinator that satisfies pkgchannel.Handler.

func (*Coordinator) HandleIncoming added in v0.9.0

func (c *Coordinator) HandleIncoming(ctx context.Context, msg pkgchannel.IncomingMessage, command, args string) (string, bool, *pkgchannel.ChatStream, error)

HandleIncoming resolves the user once, tries command handling, and if the command is not handled, streams a chat response. This avoids double resolution when a plugin needs to try commands before messaging.

func (*Coordinator) ListAgents added in v0.9.0

ListAgents returns enabled agents the user can access and the current agent ID.

func (*Coordinator) ListModels added in v0.9.0

func (c *Coordinator) ListModels() []pkgchannel.ModelOption

ListModels returns available models.

func (*Coordinator) ProvisionUser added in v0.14.0

func (c *Coordinator) ProvisionUser(ctx context.Context, req pkgchannel.ProvisionRequest) error

ProvisionUser creates or returns an existing user+identity for the given channel sender. Returns an error if auth is not configured or the user count is zero (no admin exists yet — provisioning is refused until the first admin registers to avoid stranding a deployment with zero admins).

func (*Coordinator) SwitchAgent added in v0.9.0

func (c *Coordinator) SwitchAgent(ctx context.Context, msg pkgchannel.IncomingMessage, agentSlug string) error

SwitchAgent switches the active agent for the chat context.

func (*Coordinator) SwitchModel added in v0.9.0

func (c *Coordinator) SwitchModel(provider, model string) error

SwitchModel switches the active model.

type CoordinatorOption added in v0.9.0

type CoordinatorOption func(*Coordinator)

CoordinatorOption configures the Coordinator.

func WithCoordinatorAuth added in v0.9.0

func WithCoordinatorAuth(authStore auth.AuthStore, engine *auth.PolicyEngine, linkCodes *auth.LinkCodeStore) CoordinatorOption

WithCoordinatorAuth configures the coordinator with auth support.

func WithIntentClassifier added in v0.11.1

func WithIntentClassifier(classifier IntentClassifier) CoordinatorOption

func WithVaultRecipient added in v0.15.0

func WithVaultRecipient(r *age.X25519Recipient) CoordinatorOption

WithVaultRecipient sets the master age recipient so channel-provisioned users get age keys immediately instead of waiting for the startup backfill.

func WithVaultService added in v0.15.0

func WithVaultService(svc *vault.Service) CoordinatorOption

WithVaultService configures the coordinator with vault secret management.

type IndexedAgent added in v0.9.0

type IndexedAgent struct {
	config.Agent
	GlobalIdx int
}

func IndexAgents added in v0.9.0

func IndexAgents(agents []config.Agent) []IndexedAgent

type Intent added in v0.11.1

type Intent string
const (
	IntentHelp    Intent = "help"
	IntentNew     Intent = "new"
	IntentAbort   Intent = "abort"
	IntentCompact Intent = "compact"
	IntentNone    Intent = "none"
)

type IntentClassifier added in v0.11.1

type IntentClassifier interface {
	Classify(ctx context.Context, agentID string, content []ai.ContentBlock) Intent
}

type LLMIntentClassifier added in v0.11.1

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

func NewLLMIntentClassifier added in v0.11.1

func NewLLMIntentClassifier(loadSnapshot SnapshotLoader, buildGetter ProviderGetterBuilder) *LLMIntentClassifier

func (*LLMIntentClassifier) Classify added in v0.11.1

func (c *LLMIntentClassifier) Classify(ctx context.Context, agentID string, content []ai.ContentBlock) Intent

type ProviderGetterBuilder added in v0.11.1

type ProviderGetterBuilder func(context.Context, string, config.ProviderCreds) (providers.ProviderGetter, error)

type ResolvedChat added in v0.8.0

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

func Resolve added in v0.8.0

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

func ResolveWithChannel added in v0.10.0

func ResolveWithChannel(ctx context.Context, pm *agent.PoolManager, store config.Store, authStore auth.AuthStore, engine *auth.PolicyEngine, platform, channelID, senderID string, senderIDs []string, senderName, chatID string, isGroup bool) (*ResolvedChat, error)

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)

func (*ResolvedChat) CompactSession added in v0.8.0

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

func (*ResolvedChat) ResolveSession added in v0.8.0

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

func (*ResolvedChat) RotateSession added in v0.8.0

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

func (*ResolvedChat) UserID added in v0.8.0

func (rc *ResolvedChat) UserID() int64

type ResolvedIdentity added in v0.9.0

type ResolvedIdentity struct {
	User auth.AuthUser
}

func ResolveUser added in v0.8.0

func ResolveUser(ctx context.Context, authStore auth.AuthStore, platform, externalID string) (ResolvedIdentity, error)

func ResolveUserCandidates added in v0.10.0

func ResolveUserCandidates(ctx context.Context, authStore auth.AuthStore, platform string, externalIDs []string) (ResolvedIdentity, identityMatch, error)

type SnapshotLoader added in v0.11.1

type SnapshotLoader func(context.Context, string) (*config.Snapshot, error)

Jump to

Keyboard shortcuts

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