feat: captain custom tools v1 (#13890)

# Pull Request Template

## Description

Adds custom tool support to v1

## Type of change
- [x] New feature (non-breaking change which adds functionality)


## 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.

<img width="1816" height="958" alt="CleanShot 2026-03-24 at 11 37 33@2x"
src="https://github.com/user-attachments/assets/2777a953-8b65-4a2d-88ec-39f395b3fb47"
/>

<img width="378" height="488" alt="CleanShot 2026-03-24 at 11 38 18@2x"
src="https://github.com/user-attachments/assets/f6973c99-efd0-40e4-90fe-4472a2f63cea"
/>

<img width="1884" height="1452" alt="CleanShot 2026-03-24 at 11 38
32@2x"
src="https://github.com/user-attachments/assets/9fba4fc4-0c33-46da-888a-52ec6bad6130"
/>



## Checklist:

- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
Aakash Bakhle
2026-04-02 12:40:11 +05:30
committed by GitHub
parent 211fb1102d
commit 8daf6cf6cb
21 changed files with 307 additions and 57 deletions

View File

@@ -1,16 +1,19 @@
class Api::V1::Accounts::Captain::CustomToolsController < Api::V1::Accounts::BaseController
before_action :current_account
before_action :ensure_custom_tools_enabled
before_action -> { check_authorization(Captain::CustomTool) }
before_action :set_custom_tool, only: [:show, :update, :destroy]
def index
@custom_tools = account_custom_tools.enabled
@custom_tools = account_custom_tools
end
def show; end
def create
@custom_tool = account_custom_tools.create!(custom_tool_params)
rescue Captain::CustomTool::LimitExceededError => e
render_could_not_create_error(e.message)
end
def update
@@ -22,8 +25,22 @@ class Api::V1::Accounts::Captain::CustomToolsController < Api::V1::Accounts::Bas
head :no_content
end
def test
tool = account_custom_tools.new(custom_tool_params)
result = execute_test_request(tool)
render json: { status: result.code.to_i, body: result.body.to_s.truncate(500) }
rescue StandardError => e
render json: { error: e.message }, status: :unprocessable_content
end
private
def ensure_custom_tools_enabled
return if Current.account.feature_enabled?('custom_tools') || Current.account.feature_enabled?('captain_integration_v2')
render json: { error: 'Custom tools are not enabled for this account' }, status: :forbidden
end
def set_custom_tool
@custom_tool = account_custom_tools.find(params[:id])
end
@@ -32,6 +49,11 @@ class Api::V1::Accounts::Captain::CustomToolsController < Api::V1::Accounts::Bas
@account_custom_tools ||= Current.account.captain_custom_tools
end
def execute_test_request(tool)
http_tool = Captain::Tools::HttpTool.new(nil, tool)
http_tool.send(:execute_http_request, tool.endpoint_url, nil, nil)
end
def custom_tool_params
params.require(:custom_tool).permit(
:title,