bots

package
v0.0.1-rc99 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUsageRestriction = errors.New("usage restriction")

Functions

func UsageRestrictionsForUserConfig

func UsageRestrictionsForUserConfig(client *pluginapi.Client, cfg llm.BotConfig, requestingUserID string) error

UsageRestrictionsForUserConfig returns nil if userID is allowed by cfg's UserAccessLevel / UserIDs / TeamIDs, otherwise an error wrapping ErrUsageRestriction. Callers without an MMBots instance (e.g. API code when bots may be nil) should use this with the plugin client; MMBots.CheckUsageRestrictionsForUserConfig delegates here.

Types

type AgentStore

type AgentStore interface {
	ListAgents() ([]*llm.BotConfig, error)
}

AgentStore provides read access to user-created agents from the database. This is a subset of the full store.AgentStore — only read methods needed here.

type Bot

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

Bot represents an AI bot instance with its configuration and dependencies.

Source of truth for bot fields:

  • cfg: The bot's configuration (name, display name, permissions, etc.)
  • service: The RESOLVED service configuration (use GetService() to access). DO NOT use cfg.Service or cfg.ServiceID directly - those are internal references.
  • mmBot: The Mattermost bot user
  • llm: The initialized language model instance

Bot instances should be created via EnsureBots() which properly resolves service references and initializes all fields.

func NewBot

func NewBot(cfg llm.BotConfig, service llm.ServiceConfig, mmBot *model.Bot, llmInstance llm.LanguageModel) *Bot

NewBot creates a new Bot instance with all fields initialized.

func (*Bot) GetConfig

func (b *Bot) GetConfig() llm.BotConfig

func (*Bot) GetMMBot

func (b *Bot) GetMMBot() *model.Bot

func (*Bot) GetService

func (b *Bot) GetService() llm.ServiceConfig

func (*Bot) HasNativeWebSearchEnabled

func (b *Bot) HasNativeWebSearchEnabled() bool

HasNativeWebSearchEnabled reports whether the bot is configured to use the provider's native web search AND the resolved service type actually supports native tools through Bifrost. Callers use this to decide whether to suppress Mattermost's built-in web search fallback, so we must consider the effective provider capability rather than trusting the persisted bot config alone.

func (*Bot) LLM

func (b *Bot) LLM() llm.LanguageModel

func (*Bot) SetLLMForTest

func (b *Bot) SetLLMForTest(llm llm.LanguageModel)

func (*Bot) SetServiceForTest

func (b *Bot) SetServiceForTest(service llm.ServiceConfig)

type Config

type Config interface {
	GetBots() []llm.BotConfig
	GetServiceByID(id string) (llm.ServiceConfig, bool)
	GetDefaultBotName() string
	EnableTokenUsageLogging() bool
	EnableTokenUsageLogToPlugin() bool
	EnableTokenUsageLogToFile() bool
	GetTranscriptGenerator() string
}

type MMBots

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

func New

func New(mutexPluginAPI cluster.MutexPluginAPI, pluginAPI *pluginapi.Client, licenseChecker *enterprise.LicenseChecker, config Config, agentStore AgentStore, llmUpstreamHTTPClient *http.Client, metrics llm.MetricsObserver) *MMBots

func (*MMBots) CheckUsageRestrictions

func (m *MMBots) CheckUsageRestrictions(requestingUserID string, bot *Bot, channel *model.Channel) error

func (*MMBots) CheckUsageRestrictionsForUser

func (m *MMBots) CheckUsageRestrictionsForUser(bot *Bot, requestingUserID string) error

func (*MMBots) CheckUsageRestrictionsForUserConfig

func (m *MMBots) CheckUsageRestrictionsForUserConfig(cfg llm.BotConfig, requestingUserID string) error

CheckUsageRestrictionsForUserConfig returns nil if userID is allowed by cfg's UserAccessLevel / UserIDs / TeamIDs, otherwise an error wrapping ErrUsageRestriction. This is the shared source of truth for user-scope access checks; both config-bot Bot-based callers (CheckUsageRestrictionsForUser) and DB-agent BotConfig-based callers (api.canUserAccessAgent) use it.

func (*MMBots) EnsureBots

func (b *MMBots) EnsureBots() error

func (*MMBots) ForceRefreshOnNextEnsure

func (b *MMBots) ForceRefreshOnNextEnsure()

ForceRefreshOnNextEnsure clears the optimistic ensure snapshot and sets forceRefresh so the next EnsureBots() cannot take the fast path. DB-backed agents are not part of the config-file bot slice used for botConfigsEqual, so we must invalidate when agents change.

func (*MMBots) GetAllBotUserIDs

func (b *MMBots) GetAllBotUserIDs() []string

GetAllBotUserIDs returns a list of all bot user IDs

func (*MMBots) GetAllBots

func (b *MMBots) GetAllBots() []*Bot

GetAllBots returns all bots

func (*MMBots) GetBotByID

func (b *MMBots) GetBotByID(botID string) *Bot

GetBotByID retrieves the bot associated with the given bot ID

func (*MMBots) GetBotByUsername

func (b *MMBots) GetBotByUsername(botUsername string) *Bot

GetBotByUsername retrieves the bot associated with the given bot username

func (*MMBots) GetBotByUsernameOrFirst

func (b *MMBots) GetBotByUsernameOrFirst(botUsername string) *Bot

GetBotByUsernameOrFirst retrieves the bot associated with the given bot username or the first bot if not found

func (*MMBots) GetBotConfig

func (b *MMBots) GetBotConfig(botUsername string) (llm.BotConfig, error)

func (*MMBots) GetBotConfigByID

func (b *MMBots) GetBotConfigByID(botID string) (bool, int64, bool)

GetBotConfigByID returns the bot's EnableVision and MaxFileSize. ok is false when botID is unknown.

func (*MMBots) GetBotForDMChannel

func (b *MMBots) GetBotForDMChannel(channel *model.Channel) *Bot

GetBotForDMChannel returns the bot for the given DM channel.

func (*MMBots) GetBotMentioned

func (b *MMBots) GetBotMentioned(text string) *Bot

GetBotMentioned returns the bot mentioned in the text, if any.

func (*MMBots) GetTranscribe

func (b *MMBots) GetTranscribe() Transcriber

TODO: This really doesn't belong here. Figure out where to put this.

func (*MMBots) IsAnyBot

func (b *MMBots) IsAnyBot(userID string) bool

IsAnyBot returns true if the given user is an AI bot.

func (*MMBots) SetBotsForTesting

func (b *MMBots) SetBotsForTesting(bots []*Bot)

SetBotsForTesting sets bots directly for testing purposes only

type Transcriber

type Transcriber interface {
	Transcribe(file io.Reader) (*subtitles.Subtitles, error)
}

Transcriber interface defines the contract for transcription services

Jump to

Keyboard shortcuts

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