Documentation
¶
Overview ¶
Package fetch implements the Web Reader's core retrieval module.
Fetch is the single deep module behind the tool: it takes a URL and returns model-friendly content. The HTTP client is injected so tests never touch the network. See CONTEXT.md for the Web Reader / Extraction vocabulary and docs/adr/ for the decisions this module honours.
Index ¶
Constants ¶
const DefaultCacheTTL = time.Hour
DefaultCacheTTL is how long a cached result stays fresh. One hour per the spec — short enough that content churn on most pages is respected, long enough to skip redundant re-fetches within a working session.
const DefaultTimeout = 30 * time.Second
DefaultTimeout is applied when Params.Timeout is zero. Per the spec it is 30 seconds — generous enough for a slow public page, short enough that a hung site never blocks the server.
Variables ¶
This section is empty.
Functions ¶
func IsInvalidURLError ¶
IsInvalidURLError reports whether err is an InvalidURLError. It is the typed check callers use rather than a brittle string comparison.
func IsTimeoutError ¶
IsTimeoutError reports whether err is a TimeoutError or wraps a context deadline-exceeded. Either form is treated as a timeout for the agent.
func IsUnsupportedContentError ¶
IsUnsupportedContentError reports whether err is an UnsupportedContentError.
Types ¶
type FetchError ¶
type FetchError struct {
Err error
}
FetchError wraps a transport-level failure (DNS, connection refused, TLS, etc.) as a structured tool-error so callers can tell it apart from HTTP status errors, content-type errors, and timeouts.
func (*FetchError) Error ¶
func (e *FetchError) Error() string
func (*FetchError) Unwrap ¶
func (e *FetchError) Unwrap() error
type HTTPClient ¶
HTTPClient is the seam at which the network is injected. It executes a fully-formed request, so the caller controls headers and method; the client only provides transport. Tests substitute a fake so no test ever reaches the network.
type HTTPError ¶
HTTPError is returned when the server responds with a non-2xx status code. It carries the status code and a short reason so the agent knows what went wrong without seeing the raw response.
type InvalidURLError ¶
type InvalidURLError struct {
URL string
}
InvalidURLError is the structured error returned for a malformed URL. It is the "invalid url" tool-error the agent receives — distinct from transport or HTTP errors so callers can tell failure modes apart.
func (*InvalidURLError) Error ¶
func (e *InvalidURLError) Error() string
type PanicError ¶
type PanicError struct {
Recovered any
}
PanicError is returned when a panic is recovered during the fetch/extract path. Surfacing it as an error keeps the server process alive (ADR-0005).
func (*PanicError) Error ¶
func (e *PanicError) Error() string
type Params ¶
Params holds the inputs to a single fetch. Timeout bounds the request (zero means use DefaultTimeout). ReturnFormat selects "markdown" (default, when empty) or "text". NoCache requests a fresh fetch that bypasses the cache.
type Result ¶
Result holds the output of a fetch. Title is the extracted article title (possibly empty for non-article pages; for raw-text documents it is the URL path basename). Content is the model-friendly markdown body — extracted by Readability, falling back to full-document markdown so the reader never returns empty. For raw-text documents Content is the decoded body verbatim (Passthrough, ADR-0006).
func Fetch ¶
Fetch retrieves the content at params.URL. It validates the URL first: a malformed, non-absolute, or non-http(s) URL returns an InvalidURLError without issuing any request.
Validated results are served from the in-memory cache keyed by (url, return_format); params.NoCache forces a fresh fetch. The request is bounded by params.Timeout (default 30s). A non-2xx response returns an HTTPError. An HTML response is extracted as today; a raw-text response (ADR-0006) is returned verbatim; any other content type returns an UnsupportedContentError. A transport failure returns a FetchError. Any panic during the fetch or extract path is recovered and returned as a PanicError, so the process never crashes (ADR-0005).
type TimeoutError ¶
type TimeoutError struct {
URL string
}
TimeoutError is returned when the fetch exceeds its deadline. Distinct from FetchError so the agent can tell "slow/unreachable" from "rejected".
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type UnsupportedContentError ¶
type UnsupportedContentError struct {
ContentType string
}
UnsupportedContentError is returned when the response is a binary or other non-text type (e.g. a PDF, image, audio/video, or generic binary) or has no Content-Type at all. HTML goes through Extraction and raw text documents go through Passthrough (ADR-0006); the remaining types are reported clearly rather than producing garbage.
func (*UnsupportedContentError) Error ¶
func (e *UnsupportedContentError) Error() string