2023-03-15 16:02:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
|
|
module AiHelper
|
|
|
|
class EntryPoint
|
|
|
|
def inject_into(plugin)
|
2023-03-17 14:14:19 -04:00
|
|
|
plugin.register_seedfu_fixtures(
|
2023-05-05 14:28:31 -04:00
|
|
|
Rails.root.join("plugins", "discourse-ai", "db", "fixtures", "ai_helper"),
|
2023-03-17 14:14:19 -04:00
|
|
|
)
|
2023-09-25 14:12:54 -04:00
|
|
|
|
2023-12-19 15:55:43 -05:00
|
|
|
additional_icons = %w[spell-check language images]
|
2023-09-25 14:12:54 -04:00
|
|
|
additional_icons.each { |icon| plugin.register_svg_icon(icon) }
|
2023-10-30 10:56:33 -04:00
|
|
|
|
2024-03-07 14:14:17 -05:00
|
|
|
plugin.on(:chat_message_created) do |message, channel, user, extra|
|
2023-10-30 12:32:56 -04:00
|
|
|
next unless SiteSetting.composer_ai_helper_enabled
|
|
|
|
next unless SiteSetting.ai_helper_automatic_chat_thread_title
|
2024-03-07 14:14:17 -05:00
|
|
|
next unless extra[:thread].present?
|
|
|
|
next unless extra[:thread].title.blank?
|
|
|
|
|
|
|
|
reply_count = extra[:thread].replies.count
|
|
|
|
|
|
|
|
if reply_count.between?(1, 4)
|
|
|
|
::Jobs.enqueue_in(
|
|
|
|
SiteSetting.ai_helper_automatic_chat_thread_title_delay.minutes,
|
|
|
|
:generate_chat_thread_title,
|
|
|
|
thread_id: extra[:thread].id,
|
|
|
|
)
|
|
|
|
elsif reply_count >= 5
|
|
|
|
::Jobs.enqueue(:generate_chat_thread_title, thread_id: extra[:thread].id)
|
|
|
|
end
|
2023-10-30 10:56:33 -04:00
|
|
|
end
|
2024-02-16 13:57:14 -05:00
|
|
|
|
|
|
|
plugin.add_to_serializer(
|
|
|
|
:current_user,
|
|
|
|
:ai_helper_prompts,
|
|
|
|
include_condition: -> do
|
|
|
|
SiteSetting.composer_ai_helper_enabled && scope.authenticated? &&
|
|
|
|
scope.user.in_any_groups?(SiteSetting.ai_helper_allowed_groups_map)
|
|
|
|
end,
|
|
|
|
) do
|
|
|
|
ActiveModel::ArraySerializer.new(
|
|
|
|
DiscourseAi::AiHelper::Assistant.new.available_prompts,
|
|
|
|
root: false,
|
|
|
|
)
|
|
|
|
end
|
2023-03-15 16:02:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|