Class: Legion::Tools::Base
- Inherits:
-
Object
- Object
- Legion::Tools::Base
- Defined in:
- lib/legion/tools/base.rb
Class Method Summary collapse
- .call(**_args) ⇒ Object
- .deferred(val = nil) ⇒ Object
- .deferred? ⇒ Boolean
- .description(desc = nil) ⇒ Object
- .error_response(msg) ⇒ Object
-
.extension(val = nil) ⇒ Object
Metadata that replaces Capability - Tools::Registry IS the catalog.
- .handle_exception(err, **opts) ⇒ Object
- .input_schema(schema = nil) ⇒ Object
-
.log ⇒ Object
Lazy delegation instead of include Helper — Base loads at require time before Settings is initialized; Helper#log builds TaggedLogger which calls derive_log_segments -> Settings -> possible recursion.
- .mcp_category(val = nil) ⇒ Object
- .mcp_tier(val = nil) ⇒ Object
- .runner(val = nil) ⇒ Object
- .tags(val = nil) ⇒ Object
- .text_response(data) ⇒ Object
- .tool_name(name = nil) ⇒ Object
- .trigger_words(val = nil) ⇒ Object
Class Method Details
.call(**_args) ⇒ Object
78 79 80 |
# File 'lib/legion/tools/base.rb', line 78 def call(**_args) raise NotImplementedError, "#{name} must implement .call" end |
.deferred(val = nil) ⇒ Object
31 32 33 34 35 |
# File 'lib/legion/tools/base.rb', line 31 def deferred(val = nil) return @deferred || false if val.nil? @deferred = val end |
.deferred? ⇒ Boolean
37 38 39 |
# File 'lib/legion/tools/base.rb', line 37 def deferred? deferred end |
.description(desc = nil) ⇒ Object
23 24 25 |
# File 'lib/legion/tools/base.rb', line 23 def description(desc = nil) desc ? @description = desc : (@description || '') end |
.error_response(msg) ⇒ Object
87 88 89 |
# File 'lib/legion/tools/base.rb', line 87 def error_response(msg) { content: [{ type: 'text', text: Legion::JSON.dump({ error: msg }) }], error: true } end |
.extension(val = nil) ⇒ Object
Metadata that replaces Capability - Tools::Registry IS the catalog
42 43 44 45 46 |
# File 'lib/legion/tools/base.rb', line 42 def extension(val = nil) return @extension if val.nil? @extension = val end |
.handle_exception(err, **opts) ⇒ Object
15 16 17 |
# File 'lib/legion/tools/base.rb', line 15 def handle_exception(err, **opts) log&.warn("[Legion::Tools] #{opts[:operation] || 'unknown'}: #{err.}") end |
.input_schema(schema = nil) ⇒ Object
27 28 29 |
# File 'lib/legion/tools/base.rb', line 27 def input_schema(schema = nil) schema ? @input_schema = schema : @input_schema end |
.log ⇒ Object
Lazy delegation instead of include Helper — Base loads at require time before Settings is initialized; Helper#log builds TaggedLogger which calls derive_log_segments -> Settings -> possible recursion. Subclass static tools (Do, Status, Config) CAN include Helper safely.
11 12 13 |
# File 'lib/legion/tools/base.rb', line 11 def log Legion::Logging.respond_to?(:logger) ? Legion::Logging.logger : nil end |
.mcp_category(val = nil) ⇒ Object
60 61 62 63 64 |
# File 'lib/legion/tools/base.rb', line 60 def mcp_category(val = nil) return @mcp_category if val.nil? @mcp_category = val end |
.mcp_tier(val = nil) ⇒ Object
66 67 68 69 70 |
# File 'lib/legion/tools/base.rb', line 66 def mcp_tier(val = nil) return @mcp_tier if val.nil? @mcp_tier = val end |
.runner(val = nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/legion/tools/base.rb', line 48 def runner(val = nil) return @runner if val.nil? @runner = val end |
.tags(val = nil) ⇒ Object
54 55 56 57 58 |
# File 'lib/legion/tools/base.rb', line 54 def (val = nil) return @tags || [] if val.nil? @tags = val end |
.text_response(data) ⇒ Object
82 83 84 85 |
# File 'lib/legion/tools/base.rb', line 82 def text_response(data) text = data.is_a?(String) ? data : Legion::JSON.dump(data) { content: [{ type: 'text', text: text }] } end |
.tool_name(name = nil) ⇒ Object
19 20 21 |
# File 'lib/legion/tools/base.rb', line 19 def tool_name(name = nil) name ? @tool_name = name : @tool_name end |
.trigger_words(val = nil) ⇒ Object
72 73 74 75 76 |
# File 'lib/legion/tools/base.rb', line 72 def trigger_words(val = nil) return @trigger_words || [] if val.nil? @trigger_words = val end |