
    Cj@                         % S SK JrJrJrJrJr  S SKJr  S SKrS SK	J
r
  S SKJr  \" 1 Sk5      r\\S'   Sr\\S	'    " S
 S5      r " S S5      rg)    )DictListMappingOptionalUnion)parse_qsN)verbose_logger)PASS_THROUGH_HEADER_PREFIX>   hostauthorizationapi-key	x-api-keycontent-lengthx-goog-api-key_PASS_THROUGH_PROTECTED_HEADERS)zx-amz-'_PASS_THROUGH_PROTECTED_HEADER_PREFIXESc                       \ rS rSr\ SS\R                  S\\\	\\
4   4   S\\\\	\\
4   4      S\\\	\\\   4   4   4S jj5       r\ SS\S	\S
\\   4S jj5       rSrg)BasePassthroughUtils   Nexisting_urlrequest_query_paramsdefault_query_paramsreturnc                 H   U R                   R                  S5      n[        U5      nUR                  5        VVs0 s H  u  pVU[	        U5      S:X  a  US   OU_M     nnn0 nU(       a  UR                  U5        UR                  U5        UR                  U5        U$ s  snnf )Nzutf-8   r   )querydecoder   itemslenupdate)	r   r   r   existing_query_stringexisting_query_paramskvupdated_existing_query_paramsmerged_paramss	            k/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/litellm/passthrough/utils.pyget_merged_query_parameters0BasePassthroughUtils.get_merged_query_parameters   s     !- 2 2 9 9' B ()> ? 7L6Q6Q6S)
6SdaAs1v{qt)6S 	& )

   !56 	:; 	12)
s   #Brequest_headersheadersforward_headersc                   ^ USL a  U R                  SS5        U R                  SS5        U Vs1 s H  o3R                  5       iM     nn[        U R                  5       5       H+  nUR                  5       U;   d  M  U R                  US5        M-     0 U EUEnU R	                  5        H  u  p5UR                  5       R                  [        5      (       d  M/  U[        [        5      S R                  5       mT[        ;   d  [        U4S j[         5       5      (       a  [        R                  " SU5        M  XQT'   M     U$ s  snf )z
Helper to forward headers from original request.

Also handles 'x-pass-' prefixed headers which are always forwarded
with the prefix stripped, regardless of forward_headers setting.
e.g., 'x-pass-anthropic-beta: value' becomes 'anthropic-beta: value'
Tr   Nr   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fN)
startswith).0pactual_header_names     r'   	<genexpr>DBasePassthroughUtils.forward_headers_from_request.<locals>.<genexpr>Z   s'      PD '11!44Ds   !z;x-pass- header %s maps to a protected header name; skipping)poplowerlistkeysr   r0   r
   r   r   anyr   r	   debug)r*   r+   r,   header_namecustom_header_namesheader_valuer3   s         @r'   forward_headers_from_request1BasePassthroughUtils.forward_headers_from_request8   sB    d" 0$7-JQ"R';#4#4#6'"R#O$8$8$:;$$&*==#''T:  <
 54G4G *9)>)>)@%K  "--.HII%0235&%' # &)HHC PDP M M #((U# .:*+ *A" 7 #Ss   E r/   )F)__name__
__module____qualname____firstlineno__staticmethodhttpxURLr   strr   r8   r   r   r   r(   dictboolr?   __static_attributes__rA       r'   r   r      s     GKii%c5d+;&;< 'tCsDy1A,A'BC 
c5d3i((	)	 6  +0,,, "$, ,rM   r   c                   0    \ rS rSr\S\S\4S j5       rSrg)CommonUtilsh   endpointr   c                     SSK nSU ;  a  U $ / SQnU H0  u  p4UR                  X05      (       d  M  UR                  X4U 5      n   U $    U $ )a  
Encodes any "/" found in the modelId of an AWS Bedrock Runtime Endpoint when arns are passed in.
- modelID value can be an ARN which contains slashes that SHOULD NOT be treated as path separators.
e.g endpoint: /model/<modelId>/invoke
<modelId> containing arns with slashes need to be encoded from
    arn:aws:bedrock:ap-southeast-1:123456789012:application-inference-profile/abdefg12334 =>
    arn:aws:bedrock:ap-southeast-1:123456789012:application-inference-profile%2Fabdefg12334
so that it is treated as one part of the path.
Otherwise, the encoded endpoint will return 500 error when passed to Bedrock endpoint.

See the apis in https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Amazon_Bedrock_Runtime.html
for more details on the regex patterns of modelId which we use in the regex logic below.

Args:
    endpoint (str): The original endpoint string which may contain ARNs that contain slashes.

Returns:
    str: The endpoint with properly encoded ARN slashes
r   Nzarn:aws:)
)z((custom-model)/([a-z0-9.-]+)/([a-z0-9]+)z\1%2F\2%2F\3)z!(:application-inference-profile)/\1%2F)z(:inference-profile)/rS   )z(:foundation-model)/rS   )z(:imported-model)/rS   )z(:provisioned-model)/rS   )z
(:prompt)/rS   )z(:endpoint)/rS   )z(:prompt-router)/rS   )z(:default-prompt-router)/rS   )researchsub)rQ   rT   patternspatternreplacements        r'   "encode_bedrock_runtime_modelid_arn.CommonUtils.encode_bedrock_runtime_modelid_arni   sZ    * 	 X%O
 %- Gyy++66'A %- rM   rA   N)rB   rC   rD   rE   rF   rI   rZ   rL   rA   rM   r'   rO   rO   h   s"    0S 0S 0 0rM   rO   )typingr   r   r   r   r   urllib.parser   rG   litellm._loggingr	   litellm.constantsr
   	frozensetr   __annotations__r   tupler   rO   rA   rM   r'   <module>rc      sT    7 7 !  + 8
 .7	.  	 2= ' <J JZ2 2rM   