Class: SharedTools::Tools::ComputerTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::ComputerTool
- Defined in:
- lib/shared_tools/tools/computer_tool.rb
Overview
A tool for interacting with a computer. Be careful with using as it can perform actions on your computer!
Defined Under Namespace
Modules: Action, MouseButton, ScrollDirection
Constant Summary collapse
- ACTIONS =
[ Action::KEY, Action::HOLD_KEY, Action::MOUSE_POSITION, Action::MOUSE_MOVE, Action::MOUSE_CLICK, Action::MOUSE_DOWN, Action::MOUSE_DRAG, Action::MOUSE_UP, Action::TYPE, Action::SCROLL, Action::WAIT, ].freeze
- MOUSE_BUTTON_OPTIONS =
[ MouseButton::LEFT, MouseButton::MIDDLE, MouseButton::RIGHT, ].freeze
- SCROLL_DIRECTION_OPTIONS =
[ ScrollDirection::UP, ScrollDirection::DOWN, ScrollDirection::LEFT, ScrollDirection::RIGHT, ].freeze
Instance Attribute Summary collapse
-
#driver ⇒ Object
writeonly
Set driver after instantiation (useful when tool is discovered by RubyLLM).
Class Method Summary collapse
Instance Method Summary collapse
- #execute(action:, coordinate: nil, text: nil, duration: nil, mouse_button: nil, scroll_direction: nil, scroll_amount: nil) ⇒ Object
-
#initialize(driver: nil, logger: nil) ⇒ ComputerTool
constructor
A new instance of ComputerTool.
Constructor Details
#initialize(driver: nil, logger: nil) ⇒ ComputerTool
Returns a new instance of ComputerTool.
144 145 146 147 |
# File 'lib/shared_tools/tools/computer_tool.rb', line 144 def initialize(driver: nil, logger: nil) @logger = logger || RubyLLM.logger @driver = driver # Defer default_driver to execute time to support RubyLLM tool discovery end |
Instance Attribute Details
#driver=(value) ⇒ Object (writeonly)
Set driver after instantiation (useful when tool is discovered by RubyLLM)
150 151 152 |
# File 'lib/shared_tools/tools/computer_tool.rb', line 150 def driver=(value) @driver = value end |
Class Method Details
.name ⇒ Object
14 |
# File 'lib/shared_tools/tools/computer_tool.rb', line 14 def self.name = 'computer_tool' |
Instance Method Details
#execute(action:, coordinate: nil, text: nil, duration: nil, mouse_button: nil, scroll_direction: nil, scroll_amount: nil) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/shared_tools/tools/computer_tool.rb', line 159 def execute( action:, coordinate: nil, text: nil, duration: nil, mouse_button: nil, scroll_direction: nil, scroll_amount: nil ) # Lazily resolve driver at execute time @driver ||= default_driver @logger.info({ action:, coordinate:, text:, duration:, mouse_button:, scroll_direction:, scroll_amount:, }.compact.map { |key, value| "#{key}=#{value.inspect}" }.join(" ")) # Convert coordinate hash keys to symbols if coordinate is provided coordinate = coordinate&.transform_keys(&:to_sym) case action when Action::KEY then @driver.key(text:) when Action::HOLD_KEY then @driver.hold_key(text:, duration:) when Action::MOUSE_POSITION then @driver.mouse_position when Action::MOUSE_MOVE then @driver.mouse_move(coordinate:) when Action::MOUSE_CLICK then @driver.mouse_click(coordinate:, button: ) when Action::MOUSE_DOUBLE_CLICK then @driver.mouse_double_click(coordinate:, button: ) when Action::MOUSE_TRIPLE_CLICK then @driver.mouse_triple_click(coordinate:, button: ) when Action::MOUSE_DOWN then @driver.mouse_down(coordinate:, button: ) when Action::MOUSE_UP then @driver.mouse_up(coordinate:, button: ) when Action::MOUSE_DRAG then @driver.mouse_drag(coordinate:, button: ) when Action::TYPE then @driver.type(text:) when Action::SCROLL then @driver.scroll(amount: scroll_amount, direction: scroll_direction) when Action::WAIT then @driver.wait(duration:) end end |