Ë
    ¼vëj6)  ã                  ó   — d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
mZ ddlmZmZmZ ddlmZ ddlmZmZ dd	lmZmZmZ eeegef   Zd
Ze G d„ d«      «       Z	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Z dd„Z!dd„Z"	 	 	 	 	 	 dd„Z#dd„Z$y)a\  The composition: from the design brief, the model lays the piece out. It sees the brief it wrote, the owner's
words, the facts in hand, every template on the shelf with whether it fits and why not, and the blocks, the looks a
block may take and the style words. It answers with one of three things and a reason: use a shelf template as it
is, adapt one (blocks added, removed, reordered, given looks; style changed), or design a new one from the blocks.
No order between the three and no gate: the brief and the facts decide.

Code checks only reality: the answer is a valid template (known blocks, looks and style words, values that exist)
and it fits the facts in hand. An answer that fails goes back once with the reason. After that the plainest fitting
template stands in and says what could not be made. The model call is a function the product passes in.é    )Úannotations)Ú	dataclassÚfield)ÚAnyÚCallableÚDictÚListÚOptionalé   )ÚABOUTÚCONTRACTÚLOOK)Útemplate_from_dict)ÚStyleÚTemplate)ÚFitÚValuesÚfitaZ	  You lay out one piece of content from the design brief you wrote for it. You are given that brief, the
owner's own words about the design if they said anything, what is known about the brand, the audience and the
facts in hand, what this owner kept before, every template on the shelf with one line on what it is for, its blocks,
and whether it can be filled right now and why not, and the blocks a design may use with the looks each may take
and the style words for the whole.

Answer with exactly one of three actions, as JSON:
- {"action": "use", "name": "<template>", "reason": "<one sentence>"}: a shelf template realises the brief as it is.
- {"action": "adapt", "name": "<template>", "changes": {"blocks": [<full block list>] or null, "style": {<style words
  to change>} or null}, "reason": "<one sentence>"}: a shelf template is the right start but the brief calls for
  blocks added, removed, reordered or given looks, or a different composition.
- {"action": "design", "template": {"name": "<short name>", "kind": "<kind>", "description": "<one sentence>",
  "style": {...}, "blocks": [<block list>]}, "reason": "<one sentence>"}: nothing on the shelf resembles what the
  brief asks for; compose it from the blocks.

A block in a list is a type name, or an object with its type and its looks, for example:
["header", {"type": "heading", "size": "display", "colour": "primary"}, "text", {"type": "offer", "surface": "band"},
{"type": "button", "space": "loose", "colour": "primary"}, {"type": "product", "name": "second", "optional":
["product.url"]}, "footer"]. A block's object holds only its type, a name when the type repeats, "optional" for
values it may go without, and look words; never a value (no brand.logo, no cta.url: those are facts in hand).
Give a block a look when the brief calls for it: a display heading, a band for the offer, a loose space before the
button, the primary colour on the button. Use only the block types, look words and style words given. Never choose
a template that cannot be filled; never add a block whose required values are not in hand unless you mark them
optional. The owner's own choice stands when it can be filled. Say only what the brief says: show products, a
cart, a quote or a picture only when the brief or the owner's words are about them. The reason is in the owner's
words and names what in the brief made you lay it out this way.c                  ód   — e Zd ZU ded<   ded<   ded<   dZded<    ee¬	«      Zd
ed<   dZded<   y)ÚDecisionr   ÚtemplateÚstrÚactionÚreasonNzOptional[str]Úbased_on)Údefault_factoryz	List[str]ÚtriedFÚboolÚfallback)	Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r   r   Úlistr   r   © ó    ú_/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/galaxiq_utils/templates/decide.pyr   r   2   s5   … àÓØƒKØƒKØ"€HˆmÓ"Ù¨TÔ2€Eˆ9Ó2Ø€HˆdÔr&   r   Nc                ó  ‡— | j                  «       D ��ci c]  \  }}|t        ||«      “Œ }}}t        | |‰|||||	|
«	      }g }t        d«      D ]â  } |t        |«      xs i }	 t        || |«      \  }}}t        ||«      }|j                  st        |j                  ‰«      «      ‚|j                  d«      r't        d„ |j                  D «       «      st        d«      ‚|r ||«      nd}|rt        |«      ‚t        ||t        |j                  d«      xs d«      j                  «       ||«      c S  |j                  «       D ��cg c]  \  }}|j                  sŒ|‘Œ }}}|s4t        ddj)                  ˆfd„|j+                  «       D «       «      z   «      ‚||v r|n|d   }|r|d   j-                  dd«      d   nd}t        | |   d|› d|› �d|d¬«      S c c}}w # t        t         t"        f$ r‘}t%        |«      }|j                  d«      xs( |j                  d	«      xs i j                  d«      xs d}|j'                  |j                  d
d«      › d|› d|› �j                  «       «       |d|› d�z  }Y d}~�Œ0d}~ww xY wc c}}w )z»`check` is the product's own look at a chosen design (a fact of the account the library cannot know): a reason
    it returns is sent back to the model like a value that cannot be filled.é   zcta.urlc              3  ó:   K  — | ]  }|j                   d k(  –— Œ y­w)ÚbuttonN©Útype©Ú.0Úbs     r'   ú	<genexpr>zdecide.<locals>.<genexpr>K   s   è ø€ Ò0]È°·±¸8Õ1CÑ0]ùs   ‚zkthe step has a button link but this design has no button block, so the link would go nowhere; keep a buttonNr   Ú Únamer   r   ú?ú ú: z#

Your last answer cannot be used: z. Answer again.zno template can be filled: z; c              3  ó@   •K  — | ]  }|j                  ‰«      –— Œ y ­w©N)Úwhy_not)r/   ÚfÚfireds     €r'   r1   zdecide.<locals>.<genexpr>Y   s   øè ø€ ÒBkÐXYÀ1Ç9Á9ÈU×CSÑBkùs   ƒr   éÿÿÿÿr   z	no answerÚstand_inz2 stands in; what was asked for could not be made: T)r   )Úitemsr   Ú_user_promptÚrangeÚSYSTEMÚ_template_fromÚokÚ
ValueErrorr9   ÚhasÚanyÚblocksr   r   ÚgetÚstripÚKeyErrorÚ	TypeErrorÚ_plainÚappendÚjoinÚvaluesÚsplit)Ú	templatesÚbriefrO   r;   ÚaskÚowner_wordsÚknownÚchannelr=   ÚdesignÚtasteÚcheckr3   ÚtÚfitsÚuserr   Ú_Úanswerr   r   r   r:   ÚrefusedÚexcÚwhyÚnamedÚnÚusableÚlasts      `                          r'   Údeciderf   <   s�  ø€ ð
 1:·±Ó0A×B¡W T¨1ˆD”#�a˜“.Ñ ÐB€DÑBÜ˜	 4¨°°{ÀEÈ7ÐTZÐ\aÓb€DØ€EÜ�1‹Xò QˆÙ”V˜TÓ"Ò( bˆð	QÜ)7¸À	È7Ó)SÑ&ˆH�f˜hÜ�H˜fÓ%ˆAØ—4’4Ü  §¡¨5Ó!1Ó2Ð2Ø�z‰z˜)Ô$¬SÑ0]ÈXÏ_É_Ô0]Ô-]ä ð  "Oó  Pð  PÙ).‘e˜H”o°DˆGÙÜ  Ó)Ð)Ü˜H f¬c°&·*±*¸XÓ2FÒ2LÈ"Ó.M×.SÑ.SÓ.UÐW_ÐafÓgÒgðQð& !ŸJ™J›L×1‘D�A�q¨A¯D«DŠaÐ1€FÑ1ÙÜÐ6¸¿¹ÓBkÐ]a×]hÑ]hÓ]jÔBkÓ9kÑkÓlÐlØ 6Ñ)‰8¨v°a©y€DÙ+0ˆ5�‰9�?‰?˜4 Ó# BÒ'°k€DÜ�I˜d‘O Z°D°6Ð9kÐlpÐkqÐ1rÐtxÐzð  KOô  Pð  Pùó7 Cøô" œH¤iÐ0ò 	QÜ˜“+ˆCØ—J‘J˜vÓ&ÒZ¨6¯:©:°jÓ+AÒ+GÀR×*LÑ*LÈVÓ*TÒZÐXZˆEØ�L‰L˜FŸJ™J x°Ó5Ð6°a¸°w¸bÀÀÐF×LÑLÓNÔOØÐ;¸C¸5ÀÐPÑPŽDûð		Qüó
 2s+   •GÁ$CGÅJÅJÇJÇ3BI?É?Jc                óæ  — t        | j                  d«      xs d«      j                  «       }|dk(  rt        || j                  d«      «      dd fS |dk(  rýt        || j                  d«      «      }| j                  d«      xs i }|j	                  «       }|j
                  › d�|d<   d|d	<   |j                  d
«      rDi |d
   ¥|d
   j                  «       D ��ci c]  \  }}|t        j                  v sŒ||“Œ c}}¥|d
<   |j                  d«      xs# |j                  D �	cg c]  }	t        |	«      ‘Œ c}	|d<   t        |«      d|j
                  fS |dk(  rƒt        | j                  d«      xs i «      }|j                  d|«       |j                  dd«       |j                  dt        | j                  d«      xs d«      «       d|d	<   t        |«      dd fS t        d|›�«      ‚c c}}w c c}	w )Nr   r2   Úuser3   ÚadaptÚchangesz	, adaptedÚorganisationÚownerÚstylerG   rW   r   rV   ÚkindÚcustomÚdescriptionr   zA design made for this piece.z-the action must be use, adapt or design, not )r   rH   ÚlowerÚ_namedÚ
model_dumpr3   r>   r   Úmodel_fieldsrG   Úblock_as_writtenr   ÚdictÚ
setdefaultrD   )
r^   rQ   rV   r   Úbaserj   ÚdataÚkÚvr0   s
             r'   rB   rB   _   sÍ  € Ü�—‘˜HÓ%Ò+¨Ó,×2Ñ2Ó4€FØ�‚Ü�i §¡¨FÓ!3Ó4°e¸TÐAÐAØ�ÒÜ�i §¡¨FÓ!3Ó4ˆØ—*‘*˜YÓ'Ò-¨2ˆØ�‰Ó ˆØŸ)™)˜ IÐ.ˆˆV‰Ø&ˆˆW‰Ø�;‰;�wÔØw˜t G™}ÐwÀ'È'ÑBR×BXÑBXÓBZ×0v¹$¸!¸QÐ^_Ôch×cuÑcuÒ^u°°A±Ó0vÐwˆD�‰MØ Ÿ™ XÓ.Ò\ÐPT×P[ÑP[Ö2\È1Ô3CÀAÕ3FÒ2\ˆˆX‰Ü! $Ó'¨°$·)±)Ð;Ð;Ø�ÒÜ�F—J‘J˜zÓ*Ò0¨bÓ1ˆØ�‰˜	 7Ô+Ø�‰˜ Ô)Ø�‰˜¤s¨6¯:©:°hÓ+?Ò+bÐCbÓ'cÔdØ&ˆˆW‰Ü! $Ó'¨°4Ð7Ð7Ü
ÐDÀVÀJÐOÓ
PÐPùó 1wùÚ2\s   ÃG(Ã4G(Ä"G.c                óÄ   ‡— t        |xs d«      j                  «       j                  «       Št        ˆfd„| j	                  «       D «       d «      }|€t        d|›�«      ‚|S )Nr2   c              3  óP   •K  — | ]  \  }}|j                  «       ‰k(  sŒ|–— Œ y ­wr8   )rq   )r/   rc   rZ   Úwants      €r'   r1   z_named.<locals>.<genexpr>y   s"   øè ø€ ÒE‘d�a˜°1·7±7³9ÀÓ3D”ÑEùs   ƒ&Ÿ&zthere is no template called )r   rI   rq   Únextr>   rD   )rQ   r3   Úhitr~   s      @r'   rr   rr   w   sX   ø€ ÜˆtŠz�r‹?× Ñ Ó"×(Ñ(Ó*€DÜ
ÓE˜iŸo™oÓ/ÔEÀtÓ
L€CØ
€{ÜÐ7¸°xÐ@ÓAÐAØ€Jr&   c                ó^  — d| j                   i| j                  ¥}| j                  r| j                  |d<   t        | j                  t        j                  | j                   g «      «      D ��cg c]+  \  }}|j                  sŒ|j                  rŒ |j                  ‘Œ- }}}|r||d<   |S c c}}w )z{A template's block back in the file form, looks and all, so an adaptation that changes only the style keeps
    the blocks.r-   r3   Úoptional)	r-   Úoptionsr3   ÚziprO   r   rH   ÚrequiredÚkey)ÚblockÚwrittenr{   Úcr‚   s        r'   ru   ru      sŽ   € ð �u—z‘zÐ3 U§]¡]Ð3€GØ‡z‚zØŸ*™*ˆ�‰Ü"% e§l¡l´H·L±LÀÇÁÈRÓ4PÓ"Q×s™$˜!˜QÐUV×U_ÓU_Ðhi×hrÓhr�—“Ðs€HÑsÙØ&ˆ�
ÑØ€Nùó ts   Á-B)ÂB)ÂB)c                ór  — t        | «      }d|v r¢|j                  «       D �cg c](  }|j                  «       sŒd|vsŒ|j                  «       ‘Œ* }}t        |«      dkD  r|d   nd}t        |«      dkD  r&|d   j	                  dd«      d   j                  «       nd}|› d|› �j                  d«      S |S c c}w )	zfA validation error in one line: the field and what it should have been, not the library's full report.zvalidation errorzFor further informationr   r2   r)   ú[r   r6   )r   Ú
splitlinesrI   ÚlenrP   )r`   ÚtextÚlineÚlinesÚfield_Úwhats         r'   rL   rL   ‹   s®   € äˆs‹8€DØ˜TÑ!Ø*.¯/©/Ó*;Öv $¸t¿z¹z½|ÐPiÐquÒPu�—‘•ÐvˆÐvÜ  ›Z¨!š^��q’°ˆÜ47¸³JÀ²Nˆu�Q‰x�~‰~˜c 1Ó% aÑ(×.Ñ.Ô0ÈˆØ�˜˜D˜6Ð"×(Ñ(¨Ó.Ð.Ø€Kùò	 ws   ¢B4¸B4½B4c	                ó�  — g }	| j                  «       D ]§  \  }
}||
   }|j                  rdn&d|j                  |«      j                  dd«      d   z   }|	j	                  d|
› d|j
                  › ddj                  |j                  «      xs d	› d
dj                  d„ |j                  D «       «      › d|› d�«       Œ© d|j                  «       xs d› d|j                  «       › d|j                  «       xs d› d|j                  «       xs d› d|j                  «       xs d› d|› d�dj                  |	«      z   dz   t        «       z   S )Nzcan be filledzcannot be filled: r6   r   r<   ú- z Suits: ú, Úanythingz
. Blocks: c              3  ó4   K  — | ]  }|j                   –— Œ y ­wr8   r,   r.   s     r'   r1   z_user_prompt.<locals>.<genexpr>œ   s    è ø€ ò  oIÐz{Ðop×ouÕouñ  oIùs   ‚z. ú.zTHE DESIGN BRIEF YOU WROTE
Únonez

THE BRIEF
z%

THE OWNER'S WORDS ABOUT THE DESIGN
Únothingz

WHAT IS KNOWN
znothing beyond the briefz

WHAT THIS OWNER KEPT BEFORE
znothing yetz

THE SHELF (z)
ú
z

)r>   rC   r9   rP   rM   rp   rN   ÚsuitsrG   rI   Úvocabulary_lines)rQ   r[   r;   rR   rT   rU   rV   rW   rX   Úshelfr3   rZ   r:   Ústates                 r'   r?   r?   –   s¯  € à€EØ—?‘?Ó$ò V‰ˆˆaØ�‰JˆØ#$§4¢4‘Ð-AÀAÇIÁIÈeÓDT×DZÑDZÐ[_ÐabÓDcÐdfÑDgÑ-gˆØ�‰�r˜$˜˜r !§-¡- °¸¿¹À1Ç7Á7Ó9KÒ9YÈzÐ8ZÐZdÐei×enÑenñ  oIð  @A÷  @Hñ  @Hô  oIó  fIð  eJð  JLð  MRð  LSð  STð  Uõ  	VðVð +¨6¯<©<«>Ò+C¸VÐ*DÀOÐTY×T_ÑT_ÓTaÐSbð c3Ø3>×3DÑ3DÓ3FÒ3SÈ)Ð2TÐTgÐhm×hsÑhsÓhuò  iTð  zTð  hUð U,Ø,1¯K©K«MÒ,J¸]Ð+KÈ?Ð[bÐZcÐcfðhàjn×jsÑjsÐtyÓjzñ{ð ñô (Ó)ñ*ð +r&   c                 ó(  — dj                  d„ t        j                  «       D «       «      } dj                  d„ t        j                  «       D «       «      }dj                  d„ t        j
                  j                  «       D «       «      }d| › d|› d|› �S )z¹The blocks with the values each needs, the looks a block may take and the style words for the whole: what a
    design may be made of, for any prompt that asks the model to compose one.r›   c              3  ó–   K  — | ]A  \  }}d |› dt        j                  |d«      › d�dj                  d„ |D «       «      xs dz   –— ŒC y­w)r”   z (r2   z): r•   c              3  óX   K  — | ]"  }|j                   › |j                  rd nd› �–— Œ$ y­w)r2   z (optional)N)r†   r…   )r/   r{   s     r'   r1   z-vocabulary_lines.<locals>.<genexpr>.<genexpr>¦   s4   è ø€ ò  JIÐ~ÈQÏUÉUÈGÐZ[×ZdÒZdÑTVÐjwÐSxÔJyñ  JIùs   ‚(*rš   N)r   rH   rN   )r/   rn   Úvalss      r'   r1   z#vocabulary_lines.<locals>.<genexpr>¦   sz   è ø€ ò  {ñ  \fð  \`ð  bf˜˜D˜6 ¤E§I¡I¨d°BÓ$7Ð#8¸Ð<ÀÇ	Á	ñ  JIð  DHô  JIó  AIò  AVð  MVõ  Wñ  {ùs   ‚AA	c              3  óP   K  — | ]  \  }}d |› ddj                  |«      › �–— Œ  y­w)r”   r6   ú | N)rN   )r/   rz   r{   s      r'   r1   z#vocabulary_lines.<locals>.<genexpr>§   s)   è ø€ ÒI±D°A°q˜˜1˜#˜R §
¡
¨1£˜Ô/ÑIùs   ‚$&c              3  óˆ   K  — | ]:  \  }}d |› ddj                  d„ t        |j                  dd«      D «       «      › �–— Œ< y­w)r”   r6   r¥   c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wr8   )r   )r/   Úas     r'   r1   z-vocabulary_lines.<locals>.<genexpr>.<genexpr>¨   s   è ø€ Ò-i¸¬c°!¯fÑ-iùs   ‚Ú__args__r%   N)rN   ÚgetattrÚ
annotation)r/   r3   r‘   s      r'   r1   z#vocabulary_lines.<locals>.<genexpr>¨   sK   è ø€ ò  \Ñp|ÐptÐv|˜˜4˜&  5§:¡:Ñ-i¼gÀf×FWÑFWÐYcÐegÓ>hÔ-iÓ#iÐ"jÔkñ  \ùs   ‚A Az8THE BLOCKS A DESIGN MAY USE (and the values each needs)
z

THE LOOKS A BLOCK MAY TAKE
z 

THE STYLE WORDS FOR THE WHOLE
)rN   r   r>   r   r   rt   )rG   Úlooksrm   s      r'   r�   r�   £   s»   € ð �Y‰Yñ  {ô  jr÷  jxñ  jxó  jzô  {ó  {€FØ�I‰IÑI¼D¿J¹J»LÔIÓI€EØ�I‰Iñ  \ô  AF÷  ASñ  AS÷  AYñ  AYó  A[ô  \ó  \€EØGÈÀxÐOoÐpuÐovØ1°%°ð:ð ;r&   )r2   r2   ÚemailÚNoter2   r2   N)rQ   úDict[str, Template]rR   r   rO   r   r;   zDict[str, bool]rS   ÚAskrT   r   rU   r   rV   r   r=   r   rW   r   rX   r   rY   z-Optional[Callable[[Template], Optional[str]]]Úreturnr   )r^   rv   rQ   r¯   rV   r   )rQ   r¯   r3   r   r±   r   )r±   rv   )r`   Ú	Exceptionr±   r   )r[   zDict[str, Fit]rR   r   rT   r   rU   r   rV   r   rW   r   rX   r   r±   r   )r±   r   )%Ú__doc__Ú
__future__r   Údataclassesr   r   Útypingr   r   r   r	   r
   rG   r   r   r   Úloadr   Úspecr   r   rO   r   r   r   r   rv   r°   rA   r   rf   rB   rr   ru   rL   r?   r�   r%   r&   r'   ú<module>r¹      sï   ðñkõ #ç (ß 6Õ 6ç )Ñ )Ý $ß !ß $Ñ $à��Sˆz˜4ÐÑ €ð
C€ð8 ÷ð ó ðð \bØeið PØð PØ),ð PØ<?ð PØUXð Pàð Pà$'ð Pà5bð Pànvó PóFQó0ó	óð
+Øð
+Ø%(ð
+Ø-0ó
+ô;r&   