feat: hand off if captain limits are reached

This commit is contained in:
Shivam Mishra
2025-01-17 16:44:22 +05:30
parent 5e094a866d
commit 3bac319feb
2 changed files with 8 additions and 1 deletions
@@ -3,8 +3,12 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
def perform(conversation, assistant)
@conversation = conversation
@inbox = conversation.inbox
@assistant = assistant
# this ensures that the conversation is not processed if the assistant limits are reached
return ActiveRecord::Base.transaction { process_action('handoff') } unless @inbox.captain_active?
ActiveRecord::Base.transaction do
generate_and_process_response
end
@@ -10,6 +10,9 @@ module Enterprise::MessageTemplates::HookExecutionService
end
def should_process_captain_response?
conversation.pending? && message.incoming? && inbox.captain_active?
# we don't check the captain usage limits here intentionally
# as the usage limits are checked in the job itself
# this is to ensure that the handoff can be done there if it's required
conversation.pending? && message.incoming? && inbox.captain_assistant.present?
end
end