
    b\jp                       S SK Jr  S SKJrJrJrJrJrJr  S SK	J	r	  S SK
Jr  S SKJr  S SKr\(       a  S SKJr  SS	KJr  SS
KJrJr  SSKJr  SSKJrJrJrJrJrJrJrJ r   SSK!J"r"J#r#J$r$J%r%J&r&  SSK'J(r(  SSK)J*r*J+r+  SSK,J-r-J.r.  SSK/J0r0J1r1  SSK2J3r3J4r4  SSK5J6r6J7r7  SSK8J9r9J:r:J;r;  SSK<J=r=  SSK>J?r?  SSK@JArA  SSKBJCrC  SSKDJErE  SSKFJGrG  SS/rH " S S\*5      rI " S S\+5      rJ " S S 5      rK " S! S"5      rL " S# S$5      rM " S% S&5      rNg)'    )annotations)TYPE_CHECKINGAnyListUnionIterablecast)datetime)chain)LiteralN)Sequence   )AsyncAnthropic)SessionToolRunnerBetaAnyRunnableTool)_legacy_response)BodyOmitQueryHeadersNotGivenSequenceNotStromit	not_given)is_givenpath_templatemaybe_transformstrip_not_givenasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)StreamAsyncStream)SyncPageCursorAsyncPageCursor)AsyncPaginatormake_request_options)event_list_paramsevent_send_paramsevent_stream_params)AnthropicBetaParam)BetaManagedAgentsDeltaType)BetaManagedAgentsEventParams)BetaManagedAgentsSessionEvent)"BetaManagedAgentsSendSessionEvents)$BetaManagedAgentsStreamSessionEventsEventsAsyncEventsc                     \ rS rSr\SS j5       r\SS j5       r\\\\\\\\\SSS\S.                             SS jjr	\SSS\S.               SS jjr
\\SSS\S	.               SS
 jjrSrg)r4   &   c                    [        U 5      $ z
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.

For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
)EventsWithRawResponseselfs    ^/var/www/website/venv/lib/python3.13/site-packages/anthropic/resources/beta/sessions/events.pywith_raw_responseEvents.with_raw_response'   s     %T**    c                    [        U 5      $ z
An alternative to `.with_raw_response` that doesn't eagerly read the response body.

For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
)EventsWithStreamingResponser;   s    r=   with_streaming_responseEvents.with_streaming_response1   s     +400r@   Ncreated_at_gtcreated_at_gtecreated_at_ltcreated_at_ltelimitorderpagetypesbetasextra_headersextra_query
extra_bodytimeoutc                  U(       d  [        SU< 35      e0 [        S[        U
5      (       a#  SR                  [	        S U
 5       S/5      5      O[
        05      EU=(       d    0 EnSS0U=(       d    0 EnU R                  [        SUS9[        [           [        UUUU[        UUUUUUUU	S.[        R                  5      S	9[        [        [        5      S
9$ )  
List Events

Args:
  created_at_gt: Return events created after this time (exclusive).

  created_at_gte: Return events created at or after this time (inclusive).

  created_at_lt: Return events created before this time (exclusive).

  created_at_lte: Return events created at or before this time (inclusive).

  limit: Query parameter for limit

  order: Sort direction for results, ordered by created_at. Defaults to asc
      (chronological).

  page: Opaque pagination cursor from a previous response's next_page.

  types: Filter by event type. Values match the `type` field on returned events (for
      example, `user.message` or `agent.tool_use`). Omit to return all event types.

  betas: Optional header to specify the beta version(s) you want to use.

  extra_headers: Send extra headers

  extra_query: Add additional query parameters to the request

  extra_body: Add additional JSON properties to the request

  timeout: Override the client-level default timeout for this request, in seconds
9Expected a non-empty value for `session_id` but received anthropic-beta,c              3  8   #    U  H  n[        U5      v   M     g 7fNstr.0es     r=   	<genexpr>Events.list.<locals>.<genexpr>s        5Lec!ffe   managed-agents-2026-04-01*/v1/sessions/{session_id}/events?beta=true
session_idrG   rH   rI   rJ   rK   rL   rM   rN   rP   rQ   rR   rS   queryrM   optionsmodel)
ValueErrorr   r   joinr   r   _get_api_listr   r'   r1   r*   r   r+   EventListParamsr	   r   r<   rg   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   s                  r=   listEvents.list:   s   h XYcXfghh	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`!!FS]^ =>(+'%%)6*8)6*8!&!& $!&	 &55& 2- " 
 	
r@   rO   rP   rQ   rR   rS   c               n   U(       d  [        SU< 35      e0 [        S[        U5      (       a#  SR                  [	        S U 5       S/5      5      O[
        05      EU=(       d    0 EnSS0U=(       d    0 EnU R                  [        SUS9[        SU0[        R                  5      [        XEXgS	9[        S
9$ )}  
Send Events

Args:
  events: Events to send to the `session`.

  betas: Optional header to specify the beta version(s) you want to use.

  extra_headers: Send extra headers

  extra_query: Add additional query parameters to the request

  extra_body: Add additional JSON properties to the request

  timeout: Override the client-level default timeout for this request, in seconds
rV   rW   rX   c              3  8   #    U  H  n[        U5      v   M     g 7frZ   r[   r]   s     r=   r`   Events.send.<locals>.<genexpr>   rb   rc   rd   re   rf   eventsrP   rQ   rR   rS   bodyrl   cast_to)rn   r   r   ro   r   r   _postr   r   r,   EventSendParamsr*   r2   r<   rg   rz   rO   rP   rQ   rR   rS   s           r=   sendEvents.send   s    : XYcXfghh	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`zzFS]^ (F!35F5V5VW(+Q[ 7  
 	
r@   event_deltasrO   rP   rQ   rR   rS   c                  U(       d  [        SU< 35      e0 [        S[        U5      (       a#  SR                  [	        S U 5       S/5      5      O[
        05      EU=(       d    0 EnSS0U=(       d    0 EnU R                  [        SUS9[        UUUU[        SU0[        R                  5      S	9[        [        [        5      S
[        [           S9$ )M  
Stream Events

Args:
  event_deltas: When set, this connection also receives streaming deltas (`event_start`,
      `event_delta`) while an event is being produced, before the event itself
      arrives. Deltas are best-effort; when the final event is produced it carries the
      complete content. A model request that ends early (an error or interrupt)
      produces no final event — its terminal `span.model_request_end` closes the
      preview. Accepts one or more event types to preview and may be repeated:
      `agent.message` streams `content_delta` fragments; `agent.thinking` is
      start-only — a signal that the agent has begun extended thinking, concluded by
      the `agent.thinking` event itself. Only previews of the requested event types
      are sent.

  betas: Optional header to specify the beta version(s) you want to use.

  extra_headers: Send extra headers

  extra_query: Add additional query parameters to the request

  extra_body: Add additional JSON properties to the request

  timeout: Override the client-level default timeout for this request, in seconds
rV   rW   rX   c              3  8   #    U  H  n[        U5      v   M     g 7frZ   r[   r]   s     r=   r`    Events.stream.<locals>.<genexpr>   rb   rc   rd   1/v1/sessions/{session_id}/events/stream?beta=truerf   r   ri   Trl   r~   stream
stream_cls)rn   r   r   ro   r   r   _getr   r*   r   r-   EventStreamParamsr	   r   r3   r%   r<   rg   r   rO   rP   rQ   rR   rS   s           r=   r   Events.stream   s    L XYcXfghh	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`yyMZde(+'%%~|&DFYFkFkl 9 BC  
 	
r@    )returnr:   )r   rC   )rg   r\   rG   Union[str, datetime] | OmitrH   r   rI   r   rJ   r   rK   
int | OmitrL   Literal['asc', 'desc'] | OmitrM   
str | OmitrN   SequenceNotStr[str] | OmitrO   List[AnthropicBetaParam] | OmitrP   Headers | NonerQ   Query | NonerR   Body | NonerS   'float | httpx.Timeout | None | NotGivenr   z-SyncPageCursor[BetaManagedAgentsSessionEvent]rg   r\   rz   z&Iterable[BetaManagedAgentsEventParams]rO   r   rP   r   rQ   r   rR   r   rS   r   r   r2   )rg   r\   r   'List[BetaManagedAgentsDeltaType] | OmitrO   r   rP   r   rQ   r   rR   r   rS   r   r   z,Stream[BetaManagedAgentsStreamSessionEvents])__name__
__module____qualname____firstlineno__r    r>   rD   r   r   rs   r   r   __static_attributes__r   r@   r=   r4   r4   &   s   + + 1 1 6:6:596: /3,015 )-$("&;D%Z
Z
 3	Z

 4Z
 3Z
 4Z
 Z
 -Z
 Z
 *Z
 /Z
 &Z
  "!Z
"  #Z
$ 9%Z
& 
7'Z
B 26 )-$("&;D1
1
 7	1

 /1
 &1
 "1
  1
 91
 
,1
n AE15 )-$("&;DA
A
 >	A

 /A
 &A
 "A
  A
 9A
 
6A
 A
r@   c                  >   \ rS rSr\SS j5       r\SS j5       r\\\\\\\\\SSS\S.                             SS jjr	\SSS\S.               SS jjr
\\SSS\S	.               SS
 jjr\SSS.           SS jjrSrg)r5   i  c                    [        U 5      $ r9   )AsyncEventsWithRawResponser;   s    r=   r>   AsyncEvents.with_raw_response  s     *$//r@   c                    [        U 5      $ rB   ) AsyncEventsWithStreamingResponser;   s    r=   rD   #AsyncEvents.with_streaming_response  s     055r@   NrF   c                  U(       d  [        SU< 35      e0 [        S[        U
5      (       a#  SR                  [	        S U
 5       S/5      5      O[
        05      EU=(       d    0 EnSS0U=(       d    0 EnU R                  [        SUS9[        [           [        UUUU[        UUUUUUUU	S.[        R                  5      S	9[        [        [        5      S
9$ )rU   rV   rW   rX   c              3  8   #    U  H  n[        U5      v   M     g 7frZ   r[   r]   s     r=   r`   #AsyncEvents.list.<locals>.<genexpr>Z  rb   rc   rd   re   rf   rh   ri   rk   )rn   r   r   ro   r   r   rp   r   r(   r1   r*   r   r+   rq   r	   r   rr   s                  r=   rs   AsyncEvents.list!  s   h XYcXfghh	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`!!FS]^ !>?(+'%%)6*8)6*8!&!& $!&	 &55& 2- " 
 	
r@   ru   c                 #    U(       d  [        SU< 35      e0 [        S[        U5      (       a#  SR                  [	        S U 5       S/5      5      O[
        05      EU=(       d    0 EnSS0U=(       d    0 EnU R                  [        SUS9[        SU0[        R                  5      I S	h  vN [        XEXgS
9[        S9I S	h  vN $  N N7f)rw   rV   rW   rX   c              3  8   #    U  H  n[        U5      v   M     g 7frZ   r[   r]   s     r=   r`   #AsyncEvents.send.<locals>.<genexpr>  rb   rc   rd   re   rf   rz   Nr{   r|   )rn   r   r   ro   r   r   r   r   r   r,   r   r*   r2   r   s           r=   r   AsyncEvents.send}  s     : XYcXfghh	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`ZZFS]^,h-?ARAbAbcc(+Q[ 7   
 
 	
c
s$   B*C,C	
-CCCCr   c                 #    U(       d  [        SU< 35      e0 [        S[        U5      (       a#  SR                  [	        S U 5       S/5      5      O[
        05      EU=(       d    0 EnSS0U=(       d    0 EnU R                  [        SUS9[        UUUU[        SU0[        R                  5      I S	h  vN S
9[        [        [        5      S[        [           S9I S	h  vN $  N0 N7f)r   rV   rW   rX   c              3  8   #    U  H  n[        U5      v   M     g 7frZ   r[   r]   s     r=   r`   %AsyncEvents.stream.<locals>.<genexpr>  rb   rc   rd   r   rf   r   Nri   Tr   )rn   r   r   ro   r   r   r   r   r*   r   r-   r   r	   r   r3   r&   r   s           r=   r   AsyncEvents.stream  s    L XYcXfghh	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`YYMZde(+'%1#\24G4Y4Y  9 "#GH  
 
 	

s$   B3C*5C&6+C*!C("C*(C*)max_idleenvironment_keyrP   c          	     t    SSK JnJn  [        U5      (       d  UnU" [	        SU R
                  5      UUUUUS9$ )u:  Dispatch a self-hosted session's tool-call events.

The sessions-side counterpart to ``client.beta.messages.tool_runner``:
returns a :class:`~anthropic.lib.environments.SessionToolRunner` — an
async iterable that attaches to the session's event stream, reconciles
against the events-list endpoint, runs the matching tool from ``tools``
for each tool-call event, posts the matching result event back, and
yields one :class:`~anthropic.lib.environments.DispatchedToolCall` per
completed call. It handles both tool-call kinds: ``agent.tool_use``
(built-in agent-toolset tools) answered with ``user.tool_result``, and
``agent.custom_tool_use`` (custom, user-defined tools) answered with
``user.custom_tool_result``. A call the server gated behind user
confirmation (``evaluated_permission`` ``ask``, e.g. a tool configured
with the ``always_ask`` permission policy) is held until the matching
``user.tool_confirmation`` event arrives — executed on ``allow``,
never executed on ``deny`` (the denied call is still yielded with
``confirmation="deny"`` so it can be observed). Internally drives
event-stream reconnect (with capped backoff) via an anyio task group
so it works under both ``asyncio`` and ``trio``.

Iteration ends when the session terminates (``session.status_terminated``
/ ``session.deleted``), when the consumer breaks out of the loop, or —
once the session has gone idle with ``stop_reason`` ``end_turn`` —
``max_idle`` seconds elapse with no new event (any new event resets that
countdown; it re-arms on the next ``end_turn`` idle). ``max_idle=None``
disables that last condition. It does **not** touch the work-item lease —
wrap it in an :class:`~anthropic.lib.environments.EnvironmentWorker` if
you need heartbeating / force-stop.

Usage::

    from anthropic.lib.tools.agent_toolset import AgentToolContext, beta_agent_toolset_20260401

    async with AgentToolContext(workdir=...) as env:
        async for call in client.beta.sessions.events.tool_runner(
            work.data.id,
            tools=[*beta_agent_toolset_20260401(env), my_tool],
        ):
            ...

Args:
  session_id: The session whose events stream we attach to. Passed
    positionally, matching ``list`` / ``send`` / ``stream`` on this
    resource.
  tools: Registry of tool callables the runner will execute when the
    agent emits matching ``agent.tool_use`` / ``agent.custom_tool_use``
    events — the same :class:`~anthropic.lib.tools.BetaAsyncFunctionTool`
    shape ``client.beta.messages.tool_runner`` accepts.
  max_idle: Seconds to keep running after the session goes idle with
    ``stop_reason`` ``end_turn`` before stopping; any new event resets
    the countdown. Defaults to ``DEFAULT_MAX_IDLE`` (60s) when not
    given. ``None`` disables it.
  environment_key: The self-hosted environment key. When set, the
    runner builds a Bearer-only scoped sub-client keyed to that
    environment for the event stream / list / send calls; leave it
    unset to authenticate those calls with the parent client's own
    credentials.
  extra_headers: Optional headers passed through per request on every
    call the runner makes (event stream / list / send). They are
    threaded into each call's ``extra_headers=`` and never assigned
    onto the client, so client state is not mutated. Auth and
    ``x-stainless-helper`` are supplied by the runner's scoped
    sub-client (and the parent client's ``default_headers`` propagate
    via its ``client.copy()``); a header given here overrides the
    scoped client's same-named default for that request, so use it for
    caller passthrough (e.g. trace ids), not to set auth.
r   )DEFAULT_MAX_IDLEr   r   )toolsr   r   rP   )lib.tools._beta_session_runnerr   r   r   r	   _client)r<   rg   r   r   r   rP   r   r   s           r=   tool_runnerAsyncEvents.tool_runner  sD    ^ 	[!!'H !4<<0+'
 	
r@   r   )r   r   )r   r   )rg   r\   rG   r   rH   r   rI   r   rJ   r   rK   r   rL   r   rM   r   rN   r   rO   r   rP   r   rQ   r   rR   r   rS   r   r   z]AsyncPaginator[BetaManagedAgentsSessionEvent, AsyncPageCursor[BetaManagedAgentsSessionEvent]]r   )rg   r\   r   r   rO   r   rP   r   rQ   r   rR   r   rS   r   r   z1AsyncStream[BetaManagedAgentsStreamSessionEvents])rg   r\   r   zSequence[BetaAnyRunnableTool]r   zfloat | None | NotGivenr   z
str | NonerP   r   r   r   )r   r   r   r   r    r>   rD   r   r   rs   r   r   r   r   r   r@   r=   r5   r5     s1   0 0 6 6 6:6:596: /3,015 )-$("&;D%Z
Z
 3	Z

 4Z
 3Z
 4Z
 Z
 -Z
 Z
 *Z
 /Z
 &Z
  "!Z
"  #Z
$ 9%Z
& 
g'Z
B 26 )-$("&;D1
1
 7	1

 /1
 &1
 "1
  1
 91
 
,1
n AE15 )-$("&;DC
C
 >	C

 /C
 &C
 "C
  C
 9C
 
;C
T -6&*(,[
[
 -	[

 *[
 $[
 &[
 
[
 [
r@   c                      \ rS rSrSS jrSrg)r:   iS  c                    Xl         [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR
                  5      U l        g rZ   )_eventsr   to_raw_response_wrapperrs   r   r   r<   rz   s     r=   __init__EventsWithRawResponse.__init__T  sV    $<<KK
	 %<<KK
	 '>>MM
r@   r   rs   r   r   Nrz   r4   r   Noner   r   r   r   r   r   r   r@   r=   r:   r:   S      
r@   r:   c                      \ rS rSrSS jrSrg)r   ib  c                    Xl         [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR
                  5      U l        g rZ   )r   r   async_to_raw_response_wrapperrs   r   r   r   s     r=   r   #AsyncEventsWithRawResponse.__init__c  sV    $BBKK
	 %BBKK
	 'DDMM
r@   r   Nrz   r5   r   r   r   r   r@   r=   r   r   b  r   r@   r   c                      \ rS rSrSS jrSrg)rC   iq  c                    Xl         [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l        g rZ   )r   r#   rs   r   r   r   s     r=   r   $EventsWithStreamingResponse.__init__r  sD    0KK
	 1KK
	 3MM
r@   r   Nr   r   r   r@   r=   rC   rC   q  r   r@   rC   c                      \ rS rSrSS jrSrg)r   i  c                    Xl         [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l        g rZ   )r   r$   rs   r   r   r   s     r=   r   )AsyncEventsWithStreamingResponse.__init__  sD    6KK
	 7KK
	 9MM
r@   r   Nr   r   r   r@   r=   r   r     r   r@   r   )O
__future__r   typingr   r   r   r   r   r	   r
   	itertoolsr   typing_extensionsr   httpxcollections.abcr   r   r   r   r   r    r   _typesr   r   r   r   r   r   r   r   _utilsr   r   r   r   r   _compatr    	_resourcer!   r"   	_responser#   r$   
_streamingr%   r&   
paginationr'   r(   _base_clientr)   r*   types.beta.sessionsr+   r,   r-   types.anthropic_beta_paramr.   )types.beta.beta_managed_agents_delta_typer/   4types.beta.sessions.beta_managed_agents_event_paramsr0   5types.beta.sessions.beta_managed_agents_session_eventr1   ;types.beta.sessions.beta_managed_agents_send_session_eventsr2   =types.beta.sessions.beta_managed_agents_stream_session_eventsr3   __all__r4   r5   r:   r   rC   r   r   r@   r=   <module>r      s    # B B   % (*Y ! \ \ \ g g ' ; Z . : A ] ] = T a c n r]
#d
_ d
NC
" C
L

 

 

 

 
r@   