
    *j"                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZmZmZmZ d dlmZmZ d d	lmZmZmZ  ej        e          Z ej!        d
k    Z"d!dZ#	 d"d#dZ$	 	 	 d$d%dZ%d&d Z&dS )'    )annotationsN)	AwaitableCallableSequence)replace)Any)patch_configurablerecast_checkpoint_ns)CONFCONFIG_KEY_CHECKPOINT_NSCONFIG_KEY_RESUMINGNS_SEP)GraphBubbleUpParentCommand)CommandPregelExecutableTaskRetryPolicy)      nsstrreturnc                   |                      t                    }|rJ|d                                         r0|                                 |r|d                                         0|r|                                 |rJ|d                                         r0|                                 |r|d                                         0t          j        |          S )a  Return the checkpoint namespace for the parent graph.

    The checkpoint namespace is a `|`-separated path. Each segment is usually
    of the form `name:task_id` (e.g. `parent_first:<uuid>|node:<uuid>`), but the
    runtime may also insert a purely-numeric segment (e.g. `|1`) to disambiguate
    concurrent tasks (e.g. `parent_first:<uuid>|1|node:<uuid>`).

    Numeric segments are not real path levels, so we drop them before computing
    the parent namespace.
    )splitr   isdigitpopjoin)r   partss     a/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/langgraph/pregel/_retry.py!_checkpoint_ns_for_parent_commandr!      s     HHVE  E"I%%'' 		  E"I%%''   		  E"I%%'' 		  E"I%%''  ;u    taskr   retry_policySequence[RetryPolicy] | Noneconfigurabledict[str, Any] | NoneNonec                   | j         p|}d}| j        }|t          ||          }	 	 | j                                         | j                            | j        |          S # t          $ r}|t                   t                   }|j        d         }|j        |t          |          | j        fv r&| j        D ]}|                    ||           Y d}~dS |j        t           j        k    r$t%          |t'          |                    f|_         d}~wt(          $ r  t*          $ r}t,          r&|                    d| j         d| j         d           |s d}	|D ]}
t3          |
|          r|
}	 n|	s |dz  }||	j        k    r |	j        }t9          |	j        ||	j        |dz
  z  z            }|	j        r|tA          j!        dd          z   n|}tE          j#        |           tH          %                    d	| j         d
|dd| d|j&        j'         d| 
|           t          |tP          di          }Y d}~nd}~ww xY w)zRun a task with retries.r   NTgraphDuring task with name '
' and id ''   Retrying task  after .2f seconds (attempt ) after  exc_info))r$   configr	   writesclearprocinvokeinputr   r   r   argsr+   r
   namewritersr   PARENTr   r!   r   	ExceptionSUPPORTS_EXC_NOTESadd_noteid_should_retry_onmax_attemptsinitial_intervalminmax_intervalbackoff_factorjitterrandomuniformtimesleeploggerinfo	__class____name__r   )r#   r$   r&   attemptsr8   excr   cmdwmatching_policypolicyinterval
sleep_times                r    run_with_retryr]   7   s    $4LH[F#FL99@M?	MK9##DJ777 	 	 	Tl#;<B(1+CyR!5b!9!949EEE * *AHHS&))))gn,,#C/PQS/T/TUUUW 	 	 	 )	M )	M )	M! XVtyVVDGVVVWWW  #O&  #FC00 &,OE #  MH?777&7H,O:x!|LM H 4C3IW6>!Q////x  Jz""" KK F  F  F:  F  F  FU]  F  Fgjgtg}  F  F  AD  F  F    
 (1Dd0KLLFFFFFFS)	M/@Ms+   8A   
H?*A#D:DH?%DH::H?Fstreamboolmatch_cached_writes>Callable[[], Awaitable[Sequence[PregelExecutableTask]]] | Nonec                D  K   | j         p|}d}| j        }|t          ||          }|!| j         |             d{V D ]	}|| u r dS 
	 	 | j                                         |r+| j                            | j        |          2 3 d{V }6 dS | j        	                    | j        |           d{V S # t          $ r}	|t                   t                   }
|	j        d         }|j        |
t          |
          | j        fv r&| j        D ]}|                    ||           Y d}	~	dS |j        t&          j        k    r$t+          |t-          |
                    f|	_         d}	~	wt.          $ r  t0          $ r }	t2          r&|	                    d| j         d| j         d           |s d}|D ]}t9          ||	          r|} n|s |dz  }||j        k    r |j        }t?          |j         ||j!        |dz
  z  z            }|j"        r|tG          j$        dd          z   n|}tK          j&        |           d{V  tN          (                    d	| j         d
|dd| d|	j)        j*         d|	 
|	           t          |tV          di          }Y d}	~	nd}	~	ww xY wW)z'Run a task asynchronously with retries.r   NTr*   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   ),r$   r8   r	   	cache_keyr9   r:   r;   astreamr=   ainvoker   r   r   r>   r+   r
   r?   r@   r<   r   rA   r   r!   r   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   asynciorP   rQ   rR   rS   rT   r   )r#   r$   r^   r`   r&   rU   r8   t_rV   r   rW   rX   rY   rZ   r[   r\   s                    r    arun_with_retryri      s      $4LH[F#FL99&4>+E**,,,,,,,, 	 	ADyy FME	MK C#y00VDD       !  E !Y..tz6BBBBBBBBB 	 	 	Tl#;<B(1+CyR!5b!9!949EEE * *AHHS&))))gn,,#C/PQS/T/TUUUW 	 	 	 )	M )	M )	M! XVtyVVDGVVVWWW  #O&  #FC00 &,OE #  MH?777&7H,O:x!|LM H 4C3IW6>!Q////x  -
+++++++++ KK F  F  F:  F  F  FU]  F  Fgjgtg}  F  F  AD  F  F    
 (1Dd0KLLFFFFFFS)	M;FMs>   ;B8 BB8 %B8 8
JA#E%+:E%%J=DJJr   rV   rB   c                |   t          | j        t                    r"t          |t          | j                            S t          | j        t                    r/t          | j        t                    rt          || j                  S t          | j                  r|                     |          S t          d          )zICheck if the given exception should be retried based on the retry policy.zXretry_on must be an Exception class, a list or tuple of Exception classes, or a callable)	
isinstanceretry_onr   tupletype
issubclassrB   callable	TypeError)r$   rV   s     r    rF   rF      s    ,'22 
#u\%:;;<<<	L)4	0	0 	
Zy6 6 	
 #|4555	,'	(	( 
$$S)))f
 
 	
r"   )r   r   r   r   )N)r#   r   r$   r%   r&   r'   r   r(   )FNN)r#   r   r$   r%   r^   r_   r`   ra   r&   r'   r   r(   )r$   r   rV   rB   r   r_   )'
__future__r   rf   loggingrM   sysrO   collections.abcr   r   r   dataclassesr   typingr   langgraph._internal._configr	   r
   langgraph._internal._constantsr   r   r   r   langgraph.errorsr   r   langgraph.typesr   r   r   	getLoggerrT   rQ   version_inforC   r!   r]   ri   rF    r"   r    <module>r      s   " " " " " "    



  9 9 9 9 9 9 9 9 9 9             P P P P P P P P            : 9 9 9 9 9 9 9 F F F F F F F F F F		8	$	$%0    @ +/KM KM KM KM KMb *.YM YM YM YM YMx
 
 
 
 
 
r"   