FIX: stream messages when directly PMing a persona (#500)

previous to this fix we did not consider personas a bot in the
front end
This commit is contained in:
Sam 2024-03-01 07:53:42 +11:00 committed by GitHub
parent 9fb1430e40
commit 59bab2bba3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 1 deletions

View File

@ -10,8 +10,9 @@ import copyConversation from "../discourse/lib/copy-conversation";
const AUTO_COPY_THRESHOLD = 4;
let enabledChatBotIds = [];
function isGPTBot(user) {
return user && [-110, -111, -112, -113, -114, -115, -116].includes(user.id);
return user && enabledChatBotIds.includes(user.id);
}
function attachHeaderIcon(api) {
@ -197,6 +198,7 @@ export default {
const user = container.lookup("service:current-user");
if (user?.ai_enabled_chat_bots) {
enabledChatBotIds = user.ai_enabled_chat_bots.map((bot) => bot.id);
if (settings.ai_bot_add_to_header) {
withPluginApi("1.6.0", attachHeaderIcon);
}

View File

@ -97,6 +97,14 @@ module DiscourseAi
SQL
bots.each { |hash| hash["model_name"] = model_map[hash["id"]] }
mentionables = AiPersona.mentionables(user: scope.user)
if mentionables.present?
bots.concat(
mentionables.map do |mentionable|
{ "id" => mentionable[:user_id], "username" => mentionable[:username] }
end,
)
end
bots
end

View File

@ -23,6 +23,27 @@ RSpec.describe DiscourseAi::AiBot::EntryPoint do
bot_allowed_group.add(admin)
end
it "adds mentionables to current_user_serializer" do
Group.refresh_automatic_groups!
persona =
Fabricate(
:ai_persona,
mentionable: true,
enabled: true,
allowed_group_ids: [bot_allowed_group.id],
)
persona.create_user!
serializer = CurrentUserSerializer.new(admin, scope: Guardian.new(admin))
serializer = serializer.as_json
bots = serializer[:current_user][:ai_enabled_chat_bots]
persona_bot = bots.find { |bot| bot["id"] == persona.user_id }
expect(persona_bot["username"]).to eq(persona.user.username)
end
it "queues a job to generate a reply by the AI" do
expect { PostCreator.create!(admin, post_args) }.to change(
Jobs::CreateAiReply.jobs,