channel

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: AGPL-3.0 Imports: 20 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

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

func HandleAgentCommand

func HandleAgentCommand(ctx context.Context, ac *AgentCommander, rc *ResolvedChat, args string, reply func(string))

func HandleCommand

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

func IntentToCommand(intent Intent) string

func LoadConfig

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

func ResolveAgent

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

func TryLinkCode

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

func TryLinkCodeWithCandidates

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

Types

type AgentCommander

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

func NewAgentCommander

func NewAgentCommander(store config.Store, users auth.UserStore) *AgentCommander

func (*AgentCommander) List

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

func (*AgentCommander) ListForChat

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

func (*AgentCommander) Switch

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

type ChatContext

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

type Coordinator

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

func NewCoordinator

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

NewCoordinator creates a Coordinator that satisfies pkgchannel.Handler. pm must implement both agent.ServiceManager (for routing) and userInvalidator (for /config secret updates). *agent.PoolManager satisfies both.

func (*Coordinator) HandleIncoming

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

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

func (*Coordinator) ListModels

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

ListModels returns available models.

func (*Coordinator) ProvisionUser

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

ProvisionUser checks whether a channel identity exists for the sender. Returns an error if the identity is not found — the user must first log in via OIDC and link their channel account.

func (*Coordinator) ResolveUserRoot

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

ResolveUserRoot resolves the per-user writable root for the sender in msg. It performs the same user+agent resolution as HandleIncoming but stops before starting a session, so it is cheap and safe to call before file downloads.

func (*Coordinator) SwitchAgent

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

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

SwitchModel switches the active model.

type CoordinatorOption

type CoordinatorOption func(*Coordinator)

CoordinatorOption configures the Coordinator.

func WithCoordinatorAuth

func WithCoordinatorAuth(store channelAuthStore, engine *auth.PolicyEngine, linkCodes *auth.LinkCodeStore) CoordinatorOption

WithCoordinatorAuth configures the coordinator with auth support.

func WithIntentClassifier

func WithIntentClassifier(classifier IntentClassifier) CoordinatorOption

func WithVaultRecipient

func WithVaultRecipient(r *age.X25519Recipient) CoordinatorOption

WithVaultRecipient sets the master age recipient so channel-provisioned users get age keys at creation time.

func WithVaultService

func WithVaultService(svc *vault.Service) CoordinatorOption

WithVaultService configures the coordinator with vault secret management.

type IndexedAgent

type IndexedAgent struct {
	config.Agent
	GlobalIdx int
}

func IndexAgents

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

type Intent

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

type IntentClassifier

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

type LLMIntentClassifier

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

func NewLLMIntentClassifier

func NewLLMIntentClassifier(loadSnapshot SnapshotLoader, buildStream StreamFuncBuilder) *LLMIntentClassifier

func (*LLMIntentClassifier) Classify

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

type ResolvedChat

type ResolvedChat struct {
	Service    *agent.Service
	User       auth.User
	AgentID    string
	SessionKey string
	Channel    session.Channel
	ChatCtx    ChatContext
}

func Resolve

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

func ResolveWithChannel

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

func (*ResolvedChat) Chat

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

func (*ResolvedChat) CompactSession

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

func (*ResolvedChat) ResolveSession

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

func (*ResolvedChat) UserID

func (rc *ResolvedChat) UserID() string

type ResolvedIdentity

type ResolvedIdentity struct {
	User auth.User
}

func ResolveUser

func ResolveUser(ctx context.Context, store channelAuthStore, platform, externalID string) (ResolvedIdentity, error)

func ResolveUserCandidates

func ResolveUserCandidates(ctx context.Context, store channelAuthStore, platform string, externalIDs []string) (ResolvedIdentity, identityMatch, error)

type SnapshotLoader

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

type StreamFuncBuilder added in v0.28.0

type StreamFuncBuilder func(context.Context, string, config.ProviderCreds) (providers.StreamFunc, error)

Jump to

Keyboard shortcuts

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