search

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend added in v0.29.0

type Backend interface {
	// Search returns up to limit results for query, best first.
	Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
	// FetchPage returns the readable text content of a single URL.
	FetchPage(ctx context.Context, url string) (PageContent, error)
}

Backend is the web-search capability behind the web_search and fetch_page tools and the deep-research pipeline. NativeBackend is the only implementation; the interface remains so the tools and the pipeline depend on the capability rather than the concrete type, and so a test can substitute a fake without going to the network.

func NewFallbackBackend added in v0.29.0

func NewFallbackBackend(primary, secondary Backend) Backend

NewFallbackBackend returns a Backend that answers from primary and only reaches for secondary when primary comes back with nothing usable.

Composition lives here rather than inside either backend so the order is a wiring decision, stated once at the call site, instead of a property baked into one of them. That matters because the order has changed once already and the arguments for it are not permanent: the browser path was the default while the HTTP path was easy to block, and became the fallback once the HTTP path stopped being.

A nil secondary yields primary unchanged, which is what the non-darwin build of NewSafariBackend produces — so callers wire the chain unconditionally and the platform question stays in one place.

func NewSafariBackend added in v0.29.0

func NewSafariBackend() Backend

Safari automation is macOS-only. On every other platform there is no browser fallback to offer, so this returns nil — which NewFallbackBackend reads as "no fallback" and collapses to the primary. Callers therefore wire the chain the same way everywhere, and the platform question is answered here rather than behind a build tag at every call site.

type NativeBackend added in v0.29.0

type NativeBackend struct {
	// contains filtered or unexported fields
}

NativeBackend is ogcode's web-search backend: plain HTTP against JS-free search endpoints, plus Readability text extraction. It is compiled into the binary and needs no Node.js, no npm packages and no Chromium download.

It cannot read pages that only exist after JavaScript runs, nor hosts that bot-block plain HTTP clients (Cloudflare interstitials). Those fetches fail cleanly: the deep-research pipeline drops them and synthesises from the pages it did get.

func NewNativeBackend added in v0.29.0

func NewNativeBackend() *NativeBackend

NewNativeBackend builds a native backend with its own connection pool.

func (*NativeBackend) FetchPage added in v0.29.0

func (n *NativeBackend) FetchPage(ctx context.Context, rawURL string) (PageContent, error)

FetchPage retrieves a URL over plain HTTP and extracts its readable text.

func (*NativeBackend) Search added in v0.29.0

func (n *NativeBackend) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)

Search queries each engine in turn and returns the first non-empty result set.

type PageContent

type PageContent struct {
	URL       string `json:"url"`
	Title     string `json:"title"`
	Text      string `json:"text"`
	Truncated bool   `json:"truncated"`
}

PageContent is the extracted text of a single fetched page.

type SearchResult

type SearchResult struct {
	Title   string `json:"title"`
	URL     string `json:"url"`
	Snippet string `json:"snippet"`
}

SearchResult is one entry returned by a Backend's Search.

Jump to

Keyboard shortcuts

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