+
    ©ljt'  ã                  ó
  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIt^ RIHt ]	! ]4      P!                  4       P"                  ^,          t]R,          R,          R,          tR	t^<tR
tRtR R ltR R ltR R ltR+R R lltR R ltR R lt]3R R lltR,R R lltRRRRRRR^R RR!R/R" R# llt R-R$ R% llt!R& R' lt"]#R(8X  d+   ]! R)]$! ]! 4       4       24       ]! 4       t%]! R*]% 24       R# R# ).z†PixelLab v2 REST client.

Docs: https://api.pixellab.ai/v2/llms.txt
Auth: Bearer token from apps/web/.env.local (PIXELLAB_API_TOKEN).
)ÚannotationsN)ÚPath)ÚAny)Úload_dotenvÚappsÚwebz
.env.localzhttps://api.pixellab.ai/v2g       @g     Àr@c               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚstr© )Úformats   "ÚI/Users/marcosmor/Desktop/pr_party_ibm_hackthon/scripts/pixellab/client.pyÚ__annotate__r      s   € ÷ ñ �Sñ ó    c                 ó–   € \        \        4       \        P                  P	                  R 4      p V '       g   \        R\         24      hV # )ÚPIXELLAB_API_TOKENzPIXELLAB_API_TOKEN missing in )r   ÚENV_PATHÚosÚenvironÚgetÚRuntimeError)Útokens    r   Ú_load_tokenr      s8   € Ü”ÔÜ�J‰J�N‰NÐ/Ó0€EßÜÐ;¼H¸:ÐFÓGÐGØ€Lr   c               ó   € V ^8„  d   QhRR/# )r	   r
   zdict[str, str]r   )r   s   "r   r   r   $   s   € ÷ ñ �.ñ r   c                 ó(   € R R\        4        2RRRR/# )ÚAuthorizationzBearer zContent-Typezapplication/jsonÚAccept)r   r   r   r   Ú_headersr   $   s&   € à˜7¤;£= /Ð2ØÐ*ØÐ$ðð r   c               ó    € V ^8„  d   QhRRRR/# )r	   Úmsgr   r
   ÚNoner   )r   s   "r   r   r   ,   s   € ÷ <ñ <ˆcð <�dñ <r   c                óD   € \        R V  2\        P                  RR7       R# )z[pixellab] T)ÚfileÚflushN)ÚprintÚsysÚstderr)r    s   &r   Ú_logr(   ,   s   € Ü	ˆK˜�uÐ
¤C§J¡J°d×;r   c               ó4   € V ^8„  d   QhRRRRRRRRRRR	R
RR/# )r	   Úmethodr   ÚpathÚjsonúdict[str, Any] | NoneÚparamsÚacceptú
str | NoneÚstreamÚboolr
   zrequests.Responser   )r   s   "r   r   r   0   sN   € ÷  ñ  Øð à
ð ð  ð ð "ð	 ð
 ð ð ð ð ñ r   c           
     óä  € VP                  R4      '       d   TM	\         V 2p\        4       pV'       d   WGR&   Vf   RMR\        VP	                  4       4       2p\        V  RV RV 24       \        P                  ! V VVVV\        VR7      p	V	P                  R8X  d    \        RV	P                  R	,           24      hV	P                  R
8X  d    \        RV	P                  R	,           24      hV	# )zkAuthenticated request against the PixelLab v2 API.

`path` may be a full URL or a path beginning with `/`.
Úhttpr   z	(no body)zkeys=Ú )Úheadersr,   r.   Útimeoutr1   i‘  z 401 Unauthorized from PixelLab: ºNéÈ   Ni’  z'402 Payment required (out of credits): )Ú
startswithÚBASE_URLr   ÚlistÚkeysr(   ÚrequestsÚrequestÚDEFAULT_TIMEOUTÚstatus_coder   Útext)
r*   r+   r,   r.   r/   r1   Úurlr6   Úsafe_payloadÚresps
   &&&&&&    r   Úauthenticated_requestrF   0   së   € ð —/‘/ &×)Ò)‰$´(°¸D¸6Ð/B€CÜ‹j€GßØ"�Ñà"&¢,‘;°e¼DÀÇÁÃÓ<MÐ;NÐ4O€LÜˆFˆ8�1�S�E˜˜<˜.Ð	)Ô*Ü×ÒØØØØØÜØô€Dð ×Ñ˜3ÔÜÐ=¸d¿i¹iÈ½oÐ=NÐOÓPÐPØ×Ñ˜3ÔÜÐDÀTÇYÁYÈtÅ_ÐDUÐVÓWÐWØ€Kr   c               ó   € V ^8„  d   QhRR/# )r	   r
   r-   r   )r   s   "r   r   r   S   s   € ÷ 	ñ 	Ð*ñ 	r   c                 ó  €  \        RR4      p V P                  ^È8X  d   V P                  4       # \        RV P                   RV P                  R,           24       R#   \
         d   p\        RT 24        Rp?R# Rp?ii ; i)uA   GET /balance â€” best-effort; returns None if endpoint is absent.ÚGETz/balancezGET /balance -> r5   :Néx   NzGET /balance failed: N)rF   rA   r,   r(   rB   Ú	Exception)rE   Úexcs     r   Úget_balancerM   S   s€   € ð,Ü$ U¨JÓ7ˆØ×Ñ˜sÔ"Ø—9‘9“;ÐÜÐ × 0Ñ 0Ð1°°4·9±9¸Tµ?Ð2CÐDÔEñ øô ô ,ÜÐ$ S EÐ*×+Ð+Ùûð,ús   ‚,A ¯,A ÁBÁ(A<Á<Bc               ó   € V ^8„  d   QhRR/# )r	   r
   zlist[dict[str, Any]] | Noner   )r   s   "r   r   r   _   s   € ÷ ñ Ð"=ñ r   c            
     ór  € . R	Op V  F‚  p \        RV4      pTP                  ^È8X  dG   TP	                  4       p\        RT R\        T\        4      '       d   \        T4      MR 24       Tu # \        RT RTP                   24       K„  	  R#   \         d   p\        RT RT 24        Rp?Kª  Rp?ii ; i)
z?Try a few likely endpoints to enumerate template animation IDs.rI   zGET z	 failed: Nzanimation templates found at ú: Údictú -> )z/animations/templatesz/animate-character/templatesz/templates/animationsz/animation-templates)rF   rK   r(   rA   r,   Ú
isinstancer<   Úlen)Ú
candidatesr+   rE   rL   Údatas        r   Úlist_animation_templatesrW   _   s½   € ò€Jó ˆð	Ü(¨°Ó5ˆDð ×Ñ˜sÔ"Ø—9‘9“;ˆDÜÐ0°°°bÄjÐQUÔW[×F\ÒF\¼¸T¼ÐbhÐ8iÐjÔkØŠKÜˆt�D�6˜˜d×.Ñ.Ð/Ð0Ö1ñ ñ øô ô 	Ü�4˜�v˜Y s eÐ,Ô-Ýûð	ús   ‹BÂB6ÂB1Â1B6c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Újob_idr   r7   Úfloatr
   údict[str, Any]r   )r   s   "r   r   r   u   s!   € ÷ $ñ $˜ð $ uð $À.ñ $r   c           	     ó„  € \         P                  ! 4       pRp \         P                  ! 4       V,
          pWA8”  d   \        RV  RV RV R24      h\        RRV  24      pVP                  ^È8w  d0   \        RV  R	VP                   R
VP                  R,           24      hVP                  4       pVP                  R4      ;'       g    VP                  R4      ;'       g    RpWs8w  d   \        RV  RV RVR R24       TpVR9   d   V# VR9   d   \        RV  RV RV 24      h\         P                  ! \        4       EK*  )zLPoll GET /background-jobs/{id} every POLL_INTERVAL_S until completed/failed.Ú zjob z not completed within zs (last status=Ú)rI   z/background-jobs/zpoll rR   r5   r8   ÚstatusÚstatez status=z (t=ú.1fús)z ended with status=rP   >   ÚsuccessÚ	completedÚ	succeeded>   ÚerrorÚfailedÚ	cancelled)ÚtimeÚ	monotonicÚTimeoutErrorrF   rA   r   rB   r,   r   r(   ÚsleepÚPOLL_INTERVAL_S)rY   r7   ÚstartÚlast_statusÚelapsedrE   rV   r_   s   &&      r   Úwait_for_jobrq   u   s@  € ä�NŠNÓ€EØ€KØ
Ü—.’.Ó" UÕ*ˆØÔÜ  f XÐ-CÀGÀ9ÈOÐ\gÐ[hÐhiÐjÓkÐkÜ$ UÐ.?À¸xÐ,HÓIˆØ×Ñ˜sÔ"Ü  v h¨d°4×3CÑ3CÐ2DÀAÀdÇiÁiÐPTÅoÐEVÐWÓXÐXØ�y‰y‹{ˆØ—‘˜(Ó#×>Ð> t§x¡x°Ó'8×>Ð>¸BˆØÔ Ü�4˜�x˜x¨ x¨t°G¸C°=ÀÐCÔDØ ˆKØÐ:Ô:ØˆKØÐ5Ô5Ü  f XÐ-@ÀÀÈÈ4È&ÐQÓRÐRÜ�
Š
”?×#r   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Údescriptionr   Únamer0   r
   r[   r   )r   s   "r   r   r   Œ   s&   € ÷ Iñ I #ð I¨Zð IÀ>ñ Ir   c                óò  € TpRRRV RR^@R^@/RRR	R
RRRRRR/p\        RRVR7      pVP                  R9  d-   \        RVP                   RVP                  R,           24      hVP	                  4       pVP                  R4      ;'       g    VP                  R4      pVP                  R4      ;'       g    VP                  R4      pV'       g   \        RV 24      hV'       d   \        V4       RVRVRV/# )a  POST /create-character-with-8-directions (mode=standard). Waits for job.

The `name` arg is currently ignored: /create-character-with-8-directions does
not accept a `name` field (only /create-character-v3 / pro do). Kept in
signature for callers that pass it.
ÚmodeÚstandardrs   Ú
image_sizeÚwidthÚheightÚtemplate_idÚ	mannequinÚviewzlow top-downÚoutlineÚmediumÚshadingÚsoftÚdetailÚhighÚPOSTz#/create-character-with-8-directions©r,   zcreate character failed: r5   ºNi�  NÚbackground_job_idrY   Úcharacter_idÚidz,create character: no character_id returned: Úraw©r9   éÊ   )rF   rA   r   rB   r,   r   rq   )rs   rt   Ú_ÚpayloadrE   rV   rY   rˆ   s   &&      r   Úcreate_characterr�   Œ   s
  € ð 	€Að 	�
Ø�{Ø�w  H¨bÐ1Ø�{Ø�Ø�8Ø�6Ø�&ð	€Gô ! Ð)NÐU\Ô]€DØ×Ñ˜zÔ)ÜÐ6°t×7GÑ7GÐ6HÈÈ$Ï)É)ÐTXÍ/ÐIZÐ[Ó\Ð\Ø�9‰9‹;€DØ�X‰XÐ)Ó*×@Ð@¨d¯h©h°xÓ.@€FØ—8‘8˜NÓ+×=Ð=¨t¯x©x¸«~€LßÜÐIÈ$ÈÐPÓQÐQßÜ�VÔØ˜L¨(°F¸EÀ4ÐHÐHr   Útemplate_animation_idÚaction_descriptionÚ
directionsÚframe_countÚseedÚanimation_namec               ó8   € V ^8„  d   QhRRRRRRRRRR	R
RRRRR/# )r	   rˆ   r   r�   r0   r‘   r’   zlist[str] | Noner“   Úintr”   z
int | Noner•   r
   r[   r   )r   s   "r   r   r   ­   sZ   € ÷ /-ñ /-Øð/-ð &ð/-ð #ð	/-ð
 !ð/-ð ð/-ð ð/-ð ð/-ð ñ/-r   c          	     ó�  € RT RT;'       g    R./pV'       d   WgR&   V'       d   RVR&   WR&   M!V'       d   RVR&   W'R	&   WGR
&   M\        R4      hVe   WWR&   \        RRVR7      pVP                  R9  d:   \        RT;'       g    T RVP                   RVP                  R,           24      hVP                  4       p	\        V	P                  R4      ;'       g    . 4      p
V	P                  R4      ;'       g    V	P                  R4      pV'       d   Wº9  d   V
P                  V4       V
 F  p\        V4       K  	  RV
RV	/# )zÚPOST /animate-character. Mode=template if template id, else v3 with description.

Always waits for the background job. Pass animation_name to control the
folder name in the resulting ZIP (defaults to a generated one).
rˆ   r’   Úsouthr•   Útemplaterv   r�   Úv3r‘   r“   z8Must provide template_animation_id or action_descriptionr”   r„   z/animate-characterr…   zanimate failed [z]: r5   r†   Úbackground_job_idsr‡   rY   Újob_idsrŠ   r‹   )
Ú
ValueErrorrF   rA   r   rB   r,   r<   r   Úappendrq   )rˆ   r�   r‘   r’   r“   r”   r•   rŽ   rE   rV   r�   ÚsingleÚjids   &$$$$$$      r   Úanimate_characterr¢   ­   sT  € ð  	˜Ø�j×-Ð- W Ið€G÷ Ø$2Ð Ñ!ßØ$ˆ�‰Ø+@Ð'Ò(ß	Øˆ�‰Ø(:Ð$Ñ%Ø!,�ÒäÐSÓTÐTØÒØ�‰ä  Ð)=ÀGÔL€DØ×Ñ˜zÔ)ÜØÐ4×JÐJÐ8JÐKÈ3Ø×ÑÐ   $§)¡)¨D¥/Ð!2ð4ó
ð 	
ð �9‰9‹;€Dä˜dŸh™hÐ';Ó<×BÐBÀÓC€GØ�X‰XÐ)Ó*×@Ð@¨d¯h©h°xÓ.@€Fß�&Ô'Ø�‰�vÔÛˆÜ�SÖñ à�w  tÐ,Ð,r   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   rˆ   r   r7   rZ   r
   r!   r   )r   s   "r   r   r   ß   s&   € ÷ Zñ Z Sð Z°5ð ZÀTñ Zr   c                óÊ  € \         P                  ! 4       p \         P                  ! 4       V,
          pW18”  d   \        RV RV  24      h\        RRV  R2RRR7      pVP                  ^È8X  d   VP                  4        R	# VP                  R
8X  d)   \        RVR R24       \         P                  ! R4       K£  \        RVP                   RVP                  R,           24      h)zLPoll GET /characters/{id}/zip with HEAD-like behavior until ready (not 423).Tzzip not ready within zs for character rI   ú/characters/ú/zipúapplication/zip©r/   r1   Ni§  z$zip not ready (423), retry in 5s (t=ra   rb   g      @zzip pre-check failed: r5   r8   )
ri   rj   rk   rF   rA   Úcloser(   rl   r   rB   )rˆ   r7   rn   rp   rE   s   &&   r   Úwait_for_zip_readyrª   ß   s×   € ä�NŠNÓ€EØ
Ü—.’.Ó" UÕ*ˆØÔÜÐ!6°w°iÐ?OÐP\È~Ð^Ó_Ð_Ü$Ø�\ , ¨tÐ4Ð=NÐW[ô
ˆð ×Ñ˜sÔ"Ø�J‰JŒLÙØ×Ñ˜sÔ"ÜÐ7¸À°}ÀBÐGÔHÜ�JŠJ�sŒOÙÜÐ3°D×4DÑ4DÐ3EÀQÀtÇyÁyÐQUÅÐFWÐXÓYÐYr   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   rˆ   r   Ú
output_dirr   r
   z
list[Path]r   )r   s   "r   r   r   ó   s!   € ÷ ñ ˜sð °ð ¸ñ r   c                ó  € VP                  RRR7       \        RRV  R2RRR7      pVP                  ^È8w  d-   \        RVP                   R	VP                  R
,           24      h\
        P                  ! VP                  4      p. p\        P                  ! V4      ;_uu_ 4       pVP                  4        Fó  pVP                  R4      '       d   K  \        V4      p\        VP                  4      ^8”  d   \        VP                  R,          !  pW,          pVP                  P                  RRR7       VP!                  V4      ;_uu_ 4       q˜P!                  R4      ;_uu_ 4       p
V
P#                  V	P%                  4       4       RRR4       RRR4       VP'                  V4       Kõ  	  RRR4       \)        R\        V4       RV 24       V#   + '       g   i     LQ; i  + '       g   i     L\; i  + '       g   i     LR; i)zLGET /characters/{id}/zip and unzip into output_dir. Returns extracted paths.T)ÚparentsÚexist_okrI   r¥   r¦   r§   r¨   zdownload zip failed: r5   r8   Ú/:é   NNÚwbNz	unzipped z files into )ÚmkdirrF   rA   r   rB   ÚioÚBytesIOÚcontentÚzipfileÚZipFileÚnamelistÚendswithr   rT   ÚpartsÚparentÚopenÚwriteÚreadrŸ   r(   )rˆ   r¬   rE   ÚbufÚ	extractedÚzfÚmemberÚrelÚtargetÚsrcÚdsts   &&         r   Údownload_ziprÈ   ó   s…  € à×Ñ˜T¨DÐÔ1Ü Ø�˜l˜^¨4Ð0Ð9JÐSWô€Dð ×Ñ˜3ÔÜÐ2°4×3CÑ3CÐ2DÀAÀdÇiÁiÐPTÅoÐEVÐWÓXÐXÜ
�*Š*�T—\‘\Ó
"€CØ€IÜ	�Š˜×	Ô	 Ø—k‘k–mˆFØ�‰˜s×#Ò#Ùô �v“,ˆCÜ�3—9‘9‹~ Ô!Ü˜CŸI™I b�MÑ*�ØÕ%ˆFØ�M‰M×Ñ¨°tÐÔ<Ø—‘˜—” C¯©°T×):Ô):¸cØ—	‘	˜#Ÿ(™(›*Ô%÷ *;—à×Ñ˜VÖ$ñ $÷ 
ô 	ˆ9”S˜“^Ð$ L°°Ð	=Ô>ØÐ÷	 *;×):ú——ú÷ 
×	ús=   Â$B*G6ÅG#Å' GÆG#ÆG6ÇG ÇG#Ç#G3Ç.G6Ç6H	Ú__main__ztoken loaded: z	balance: )NNNF)N)g      n@)&Ú__doc__Ú
__future__r   r´   r   r&   ri   r·   Úpathlibr   Útypingr   r>   Údotenvr   Ú__file__Úresolver®   Ú	REPO_ROOTr   r;   r@   rm   ÚPOLL_TIMEOUT_Sr   r   r(   rF   rM   rW   rq   r�   r¢   rª   rÈ   Ú__name__r2   Úbalr   r   r   Ú<module>rÕ      s(  ðñõ #ã 	Û 	Û 
Û Û Ý Ý ã Ý á�‹N×"Ñ"Ó$×,Ñ,¨QÕ/€	Ø�vÕ Õ%¨Õ4€Ø'€Ø€Ø€Ø€õõõ<÷ õF	õð, 0>÷ $÷.IðB/-ð )-ð/-ð &*ð	/-ð
 $(ð/-ð ð/-ð ð/-ð "&÷/-÷dZõ(ð8 ˆzÔáˆ>™$™{›}Ó-Ð.Ð	/Ô0Ù
‹-€CÙˆ9�S�EÐ	Öñ	 r   