
    dh	                         S SK r S SKJr  S SKJrJrJr  S SKJr  S SK	J
r
Jr  S SKJr   " S S\
5      r " S	 S
\5      rg)    N)EmailMessage)ListOptionalType)CallbackManagerForToolRun)	BaseModelField)GmailBaseToolc                       \ rS rSr% Sr\" SSS9r\\S'   \" SSS9r	\
\   \S'   \" SS	S9r\\S
'   \" SSS9r\\
\      \S'   \" SSS9r\\
\      \S'   Srg)CreateDraftSchema   zInput for CreateDraftTool..z$The message to include in the draft.)descriptionmessagezThe list of recipients.tozThe subject of the message.subjectNzThe list of CC recipients.cczThe list of BCC recipients.bcc )__name__
__module____qualname____firstlineno____doc__r	   r   str__annotations__r   r   r   r   r   r   __static_attributes__r       d/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/gmail/create_draft.pyr   r      s    $:GS  -BS	  1GS  $0Bc   %1 C$s)	 r   r   c                       \ rS rSr% SrSr\\S'   Sr\\S'   \	r
\\	   \S'     SS	\S
\\   S\S\\\      S\\\      S\4S jjr   SS	\S
\\   S\S\\\      S\\\      S\\   S\4S jjrSrg)GmailCreateDraft$   z*Tool that creates a draft email for Gmail.create_gmail_draftnamezGUse this tool to create a draft email with the provided message fields.r   args_schemaNr   r   r   r   r   returnc                 4   [        5       nUR                  U5        SR                  U5      US'   X6S'   Ub  SR                  U5      US'   Ub  SR                  U5      US'   [        R                  " UR                  5       5      R                  5       nSSU00$ )Nz, ToSubjectCcBccr   raw)r   set_contentjoinbase64urlsafe_b64encodeas_bytesdecode)selfr   r   r   r   r   draft_messageencoded_messages           r   _prepare_draft_message'GmailCreateDraft._prepare_draft_message-   s     %!!'*"iimd#*i >"&))B-M$?#'99S>M%  22=3I3I3KLSSUE?344r   run_managerc                     U R                  XX4U5      nU R                  R                  5       R                  5       R	                  SUS9R                  5       nSUS    3n	U	$ ! [         a  n
[        SU
 35      eS n
A
ff = f)Nme)userIdbodyzDraft created. Draft Id: idzAn error occurred: )r5   api_resourceusersdraftscreateexecute	Exception)r2   r   r   r   r   r   r7   create_messagedraftoutputes              r   _runGmailCreateDraft._runC   s    	7!88gSVWN!!'')t.9	  1t>FM 	71!566	7s   A A# #
B -A;;B r   )NN)NNN)r   r   r   r   r   r#   r   r   r   r   r$   r   r   r   dictr5   r   rG   r   r   r   r   r    r    $   s   4$D#$Q   ,=K'(< #'#'55 I5 	5
 T#Y5 d3i 5 
56 #'#';?77 I7 	7
 T#Y7 d3i 7 787 
7 7r   r    )r.   email.messager   typingr   r   r   langchain_core.callbacksr   pydanticr   r	   $langchain_community.tools.gmail.baser
   r   r    r   r   r   <module>rO      s2     & ' ' > % >	 237} 37r   