Ë
    uPêj.$  ã                   óª   — U d dl Z d dl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 d dlmZmZmZ i Zd„ Z e«       Z G d	„ d
«      Z e«       Zeed<   y)é    N)ÚCallable)ÚPath)ÚFinal)Úverbose_proxy_logger)ÚCustomPromptManagement)Ú
PromptInfoÚPromptLiteLLMParamsÚ
PromptSpecc            	      ó  — i } 	 t        t        «      j                  j                  j                  }t        j                  j                  |d«      }t        j                  j                  |«      st        j                  d«       | S t        j                  |«      D �],  }t        j                  j                  ||«      }t        j                  j                  |«      r|j                  d«      rŒUt        j                  j                  |d«      }t        j                  j                  |«      sŒ•d|› �}	 t        j                  d|«       t        j                  |«      }t        |d«      r[t        |d«      }t!        |t"        «      r?| j%                  |«       t        j                  d|t'        |j)                  «       «      «       �Œ/ t        j                  dt1        | «      t'        | j)                  «       «      «       | S # t*        $ r"}	t        j,                  d	||	«       Y d
}	~	�Œ�d
}	~	wt.        $ r"}	t        j,                  d||	«       Y d
}	~	�Œ¸d
}	~	ww xY w# t.        $ r!}	t        j,                  d|	«       Y d
}	~	| S d
}	~	ww xY w)ax  
    Get prompt initializers by discovering them from the prompt_integrations directory structure.

    Scans the integrations directory for subdirectories containing __init__.py files
    with either prompt_initializer_registry or initialize_prompt functions.

    Returns:
        Dict[str, Callable]: A dictionary mapping guardrail types to their initializer functions
    Úintegrationsz integrations directory not foundÚ__z__init__.pyzlitellm.integrations.z&Discovering prompt integrations in: %sÚprompt_initializer_registryz+Found prompt_initializer_registry in %s: %szCould not import %s: %sNzError processing %s: %sz%Discovered %s prompt initializers: %sz)Error discovering prompt initializers: %s)r   Ú__file__ÚparentÚosÚpathÚjoinÚexistsr   ÚdebugÚlistdirÚisdirÚ
startswithÚ	importlibÚimport_moduleÚhasattrÚgetattrÚ
isinstanceÚdictÚupdateÚlistÚkeysÚImportErrorÚerrorÚ	ExceptionÚlen)
Údiscovered_initializersÚcurrent_dirÚintegrations_dirÚitemÚ	item_pathÚ	init_fileÚmodule_pathÚmoduleÚregistryÚes
             új/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/prompts/prompt_registry.pyÚ(get_prompt_initializer_from_integrationsr1      s  € ð ;=Ðð2Sä!¤(›^×2Ñ2×9Ñ9×@Ñ@ˆÜ"$§'¡'§,¡,¨{¸NÓ"KÐä�w‰w�~‰~Ð.Ô/Ü ×&Ñ&Ð'IÔJØ*Ð*ô —J‘JÐ/Ó0ó !	ˆDÜŸ™Ÿ™Ð%5°tÓ<ˆIô —7‘7—=‘= Ô+¨t¯©¸tÔ/DØô Ÿ™Ÿ™ Y°Ó>ˆIÜ—7‘7—>‘> )Ô,Øà1°$°Ð8ˆKðä$×*Ñ*Ð+SÐU`Ôaä"×0Ñ0°Ó=�ô ˜6Ð#@ÔAÜ& vÐ/LÓM�HÜ! (¬DÔ1Ø/×6Ñ6°xÔ@Ü,×2Ñ2ØIÈ;ÔX\Ð]e×]jÑ]jÓ]lÓXmôùð1!	ôF 	×"Ñ"Ø3´SÐ9PÓ5QÔSWÐXo×XtÑXtÓXvÓSwô	
ð #Ð"øô ò Ü$×*Ñ*Ð+DÀkÐSTÔUÝûÜò Ü$×*Ñ*Ð+DÀkÐSTÔUÝûðûô ò SÜ×"Ñ"Ð#NÐPQ×RÐRà"Ð"ûðSús\   „BI ÂB/I Ä7BHÇ	:I È	IÈH+È%I È+IÈ7IÉI ÉIÉI É	JÉ%JÊJc                   óÞ   — e Zd ZdZd„ Z	 ddededz  dedz  fd„Zdedeee	f   fd„Z
dededz  fd	„Zdededz  fd
„Zdededz  fd„Zdede	dz  fd„Zdeddfd„Zddededz  dee   fd„Zy)ÚInMemoryPromptRegistryzM
    Class that handles adding prompt callbacks to the CallbacksManager.
    c                 ó"   — i | _         	 i | _        y ©N)ÚIN_MEMORY_PROMPTSÚprompt_id_to_custom_prompt)Úselfs    r0   Ú__init__zInMemoryPromptRegistry.__init__]   s    € Ø8:ˆÔð	ð UWˆÔ'ð	ó    NÚpromptÚconfig_file_pathÚreturnc                 ó&  — ddl }|j                  }|| j                  v r$t        j                  d«       | j                  |   S | j                  |¬«      \  }}|j                  j                  |«       || j                  |<   || j                  |<   |S )z¶
        Initialize a guardrail from a dictionary and add it to the litellm callback manager

        Returns a Guardrail object if the guardrail is initialized successfully
        r   Nz-prompt_id already exists in IN_MEMORY_PROMPTS©r;   )	ÚlitellmÚ	prompt_idr6   r   r   Ú_build_prompt_callbackÚlogging_callback_managerÚadd_litellm_callbackr7   )r8   r;   r<   r@   rA   Úparsed_promptÚcustom_prompt_callbacks          r0   Úinitialize_promptz(InMemoryPromptRegistry.initialize_prompth   s—   € ó 	à!×+Ñ+ˆ	Ø˜×.Ñ.Ñ.Ü ×&Ñ&Ð'VÔWØ×)Ñ)¨)Ñ4Ð4à04×0KÑ0KÐSYÐ0KÓ0ZÑ-ˆÐ-Ø×(Ñ(×=Ñ=Ð>TÔUð -:ˆ×Ñ˜yÑ)Ø5Kˆ×'Ñ'¨	Ñ2àÐr:   c           
      ó4  — |j                   }t        j                  d|«       t        |t        «      rt        di |¤Ž}n|}|j                  }|€t        d«      ‚t        j                  |«      }|€t        d|› �«      ‚ |||«      }t        |t        «      st        dt        |«      › �«      ‚t        |j                  ||j                  xs t        d¬«      |j                   |j"                  |j$                  |j&                  |j(                  ¬«      }||fS )	Nzlitellm_params= %szprompt_integration is requiredzUnsupported prompt: z(CustomPromptManagement is required, got Úconfig)Úprompt_type)rA   Úlitellm_paramsÚprompt_infoÚ
created_atÚ
updated_atÚversionÚenvironmentÚ
created_by© )rK   r   r   r   r   r	   Úprompt_integrationÚ
ValueErrorr   Úgetr   Útyper
   rA   rL   r   rM   rN   rO   rP   rQ   )r8   r;   Úlitellm_params_datarK   rS   ÚinitializerrF   rE   s           r0   rB   z-InMemoryPromptRegistry._build_prompt_callback‚   s#  € Ø%+×%:Ñ%:ÐÜ×"Ñ"Ð#7Ð9LÔMäÐ)¬4Ô0Ü0ÑGÐ3FÑG‰Nà0ˆNà$2×$EÑ$EÐØÐ%ÜÐ=Ó>Ð>ä8×<Ñ<Ð=OÓPˆØÐÜÐ3Ð4FÐ3GÐHÓIÐIá(3°NÀFÓ(KÐÜÐ0Ô2HÔIÜØ:¼4Ð@VÓ;WÐ:XÐYóð ô  *Ø×&Ñ&Ø)Ø×*Ñ*ÒN¬jÀXÔ.NØ×(Ñ(Ø×(Ñ(Ø—N‘NØ×*Ñ*Ø×(Ñ(ô	 
ˆð Ð4Ð4Ð4r:   c                 ó¤  — dd l }| j                  |¬«      \  }}| j                  j                  |j                  d «      }| j
                  j                  |j                  d «       |�|j                  j                  |«       |j                  j                  |«       || j
                  |j                  <   || j                  |j                  <   |S )Nr   r?   )	r@   rB   r7   ÚpoprA   r6   rC   Úremove_callback_from_all_listsrD   )r8   r;   r@   rE   Únew_callbackÚstale_callbacks         r0   Úreload_promptz$InMemoryPromptRegistry.reload_prompt¥   s¸   € Ûà&*×&AÑ&AÈÐ&AÓ&PÑ#ˆ�|Ø $× ?Ñ ?× CÑ CÀF×DTÑDTÐVZÓ [ˆØ×Ñ×"Ñ" 6×#3Ñ#3°TÔ:ØÐ%Ø×,Ñ,×KÑKÈNÔ[Ø×(Ñ(×=Ñ=¸lÔKØ3@ˆ×Ñ˜v×/Ñ/Ñ0Ø<Hˆ×'Ñ'¨×(8Ñ(8Ñ9ØÐr:   c                 ó   — | j                   j                  |j                  «      }|€| j                  |¬«      S |j                  |j                  k(  r|j
                  |j
                  k(  r|S | j                  |¬«      S )Nr?   )r6   rU   rA   rG   rK   rL   r^   )r8   r;   Úexistings      r0   Úsync_prompt_from_dbz*InMemoryPromptRegistry.sync_prompt_from_db²   sy   € Ø×0Ñ0×4Ñ4°V×5EÑ5EÓFˆØÐØ×)Ñ)°Ð)Ó8Ð8Ø×"Ñ" f×&;Ñ&;Ò;À×@TÑ@TÐX^×XjÑXjÒ@jØˆOØ×!Ñ!¨Ð!Ó0Ð0r:   rA   c                 ó8   — | j                   j                  |«      S )z4
        Get a prompt by its ID from memory
        )r6   rU   ©r8   rA   s     r0   Úget_prompt_by_idz'InMemoryPromptRegistry.get_prompt_by_idº   s   € ð ×%Ñ%×)Ñ)¨)Ó4Ð4r:   c                 ó8   — | j                   j                  |«      S )z=
        Get a prompt callback by its ID from memory
        )r7   rU   rc   s     r0   Úget_prompt_callback_by_idz0InMemoryPromptRegistry.get_prompt_callback_by_idÀ   s   € ð ×.Ñ.×2Ñ2°9Ó=Ð=r:   c                 ó¸   — dd l }| j                  j                  |d «       | j                  j                  |d «      }|�|j                  j                  |«       y y )Nr   )r@   r6   rZ   r7   rC   r[   )r8   rA   r@   r]   s       r0   Úremove_promptz$InMemoryPromptRegistry.remove_promptÆ   sR   € Ûà×Ñ×"Ñ" 9¨dÔ3Ø $× ?Ñ ?× CÑ CÀIÈtÓ TˆØÐ%Ø×,Ñ,×KÑKÈNÕ[ð &r:   Úbase_prompt_idrP   c                 óâ   — ddl m} | j                  j                  «       D ��cg c]$  \  }} ||¬«      |k(  r|�|j                  |k(  r|‘Œ& }}}|D ]  }| j                  |¬«       Œ |S c c}}w )a–  
        Delete all prompts matching the given base prompt ID from memory, along with their
        registered callbacks; scoped to one environment when given.

        Args:
            base_prompt_id: The base prompt ID (without version suffix)
            environment: When set, only delete prompts deployed to this environment

        Returns:
            List of prompt IDs that were deleted
        r   )Úget_base_prompt_id)rA   )Ú&litellm.proxy.prompts.prompt_endpointsrk   r6   ÚitemsrP   rh   )r8   ri   rP   rk   Úpidr;   Úprompts_to_deletes          r0   Údelete_prompts_by_base_idz0InMemoryPromptRegistry.delete_prompts_by_base_idÎ   sŠ   € õ 	Nð  $×5Ñ5×;Ñ;Ó=÷$
á��VÙ!¨CÔ0°NÒBØÐ$¨×(:Ñ(:¸kÒ(Iò ð$
Ðñ $
ð %ò 	.ˆCØ×Ñ¨ÐÕ-ð	.ð !Ð ùó$
s   ¤)A+r5   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r9   r
   ÚstrrG   Útupler   rB   r^   ra   rd   rf   rh   r    rp   rR   r:   r0   r3   r3   X   sø   „ ñò	ð (,ñàðð  ™*ðð 
�dÑ	ó	ð4!5¨Zð !5¸EÀ*ÐNdÐBdÑ<eó !5ðF Jð °:ÀÑ3Dó ð1¨*ð 1¸ÀdÑ9Jó 1ð5¨#ð 5°*¸tÑ2Có 5ð>°3ð >Ð;QÐTXÑ;Xó >ð\ sð \¨tó \ñ!¸ð !È#ÐPTÉ*ð !Ð`dÐehÑ`iô !r:   r3   ÚIN_MEMORY_PROMPT_REGISTRY)r   r   Úcollections.abcr   Úpathlibr   Útypingr   Úlitellm._loggingr   Ú-litellm.integrations.custom_prompt_managementr   Ú"litellm.types.prompts.init_promptsr   r	   r
   r   r1   r3   rw   Ú__annotations__rR   r:   r0   ú<module>r      s\   ðÜ Û 	Ý $Ý Ý å 1Ý P÷ñ ð !Ð ò@#ñF GÓHÐ ÷N!ñ N!ñb $:Ó#;Ð ˜5Ô ;r:   