Documentation
¶
Overview ¶
Package web contains shared contracts and utilities for the reusable web stack.
Index ¶
- Constants
- Variables
- func EnrichBrowserPermissionInput(input map[string]any, action string, currentURL string) map[string]any
- func EnrichFetchPermissionInput(input map[string]any) map[string]any
- func EnrichSearchPermissionInput(input map[string]any) map[string]any
- func EvaluatePermission(input map[string]any) types.PermissionResult
- func HostMatchesDomain(host string, domain string) bool
- func IsPreapproved(hostname string) bool
- func IsPreapprovedPath(hostname, pathname string) bool
- func NormalizeHost(host string) string
- func PermissionMatcher(input map[string]any) func(string) bool
- func RejectLocalDialTarget(ctx context.Context, address string, resolver HostResolver) error
- func RejectLocalNetworkTarget(parsed *url.URL) error
- func ResolveAndRejectLocalNetworkTarget(ctx context.Context, parsed *url.URL, resolver HostResolver) error
- type ArtifactStore
- type BrowserManager
- type CrawlPage
- type CrawlRequest
- type CrawlResponse
- type CrawlService
- type DomainCategory
- type FetchRequest
- type FetchResponse
- type FetchService
- type HostResolver
- type MapEntry
- type MapRequest
- type MapResponse
- type MapService
- type RedirectInfo
- type SearchRequest
- type SearchResponse
- type SearchResult
- type SearchService
- type TTLCache
- type TTLCacheConfig
Constants ¶
const ( // RenderModeAuto lets the fetch core choose the cheapest backend. RenderModeAuto = "auto" // RenderModeHTTP forces the HTTP fast path. RenderModeHTTP = "http" // RenderModeBrowser forces JS-rendered browser extraction. RenderModeBrowser = "browser" )
const ( // ActionFetch identifies HTTP or browser-backed page retrieval. ActionFetch = "fetch" // ActionSearch identifies outbound search requests. ActionSearch = "search" // ActionMap identifies bounded website discovery requests. ActionMap = "map" // ActionCrawl identifies bounded multi-page crawl requests. ActionCrawl = "crawl" // ActionOpen identifies browser page creation. ActionOpen = "open" ActionNavigate = "navigate" // ActionSnapshot identifies browser read-only extraction. ActionSnapshot = "snapshot" // ActionClick identifies browser interaction through a click. ActionClick = "click" // ActionType identifies browser interaction through typing. ActionType = "type" // ActionPress identifies browser interaction through keyboard presses. ActionPress = "press" // ActionScroll identifies viewport movement on the current page. ActionScroll = "scroll" // ActionWait identifies browser stabilization waits. ActionWait = "wait" // ActionScreenshot identifies visual page capture. ActionScreenshot = "screenshot" // ActionExtract identifies read-oriented extraction from the current browser page. ActionExtract = "extract" // ActionListPages identifies page enumeration inside the local browser session. ActionListPages = "list_pages" // ActionNetworkList identifies read-only browser network inspection. ActionNetworkList = "network_list" // ActionDownloadList identifies read-only browser download inspection. ActionDownloadList = "list_downloads" // ActionNetworkPolicy identifies read-only browser network policy inspection. ActionNetworkPolicy = "network_policy" // ActionSetNetworkPolicy identifies local browser request-policy mutation. ActionSetNetworkPolicy = "set_network_policy" // ActionSearchContent identifies read-only search over stored browser snapshots. ActionSearchContent = "search_content" // ActionSelectPage identifies active page switching inside the local browser session. ActionSelectPage = "select_page" // ActionClosePage identifies page closure inside the local browser session. ActionClosePage = "close_page" )
const ( // CategoryRead is a non-mutating content retrieval action. CategoryRead = "read" // CategorySearch is a query-oriented discovery action. CategorySearch = "search" CategoryNavigate = "navigate" // CategoryInteract performs a user-like page interaction. CategoryInteract = "interact" // CategorySession mutates only ephemeral local browser session state. CategorySession = "session" )
Variables ¶
var PreapprovedHosts = map[string]bool{}/* 445 elements not displayed */
PreapprovedHosts enumerates hosts that are safe to access without extra prompts.
var PreapprovedPathPrefixes = map[string][]string{
"github.com": {"/anthropics"},
}
PreapprovedPathPrefixes contains host/path combinations that are allowed more narrowly than the full host.
Functions ¶
func EnrichBrowserPermissionInput ¶
func EnrichBrowserPermissionInput(input map[string]any, action string, currentURL string) map[string]any
EnrichBrowserPermissionInput normalizes browser tool inputs and optionally attaches the current page URL.
func EnrichFetchPermissionInput ¶
EnrichFetchPermissionInput normalizes fetch tool inputs into a stable permission shape.
func EnrichSearchPermissionInput ¶
EnrichSearchPermissionInput normalizes search tool inputs into a stable permission shape.
func EvaluatePermission ¶
func EvaluatePermission(input map[string]any) types.PermissionResult
EvaluatePermission applies lightweight shared web policy before the global permission pipeline runs.
func HostMatchesDomain ¶
HostMatchesDomain centralizes host/domain matching for filtering and permission logic.
func IsPreapproved ¶
IsPreapproved reports whether the hostname is globally preapproved.
func IsPreapprovedPath ¶
IsPreapprovedPath reports whether a hostname/path pair is preapproved by either host-wide or path-scoped rules.
func NormalizeHost ¶
NormalizeHost strips superficial hostname differences before policy checks.
func PermissionMatcher ¶
PermissionMatcher compiles a shared matcher used by content-specific permission rules.
func RejectLocalDialTarget ¶
func RejectLocalDialTarget(ctx context.Context, address string, resolver HostResolver) error
RejectLocalDialTarget validates a host:port dial target before a transport opens a socket. This closes the gap where a public hostname resolves to a private address after initial URL validation.
func RejectLocalNetworkTarget ¶
RejectLocalNetworkTarget blocks obvious SSRF-style targets before any network work starts. This fast path still checks only the literal host so lightweight normalization can reject obviously local targets before any DNS work starts.
func ResolveAndRejectLocalNetworkTarget ¶
func ResolveAndRejectLocalNetworkTarget(ctx context.Context, parsed *url.URL, resolver HostResolver) error
ResolveAndRejectLocalNetworkTarget hardens SSRF protection by resolving the hostname and rejecting any target that resolves to loopback, private, or local network addresses.
Types ¶
type ArtifactStore ¶
type ArtifactStore = storage.ArtifactStore
ArtifactStore exposes persisted blob storage to reusable web services without coupling them to a provider.
type BrowserManager ¶
type BrowserManager = browsercore.Manager
BrowserManager exposes the shared browser runtime without tying callers to a concrete implementation.
type CrawlPage ¶
type CrawlPage struct {
URL string
FinalURL string
Depth int
Mode string
Content string
PersistedPath string
PersistedSize int
}
CrawlPage represents one crawled page.
type CrawlRequest ¶
type CrawlRequest struct {
URL string
SessionID types.SessionID
MaxPages int
MaxDepth int
RenderMode string
IncludeSubdomains bool
IncludePatterns []string
ExcludePatterns []string
}
CrawlRequest describes a bounded multi-page collection request.
type CrawlResponse ¶
CrawlResponse is the normalized output shape shared by crawl callers.
type CrawlService ¶
type CrawlService interface {
Crawl(ctx context.Context, request CrawlRequest) (CrawlResponse, error)
}
CrawlService represents the reusable crawl core exposed from internal/web.
type DomainCategory ¶
type DomainCategory struct {
ID string `json:"id"`
Label string `json:"label"`
Icon string `json:"icon"`
Domains []string `json:"domains"`
}
DomainCategory groups related domains for the frontend domain catalog UI.
func DomainCatalog ¶
func DomainCatalog() []DomainCategory
DomainCatalog returns the curated pre-approved domain list organized by category.
type FetchRequest ¶
FetchRequest is the common input shape for reusable web fetch services.
type FetchResponse ¶
type FetchResponse struct {
Content string
Bytes int
Code int
CodeText string
ContentType string
FinalURL string
PersistedPath string
PersistedSize int
BrowserRecommended bool
Mode string
Redirect *RedirectInfo
}
FetchResponse is the normalized output shape shared by fetch callers.
type FetchService ¶
type FetchService interface {
Fetch(ctx context.Context, request FetchRequest) (FetchResponse, error)
}
FetchService represents the reusable fetch core exposed from internal/web.
type HostResolver ¶
type HostResolver interface {
LookupNetIP(ctx context.Context, network string, host string) ([]netip.Addr, error)
}
HostResolver abstracts hostname resolution so network policy can be tested and reused by HTTP fetch, crawl, and future browser transports.
func DefaultResolver ¶
func DefaultResolver() HostResolver
DefaultResolver is the process-wide DNS resolver used when no explicit resolver is supplied by a web subsystem.
type MapRequest ¶
MapRequest describes a bounded website discovery request.
type MapResponse ¶
MapResponse is the normalized output shape shared by map callers.
type MapService ¶
type MapService interface {
Map(ctx context.Context, request MapRequest) (MapResponse, error)
}
MapService represents the reusable map core exposed from internal/web.
type RedirectInfo ¶
type RedirectInfo struct {
Type string `json:"type"`
OriginalURL string `json:"originalUrl"`
RedirectURL string `json:"redirectUrl"`
StatusCode int `json:"statusCode"`
}
RedirectInfo signals that a host-changing redirect should be explicitly followed by the caller.
type SearchRequest ¶
SearchRequest is the common input shape for reusable web search services.
type SearchResponse ¶
type SearchResponse struct {
Query string
Results []SearchResult
Provider string
DurationSeconds float64
}
SearchResponse is the normalized output shape shared by search callers.
type SearchResult ¶
SearchResult is a provider-agnostic search hit used across wrappers and services.
type SearchService ¶
type SearchService interface {
Search(ctx context.Context, request SearchRequest) (SearchResponse, error)
}
SearchService represents the reusable search core exposed from internal/web.
type TTLCache ¶
type TTLCache[V any] struct { // contains filtered or unexported fields }
TTLCache is a generic in-memory cache with simple oldest-expiry eviction.
func NewTTLCache ¶
func NewTTLCache[V any](config TTLCacheConfig) *TTLCache[V]
NewTTLCache creates a new shared cache with pragmatic defaults if values are omitted.
type TTLCacheConfig ¶
TTLCacheConfig configures a lightweight in-memory TTL cache shared by web subsystems.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package browser provides the shared local browser runtime used by Seshat tools and sessions.
|
Package browser provides the shared local browser runtime used by Seshat tools and sessions. |
|
Package fetch contains the reusable web fetch core shared by browser- and tool-facing adapters.
|
Package fetch contains the reusable web fetch core shared by browser- and tool-facing adapters. |
|
Package search contains the reusable web search core shared by tool wrappers.
|
Package search contains the reusable web search core shared by tool wrappers. |
|
Package searxng provides a full-featured SearXNG search client for Go, mirroring the mcp-searxng TypeScript server (src/search.ts).
|
Package searxng provides a full-featured SearXNG search client for Go, mirroring the mcp-searxng TypeScript server (src/search.ts). |