
    gz              	         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mZmZmZmZ d dlmZmZ ddlmZmZ erdd	lmZ n
 ed
d      ZdZ eddd      Z	  edde      Z	  eddd      Z	 e G d deeef                Z G d deeeeef         Ze G d dee                Z e G d d             Z!e G d deeeef                Z"y)    )annotations)ABCabstractmethod)	dataclassis_dataclass)cache)TYPE_CHECKINGAnyClassVarGeneric
get_originget_type_hints)NeverTypeVar   )_utils
exceptions)StateTr   N)default)GraphRunContextBaseNodeEndEdgeNodeDefDepsTRunEndTT)	covariantr   NodeRunEndTr   )r   contravariantc                  (    e Zd ZU dZded<   	 ded<   y)r   zContext for a graph.r   stater   depsN__name__
__module____qualname____doc____annotations__     I/var/www/openai/venv/lib/python3.12/site-packages/pydantic_graph/nodes.pyr   r      s    M!
K%r*   r   c                  t    e Zd ZU dZdZded<   	 ed
d       Zee	dd              Z
edd       Zedd       Zy	)r   zBase class for a node.FzClassVar[bool]docstring_notesc                   K   yw)aB  Run the node.

        This is an abstract method that must be implemented by subclasses.

        !!! note "Return types used at runtime"
            The return type of this method are read by `pydantic_graph` at runtime and used to define which
            nodes can be called next in the graph. This is displayed in [mermaid diagrams](mermaid.md)
            and enforced when running the graph.

        Args:
            ctx: The graph context.

        Returns:
            The next node to run or [`End`][pydantic_graph.nodes.End] to signal the end of the graph.
        Nr)   )selfctxs     r+   runzBaseNode.run0   s     " 	s   c                    | j                   S )zGet the ID of the node.)r$   )clss    r+   get_idzBaseNode.get_idC   s     ||r*   c                    | j                   sy| j                  }|r+t        |       r |j                  | j                   d      rd}|rddl}|j                  |      }|S )a   Get a note about the node to render on mermaid charts.

        By default, this returns a note only if [`docstring_notes`][pydantic_graph.nodes.BaseNode.docstring_notes]
        is `True`. You can override this method to customise the node notes.
        N(r   )r-   r'   r   
startswithr$   inspectcleandoc)r3   	docstringr8   s      r+   get_notezBaseNode.get_noteI   s]     ""KK	c*y/C/Cs||nTUDV/WI((3Ir*   c                T   t        | j                  |d      }	 |d   }i }d}d}t        j                  |      D ]  }t        j                  |      \  }}	t        d |	D        t        d            }
t        |      xs |}|t        u r|
}Q|t        u rd}\t        |t              r|
||j                         <   t        j                  d	|        t        | | j                         | j!                         |||      S # t        $ r}t        j                  d|  d      |d}~ww xY w)
zGet the node definition.T)localnsinclude_extrasreturnzNode z2 is missing a return type hint on its `run` methodNFc              3  B   K   | ]  }t        |t              s|  y w)N)
isinstancer   ).0as     r+   	<genexpr>z(BaseNode.get_node_def.<locals>.<genexpr>k   s     GKq:a3FKs   zInvalid return type: )r   r1   KeyErrorr   GraphSetupErrorr   get_union_argsunpack_annotatednextr   r   r   r   
issubclassr4   r   r;   )r3   local_ns
type_hintsreturn_hintenext_node_edgesend_edgereturns_base_nodereturn_typer   edgereturn_type_origins               r+   get_node_defzBaseNode.get_node_def]   s9    $CGGXdS
	u$X.K ,. $"'!00=K'-'>'>{'K$KGKGdTD!+K!8!GK!S(#x/$(!.98< 2 2 45 003H1VWW > JJLLLN
 	
)  	u,,uSE9k-lmstt	us   C? ?	D'D""D'N)r0   zGraphRunContext[StateT, DepsT]r?   z/BaseNode[StateT, DepsT, Any] | End[NodeRunEndT])r?   str)r?   
str | None)rK   zdict[str, Any] | Noner?   z#NodeDef[StateT, DepsT, NodeRunEndT])r$   r%   r&   r'   r-   r(   r   r1   classmethodr   r4   r;   rU   r)   r*   r+   r   r   %   sl     &+O^+  $ 
    &  
  
r*   r   c                      e Zd ZU dZded<   y)r   z:Type to return from a node to signal the end of the graph.r   dataNr#   r)   r*   r+   r   r      s    D
M(r*   r   c                      e Zd ZU dZded<   y)r   z2Annotation to apply a label to an edge in a graph.rW   labelNr#   r)   r*   r+   r   r      s    <r*   r   c                  X    e Zd ZU dZded<   	 ded<   	 ded<   	 ded	<   	 d
ed<   	 ded<   y)r   a  Definition of a node.

    This is a primarily internal representation of a node; in general, it shouldn't be necessary to use it directly.

    Used by [`Graph`][pydantic_graph.graph.Graph] to store information about a node, and when generating
    mermaid graphs.
    z*type[BaseNode[StateT, DepsT, NodeRunEndT]]noderV   node_idrW   notezdict[str, Edge]rO   zEdge | NonerP   boolrQ   Nr#   r)   r*   r+   r   r      s>     54%L
:$$3cbr*   r   )#
__future__r   _annotationsabcr   r   dataclassesr   r   	functoolsr   typingr	   r
   r   r   r   r   typing_extensionsr   r    r   r   r!   r   __all__r   r   r   r   r   r   r   r   r)   r*   r+   <module>rk      s   2 # /  T T ,  Xt,F
J
)tT
: emtUC gT: = &gfem, & &Y
sGFE;67 Y
x )''
 ) )    cgfe[01 c cr*   