
    %j                        d Z 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 dd	lmZ dd
lmZ ddlmZmZ  G d d          Ze		 ddd            Z ed          dd            ZdS )zADependency resolution: resolving, wrapping, and failure handling.    )annotationsN)AsyncGeneratorCallable)AsyncExitStackasynccontextmanager)	lru_cache)Any   )get_annotation_dependencies)_Depends)get_dependency_parametersget_signaturec                      e Zd ZdZd
dZd	S )FailedDependencyz;Placeholder for a dependency that raised during resolution.	parameterstrerror	ExceptionreturnNonec                "    || _         || _        d S N)r   r   )selfr   r   s      _/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/uncalled_for/resolution.py__init__zFailedDependency.__init__   s    "


    N)r   r   r   r   r   r   )__name__
__module____qualname____doc__r    r   r   r   r      s.        EE     r   r   functionCallable[..., Any]kwargsdict[str, Any] | Noner   AsyncGenerator[dict[str, Any]]c               4  K   |pi }t           j                            i           }	 t                      4 d{V }t           j                            |          }	 i }t          |           }|                                D ]^\  }}	||v r||         ||<   	 |                    |	           d{V ||<   5# t          $ r}
t          ||
          ||<   Y d}
~
Wd}
~
ww xY wt          |           }|                                D ]d\  }}|                    ||                    |                    }|D ]3}	|	                    ||          }|                    |           d{V  4e|W V  t           j                            |           n$# t           j                            |           w xY w	 ddd          d{V  n# 1 d{V swxY w Y   t           j                            |           dS # t           j                            |           w xY w)am  Resolve all dependencies declared on a function's signature.

    Yields a dict mapping parameter names to resolved values. Dependencies
    are entered as async context managers and cleaned up when the context
    exits.

    Parameters already present in *kwargs* are passed through without
    resolution, allowing callers to override specific dependencies.
    N)r   cachesetr   stackr   itemsenter_async_contextr   r   r   getbind_to_parameterreset)r"   r$   providedcache_tokenr*   stack_token	arguments
parametersr   
dependencyr   annotation_dependenciesparameter_namedependenciesvaluebounds                   r   resolved_dependenciesr;      s      |H.$$R((K*!## 	2 	2 	2 	2 	2 	2 	2u".,,U33K2,.	6x@@
-7-=-=-?-? 
R 
R)Iz H,,/7	/B	), R5:5N5N&6 6 0 0 0 0 0 0	),, % R R R/?	5/Q/Q	),,,,,,R +Fh*O*O'4K4Q4Q4S4S ? ?0NL$LL~9V9VWWE&2 ? ?
 * < <^U S S#77>>>>>>>>>>?  $$[1111$$[111117	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2: 	[)))))[))))sq   G6  G:FB65F6
C CFCBF- G!F..G2G6 
GG6 GG6 6!Hi  )maxsizec                    t          t                               t                     }s|s S t                     }fd|j                                        D             }|                    |t          j        j	                  }t          j
                   d fd} j        |_         j        |_        ||_        fd j                                        D             |_        |S )	a  Produce a wrapper whose signature hides dependency parameters.

    If *function* has no ``Dependency`` defaults, it is returned unchanged.
    Otherwise an async wrapper is returned that resolves dependencies
    automatically and forwards user-supplied keyword arguments.
    c                "    g | ]\  }}|v	|S r!   r!   ).0namepdependency_namess      r   
<listcomp>z(without_dependencies.<locals>.<listcomp>X   s3       D!''' 	
'''r   )r4   return_annotationr$   r	   r   c                    K   t          |           4 d {V }i || }r  di | d {V cd d d           d {V  S  di |cd d d           d {V  S # 1 d {V swxY w Y   d S )Nr!   )r;   )r$   resolved
all_kwargsr"   is_asyncs      r   wrapperz%without_dependencies.<locals>.wrapperc   si     (6:: 	* 	* 	* 	* 	* 	* 	*h/H//J 4%X33
33333333	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 8))j))		* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   AA
A'*A'c                0    i | ]\  }}|v	|d k    ||S )r   r!   )r?   kvrB   s      r   
<dictcomp>z(without_dependencies.<locals>.<dictcomp>m   s;       Aq$$$h 	
1)6r   )r$   r	   r   r	   )r)   r   r   r   r4   r+   replaceinspect	Parameteremptyiscoroutinefunctionr   r    __signature____annotations__)r"   r6   original_signaturefiltered_parametersnew_signaturerI   rB   rH   s   `     @@r   without_dependenciesrX   J   sC    4X>>??9(CC $; &x00   )4::<<  
 '..&':K:Q /  M *844H* * * * * * *  (G&GO)G   ,2244  G Nr   r   )r"   r#   r$   r%   r   r&   )r"   r#   r   r#   )r    
__future__r   rO   collections.abcr   r   
contextlibr   r   	functoolsr   typingr	   r   
functionalr   introspectionr   r   r   r;   rX   r!   r   r   <module>r`      sB   G G " " " " " "  4 4 4 4 4 4 4 4 : : : : : : : :             4 4 4 4 4 4             C C C C C C C C         %).* .* .* .* .*b 5( ( ( ( ( (r   