a
    ”˜ëjr]  ã                   @  sÊ  d Z ddlmZ ddlZddl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mZ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mZ erÐddl m!Z! ddl"m#Z# ddlmZ$ G dd„ deƒZ%G dd„ deƒZ&dddœdd„Z'G dd„ deƒZ(G dd„ deƒZ)G dd„ deƒZ*G dd„ de
ƒZ+eG d d!„ d!ƒƒZ,G d"d#„ d#e
ƒZ-dd$dd%œd&d'„Z.d(d)œddd*d+œd,d-„Z/eG d.d/„ d/ƒƒZ0d8d/d1d2d3œd4d5„Z1d9d/d1d2d3œd6d7„Z2dS ):zGraph used in Runnables.é    )ÚannotationsN)Údefaultdict)Ú	dataclassÚfield)ÚEnum)	ÚTYPE_CHECKINGÚAnyÚCallableÚ
NamedTupleÚOptionalÚProtocolÚ	TypedDictÚUnionÚoverload)ÚUUIDÚuuid4)Úto_json_not_implemented)ÚRunnableÚRunnableSerializable)Ú_IgnoreUnserializableÚis_basemodel_subclass)ÚSequence)Ú	BaseModel)r   c                   @  s   e Zd ZdZddœdd„ZdS )ÚStringifiablez7Protocol for objects that can be converted to a string.Ústr©Úreturnc                 C  s   dS )zConvert the object to a string.N© ©Úselfr   r   ú]/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain_core/runnables/graph.pyÚ__str__%   s    zStringifiable.__str__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r   r   r   r    r   "   s   r   c                   @  s"   e Zd ZU dZded< ded< dS )Ú
LabelsDictz4Dictionary of labels for nodes and edges in a graph.zdict[str, str]ÚnodesÚedgesN©r"   r#   r$   r%   Ú__annotations__r   r   r   r    r&   )   s   
r&   r   Úbool)Úvaluer   c                 C  s&   zt | ƒ W n ty    Y dS 0 dS )z¡Check if a string is a valid UUID.

    Args:
        value: The string to check.

    Returns:
        True if the string is a valid UUID, False otherwise.
    FT)r   Ú
ValueError)r,   r   r   r    Úis_uuid2   s
    	r.   c                   @  sT   e Zd ZU dZded< ded< dZded< dZd	ed
< dddœddd dœdd„ZdS )ÚEdgezEdge in a graph.r   ÚsourceÚtargetNúOptional[Stringifiable]ÚdataFr+   Úconditional©r0   r1   úOptional[str])r0   r1   r   c                C  s    t |p
| j|p| j| j| jd�S )a/  Return a copy of the edge with optional new source and target nodes.

        Args:
            source: The new source node id. Defaults to None.
            target: The new target node id. Defaults to None.

        Returns:
            A copy of the edge with the new source and target nodes.
        ©r0   r1   r3   r4   )r/   r0   r1   r3   r4   )r   r0   r1   r   r   r    ÚcopyN   s    üz	Edge.copy)r"   r#   r$   r%   r*   r3   r4   r8   r   r   r   r    r/   B   s   
ÿr/   c                   @  sL   e Zd ZU dZded< ded< ded< ded< d	d	d
œddd dœdd„Zd	S )ÚNodezNode in a graph.r   ÚidÚnameú*Union[type[BaseModel], RunnableType, None]r3   úOptional[dict[str, Any]]ÚmetadataN©r:   r;   r6   )r:   r;   r   c                C  s    t |p
| j|p| j| j| jd�S )a  Return a copy of the node with optional new id and name.

        Args:
            id: The new node id. Defaults to None.
            name: The new node name. Defaults to None.

        Returns:
            A copy of the node with the new id and name.
        )r:   r;   r3   r>   )r9   r:   r;   r3   r>   )r   r:   r;   r   r   r    r8   n   s    üz	Node.copy)r"   r#   r$   r%   r*   r8   r   r   r   r    r9   b   s   
ür9   c                   @  s"   e Zd ZU dZded< ded< dS )ÚBranchzBranch in a graph.zCallable[..., str]Ú	conditionzOptional[dict[str, str]]ZendsNr)   r   r   r   r    r@   …   s   
r@   c                   @  s@   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdS )Ú
CurveStylez5Enum for different curve styles supported by Mermaid.ZbasisZbumpXZbumpYZcardinalZ
catmullRomZlinearZ	monotoneXZ	monotoneYZnaturalÚstepZ	stepAfterZ
stepBeforeN)r"   r#   r$   r%   ZBASISZBUMP_XZBUMP_YZCARDINALZCATMULL_ROMÚLINEARZ
MONOTONE_XZ
MONOTONE_YZNATURALZSTEPZ
STEP_AFTERZSTEP_BEFOREr   r   r   r    rB   Ž   s   rB   c                   @  s6   e Zd ZU dZdZded< dZded< dZded< d	S )
Ú
NodeStylesa=  Schema for Hexadecimal color codes for different node types.

    Args:
        default: The default color code. Defaults to "fill:#f2f0ff,line-height:1.2".
        first: The color code for the first node. Defaults to "fill-opacity:0".
        last: The color code for the last node. Defaults to "fill:#bfb6fc".
    zfill:#f2f0ff,line-height:1.2r   Údefaultzfill-opacity:0Úfirstzfill:#bfb6fcÚlastN)r"   r#   r$   r%   rF   r*   rG   rH   r   r   r   r    rE   Ÿ   s   
rE   c                   @  s   e Zd ZdZdZdZdS )ÚMermaidDrawMethodz5Enum for different draw methods supported by Mermaid.Z	pyppeteerÚapiN)r"   r#   r$   r%   Z	PYPPETEERÚAPIr   r   r   r    rI   ®   s   rI   r<   )r:   r3   r   c                 C  sF   t | ƒr|du r| S t|tƒr&| ¡ n|j}| d¡s:|S |dd… S )z¨Convert the data of a node to a string.

    Args:
        id: The node id.
        data: The node data.

    Returns:
        A string representation of the data.
    Nr   é   )r.   Ú
isinstancer   Úget_namer"   Ú
startswith)r:   r3   Zdata_strr   r   r    Únode_data_str·   s    rP   F©Úwith_schemasz%dict[str, Union[str, dict[str, Any]]])ÚnoderR   r   c                C  sà   | j du ri }n¸t| j tƒr>d| j  ¡ t| j| j ƒdœdœ}nŠt| j tƒrpdt| j ƒd t| j| j ƒdœdœ}nXt 	| j ¡r´t
| j ƒr´|ržd| j jtd�dœndt| j| j ƒdœ}ndt| j| j ƒdœ}| jdurÜ| j|d	< |S )
a8  Convert the data of a node to a JSON-serializable format.

    Args:
        node: The node to convert.
        with_schemas: Whether to include the schema of the data if
            it is a Pydantic model. Defaults to False.

    Returns:
        A dictionary with the type of the data and the data itself.
    NZrunnabler?   )Útyper3   r:   Zschema)Zschema_generatorÚunknownr>   )r3   rM   r   Zlc_idrP   r:   r   r   ÚinspectÚisclassr   Zmodel_json_schemar   r>   )rS   rR   Újsonr   r   r    Únode_data_jsonÊ   s@    
þþþþúÿþþøþ

rY   c                   @  sÚ  e Zd ZU dZeed�Zded< eed�Z	ded< ddœd	d
dœdd„Z
d	dœdd„Zddœdd„ZdVddœdddddœdd„Zdddœdd „ZdWddd!d	d"d#œd$d%„Zd&d'œd dd(d)œd*d+„Zd dœd,d-„Zd.dœd/d0„Zd.dœd1d2„Zddœd3d4„Zddœd5d6„Zddœd7d8„Zddœd9d:„ZedXddd;dd<œd=d>„ƒZedYddd;d?d<œd@d>„ƒZdZddd;dAd<œdBd>„ZdCejddDddEœd	dFdGdHdddIœdJdK„ZejddDdejdLdMdNdOdddPœdFdGdHddQddHdHdRddd?dSœdTdU„ZdS )[ÚGraphzÁGraph of nodes and edges.

    Args:
        nodes: Dictionary of nodes in the graph. Defaults to an empty dictionary.
        edges: List of edges in the graph. Defaults to an empty list.
    )Údefault_factoryzdict[str, Node]r'   z
list[Edge]r(   FrQ   r+   zdict[str, list[dict[str, Any]]])rR   r   c                  sŠ   dd„ t | j ¡ ƒD ƒ‰ g }| jD ]F}ˆ |j ˆ |j dœ}|jdurP|j|d< |jr^d|d< | |¡ q"‡ ‡fdd	„| j ¡ D ƒ|d
œS )a   Convert the graph to a JSON-serializable format.

        Args:
            with_schemas: Whether to include the schemas of the nodes if they are
                Pydantic models. Defaults to False.

        Returns:
            A dictionary with the nodes and edges of the graph.
        c                 S  s(   i | ] \}}|j t|j ƒr|n|j “qS r   )r:   r.   )Ú.0ÚirS   r   r   r    Ú
<dictcomp>  s   ÿz!Graph.to_json.<locals>.<dictcomp>r5   Nr3   Tr4   c                   s&   g | ]}d ˆ |j  it|ˆd�¥‘qS )r:   rQ   )r:   rY   ©r\   rS   ©Zstable_node_idsrR   r   r    Ú
<listcomp>(  s
   ý
ÿ
þz!Graph.to_json.<locals>.<listcomp>©r'   r(   )	Ú	enumerater'   Úvaluesr(   r0   r1   r3   r4   Úappend)r   rR   r(   ÚedgeZ	edge_dictr   r`   r    Úto_json  s$    
þ
þ

ûøzGraph.to_jsonr   c                 C  s
   t | jƒS )z'Return whether the graph has any nodes.)r+   r'   r   r   r   r    Ú__bool__2  s    zGraph.__bool__r   c                 C  s   t ƒ jS )zfReturn a new unique node identifier.

        It that can be used to add a node to the graph.
        )r   Úhexr   r   r   r    Únext_id6  s    zGraph.next_idN)r>   r<   r6   r=   r9   )r3   r:   r>   r   c                C  sX   |dur&|| j v r&d|› d�}t|ƒ‚|p0|  ¡ }t|||t||ƒd�}|| j |j< |S )a|  Add a node to the graph and return it.

        Args:
            data: The data of the node.
            id: The id of the node. Defaults to None.
            metadata: Optional metadata for the node. Defaults to None.

        Returns:
            The node that was added to the graph.

        Raises:
            ValueError: If a node with the same id already exists.
        NzNode with id z already exists)r:   r3   r>   r;   )r'   r-   rj   r9   rP   r:   )r   r3   r:   r>   ÚmsgÚid_rS   r   r   r    Úadd_node=  s    zGraph.add_nodeÚNone)rS   r   c                   s(   | j  ˆ j¡ ‡ fdd„| jD ƒ| _dS )zyRemove a node from the graph and all edges connected to it.

        Args:
            node: The node to remove.
        c                   s"   g | ]}ˆ j |j|jhvr|‘qS r   )r:   r0   r1   ©r\   rf   ©rS   r   r    ra   `  s   z%Graph.remove_node.<locals>.<listcomp>N)r'   Úpopr:   r(   )r   rS   r   rp   r    Úremove_nodeY  s    
ÿzGraph.remove_noder2   r/   )r0   r1   r3   r4   r   c                 C  sh   |j | jvr"d|j › d�}t|ƒ‚|j | jvrDd|j › d�}t|ƒ‚t|j |j ||d�}| j |¡ |S )aÙ  Add an edge to the graph and return it.

        Args:
            source: The source node of the edge.
            target: The target node of the edge.
            data: Optional data associated with the edge. Defaults to None.
            conditional: Whether the edge is conditional. Defaults to False.

        Returns:
            The edge that was added to the graph.

        Raises:
            ValueError: If the source or target node is not in the graph.
        zSource node z not in graphzTarget node r7   )r:   r'   r-   r/   r(   re   )r   r0   r1   r3   r4   rk   rf   r   r   r    Úadd_edged  s    ÿzGraph.add_edgeÚ ©Úprefixz%tuple[Optional[Node], Optional[Node]])Úgraphrv   r   c                  s²   t dd„ |j ¡ D ƒƒrd‰ dddœ‡ fdd„‰| j ‡fdd	„|j ¡ D ƒ¡ | j ‡fd
d„|jD ƒ¡ | ¡ | ¡  }}|r”|j	ˆ|j
ƒd�nd|r¬|j	ˆ|j
ƒd�ndfS )aS  Add all nodes and edges from another graph.

        Note this doesn't check for duplicates, nor does it connect the graphs.

        Args:
            graph: The graph to add.
            prefix: The prefix to add to the node ids. Defaults to "".

        Returns:
            A tuple of the first and last nodes of the subgraph.
        c                 s  s   | ]}t |jƒV  qd S ©N)r.   r:   r_   r   r   r    Ú	<genexpr>“  ó    zGraph.extend.<locals>.<genexpr>rt   r   )rl   r   c                   s   ˆ rˆ › d| › �S | S )Nú:r   )rl   ru   r   r    Úprefixed–  s    zGraph.extend.<locals>.prefixedc                   s&   i | ]\}}ˆ |ƒ|j ˆ |ƒd �“qS ©©r:   ©r8   )r\   ÚkÚv©r|   r   r    r^   ›  rz   z Graph.extend.<locals>.<dictcomp>c                   s&   g | ]}|j ˆ |jƒˆ |jƒd �‘qS ©r5   ©r8   r0   r1   ro   r‚   r   r    ra   Ÿ  s   ÿz Graph.extend.<locals>.<listcomp>r~   N)Úallr'   rd   ÚupdateÚitemsr(   ÚextendÚ
first_nodeÚ	last_noder8   r:   )r   rw   rv   rG   rH   r   )rv   r|   r    rˆ   …  s    ÿ
þÿþzGraph.extendc                   s€   t tƒ}| j ¡ D ]}||j  |j¡ qdd„ | ¡ D ƒ‰dddœ‡fdd„‰ t‡ fdd„| j ¡ D ƒ‡ fdd	„| j	D ƒd
�S )ztReturn a new graph with all nodes re-identified.

        Uses their unique, readable names where possible.
        c                 S  sF   i | ]>\}}t |ƒD ],\}}|t|ƒd kr.|n|› d|d  › �“qqS )é   Ú_)rc   Úlen)r\   Z	node_nameZnode_idsr]   Únode_idr   r   r    r^   ´  s   þzGraph.reid.<locals>.<dictcomp>r   )rŽ   r   c                   s   ˆ |  }t | ƒr|S | S rx   )r.   )rŽ   Úlabel)Úunique_labelsr   r    Ú_get_node_idº  s    z Graph.reid.<locals>._get_node_idc                   s&   i | ]\}}ˆ |ƒ|j ˆ |ƒd �“qS r}   r   )r\   rl   rS   ©r‘   r   r    r^   Á  s   ÿc                   s&   g | ]}|j ˆ |jƒˆ |jƒd �‘qS rƒ   r„   ro   r’   r   r    ra   Å  s
   üþzGraph.reid.<locals>.<listcomp>rb   )
r   Úlistr'   rd   r;   re   r:   r‡   rZ   r(   )r   Znode_name_to_idsrS   r   )r‘   r�   r    Úreid«  s    þ
þ
ûûz
Graph.reidúOptional[Node]c                 C  s   t | ƒS )a8  Find the single node that is not a target of any edge.

        If there is no such node, or there are multiple, return None.
        When drawing the graph, this node would be the origin.

        Returns:
            The first node, or None if there is no such node or multiple
            candidates.
        )Ú_first_noder   r   r   r    r‰   Î  s    
zGraph.first_nodec                 C  s   t | ƒS )a<  Find the single node that is not a source of any edge.

        If there is no such node, or there are multiple, return None.
        When drawing the graph, this node would be the destination.

        Returns:
            The last node, or None if there is no such node or multiple
            candidates.
        )Ú
_last_noder   r   r   r    rŠ   Ú  s    
zGraph.last_nodec                   sF   |   ¡ ‰ ˆ rBt| ˆ jgd�rBt‡ fdd„| jD ƒƒdkrB|  ˆ ¡ dS )z›Remove the first node if it exists and has a single outgoing edge.

        i.e., if removing it would not leave the graph without a "first" node.
        ©Úexcludec                   s   h | ]}|j ˆ jkr|’qS r   )r0   r:   ©r\   Úe©r‰   r   r    Ú	<setcomp>ï  rz   z(Graph.trim_first_node.<locals>.<setcomp>r‹   N)r‰   r–   r:   r�   r(   rr   r   r   rœ   r    Útrim_first_nodeæ  s    ÿþýzGraph.trim_first_nodec                   sF   |   ¡ ‰ ˆ rBt| ˆ jgd�rBt‡ fdd„| jD ƒƒdkrB|  ˆ ¡ dS )z™Remove the last node if it exists and has a single incoming edge.

        i.e., if removing it would not leave the graph without a "last" node.
        r˜   c                   s   h | ]}|j ˆ jkr|’qS r   )r1   r:   rš   ©rŠ   r   r    r�   ü  rz   z'Graph.trim_last_node.<locals>.<setcomp>r‹   N)rŠ   r—   r:   r�   r(   rr   r   r   rŸ   r    Útrim_last_nodeó  s    ÿþýzGraph.trim_last_nodec                 C  s(   ddl m} |dd„ | j ¡ D ƒ| jƒS )zcDraw the graph as an ASCII art string.

        Returns:
            The ASCII art string.
        r   )Ú
draw_asciic                 S  s   i | ]}|j |j“qS r   r?   r_   r   r   r    r^   
  rz   z$Graph.draw_ascii.<locals>.<dictcomp>)Z$langchain_core.runnables.graph_asciir¡   r'   rd   r(   )r   r¡   r   r   r    r¡      s
    þzGraph.draw_asciic                 C  s   t |  ¡ ƒ dS )z'Print the graph as an ASCII art string.N)Úprintr¡   r   r   r   r    Úprint_ascii  s    zGraph.print_asciizOptional[LabelsDict])Úoutput_file_pathÚfontnameÚlabelsr   c                 C  s   d S rx   r   ©r   r¤   r¥   r¦   r   r   r    Údraw_png  s    zGraph.draw_pngÚbytesc                 C  s   d S rx   r   r§   r   r   r    r¨     s    zUnion[bytes, None]c                 C  sb   ddl m} dd„ | j ¡ D ƒ}||ti |¥|dur<|d ni ¥|durP|d ni d�ƒ | |¡S )	aµ  Draw the graph as a PNG image.

        Args:
            output_file_path: The path to save the image to. If None, the image
                is not saved. Defaults to None.
            fontname: The name of the font to use. Defaults to None.
            labels: Optional labels for nodes and edges in the graph. Defaults to None.

        Returns:
            The PNG image as bytes if output_file_path is None, None otherwise.
        r   )Ú	PngDrawerc                 S  s   i | ]}|j |j“qS r   r?   r_   r   r   r    r^   6  rz   z"Graph.draw_png.<locals>.<dictcomp>Nr'   r(   rb   )Z"langchain_core.runnables.graph_pngrª   r'   rd   r&   Zdraw)r   r¤   r¥   r¦   rª   Zdefault_node_labelsr   r   r    r¨   "  s    ÿþûþ	÷Té	   )Úwith_stylesÚcurve_styleÚnode_colorsÚwrap_label_n_wordsÚfrontmatter_configrB   zOptional[NodeStyles]Úint)r¬   r­   r®   r¯   r°   r   c          
      C  sV   ddl m} |  ¡ }| ¡ }| ¡ }	||j|j|r8|jnd|	rD|	jnd|||||d�	S )aq  Draw the graph as a Mermaid syntax string.

        Args:
            with_styles: Whether to include styles in the syntax. Defaults to True.
            curve_style: The style of the edges. Defaults to CurveStyle.LINEAR.
            node_colors: The colors of the nodes. Defaults to NodeStyles().
            wrap_label_n_words: The number of words to wrap the node labels at.
                Defaults to 9.
            frontmatter_config (dict[str, Any], optional): Mermaid frontmatter config.
                Can be used to customize theme and styles. Will be converted to YAML and
                added to the beginning of the mermaid graph. Defaults to None.

                See more here: https://mermaid.js.org/config/configuration.html.

                Example config:

                .. code-block:: python

                {
                    "config": {
                        "theme": "neutral",
                        "look": "handDrawn",
                        "themeVariables": { "primaryColor": "#e2e2e2"},
                    }
                }


        Returns:
            The Mermaid syntax string.
        r   )Údraw_mermaidN)	r'   r(   r‰   rŠ   r¬   r­   Znode_stylesr¯   r°   )Ú&langchain_core.runnables.graph_mermaidr²   r”   r‰   rŠ   r'   r(   r:   )
r   r¬   r­   r®   r¯   r°   r²   rw   r‰   rŠ   r   r   r    r²   C  s    (÷zGraph.draw_mermaidZwhiteé
   r‹   g      ð?)r­   r®   r¯   r¤   Údraw_methodÚbackground_colorÚpaddingÚmax_retriesÚretry_delayr°   Úbase_urlrI   Úfloat)r­   r®   r¯   r¤   rµ   r¶   r·   r¸   r¹   r°   rº   r   c             
   C  s6   ddl m} | j||||
d�}||||||||	|d�S )aî  Draw the graph as a PNG image using Mermaid.

        Args:
            curve_style: The style of the edges. Defaults to CurveStyle.LINEAR.
            node_colors: The colors of the nodes. Defaults to NodeStyles().
            wrap_label_n_words: The number of words to wrap the node labels at.
                Defaults to 9.
            output_file_path: The path to save the image to. If None, the image
                is not saved. Defaults to None.
            draw_method: The method to use to draw the graph.
                Defaults to MermaidDrawMethod.API.
            background_color: The color of the background. Defaults to "white".
            padding: The padding around the graph. Defaults to 10.
            max_retries: The maximum number of retries (MermaidDrawMethod.API).
                Defaults to 1.
            retry_delay: The delay between retries (MermaidDrawMethod.API).
                Defaults to 1.0.
            frontmatter_config (dict[str, Any], optional): Mermaid frontmatter config.
                Can be used to customize theme and styles. Will be converted to YAML and
                added to the beginning of the mermaid graph. Defaults to None.

                See more here: https://mermaid.js.org/config/configuration.html.

                Example config:

                .. code-block:: python

                {
                    "config": {
                        "theme": "neutral",
                        "look": "handDrawn",
                        "themeVariables": { "primaryColor": "#e2e2e2"},
                    }
                }
            base_url: The base URL of the Mermaid server for rendering via API.
                Defaults to None.

        Returns:
            The PNG image as bytes.

        r   )Údraw_mermaid_png)r­   r®   r¯   r°   )Úmermaid_syntaxr¤   rµ   r¶   r·   r¸   r¹   rº   )r³   r¼   r²   )r   r­   r®   r¯   r¤   rµ   r¶   r·   r¸   r¹   r°   rº   r¼   r½   r   r   r    r¼   }  s"    9üøzGraph.draw_mermaid_png)N)NF)NN)NN)NNN) r"   r#   r$   r%   r   Údictr'   r*   r“   r(   rg   rh   rj   rm   rr   rs   rˆ   r”   r‰   rŠ   rž   r    r¡   r£   r   r¨   rB   rD   r²   rI   rK   r¼   r   r   r   r    rZ     sj   
%
 ýû  û"ÿ&#  ü  ü	   ü$ù=órZ   r   zSequence[str]r•   )rw   r™   r   c                   sF   ‡ fdd„| j D ƒ‰‡ ‡fdd„| j ¡ D ƒ}t|ƒdkrB|d S dS )zñFind the single node that is not a target of any edge.

    Exclude nodes/sources with ids in the exclude list.
    If there is no such node, or there are multiple, return None.
    When drawing the graph, this node would be the origin.
    c                   s   h | ]}|j ˆ vr|j’qS r   r5   ro   r˜   r   r    r�   Ó  rz   z_first_node.<locals>.<setcomp>c                   s$   g | ]}|j ˆ vr|j ˆvr|‘qS r   r~   r_   ©r™   Útargetsr   r    ra   Ô  s   þz_first_node.<locals>.<listcomp>r‹   r   N©r(   r'   rd   r�   ©rw   r™   Úfoundr   r¿   r    r–   Ì  s
    þr–   c                   sF   ‡ fdd„| j D ƒ‰‡ ‡fdd„| j ¡ D ƒ}t|ƒdkrB|d S dS )zöFind the single node that is not a source of any edge.

    Exclude nodes/targets with ids in the exclude list.
    If there is no such node, or there are multiple, return None.
    When drawing the graph, this node would be the destination.
    c                   s   h | ]}|j ˆ vr|j’qS r   )r1   r0   ro   r˜   r   r    r�   ã  rz   z_last_node.<locals>.<setcomp>c                   s$   g | ]}|j ˆ vr|j ˆvr|‘qS r   r~   r_   ©r™   Úsourcesr   r    ra   ä  s   þz_last_node.<locals>.<listcomp>r‹   r   NrÁ   rÂ   r   rÄ   r    r—   Ü  s
    þr—   )r   )r   )3r%   Ú
__future__r   rV   Úcollectionsr   Zdataclassesr   r   Úenumr   Útypingr   r   r	   r
   r   r   r   r   r   Úuuidr   r   Z langchain_core.load.serializabler   Zlangchain_core.runnables.baser   r   Zlangchain_core.utils.pydanticr   r   Úcollections.abcr   Zpydanticr   ZRunnableTyper   r&   r.   r/   r9   r@   rB   rE   rI   rP   rY   rZ   r–   r—   r   r   r   r    Ú<module>   sD   ,	 #		ÿ7   M