webfetch

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package webfetch provides an HTTP fetch tool with content extraction for agent use.

Index

Constants

View Source
const (

	// ModeText extracts readable text from the HTML.
	ModeText = "text"
	// ModeHTML returns raw HTML truncated to max length.
	ModeHTML = "html"
	// ModeMarkdown returns simplified markdown.
	ModeMarkdown = "markdown"
)

Variables

View Source
var ErrBlockedURL = errors.New("URL targets a blocked internal/private network address")

ErrBlockedURL is returned when a URL targets an internal or private network address.

Functions

func BuildTools

func BuildTools() []*agent.Tool

BuildTools creates web fetch agent tools.

func ValidateURLForP2P

func ValidateURLForP2P(rawURL string) error

ValidateURLForP2P checks that a URL is safe in a P2P context. It blocks file:// schemes and URLs resolving to internal/private network addresses.

Types

type FetchResult

type FetchResult struct {
	URL           string `json:"url"`
	Title         string `json:"title"`
	Content       string `json:"content"`
	ContentLength int    `json:"content_length"`
	Truncated     bool   `json:"truncated"`
}

FetchResult holds the extracted content from a fetched web page.

func Fetch

func Fetch(ctx context.Context, rawURL string, mode string, maxLength int, p2pSafe bool) (*FetchResult, error)

Fetch downloads a web page and extracts content in the specified mode. Supported modes: "text" (default), "html" (raw HTML), "markdown" (simplified). maxLength controls the maximum character length of the returned content. When p2pSafe is true, each redirect target is validated before following.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL