Documentation
¶
Index ¶
- Variables
- func ResolveAgentUsernames(resolver UsernameResolver, usernames []string) (resolved map[string]string, unresolved []string)
- func ResolveBridgeFallbacks(services []llm.ServiceConfig, primary llm.ServiceConfig) ([]llm.ServiceConfig, error)
- func ServiceCanServeCompletions(svc llm.ServiceConfig) bool
- func TeamMemberActive(client *pluginapi.Client, teamID, userID string) (bool, error)
- func UsageRestrictionsForUserConfig(client *pluginapi.Client, cfg llm.BotConfig, requestingUserID string) error
- type AgentStore
- type Bot
- func (b *Bot) BotUserID() string
- func (b *Bot) CanAttachSandboxFiles() bool
- func (b *Bot) GetConfig() llm.BotConfig
- func (b *Bot) GetMMBot() *model.Bot
- func (b *Bot) GetService() llm.ServiceConfig
- func (b *Bot) HasNativeCodeExecutionEnabled() bool
- func (b *Bot) HasNativeWebSearchEnabled() bool
- func (b *Bot) LLM() llm.LanguageModel
- func (b *Bot) ProviderServices() *llm.ProviderServices
- func (b *Bot) SetLLMForTest(llm llm.LanguageModel)
- func (b *Bot) SetProviderServicesForTest(services *llm.ProviderServices)
- func (b *Bot) SetServiceForTest(service llm.ServiceConfig)
- func (b *Bot) ShouldPromiseSandboxFiles() bool
- func (b *Bot) WithConfig(cfg llm.BotConfig) *Bot
- type Config
- type MMBots
- func (b *MMBots) AcquireServiceLLM(svc llm.ServiceConfig, fallbacks []llm.ServiceConfig) (llm.LanguageModel, func(), error)
- func (b *MMBots) CheckUsageRestrictions(ctx context.Context, requestingUserID string, bot *Bot, channel *model.Channel) error
- func (b *MMBots) CheckUsageRestrictionsForChannel(bot *Bot, channel *model.Channel) error
- func (b *MMBots) CheckUsageRestrictionsForUser(ctx context.Context, bot *Bot, requestingUserID string) error
- func (b *MMBots) CheckUsageRestrictionsForUserConfig(ctx context.Context, cfg llm.BotConfig, requestingUserID string) error
- func (b *MMBots) EnsureBots() error
- func (b *MMBots) ForceRefreshOnNextEnsure()
- func (b *MMBots) GetAllBotUserIDs() []string
- func (b *MMBots) GetAllBots() []*Bot
- func (b *MMBots) GetBotByID(botID string) *Bot
- func (b *MMBots) GetBotByIDOrUsername(botUserID, legacyUsername string) *Bot
- func (b *MMBots) GetBotByUsername(botUsername string) *Bot
- func (b *MMBots) GetBotByUsernameOrFirst(botUsername string) *Bot
- func (b *MMBots) GetBotConfigByID(botID string) (bool, int64, bool)
- func (b *MMBots) GetBotForDMChannel(channel *model.Channel) *Bot
- func (b *MMBots) GetBotMentioned(text string) *Bot
- func (b *MMBots) GetTranscribe() Transcriber
- func (b *MMBots) IsAnyBot(userID string) bool
- func (b *MMBots) ReconcileServiceLLMs(services []llm.ServiceConfig)
- func (b *MMBots) RefreshAgent(agentID string) error
- func (b *MMBots) SetBaseLLMBuilderForTest(...)
- func (b *MMBots) SetBotsForTesting(bots []*Bot)
- func (b *MMBots) ShutdownServiceLLMs()
- type Transcriber
- type UsernameResolver
Constants ¶
This section is empty.
Variables ¶
var ErrUsageRestriction = errors.New("usage restriction")
Functions ¶
func ResolveAgentUsernames ¶ added in v2.11.0
func ResolveAgentUsernames(resolver UsernameResolver, usernames []string) (resolved map[string]string, unresolved []string)
ResolveAgentUsernames maps each legacy username reference to the bot user ID of the agent whose account currently holds it, and returns the usernames no agent holds. It reads bot accounts through the Mattermost API, so callers must not hold a database transaction open around it.
func ResolveBridgeFallbacks ¶ added in v2.8.0
func ResolveBridgeFallbacks(services []llm.ServiceConfig, primary llm.ServiceConfig) ([]llm.ServiceConfig, error)
ResolveBridgeFallbacks resolves the complete fallback chain of primary from the given service snapshot, and verifies that every fallback is itself able to serve a completion. It is kept separate from ServiceCanServeCompletions so a broken chain surfaces as a descriptive error instead of silently making the primary ineligible. llm.ResolveFallbackChain already rejects a member that fails llm.IsValidService, so the checks below only have to cover what ServiceCanServeCompletions adds on top of it.
primary is expected to come from services, so the whole chain resolves from one consistent view. Duplicate service IDs in the snapshot resolve to the first entry, matching how the configuration itself is read.
func ServiceCanServeCompletions ¶ added in v2.8.0
func ServiceCanServeCompletions(svc llm.ServiceConfig) bool
ServiceCanServeCompletions reports whether completions can be run against this service directly, without an agent in front of it.
The service path has no agent to supply a model override, so a service without a default model cannot serve a completion at all. `scale` passes llm.IsValidService but has no Bifrost provider mapping, so it is excluded here even though it remains a valid stored configuration.
func TeamMemberActive ¶ added in v2.10.0
TeamMemberActive reports whether userID has a non-deleted membership in teamID. A missing membership is reported as false rather than an error.
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. This is the shared source of truth for user-scope access checks. 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 ¶
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
- providerServices: resolved from the concrete client before wrapping (see llm.ProviderServices)
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 has no provider services. Use EnsureBots for a wired bot, or WithConfig to derive one.
func (*Bot) BotUserID ¶ added in v2.7.0
BotUserID returns the Mattermost user ID of the bot's user account, or "" when no bot user exists.
func (*Bot) CanAttachSandboxFiles ¶ added in v2.11.0
CanAttachSandboxFiles gates the attach path: the sandbox is enabled and some service in the fallback chain can serve its files. The attach path takes whatever files the hop that served the turn produced.
func (*Bot) GetService ¶
func (b *Bot) GetService() llm.ServiceConfig
func (*Bot) HasNativeCodeExecutionEnabled ¶ added in v2.7.0
HasNativeCodeExecutionEnabled is independent of file retrieval. OpenAI can run the sandbox but cannot serve its files; use CanAttachSandboxFiles and ShouldPromiseSandboxFiles for attach and prompt gating.
func (*Bot) HasNativeWebSearchEnabled ¶
HasNativeWebSearchEnabled is used to suppress Mattermost's built-in web search fallback.
func (*Bot) LLM ¶
func (b *Bot) LLM() llm.LanguageModel
func (*Bot) ProviderServices ¶ added in v2.7.0
func (b *Bot) ProviderServices() *llm.ProviderServices
ProviderServices is nil-safe; callers must tolerate nil (bots built outside EnsureBots).
func (*Bot) SetLLMForTest ¶
func (b *Bot) SetLLMForTest(llm llm.LanguageModel)
func (*Bot) SetProviderServicesForTest ¶ added in v2.7.0
func (b *Bot) SetProviderServicesForTest(services *llm.ProviderServices)
func (*Bot) SetServiceForTest ¶
func (b *Bot) SetServiceForTest(service llm.ServiceConfig)
func (*Bot) ShouldPromiseSandboxFiles ¶ added in v2.11.0
ShouldPromiseSandboxFiles gates the prompt text telling the model that sandbox output files are attached automatically. The prompt may only promise what the primary can deliver: the primary serves most turns, so a fallback that can serve files must not make every turn promise files that never arrive.
type Config ¶
type Config interface {
GetBots() []llm.BotConfig
GetServiceByID(id string) (llm.ServiceConfig, bool)
GetServices() []llm.ServiceConfig
GetDefaultBotName() string
EnableTokenUsageLogging() bool
EnableTokenUsageLogToPlugin() bool
EnableTokenUsageLogToFile() bool
GetTranscriptGenerator() string
GetTranscriptBotUserID() 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, accessChecker *accesscontrol.Checker, llmUpstreamHTTPClient *http.Client, metrics llm.MetricsObserver) *MMBots
New builds the bot registry. accessChecker must be non-nil; tests that want no-policies-anywhere pass accesscontrol.New with PassthroughClient.
func (*MMBots) AcquireServiceLLM ¶ added in v2.8.0
func (b *MMBots) AcquireServiceLLM(svc llm.ServiceConfig, fallbacks []llm.ServiceConfig) (llm.LanguageModel, func(), error)
AcquireServiceLLM returns a language model for direct (agent-less) calls against svc. The caller must invoke release when the request is done; the model may be shut down shortly afterwards if the configuration changed in the meantime.
func (*MMBots) CheckUsageRestrictions ¶
func (*MMBots) CheckUsageRestrictionsForChannel ¶ added in v2.6.0
CheckUsageRestrictionsForChannel returns nil when the bot's ChannelAccessLevel configuration allows use in the given channel, otherwise an error wrapping ErrUsageRestriction. Unlike CheckUsageRestrictions it does not consider user-scope restrictions, so callers can validate channel-level settings (e.g. auto-reply) independent of any requesting user.
func (*MMBots) CheckUsageRestrictionsForUser ¶
func (*MMBots) CheckUsageRestrictionsForUserConfig ¶
func (b *MMBots) CheckUsageRestrictionsForUserConfig(ctx context.Context, cfg llm.BotConfig, requestingUserID string) error
CheckUsageRestrictionsForUserConfig is the composite per-request user gate: ABAC agent decision (legacy UserAccessLevel as legacyCheck), then ABAC service for cfg.ServiceID. Denied fallback hops are dropped per request rather than hiding the agent; see allowedFallbackServiceIDs.
func (*MMBots) EnsureBots ¶
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 ¶
GetAllBotUserIDs returns a list of all bot user IDs
func (*MMBots) GetBotByID ¶
GetBotByID retrieves the bot associated with the given bot ID
func (*MMBots) GetBotByIDOrUsername ¶ added in v2.11.0
GetBotByIDOrUsername resolves a stored or requested agent reference: by its bot user ID when one is set, otherwise by the legacy username, which only selects the agent whose account currently holds it. A missing agent returns nil rather than another agent, which would run with that agent's model, instructions, tools, and identity.
func (*MMBots) GetBotByUsername ¶
GetBotByUsername retrieves the bot whose Mattermost account currently holds the given username. A name the registry does not know is resolved through the bot account that holds it, so an agent stays reachable under its new name while the registry still lists it under the old one after a rename.
func (*MMBots) GetBotByUsernameOrFirst ¶
GetBotByUsernameOrFirst retrieves the bot with the given username, or the first bot when no username is given. A named bot that is not available returns nil: serving another agent instead would run the request with that agent's model, instructions, tools, and identity.
func (*MMBots) GetBotConfigByID ¶
GetBotConfigByID returns the bot's EnableVision and MaxFileSize. ok is false when botID is unknown.
func (*MMBots) GetBotForDMChannel ¶
GetBotForDMChannel returns the bot for the given DM channel.
func (*MMBots) GetBotMentioned ¶
GetBotMentioned returns the bot mentioned in the text, if any. A bot is mentioned only under a username its Mattermost account currently holds.
func (*MMBots) GetTranscribe ¶
func (b *MMBots) GetTranscribe() Transcriber
TODO: This really doesn't belong here. Figure out where to put this.
func (*MMBots) ReconcileServiceLLMs ¶ added in v2.8.0
func (b *MMBots) ReconcileServiceLLMs(services []llm.ServiceConfig)
ReconcileServiceLLMs drops cached models whose service or fallback chain changed or disappeared. Entries still in use are retired and shut down once their last lease is released.
func (*MMBots) RefreshAgent ¶ added in v2.10.0
RefreshAgent rebuilds the registry entry of one DB-backed agent from the store and swaps in just that entry, so a renamed agent is listed under its new name and account without waiting for a full rebuild. When the agent cannot be rebuilt, or is no longer active, its entry is removed instead. Name-based lookups do not depend on it having run: they check the live account. It never creates bot accounts (EnsureBots does, under the cluster mutex), and it leaves the next EnsureBots to reconcile every other bot.
func (*MMBots) SetBaseLLMBuilderForTest ¶ added in v2.8.0
func (b *MMBots) SetBaseLLMBuilderForTest(builder func(svc llm.ServiceConfig, fallbacks []llm.ServiceConfig) (llm.LanguageModel, func(), error))
SetBaseLLMBuilderForTest installs a test-only provider client builder. The wrapper chain around it stays the production one.
func (*MMBots) SetBotsForTesting ¶
SetBotsForTesting sets bots directly for testing purposes only
func (*MMBots) ShutdownServiceLLMs ¶ added in v2.8.0
func (b *MMBots) ShutdownServiceLLMs()
ShutdownServiceLLMs shuts every provider client down, cached or retired, regardless of outstanding leases. Agents use these clients too. Called on plugin deactivation.
type Transcriber ¶
Transcriber interface defines the contract for transcription services
type UsernameResolver ¶ added in v2.11.0
UsernameResolver selects the agent whose account currently holds a username.