
    Ng                         d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZ  G d d	e          Z G d
 de          ZdS )zUtil that Searches calendar events in Office 365.

Free, but setup is required. See link below.
https://learn.microsoft.com/en-us/graph/auth/
    )datetime)AnyDictListOptionalType)CallbackManagerForToolRun)	BaseModel
ConfigDictField)O365BaseTool)
UTC_FORMAT
clean_bodyc                       e Zd ZU dZ ed          Zeed<    ed          Zeed<    edd	          Z	e
ed
<    edd	          Zeed<   dS )SearchEventsInputzeInput for SearchEmails Tool.

    From https://learn.microsoft.com/en-us/graph/search-query-parameterun   The start datetime for the search query in the following format:  YYYY-MM-DDTHH:MM:SS±hh:mm, where "T" separates the date and time  components, and the time zone offset is specified as ±hh:mm.  For example: "2023-06-09T10:30:00+03:00" represents June 9th,  2023, at 10:30 AM in a time zone with a positive offset of 3  hours from Coordinated Universal Time (UTC).)descriptionstart_datetimeul   The end datetime for the search query in the following format:  YYYY-MM-DDTHH:MM:SS±hh:mm, where "T" separates the date and time  components, and the time zone offset is specified as ±hh:mm.  For example: "2023-06-09T10:30:00+03:00" represents June 9th,  2023, at 10:30 AM in a time zone with a positive offset of 3  hours from Coordinated Universal Time (UTC).end_datetime
   z(The maximum number of results to return.)defaultr   max_resultsTzWhether the event's body is truncated to meet token number limits. Set to False for searches that will retrieve small events, otherwise, set to True.truncateN)__name__
__module____qualname____doc__r   r   str__annotations__r   r   intr   bool     m/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/office365/events_search.pyr   r      s         K K  %<	 	 	NC 	 	 	 <	 	 	L# 	 	 	 u>  K    U  Hd     r"   r   c                       e Zd ZU dZdZeed<   eZe	e
         ed<   dZeed<    ed          Z	 	 	 	 ddededededee         dedeeeef                  fdZdS )O365SearchEventszKSearch calendar events in Office 365.

    Free, but setup is required
    events_searchnameargs_schemaa   Use this tool to search for the user's calendar events. The input must be the start and end datetimes for the search query. The output is a JSON list of all the events in the user's calendar between the start and end times. You can assume that the user can  not schedule any meeting over existing meetings, and that the user is busy during meetings. Any times without events are free for the user. r   forbid)extrar   TN   r   r   r   r   run_managertruncate_limitreturnc                    | j                                         }|                                }t          j        |t
                    }	t          j        |t
                    }
|                    d                              |	          }|                    d          	                    d          
                    |
           |                    |d|          }g }|D ]}i }|j        |d<   |j        |d<   |r t          |j                  d |         |d<   nt          |j                  |d<   |	j        }|j                            |                              t
                    |d	<   |j                            |                              t
                    |d
<   |j                            |                              t
                    |d<   |                    |           |S )NstartandendT)queryinclude_recurringlimit	organizersubjectbodyr   r   modified_date)accountscheduleget_default_calendardtstrptimer   	new_querygreater_equalchainon_attribute
less_equal
get_eventsr6   r7   r   r8   tzinfor0   
astimezonestrftimer2   modifiedappend)selfr   r   r   r   r,   r-   r;   calendarstart_datetime_queryend_datetime_queryqeventsoutput_eventseventoutput_event	time_zones                    r#   _runzO365SearchEvents._runM   s    <((**0022  "{>:FF[zBB w''556JKK	##E**556HIII$$1K$XX  	/ 	/EL(-L%&+mL# >'1%*'='=o~o'NV$$'1%*'='=V$ -3I-2[-C-CI-N-N-W-W. .L)* ,19+?+?	+J+J+S+S, ,L( -2N,E,E- -hz"" )   ....r"   )r   TNr+   )r   r   r   r   r'   r   r   r   r(   r   r
   r   r   model_configr   r    r   r	   r   r   r   rT   r!   r"   r#   r%   r%   8   s          
  D##4Ki444	T     :  L ;?!2 22 2 	2
 2 782 2 
d38n	2 2 2 2 2 2r"   r%   N)r   r   r=   typingr   r   r   r   r   langchain_core.callbacksr	   pydanticr
   r   r   (langchain_community.tools.office365.baser   )langchain_community.tools.office365.utilsr   r   r   r%   r!   r"   r#   <module>r[      s    $ # # # # # 2 2 2 2 2 2 2 2 2 2 2 2 2 2 > > > > > > 1 1 1 1 1 1 1 1 1 1 A A A A A A L L L L L L L L$ $ $ $ $	 $ $ $NG G G G G| G G G G Gr"   