o
    i                     @   s>   d d Z G dd dZG dd dZdd ZG dd	 d	Zd
S )c                 C   sT   t | tsdS t| dkrdS t | d tsdS t | d ts(t | d ts(dS dS )NF          T)
isinstancelistlenstrintfloat)obj r   9/mnt/c/Users/fbmor/ComfyUI/comfy_execution/graph_utils.pyis_link   s   
r   c                   @   sh   e Zd ZdZdZdZdddZedddZeddd	Z	dd
dZ
dd Zdd Zdd Zdd ZdS )GraphBuilder r   Nc                 C   s*   |d u r
t  | _n|| _i | _d| _d S Nr   )r   alloc_prefixprefixnodesid_gen)selfr   r   r   r   __init__   s
   
zGraphBuilder.__init__c                 C   s   || _ || _|| _d S N)_default_prefix_root_default_prefix_call_index_default_prefix_graph_index)clsprefix_root
call_indexgraph_indexr   r   r   set_default_prefix   s   
zGraphBuilder.set_default_prefixc                 C   sR   |d u rt j}|d u rt j}|d u rt j}| d| d| d}t  jd7  _|S )N.r   )r   r   r   r   )r   rootr   r   resultr   r   r   r       s   zGraphBuilder.alloc_prefixc                 K   sX   |d u rt | j}|  jd7  _| j| }|| jv r| j| S t|||}|| j|< |S r   )r   r   r   r   Node)r   
class_typeidkwargsnoder   r   r   r'   ,   s   




zGraphBuilder.nodec                 C   s   | j | }| j|S r   )r   r   getr   r%   r   r   r   lookup_node8      
zGraphBuilder.lookup_nodec                 C   s(   i }| j  D ]
\}}| ||< q|S r   )r   items	serialize)r   outputnode_idr'   r   r   r   finalize<   s   zGraphBuilder.finalizec                 C   s   | j | }g }| j D ]-}|j D ]%\}}t|r8|d |kr8|d |kr8|d u r3|||f q||j|< qq|D ]\}}|j|= q<d S )Nr   r   )r   r   valuesinputsr,   r   append)r   r/   index	new_value	to_remover'   keyvaluer   r   r   replace_node_outputB   s   
 

z GraphBuilder.replace_node_outputc                 C   s   | j | }| j|= d S r   )r   r   r)   r   r   r   remove_nodeO   r+   zGraphBuilder.remove_noder   )r   )NNN)__name__
__module____qualname__r   r   r   r   classmethodr   r   r'   r*   r0   r9   r:   r   r   r   r   r      s    

r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )r#   c                 C   s   || _ || _|| _d | _d S r   )r%   r$   r2   override_display_id)r   r%   r$   r2   r   r   r   r   T   s   
zNode.__init__c                 C   s
   | j |gS r   )r%   )r   r4   r   r   r   outZ      
zNode.outc                 C   s0   |d u r|| j v r| j |= d S d S || j |< d S r   )r2   )r   r7   r8   r   r   r   	set_input]   s
   
zNode.set_inputc                 C   s   | j |S r   )r2   r(   )r   r7   r   r   r   	get_inputd   s   zNode.get_inputc                 C   
   || _ d S r   )r?   )r   r?   r   r   r   set_override_display_idg   rA   zNode.set_override_display_idc                 C   s&   | j | jd}| jd ur| j|d< |S )Nr$   r2   r?   )r$   r2   r?   )r   
serializedr   r   r   r-   j   s   

zNode.serializeN)	r;   r<   r=   r   r@   rB   rC   rE   r-   r   r   r   r   r#   S   s    r#   c                 C   s   i }|   D ]9\}}|| }|d i d}|di   D ]\}}	t|	r4||	d  |	d g|d |< q|	|d |< q|||< qg }
tt|D ]}|| }t|r`|
||d  |d g qH|
| qH|t|
fS )Nr$   rF   r2   r   r   )r,   r(   r   ranger   r3   tuple)graphoutputsr   	new_graphr/   	node_infonew_node_idnew_node
input_nameinput_valuenew_outputsnr.   r   r   r   add_graph_prefixs   s    
rT   c                   @   s   e Zd ZdZdd ZdS )ExecutionBlockera  
    Return this from a node and any users will be blocked with the given error message.
    If the message is None, execution will be blocked silently instead.
    Generally, you should avoid using this functionality unless absolutely necessary. Whenever it's
    possible, a lazy input will be more efficient and have a better user experience.
    This functionality is useful in two cases:
    1. You want to conditionally prevent an output node from executing. (Particularly a built-in node
       like SaveImage. For your own output nodes, I would recommend just adding a BOOL input and using
       lazy evaluation to let it conditionally disable itself.)
    2. You have a node with multiple possible outputs, some of which are invalid and should not be used.
       (I would recommend not making nodes like this in the future -- instead, make multiple nodes with
       different outputs. Unfortunately, there are several popular existing nodes using this pattern.)
    c                 C   rD   r   )message)r   rV   r   r   r   r      rA   zExecutionBlocker.__init__N)r;   r<   r=   __doc__r   r   r   r   r   rU      s    rU   N)r   r   r#   rT   rU   r   r   r   r   <module>   s
    F 