
    i                     6   d dl mZmZmZmZmZmZ d dlZddlm	Z	m
Z
 ddlmZ ddlmZ ddddddddeee                  d	ed
ee         dee         dee         dee         deed                  deeee
f                  deeef         fdZdeeef         deeef         fdZddddddddedeee                  d	ed
ee         dee         dee         dee         deed                  deeee
f                  de	fdZdedede	fdZddddedededee         de	f
dZddddddddddedeee                  d	ed
ee         dee         dedee         dee         dee         deed                  deeee
f                  de	fdZdededefd ZdS )!    )AnyDictListLiteralOptionalUnionN   )AgentResponseAgentWebhookConfig)AsyncHttpClient)_normalize_schema)schemaintegrationmax_creditsstrict_constrain_to_urlsmodelwebhookurlspromptr   r   r   r   r   )zspark-1-prozspark-1-minir   returnc                   i }| | |d<   ||d<   |<t          |          }	|	|	|d<   n%t          dt          |          j         d          |Et	          |                                          r$t	          |                                          |d<   ||dk    r||d<   ||r||d	<   |||d
<   |4t          |t                    r||d<   n|                    d          |d<   |S )Nr   r   r   zInvalid schema type: zN. Schema must be a dict, Pydantic BaseModel class, or Pydantic model instance.r   r   
maxCreditsstrictConstrainToURLsr   r   T)exclude_none)r   
ValueErrortype__name__strstrip
isinstance
model_dump)
r   r   r   r   r   r   r   r   bodynormalized_schemas
             h/home/agentuser/.hermes/hermes-agent/venv/lib/python3.11/site-packages/firecrawl/v2/methods/aio/agent.py_prepare_agent_requestr%   	   s;    DVDN-f55(.DNN_V(= _ _ _   3{#3#3#9#9#;#;!+..4466];??(\+0H+(@$%Wgs## 	D%DOO%00d0CCDOK    payloadc                 p    t          |           }d|v rd|vr|d         |d<   d|v rd|vr|d         |d<   |S )N	expiresAt
expires_atcreditsUsedcredits_used)dict)r'   outs     r$   !_normalize_agent_response_payloadr/   1   sZ    
w--Ccl#55,Lc 9 9!-0NJr&   clientc          
         K   t          ||||||||          }	|                     d|	           d {V }
t          |
                                          }t	          di |S )Nr   r   r   r   r   r   r   z	/v2/agent )r%   postr/   jsonr
   )r0   r   r   r   r   r   r   r   r   r"   respr'   s               r$   start_agentr7   :   s       "!9	 	 	D [$////////D/		<<G##7###r&   job_idc                    K   |                      d|            d {V }t          |                                          }t          di |S )N
/v2/agent/r3   )getr/   r5   r
   )r0   r8   r6   r'   s       r$   get_agent_statusr<   U   s[      11122222222D/		<<G##7###r&      poll_intervaltimeoutr?   r@   c                F  K   t          j                                                    }	 t          | |           d {V }|j        dv r|S |.t          j                                                    |z
  |k    r|S t          j        t          d|                     d {V  z)NT)	completedfailed	cancelled   )asyncioget_event_looptimer<   statussleepmax)r0   r8   r?   r@   start_tsrI   s         r$   
wait_agentrM   [   s       %'',,..H3'77777777=@@@MG$:$<$<$A$A$C$Ch$NRY#Y#YMmC=112222222223r&   )r   r   r?   r@   r   r   r   r   c       	            K   t          | |||||||	|
	  	         d {V }t          |dd           }|s|S t          | |||           d {V S )Nr2   idr>   )r7   getattrrM   )r0   r   r   r   r   r?   r@   r   r   r   r   startedr8   s                r$   agentrR   l   s        !9
 
 
 
 
 
 
 
 
G WdD))F FF-QXYYYYYYYYYYr&   c                    K   |                      d|            d{V }|                                                    dd          S )a  
    Cancel a running agent job.

    Args:
        client: Async HTTP client instance
        job_id: ID of the agent job to cancel

    Returns:
        bool: True if the agent was cancelled, False otherwise

    Raises:
        Exception: If the cancellation fails
    r:   NsuccessF)deleter5   r;   )r0   r8   r6   s      r$   cancel_agentrV      sP       4F4455555555D99;;??9e,,,r&   )typingr   r   r   r   r   r   rF   typesr
   r   utils.http_client_asyncr   utils.validationr   r   intboolr%   r/   r7   r<   rM   rR   rV   r3   r&   r$   <module>r]      s   < < < < < < < < < < < < < < < <  6 6 6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 1 1 1 !!%!%/3>B8<% % %
49
% % SM	%
 #% #% 'tn% G9:;% eC!3345% 
#s(^% % % %PtCH~ $sCx.     !!%!%/3>B8<$ $ $$
49
$ 	$
 SM$ #$ #$ 'tn$ G9:;$ eC!3345$ $ $ $ $6$? $C $M $ $ $ $ !3 3 333 	3
 c]3 3 3 3 3, !!%!!%/3>B8<Z Z ZZ
49
Z 	Z
 SMZ #Z Z c]Z #Z 'tnZ G9:;Z eC!3345Z Z Z Z Z>- - - - - - - - -r&   