
    W0i                         d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
  ej                  d      Zddedee   d	efd
Zddedee   d	efdZded	efdZ G d d      Zdad	efdZy)uM  
ADK Orchestrator — Native Google ADK Integration
================================================
Wraps the Genesis Superior Browser (GSB) stack directly into 
Google Agent Development Kit (ADK) native tools. This allows 
Gemini 3.0 Flash to control the full L5 Supremacy stack 
(Stealth -> Vision -> Lux -> Delegation) natively.
    N)DictAnyOptional)get_gsb)JulesBridgez genesis_v2.core.adk_orchestratorinstructionexpected_outcomereturnc                 L  K   	 t               }t        j                  d|  d       |j                  |        d{   }ddl} |j
                  |      S 7 # t        $ r@}t        j                  d|         j
                  dt        |      d      cY d}~S d}~ww xY ww)a[  
    Executes a high-level browser or desktop OS task using the Genesis Superior Browser (GSB).
    The GSB will automatically select the best engine (Stealth, Vision, or Lux Meta-Engine) 
    to fulfill the instruction natively without requiring explicit selectors.
    
    Args:
        instruction: The natural language description of what to do (e.g. "Click the 'Login' button").
        expected_outcome: Optional description of what defines success for this instruction.
        
    Returns:
        JSON string containing the execution result, status, and which engine handled the request.
    z$ADK orchestrating GSB instruction: ''Nr   zADK Execution Failed: failedstatuserror)	r   loggerinfoexecute_taskjsondumps	Exceptionr   str)r   r	   gsbresultr   es         9/mnt/e/genesis-system/genesis_v2/core/adk_orchestrator.pyadk_execute_browser_actionr      s     Ai:;-qIJ ''44 	tzz&!!	 5
  A-aS12tzzXA?@@AsD   B$7A AA B$A 	B!!5BB!B$B!!B$
target_urlextraction_schemac                    K   yw)a-  
    Navigates to a URL and extracts content using the Genesis Tri-Layer extraction system.
    
    Args:
        target_url: URL to visit.
        extraction_schema: Optional JSON schema defining the required output structure.
        
    Returns:
        JSON string of the extracted content.
    z>{"status": "success", "data": "extracted content placeholder"} )r   r   s     r   adk_extract_page_contentr!   2   s      Ls   problem_statementc                   K   	 t               }t        j                  d|  d       d|  }|j                  |      }|rt	        j
                  ddd      S t	        j
                  ddd	      S # t        $ rC}t        j                  d
|        t	        j
                  dt        |      d	      cY d}~S d}~ww xY ww)a  
    Triggers a 'Deep Think' session via Jules (the Strategic Architect) to solve 
    complex systemic problems or design new architectures that require deep reasoning.
    
    Args:
        problem_statement: The question or problem for the strategic architect to solve.
        
    Returns:
        JSON string indicating that the session has been kicked off asynchronously.
    z'ADK orchestrating Deep Think session: 'r   zCAs the Genesis Strategic Architect, apply deep reasoning to solve: successzCDeep Think session initiated. Results will be pulled automatically.)r   messager   zFailed to create Jules session.r   zADK Ask Architect Failed: N)	r   r   r   create_sessionr   r   r   r   r   )r"   bridgepromptr$   r   s        r   adk_ask_architectr)   @   s     A=>O=PPQRSVWhVij''/::  @E  F  G  GzzX8YZ[[ A1!56zzXA?@@AsA   B>AA/ B>A/ .B>/	B;88B60B;1B>6B;;B>c                   D    e Zd ZdZd	defdZdefdZdedeee	f   fdZ
y)
ADKOrchestratorzv
    Manages the lifecycle of ADK agents and exposes the Genesis ecosystem 
    native tools to Gemini 3.0 Flash.
    
model_namec                     || _         t        t        t        g| _        t
        j                  dt        | j                         d| j                    d       y )Nz"ADK Orchestrator initialized with z native tools for .)r,   r   r!   r)   toolsr   r   len)selfr,   s     r   __init__zADKOrchestrator.__init__c   sL    $&$


 	8TZZ8II[\`\k\k[llmno    r
   c                     | j                   S )zBReturn the list of functions intended for Google ADK registration.)r/   )r1   s    r   get_native_toolsz ADKOrchestrator.get_native_toolsl   s    zzr3   r(   c                 b   K   t         j                  d|dd  d       d| j                  ddS w)z
        Directly invoke the Gemini agent with the ADK toolkit. 
        This replaces the custom `GeminiRateMaximizer` loops.
        zADK Agent invoked with prompt: N2   z...r$   zNSimulation of ADK Agent completing the workflow leveraging GSB tools natively.)r   
model_usedresponse)r   r   r,   )r1   r(   s     r   invoke_agentzADKOrchestrator.invoke_agentp   s=     
 	5fSbk]#FG  //h
 	
s   -/N)zgemini-3.0-flash)__name__
__module____qualname____doc__r   r2   listr5   r   r   r:   r    r3   r   r+   r+   ]   s<    
p3 p$ 
 
c3h 
r3   r+   c                  .    t         
t               a t         S N)_orchestratorr+   r    r3   r   get_adk_orchestratorrC      s    ')r3   rA   )r>   r   loggingtypingr   r   r   genesis_v2.core.browser_gsbr   genesis_v2.core.jules_bridger   	getLoggerr   r   r   r!   r)   r+   rB   rC   r    r3   r   <module>rI      s      & & / 4			=	>A# ARU Abe A6Ls LxPS} L`c LAs As A:!
 !
H o r3   