
    Xi                       U d 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mZ ddlm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<   	  G d dee      Z G d dee      Z G d dee      Ze G d d             Ze G d d             Ze G d 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%y,)-zRLM Neo-Cortex -- Component Interface Contracts.

All modules import from here. No module imports another module directly.
Cross-module communication goes through these typed protocols.
    )annotations)	dataclassfield)datetime)Enum)AnyDictListOptionalProtocolTuple)UUIDi   intEMBEDDING_DIMg      @floatDEFAULT_DECAY_HALF_LIFEg      ?SURPRISE_THRESHOLDi }  MAX_CONTENT_LENGTHi,  REDIS_TTL_ENTITLEMENTc                       e Zd ZdZdZdZdZdZy)
MemoryTierz,Memory storage tier based on surprise score.discardworkingepisodicsemanticN)__name__
__module____qualname____doc__DISCARDWORKINGEPISODICSEMANTIC     +/mnt/e/genesis-system/core/rlm/contracts.pyr   r   '   s    6GGHHr%   r   c                       e Zd ZdZdZdZdZdZy)CustomerTierz*Subscription tier for billing entitlement.starterprofessional
enterprisequeenN)r   r   r   r   STARTERPROFESSIONAL
ENTERPRISEQUEENr$   r%   r&   r(   r(   /   s    4G!LJEr%   r(   c                      e Zd ZdZdZdZdZy)FeedbackSignalzPreference feedback from user.r      N)r   r   r   r   NEGATIVENEUTRALPOSITIVEr$   r%   r&   r2   r2   7   s    (HGHr%   r2   c                      e Zd ZU dZded<   ded<   ded<   ded<   dZd	ed
<   ej                  Zded<    e	e
      Zded<    e	ej                        Zded<   dZded<   dZded<   y)MemoryRecordz1A single memory item flowing through the gateway.r   	tenant_idstrcontentsourcedomain        r   surprise_scorer   memory_tierdefault_factoryDict[str, Any]metadatar   
created_atNzOptional[str]	vector_idzOptional[int]pg_id)r   r   r   r   __annotations__r@   r   r!   rA   r   dictrE   r   utcnowrF   rG   rH   r$   r%   r&   r9   r9   B   si    ;OLKKNE(00K0$T:Hn: AJA#I}#E=r%   r9   c                      e Zd ZU dZded<   ded<   dZded<   d	Zded
<   dZded<    ee	      Z
ded<    ee      Zded<   y)EntitlementManifestz*Capability manifest for a specific tenant.r   r:   r(   tierd   r   memory_limit_mbi  max_memories_per_daymoderater;   decay_policyrB   z	List[str]allowed_mcp_toolszDict[str, bool]featuresN)r   r   r   r   rI   rP   rQ   rS   r   listrT   rJ   rU   r$   r%   r&   rM   rM   Q   sN    4O
OS ###"L#"#(#>y> %d ;Ho;r%   rM   c                  h    e Zd ZU dZded<   ded<   ded<   dZded<   dZd	ed
<    ee      Z	ded<   y)PreferencePairz*A single preference pair for DPO training.r;   
input_textchosen_outputrejected_outputtelegram_feedbackannotator_idg      ?r   
confidencerB   rD   rE   N)
r   r   r   r   rI   r]   r^   r   rJ   rE   r$   r%   r&   rX   rX   ]   s9    4O+L#+J$T:Hn:r%   rX   c                      e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 ddZ	 d		 	 	 	 	 	 	 d
dZ	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 	 	 ddZy)MemoryGatewayProtocolz&Contract for Module 1: Memory Gateway.Nc                   K   y wNr$   )selfr:   r<   r=   r>   rE   s         r&   write_memoryz"MemoryGatewayProtocol.write_memoryo   s         c                   K   y wrb   r$   )rc   r:   querylimits       r&   read_memoriesz#MemoryGatewayProtocol.read_memoriest   s	      re   c                   K   y wrb   r$   )rc   r:   	memory_ids      r&   delete_memoryz#MemoryGatewayProtocol.delete_memoryx   	     re   c                   K   y wrb   r$   )rc   r:   rg   rh   	min_scores        r&   search_memoriesz%MemoryGatewayProtocol.search_memories|   s      !re   rb   )r:   r   r<   r;   r=   r;   r>   r;   rE   zOptional[Dict[str, Any]]returnr9   )
   )r:   r   rg   r;   rh   r   rq   List[MemoryRecord])r:   r   rk   r;   rq   bool)rr   r?   )
r:   r   rg   r;   rh   r   ro   r   rq   rs   )r   r   r   r   rd   ri   rl   rp   r$   r%   r&   r`   r`   l   s    0 .2(+58BE* 
 9;!!&)!25!	!*-	
 9;!!&)!25!! 
!r%   r`   c                  @    e Zd ZdZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZy)	EntitlementLedgerProtocolz*Contract for Module 2: Entitlement Ledger.c                   K   y wrb   r$   rc   r:   s     r&   get_manifestz&EntitlementLedgerProtocol.get_manifest        re   c                   K   y wrb   r$   )rc   r:   new_tiers      r&   update_tierz%EntitlementLedgerProtocol.update_tier   s	     !re   c                   K   y wrb   r$   )rc   r:   	operations      r&   check_quotaz%EntitlementLedgerProtocol.check_quota   rm   re   N)r:   r   rq   rM   )r:   r   r|   r(   rq   rM   )r:   r   r   r;   rq   rt   )r   r   r   r   ry   r}   r   r$   r%   r&   rv   rv      sB    4M"")5"	"*-	r%   rv   c                  (    e Zd ZdZ	 	 	 	 	 	 	 	 ddZy)SurpriseIntegrationProtocolz,Contract for Module 3: Surprise Integration.c                     y rb   r$   )rc   r<   r=   r>   s       r&   score_contentz)SurpriseIntegrationProtocol.score_content   s    #&r%   N)r<   r;   r=   r;   r>   r;   rq   zTuple[float, MemoryTier])r   r   r   r   r   r$   r%   r&   r   r      s*    6''$''14'	!'r%   r   c                  4    e Zd ZdZ	 d	 	 	 ddZ	 d	 	 	 ddZy)DecaySchedulerProtocolz2Contract for Module 4: Ebbinghaus Decay Scheduler.Nc                   K   y wrb   r$   rx   s     r&   run_decay_cyclez&DecaySchedulerProtocol.run_decay_cycle   	     re   c                   K   y wrb   r$   rx   s     r&   get_decay_statsz&DecaySchedulerProtocol.get_decay_stats   r   re   rb   )r:   Optional[UUID]rq   Dict[str, int])r:   r   rq   rD   )r   r   r   r   r   r   r$   r%   r&   r   r      s9    < +/'	
 +/'	r%   r   c                  6    e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 ddZddZy)FeedbackCollectorProtocolz4Contract for Module 5: Feedback Collection Pipeline.Nc                   K   y wrb   r$   )rc   r:   interaction_idsignalcontexts        r&   record_feedbackz)FeedbackCollectorProtocol.record_feedback   s      re   c                   K   y wrb   r$   )rc   s    r&   get_pair_countz(FeedbackCollectorProtocol.get_pair_count   rz   re   rb   )
r:   r   r   r;   r   r2   r   zOptional[Dict]rq   rX   )rq   r   )r   r   r   r   r   r   r$   r%   r&   r   r      s>    > ;?/2)7 

 /r%   r   c                  N    e Zd ZdZ	 	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZ	 	 	 	 	 	 d	dZy)
TenantPartitionProtocolz+Contract for Module 6: Tenant Partitioning.c                   K   y wrb   r$   )rc   r:   rN   s      r&   create_tenantz%TenantPartitionProtocol.create_tenant   rm   re   c                   K   y wrb   r$   )rc   r:   cryptographic_shreds      r&   delete_tenant_dataz*TenantPartitionProtocol.delete_tenant_data   r   re   c                   K   y wrb   r$   )rc   tenant_atenant_bs      r&   verify_isolationz(TenantPartitionProtocol.verify_isolation   rm   re   N)r:   r   rN   r(   rq   rt   )F)r:   r   r   rt   rq   r   )r   r   r   r   rq   rt   )r   r   r   r   r   r   r   r$   r%   r&   r   r      sb    5%1	
 <A48	(,	r%   r   N)&r   
__future__r   dataclassesr   r   r   enumr   typingr   r	   r
   r   r   r   uuidr   r   rI   r   r   r   r   r;   r   r(   r   r2   r9   rM   rX   r`   rv   r   r   r   r   r$   r%   r&   <module>r      s%  
 # (   = =  s  H!$  $ 1  E   C  C   A  s   :d 3 S$        < < < ; ; ;!H !, '( '	X 	/ /h r%   