
    ՘i\                         d Z ddlZddlZddlZddlmZmZmZ 	 ddlZ ej                  d      Z G d d      Zy# e	$ r dZY &w xY w)u  
Lux Meta Engine — Genesis Superior Browser (GSB) Layer 4
========================================================
Transcend the browser. This engine operates at the OS level, capturing the
entire virtual display and using OpenAGI's Lux foundation model to infer
human-parity mouse clicks, scrolls, and keypresses.

This implementation acts as the bridge to the Lux inference service, performing
physical OS interaction using PyAutoGUI.
    N)DictAnyOptionalz'genesis_v2.core.browser.lux_meta_enginec                   t    e Zd ZddefdZdefdZdededeeef   fdZ	deeef   fd	Z
dedeeef   fd
Zy)LuxMetaEngine
display_idc                     || _         | j                   t        j                  d<   t        st        j                  d       d| _        y d| _        dt        _        y )NDISPLAYzEPyAutoGUI not installed. Lux Meta Engine will run in simulation mode.TF)r   osenviron	pyautoguiloggerwarningsimulation_modeFAILSAFE)selfr   s     H/mnt/e/genesis-system/genesis_v2/core/browser_engines/lux_meta_engine.py__init__zLuxMetaEngine.__init__   sC    $ $

9NNbc#'D #(D !&I    returnc                    K   | j                   rt        j                  d       yt        j                         }t        j                  d|j
                          yw)z$Capture the current OS-level screen.z"Simulation: Capturing screen stub.s   mock_image_byteszCaptured screen of size )r   r   infor   
screenshotsize)r   r   s     r   capture_screenzLuxMetaEngine.capture_screen&   sI     KK<=&))+
.z.?@A"s   AAimage_bytesinstructionc                 x   K   t         j                  d| d       t        j                  d       ddddddS w)	z
        Send the screen and instruction to the Lux model.
        Returns coordinate map and action type (click, type, scroll).
        z/Sending screen to Lux Model with instruction: ''   clicki  )xygffffff?)actioncoordinates
confidence)r   r   timesleep)r   r   r   s      r   infer_lux_actionzLuxMetaEngine.infer_lux_action1   sD     
 	Ek]RSTU

1 !$3/
 	
s   8:action_datac                   K   |j                  d      }| j                  rt        j                  d|        y|dk(  r|j                  di       }|j                  dd      |j                  dd      }}t        j                  d	| d
| d       t	        j
                  ||dt        j                         t	        j                          y|dk(  rB|j                  dd      }t        j                  d|        t	        j                  |d       y|dk(  r@|j                  dd      }t        j                  d|        t	        j                  |       yyw)z-Execute the predicted action using PyAutoGUI.r$   z#Simulation: Executing OS Action -> Nr!   r%   r"   r   r#   zOS-Level Click at (z, )g      ?)durationtweentypetext zOS-Level Typing: g?)intervalscrollamountizOS-Level Scroll: )
getr   r   r   r   moveToeaseInOutQuadr!   writer3   )r   r*   r$   coordsr"   r#   r0   r4   s           r   execute_os_actionzLuxMetaEngine.execute_os_actionA   s&    *KK=k]KLW __]B7F::c1%vzz#q'9qAKK-aS1#Q78 QCy7N7NOOOv??62.DKK+D623OOD40x __Xs3FKK+F845V$  s   EEc                   K   	 t         j                  d| d       | j                          d{   }| j                  ||       d{   }|j	                  dd      dkD  r| j                  |       d{    d|dS d	d
dS 7 V7 >7 # t        $ r0}t         j                  d|        d	t        |      dcY d}~S d}~ww xY ww)z+Complete workflow for a single instruction.z!Lux Meta Engine activating for: 'r   Nr&   r   g?success)statusr$   failedzLow confidence from Lux model)r=   errorz"Lux Meta Engine execution failed: )	r   r   r   r)   r5   r:   	Exceptionr?   str)r   r   screen_bytesr*   es        r   run_instructionzLuxMetaEngine.run_instruction]   s     	9KK;K=JK!%!4!4!66L $ 5 5lK PPK|Q/#5,,[999"+{CC"*5TUU 7P :
  	9LL=aSAB&Q88	9st   C	,B BB 
B	-B 8B9B C	B C	B 	B B 	C%C;C<C	CC	N)z:0)__name__
__module____qualname__rA   r   bytesr   r   r   r)   r:   rD    r   r   r   r      sn    '3 '	#e 	#
% 
c 
dSVX[S[n 
 %4S> %89 9c3h 9r   r   )__doc__r   r'   loggingtypingr   r   r   r   ImportError	getLoggerr   r   rI   r   r   <module>rO      sZ   	 
   & & 
		D	ET9 T9  Is   ; AA