Ë
    §‘ˆj;  ã                   óÈ  — d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	mZ
 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlZd dlZd dlZ ej4                  ej6                  d	¬
«        ej8                  d«      Z ed¬«      Zej>                  jA                  d«      D � cg c]  } | jC                  «       ‘Œ c} Z"ejG                  ee"ddgdg¬«       ejI                  e«      dedefd„«       Z%ejI                  e&«      dede&fd„«       Z'ejQ                  d«      d„ «       Z)ejU                  e«       ejU                  e
«       ejU                  e«       ejU                  e«       ejU                  e«       ejW                  d«      ejW                  d«      d„ «       «       Z,ejW                  d«      defd„«       Z-e.dk(  r ej^                  ddd d¬!«       yyc c} w )"é    )ÚFastAPIÚRequest)ÚJSONResponse)ÚCORSMiddleware)Úrouter)Úsettings)ÚQuotaExceededError)Ú
redis_poolNz4%(asctime)s - %(name)s - %(levelname)s - %(message)s)ÚlevelÚformatÚmainzStrategist AI Service)Útitleú,TÚ*)Úallow_originsÚallow_credentialsÚallow_methodsÚallow_headersÚrequestÚexcc              ƒ   ó‚   K  — t         j                  d|j                  › �«       t        dd|j                  dœ¬«      S ­w)NzQuota exceeded: i“  Úerror©ÚstatusÚmessage©Ústatus_codeÚcontent)ÚloggerÚwarningr   r   ©r   r   s     ú'/var/www/html/strategist-ai/app/main.pyÚquota_exception_handlerr#   $   s:   è ø€ ä
‡N�NÐ% c§k¡k ]Ð3Ô4ÜØØ"¨s¯{©{Ñ;ôð ùs   ‚=?c              ƒ   ó^   K  — t         j                  d|› �d¬«       t        ddddœ¬«      S ­w)	NzUnhandled exception: T)Úexc_infoiô  r   z"An internal server error occurred.r   r   )r   r   r   r!   s     r"   Úglobal_exception_handlerr&   -   s7   è ø€ ä
‡L�LÐ(¨¨Ð.¸€LÔ>ÜØØ"Ð/SÑTôð ùs   ‚+-Ústartupc               ƒ   ó¸  K  — t        j                  «        t        j                  d«       t        j                  dt        j
                  › �«       t        j                  dt        j                  › �«       t        j                  dt        j                  › �«       t        j                  dt        j                  › �«       t        j                  d«       y ­w)Nz!Starting Strategist AI Service...zCORS Allowed Origins: zDatabase Host: zLLM Model: zEmbedding Model: zProduction readiness audit: OK)	r
   Úresetr   Úinfor   ÚALLOWED_ORIGINSÚDB_HOSTÚ	LLM_MODELÚEMBED_MODEL© ó    r"   Ústartup_eventr1   ?   s˜   è ø€ ô ×ÑÔä
‡K�KÐ3Ô4Ü
‡K�KÐ(¬×)AÑ)AÐ(BÐCÔDÜ
‡K�K�/¤(×"2Ñ"2Ð!3Ð4Ô5Ü
‡K�K�+œh×0Ñ0Ð1Ð2Ô3Ü
‡K�KÐ#¤H×$8Ñ$8Ð#9Ð:Ô;Ü
‡K�KÐ0Õ1ùs   ‚CCú/z/healthc               ƒ   ó<   K  — ddt        j                   «       ddœS ­w)NÚhealthyzStrategist AIz1.0.0)r   ÚserviceÚ	timestampÚversion)Útimer/   r0   r"   Úhealth_checkr9   V   s$   è ø€ ð Ø"Ü—Y‘Y“[Øñ	ð ùs   ‚z/debug-pathc              ƒ   ób   K  — | j                   j                  t        | j                   «      dœS ­w)N)ÚpathÚfull_url)Úurlr;   Ústr)r   s    r"   Ú
debug_pathr?   `   s+   è ø€ ð —‘× Ñ Ü˜Ÿ™Ó$ñð ùs   ‚-/Ú__main__zapp.main:appz0.0.0.0iA  )ÚhostÚportÚreload)0Úfastapir   r   Úfastapi.responsesr   Úfastapi.middleware.corsr   Úapp.api.endpointsr   Úapp.api.websocketÚ	ws_routerÚapp.api.shopifyÚshopify_routerÚapp.api.sourcesÚsources_routerÚapp.api.catalogÚcatalog_routerÚapp.core.configr   Úapp.services.infra.quotasr	   Úapp.services.infra.redisr
   ÚuvicornÚloggingr8   ÚbasicConfigÚINFOÚ	getLoggerr   Úappr+   ÚsplitÚstripÚoriginsÚadd_middlewareÚexception_handlerr#   Ú	Exceptionr&   Úon_eventr1   Úinclude_routerÚgetr9   r?   Ú__name__Úrun)Úos   0r"   ú<module>re      só  ðß $Ý *Ý 2Ý $Ý 1Ý 4Ý 4Ý 4Ý $Ý 8Ý /Û Û Û ð €× Ñ Ø
�,‰,ØAõð 
ˆ×	Ñ	˜6Ó	"€áÐ+Ô,€ð '×6Ñ6×<Ñ<¸SÓAÖ
B˜ˆ1�7‰7�9Ò
B€Ø × Ñ ØØØØ�%Ø�%ð ô ð ×ÑÐ)Ó*ð¨7ð Ð9Kò ó +ðð ×Ñ�yÓ!ð¨Gð ¸)ò ó "ðð" ‡�ˆiÓñ2ó ð2ð  × Ñ �6Ô Ø × Ñ �9Ô Ø × Ñ �>Ô "Ø × Ñ �>Ô "Ø × Ñ �>Ô "à‡�ˆƒØ‡�ˆÓñó ó ðð ‡�ˆÓð˜gò ó ðð ˆzÒØ€G‡K�K� Y°TÀ$ÖGð ùò[ Cs   Â'G