Class: Legion::Extensions::Capability
- Inherits:
-
Data
- Object
- Data
- Legion::Extensions::Capability
- Defined in:
- lib/legion/extensions/capability.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#loaded_at ⇒ Object
readonly
Returns the value of attribute loaded_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Class Method Summary collapse
- .from_absorber(extension:, absorber:, patterns: [], description: nil) ⇒ Object
- .from_runner(extension:, runner:, function:, **opts) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def description @description end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def extension @extension end |
#function ⇒ Object (readonly)
Returns the value of attribute function
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def function @function end |
#loaded_at ⇒ Object (readonly)
Returns the value of attribute loaded_at
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def loaded_at @loaded_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def parameters @parameters end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def runner @runner end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags
5 6 7 |
# File 'lib/legion/extensions/capability.rb', line 5 def @tags end |
Class Method Details
.from_absorber(extension:, absorber:, patterns: [], description: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/legion/extensions/capability.rb', line 9 def self.from_absorber(extension:, absorber:, patterns: [], description: nil) absorber_name = absorber.name&.split('::')&.last || absorber.object_id.to_s snake = absorber_name.gsub(/([A-Z])/, '_\1').sub(/^_/, '').downcase canonical = "#{extension}:absorber:#{snake}" new( name: canonical, extension: extension, runner: 'Absorber', function: absorber_name, description: description, parameters: { input: { type: :string, required: true } }, tags: ['absorber'] + patterns.map { |p| "pattern:#{p[:type]}:#{p[:value]}" }, loaded_at: Time.now ) end |
.from_runner(extension:, runner:, function:, **opts) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/legion/extensions/capability.rb', line 25 def self.from_runner(extension:, runner:, function:, **opts) canonical = "#{extension}:#{runner.to_s.gsub(/([A-Z])/, '_\1').sub(/^_/, '').downcase}:#{function}" new( name: canonical, extension: extension, runner: runner.to_s, function: function.to_s, description: opts[:description], parameters: opts[:parameters] || {}, tags: Array(opts[:tags]), loaded_at: Time.now ) end |
Instance Method Details
#matches_intent?(text) ⇒ Boolean
39 40 41 42 43 44 45 46 |
# File 'lib/legion/extensions/capability.rb', line 39 def matches_intent?(text) words = text.downcase.split(/\s+/) searchable = [description, *, extension, runner, function] .compact.join(' ').downcase matching = words.count { |w| searchable.include?(w) } matching.to_f / [words.length, 1].max >= 0.4 end |
#to_mcp_tool ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/extensions/capability.rb', line 48 def to_mcp_tool snake_runner = runner.gsub(/([A-Z])/, '_\1').sub(/^_/, '').downcase tool_name = "legion.#{extension.delete_prefix('lex-').tr('-', '_')}.#{snake_runner}.#{function}" properties = (parameters || {}).transform_values do |v| v.is_a?(Hash) ? v : { type: v.to_s } end { name: tool_name, description: description || "#{extension} #{runner}##{function}", input_schema: { type: 'object', properties: properties, required: parameters&.select { |_, v| v.is_a?(Hash) && v[:required] }&.keys&.map(&:to_s) || [] } } end |