
    g3fiK                       U d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZ ddlmZmZmZ ddlmZ ddlmZmZ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!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. erddl/m0Z0m1Z1 ddl%m2Z2m3Z3 ne4ez  dz  Z1 G d de$d      Z5 G d de$d      Z6g dZ7g dZ8dZ9 edd      Z:de;d<   	 	 	 	 d/dZ<ed0d       Z=d1d2d Z>	 	 	 	 	 	 d3d!Z?dddddd"	 	 	 	 	 	 	 	 	 	 	 	 	 d4d#Z@d5d$ZA	 d1	 	 	 	 	 	 	 	 	 	 	 d6d%ZB	 d1	 	 	 	 	 	 	 	 	 	 	 d7d&ZCd8d'ZD	 	 	 	 d9d(ZE ed)      ZF ed*      ZG G d+ d,e      ZHe	 	 	 	 d:d-       ZI	 	 	 	 	 	 	 	 	 	 d;d.ZJy)<z&Configuration utilities for Runnables.    )annotationsN)	AwaitableCallable	GeneratorIterableIteratorSequence)ExecutorFutureThreadPoolExecutor)contextmanager)Context
ContextVarTokencopy_context)partial)TYPE_CHECKINGAny	ParamSpecTypeVarcast)_set_tracing_contextget_tracing_context)	TypedDict)AsyncCallbackManagerCallbackManager)InputOutputaccepts_configaccepts_run_manager)LangChainTracer)BaseCallbackManager	Callbacks)AsyncCallbackManagerForChainRunCallbackManagerForChainRunc                      e Zd ZdZy)	EmptyDictzEmpty dict type.N)__name__
__module____qualname____doc__     ]/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/runnables/config.pyr'   r'   /   s    r-   r'   F)totalc                  p    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ed<   	 ded<   y)RunnableConfigzConfiguration for a `Runnable`.

    See the [reference docs](https://reference.langchain.com/python/langchain_core/runnables/#langchain_core.runnables.RunnableConfig)
    for more details.
    z	list[str]tagszdict[str, Any]metadatar#   	callbacksstrrun_name
int | Nonemax_concurrencyintrecursion_limitconfigurablezuuid.UUID | Nonerun_idN)r(   r)   r*   r+   __annotations__r,   r-   r.   r1   r1   3   sm     O
 
 
 M*  
 
 !  r-   r1   )r2   r3   r4   r6   r8   r:   r;   r<   )r2   r3   r4   r;      child_runnable_config)defaultz!ContextVar[RunnableConfig | None]var_child_runnable_configc                6   t         j                  |       }d}| j                  d      x}rlt        |dd      x}r]t	        d t        |dg       D        d      x}r=|j
                  j                  t        |            x}rt               }t        d|i       ||fS )zSet the child Runnable config + tracing context.

    Args:
        config: The config to set.

    Returns:
        The token to reset the config and the previous tracing context.
    Nr4   parent_run_idc              3  @   K   | ]  }t        |t              r|  y wN)
isinstancer!   ).0handlers     r.   	<genexpr>z&_set_config_context.<locals>.<genexpr>   s"      !'?; s   handlersparent)	rA   setgetgetattrnextrun_mapr5   r   r   )configconfig_tokencurrent_contextr4   rC   tracerruns          r.   _set_config_contextrV      s     -008LOjj-	-	-$YFFMF #*9j"#E
  F  NN&&s='9::S:-/h_-((r-   c              #  Z  K   t               }|j                  t        |       \  }}	 | |j                  t        j                  |       |j                  t
        ddddddd       y# |j                  t        j                  |       |j                  t
        ddddddd       w xY ww)zSet the child Runnable config + tracing context.

    Args:
        config: The config to set.

    Yields:
        The config context.
    N)rK   project_namer2   r3   enabledclient)r   rU   rV   rA   resetr   )rQ   ctxrR   _s       r.   set_config_contextr^      s      .Cgg16:OL!
	)//>  $ 
	
 	)//>  $ 
	
s   $B+A) >B+)?B((B+c                    t        g i dt        i       }t        j                         x}rW|j	                  t        d|j                         D ci c]"  \  }}|||t        v r|j                         n|$ c}}             | _|j	                  t        d| j                         D ci c]*  \  }}|#|t        v r||t        v r|j                         n|, c}}             | ,| j                         D ]  \  }}|t        vs|||d   |<    |j                  di       j                         D ]N  \  }}|j                  d      rt        |t        t        t        t        f      s9||d   vsA|dk7  sG||d   |<   P |S c c}}w c c}}w )zEnsure that a config is a dict with all keys present.

    Args:
        config: The config to ensure.

    Returns:
        The ensured config.
    N)r2   r3   r4   r:   r;   r1   r;   __r3   api_key)r1   DEFAULT_RECURSION_LIMITrA   rM   updater   itemsCOPIABLE_KEYScopyCONFIG_KEYS
startswithrF   r5   r9   floatbool)rQ   empty
var_configkvkeyvalues          r.   ensure_configrq      s    /E /2244z4  !+ 0 0 21} 1#5qvvx1<		
   !'1}k)9 1#5qvvx1<		
 LLN 	-DAq#+,n%a(	- ii399; +
Ut$53UD"9:5,,y %*E*c"+ L=s   'F(/F
c           	        |dk  rd| }t        |      t        | t              r+t        |       |k7  rdt        |        d| d}t        |      t        | t              rt	        t        t        |             S |dkD  rt        | t              r| j                  d      t        j                  dt        d	
       t        d| j                         D ci c]  \  }}|dk7  s|| c}}      }t        |      D cg c]  }|rt        |      n
t        |        c}S t        |      D cg c]  }t        |        c}S c c}}w c c}w c c}w )az  Get a list of configs from a single config or a list of configs.

     It is useful for subclasses overriding batch() or abatch().

    Args:
        config: The config or list of configs.
        length: The length of the list.

    Returns:
        The list of configs.

    Raises:
        ValueError: If the length of the list is not equal to the length of the inputs.

    r   zlength must be >= 0, but got z<config must be a list of the same length as inputs, but got z configs for z inputs   r<   z@Provided run_id be used only for the first element of the batch.   )category
stacklevelr1   )
ValueErrorrF   r	   lenlistmaprq   dictrM   warningswarnRuntimeWarningr   rd   range)rQ   lengthmsgrm   rn   
subsequentis          r.   get_config_listr      s@   $ z-fX6o&(#Fv(=6{m=A 	 o&(#Cv.//zj.6::h3G3SN#	

 P1!x-q!tP


 6]
 *+M*%f0EE
 	
 ,1=9aM&!99 Q
 :s   E#E=E,E)r4   r:   r8   r6   r;   c                   t        |       } ||| d<   d| v r| d= d| v r| d= ||| d<   ||| d<   ||| d<   |i | j                  di       || d<   | S )ag  Patch a config with new values.

    Args:
        config: The config to patch.
        callbacks: The callbacks to set.
        recursion_limit: The recursion limit to set.
        max_concurrency: The max concurrency to set.
        run_name: The run name to set.
        configurable: The configurable to set.

    Returns:
        The patched config.
    r4   r6   r<   r:   r8   r;   )rq   rM   )rQ   r4   r:   r8   r6   r;   s         r.   patch_configr   *  s    , 6"F ({z"vx "$3 !"$3 !%z!SFJJ~r$B!Sl!S~Mr-   c            
     @   i }d | D        D ]  }|D ]  }|dk(  r-i |j                  di       |j                  d      xs i |d<   6|dk(  r>t        t        |j                  dg       |j                  d      xs g z               |d<   y|dk(  r-i |j                  di       |j                  d      xs i |d<   |dk(  r|j                  d      }|d   }t        |t              ra||j                         |d<   t        |t              r
||z   |d<   |j                         }|D ]  }|j                  |d        ||d<   7|;||j                         |d<   Rt        |t              r1|j                         }|D ]  }|j                  |d        ||d<   |j                  |      |d<   |dk(  r|d   t        k7  s|d   |d<   |t        v r||   ||   j                         ||<   ||   xs |j                  |      ||<     |S )	zMerge multiple configs into one.

    Args:
        *configs: The configs to merge.

    Returns:
        The merged config.
    c              3  8   K   | ]  }|t        |        y wrE   )rq   )rG   cs     r.   rI   z merge_configs.<locals>.<genexpr>`  s     F=#Fs   r3   r2   r;   r4   T)inheritr:   )
rM   sortedrL   rF   ry   rf   add_handlermergerb   re   )configsbaserQ   ro   base_callbacksthese_callbacksmngrcallbacks           r.   merge_configsr   T  su    D GWF 29 1	9Cj $hhz2.$zz*-3$Z  %,

60B0HbIJ V &(hh~r2(zz.17R(^$ #!%+!6"("5 ot4%-,;,@,@,B[)#ND9,:_,L[)  .224(7 EH ,,Xt,DE,0[)$0%-,;,@,@,B[)#ND9.335(6 EH ,,Xt,DE,0[) -;,@,@,Q[)))+,0GG.45F.GD*+%&+*A"3K,,.S	"3K8488C=S	c1	929f Kr-   c                    t        |       r&|t        ||j                               |d<   n||d<   |t        |       r||d<    | |fi |S )a  Call function that may optionally accept a run_manager and/or config.

    Args:
        func: The function to call.
        input: The input to the function.
        config: The config to pass to the function.
        run_manager: The run manager to pass to the function.
        **kwargs: The keyword arguments to pass to the function.

    Returns:
        The output of the function.
    r4   rQ   run_managerr   r   	get_childr    funcinputrQ   r   kwargss        r.   call_func_with_variable_argsr     s^    , d"+Fk>S>S>UVF8%F8#6t#< +}   r-   c                    t        |       r&|t        ||j                               |d<   n||d<   |t        |       r||d<    | |fi |S )a  Async call function that may optionally accept a run_manager and/or config.

    Args:
        func: The function to call.
        input: The input to the function.
        config: The config to pass to the function.
        run_manager: The run manager to pass to the function.
        **kwargs: The keyword arguments to pass to the function.

    Returns:
        The output of the function.
    r   rQ   r   r   r   s        r.   acall_func_with_variable_argsr     s^    0 d"+Fk>S>S>UVF8%F8#6t#< +}   r-   c                    t        j                  | j                  d      | j                  d      | j                  d            S )z|Get a callback manager for a config.

    Args:
        config: The config.

    Returns:
        The callback manager.
    r4   r2   r3   inheritable_callbacksinheritable_tagsinheritable_metadata)r   	configurerM   rQ   s    r.   get_callback_manager_for_configr     s;     $$$jj5F+#ZZ
3 r-   c                    t        j                  | j                  d      | j                  d      | j                  d            S )zGet an async callback manager for a config.

    Args:
        config: The config.

    Returns:
        The async callback manager.
    r4   r2   r3   r   )r   r   rM   r   s    r.   %get_async_callback_manager_for_configr     s;      ))$jj5F+#ZZ
3 r-   PTc                  P     e Zd ZdZ	 	 	 	 	 	 	 	 d fdZ	 	 	 	 	 	 	 	 d fdZ xZS )ContextThreadPoolExecutorz?ThreadPoolExecutor that copies the context to the child thread.c           
     v    t         |   t        dt        t	               j
                  |g|i |            S )a  Submit a function to the executor.

        Args:
            func: The function to submit.
            *args: The positional arguments to the function.
            **kwargs: The keyword arguments to the function.

        Returns:
            The future for the function.
        Callable[..., T])supersubmitr   r   r   rU   )selfr   argsr   	__class__s       r.   r   z ContextThreadPoolExecutor.submit  s;      w~#W\^-?-?%W%WPV%WX
 	
r-   c                    t        t        |d               D cg c]  }t                c}dfd}t        |   |g|i |S c c}w )a9  Map a function to multiple iterables.

        Args:
            fn: The function to map.
            *iterables: The iterables to map over.
            timeout: The timeout for the map.
            chunksize: The chunksize for the map.

        Returns:
            The iterator for the mapped function.
        r   c                 F     j                         j                  g|  S rE   )poprU   )r   contextsfns    r.   _wrapped_fnz2ContextThreadPoolExecutor.map.<locals>._wrapped_fn(  s!    %8<<>%%b0400r-   )r   r   returnr   )r   rx   r   r   rz   )r   r   	iterablesr   r]   r   r   r   s    `    @r.   rz   zContextThreadPoolExecutor.map  sX    " -2#il2C,DEqLNE	1 w{

 
 	
 Fs   A)r   Callable[P, T]r   P.argsr   P.kwargsr   z	Future[T])r   r   r   zIterable[Any]r   r   r   zIterator[T])r(   r)   r*   r+   r   rz   __classcell__)r   s   @r.   r   r     sa    I

 
 	

 

(

 "
 	

 

 
r-   r   c              #     K   | xs i } t        | j                  d            5 }| ddd       y# 1 sw Y   yxY ww)zlGet an executor for a config.

    Args:
        config: The config.

    Yields:
        The executor.
    r8   )max_workersN)r   rM   )rQ   executors     r.   get_executor_for_configr   2  sB      \rF	"JJ01
 	  s   ">2	>;>c           
     H  K   dfd}| t        | t              rRt        j                         j	                  dt        dt        t               j                  |                   d{   S t        j                         j	                  | |       d{   S 7 07 w)a,  Run a function in an executor.

    Args:
        executor_or_config: The executor or config to run in.
        func: The function.
        *args: The positional arguments to the function.
        **kwargs: The keyword arguments to the function.

    Returns:
        The output of the function.
    c                 F    	  i S # t         $ r} t        | d } ~ ww xY wrE   )StopIterationRuntimeError)excr   r   r   s    r.   wrapperz run_in_executor.<locals>.wrapperW  s2    	(((( 	( C'		(s    	  Nr   )r   r   )	rF   r{   asyncioget_running_looprun_in_executorr   r   r   rU   )executor_or_configr   r   r   r   s    ``` r.   r   r   E  s     $( !Z0BD%I--/??#W\^-?-?%IJ
 
 	

 ))+;;<NPWXXX

 Ys$   A(B"-B.+B"B B" B")rQ   r1   r   z:tuple[Token[RunnableConfig | None], dict[str, Any] | None])rQ   r1   r   zGenerator[Context, None, None]rE   )rQ   RunnableConfig | Noner   r1   )rQ   z0RunnableConfig | Sequence[RunnableConfig] | Noner   r9   r   zlist[RunnableConfig])rQ   r   r4   zBaseCallbackManager | Noner:   r7   r8   r7   r6   z
str | Noner;   zdict[str, Any] | Noner   r1   )r   r   r   r1   )r   zCallable[[Input], Output] | Callable[[Input, RunnableConfig], Output] | Callable[[Input, CallbackManagerForChainRun], Output] | Callable[[Input, CallbackManagerForChainRun, RunnableConfig], Output]r   r   rQ   r1   r   z!CallbackManagerForChainRun | Noner   r   r   r   )r   zCallable[[Input], Awaitable[Output]] | Callable[[Input, RunnableConfig], Awaitable[Output]] | Callable[[Input, AsyncCallbackManagerForChainRun], Awaitable[Output]] | Callable[[Input, AsyncCallbackManagerForChainRun, RunnableConfig], Awaitable[Output]]r   r   rQ   r1   r   z&AsyncCallbackManagerForChainRun | Noner   r   r   zAwaitable[Output])rQ   r1   r   r   )rQ   r1   r   r   )rQ   r   r   zGenerator[Executor, None, None])
r   z Executor | RunnableConfig | Noner   r   r   r   r   r   r   r   )Kr+   
__future__r   r   uuidr|   collections.abcr   r   r   r   r   r	   concurrent.futuresr
   r   r   
contextlibr   contextvarsr   r   r   r   	functoolsr   typingr   r   r   r   r   langsmith.run_helpersr   r   typing_extensionsr    langchain_core.callbacks.managerr   r   langchain_core.runnables.utilsr   r   r   r     langchain_core.tracers.langchainr!   langchain_core.callbacks.baser"   r#   r$   r%   ry   r'   r1   rg   re   rb   rA   r=   rV   r^   rq   r   r   r   r   r   r   r   r   r   r   r   r   r,   r-   r.   <module>r      s   , "    X X C C % @ @   L ' R  =L  s
T!I	 6Ye 6r	   @JT@ <  ) )? )F 
 
82j+:<+:FI+:+:b -1"&"&*.'!' *'  	'
  ' ' (' 'T?R 6:!L!
 ! ! 3! ! !R ;?!! ! ! 8! ! !D $ cNCL1
 2 1
h !$ $"Y8"Y
"Y "Y 	"Y
 "Yr-   