
    Rmj                    4   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
mZmZ ddlmZmZmZ ddlmZ  G d de          Z G d	 d
ed          Z G d de          Z G d de
          Zd*dZd+dZ ed           G d d                      Z ed           G d d                      Z ed           G d d                      Z ed           G d  d!                      Zd"Z ed           G d# d$                      Zd,d'Zg d(Z d)S )-z+PII redaction plugin configuration helpers.    )annotations)	dataclassfieldfieldsis_dataclass)LiteralProtocol	TypedDictcast)Json
JsonObjectUnsupportedBehavior)pluginc                  .    e Zd ZU ded<   ded<   ded<   dS )_ConfigDiagnosticRequiredzLiteral['warning', 'error']levelstrcodemessageN)__name__
__module____qualname____annotations__     `/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/nemo_relay/pii_redaction.pyr   r      s.         &&&&IIILLLLLr   r   c                  (    e Zd ZU dZded<   ded<   dS )ConfigDiagnosticz(One PII redaction validation diagnostic.r   	componentr   Nr   r   r   __doc__r   r   r   r   r   r      s(         22NNNJJJJJr   r   F)totalc                      e Zd ZU dZded<   dS )ConfigReportz2Validation report for PII redaction configuration.zlist[ConfigDiagnostic]diagnosticsNr    r   r   r   r$   r$      s$         <<''''''r   r$   c                      e Zd ZddZdS )_SupportsToDictreturnr   c                    d S Nr   selfs    r   to_dictz_SupportsToDict.to_dict#   s      r   Nr(   r   )r   r   r   r-   r   r   r   r'   r'   "   s        ((((((r   r'   valueobjectr(   r   c                    t           d          r't          t                                                     S t	                     r1t           t                    s fdt                     D             S t           t                    rd  D             S t           t                    rd  
                                D             S t          t                     S )Nr-   c                h    i | ].}t          |j                  x|j        t                    /S r*   )getattrname
_normalize).0
field_infofield_valuer/   s     r   
<dictcomp>z_normalize.<locals>.<dictcomp>*   sF     
 
 
&ujo>>>K OZ44KKKr   c                ,    g | ]}t          |          S r   )r5   )r6   items     r   
<listcomp>z_normalize.<locals>.<listcomp>0   s     333T
4  333r   c                ^    i | ]*\  }}|t          t          |          t          |          +S r*   )r   r   r5   )r6   keyvals      r   r9   z_normalize.<locals>.<dictcomp>2   s2    aaaHCQTQ`S#
3Q`Q`Q`r   )hasattrr   r'   r-   r   
isinstancetyper   listdictitemsr   )r/   r8   s   `@r   r5   r5   &   s    ui   6OU++33555E 
:eT#:#: 

 
 
 
 
$Umm
 
 
 	

 % 433U3333% baaaaaaer   r   c                F    t          t          t          |                     S r*   )r   r   r5   )r/   s    r   _normalize_objectrG   6   s    
Ju--...r   T)slotsc                  F    e Zd ZU dZdZded<   dZded<   dZded<   dd
ZdS )ConfigPolicyz3Policy for unsupported PII redaction configuration.warnr   unknown_componentunknown_fielderrorunsupported_valuer(   r   c                ,    | j         | j        | j        dS )z9Serialize this policy to the canonical JSON object shape.rL   rM   rO   rQ   r+   s    r   r-   zConfigPolicy.to_dictB   s%     "&!7!/!%!7
 
 	
r   Nr.   )	r   r   r   r!   rL   r   rM   rO   r-   r   r   r   rJ   rJ   :   se         ==-33333)/M////-44444
 
 
 
 
 
r   rJ   c                      e Zd ZU dZdZded<    ee          Zded<   dZ	d	ed
<   dZ
d	ed<   dZd	ed<   dZd	ed<   dZded<   dZded<   ddZdS )BuiltinConfigz2Deterministic built-in redaction backend settings.removez<Literal['remove', 'redact', 'regex_replace', 'hash', 'mask']actiondefault_factoryz	list[str]target_pathsN
str | Nonepatterndetectorreplacement	mask_char
int | Noneunmasked_prefixunmasked_suffixr(   r   c                    t          | j        | j        | j        | j        | j        | j        | j        | j        d          S )zJSerialize this built-in backend config to the canonical JSON object shape.)rU   rX   rZ   r[   r\   r]   r_   r`   )	rG   rU   rX   rZ   r[   r\   r]   r_   r`   r+   s    r   r-   zBuiltinConfig.to_dictX   sJ     + $ 1< M#/!^#'#7#'#7	 	
 
 	
r   r.   )r   r   r   r!   rU   r   r   rC   rX   rZ   r[   r\   r]   r_   r`   r-   r   r   r   rS   rS   K   s         <<KSFSSSS#eD999L9999GH"K"""" I    "&O&&&&"&O&&&&
 
 
 
 
 
r   rS   c                  b    e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	d	ed
<   ddZ
dS )LocalModelConfigz)Future local-model backend seam settings.NrY   backendmodel_iddetector_profilezbool | Noneallow_networkr^   max_latency_msr(   r   c                ^    t          | j        | j        | j        | j        | j        d          S )zESerialize this local-model config to the canonical JSON object shape.)rd   re   rf   rg   rh   )rG   rd   re   rf   rg   rh   r+   s    r   r-   zLocalModelConfig.to_dictr   s:     < M$($9!%!3"&"5 
 
 	
r   r.   )r   r   r   r!   rd   r   re   rf   rg   rh   r-   r   r   r   rc   rc   h   s         33GH#'''''!%M%%%%!%N%%%%

 

 

 

 

 

r   rc   c                      e Zd ZU dZdZded<   dZded<   dZd	ed
<   dZd	ed<   dZ	d	ed<   dZ
d	ed<   dZd	ed<   dZded<   dZded<   dZded<   dZded<    ee          Zded<   ddZdS )PiiRedactionConfigzDCanonical config document for the top-level PII redaction component.   intversionbuiltinz!Literal['builtin', 'local_model']modeTboolinputoutput
tool_inputtool_outputmarkd   priorityNzMLiteral['openai_chat', 'openai_responses', 'anthropic_messages'] | str | NonecodeczBuiltinConfig | NonezLocalModelConfig | NonelocalrV   rJ   policyr(   r   c                    t          | j        | j        | j        | j        | j        | j        | j        | j        | j	        | j
        | j        | j        d          S )zGSerialize this PII redaction config to the canonical JSON object shape.)rn   rp   rr   rs   rt   ru   rv   rx   ry   ro   rz   r{   )rG   rn   rp   rr   rs   rt   ru   rv   rx   ry   ro   rz   r{   r+   s    r   r-   zPiiRedactionConfig.to_dict   s[     <	+"o#/	 M<+ 
 
 	
r   r.   )r   r   r   r!   rn   r   rp   rr   rs   rt   ru   rv   rx   ry   ro   rz   r   rJ   r{   r-   r   r   r   rk   rk      s	        NNG.7D7777EFJKDH[_E____$(G((((%)E)))) 5>>>F>>>>
 
 
 
 
 
r   rk   pii_redactionc                  4    e Zd ZU dZded<   dZded<   dd	Zd
S )ComponentSpecz*Top-level PII redaction component wrapper.PiiRedactionConfig | JsonObjectconfigTrq   enabledr(   r   c                F    t           | j        t          | j                  dS )z7Serialize this component to the canonical plugin shape.)kindr   r   )PII_REDACTION_PLUGIN_KINDr   rG   r   r+   s    r   r-   zComponentSpec.to_dict   s(     .|'44
 
 	
r   Nr.   )r   r   r   r!   r   r   r-   r   r   r   r   r      sM         44++++G
 
 
 
 
 
r   r   r   r   c                    t          j        t          j        t          |           g                    }t	          t
          |          S )z?Validate a PII redaction config document without activating it.)
components)plugin_modulevalidatePluginConfigr   r   r$   )r   reports     r   validate_configr      sI    #"%f--.	
 	
 	
 F
 f%%%r   )	rS   r   r   rJ   r$   rc   r   rk   r   N)r/   r0   r(   r   )r/   r0   r(   r   )r   r   r(   r$   )!r!   
__future__r   dataclassesr   r   r   r   typingr   r	   r
   r   
nemo_relayr   r   r   r   r   r   r   r$   r'   r5   rG   rJ   rS   rc   rk   r   r   r   __all__r   r   r   <module>r      s   2 1 " " " " " " > > > > > > > > > > > > 5 5 5 5 5 5 5 5 5 5 5 5 < < < < < < < < < < . . . . . .    	       0    ( ( ( ( (9 ( ( () ) ) ) )h ) ) )    / / / / 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
8 
 
 
 
 
 
 
 
, !
 !
 !
 !
 !
 !
 !
 !
H ,  
 
 
 
 
 
 
 
& & & &
 
 
r   