feat(ee): Add Captain features (#10665)

Migration Guide: https://chwt.app/v4/migration

This PR imports all the work related to Captain into the EE codebase. Captain represents the AI-based features in Chatwoot and includes the following key components:

- Assistant: An assistant has a persona, the product it would be trained on. At the moment, the data at which it is trained is from websites. Future integrations on Notion documents, PDF etc. This PR enables connecting an assistant to an inbox. The assistant would run the conversation every time before transferring it to an agent.
- Copilot for Agents: When an agent is supporting a customer, we will be able to offer additional help to lookup some data or fetch information from integrations etc via copilot.
- Conversation FAQ generator: When a conversation is resolved, the Captain integration would identify questions which were not in the knowledge base.
- CRM memory: Learns from the conversations and identifies important information about the contact.

---------

Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com>
Co-authored-by: Sojan <sojan@pepalo.com>
Co-authored-by: iamsivin <iamsivin@gmail.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Pranav
2025-01-14 16:15:47 -08:00
committed by GitHub
parent 7b31b5ad6e
commit d070743383
184 changed files with 6666 additions and 2242 deletions

View File

@@ -1,5 +1,29 @@
module Enterprise::Api::V1::Accounts::ConversationsController
extend ActiveSupport::Concern
included do
before_action :set_assistant, only: [:copilot]
end
def copilot
assistant = @conversation.inbox.captain_assistant
return render json: { message: I18n.t('captain.copilot_error') } unless assistant
response = Captain::Copilot::ChatService.new(
assistant,
messages: copilot_params[:previous_messages],
conversation_history: @conversation.to_llm_text
).execute(copilot_params[:message])
render json: { message: response }
end
def permitted_update_params
super.merge(params.permit(:sla_policy_id))
end
private
def copilot_params
params.permit(:previous_messages, :message, :assistant_id)
end
end

View File

@@ -1,8 +1,4 @@
module Enterprise::Api::V1::Accounts::InboxesController
def response_sources
@response_sources = @inbox.response_sources
end
def inbox_attributes
super + ee_inbox_attributes
end

View File

@@ -10,7 +10,7 @@ module Enterprise::SuperAdmin::AppConfigsController
when 'internal'
@allowed_configs = internal_config_options
when 'captain'
@allowed_configs = %w[CAPTAIN_API_URL CAPTAIN_APP_URL]
@allowed_configs = %w[CAPTAIN_OPEN_AI_API_KEY]
else
super
end

View File

@@ -0,0 +1,30 @@
class Enterprise::Webhooks::FirecrawlController < ActionController::API
def process_payload
if crawl_page_event?
Captain::Tools::FirecrawlParserJob.perform_later(
assistant_id: permitted_params[:assistant_id],
payload: permitted_params[:data]
)
end
head :ok
end
private
def crawl_page_event?
permitted_params[:type] == 'crawl.page'
end
def permitted_params
params.permit(
:type,
:assistant_id,
:success,
:id,
:metadata,
:format,
:firecrawl,
{ data: {} }
)
end
end