Documentation
¶
Index ¶
- Constants
- Variables
- func Address(cfg *config.Config, key, fallback string) (used, shown string)
- func AlwaysBlocked(raw string) bool
- func CarriesSecret(text string) bool
- func Chosen(cfg *config.Config, key string) string
- func Client(cfg *config.Config, timeout time.Duration, follow bool) *http.Client
- func Credential(providers *provider.Registry, creds *credentials.Registry, cfg *config.Config, ...) (credentials.Credential, bool)
- func Decoded(contentType string, body []byte) []byte
- func Failure(title, kind string, err error) string
- func FakeIP(cfg *config.Config, ip netip.Addr) bool
- func FreeErrorf(format string, args ...any) error
- func FreeFailure(title, kind string, err error, key, site string, others bool) string
- func FreeMCP(ctx context.Context, cfg *config.Config, endpoint, tool string, ...) (string, error)
- func FreeOn(cfg *config.Config) bool
- func GlanceCredential(providers *provider.Registry, creds *credentials.Registry, cfg *config.Config, ...) (credentials.Credential, bool)
- func Holds(data []byte) bool
- func IsFreeError(err error) bool
- func Keyless(cfg *config.Config, name, key string) bool
- func Kind(data []byte) string
- func MetadataLiteral(literalURL string) bool
- func NormalizeURL(raw string) string
- func Object(data []byte, v any) error
- func Origin(message string) bool
- func OriginError(status any, reason string) string
- func Picked(cfg *config.Config, name string) bool
- func Private(ip netip.Addr) bool
- func RenewXAI(ctx context.Context, providers *provider.Registry, creds *credentials.Registry, ...) error
- func SafeFor(cfg *config.Config, raw string, private bool) bool
- func SafeURL(cfg *config.Config, raw string) bool
- func Status(value any) (int, bool)
- func Tier(cfg *config.Config, name string) string
- type Backend
- type Block
- type BlockedError
- type Capability
- type Data
- type Free
- type FreeError
- type Hit
- type Page
- type Parser
- type Plan
- type Reader
- type Registrant
- type Registry
- func (r *Registry) Active(cfg *config.Config, capability Capability) (Backend, bool)
- func (r *Registry) Available(cfg *config.Config) bool
- func (r *Registry) Backend(cfg *config.Config, name string) (Backend, bool)
- func (r *Registry) Backends(cfg *config.Config) []Backend
- func (r *Registry) Choice(cfg *config.Config, capability Capability) string
- func (r *Registry) Choose(cfg *config.Config, name string, use Use, plan string) (string, error)
- func (r *Registry) Fetch(ctx context.Context, cfg *config.Config, session string, urls []string) ([]*Page, error)
- func (r *Registry) FreeExtract(ctx context.Context, cfg *config.Config, name string, urls []string) ([]*Page, error)
- func (r *Registry) FreeSearch(ctx context.Context, cfg *config.Config, name, query string, limit int) (*Results, error)
- func (r *Registry) InUse(cfg *config.Config) string
- func (r *Registry) Named(cfg *config.Config, capability Capability) string
- func (r *Registry) Parse(cfg *config.Config) func(ctx context.Context, data []byte, filename string) (string, error)
- func (r *Registry) Read(cfg *config.Config) *Registry
- func (r *Registry) Reads() bool
- func (r *Registry) Register(registrant Registrant)
- func (r *Registry) RescueExtract(ctx context.Context, cfg *config.Config, name string, urls []string, ...) ([]*Page, error)
- func (r *Registry) RescueSearch(ctx context.Context, cfg *config.Config, name, failure, query string, ...) (*Results, error)
- func (r *Registry) Rescues(cfg *config.Config, backend Backend) bool
- func (r *Registry) Rotation(cfg *config.Config) []Backend
- func (r *Registry) Serving(cfg *config.Config, capability Capability) (Backend, error)
- func (r *Registry) Settled(cfg *config.Config, capability Capability) string
- func (r *Registry) Standing(cfg *config.Config, backend Backend) Standing
- type Request
- type Response
- type Results
- type Standing
- type Text
- type Texts
- type Use
- type Verbatim
- type Web
- type XAI
Constants ¶
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
const ( KindList = "a list" KindMapping = "a mapping" )
Kinds of JSON value a reply is read by
const BlockedPrivate = "Blocked: URL targets a private or internal network address"
Why a URL whose host is private or internal is not read
const FreeTimeout = 30 * time.Second
Longest one call to a free plan's endpoint may take
const (
XAIOAuth = "xai-oauth"
)
Provider kinds of an xAI API key and of a Grok sign in
Variables ¶
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 ¶
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 ¶
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 ¶
Whether the text carries what looks like an API key or token: a known prefix and body, not glued to more identifier characters
func 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 ¶
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 ¶
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 ¶
Whether the address is one a local DNS proxy of the profile answers with in place of a real one
func FreeErrorf ¶
func FreeFailure ¶
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 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 ¶
Whether a JSON value holds something: not null, false or zero, nor empty text, list or object
func IsFreeError ¶
func Keyless ¶
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 MetadataLiteral ¶
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 ¶
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 ¶
Decodes a JSON object into v, failing with what it got when the value is something else
func Origin ¶
Whether a page's error is the HTTP answer of the page itself, which no other backend would read differently
func OriginError ¶
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 Private ¶
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 ¶
SafeURL with private and internal addresses allowed by the caller's own switch, such as the one of the browser
func SafeURL ¶
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
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
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
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
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 Refused ¶
Page a vendor listed as failed: the page's own answer when the vendor gives a usable status, else what the vendor said
func Unreadable ¶
The same failure for every URL
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 Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Active ¶
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 ¶
Whether some backend can answer: web_search and web_extract are offered only then
func (*Registry) Backends ¶
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 ¶
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) 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 ¶
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) 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 ¶
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 ¶
Backends of the free ring that can answer now, the ring entered at its start
func (*Registry) Serving ¶
Backend that serves a call for the capability, or the error the model reads when none can
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 ¶
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
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 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
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) UnmarshalJSON ¶
type Texts ¶
type Texts []string
Texts of a JSON list, or of a lone value, the items holding nothing left out
func (*Texts) UnmarshalJSON ¶
type Verbatim ¶
type Verbatim string
Failure whose text reaches the model as it is, a backend having worded it for the model
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