fetch

package
v0.0.0-...-6c5c7c9 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderExa        = "exa"
	ProviderDirect     = "direct"
	DefaultTimeoutSecs = 30
	DefaultMaxChars    = 50_000
)

Variables

View Source
var DefaultFallbackOrder = []string{
	ProviderExa,
	ProviderDirect,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Provider  string   `yaml:"provider"`
	Fallbacks []string `yaml:"fallbacks"`

	Exa    ExaConfig    `yaml:"exa"`
	Direct DirectConfig `yaml:"direct"`
}

Config controls fetch provider selection and credentials.

func ApplyEnvDefaults

func ApplyEnvDefaults(cfg *Config) *Config

ApplyEnvDefaults fills empty config fields from environment variables.

func ConfigFromEnv

func ConfigFromEnv() *Config

ConfigFromEnv builds a fetch config using environment variables.

func (*Config) WithDefaults

func (c *Config) WithDefaults() *Config

type DirectConfig

type DirectConfig struct {
	Enabled      *bool  `yaml:"enabled"`
	TimeoutSecs  int    `yaml:"timeout_seconds"`
	UserAgent    string `yaml:"user_agent"`
	Readability  bool   `yaml:"readability"`
	MaxChars     int    `yaml:"max_chars"`
	MaxRedirects int    `yaml:"max_redirects"`
	CacheTtlSecs int    `yaml:"cache_ttl_seconds"`
}

type ExaConfig

type ExaConfig struct {
	Enabled           *bool  `yaml:"enabled"`
	BaseURL           string `yaml:"base_url"`
	APIKey            string `yaml:"api_key"`
	IncludeText       bool   `yaml:"include_text"`
	TextMaxCharacters int    `yaml:"text_max_chars"`
}

type Provider

type Provider interface {
	Name() string
	Fetch(ctx context.Context, req Request) (*Response, error)
}

Provider fetches readable content for a given backend.

type Registry

type Registry = registry.Registry[Provider]

Registry is an alias for a generic registry of fetch providers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty registry.

type Request

type Request struct {
	URL         string
	ExtractMode string // "markdown" or "text"
	MaxChars    int
}

Request represents a normalized fetch request.

type Response

type Response struct {
	URL           string
	FinalURL      string
	Status        int
	ContentType   string
	ExtractMode   string
	Extractor     string
	Truncated     bool
	Length        int
	RawLength     int
	WrappedLength int
	FetchedAt     string
	TookMs        int64
	Text          string
	Warning       string
	Cached        bool
	Provider      string
	Extras        map[string]any
}

Response represents normalized fetch output.

func Fetch

func Fetch(ctx context.Context, req Request, cfg *Config) (*Response, error)

Fetch executes a fetch using the configured provider chain.

Jump to

Keyboard shortcuts

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