Class: Legion::CLI::Chat::Tools::ViewEvents

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/legion/cli/chat/tools/view_events.rb

Constant Summary collapse

DEFAULT_PORT =
4567
DEFAULT_HOST =
'127.0.0.1'

Instance Method Summary collapse

Instance Method Details

#execute(count: 15) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/legion/cli/chat/tools/view_events.rb', line 28

def execute(count: 15)
  count = count.to_i.clamp(1, 100)
  data = api_get("/api/events/recent?count=#{count}")
  return "API error: #{data[:error]}" if data[:error]

  events = data[:data] || data
  events = [events] if events.is_a?(Hash)
  return 'No recent events.' if !events.is_a?(Array) || events.empty?

  format_events(events)
rescue Errno::ECONNREFUSED
  'Legion daemon not running (cannot reach events API).'
rescue StandardError => e
  Legion::Logging.warn("ViewEvents#execute failed: #{e.message}") if defined?(Legion::Logging)
  "Error fetching events: #{e.message}"
end