
    ɢi#                         d Z ddlZddlZddlmZ ddlmZ  ej                  e      Z	 G d d      Z
	 	 	 	 ddedee   d	ee   d
ee   dee   defdZ	 	 	 	 	 	 dded	ed
ee   dededededefdZy)uW  Context Engine — structured context assembly for AI prompts.

Provides:
- ContextAssembler: priority-ordered, deduplicated context block manager
- build_domain_context: assembles context for domain analysis
- build_generation_context: assembles context for content generation

Zero imports from app/. Uses ContextBlock from aura_core.types.
    N)Optional)ContextBlockc            	       j    e Zd Zd Zdedd fdZddedededd fdZdd	edefd
Z	d Z
edefd       Zy)ContextAssemblerc                 0    g | _         t               | _        y N)_blocksset_seenselfs    6/sites/domain-asset-master/aura_core/context/engine.py__init__zContextAssembler.__init__   s    +-"u
    blockreturnc                     |j                    d|j                   }|| j                  v r| S | j                  j                  |       | j                  j                  |       | S )N:)sourcecontentr   addr	   append)r   r   keys      r   r   zContextAssembler.add   sR    a/$**K

sE"r   r   r   priorityc                 <    | j                  t        |||            S )N)r   r   r   )r   r   )r   r   r   r   s       r   add_rawzContextAssembler.add_raw!   s    xxFGhWXXr   	max_charsc                 6   | j                   syt        | j                   d       }g }|D ]@  }d|j                  j                          d}|j	                  | d|j
                          B dj                  |      }|dkD  rt        |      |kD  r|d | d	z   }|S )
N c                     | j                    S r   r   )bs    r   <lambda>z)ContextAssembler.render.<locals>.<lambda>(   s    AJJ; r   )r   z--- z ---
z

r   z
[...truncated])r	   sortedr   upperr   r   joinlen)r   r   sorted_blockssectionsr   headerfulls          r   renderzContextAssembler.render$   s    ||t||1FG" 	:EELL..016FOOvhb89	: {{8$q=SY2
#&88Dr   c                 l    | j                   j                          | j                  j                          y r   )r	   clearr   r   s    r   r/   zContextAssembler.clear6   s"    

r   c                 ,    t        | j                        S r   )r(   r	   r   s    r   block_countzContextAssembler.block_count:   s    4<<  r   N)r   )__name__
__module____qualname__r   r   r   strintr   r-   r/   propertyr1    r   r   r   r      su    % *< Yc YC Y3 YGY Y C $ !S ! !r   r   domainanalysisnichebrand	valuationr   c                    t               }|j                  dd|  d       |rg }|j                  d      r&|j                  ddj	                  |d                 |j                  d      r|j                  d	|d           |j                  d
g       }|rB|D cg c]  }|j                  dd       }	}|j                  ddj	                  |	              |r#|j                  ddj	                  |      d       |rg }|j                  d      r|j                  d|d           |j                  d      r|j                  d|d           |j                  d      r|j                  d|d           |j                  d      r|j                  d|d           |j                  d      r8|d   }
t        |
t              r#|j                  ddj	                  |
              |r#|j                  ddj	                  |      d       |rwg }|j                  d      r|j                  d|d           |j                  d      r|j                  d|d           |r#|j                  ddj	                  |      d        |rg }|j                  d!      r|j                  d"|d!   d#       |j                  d$      r|j                  d%|d$   d#       |j                  d&      r|j                  d'|d&   d#       |r#|j                  d(dj	                  |      d)       |j                         S c c}w )*Nr9   Domain: 
   r!   keywordsz
Keywords: z, domain_summaryz	Summary: nichesnameUnknownzIdentified niches: r:   r$      Niche: descriptionzDescription: target_audiencezTarget Audience: monetization_modelzMonetization: affiliate_programszAffiliate Programs: r;      Brand: tagline	Tagline: r<      domain_only_valuezDomain Value: $,best_developed_valuezDeveloped Value: $best_monthly_netzMonthly Net Potential: $r=      )r   r   getr   r'   
isinstancelistr-   )r9   r:   r;   r<   r=   capartsrC   nniche_namesprogramss              r   build_domain_contextr^   ?   s    
	BJJx8F8,rJ:<<
#LL:dii0D&E%FGH<<()LL9X.>%?$@ABh+=CD1553DKDLL.tyy/E.FGHJJz499U#3aJ@99VLL75=/2399]#LL=})=(>?@99&'LL,U3D-E,FGH99)*LL>%0D*E)FGH99)*12H(D)3DIIh4G3HIJJJw		% 01J=99VLL75=/2399YLL9U9%5$678JJw		% 01J===,-LL?95H+I!*LMN==/0LL-i8N.OPQ-RST==+,LL3I>P4QRS3TUVJJ{DIIe$4qJA99;U Es   M tonedepthsection_typeextra_contextc                 P   t               }|j                  dd|  d       |r|j                  dd| d       |rwg }|j                  d      r|j                  d	|d           |j                  d
      r|j                  d|d
           |r#|j                  ddj	                  |      d       |r|j                  dd| d       |dk7  r|j                  dd| d       |r|j                  dd| d       |r|j                  d|d       |j                         S )Nr9   r?   r@   r!   r;   rG   	   rD   rM   rN   rO   r<   r$   rF   r_   zTone: rL   standardr`   zContent Depth: rP   sectionzSection Type: rU   extra   )r   r   rV   r   r'   r-   )	r9   r;   r<   r_   r`   ra   rb   rY   rZ   s	            r   build_generation_contextri      s(    
	BJJx8F8,rJ:


7geW-
:99VLL75=/2399YLL9U9%5$678JJw		% 01J=


6VD6?Q
7



7oeW5
B


9|n=
J


7MA
699;r   )NNNN)r   Nr   re   r   r   )__doc__jsonloggingtypingr   aura_core.typesr   	getLoggerr2   loggerr   r5   dictr^   ri   r8   r   r   <module>rr      s       (			8	$(! (!Z  $   $==tn= D>= D>	=
 ~= 	=D  %%% D>% 	%
 % % % 	%r   