§
    šŠtjO(  ã            	      óô  — d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
lmZmZ d dlmZ dZ edd¬¦  «         G d„ d¦  «        ¦   «         Z edd¬¦  «         G d„ d¦  «        ¦   «         Z G d„ d¦  «        Z d'd„Z!d(d„Z" G d„ dee
e         d¬¦  «        Z# ed)i e¤Ž G d„ d e
e         ¦  «        ¦   «         Z$ e$d!d!e!e"d!d!d!¬"¦  «        Z%d*d+d&„Z&d!S ),é    )Úannotations)ÚCallable)Ú	dataclassÚfieldÚreplace)ÚAnyÚGenericÚcast)Ú	BaseStore)ÚBaseUser)Ú	TypedDictÚUnpack)ÚCONFÚCONFIG_KEY_RUNTIME)Ú
get_config)Ú
_DC_KWARGSÚStreamWriter)ÚContextT)r   ÚExecutionInfoÚ
RunControlÚRuntimeÚ
ServerInfoÚget_runtimeT)ÚfrozenÚslotsc                  ó€   — e Zd ZU dZded<   	 ded<   	 ded<   	 dZded<   	 dZded	<   	 d
Zded<   	 dZded<   	 dd„Z	dS )r   zORead-only execution info/metadata for the execution of current thread/run/node.ÚstrÚcheckpoint_idÚcheckpoint_nsÚtask_idNú
str | NoneÚ	thread_idÚrun_idé   ÚintÚnode_attemptzfloat | NoneÚnode_first_attempt_timeÚ	overridesr   Úreturnc                ó   — t          | fi |¤ŽS )zAReturn a new execution info object with selected fields replaced.©r   ©Úselfr(   s     úO/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langgraph/runtime.pyÚpatchzExecutionInfo.patch7   s   € å�tÐ)Ð)˜yÐ)Ð)Ð)ó    )r(   r   r)   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r"   r#   r&   r'   r/   © r0   r.   r   r      sµ   € € € € € € àYÐYàÐÐÑØ6àÐÐÑØ=à€L€L�LØ0à €IÐ Ð Ð Ñ ðHð €FÐÐÐÑðAð €LÐÐÐÑØ<à,0ÐÐ0Ð0Ð0Ñ0ØFð*ð *ð *ð *ð *ð *r0   r   c                  ó:   — e Zd ZU dZded<   	 ded<   	 dZded<   dS )r   zmMetadata injected by LangGraph Server. None when running open-source LangGraph without LangSmith deployments.r   Úassistant_idÚgraph_idNzBaseUser | NoneÚuser)r1   r2   r3   r4   r5   r:   r6   r0   r.   r   r   <   sH   € € € € € € àwÐwàÐÐÑØ5à€M€M�MØ1à €DÐ Ð Ð Ñ ðð r0   r   c                  óX   — e Zd ZdZdZdd„Zddd	„Zedd„¦   «         Zedd„¦   «         Z	dS )r   aŽ  Run-scoped control surface for cooperative draining.

    Intended for a single graph run. Create a fresh `RunControl` per run;
    reusing a control after `request_drain()` leaves it drained.

    Safe to call from any thread: the drain request is represented by a
    single attribute write, so no lock is needed for this signal.
    If more mutable state is added here, add synchronization.
    ©Ú_drain_reasonr)   ÚNonec                ó   — d | _         d S ©Nr<   ©r-   s    r.   Ú__init__zRunControl.__init__\   s   € Ø)-ˆÔÐÐr0   ÚshutdownÚreasonr   c                ó   — || _         d S r@   r<   )r-   rD   s     r.   Úrequest_drainzRunControl.request_drain_   s   € Ø#ˆÔÐÐr0   Úboolc                ó   — | j         d uS r@   r<   rA   s    r.   Údrain_requestedzRunControl.drain_requestedb   s   € àÔ!¨Ð-Ð-r0   r!   c                ó   — | j         S r@   r<   rA   s    r.   Údrain_reasonzRunControl.drain_reasonf   s   € àÔ!Ð!r0   N©r)   r>   )rC   )rD   r   r)   r>   ©r)   rG   ©r)   r!   )
r1   r2   r3   r4   Ú	__slots__rB   rF   ÚpropertyrI   rK   r6   r0   r.   r   r   O   s’   € € € € € ðð ð #€Ið.ð .ð .ð .ð$ð $ð $ð $ð $ð ð.ð .ð .ñ „Xð.ð ð"ð "ð "ñ „Xð"ð "ð "r0   r   Ú_r   r)   r>   c                ó   — d S r@   r6   )rQ   s    r.   Ú_no_op_stream_writerrS   k   ó   € € € r0   c                 ó   — d S r@   r6   r6   r0   r.   Ú_no_op_heartbeatrV   n   rT   r0   c                  ó`   — e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   dS )Ú_RuntimeOverridesr   ÚcontextúBaseStore | NoneÚstorer   Ústream_writerúCallable[[], None]Ú	heartbeatr   Úpreviousr   Úexecution_infoúServerInfo | NoneÚserver_infoúRunControl | NoneÚcontrolN)r1   r2   r3   r5   r6   r0   r.   rX   rX   q   so   € € € € € € ØÐÐÑØÐÐÑØÐÐÑØ!Ð!Ð!Ñ!Ø€M€M�MØ!Ð!Ð!Ñ!Ø"Ð"Ð"Ñ"ØÐÐÑÐÐr0   rX   F)Útotalc                  ó|  — e Zd ZU dZ ed¬¦  «        Zded<   	  ed¬¦  «        Zded<   	  ee¬¦  «        Z	ded	<   	  ee
¬¦  «        Zd
ed<   	  ed¬¦  «        Zded<   	  ed¬¦  «        Zded<   	  ed¬¦  «        Zded<   	  ed¬¦  «        Zded<   	 d d„Zd!d„Zd"d„Zed#d„¦   «         Zed$d„¦   «         ZdS )%r   a†	  Convenience class that bundles run-scoped context and other runtime utilities.

    This class is injected into graph nodes and middleware. It provides access to
    `context`, `store`, `stream_writer`, `previous`, and `execution_info`.

    !!! note "Accessing `config`"

        `Runtime` does not include `config`. To access `RunnableConfig`, you can inject
        it directly by adding a `config: RunnableConfig` parameter to your node function
        (recommended), or use `get_config()` from `langgraph.config`.

    !!! note
        `ToolRuntime` (from `langgraph.prebuilt`) is a subclass that provides similar
        functionality but is designed specifically for tools. It shares `context`, `store`,
        and `stream_writer` with `Runtime`, and adds tool-specific attributes like `config`,
        `state`, and `tool_call_id`.

    !!! version-added "Added in version v0.6.0"

    Example:

    ```python
    from typing import TypedDict
    from langgraph.graph import StateGraph
    from dataclasses import dataclass
    from langgraph.runtime import Runtime
    from langgraph.store.memory import InMemoryStore


    @dataclass
    class Context:  # (1)!
        user_id: str


    class State(TypedDict, total=False):
        response: str


    store = InMemoryStore()  # (2)!
    store.put(("users",), "user_123", {"name": "Alice"})


    def personalized_greeting(state: State, runtime: Runtime[Context]) -> State:
        '''Generate personalized greeting using runtime context and store.'''
        user_id = runtime.context.user_id  # (3)!
        name = "unknown_user"
        if runtime.store:
            if memory := runtime.store.get(("users",), user_id):
                name = memory.value["name"]

        response = f"Hello {name}! Nice to see you again."
        return {"response": response}


    graph = (
        StateGraph(state_schema=State, context_schema=Context)
        .add_node("personalized_greeting", personalized_greeting)
        .set_entry_point("personalized_greeting")
        .set_finish_point("personalized_greeting")
        .compile(store=store)
    )

    result = graph.invoke({}, context=Context(user_id="user_123"))
    print(result)
    # > {'response': 'Hello Alice! Nice to see you again.'}
    ```

    1. Define a schema for the runtime context.
    2. Create a store to persist memories and other information.
    3. Use the runtime context to access the `user_id`.
    N)Údefaultr   rY   rZ   r[   r   r\   r]   r^   r   r_   zExecutionInfo | Noner`   ra   rb   rc   rd   ÚotherúRuntime[ContextT]r)   c           
     ó6  — t          |j        p| j        |j        p| j        |j        t          ur|j        n| j        |j        t          ur|j        n| j        |j        €| j        n|j        |j        p| j        |j	        p| j	        |j
        p| j
        ¬¦  «        S )z‹Merge two runtimes together.

        If a value is not provided in the other runtime, the value from the current runtime is used.
        N)rY   r[   r\   r^   r_   r`   rb   rd   )r   rY   r[   r\   rS   r^   rV   r_   r`   rb   rd   )r-   rh   s     r.   ÚmergezRuntime.mergeð   s©   € õ
 Ø”MÐ1 T¤\Ø”+Ð+ ¤àÔ"Õ*>Ð>Ð>ð  Ô-Ð-àÔ#àŒÕ&6Ð6Ð6ð ”o�oà”Ø&+¤nÐ&<�T”]�]À%Ä.Ø Ô/ÐF°4Ô3FØÔ)Ð=¨TÔ-=Ø”MÐ1 T¤\ð
ñ 
ô 
ð 	
r0   r(   ú#Unpack[_RuntimeOverrides[ContextT]]c                ó   — t          | fi |¤ŽS )z@Replace the runtime with a new runtime with the given overrides.r+   r,   s     r.   ÚoverridezRuntime.override  s   € õ �tÐ)Ð)˜yÐ)Ð)Ð)r0   c                ót   — | j         €d}t          |¦  «        ‚t          |  | j         j        di |¤Ž¬¦  «        S )zBReturn a new runtime with selected execution_info fields replaced.Nz2Cannot patch execution_info before it has been set)r`   r6   )r`   ÚRuntimeErrorr   r/   )r-   r(   Úmsgs      r.   Úpatch_execution_infozRuntime.patch_execution_info
  sQ   € àÔÐ&ØFˆCÝ˜sÑ#Ô#Ð#ÝØØ4˜4Ô.Ô4ÐAÐA°yÐAÐAð
ñ 
ô 
ð 	
r0   rG   c                ó,   — | j         �| j         j        ndS )NF)rd   rI   rA   s    r.   rI   zRuntime.drain_requested  s   € à/3¬|Ð/GˆtŒ|Ô+Ð+ÈUÐRr0   r!   c                ó,   — | j         �| j         j        nd S r@   )rd   rK   rA   s    r.   rK   zRuntime.drain_reason  s   € à,0¬LÐ,DˆtŒ|Ô(Ð(È$ÐNr0   )rh   ri   r)   ri   )r(   rl   r)   ri   )r(   r   r)   ri   rM   rN   )r1   r2   r3   r4   r   rY   r5   r[   rS   r\   rV   r^   r_   r`   rb   rd   rk   rn   rr   rP   rI   rK   r6   r0   r.   r   r   |   sÇ  € € € € € € ðFð FðP ˜ dÐ+Ñ+Ô+€GÐ+Ð+Ð+Ñ+ð5ð $˜e¨DÐ1Ñ1Ô1€EÐ1Ð1Ð1Ñ1ØCà"' %Ð0DÐ"EÑ"EÔ"E€MÐEÐEÐEÑEØ4à$) EÐ2BÐ$CÑ$CÔ$C€IÐCÐCÐCÑCðð �E $Ð'Ñ'Ô'€HÐ'Ð'Ð'Ñ'ðð
 ,1¨5¸Ð+>Ñ+>Ô+>€NÐ>Ð>Ð>Ñ>ð2ð &+ U°4Ð%8Ñ%8Ô%8€KÐ8Ð8Ð8Ñ8Øwà!& ¨tÐ!4Ñ!4Ô!4€GÐ4Ð4Ð4Ñ4ðð
ð 
ð 
ð 
ð(*ð *ð *ð *ð
ð 
ð 
ð 
ð ðSð Sð Sñ „XðSð ðOð Oð Oñ „XðOð Oð Or0   r   N)rY   r[   r\   r^   r_   r`   rd   Úcontext_schemaútype[ContextT] | Noneri   c                ó¤   — t          t          t                   t          ¦   «         t                                        t          ¦  «        ¦  «        }|S )zÕGet the runtime for the current graph run.

    Args:
        context_schema: Optional schema used for type hinting the return type of the runtime.

    Returns:
        The runtime for the current graph run.
    )r
   r   r   r   r   Úgetr   )ru   Úruntimes     r.   r   r   (  s5   € õ •7�8Ô$¥j¡l¤lµ4Ô&8×&<Ò&<Õ=OÑ&PÔ&PÑQÔQ€GØ€Nr0   )rQ   r   r)   r>   rL   r6   r@   )ru   rv   r)   ri   )'Ú
__future__r   Úcollections.abcr   Údataclassesr   r   r   Útypingr   r	   r
   Úlanggraph.store.baser   Úlanggraph_sdk.auth.typesr   Útyping_extensionsr   r   Úlanggraph._internal._constantsr   r   Úlanggraph.configr   Úlanggraph.typesr   r   Úlanggraph.typingr   Ú__all__r   r   r   rS   rV   rX   r   ÚDEFAULT_RUNTIMEr   r6   r0   r.   ú<module>r‡      s®  ðØ "Ð "Ð "Ð "Ð "Ð "à $Ð $Ð $Ð $Ð $Ð $Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à *Ð *Ð *Ð *Ð *Ð *Ø -Ð -Ð -Ð -Ð -Ð -Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /à CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø %Ð %Ð %Ð %Ð %Ð %ð€ð €�$˜dÐ#Ñ#Ô#ð*ð *ð *ð *ð *ñ *ô *ñ $Ô#ð*ðB €�$˜dÐ#Ñ#Ô#ðð ð ð ð ñ ô ñ $Ô#ðð$"ð "ð "ð "ð "ñ "ô "ð "ð8 .Ð -Ð -Ð -ð $Ð #Ð #Ð #ðð ð ð ð ˜	 7¨8Ô#4¸Eð ñ ô ð ð €ÐÐˆZÐÐð]Oð ]Oð ]Oð ]Oð ]Oˆg�hÔñ ]Oô ]Oñ Ôð]Oð@ �'ØØ
Ø&ØØØØðñ ô €ðð ð ð ð ð ð r0   