
    ɢi!"              
       $   d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ  ej                  e      Zddddd	d
dddddd
dddddd
dddddd
dddddd
gZ G d de      Z G d de      Z G d de      Z	 	 	 d7deded eee      d!efd"Zd#ed!efd$Zd#ed!efd%Zd#ed!efd&Zd#ed!efd'Zd#ed!efd(Zeeeeed)Zd*ed#ed!efd+Zd*ed!ee ee   f   fd,Z!ded-eeef   d!efd.Z" e	d/d0d1e2      d#ed!e
fd3       Z#d*ed4ed5ed!efd6Z$y)8u  
Orchestrator Engine — composes all aura_core engines into a pipeline.

Stages run sequentially, each producing typed output that feeds the next.
Supports partial runs, stage skipping, and error-halt semantics.
Zero imports from app/. Uses module registry for engine dispatch.
    N)Optional)	BaseModelField)aura_moduleModuleResult)OrchestratorInput	blueprintTzAGenerate site blueprint with section definitions and depth config)namemoduleorderrequireddescription	valuation   Fz=Calculate domain value, revenue models, and traffic estimatescontext   z*Assemble structured context for AI promptstheme   z0Generate visual theme from brand colors and mood	validator   z*Validate and auto-repair generated contentc                       e Zd ZU dZeed<   dZeed<    ee      Z	ee   ed<    ee
      Ze
ed<   dZeed	<   dZeed
<    ee      Zee
   ed<   y)OrchestratorConfig domaincomprehensivedepthdefault_factoryskip_stagesbrand_colorsprofessionalmoodnichenichesN)__name__
__module____qualname__r   str__annotations__r   r   listr   dictr    r"   r#   r$        ;/sites/domain-asset-master/aura_core/orchestrator/engine.pyr   r      s^    FC E3 "48Kc8t4L$4D#E3Ot4FDJ4r-   r   c                       e Zd ZU eed<   eed<    ee      Zee   ed<    ee      Z	ee   ed<    ee
      Ze
ed<   dZeed<   y	)
OrchestratorResultr   successr   stages_completedstages_failedpackage        total_elapsed_msN)r%   r&   r'   r(   r)   boolr   r*   r2   r3   r+   r4   r6   floatr,   r-   r.   r0   r0   %   sM    KM"'"=d3i=$T:M49:$/GT/!e!r-   r0   c                   n    e Zd ZU dZeed<   dZeed<   dZe	e
   ed<   dZeed<    ee	      Zee   ed
<   y)StageResultTokr   
stage_nameNoutputr5   
elapsed_msr   errors)r%   r&   r'   r;   r7   r)   r<   r(   r=   r   r+   r>   r8   r   r*   r?   r,   r-   r.   r:   r:   .   s@    BOJ!FHTN!Jd3FDI3r-   r:   r   r   r   returnc                 (    t        d| ||xs g d|S )N)r   r   r   r,   )r   )r   r   r   kwargss       r.   get_pipeline_configrC   6   s.      %2 	 r-   configc                     ddl m}m}m} | j	                  dd      } ||      } ||      } ||      \  }}|j                         |j                         ||dS )Nr   )get_default_blueprintvalidate_blueprintblueprint_to_prompt_specr   r   )r	   
validationprompt_specjson_schema)aura_core.blueprint.enginerF   rG   rH   get
model_dump)	rD   rF   rG   rH   r   bprI   rJ   rK   s	            r.   _run_blueprintrP   D   s`    nnJJw0E	u	%B#B'J7;K]]_ ++-""	 r-   c                     ddl m} | j                  dd      }| j                  dg       }|r|sdddS  ||d|i      }|j                         S )	Nr   )valuate_domainr   r   r$   Tzdomain or niches not provided)skippedreason)aura_core.valuation.enginerR   rM   rN   )rD   rR   r   r$   results        r.   _run_valuationrW   R   sV    9ZZ"%FZZ"%F+JKKFXv$67Fr-   c                     ddl m} | j                  dd      }| j                  d      }| j                  d      }| j                  d      }| j                  d      } ||||||	      }||d
S )Nr   )build_domain_contextr   r   analysis
niche_databrandr   )r   rZ   r#   r\   r   )r   context_text)aura_core.context.enginerY   rM   )rD   rY   r   rZ   r#   r\   r   context_strs           r.   _run_contextr`   \   ss    =ZZ"%Fzz*%HJJ|$EJJwE

;'I&K k::r-   c                 H   ddl m}  || j                  d| j                  dd            | j                  d| j                  dd            | j                  d	| j                  d
d            | j                  dd      | j                  dd            }|j                         S )Nr   )generate_themeprimary_colorprimary#4F46E5secondary_color	secondary#7C3AEDaccent_coloraccent#06B6D4r"   r!   r#   r   )rd   rg   rj   r"   r#   )aura_core.theme.enginerb   rM   rN   )rD   rb   rV   s      r.   
_run_themerm   m   s    5

?FJJy),LM**.

;	0RSzz.&**Xy*IJZZ/jj"%F r-   c                 h    ddl m} | j                  di       } ||      \  }}|j                         S )Nr   )validate_site_copy	site_copy)aura_core.validator.enginero   rM   to_dict)rD   ro   rp   repaired_datareporters        r.   _run_validatorru   y   s3    =

;+I0;M8r-   )r	   r   r   r   r   r<   c           	         t         j                  |       }|t        d| d|  g      S t        j                         }	  ||      }t        j                         |z
  dz  }t        d| ||      S # t
        $ rV}t        j                         |z
  dz  }t        j                  d|  d       t        d| |t        |      g	      cY d }~S d }~ww xY w)
NFzUnknown stage: )r;   r<   r?   i  T)r;   r<   r=   r>   z[orchestrator] Stage 'z' failed)r;   r<   r>   r?   )	_STAGE_RUNNERSrM   r:   timeperf_counter	Exceptionlogger	exceptionr(   )r<   rD   runnerstartr=   elapsedes          r.   	run_stager      s    
+F~!%j\23
 	

 E
$$&.$6!	
 	
  
$$&.$61*XFG!F8	
 	

s   0A0 0	C9AC
C
Cc                 N    |d|  dgfS t        |t              sd|  dgfS dg fS )NFz: output is Nonez: output is not a dictT)
isinstancer+   )r<   r=   s     r.   validate_stage_outputr      sF    ~*%56777fd#*%;<===8Or-   stage_resultsc                    | g g dd}d}|j                         D ]X  \  }}||j                  z  }|j                  r$|d   j                  |       |j                  ||<   E|d   j                  |       Z t        |d      |d<   |S )Nr5   )r   r2   r3   r6   r2   r3   r   r6   )itemsr>   r;   appendr=   round)r   r   r4   total_msr
   rV   s         r.   assemble_packager      s    	G H%++- 2fF%%%99&'..t4"MMGDMO$++D12 #(!"4GNr-   orchestratorz1.0.0up   End-to-end pipeline composing all aura_core engines: blueprint → valuation → context → theme → validator)r
   versionr   input_modelc                    t        | t              st        di | n| }i }g }g }t        D ]j  }|d   }||j                  v rt	        |||      }t        ||      }|||<   |j                  r|j                  |       S|j                  |       |d   sj n t        |j                  |      }	t        t        |      dk(  t        |j                  t        |      dk(  |||	|	d               S )Nr
   r   r   r6   )r   r1   r2   r3   r4   r6   )r;   r=   r,   )r   r   PIPELINE_STAGESr   _build_stage_configr   r;   r   r   r   r   lenr0   )
rD   orch_configr   r2   r3   	stage_defr
   stage_configrV   r4   s
             r.   run_pipeliner      s
    7AI[6\$.v.bhKMM$ 	 ;****4mL4.$d99##D)  &$  {11=AG}"!%%&!+-'$%78

 
r-   r   prior_resultsc                    | dk(  rd|j                   iS | dk(  r|j                  |j                  dS | dk(  r|j                  |j                  dS | dk(  rX|j                  }|j                  dd	      |j                  d
d      |j                  dd      |j                  |j                  dS | dk(  r-|j                  dt                     j                  xs i }i i dS i S )Nr	   r   r   )r   r$   r   )r   r#   r   rd   re   rg   rh   rj   rk   )rc   rf   ri   r"   r#   r   )rp   r\   )	r   r   r$   r#   r    rM   r"   r:   r=   )r<   r   r   colors	bp_outputs        r.   r   r      s    [ **++	{	"%,,8J8JKK	y	 %,,{7H7HII	w	))#ZZ	9=%zz+yA"JJx;$$ &&
 	
 
{	"!%%k;=AHHNB	"--Ir-   )r   r   N)%__doc__rx   loggingtypingr   pydanticr   r   aura_core.module_contractr   r   aura_core.typesr   	getLoggerr%   r{   r   r   r0   r:   r(   r*   rC   r+   rP   rW   r`   rm   ru   rw   r   tupler7   r   r   r   r   r,   r-   r.   <module>r      s8      % ? -			8	$ K!  _b  cK!  `_  `)aU  \H  I!  WI  JK!  `L  M5 5" "4) 4  '+ $s)$
 4 D 4 D ; ;$ ;"	t 	 	4 D   
# 
t 
 
:c eD$s)O6L S c;6F1G D & 	 C!	" ", ""JC 6H Y] bf r-   