
    ci;                        U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ 	 d dlZej>                  j@                  jB                  Z!	 d dl#Z#e#jH                  jJ                  Z%	 ejN                  Z(ee)   e*d<   	 ejV                  Z,e-e*d	<   	  ej\                         Z/ee)ee)   f   e*d
<   	 d dl0m1Z1 e1jd                  Z3	 d dl4m5Z5 e5jl                  Z7	 d dl8Z8e8jr                  Z9e	e)ef   Z: G d de      Z; G d de      Z< G d de      Z= ej|                  d      Z? e@e( eAe,      z         ZB e-ddg      ZCdZDdZEdZFdZGdZHdZI	 dPdee:ej                  f   deej                     dej                  fdZKdej                  de:fd ZLdede:fd!ZMde7de:fd"ZNdee3e7f   de:fd#ZOd$ej                  de
e   fd%ZQd&ee)   dee)d'f   fd(ZRe?fded)ee)   d*ej|                  dee)e)f   fd+ZSdd,d)ee)e)f   d&eee)   ee)d'f   f   d-eee)      dee)ee)ef   f   fd.ZT	 	 	 dQded/eee)      d0eee)ee)   f      d1eee)ef      dee)e)f   f
d2ZUd3ej                  deWfd4ZXdi g d5d6ed7ef   d8ee)   d9ee)e)f   d:ee)   de:f
d;ZYdeWfd<ZZd=e9de	e)ef   fd>Z[dej                  fd?Z]dej                  fd@Z^dej                  fdAZ_dej                  fdBZ`dej                  fdCZadeej                     fdDZbdeej                     fdEZcdeej                     fdFZddeej                     fdGZedeej                     fdHZfdeej                     fdIZgdeej                     fdJZhdKee)   dLee)   fdMZidNeje)e)f   ddfdOZky# e"$ r eZ!Y Cw xY w# e&$ r eZ%Y 6w xY w# e&$ r g Z(ee)   e*d<   Y 7w xY w# e&$ r  e-       Z,e-e*d	<   Y =w xY w# e&$ r i Z/ee)ee)   f   e*d
<   Y 9w xY w# e"$ r eZ3Y 4w xY w# e"$ r eZ7Y /w xY w# e"$ r eZ9Y ,w xY w)R    N)AnyCallableDictIterableListMappingOptionalSequenceSet	TypedDictUnion)metadata)base)httpbody_pb2)
struct_pb2)json_format_BUILTIN_MODULE_NAMES_STDLIB_MODULE_NAMES_PACKAGE_DISTRIBUTIONS)chat)run_responsec                       e Zd ZU ee   ed<   y)_RequirementsValidationActionsappendN__name__
__module____qualname__r   str__annotations__     D/tmp/pip-target-z3e9_cxr/lib/python/vertexai/agent_engines/_utils.pyr   r   i   s    Hr"   r   c                   .    e Zd ZU ee   ed<   ee   ed<   y)_RequirementsValidationWarningsmissingincompatibleNr   r!   r"   r#   r%   r%   m   s    Xc(r"   r%   c                   "    e Zd ZU eed<   eed<   y)_RequirementsValidationResultwarningsactionsN)r   r   r   r%   r    r   r!   r"   r#   r)   r)   r   s    --++r"   r)   zvertexai.agent_enginescloudpicklepydanticr+   r   r*   r&   r'   installation_scriptsobjmessagereturnc                    |t        j                         }t        | t        j                  t         j                  f      r| S 	 t        j                  | |j                         |S # t        $ r t        j                  | |       Y |S w xY w)a<  Parses a JSON-like object into a message.

    If the object is already a message, this will return the object as-is. If
    the object is a JSON Dict, this will parse and merge the object into the
    message.

    Args:
        obj (Union[dict[str, Any], proto.Message]):
            Required. The object to convert to a proto message.
        message (proto.Message):
            Optional. A protocol buffer message to merge the obj into. It
            defaults to Struct() if unspecified.

    Returns:
        proto.Message: The same message passed as argument.
    )	r   Struct
isinstanceprotoMessager   	ParseDict_pbAttributeError)r/   r0   s     r#   to_protor:      s{    ( ##%#z'8'89:
,c7;;/ N  ,c7+N,s    A& &B	B	c                     	 t        j                  t        j                  | j                  d            }|S # t
        $ r. t        j                  t        j                  | d            }Y |S w xY w)a  Converts the contents of the protobuf message to JSON format.

    Args:
        message (proto.Message):
            Required. The proto message to be converted to a JSON dictionary.

    Returns:
        dict[str, Any]: A dictionary containing the contents of the proto.
    T)preserving_proto_field_name)jsonloadsr   MessageToJsonr8   r9   )r0   results     r#   to_dictrA      sn    
::%%,0
 M  
::%%,0
 M
s   48 3A/.A/c                     t        j                  |       st        d|        t        j                  t        j
                  t        j                  |                   S )a6  Converts a dataclass to a JSON dictionary.

    Args:
        obj (Any):
            Required. The dataclass to be converted to a JSON dictionary.

    Returns:
        dict[str, Any]: A dictionary containing the contents of the dataclass.

    Raises:
        TypeError: If the object is not a dataclass.
    zObject is not a dataclass: )dataclassesis_dataclass	TypeErrorr=   r>   dumpsasdictr/   s    r#   _dataclass_to_dict_or_raiserI      sH     ##C(5cU;<<::djj!3!3C!89::r"   c                 :   t        | d      r| j                          d}t        | dd      /t        | j                  dd      t        | j                  dd      d}d}t        | dd      Yt        | j                  d      r.t        j                  | j                  j                               }nt        | j                        }t        | d	d      t        t        | d
g             t        | dd      ||d}t        j                  t        j                  |            S )a  Converts an AutogenRunResponse object into a JSON-serializable dictionary.

    This function takes a `RunResponseProtocol` object and transforms its
    relevant attributes into a dictionary format suitable for JSON conversion.

    The `RunResponseProtocol` defines the structure of the response object,
    which typically includes:

    *   **summary** (`Optional[str]`):
        A textual summary of the run.
    *   **messages** (`Iterable[Message]`):
        A sequence of messages exchanged during the run.
        Each message is expected to be a JSON-serializable dictionary (`Dict[str,
        Any]`).
    *   **events** (`Iterable[BaseEvent]`):
        A sequence of events that occurred during the run.
        Note: The `process()` method, if present, is called before conversion,
        which typically clears this event queue.
    *   **context_variables** (`Optional[dict[str, Any]]`):
        A dictionary containing contextual variables from the run.
    *   **last_speaker** (`Optional[Agent]`):
        The agent that produced the last message.
        The `Agent` object has attributes like `name` (Optional[str]) and
        `description` (Optional[str]).
    *   **cost** (`Optional[Cost]`):
        Information about the computational cost of the run.
        The `Cost` object inherits from `pydantic.BaseModel` and is converted
        to JSON using its `model_dump_json()` method.
    *   **process** (`Optional[Callable[[], None]]`):
        An optional function (like a console event processor) that is called
        before the conversion takes place.
        Executing this method often clears the `events` queue.

    For a detailed definition of `RunResponseProtocol` and its components, refer
    to: https://github.com/ag2ai/ag2/blob/main/autogen/io/run_response.py

    Args:
        obj (AutogenRunResponse): The AutogenRunResponse object to convert. This
            object must conform to the `RunResponseProtocol`.

    Returns:
        JsonDict: A dictionary representation of the AutogenRunResponse, ready
            to be serialized into JSON. The dictionary includes keys like
            'summary', 'messages', 'context_variables', 'last_speaker_name',
            and 'cost'.
    processNlast_speakernamedescription)rM   rN   costmodel_dump_jsonsummarymessagescontext_variables)rQ   rR   rS   rL   rO   )hasattrrK   getattrrL   rO   r=   r>   rP   r   listrF   )r/   rL   rO   r@   s       r#   &_autogen_run_response_protocol_to_dictrW      s    b sILsND)5C,,fd;"3#3#3]DI

 DsFD!-388./::chh6689Dsxx=D 3	40j"56$S*=tD$F ::djj())r"   c                 N    t        | t              rt        |       S t        |       S )a  Converts an Autogen object to a JSON serializable object.

    In `ag2<=0.8.4`, `.run()` will return a `ChatResult` object.
    In `ag2>=0.8.5`, `.run()` will return a `RunResponse` object.

    Args:
        obj (Union[AutogenChatResult, AutogenRunResponse]):
            Required. The Autogen object to be converted to a JSON serializable
            object.

    Returns:
        JsonDict: A JSON serializable object.
    )r4   AutogenChatResultrI   rW   rH   s    r#   #to_json_serializable_autogen_objectrZ     s%    & #()*3//1#66r"   bodyc              #     K   t        | dd      }t        | dd      }||d|vr|  y	 |j                  d      }|sd y|j                  d      D ]  }|s	 t        j                  |      }| ! y# t        $ r)}t        j	                  d| d|        |  Y d}~yd}~ww xY w# t        $ r%}t        j	                  d	| d|        Y d}~ed}~ww xY ww)
a  Converts the contents of the httpbody message to JSON format.

    Args:
        body (httpbody_pb2.HttpBody):
            Required. The httpbody body to be converted to a JSON.

    Yields:
        Any: A JSON object or the original body if it is not JSON or None.
    content_typeNdatazapplication/jsonzutf-8zFailed to decode data: . Exception: 
zfailed to parse json: )rU   decode	ExceptionLOGGERwarningsplitr=   r>   )r[   r]   r^   	utf8_dataelines         r#   yield_parsed_jsonri   4  s      46L4&Dt|/A/U
KK(	 
 % Pzz$' J  0mA3GH
  P!7v]1#NOOPsW   (CA7 CB,0C7	B) B$C$B))C,	C5CCCCconstraintsSpecifierSetc                 L   t               }i }| D ]a  }	 |j                  d      rt        j                  j	                  |      }|j                  |      }|j                  xs d||j                  <   c |S # t        $ r%}t        j                  d| d|        Y d}~d}~ww xY w)aA  Parses a list of constraints into a dict of requirements.

    Args:
        constraints (list[str]):
            Required. The list of package requirements to parse. This is assumed
            to come from the `requirements.txt` file.

    Returns:
        dict[str, SpecifierSet]: The specifiers for each package.
    z.whlzFailed to parse constraint: r_   N)'_import_packaging_requirements_or_raiseendswithospathbasenameRequirementrb   rc   rd   	specifierrM   )rj   requirementsr@   
constraintrequirementrg   s         r#   parse_constraintsrw   Z  s     ;<LF! A
	""6*WW--j9
&22:>K $/#8#8#@D{ A M	  	NN9*]STRUVW	s   AA55	B#>BB#rt   loggerc                 B   |j                         }	 t        |       }|j                  d|        t        |      }t	        ||      }|j                  t        i       j                         D ]  \  }}|s	|j                  d| d|        ! |j                  t        i       j                         D ]>  \  }}	|	s	|t        k(  s|	D ]  }
|j                  |
        |j                  d|	        @ 	 |S # t        $ r}|j                  d|        Y d}~|S d}~ww xY w)z6Compiles the requirements into a list of requirements.z'Identified the following requirements: zThe following requirements are z: z)The following requirements are appended: z Failed to compile requirements: N)copyscan_requirementsinforw   compare_requirementsget_WARNINGS_KEYitemsrd   _ACTIONS_KEY_ACTION_APPENDr   rb   )r/   rt   rx   current_requirementsrj   missing_requirementswarning_typer*   action_typer+   actionrg   s               r#   validate_requirements_or_warnr   u  s<     $$&L?05=>R=STU'534H+V&:&>&>2'

%'	"L( 5l^2hZP		 %9$<$<\2$N$T$T$V 	S K;.8% 0F ''/0GyQR		S   ?9!=>>?s+   A"C6 5AC6 ;	C6 .C6 6	D?DD)required_packagesr   c          
      <   t               }|t        }t        t        t	               t	                     t        t	                           }t        |t              rt        |      }| j                         D ]  \  }}||vrH|t           t           j                  |       ||v r$|t           t           j                  | d|        R|sU||   }|s]|j                  |      |vsq|t           t            j                  | d| dt#        |       d        |S )a  Compares the requirements with the constraints.

    Args:
        requirements (Mapping[str, str]):
            Required. The packages (and their versions) to compare with the constraints.
            This is assumed to be the result of `scan_requirements`.
        constraints (Union[Sequence[str], Mapping[str, SpecifierSet]]):
            Required. The package constraints to compare against. This is assumed
            to be the result of `parse_constraints`.
        required_packages (Sequence[str]):
            Optional. The set of packages that are required to be in the
            constraints. It defaults to the set of packages that are required
            for deployment on Agent Engine.

    Returns:
        dict[str, dict[str, Any]]: The comparison result as a dictionary containing:
            * warnings:
                * missing: The set of packages that are not in the constraints.
                * incompatible: The set of packages that are in the constraints
                    but have versions that are not in the constraint specifier.
            * actions:
                * append: The set of packages that are not in the constraints
                    but should be appended to the constraints.
    )r&   r'   )r   )r*   r+   z==z (required: ))"_import_packaging_version_or_raise_DEFAULT_REQUIRED_PACKAGESr)   r%   setr   r4   rV   rw   r   r   _WARNING_MISSINGaddr   r   Version_WARNING_INCOMPATIBLEr   )rt   rj   r   packaging_versionr@   packagepackage_versionpackage_specifiers           r#   r}   r}     s+   < ;< 6*0SUS.ce<F +t$'4$0$6$6$8  +%=!"2377@++|$^488ir/!23  +G 4$ ((9ARR}%&;<@@ir/!2,sCT?U>VVWX  Mr"   ignore_modulespackage_distributionsinspect_getmembers_kwargsc                    |t         }|t        }t        t              }|xs i }t	        j
                  | fi |D ]{  \  }}|r!t	        j                  |      st        |d      s*|j                  xs dj                  d      d   }|sO||vsT|j                  |g       D ]  }|j                  |        } |D ci c]  }|t        j                  |       c}S c c}w )a  Scans the object for modules and returns the requirements discovered.

    This is not a comprehensive scan of the object, and only detects for common
    cases based on the members of the object returned by `dir(obj)`.

    Args:
        obj (Any):
            Required. The object to scan for package requirements.
        ignore_modules (Sequence[str]):
            Optional. The set of modules to ignore. It defaults to the set of
            built-in and stdlib modules.
        package_distributions (Mapping[str, Sequence[str]]):
            Optional. The mapping of module names to the set of packages that
            contain them. It defaults to the set of packages from
            `importlib_metadata.packages_distributions()`.
        inspect_getmembers_kwargs (Mapping[str, Any]):
            Optional. The keyword arguments to pass to `inspect.getmembers`. It
            defaults to an empty dictionary.

    Returns:
        Sequence[str]: The list of requirements that were discovered.
    r    .r   )_BASE_MODULESr   r   r   inspect
getmembers	isbuiltinrT   r   re   r~   r   importlib_metadataversion)	r/   r   r   r   modules_found_attrmodule_namemodules	            r#   r{   r{     s    8 &$ 623M 9 ?R%%cG-FG *4w((.gdL6Q,"33C8;;n</33KD *!!&)** FSS6F&..v66SSSs   >Cparamc                     | j                   t        j                  j                  k(  ryt	        | j                   t
              ryt               }	  |j                  | j                          y# t        $ r Y yw xY w)z1Checks if the parameter is pydantic serializable.TF)	
annotationr   	Parameteremptyr4   r   _import_pydantic_or_raiseTypeAdapterrb   )r   r-   s     r#   _is_pydantic_serializabler     sl     7,,222%""C((*HU--. s   A, ,	A87A8)schema_namedescriptionsrequiredf.r   r   r   c                   t               }t        t        j                  |       j                        }|j                         D ci c]  \  }}|j                  t        j                  j                  t        j                  j                  t        j                  j                  fv rht        |      r]||j                  t        j                  j                  k7  r|j                  nt         |j                  |j!                  |d            f }}} |j"                  | j$                  fi |j'                         }	|	j)                  dd       |	j!                  di       j                         D ]  \  }}
|
j)                  dd       ||   j                  }t+        j,                  |      t.        u sCt1        d      t+        j2                  |      v sd|
j)                  dg       D ]"  }|j!                  d      }|s|dk7  s||
d<    n d	|
d
<    |r||	d<   n|D cg c]  }||   j4                  t        j                  j                  k(  r^||   j                  t        j                  j                  t        j                  j                  t        j                  j                  fv r| c}|	d<   t        | j$                  | j6                  |	      }|r||d<   |S c c}}w c c}w )a/  Generates the OpenAPI Schema for a callable object.

    Only positional and keyword arguments of the function `f` will be supported
    in the OpenAPI Schema that is generated. I.e. `*args` and `**kwargs` will
    not be present in the OpenAPI schema returned from this function. For those
    cases, you can either include it in the docstring for `f`, or modify the
    OpenAPI schema returned from this function to include additional arguments.

    Args:
        f (Callable):
            Required. The function to generate an OpenAPI Schema for.
        schema_name (str):
            Optional. The name for the OpenAPI schema. If unspecified, the name
            of the Callable will be used.
        descriptions (Mapping[str, str]):
            Optional. A `{name: description}` mapping for annotating input
            arguments of the function with user-provided descriptions. It
            defaults to an empty dictionary (i.e. there will not be any
            description for any of the inputs).
        required (Sequence[str]):
            Optional. For the user to specify the set of required arguments in
            function calls to `f`. If specified, it will be automatically
            inferred from `f`.

    Returns:
        dict[str, Any]: The OpenAPI Schema for the function `f` in JSON format.
    N)rN   titler   
propertiesanyOftypenullTnullabler   )rM   rN   
parametersrM   )r   dictr   	signaturer   r   kindr   POSITIONAL_OR_KEYWORDKEYWORD_ONLYPOSITIONAL_ONLYr   r   r   r   Fieldr~   create_modelr   schemapoptyping
get_originr   r   get_argsdefault__doc__)r   r   r   r   r-   defaultsrM   r   fields_dictr   function_argr   r   schema_typeks                  r#   generate_schemar     s   D )*HG%%a(334H  $>>+ D%::33**--

 &e,- 	 "'!1!1W5F5F5L5L!LURUHNN ),,T48	
 	
K 2 '&&qzzA[AHHJJ
 NN7B(nn\2>DDF ,l"%d^..

 Z(E1d4jFOOE
 7
 '**7B7 $jj0;&#8+6L(	
 (,L$',* !)
:
 "
##w'8'8'>'>>QK$$%%;;%%22%%55	 "

: qzzqyyZPF$vMSr"
s   CKBK%c                     t               }|j                  j                  }|j                  j                  }t	        | ||f      S )z5Returns True if the tracer_provider is Proxy or NoOp.)_import_opentelemetry_or_warntraceProxyTracerProviderNoOpTracerProviderr4   )tracer_provideropentelemetryr   r   s       r#    is_noop_or_proxy_tracer_providerr   x  sB    13M'--AA&,,??o(:<O'PQQr"   eventc                 L    t        j                  | j                  d            S )z5Dumps an ADK event to a JSON-serializable dictionary.T)exclude_none)r=   r>   rP   )r   s    r#   dump_event_for_jsonr     s    ::e+++>??r"   c                  N    	 ddl m}  | S # t        $ r}t        d      |d}~ww xY w)z)Tries to import the Cloud Storage module.r   )storagezaCloud Storage is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.N)google.cloudr   ImportError)r   rg   s     r#   _import_cloud_storage_or_raiser     s;    ( N  D
 	   
 	$$c                  J    	 ddl } | S # t        $ r}t        d      |d}~ww xY w)z'Tries to import the cloudpickle module.r   Nz_cloudpickle is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.)r,   r   )r,   rg   s     r#   _import_cloudpickle_or_raiser     s<       D
 	s    	""c                      	 ddl } | j                  }| S # t        $ r
 ddl m}  Y | S t        $ r}t	        d      |d}~ww xY w)z$Tries to import the pydantic module.r   N)v1z\pydantic is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.)r-   r   r9   r   r   )r-   r   rg   s      r#   r   r     sX    
NN O  ,+ O  D
 	s    ??:?c                  N    	 ddl m}  | S # t        $ r}t        d      |d}~ww xY w)2Tries to import the packaging.requirements module.r   )rt   zjpackaging.requirements is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.N)	packagingrt   r   )rt   rg   s     r#   rm   rm     s<    *   D
 	r   c                  N    	 ddl m}  | S # t        $ r}t        d      |d}~ww xY w)r   r   )r   zepackaging.version is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.N)r   r   r   )r   rg   s     r#   r   r     s;    % N  D
 	r   c                  X    	 ddl } | S # t        $ r t        j                  d       Y yw xY w)z)Tries to import the opentelemetry module.r   Neopentelemetry-sdk is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.)r   r   rc   rd   r   s    r#   r   r     s6    
 
D	
 
s    ))c                      	 ddl } | j                  j                  S # t        $ r t        j                  d       Y yw xY w)z3Tries to import the opentelemetry.sdk.trace module.r   Nr   )opentelemetry.sdk.tracesdkr   r   rc   rd   r   s    r#   '_import_opentelemetry_sdk_trace_or_warnr     sB    
&  &&& 
D	
 
    ==c                      	 ddl } | j                  j                  S # t        $ r t        j                  d       Y yw xY w)z1Tries to import the google.cloud.trace_v2 module.r   Nzfgoogle-cloud-trace is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.)google.cloud.trace_v2cloudtrace_v2r   rc   rd   )googles    r#   _import_cloud_trace_v2_or_warnr     s@    
$||$$$ 
D	
 
r   c                      	 ddl } | j                  j                  S # t        $ r t        j                  d       Y yw xY w)z>Tries to import the opentelemetry.exporter.cloud_trace module.r   Nztopentelemetry-exporter-gcp-trace is not installed. Please call 'pip install google-cloud-aiplatform[agent_engines]'.)"opentelemetry.exporter.cloud_traceexportercloud_tracer   rc   rd   r   s    r#   $_import_cloud_trace_exporter_or_warnr     sB    
1%%111 
I	
 
r   c                      	 ddl } | j                  j                  S # t        $ r t        j                  d       Y yw xY w)zCTries to import the openinference.instrumentation.langchain module.r   Nzwopeninference-instrumentation-langchain is not installed. Please call 'pip install google-cloud-aiplatform[langchain]'.)'openinference.instrumentation.langchaininstrumentation	langchainr   rc   rd   openinferences    r#   '_import_openinference_langchain_or_warnr    sB    
6,,666 
E	
 
r   c                      	 ddl } | j                  j                  S # t        $ r t        j                  d       Y yw xY w)zATries to import the openinference.instrumentation.autogen module.r   Nzoopeninference-instrumentation-autogen is not installed. Please call 'pip install google-cloud-aiplatform[ag2]'.)%openinference.instrumentation.autogenr   autogenr   rc   rd   r  s    r#   %_import_openinference_autogen_or_warnr    sA    
4,,444 
?	
 
r   c                  \    	 ddl m}  | S # t        $ r t        j	                  d       Y yw xY w)z)Tries to import the autogen.tools module.r   toolszWautogen.tools is not installed. Please call `pip install google-cloud-aiplatform[ag2]`.N)r  r  r   rc   rd   r
  s    r#   _import_autogen_tools_or_warnr    s4    
! 
?	
 
s   
 ++script_pathsextra_packagesc           
         | D ]  }|j                  t              s=t        j                  d| dt         dt         d       t	        d| dt         d      ||vsZt        j                  d| d       t	        d| d	       |D ]D  }|j                  t              s|| vst        j                  d
| d       t	        d
| d       y)a2  Validates the installation scripts' path explicitly provided by the user.

    Args:
        script_paths (Sequence[str]):
            Required. The paths to the installation scripts.
        extra_packages (Sequence[str]):
            Required. The extra packages to be updated.

    Raises:
        ValueError: If a user-defined script is not under the expected
            subdirectory, or not in `extra_packages`, or if an extra package is
            in the installation scripts subdirectory, but is not specified as an
            installation script.
    z"User-defined installation script 'z' is not in the expected 'z(' subdirectory. Ensure it is placed in 'z' within your `extra_packages`.zRequired installation script 'z' is not under ''zC' is not in extra_packages. Ensure it is added to `extra_packages`.z$' does not exist in `extra_packages`zExtra package 'z' is in the installation scripts subdirectory, but is not specified as an installation script in `build_options`. Ensure it is added to installation_scripts for automatic execution.zq' is in the installation scripts subdirectory, but is not specified as an installation script in `build_options`.N)
startswith_INSTALLATION_SUBDIRrc   rd   
ValueError)r  r  script_pathextra_packages       r#   &validate_installation_scripts_or_raiser  '  s4   $ $ %%&:;NN4[M B!!5 6 7++?*@ A$% 0 >!!5 6a9 
 n,NN4[M BJ K 4[M B5 6 %. ( $$%9:\1NN!- 1' ' !- 1- - " r"   resource_limitsc                    t        | t              st        dt        |              d| vsd| vrt	        d      t        | d         }| d   }|dvrt        d|       t        |t              r|j                  d      st        d|       	 t        |d	d
       }|dkD  rt        d| d      |dkD  rd}n|dkD  rd}n|dkD  rd}n
|dkD  rd}nd}||k  rt        d| d| d|       y	# t        $ r t        d| d      w xY w)ay  Validates the resource limits.

    Checks that the resource limits are a dict with 'cpu' and 'memory' keys.
    Checks that the 'cpu' value is one of 1, 2, 4, 6, 8.
    Checks that the 'memory' value is a string ending with 'Gi'.
    Checks that the memory size is smaller than 32Gi.
    Checks that the memory size requires at least the specified number of CPUs.

    Args:
        resource_limits: The resource limits to be validated.

    Raises:
        TypeError: If the resource limits are not a dict.
        KeyError: If the resource limits do not contain 'cpu' and 'memory' keys.
        ValueError: If the 'cpu' value is not one of 1, 2, 4, 6, 8.
        ValueError: If the 'memory' value is not a string ending with 'Gi'.
        ValueError: If the memory size is too large.
        ValueError: If the memory size requires more CPUs than the specified
        'cpu' value.
    z$resource_limits must be a dict. Got cpumemoryz5resource_limits must contain 'cpu' and 'memory' keys.)               z9resource_limits['cpu'] must be one of 1, 2, 4, 6, 8. Got GizAresource_limits['memory'] must be a string ending with 'Gi'. Got NzInvalid memory value: z&. Must be an integer followed by 'Gi'.    zMemory size of z) is too large. Must be smaller than 32Gi.   r     r  r  r  r  z requires at least z CPUs. Got )	r4   r   rE   r   KeyErrorintr  r   rn   )r  r  
memory_str	memory_gbmin_cpus        r#   "_validate_resource_limits_or_raiser*  d  s   * ot,>tO?T>UVWWO#x'FNOO
oe$
%C *J
/!J3%P
 	
 j#&j.A.A$.G<!
 	



3B(	 2~j\)RS
 	
 2~	R	Q	Q
W}j\)<WI F5
 	
 -  
$ZL 1! !
 	

s   C. .D)N)NNN)lrC   r   r=   ro   systypesr   r   r   r   r   r   r   r	   r
   r   r   r   	importlibr   r   r5   google.cloud.aiplatformr   
google.apir   google.protobufr   r   langchain_core.runnables.configlangchain_core	runnablesconfigRunnableConfigr   r   
specifiersrk   r9   builtin_module_namesr   r   r    stdlib_module_namesr   	frozensetpackages_distributionsr   autogen.agentchatr   
ChatResultrY   
autogen.ior   RunResponseAutogenRunResponser-   	BaseModelJsonDictr   r%   r)   Loggerrc   r   tupler   r   r   r   r   r   r   r  r6   r:   rA   rI   rW   rZ   HttpBodyri   rw   r   r}   r{   r   boolr   r   r   r   
ModuleTyper   r   r   rm   r   r   r   r   r   r  r  r  r  r   r*  r!   r"   r#   <module>rG     s_       	 
      5  ( # & ' +#--44CCN''44L.+.+C+C8C=C2&)&=&=)==1113 GC#$67 &'%11""I S>Y i 
,I ,
 
-	.)E2F,GGH&z'BC  & - 
 (,	x&	'emm$ ]]>U]] x 8;S ;X ;$I*	I*I*X7		
7
 70#L11 #hsm #L#S. !< !	s) KK S#X	B 26	7#s(#7x}gc>.A&BBC7  .	7
 S'#s(##$7x /3CG=A	)T	)TXc]+)T $GC#,>$?@)T  (S(9:	)T
 S#X)TXW%6%6 4 & "&&( mSm #m #s(#	m
 smm m`R R@y @T#s(^ @
	(8(8 		e&6&6 	5#3#3  	1A1A 		E,<,< 	x0@0@'A %:J:J1K 1A1A(B hu7G7G.H %:J:J1K x8H8H/I x0@0@'A :3-:SM:zD
S#X D
4 D
a  N  L
  .+-8C=-.  2&/k)12  =:<GC#$67<=      Is   $N8  O O 0O* P !P 4P+ P9 8OOOOO'&O'*O?>O?PPP('P(+P65P69QQ