web

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 38 Imported by: 0 modules, 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

View Source
const (
	InUse         = "In use"
	InTurns       = "In use, taking turns"
	InSearches    = "In use for searches"
	InPages       = "In use for pages"
	Ready         = "Ready"
	FreeState     = "Free"
	NeedsKey      = "Needs an API key"
	NeedsAddress  = "Needs a server address"
	NeedsSignIn   = "Needs a sign-in"
	NeedsSettings = "Needs setup"
)

States of a service, in the words every page and command says them in

View Source
const (
	KindList    = "a list"
	KindMapping = "a mapping"
)

Kinds of JSON value a reply is read by

View Source
const BlockedPrivate = "Blocked: URL targets a private or internal network address"

Why a URL whose host is private or internal is not read

View Source
const FreeTimeout = 30 * time.Second

Longest one call to a free plan's endpoint may take

View Source
const (
	XAIOAuth = "xai-oauth"
)

Provider kinds of an xAI API key and of a Grok sign in

Variables

View Source
var ErrNoReader = errors.New("Nothing reads web pages in this build of icebath.")

Refusal of a page read where nothing reads pages, such as a build without the agent's web tools

Functions

func Address

func Address(cfg *config.Config, key, fallback string) (used, shown string)

Address of a backend the setting under the key names, its end slash cut, the fallback when it comes to none: as it is read for use, and as the settings write it, every ${NAME} kept, which is what an error or a message says in its place

func AlwaysBlocked

func AlwaysBlocked(raw string) bool

Whether the URL reaches cloud metadata, which the browser and media tools refuse whatever the private address settings say: an authority another client could read another host from, a metadata host name, or a host that is or resolves to a metadata or link local address. A URL that cannot be read is refused, a name that does not resolve is not

func CarriesSecret

func CarriesSecret(text string) bool

Whether the text carries what looks like an API key or token: a known prefix and body, not glued to more identifier characters

func Chosen

func Chosen(cfg *config.Config, key string) string

Backend a web backend setting names, lower cased, empty when unset

func Client

func Client(cfg *config.Config, timeout time.Duration, follow bool) *http.Client

HTTP client that checks every address it connects to against the same rules as SafeURL, dialing a checked address with the host name kept for TLS, and every redirect target before following it. A proxy the profile's environment sets is dialed as it is, and the authorities it trusts are those of its environment

func Credential

func Credential(providers *provider.Registry, creds *credentials.Registry, cfg *config.Config, kind string) (credentials.Credential, bool)

Credential of a kind of model provider for a web backend or tool: from the provider of that kind the profile has, the account the rotation gives with its sign-in renewed when due, else from the environment when the profile has none

func Decoded

func Decoded(contentType string, body []byte) []byte

Bytes in UTF-8 from the charset the content type names, as they are when it names UTF-8, none, or one no decoder knows

func Failure

func Failure(title, kind string, err error) string

What the model reads of a failed call to a backend: a Verbatim failure as it is, any other after the backend and what it was doing

func FakeIP

func FakeIP(cfg *config.Config, ip netip.Addr) bool

Whether the address is one a local DNS proxy of the profile answers with in place of a real one

func FreeErrorf

func FreeErrorf(format string, args ...any) error

func FreeFailure

func FreeFailure(title, kind string, err error, key, site string, others bool) string

Message of a failed free plan call naming the key that would make the service reliable, and other backends when there are

func FreeMCP

func FreeMCP(ctx context.Context, cfg *config.Config, endpoint, tool string, arguments map[string]any) (string, error)

Calls a tool of a free plan's public MCP endpoint for the profile of the settings, through its proxy, and returns the first text it answers with. Every failure, of the connection, the status or the tool, is a FreeError

func FreeOn

func FreeOn(cfg *config.Config) bool

Whether free plans may answer when a backend has no key

func GlanceCredential

func GlanceCredential(providers *provider.Registry, creds *credentials.Registry, cfg *config.Config, kind string) (credentials.Credential, bool)

Credential of a kind as Credential gives it, for a page or a standing that shows whether a backend, tool or service can be used rather than a call about to go out: the account of the provider glanced at, nothing renewed or probed while the page waits and what is due done behind, so the next look shows it

func Holds

func Holds(data []byte) bool

Whether a JSON value holds something: not null, false or zero, nor empty text, list or object

func IsFreeError

func IsFreeError(err error) bool

func Keyless

func Keyless(cfg *config.Config, name, key string) bool

Whether a call to the backend goes to its free plan: pinned free, or with no key while free plans are on, never when pinned paid

func Kind

func Kind(data []byte) string

Kind of a JSON value, as a failure names what it got

func MetadataLiteral

func MetadataLiteral(literalURL string) bool

Whether a URL that names no scheme, such as //169.254.169.254/ in a script, reaches cloud metadata by its literal host, read without DNS: an ambiguous authority, a metadata host name, or a metadata address however its numbers are spelled

func NormalizeURL

func NormalizeURL(raw string) string

URL as a request sends it: the host in IDNA ASCII and text outside ASCII in the path, query and fragment percent encoded. Anything but an http URL comes back trimmed and otherwise as it was

func Object

func Object(data []byte, v any) error

Decodes a JSON object into v, failing with what it got when the value is something else

func Origin

func Origin(message string) bool

Whether a page's error is the HTTP answer of the page itself, which no other backend would read differently

func OriginError

func OriginError(status any, reason string) string

Error naming the page's own HTTP answer when the status is 400 or above, the reason after it; empty for any other status

func Picked

func Picked(cfg *config.Config, name string) bool

Whether any web backend setting names the backend

func Private

func Private(ip netip.Addr) bool

Whether the address is in a block that is not globally reachable, for a service that sends no key to a server of this machine or network

func RenewXAI

func RenewXAI(ctx context.Context, providers *provider.Registry, creds *credentials.Registry, cfg *config.Config) error

Renews the Grok sign-in of the profile now, after xAI refused a call made with it

func SafeFor

func SafeFor(cfg *config.Config, raw string, private bool) bool

SafeURL with private and internal addresses allowed by the caller's own switch, such as the one of the browser

func SafeURL

func SafeURL(cfg *config.Config, raw string) bool

Whether the URL is http or https on a public host: not ambiguous, not cloud metadata, and resolving to no private or internal address unless Private allows those. Anything that cannot be checked is refused, but a name that does not resolve passes through a proxy, which resolves it itself

func Status

func Status(value any) (int, bool)

HTTP status a vendor gives for a page: a three digit code as a number, or as decimal text in any script

func Tier

func Tier(cfg *config.Config, name string) string

Plan pinned for the backend in web.provider_tier: free, paid, or auto

Types

type Backend

type Backend struct {
	// As web.backend names it
	Name  string
	Title string
	// What it is and what it needs
	About string
	// Settings a person sets to use it, such as its key and its address
	Settings []string
	Plans    []Plan
	// Search returns the answer, or an error that stops the call. A backend that cannot search leaves it nil
	Search func(ctx context.Context, cfg *config.Config, query string, limit int) (*Results, error)
	// Extract returns one page for each URL, or an error that failed them all. A backend that cannot read pages leaves it nil
	Extract func(ctx context.Context, cfg *config.Config, urls []string, format string) ([]*Page, error)
	// Whether it is set up, read without the network: its key or address is set, or it is chosen where choosing is enough
	Ready func(cfg *config.Config) bool
	// Whether it answers without a key on a free plan of its own
	Keyless bool
	Free    *Free
	Parser  *Parser
	// Never picked on its own, only chosen by name: its credential is there for other features too
	Explicit bool
	// Place among several set up backends when none is chosen, lowest first so paid ones win over free ones. Zero takes no place
	Rank int
	// Used when nothing else is set up or free, its errors then saying how to set one up
	Fallback bool
}

A service that answers web searches, reads pages, or both

func (Backend) FreeReady

func (b Backend) FreeReady(cfg *config.Config) bool

Whether it can answer on a free plan with the settings

func (Backend) Set

func (b Backend) Set(cfg *config.Config) bool

Whether it is set up

type Block

type Block struct {
	URL  string
	Host string
	Rule string
	// Where the rule comes from: config, or the file that holds it
	Source  string
	Message string
}

Why the website blocklist refuses a URL

func Blocked

func Blocked(cfg *config.Config, raw string) *Block

Rule of the blocklist refusing the URL, nil when it is allowed or the blocklist is off. A shared file that cannot be read adds no rules

type BlockedError

type BlockedError struct {
	Message string
}

Refusal of a connection to a private or internal address

func (*BlockedError) Error

func (e *BlockedError) Error() string

type Capability

type Capability string

What a backend is asked to do

const (
	Searching Capability = "search"
	Reading   Capability = "extract"
)

type Data

type Data struct {
	Web []Hit `json:"web"`
	// Free backend that answered in place of the one the search started at
	ServedBy string `json:"served_by,omitempty"`
	// Backend that failed the search the free ring then answered
	RescuedFrom string `json:"rescued_from,omitempty"`
	// What the failed backend said, and that the next search goes to it again
	BackendError string `json:"backend_error,omitempty"`
}

type Free

type Free struct {
	Search  func(ctx context.Context, cfg *config.Config, query string, limit int) (*Results, error)
	Extract func(ctx context.Context, cfg *config.Config, urls []string) ([]*Page, error)
	// Whether the backend's own calls go to its free plan with the settings
	Used func(cfg *config.Config) bool
	// Whether an error of the ring stops the backend's call as it is, rather than coming back as the backend's own failed search or
	// pages
	Raises bool
}

Free plan of a backend that the free ring goes round: anonymous search and page reading, for the profile of the settings, whose proxy and authorities its requests go through

type FreeError

type FreeError struct {
	Message string
}

Failure of a call to a free plan that the vendor or its endpoint reported

func (*FreeError) Error

func (e *FreeError) Error() string

type Hit

type Hit struct {
	Title       string `json:"title"`
	URL         string `json:"url"`
	Description string `json:"description"`
	Position    int    `json:"position"`
}

One search result

type Page

type Page struct {
	URL     string
	Title   string
	Content string
	Error   string
	// URL that was asked for, when the page reports the one it ended at after redirects
	Source string
	// Rule of the website blocklist that refused the page
	Blocked *Block
}

One page read, or why it could not be

func Document

func Document(url, title, content string) *Page

func Refused

func Refused(url string, status any, reason, body string) *Page

Page a vendor listed as failed: the page's own answer when the vendor gives a usable status, else what the vendor said

func Unread

func Unread(url, message string) *Page

func Unreadable

func Unreadable(urls []string, message string) []*Page

The same failure for every URL

func (*Page) WithStatus

func (p *Page) WithStatus(status any, reason string) *Page

The page marked as failed when its own answer was 400 or above, its body kept as content

type Parser

type Parser struct {
	// Whether it can read them with the settings, its key set
	Ready func(cfg *config.Config) bool
	// Markdown of the file
	Parse func(ctx context.Context, cfg *config.Config, data []byte, filename string) (string, error)
}

Reading of document files sent to a backend, such as a PDF whose pages have no text layer

type Plan

type Plan struct {
	Title string
	// Price and needs in a few words, such as "free · no key"
	Badge string
	About string
	// Plan it pins in web.provider_tier, free or paid, none when empty
	Tier string
	// Setting of the key it asks for, where to get one and what to ask
	Key    string
	Prompt string
	Link   string
	// Kind of provider whose sign-in it runs on, empty for none
	SignIn string
}

One way of using a backend offered where backends are picked

type Reader

type Reader interface {
	// Pages of the URLs in the order asked, for the session of the profile of the settings, empty for none; an error when the reading
	// failed as a whole, a page that could not be read saying why itself
	Fetch(ctx context.Context, cfg *config.Config, session string, urls []string) ([]*Page, error)
}

Registrant that reads pages for every feature of icebath the way the agent's tool that reads pages does: through the website blocklist and the checks of private addresses at every redirect, from its cache of pages, a document read as text, each page within the character budget of the tool, the whole text of a longer one saved where the agent can read it. A registrant that only reads pages implements Backends returning nil

type Registrant

type Registrant interface {
	// Backends of the profile of the settings, such as those the extensions it installed bring besides the ones every profile has
	Backends(cfg *config.Config) []Backend
}

type Registry

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

func (*Registry) Active

func (r *Registry) Active(cfg *config.Config, capability Capability) (Backend, bool)

Backend that answers the capability when it is asked for by what is set up rather than by name: the one chosen when it serves it, else the only one set up, else the first set up by rank, else a free one

func (*Registry) Available

func (r *Registry) Available(cfg *config.Config) bool

Whether some backend can answer: web_search and web_extract are offered only then

func (*Registry) Backend

func (r *Registry) Backend(cfg *config.Config, name string) (Backend, bool)

Backend of the profile of the settings with the name

func (*Registry) Backends

func (r *Registry) Backends(cfg *config.Config) []Backend

Every backend of the profile of the settings, in the order they were registered, one whose name an earlier backend has left out so an extension never shadows a built in one

func (*Registry) Choice

func (r *Registry) Choice(cfg *config.Config, capability Capability) string

Name of the backend that serves the capability: the one pinned for it, else the one chosen for both, else the first set up, else a free one, else the fallback. Empty when there is none at all

func (*Registry) Choose

func (r *Registry) Choose(cfg *config.Config, name string, use Use, plan string) (string, error)

Chooses what the service of the name is used for and its plan, clearing what the choice replaces, and answers what is in use for what now; no name leaves every choice to Automatic. A plan of auto puts it back to what its key decides, an empty one leaves it

func (*Registry) Fetch

func (r *Registry) Fetch(ctx context.Context, cfg *config.Config, session string, urls []string) ([]*Page, error)

Pages of the URLs as the first registrant that reads pages reads them, those of the registries nested in this one among them; ErrNoReader when none does

func (*Registry) FreeExtract

func (r *Registry) FreeExtract(ctx context.Context, cfg *config.Config, name string, urls []string) ([]*Page, error)

Pages read on the free ring from the backend named, going on to the next only while every page came back throttled. An error a backend returns stops the walk

func (*Registry) FreeSearch

func (r *Registry) FreeSearch(ctx context.Context, cfg *config.Config, name, query string, limit int) (*Results, error)

Search on the free ring from the backend named, going on to the next while one is throttled or refuses. An error a backend returns stops the walk

func (*Registry) InUse

func (r *Registry) InUse(cfg *config.Config) string

What answers searches and reads pages for the profile now, as one sentence

func (*Registry) Named

func (r *Registry) Named(cfg *config.Config, capability Capability) string

Backend chosen for the capability, pinned or for both, empty when none is

func (*Registry) Parse

func (r *Registry) Parse(cfg *config.Config) func(ctx context.Context, data []byte, filename string) (string, error)

Reader of document files of the first backend that can read them, when hosted reading is on; nil when none can

func (*Registry) Read

func (r *Registry) Read(cfg *config.Config) *Registry

Registry of the backends of the profile of the settings for one read of how they stand, such as the page of Web search or the check of whether the web tools are on offer: the backends found once, and each asked whether it is set up at most once however often the read asks. Other settings are read through the registry it was made from

func (*Registry) Reads

func (r *Registry) Reads() bool

Whether a registrant reads pages

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

func (*Registry) RescueExtract

func (r *Registry) RescueExtract(ctx context.Context, cfg *config.Config, name string, urls []string, pages []*Page) ([]*Page, error)

Pages the free ring reads in place of a backend that failed every one. Pages the website blocklist refused stay as they are, and when the ring fails them all as well the backend's failures stand

func (*Registry) RescueSearch

func (r *Registry) RescueSearch(ctx context.Context, cfg *config.Config, name, failure, query string, limit int) (*Results, error)

Search the free ring answers in place of the backend that failed it, saying so, else the failure of both

func (*Registry) Rescues

func (r *Registry) Rescues(cfg *config.Config, backend Backend) bool

Whether a failed call to the backend is tried once more on the free ring: rescue is on and the call did not go to the ring already

func (*Registry) Rotation

func (r *Registry) Rotation(cfg *config.Config) []Backend

Backends of the free ring that can answer now, the ring entered at its start

func (*Registry) Serving

func (r *Registry) Serving(cfg *config.Config, capability Capability) (Backend, error)

Backend that serves a call for the capability, or the error the model reads when none can

func (*Registry) Settled

func (r *Registry) Settled(cfg *config.Config, capability Capability) string

Name of the backend the settings or what is set up give the capability: the one pinned for it, else the one chosen for both, else the first set up. Empty when it is left to the free ring

func (*Registry) Standing

func (r *Registry) Standing(cfg *config.Config, backend Backend) Standing

How the service stands for the profile: what it answers now, else whether it is ready, free, or what it needs first

type Request

type Request struct {
	// GET when empty
	Method string
	URL    string
	Query  url.Values
	Header map[string]string
	// Sent as JSON when set
	Body any
	// Longest the call may take, no limit for zero
	Timeout time.Duration
	// Start of URL that a setting names, and that start as the settings write it, every ${NAME} kept: an error of the call says Shown in
	// the place of Base, so no error shows the value of a variable a setting names. Both empty for a URL no setting names
	Base, Shown string
}

One call to a web backend

type Response

type Response struct {
	Status int
	Header http.Header
	Body   []byte
	// Address that answered, after redirects
	URL string
}

func Send

func Send(ctx context.Context, cfg *config.Config, request Request) (*Response, error)

Sends the request for the profile of the settings, through the proxy and with the authorities of its environment, and reads the whole answer. Redirects are followed, the headers the call sets going only to the host it was sent to

func (*Response) Decode

func (r *Response) Decode(v any) error

Answer read as JSON into v

func (*Response) Detail

func (r *Response) Detail() string

What a failed answer said, its status when it said nothing

func (*Response) OK

func (r *Response) OK() bool

func (*Response) Text

func (r *Response) Text() string

Answer as text, read in the charset its Content-Type names, else as UTF-8

type Results

type Results struct {
	Success bool   `json:"success"`
	Data    *Data  `json:"data,omitempty"`
	Error   string `json:"error,omitempty"`
}

Answer of a search, as the model reads it

func Failed

func Failed(message string) *Results

func Found

func Found(hits []Hit) *Results

func GetJSON

func GetJSON(ctx context.Context, cfg *config.Config, label, reach string, request Request, v any) *Results

Answer of a GET read as JSON into v, else the failed search to give back: the backend could not be reached, answered with a status that is not 2xx, or not with JSON. Reach names what could not be reached, the label when empty. The request goes as Send sends it for the profile of the settings

func (*Results) Clone

func (r *Results) Clone() *Results

Independent copy

type Standing

type Standing struct {
	// Its state in the state words
	State string
	// It can answer as it is: set up, or on a free plan
	Usable bool
	// It answers searches, reads pages, and does either taking turns with the other free services
	Searching, Reading, Rotating bool
	// What a plan of it needs, when it can't answer: the setting of its key or address, and whether that is a secret
	Needs string
}

How a service stands for a profile

type Text

type Text string

JSON value read as text: a string as it is, a number or boolean as written, null as nothing, an array or object as its JSON

func (Text) String

func (t Text) String() string

func (*Text) UnmarshalJSON

func (t *Text) UnmarshalJSON(data []byte) error

type Texts

type Texts []string

Texts of a JSON list, or of a lone value, the items holding nothing left out

func (*Texts) UnmarshalJSON

func (t *Texts) UnmarshalJSON(data []byte) error

type Use

type Use int

What a service is chosen for

const (
	// Left as it is, when only the plan changes
	Unchanged Use = iota
	Both
	Searches
	Pages
)

type Verbatim

type Verbatim string

Failure whose text reaches the model as it is, a backend having worded it for the model

func (Verbatim) Error

func (v Verbatim) Error() string

type Web

type Web struct {
	Registry
}

func New

func New(cfg *config.Config) *Web

The choices of service the settings offer list those of the profile whose settings are read

type XAI

type XAI struct {
	Key     string
	BaseURL string
	// The address as the provider's setting writes it, every ${NAME} kept: what a message or a log names
	Shown string
	// Provider kind the bearer comes from, xai or XAIOAuth
	Source string
}

Bearer of a direct call to xAI and the address it goes to

func GlanceXAIBearer

func GlanceXAIBearer(providers *provider.Registry, creds *credentials.Registry, cfg *config.Config, preferKey bool) (XAI, bool)

Bearer of direct calls to xAI as XAIBearer gives it, for a page or a standing that shows whether xAI can be used rather than a call about to go out: the credential of each kind glanced at as GlanceCredential reads it

func XAIBearer

func XAIBearer(providers *provider.Registry, creds *credentials.Registry, cfg *config.Config, preferKey bool) (XAI, bool)

Bearer of direct calls to xAI: the API key first when preferred, else the Grok sign in first, the sign-in renewed when due. An address set in ICEBATH_XAI_BASE_URL or XAI_BASE_URL is used only over HTTPS on x.ai, so the bearer never leaves xAI

func XAIBearerFrom

func XAIBearerFrom(cfg *config.Config, preferKey bool, find func(kind string) (credentials.Credential, bool)) (XAI, bool)

Bearer of direct calls to xAI as XAIBearer chooses it and the address it goes to, the credential of each kind found by the way given

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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