
    yjd                     n    d Z ddlmZ ddlmZ ddlmZ  G d de          Z G d de          ZddgZ	d	S )
z
Dream events for Honcho telemetry.

Dream tasks handle memory consolidation through specialist agents (deduction, induction).
Events track both the overall dream run and individual specialist executions,
with run_id correlation for analytics queries.
    )ClassVar)Field)	BaseEventc                   n   e Zd ZU dZdZee         ed<   dZee	         ed<   dZ
ee         ed<    edd	
          Zeed<    edd
          Zeed<    edd
          Zedz  ed<    edd
          Zeed<    edd
          Zeed<    edd
          Zee         ed<    edd
          Zeed<    edd
          Zeed<    edd          Zeed<    edd           Ze	ed!<    edd"
          Ze	ed#<    edd$
          Ze	ed%<    edd&
          Ze	ed'<    edd(
          Zeed)<    edd*          Zedz  ed+<    edd,          Ze	ed-<    edd.          Zedz  ed/<    edd0          Z edz  ed1<    edd2          Z!e	dz  ed3<    edd4          Z"e	dz  ed5<   d6efd7Z#dS )8DreamRunEventa  Emitted when a full dream orchestration completes.

    This is the top-level event for a dream run, providing aggregate metrics
    across all specialists. Individual specialist details are captured in
    DreamSpecialistEvent with the same run_id for correlation.
    z	dream.run_event_type   _schema_versiondream	_category.Nanoid for run correlationdescriptionrun_idWorkspace nameworkspace_nameNzSession name if specifiedsession_nameObserver peer nameobserverObserved peer nameobservedz7Specialists executed (e.g., ['deduction', 'induction'])specialists_runz&Whether deduction specialist succeededdeduction_successz&Whether induction specialist succeededinduction_successFz&Whether surprisal sampling was enableddefaultr   surprisal_enabledr   z High-surprisal conclusions foundsurprisal_conclusion_countz+Total LLM iterations across all specialiststotal_iterationsz)Total input tokens across all specialiststotal_input_tokensz*Total output tokens across all specialiststotal_output_tokenszTotal processing timetotal_duration_mszBDreamType slug (currently 'omni'; future: 'deductive'/'inductive')
dream_typeua   len(settings.DREAM.ENABLED_TYPES) at run start — how many dream types this deploy was producingenabled_types_countzWhat tripped the schedule: 'document_threshold' | 'manual' | 'surprisal'. Captured at schedule time and threaded through the queue payload.trigger_reasonzWhat governed when this dream actually fired: 'idle_timeout' | 'immediate' | 'min_hours_gate'. Disambiguates from trigger_reason to preserve the two-gate scheduler semantics in analytics.delay_reasonu   Document count at the moment check_and_schedule_dream made the decision. Named _at_schedule because the live count changes between schedule and fire (idle delay) — this is the snapshot, not the current value.&documents_since_last_dream_at_schedulez;settings.DREAM.DOCUMENT_THRESHOLD snapshot at schedule timedocument_thresholdreturnc                     | j         S )z)Resource ID is the run_id for uniqueness.)r   selfs    B/DATA/AppData/hermes/projects/honcho/src/telemetry/events/dream.pyget_resource_idzDreamRunEvent.get_resource_idm   s
    {    )$__name__
__module____qualname____doc__r   r   str__annotations__r
   intr   r   r   r   r   r   r   r   listr   boolr   r   r   r   r    r!   r"   floatr#   r$   r%   r&   r'   r(   r.    r/   r-   r   r      s          "-K#,,,%&OXc]&&&&Ix}&&& %)EFFFFCFFF  %1ABBBNCBBB  %uT7RSSSL#*SSS E#+?@@@Hc@@@E#+?@@@Hc@@@ "'R" " "OT#Y    $eA  t    $eA  t   
 $e#K  t    ',eA' ' '   
 "EF  c    $eD       %uE          %uS6MNNNuNNN #UX  Jd
     %uw         "'P" " "NC$J     %uI     L#*    :?L: : :*C$J    &+UQ& & &d
   
      r/   r   c                      e Zd ZU dZdZee         ed<   dZee	         ed<   dZ
ee         ed<    edd	
          Zeed<    edd
          Zeed<    edd
          Zeed<    edd
          Zeed<    edd
          Zeed<    edd
          Ze	ed<    edd
          Ze	ed<    edd
          Ze	ed<    edd
          Ze	ed<    edd
          Zeed<    edd
          Zeed<    ed d!"          Ze	ed#<    ed d$"          Ze	ed%<    eed&'          Zeee	f         ed(<    eed)'          Zeee	f         ed*<    ed+d,"          Zeed-<    ed d."          Ze	ed/<    ed0d1"          Z ed0z  ed2<   d3efd4Z!d0S )5DreamSpecialistEventzEmitted when an individual dream specialist completes.

    Each specialist (deduction, induction) emits its own event with
    the same run_id as the parent DreamRunEvent for correlation.
    zdream.specialistr   r	   r
   r   r   .r   r   r   z+Specialist type: 'deduction' or 'induction'specialist_typer   r   r   r   r   r   zNumber of LLM iterations
iterationszTotal tool calls madetool_calls_countzInput tokens usedinput_tokenszOutput tokens generatedoutput_tokenszProcessing timeduration_msz Whether the specialist succeededsuccessr   ziActual observations created across all create_observations calls (from ToolResult.metadata.created_count)r   created_observation_countziActual observations deleted across all delete_observations calls (from ToolResult.metadata.deleted_count)deleted_observation_countu  Counts of created observations per level (explicit / deductive / inductive / contradiction), aggregated across all create_observations tool calls in this specialist run. Levels with zero count may be omitted; queries should treat missing keys as 0. Dict-of-counts rather than list[str] because dream specialists can produce 10-20+ observations per run — a flat list becomes noisy at that scale.)default_factoryr   created_counts_by_levelzvCounts of deleted observations per level, aggregated across all delete_observations tool calls in this specialist run.deleted_counts_by_levelFz;True when at least one update_peer_card tool call succeededpeer_card_updatedzPNumber of search_memory / search_messages / search_messages_temporal invocationssearch_tool_calls_countNz9Exception class name when success=False; None on success.error_classr)   c                 $    | j          d| j         S )z?Resource ID includes run_id and specialist type for uniqueness.:)r   r=   r+   s    r-   r.   z$DreamSpecialistEvent.get_resource_id   s    +66 4666r/   )"r0   r1   r2   r3   r   r   r4   r5   r
   r6   r   r   r   r=   r   r   r   r>   r?   r@   rA   rB   r9   rC   r8   rD   rE   dictrG   rH   rI   rJ   rK   r.   r:   r/   r-   r<   r<   r   sY          "4K#333%&OXc]&&&&Ix}&&& %)EFFFFCFFF !5F  OS   
  %1ABBBNCBBB E#+?@@@Hc@@@E#+?@@@Hc@@@ eC-GHHHJHHH!E#3JKKKcKKKc/BCCCL#CCCs0IJJJM3JJJs0ABBBKBBBE#+MNNNGTNNN &+U& & &s    &+U& & &s    /4e0/ / /T#s(^    /4eE/ / /T#s(^    $eQ  t    $)5f$ $ $S    $eO  Kt   
7 7 7 7 7 7 7r/   r<   N)
r3   typingr   pydanticr   src.telemetry.events.baser   r   r<   __all__r:   r/   r-   <module>rS      s                 / / / / / /_ _ _ _ _I _ _ _DR7 R7 R7 R7 R79 R7 R7 R7l r/   