Class: ActAsAgent::Tools::ListFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/act_as_agent/tools/list_files.rb

Constant Summary collapse

ERROR =
ActAsAgent::Errors::ToolIncorrectArgsError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_folder: nil) ⇒ ListFiles

Returns a new instance of ListFiles.



12
13
14
# File 'lib/act_as_agent/tools/list_files.rb', line 12

def initialize(root_folder: nil)
  @root_folder = root_folder
end

Instance Attribute Details

#root_folderObject (readonly)

Returns the value of attribute root_folder.



10
11
12
# File 'lib/act_as_agent/tools/list_files.rb', line 10

def root_folder
  @root_folder
end

Instance Method Details

#call(args = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/act_as_agent/tools/list_files.rb', line 35

def call(args = {})
  path = args.fetch("path", nil)

  return Dir.glob(path) unless path.nil? || path.chomp == ""
  return Dir.glob(root_folder) unless root_folder.nil?

  ERROR.new("Incorrect params have been given to list files tool")
end

#descriptionObject



20
21
22
# File 'lib/act_as_agent/tools/list_files.rb', line 20

def description
  "List files in the directory and all subdirectories. Pass the path to lookup"
end

#input_schemaObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/act_as_agent/tools/list_files.rb', line 24

def input_schema
  {
    type: "object",
    properties: {
      root_folder: { type: "string",
                     description: "The root folder of the list folder. By default it will use current folder." }
    },
    required: []
  }
end

#nameObject



16
17
18
# File 'lib/act_as_agent/tools/list_files.rb', line 16

def name
  self.class.to_s.gsub("::", "__")
end