+
    O(i                    >   R t ^ RIHt ^ RIt^ RIHtHt ^ RIHtH	t	H
t
 ^ RIHt ^ RIHt ^ RIHtHtHtHtHt ^RIHtHt ^R	IHt ]! R
4      t ! R R]],          4      t ! R R4      t]R R l4       t]R R l4       t]R R l4       t]R R l4       tR R ltR# )z9App-scoped shared dependencies: Shared and SharedContext.)annotationsN)	AwaitableCallable)AbstractAsyncContextManagerAbstractContextManagerAsyncExitStack)
ContextVar)TracebackType)AnyClassVarTypeVarcastoverload)DependencyFactory_FunctionalDependency)get_dependency_parametersRc                  2    ] tR t^tRtR R ltR R ltRtR# )_SharedzApp-scoped dependency resolved once and reused across all calls.

Unlike _Depends (which resolves per-call), _Shared dependencies initialize
once within a SharedContext and the same instance is provided to all
subsequent resolutions.
c                   V ^8  d   QhRR/# )   returnr    )formats   "Y/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/uncalled_for/shared.py__annotate___Shared.__annotate__   s     " "! "    c                	  "   \         P                  P                  4       pV P                  V9   d   WP                  ,          # V P	                  4       G R j  xL
 p\         P
                  P                  4       ;_uu_4       GR j  xL
  V P                  V9   d%   WP                  ,          uuR R R 4      GR j  xL
  # \         P                  P                  4       pV P                  ! R/ VB pV P                  W44      G R j  xL
 pWQV P                  &   TuuR R R 4      GR j  xL
  #  L L Lt L, L  + GR j  xL 
 '       g   i     R # ; i5i)Nr   )SharedContextresolvedgetfactory_resolve_parameterslockstack_resolve_factory_value)selfr    	argumentsr%   	raw_valueresolved_values   &     r   
__aenter___Shared.__aenter__   s      ))--/<<8#LL))2244	 %%))+++||x'- ,++ "''++-E1y1I#'#>#>u#PPN%3T\\"! ,++ 5+ Q ,+++s   AED+.ED-E
#D5-E:D/;E AD5D1D5E%D3&E-E/E1D53E5E	;D><
E	E			Ec                   V ^8  d   QhRR/# )r   r   zdict[str, Any]r   )r   s   "r   r   r   1   s      > r   c                	   "   \         P                  P                  4       p/ p\        V P                  4      pVP                  4        F   w  rEVP                  V4      G R j  xL
 W$&   K"  	  V#  L5iN)r   r%   r!   r   r"   itemsenter_async_context)r'   r%   r(   
parameters	parameter
dependencys   &     r   r#   _Shared._resolve_parameters1   sf     ##'')$&	.t||<
%/%5%5%7!I).)B)B:)N#NI  &8  $Os   AA0!A."A0r   N)__name__
__module____qualname____firstlineno____doc__r+   r#   __static_attributes__r   r   r   r   r      s    "& r   r   c                      ] tR t^<t$ Rt]! R4      tR]R&   ]! R4      tR]R&   ]! R4      t	R	]R
&   R R lt
R R ltRtR# )r   a{  Manages app-scoped Shared dependency lifecycle.

Use as an async context manager to establish a scope for Shared
dependencies. All Shared factories resolved within this scope will
be cached and reused. Context managers are cleaned up when the
SharedContext exits.

Example::

    async with SharedContext():
        async with resolved_dependencies(my_func) as dependencies:
            # Shared dependencies are resolved once and cached here
            ...
        async with resolved_dependencies(my_func) as dependencies:
            # Same Shared instances reused
            ...
    # Shared context managers are cleaned up here
shared_resolvedz7ClassVar[ContextVar[dict[DependencyFactory[Any], Any]]]r    shared_lockz"ClassVar[ContextVar[asyncio.Lock]]r$   shared_stackz$ClassVar[ContextVar[AsyncExitStack]]r%   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   SharedContext.__annotate__V   s      - r   c                	  "   \        4       V n        V P                  P                  4       G R j  xL
  \        P                  P                  / 4      V n        \        P                  P                  \        P                  ! 4       4      V n
        \        P                  P                  V P                  4      V n        V #  L5ir/   )r   _stackr+   r   r    set_resolved_tokenr$   asyncioLock_lock_tokenr%   _stack_token)r'   s   &r   r+   SharedContext.__aenter__V   s     $&kk$$&&&,5599"=(--11',,.A)//33DKK@ 	's   -CB?BCc               (    V ^8  d   QhRRRRRRRR/# )	r   exc_typeztype[BaseException] | None	exc_valuezBaseException | None	tracebackzTracebackType | Noner   Noner   )r   s   "r   r   rA   `   s2     
; 
;,
; (
; (	
;
 

;r   c                	P  "   V P                   P                  WV4      G R j  xL
  \        P                  P	                  V P
                  4       \        P                  P	                  V P                  4       \        P                  P	                  V P                  4       R #  L5ir/   )
rC   	__aexit__r   r%   resetrI   r$   rH   r    rE   )r'   rL   rM   rN   s   &&&&r   rQ   SharedContext.__aexit__`   su      kk##HCCC!!$"3"34  !1!12$$T%9%9:	 	Ds    B&B$BB&)rH   rE   rC   rI   N)r6   r7   r8   r9   r:   r   r    __annotations__r$   r%   r+   rQ   r;   r   r   r   r   r   <   sR    & ISIHE  0:-/HD
,H2<^2LE/L
; 
;r   r   c                    V ^8  d   QhRRRR/# )r   r"   z-Callable[..., AbstractAsyncContextManager[R]]r   r   r   )r   s   "r   r   r   n   s     L LA La Lr   c                    R # r/   r   r"   s   &r   SharedrX   m   s    ILr   c                    V ^8  d   QhRRRR/# )r   r"   z(Callable[..., AbstractContextManager[R]]r   r   r   )r   s   "r   r   r   p   s     G G< G Gr   c                    R # r/   r   rW   s   &r   rX   rX   o   s    DGr   c                    V ^8  d   QhRRRR/# )r   r"   zCallable[..., Awaitable[R]]r   r   r   )r   s   "r   r   r   r   s     : :/ :A :r   c                    R # r/   r   rW   s   &r   rX   rX   q   s    7:r   c                    V ^8  d   QhRRRR/# )r   r"   zCallable[..., R]r   r   r   )r   s   "r   r   r   t   s     / /$ / /r   c                    R # r/   r   rW   s   &r   rX   rX   s   s    ,/r   c                    V ^8  d   QhRRRR/# )r   r"   zDependencyFactory[R]r   r   r   )r   s   "r   r   r   u   s     % %( %Q %r   c                4    \        \        \        V 4      4      # )u:  Declare an app-scoped dependency shared across all calls.

The factory initializes once within a ``SharedContext`` and the value is
reused for all subsequent resolutions. Factories may be:

- A sync function returning a value
- An async function returning a value
- A sync generator (context manager) yielding a value
- An async generator (async context manager) yielding a value

Context managers are cleaned up when the SharedContext exits.
Identity is the factory function — multiple ``Shared(same_factory)``
declarations anywhere resolve to the same cached value.
)r   r   r   rW   s   &r   rX   rX   u   s     77#$$r   )r:   
__future__r   rF   collections.abcr   r   
contextlibr   r   r   contextvarsr   typesr	   typingr
   r   r   r   r   
functionalr   r   introspectionr   r   r   r   rX   r   r   r   <module>ri      s    ? "  / 
 #  9 9 @ 4CL##A& #L.; .;b 
 L 
 L	 G 
 G	 : 
 :	 / 
 /%r   