
    yj                         d Z ddlmZ ddlmZmZmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZ  G d dee          Z G d	 d
e          Z G d de          Z G d de          Z G d de          Zdedz  dedz  fdZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d e          Z G d! d"e          Z G d# d$e          Z G d% d&e          Z  G d' d(e           Z!dS ))zConfiguration schemas for hierarchical settings resolution.

Covers workspace, session, and message-level configuration as well as
the fully-resolved variants used at runtime.
    )Enum)AnySelfcast)	BaseModel
ConfigDictFieldfield_validatormodel_validator)settings)estimate_tokensc                       e Zd ZdZdZdS )	DreamTypez&Types of dreams that can be triggered.omniN)__name__
__module____qualname____doc__OMNI     A/DATA/AppData/hermes/projects/honcho/src/schemas/configuration.pyr   r      s        00DDDr   r   c                       e Zd ZU  edd          Zedz  ed<    edd          Zedz  ed<    e	d          e
dedz  dedz  fd	                        ZdS )
ReasoningConfigurationNz*Whether to enable reasoning functionality.defaultdescriptionenabledzOptional custom instructions for the reasoning system on this workspace/session/message. Rejected if they exceed the deriver custom-instruction token cap.custom_instructionsvaluereturnc                      t          |          S N$_validate_custom_instructions_budgetclsr    s     r   validate_custom_instructionsz3ReasoningConfiguration.validate_custom_instructions         4E:::r   )r   r   r   r	   r   bool__annotations__r   strr
   classmethodr(   r   r   r   r   r      s          5@  GTD[    ',e q' ' 't   
 _*++;t ;d
 ; ; ; [ ,+; ; ;r   r   c                   d    e Zd ZU  edd          Zedz  ed<    edd          Zedz  ed<   dS )PeerCardConfigurationNzGWhether to use peer card related to this peer during reasoning process.r   usez/Whether to generate peer card based on content.create)r   r   r   r	   r0   r*   r+   r1   r   r   r   r/   r/   &   sz         u]  C     %E  FD4K     r   r/   c                       e Zd ZU  edd          Zedz  ed<    eddd          Zedz  ed<    edd	d
          Z	edz  ed<    e
d          defd            ZdS )SummaryConfigurationNz(Whether to enable summary functionality.r   r   
   z}Number of messages per short summary. Must be positive, greater than or equal to 10, and less than messages_per_long_summary.)r   ger   messages_per_short_summary   zNumber of messages per long summary. Must be positive, greater than or equal to 20, and greater than messages_per_short_summary.messages_per_long_summaryaftermoder!   c                 T    | j         }| j        }||||k    rt          d          | S )z@Validate that short summary threshold <= long summary threshold.NzFmessages_per_short_summary must be less than messages_per_long_summary)r6   r8   
ValueError)selfshortlongs      r   validate_summary_thresholdsz0SummaryConfiguration.validate_summary_thresholdsA   sC     /-!1etmmX   r   )r   r   r   r	   r   r*   r+   r6   intr8   r   r   rA   r   r   r   r3   r3   1   s          5>  GTD[    .3U T. . .d
   
 -2E W- - -sTz    _'"""
T 
 
 
 #"
 
 
r   r3   c                   :    e Zd ZU  edd          Zedz  ed<   dS )DreamConfigurationNzWhether to enable dream functionality. If reasoning is disabled, dreams will also be disabled and this setting will be ignored.r   r   )r   r   r   r	   r   r*   r+   r   r   r   rD   rD   O   sJ          5 V  GTD[     r   rD   r   Nr!   c                     | d S |                                  s| S t          j        j        }|dk    rt	          d          t          |           |k    rt	          d| d          | S )Nr   z7custom_instructions are not enabled for this deploymentzDcustom_instructions exceeds DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS (z tokens))stripr   DERIVERMAX_CUSTOM_INSTRUCTIONS_TOKENSr=   r   )r   
max_tokenss     r   r%   r%   V   s     "t$$&& #""!@JQRSSS*++j88gS]ggg
 
 	
 r   c                       e Zd ZU dZ ed          Z edd          Zedz  e	d<    edd          Z
edz  e	d	<    edd
          Zedz  e	d<    edd          Zedz  e	d<   dS )WorkspaceConfigurationz
    The set of options that can be in a workspace DB-level configuration dictionary.

    All fields are optional. Session-level configuration overrides workspace-level configuration, which overrides global configuration.
    allow)extraN*Configuration for reasoning functionality.r   	reasoningzConfiguration for peer card functionality. If reasoning is disabled, peer cards will also be disabled and these settings will be ignored.	peer_cardz(Configuration for summary functionality.summaryzConfiguration for dream functionality. If reasoning is disabled, dreams will also be disabled and these settings will be ignored.dream)r   r   r   r   r   model_configr	   rO   r   r+   rP   r/   rQ   r3   rR   rD   r   r   r   rK   rK   j   s          :G,,,L/4u@0 0 0I%,    /4e `/ / /I$t+    ,15>, , ,G!D(    (-u X( ( (E$     r   rK   c                       e Zd ZdZdS )SessionConfigurationz
    The set of options that can be in a session DB-level configuration dictionary.

    All fields are optional. Session-level configuration overrides workspace-level configuration, which overrides global configuration.
    N)r   r   r   r   r   r   r   rU   rU      s          	Dr   rU   c                   >    e Zd ZU dZ edd          Zedz  ed<   dS )MessageConfigurationz
    The set of options that can be in a message DB-level configuration dictionary.

    All fields are optional. Message-level configuration overrides all other configurations.
    NrN   r   rO   )r   r   r   r   r	   rO   r   r+   r   r   r   rW   rW      sU           05u@0 0 0I%,     r   rW   c                   |    e Zd ZU eed<   dZedz  ed<    ed          ededz  dedz  fd                        Z	dS )ResolvedReasoningConfigurationr   Nr   r    r!   c                      t          |          S r#   r$   r&   s     r   r(   z;ResolvedReasoningConfiguration.validate_custom_instructions   r)   r   )
r   r   r   r*   r+   r   r,   r
   r-   r(   r   r   r   rY   rY      s~         MMM&*t***_*++;t ;d
 ; ; ; [ ,+; ; ;r   rY   c                   $    e Zd ZU eed<   eed<   dS )ResolvedPeerCardConfigurationr0   r1   Nr   r   r   r*   r+   r   r   r   r\   r\      s"         	IIILLLLLr   r\   c                   .    e Zd ZU eed<   eed<   eed<   dS )ResolvedSummaryConfigurationr   r6   r8   N)r   r   r   r*   r+   rB   r   r   r   r_   r_      s3         MMM ####""""""r   r_   c                       e Zd ZU eed<   dS )ResolvedDreamConfigurationr   Nr]   r   r   r   ra   ra      s         MMMMMr   ra   c                       e Zd ZU dZeed<   eed<   eed<   eed<    e	d          e
ded	efd
                        ZdS )ResolvedConfigurationz
    The final resolved configuration for a given message.
    Hierarchy: message > session > workspace > global configuration
    rO   rP   rQ   rR   beforer:   datar!   c                     t          |t                    s|S t          t          t          t          f         |          }d|v rd|vr|                    d          |d<   |S )z>Handle v3.0.0 migration: 'deriver' was renamed to 'reasoning'.deriverrO   )
isinstancedictr   r,   r   pop)r'   re   configs      r   migrate_deriver_to_reasoningz2ResolvedConfiguration.migrate_deriver_to_reasoning   sb     $%% 	Kd38nd++;f#<#<"(**Y"7"7F;r   N)r   r   r   r   rY   r+   r\   r_   ra   r   r-   r   rl   r   r   r   rc   rc      s          
 .---,,,,))))%%%%_(###
 
 
 
 
 [ $#
 
 
r   rc   c                   :    e Zd ZU  edd          Zedz  ed<   dS )
PeerConfigNzGWhether Honcho will use reasoning to form a representation of this peerr   
observe_me)r   r   r   r	   ro   r*   r+   r   r   r   rn   rn      sG         #e]  Jt     r   rn   c                   :    e Zd ZU  edd          Zedz  ed<   dS )SessionPeerConfigNziWhether this peer should form a session-level theory-of-mind representation of other peers in the sessionr   observe_others)r   r   r   r	   rr   r*   r+   r   r   r   rq   rq      sG         "'%# # #ND4K     r   rq   )"r   enumr   typingr   r   r   pydanticr   r   r	   r
   r   
src.configr   src.utils.tokensr   r,   r   r   r/   r3   rD   r%   rK   rU   rW   rY   r\   r_   ra   rc   rn   rq   r   r   r   <module>rx      s>          " " " " " " " " " " S S S S S S S S S S S S S S       , , , , , ,    T   ; ; ; ; ;Y ; ; ;     I       9   <       t4Z   (    Y   6	 	 	 	 	1 	 	 	
 
 
 
 
9 
 
 
; ; ; ; ;Y ; ; ;    I   
# # # # #9 # # #           I   4           
     r   