Module: Legion::CLI::Chat::ExtensionToolLoader
- Defined in:
- lib/legion/cli/chat/extension_tool_loader.rb
Constant Summary collapse
- TIER_ORDER =
{ read: 0, write: 1, shell: 2 }.freeze
Class Method Summary collapse
- .collect_tool_classes(tools_module) ⇒ Object
- .discover ⇒ Object
- .effective_tier(tool_class, extension_name) ⇒ Object
- .extension_settings(extension_name) ⇒ Object
- .reset! ⇒ Object
- .tool_enabled?(extension_name) ⇒ Boolean
- .tools_dir_for(extension_path) ⇒ Object
Class Method Details
.collect_tool_classes(tools_module) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/legion/cli/chat/extension_tool_loader.rb', line 24 def collect_tool_classes(tools_module) tools_module.constants.filter_map do |const_name| klass = tools_module.const_get(const_name) klass if klass.is_a?(Class) && klass < RubyLLM::Tool end end |
.discover ⇒ Object
12 13 14 |
# File 'lib/legion/cli/chat/extension_tool_loader.rb', line 12 def discover @discover ||= load_all_extension_tools end |
.effective_tier(tool_class, extension_name) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/legion/cli/chat/extension_tool_loader.rb', line 38 def effective_tier(tool_class, extension_name) class_tier = if tool_class.respond_to?(:declared_permission_tier) tool_class. else :write end override = settings_tier_for(tool_class, extension_name) return class_tier unless override TIER_ORDER[override] > TIER_ORDER[class_tier] ? override : class_tier end |
.extension_settings(extension_name) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/legion/cli/chat/extension_tool_loader.rb', line 50 def extension_settings(extension_name) return nil unless defined?(Legion::Settings) Legion::Settings[:extensions]&.[](extension_name.to_sym) rescue StandardError => e Legion::Logging.warn("ExtensionToolLoader#extension_settings failed for #{extension_name}: #{e.}") if defined?(Legion::Logging) nil end |
.reset! ⇒ Object
16 17 18 |
# File 'lib/legion/cli/chat/extension_tool_loader.rb', line 16 def reset! @discover = nil end |
.tool_enabled?(extension_name) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/legion/cli/chat/extension_tool_loader.rb', line 31 def tool_enabled?(extension_name) settings = extension_settings(extension_name) return true unless settings&.dig(:tools, :enabled) == false false end |
.tools_dir_for(extension_path) ⇒ Object
20 21 22 |
# File 'lib/legion/cli/chat/extension_tool_loader.rb', line 20 def tools_dir_for(extension_path) "#{extension_path}/tools" end |