Class: RCrewAI::Tools::FileWriter

Inherits:
Base
  • Object
show all
Defined in:
lib/rcrewai/tools/file_writer.rb

Constant Summary

Constants included from RCrewAI::ToolSchema

RCrewAI::ToolSchema::TYPE_MAP

Instance Method Summary collapse

Methods inherited from Base

available_tools, create_tool, #description, #execute_with_validation, #json_schema, list_available_tools, #name, #validate_params!

Methods included from RCrewAI::ToolSchema

#description, extended, #json_schema, #param, #params, #tool_name

Constructor Details

#initialize(**options) ⇒ FileWriter

Returns a new instance of FileWriter.



19
20
21
22
23
24
# File 'lib/rcrewai/tools/file_writer.rb', line 19

def initialize(**options)
  super()
  @max_file_size = options.fetch(:max_file_size, 10_000_000) # 10MB
  @allowed_extensions = options.fetch(:allowed_extensions, %w[.txt .md .json .yaml .yml .csv .log])
  @create_directories = options.fetch(:create_directories, true)
end

Instance Method Details

#execute(**params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rcrewai/tools/file_writer.rb', line 26

def execute(**params)
  validate_params!(params, required: %i[file_path content], optional: %i[mode encoding])

  file_path = params[:file_path]
  content = params[:content]
  mode = params[:mode] || 'w' # 'w' for write, 'a' for append
  encoding = params[:encoding] || 'utf-8'

  begin
    write_file(file_path, content, mode, encoding)
  rescue StandardError => e
    "File write failed: #{e.message}"
  end
end