webfetch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Tool = tools.DefineTool("web_fetch", "Fetch a URL and return its text content. Automatically uses a headless browser if the page appears to be a JavaScript SPA.",
	map[string]any{
		"type": "object",
		"properties": map[string]any{
			"url":      map[string]any{"type": "string", "description": "URL to fetch (https:// or http://)"},
			"max_size": map[string]any{"type": "integer", "description": "Maximum bytes to return (default: 100000, max: 500000)"},
		},
		"required": []string{"url"},
	},
	func(ctx context.Context, p WebFetchParams) (string, error) {
		if err := validateAndClampURL(p.URL, &p.MaxSize); err != nil {
			return "", err
		}

		result, err := fetchHTTP(ctx, p.URL, p.MaxSize)
		if err != nil {
			return "", err
		}

		if looksLikeSPAShell(result) {
			rendered, err := renderJS(ctx, p.URL, p.MaxSize)
			if err != nil {
				return result, nil
			}
			return rendered, nil
		}

		return result, nil
	},
)

Functions

func CloseBrowser

func CloseBrowser()

Types

type WebFetchParams

type WebFetchParams struct {
	URL     string `json:"url"`
	MaxSize int    `json:"max_size,omitempty"`
}

Jump to

Keyboard shortcuts

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