o
    i                     @  sn  d dl mZ d dl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 d dlmZ d dlmZmZmZ d	d
lmZmZ dZedddZ	 eddddZ	 eddedZ	 eddddZ	 eddG dd deeef Z G dd deeeeef Z!eG dd dee Z"d%ddZ#edd G d!d" d"Z$eddG d#d$ d$eeeef Z%dS )&    )annotationsN)ABCabstractmethod)	dataclassis_dataclass)cache)AnyClassVarGeneric
get_originget_type_hints)uuid4)NeverSelfTypeVar   )_utils
exceptions)GraphRunContextBaseNodeEndEdgeNodeDefDepsTStateTRunEndTr   )defaultr   T)	covariantr   NodeRunEndTr   )r   contravariant)kw_onlyc                   @  s$   e Zd ZU dZded< 	 ded< dS )r   zContext for a graph.r   stater   depsN__name__
__module____qualname____doc____annotations__ r)   r)   Z/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_graph/nodes.pyr      s   
 r   c                   @  sz   e Zd ZU dZdZded< 	 ed d	d
Zd!ddZd"ddZ	e
ed!ddZe
d#ddZe
d$ddZd%ddZdS )&r   zBase class for a node.FzClassVar[bool]docstring_notesctxGraphRunContext[StateT, DepsT]return/BaseNode[StateT, DepsT, Any] | End[NodeRunEndT]c                   s   dS )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)   )selfr,   r)   r)   r*   run0   s   zBaseNode.runstrc                 C  s.   t | dd  }r
|S t|   | jd< }|S N__snapshot_id)getattrgenerate_snapshot_idget_node_id__dict__r0   snapshot_idr)   r)   r*   get_snapshot_idC   s   zBaseNode.get_snapshot_idr:   Nonec                 C     || j d< d S r3   r8   r9   r)   r)   r*   set_snapshot_idJ      zBaseNode.set_snapshot_idc                 C  s   | j S )zGet the ID of the node.)r$   )clsr)   r)   r*   r7   M   s   zBaseNode.get_node_id
str | Nonec                 C  sL   | j sdS | j}|rt| r|| j drd}|r$ddl}||}|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)rA   	docstringrE   r)   r)   r*   get_noteS   s   
zBaseNode.get_notelocal_nsdict[str, Any] | None#NodeDef[StateT, DepsT, NodeRunEndT]c              
   C  s   t | j|dd}z|d }W n ty$ } z
td|  d|d}~ww i }d}d}t|D ]<}t|\}}	tdd	 |	D t	d}
t
|pJ|}|tu rR|
}q0|tu rYd}q0t|tre|
|| < q0td
| t| |  |  |||dS )zGet the node definition.T)localnsinclude_extrasr.   zNode z2 is missing a return type hint on its `run` methodNFc                 s  s    | ]
}t |tr|V  qd S )N)
isinstancer   ).0ar)   r)   r*   	<genexpr>u   s    z(BaseNode.get_node_def.<locals>.<genexpr>zInvalid return type: )nodenode_idnotenext_node_edgesend_edgereturns_base_node)r   r1   KeyErrorr   GraphSetupErrorr   get_union_argsunpack_annotatednextr   r   r   r   
issubclassr7   r   rH   )rA   rI   
type_hintsreturn_hinterU   rV   rW   return_typer   edgereturn_type_originr)   r)   r*   get_node_defg   s:   
zBaseNode.get_node_defr   c                 C  s
   t | S )z Returns a deep copy of the node.)copydeepcopy)r0   r)   r)   r*   	deep_copy   s   
zBaseNode.deep_copyN)r,   r-   r.   r/   r.   r2   )r:   r2   r.   r<   )r.   rB   )rI   rJ   r.   rK   )r.   r   )r$   r%   r&   r'   r+   r(   r   r1   r;   r?   classmethodr   r7   rH   rd   rg   r)   r)   r)   r*   r   %   s    
 

!r   c                   @  s:   e Zd ZU dZded< 	 dddZdd	d
ZdddZdS )r   z:Type to return from a node to signal the end of the graph.r   datar.   End[RunEndT]c                 C  s0   | j du r| S tt| j }||   |S )z*Returns a deep copy of the end of the run.N)rj   r   re   rf   r?   r;   )r0   endr)   r)   r*   deep_copy_data   s
   
zEnd.deep_copy_datar2   c                 C  s*   t | dd  }r
|S td | jd< }|S )Nr4   rl   )r5   r6   r8   r9   r)   r)   r*   r;      s   zEnd.get_snapshot_idset_idr<   c                 C  r=   r3   r>   )r0   rn   r)   r)   r*   r?      r@   zEnd.set_snapshot_idN)r.   rk   rh   )rn   r2   r.   r<   )r$   r%   r&   r'   r(   rm   r;   r?   r)   r)   r)   r*   r      s   
 

	r   rS   r2   r.   c                 C  s   |  dt  j S )N:)r   hex)rS   r)   r)   r*   r6      s   r6   )frozenc                   @  s   e Zd ZU dZded< dS )r   z2Annotation to apply a label to an edge in a graph.rB   labelNr#   r)   r)   r)   r*   r      s   
 r   c                   @  sL   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< dS )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]]rR   r2   rS   rB   rT   zdict[str, Edge]rU   zEdge | NonerV   boolrW   Nr#   r)   r)   r)   r*   r      s   
 r   )rS   r2   r.   r2   )&
__future__r   _annotationsre   abcr   r   dataclassesr   r   	functoolsr   typingr   r	   r
   r   r   uuidr   typing_extensionsr   r   r    r   r   __all__r   r   r   r   r   r   r   r6   r   r   r)   r)   r)   r*   <module>   s8    	i
 