Class: RcrewAI::Rails::Tools::ActiveStorageTool

Inherits:
RCrewAI::Tools::Base
  • Object
show all
Defined in:
lib/rcrewai/rails/tools/active_storage_tool.rb

Instance Method Summary collapse

Constructor Details

#initialize(allowed_operations: %i[attach download analyze])) ⇒ ActiveStorageTool

Returns a new instance of ActiveStorageTool.



14
15
16
17
# File 'lib/rcrewai/rails/tools/active_storage_tool.rb', line 14

def initialize(allowed_operations: %i[attach download analyze])
  super()
  @allowed_operations = allowed_operations.map(&:to_sym)
end

Instance Method Details

#execute(operation:, params: {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rcrewai/rails/tools/active_storage_tool.rb', line 19

def execute(operation:, params: {})
  op = operation.to_sym
  validate_operation!(op)
  opts = (params || {}).transform_keys(&:to_sym)

  case op
  when :attach   then attach_file(opts)
  when :download then download_file(opts)
  when :analyze  then analyze_file(opts)
  when :delete   then delete_file(opts)
  when :url      then get_url(opts)
  else { error: "Unknown operation: #{operation}" }
  end
rescue => e
  { error: "Active Storage operation failed", message: e.message }
end