{"version":3,"file":"direct-automation-adapter-CeOrBE8g.cjs","sources":["../../lib/vowel/adapters/automation/direct-automation-adapter.ts"],"sourcesContent":["/**\n * @fileoverview Direct Automation Adapter - Same-tab DOM interaction for SPAs\n * \n * This file contains the `DirectAutomationAdapter` class which enables voice-controlled\n * page automation in Single Page Applications. It provides intelligent DOM element\n * searching and manipulation capabilities, allowing the AI to interact with your page\n * through voice commands.\n * \n * Use Cases:\n * - Voice-controlled form filling\n * - Voice-activated button clicks\n * - Voice-driven search and filtering\n * - Accessibility enhancements\n * - Hands-free application control\n * \n * Key Features:\n * - Fuzzy DOM element searching\n * - Intelligent element identification\n * - Click, type, focus, scroll actions\n * - Keyboard event simulation\n * - Page snapshot generation\n * \n * @module @vowel.to/client/adapters/automation\n * @author vowel.to\n * @license Proprietary\n * \n * @example\n * ```ts\n * import { DirectAutomationAdapter } from '@vowel.to/client/adapters/automation';\n * \n * const automationAdapter = new DirectAutomationAdapter();\n * \n * // Search for elements\n * const results = await automationAdapter.searchElements('add to cart button');\n * \n * // Click an element\n * await automationAdapter.clickElement(results.elements[0].id);\n * ```\n */\n\nimport type {\n  AutomationAdapter,\n  AutomationSearchOptions,\n  AutomationSearchResults,\n  AutomationActionResult\n} from '../../types';\nimport { FuzzyDOMSearcher } from '../../platforms/generic/dom-search';\nimport { DOMManipulator } from '../../platforms/generic/dom-tools';\nimport type { FloatingCursorManager } from '../../managers/FloatingCursorManager';\nimport { getActionNotifier } from '../../core/action-notifier';\n\n/**\n * Direct Automation Adapter\n * \n * Handles same-tab DOM interaction for SPAs.\n * Uses FuzzyDOMSearcher for intelligent element finding and\n * DOMManipulator for reliable interaction.\n */\nexport class DirectAutomationAdapter implements AutomationAdapter {\n  private searcher: FuzzyDOMSearcher;\n  private manipulator: DOMManipulator;\n\n  constructor() {\n    this.searcher = new FuzzyDOMSearcher();\n    this.manipulator = new DOMManipulator({\n      getElementById: (id) => this.searcher.getElementById(id)\n    });\n\n    console.log('🤖 [DirectAutomationAdapter] Initialized for same-tab DOM interaction');\n  }\n\n  /**\n   * Set floating cursor manager for visual feedback\n   * @deprecated Floating cursor now uses ActionNotifier. This method is kept for backwards compatibility but does nothing.\n   */\n  public setFloatingCursorManager(_manager: FloatingCursorManager): void {\n    // No-op: Floating cursor now receives updates via ActionNotifier\n    console.log('🤖 [DirectAutomationAdapter] setFloatingCursorManager called (deprecated - now uses ActionNotifier)');\n  }\n\n  /**\n   * Search for elements on the page\n   */\n  async searchElements(\n    query: string,\n    options?: AutomationSearchOptions\n  ): Promise<AutomationSearchResults> {\n    console.log(`🤖 [DirectAutomationAdapter] Searching for: \"${query}\"`);\n    \n    // Notify about search action\n    const notifier = getActionNotifier();\n    notifier.notifySearch(query);\n    \n    try {\n      const results = this.searcher.search(query, options);\n      \n      console.log(`   ✅ Found ${results.elements.length} elements`);\n      \n      // Notify about first result if available\n      if (results.elements.length > 0) {\n        const firstElement = results.elements[0];\n        notifier.notify({\n          type: 'search',\n          message: `Found: ${firstElement.text || firstElement.ariaLabel || 'element'}`,\n          targetElementId: firstElement.id,\n          isIdle: true,\n          timestamp: Date.now(),\n        });\n      }\n      \n      return results;\n    } catch (error) {\n      console.error(`   ❌ Search failed:`, error);\n      throw error;\n    }\n  }\n\n  /**\n   * Get page snapshot\n   */\n  async getPageSnapshot(): Promise<string> {\n    console.log(`🤖 [DirectAutomationAdapter] Generating page snapshot`);\n    \n    try {\n      const snapshot = this.searcher.getCompressedPageSnapshot();\n      \n      console.log(`   ✅ Snapshot generated`);\n      \n      return snapshot;\n    } catch (error) {\n      console.error(`   ❌ Snapshot generation failed:`, error);\n      throw error;\n    }\n  }\n\n  /**\n   * Click an element\n   */\n  async clickElement(id: string, reason?: string): Promise<AutomationActionResult> {\n    console.log(`🤖 [DirectAutomationAdapter] Clicking element: ${id}`);\n    if (reason) {\n      console.log(`   📝 Reason: ${reason}`);\n    }\n    \n    // Notify about click action\n    const notifier = getActionNotifier();\n    notifier.notifyClick(id, reason);\n    \n    try {\n      const result = await this.manipulator.clickElement({ id });\n      \n      if (result.success) {\n        console.log(`   ✅ Click successful`);\n      } else {\n        console.error(`   ❌ Click failed: ${result.error}`);\n      }\n      \n      return result;\n    } catch (error) {\n      console.error(`   ❌ Click error:`, error);\n      return {\n        success: false,\n        error: error instanceof Error ? error.message : String(error)\n      };\n    }\n  }\n\n  /**\n   * Type text into an element\n   */\n  async typeIntoElement(id: string, text: string, reason?: string): Promise<AutomationActionResult> {\n    console.log(`🤖 [DirectAutomationAdapter] Typing into element: ${id}`);\n    if (reason) {\n      console.log(`   📝 Reason: ${reason}`);\n    }\n    \n    // Notify about type action\n    const notifier = getActionNotifier();\n    notifier.notifyType(id, text, reason);\n    \n    try {\n      const result = await this.manipulator.typeIntoElement({ id, text });\n      \n      if (result.success) {\n        console.log(`   ✅ Type successful`);\n      } else {\n        console.error(`   ❌ Type failed: ${result.error}`);\n      }\n      \n      return result;\n    } catch (error) {\n      console.error(`   ❌ Type error:`, error);\n      return {\n        success: false,\n        error: error instanceof Error ? error.message : String(error)\n      };\n    }\n  }\n\n  /**\n   * Focus an element\n   */\n  async focusElement(id: string, reason?: string): Promise<AutomationActionResult> {\n    console.log(`🤖 [DirectAutomationAdapter] Focusing element: ${id}`);\n    if (reason) {\n      console.log(`   📝 Reason: ${reason}`);\n    }\n    \n    // Notify about focus action\n    const notifier = getActionNotifier();\n    notifier.notify({\n      type: 'focus',\n      message: reason || 'Focused element',\n      targetElementId: id,\n      isIdle: true,\n      timestamp: Date.now(),\n    });\n    \n    try{\n      const result = await this.manipulator.focusElement({ id });\n      \n      if (result.success) {\n        console.log(`   ✅ Focus successful`);\n      } else {\n        console.error(`   ❌ Focus failed: ${result.error}`);\n      }\n      \n      return result;\n    } catch (error) {\n      console.error(`   ❌ Focus error:`, error);\n      return {\n        success: false,\n        error: error instanceof Error ? error.message : String(error)\n      };\n    }\n  }\n\n  /**\n   * Scroll to an element\n   */\n  async scrollToElement(id: string, reason?: string): Promise<AutomationActionResult> {\n    console.log(`🤖 [DirectAutomationAdapter] Scrolling to element: ${id}`);\n    if (reason) {\n      console.log(`   📝 Reason: ${reason}`);\n    }\n    \n    // Notify about scroll action\n    const notifier = getActionNotifier();\n    notifier.notify({\n      type: 'scroll',\n      message: reason || 'Scrolled to element',\n      targetElementId: id,\n      isIdle: true,\n      timestamp: Date.now(),\n    });\n    \n    try {\n      const result = await this.manipulator.scrollToElement({ id });\n      \n      if (result.success) {\n        console.log(`   ✅ Scroll successful`);\n      } else {\n        console.error(`   ❌ Scroll failed: ${result.error}`);\n      }\n      \n      return result;\n    } catch (error) {\n      console.error(`   ❌ Scroll error:`, error);\n      return {\n        success: false,\n        error: error instanceof Error ? error.message : String(error)\n      };\n    }\n  }\n\n  /**\n   * Press a key\n   */\n  async pressKey(key: string, reason?: string): Promise<AutomationActionResult> {\n    console.log(`🤖 [DirectAutomationAdapter] Pressing key: ${key}`);\n    if (reason) {\n      console.log(`   📝 Reason: ${reason}`);\n    }\n    \n    try {\n      const result = await this.manipulator.pressKey({ key });\n      \n      if (result.success) {\n        console.log(`   ✅ Key press successful`);\n      } else {\n        console.error(`   ❌ Key press failed: ${result.error}`);\n      }\n      \n      return result;\n    } catch (error) {\n      console.error(`   ❌ Key press error:`, error);\n      return {\n        success: false,\n        error: error instanceof Error ? error.message : String(error)\n      };\n    }\n  }\n\n  /**\n   * Clear element store (call on page navigation)\n   */\n  clearStore(): void {\n    this.searcher.clearStore();\n  }\n}\n\n"],"names":["FuzzyDOMSearcher","DOMManipulator","getActionNotifier"],"mappings":";;;;;;;AA0DO,MAAM,uBAAA,CAAqD;AAAA,EACxD,QAAA;AAAA,EACA,WAAA;AAAA,EAER,WAAA,GAAc;AACZ,IAAA,IAAA,CAAK,QAAA,GAAW,IAAIA,0BAAA,EAAiB;AACrC,IAAA,IAAA,CAAK,WAAA,GAAc,IAAIC,wBAAA,CAAe;AAAA,MACpC,gBAAgB,CAAC,EAAA,KAAO,IAAA,CAAK,QAAA,CAAS,eAAe,EAAE;AAAA,KACx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