Ë
    tPêj~[  ã                  ó  — U d dl mZ d dlmZ d dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZ d d	l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 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) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/ dZ0de1d<   dZ2de1d<   dZ3de1d<   dZ4de1d<   dZ5de1d<    e6h d £«      Z7de1d!<    e6d"«      Z8de1d#<    e6d$«      Z9de1d%<   e8e9z  Z:de1d&<    G d'„ d(e;«      Z<d-d)„Z=d.d*„Z> G d+„ d,e«      Z?y	)/é    )Úannotations)ÚAsyncGenerator)Údatetime)ÚFinalÚLiteralÚ	TypeGuard)ÚHTTPException)Ú	HTTPError)ÚResponse)Ú	BaseModelÚTypeAdapterÚValidationErrorN)Úverbose_proxy_logger)ÚCustomGuardrail)Úget_async_httpx_clientÚhttpxSpecialProvider)ÚUserAPIKeyAuth)Ú*add_guardrail_to_applied_guardrails_header)Úbuild_inspection_messages)Úget_secret_str)ÚGuardrailEventHooksÚMode)ÚGuardrailConfigModel)ÚRepelloAIAnalyzeResponse)ÚCallTypesLiteralÚGuardrailStatusÚLLMResponseTypesÚModelResponseÚModelResponseStreamz"https://argusapi.repello.ai/sdk/v1r   ÚDEFAULT_REPELLOAI_API_BASEg      >@ÚDEFAULT_REPELLOAI_TIMEOUTÚblockedÚBLOCKED_VERDICTÚflaggedÚFLAGGED_VERDICTÚpassedÚPASSED_VERDICT>   é‘  é“  é”  é¦  é�  ÚCONFIG_ERROR_STATUS_CODES)ÚnameÚdescriptionÚtitleÚconstÚdefaultÚ_SCHEMA_SCALAR_KEYS)ÚenumÚexamplesÚ_SCHEMA_LIST_KEYSÚ_SCHEMA_EXTRACTED_KEYSc                  ó   — e Zd Zy)Ú RepelloAIGuardrailMissingSecretsN)Ú__name__Ú
__module__Ú__qualname__© ó    ú�/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_hooks/repelloai/repelloai.pyr9   r9   5   s   „ Ør>   r9   c                ó"   — t        | t        «      S ©N)Ú
isinstanceÚdict©Úvalues    r?   Ú_is_object_dictrF   9   ó   € Ü�eœTÓ"Ð"r>   c                ó"   — t        | t        «      S rA   )rB   ÚlistrD   s    r?   Ú_is_object_listrJ   =   rG   r>   c                  óæ  ‡ — e Zd Zedd„«       Zedd„«       Zedd„«       Zedd„«       Zedd„«       Z		 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Z
	 	 	 	 	 	 	 	 	 	 d d„Zed!d„«       Zd"d	„Zd#d
„Zd$d„Zed%d„«       Zed&d„«       Zedd„«       Zed'd„«       Zedd„«       Zed(d„«       Z	 	 	 	 	 	 	 	 	 	 d)d„Z	 	 	 	 	 	 d*d„Z	 	 	 	 	 	 	 	 d+d„Zed,d„«       Zed-d„«       Zed-d„«       Zed.d„«       Zˆ xZS )/ÚRepelloAIGuardrailc                óB   — t         j                  t         j                  gS rA   )r   Úpre_callÚ	post_call)Úclss    r?   Úget_supported_event_hooksz,RepelloAIGuardrail.get_supported_event_hooksB   s    € ô  ×(Ñ(Ü×)Ñ)ð
ð 	
r>   c                óT   — t        | «      r| j                  |«      S t        | |d «      S rA   )rF   ÚgetÚgetattr)ÚobjÚkeys     r?   Ú
_get_fieldzRepelloAIGuardrail._get_fieldI   s'   € ä˜3ÔØ—7‘7˜3“<ÐÜ�s˜C Ó&Ð&r>   c                óª  — g }| j                  |d«      }t        |«      r^|D ]Y  }| j                  |d«      }| j                  |d«      }t        |t        «      sŒ8|j	                  «       sŒI|j                  |«       Œ[ | j                  |d«      }| j                  |d«      }t        |t        «      r!|j	                  «       r|j                  |«       |S )NÚ
tool_callsÚfunctionÚ	argumentsÚfunction_call)rW   rJ   rB   ÚstrÚstripÚappend)rP   ÚmessageÚargsrY   Ú	tool_callrZ   r[   r\   s           r?   Ú$_extract_tool_call_args_from_messagez7RepelloAIGuardrail._extract_tool_call_args_from_messageO   s³   € à!#ˆàŸN™N¨7°LÓAˆ
Ü˜:Ô&Ø'ò +�	ØŸ>™>¨)°ZÓ@�ØŸN™N¨8°[ÓA�	Ü˜i¬Õ-°)·/±/Õ2CØ—K‘K 	Õ*ð	+ð  #Ÿ~™~¨g°ÓGˆØ—N‘N =°+Ó>ˆ	Ü�i¤Ô%¨)¯/©/Ô*;Ø�K‰K˜	Ô"àˆr>   c                ó`  — g }| g}|�r|j                  «       }t        |«      rÛt        D ]8  }|j                  |«      }t	        |t
        «      sŒ%|sŒ(|j                  |«       Œ: t        D ]K  }|j                  |«      }t        |«      sŒ |D ]'  }t	        |t
        «      sŒ|sŒ|j                  |«       Œ) ŒM |j                  «       D ��	cg c]  \  }}	|t        vsŒ|	‘Œ }
}}	|j                  t        |
«      «       n%t        |«      r|j                  t        |«      «       |r�Œ|S c c}	}w rA   )ÚpoprF   r3   rS   rB   r]   r_   r6   rJ   Úitemsr7   ÚextendÚreversed)ÚnodeÚtextsÚstackÚcurrentrV   rE   rf   ÚitemÚkÚvÚ	remainings              r?   Ú_iter_schema_textz$RepelloAIGuardrail._iter_schema_textb   s  € à"$ˆØ&* VˆâØ—i‘i“kˆGÜ˜wÔ'Ü.ò ,�CØ#ŸK™K¨Ó,�EÜ! %¬Õ-²%ØŸ™ UÕ+ð,ô -ò 3�CØ#ŸK™K¨Ó,�EÜ& uÕ-Ø$)ò 3˜DÜ)¨$´Õ4ºØ %§¡¨TÕ 2ñ3ð3ð :A¿¹»×*l±°°AÈAÔUkÒLkª1Ð*l�	Ñ*lØ—‘œX iÓ0Õ1Ü  Ô)Ø—‘œX gÓ.Ô/ó! ð$ ˆùó +ms   ÃD*ÃD*c                óˆ  — g }|j                  d«      }t        |«      r|ng D ]K  }t        |«      sŒ|j                  d«      }t        |«      sŒ,|j                  | j	                  |«      «       ŒM |j                  d«      }t        |«      r|ng D ].  }t        |«      sŒ|j                  | j	                  |«      «       Œ0 |S )NÚtoolsrZ   Ú	functions)rS   rJ   rF   rg   rq   )rP   Údatarj   rs   ÚtoolrZ   rt   s          r?   Ú_extract_tool_definition_textz0RepelloAIGuardrail._extract_tool_definition_text{   s³   € à"$ˆà—x‘x Ó(ˆÜ,¨UÔ3‘E¸ò 	>ˆDÜ" 4Ô(ØØ—x‘x 
Ó+ˆHÜ˜xÕ(Ø—‘˜S×2Ñ2°8Ó<Õ=ð	>ð  Ÿ8™8 KÓ0ˆ	Ü%4°YÔ%?™	ÀRò 	>ˆHÜ˜xÕ(Ø—‘˜S×2Ñ2°8Ó<Õ=ð	>ð ˆr>   c           	     ó®  •— |xs t        d«      xs t        d«      xs d| _        | j                  st        d«      ‚|| _        | j                  st	        d«      ‚|xs t        d«      xs t
        | _        |dk(  rdnd| _        t        t        j                  d	t        i¬
«      | _        t        ‰| �9  |||t        | j!                  «       «      ¬«       y )NÚARGUS_API_KEYÚREPELLOAI_API_KEYÚ z{Couldn't get Repello API key. Set `ARGUS_API_KEY` in the environment or pass `api_key` to the guardrail in the config file.zŠRepello guardrail requires an `asset_id`. Create an asset in the Repello dashboard and set `asset_id` on the guardrail in the config file.ÚREPELLOAI_API_BASEÚ	fail_openÚfail_closedÚtimeout)Úllm_providerÚparams)Úguardrail_nameÚ
event_hookÚ
default_onÚsupported_event_hooks)r   Úrepelloai_api_keyr9   Úasset_idÚ
ValueErrorr    Úapi_baseÚunreachable_fallbackr   r   ÚGuardrailCallbackr!   Úasync_handlerÚsuperÚ__init__rI   rQ   )	ÚselfÚapi_keyr‰   r‡   rŠ   r‚   rƒ   r„   Ú	__class__s	           €r?   rŽ   zRepelloAIGuardrail.__init__Ž   sä   ø€ ð ")Ò!x¬N¸?Ó,KÒ!xÌ~Ð^qÓOrÒ!xÐvxˆÔØ×%Ò%Ü2ðIóð ð
 !ˆŒØ�}Š}ÜðTóð ð
 !Òf¤NÐ3GÓ$HÒfÔLfˆŒà/°;Ò>‰KÀMð 	Ô!ô 4Ü-×?Ñ?ØÔ8Ð9ô
ˆÔô 	‰ÑØ)Ø!Ø!Ü"& t×'EÑ'EÓ'GÓ"Hð	 	õ 	
r>   c              ƒ  óP  K  — | j                   › d|› �}| j                  xs d||idœ}d}d}t        j                  «       }	d }
	 t	        j
                  d|«       | j                  j                  |d| j                  i|¬«      ƒ d {  –—† }|€t        d«      ‚|}| j                  |«       |j                  «        	 t        t        «      j                  |j                  «      }
t	        j
                  d|
«       | j'                  |
«      rd}|
t        j                  «       }|
�t)        |
«      }| j+                  ||||	j-                  «       |j-                  «       ||	z
  j/                  «       i |¬«       S 7 Œï# t         $ r }t#        d	d
|j$                  dœ¬«      |‚d }~ww xY w# t"        $ rJ}d}t1        |j2                  t(        t4        f«      st7        |j2                  «      }‚ |j2                  }‚ d }~wt8        $ r�}d}t7        |«      }| j;                  |«      cY d }~t        j                  «       }|
�t)        |
«      }| j+                  ||||	j-                  «       |j-                  «       ||	z
  j/                  «       i |¬«       S d }~wt<        $ r"}d}t7        |«      }t#        d	ddi¬«      |‚d }~ww xY w# t        j                  «       }|
�t)        |
«      }| j+                  ||||	j-                  «       |j-                  «       ||	z
  j/                  «       i |¬«       w xY w­w)Nz	/analyze/r{   )r‡   Ú	scan_dataÚsuccesszRepelloAI Argus request: %sz	X-API-Key)ÚurlÚheadersÚjsonz$RepelloAI Argus returned no responseéô  z/RepelloAI Argus guardrail returned invalid JSON©ÚerrorÚstatus_code©r›   ÚdetailzRepelloAI Argus response: %sÚguardrail_intervened)Úguardrail_json_responseÚguardrail_statusÚrequest_dataÚ
start_timeÚend_timeÚdurationÚmasked_entity_countÚ
event_typeÚguardrail_failed_to_respondrš   z RepelloAI Argus guardrail failed)r‰   r‡   r   Únowr   ÚdebugrŒ   Úpostr†   rˆ   Ú_raise_for_config_errorÚraise_for_statusr   r   Úvalidate_jsonÚtextr   r	   r›   Ú_verdict_blocksrC   Ú:add_standard_logging_guardrail_information_to_request_dataÚ	timestampÚtotal_secondsrB   r�   rI   r]   r
   Ú_handle_unreachableÚ	Exception)r�   r®   Ústager¡   r¦   ÚendpointÚrequestÚstatusrŸ   r¢   Úrepelloai_responseÚraw_responseÚresponseÚer£   s                  r?   Ú_call_analyzez RepelloAIGuardrail._call_analyzeµ   sH  è ø€ ð "Ÿ]™]˜O¨9°U°GÐ<ˆàŸ™Ò+¨Ø ˜ñ-
ˆð
 #,ˆØUWÐÜ&.§l¡l£nˆ
Ø>BÐð3	Ü ×&Ñ&Ð'DÀgÔNØ7;×7IÑ7I×7NÑ7NØØ$ d×&<Ñ&<Ð=Øð 8Oó 8÷ 2ˆLð
 Ð#Ü Ð!GÓHÐHØ-9ˆHØ×(Ñ(¨Ô2Ø×%Ñ%Ô'ð	Ü%0Ô1IÓ%J×%XÑ%XÐYa×YfÑYfÓ%gÐ"ô !×&Ñ&Ð'EÐGYÔZØ×#Ñ#Ð$6Ô7Ø/�Ø%ô 'Ÿl™l›nˆHØ!Ð-Ü*.Ð/AÓ*BÐ'Ø×KÑKØ(?Ø!'Ø)Ø%×/Ñ/Ó1Ø!×+Ñ+Ó-Ø" ZÑ/×>Ñ>Ó@Ø$&Ø%ð Lõ 	ðQ2ùô #ò Ü#Ø #à!RØ'/×';Ñ';ñôð ðûðûô ò 	Ø2ˆFÜ;EÀaÇhÁhÔQUÔW[ÐP\Ô;]¤c¨!¯(©(£mÐ#Øð de×ckÑckÐ#ØûÜò 	/Ø2ˆFÜ&)¨!£fÐ#Ø×+Ñ+¨AÓ.Ô.ô 'Ÿl™l›nˆHØ!Ð-Ü*.Ð/AÓ*BÐ'Ø×KÑKØ(?Ø!'Ø)Ø%×/Ñ/Ó1Ø!×+Ñ+Ó-Ø" ZÑ/×>Ñ>Ó@Ø$&Ø%ð Lõ 	ûô ò 	nØ2ˆFÜ&)¨!£fÐ#Ü¨C¸ÐBdÐ8eÔfÐlmÐmûð	nûô
 'Ÿl™l›nˆHØ!Ð-Ü*.Ð/AÓ*BÐ'Ø×KÑKØ(?Ø!'Ø)Ø%×/Ñ/Ó1Ø!×+Ñ+Ó-Ø" ZÑ/×>Ñ>Ó@Ø$&Ø%ð Lõ 	üs›   ‚AL&ÁAF% ÂE7Â4F% Â=(E9 Ã%*F% ÄA(L&Å7F% Å9	F"ÆFÆF"Æ"F% Æ%	J7Æ.AG3Ç3J7Ç?J	ÈJ7ÈJ: È!A(L&Ê	J7ÊJ2Ê2J7Ê7J: Ê:A)L#Ì#L&c                ó\   — | j                   t        v rt        dd| j                   dœ¬«      ‚y )Nr˜   z*RepelloAI Argus guardrail is misconfiguredr™   rœ   )r›   r-   r	   )r»   s    r?   r«   z*RepelloAIGuardrail._raise_for_config_errorû   s7   € à×ÑÔ#<Ñ<ÜØàIØ#+×#7Ñ#7ñôð ð =r>   c                óŠ   — |€y|j                  d«      }|t        k(  ry|t        t        fv ryt	        j
                  d|«       y)NFÚverdictTzARepelloAI Argus returned an unrecognized verdict (%s) - blocking.)rS   r#   r'   r%   r   Úwarning)r�   r¹   rÀ   s      r?   r¯   z"RepelloAIGuardrail._verdict_blocks  sO   € ØÐ%ØØ+×/Ñ/°	Ó:ˆØ”oÒ%ØØ”~¤Ð7Ñ7ØÜ×$Ñ$ØOØô	
ð r>   c                ó~   — t        j                  dt        |«      «       | j                  dk(  rt	        dddi¬«      ‚y )NzRepelloAI Argus unreachable: %sr~   r˜   rš   z%RepelloAI Argus guardrail unreachablerœ   )r   rÁ   r]   rŠ   r	   )r�   rš   s     r?   r³   z&RepelloAIGuardrail._handle_unreachable  sC   € Ü×$Ñ$Ð%FÌÈEË
ÔSØ×$Ñ$¨Ò5ÜØØÐ!HÐIôð ð r>   c                ó†   — |€y | j                  |«      rt        d| j                  |«      ¬«      ‚| j                  |«       y )Nr,   rœ   )r¯   r	   Ú_format_blocked_detailÚ_log_flagged_verdict)r�   r¹   s     r?   Ú_raise_if_blockedz$RepelloAIGuardrail._raise_if_blocked  sJ   € ØÐ%ØØ×ÑÐ 2Ô3ÜØØ×2Ñ2Ð3EÓFôð ð 	×!Ñ!Ð"4Õ5r>   c                óô  — |j                  d«      }t        |t        «      r|syg }|D ]¶  }|j                  d«      xs d}g }|j                  d«      }|r|j                  d|› �«       |j                  d«      }t        |t        «      r'|j                  d«      }	|	�|j                  d	|	› �«       |rd
dj                  |«      › d�nd}
|j                  |› |
› �«       Œ¸ |syddj                  |«      › d�S )NÚpolicies_violatedz%Blocked by RepelloAI Argus guardrail.Úpolicy_nameÚunknown_policyÚaction_takenzaction: ÚdetailsÚscorezscore: z (z, ú)r{   z9Blocked by RepelloAI Argus guardrail. Policies violated: z; ú.)rS   rB   rI   r_   rC   Újoin)rP   r¹   ÚpoliciesÚformatted_policiesÚpolicyrÉ   rÌ   rË   Úpolicy_detailsrÍ   Úsuffixs              r?   rÄ   z)RepelloAIGuardrail._format_blocked_detail'  s  € à,×0Ñ0Ð1DÓEˆÜ˜(¤DÔ)±Ø:à/1ÐØò 	@ˆFØ Ÿ*™* ]Ó3ÒGÐ7GˆKØ!#ˆGØ!Ÿ:™: nÓ5ˆLÙØ—‘ ¨,¨Ð8Ô9Ø#ŸZ™Z¨	Ó2ˆNÜ˜.¬$Ô/Ø&×*Ñ*¨7Ó3�ØÐ$Ø—N‘N W¨U¨GÐ#4Ô5Ù3:�r˜$Ÿ)™) GÓ,Ð-¨QÑ/ÀˆFØ×%Ñ%¨¨°f°XÐ&>Õ?ð	@ñ "Ø:ØJÈ4Ï9É9ÐUgÓKhÐJiÐijÐkÐkr>   c                ó€   — | j                  d«      t        k(  r&t        j                  d| j                  d«      «       y y )NrÀ   z-RepelloAI Argus flagged content (allowed): %srÈ   )rS   r%   r   rÁ   )r¹   s    r?   rÅ   z'RepelloAIGuardrail._log_flagged_verdict@  s;   € à×!Ñ! )Ó,´Ò?Ü ×(Ñ(Ø?Ø"×&Ñ&Ð':Ó;õð @r>   c                óŒ   — t        | «      }|D �cg c])  }t        |j                  d«      x}t        «      sŒ%|sŒ(|‘Œ+ c}S c c}w )NÚcontent)r   rB   rS   r]   )ru   Úmessagesr`   rØ   s       r?   Ú_extract_prompt_message_textz/RepelloAIGuardrail._extract_prompt_message_textH  s<   € ä3°DÓ9ˆØ'/Ör˜G´:ÈÏÉÐU^ÓI_Ð>_¸gÔadÕ3eÒjq’ÒrÐrùÒrs   �&A·AºAc                óÊ   — t        | «      sg S | D �cg c]F  }t        |«      r9|j                  d«      dk(  r%t        |j                  d«      x}t        «      r|r|‘ŒH c}S c c}w )NÚtypeÚ
input_textr®   )rJ   rF   rS   rB   r]   )rØ   Úpartr®   s      r?   Ú_extract_input_text_partsz,RepelloAIGuardrail._extract_input_text_partsM  sc   € ä˜wÔ'ØˆIð  ö
àÜ˜tÔ$¨¯©°&Ó)9¸\Ò)IÜ $§(¡(¨6Ó"2Ð2˜$´CÔ8¹Tò ò
ð 	
ùò 
s   ’AA c                óº   — | j                  d«      }t        |t        «      r|r|gS t        |«      r$|D �cg c]  }t        |t        «      sŒ|sŒ|‘Œ c}S g S c c}w )NÚprompt)rS   rB   r]   rJ   )ru   rá   rm   s      r?   Ú_extract_prompt_field_textz-RepelloAIGuardrail._extract_prompt_field_textX  sR   € àŸ™ Ó*ˆÜ�fœcÔ"¡vØ�8ˆOÜ˜6Ô"Ø%+ÖN˜T¬z¸$ÄÕ/DÊ’DÒNÐNØˆ	ùò Os   ¶AÁAÁAc                óÐ  — | j                  |«      }|j                  | j                  |«      «       |j                  d«      }t	        |t
        «      r|r|j                  |«       |j                  d«      }t        |«      r'|D ]"  }|j                  | j                  |«      «       Œ$ |j                  d«      }t        |«      rg|D ]b  }t        |«      sŒd|vrŒ|j                  | j                  |«      «       |j                  | j                  |j                  d«      «      «       Œd |j                  | j                  |«      «       |rdj                  d„ |D «       «      S d S )NÚinstructionsrÙ   ÚinputÚrolerØ   ú
c              3  ó&   K  — | ]	  }|sŒ|–— Œ y ­wrA   r=   )Ú.0r®   s     r?   ú	<genexpr>z:RepelloAIGuardrail._extract_prompt_text.<locals>.<genexpr>y  s   è ø€ Ò8 $²4œÑ8ùs   ‚Š)rÚ   rg   râ   rS   rB   r]   r_   rJ   rc   rF   rß   rw   rÐ   )rP   ru   rj   rä   Úraw_messagesr`   Ú	raw_inputrm   s           r?   Ú_extract_prompt_textz'RepelloAIGuardrail._extract_prompt_texta  s5  € à×7Ñ7¸Ó=ˆØ�‰�S×3Ñ3°DÓ9Ô:à"Ÿh™h ~Ó6ˆÜ�l¤CÔ(©\Ø�L‰L˜Ô&à"Ÿh™h zÓ2ˆÜ˜<Ô(Ø'ò P�Ø—‘˜S×EÑEÀgÓNÕOðPð  Ÿ8™8 GÓ,ˆ	Ü˜9Ô%Ø!ò U�Ü" 4Õ(Ø TÑ)Ø Ø—L‘L ×!IÑ!IÈ$Ó!OÔPØ—L‘L ×!>Ñ!>¸t¿x¹xÈ	Ó?RÓ!SÕTðUð 	�‰�S×6Ñ6°tÓ<Ô=Ù<Aˆt�y‰yÑ8¨%Ô8Ó8ÐKÀtÐKr>   c              ƒ  óh  K  — t        j                  d«       t        j                  }| j	                  ||¬«      dur|S | j                  |«      }|st        j                  d«       |S | j                  |d||¬«      ƒ d {  –—† }| j                  |«       t        || j                  ¬«       |S 7 Œ.­w)NzRepelloAI Argus: pre_call_hook©ru   r¦   Tz?RepelloAI Argus: no inspectable prompt text in data - skipping.rá   ©r®   rµ   r¡   r¦   ©r¡   r‚   )r   r©   r   rN   Úshould_run_guardrailrí   rÁ   r½   rÆ   r   r‚   )r�   Úuser_api_key_dictÚcacheru   Ú	call_typer¦   r®   r¹   s           r?   Úasync_pre_call_hookz&RepelloAIGuardrail.async_pre_call_hook{  sÅ   è ø€ ô 	×"Ñ"Ð#CÔDä/×8Ñ8ˆ
à×%Ñ%Ø jð &ó ð ñð
 ˆKà×/Ñ/°Ó5ˆÙÜ ×(Ñ(Ð)jÔkØˆKà*.×*<Ñ*<ØØØØ!ð	 +=ó +
÷ %
Ðð 	×ÑÐ1Ô2ä2ÀÐUY×UhÑUhÕiØˆð%
úó   ‚A?B2ÂB0Â/B2c              ƒ  óh  K  — t        j                  d«       t        j                  }| j	                  ||¬«      dur|S | j                  |«      }|st        j                  d«       |S | j                  |d||¬«      ƒ d {  –—† }| j                  |«       t        || j                  ¬«       |S 7 Œ.­w)Nz'RepelloAI Argus: post_call_success_hookrï   Tz9RepelloAI Argus: no inspectable response text - skipping.r»   rð   rñ   )r   r©   r   rO   rò   Ú_extract_response_textrÁ   r½   rÆ   r   r‚   )r�   ru   ró   r»   r¦   r®   r¹   s          r?   Úasync_post_call_success_hookz/RepelloAIGuardrail.async_post_call_success_hook�  sÅ   è ø€ ô 	×"Ñ"Ð#LÔMä/×9Ñ9ˆ
à×%Ñ%Ø jð &ó ð ñð
 ˆOà×1Ñ1°(Ó;ˆÙÜ ×(Ñ(Ð)dÔeØˆOà*.×*<Ñ*<ØØØØ!ð	 +=ó +
÷ %
Ðð 	×ÑÐ1Ô2ä2ÀÐUY×UhÑUhÕiØˆð%
úr÷   c               óŽ  K  — ddl m} t        j                  }| j	                  ||¬«      dur|2 3 d {  –—† }|­–— Œg }|2 3 d {  –—† }|j                  |«       Œ7 Œ)6 y 7 Œ6 |j                  |¬«      }t        |t        «      r| j                  |«      nd }	|	rh| j                  |	d||¬«      ƒ d {  –—†7  }
|
�| j                  |
«       | j                  |
«      rddlm}  |d	«      ‚t        || j                   ¬
«       n4t#        j$                  d| j                   t'        |«      j(                  «       |D ]  }|­–— Œ	 y ­w)Nr   )Úmainrï   T)Úchunksr»   rð   )ÚStreamingCallbackErrorz$Blocked by RepelloAI Argus guardrailrñ   zhRepelloAI Argus: no inspectable text in streamed response; skipping scan. guardrail=%s assembled_type=%s)Úlitellmrü   r   rO   rò   r_   Ústream_chunk_builderrB   r   rù   r½   rÅ   r¯   Úlitellm.proxy.proxy_serverrþ   r   r‚   r   rÁ   rÜ   r:   )r�   ró   r»   r¡   Úlitellm_mainr¦   Úchunkrý   Ú	assembledr®   r¹   rþ   s               r?   Ú'async_post_call_streaming_iterator_hookz:RepelloAIGuardrail.async_post_call_streaming_iterator_hook¾  ss  è ø€ õ 	1ä/×9Ñ9ˆ
à×%Ñ%Ø!¨jð &ó ð ñð
  (÷ ð �eØ”ð 46ˆØ#÷ 	!ð 	!�%Ø�M‰M˜%Õ ðø˜xàð	!ø˜8ð !×5Ñ5Øð 6ó 
ˆ	ô AKÈ9ÔVcÔ@d�d×1Ñ1°)Ô<ÐjnˆÙØ.2×.@Ñ.@ØØ Ø)Ø%ð	 /Aó /÷ )ð )Ðð "Ð-Ø×)Ñ)Ð*<Ô=Ø×#Ñ#Ð$6Ô7ÝMá,Ð-SÓTÐTÜ6ÀLÐae×atÑatÖuä ×(Ñ(ð1à×#Ñ#Ü�Y“×(Ñ(ô	ð ò 	ˆEØŒKñ	ùsW   ‚.E°A ´AµA ¸EÁA$ÁA"ÁA$ÁEÁA Á EÁ"A$Á$AEÂ4B7Â5BEc                ó  — t        | «      r| }nDt        | t        «      r| j                  «       }n#t	        | dd «      }t        |t
        «      r|r|S i }t        j                  |«      }|r|S t        j                  |«      S )NÚoutput_text)	rF   rB   r   Ú
model_dumprT   r]   rL   Ú_extract_chat_completion_textÚ_extract_responses_api_text)r»   Úresponse_dictr  r®   s       r?   rù   z)RepelloAIGuardrail._extract_response_textò  sz   € ä˜8Ô$Ø$‰MÜ˜¤-Ô0à×#Ñ#Ó%ñ ô ")¨°=À$Ó!GˆKÜ˜+¤sÔ+±Ø"Ð"ØˆMä(×FÑFÀ}ÓUˆÙØˆKÜ!×=Ñ=¸mÓLÐLr>   c                óÜ  — |j                  d«      }t        |«      sy g }|D ]´  }t        |«      sŒ|j                  d«      }t        |«      rT|j                  d«      }t        |t        «      r|r|j                  |«       |j                  | j                  |«      «       |j                  d«      }t        |t        «      sŒ¡|sŒ¤|j                  |«       Œ¶ |rdj                  |«      S d S )NÚchoicesr`   rØ   r®   rç   )	rS   rJ   rF   rB   r]   r_   rg   rc   rÐ   )rP   r  r  ÚpartsÚchoicer`   rØ   r®   s           r?   r	  z0RepelloAIGuardrail._extract_chat_completion_text  sÍ   € à&×*Ñ*¨9Ó5ˆÜ˜wÔ'ØØ"$ˆØò 	#ˆFÜ" 6Ô*ØØ—j‘j Ó+ˆGÜ˜wÔ'Ø!Ÿ+™+ iÓ0�Ü˜g¤sÔ+±Ø—L‘L Ô)Ø—‘˜S×EÑEÀgÓNÔOØ—:‘:˜fÓ%ˆDÜ˜$¤Õ$ªØ—‘˜TÕ"ð	#ñ $)ˆt�y‰y˜ÓÐ2¨dÐ2r>   c                ó&  — | j                  d«      }t        |«      sy g }|D ]Ù  }t        |«      sŒ|j                  d«      }|dk(  r5|j                  d«      }t        |t        «      r|r|j                  |«       ŒZ|dk7  rŒ`|j                  d«      }t        |«      sŒ}|D ]X  }t        |«      sŒ|j                  d«      dvrŒ#|j                  d«      }t        |t        «      sŒE|sŒH|j                  |«       ŒZ ŒÛ |rd	j                  |«      S d S )
NÚoutputrÜ   r\   r[   r`   rØ   )r  r®   r®   r{   )rS   rJ   rF   rB   r]   r_   rÐ   )	r  r  rj   Úoutput_itemÚ	item_typer[   rØ   Úcontent_itemr®   s	            r?   r
  z.RepelloAIGuardrail._extract_responses_api_text  s  € à%×)Ñ)¨(Ó3ˆÜ˜vÔ&ØØ"$ˆØ!ò 	'ˆKÜ" ;Ô/ØØ#Ÿ™¨Ó/ˆIØ˜OÒ+Ø'ŸO™O¨KÓ8�	Ü˜i¬Ô-±)Ø—L‘L Ô+ØØ˜IÒ%ØØ!—o‘o iÓ0ˆGÜ" 7Ô+ØØ 'ò '�Ü& |Ô4ØØ×#Ñ# FÓ+Ð3JÑJØØ#×'Ñ'¨Ó/�Ü˜d¤CÕ(ªTØ—L‘L Õ&ñ'ð	'ñ, "'ˆr�w‰w�u‹~Ð0¨DÐ0r>   c                 ó   — ddl m}  | S )Nr   ©ÚRepelloAIGuardrailConfigModel)Ú8litellm.types.proxy.guardrails.guardrail_hooks.repelloair  r  s    r?   Úget_config_modelz#RepelloAIGuardrail.get_config_model7  s   € õ	
ð -Ð,r>   )Úreturnzlist[GuardrailEventHooks])rU   ÚobjectrV   r]   r  r  )r`   r  r  ú	list[str])ri   r  r  r  )ru   údict[str, object]r  r  )NNNr~   NNF)r�   ú
str | Noner‰   r  r‡   r  rŠ   z#Literal['fail_closed', 'fail_open']r‚   r  rƒ   z=GuardrailEventHooks | list[GuardrailEventHooks] | Mode | Noner„   Úbool)
r®   r]   rµ   zLiteral['prompt', 'response']r¡   r  r¦   r   r  úRepelloAIAnalyzeResponse | None)r»   ÚHttpxResponser  ÚNone)r¹   r   r  r  )rš   r´   r  r   )r¹   r   r  r"  )r¹   r   r  r]   )r¹   r   r  r"  )rØ   r  r  r  )ru   r  r  r  )
ró   r   rô   zlitellm.DualCacheru   r  rõ   r   r  z*Exception | str | dict[str, object] | None)ru   r  ró   r   r»   r   )ró   r   r»   ú)AsyncGenerator[ModelResponseStream, None]r¡   r  r  r#  )r»   r  r  r  )r  r  r  r  )r  z,type[GuardrailConfigModel[BaseModel]] | None)r:   r;   r<   ÚclassmethodrQ   ÚstaticmethodrW   rc   rq   rw   rŽ   r½   r«   r¯   r³   rÆ   rÄ   rÅ   rÚ   rß   râ   rí   rö   rú   r  rù   r	  r
  r  Ú__classcell__)r‘   s   @r?   rL   rL   A   s{  ø„ Øò
ó ð
ð ò'ó ð'ð
 òó ðð$ òó ðð0 òó ðð( #Ø#Ø#ØDQØ%)ØVZØ ð%
àð%
ð ð%
ð ð	%
ð
 Bð%
ð #ð%
ð Sð%
ð õ%
ðNDàðDð -ðDð (ð	Dð
 (ðDð 
)óDðL òó ðóóó6ð òló ðlð0 òó ðð òsó ðsð ò
ó ð
ð òó ðð òLó ðLð2 à)ð ð !ð ð  ð	 ð
 $ð ð 
4ó ðDàðð *ðð #ó	ðB2à)ð2ð <ð2ð (ð	2ð
 
3ó2ðh òMó ðMð$ ò3ó ð3ð& ò1ó ð1ð: ò-ó ô-r>   rL   )rE   r  r  zTypeGuard[dict[str, object]])rE   r  r  zTypeGuard[list[object]])@Ú
__future__r   Úcollections.abcr   r   Útypingr   r   r   Úfastapir	   Úhttpxr
   r   r!  Úpydanticr   r   r   rÿ   Úlitellm._loggingr   Ú%litellm.integrations.custom_guardrailr   Ú&litellm.llms.custom_httpx.http_handlerr   r   Úlitellm.proxy._typesr   Ú)litellm.proxy.common_utils.callback_utilsr   Ú'litellm.proxy.guardrails._content_utilsr   Úlitellm.secret_managers.mainr   Úlitellm.types.guardrailsr   r   Ú3litellm.types.proxy.guardrails.guardrail_hooks.baser   r  r   Úlitellm.types.utilsr   r   r   r   r   r    Ú__annotations__r!   r#   r%   r'   Ú	frozensetr-   r3   r6   r7   r´   r9   rF   rJ   rL   r=   r>   r?   ú<module>r9     sú   ðÞ "å *Ý ß ,Ñ ,å !Ý Ý +ß <Ñ <ã Ý 1Ý A÷õ 0õõ NÝ 7ß >Ý Tõ÷õ ð %IÐ ˜EÓ HØ#'Ð ˜5Ó 'Ø"€�Ó "Ø"€�Ó "Ø €�Ó  ñ
 $-Ò-FÓ#GÐ ˜5Ó GÙ&Ð'[Ó\Ð �UÓ \Ù$Ð%9Ó:Ð �5Ó :Ø 3Ð6GÑ GÐ ˜Ó Gô	 yô 	ó#ó#ô|-˜õ |-r>   