Ë
    òÏjO(  ã            	      ó¤  — 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&y)%é    )Ú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	y)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_timec                ó   — t        | fi |¤ŽS )zAReturn a new execution info object with selected fields replaced.©r   ©ÚselfÚ	overridess     úN/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph/runtime.pyÚpatchzExecutionInfo.patch7   s   € ä�tÑ)˜yÑ)Ð)ó    )r,   r   Úreturnr   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r"   r#   r&   r'   r.   © r/   r-   r   r      sc   … áYàÓØ6àÓØ=àƒLØ0à €IˆzÓ ðHð €FˆJÓðAð €L�#ÓØ<à,0Ð˜\Ó0ØFô*r/   r   c                  ó8   — e Zd ZU dZded<   	 ded<   	 dZded<   y)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   r/   r-   r   r   <   s%   … áwàÓØ5àƒMØ1à €Dˆ/Ó ðr/   r   c                  óJ   — e Zd ZdZdZdd„Zd	d
d„Zedd„«       Zedd„«       Z	y)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_reasonc                ó   — d | _         y ©Nr<   ©r+   s    r-   Ú__init__zRunControl.__init__\   s
   € Ø)-ˆÕr/   c                ó   — || _         y r?   r<   )r+   Úreasons     r-   Úrequest_drainzRunControl.request_drain_   s
   € Ø#ˆÕr/   c                ó   — | j                   d uS r?   r<   r@   s    r-   Údrain_requestedzRunControl.drain_requestedb   s   € à×!Ñ!¨Ð-Ð-r/   c                ó   — | j                   S r?   r<   r@   s    r-   Údrain_reasonzRunControl.drain_reasonf   s   € à×!Ñ!Ð!r/   N©r0   ÚNone)Úshutdown)rC   r   r0   rJ   ©r0   Úbool©r0   r!   )
r1   r2   r3   r4   Ú	__slots__rA   rD   ÚpropertyrF   rH   r6   r/   r-   r   r   O   s@   „ ñð #€Ió.ô$ð ò.ó ð.ð ò"ó ñ"r/   r   c                 ó   — y r?   r6   )Ú_s    r-   Ú_no_op_stream_writerrS   k   s   € ¨#r/   c                  ó   — y r?   r6   r6   r/   r-   Ú_no_op_heartbeatrU   n   s   €  r/   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<   y)Ú_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   r/   r-   rW   rW   q   s1   … ØÓØÓØÓØ!Ó!ØƒMØ!Ó!Ø"Ó"ØÔr/   rW   F)Útotalc                  óF  — 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y)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   rX   rY   rZ   r   r[   r\   r]   r   r^   zExecutionInfo | Noner_   r`   ra   rb   rc   c                óü  — t        |j                  xs | j                  |j                  xs | j                  |j                  t        ur|j                  n| j                  |j
                  t        ur|j
                  n| j
                  |j                  €| j                  n|j                  |j                  xs | j                  |j                  xs | j                  |j                  xs | 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.
        )rX   rZ   r[   r]   r^   r_   ra   rc   )r   rX   rZ   r[   rS   r]   rU   r^   r_   ra   rc   )r+   Úothers     r-   ÚmergezRuntime.mergeð   s¿   € ô
 Ø—M‘MÒ1 T§\¡\Ø—+‘+Ò+ §¡à×"Ñ"Ô*>Ñ>ð  ×-Ò-à×#Ñ#à�‰Ô&6Ñ6ð —o’oà—‘Ø&+§n¡nÐ&<�T—]’]À%Ç.Á.Ø ×/Ñ/ÒF°4×3FÑ3FØ×)Ñ)Ò=¨T×-=Ñ-=Ø—M‘MÒ1 T§\¡\ô
ð 	
r/   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Ñ)Ð)r/   c                ó‚   — | j                   €d}t        |«      ‚t        |  | j                   j                  di |¤Ž¬«      S )zBReturn a new runtime with selected execution_info fields replaced.z2Cannot patch execution_info before it has been set)r_   r6   )r_   ÚRuntimeErrorr   r.   )r+   r,   Úmsgs      r-   Úpatch_execution_infozRuntime.patch_execution_info
  sG   € à×ÑÐ&ØFˆCÜ˜sÓ#Ð#ÜØØ4˜4×.Ñ.×4Ñ4ÑA°yÑAô
ð 	
r/   c                óJ   — | j                   �| j                   j                  S dS )NF)rc   rF   r@   s    r-   rF   zRuntime.drain_requested  s    € à/3¯|©|Ð/Gˆt�|‰|×+Ñ+ÐRÈUÐRr/   c                óJ   — | j                   �| j                   j                  S d S r?   )rc   rH   r@   s    r-   rH   zRuntime.drain_reason  s    € à,0¯L©LÐ,Dˆt�|‰|×(Ñ(ÐNÈ$ÐNr/   )rh   úRuntime[ContextT]r0   rr   )r,   z#Unpack[_RuntimeOverrides[ContextT]]r0   rr   )r,   r   r0   rr   rL   rN   )r1   r2   r3   r4   r   rX   r5   rZ   rS   r[   rU   r]   r^   r_   ra   rc   ri   rk   ro   rP   rF   rH   r6   r/   r-   r   r   |   sÿ   … ñFñP  dÔ+€GˆXÓ+ð5ñ $¨DÔ1€EÐÓ1ØCá"'Ð0DÔ"E€M�<ÓEØ4á$)Ð2BÔ$C€IÐ!ÓCðñ  $Ô'€HˆcÓ'ðñ
 ,1¸Ô+>€NÐ(Ó>ð2ñ &+°4Ô%8€KÐ"Ó8Øwá!&¨tÔ!4€GÐÓ4ðó
ð(*Ø>ð*à	ó*ó
ð òSó ðSð òOó ñOr/   r   N)rX   rZ   r[   r]   r^   r_   rc   c                óx   — t        t        t           t        «       t           j                  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   )Úcontext_schemaÚruntimes     r-   r   r   (  s-   € ô ”7œ8Ñ$¤j£l´4Ñ&8×&<Ñ&<Ô=OÓ&PÓQ€GØ€Nr/   )rR   r   r0   rJ   rI   r6   r?   )ru   ztype[ContextT] | Noner0   rr   )'Ú
__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   rU   rW   r   ÚDEFAULT_RUNTIMEr   r6   r/   r-   Ú<module>r„      sò   ðÝ "å $ß 1Ñ 1ß %Ñ %å *Ý -ß /ç CÝ 'ß 4Ý %ð€ñ �$˜dÔ#÷*ð *ó $ð*ñB �$˜dÔ#÷ð ó $ð÷$"ñ "ó8 .ó $ô˜	 7¨8Ñ#4¸Eõ ñ ÑˆZÑô]Oˆg�hÑó ]Oó ð]Oñ@ ØØ
Ø&ØØØØô€õr/   