ó
    °"³j…"  ã                  óâ  • S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	J
r
JrJrJrJr  SSKJr  SSKJrJrJr  SSKJr  \" S	S
S9r\" SS
S9r\" SS
S9r\" SS
S9r\" SS9 " S S\
\\\4   5      5       r " S S\\\\\4   5      r " S S\\\\\4   5      r\\	\	\	\	4   r \" SS9 " S S\
\\\\4   5      5       r\ " S S\\\\	4   5      5       r  " S S\\\\	\\\\	4   \\	   -  4   5      r!g)zõStep-based graph execution components.

This module provides the core abstractions for step-based graph execution,
including step contexts, step functions, and step nodes that bridge between
the declarative `BaseNode` API and the builder graph.
é    )Úannotations)ÚAsyncIteratorÚ	Awaitable)Ú	dataclass)ÚAnyÚGenericÚProtocolÚcastÚ
get_originÚoverload)ÚTypeVar)ÚBaseNodeÚEndÚGraphRunContext)ÚNodeIDÚStateTT)Úinfer_varianceÚDepsTÚInputTÚOutputTF)Úinitc                  ó„   • \ rS rSr% SrS\S'    S\S'    S\S'    SS	 jr\SS
 j5       r\SS j5       r	\SS j5       r
Srg)ÚStepContexté   a5  Context information passed to step functions during graph execution.

The step context provides access to the current graph state, dependencies, and input data for a step.

Type Parameters:
    StateT: The type of the graph state
    DepsT: The type of the dependencies
    InputT: The type of the input data
r   Ú_stater   Ú_depsr   Ú_inputsc               ó(   • Xl         X l        X0l        g ©N)r   r   r   )ÚselfÚstateÚdepsÚinputss       ÚP/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_graph/step.pyÚ__init__ÚStepContext.__init__,   s   € ØŒØŒ
Ø�ó    c                ó   • U R                   $ r   )r   ©r    s    r$   r!   ÚStepContext.state1   s   € à�{‰{Ðr'   c                ó   • U R                   $ r   )r   r)   s    r$   r"   ÚStepContext.deps5   s   € à�z‰zÐr'   c                ó   • U R                   $ )z[The input data for this step.

This must be a property to ensure correct variance behavior
)r   r)   s    r$   r#   ÚStepContext.inputs9   s   € ð �|‰|Ðr'   )r   r   r   N)r!   r   r"   r   r#   r   )Úreturnr   )r/   r   )r/   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r%   Úpropertyr!   r"   r#   Ú__static_attributes__© r'   r$   r   r      sb   ‡ ñð ƒNØ"ØƒLØ%ØƒOØ'ôð
 óó ðð óó ðð óó ór'   r   c                  ó"   • \ rS rSrSrSS jrSrg)ÚStepFunctionéB   aF  Protocol for step functions that can be executed in the graph.

Step functions are async callables that receive a step context and return a result.

Type Parameters:
    StateT: The type of the graph state
    DepsT: The type of the dependencies
    InputT: The type of the input data
    OutputT: The type of the output data
c                ó   • [         e)z¼Execute the step function with the given context.

Args:
    ctx: The step context containing state, dependencies, and inputs

Returns:
    An awaitable that resolves to the step's output
©ÚNotImplementedError©r    Úctxs     r$   Ú__call__ÚStepFunction.__call__N   s
   € ô "Ð!r'   r8   N)r@   ú"StepContext[StateT, DepsT, InputT]r/   zAwaitable[OutputT]©r0   r1   r2   r3   r4   rA   r7   r8   r'   r$   r:   r:   B   s   † ñ	÷	"r'   r:   c                  ó"   • \ rS rSrSrSS jrSrg)ÚStreamFunctionéZ   aS  Protocol for stream functions that can be executed in the graph.

Stream functions are async callables that receive a step context and return an async iterator.

Type Parameters:
    StateT: The type of the graph state
    DepsT: The type of the dependencies
    InputT: The type of the input data
    OutputT: The type of the output data
c              #  ó   #   • [         e7f)z½Execute the stream function with the given context.

Args:
    ctx: The step context containing state, dependencies, and inputs

Returns:
    An async iterator yielding the streamed output
r=   r?   s     r$   rA   ÚStreamFunction.__call__f   s   é € ô "Ð!ùs   ‚	r8   N)r@   rC   r/   zAsyncIterator[OutputT]rD   r8   r'   r$   rF   rF   Z   s   † ñ	÷
r'   rF   c                  óž   • \ rS rSr% SrS\S'    S\S'    S\S'    S	S
.SS jjr\SS j5       r\	SSS jj5       r
\	SS j5       r
SSS jjr
Srg	)ÚStepéw   an  A step in the graph execution that wraps a step function.

Steps represent individual units of execution in the graph, encapsulating
a step function along with metadata like ID and label.

Type Parameters:
    StateT: The type of the graph state
    DepsT: The type of the dependencies
    InputT: The type of the input data
    OutputT: The type of the output data
r   Úidú,StepFunction[StateT, DepsT, InputT, OutputT]Ú_callú
str | NoneÚlabelN)rQ   c               ó(   • Xl         X l        X0l        g r   )rM   rO   rQ   )r    rM   ÚcallrQ   s       r$   r%   ÚStep.__init__Œ   s   € ØŒØŒ
Ø�
r'   c                ó   • U R                   $ )zXThe step function to execute. This needs to be a property for proper variance inference.)rO   r)   s    r$   rS   Ú	Step.call‘   s   € ð �z‰zÐr'   c                ó   • g r   r8   ©r    r#   s     r$   Úas_nodeÚStep.as_node–   s   € ØGJr'   c                ó   • g r   r8   rX   s     r$   rY   rZ   ™   s   € ØBEr'   c                ó   • [        X5      $ )zÅCreate a step node with bound inputs.

Args:
    inputs: The input data to bind to this step, or None

Returns:
    A [`StepNode`][pydantic_graph.step.StepNode] with this step and the bound inputs
)ÚStepNoderX   s     r$   rY   rZ   œ   s   € ô ˜Ó%Ð%r'   )rO   rM   rQ   )rM   r   rS   rN   rQ   rP   )r/   rN   r   )r#   ÚNoner/   úStepNode[StateT, DepsT])r#   r   r/   r_   )r#   zInputT | Noner/   r_   )r0   r1   r2   r3   r4   r5   r%   r6   rS   r   rY   r7   r8   r'   r$   rK   rK   w   sg   ‡ ñ
ð 	ƒJØ*Ø7Ó7Ø'ØÓØ6ànr÷ ð
 óó ðð ÝJó ØJàÛEó ØE÷	&ñ 	&r'   rK   c                  ó<   • \ rS rSr% SrS\S'    S\S'    S
S jrSrg	)r]   é¨   a‘  A `BaseNode` that represents a builder step with bound inputs.

`StepNode` lets a [`BaseNode`][pydantic_graph.BaseNode] subclass hand off to a builder
[`Step`][pydantic_graph.step.Step] by wrapping the step together with the value it should
receive as `inputs`. It is not meant to be run directly; returning a `StepNode` from a
`BaseNode.run` method tells the graph builder which step to invoke next.
zStep[StateT, DepsT, Any, Any]Ústepr   r#   c              ƒ  ó    #   • [        S5      e7f)zÑAttempt to run the step node.

Args:
    ctx: The graph execution context

Returns:
    The result of step execution

Raises:
    NotImplementedError: Always raised as StepNode is not meant to be run directly
z�`StepNode` is not meant to be run directly, it is meant to be returned from a `BaseNode` subclass to indicate a transition to a builder step.r=   r?   s     r$   ÚrunÚStepNode.run¸   s   é € ô "ð \ó
ð 	
ùs   ‚r8   N)r@   zGraphRunContext[StateT, DepsT]r/   ú'BaseNode[StateT, DepsT, Any] | End[Any])r0   r1   r2   r3   r4   r5   rd   r7   r8   r'   r$   r]   r]   ¨   s   ‡ ñð (Ó'ØàƒKØ(÷
r'   r]   c                  ó\   ^ • \ rS rSr% SrS\S'    SSS.     S
U 4S jjjrSS jrS	rU =r	$ )ÚNodeStepéË   a+  A step that wraps a `BaseNode` type for execution by the builder graph.

`NodeStep` lets a [`BaseNode`][pydantic_graph.BaseNode] subclass participate as a step in the
builder graph. It validates that the input is an instance of the expected node type and runs
it with the appropriate graph context.
ú"type[BaseNode[StateT, DepsT, Any]]Ú	node_typeN)rM   rQ   c               óª   >• [         TU ]  U=(       d    [        UR                  5       5      U R                  US9  [        U5      =(       d    UU l        g)zØInitialize a node step.

Args:
    node_type: The BaseNode class this step will execute
    id: Optional unique identifier, defaults to the node's get_node_id()
    label: Optional human-readable label for this step
)rM   rS   rQ   N)Úsuperr%   r   Úget_node_idÚ
_call_noder   rk   )r    rk   rM   rQ   Ú	__class__s       €r$   r%   ÚNodeStep.__init__Ö   sJ   ø€ ô 	‰ÑØ×4”V˜I×1Ñ1Ó3Ó4Ø—‘Øð 	ñ 	
ô $ IÓ.×;°)ˆ�r'   c              ƒ  ó>  #   • UR                   n[        X R                  5      (       d  [        SU SU R                   35      e[	        [
        [        [        [        4   U5      nUR                  [        UR                  UR                  S95      I Sh  v•N $  N7f)a	  Execute the wrapped node with the step context.

Args:
    ctx: The step context containing the node instance to run

Returns:
    The result of running the node, either another BaseNode or End

Raises:
    ValueError: If the input node is not of the expected type
zNode z is not of type )r!   r"   N)r#   Ú
isinstancerk   Ú
ValueErrorr
   r   r   r   r   rd   r   r!   r"   )r    r@   Únodes      r$   ro   ÚNodeStep._call_nodeí   sy   é € ð �z‰zˆÜ˜$§¡×/Ñ/Ü˜u T FÐ*:¸4¿>¹>Ð:JÐKÓLÐLÜ”HœV¤U¬CÐ/Ñ0°$Ó7ˆØ—X‘Xœo°C·I±IÀCÇHÁHÑMÓN×NÐNÑNùs   ‚BBÂBÂB)rk   )rk   rj   rM   zNodeID | NonerQ   rP   )r@   zStepContext[StateT, DepsT, Any]r/   rf   )
r0   r1   r2   r3   r4   r5   r%   ro   r7   Ú__classcell__)rp   s   @r$   rh   rh   Ë   sM   ø‡ ñð 2Ó1Ø/ð !Ø ñ<à5ð<ð ð	<ð
 ÷<ð <÷.Oò Or'   rh   N)"r4   Ú
__future__r   Úcollections.abcr   r   Údataclassesr   Útypingr   r   r	   r
   r   r   Útyping_extensionsr   Úpydantic_graph.basenoder   r   r   Úpydantic_graph.id_typesr   r   r   r   r   r   r:   rF   ÚAnyStepFunctionrK   r]   rh   r8   r'   r$   Ú<module>r€      sX  ðñõ #ç 4Ý !ß E× Eå %ç BÑ BÝ *á	�¨$Ñ	/€Ù�¨Ñ-€Ù	�¨$Ñ	/€Ù
�)¨DÑ
1€ñ �Ñô%�'˜& %¨Ð/Ñ0ó %ó ð%ôP"�8˜F E¨6°7Ð:Ñ;ô "ô0�X˜f e¨V°WÐ<Ñ=ô ð2 ˜s C¨¨cÐ1Ñ2€Ø >ñ �Ñô-&ˆ7�6˜5 &¨'Ð1Ñ2ó -&ó ð-&ð` ô
ˆx˜  sÐ*Ñ+ó 
ó ð
ôD2Oˆt�F˜E 3¨°¸ÀÐ1CÑ(DÀsÈ3ÁxÑ(OÐOÑPõ 2Or'   