Kward

Class: Kward::Tools::FetchContent

Inherits:
Base
  • Object
show all
Defined in:
lib/kward/tools/fetch_content.rb

Overview

Fetches a specific URL and extracts readable page content.

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#schema

Constructor Details

#initialize(web_fetch:) ⇒ FetchContent

Builds the tool schema and stores the execution dependency.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kward/tools/fetch_content.rb', line 11

def initialize(web_fetch:)
  @web_fetch = web_fetch
  super(
    "fetch_content",
    "Fetch a specific URL and extract readable bounded content.",
    properties: {
      url: {
        type: "string",
        description: "HTTP or HTTPS URL to fetch."
      },
      max_bytes: {
        type: "integer",
        description: "Maximum returned content bytes; default 16384, max 131072."
      },
      extract: {
        type: "string",
        enum: %w[auto text markdown],
        description: "Extraction mode; default auto."
      }
    },
    required: ["url"]
  )
end

Instance Method Details

#call(args, _conversation, cancellation: nil) ⇒ Object

Executes the tool and returns model-facing output text.



36
37
38
# File 'lib/kward/tools/fetch_content.rb', line 36

def call(args, _conversation, cancellation: nil)
  @web_fetch.fetch_content(args)
end