Class: Tidewave::Tools::GetLogs
- Inherits:
-
Tidewave::Tool
- Object
- Tidewave::Tool
- Tidewave::Tools::GetLogs
- Defined in:
- lib/tidewave/tools/get_logs.rb
Constant Summary collapse
- DESCRIPTION =
<<~DESCRIPTION.freeze Returns all log output, excluding logs that were caused by other tool calls. Use this tool to check for request logs or potentially logged errors. DESCRIPTION
Instance Method Summary collapse
- #call(arguments) ⇒ Object
- #definition ⇒ Object
-
#initialize(options = {}) ⇒ GetLogs
constructor
A new instance of GetLogs.
Methods inherited from Tidewave::Tool
descendants, inherited, #validate_and_call
Constructor Details
#initialize(options = {}) ⇒ GetLogs
Returns a new instance of GetLogs.
12 13 14 |
# File 'lib/tidewave/tools/get_logs.rb', line 12 def initialize( = {}) @log_file = [:log_file] ? Pathname.new([:log_file].to_s) : nil end |
Instance Method Details
#call(arguments) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tidewave/tools/get_logs.rb', line 43 def call(arguments) tail = arguments.fetch("tail") grep = arguments["grep"] return "Log file not found" unless @log_file&.exist? regex = Regexp.new(grep, Regexp::IGNORECASE) if grep matching_lines = [] tail_lines(@log_file) do |line| if regex.nil? || line.match?(regex) matching_lines.unshift(line) break if matching_lines.size >= tail end end matching_lines.join end |
#definition ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tidewave/tools/get_logs.rb', line 16 def definition return nil unless @log_file { "name" => "get_logs", "description" => DESCRIPTION, "inputSchema" => { "type" => "object", "properties" => { "tail" => { "type" => "integer", "not" => { "type" => "null" }, "description" => "The number of log entries to return from the end of the log" }, "grep" => { "type" => "string", "minLength" => 1, "description" => "Filter logs with the given regular expression (case insensitive). E.g. \"error\" when you want to capture errors in particular" } }, "required" => [ "tail" ] } } end |