extract

package
v0.8.20 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 27 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeURL

func NormalizeURL(raw string) string

NormalizeURL defaults a missing scheme to https so callers can pass a bare host

Types

type Config

type Config struct {
	Enabled              bool          `json:"enabled" mapstructure:"enabled"`
	DefaultMode          string        `json:"default_mode" mapstructure:"default_mode"`
	Timeout              time.Duration `json:"timeout" mapstructure:"timeout"`
	MaxBytes             int           `json:"max_bytes" mapstructure:"max_bytes"`
	MaxConcurrent        int           `json:"max_concurrent" mapstructure:"max_concurrent"`
	AllowPrivateNetworks bool          `json:"allow_private_networks" mapstructure:"allow_private_networks"`
}

func DefaultConfig

func DefaultConfig() Config

func (Config) BatchTimeout

func (c Config) BatchTimeout(count int) time.Duration

BatchTimeout derives the wall-clock ceiling for enriching one search response (extract=true) from the per-URL budget. Workers run in ceil(count/MaxConcurrent) waves; each worker's worst case is a raw fetch plus a rendered escalation, so a single Extract is bounded by 2*Timeout. This keeps the batch bound an explicit consequence of Timeout rather than a separate knob that can drift out of sync.

func (Config) Normalized

func (c Config) Normalized() Config

type ExtractMeta

type ExtractMeta struct {
	ModeUsed  string `json:"mode_used"`
	FetchedAt string `json:"fetched_at"`
	Bytes     int    `json:"bytes"`
	TookMs    int64  `json:"took_ms"`
}

type ExtractRequest

type ExtractRequest struct {
	URL      string
	Mode     Mode
	ProxyURL string
	LangCode string
	Timeout  time.Duration
	MaxBytes int
	// FullPage selects whole-readable-body extraction instead of the default
	// article-only (trafilatura) extraction. LLM agents fetching arbitrary URLs
	// often want the full page; FullPage keeps nav/feature/landing content that
	// trafilatura strips. The zero value (false) preserves the cleaned default.
	FullPage bool
	// PreserveStructure converts the page's content container as-is instead of
	// running article detection: <main>, or a known reference layout (DocBook,
	// Texinfo, Apache httpd; <body> for man pages). Headings, code blocks and
	// API signatures survive, and so do menus inside that container. Falls back
	// to article detection when there is no container or it lacks structure.
	// FullPage takes precedence.
	PreserveStructure bool
	// UseLLMSTxt, when set and the URL is a site root, probes /llms-full.txt then
	// /llms.txt and returns that LLM-optimized markdown instead of scraping HTML.
	UseLLMSTxt bool
	// MinRunes is the per-request auto-mode escalation floor: raw output below
	// this many extracted-text runes escalates to a render. 0 uses defaultMinRunes.
	MinRunes int
}

type ExtractResult

type ExtractResult struct {
	URL         string            `json:"url"`
	Title       string            `json:"title"`
	Description string            `json:"description"`
	Markdown    string            `json:"markdown"`
	Text        string            `json:"text"`
	Headings    []Heading         `json:"headings,omitempty"`
	Links       []Link            `json:"links,omitempty"`
	Canonical   string            `json:"canonical,omitempty"`
	Lang        string            `json:"lang,omitempty"`
	SchemaOrg   []json.RawMessage `json:"schema_org,omitempty"`
	OGTags      map[string]string `json:"og_tags,omitempty"`
	Meta        ExtractMeta       `json:"meta"`
}

type Extractor

type Extractor struct {
	RawFetch      RawFetcher
	RenderedFetch RenderedFetcher
	Cfg           Config
}

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, req ExtractRequest) (*ExtractResult, error)

type FetchResponse

type FetchResponse struct {
	StatusCode int
	Body       []byte
	// FinalURL is the document URL after redirects. Empty uses the request URL.
	FinalURL string
	// Truncated means Body was cut at the byte budget. HTML survives that, PDFs do not.
	Truncated bool
}

type Heading

type Heading struct {
	Level int    `json:"level"`
	Text  string `json:"text"`
}
type Link struct {
	Text string `json:"text"`
	URL  string `json:"url"`
}

type Mode

type Mode string
const (
	ModeAuto     Mode = "auto"
	ModeFast     Mode = "fast"
	ModeRendered Mode = "rendered"
)

type RawFetcher

type RawFetcher func(ctx context.Context, req ExtractRequest) (*FetchResponse, error)

type RenderedFetcher

type RenderedFetcher func(ctx context.Context, req ExtractRequest) (*FetchResponse, error)

Jump to

Keyboard shortcuts

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