feat: update tools to make this public
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
class Captain::Tools::AddContactNoteTool < Captain::Tools::BaseAgentTool
|
||||
class Captain::Tools::AddContactNoteTool < Captain::Tools::BasePublicTool
|
||||
description 'Add a note to a contact profile'
|
||||
param :contact_id, type: 'string', desc: 'The ID of the contact'
|
||||
param :note, type: 'string', desc: 'The note content to add to the contact'
|
||||
@@ -30,7 +30,7 @@ class Captain::Tools::AddContactNoteTool < Captain::Tools::BaseAgentTool
|
||||
)
|
||||
end
|
||||
|
||||
def active?
|
||||
user_has_permission('contact_manage')
|
||||
def permissions
|
||||
%w[contact_manage]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Captain::Tools::AddLabelToConversationTool < Captain::Tools::BaseAgentTool
|
||||
class Captain::Tools::AddLabelToConversationTool < Captain::Tools::BasePublicTool
|
||||
description 'Add a label to a conversation'
|
||||
param :conversation_id, type: 'integer', desc: 'The ID of the conversation'
|
||||
param :label_name, type: 'string', desc: 'The name of the label to add'
|
||||
@@ -59,4 +59,4 @@ class Captain::Tools::AddLabelToConversationTool < Captain::Tools::BaseAgentTool
|
||||
error: message
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Captain::Tools::AddPrivateNoteTool < Captain::Tools::BaseAgentTool
|
||||
class Captain::Tools::AddPrivateNoteTool < Captain::Tools::BasePublicTool
|
||||
description 'Add a private note to a conversation'
|
||||
param :conversation_id, type: 'string', desc: 'The display ID of the conversation'
|
||||
param :note, type: 'string', desc: 'The private note content'
|
||||
@@ -32,9 +32,7 @@ class Captain::Tools::AddPrivateNoteTool < Captain::Tools::BaseAgentTool
|
||||
)
|
||||
end
|
||||
|
||||
def active?
|
||||
user_has_permission('conversation_manage') ||
|
||||
user_has_permission('conversation_unassigned_manage') ||
|
||||
user_has_permission('conversation_participating_manage')
|
||||
def permissions
|
||||
%w[conversation_manage conversation_unassigned_manage conversation_participating_manage]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
require 'agents'
|
||||
|
||||
class Captain::Tools::BaseAgentTool < Agents::Tool
|
||||
def initialize(assistant, user: nil)
|
||||
@assistant = assistant
|
||||
@user = user
|
||||
@account_user = find_account_user if @user.present?
|
||||
super()
|
||||
end
|
||||
|
||||
def active?
|
||||
user_has_permission(required_permission)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def required_permission
|
||||
# Override in subclasses to specify the required permission
|
||||
'agent'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_has_permission(permission)
|
||||
return false if @account_user.blank?
|
||||
|
||||
return @account_user.custom_role.permissions.include?(permission) if @account_user.custom_role.present?
|
||||
|
||||
# Default permission for agents without custom roles
|
||||
@account_user.administrator? || @account_user.agent?
|
||||
end
|
||||
|
||||
def find_account_user
|
||||
AccountUser.find_by(account_id: @assistant.account_id, user_id: @user.id)
|
||||
end
|
||||
|
||||
def account_scoped(model_class)
|
||||
model_class.where(account_id: @assistant.account_id)
|
||||
end
|
||||
|
||||
def log_tool_usage(action, details = {})
|
||||
Rails.logger.info do
|
||||
"#{self.class.name}: #{action} by user #{@user&.id} for assistant #{@assistant&.id} - #{details.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
require 'agents'
|
||||
|
||||
class Captain::Tools::BasePublicTool < Agents::Tool
|
||||
def initialize(assistant)
|
||||
@assistant = assistant
|
||||
super()
|
||||
end
|
||||
|
||||
def active?
|
||||
# Public tools are always active
|
||||
true
|
||||
end
|
||||
|
||||
def permissions
|
||||
# Override in subclasses to specify required permissions
|
||||
# Returns empty array for public tools (no permissions required)
|
||||
[]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def account_scoped(model_class)
|
||||
model_class.where(account_id: @assistant.account_id)
|
||||
end
|
||||
|
||||
def log_tool_usage(action, details = {})
|
||||
Rails.logger.info do
|
||||
"#{self.class.name}: #{action} for assistant #{@assistant&.id} - #{details.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
class Captain::Tools::SearchContactTool < Captain::Tools::BaseAgentTool
|
||||
class Captain::Tools::SearchContactTool < Captain::Tools::BasePublicTool
|
||||
description 'Search for a contact by email, phone number, or identifier'
|
||||
param :query, type: 'string', desc: 'Email, phone number, or identifier to search for'
|
||||
|
||||
@@ -52,4 +52,4 @@ class Captain::Tools::SearchContactTool < Captain::Tools::BaseAgentTool
|
||||
error: message
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Captain::Tools::UpdatePriorityTool < Captain::Tools::BaseAgentTool
|
||||
class Captain::Tools::UpdatePriorityTool < Captain::Tools::BasePublicTool
|
||||
description 'Update the priority of a conversation'
|
||||
param :conversation_id, type: 'string', desc: 'The display ID of the conversation'
|
||||
param :priority, type: 'string', desc: 'The priority level: low, medium, high, urgent, or nil to remove priority'
|
||||
@@ -57,9 +57,7 @@ class Captain::Tools::UpdatePriorityTool < Captain::Tools::BaseAgentTool
|
||||
conversation.update!(priority: priority)
|
||||
end
|
||||
|
||||
def active?
|
||||
user_has_permission('conversation_manage') ||
|
||||
user_has_permission('conversation_unassigned_manage') ||
|
||||
user_has_permission('conversation_participating_manage')
|
||||
def permissions
|
||||
%w[conversation_manage conversation_unassigned_manage conversation_participating_manage]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user