Class: Tidewave::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/tidewave/tool.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_options = {}) ⇒ Tool

Returns a new instance of Tool.



16
17
# File 'lib/tidewave/tool.rb', line 16

def initialize(_options = {})
end

Class Method Details

.descendantsObject



6
7
8
# File 'lib/tidewave/tool.rb', line 6

def descendants
  @descendants ||= []
end

.inherited(subclass) ⇒ Object



10
11
12
13
# File 'lib/tidewave/tool.rb', line 10

def inherited(subclass)
  descendants << subclass
  super
end

Instance Method Details

#call(_arguments = {}) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/tidewave/tool.rb', line 23

def call(_arguments = {})
  raise NotImplementedError, "#{self.class} must implement #call"
end

#definitionObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/tidewave/tool.rb', line 19

def definition
  raise NotImplementedError, "#{self.class} must implement #definition"
end

#validate_and_call(arguments) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tidewave/tool.rb', line 27

def validate_and_call(arguments)
  arguments ||= {}

  unless arguments.is_a?(Hash)
    raise ArgumentError, "Invalid arguments: expected an object"
  end

  # This validator intentionally enforces only a small subset of JSON Schema:
  # `type`, `required`, and scalar `default` values. Other keywords such as
  # `minLength`, `maxLength`, `enum`, and `pattern` remain descriptive until
  # Tidewave grows broader schema support.
  validate_schema(arguments, definition.fetch("inputSchema", {}))
  call(arguments)
end