Documentation
¶
Index ¶
- Constants
- Variables
- func BuildTools(sm *SessionManager) []*agent.Tool
- func ValidateURLForP2P(rawURL string) error
- func WithRequestState(ctx context.Context, state *RequestState) context.Context
- type ActionCandidate
- type ArticleResult
- type Config
- type ElementInfo
- type LinksResult
- type PageLink
- type PageSnapshot
- type RequestState
- type ScreenshotResult
- type SearchResponse
- type SearchResult
- type Session
- type SessionManager
- type Tool
- func (t *Tool) Click(ctx context.Context, sessionID, selector string) error
- func (t *Tool) Close() error
- func (t *Tool) CloseSession(sessionID string) error
- func (t *Tool) CurrentURL(sessionID string) (string, error)
- func (t *Tool) Eval(sessionID, script string) (interface{}, error)
- func (t *Tool) Extract(sessionID, mode string, limit int) (interface{}, error)
- func (t *Tool) GetElementInfo(sessionID, selector string) (*ElementInfo, error)
- func (t *Tool) GetSnapshot(sessionID string) (map[string]string, error)
- func (t *Tool) GetText(sessionID, selector string) (string, error)
- func (t *Tool) HasSession(sessionID string) bool
- func (t *Tool) Navigate(ctx context.Context, sessionID, url string) error
- func (t *Tool) NewSession() (string, error)
- func (t *Tool) Observe(sessionID string, limit int) ([]ActionCandidate, error)
- func (t *Tool) Screenshot(sessionID string, fullPage bool) (*ScreenshotResult, error)
- func (t *Tool) Search(ctx context.Context, sessionID, query string, limit int) (*SearchResponse, error)
- func (t *Tool) Snapshot(sessionID string, linkLimit, actionLimit int) (*PageSnapshot, error)
- func (t *Tool) Type(ctx context.Context, sessionID, selector, text string) error
- func (t *Tool) WaitForSelector(ctx context.Context, sessionID, selector string, timeout time.Duration) error
Constants ¶
const MaxSearchesPerRequest = 2
MaxSearchesPerRequest is the hard limit on browser_search calls per request. The agent gets one initial search plus one reformulation (total 2). The 3rd attempt is blocked with a structured stop response.
Variables ¶
var ErrBlockedURL = errors.New("URL targets a blocked internal/private network address")
ErrBlockedURL is returned when a URL targets an internal or private network address.
var ErrBrowserPanic = errors.New("browser panic recovered")
ErrBrowserPanic is returned when a rod/CDP panic is recovered.
var ErrEvalBlockedP2P = errors.New("eval action is not permitted for remote peer requests")
ErrEvalBlockedP2P is returned when eval is attempted from a P2P peer context.
var ErrSearchLimitReached = errors.New(
"browser_search is no longer available: search limit (2) reached — " +
"present your existing results to the user, do NOT call browser_search again",
)
ErrSearchLimitReached is returned when browser_search exceeds MaxSearchesPerRequest. The error message instructs the model to stop searching and use existing results.
Functions ¶
func BuildTools ¶ added in v0.7.0
func BuildTools(sm *SessionManager) []*agent.Tool
BuildTools creates browser agent tools backed by the given SessionManager.
func ValidateURLForP2P ¶ added in v0.7.0
ValidateURLForP2P checks that a URL is safe for navigation in a P2P context. It blocks file:// schemes and URLs that resolve to internal/private network addresses.
func WithRequestState ¶ added in v0.7.0
func WithRequestState(ctx context.Context, state *RequestState) context.Context
Types ¶
type ActionCandidate ¶ added in v0.7.0
type ActionCandidate struct {
Selector string `json:"selector"`
Tag string `json:"tag"`
Type string `json:"type,omitempty"`
Role string `json:"role,omitempty"`
Text string `json:"text,omitempty"`
Href string `json:"href,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
}
ActionCandidate is an actionable element discovered on the current page.
type ArticleResult ¶ added in v0.7.0
type ArticleResult struct {
PageType string `json:"pageType"`
Title string `json:"title"`
URL string `json:"url"`
Headings []string `json:"headings,omitempty"`
Content string `json:"content"`
Empty bool `json:"empty"`
}
ArticleResult contains structured article-like content from the current page.
type ElementInfo ¶
type ElementInfo struct {
TagName string `json:"tagName"`
ID string `json:"id,omitempty"`
ClassName string `json:"className,omitempty"`
InnerText string `json:"innerText,omitempty"`
InnerHTML string `json:"innerHTML,omitempty"`
Href string `json:"href,omitempty"`
Value string `json:"value,omitempty"`
}
ElementInfo holds element information
type LinksResult ¶ added in v0.7.0
type LinksResult struct {
Title string `json:"title"`
URL string `json:"url"`
Links []PageLink `json:"links,omitempty"`
}
LinksResult contains extracted links from the current page.
type PageLink ¶ added in v0.7.0
type PageLink struct {
Text string `json:"text"`
URL string `json:"url"`
Selector string `json:"selector,omitempty"`
}
PageLink is a structured link extracted from the current page.
type PageSnapshot ¶ added in v0.7.0
type PageSnapshot struct {
PageType string `json:"pageType"`
Title string `json:"title"`
URL string `json:"url"`
Snippet string `json:"snippet"`
ResultCount int `json:"resultCount"`
Empty bool `json:"empty"`
Headings []string `json:"headings,omitempty"`
Links []PageLink `json:"links,omitempty"`
Actions []ActionCandidate `json:"actions,omitempty"`
SearchResults []SearchResult `json:"searchResults,omitempty"`
}
PageSnapshot is a structured summary of the current page.
type RequestState ¶ added in v0.7.0
type RequestState struct {
ID string
// contains filtered or unexported fields
}
RequestState tracks browser-search churn for a single agent request.
func NewRequestState ¶ added in v0.7.0
func NewRequestState() *RequestState
func RequestStateFromContext ¶ added in v0.7.0
func RequestStateFromContext(ctx context.Context) *RequestState
func (*RequestState) CurrentURL ¶ added in v0.7.0
func (s *RequestState) CurrentURL() string
func (*RequestState) IsLimitReached ¶ added in v0.7.0
func (s *RequestState) IsLimitReached() bool
IsLimitReached reports whether the search limit has already been reached without recording a new search attempt.
func (*RequestState) RecordSearch ¶ added in v0.7.0
type ScreenshotResult ¶
type ScreenshotResult struct {
Data string `json:"data"` // base64 encoded
MimeType string `json:"mimeType"`
Width int `json:"width"`
Height int `json:"height"`
}
ScreenshotResult holds screenshot data
type SearchResponse ¶ added in v0.7.0
type SearchResponse struct {
PageType string `json:"pageType"`
Query string `json:"query,omitempty"`
Title string `json:"title"`
URL string `json:"url"`
ResultCount int `json:"resultCount"`
Empty bool `json:"empty"`
Results []SearchResult `json:"results,omitempty"`
LimitReached bool `json:"limitReached,omitempty"`
NextStep string `json:"nextStep,omitempty"`
Warning string `json:"warning,omitempty"`
}
SearchResponse is a structured response for browser-based web search.
type SearchResult ¶ added in v0.7.0
type SearchResult struct {
Title string `json:"title"`
URL string `json:"url"`
Snippet string `json:"snippet,omitempty"`
}
SearchResult is a structured web search result item.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager provides implicit session management. It auto-creates a session on first use and reuses it for subsequent calls.
func NewSessionManager ¶
func NewSessionManager(tool *Tool) *SessionManager
NewSessionManager creates a SessionManager that wraps the given Tool.
func (*SessionManager) Close ¶
func (sm *SessionManager) Close() error
Close closes the underlying browser tool and clears the session.
func (*SessionManager) EnsureSession ¶
func (sm *SessionManager) EnsureSession() (string, error)
EnsureSession returns the active session ID, creating one if none exists. On ErrBrowserPanic, it closes and reconnects once before returning an error.
func (*SessionManager) Tool ¶
func (sm *SessionManager) Tool() *Tool
Tool returns the underlying browser Tool.
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool provides browser automation
func (*Tool) CloseSession ¶
CloseSession closes a browser session
func (*Tool) CurrentURL ¶ added in v0.7.0
CurrentURL returns the current page URL for the given session.
func (*Tool) GetElementInfo ¶
func (t *Tool) GetElementInfo(sessionID, selector string) (*ElementInfo, error)
GetElementInfo gets information about an element
func (*Tool) GetSnapshot ¶
GetSnapshot returns basic page info (title and snippet)
func (*Tool) HasSession ¶
HasSession reports whether a session with the given ID exists.
func (*Tool) NewSession ¶
NewSession creates a new browser session
func (*Tool) Observe ¶ added in v0.7.0
func (t *Tool) Observe(sessionID string, limit int) ([]ActionCandidate, error)
Observe returns actionable elements from the current page.
func (*Tool) Screenshot ¶
func (t *Tool) Screenshot(sessionID string, fullPage bool) (*ScreenshotResult, error)
Screenshot captures a screenshot
func (*Tool) Search ¶ added in v0.7.0
func (t *Tool) Search(ctx context.Context, sessionID, query string, limit int) (*SearchResponse, error)
Search performs browser-native web search and returns structured results.
func (*Tool) Snapshot ¶ added in v0.7.0
func (t *Tool) Snapshot(sessionID string, linkLimit, actionLimit int) (*PageSnapshot, error)
Snapshot returns a structured summary of the current page.