
    epj                    h    d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 e G d d                      ZdS )u-  Per-turn context shared between ``GatewayRunner._run_agent_inner`` and the
``TurnRunner`` collaborator (gateway/run.py).

``_run_agent_inner`` historically defined its tool-progress plumbing as nested
closures (``progress_callback`` ~250 LOC, ``send_progress_messages`` ~353 LOC)
that closed over ~20 enclosing locals.  ``TurnContext`` is the extraction seam:
each closed-over local becomes a field on this dataclass, so the closure bodies
can move onto ``TurnRunner`` methods unchanged modulo ``name`` -> ``ctx.name``
rewrites.

Field notes:

- All fields are written once by ``_run_agent_inner`` while wiring up the turn
  (a few — ``_progress_metadata``, ``_progress_reply_to``, ``agent_holder`` —
  are computed slightly later than construction and assigned onto the ctx as
  soon as the original locals were bound).  None of the original closures
  *rebound* their captured names (no ``nonlocal``); mutable state uses the
  same single-element-list containers as before (``last_progress_msg``,
  ``repeat_count``, ...), so mutation stays visible to the outer body through
  the shared objects exactly as it did through the shared closure cells.
- ``_run_still_current`` stays a callable (it captures ``self``/
  ``session_key``/``run_generation``); carrying the callable keeps the
  extracted bodies byte-identical.
    )annotations)	dataclassfield)AnyCallableListOptionalc                     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<    ed           Zded<    ed           Zded<    ed           Zded<    ed           Zded<    ed           Zded<    ed            Zded!<   d"Zd#ed$<   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d0<   dZ d,ed1<   dZ!d,ed2<   dZ"d3ed4<   d5Z#d	ed6<    ee$          Z%d7ed8<   d9Z&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dA<   dZ,dedB<   dZ-dedC<   dZ.dedD<   dZ/dedE<   dZ0dedF<   dZ1dedG<   dZ2dedH<    edI           Z3dedJ<    edK           Z4dedL<    edM           Z5dedN<    edO           Z6dedP<    edQ           Z7dedR<    edS           Z8dedT<   dZ9dedU<   dZ:dedV<   dZ;dedW<   dZ<dedX<   dZ=dedY<   dZ>d(edZ<   dZ?d[ed\<   dZ@d[ed]<   dZAd[ed^<   dZBd[ed_<   dZCd[ed`<   dS )aTurnContextzDClosed-over locals of ``_run_agent_inner`` needed by ``TurnRunner``.Nr   sourcezCallable[[], bool]_run_still_current_live_status_adapteroffstr_live_status_modeFbool_thinking_enabledprogress_modegroupedprogress_groupingtool_progress_enabledprogress_queue	log_queuec                     d gS N r       :/home/thesage/.hermes/hermes-agent/gateway/turn_context.py<lambda>zTurnContext.<lambda>3   s    TF r   )default_factorylistlast_progress_msgc                     d gS r   r   r   r   r   r   zTurnContext.<lambda>4   s    TF r   	last_toolc                     dgS NFr   r   r   r   r   zTurnContext.<lambda>5   s    5' r   last_was_terminal_blockc                     dgS )Nr   r   r   r   r   r   zTurnContext.<lambda>6   s    s r   repeat_countc                     dgS r&   r   r   r   r   r   zTurnContext.<lambda>7   s    w r   long_tool_hint_firedc                     d gS r   r   r   r   r   r   zTurnContext.<lambda>8       v r   agent_holderg      >@float_LONG_TOOL_THRESHOLD_S_cleanup_progressz	List[str]_cleanup_msg_idszOptional[dict]_progress_metadatazOptional[Any]_progress_reply_tozOptional[str]messagehistorycontext_promptchannel_prompt
session_idsession_keyzOptional[int]run_generation process_task_idzfrozenset[str]process_baseliner   int_interrupt_depthevent_message_id
moa_configpersist_user_messagezOptional[float]persist_user_timestampuser_configenabled_toolsetsdisabled_toolsetslog_mode_enabled"interim_assistant_messages_enabledneeds_progress_queueAIAgentresolve_display_settingc                     d gS r   r   r   r   r   r   zTurnContext.<lambda>k   s     r   result_holderc                     d gS r   r   r   r   r   r   zTurnContext.<lambda>l   r-   r   tools_holderc                     d gS r   r   r   r   r   r   zTurnContext.<lambda>m   s    $ r   stream_consumer_holderc                     d gS r   r   r   r   r   r   zTurnContext.<lambda>n   s     r   streaming_tts_consumer_holderc                     dgS r&   r   r   r   r   r   zTurnContext.<lambda>q   s    E7 r   _voice_ack_firedc                     d gS r   r   r   r   r   r   zTurnContext.<lambda>r   s    D6 r   _voice_ack_guild_voice_ack_loop_loop_for_step
_hooks_ref_status_adapter_status_chat_id_status_thread_metadatazOptional[Callable]progress_callbackvoice_ack_callback_step_callback_sync_event_callback_sync_status_callback_sync)D__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r   r   r   r   r"   r$   r'   r)   r+   r.   r0   r1   r!   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r=   	frozensetr>   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rN   rP   rR   rT   rV   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   r   r   r   r   r       s        NN F-11111 $$$$$"""""#####M&&&&&"''''' NI $eNNCCCCCCCeNN;;;I;;;;$)E//$J$J$JJJJJ{{;;;L;;;;!&!G!G!GGGGG~~>>>L>>>> %)((((#####"'%"="="===== *.----(,,,,, "G!!!! G$(N(((($(N(((( $J$$$$!%K%%%%$(N((((O',uY'G'G'GGGGG&*****!%J%%%%*......22222K     !!!!!"""""/4&4444!&&&&& G#'''''  %???M????~~>>>L>>>>#(5#H#H#HHHHH*/%*O*O*O!OOOO #U??CCCCCCC"U>>BBBBBBBO NJOO.22222
 -10000-11111.22222/3333304444444r   r   N)rg   
__future__r   dataclassesr   r   typingr   r   r   r	   r   r   r   r   <module>rm      s    2 # " " " " " ( ( ( ( ( ( ( ( 0 0 0 0 0 0 0 0 0 0 0 0 b5 b5 b5 b5 b5 b5 b5 b5 b5 b5r   