
    MiY                     X    S SK JrJrJrJr  S SKJr  S SKr " S S5      r " S S5      r	g)    )DictListOptionalUnion)parse_qsNc                       \ rS rSr\S\R                  S\\\	\\
4   4   S\\\	\\\   4   4   4S j5       r\ SS\S\S\\   4S	 jj5       rS
rg)BasePassthroughUtils   existing_urlrequest_query_paramsreturnc                     U R                   R                  S5      n[        U5      nUR                  5        VVs0 s H  u  pEU[	        U5      S:X  a  US   OU_M     nnn0 UEUE$ s  snnf )Nzutf-8   r   )querydecoder   itemslen)r   r   existing_query_stringexisting_query_paramskvupdated_existing_query_paramss          s/var/www/eduai.edurigo.com/storigo/production/storigo_env/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 	& )
 I&H*GHH	)
s   #A&request_headersheadersforward_headersc                 d    USL a*  U R                  SS5        U R                  SS5        0 U EUEnU$ )z1
Helper to forward headers from original request
Tzcontent-lengthNhost)pop)r   r   r   s      r   forward_headers_from_request1BasePassthroughUtils.forward_headers_from_request   sC     d" 0$7- 54G4G     N)F)__name__
__module____qualname____firstlineno__staticmethodhttpxURLr   strr   listr   r   dictr   boolr"   __static_attributes__r%   r$   r   r	   r	      s    IiiI7;CsDyAQ<Q7RI	c5d3i((	)I I  +0 "$ r$   r	   c                   0    \ rS rSr\S\S\4S j5       rSrg)CommonUtils)   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)/r7   )z(:foundation-model)/r7   )z(:imported-model)/r7   )z(:provisioned-model)/r7   )z
(:prompt)/r7   )z(:endpoint)/r7   )z(:prompt-router)/r7   )z(:default-prompt-router)/r7   )researchsub)r5   r8   patternspatternreplacements        r   "encode_bedrock_runtime_modelid_arn.CommonUtils.encode_bedrock_runtime_modelid_arn*   sZ    * 	 X%O
  %- Gyy++66'A %- r$   r%   N)r&   r'   r(   r)   r*   r-   r>   r1   r%   r$   r   r3   r3   )   s"    1S 1S 1 1r$   r3   )
typingr   r   r   r   urllib.parser   r+   r	   r3   r%   r$   r   <module>rB      s&    . . !    D3 3r$   