
    jY                     X    d dl mZmZmZmZ d dlmZ d dlZ G d d      Z G d d      Z	y)    )DictListOptionalUnion)parse_qsNc                       e Zd Zedej
                  deeeee	f   f   deeeee
e   f   f   fd       Ze	 d
dededee   fd       Zy	)BasePassthroughUtilsexisting_urlrequest_query_paramsreturnc                     | j                   j                  d      }t        |      }|j                         D ci c]  \  }}|t	        |      dk(  r|d   n| }}}i ||S c c}}w )Nzutf-8   r   )querydecoder   itemslen)r
   r   existing_query_stringexisting_query_paramskvupdated_existing_query_paramss          r/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/litellm/passthrough/utils.pyget_merged_query_parametersz0BasePassthroughUtils.get_merged_query_parameters   s    
 !- 2 2 9 9' B ()> ? 7L6Q6Q6S)
6SdaAs1v{qt)6S 	& )
 I&H*GHH	)
s    A#request_headersheadersforward_headersc                 b    |du r*| j                  dd       | j                  dd       i | |}|S )zA
        Helper to forward headers from original request
        Tzcontent-lengthNhost)pop)r   r   r   s      r   forward_headers_from_requestz1BasePassthroughUtils.forward_headers_from_request   sC     d" 0$7- 54G4G    N)F)__name__
__module____qualname__staticmethodhttpxURLr   strr   listr   r   dictr   boolr     r!   r   r	   r	      s    IiiI7;CsDyAQ<Q7RI	c5d3i((	)I I  +0 "$ r!   r	   c                   &    e Zd Zededefd       Zy)CommonUtilsendpointr   c                     ddl }d| vr| S g d}|D ]-  \  }}|j                  ||       s|j                  |||       }  | S  | S )av  
        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)/r1   )z(:foundation-model)/r1   )z(:imported-model)/r1   )z(:provisioned-model)/r1   )z
(:prompt)/r1   )z(:endpoint)/r1   )z(:prompt-router)/r1   )z(:default-prompt-router)/r1   )researchsub)r/   r2   patternspatternreplacements        r   "encode_bedrock_runtime_modelid_arnz.CommonUtils.encode_bedrock_runtime_modelid_arn*   s]    * 	 X%O
  %- G[yy(+66';A %- r!   N)r"   r#   r$   r%   r(   r8   r,   r!   r   r.   r.   )   s"    1S 1S 1 1r!   r.   )
typingr   r   r   r   urllib.parser   r&   r	   r.   r,   r!   r   <module>r;      s&    . . !    D3 3r!   