
    b\j                       % S SK Jr  S SKJrJr  S SKJrJr  S SKJrJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJrJr  S
S/r\rS\S
'   \" SSS\R,                  S9r\      SS j5       r\      SS j5       r      SS jrg)    )annotations)TYPE_CHECKINGoverload)datetimetimezone)	TypeAliasassert_never   )
model_copy)build)AnthropicError)"BetaManagedAgentsAgentMessageEvent$BetaManagedAgentsStreamSessionEventsAccumulatedEventaccumulate_managed_agents_eventr   i     )tzinfoc                    g N accumulatedevents     X/var/www/website/venv/lib/python3.13/site-packages/anthropic/lib/sessions/_accumulate.pyr   r      s     *-    c                    g r   r   r   s     r   r   r      s     "r   c                   UR                   S:X  a  UR                  R                   S:X  a)  [        [        UR                  R                  S/ [
        S9$ UR                  R                   S:X  a  U $ [        (       a  [        UR                  5        U $ UR                   S:X  a
  [        USS9$ UR                   S:X  GaO  U c  [        SUR                   S	35      eUR                  R                  nUc  S
nUR                  R                  nU[        U R                  5      :  a%  [        SU S[        U R                  5       S35      e[        U R                  5      nU[        U5      :X  a  UR!                  [        U5      5        OrXB   nUR                   S:X  a>  UR                   S:X  a-  [        U5      nUR"                  UR"                  -   Ul        XdU'   O [        (       a  [        UR                   5        [        U 5      nXGl        U$ UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gd  UR                   S:X  Gdw  UR                   S:X  Gdf  UR                   S:X  GdU  UR                   S:X  GdD  UR                   S:X  Gd3  UR                   S:X  Gd"  UR                   S:X  Gd  UR                   S:X  Gd   UR                   S:X  d  UR                   S :X  d  UR                   S!:X  d  UR                   S":X  d  UR                   S#:X  d  UR                   S$:X  d  UR                   S%:X  d  UR                   S&:X  d  UR                   S':X  dp  UR                   S(:X  d`  UR                   S):X  dP  UR                   S*:X  d@  UR                   S+:X  d0  UR                   S,:X  d   UR                   S-:X  d  UR                   S.:X  a  U $ [        (       a  [        U5        U $ )/ug  Fold one preview event into an ``agent.message`` snapshot. Returns a fresh
snapshot — the ``accumulated`` argument is never mutated.

- ``event_start`` opens the preview: a new snapshot with empty content is
  returned (so ``accumulated`` may be ``None``). Its ``processed_at`` is an
  epoch placeholder that the buffered final event's server timestamp
  replaces. ``accumulated`` is passed through unchanged when the
  previewed event is not an ``agent.message`` — this helper only tracks
  ``agent.message`` previews.
- ``event_delta`` is folded into ``accumulated``: a new ``delta.index``
  inserts the fragment as a fresh content entry; an existing index returns
  a copy with that entry appended to. An unrecognised fragment type on an
  existing index passes the entry through unchanged — deltas are
  best-effort and the buffered final event is canonical — but is a
  type-check-time error via the exhaustiveness guard, matching
  ``accumulate_event`` in ``lib/streaming/_messages.py``.
- ``agent.message`` is the buffered final event: a copy of it is returned,
  replacing whatever the preview had accumulated.
event_startzagent.message)idtypecontentprocessed_atzagent.thinkingT)deepevent_deltazevent_delta for z  received before its event_startr   zevent_delta index z& is beyond the end of content (length )textzuser.messagezuser.interruptzuser.tool_confirmationzuser.tool_resultzuser.custom_tool_resultzuser.define_outcomezagent.tool_usezagent.tool_resultzagent.custom_tool_usezagent.mcp_tool_usezagent.mcp_tool_resultzagent.thread_message_receivedzagent.thread_message_sentzagent.thread_context_compactedzsession.errorzsession.updatedzsession.deletedzsession.status_runningzsession.status_idlezsession.status_rescheduledzsession.status_terminatedzsession.thread_createdzsession.thread_status_runningzsession.thread_status_idlez!session.thread_status_rescheduledz session.thread_status_terminatedzspan.model_request_startzspan.model_request_endzspan.outcome_evaluation_startzspan.outcome_evaluation_ongoingzspan.outcome_evaluation_endzsystem.message)r    r   r   r   r   _UNPROCESSEDr   r	   r   r   event_iddeltaindexr!   lenlistappendr&   )r   r   idxfragmentr!   existingupdatedsnapshots           r   r   r   #   s   . zz]";;.2;;>>$)  [[!11  }U[[)		&%d++	}	$ #3ENN3CCc!deekk;C;;&& [(()) $SE)OPST_TgTgPhOiijk  {**+#g,NN:h/0|H}}&==F*(2G#+==8==#@GL#*CL != /k*" 	

n$::))::11::++::22::..::))::))::,,::00::--::00::88::44::99::(::**::**::11::..::55::44::11::88::55::<<::;;::33::11::88::::::66::)) =r   N)r   AccumulatedEvent | Noner   r   returnr   )r   r3   r   r   r4   r3   )
__future__r   typingr   r   r   r   typing_extensionsr   r	   _compatr   _modelsr   _exceptionsr   types.beta.sessionsr   r   __all__r   __annotations__utcr'   r   r   r   r   <module>r?      s    " * ' 5 !  ) k@
A@ ) @ a8<<8 
-(--- (- 
- 
"("/" " 
"y(y/y yr   