Documentation
¶
Overview ¶
Package web defines provider-neutral web search and page-fetching tools.
Searcher and Fetcher are independent capabilities because not every provider supports both. A provider client may implement either or both; each provider owns one package and one transport client. NewSearchTool and NewFetchTool adapt those capabilities to the core tool contract.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingFetchRequest = errors.New("web: fetch request must not be nil") ErrEmptyURL = errors.New("web: fetch URL must not be empty") ErrInvalidURL = errors.New("web: fetch URL must be an absolute http(s) URL") ErrInvalidFormat = errors.New("web: content format must be markdown, html, or text") ErrMissingFetcher = errors.New("web: fetcher is required") ErrMissingFetchResponse = errors.New("web: fetch response must not be nil") ErrInvalidFetchResponse = errors.New("web: fetch response is invalid") ErrUnsupportedFormat = errors.New("web: content format is not supported by provider") )
var ( ErrMissingSearchRequest = errors.New("web: search request must not be nil") ErrEmptyQuery = errors.New("web: search query must not be empty") ErrDomainsBothSides = errors.New("web: allowed_domains and blocked_domains are mutually exclusive") ErrInvalidMaxResults = errors.New("web: max_results must be between 1 and 20 when set") ErrTooManyDomains = errors.New("web: at most 20 allowed_domains or blocked_domains may be set") ErrInvalidDomain = errors.New("web: domain filter must be a bare hostname without scheme, port, path, query, or fragment") ErrInvalidRecency = errors.New("web: recency must be hour, day, week, month, or year") ErrMissingSearcher = errors.New("web: searcher is required") ErrMissingSearchResponse = errors.New("web: search response must not be nil") ErrInvalidSearchResponse = errors.New("web: search response is invalid") ErrUnsupportedFilter = errors.New("web: search filter is not supported by provider") )
Functions ¶
This section is empty.
Types ¶
type ContentFormat ¶
type ContentFormat string
const ( // FormatMarkdown is the default format. FormatMarkdown ContentFormat = "markdown" FormatHTML ContentFormat = "html" FormatText ContentFormat = "text" )
func (ContentFormat) Normalize ¶ added in v0.24.0
func (c ContentFormat) Normalize() (ContentFormat, error)
func (ContentFormat) Validate ¶
func (c ContentFormat) Validate() error
type FetchRequest ¶
type FetchRequest struct {
URL string `json:"url" jsonschema:"minLength=1" jsonschema_description:"Absolute http(s) URL of the page to fetch."`
// Format selects the response format. "" defaults to markdown.
Format ContentFormat `` /* 178-byte string literal not displayed */
}
func (*FetchRequest) Prepare ¶
func (f *FetchRequest) Prepare() (*FetchRequest, error)
Prepare returns a normalized and validated request without mutating f.
func (*FetchRequest) Validate ¶
func (f *FetchRequest) Validate() error
type FetchResponse ¶
type FetchResponse struct {
Content string `json:"content"`
Format ContentFormat `json:"format"`
}
func (*FetchResponse) Validate ¶
func (f *FetchResponse) Validate() error
type FetchTool ¶
type FetchTool struct {
// contains filtered or unexported fields
}
func NewFetchTool ¶
func (FetchTool) Call ¶
func (r FetchTool) Call(ctx context.Context, invocation toolcontract.Invocation) (chat.ToolOutput, error)
func (FetchTool) ConcurrencyPolicy ¶ added in v0.19.0
func (FetchTool) ConcurrencyPolicy() func(toolcontract.Invocation) (string, bool)
func (FetchTool) Definition ¶
func (r FetchTool) Definition() chat.ToolDefinition
func (FetchTool) Unwrap ¶ added in v0.19.0
func (r FetchTool) Unwrap() toolcontract.Tool
type Fetcher ¶
type Fetcher interface {
// Fetch retrieves and renders exactly request.URL in the requested format
// without mutating or retaining request. Implementations must honor ctx,
// preserve network error causes, and transfer response ownership to the
// caller.
Fetch(ctx context.Context, request *FetchRequest) (*FetchResponse, error)
}
Fetcher is the provider boundary behind the model-facing page fetch tool. Network authority, authentication, redirects, and provider defaults are frozen in the implementation rather than supplied by model arguments. Implementations must support concurrent calls, including calls through other tools sharing the same backend; fetch tools advertise parallel use.
type Recency ¶
type Recency string
Recency expresses a relative freshness window shared across backends.
type SearchRequest ¶
type SearchRequest struct {
Query string `` /* 155-byte string literal not displayed */
// Zero selects the configured provider default.
MaxResults int `` /* 187-byte string literal not displayed */
AllowedDomains []string `` /* 202-byte string literal not displayed */
BlockedDomains []string `` /* 197-byte string literal not displayed */
// Recency filters to a coarse time-window. "" = no time filter.
Recency Recency `` /* 167-byte string literal not displayed */
}
func (*SearchRequest) Prepare ¶
func (s *SearchRequest) Prepare() (*SearchRequest, error)
Prepare returns an independently owned, normalized request after validating it. The receiver is never mutated.
func (*SearchRequest) QueryWithSiteOperators ¶
func (s *SearchRequest) QueryWithSiteOperators() string
QueryWithSiteOperators returns Query with Google-style site:/-site: operators for the request's domain filters. Providers without native domain fields use this projection. Allowed domains form an OR group; every blocked domain is excluded. Empty domain entries are ignored.
func (*SearchRequest) Validate ¶
func (s *SearchRequest) Validate() error
type SearchResponse ¶
type SearchResponse struct {
Query string `json:"query"`
Results []*SearchResult `json:"results"`
}
func (*SearchResponse) Validate ¶
func (s *SearchResponse) Validate() error
type SearchResult ¶
type SearchTool ¶
type SearchTool struct {
// contains filtered or unexported fields
}
func NewSearchTool ¶
func NewSearchTool(searcher Searcher) (*SearchTool, error)
func (SearchTool) Call ¶
func (r SearchTool) Call(ctx context.Context, invocation toolcontract.Invocation) (chat.ToolOutput, error)
func (SearchTool) ConcurrencyPolicy ¶ added in v0.19.0
func (SearchTool) ConcurrencyPolicy() func(toolcontract.Invocation) (string, bool)
func (SearchTool) Definition ¶
func (r SearchTool) Definition() chat.ToolDefinition
func (SearchTool) Unwrap ¶ added in v0.19.0
func (r SearchTool) Unwrap() toolcontract.Tool
type Searcher ¶
type Searcher interface {
// Search performs one request without mutating or retaining it and transfers
// ownership of a normalized response to the caller. Implementations must
// honor ctx, preserve provider error causes, and reject unsupported explicit
// fields instead of silently ignoring them.
Search(ctx context.Context, request *SearchRequest) (*SearchResponse, error)
}
Searcher is the provider boundary behind the model-facing search tool. It receives only the normalized provider-neutral contract; authentication, endpoint selection, and provider defaults are frozen in the implementation. Implementations must support concurrent calls, including calls through other tools sharing the same backend; search tools advertise parallel use.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package brave wires Brave's Web Search API into web.Searcher.
|
Package brave wires Brave's Web Search API into web.Searcher. |
|
Package exa integrates Exa's Search and Contents APIs with the provider-neutral web contracts.
|
Package exa integrates Exa's Search and Contents APIs with the provider-neutral web contracts. |
|
Package firecrawl integrates Firecrawl's Search and Scrape APIs with the provider-neutral web contracts.
|
Package firecrawl integrates Firecrawl's Search and Scrape APIs with the provider-neutral web contracts. |
|
Package jina integrates Jina Search and Jina Reader with the provider-neutral web contracts.
|
Package jina integrates Jina Search and Jina Reader with the provider-neutral web contracts. |
|
Package perplexity wires Perplexity's Search API into web.Searcher.
|
Package perplexity wires Perplexity's Search API into web.Searcher. |
|
Package serper wires Serper's Google Search API into web.Searcher.
|
Package serper wires Serper's Google Search API into web.Searcher. |
|
Package tavily integrates Tavily Search and Extract with the provider-neutral web contracts.
|
Package tavily integrates Tavily Search and Extract with the provider-neutral web contracts. |