Class: Legion::CLI::Chat::Tools::ViewTrends

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

Constant Summary collapse

DEFAULT_PORT =
4567
DEFAULT_HOST =
'127.0.0.1'

Instance Method Summary collapse

Instance Method Details

#execute(hours: 24, buckets: 12) ⇒ Object



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

def execute(hours: 24, buckets: 12)
  hours = hours.to_i.clamp(1, 168)
  buckets = buckets.to_i.clamp(2, 48)

  data = api_get("/api/traces/trend?hours=#{hours}&buckets=#{buckets}")
  return "API error: #{data[:error][:message]}" if data[:error]

  format_trend(data[:data] || data)
rescue Errno::ECONNREFUSED
  'Legion daemon not running (cannot reach trend API).'
rescue StandardError => e
  Legion::Logging.warn("ViewTrends#execute failed: #{e.message}") if defined?(Legion::Logging)
  "Error fetching trends: #{e.message}"
end