discourse/plugins/discourse-ai/app/jobs/regular/create_ai_chat_reply.rb
Sam e3fae646d4
DEV: AI persona to agent migration (#38319)
Co-authored-by: Keegan George <kgeorge13@gmail.com>
2026-03-10 15:59:45 +11:00

27 lines
742 B
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class CreateAiChatReply < ::Jobs::Base
sidekiq_options retry: false
def execute(args)
channel = ::Chat::Channel.find_by(id: args[:channel_id])
return if channel.blank?
message = ::Chat::Message.find_by(id: args[:message_id])
return if message.blank?
agentClass = DiscourseAi::Agents::Agent.find_by(id: args[:agent_id], user: message.user)
return if agentClass.blank?
user = User.find_by(id: agentClass.user_id)
bot = DiscourseAi::Agents::Bot.as(user, agent: agentClass.new)
DiscourseAi::AiBot::Playground.new(bot).reply_to_chat_message(
message,
channel,
args[:context_post_ids],
)
end
end
end