
    0jm                       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	Z	d dl
mZ ddlmZ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 dd	lmZ dd
lmZmZ ddlm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z4m5Z6m7Z7 ddl8m9Z9 ddgZ: G d de          Z; G d de          Z< G d d          Z= G d d          Z> G d d          Z? G d d          Z@dS )     )annotationsN)DictTypeUnionOptionaloverload)prepare_timeout_float   )task_run_create_paramstask_run_result_params)BodyOmitQueryHeadersNotGivenomit	not_given)maybe_transformasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)to_raw_response_wrapperto_streamed_response_wrapperasync_to_raw_response_wrapper"async_to_streamed_response_wrapper)make_request_options)TaskRun)TaskRunResult)OutputTOutputSchemaTaskSpecParam)build_task_spec_param)ParsedTaskRunResult)wait_for_resultwait_for_result_asynctask_run_result_parser)SourcePolicyTaskRunResourceAsyncTaskRunResourcec            	         e Zd ZdZed6d            Zed7d            Zeeeedddedd8dZ	dddedd9d!Z
eddded"d:d&Zedddd'd;d-Zeeeddded.d<d0            Zeeddded1d=d4            Zeeddded.d>d5ZdS )?r)     The Task API executes web research and extraction tasks.

    Clients submit a natural-language objective with an optional input schema; the service plans retrieval, fetches relevant URLs, and returns outputs that conform to a provided or inferred JSON schema. Supports deep research style queries and can return rich structured JSON outputs. Processors trade-off between cost, latency, and quality. Each processor supports calibrated confidences.
    - Output metadata: citations, excerpts, reasoning, and confidence per field
    returnTaskRunResourceWithRawResponsec                     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/parallel-web/parallel-sdk-python#accessing-raw-response-data-eg-headers
        )r.   selfs    c/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/parallel/resources/task_run.pywith_raw_responsez!TaskRunResource.with_raw_response.   s     .d333    $TaskRunResourceWithStreamingResponsec                     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/parallel-web/parallel-sdk-python#with_streaming_response
        )r6   r1   s    r3   with_streaming_responsez'TaskRunResource.with_streaming_response8   s     4D999r5   Nmetadataprevious_interaction_idsource_policy	task_specextra_headersextra_query
extra_bodytimeoutinputUnion[str, Dict[str, object]]	processorstrr;   3Optional[Dict[str, Union[str, float, bool]]] | Omitr<   Optional[str] | Omitr=   Optional[SourcePolicy] | Omitr>   Optional[TaskSpecParam] | Omitr?   Headers | Noner@   Query | NonerA   Body | NonerB   'float | httpx.Timeout | None | NotGivenr   c       
            |                      dt          ||||||dt          j                  t	          |||	|
          t
                    S )(  
        Initiates a task run.

        Returns immediately with a run object in status 'queued'.

        Beta features can be enabled by setting the 'parallel-beta' header.

        Args:
          input: Input to the task, either text or a JSON object.

          processor: Processor to use for the task.

          metadata: User-provided metadata stored with the run. Keys and values must be strings with
              a maximum length of 16 and 512 characters respectively.

          previous_interaction_id: Interaction ID to use as context for this request.

          source_policy: Source policy for web search results.

              This policy governs which sources are allowed/disallowed in results.

          task_spec: Specification for a task.

              Auto output schemas can be specified by setting `output_schema={"type":"auto"}`.
              Not specifying a TaskSpec is the same as setting an auto output schema.

              For convenience bare strings are also accepted as input or output schemas.

          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
        /v1/tasks/runsrC   rE   r;   r<   r=   r>   r?   r@   rA   rB   bodyoptionscast_to)_postr   r   TaskRunCreateParamsr   r   r2   rC   rE   r;   r<   r=   r>   r?   r@   rA   rB   s              r3   createzTaskRunResource.createA   sx    h zz "!* (/F%2!*  ':
 
 )+Q[el   !  
 
 	
r5   rS   run_idc          	         |st          d|          |                     d| t          ||||          t                    S )  
        Retrieves run status by run_id.

        The run result is available from the `/result` endpoint.

        Args:
          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
        5Expected a non-empty value for `run_id` but received /v1/tasks/runs/rS   rV   rW   
ValueError_getr   r   r2   r\   r?   r@   rA   rB   s         r3   retrievezTaskRunResource.retrieve   sm    2  	a_U[__```yy&f&&(+Q[el     
 
 	
r5   api_timeoutr?   r@   rA   rB   rh   
int | Omitr   c                   |st          d|          |                     d| dt          ||||t          d|it          j                            t                    S )z  
        Retrieves a run result by run_id, blocking until the run is completed.

        Args:
          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
        r_   r`   /resultrh   r?   r@   rA   rB   queryra   )rc   rd   r   r   r   TaskRunResultParamsr   r2   r\   rh   r?   r@   rA   rB   s          r3   resultzTaskRunResource.result   s    0  	a_U[__```yy-f---(+'%%}k&BDZDnoo   "  

 

 
	
r5   outputr?   r@   rA   deadlinefloatrs   -Optional[OutputSchema] | Type[OutputT] | Omit,TaskRunResult | ParsedTaskRunResult[OutputT]c               D     d	 fd}t          |||          S )
9Wait for a task run to complete within the given timeout.r\   rF   rt   ru   r-   rw   c                    |t          j                    z
  }                    | |          }t          |          S NrS   time	monotonicrq   r'   	r\   rt   rB   task_run_resultrA   r?   r@   rs   r2   s	       r3   _fetcherz2TaskRunResource._wait_for_result.<locals>._fetcher   sN    !1!11G"kk+'% *  O */6BBBr5   r\   rt   callabler\   rF   rt   ru   r-   rw   )_wait_for_resultr2   r\   rt   rs   r?   r@   rA   r   s   `  ```` r3   r   z TaskRunResource._wait_for_result   sZ    		C 		C 		C 		C 		C 		C 		C 		C 		C 		C  v8TTTTr5   r;   rs   r?   r@   rA   rB   Optional[OutputSchema] | Omitc                   d S N 	r2   rC   rE   r;   rs   r?   r@   rA   rB   s	            r3   executezTaskRunResource.execute   s	     r5   r;   r?   r@   rA   rB   Type[OutputT]ParsedTaskRunResult[OutputT]c                   d S r   r   r   s	            r3   r   zTaskRunResource.execute   s	     (+sr5   c          
         ddi|pi }t          |          }t          j                    |z   }	|                     |||t	          ||          ||||          }
|                     |
j        |	||||          S )?  
        Convenience method to create and execute a task run in a single call.

        Awaits run completion. If the run is successful, a `ParsedTaskRunResult`
        is returned when a pydantic was specified in `output`. Otherwise, a
        `TaskRunResult` is returned.

        Possible errors:
        - `TimeoutError`: If the run does not finish within the specified timeout.
        - `APIStatusError`: If the API returns a non-200-range status code.
        - `APIConnectionError`: If the connection to the API fails.

        Args:
          input: Input to the task, either text or a JSON object.

          processor: Processor to use for the task.

          metadata: User-provided metadata stored with the run. Keys and values must be strings with
            a maximum length of 16 and 512 characters respectively.

          output: Optional output schema or pydantic type. If pydantic is provided,
            the response will have a parsed field.

          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.
            If the result is not available within the timeout, a `TimeoutError` is raised.
        X-Stainless-Poll-HelpertruerC   rE   r;   r>   r?   r@   rA   rB   r\   rt   rs   r?   r@   rA   r	   r}   r~   r[   r#   r   r\   r2   rC   rE   r;   rs   r?   r@   rA   rB   rt   task_runs              r3   r   zTaskRunResource.execute
  s    \ 3FT}?RPRT'00>##g-;;+FE::'#!  	
 	
 $$?'#! % 
 
 	
r5   )r-   r.   )r-   r6   rC   rD   rE   rF   r;   rG   r<   rH   r=   rI   r>   rJ   r?   rK   r@   rL   rA   rM   rB   rN   r-   r   r\   rF   r?   rK   r@   rL   rA   rM   rB   rN   r-   r   r\   rF   rh   ri   r?   rK   r@   rL   rA   rM   rB   rN   r-   r   r\   rF   rt   ru   rs   rv   r?   rK   r@   rL   rA   rM   r-   rw   rC   rD   rE   rF   r;   rG   rs   r   r?   rK   r@   rL   rA   rM   rB   rN   r-   r   rC   rD   rE   rF   r;   rG   rs   r   r?   rK   r@   rL   rA   rM   rB   rN   r-   r   rC   rD   rE   rF   r;   rG   rs   rv   r?   rK   r@   rL   rA   rM   rB   rN   r-   rw   __name__
__module____qualname____doc__r   r4   r9   r   r   r[   rf   rq   r   r   r   r   r5   r3   r)   r)   '   s         4 4 4 _4 : : : _: IM8<7;48 )-$("&;DE
 E
 E
 E
 E
 E
Z )-$("&;D!
 !
 !
 !
 !
 !
N #' )-$("&;D$
 $
 $
 $
 $
 $
V AE )-$("&U U U U U U6  IM04 )-$("&;D     X  IM )-$("&;D+ + + + + X+& IM@D )-$("&;DE
 E
 E
 E
 E
 E
 E
 E
r5   c            	         e Zd ZdZed6d            Zed7d            Zeeeedddedd8dZ	dddedd9d!Z
eddded"d:d&Zedddd'd;d-Zeeeddded.d<d0            Zeeddded1d=d4            Zeeddded.d>d5ZdS )?r*   r,   r-   #AsyncTaskRunResourceWithRawResponsec                     t          |           S r0   )r   r1   s    r3   r4   z&AsyncTaskRunResource.with_raw_responseY  s     34888r5   )AsyncTaskRunResourceWithStreamingResponsec                     t          |           S r8   )r   r1   s    r3   r9   z,AsyncTaskRunResource.with_streaming_responsec  s     9>>>r5   Nr:   rC   rD   rE   rF   r;   rG   r<   rH   r=   rI   r>   rJ   r?   rK   r@   rL   rA   rM   rB   rN   r   c       
           K   |                      dt          ||||||dt          j                   d{V t	          |||	|
          t
                     d{V S )rP   rQ   rR   NrS   rT   )rX   r   r   rY   r   r   rZ   s              r3   r[   zAsyncTaskRunResource.createl  s      h ZZ,"!* (/F%2!*  ':
 
 
 
 
 
 
 
 )+Q[el   !   
 
 
 
 
 
 
 
 	
r5   rS   r\   c          	        K   |st          d|          |                     d| t          ||||          t                     d{V S )r^   r_   r`   rS   ra   Nrb   re   s         r3   rf   zAsyncTaskRunResource.retrieve  s      2  	a_U[__```YY&f&&(+Q[el     
 
 
 
 
 
 
 
 	
r5   rg   rh   ri   r   c                  K   |st          d|          |                     d| dt          ||||t          d|it          j                   d{V           t                     d{V S )rk   r_   r`   rl   rh   Nrm   ra   )rc   rd   r   r   r   ro   r   rp   s          r3   rq   zAsyncTaskRunResource.result  s      0  	a_U[__```YY-f---(+'%1"K02H2\          "  
 
 
 
 
 
 
 
 	
r5   rr   rt   ru   rs   rv   rw   c               T    K   d
 fd}t          |||           d	{V S )ry   r\   rF   rt   ru   r-   rw   c                   K   |t          j                    z
  }                    | |           d {V }t          |          S r{   r|   r   s	       r3   r   z7AsyncTaskRunResource._wait_for_result.<locals>._fetcher  sp      !1!11G$(KK+'% %0 % %      O */6BBBr5   r   Nr   )_wait_for_result_asyncr   s   `  ```` r3   r   z%AsyncTaskRunResource._wait_for_result  sq      		C 		C 		C 		C 		C 		C 		C 		C 		C 		C ,6HW_``````````r5   r   r   c               
   K   d S r   r   r   s	            r3   r   zAsyncTaskRunResource.execute  s       r5   r   r   r   c               
   K   d S r   r   r   s	            r3   r   zAsyncTaskRunResource.execute&  s       (+sr5   c          
       K   ddi|pi }t          |          }t          j                    |z   }	|                     |||t	          ||          ||||           d{V }
|                     |
j        |	||||           d{V S )r   r   r   r   Nr   r   r   s              r3   r   zAsyncTaskRunResource.execute3  s      \ 3FT}?RPRT'00>##g-+FE::'#! % 	
 	
 	
 	
 	
 	
 	
 	
 **?'#! + 
 
 
 
 
 
 
 
 	
r5   )r-   r   )r-   r   r   r   r   r   r   r   r   r   r   r5   r3   r*   r*   R  s         9 9 9 _9 ? ? ? _? IM8<7;48 )-$("&;DE
 E
 E
 E
 E
 E
Z )-$("&;D!
 !
 !
 !
 !
 !
N #' )-$("&;D&
 &
 &
 &
 &
 &
Z AE )-$("&a a a a a a6  IM04(,$("&;D     X  IM(,$("&;D+ + + + + X+" IM@D )-$("&;DE
 E
 E
 E
 E
 E
 E
 E
r5   c                      e Zd ZddZdS )r.   r   r)   r-   Nonec                    || _         t          |j                  | _        t          |j                  | _        t          |j                  | _        d S r   )	_task_runr   r[   rf   rq   r2   r   s     r3   __init__z'TaskRunResourceWithRawResponse.__init__|  sT    !-O
 
 0
 
 .O
 
r5   Nr   r)   r-   r   r   r   r   r   r   r5   r3   r.   r.   {  (        
 
 
 
 
 
r5   r.   c                      e Zd ZddZdS )r   r   r*   r-   r   c                    || _         t          |j                  | _        t          |j                  | _        t          |j                  | _        d S r   )r   r   r[   rf   rq   r   s     r3   r   z,AsyncTaskRunResourceWithRawResponse.__init__  sT    !3O
 
 6
 
 4O
 
r5   Nr   r*   r-   r   r   r   r5   r3   r   r     r   r5   r   c                      e Zd ZddZdS )r6   r   r)   r-   r   c                    || _         t          |j                  | _        t          |j                  | _        t          |j                  | _        d S r   )r   r   r[   rf   rq   r   s     r3   r   z-TaskRunResourceWithStreamingResponse.__init__  sT    !2O
 
 5
 
 3O
 
r5   Nr   r   r   r5   r3   r6   r6     r   r5   r6   c                      e Zd ZddZdS )r   r   r*   r-   r   c                    || _         t          |j                  | _        t          |j                  | _        t          |j                  | _        d S r   )r   r   r[   rf   rq   r   s     r3   r   z2AsyncTaskRunResourceWithStreamingResponse.__init__  sT    !8O
 
 ;
 
 9O
 
r5   Nr   r   r   r5   r3   r   r     r   r5   r   )A
__future__r   r}   typingr   r   r   r   r   httpxparallel.lib._timer	   typesr   r   _typesr   r   r   r   r   r   r   _utilsr   r   _compatr   	_resourcer   r   	_responser   r   r   r   _base_clientr   types.task_runr   types.task_run_resultr   types.task_spec_paramr    r!   r"   lib._parsing._task_specr#   types.parsed_task_run_resultr$   lib._parsing._task_run_resultr%   r   r&   r   r'   !types.shared_params.source_policyr(   __all__r)   r*   r.   r   r6   r   r   r5   r3   <module>r      s   # " " " " "  8 8 8 8 8 8 8 8 8 8 8 8 8 8  4 4 4 4 4 4 B B B B B B B B J J J J J J J J J J J J J J J J J J ; ; ; ; ; ; ; ; % % % % % % 9 9 9 9 9 9 9 9            0 / / / / / $ $ $ $ $ $ 1 1 1 1 1 1 H H H H H H H H H H ; ; ; ; ; ; > > > > > >         
 = < < < < <4
5h
 h
 h
 h
 h
o h
 h
 h
V	f
 f
 f
 f
 f
+ f
 f
 f
R	
 
 
 
 
 
 
 

 
 
 
 
 
 
 

 
 
 
 
 
 
 

 
 
 
 
 
 
 
 
 
r5   