
    /j                        S SK Jr  S SKrS SKJr  S SKrSSKJr  \/ \R                  4   r	\R                  \	S-     " S5      rS
S jrSS jrSS	 jrg)    )annotationsN)Callable   )loggeragent_http_sessionc                 F   ^ S mSU4S jjn [         R                  U 5        U $ )Nc                   > Tb  TR                   (       aa  [        R                  " S5        SSKJn    U " 5       R
                  R                  n[        R                  " SSS9n[        R                  " XS9mT$ ! [         a    S n N9f = f)Nz-http_session(): creating a new httpclient ctxr   )get_job_context2   x   )limit_per_hostkeepalive_timeout)proxy	connector)closedr   debugjobr
   proc
http_proxyRuntimeErroraiohttpTCPConnectorClientSession)r
   r   r   	g_sessions      R/app/agent/.venv/lib/python3.13/site-packages/livekit/agents/utils/http_context.py_new_session&_new_session_ctx.<locals>._new_session   s    	 0 0LLHI-",.33>>
  ,,!"%I  --JTI   "!
"s   A9 9BBreturnzaiohttp.ClientSession)_ContextVarset)r   r   s    @r   _new_session_ctxr"      s!    .2I& OOL!    c                 V    [         R                  S5      n U c  [        S5      eU " 5       $ )zOptional utility function to avoid having to manually manage an aiohttp.ClientSession lifetime.
On job processes, this http session will be bound to the main event loop.
Na  Attempted to use an http session outside of a job context. This is probably because you are trying to use a plugin without using the agent worker api. You may need to create your own aiohttp.ClientSession, pass it into the plugin constructor as a kwarg, and manage its lifecycle.)r    getr   vals    r   http_sessionr(   (   s3    
 //$
C
{ f
 	
 5Lr#   c                    #    [         R                  S 5      n U bI  [        R                  " S5        U " 5       R	                  5       I S h  vN   [         R                  S 5        g g  N7f)Nz*http_session(): closing the httpclient ctx)r    r%   r   r   closer!   r&   s    r   _close_http_ctxr+   6   sJ     
//$
C
ABekkm s   AA'	A%
A')r   _ClientFactoryr   )r   None)
__future__r   contextvarscollections.abcr   r   logr   r   r,   
ContextVarr    r"   r(   r+    r#   r   <module>r4      sS    "  $  "g3334$$^d%:;<PQ4r#   