
    Sj                     b   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y)!    )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<   |5t        |      }	|	|	|d<   n"t        dt        |      j                   d      |5t	        |      j                         rt	        |      j                         |d<   |
|dkD  r||d<   ||r||d	<   |||d
<   |,t        |t              r||d<   |S |j                  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
             Q/root/.hermes/venv/lib/python3.12/site-packages/firecrawl/v2/methods/aio/agent.py_prepare_agent_requestr%   	   s    DVDN-f5(.DN'V(=(='> ?_ _  3{#3#9#9#;!+.446];?(\+0H(@$%Wgs#%DO K &00d0CDOK    payloadc                 \    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   sL    
w-Ccl#5,Lc 9!-0NJr&   clientc          
         K   t        ||||||||      }	| j                  d|	       d {   }
t        |
j                               }t	        di |S 7 (w)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   :   sb      "!9	D [$//D/		<G#7## 0s   )AA)Ajob_idc                    K   | j                  d|        d {   }t        |j                               }t        di |S 7 (w)N
/v2/agent/r3   )getr/   r5   r
   )r0   r8   r6   r'   s       r$   get_agent_statusr<   U   sA     j122D/		<G#7## 3s   AA)A   poll_intervaltimeoutr?   r@   c                H  K   t        j                         j                         }	 t        | |       d {   }|j                  dv r|S |*t        j                         j                         |z
  |kD  r|S t        j
                  t        d|             d {    x7 h7 w)N)	completedfailed	cancelled   )asyncioget_event_looptimer<   statussleepmax)r0   r8   r?   r@   start_tsrI   s         r$   
wait_agentrM   [   s      %%',,.H
'77==@@MG$:$:$<$A$A$Ch$NRY#YMmmC=1222 7
 	3s"   3B"BA"B"B B" B")r   r   r?   r@   r   r   r   r   c       	            K   t        | |||||||	|
	       d {   }t        |dd       }|s|S t        | |||       d {   S 7 ,7 w)Nr2   idr>   )r7   getattrrM   )r0   r   r   r   r   r?   r@   r   r   r   r   startedr8   s                r$   agentrR   l   sk       !9
 
G WdD)FFF-QXYYY
 Zs!   AA'AA	A	Ac                    K   | j                  d|        d{   }|j                         j                  dd      S 7 $w)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      s<      F8455D99;??9e,, 6s   A?%A)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 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
 c]3 3, !!%!!%/3>B8<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>- - - -r&   