Ë
    ¼vëjË  ã                  ó`  — d Z ddlmZ ddlZddlmZmZmZmZ ddl	m
Z
mZ ddlmZmZ eeegeeef   f   Zd ed	d
d¬«       edd
dd¬«       edd
d¬«      giZdZ ej&                  d«      Z ej&                  d«      ZdZ G d„ de«      Zd d„Zd!d„Zd"d#d„Zd$d„Zd"d%d„Zd&d„Zd'd„Zd(d„Z y))ay  The words for a chosen template: which slots the copy model writes, the prompt that asks for exactly those, and the
checks on what came back (size, and no code or figure nobody gave). Words the owner dictated are held already and are
never rewritten; the model is told them so the rest matches. The model call is a function the product passes in:
(system, user) -> {key: text}.é    )ÚannotationsN)ÚAnyÚCallableÚDictÚListé   )ÚTemplateÚValue)ÚValuesÚmeasureÚemailúcopy.subjectÚcopyé	   )ÚkeyÚsourceÚ	max_wordsúcopy.subject_namedF)r   r   Úrequiredr   úcopy.preheaderé   z{{first_name}}z\b[A-Z][A-Z0-9]{3,}\bu)   \d+(?:\.\d+)?\s?%|[$Â£â‚¬â‚¹]\s?\d[\d,.]*a;  You write the words for one piece of content whose design is already chosen. You are given the brief,
what is known about the brand, the audience and the facts in hand, any words the owner dictated, and the slots to
fill, each with what it is and how long it may be. Write every slot asked for and nothing else. Rules: say only
what the brief and the facts say, never invent a number, a code, a date, a place or a product; no links or web
addresses in the words, the design carries the button; no placeholders and no merge fields, except the one token
{{first_name}} in copy.subject_named, which the sender replaces with the person's first name; match the dictated
words in tone and do not repeat them; keep to each slot's length; plain language a person would say. Answer as a
JSON object whose keys are exactly the slot keys.c                  ó   — e Zd ZdZy)ÚInventedzEThe words state a code or a figure nothing given to the writer holds.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú]/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/galaxiq_utils/templates/copy.pyr   r       s   „ ÚOr   r   c                óL  — | j                  «       D �cg c]  }|j                  dk(  sŒ|‘Œ c}t        t        j	                  | j
                  g «      «      z   }|D �cg c]   }|j                  |j                  «      rŒ|‘Œ" }}|rt        d„ |D «       «      rg S |S c c}w c c}w )zgThe copy values this template needs that nobody holds yet, plus the channel's own (an email's subject).r   c              3  óV   K  — | ]!  }|j                    xs |j                  d v –— Œ# y­w))r   r   N)r   r   ©Ú.0Úvs     r    ú	<genexpr>z!slots_to_write.<locals>.<genexpr>*   s)   è ø€ ÒpÐfg !§*¡*˜nÒa°·±Ð9aÐ0aÓaÑpùs   ‚'))	Úvaluesr   ÚlistÚEXTRAÚgetÚchannelÚhasr   Úall)Útemplater'   r%   ÚwantedÚlefts        r    Úslots_to_writer1   $   sŠ   € à!Ÿ™Ó*ÖA�A¨a¯h©h¸&Ó.@ŠaÒAÄDÌÏÉÐS[×ScÑScÐegÓIhÓDiÑi€FØÖ7�! V§Z¡Z°·±Õ%6ŠAÐ7€DÐ7ñ œ#ÑpÐkoÔpÔpˆ2ÐzÐvzÐzùò	 BùÚ7s   “B¨BÁ B!Á>B!c                óè   — | j                  «       D �ci c]T  }|j                  dk(  sŒ|j                  |j                  «      sŒ/|j                  |j	                  |j                  «      “ŒV c}S c c}w )Nr   )r'   r   r,   r   r*   )r.   r'   r%   s      r    Údictatedr3   -   sS   € Ø.6¯o©oÓ.?Öl¨À1Ç8Á8ÈvÓCUÐZ`×ZdÑZdÐef×ejÑejÕZkˆA�E‰E�6—:‘:˜aŸe™eÓ$Ñ$ÒlÐlùÒls   “A/¨A/Á(A/c                óv  ‡— g }|D �]*  Št        ˆfd„| j                  D «       | j                  «      }‰j                  dk(  rd}nJ‰j                  dk(  rd}n8‰j                  dk(  rd}n&‰j                  dk(  rd	}n‰j                  d
k(  rd}nd}‰j
                  rd‰j
                  › d�n‰j                  rd‰j                  › d�nd}	‰j                  rdnd}
|j                  d‰j                  › d‰j                  j                  d«      d   j                  dd«      › d|› d|› d|	› |
› �«       �Œ- dj                  d„ t        | |«      j                  «       D «       «      xs d}d|j                  «       › d|j                  «       xs d › d!|j                  «       xs d"› d#|› d$�	dj                  |«      z   S )%Nc              3  óŒ   •K  — | ];  }|j                   D ]*  }|j                  ‰j                  k(  sŒ|j                  –— Œ, Œ= y ­w©N)r'   r   Útype)r$   ÚbÚbvr%   s      €r    r&   zuser_prompt.<locals>.<genexpr>4   s6   øè ø€ Ò\ ÀÇÁÒ\¸"ÈBÏFÉFÐVW×V[ÑV[ËO�a—f•fÐ\�fÑ\ùs
   ƒ-A±Az
facts.rowsz;a list of [label, value] pairs, only facts the brief statesz	copy.bodyz~a list of two or three short paragraphs, each one or two full sentences that read on from each other; never one-line fragmentsr   z°the subject for a person whose first name is known: the same idea as copy.subject with {{first_name}} in it once, where a name reads naturally; leave it out if a name would notr   zrthe preview line a mail client shows beside the subject: one sentence that adds to the subject, not a repeat of itr(   za list of short lineszone lineúat most ú wordsú charactersÚshortÚ z2; optional: leave it out unless it earns its placeú- z: the ú.éÿÿÿÿÚ_ú z of the z; ú
c              3  ó2   K  — | ]  \  }}d |› d|› �–— Œ y­w©r?   z: Nr   )r$   Úkr%   s      r    r&   zuser_prompt.<locals>.<genexpr>D   s    è ø€ ÒR¡t q¨!�r˜!˜˜B˜q˜c”]ÑRùó   ‚Únonez
THE BRIEF
z

WHAT IS KNOWN
znothing beyond the briefz

THE BRAND'S VOICE
zplain and warmz<

WORDS THE OWNER DICTATED (already placed, do not rewrite)
z

THE SLOTS TO WRITE
)ÚnextÚblocksr+   r   Úkindr   Ú	max_charsr   ÚappendÚsplitÚreplaceÚjoinr3   ÚitemsÚstrip)r.   Úslotsr'   ÚbriefÚknownÚvoiceÚlinesÚblockÚshapeÚsizeÚstandingÚsaidr%   s               @r    Úuser_promptr^   1   sÙ  ø€ Ø€EØó {ˆÜÓ\ h§o¡oÔ\Ð^f×^nÑ^nÓoˆØ�5‰5�LÒ ØQ‰EØ�U‰U�kÒ!ð U‰EØ�U‰UÐ*Ò*ð G‰EØ�U‰UÐ&Ò&ð I‰EØ�V‰V�vÒØ+‰EàˆEØ12·²�˜!Ÿ+™+˜ fÑ-Ðij×itÒitÀHÈQÏ[É[ÈMÐYdÑBeð  {BˆØŸš‘2Ð)]ˆØ�‰�r˜!Ÿ%™%˜  q§u¡u§{¡{°3Ó'7¸Ñ';×'CÑ'CÀCÈÓ'MÐ&NÈhÐW\ÐV]Ð]_Ð`eÐ_fÐfhÐimÐhnÐowÐnxÐyÖzð!{ð" �9‰9ÑR¬x¸À&Ó/I×/OÑ/OÓ/QÔRÓRÒ\ÐV\€DØ˜%Ÿ+™+›-˜Ð(;¸E¿K¹K»MÒ<gÐMgÐ;hð i"Ø"'§+¡+£-Ò"CÐ3CÐ!Dð  EDð  EIð  DJð J#ð$à&*§i¡i°Ó&6ñ7ð 8r   c           	     ób  — dj                  d„ | j                  «       D «       «      }|j                  «       j                  dd«      }t	        t
        j                  |«      t        j                  |«      z   D �ch c]'  }|j                  «       j                  dd«      |vsŒ&|’Œ) c}«      S c c}w )zQCodes and amounts in the answer that appear nowhere in what the writer was given.rC   c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wr6   ©Ú_flatr#   s     r    r&   zinvented.<locals>.<genexpr>L   s   è ø€ Ò6 ”E˜!—HÑ6ùrH   r>   )rQ   r'   ÚupperrP   ÚsortedÚCODEÚfindallÚAMOUNT)ÚanswerÚgivenÚtextÚhaveÚms        r    Úinventedrm   J   s�   € à�8‰8Ñ6 f§m¡m£oÔ6Ó6€DØ�;‰;‹=× Ñ   bÓ)€DÜœdŸl™l¨4Ó0´6·>±>À$Ó3GÑGÖr˜È1Ï7É7Ë9×K\ÑK\Ð]`ÐbdÓKeÐmqÒKq’1ÒrÓsÐsùÒrs   Á9'B,Â!B,c                óÐ  ‡‡— t        | ‰«      Š‰si S t        | ‰‰|||«      }dj                  ||t        t	        t        | ‰«      j                  «       «      «      dj                  ˆfd„dD «       «      g«      }t        ‰ |t        |«      xs i «      }t        | |«      dD �	cg c]2  }	|	|v sŒt        t        ||	   «      j                  «       «      dkD  sŒ1|	‘Œ4 c}	z   }
t        ||«      }|
s|rÁ|}|
r |ddj                  ˆfd„|
D «       «      z   z  }|r|d	d
j                  |«      z   dz   z  }t        ‰ |t        |«      xs i «      }|j                  |j                  «       D �	�ci c]  \  }	}|s|	|
v sŒ|	|“Œ c}}	«       t        ||«      }|rt!        dd
j                  |«      › d�«      ‚|j                  «       D ]  \  }}‰j#                  ||«       Œ |S c c}	w c c}}	w )zþFills the template's copy slots into `values`. A slot over its size, or words stating a code or a figure
    nobody gave, are asked for again once with the reason; words still inventing are refused (Invented). Returns
    {key: text} of what was written.rC   c              3  óZ   •K  — | ]"  }t        ‰j                  |«      xs d «      –— Œ$ y­w)r>   N)Ústrr*   )r$   rG   r'   s     €r    r&   zwrite.<locals>.<genexpr>Z   s#   øè ø€ Ò}¸Aœs 6§:¡:¨a£=Ò#6°B×7Ñ}ùs   ƒ(+)z
offer.codez
offer.saidz
cart.totalzproduct.price)r   r   zG

These came back too long; write only these again, within their size:
rD   c              3  óB   •K  — | ]  }d |› dt        ‰|«      › �–— Œ y­wrF   )Ú_size)r$   rG   rT   s     €r    r&   zwrite.<locals>.<genexpr>a   sN   øè ø€ ò  nYð  OPÐprÐstÐruÐuwÔx}ð  Dð  FGó  yHð  xIô  oJñ  nYùs   ƒzT

These were stated but nothing you were given holds them, so they must not appear: z, za. Write every slot again without them. Say there is a code or a discount only when one was given.zthe words state z-, which the brief and the journey do not give)r1   r^   rQ   rb   r(   r3   r'   Ú_onlyÚSYSTEMr   Úlenrp   rO   rm   ÚupdaterR   r   Úput)r.   r'   rU   ÚaskrV   rW   Úpromptri   rh   rG   ÚoverÚmade_upÚagainÚretryr%   Ústillr   rj   rT   s    `                @r    Úwriter   Q   s	  ù€ ô ˜8 VÓ,€EÙØˆ	Ü˜ 5¨&°%¸ÀÓF€FØ�H‰H�e˜U¤E¬$¬x¸À&Ó/I×/PÑ/PÓ/RÓ*SÓ$TØ—h‘hÓ}ÐA|Ô}Ó}ðó @€Eä�5™#œf fÓ-Ò3°Ó4€FÜ�8˜VÓ$Ð3DÖ'x¨aÈÈVÊÔX[Ô\_Ð`fÐghÑ`iÓ\j×\pÑ\pÓ\rÓXsÐvwÓXwªÒ'xÑx€DÜ�v˜uÓ%€GÙ‰wØˆÙØÐaÐdh×dmÑdmó  nYð  TXô  nYó  eYñ  Yñ  YˆEÙØÐnÐqu×qzÑqzð  |Có  rDñ  DØ{ñ|ñ }ˆEä�e™S¤¨Ó/Ò5°2Ó6ˆØ�‰¨¯©«×N¡  1¹ÀAÈÂI�q˜!‘tÓNÔOÜ˜ Ó'ˆÙÜÐ-¨d¯i©i¸Ó.>Ð-?Ð?lÐmÓnÐnØ—\‘\“^ò ‰	ˆˆTØ�
‰
�3˜Õðà€Mùò! (yùó Os   Â$	GÂ.(GÃGÅ)G"
Å8G"
c           	     ó®   — | D �ch c]  }|j                   ’Œ }}|j                  «       D ��ci c]  \  }}||v sŒ|d dg i fvsŒ||“Œ c}}S c c}w c c}}w )Nr>   )r   rR   )rT   rh   r%   ÚkeysrG   s        r    rs   rs   o   sX   € Ø Ö!�aˆA�E‹EÐ!€DÐ!Ø#Ÿ\™\›^×Y‘T�Q˜¨q°Dªy¸QÀtÈRÐQSÐUWÐFXÒ=XˆAˆq‰DÓYÐYùò "ùÛYs   …A­AºAÁAc                óª   ‡— t        ˆfd„| D «       d «      }|r|j                  rd|j                  › d�S |r|j                  rd|j                  › d�S dS )Nc              3  óB   •K  — | ]  }|j                   ‰k(  sŒ|–— Œ y ­wr6   )r   )r$   Úsr   s     €r    r&   z_size.<locals>.<genexpr>u   s   øè ø€ Ò/�A !§%¡%¨3£,ŒaÑ/ùs   ƒ˜r:   r;   r<   r=   )rJ   r   rM   )rT   r   r%   s    ` r    rr   rr   t   sb   ø€ ÜÓ/˜Ô/°Ó6€AÙ-.°1·;²;ˆX�a—k‘k�] &Ð)ð  JÑklÐqr×q|Òq|ÀhÈqÏ{É{ÈmÐ[fÐDgð  Jð  CJð  Jr   c                ó|   — t        | t        t        f«      rdj                  d„ | D «       «      S t	        | xs d«      S )NrC   c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wr6   ra   )r$   Úxs     r    r&   z_flat.<locals>.<genexpr>{   s   è ø€ Ò, Qœ˜aŸÑ,ùrH   r>   )Ú
isinstancer(   ÚtuplerQ   rp   )r%   s    r    rb   rb   y   s3   € Ü�!”dœE�]Ô#Ø�x‰xÑ,¨!Ô,Ó,Ð,ÜˆqŠw�B‹<Ðr   )r.   r	   r'   r   ÚreturnúList[Value])r.   r	   r'   r   rŠ   úDict[str, Any])r>   r>   )r.   r	   rT   r‹   r'   r   rU   rp   rV   rp   rW   rp   rŠ   rp   )rh   rŒ   ri   rp   rŠ   z	List[str])r.   r	   r'   r   rU   rp   rx   ÚAskrV   rp   rW   rp   rŠ   rŒ   )rT   r‹   rh   rŒ   rŠ   rŒ   )rT   r‹   r   rp   rŠ   rp   )r%   r   rŠ   rp   )!r   Ú
__future__r   ÚreÚtypingr   r   r   r   Úspecr	   r
   r'   r   r   rp   r�   r)   Ú
NAME_TOKENÚcompilere   rg   rt   Ú
ValueErrorr   r1   r3   r^   rm   r   rs   rr   rb   r   r   r    ú<module>r•      sÝ   ðñ"õ #ã 	ß ,Ó ,ç !ß #à��Sˆz˜4  S ™>Ð)Ñ*€à	‘5˜^°FÀaÔHÙÐ1¸&È5Ð\]Ô^ÙÐ-°fÈÔKðMð 	N€ð €
Ø€r‡z�zÐ*Ó+€Ø	ˆ�‰Ð@Ó	A€ð
5€ôPˆzô Pó{ómô8ó2tôó<Zó
Jô
r   