
    D_i@                    J   S r SSKJr  SSKJrJrJrJr  SSKJ	r	J
r
  SSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  \(       a  SS
KJr  SSKJr  SSKJr  SSKJr      SS jr " S S\ 5      r! " S S\5      r"      SS jr# " S S\"5      r$SS jr%SS jr&SS.S S jjr'g)!zBase message.    )annotations)TYPE_CHECKINGAnycastoverload)
ConfigDictField)warn_deprecated)Serializable)get_bolded_text)merge_dictsmerge_lists)is_interactive_env)Sequence)SelfcontentChatPromptTemplateBaseMessagec                z    [        U S0 5      nUR                  S5      nUb  [        U[        5      (       a  SUS.$ g)aP  Extract `reasoning_content` from `additional_kwargs`.

Handles reasoning content stored in various formats:
- `additional_kwargs["reasoning_content"]` (string) - Ollama, DeepSeek, XAI, Groq

Args:
    message: The message to extract reasoning from.

Returns:
    A `ReasoningContentBlock` if reasoning content is found, None otherwise.
additional_kwargsreasoning_contentN	reasoning)typer   )getattrget
isinstancestr)messager   r   s      V/home/james-whalen/.local/lib/python3.13/site-packages/langchain_core/messages/base.py)_extract_reasoning_from_additional_kwargsr"      sH      )<bA)--.AB$4Es)K)K#2CDD    c                  0    \ rS rSrSrSrSS jrSS jrSrg)	TextAccessor/   aB  String-like object that supports both property and method access patterns.

Exists to maintain backward compatibility while transitioning from method-based to
property-based text access in message objects. In LangChain <v1.0, message text was
accessed via `.text()` method calls. In v1.0=<, the preferred pattern is property
access via `.text`.

Rather than breaking existing code immediately, `TextAccessor` allows both
patterns:
- Modern property access: `message.text` (returns string directly)
- Legacy method access: `message.text()` (callable, emits deprecation warning)

 c                ,    [         R                  X5      $ )z!Create new TextAccessor instance.)r   __new__)clsvalues     r!   r)   TextAccessor.__new__@   s    {{3&&r#   c                .    [        SSSS9  [        U 5      $ )a  Enable method-style text access for backward compatibility.

This method exists solely to support legacy code that calls `.text()`
as a method. New code should use property access (`.text`) instead.

!!! deprecated
    As of `langchain-core` 1.0.0, calling `.text()` as a method is deprecated.
    Use `.text` as a property instead. This method will be removed in 2.0.0.

Returns:
    The string content, identical to property access.

z1.0.0z`Calling .text() as a method is deprecated. Use .text as a property instead (e.g., message.text).z2.0.0)sincer    removal)r
   r   selfs    r!   __call__TextAccessor.__call__D   s&     	H 	
 4yr#   N)r+   r   returnr   )r4   r   )	__name__
__module____qualname____firstlineno____doc__	__slots__r)   r2   __static_attributes__r'   r#   r!   r%   r%   /   s     I'r#   r%   c                    ^  \ rS rSr% SrS\S'    \" \S9rS\S'    \" \S9r	S\S'    S	\S
'    Sr
S\S'    \" SSS9rS\S'    \" SS9r\      SS j5       r\  S       S S jj5       r  S       S U 4S jjjr\S!S j5       r\S"S j5       r\S#S j5       r\S$S j5       rS%S jr S&   S'S jjrS(S jrSrU =r$ ))r   ]   zBase abstract message class.

Messages are the inputs and outputs of a chat model.

Examples include [`HumanMessage`][langchain.messages.HumanMessage],
[`AIMessage`][langchain.messages.AIMessage], and
[`SystemMessage`][langchain.messages.SystemMessage].
str | list[str | dict]r   )default_factorydictr   response_metadatar   r   Nz
str | NonenameT)defaultcoerce_numbers_to_stridallow)extrac                    g Nr'   )r1   r   kwargss      r!   __init__BaseMessage.__init__   s    
 r#   c                    g rI   r'   )r1   r   content_blocksrJ   s       r!   rK   rL      s     r#   c                V   > Ub  [         TU ]  " SSU0UD6  g[         TU ]  " SSU0UD6  g)zInitialize a `BaseMessage`.

Specify `content` as positional arg or `content_blocks` for typing.

Args:
    content: The contents of the message.
    content_blocks: Typed standard content.
    **kwargs: Additional arguments to pass to the parent class.
Nr   r'   )superrK   )r1   r   rN   rJ   	__class__s       r!   rK   rL      s5     %G>^>v>G7W77r#   c                    g)z2`BaseMessage` is serializable.

Returns:
    True
Tr'   r*   s    r!   is_lc_serializableBaseMessage.is_lc_serializable   s     r#   c                
    / SQ$ )z_Get the namespace of the LangChain object.

Returns:
    `["langchain", "schema", "messages"]`
)	langchainschemamessagesr'   rS   s    r!   get_lc_namespaceBaseMessage.get_lc_namespace   s
     32r#   c                   SSK Jn  SSKJn  SSKJn  SSKJn  SSKJ	n  SSK
Jn  / n[        U R                  [        5      (       a  U R                  (       a  U R                  /OU R                  nU H  n	[        U	[        5      (       a  UR                  SU	S	.5        M.  [        U	[        5      (       d  ME  U	R!                  S
5      n
XR"                  ;  a  UR                  SU	S.5        M{  SU	;   a  UR                  SU	S.5        M  UR                  [%        SU	5      5        M     UUUUU4 H  nU" U5      nM     U$ )zdLoad content blocks from the message content.

!!! version-added "Added in `langchain-core` 1.0.0"

r   r   )#_convert_to_v1_from_anthropic_input)"_convert_to_v1_from_converse_input)_convert_to_v1_from_genai_input)"_convert_v0_multimodal_input_to_v1)*_convert_to_v1_from_chat_completions_inputtext)r   rb   r   non_standard)r   r+   source_typeztypes.ContentBlock)langchain_core.messagesr   3langchain_core.messages.block_translators.anthropicr]   :langchain_core.messages.block_translators.bedrock_converser^   6langchain_core.messages.block_translators.google_genair_   6langchain_core.messages.block_translators.langchain_v0r`   0langchain_core.messages.block_translators.openaira   r   r   appendr@   r   KNOWN_BLOCK_TYPESr   )r1   typesr]   r^   r_   r`   ra   blocksr   item	item_typeparsing_steps               r!   rN   BaseMessage.content_blocks   s    	=	
	
	
	
	
 ,. $,,,, \\N	 	 D$$$vt<=D$'' HHV,	$;$;; MM>D"IJ %,~&MN  MM$';T"BC% . /6/+.
L "&)F
 r#   c                   [        U R                  [        5      (       a  U R                  nOU R                   Vs/ s HW  n[        U[        5      (       d=  UR                  S5      S:X  d  M/  [        UR                  S5      [        5      (       d  MU  UPMY     nnSR	                  S U 5       5      n[        U5      $ s  snf )a[  Get the text content of the message as a string.

Can be used as both property (`message.text`) and method (`message.text()`).

!!! deprecated
    As of `langchain-core` 1.0.0, calling `.text()` as a method is deprecated.
    Use `.text` as a property instead. This method will be removed in 2.0.0.

Returns:
    The text content of the message.

r   rb    c              3  Z   #    U  H!  n[        U[        5      (       a  UOUS    v   M#     g7f)rb   N)r   r   ).0blocks     r!   	<genexpr>#BaseMessage.text.<locals>.<genexpr>  s)      !PVuE3//U6]BPVs   )+)r   r   r   r   joinr%   )r1   
text_valuerw   rn   s       r!   rb   BaseMessage.text  s     dllC((J
 "\\)EeS))IIf%/  5?uyy?PRU4V )    !PV! J J''s   .B>-"B>B>c                >    SSK Jn  U" U /S9nUR                  U5      $ )zConcatenate this message with another message.

Args:
    other: Another message to concatenate with this one.

Returns:
    A ChatPromptTemplate containing both messages.
r   r   )rY   )langchain_core.prompts.chatr   __add__)r1   otherr   prompts       r!   r   BaseMessage.__add__$  s#     	C#dV4~~e$$r#   c                    [        U R                  R                  5       S-   US9nU R                  b  USU R                   3-  nU SU R                   3$ )zGet a pretty representation of the message.

Args:
    html: Whether to format the message as HTML. If `True`, the message will be
        formatted with HTML tags.

Returns:
    A pretty representation of the message.

z Messageboldz
Name: z

)get_msg_title_reprr   titlerB   r   )r1   htmlr   s      r!   pretty_reprBaseMessage.pretty_repr3  sT     #499??#4z#AM99 x		{++ET\\N++r#   c                D    [        U R                  [        5       S95        g)z-Print a pretty representation of the message.)r   N)printr   r   r0   s    r!   pretty_printBaseMessage.pretty_printG  s    d$6$89:r#   r'   )r   r>   rJ   r   r4   None)NN)r   zstr | list[str | dict] | NonerN   zlist[types.ContentBlock] | NonerJ   r   r4   r   )r4   bool)r4   z	list[str])r4   zlist[types.ContentBlock])r4   r%   )r   r   r4   r   )F)r   r   r4   r   )r4   r   )r5   r6   r7   r8   r9   __annotations__r	   r@   r   rA   rB   rE   r   model_configr   rK   classmethodrT   rZ   propertyrN   rb   r   r   r   r;   __classcell__)rQ   s   @r!   r   r   ]   s    $#&#D9t9 $D9t9I
I D* 4tDB
D L '  
	   26:>. 8 	
 
  26:>8.8 88 	8
 
8 8(   3 3 = =~ ( (8%" ,, 
,(; ;r#   c                   U c  SOU nU H  n[        U[        5      (       a"  [        U[        5      (       a  X#-  nM3  U/UQnM:  [        U[        5      (       a  [        [	        SU5      U5      nMg  U(       a'  [        US   [        5      (       a  US==   U-  ss'   M  US:X  a  M  U(       d  M  UR                  U5        M     U$ )zMerge multiple message contents.

Args:
    first_content: The first `content`. Can be a string or a list.
    contents: The other `content`s. Can be a string or a list.

Returns:
    The merged content.

rt   list)r   r   r   r   r   rk   )first_contentcontentsmergedr   s       r!   merge_contentr   L  s     !(RmFfc""'3''! !+7+&& ff!5w?F 
6":s332J'!J]VMM'"- . Mr#   c                  "    \ rS rSrSrSS jrSrg)BaseMessageChunkiw  zCMessage chunk, which can be concatenated with other Message chunks.c           
        [        U[        5      (       a  U R                  U R                  U R                  [        U R                  UR                  5      [        U R                  UR                  5      [        U R                  UR                  5      S9$ [        U[        5      (       a  [        S U 5       5      (       as  [        U R                  /S U 5       Q76 n[        U R                  /S U 5       Q76 n[        U R                  /S U 5       Q76 nU R                  U R                  UUUS9$ SU R                  R                   SUR                  R                   S	3n[        U5      e)
aR  Message chunks support concatenation with other message chunks.

This functionality is useful to combine message chunks yielded from
a streaming model into a complete message.

Args:
    other: Another message chunk to concatenate with this one.

Returns:
    A new message chunk that is the concatenation of this message chunk
    and the other message chunk.

Raises:
    TypeError: If the other object is not a message chunk.

Example:
    ```txt
      AIMessageChunk(content="Hello", ...)
    + AIMessageChunk(content=" World", ...)
    = AIMessageChunk(content="Hello World", ...)
    ```
)rE   r   r   r   rA   c              3  B   #    U  H  n[        U[        5      v   M     g 7frI   )r   r   rv   os     r!   rx   +BaseMessageChunk.__add__.<locals>.<genexpr>  s      +
5:Jq*++Us   c              3  8   #    U  H  oR                   v   M     g 7frI   r   r   s     r!   rx   r     s     3Mu!IIu   c              3  8   #    U  H  oR                   v   M     g 7frI   )r   r   s     r!   rx   r          )Mu!*=*=ur   c              3  8   #    U  H  oR                   v   M     g 7frI   )rA   r   s     r!   rx   r     r   r   )rE   r   r   rA   z$unsupported operand type(s) for +: "z" and "")r   r   rQ   rE   r   r   r   r   r   rA   r   allr5   	TypeError)r1   r   r   r   rA   msgs         r!   r   BaseMessageChunk.__add__z  sl   . e-.. >>77YY%dllEMMB"-**E,C,C# #.**E,C,C# " 
 
 eT""s +
5:+
 (
 (
 $DLLN3Mu3MNG +&&!)Mu)M! !,&&!)Mu)M! >>77"3"3	 "   3~~&&'eoo../q2 	
 nr#   r'   N)r   r   r4   r   )r5   r6   r7   r8   r9   r   r;   r'   r#   r!   r   r   w  s
    M;r#   r   c                <    U R                   U R                  5       S.$ )zConvert a Message to a dictionary.

Args:
    message: Message to convert.

Returns:
    Message as a dict. The dict will have a `type` key with the message type
    and a `data` key with the message data as a dict.

)r   data)r   
model_dump)r    s    r!   message_to_dictr     s     LL'*<*<*>??r#   c                D    U  Vs/ s H  n[        U5      PM     sn$ s  snf )zConvert a sequence of Messages to a list of dictionaries.

Args:
    messages: Sequence of messages (as `BaseMessage`s) to convert.

Returns:
    List of messages as dicts.

)r   )rY   ms     r!   messages_to_dictr     s!     )111OA111s   Fr   c                   SU -   S-   nS[        U5      -
  S-  nSU-  n[        U5      S-  (       a  US-   OUnU(       a  [        U5      nU U U 3$ )zGet a title representation for a message.

Args:
    title: The title.
    bold: Whether to bold the title.

Returns:
    The title representation.

 P      =)lenr   )r   r   paddedsep_lensep
second_seps         r!   r   r     sc     5[3FCKA%G
-C!&kAos3J (U6(:,''r#   N)r    r   r4   z"types.ReasoningContentBlock | None)r   r>   r   r>   r4   r>   )r    r   r4   r@   )rY   zSequence[BaseMessage]r4   z
list[dict])r   r   r   r   r4   r   )(r9   
__future__r   typingr   r   r   r   pydanticr   r	   langchain_core._api.deprecationr
    langchain_core.load.serializabler   langchain_core.utilsr   langchain_core.utils._merger   r   $langchain_core.utils.interactive_envr   collections.abcr   typing_extensionsr   re   r   rm   r~   r   r"   r   r%   r   r   r   r   r   r   r'   r#   r!   <module>r      s     " 5 5 & ; 9 0 @ C(&8>'.+3 +\l;, l;^()(%( (V>{ >B@
2 49 ( (r#   