# Pull Request Template ## Description Captain v1 does not have access to contact attributes. Added a toggle to let user choose if they want contact information available to Captain. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. Specs and locally <img width="1924" height="740" alt="CleanShot 2026-03-19 at 18 48 19@2x" src="https://github.com/user-attachments/assets/353cfeaa-cd58-40eb-89e7-d660a1dc1185" /> ![Uploading CleanShot 2026-03-19 at 18.53.26@2x.png…]() ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
102 lines
3.1 KiB
Ruby
102 lines
3.1 KiB
Ruby
class Api::V1::Accounts::Captain::AssistantsController < Api::V1::Accounts::BaseController
|
|
before_action :current_account
|
|
before_action -> { check_authorization(Captain::Assistant) }
|
|
|
|
before_action :set_assistant, only: [:show, :update, :destroy, :playground]
|
|
|
|
def index
|
|
@assistants = account_assistants.ordered
|
|
end
|
|
|
|
def show; end
|
|
|
|
def create
|
|
@assistant = account_assistants.create!(assistant_params)
|
|
end
|
|
|
|
def update
|
|
@assistant.update!(assistant_params)
|
|
end
|
|
|
|
def destroy
|
|
@assistant.destroy
|
|
head :no_content
|
|
end
|
|
|
|
def playground
|
|
response = if captain_v2_enabled?
|
|
Captain::Assistant::AgentRunnerService.new(assistant: @assistant, source: 'playground').generate_response(
|
|
message_history: playground_message_history
|
|
)
|
|
else
|
|
Captain::Llm::AssistantChatService.new(assistant: @assistant, source: 'playground').generate_response(
|
|
additional_message: playground_params[:message_content],
|
|
message_history: message_history
|
|
)
|
|
end
|
|
|
|
render json: response
|
|
end
|
|
|
|
def tools
|
|
assistant = Captain::Assistant.new(account: Current.account)
|
|
@tools = assistant.available_agent_tools
|
|
end
|
|
|
|
private
|
|
|
|
def set_assistant
|
|
@assistant = account_assistants.find(params[:id])
|
|
end
|
|
|
|
def account_assistants
|
|
@account_assistants ||= Captain::Assistant.for_account(Current.account.id)
|
|
end
|
|
|
|
def assistant_params
|
|
permitted = params.require(:assistant).permit(:name, :description,
|
|
config: [
|
|
:product_name, :feature_faq, :feature_memory, :feature_citation,
|
|
:feature_contact_attributes,
|
|
:welcome_message, :handoff_message, :resolution_message,
|
|
:instructions, :temperature
|
|
])
|
|
|
|
# Handle array parameters separately to allow partial updates
|
|
permitted[:response_guidelines] = params[:assistant][:response_guidelines] if params[:assistant].key?(:response_guidelines)
|
|
|
|
permitted[:guardrails] = params[:assistant][:guardrails] if params[:assistant].key?(:guardrails)
|
|
|
|
permitted
|
|
end
|
|
|
|
def playground_params
|
|
params.require(:assistant).permit(:message_content, message_history: [:role, :content, :agent_name])
|
|
end
|
|
|
|
def message_history
|
|
(playground_params[:message_history] || []).map do |message|
|
|
{
|
|
role: message[:role],
|
|
content: message[:content],
|
|
agent_name: message[:agent_name]
|
|
}.compact
|
|
end
|
|
end
|
|
|
|
def playground_message_history
|
|
history = message_history
|
|
current_message = playground_params[:message_content]
|
|
return history if current_message.blank?
|
|
|
|
current_user_message = { role: 'user', content: current_message }
|
|
return history if history.last == current_user_message
|
|
|
|
history + [current_user_message]
|
|
end
|
|
|
|
def captain_v2_enabled?
|
|
@assistant.account.feature_enabled?('captain_integration_v2')
|
|
end
|
|
end
|