diff --git a/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb index 21675bad0..ebeaaf67f 100644 --- a/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb @@ -33,7 +33,8 @@ class Api::V1::Accounts::Captain::AssistantsController < Api::V1::Accounts::Base end def tools - @tools = Captain::Assistant.available_agent_tools + assistant = Captain::Assistant.new(account: Current.account) + @tools = assistant.available_agent_tools end private diff --git a/enterprise/app/models/captain/assistant.rb b/enterprise/app/models/captain/assistant.rb index 0423abf67..3ee5f617c 100644 --- a/enterprise/app/models/captain/assistant.rb +++ b/enterprise/app/models/captain/assistant.rb @@ -50,6 +50,21 @@ class Captain::Assistant < ApplicationRecord name end + def available_agent_tools + tools = self.class.built_in_agent_tools.dup + + if account.feature_enabled?(:captain_custom_tools) + custom_tools = Captain::CustomTool.where(account_id: account_id, enabled: true).map(&:to_tool_metadata) + tools.concat(custom_tools) + end + + tools + end + + def available_tool_ids + available_agent_tools.pluck(:id) + end + def push_event_data { id: id, diff --git a/enterprise/app/models/concerns/captain_tools_helpers.rb b/enterprise/app/models/concerns/captain_tools_helpers.rb index 5a660310c..34133aac2 100644 --- a/enterprise/app/models/concerns/captain_tools_helpers.rb +++ b/enterprise/app/models/concerns/captain_tools_helpers.rb @@ -8,12 +8,12 @@ module Concerns::CaptainToolsHelpers TOOL_REFERENCE_REGEX = %r{\[[^\]]+\]\(tool://([^/)]+)\)} class_methods do - # Returns all available agent tools with their metadata. + # Returns all built-in agent tools with their metadata. # Only includes tools that have corresponding class files and can be resolved. # # @return [Array] Array of tool hashes with :id, :title, :description, :icon - def available_agent_tools - @available_agent_tools ||= load_agent_tools + def built_in_agent_tools + @built_in_agent_tools ||= load_agent_tools end # Resolves a tool class from a tool ID. @@ -26,12 +26,12 @@ module Concerns::CaptainToolsHelpers class_name.safe_constantize end - # Returns an array of all available tool IDs. - # Convenience method that extracts just the IDs from available_agent_tools. + # Returns an array of all built-in tool IDs. + # Convenience method that extracts just the IDs from built_in_agent_tools. # - # @return [Array] Array of available tool IDs - def available_tool_ids - @available_tool_ids ||= available_agent_tools.map { |tool| tool[:id] } + # @return [Array] Array of built-in tool IDs + def built_in_tool_ids + @built_in_tool_ids ||= built_in_agent_tools.map { |tool| tool[:id] } end private