
    _j                     x   S SK JrJrJrJrJrJr  S SKrSSKJ	r	J
r
  SSKJr  SSKJr  SSSSSSS.S\\\      S	\S
\\   S\\   S\\   S\\   S\\S      S\\\\
4      S\\\4   4S jjrS\\\4   S\\\4   4S jrSSSSSSS.S\S\\\      S	\S
\\   S\\   S\\   S\\   S\\S      S\\\\
4      S\	4S jjrS\S\S\	4S jrSSS.S\S\S\S\\   S\	4
S jjrSSSSSSSSS.S\S\\\      S	\S
\\   S\\   S\S\\   S\\   S\\   S\\S      S\\\\
4      S\	4S jjrS\S\S\4S  jrg)!    )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                   0 nU b  XS'   XS'   Ub5  [        U5      n	U	b  XS'   O"[        S[        U5      R                   S35      eUb:  [	        U5      R                  5       (       a  [	        U5      R                  5       US'   Ub
  US:  a  XHS'   Ub  U(       a  XXS	'   Ub  XhS
'   Ub-  [        U[        5      (       a  XxS'   U$ UR                  SS9US'   U$ )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
             S/home/rurouni/.local/lib/python3.13/site-packages/firecrawl/v2/methods/aio/agent.py_prepare_agent_requestr%   	   s    DVN-f5(.N'V(=(='> ?_ _  3{#3#9#9#;#;!+.446];?(\+0H(@$%Wgs##%O K &00d0CDOK    payloadc                 l    [        U 5      nSU;   a  SU;  a  US   US'   SU;   a  SU;  a  US   US'   U$ )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                   #    [        UUUUUUUUS9n	U R                  SU	5      I S h  vN n
[        U
R                  5       5      n[	        S0 UD6$  N(7f)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   :   sa      "!9	D [$//D/		<G#7## 0s   &AA)Ajob_idc                    #    U R                  SU 35      I S h  vN n[        UR                  5       5      n[        S0 UD6$  N(7f)N
/v2/agent/r3   )getr/   r5   r
   )r0   r8   r6   r'   s       r$   get_agent_statusr<   U   s@     j122D/		<G#7## 3s   AA)A   poll_intervaltimeoutr?   r@   c                V  #    [         R                  " 5       R                  5       n [        X5      I S h  vN nUR                  S;   a  U$ Ub,  [         R                  " 5       R                  5       U-
  U:  a  U$ [         R
                  " [        SU5      5      I S h  vN   M~   No N7f)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       	            #    [        U UUUUUUU	U
S9	I S h  vN n[        USS 5      nU(       d  U$ [        XXVS9I S h  vN $  N, N7f)Nr2   idr>   )r7   getattrrM   )r0   r   r   r   r   r?   r@   r   r   r   r   startedr8   s                r$   agentrR   l   sd       !9
 
G WdD)FF-YYY
 Zs    AA'AA AAc                    #    U R                  SU 35      I Sh  vN nUR                  5       R                  SS5      $  N$7f)z
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&   