
    &`i$                         d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ  e j        e          Z ed
          Z ed          Z G d dee	eef                   Z ed           G d d                      Zdede defdZ!dddddddede dee          deeeef                  deee ef                  deeee gef                  de"defdZ#dd dede d!eee f         d"eeef         deee ef                  deee gef         de
e         fd#Z$d$edeee ef                  defd%Z%ded!eee f         de fd&Z&dS )'    N)deepcopy)	dataclass)AnyCallableDictGenericListOptionalTypeVarUnion)_PyObjScanner)SERVE_LOGGER_NAME)Application
Deployment)DeploymentHandle)LoggingConfigKVc                   `     e Zd ZdZdedef fdZdedef fdZdef fdZde	f fdZ
 xZS )	IDDictzDictionary that uses id() for keys instead of hash().

    This is necessary because Application objects aren't hashable and we want each
    instance to map to a unique key.
    keyreturnc                     t          |t                    st          |          }t                                          |          S N)
isinstanceintidsuper__getitem__selfr   	__class__s     p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/_private/build_app.pyr   zIDDict.__getitem__   8    #s## 	S''Cww""3'''    valuec                     t          |t                    st          |          }t                                          ||          S r   )r   r   r   r   __setitem__)r!   r   r&   r"   s      r#   r(   zIDDict.__setitem__   s:    #s## 	S''Cww""3...r%   c                     t          |t                    st          |          }t                                          |          S r   )r   r   r   r   __delitem__r    s     r#   r*   zIDDict.__delitem__#   r$   r%   c                     t          |t                    st          |          }t                                          |          S r   )r   r   r   r   __contains__r    s     r#   r,   zIDDict.__contains__(   s8    #s## 	S''Cww##C(((r%   )__name__
__module____qualname____doc__r   r   r   r(   r*   objectr,   __classcell__)r"   s   @r#   r   r      s         (q (Q ( ( ( ( ( (
/q / / / / / / /
(q ( ( ( ( ( (
) ) ) ) ) ) ) ) ) ) )r%   r   T)frozenc                       e Zd ZU eed<   ee         ed<   ee         ed<   eed<   ee         ed<   e	ee
f         ed<   eed<   dS )	BuiltApplicationnameroute_prefixlogging_configingress_deployment_namedeploymentsdeployment_handlesexternal_scaler_enabledN)r-   r.   r/   str__annotations__r
   r   r	   r   r   r   bool r%   r#   r5   r5   .   s          III3-]++++ !   j!!!! S"223333!!!!!!r%   r5   
deploymentapp_namer   c                 .    t          | j        |          S )N)rB   )r   r6   )rA   rB   s     r#   _make_deployment_handle_defaultrD   ?   s#        r%   F)r7   r8   default_runtime_envmake_deployment_handler<   appr6   r7   r8   rE   rF   r<   c          
         	 |t           }t                      }t                      	t          | ||	||          }t          |||| j        j        |	fd|                                D             |          S )a  Builds the application into a list of finalized deployments.

    The following transformations are made:
        - Application objects in constructor args/kwargs are converted to
          DeploymentHandles for injection at runtime.
        - Name conflicts from deployments that use the same class are handled
          by appending a monotonically increasing suffix (e.g., SomeClass_1).

    Returns: BuiltApplication
    N)rB   handlesdeployment_namesrE   rF   c                 (    i | ]\  }}|         |S r@   r@   ).0rG   handlerJ   s      r#   
<dictcomp>zbuild_app.<locals>.<dictcomp>q   s2     
 
 
.9c6S!6
 
 
r%   )r6   r7   r8   r9   r:   r;   r<   )rD   r   _build_app_recursiver5   _bound_deploymentr6   items)
rG   r6   r7   r8   rE   rF   r<   rI   r:   rJ   s
            @r#   	build_apprR   H   s    , %!@hhGxx&)/5  K !% # 5 :
 
 
 
=D]]__
 
 
 !8
 
 
 
r%   )rE   rJ   rI   c                   | |v rg S g }t          t                    }	 |                    | j        j        | j        j        f          }|D ]*}	|                    t          |	|||||                     +|                    |          \  }
}| j        	                    t          | |          |
|          }t          ||          } |||          || <   ||gz   |                                 S # |                                 w xY w)aN  Recursively traverses the graph of Application objects.

    Each Application will have an associated DeploymentHandle created that will replace
    it in any occurrences in other Applications' args or kwargs.

    Also collects a list of the unique Applications encountered and returns them as
    deployable Deployment objects.
    )source_type)rB   rI   rJ   rF   rE   )r6   
_init_args_init_kwargs)r   r   
find_nodesrP   	init_argsinit_kwargsextendrO   replace_nodesoptions$_get_unique_deployment_name_memoized_set_default_runtime_envclear)rG   rB   rJ   rI   rE   rF   r:   scanner
child_apps	child_appnew_init_argsnew_init_kwargsfinal_deployments                r#   rO   rO   x   sX   ( g~~	K444G%''",c.C.OP
 

 $ 
	 
	I$%#%5+A(;  	 	 	 	 *1)>)>w)G)G&0885c;KLL$( 9 
 

 41
 
 .-
 

 .//s   B?C3 3D	dc                     |s| S t          | j        pi           }|                    dd          }d|vr||d<   n||d                             d|           |                     |          S )ah  Configures the deployment with the provided default runtime_env.

    If the deployment does not have a runtime_env configured, the default will be set.

    If it does have a runtime_env configured but that runtime_env does not have a
    working_dir, only the working_dir field will be set.

    Else the deployment's runtime_env will be left untouched.
    working_dirNruntime_env)ray_actor_options)r   rj   get
setdefaultr\   )rf   rE   rj   default_working_dirs       r#   r^   r^      s       !4!:;;-11-FF---+>-((		(-(33MCVWWW99'89999r%   c                 *   | |v r||          S d}| j         j        }||                                v r,| j         j         d| }|dz  }||                                v ,|dk    r+t                              d| j         j         d| d           ||| <   |S )a  Generates a name for the deployment.

    This is used to handle collisions when the user does not specify a name
    explicitly, so typically we'd use the class name as the default.

    In that case, we append a monotonically increasing suffix to the name, e.g.,
    Deployment, then Deployment_1, then Deployment_2, ...

    Names are memoized in the `deployment_names` dict, which should be passed to
    subsequent calls to this function.
       _z3There are multiple deployments with the same name 'z'. Renaming one to 'z'.)rP   r6   valuesloggerwarning)rG   rJ   idxr6   s       r#   r]   r]      s     $$
C %D
"))++
+
+',44s44q "))++
+
+ axxI%*I I@DI I I	
 	
 	

 !SKr%   )'loggingcopyr   dataclassesr   typingr   r   r   r   r	   r
   r   r   ray.dag.py_obj_scannerr   ray.serve._private.constantsr   ray.serve.deploymentr   r   ray.serve.handler   ray.serve.schemar   	getLoggerrr   r   r   dictr   r5   r=   rD   r?   rR   rO   r^   r]   r@   r%   r#   <module>r      sm          ! ! ! ! ! ! O O O O O O O O O O O O O O O O O O O O 0 0 0 0 0 0 : : : : : : 8 8 8 8 8 8 8 8 - - - - - - * * * * * *		,	-	-GCLLGCLL) ) ) ) )T71a4= ) ) )8 $" " " " " " " " &)    #';?48 	$)- - -	- - 3-	-
 U4#678- "$sCx.1- %*c"$445- "- - - - -l 59> > >	> > [#-.	>
 K!112> "$sCx.1> %j#%68H%HI> 
*> > > >B::(0c3h(@:: : : :2	(.{C/?(@     r%   