
    i                         d Z ddlZddlZddlZddlmZmZmZ  ej        e	          Z
 ej                    Zd Zd ZdZddd	d
dddid
gddZd ZdedefdZ ej        ddeeeg ddd	  	         dS )zFeishu Document Tool -- read document content via Feishu/Lark API.

Provides ``feishu_doc_read`` for reading document content as plain text.
Uses the same lazy-import + BaseRequest pattern as feishu_comment.py.
    N)registry
tool_errortool_resultc                     | t           _        dS )zFStore a lark client for the current thread (called by feishu_comment).N)_localclient)r   s    :/home/ubuntu/.hermes/hermes-agent/tools/feishu_doc_tool.py
set_clientr
      s    FMMM    c                  .    t          t          dd          S )z7Return the lark client for the current thread, or None.r   N)getattrr    r   r	   
get_clientr      s    68T***r   z5/open-apis/docx/v1/documents/:document_id/raw_contentfeishu_doc_readzRead the full content of a Feishu/Lark document as plain text. Useful when you need more context beyond the quoted text in a comment.object	doc_tokenstringz>The document token (from the document URL or comment context).)typedescription)r   
propertiesrequired)namer   
parametersc                  2    	 dd l } dS # t          $ r Y dS w xY w)Nr   TF)	lark_oapiImportError)r   s    r	   _check_feishur   6   s:    t   uus    
argsreturnc                    |                      dd                                          }|st          d          S t                      }|t          d          S 	 ddlm} ddlm} ddlm	} n# t          $ r t          d	          cY S w xY w|                                                    |j                                      t                                        |j        h                              d
|i                                          }|                    |          }t+          |dd           }	|	dk    r&t+          |dd          }
t          d|	 d|
           S t+          |dd           }|rt-          |d          rq	 t/          j        |j                  }|                     di                                dd          }t5          d|          S # t.          j        t8          f$ r Y nw xY wt+          |dd           }|r[t;          |t<                    r|                     dd          }nt+          |dt?          |                    }t5          d|          S t          d          S )Nr    zdoc_token is requiredz=Feishu client not available (not in a Feishu comment context)r   )AccessTokenType)
HttpMethod)BaseRequestzlark_oapi not installeddocument_idcodemsgzunknown errorzFailed to read document: code=z msg=rawcontentdataT)successr)   z%No content returned from document API) getstripr   r   r   r"   lark_oapi.core.enumr#   !lark_oapi.core.model.base_requestr$   r   builderhttp_methodGETuri_RAW_CONTENT_URItoken_typesTENANTpathsbuildrequestr   hasattrjsonloadsr)   r   JSONDecodeErrorAttributeError
isinstancedictstr)r   kwargsr   r   r"   r#   r$   r9   responser&   r'   r(   bodyr)   r*   s                  r	   _handle_feishu_doc_readrE   >   s   b))//11I 31222\\F~YZZZ5------222222AAAAAAA 5 5 53444445 		Z^	$	$				o,-	.	.	y)	*	*	  ~~g&&H8VT**Dqyyh77K4KKcKKLLL
(E4
(
(C
 wsI&& 	:ck**Dhhvr**..y"==GtW====$n5 	 	 	D	 8VT**D :dD!! 	:hhy"--GGdIs4yy99G49999=>>>s%   A- -B	B	AG G32G3
feishu_docFzRead Feishu document contentu   📄)	r   toolsetschemahandlercheck_fnrequires_envis_asyncr   emoji)__doc__r;   logging	threadingtools.registryr   r   r   	getLogger__name__loggerlocalr   r
   r   r4   FEISHU_DOC_READ_SCHEMAr   r@   rA   rE   registerr   r   r	   <module>rX      sR          < < < < < < < < < <		8	$	$ 
		  
+ + + K  	Q  _ 
 !M	 	  &  4?$ 4?S 4? 4? 4? 4?v  	!#.

 
 
 
 
 
r   