
    4Rj                       d dl mZ d dlZd dlmZmZmZmZmZ d dl	m
Z
 d dlZerd dlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZmZmZmZ ddlmZmZm Z m!Z!m"Z" ddl#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddgZ? G d de&      Z@ G d de'      ZA G d d      ZB G d d      ZC G d d      ZD G d  d!      ZEy)"    )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            	         e Zd Zedd       Zedd       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	eeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
eddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Zeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)r.   c                    t        |       S a  
        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    r/var/www/html/meridian/meridian-ai/venv/lib/python3.12/site-packages/anthropic/resources/beta/environments/work.pywith_raw_responsezWork.with_raw_response)   s     #4((    c                    t        |       S 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
        )WorkWithStreamingResponser4   s    r6   with_streaming_responsezWork.with_streaming_response3   s     )..r8   Nbetasextra_headersextra_query
extra_bodytimeoutc          
     F   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        ||||	      t        
      S )  
        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  2   K   | ]  }t        |        y wNstr.0es     r6   	<genexpr>z Work.retrieve.<locals>.<genexpr>c        5Lc!f5L   managed-agents-2026-04-01:/v1/environments/{environment_id}/work/{work_id}?beta=trueenvironment_idwork_idr?   r@   rA   rB   optionscast_to

ValueErrorr   r   joinr	   r   _getr   r$   r+   r5   rW   rV   r>   r?   r@   rA   rB   s           r6   retrievezWork.retrieve<   s    @ \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`yyL-
 )+Q[el '  

 
	
r8   c          
     |   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        d	|it        j                        t        ||||
      t              S )w  
        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
        rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   zWork.update.<locals>.<genexpr>   rQ   rR   rS   rT   rU   metadatarX   bodyrZ   r[   )r]   r   r   r^   r	   r   _postr   r   r(   WorkUpdateParamsr$   r+   	r5   rW   rV   re   r>   r?   r@   rA   rB   s	            r6   updatez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[el '  
 	
r8   limitpager>   r?   r@   rA   rB   c               t   |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d|      t        t           t        ||||t        ||dt        j                        	      t        
      S )J  
        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
        rE   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   zWork.list.<locals>.<genexpr>   rQ   rR   rS   0/v1/environments/{environment_id}/work?beta=truerV   rm   rn   r?   r@   rA   rB   queryrn   rZ   model)r]   r   r   r^   r	   r   _get_api_listr   r!   r+   r$   r   r%   WorkListParams	r5   rV   rm   rn   r>   r?   r@   rA   rB   s	            r6   listz	Work.list   s    J \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`!!L]kl 23(+'%%!& $ %33 %! " 
 	
r8   c          
     F   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        ||||	      t        
      S )"  
        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
        rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   zWork.ack.<locals>.<genexpr>$  rQ   rR   rS   >/v1/environments/{environment_id}/work/{work_id}/ack?beta=truerU   rX   rY   
r]   r   r   r^   r	   r   rh   r   r$   r+   r`   s           r6   ackzWork.ack   s    B \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`zzP-
 )+Q[el '  

 
	
r8   desired_ttl_secondsexpected_last_heartbeatr>   r?   r@   rA   rB   c               ~   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        ||||	t        ||d	t        j                        
      t              S )  
        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
        rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z!Work.heartbeat.<locals>.<genexpr>h  rQ   rR   rS   D/v1/environments/{environment_id}/work/{work_id}/heartbeat?beta=truerU   r   r   ru   rY   )r]   r   r   r^   r	   r   rh   r   r$   r   r)   WorkHeartbeatParamsr-   
r5   rW   rV   r   r   r>   r?   r@   rA   rB   s
             r6   	heartbeatzWork.heartbeat8  s   R \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`zzV-
 )+'%%/B3J *== 8'  
 	
r8   block_msreclaim_older_than_msr>   anthropic_worker_idr?   r@   rA   rB   c               ^   |st        d|      i t        t        |      r#dj                  t	        d |D        dg            nt
        |d      |xs i }ddi|xs i }| j                  t        d|      t        ||||	t        ||d	t        j                        
      t              S )  
        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
        rE   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   zWork.poll.<locals>.<genexpr>  rQ   rR   rS   rG   zAnthropic-Worker-IDrG   5/v1/environments/{environment_id}/work/poll?beta=truers   r   r   ru   rY   )r]   r   r   r^   r	   r   r_   r   r$   r   r&   WorkPollParamsr+   
r5   rV   r   r   r>   r   r?   r@   rA   rB   s
             r6   pollz	Work.poll  s    X \]k\nopp

   '*hhu5Le5LOjNk/l&m"+>	

 "

 *+F`=K^\^`yyQbpq(+'%%$,1F %33 '  
 	
r8   c          
     $   |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d|      t        ||||      t        	      S )
  
        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
        rE   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   zWork.stats.<locals>.<genexpr>  rQ   rR   rS   6/v1/environments/{environment_id}/work/stats?beta=truers   rX   rY   
r]   r   r   r^   r	   r   r_   r   r$   r,   r5   rV   r>   r?   r@   rA   rB   s          r6   statsz
Work.stats  s    4 \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`yyRcqr(+Q[el 1  
 	
r8   forcer>   r?   r@   rA   rB   c          
     |   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        d	|it        j                        t        ||||
      t              S ).  
        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
        rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   zWork.stop.<locals>.<genexpr>+  rQ   rR   rS   ?/v1/environments/{environment_id}/work/{work_id}/stop?beta=truerU   r   rX   rf   )r]   r   r   r^   r	   r   rh   r   r   r'   WorkStopParamsr$   r+   	r5   rW   rV   r   r>   r?   r@   rA   rB   s	            r6   stopz	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[el '  
 	
r8   )returnr3   )r   r;   rW   rL   rV   rL   r>   List[AnthropicBetaParam] | Omitr?   Headers | Noner@   Query | NonerA   Body | NonerB   'float | httpx.Timeout | None | NotGivenr   r+   rW   rL   rV   rL   re   zDict[str, Optional[str]]r>   r   r?   r   r@   r   rA   r   rB   r   r   r+   )rV   rL   rm   
int | Omitrn   Optional[str] | Omitr>   r   r?   r   r@   r   rA   r   rB   r   r   z"SyncPageCursor[BetaSelfHostedWork]rW   rL   rV   rL   r   Optional[int] | Omitr   r   r>   r   r?   r   r@   r   rA   r   rB   r   r   r-   rV   rL   r   r   r   r   r>   r   r   z
str | Omitr?   r   r@   r   rA   r   rB   r   r   zOptional[BetaSelfHostedWork]rV   rL   r>   r   r?   r   r@   r   rA   r   rB   r   r   r,   rW   rL   rV   rL   r   zbool | Omitr>   r   r?   r   r@   r   rA   r   rB   r   r   r+   )__name__
__module____qualname__r   r7   r<   r   r   ra   rk   r|   r   r   r   r   r    r8   r6   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=
 
=
r8   c            
      v   e Zd Zedd       Zedd       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	eeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
eddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Zeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 ddZeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdeddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d dZdddddeeddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZy)"r/   c                    t        |       S r2   )AsyncWorkWithRawResponser4   s    r6   r7   zAsyncWork.with_raw_responseB  s     (--r8   c                    t        |       S r:   )AsyncWorkWithStreamingResponser4   s    r6   r<   z!AsyncWork.with_streaming_responseL  s     .d33r8   Nr=   c          
     b  K   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        ||||	      t        
       d{   S 7 w)rD   rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z%AsyncWork.retrieve.<locals>.<genexpr>|  rQ   rR   rS   rT   rU   rX   rY   Nr\   r`   s           r6   ra   zAsyncWork.retrieveU  s     @ \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`YYL-
 )+Q[el '  

 

 
	
 

   B&B/(B-)B/c          
       K   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        d	|it        j                         d
{   t        ||||      t               d
{   S 7 $7 w)rc   rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z#AsyncWork.update.<locals>.<genexpr>  rQ   rR   rS   rT   rU   re   NrX   rf   )r]   r   r   r^   r	   r   rh   r   r   r(   ri   r$   r+   rj   s	            r6   rk   z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[el '   
 
 	
 j
$   B)C+C
,CCCCrl   c               t   |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d|      t        t           t        ||||t        ||dt        j                        	      t        
      S )rp   rE   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z!AsyncWork.list.<locals>.<genexpr>  rQ   rR   rS   rr   rs   rt   ru   rw   )r]   r   r   r^   r	   r   ry   r   r"   r+   r$   r   r%   rz   r{   s	            r6   r|   zAsyncWork.list  s    J \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`!!L]kl !34(+'%%!& $ %33 %! " 
 	
r8   c          
     b  K   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        ||||	      t        
       d{   S 7 w)r~   rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z AsyncWork.ack.<locals>.<genexpr>=  rQ   rR   rS   r   rU   rX   rY   Nr   r`   s           r6   r   zAsyncWork.ack  s     B \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`ZZP-
 )+Q[el '   

 

 
	
 

r   r   c                 K   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        ||||	t        ||d	t        j                         d
{         t               d
{   S 7 7 w)r   rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z&AsyncWork.heartbeat.<locals>.<genexpr>  rQ   rR   rS   r   rU   r   Nru   rY   )r]   r   r   r^   r	   r   rh   r   r$   r   r)   r   r-   r   s
             r6   r   z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$   B3C5C6CCCCr   c                 K   |st        d|      i t        t        |      r#dj                  t	        d |D        dg            nt
        |d      |xs i }ddi|xs i }| j                  t        d|      t        ||||	t        ||d	t        j                         d
{         t               d
{   S 7 7 w)r   rE   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z!AsyncWork.poll.<locals>.<genexpr>  rQ   rR   rS   r   rG   r   rs   r   Nru   rY   )r]   r   r   r^   r	   r   r_   r   r$   r   r&   r   r+   r   s
             r6   r   zAsyncWork.poll  s     X \]k\nopp

   '*hhu5Le5LOjNk/l&m"+>	

 "

 *+F`=K^\^`YYQbpq(+'%1$,1F %33  '  
 
 	

s$   B#C%C&C<C=CCc          
     @  K   |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d|      t        ||||      t        	       d
{   S 7 w)r   rE   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z"AsyncWork.stats.<locals>.<genexpr>
  rQ   rR   rS   r   rs   rX   rY   Nr   r   s          r6   r   zAsyncWork.stats  s     4 \]k\nopp	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`YYRcqr(+Q[el 1  
 
 	
 
s   BBBBr   c          
       K   |st        d|      |st        d|      i t        dt        |      r#dj                  t	        d |D        dg            nt
        i      |xs i }ddi|xs i }| j                  t        d||      t        d	|it        j                         d
{   t        ||||      t               d
{   S 7 $7 w)r   rE   rF   rG   rH   c              3  2   K   | ]  }t        |        y wrJ   rK   rM   s     r6   rP   z!AsyncWork.stop.<locals>.<genexpr>D  rQ   rR   rS   r   rU   r   NrX   rf   )r]   r   r   r^   r	   r   rh   r   r   r'   r   r$   r+   r   s	            r6   r   zAsyncWork.stop  s    F \]k\noppUV]U`abb	
$ '*hhu5Le5LOjNk/l&m"	
 "	
 *+F`=K^\^`ZZQ-
 -gu-=?O?^?^__(+Q[el '   
 
 	
 `
r   FT)	worker_idr   r   drain	auto_stopr?   c          
         ddl m}	 ddlm}
m} t        |      s|
} |	t        d| j                        |d      } ||j                  j                  j                  |||||||      S )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)rV   r   r   r   r   r   r?   )lib._scoped_clientr   lib.environments._pollerr   r   r   r   _clientbetaenvironmentswork)r5   rV   environment_keyr   r   r   r   r   r?   r   r   r   scopeds                r6   pollerzAsyncWork.pollerY  so    r 	IJ!$H.!4<<0&-

 KK$$)))"7'	
 		
r8   	rV   r   toolsworkdirunrestricted_pathsmax_file_bytesmax_idler   r?   c       	            ddl m}
 ddlm} t	        |      s|} |
t        d| j                        |||||||||	
      S )um  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   )r5   rV   r   r   r   r   r   r   r   r?   r   r   s               r6   workerzAsyncWork.worker  sP    B 	CG!'H !4<<0)+1)'
 	
r8   )r   r   )r   r   r   r   )rV   rL   rm   r   rn   r   r>   r   r?   r   r@   r   rA   r   rB   r   r   zGAsyncPaginator[BetaSelfHostedWork, AsyncPageCursor[BetaSelfHostedWork]]r   r   r   r   )rV   rL   r   rL   r   
str | Noner   int | None | NotGivenr   z
int | Noner   boolr   r   r?   r   r   z!AsyncIterator[BetaSelfHostedWork])rV   r   r   r   r   zEnvironmentWorkerTools | Noner   zstr | os.PathLike[str] | Noner   r   r   r   r   zfloat | None | NotGivenr   r   r?   r   r   r   )r   r   r   r   r7   r<   r   r   ra   rk   r|   r   r   r   r   r   r   r   r   r8   r6   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
r8   c                      e Zd ZddZy)r3   c                R   || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j                        | _	        t        j                  |j                        | _
        y rJ   )_workr   to_raw_response_wrapperra   rk   r|   r   r   r   r   r   r5   r   s     r6   __init__zWorkWithRawResponse.__init__  s    
(@@MM
 '>>KK
 %<<II
	 $;;HH
 *AANN
 %<<II
	 &==JJ

 %<<II
	r8   Nr   r.   r   Noner   r   r   r   r   r8   r6   r3   r3         
r8   r3   c                      e Zd ZddZy)r   c                R   || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j                        | _	        t        j                  |j                        | _
        y rJ   )r   r   async_to_raw_response_wrapperra   rk   r|   r   r   r   r   r   r   s     r6   r   z!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
	r8   Nr   r/   r   r   r   r   r8   r6   r   r     r   r8   r   c                      e Zd ZddZy)r;   c                   || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j
                        | _        t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j                        | _	        y rJ   )
r   r   ra   rk   r|   r   r   r   r   r   r   s     r6   r   z"WorkWithStreamingResponse.__init__:  s    
4MM
 3KK
 1II
	 0HH
 6NN
 1II
	 2JJ

 1II
	r8   Nr   r   r   r8   r6   r;   r;   9  r   r8   r;   c                      e Zd ZddZy)r   c                   || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j
                        | _        t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j                        | _	        y rJ   )
r   r    ra   rk   r|   r   r   r   r   r   r   s     r6   r   z'AsyncWorkWithStreamingResponse.__init__X  s    
:MM
 9KK
 7II
	 6HH
 <NN
 7II
	 8JJ

 7II
	r8   Nr  r   r   r8   r6   r   r   W  r   r8   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/   r3   r   r;   r   r   r8   r6   <module>r     s    # 	 < <  -*V ! L L L g g ' ; Z : A  > P f t;
V
? V
ry

  y

x
 
<
 
<
 
<
 
r8   