This site setting name is misleading (cc @falco/@roman) it should be ai_bot_add_ai_pm_to_header
AI bot research here:
Look up site setting context
Reading context for: ai_helper_add_ai_pm_to_header
The
ai_helper_add_ai_pm_to_headeris a site setting in the Discourse AI plugin. When enabled, it displays a button in the header of the Discourse forum that allows users to start a private message (PM) with an AI Bot.Here’s a detailed breakdown of how it works:
The setting is defined in the
settings.ymlfile of the Discourse AI plugin with a default value oftrue. This means that, by default, the button to start a PM with the AI Bot is displayed in the header.The setting is used in the
ai-bot-replies.jsfile. This JavaScript file contains the logic for interacting with the AI Bot.The
attachHeaderIconfunction checks if theai_helper_add_ai_pm_to_headersetting is enabled. If it is, it retrieves the list of enabled AI Bots from theai_bot_enabled_chat_botssetting. This setting contains a list of AI Bots that are enabled for chat, separated by a pipe (|).If there are any enabled AI Bots, the
attachHeaderIconfunction attaches two widget actions to the header:showAiBotPanelandhideAiBotPanel. These actions control the visibility of the AI Bot panel.The
showAiBotPanelaction sets thebotSelectorVisiblestate totrue, which shows the AI Bot panel.The
hideAiBotPanelaction sets thebotSelectorVisiblestate tofalse, which hides the AI Bot panel.Please note that the user ID of the AI Bot is hardcoded as
-110,-111, and-112in theisGPTBotfunction. This function checks if a user is an AI Bot based on their user ID.
Look up site setting context
Reading context for: ai_bot_allowed_groups
The
ai_bot_allowed_groupssetting controls which user groups are permitted to interact with the AI Bot in private messages. This is particularly important for controlling who can receive replies from the AI Bot in a PM context.The default groups allowed are
@staff(group id: 3) and@trust_level_4(group id: 14). These group ids are specified in theai_bot_allowed_groupssetting in thesettings.ymlfile of thediscourse-aiplugin.The
ai_bot_allowed_groupssetting is used in theai-bot-replies.jsinitializer. Here, it checks if the current user is a member of any of the allowed groups. If the user is in an allowed group and the AI Bot feature is enabled, the initializer attaches the header icon and initializes AI Bot replies.The
ai_bot_allowed_groupssetting is also used in theentry_point.rbmodule of the AI Bot. This module adds theai_enabled_chat_botsattribute to thecurrent_userserializer. This attribute is included if the AI Bot feature is enabled and the authenticated user is a member of any of the allowed groups.When a new post is created, the
post_createdevent is triggered. If the post is a regular post in a private message and the post’s user is in any of the allowed groups, an AI reply job is enqueued.In summary, the
ai_bot_allowed_groupssetting is crucial for controlling which users can interact with the AI Bot in private messages. It is used in several places in thediscourse-aiplugin to enforce this restriction.