Class: Antigravity::Tool::Dynamic

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

Overview

Factory for dynamic Proc-based tools

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description: '', params: {}, &block) ⇒ Dynamic

Returns a new instance of Dynamic.



83
84
85
86
87
88
89
# File 'lib/antigravity/tool.rb', line 83

def initialize(name, description: '', params: {}, &block)
  super()
  @dynamic_name = name.to_s
  @dynamic_description = description
  @params = params
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



81
82
83
# File 'lib/antigravity/tool.rb', line 81

def block
  @block
end

#paramsObject (readonly)

Returns the value of attribute params.



81
82
83
# File 'lib/antigravity/tool.rb', line 81

def params
  @params
end

Instance Method Details

#call(params = nil, **kwargs) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/antigravity/tool.rb', line 95

def call(params = nil, **kwargs)
  return nil unless @block

  if params && kwargs.empty?
    # Old-style: tool.call({key: value})
    @block.call(params)
  else
    # New-style: tool.call(key: value)
    @block.call(**kwargs)
  end
end

#to_json_schemaObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/antigravity/tool.rb', line 107

def to_json_schema
  properties = {}
  required_params = []

  @params.each do |param_name, spec|
    properties[param_name] = {
      type: (spec[:type] || :string).to_s,
      description: spec[:description] || spec[:desc] || ''
    }
    required_params << param_name.to_s unless spec[:required] == false
  end

  {
    name: @dynamic_name,
    description: @dynamic_description,
    parameters: {
      type: 'object',
      properties: properties,
      required: required_params
    }
  }
end

#tool_nameObject



91
92
93
# File 'lib/antigravity/tool.rb', line 91

def tool_name
  @dynamic_name
end