Documentation
¶
Index ¶
- Constants
- Variables
- type ConfigProvider
- type Conversations
- func (c *Conversations) CreateOrGetDMConversation(botID string, postingUser *model.User, channel *model.Channel, ...) (*DMConversationResult, error)
- func (c *Conversations) DeleteConversationsForDeletedPost(post *model.Post) error
- func (c *Conversations) HandleLoopInAgent(ctx context.Context, userID string, bot *bots.Bot, post *model.Post, ...) error
- func (c *Conversations) HandleRegenerate(ctx stdcontext.Context, userID string, post *model.Post, ...) error
- func (c *Conversations) HandleToolCall(ctx context.Context, userID string, post *model.Post, channel *model.Channel, ...) error
- func (c *Conversations) HandleToolResult(ctx context.Context, userID string, post *model.Post, channel *model.Channel, ...) error
- func (c *Conversations) MessageHasBeenPosted(_ *plugin.Context, post *model.Post)
- func (c *Conversations) ProcessDMRequest(ctx stdcontext.Context, convID string, lm llm.LanguageModel, ...) (*DMStreamResult, error)
- func (c *Conversations) SaveTitle(threadID, title string) error
- func (c *Conversations) SaveTitleAsync(threadID, title string)
- func (c *Conversations) SetConversationService(svc *conversation.Service)
- func (c *Conversations) SetMeetingsService(meetingsService MeetingsService)
- func (c *Conversations) SetToolPolicyChecker(checker mcp.ToolPolicyChecker)
- type DMConversationResult
- type DMStreamResult
- type MeetingsService
Constants ¶
const ( AgentMentionReminderBotUserIDProp = "bot_user_id" AgentMentionReminderBotUsernameProp = "bot_username" AgentMentionReminderBotDisplayNameProp = "bot_display_name" AgentMentionReminderTargetPostIDProp = "target_post_id" )
Prop keys carried on the custom post for the webapp to read when rendering.
const ( ActivateAIProp = "activate_ai" FromWebhookProp = "from_webhook" FromBotProp = "from_bot" FromPluginProp = "from_plugin" FromOAuthAppProp = "from_oauth_app" WranglerProp = "wrangler" )
const ( ReferencedRecordingFileID = "referenced_recording_file_id" ReferencedTranscriptPostID = "referenced_transcript_post_id" )
const AgentMentionReminderPostType = "custom_agent_mention_reminder"
AgentMentionReminderPostType is the custom post type used for the ephemeral "you must @mention an agent" reminder rendered by the webapp.
const AnalysisTypeProp = "prompt_type"
const ThreadIDProp = "referenced_thread"
Variables ¶
var ( ErrLoopInNotPostOwner = errors.New("only the post author can loop in an agent") ErrLoopInNotThreadReply = errors.New("loop in is only available for thread replies") ErrLoopInUnsupportedChannel = errors.New("loop in is not available in direct or group messages") ErrLoopInAlreadyMentioned = errors.New("post already mentions an agent") ErrLoopInWrongAgent = errors.New("previous post in thread was not authored by the requested agent") ErrLoopInNoAgentContext = errors.New("no agent context for this thread reply") )
var ErrInvalidToolAnswer = errors.New("invalid answer for user interaction tool call")
ErrInvalidToolAnswer is returned when an accepted user-interaction tool call (e.g. AskUserQuestion) arrives without a valid answer. The pending state is left untouched so the user can answer again. The HTTP layer maps this to 400 Bad Request.
var ( // ErrNoResponse is returned when no response is posted under a normal condition. ErrNoResponse = errors.New("no response") )
var ErrNotRequester = errors.New("only the original requester can approve/reject tool calls")
ErrNotRequester is returned when a user other than the original conversation requester attempts to approve or reject tool calls/results. The HTTP layer maps this to 403 Forbidden.
var ErrPostMissingConversationID = errors.New("post missing conversation_id")
ErrPostMissingConversationID is returned when a tool-approval request arrives for a post that has no conversation_id prop. The HTTP layer maps this to 400 Bad Request.
var ErrRemoteMCPNotLicensed = errors.New("tools from remote MCP servers require a license with MCP support")
ErrRemoteMCPNotLicensed is returned when a tool decision would execute, or share the output of, a tool served by a remote/external MCP server on a server whose license does not include MCP support. Built-in tools (empty ServerOrigin) and embedded Mattermost MCP tools (mcp.EmbeddedClientKey) are basic tool integrations and never require a license. The HTTP layer maps this to 403 Forbidden.
This gate is the decision-time backstop for pending remote tool calls persisted before a license change; the primary enforcement is at supply time, where llmcontext.Builder drops remote MCP tools from the LLM context entirely on unlicensed servers.
var ErrStaleToolClick = errors.New("stale or duplicate tool-approval click")
ErrStaleToolClick is returned when a tool-approval click cannot be resolved because the pending tool state no longer matches the request. Typical causes: another browser tab already approved/rejected, the post is not an approval post, or the approval has expired. The HTTP layer maps this to 400 Bad Request rather than 500 Internal Server Error.
Functions ¶
This section is empty.
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
EnableChannelMentionToolCalling() bool
AllowNativeWebSearchInChannels() bool
MCP() mcp.Config
}
ConfigProvider provides configuration values for conversation behavior
type Conversations ¶
type Conversations struct {
// contains filtered or unexported fields
}
func New ¶
func New( prompts *llm.Prompts, mmClient mmapi.Client, streamingService streaming.Service, contextBuilder *llmcontext.Builder, botsService *bots.MMBots, db *mmapi.DBClient, licenseChecker *enterprise.LicenseChecker, i18nBundle *i18n.Bundle, meetingsService MeetingsService, configProvider ConfigProvider, ) *Conversations
func (*Conversations) CreateOrGetDMConversation ¶
func (c *Conversations) CreateOrGetDMConversation( botID string, postingUser *model.User, channel *model.Channel, post *model.Post, llmCtx *llm.Context, ) (*DMConversationResult, error)
CreateOrGetDMConversation creates or retrieves a conversation for a DM. This is separated from ProcessDMRequest so the conversation_id can be set on the response post before it is created.
func (*Conversations) DeleteConversationsForDeletedPost ¶
func (c *Conversations) DeleteConversationsForDeletedPost(post *model.Post) error
DeleteConversationsForDeletedPost soft-deletes conversations associated with the given post. If the post is a root post, conversations keyed by that RootPostID are marked as deleted.
func (*Conversations) HandleLoopInAgent ¶
func (c *Conversations) HandleLoopInAgent(ctx context.Context, userID string, bot *bots.Bot, post *model.Post, channel *model.Channel) error
HandleLoopInAgent processes the user's thread reply through the conversation flow when they click "loop in" on the agent mention reminder.
func (*Conversations) HandleRegenerate ¶
func (c *Conversations) HandleRegenerate(ctx stdcontext.Context, userID string, post *model.Post, channel *model.Channel) error
HandleRegenerate handles post regeneration requests
func (*Conversations) HandleToolCall ¶
func (c *Conversations) HandleToolCall(ctx context.Context, userID string, post *model.Post, channel *model.Channel, acceptedToolIDs []string, toolAnswers map[string]mmtools.UserInteractionAnswer) error
HandleToolCall handles user approval/rejection of pending tool calls via conversation entities. It looks up pending tool_use blocks in the conversation turns, executes approved tools, writes results back as turns, and streams a follow-up LLM response.
toolAnswers carries the user's answers for accepted user-interaction tool calls (e.g. AskUserQuestion), keyed by tool_use block ID. Those blocks are not executed; the validated answer becomes the tool result.
func (*Conversations) HandleToolResult ¶
func (c *Conversations) HandleToolResult(ctx context.Context, userID string, post *model.Post, channel *model.Channel, acceptedToolIDs []string) error
HandleToolResult handles user approval of the second-stage tool-result sharing. It flips shared flags for accepted results and, in channels, streams the LLM follow-up with unshared content redacted so private tool output cannot leak into the channel-visible reply.
func (*Conversations) MessageHasBeenPosted ¶
func (c *Conversations) MessageHasBeenPosted(_ *plugin.Context, post *model.Post)
func (*Conversations) ProcessDMRequest ¶
func (c *Conversations) ProcessDMRequest( ctx stdcontext.Context, convID string, lm llm.LanguageModel, llmCtx *llm.Context, maxToolTurns int, ) (*DMStreamResult, error)
ProcessDMRequest builds a completion request from the conversation and runs the tool loop, returning the final stream. The conversation must already exist (created via CreateOrGetDMConversation).
maxToolTurns bounds the tool-call-execute-recall loop for this bot; pass 0 or any non-positive value to use the system default (llm.DefaultMaxToolTurns).
func (*Conversations) SaveTitle ¶
func (c *Conversations) SaveTitle(threadID, title string) error
SaveTitle saves a title for a conversation identified by its root post ID. It looks up the conversation by RootPostID and updates the title via the LLM_Conversations table.
func (*Conversations) SaveTitleAsync ¶
func (c *Conversations) SaveTitleAsync(threadID, title string)
SaveTitleAsync saves a title asynchronously
func (*Conversations) SetConversationService ¶
func (c *Conversations) SetConversationService(svc *conversation.Service)
SetConversationService sets the conversation entity service.
func (*Conversations) SetMeetingsService ¶
func (c *Conversations) SetMeetingsService(meetingsService MeetingsService)
SetMeetingsService sets the meetings service (used to break circular dependency during initialization)
func (*Conversations) SetToolPolicyChecker ¶
func (c *Conversations) SetToolPolicyChecker(checker mcp.ToolPolicyChecker)
SetToolPolicyChecker sets the per-tool policy checker used for auto-approval and DM auto-run decisions.
type DMConversationResult ¶
DMConversationResult is the return value of CreateOrGetDMConversation.
type DMStreamResult ¶
type DMStreamResult struct {
Stream *llm.TextStreamResult
}
DMStreamResult is the return value of ProcessDMRequest.
type MeetingsService ¶
type MeetingsService interface {
GetCaptionsFileIDFromProps(post *model.Post) (fileID string, err error)
SummarizeTranscription(ctx stdcontext.Context, bot *bots.Bot, transcription *subtitles.Subtitles, context *llm.Context) (*llm.TextStreamResult, error)
}
MeetingsService defines the interface for meetings functionality needed by conversations