class Riffer::Tool
Public Instance Methods
Source
# File lib/riffer/tool.rb, line 14 def call(context:, **kwargs) raise NotImplementedError, "#{self.class} must implement #call" end
Source
# File lib/riffer/tool.rb, line 38 def call_with_validation(context:, **kwargs) params_builder = self.class.params begin validated_args = params_builder ? params_builder.validate(kwargs) : kwargs rescue Riffer::ValidationError => e return Riffer::Tools::Response.error(e.message, type: :validation_error) end result = Timeout.timeout(self.class.timeout, Riffer::TimeoutError) do call(context: context, **validated_args) #: untyped end unless result.is_a?(Riffer::Tools::Response) raise Riffer::Error, "#{self.class} must return a Riffer::Tools::Response from #call" end result rescue Riffer::TimeoutError Riffer::Tools::Response.error( "Tool execution timed out after #{self.class.timeout} seconds", type: :timeout_error, ) rescue Riffer::ToolExecutionError => e Riffer::Tools::Response.error(e.message, type: :execution_error) # Anything outside StandardError — an unimplemented #call above all — still # propagates: a broken tool is a broken deploy, not a bad request. rescue StandardError => e Riffer::Tools::Response.error( "Error executing tool: #{e.class}: #{e.message}", type: :unhandled_error, exception: e, ) end
Source
# File lib/riffer/tool.rb, line 32 def error(message, type: :execution_error) Riffer::Tools::Response.error(message, type: type) end
Source
# File lib/riffer/tool.rb, line 26 def json(result) Riffer::Tools::Response.json(result) end
Source
# File lib/riffer/tool.rb, line 20 def text(result) Riffer::Tools::Response.text(result) end