
    Sj@                     n   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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)
HttpClient)handle_response_error)_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
             M/root/.hermes/venv/lib/python3.12/site-packages/firecrawl/v2/methods/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_payloadr0   2   sL    
w-Ccl#5,Lc 9!-0NJr'   clientc          
          t        ||||||||      }	| j                  d|	      }
|
j                  st        |
d       t	        |
j                               }t        di |S )Nr   r   r   r   r   r   r   z	/v2/agentagent )r&   postokr   r0   jsonr
   )r1   r   r   r   r   r   r   r   r   r#   respr(   s               r%   start_agentr:   ;   sg     "!9	D ;;{D)D77dG,/		<G#7##r'   job_idc                     | j                  d|       }|j                  st        |d       t        |j	                               }t        di |S )N
/v2/agent/zagent-statusr5   )getr7   r   r0   r8   r
   )r1   r;   r9   r(   s       r%   get_agent_statusr?   X   sF    ::
6(+,D77dN3/		<G#7##r'   poll_intervaltimeoutrA   rB   c                    t        j                          }	 t        | |      }|j                  dv r|S |t        j                          |z
  |kD  r|S t        j                  t	        d|             Z)N)	completedfailed	cancelled   )timer?   statussleepmax)r1   r;   rA   rB   start_tsrI   s         r%   
wait_agentrM   `   se     yy{H
!&&1==@@MDIIK($:g#EM

3q-() r'   )r   r   rA   rB   r   r   r   r   c       	         j    t        | |||||||	|
	      }t        |dd       }|s|S t        | |||      S )Nr3   idr@   )r:   getattrrM   )r1   r   r   r   r   rA   rB   r   r   r   r   startedr;   s                r%   r4   r4   q   sR     !9
G WdD)FffM7SSr'   c                     | j                  d|       }|j                  st        |d       |j                         j	                  dd      S )a
  
    Cancel a running agent job.

    Args:
        client: 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=   zcancel agentsuccessF)deleter7   r   r8   r>   )r1   r;   r9   s      r%   cancel_agentrU      sA     ==:fX./D77dN399;??9e,,r'   )typingr   r   r   r   r   r   rH   typesr
   r   utils.http_clientr   utils.error_handlerr   utils.validationr   r   intboolr&   r0   r:   r?   rM   r4   rU   r5   r'   r%   <module>r]      s   < <  5 * 7 0 !!%!%/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$ $:$Z $ $ $ !*** 	*
 c]* *, !!%!!%/3>B8<TT
49
T 	T
 SMT #T T c]T #T 'tnT G9:;T eC!3345T T>- -S -T -r'   