
    i`                     x    S r SSKrSSKrSSKrSSKJrJrJr  SSKJ	r	  \R                  " S5      r " S S5      rg)u   
Genesis Superior Browser (GSB) — Vision Bridge (Layer 2)
=======================================================
Integrates Gemini Flash Vision to reason about page state and identify coordinates.
    N)DictListOptional)Pagezgenesis_v2.core.browser.visionc                   F    \ rS rSrSS jrS\S\S\4S jrS\S\4S	 jr	S
r
g)VisionBridge   Nc                     Xl         g Nclient)selfgemini_clients     BE:\genesis-system\genesis_v2\core\browser_engines\vision_bridge.py__init__VisionBridge.__init__   s    #    pagegoalreturnc                   #    UR                  SSS9I Sh  vN n[        R                  " U5      R                  S5      nSU S3nU R                  (       d  [
        R                  S5        S	S
S.$  U R                  R                  XTS9n[        R                  " U5      $  N! [         a/  n[
        R                  SU 35        S[        U5      0s SnA$ SnAff = f7f)zm
Takes a screenshot, sends it to Gemini Flash, and returns 
the coordinates of the element to interact with.
pngF)type	full_pageNzutf-8zF
        Analyze this screenshot of a webpage. 
        Your goal is: a  
        
        Return a JSON object with:
        1. "reasoning": Why you choosing this action.
        2. "action": One of ["click", "type", "scroll", "wait"].
        3. "coordinates": {"x": Number, "y": Number} of the target element.
        4. "selector": (Optional) The CSS selector if you can identify it reliably.
        5. "input_text": (Optional) If action is 'type'.

        The screen resolution is 1920x1080.
        ONLY return JSON.
        zDNo Gemini client provided to VisionBridge. Visual reasoning limited.waitzNo vision brain connected.)action	reasoning)	image_b64zVision analysis failed: error)
screenshotbase64	b64encodedecoder   loggerwarningquery_visionjsonloads	Exceptionr   str)r   r   r   screenshot_bytesscreenshot_b64promptresponsees           r   analyze_pageVisionBridge.analyze_page   s     
 "&eu!MM))*:;BB7Kf 	 {{ NNab$3OPP	%{{///QH ::h''; N<  	%LL3A378SV$$	%s@   CB!AC2.B#  C#
C-$CCCCCvision_resultc                   #    UR                  S5      nUR                  S5      nUS:X  aK  U(       aD  UR                  R                  US   US   5      I Sh  vN   [        R	                  SU 35        U$ US:X  a~  U(       aw  UR                  R                  US   US   5      I Sh  vN   UR
                  R                  UR                  S	S
5      5      I Sh  vN   [        R	                  SU 35        U$ US:X  a9  UR                  R                  SS5      I Sh  vN   [        R	                  S5        U$  N N Nc N!7f)z3Executes the action determined by the vision brain.r   coordinatesclickxyNz"Vision-grounded click executed at r   
input_text z#Vision-grounded typing executed at scrollr   i  z Vision-grounded scroll executed.)getmouser5   r$   infokeyboardr   wheel)r   r   r2   r   coordss        r   execute_vision_move VisionBridge.execute_vision_move:   s%    ""8,""=1W**""6#;s<<<KK<VHEF  v&**""6#;s<<<--$$]%6%6|R%HIIIKK=fXFG
 	 x**""1c***KK:; = =I +sJ   AED;AE(D=)2ED?AEE E=E?EEr   r   )__name__
__module____qualname____firstlineno__r   r   r*   r   r0   rA   __static_attributes__ r   r   r   r      s5    $%%t %%3 %%4 %%Nd 4 r   r   )__doc__r!   r'   loggingtypingr   r   r   playwright.async_apir   	getLoggerr$   r   rH   r   r   <module>rN      s9       ' ' %			;	<; ;r   