
    b\j                       S SK Jr  S SKrS SKJrJrJrJr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  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+J,r,J-r-  SSK.J/r/J0r0  SSK1J2r2J3r3J4r4J5r5J6r6  SSK7J8r8  SSK9J:r:  SSK;J<r<  SSK=J>r>  SS/r? " S S\&5      r@ " S S\'5      rA " S S5      rB " S S5      rC " S S5      rD " S  S!5      rEg)"    )annotationsN)TYPE_CHECKINGDictListOptionalcast)chain)AsyncIterator   )AsyncAnthropic)EnvironmentWorkerEnvironmentWorkerTools)_legacy_response)BodyOmitQueryHeadersNotGiven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)SyncPageCursorAsyncPageCursor)AsyncPaginatormake_request_options)work_list_paramswork_poll_paramswork_stop_paramswork_update_paramswork_heartbeat_params)AnthropicBetaParam)BetaSelfHostedWork)BetaSelfHostedWorkQueueStats)#BetaSelfHostedWorkHeartbeatResponseWork	AsyncWorkc            	      $   \ 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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S jjr\\SSS\S.                 SS jjrSrg)r.   (   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
)WorkWithRawResponseselfs    `/var/www/website/venv/lib/python3.13/site-packages/anthropic/resources/beta/environments/work.pywith_raw_responseWork.with_raw_response)   s     #4((    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
)WorkWithStreamingResponser5   s    r7   with_streaming_responseWork.with_streaming_response3   s     )..r:   Nbetasextra_headersextra_query
extra_bodytimeoutc          
     f   U(       d  [        SU< 35      e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US9[        XEXgS	9[        S
9$ )  
Note: these endpoints are called automatically by the pre-built environment
worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted
sandbox environments. They are included here as a reference; you do not need to
invoke them directly.

Retrieve detailed information about a specific work item.

Args:
  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
=Expected a non-empty value for `environment_id` but received 6Expected a non-empty value for `work_id` but received anthropic-beta,c              3  8   #    U  H  n[        U5      v   M     g 7fNstr.0es     r7   	<genexpr> Work.retrieve.<locals>.<genexpr>c        5Lec!ffe   managed-agents-2026-04-01:/v1/environments/{environment_id}/work/{work_id}?beta=trueenvironment_idwork_idrB   rC   rD   rE   optionscast_to

ValueErrorr   r   joinr	   r   _getr   r$   r+   r6   r[   rZ   rA   rB   rC   rD   rE   s           r7   retrieveWork.retrieve<   s    @ \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`yyL-
 )+Q[ '  

 
	
r:   c                  U(       d  [        SU< 35      e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US9[        S	U0[        R                  5      [        XVXxS
9[        S9$ )  
Note: these endpoints are called automatically by the pre-built environment
worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted
sandbox environments. They are included here as a reference; you do not need to
invoke them directly.

Update work item metadata with merge semantics.

Args:
  metadata: Metadata patch. Set a key to a string to upsert it, or to null to delete it.
      Omit the field to preserve existing metadata.

  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
rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   Work.update.<locals>.<genexpr>   rU   rV   rW   rX   rY   metadatar\   bodyr^   r_   )ra   r   r   rb   r	   r   _postr   r   r(   WorkUpdateParamsr$   r+   	r6   r[   rZ   rk   rA   rB   rC   rD   rE   s	            r7   updateWork.updatew   s    H \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`zzL-
 !*h!79K9\9\](+Q[ '  
 	
r:   limitpagerA   rB   rC   rD   rE   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S.[        R                  5      S	9[        S
9$ )  
Note: these endpoints are called automatically by the pre-built environment
worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted
sandbox environments. They are included here as a reference; you do not need to
invoke them directly.

List work items in an environment.

Args:
  limit: Maximum number of work items to return

  page: Opaque cursor from previous response for pagination

  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
rH   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   Work.list.<locals>.<genexpr>   rU   rV   rW   0/v1/environments/{environment_id}/work?beta=truerZ   rt   ru   rB   rC   rD   rE   queryru   r^   model)ra   r   r   rb   r	   r   _get_api_listr   r!   r+   r$   r   r%   WorkListParams	r6   rZ   rt   ru   rA   rB   rC   rD   rE   s	            r7   list	Work.list   s    J \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`!!L]kl 23(+'%%!& $ %33 %! " 
 	
r:   c          
     f   U(       d  [        SU< 35      e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US9[        XEXgS	9[        S
9$ )  
Note: these endpoints are called automatically by the pre-built environment
worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted
sandbox environments. They are included here as a reference; you do not need to
invoke them directly.

Acknowledge receipt of a work item, transitioning it from 'queued' to 'starting'
and removing it from the queue.

Args:
  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
rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   Work.ack.<locals>.<genexpr>$  rU   rV   rW   >/v1/environments/{environment_id}/work/{work_id}/ack?beta=truerY   r\   r]   
ra   r   r   rb   r	   r   rn   r   r$   r+   rd   s           r7   ackWork.ack   s    B \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`zzP-
 )+Q[ '  

 
	
r:   desired_ttl_secondsexpected_last_heartbeatrA   rB   rC   rD   rE   c                  U(       d  [        SU< 35      e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US9[        UUUU	[        UUS	.[        R                  5      S
9[        S9$ )
  
Note: these endpoints are called automatically by the pre-built environment
worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted
sandbox environments. They are included here as a reference; you do not need to
invoke them directly.

Record a heartbeat for a work item to maintain the lease.

Args:
  desired_ttl_seconds: Desired TTL in seconds

  expected_last_heartbeat: Expected last_heartbeat for conditional update (optimistic concurrency). Use
      literal 'NO_HEARTBEAT' to claim an unclaimed lease (first heartbeat). For
      subsequent heartbeats, echo the server's previous last_heartbeat value exactly.
      Returns 412 Precondition Failed if the actual value doesn't match.

  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
rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   !Work.heartbeat.<locals>.<genexpr>h  rU   rV   rW   D/v1/environments/{environment_id}/work/{work_id}/heartbeat?beta=truerY   r   r   r}   r]   )ra   r   r   rb   r	   r   rn   r   r$   r   r)   WorkHeartbeatParamsr-   
r6   r[   rZ   r   r   rA   rB   rC   rD   rE   s
             r7   	heartbeatWork.heartbeat8  s   R \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`zzV-
 )+'%%/B3J *== 8'  
 	
r:   block_msreclaim_older_than_msrA   anthropic_worker_idrB   rC   rD   rE   c               v   U(       d  [        SU< 35      e0 [        [        U5      (       a#  SR                  [	        S U 5       S/5      5      O[
        US.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S	.[        R                  5      S
9[        S9$ )F  
Note: these endpoints are called automatically by the pre-built environment
worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted
sandbox environments. They are included here as a reference; you do not need to
invoke them directly.

Long poll for work items in the queue.

Args:
  block_ms: How long to wait for work to arrive before returning. Must be 1-999 in
      milliseconds. Defaults to non-blocking (returns immediately if no work is
      available).

  reclaim_older_than_ms: Reclaim unacknowledged work items older than this many milliseconds. If omitted,
      uses the default (5000ms).

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

  anthropic_worker_id: Unique identifier for the specific worker polling, used to track aggregated
      environment-level work metrics in Console

  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
rH   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   Work.poll.<locals>.<genexpr>  rU   rV   rW   rJ   zAnthropic-Worker-IDrJ   5/v1/environments/{environment_id}/work/poll?beta=truer{   r   r   r}   r]   )ra   r   r   rb   r	   r   rc   r   r$   r   r&   WorkPollParamsr+   
r6   rZ   r   r   rA   r   rB   rC   rD   rE   s
             r7   poll	Work.poll  s    X \]k\nopp

   '*hhu5Le5LOjNk/l&m"+>	

 "

 *+F`=K^\^`yyQbpq(+'%%$,1F %33 '  
 	
r:   c          
     8   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[        X4XVS9[        S	9$ )
}  
Get statistics about the work queue for an environment.

Args:
  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
rH   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   Work.stats.<locals>.<genexpr>  rU   rV   rW   6/v1/environments/{environment_id}/work/stats?beta=truer{   r\   r]   
ra   r   r   rb   r	   r   rc   r   r$   r,   r6   rZ   rA   rB   rC   rD   rE   s          r7   stats
Work.stats  s    4 \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`yyRcqr(+Q[ 1  
 	
r:   forcerA   rB   rC   rD   rE   c                  U(       d  [        SU< 35      e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US9[        S	U0[        R                  5      [        XVXxS
9[        S9$ )  
Note: these endpoints are called automatically by the pre-built environment
worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted
sandbox environments. They are included here as a reference; you do not need to
invoke them directly.

Stop a work item, initiating graceful or forced shutdown.

Args:
  force: If true, immediately stop work without graceful shutdown

  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
rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   Work.stop.<locals>.<genexpr>+  rU   rV   rW   ?/v1/environments/{environment_id}/work/{work_id}/stop?beta=truerY   r   r\   rl   )ra   r   r   rb   r	   r   rn   r   r   r'   WorkStopParamsr$   r+   	r6   r[   rZ   r   rA   rB   rC   rD   rE   s	            r7   stop	Work.stop  s    F \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`zzQ-
 !'5!13C3R3RS(+Q[ '  
 	
r:    )returnr4   )r   r=   r[   rO   rZ   rO   rA   List[AnthropicBetaParam] | OmitrB   Headers | NonerC   Query | NonerD   Body | NonerE   'float | httpx.Timeout | None | NotGivenr   r+   r[   rO   rZ   rO   rk   zDict[str, Optional[str]]rA   r   rB   r   rC   r   rD   r   rE   r   r   r+   )rZ   rO   rt   
int | Omitru   Optional[str] | OmitrA   r   rB   r   rC   r   rD   r   rE   r   r   z"SyncPageCursor[BetaSelfHostedWork]r[   rO   rZ   rO   r   Optional[int] | Omitr   r   rA   r   rB   r   rC   r   rD   r   rE   r   r   r-   rZ   rO   r   r   r   r   rA   r   r   z
str | OmitrB   r   rC   r   rD   r   rE   r   r   zOptional[BetaSelfHostedWork]rZ   rO   rA   r   rB   r   rC   r   rD   r   rE   r   r   r,   r[   rO   rZ   rO   r   zbool | OmitrA   r   rB   r   rC   r   rD   r   rE   r   r   r+   )__name__
__module____qualname____firstlineno__r   r8   r>   r   r   re   rq   r   r   r   r   r   r   __static_attributes__r   r:   r7   r.   r.   (   s   ) ) / / 26 )-$("&;D9
9
 	9

 /9
 &9
 "9
  9
 99
 
9
B 26 )-$("&;D>
>
 	>

 +>
 />
 &>
 ">
  >
 9>
 
>
H !%)15 )-$("&;DC
C
 	C

 #C
 /C
 &C
 "C
  C
 9C
 
,C
T 26 )-$("&;D:
:
 	:

 /:
 &:
 ":
  :
 9:
 
:
B 598<15 )-$("&;DL
L
 	L

 2L
 "6L
 /L
 &L
 "L
  L
 9L
 
-L
d *.6:15*. )-$("&;DJ
J
 '	J

  4J
 /J
 (J
 &J
 "J
  J
 9J
 
&J
` 26 )-$("&;D-
-
 /	-
 &-
 "-
  -
 9-
 
&-
h "15 )-$("&;D=
=
 	=

 =
 /=
 &=
 "=
  =
 9=
 
=
 =
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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 S jjr\\SSS\S.                 S!S jjrS\SSSSS.                 S"S jjrSSSSS\\SSS.	                   S#S jjrSrg)$r/   iA  c                    [        U 5      $ r3   )AsyncWorkWithRawResponser5   s    r7   r8   AsyncWork.with_raw_responseB  s     (--r:   c                    [        U 5      $ r<   )AsyncWorkWithStreamingResponser5   s    r7   r>   !AsyncWork.with_streaming_responseL  s     .d33r:   Nr@   c          
       #    U(       d  [        SU< 35      e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US9[        XEXgS	9[        S
9I Sh  vN $  N7f)rG   rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   %AsyncWork.retrieve.<locals>.<genexpr>|  rU   rV   rW   rX   rY   r\   r]   Nr`   rd   s           r7   re   AsyncWork.retrieveU  s     @ \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`YYL-
 )+Q[ '  

 

 
	
 

   B6B?8B=9B?c                 #    U(       d  [        SU< 35      e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US9[        S	U0[        R                  5      I S
h  vN [        XVXxS9[        S9I S
h  vN $  N N7f)rh   rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   #AsyncWork.update.<locals>.<genexpr>  rU   rV   rW   rX   rY   rk   Nr\   rl   )ra   r   r   rb   r	   r   rn   r   r   r(   ro   r$   r+   rp   s	            r7   rq   AsyncWork.update  s    H \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`ZZL-
 -j(-CEWEhEhii(+Q[ '   
 
 	
 j
$   CC$C 
C$C"C$"C$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[        UUS.[        R                  5      S	9[        S
9$ )rw   rH   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   !AsyncWork.list.<locals>.<genexpr>  rU   rV   rW   rz   r{   r|   r}   r   )ra   r   r   rb   r	   r   r   r   r"   r+   r$   r   r%   r   r   s	            r7   r   AsyncWork.list  s    J \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`!!L]kl !34(+'%%!& $ %33 %! " 
 	
r:   c          
       #    U(       d  [        SU< 35      e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US9[        XEXgS	9[        S
9I Sh  vN $  N7f)r   rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS    AsyncWork.ack.<locals>.<genexpr>=  rU   rV   rW   r   rY   r\   r]   Nr   rd   s           r7   r   AsyncWork.ack  s     B \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`ZZP-
 )+Q[ '   

 

 
	
 

r   r   c                 #    U(       d  [        SU< 35      e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US9[        UUUU	[        UUS	.[        R                  5      I S
h  vN S9[        S9I S
h  vN $  N N7f)r   rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   &AsyncWork.heartbeat.<locals>.<genexpr>  rU   rV   rW   r   rY   r   Nr}   r]   )ra   r   r   rb   r	   r   rn   r   r$   r   r)   r   r-   r   s
             r7   r   AsyncWork.heartbeatQ  s    R \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`ZZV-
 )+'%1/B3J *==  8'   
 
 	

s$   CC'C#C'C%C'%C'r   c                 #    U(       d  [        SU< 35      e0 [        [        U5      (       a#  SR                  [	        S U 5       S/5      5      O[
        US.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S	.[        R                  5      I S
h  vN S9[        S9I S
h  vN $  N N7f)r   rH   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   !AsyncWork.poll.<locals>.<genexpr>  rU   rV   rW   r   rJ   r   r{   r   Nr}   r]   )ra   r   r   rb   r	   r   rc   r   r$   r   r&   r   r+   r   s
             r7   r   AsyncWork.poll  s     X \]k\nopp

   '*hhu5Le5LOjNk/l&m"+>	

 "

 *+F`=K^\^`YYQbpq(+'%1$,1F %33  '  
 
 	

s$   B5C7C8CC	CCc          
     T  #    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[        X4XVS9[        S	9I S
h  vN $  N7f)r   rH   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   "AsyncWork.stats.<locals>.<genexpr>
  rU   rV   rW   r   r{   r\   r]   Nr   r   s          r7   r   AsyncWork.stats  s     4 \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`YYRcqr(+Q[ 1  
 
 	
 
s   BB(!B&"B(r   c                 #    U(       d  [        SU< 35      e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US9[        S	U0[        R                  5      I S
h  vN [        XVXxS9[        S9I S
h  vN $  N N7f)r   rH   rI   rJ   rK   c              3  8   #    U  H  n[        U5      v   M     g 7frM   rN   rP   s     r7   rS   !AsyncWork.stop.<locals>.<genexpr>D  rU   rV   rW   r   rY   r   Nr\   rl   )ra   r   r   rb   r	   r   rn   r   r   r'   r   r$   r+   r   s	            r7   r   AsyncWork.stop  s    F \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`ZZQ-
 -gu-=?O?^?^__(+Q[ '   
 
 	
 `
r   FT)	worker_idr   r   drain	auto_stoprB   c                   SSK Jn	  SSKJn
Jn  [        U5      (       d  U
nU	" [        SU R                  5      USS9nU" UR                  R                  R                  UUUUUUUS9$ )u  Async-iterate work items claimed from a self-hosted environment.

Each yielded item has been ack'd. The environment key authenticates the
poll, ack, and stop calls via a scoped sub-client (built once per
call). Async only — available on :class:`~anthropic.AsyncAnthropic`
(the sync client does not expose ``poller``).

With the defaults this loops forever and calls ``stop`` after the
consuming ``async for`` body returns or raises (long-running runner
shape). Pass ``drain=True, auto_stop=False`` to drain whatever is queued
and return without owning the stop call (webhook-dispatch shape — each
item is handed off to another process that calls ``stop`` when done).

Args:
  environment_id: The self-hosted environment to claim work from.
  environment_key: The environment key — used as the Bearer credential
    on the scoped sub-client that issues poll / ack / stop requests.
  worker_id: Optional identifier sent on each poll. Defaults to a
    unique, hostname-prefixed id.
  block_ms: How long the server should hold an empty poll open before
    returning (long-poll). Server caps this at 999. Defaults to
    ``POLL_BLOCK_MS`` (999) when not given. Pass ``None`` to omit for a
    non-blocking poll — the server rejects ``0``.
  reclaim_older_than_ms: Reclaim un-ack'd work older than this many ms.
    Forwarded to the underlying poll request.
  drain: When True, return after the first empty poll instead of
    sleeping and re-polling.
  auto_stop: When True (default), call ``stop`` after the consumer's
    loop body completes. Set False when handing items off to another
    process that owns the stop call.
  extra_headers: Optional headers passed through per request on the
    poll / ack / stop calls. 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 scoped sub-client built here (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   )_copy_client_with_bearer_auth)POLL_BLOCK_MS
aiter_workr   zenvironments-work-poller)
auth_tokenhelper)rZ   r   r   r   r   r   rB   )lib._scoped_clientr   lib.environments._pollerr  r  r   r   _clientbetaenvironmentswork)r6   rZ   environment_keyr   r   r   r   r   rB   r   r  r  scopeds                r7   pollerAsyncWork.pollerY  sr    r 	IJ!!$H.!4<<0&-

 KK$$)))"7'	
 		
r:   	rZ   r  toolsworkdirunrestricted_pathsmax_file_bytesmax_idler   rB   c       	            SSK Jn
  SSKJn  [	        U5      (       d  UnU
" [        SU R                  5      UUUUUUUUU	S9
$ )u  Build an :class:`~anthropic.lib.environments.EnvironmentWorker` bound to this async client.

The full worker: it polls the environment for work, and for each claimed
session sets up the workdir + downloads the session agent's skills, runs
the given ``tools`` against the session's tool-call events while
heartbeating the work-item lease, force-stops the work on exit, and
loops. Composed from this resource's :meth:`poller` and the per-session
session tool runner.

``EnvironmentWorker`` is async only — its ``run`` / ``handle_item``
coroutines need an event loop. With this :class:`~anthropic.AsyncAnthropic`
client the returned worker is ready to ``await worker.run()`` (long-running
poll loop) or ``await worker.handle_item()`` (single already-claimed work
item). It can also be constructed directly:
``EnvironmentWorker(client, ...)``.

Args:
  environment_id: The self-hosted environment to poll for work. Required
    by ``EnvironmentWorker.run``; not used by
    ``EnvironmentWorker.handle_item``.
  environment_key: The environment key — the worker's single credential,
    used as Bearer auth on the control-plane and session-level calls.
  tools: Tools to expose to each claimed session. Either a fixed list or
    a factory invoked once per session with that session's
    ``AgentToolContext``. Defaults to ``beta_agent_toolset_20260401(env)``.
  workdir: Base directory for the per-session ``AgentToolContext``.
    Defaults to ``os.getcwd()`` captured when the worker is constructed
    (TS parity: ``process.cwd()`` at construction).
  unrestricted_paths: Forwarded to the per-session ``AgentToolContext``.
  max_file_bytes: Forwarded to the per-session ``AgentToolContext`` — the
    size cap (bytes) for the ``read``/``edit`` tools. ``not_given``
    (default) uses the built-in 256 KiB cap; a positive int sets a custom
    cap; ``None`` disables the cap.
  max_idle: Seconds to keep running after the session goes idle with
    ``stop_reason`` ``end_turn``. Defaults to ``DEFAULT_MAX_IDLE`` (60s)
    when not given. ``None`` disables it.
  worker_id: Optional identifier sent on each poll. Defaults to a unique,
    hostname-prefixed id.
  extra_headers: Optional headers passed through per request on every
    call the worker makes (poll / ack / stop / heartbeat and the
    session tool runner's 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 worker's scoped
    sub-clients (and the parent client's ``default_headers`` propagate
    via their ``client.copy()``); a header given here overrides a
    scoped client's same-named default for that request, so use it for
    caller passthrough (e.g. trace ids), not to set auth.
r   )r   )DEFAULT_MAX_IDLEr   r  )lib.environments._workerr   lib.tools._beta_session_runnerr  r   r   r  )r6   rZ   r  r  r  r  r  r  r   rB   r   r  s               r7   workerAsyncWork.worker  sS    B 	CG!!'H !4<<0)+1)'
 	
r:   r   )r   r   )r   r   r   r   )rZ   rO   rt   r   ru   r   rA   r   rB   r   rC   r   rD   r   rE   r   r   zGAsyncPaginator[BetaSelfHostedWork, AsyncPageCursor[BetaSelfHostedWork]]r   r   r   r   )rZ   rO   r  rO   r   
str | Noner   int | None | NotGivenr   z
int | Noner   boolr   r  rB   r   r   z!AsyncIterator[BetaSelfHostedWork])rZ   r  r  r  r  zEnvironmentWorkerTools | Noner  zstr | os.PathLike[str] | Noner  r  r  r  r  zfloat | None | NotGivenr   r  rB   r   r   r   )r   r   r   r   r   r8   r>   r   r   re   rq   r   r   r   r   r   r   r  r  r   r   r:   r7   r/   r/   A  s   . . 4 4 26 )-$("&;D9
9
 	9

 /9
 &9
 "9
  9
 99
 
9
B 26 )-$("&;D>
>
 	>

 +>
 />
 &>
 ">
  >
 9>
 
>
H !%)15 )-$("&;DC
C
 	C

 #C
 /C
 &C
 "C
  C
 9C
 
QC
T 26 )-$("&;D:
:
 	:

 /:
 &:
 ":
  :
 9:
 
:
B 598<15 )-$("&;DL
L
 	L

 2L
 "6L
 /L
 &L
 "L
  L
 9L
 
-L
d *.6:15*. )-$("&;DJ
J
 '	J

  4J
 /J
 (J
 &J
 "J
  J
 9J
 
&J
` 26 )-$("&;D-
-
 /	-
 &-
 "-
  -
 9-
 
&-
h "15 )-$("&;D=
=
 	=

 =
 /=
 &=
 "=
  =
 9=
 
=
H !%*3,0(,M
 M
 	M

 M
 (M
  *M
 M
 M
 &M
 
+M
d &*&*/315#(09,5 $(,R
 #R
 $	R

 -R
 /R
 !R
 .R
 *R
 R
 &R
 
R
 R
r:   c                      \ rS rSrSS jrSrg)r4   i  c                `   Xl         [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR
                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR                  5      U l	        [        R                  " UR                  5      U l
        g rM   )_workr   to_raw_response_wrapperre   rq   r   r   r   r   r   r   r6   r
  s     r7   __init__WorkWithRawResponse.__init__  s    
(@@MM
 '>>KK
 %<<II
	 $;;HH
 *AANN
 %<<II
	 &==JJ

 %<<II
	r:   	r   r   r   r   r   re   r   r   rq   Nr
  r.   r   Noner   r   r   r   r#  r   r   r:   r7   r4   r4         
r:   r4   c                      \ rS rSrSS jrSrg)r   i  c                `   Xl         [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR
                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        [        R                  " UR                  5      U l	        [        R                  " UR                  5      U l
        g rM   )r   r   async_to_raw_response_wrapperre   rq   r   r   r   r   r   r   r"  s     r7   r#  !AsyncWorkWithRawResponse.__init__  s    
(FFMM
 'DDKK
 %BBII
	 $AAHH
 *GGNN
 %BBII
	 &CCJJ

 %BBII
	r:   r%  Nr
  r/   r   r'  r(  r   r:   r7   r   r     r)  r:   r   c                      \ rS rSrSS jrSrg)r=   i9  c                   Xl         [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l        [        UR
                  5      U l        [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l	        g rM   )
r   r   re   rq   r   r   r   r   r   r   r"  s     r7   r#  "WorkWithStreamingResponse.__init__:  s    
4MM
 3KK
 1II
	 0HH
 6NN
 1II
	 2JJ

 1II
	r:   r%  Nr&  r(  r   r:   r7   r=   r=   9  r)  r:   r=   c                      \ rS rSrSS jrSrg)r   iW  c                   Xl         [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l        [        UR
                  5      U l        [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l        [        UR                  5      U l	        g rM   )
r   r    re   rq   r   r   r   r   r   r   r"  s     r7   r#  'AsyncWorkWithStreamingResponse.__init__X  s    
:MM
 9KK
 7II
	 6HH
 <NN
 7II
	 8JJ

 7II
	r:   r%  Nr.  r(  r   r:   r7   r   r   W  r)  r:   r   )F
__future__r   ostypingr   r   r   r   r   	itertoolsr	   httpxcollections.abcr
   r  r   r  r   r    r   _typesr   r   r   r   r   r   r   _utilsr   r   r   r   r   _compatr   	_resourcer   r   	_responser   r    
paginationr!   r"   _base_clientr#   r$   types.beta.environmentsr%   r&   r'   r(   r)   types.anthropic_beta_paramr*   -types.beta.environments.beta_self_hosted_workr+   9types.beta.environments.beta_self_hosted_work_queue_statsr,   @types.beta.environments.beta_self_hosted_work_heartbeat_responser-   __all__r.   r/   r4   r   r=   r   r   r:   r7   <module>rI     s    # 	 < <  -*V ! L L L g g ' ; Z : A  > P f t;
V
? V
ry

  y

x
 
<
 
<
 
<
 
r:   