+
    Vi                         R t ^ RIHtHtHtHtHtHt ^RIH	t	H
t
HtHtHtHt ^RIHtHt ^RIHtHtHtHt ]! R4      tR R ltR R	 ltR
 R ltR R ltR# )z,
Search functionality for Firecrawl v2 API.
)DictAnyUnionListTypeVarType)SearchRequest
SearchDataDocumentSearchResultWebSearchResultNewsSearchResultImages)normalize_document_input_map_search_result_keys)
HttpClienthandle_response_errorvalidate_scrape_optionsprepare_scrape_optionsTc                <    V ^8  d   QhR\         R\        R\        /# )   clientrequestreturn)r   r   r	   )formats   "Z/home/ubuntu/hermes-agent/venv/lib/python3.14/site-packages/firecrawl/v2/methods/search.py__annotate__r      s&     ' ''' '    c                z   \        V4      p V P                  RV4      pVP                  ^8w  d   \        VR4       VP	                  4       pVP                  R4      '       g   \        VR4       VP                  R/ 4      ;'       g    / p\        4       pRV9   d   \        VR,          \        4      Vn	        RV9   d   \        VR,          \        4      Vn        RV9   d   \        VR,          \        4      Vn        V#   \         d0   p\        TR4      '       d   \        \!        TR4      R4       ThR	p?ii ; i)
z
Search for documents.

Args:
    client: HTTP client instance
    request: Search request
    
Returns:
    SearchData with search results grouped by source type
    
Raises:
    FirecrawlError: If the search operation fails
z
/v2/searchsearchsuccessdatawebnewsimagesresponseN)_prepare_search_requestpoststatus_coder   jsongetr	   _transform_arrayr   r"   r   r#   r   r$   	Exceptionhasattrgetattr)r   r   request_datar%   response_datar!   outerrs   &&      r   r   r      s
   " +73L;;|\:3&!(H5   ++!(H5  ,22lD=&tE{ODCGT>'V6FGCHt)$x.:LMCJ
  3
##!'#z":HE	s%   AD  #$D  A7D   D:*D55D:c          	          V ^8  d   QhR\         \        ,          R\        \        ,          R\         \        \        R3,          ,          /# )r   arrresult_typer   r
   )r   r   r   r   r   )r   s   "r   r   r   5   s7     % %$s) %$q' %d5JCW>X %r   c           
     &   . pV  EF  pV'       d   \        V\        4      '       d   RV9   g2   RV9   g+   RV9   g$   RV9   g   RV9   g   RV9   g   RV9   g   RV9   d&   VP                  \        R/ \	        V4      B 4       K  R	pV\
        8X  d   R
pMV\        8X  d   RpMV\        8X  d   RpV'       d%   \        W44      pVP                  V! R/ VB 4       K  VP                  V! R/ VB 4       K  VP                  V! VR7      4       EK
  	  V# )a  
Transforms an array of items into a list of result_type or Document.
If the item dict contains any of the special keys, it is treated as a Document.
Otherwise, it is treated as result_type.
If the item is not a dict, it is wrapped as result_type with url=item.
markdownhtmlrawHtmllinks
screenshotchangeTrackingsummaryr)   Nr$   r#   r"   )url )	
isinstancedictappendr
   r   r   r   r   r   )r4   r5   resultsitemresult_type_namenormalized_items   &&    r   r+   r+   5   s     +-GJtT**d"$T!4$ D(T!$xI*B4*HIJ#' "44'/$ $44'-$ O3',$#&=d&UONN;#A#ABNN;#6#67NN;4019 : Nr   c                0    V ^8  d   QhR\         R\         /# r   r   r   )r   )r   s   "r   r   r   \   s     C Cm C Cr   c                   V P                   '       d!   V P                   P                  4       '       g   \        R4      hV P                  e9   V P                  ^ 8:  d   \        R4      hV P                  ^d8  d   \        R4      hV P                  e9   V P                  ^ 8:  d   \        R4      hV P                  R8  d   \        R4      hV P
                  e   0 RmpV P
                   Fr  p\        V\        4      '       d   W!9  d   \        RV RV 24      hK2  \        VR	4      '       g   KF  VP                  V9  g   KY  \        RVP                   RV 24      h	  V P                  e   0 RmpV P                   Fr  p\        V\        4      '       d   WC9  d   \        R
V RV 24      hK2  \        VR	4      '       g   KF  VP                  V9  g   KY  \        R
VP                   RV 24      h	  V P                  eT   \        V P                  \        4      '       d)   \        V P                  P                  4       4      ^ 8X  d   \        R4      hV P                  eT   \        V P                  \        4      '       d)   \        V P                  P                  4       4      ^ 8X  d   \        R4      hV P                  e   \        V P                  4       V # )z
Validate and normalize search request.

Args:
    request: Search request to validate
    
Returns:
    Validated request
    
Raises:
    ValueError: If request is invalid
zQuery cannot be emptyzLimit must be positivezLimit cannot exceed 100zTimeout must be positivei z*Timeout cannot exceed 300000ms (5 minutes)zInvalid source type: z. Valid types: typezInvalid category type: z#Location must be a non-empty stringztbs must be a non-empty string>   r"   r#   r$   >   pdfgithubresearch)querystrip
ValueErrorlimittimeoutsourcesr@   strr-   rJ   
categorieslocationlentbsscrape_optionsr   )r   valid_sourcessourcevalid_categoriescategorys   &    r   _validate_search_requestr^   \   si    === 3 3 5 5011 }} ==A566==3677 "??a788??V#IJJ "1ooF&#&&.$'<VHOTaSb%cdd /((;;m3$'<V[[MYfXg%hii & %8**H(C((3$'>xjXhWi%jkk 46**==(88$'>x}}o_]m\n%opp + #'**C00C8H8H8N8N8P4QUV4VBCC {{'++s++s7;;3D3D3F/G1/L=>> ) 6 67Nr   c                R    V ^8  d   QhR\         R\        \        \        3,          /# rH   )r   r   rT   r   )r   s   "r   r   r      s"     ) )] )tCH~ )r   c                   \        V 4      pVP                  RRR7      pRV9  d   VP                  e   VP                  VR&   RV9  d   VP                  e   VP                  VR&   VP                  e"   VP                  VR&   VP                  RR4       VP                  e4   \        VP                  4      pV'       d   W2R&   VP                  R	R4       \        VR
R4      pVe&   \        V4      P                  4       pV'       d   WRR
&   V# )zs
Prepare a search request payload.

Args:
    request: Search request
    
Returns:
    Request payload dictionary
T)exclude_noneby_aliasrQ   NrR   ignoreInvalidURLsignore_invalid_urlsscrapeOptionsrY   integration)r^   
model_dumprQ   rR   rd   poprY   r   r.   rT   rO   )r   validated_requestr!   scrape_dataintegration_valueintegration_strs   &     r   r&   r&      s    19''TD'ID d066B)//W!2!:!:!F+33Y ,,8$5$I$I !&- ''3,->-M-MN$/!!4(   1=$G$/0668"1Kr   N)__doc__typingr   r   r   r   r   r   typesr   r	   r
   r   r   r   utils.normalizer   r   utilsr   r   r   r   r   r   r+   r^   r&   r?   r   r   <module>rr      sB    9 8 n n O f fCL'R%NCL)r   