/** * Intelligence Handlers * * MCP tool handlers for AI browser tools integration. * These handlers provide intelligence to LLMs that control their own browsers * (like Claude-in-Chrome, browser-use, etc.) without requiring Unbrowser * to do the actual browsing. * * The key insight: LLMs with browser access should try Unbrowser FIRST * before opening a browser window. Unbrowser can often provide the data * directly via cached results, discovered APIs, or direct HTTP fetches. */ import { type McpResponse } from '../response-formatters.js'; /** * Response indicating whether Unbrowser could fulfill the request * or if the LLM should use its own browser */ export interface IntelligenceResponse { /** Did we successfully get the data? */ success: boolean; /** How we got the data (or why we couldn't) */ source: 'cache' | 'api' | 'fetch' | 'unavailable'; /** The content (if successful) */ content?: { title?: string; markdown?: string; text?: string; structured?: Record; }; /** If we couldn't get it, guidance for the LLM's browser */ fallback?: { reason: 'requires_auth' | 'requires_interaction' | 'blocked' | 'dynamic_content' | 'unknown'; suggestion: string; }; /** Hints to help the LLM browse more effectively */ browserHints?: { waitForSelector?: string; rateLimit?: number; requiredHeaders?: Record; avoidSelectors?: string[]; knownSelectors?: Record; antiBot?: { type: string; severity: string; }; }; /** Metadata about the response */ meta: { domain: string; hasLearnedPatterns: boolean; patternConfidence?: number; fetchDuration?: number; cachedAt?: string; }; } /** * Domain check response - what we know about a URL before browsing */ export interface DomainCheckResponse { domain: string; url: string; /** Can Unbrowser likely get this data without browser automation? */ canFetchDirectly: boolean; /** Why or why not */ reason: string; /** What we know about this domain */ knowledge: { hasLearnedPatterns: boolean; patternCount: number; templateType?: string; successRate?: number; lastSeen?: string; }; /** Site-specific quirks we've learned */ quirks?: { rateLimit?: number; requiresAuth?: boolean; hasAntiBot?: boolean; antiBotType?: string; }; /** Recommendations for browsing */ recommendations: string[]; /** Known selectors that work on this site */ knownSelectors?: Record; } /** * Arguments for unbrowser_get tool */ export interface UnbrowserGetArgs { url: string; extract?: 'auto' | 'product' | 'article' | 'structured' | 'markdown' | 'text'; maxAge?: number; timeout?: number; } /** * Arguments for unbrowser_check tool */ export interface UnbrowserCheckArgs { url: string; } /** * Handle unbrowser_get tool call * * Attempts to get content from a URL without browser automation. * Returns the content if successful, or guidance for browser automation if not. */ export declare function handleUnbrowserGet(args: UnbrowserGetArgs): Promise; /** * Handle unbrowser_check tool call * * Returns what Unbrowser knows about a URL/domain without fetching. * Useful for LLMs to decide whether to try unbrowser_get or go straight to browser. */ export declare function handleUnbrowserCheck(args: UnbrowserCheckArgs): Promise; /** * Clear the response cache (for testing) */ export declare function clearIntelligenceCache(): void; //# sourceMappingURL=intelligence-handlers.d.ts.map