Class: SharedTools::Tools::BrowserTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::BrowserTool
- Defined in:
- lib/shared_tools/tools/browser_tool.rb
Overview
A tool for controller a browser.
Defined Under Namespace
Modules: Action
Constant Summary collapse
- ACTIONS =
[ Action::VISIT, Action::PAGE_INSPECT, Action::UI_INSPECT, Action::SELECTOR_INSPECT, Action::CLICK, Action::TEXT_FIELD_SET, Action::SCREENSHOT, ].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
- #cleanup! ⇒ Object
- #execute(action:, url: nil, selector: nil, value: nil, context_size: 2, full_html: false, text_content: nil) ⇒ String
-
#initialize(logger: nil, driver: nil) ⇒ BrowserTool
constructor
A new instance of BrowserTool.
Constructor Details
#initialize(logger: nil, driver: nil) ⇒ BrowserTool
Returns a new instance of BrowserTool.
150 151 152 153 |
# File 'lib/shared_tools/tools/browser_tool.rb', line 150 def initialize(logger: nil, driver: 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)
156 157 158 |
# File 'lib/shared_tools/tools/browser_tool.rb', line 156 def driver=(value) @driver = value end |
Class Method Details
.name ⇒ Object
9 |
# File 'lib/shared_tools/tools/browser_tool.rb', line 9 def self.name = 'browser_tool' |
Instance Method Details
#cleanup! ⇒ Object
158 159 160 |
# File 'lib/shared_tools/tools/browser_tool.rb', line 158 def cleanup! @driver.close end |
#execute(action:, url: nil, selector: nil, value: nil, context_size: 2, full_html: false, text_content: nil) ⇒ String
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 200 201 202 203 |
# File 'lib/shared_tools/tools/browser_tool.rb', line 171 def execute(action:, url: nil, selector: nil, value: nil, context_size: 2, full_html: false, text_content: nil) # Lazily resolve driver at execute time @driver ||= default_driver case action.to_s.downcase when Action::VISIT require_param!(:url, url) visit_tool.execute(url:) when Action::PAGE_INSPECT if full_html page_inspect_tool.execute else page_inspect_tool.execute(summarize: true) end when Action::UI_INSPECT require_param!(:text_content, text_content) inspect_tool.execute(text_content:, selector:, context_size:) when Action::SELECTOR_INSPECT require_param!(:selector, selector) selector_inspect_tool.execute(selector:, context_size:) when Action::CLICK require_param!(:selector, selector) click_tool.execute(selector:) when Action::TEXT_FIELD_SET require_param!(:selector, selector) require_param!(:value, value) text_field_area_set_tool.execute(selector:, text: value) when Action::SCREENSHOT page_screenshot_tool.execute else { error: "Unsupported action: #{action}. Supported actions are: #{ACTIONS.join(', ')}" } end end |