
    i                     \    d dl Z d dlmZ d dlmZmZmZ d
dedededeeef         def
d	ZdS )    N)datetime)DictAnyListintentdaxresultusagereturnc                    t          j                                        d          }|}t          |t                    r	 t          j        |          }n#  Y nxY wt          |t                    rt          |          dk    rt          |d         t                    rd|d         v r{	 |d         d         }t          |t                    r?|
                    d          s|
                    d          rt          j        |          }n|}n#  |d         d         }Y nxY w| |||dt          j                    j        t          j                    j        dd}t          j        |d	
          S )u   
    Formatea el resultado técnico del MCP para que el nodo de respuesta (LHIA) 
    tenga todo el contexto necesario, incluyendo la fecha real y el DAX usado.
    z%Y-%m-%d %H:%Mr   text{[i  )year_gestion
mes_actual
dia_actual)r   dax_ejecutadoresultado_crudofecha_consultametadataF)ensure_ascii)r   nowstrftime
isinstancestrjsonloadslistlendict
startswithmonthdaydumps)r   r   r	   r
   current_dateparsed_resulttext_contentcontexto_tecnicos           wC:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\agent\utils\context_helper.pyformat_mcp_outputr*      s   
 <>>**+;<<L M&# 	 Jv..MM	D -&& 
93}+=+=+A+AmA&-- 		9&M!<L2L2L9,Q/7lC00 1l6M6Mc6R6R 1VbVmVmnqVrVr 1$(J|$<$<MM$0M9 -a 0 8 (& ",...",..,
 

 
 :&U;;;;s   A A)A$D D )N)r   r   typingr   r   r   r   r*        r)   <module>r.      s           " " " " " " " " " ")< )<c )< )<S )<c3h )<[^ )< )< )< )< )< )<r-   