
    %`i2                     p   d dl Z d dlZd dlmZ d dlmZ d dlmZ dZe j	        
                    dd          dk    at          Ze j	                            ddi           d	Z ej                    ad
t           _        d ZdefdZd Zd Zd Zed             Zed             ZdefdZd Zd Zd Zd ZdS )    N)contextmanagerwraps)auto_init_ray__ray_client_mode_key__RAY_CLIENT_MODE01FTc                  \    t          t          d          sdt          _        t          j        S )zGet's the value of `_client_hook_status_on_thread`.
    Since `_client_hook_status_on_thread` is a thread-local variable, we may
    need to add and set the 'status' attribute.
    statusT)hasattr_client_hook_status_on_threadr        q/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/client_mode_hook.py!_get_client_hook_status_on_threadr      s)     0(;; 4/3%,(//r   valc                     | t           _        d S N)r   r   r   s    r   _set_client_hook_statusr   '   s    +.!(((r   c                  :    t                      } dt          _        | S NF)r   r   r   )outs    r   _disable_client_hookr   ,   s    
+
-
-C+0!(Jr   c                  
    da dS )zkForce client mode to be enabled.
    NOTE: This should not be used in tests, use `enable_client_mode`.
    TNis_client_mode_enabledr   r   r   _explicitly_enable_client_moder   3   s    
 "r   c                  
    da d S r   r   r   r   r   _explicitly_disable_client_moder!   ;   s    "r   c               #   v   K   t                      } 	 d V  t          |            d S # t          |            w xY wr   )r   r   r   s    r   disable_client_hookr#   @   sH      

 
 C%


$$$$$$$$$s   ' 8c               #   r   K   t                       	 d V  t                       d S # t                       w xY wr   )r   r!   r   r   r   enable_client_moder%   I   sE      "$$$*


')))))'))))s   & 6funcc                 L     ddl m t                      fd            }|S )zDecorator for whether to use the 'regular' ray version of a function,
    or the Ray Client version of that function.

    Args:
        func: This function. This is set when this function is used
            as a decorator.
    r   rayc                      t                      r-j        dk    st          r t          j                  | i |S  | i |S )Ninit)client_mode_should_convert__name__!is_client_mode_enabled_by_defaultgetattr)argskwargsr&   r)   s     r   wrapperz!client_mode_hook.<locals>.wrapper]   s_     &'' 	D }&&*K&2wsDM22DCFCCCtT$V$$$r   )ray.util.clientr)   r   )r&   r2   r)   s   ` @r   client_mode_hookr4   R   sM     $#####
4[[
% 
% 
% 
% 
% [
% Nr   c                  :    t           pt          ot                      S )z;Determines if functions should be converted to client mode.)r   r.   r   r   r   r   r,   r,   m   s      	C"C.
+
-
-.r   c                 <     t                      fd            }|S )a  Wraps a function called during client mode for execution as a remote
    task.

    Can be used to implement public features of ray client which do not
    belong in the main ray API (`ray.*`), yet require server-side execution.
    An example is the creation of placement groups:
    `ray.util.placement_group.placement_group()`. When called on the client
    side, this function is wrapped in a task to facilitate interaction with
    the GCS.
    c                      ddl m} t                       t                      rA |                    d                    } |j        | i |}|                    |          S  | i |S )Nr   r(   )num_cpus)r3   r)   r   r,   remoteget)r0   r1   r)   frefr&   s        r   r2   z!client_mode_wrap.<locals>.wrapper   s    '''''' &'' 	 &

A
&&t,,A!(D+F++C773<<tT$V$$$r   r   )r&   r2   s   ` r   client_mode_wrapr=   w   s5     4[[
% 
% 
% 
% [
% Nr   c                    ddl m} t          | t          d          }||                    |          s+|                    |           }t          | t          |           |                    |          } |j        ||fi |S )aX  Runs a preregistered ray RemoteFunction through the ray client.

    The common case for this is to transparently convert that RemoteFunction
    to a ClientRemoteFunction. This happens in circumstances where the
    RemoteFunction is declared early, in a library and only then is Ray used in
    client mode -- necessitating a conversion.
    r   r(   N)	r3   r)   r/   RAY_CLIENT_MODE_ATTR_converted_key_exists_convert_functionsetattr_get_converted_remote)func_clsin_args	in_kwargsr1   r)   keyclient_funcs          r   client_mode_convert_functionrJ      s     $#####
(0$
7
7C 	S66s;;##H--.444$$S))K;w	<<V<<<r   c                    ddl m} t          | t          d          }||                    |          s+|                    |           }t          | t          |           |                    |          } |j        ||fi |S )aN  Runs a preregistered actor class on the ray client

    The common case for this decorator is for instantiating an ActorClass
    transparently as a ClientActorClass. This happens in circumstances where
    the ActorClass is declared early, in a library and only then is Ray used in
    client mode -- necessitating a conversion.
    r   r(   N)	r3   r)   r/   r?   r@   _convert_actorrB   rC   rD   )	actor_clsrF   rG   r1   r)   rH   client_actors          r   client_mode_convert_actorrO      s     $#####
)14
8
8C 	S66s;;  ++	/555%%c**L<==f===r   ) os	threading
contextlibr   	functoolsr   ray._private.auto_init_hookr   r?   environr:   r   r.   updateis_init_calledlocalr   r   r   boolr   r   r   r!   r#   r%   callabler4   r,   r=   rJ   rO   r   r   r   <module>r[      s   				     % % % % % %       5 5 5 5 5 5 1  (93??3F  %; ! 
  $c* + + + !0	 1 1 '+  $0 0 0/ / / / /
  " " "# # #
 % % % * * *8    6. . .  8= = =*> > > > >r   