/** * Smart DOM Search with Levenshtein Distance * * Searches elements by text, classes, aria-labels, values, etc. * Uses spoken-word IDs (e.g., "apple_banana") for easy interaction * IDs are deterministically generated from XPath for consistency */ /** * Levenshtein search options */ export interface LevenshteinSearchOptions { /** Maximum Levenshtein distance (lower = stricter, default: 3) */ maxDistance?: number; /** Minimum similarity score 0-1 (higher = stricter, default: 0.6) */ minSimilarity?: number; /** Maximum results to return (default: 10) */ maxResults?: number; /** Search in class names (default: true) */ searchClasses?: boolean; /** Search in element IDs (default: true) */ searchIds?: boolean; /** Search in text content (default: true) */ searchText?: boolean; /** Search in placeholders (default: true) */ searchPlaceholders?: boolean; /** Search in aria labels (default: true) */ searchAriaLabels?: boolean; /** Search in element values - inputs, selects, radio buttons, etc. (default: true) */ searchValues?: boolean; /** Only return interactive elements (default: false) */ requireInteractive?: boolean; /** Only return visible elements (default: true) */ requireVisible?: boolean; /** Filter by tag name (e.g., 'button', 'input') */ tag?: string; } /** * Search result element */ export interface SearchResultElement { /** Spoken-word ID for interaction (e.g., "apple_banana") */ id: string; /** HTML tag name */ tag: string; /** Element type (for inputs) */ type?: string; /** Visible text content (truncated) */ text?: string; /** Placeholder text */ placeholder?: string; /** ARIA label */ ariaLabel?: string; /** Role */ role?: string; /** Match score (0-1, higher = better) */ matchScore: number; /** Field that matched (e.g., 'text', 'aria-label', 'class') */ matchedField?: string; /** Value that matched */ matchedValue?: string; /** Whether element is visible */ visible: boolean; /** Whether element is interactive */ interactive: boolean; } /** * Search results */ export interface DOMSearchResults { /** Search query that was used */ query: string; /** Found elements */ elements: SearchResultElement[]; /** Total elements searched */ totalSearched: number; /** Timestamp */ timestamp: number; } /** * Smart DOM Searcher with Levenshtein Distance * * Features: * - Searches across all element properties (text, classes, aria-labels, values, etc.) * - Generates deterministic spoken-word IDs from XPath * - Maintains element store for reliable interaction */ export declare class FuzzyDOMSearcher { /** Element store: spoken ID -> actual element */ private elementStore; /** * Generate XPath for an element */ private getElementXPath; /** * Simple hash function for strings */ private simpleHash; /** * Generate spoken-word ID from XPath * Format: "word1_word2" (e.g., "apple_banana") */ private generateSpokenId; /** * Get or create spoken ID for element */ private getElementId; /** * Get element by spoken ID */ getElementById(id: string): Element | null; /** * Clear element store (call on page navigation) */ clearStore(): void; /** * Search for elements by term using Levenshtein distance * * @param query - Search term (e.g., "cart button", "search", "add to cart") * @param options - Search options * @returns Search results with spoken IDs */ search(query: string, options?: LevenshteinSearchOptions): DOMSearchResults; /** * Get compressed page snapshot using Playwright's AI snapshot algorithm * Returns a hierarchical ARIA tree view optimized for AI comprehension * * This uses the same algorithm as Playwright's built-in AI snapshot feature, * which provides semantic structure and interactive element references. * * Performance optimizations: * - Uses efficient ARIA tree generation (O(n) where n = DOM nodes) * - Caches element mappings to avoid redundant lookups * - Uses regex replacement with pre-compiled patterns * - Detailed timing metrics for performance monitoring * - No size limits (LLM supports very long context) */ getCompressedPageSnapshot(): string; /** * Calculate Levenshtein distance between two strings * Optimized with early exit for performance */ private levenshteinDistance; /** * Calculate similarity score from Levenshtein distance * Returns 0-1 (higher = more similar) * * Enhanced with substring matching for better partial matches */ private calculateSimilarity; /** * Check if element is visible */ private isElementVisible; /** * Check if element is interactive */ private isElementInteractive; /** * Check if element should be skipped */ private shouldSkipElement; } //# sourceMappingURL=dom-search.d.ts.map