Class: RubynCode::Tools::WebFetch

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/web_fetch.rb

Constant Summary collapse

TOOL_NAME =
'web_fetch'
DESCRIPTION =
'Fetch the content of a web page and return it as text. ' \
'Useful for reading documentation, READMEs, or API docs.'
PARAMETERS =
{
  url: {
    type: :string, required: true,
    description: 'The URL to fetch (must start with http:// or https://)'
  },
  max_length: {
    type: :integer, required: false, default: 10_000,
    description: 'Maximum number of characters to return (default: 10000)'
  }
}.freeze
RISK_LEVEL =
:external
REQUIRES_CONFIRMATION =
true
MAX_REDIRECTS =
5
REDIRECT_STATUSES =
[301, 302, 303, 307, 308].freeze

Instance Attribute Summary

Attributes inherited from Base

#project_root

Instance Method Summary collapse

Methods inherited from Base

description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, summarize, to_schema, tool_name, #truncate

Constructor Details

This class inherits a constructor from RubynCode::Tools::Base

Instance Method Details

#execute(url:, max_length: 10_000) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/rubyn_code/tools/web_fetch.rb', line 29

def execute(url:, max_length: 10_000)
  validate_url!(url)
  max_length = max_length.to_i.clamp(500, 100_000)

  response = fetch_page(url)
  text = html_to_text(response.body)
  text = collapse_whitespace(text)

  format_fetched_content(url, text, max_length)
end