
    _j~                    	   % S r SSKrSSKrSSKrSSKJrJrJrJrJ	r	J
r
JrJrJr  SSKrSSKJr  SSKrSSKrSSKrSSKrSSKrSSKr\R,                  " S5      r\R0                  \S'   S r\" 5       r\" S5      r " S	 S
\R:                  5      r " S S\R:                  5      r " S S\R:                  5      r  " S S\R:                  5      r! " S S\R:                  \\   5      r" " S S\R:                  5      r# " S S\R:                  5      r$ " S S\R:                  5      r% " S S\R:                  5      r& " S S\R:                  5      r' " S S\R:                  5      r( " S S \R:                  5      r) " S! S"\R:                  5      r* " S# S$\R:                  5      r+ " S% S&\R:                  5      r, " S' S(\R:                  5      r- " S) S*\R:                  5      r. " S+ S,\R:                  5      r/ " S- S.\R:                  5      r0 " S/ S0\R:                  5      r1 " S1 S2\&5      r2 " S3 S4\"\   \\   5      r3 " S5 S6\R:                  5      r4 " S7 S8\R:                  5      r5 " S9 S:\R:                  5      r6 " S; S<\R:                  5      r7 " S= S>\R:                  5      r8 " S? S@\R:                  5      r9 " SA SB\R:                  5      r: " SC SD\R:                  5      r; " SE SF\R:                  5      r< " SG SH\R:                  5      r= " SI SJ\R:                  \\   5      r> " SK SL\R:                  5      r? " SM SN\R:                  5      r@ " SO SP\R:                  5      rA " SQ SR\R:                  5      rB " SS ST\R:                  5      rC " SU SV\R:                  5      rD " SW SX\R:                  5      rE " SY SZ\R:                  5      rF " S[ S\\R:                  5      rG " S] S^\R:                  5      rH " S_ S`\R:                  5      rI " Sa Sb\R:                  5      rJ " Sc Sd\R:                  5      rK " Se Sf\R:                  5      rL " Sg Sh\R:                  5      rM " Si Sj\R:                  5      rN " Sk Sl\R:                  5      rO " Sm SN\R:                  5      r@ " Sn SH\R:                  5      r= " So Sp5      rP " Sq Sr5      rQ " Ss St\P5      rR " Su Sv\Q5      rSg)wa"  
Firecrawl v1 API Client - Legacy Implementation

This module provides the legacy v1 implementation of the Firecrawl SDK.
It contains the complete `V1FirecrawlApp` class with all v1 API methods and types
for backward compatibility. This is used by the unified client to provide
version-specific access patterns like app.v1.scrape_url().

Classes:
    - V1FirecrawlApp: Legacy v1 client for interacting with the Firecrawl API.
    - AsyncV1FirecrawlApp: Async version of the v1 client.
    - CrawlWatcher: WebSocket-based crawl monitoring for v1.
    N)	AnyDictOptionalListUnionCallableLiteralTypeVarGeneric)datetime	firecrawlloggerc                      SSK Jn   [        R                  R	                  [
        5      nU " [        R                  R                  US5      5      R                  5       n[        R                  " SU[        R                  5      nU(       a  UR                  S5      R                  5       $ g ! [         a    [        S5         g f = f)Nr   )Pathz__init__.pyz"^__version__ = ['\"]([^'\"]*)['\"]   z&Failed to get version from __init__.py)pathlibr   ospathdirname__file__join	read_textresearchMgroupstrip	Exceptionprint)r   package_pathversion_fileversion_matchs       H/home/rurouni/.local/lib/python3.13/site-packages/firecrawl/v1/client.pyget_versionr$      s    	WW__X.l"'',,|]CDNNPlii E|UWUYUYZm	$$Q'--/
/ 
	 45s   B(B, ,CCTc                   B    \ rS rSr% SrSr\S   \S'   Sr\	\
   \S'   Srg)V1AgentOptionsP   zConfiguration for the agent.FIRE-1modelNprompt )__name__
__module____qualname____firstlineno____doc__r*   r	   __annotations__r+   r   str__static_attributes__r,       r#   r'   r'   P   s"    &'E78' FHSM r5   r'   c                   .    \ rS rSr% SrSr\S   \S'   Srg)V1AgentOptionsExtractU   2Configuration for the agent in extract operations.r)   r*   r,   N	r-   r.   r/   r0   r1   r*   r	   r2   r4   r,   r5   r#   r7   r7   U       <'E78'r5   r7   c                   :    \ rS rSr% Sr\\   \S'   \\   \S'   Srg)V1ActionsResultY   z,Result of actions performed during scraping.screenshotspdfsr,   N)	r-   r.   r/   r0   r1   r   r3   r2   r4   r,   r5   r#   r=   r=   Y   s    6c
s)Or5   r=   c                       \ rS rSr% SrSr\\   \S'   \\S'   \\S'   Sr	\\
\\4      \S'   \R                  " SSS	9r\\   \S
'   Srg)V1ChangeTrackingData^   z&
Data for the change tracking format.
NpreviousScrapeAtchangeStatus
visibilitydiffjsonalias
json_fieldr,   )r-   r.   r/   r0   r1   rD   r   r3   r2   rG   r   r   pydanticFieldrK   r4   r,   r5   r#   rB   rB   ^   sS     '+hsm*O%)D(4S>
") (t6 BJBr5   rB   c                   B   \ rS rSr% SrSr\\   \S'   Sr	\\   \S'   Sr
\\   \S'   Sr\\   \S'   Sr\\\      \S'   Sr\\   \S	'   \R"                  " SS
S9r\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Srg)V1FirecrawlDocumenth   z-Document retrieved or processed by Firecrawl.NurlmarkdownhtmlrawHtmllinksextractrH   rI   rK   
screenshotmetadataactionstitledescriptionchangeTrackingr,   )r-   r.   r/   r0   r1   rQ   r   r3   r2   rR   rS   rT   rU   r   rV   r%   rL   rM   rK   rW   rX   r   rY   r=   rZ   r[   r\   rB   r4   r,   r5   r#   rO   rO   h   s    7C#"Hhsm"D(3-!GXc]!!%E8DI%GXa[&nnT@J@ $J$"Hhsm")-GXo&-E8C=!%K#%59NH129r5   rO   c                   H    \ rS rSr% SrSr\\   \S'   Sr	\\
\      \S'   Srg)V1LocationConfigx   z$Location configuration for scraping.Ncountry	languagesr,   )r-   r.   r/   r0   r1   r`   r   r3   r2   ra   r   r4   r,   r5   r#   r^   r^   x   s&    .!GXc]!%)IxS	")r5   r^   c                       \ rS rSr% Sr\\S'   Sr\\	\\4      \S'   Sr
\\	\\4      \S'   Sr\\\S         \S'   S	rg)
V1WebhookConfig}   zConfiguration for webhooks.rQ   NheadersrX   )	completedfailedpagestartedeventsr,   )r-   r.   r/   r0   r1   r3   r2   re   r   r   rX   rj   r   r	   r4   r,   r5   r#   rc   rc   }   sR    %	H(,GXd38n%,)-HhtCH~&-PTFHT'"JKLMTr5   rc   c                       \ rS rSr% SrSr\\\S         \	S'   \
R                  " SSS9r\\   \	S'   Sr\\   \	S	'   Sr\\   \	S
'   Srg)V1ChangeTrackingOptions   z"Configuration for change tracking.N)zgit-diffrH   modesschemarI   schema_fieldr+   tagr,   )r-   r.   r/   r0   r1   rn   r   r   r	   r2   rL   rM   rp   r   r+   r3   rq   r4   r,   r5   r#   rl   rl      sT    ,9=E8D!3456="*..X"FL(3-F FHSM C#r5   rl   c                      \ rS rSr% SrSr\\\S         \	S'   Sr
\\\\4      \	S'   Sr\\\      \	S'   Sr\\\      \	S'   Sr\\   \	S	'   Sr\\   \	S
'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\S      \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr g)V1ScrapeOptions   #Parameters for scraping operations.N
rR   rS   rT   contentrU   rW   screenshot@fullPagerV   rH   r\   formatsre   includeTagsexcludeTagsonlyMainContentwaitFor0u  timeoutlocationmobileskipTlsVerificationremoveBase64ImagesblockAdsbasicstealthenhancedautoproxychangeTrackingOptionsmaxAgestoreInCacheparsePDFr,   )!r-   r.   r/   r0   r1   ry   r   r   r	   r2   re   r   r3   rz   r{   r|   boolr}   intr   r   r^   r   r   r   r   r   r   rl   r   r   r   r4   r,   r5   r#   rs   rs      s3   - eiGXd7  $_  `  a  b  i(,GXd38n%,'+K$s)$+'+K$s)$+&*OXd^*!GXc]!"GXc]"+/Hh'(/!FHTN!*.$.)--#Hhtn#GKE8GBCDK?C8$;<C FHSM #'L(4.'#Hhtn#r5   rs   c                   R    \ rS rSr% Sr\S   \S'   Sr\\	   \S'   Sr
\\   \S'   Srg)	V1WaitAction   z'Wait action to perform during scraping.waittypeNmillisecondsselectorr,   )r-   r.   r/   r0   r1   r	   r2   r   r   r   r   r3   r4   r,   r5   r#   r   r      s+    1
&/"&L(3-&"Hhsm"r5   r   c                   R    \ rS rSr% Sr\S   \S'   Sr\\	   \S'   Sr
\\   \S'   Srg)	V1ScreenshotAction   z-Screenshot action to perform during scraping.rW   r   NfullPagequalityr,   )r-   r.   r/   r0   r1   r	   r2   r   r   r   r   r   r4   r,   r5   r#   r   r      s,    7
,
#Hhtn#!GXc]!r5   r   c                   4    \ rS rSr% Sr\S   \S'   \\S'   Srg)V1ClickAction   z(Click action to perform during scraping.clickr   r   r,   N	r-   r.   r/   r0   r1   r	   r2   r3   r4   r,   r5   r#   r   r      s    2
'
Mr5   r   c                   4    \ rS rSr% Sr\S   \S'   \\S'   Srg)V1WriteAction   z(Write action to perform during scraping.writer   textr,   Nr   r,   r5   r#   r   r      s    2
'

Ir5   r   c                   4    \ rS rSr% Sr\S   \S'   \\S'   Srg)V1PressAction   z(Press action to perform during scraping.pressr   keyr,   Nr   r,   r5   r#   r   r      s    2
'
	Hr5   r   c                   N    \ rS rSr% Sr\S   \S'   \S   \S'   Sr\\	   \S'   S	r
g)
V1ScrollAction   z)Scroll action to perform during scraping.scrollr   )updown	directionNr   r,   )r-   r.   r/   r0   r1   r	   r2   r   r   r3   r4   r,   r5   r#   r   r      s)    3
(
|$$"Hhsm"r5   r   c                   *    \ rS rSr% Sr\S   \S'   Srg)V1ScrapeAction   z)Scrape action to perform during scraping.scraper   r,   N)r-   r.   r/   r0   r1   r	   r2   r4   r,   r5   r#   r   r      s    3
(
r5   r   c                   4    \ rS rSr% Sr\S   \S'   \\S'   Srg)V1ExecuteJavascriptAction   z5Execute javascript action to perform during scraping.executeJavascriptr   scriptr,   Nr   r,   r5   r#   r   r      s    ?
%
&&Kr5   r   c                   l    \ rS rSr% Sr\S   \S'   Sr\\S      \S'   Sr	\\
   \S'   Sr\\   \S	'   S
rg)V1PDFAction   z&PDF action to perform during scraping.pdfr   N)A0A1A2A3A4A5A6LetterLegalTabloidLedgerformat	landscapescaler,   )r-   r.   r/   r0   r1   r	   r2   r   r   r   r   r   floatr4   r,   r5   r#   r   r      s@    0
%.rvFHWmnov $Ix~$!E8E?!r5   r   c                   .    \ rS rSr% SrSr\S   \S'   Srg)V1ExtractAgent   r9   r)   r*   r,   Nr:   r,   r5   r#   r   r      r;   r5   r   c                       \ rS rSr% SrSr\\   \S'   \	R                  " SSS9r\\   \S'   Sr\\   \S'   Sr\\   \S	'   S
rg)V1JsonConfig   zConfiguration for extraction.Nr+   ro   rI   rp   systemPromptagentr,   )r-   r.   r/   r0   r1   r+   r   r3   r2   rL   rM   rp   r   r   r   r   r4   r,   r5   r#   r   r      sI    ' FHSM "*..X"FL(3-F"&L(3-&&*E8N#*r5   r   c                       \ rS rSr% SrSr\\   \S'   Sr	\\   \S'   Sr
\\\\\\\\\\\\4	         \S'   Sr\\   \S'   Sr\\   \S'   S	rg)
V1ScrapeParams   ru   NrV   jsonOptionsrY   r   webhookr,   )r-   r.   r/   r0   r1   rV   r   r   r2   r   rY   r   r   r   r   r   r   r   r   r   r   r   r   r'   r   rc   r4   r,   r5   r#   r   r      s    -&*GXl#**.K,'. }AGXd5/A=R_anp~  AO  Qj  lw  "w  x  y  z  A&*E8N#*)-GXo&-r5   r   c                   P    \ rS rSr% SrSr\\S'   Sr\	\
   \S'   Sr\	\
   \S'   Srg)	V1ScrapeResponse   z"Response from scraping operations.TsuccessNwarningerrorr,   )r-   r.   r/   r0   r1   r   r   r2   r   r   r3   r   r4   r,   r5   r#   r   r      s+    ,GT!GXc]!E8C=r5   r   c                   ~    \ rS rSr% SrSr\\   \S'   Sr	\\   \S'   Sr
\\S'   Sr\\   \S'   Sr\\\      \S	'   S
rg)V1BatchScrapeResponse   z&Response from batch scrape operations.NidrQ   Tr   r   invalidURLsr,   )r-   r.   r/   r0   r1   r   r   r3   r2   rQ   r   r   r   r   r   r4   r,   r5   r#   r   r      sL    0BC#GTE8C='+K$s)$+r5   r   c                       \ rS rSr% SrSr\\S'   \S   \S'   \	\S'   \	\S'   \	\S	'   \
\S
'   Sr\\   \S'   \\   \S'   Srg)V1BatchScrapeStatusResponse   z)Response from batch scrape status checks.Tr   scrapingrf   rg   	cancelledstatusrf   totalcreditsUsed	expiresAtNnextdatar,   r-   r.   r/   r0   r1   r   r   r2   r	   r   r   r   r   r3   r   rO   r4   r,   r5   r#   r   r      sK    3GTBCCNJD(3-
"
##r5   r   c                      \ rS rSr% SrSr\\\      \	S'   Sr
\\\      \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S	'   Sr\\   \	S
'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\\\4      \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Sr\\   \	S'   Srg)V1CrawlParams   z#Parameters for crawling operations.NincludePathsexcludePathsmaxDepthmaxDiscoveryDepthlimitallowBackwardLinkscrawlEntireDomainallowExternalLinksignoreSitemapscrapeOptionsr   deduplicateSimilarURLsignoreQueryParametersregexOnFullURLdelaymaxConcurrencyallowSubdomainsr,   ) r-   r.   r/   r0   r1   r   r   r   r3   r2   r   r   r   r   r   r   r   r   r   r   r   rs   r   r   rc   r  r  r  r  r  r  r4   r,   r5   r#   r   r      s   -(,L(49%,(,L(49%,"Hhsm"'+x}+E8C=)--(,x~,)--$(M8D>(/3M8O,359GXeC0129-1HTN1,08D>0%)NHTN)E8C=$(NHSM(&*OXd^*r5   r   c                   d    \ rS rSr% SrSr\\   \S'   Sr	\\   \S'   Sr
\\S'   Sr\\   \S'   S	rg)
V1CrawlResponsei  z"Response from crawling operations.Nr   rQ   Tr   r   r,   )r-   r.   r/   r0   r1   r   r   r3   r2   rQ   r   r   r   r4   r,   r5   r#   r  r    s9    ,BC#GTE8C=r5   r  c                       \ rS rSr% SrSr\\S'   \S   \S'   \	\S'   \	\S'   \	\S	'   \
\S
'   Sr\\   \S'   \\   \S'   Srg)V1CrawlStatusResponsei  z"Response from crawl status checks.Tr   r   r   rf   r   r   r   Nr   r   r,   r   r,   r5   r#   r
  r
    sK    ,GTBCCNJD(3-
"
##r5   r
  c                   `    \ rS rSr% Sr\\S'   Sr\\	   \S'   \\S'   Sr
\\   \S'   \\S'   S	rg)
V1CrawlErrori"  zA crawl error.r   N	timestamprQ   coder   r,   )r-   r.   r/   r0   r1   r3   r2   r  r   r   r  r4   r,   r5   r#   r  r  "  s1    G$(Ix!(	HD(3-Jr5   r  c                   :    \ rS rSr% Sr\\   \S'   \\   \S'   Sr	g)V1CrawlErrorsResponsei*  z2Response from crawl/batch scrape error monitoring.errorsrobotsBlockedr,   N)
r-   r.   r/   r0   r1   r   r  r2   r3   r4   r,   r5   r#   r  r  *  s    <9r5   r  c                       \ rS rSr% SrSr\\   \S'   Sr	\\
   \S'   Sr\\
   \S'   Sr\\
   \S'   Sr\\   \S'   S	r\\   \S
'   Sr\\
   \S'   Sr\\   \S'   Srg)V1MapParamsi/  z"Parameters for mapping operations.Nr   r   includeSubdomainssitemapOnlyr   r~   r   useIndexr   r,   )r-   r.   r/   r0   r1   r   r   r3   r2   r   r   r  r  r   r   r   r  r   r^   r4   r,   r5   r#   r  r  /  sx    , FHSM $(M8D>((,x~,"&K$&E8C="GXc]"#Hhtn#+/Hh'(/r5   r  c                   V    \ rS rSr% SrSr\\S'   Sr\	\
\      \S'   Sr\	\   \S'   Srg)	V1MapResponsei:  z!Response from mapping operations.Tr   NrU   r   r,   )r-   r.   r/   r0   r1   r   r   r2   rU   r   r   r3   r   r4   r,   r5   r#   r  r  :  s0    +GT!%E8DI%E8C=r5   r  c                       \ rS rSr% SrSr\\   \S'   \	R                  " SSS9r\\   \S'   Sr\\   \S'   Sr\\   \S	'   Sr\\   \S
'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Srg)V1ExtractParamsi@  z0Parameters for extracting information from URLs.Nr+   ro   rI   rp   r   r   enableWebSearchr  originshowSourcesr   r,   )r-   r.   r/   r0   r1   r+   r   r3   r2   rL   rM   rp   r   r   r   r   r  r  r  r  r   rs   r4   r,   r5   r#   r  r  @  s    : FHSM "*..X"FL(3-F"&L(3-&)--&*OXd^*(,x~, FHSM "&K$&/3M8O,3r5   r  c                      \ rS rSr% SrSr\\   \S'   Sr	\\
S      \S'   Sr\\   \S'   Sr\\S	'   Sr\\   \S
'   Sr\\   \S'   Sr\\   \S'   Sr\\\      \S'   Sr\\   \S'   Sr\\\\4      \S'   Sr\\   \S'   Srg)V1ExtractResponseiL  z!Response from extract operations.Nr   
processingrf   rg   r   r   Tr   r   r   r   warningsreplacementsourcesr   r,   )r-   r.   r/   r0   r1   r   r   r3   r2   r   r	   r   r   r   r   r   r%   r   r   r#  r   r$  r%  r   r   r   r   r4   r,   r5   r#   r   r   L  s    +BEIFHW@ABI$(Ix!(GTD(1+E8C=!GXc]!$(HhtCy!(!%K#%(,GXd38n%,!%K#%r5   r   c                       \ rS rSr% \\S'   Sr\\   \S'   Sr	\\   \S'   Sr
\\   \S'   Sr\\   \S	'   S
r\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Srg)V1SearchParamsiZ  query   r   Ntbsfilterenlangusr`   r   apir  i`  r   r   r,   )r-   r.   r/   r0   r3   r2   r   r   r   r*  r+  r-  r`   r   r  r   r   rs   r4   r,   r5   r#   r'  r'  Z  s    JE8C=C# FHSM D(3-!GXc]!"Hhsm"!FHSM!"GXc]"/3M8O,3r5   r'  c                   `    \ rS rSr% SrSr\\S'   \\	   \S'   Sr
\\   \S'   Sr\\   \S'   S	rg)
V1SearchResponseif  z Response from search operations.Tr   r   Nr   r   r,   )r-   r.   r/   r0   r1   r   r   r2   r   rO   r   r   r3   r   r4   r,   r5   r#   r1  r1  f  s7    *GT
"
##!GXc]!E8C=r5   r1  c                   \    \ rS rSr% \\S'   Sr\\   \S'   Sr\\	   \S'   Sr
\\	   \S'   Srg)V1CreditUsageDataim  remaining_creditsNplan_creditsbilling_period_startbilling_period_endr,   )r-   r.   r/   r0   r   r2   r5  r   r6  r3   r7  r4   r,   r5   r#   r3  r3  m  s4    "&L(3-&*.(3-.(,,r5   r3  c                   *    \ rS rSr% \\S'   \\S'   Srg)V1CreditUsageResponseis  r   r   r,   N)r-   r.   r/   r0   r   r2   r3  r4   r,   r5   r#   r9  r9  s  s    M
r5   r9  c                   \    \ rS rSr% \\S'   Sr\\   \S'   Sr\\	   \S'   Sr
\\	   \S'   Srg)V1TokenUsageDataiw  remaining_tokensNplan_tokensr6  r7  r,   )r-   r.   r/   r0   r   r2   r=  r   r6  r3   r7  r4   r,   r5   r#   r;  r;  w  s4    !%K#%*.(3-.(,,r5   r;  c                   *    \ rS rSr% \\S'   \\S'   Srg)V1TokenUsageResponsei}  r   r   r,   N)r-   r.   r/   r0   r   r2   r;  r4   r,   r5   r#   r?  r?  }  s    M
r5   r?  c                   \    \ rS rSr% Sr\\   \S'   Sr\\   \S'   Sr	\\   \S'   \
\S'   Srg)V1CreditUsageHistoricalPeriodi  N	startDateendDateapiKeyr   r,   r-   r.   r/   r0   rB  r   r3   r2   rC  rD  r   r4   r,   r5   r#   rA  rA    s2    #Ix}#!GXc]! FHSM r5   rA  c                   0    \ rS rSr% \\S'   \\   \S'   Srg)V1CreditUsageHistoricalResponsei  r   periodsr,   N)	r-   r.   r/   r0   r   r2   r   rA  r4   r,   r5   r#   rG  rG    s    M/00r5   rG  c                   \    \ rS rSr% Sr\\   \S'   Sr\\   \S'   Sr	\\   \S'   \
\S'   Srg)V1TokenUsageHistoricalPeriodi  NrB  rC  rD  
tokensUsedr,   rE  r,   r5   r#   rJ  rJ    s1    #Ix}#!GXc]! FHSM Or5   rJ  c                   0    \ rS rSr% \\S'   \\   \S'   Srg)V1TokenUsageHistoricalResponsei  r   rH  r,   N)	r-   r.   r/   r0   r   r2   r   rJ  r4   r,   r5   r#   rM  rM    s    M.//r5   rM  c                   j    \ rS rSr% SrSr\\   \S'   Sr	\\
   \S'   Sr\\
   \S'   S	r\\
   \S
'   Srg	)V1GenerateLLMsTextParamsi  z3
Parameters for the LLMs.txt generation operation.

   maxUrlsFshowFullTextTcacheN._V1GenerateLLMsTextParams__experimental_streamr,   )r-   r.   r/   r0   r1   rQ  r   r   r2   rR  r   rS  rT  r4   r,   r5   r#   rO  rO    sB      GXc]#(L(4.( E8D> ,08D>0r5   rO  c                       \ rS rSr% SrSr\\   \S'   Sr	\\   \S'   Sr
\\   \S'   S	r\\   \S
'   S	r\\   \S'   S	r\\   \S'   Srg	)V1DeepResearchParamsi  z-
Parameters for the deep research operation.
   r   i  	timeLimit   rQ  NanalysisPromptr   /_V1DeepResearchParams__experimental_streamStepsr,   )r-   r.   r/   r0   r1   r   r   r   r2   rX  rQ  rZ  r3   r   r[  r   r4   r,   r5   r#   rV  rV    s^      Hhsm"Ix}"GXc]$(NHSM("&L(3-&155r5   rV  c                   p    \ rS rSr% Sr\\S'   \\S'   Sr\	\   \S'   Sr
\	\\      \S'   Sr\	\   \S'   S	rg)
V1DeepResearchResponsei  z,
Response from the deep research operation.
r   r   Nr   r#  r$  r,   )r-   r.   r/   r0   r1   r   r2   r3   r   r   r#  r   r$  r4   r,   r5   r#   r]  r]    sB     MGE8C=$(HhtCy!(!%K#%r5   r]  c                       \ rS rSr% Sr\\S'   Sr\\	\
\4      \S'   \
\S'   Sr\\
   \S'   \
\S'   \\S	'   \\S
'   \\	\
\4      \S'   \\	\
\4      \S'   \\
   \S'   Sr\\\
      \S'   Sr\\
   \S'   Srg)V1DeepResearchStatusResponsei  z3
Status response from the deep research operation.
r   Nr   r   r   r   currentDepthr   
activitiesr%  	summariesr#  r$  r,   )r-   r.   r/   r0   r1   r   r2   r   r   r   r3   r   r   r   r   r#  r$  r4   r,   r5   r#   r_  r_    s     M%)D(4S>
")KE8C=NMT#s(^$$$sCx.!!Cy$(HhtCy!(!%K#%r5   r_  c                   t    \ rS rSr% SrSr\\S'   \\S'   Sr	\
\   \S'   Sr\
\\      \S'   Sr\
\   \S	'   S
rg)V1GenerateLLMsTextResponsei  z-Response from LLMs.txt generation operations.Tr   r   Nr   r#  r$  r,   )r-   r.   r/   r0   r1   r   r   r2   r3   r   r   r#  r   r$  r4   r,   r5   r#   rd  rd    sC    7GTGE8C=$(HhtCy!(!%K#%r5   rd  c                   4    \ rS rSr% \\S'   Sr\\   \S'   Srg)$V1GenerateLLMsTextStatusResponseDatai  llmstxtNllmsfulltxtr,   )	r-   r.   r/   r0   r3   r2   rh  r   r4   r,   r5   r#   rf  rf    s    L!%K#%r5   rf  c                       \ rS rSr% SrSr\\S'   Sr\	\
   \S'   \S   \S'   Sr\	\   \S	'   \\S
'   Sr\	\\      \S'   Sr\	\   \S'   Srg) V1GenerateLLMsTextStatusResponsei  z4Status response from LLMs.txt generation operations.Tr   Nr   r!  r   r   r   r#  r$  r,   )r-   r.   r/   r0   r1   r   r   r2   r   r   rf  r	   r   r3   r#  r   r$  r4   r,   r5   r#   rj  rj    s_    >GT;?D(7
8?788E8C=N$(HhtCy!(!%K#%r5   rj  c                   f    \ rS rSr% Sr\\S'   \\\	\
4      \S'   Sr\\	   \S'   Sr\\	   \S'   Srg)	r1  i  z%
Response from the search operation.
r   r   Nr   r   r,   )r-   r.   r/   r0   r1   r   r2   r   r   r3   r   r   r   r   r4   r,   r5   r#   r1  r1    s=     M
tCH~
!GXc]!E8C=r5   c                       \ rS rSr% SrSr\\   \S'   \	R                  " SSS9r\\   \S'   Sr\\   \S'   S	r\\   \S
'   S	r\\   \S'   S	r\\   \S'   S	r\\   \S'   Sr\\\\4      \S'   Srg)r  i  z'
Parameters for the extract operation.
Nr+   ro   rI   rp   system_promptFallow_external_linksenable_web_searchr  show_sourcesr   r,   )r-   r.   r/   r0   r1   r+   r   r3   r2   rL   rM   rp   r   rm  rn  r   ro  r  rp  r   r   r4   r,   r5   r#   r  r    s     !FHSM "*..X"FL(3-F#'M8C='+0(4.0(-x~-&+OXd^+#(L(4.(&*E8DcN#*r5   c            0       R   \ rS rSrSrSrSS\\   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S
.S\S\\	\
S         S\\\\4      S\\	\      S\\	\      S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\
S      S\\   S\\   S\\   S\\	\\\\\\\\\\4	         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\4S, jjr S\!4S- jr"S\#4S. jr$SS0\S\%4S1 jjr&SS0\S\'4S2 jjr(SSSSSSSSSSSSSSSSSSS3SS4.S\S5\\	\      S6\\	\      S7\\   S8\\   S&\\   S9\\   S:\\   S;\\   S<\\   S+\\   S=\\\\)4      S>\\   S?\\   S@\\   SA\\   SB\\   SC\\   S"\\   SD\\   SE\\   S\*4,SF jjr+SSSSSSSSSSSSSSSSSSSSG.S\S5\\	\      S6\\	\      S7\\   S8\\   S&\\   S9\\   S:\\   S;\\   S<\\   S+\\   S=\\\\)4      S>\\   S?\\   S@\\   SA\\   SB\\   SC\\   S"\\   SE\\   S\,4*SH jjr-SI\S\*4SJ jr.SI\S\/4SK jr0SI\S\\\4   4SL jr1SSSSSSSSSSSSSSSSSSSSG.S\S5\\	\      S6\\	\      S7\\   S8\\   S&\\   S9\\   S:\\   S;\\   S<\\   S+\\   S=\\\\)4      S>\\   S?\\   S@\\   SA\\   SB\\   SC\\   S"\\   SE\\   SSM4*SN jjr2SSSSSS	SSSO.S\SP\\   S<\\   SQ\\   SR\\   S&\\   S\\   SS\\   S\\   S\34ST jjr4SSSSSSS	SSSSSSSSSSS3SSSSU.SV\	\   S\\	\
SW         S\\\\4      S\\	\      S\\	\      S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\
S      S\\   S\\   S\\	\\\\\\\\\\4	         SX\\5   SD\\   SC\\   S"\\   SE\\   S\64.SY jjr7SSSSSSS	SSSSSSSSSSSSSSZ.SV\	\   S\\	\
SW         S\\\\4      S\\	\      S\\	\      S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\
S      S\\   S\\   S\\	\\\\\\\\\\4	         SX\\5   SC\\   SE\\   S"\\   S\84,S[ jjr9SSSSSSS	SSSSSSSSSSSSSS\.SV\	\   S\\	\
SW         S\\\\4      S\\	\      S\\	\      S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\
S      S\\   S\\   S\\	\\\\\\\\\\4	         SX\\5   SC\\   S"\\   SE\\   SSM4,S] jjr:SI\S\64S^ jr;SI\S\/4S_ jr< SSSSS/S/S/SS`.SV\\	\      Sa\\   Sb\\   Sc\\   S;\\   Sd\\   Se\\   SX\\\\4      S\=\   4Sf jjjr>Sg\S\=\   4Sh jr? SSSSS/S/S/SS`.SV\\	\      Sa\\   Sb\\   Sc\\   S;\\   Sd\\   Se\\   SX\\\\4      S\=\   4Si jjjr@SSSSSj.S\Sk\\   Sl\\   Sm\\   Sn\\   S\A4So jjrBSSSSSj.S\Sk\\   Sl\\   Sm\\   Sn\\   S\C4Sp jjrDSI\S\A4Sq jrE SSE\\   S\\\4   4Sr jjrF  SS\Ss\\\4   S\\\4   St\Su\GS\HR                  4Sv jjrJ  SS\S\\\4   St\Su\GS\HR                  4
Sw jjrK  SS\S\\\4   St\Su\GS\HR                  4
Sx jjrLSI\S\\\4   SD\S\*4Sy jrMSz\HR                  S{\SS4S| jrNS}\S{\S~\S\S\4
S jrOSSSSSSSSS.S%\S7\\   S\\   Sk\\   S\\   Sc\\   S\\   S\\P\\\4   /S4      S\\P\\\4   /S4      S\Q4S jjrRSSSSSSS.S%\S7\\   S\\   Sk\\   S\\   Sc\\   S\\   S\\\4   4S jjrSSI\S\Q4S jrTS\\\4   S\SS4S jrUS rVSS jrWS rXSS jrYS rZS r[S r\SS jr]SS jr^Sr_g)V1FirecrawlAppi  a  
Legacy v1 Firecrawl client for backward compatibility.

This class provides the complete v1 API implementation including:
- URL scraping with various formats and options
- Website crawling with monitoring capabilities
- Batch scraping operations
- Search functionality
- Data extraction with LLM integration
- Deep research capabilities
- LLMs.txt generation

This is used by the unified client to provide version-specific access
through app.v1.method_name() patterns.
a  Schema contains invalid structure for OpenAI: object type with no 'properties' defined but 'additionalProperties: true' (schema-less dictionary not supported by OpenAI). Please define specific properties for your object. Note: Recursive schemas using '$ref' are supported.Napi_keyapi_urlreturnc                 T   U=(       d    [         R                  " S5      U l        U=(       d    [         R                  " SS5      U l        SU R                  ;   a-  U R                  c   [        R                  S5        [        S5      e[        R                  SU R                   35        g)	z
Initialize the V1FirecrawlApp instance with API key, API URL.

Args:
    api_key (Optional[str]): API key for authenticating with the Firecrawl API.
    api_url (Optional[str]): Base URL for the Firecrawl API.
FIRECRAWL_API_KEYFIRECRAWL_API_URLhttps://api.firecrawl.devzapi.firecrawl.devNz%No API key provided for cloud servicezNo API key providedz)Initialized V1FirecrawlApp with API URL: )r   getenvrs  rt  r   r   
ValueErrordebug)selfrs  rt  s      r#   __init__V1FirecrawlApp.__init__	  s{     @")),?"@]")),?A\"] $,,.4<<3GNNBC233@OPr5   r~   )ry   re   include_tagsexclude_tagsonly_main_contentwait_forr   r   r   skip_tls_verificationremove_base64_images	block_adsr   	parse_pdfrV   json_optionsrY   change_tracking_optionsmax_agestore_in_cachezero_data_retentionrQ   ry   rv   re   r  r  r  r  r   r   r   r  r  r  r   r   r  rV   r  rY   r  r  r  r  c                
   U R                  US5        U R                  5       nUS[         3S.nU(       a  UUS'   U(       a  UUS'   U(       a  UUS'   U(       a  UUS'   Ub  UUS	'   U(       a  UUS
'   U(       a  UUS'   U	(       a  U	R                  SSS9US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   U(       a  UUS'   Ub  UUS'   Ubm  U R	                  U5      n[        U[        5      (       a  SU;   a  U R	                  US   5      US'   [        U[        5      (       a  UOUR                  SSS9US'   Ubm  U R	                  U5      n[        U[        5      (       a  SU;   a  U R	                  US   5      US'   [        U[        5      (       a  UOUR                  SSS9US'   U(       a;  U Vs/ s H*  n[        U[        5      (       a  UOUR                  SSS9PM,     snUS'   U(       a*  [        U[        5      (       a  UOUR                  SSS9US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   UR                  U5        SU;   a0  US   (       a&  SUS   ;   a  U R	                  US   S   5      US   S'   SU;   a0  US   (       a&  SUS   ;   a  U R	                  US   S   5      US   S'   [        R                  " U R                   S3UUUb  US-  S-   OSS 9nUR                  S!:X  a`   UR                  5       nUR                  S"5      (       a  S#U;   a  [        S(0 US#   D6$ S$U;   a  [        S%US$    35      e[        S%U 35      eU R!                  US'5        gs  snf ! [         a    [        S&5      ef = f))ag  
Scrape and extract content from a URL.

Args:
  url (str): Target URL to scrape
  formats (Optional[List[Literal["markdown", "html", "rawHtml", "content", "links", "screenshot", "screenshot@fullPage", "extract", "json"]]]): Content types to retrieve (markdown/html/etc)
  headers (Optional[Dict[str, str]]): Custom HTTP headers
  include_tags (Optional[List[str]]): HTML tags to include
  exclude_tags (Optional[List[str]]): HTML tags to exclude
  only_main_content (Optional[bool]): Extract main content only
  wait_for (Optional[int]): Wait for a specific element to appear
  timeout (Optional[int]): Request timeout (ms)
  location (Optional[LocationConfig]): Location configuration
  mobile (Optional[bool]): Use mobile user agent
  skip_tls_verification (Optional[bool]): Skip TLS verification
  remove_base64_images (Optional[bool]): Remove base64 images
  block_ads (Optional[bool]): Block ads
  proxy (Optional[Literal["basic", "stealth", "auto"]]): Proxy type (basic/stealth)
  extract (Optional[JsonConfig]): Content extraction settings
  json_options (Optional[JsonConfig]): JSON extraction settings
  actions (Optional[List[Union[WaitAction, ScreenshotAction, ClickAction, WriteAction, PressAction, ScrollAction, ScrapeAction, ExecuteJavascriptAction, PDFAction]]]): Actions to perform
  change_tracking_options (Optional[ChangeTrackingOptions]): Change tracking settings
  zero_data_retention (Optional[bool]): Whether to delete data after scrape is done


Returns:
  ScrapeResponse with:
  * Requested content formats
  * Page metadata
  * Extraction results
  * Success/error status

Raises:
  Exception: If scraping fails

scrape_urlpython-sdk@rQ   r  ry   re   rz   r{   Nr|   r}   r   Tby_aliasexclude_noner   r   r   r   r   r   r   ro   rV   r   rY   r   r   r   zeroDataRetention
/v1/scrape     @@r)  re   rH   r      r   r   r   Failed to scrape URL. Error: +Failed to parse Firecrawl response as JSON.z
scrape URLr,   )_validate_kwargs_prepare_headersversiondict_ensure_schema_dict
isinstanceupdaterequestspostrt  status_coderH   getr   r   r{  _handle_error)r}  rQ   ry   re   r  r  r  r  r   r   r   r  r  r  r   r  rV   r  rY   r  r  r  r  kwargs_headersscrape_paramsactionresponseresponse_jsons                                r#   r  V1FirecrawlApp.scrape_url  sY   | 	fl3((* #G9-
 '.M)$'.M)$+7M-(+7M-((/@M+,'/M)$'.M)$(0tRV(WM*%&,M(# ,3HM/0+2FM./ (1M*%%*M'" (1M*%..w7G'4((X-@$($<$<WX=N$O!2<Wd2K2KwQXQ]Q]gkz~Q]QM)$#33LAL,--(l2J)-)A)A,xBX)YX&;ElTX;Y;Y<_k_p_pz~  NR_p  `SM-( MT  (U  MT  CI*VT2J2JPVP[P[eix|P[P}(}  MT  (UM)$"PZ[rtxPyPy5L  @W  @\  @\  fj  y}  @\  @~M12&-M(#%,:M.)*1DM-.V$%-	*BxS`ajSkGk151I1I-XaJbckJl1mM)$X.M)mM.Jx[hiv[wOw595M5Mm\iNjksNt5uM-(2 ==||nJ'-4-@Wv%)d	
 3&	O ( $$Y//Fm4K+DmF.CDD-#&CMRYDZC[$\]]#&CM?$STT x6K (UD  O MNNOs   81M'59M, /%M, ,N)r   r*  r+  r-  r`   r   r   scrape_optionsr(  r   r*  r+  r-  r`   r  c                   U R                  U
S5        0 nUb  X+S'   Ub  X;S'   Ub  XKS'   Ub  X[S'   Ub  XkS'   Ub  X{S'   Ub  XS	'   U	b  U	R                  S
S
S9US'   UR                  U
5        UR                  S5      n[	        SSU0UD6nUR                  S
S
S9nS[
         3US'   U(       a  XS'   [        R                  " U R                   S3SSU R                   30US9nUR                  S:X  a]   UR                  5       nUR                  S5      (       a  SU;   a  [        S0 UD6$ SU;   a  [        SUS    35      e[        SU 35      eU R                  US5        g! [         a    [        S5      ef = f)a  
Search for content using Firecrawl.

Args:
    query (str): Search query string
    limit (Optional[int]): Max results (default: 5)
    tbs (Optional[str]): Time filter (e.g. "qdr:d")
    filter (Optional[str]): Custom result filter
    lang (Optional[str]): Language code (default: "en")
    country (Optional[str]): Country code (default: "us") 
    location (Optional[str]): Geo-targeting
    timeout (Optional[int]): Request timeout in milliseconds
    scrape_options (Optional[ScrapeOptions]): Result scraping configuration
    **kwargs: Additional keyword arguments for future compatibility

Returns:
    SearchResponse: Response containing:
        * success (bool): Whether request succeeded
        * data (List[FirecrawlDocument]): Search results
        * warning (Optional[str]): Warning message if any
        * error (Optional[str]): Error message if any

Raises:
    Exception: If search fails or response cannot be parsed
r   Nr   r*  r+  r-  r`   r   r   Tr  r   integrationr(  r  r  
/v1/searchAuthorizationBearer re   rH   r  r   r   r   zSearch failed. Error: r  r,   )r  r  r  r  r'  r  r  r  rt  rs  r  rH   r1  r   r{  r  )r}  r(  r   r*  r+  r-  r`   r   r   r  r  search_params_integrationfinal_paramsparams_dictr  r  s                    r#   r   V1FirecrawlApp.search  s   N 	fh/  %*'"?#&% &,(#$(&!'.)$(0*%'.)$%-;-@-@$]a-@-bM/* 	V$$((7 &CEC]C"''D'I"-gY 7H)5& ==||nJ'$~&>?
 3&	O ( $$Y//Fm4K+<m<<-#&<]7=S<T$UVV#&<]O$LMM x2  O MNNOs   56E$ ,%E$ $E:c                    U R                  5       nU R                  U R                   S3U5      nUR                  S:X  a]   UR	                  5       nUR                  S5      (       a  SU;   a  [        S
0 UD6$ SU;   a  [        SUS    35      e[        SU 35      eU R                  US5        g	! [         a    [        S5      ef = f)z1Get current credit usage and billing period (v1)./v1/team/credit-usager  r   r   r   z#Failed to get credit usage. Error: r  zget credit usageNr,   )
r  _get_requestrt  r  rH   r  r9  r   r{  r  r}  r  r  r  s       r#   get_credit_usageV1FirecrawlApp.get_credit_usage  s    ((*$$||n12

 3&	O ( $$Y//Fm4K0A=AA-#&I-X_J`Ia$bcc#&I-$YZZ x);<  O MNNO   6B0 8%B0 0Cc                    U R                  5       nU R                  U R                   S3U5      nUR                  S:X  a]   UR	                  5       nUR                  S5      (       a  SU;   a  [        S
0 UD6$ SU;   a  [        SUS    35      e[        SU 35      eU R                  US5        g	! [         a    [        S5      ef = f)z0Get current token usage and billing period (v1)./v1/team/token-usager  r   r   r   z"Failed to get token usage. Error: r  zget token usageNr,   )
r  r  rt  r  rH   r  r?  r   r{  r  r  s       r#   get_token_usageV1FirecrawlApp.get_token_usage'  s    ((*$$||n01

 3&	O ( $$Y//Fm4K/@-@@-#&HW^I_H`$abb#&H$XYY x):;  O MNNOr  F
by_api_keyc                    U R                  5       nU R                   S3U(       a  SOS-   nU R                  X25      nUR                  S:X  a]   UR	                  5       nUR                  S5      (       a  SU;   a  [        S0 UD6$ SU;   a  [        SUS    35      e[        SU 35      eU R                  US
5        g! [         a    [        S	5      ef = f)z!Get historical credit usage (v1).z /v1/team/credit-usage/historical?byApiKey=true r  r   rH  r   z.Failed to get historical credit usage. Error: r  zget credit usage historicalNr,   )
r  rt  r  r  rH   r  rG  r   r{  r  r}  r  r  rQ   r  r  s         r#   get_credit_usage_historical*V1FirecrawlApp.get_credit_usage_historical=  s    ((*>?WaCSgij$$S33&	O ( $$Y//I4N:K]KK-#&TUbcjUkTl$mnn#&TUbTc$dee x)FG  O MNNO   6B= %B= =Cc                    U R                  5       nU R                   S3U(       a  SOS-   nU R                  X25      nUR                  S:X  a]   UR	                  5       nUR                  S5      (       a  SU;   a  [        S0 UD6$ SU;   a  [        SUS    35      e[        SU 35      eU R                  US
5        g! [         a    [        S	5      ef = f)z Get historical token usage (v1).z/v1/team/token-usage/historicalr  r  r  r   rH  r   z-Failed to get historical token usage. Error: r  zget token usage historicalNr,   )
r  rt  r  r  rH   r  rM  r   r{  r  r  s         r#   get_token_usage_historical)V1FirecrawlApp.get_token_usage_historicalQ  s    ((*=>V`BRfhi$$S33&	O ( $$Y//I4N9JMJJ-#&STabiTjSk$lmm#&STaSb$cdd x)EF  O MNNOr     )include_pathsexclude_paths	max_depthmax_discovery_depthr   allow_backward_linkscrawl_entire_domainrn  ignore_sitemapr  r   deduplicate_similar_urlsignore_query_parametersregex_on_full_urlr  allow_subdomainsmax_concurrencyr  poll_intervalidempotency_keyr  r  r  r  r  r  rn  r  r   r  r  r  r  r  r  r  r  c                J   U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   OUb  UUS	'   U	b  U	US
'   U
b  U
US'   Ub  UR                  SSS9US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   UR                  U5        UR                  S5      n[	        S 0 UD6nUR                  SSS9nUUS'   S[
         3US'   U(       a  UUS'   U R                  U5      nU R                  U R                   S3UU5      nUR                  S:X  a3   UR                  5       R                  S5      nU R                  UUU5      $ U R                  US5        g!   [        S5      e= f)!a  
Crawl a website starting from a URL.

Args:
    url (str): Target URL to start crawling from
    include_paths (Optional[List[str]]): Patterns of URLs to include
    exclude_paths (Optional[List[str]]): Patterns of URLs to exclude
    max_depth (Optional[int]): Maximum crawl depth
    max_discovery_depth (Optional[int]): Maximum depth for finding new URLs
    limit (Optional[int]): Maximum pages to crawl
    allow_backward_links (Optional[bool]): DEPRECATED: Use crawl_entire_domain instead
    crawl_entire_domain (Optional[bool]): Follow parent directory links
    allow_external_links (Optional[bool]): Follow external domain links
    ignore_sitemap (Optional[bool]): Skip sitemap.xml processing
    scrape_options (Optional[ScrapeOptions]): Page scraping configuration
    webhook (Optional[Union[str, WebhookConfig]]): Notification webhook settings
    deduplicate_similar_urls (Optional[bool]): Remove similar URLs
    ignore_query_parameters (Optional[bool]): Ignore URL parameters
    regex_on_full_url (Optional[bool]): Apply regex to full URLs
    delay (Optional[int]): Delay in seconds between scrapes
    allow_subdomains (Optional[bool]): Follow subdomains
    max_concurrency (Optional[int]): Maximum number of concurrent scrapes
    zero_data_retention (Optional[bool]): Whether to delete data after 24 hours
    poll_interval (Optional[int]): Seconds between status checks (default: 2)
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    CrawlStatusResponse with:
    * Crawling status and progress
    * Crawled page contents
    * Success/error information

Raises:
    Exception: If crawl fails
	crawl_urlNr   r   r   r   r   r   r   r   r   Tr  r   r   r  r  r  r  r  r  r  r  rQ   r  r  	/v1/crawlr  r   r  start crawl jobr,   )r  r  r  r  r   r  r  _post_requestrt  r  rH   r   _monitor_job_statusr  )r}  rQ   r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  r  r  crawl_paramsr  r  r  re   r  r   s                                 r#   r  V1FirecrawlApp.crawl_urle  sX   ~ 	fk2 $+8L($+8L( '0L$*0CL,-$)L!*0CL,-!-1EL-.+1EL-.%,:L)%,:,?,?\`,?,aL)&-L##/5ML12".4KL01(->L)*$)L!'.>L*+&-<L)**0CL,-F##''6 %4|4"''D'I E"-gY 7H)5K& ''8%%i&@+wW3&P]]_((. ++BGGx):;	P"MOOs   F F")r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  c                   U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   OUb  UUS	'   U	b  U	US
'   U
b  U
US'   Ub  UR                  SSS9US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   UR                  U5        [        S0 UD6nUR                  SSS9nUUS'   S[         3US'   U R                  U5      nU R                  U R                   S3UU5      nUR                  S:X  a   [        S0 UR                  5       D6$ U R                  US5        g!   [        S5      e= f)a  
Start an asynchronous crawl job.

Args:
    url (str): Target URL to start crawling from
    include_paths (Optional[List[str]]): Patterns of URLs to include
    exclude_paths (Optional[List[str]]): Patterns of URLs to exclude
    max_depth (Optional[int]): Maximum crawl depth
    max_discovery_depth (Optional[int]): Maximum depth for finding new URLs
    limit (Optional[int]): Maximum pages to crawl
    allow_backward_links (Optional[bool]): DEPRECATED: Use crawl_entire_domain instead
    crawl_entire_domain (Optional[bool]): Follow parent directory links
    allow_external_links (Optional[bool]): Follow external domain links
    ignore_sitemap (Optional[bool]): Skip sitemap.xml processing
    scrape_options (Optional[V1ScrapeOptions]): Page scraping configuration
    webhook (Optional[Union[str, V1WebhookConfig]]): Notification webhook settings
    deduplicate_similar_urls (Optional[bool]): Remove similar URLs
    ignore_query_parameters (Optional[bool]): Ignore URL parameters
    regex_on_full_url (Optional[bool]): Apply regex to full URLs
    delay (Optional[int]): Delay in seconds between scrapes
    allow_subdomains (Optional[bool]): Follow subdomains
    max_concurrency (Optional[int]): Maximum number of concurrent scrapes
    zero_data_retention (Optional[bool]): Whether to delete data after 24 hours
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1CrawlResponse with:
    * success - Whether crawl started successfully
    * id - Unique identifier for the crawl job
    * url - Status check URL for the crawl
    * error - Error message if start failed

Raises:
    Exception: If crawl initiation fails
async_crawl_urlNr   r   r   r   r   r   r   r   r   Tr  r   r   r  r  r  r  r  r  r  rQ   r  r  r  r  r  r  r,   )r  r  r  r   r  r  r  rt  r  r  rH   r   r  )r}  rQ   r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  re   r  s                              r#   r  V1FirecrawlApp.async_crawl_url  s%   | 	f&78 $+8L($+8L( '0L$*0CL,-$)L!*0CL,-!-1EL-.+1EL-.%,:L)%,:,?,?\`,?,aL)&-L##/5ML12".4KL01(->L)*$)L!'.>L*+&-<L)**0CL,-F# %4|4"''D'I E"-gY 7H ''8%%i&@+wW3&P&999 x):;P"MOOs   3E E,r   c                 ^   SU 3nU R                  5       nU R                  U R                   U 3U5      nUR                  S:X  Ga   UR	                  5       nUS   S:X  a  SU;   a  US   nSU;   a  [        US   5      S:X  a  OUR                  S5      nU(       d  [        R                  S	5        O U R                  Xs5      nUR                  S:w  a#  [        R                  S
UR                   35        O< UR	                  5       n	UR                  U	R                  S/ 5      5        U	nSU;   a  M  XeS'   UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      S.nSU;   a  US   US'   SU;   a  US   US'   [        SSSU;   a  SOS0UD6$ U R                  US5        g!   [        S5      e= f!   [        S5      e= f! [
         a#  n
[        R                  SU
 35         Sn
A
M  Sn
A
ff = f)a  
Check the status and results of a crawl job.

Args:
    id: Unique identifier for the crawl job

Returns:
    V1CrawlStatusResponse containing:

    Status Information:
    * status - Current state (scraping/completed/failed/cancelled)
    * completed - Number of pages crawled
    * total - Total pages to crawl
    * creditsUsed - API credits consumed
    * expiresAt - Data expiration timestamp
    
    Results:
    * data - List of crawled documents
    * next - URL for next page of results (if paginated)
    * success - Whether status check succeeded
    * error - Error message if failed

Raises:
    Exception: If status check fails

/v1/crawl/r  r  r   rf   r   r   r   Expected 'next' URL is missing.Failed to fetch next page: !Error during pagination request: Nr   r   r   r   r   rf   r   r   r   r   r   FTcheck crawl statusr,   )r  r  rt  r  rH   r   lenr  r   r   r   extendr
  r  r}  r   endpointre   r  status_datar   next_urlstatus_response	next_dataes              r#   check_crawl_status!V1FirecrawlApp.check_crawl_statusc  sL   4  t$'')$$~hZ%@'J3&P&mmo 8$3[(&v.D K/{623q8!#.??6#:'"NN+LM!".2.?.?.RO.::cA &/J?KfKfJg-h i %`,;,@,@,B	 !KK	fb(AB*3K# !K/* +/' &//(3$1(__[9*}=(__[9#/H +%$/$8!$#.v#6 ( !(K!7T 
 x)=>aP"MOO$`&/2]&_ _  ) ""LL+LQC)PQ!"s=   G 4AG? 9G/ 	#G? G,/G<<G? ?
H,	H''H,c                     U R                  5       nU R                  U R                   SU S3U5      nUR                  S:X  a   [	        S0 UR                  5       D6$ U R                  US5        g!   [        S5      e= f)a  
Returns information about crawl errors.

Args:
    id (str): The ID of the crawl job

Returns:
    V1CrawlErrorsResponse containing:
    * errors (List[Dict[str, str]]): List of errors with fields:
        - id (str): Error ID
        - timestamp (str): When the error occurred
        - url (str): URL that caused the error
        - error (str): Error message
    * robotsBlocked (List[str]): List of URLs blocked by robots.txt

Raises:
    Exception: If error check fails
r  /errorsr  r  zcheck crawl errorsNr,   r  r  rt  r  r  rH   r   r  r}  r   re   r  s       r#   check_crawl_errors!V1FirecrawlApp.check_crawl_errors  s    & '')$$~Zt7%KWU3&P,?x}}?? x)=>P"MOO   A0 0A=c                     U R                  5       nU R                  U R                   SU 3U5      nUR                  S:X  a   UR	                  5       $ U R                  US5        g!   [        S5      e= f)-  
Cancel an asynchronous crawl job.

Args:
    id (str): The ID of the crawl job to cancel

Returns:
    Dict[str, Any] containing:
    * success (bool): Whether cancellation was successful
    * error (str, optional): Error message if cancellation failed

Raises:
    Exception: If cancellation fails
r  r  r  zcancel crawl jobN)r  _delete_requestrt  r  rH   r   r  r  s       r#   cancel_crawlV1FirecrawlApp.cancel_crawl  sz     '')''4<<.
2$(GQ3&P}}& x);<P"MOOs   A& &A3V1CrawlWatcherc                    U R                   " U40 SU_SU_SU_SU_SU_SU_SU_SU	_S	U
_S
U_SU_SU_SU_SU_SU_SU_SU_SU_SU_UD6nUR                  (       a'  UR                  (       a  [        UR                  U 5      $ [	        S5      e)am  
Initiate a crawl job and return a CrawlWatcher to monitor the job via WebSocket.

Args:
    url (str): Target URL to start crawling from
    include_paths (Optional[List[str]]): Patterns of URLs to include
    exclude_paths (Optional[List[str]]): Patterns of URLs to exclude
    max_depth (Optional[int]): Maximum crawl depth
    max_discovery_depth (Optional[int]): Maximum depth for finding new URLs
    limit (Optional[int]): Maximum pages to crawl
    allow_backward_links (Optional[bool]): DEPRECATED: Use crawl_entire_domain instead
    crawl_entire_domain (Optional[bool]): Follow parent directory links
    allow_external_links (Optional[bool]): Follow external domain links
    ignore_sitemap (Optional[bool]): Skip sitemap.xml processing
    scrape_options (Optional[V1ScrapeOptions]): Page scraping configuration
    webhook (Optional[Union[str, V1WebhookConfig]]): Notification webhook settings
    deduplicate_similar_urls (Optional[bool]): Remove similar URLs
    ignore_query_parameters (Optional[bool]): Ignore URL parameters
    regex_on_full_url (Optional[bool]): Apply regex to full URLs
    delay (Optional[int]): Delay in seconds between scrapes
    allow_subdomains (Optional[bool]): Follow subdomains
    max_concurrency (Optional[int]): Maximum number of concurrent scrapes
    zero_data_retention (Optional[bool]): Whether to delete data after 24 hours
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1CrawlWatcher: An instance to monitor the crawl job via WebSocket

Raises:
    Exception: If crawl job fails to start
r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  Crawl job failed to start)r  r   r   r  r   )r}  rQ   r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  r  crawl_responses                          r#   crawl_url_and_watch"V1FirecrawlApp.crawl_url_and_watch  s	   r --
'
 (
  	

 !4
 
 "6
 !4
 "6
 *
 *
 
 &>
 %<
 0
  !
" .#
$ ,%
& !4'
( ,+
. !!n&7&7!."3"3T::788r5   )r   r  include_subdomainssitemap_onlyr   r   	use_indexr   r   r  r  r  c                   U R                  U
S5        0 nUb  X+S'   Ub  X;S'   Ub  XKS'   Ub  X[S'   Ub  XkS'   Ub  X{S'   Ub  XS	'   U	b  U	R                  S
S
S9US'   UR                  U
5        UR                  S5      n[	        S0 UD6nUR                  S
S
S9nXS'   S[
         3US'   U(       a  XS'   [        R                  " U R                   S3SSU R                   30US9nUR                  S:X  a]   UR                  5       nUR                  S5      (       a  SU;   a  [        S0 UD6$ SU;   a  [        SUS    35      e[        SU 35      eU R                  US5        g! [         a    [        S5      ef = f)a  
Map and discover links from a URL.

Args:
    url (str): Target URL to map
    search (Optional[str]): Filter pattern for URLs
    ignore_sitemap (Optional[bool]): Skip sitemap.xml processing
    include_subdomains (Optional[bool]): Include subdomain links
    sitemap_only (Optional[bool]): Only use sitemap.xml
    limit (Optional[int]): Maximum URLs to return
    timeout (Optional[int]): Request timeout in milliseconds
    **kwargs: Additional parameters to pass to the API

Returns:
    V1MapResponse: Response containing:
        * success (bool): Whether request succeeded
        * links (List[str]): Discovered URLs
        * error (Optional[str]): Error message if any

Raises:
    Exception: If mapping fails or response cannot be parsed
map_urlNr   r   r  r  r   r   r  Tr  r   r  rQ   r  r  /v1/mapr  r  r  r  r   rU   r   zMap failed. Error: r  mapr,   )r  r  r  r  r  r  r  r  rt  rs  r  rH   r  r   r{  r  )r}  rQ   r   r  r  r  r   r   r  r   r  
map_paramsr  r  r  r  r  s                    r#   r  V1FirecrawlApp.map_urlA  s   H 	fi0 
 #)x %*8').@*+#(4}%"'w$+y! %.z"%-]]Dt]%TJz" 	&!!~~m4 #0Z0"''D'I E"-gY 7H)5& ==||nG$$~&>?
 3&	O ( $$Y//G}4L(9=99-#&9-:P9Q$RSS#&9-$IJJ x/  O MNNOs   76E& .%E& &E<)ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  r  urls	rR   rS   rT   rw   rU   rW   rx   rV   rH   r   c                0   U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS	'   U	b  U	R                  S
S
S9US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   U(       a;  U Vs/ s H*  n[        U[        5      (       a  UOUR                  S
S
S9PM,     snUS'   Ub  UR                  S
S
S9US'   Ub  UUS'   Ub  UUS'   UR	                  U5        [        S!0 UD6nUR                  S
S
S9nUUS'   S[         3US'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   U R                  U5      nU R                  U R                   S3UU5      nUR                  S:X  a3   UR                  5       R                  S5      nU R                  UUU5      $ U R                  US 5        gs  snf !   [        S5      e= f)"aH  
Batch scrape multiple URLs and monitor until completion.

Args:
    urls (List[str]): URLs to scrape
    formats (Optional[List[Literal]]): Content formats to retrieve
    headers (Optional[Dict[str, str]]): Custom HTTP headers
    include_tags (Optional[List[str]]): HTML tags to include
    exclude_tags (Optional[List[str]]): HTML tags to exclude
    only_main_content (Optional[bool]): Extract main content only
    wait_for (Optional[int]): Wait time in milliseconds
    timeout (Optional[int]): Request timeout in milliseconds
    location (Optional[LocationConfig]): Location configuration
    mobile (Optional[bool]): Use mobile user agent
    skip_tls_verification (Optional[bool]): Skip TLS verification
    remove_base64_images (Optional[bool]): Remove base64 encoded images
    block_ads (Optional[bool]): Block advertisements
    proxy (Optional[Literal]): Proxy type to use
    extract (Optional[JsonConfig]): Content extraction config
    json_options (Optional[JsonConfig]): JSON extraction config
    actions (Optional[List[Union]]): Actions to perform
    agent (Optional[AgentOptions]): Agent configuration
    max_concurrency (Optional[int]): Maximum number of concurrent scrapes
    poll_interval (Optional[int]): Seconds between status checks (default: 2)
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1BatchScrapeStatusResponse with:
    * Scraping status and progress
    * Scraped content for each URL
    * Success/error information

Raises:
    Exception: If batch scrape fails
batch_scrape_urlsNry   re   rz   r{   r|   r}   r   Tr  r   r   r   r   r   r   ro   rV   r   rY   r   r  r  r  r  r  /v1/batch/scraper  r   r  start batch scrape jobr,   )r  r  r  r  r  r   r  r  r  rt  r  rH   r  r   r  r  )r}  r  ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  r  r  r  r  r  r  r  r   s                                 r#   r   V1FirecrawlApp.batch_scrape_urls  s   @ 	f&9: '.M)$'.M)$#+7M-(#+7M-((/@M+,'/M)$'.M)$(0tRV(WM*%&,M(# ,3HM/0+2FM./ (1M*%%*M'"..w7G'4((X-@$($<$<WX=N$O!2<Wd2K2KwQXQ]Q]gkz~Q]QM)$#33LAL,--(l2J)-)A)A,xBX)YX&;ElTX;Y;Y<_k_p_pz~  NR_p  `SM-( MT  (U  MT  CI*VT2J2JPVP[P[eix|P[P}(}  MT  (UM)$%*ZZDZ%QM'"&.=M*+*1DM-. 	V$ &66"''D'I"F"-gY 7H#I(>8{[dOeCe/3/G/GT]H^_gHh/iK	"8,K'K,F8WbcpWqKq373K3KKXeLfgoLp3qK&x0 ''8%%6F&GV]^3&P]]_((. ++BGGx)ABC (U:P"MOOs   61L>L L)ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  c                   U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS	'   U	b  U	R                  S
S
S9US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   U(       a;  U Vs/ s H*  n[        U[        5      (       a  UOUR                  S
S
S9PM,     snUS'   Ub  UR                  S
S
S9US'   Ub  UUS'   Ub  UUS'   UR	                  U5        [        S 0 UD6nUR                  S
S
S9nUUS'   S[         3US'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   U R                  U5      nU R                  U R                   S3UU5      nUR                  S:X  a   [        S 0 UR                  5       D6$ U R                  US5        gs  snf !   [        S5      e= f)!av  
Initiate a batch scrape job asynchronously.

Args:
    urls (List[str]): URLs to scrape
    formats (Optional[List[Literal]]): Content formats to retrieve
    headers (Optional[Dict[str, str]]): Custom HTTP headers
    include_tags (Optional[List[str]]): HTML tags to include
    exclude_tags (Optional[List[str]]): HTML tags to exclude
    only_main_content (Optional[bool]): Extract main content only
    wait_for (Optional[int]): Wait time in milliseconds
    timeout (Optional[int]): Request timeout in milliseconds
    location (Optional[LocationConfig]): Location configuration
    mobile (Optional[bool]): Use mobile user agent
    skip_tls_verification (Optional[bool]): Skip TLS verification
    remove_base64_images (Optional[bool]): Remove base64 encoded images
    block_ads (Optional[bool]): Block advertisements
    proxy (Optional[Literal]): Proxy type to use
    extract (Optional[JsonConfig]): Content extraction config
    json_options (Optional[JsonConfig]): JSON extraction config
    actions (Optional[List[Union]]): Actions to perform
    agent (Optional[AgentOptions]): Agent configuration
    max_concurrency (Optional[int]): Maximum number of concurrent scrapes
    zero_data_retention (Optional[bool]): Whether to delete data after 24 hours
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1BatchScrapeResponse with:
    * success - Whether job started successfully
    * id - Unique identifier for the job
    * url - Status check URL
    * error - Error message if start failed

Raises:
    Exception: If job initiation fails
async_batch_scrape_urlsNry   re   rz   r{   r|   r}   r   Tr  r   r   r   r   r   r   ro   rV   r   rY   r   r  r  r  r  r  r  r  r  r  r,   )r  r  r  r  r  r   r  r  r  rt  r  r   rH   r   r  )r}  r  ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  r  r  r  r  r  r  s                               r#   r  &V1FirecrawlApp.async_batch_scrape_urls+  s   @ 	f&?@ '.M)$'.M)$#+7M-(#+7M-((/@M+,'/M)$'.M)$(0tRV(WM*%&,M(# ,3HM/0+2FM./ (1M*%%*M'"..w7G'4((X-@$($<$<WX=N$O!2<Wd2K2KwQXQ]Q]gkz~Q]QM)$#33LAL,--(l2J)-)A)A,xBX)YX&;ElTX;Y;Y<_k_p_pz~  NR_p  `SM-( MT  (U  MT  CI*VT2J2JPVP[P[eix|P[P}(}  MT  (UM)$%*ZZDZ%QM'"&.=M*+*1DM-. 	V$ &66"''D'I"F"-gY 7H#I(>8{[dOeCe/3/G/GT]H^_gHh/iK	"8,K'K,F8WbcpWqKq373K3KKXeLfgoLp3qK&x0 ''8%%6F&GV]^3&P,?x}}?? x)ABA (U:P"MOOs   61K*>K/ /K<)ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  c                   U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS	'   U	b  U	R                  S
S
S9US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   U(       a;  U Vs/ s H*  n[        U[        5      (       a  UOUR                  S
S
S9PM,     snUS'   Ub  UR                  S
S
S9US'   Ub  UUS'   Ub  UUS'   UR	                  U5        [        S!0 UD6nUR                  S
S
S9nUUS'   S[         3US'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   U R                  U5      nU R                  U R                   S3UU5      nUR                  S:X  a]   [        S!0 UR                  5       D6nUR                  (       a'  UR                  (       a  [        UR                  U 5      $ [!        S5      eU R#                  US 5        gs  snf !   [!        S5      e= f)"a8  
Initiate a batch scrape job and return a CrawlWatcher to monitor the job via WebSocket.

Args:
    urls (List[str]): URLs to scrape
    formats (Optional[List[Literal]]): Content formats to retrieve
    headers (Optional[Dict[str, str]]): Custom HTTP headers
    include_tags (Optional[List[str]]): HTML tags to include
    exclude_tags (Optional[List[str]]): HTML tags to exclude
    only_main_content (Optional[bool]): Extract main content only
    wait_for (Optional[int]): Wait time in milliseconds
    timeout (Optional[int]): Request timeout in milliseconds
    location (Optional[LocationConfig]): Location configuration
    mobile (Optional[bool]): Use mobile user agent
    skip_tls_verification (Optional[bool]): Skip TLS verification
    remove_base64_images (Optional[bool]): Remove base64 encoded images
    block_ads (Optional[bool]): Block advertisements
    proxy (Optional[Literal]): Proxy type to use
    extract (Optional[JsonConfig]): Content extraction config
    json_options (Optional[JsonConfig]): JSON extraction config
    actions (Optional[List[Union]]): Actions to perform
    agent (Optional[AgentOptions]): Agent configuration
    max_concurrency (Optional[int]): Maximum number of concurrent scrapes
    zero_data_retention (Optional[bool]): Whether to delete data after 24 hours
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1CrawlWatcher: An instance to monitor the batch scrape job via WebSocket

Raises:
    Exception: If batch scrape job fails to start
batch_scrape_urls_and_watchNry   re   rz   r{   r|   r}   r   Tr  r   r   r   r   r   r   ro   rV   r   rY   r   r  r  r  r  r  r  r   Batch scrape job failed to startr  r  r,   )r  r  r  r  r  r   r  r  r  rt  r  r   rH   r   r   r  r   r  )r}  r  ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  r  r  r  r  r  r  r  s                                r#   r"  *V1FirecrawlApp.batch_scrape_urls_and_watch  s
   x 	f&CD '.M)$'.M)$#+7M-(#+7M-((/@M+,'/M)$'.M)$(0tRV(WM*%&,M(# ,3HM/0+2FM./ (1M*%%*M'"..w7G'4((X-@$($<$<WX=N$O!2<Wd2K2KwQXQ]Q]gkz~Q]QM)$#33LAL,--(l2J)-)A)A,xBX)YX&;ElTX;Y;Y<_k_p_pz~  NR_p  `SM-( MT  (U  MT  CI*VT2J2JPVP[P[eix|P[P}(}  MT  (UM)$%*ZZDZ%QM'"&.=M*+*1DM-. 	V$ &66"''D'I"F"-gY 7H#I(>8{[dOeCe/3/G/GT]H^_gHh/iK	"8,K'K,F8WbcpWqKq373K3KKXeLfgoLp3qK&x0 ''8%%6F&GV]^3&P!6!I!I!))n.?.?).*;*;TBB#$FGG x)ABI (UBP"MOOs   61L->AL2 L2 2L?c                 `   SU 3nU R                  5       nU R                  U R                   U 3U5      nUR                  S:X  Ga   UR	                  5       nUS   S:X  a  SU;   a  US   nSU;   a  [        US   5      S:X  a  OUR                  S5      nU(       d  [        R                  S	5        O U R                  Xs5      nUR                  S:w  a#  [        R                  S
UR                   35        O< UR	                  5       n	UR                  U	R                  S/ 5      5        U	nSU;   a  M  XeS'   [        S0 SU;   a  SOSUR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      S.	D6$ U R                  US5        g!   [        S5      e= f!   [        S5      e= f! [
         a#  n
[        R                  SU
 35         Sn
A
M  Sn
A
ff = f)a   
Check the status of a batch scrape job using the Firecrawl API.

Args:
    id (str): The ID of the batch scrape job.

Returns:
    V1BatchScrapeStatusResponse: The status of the batch scrape job.

Raises:
    Exception: If the status check request fails.
/v1/batch/scrape/r  r  r   rf   r   r   r   r  r  r  Nr   FTr   r   r   )	r   r   r   rf   r   r   r   r   r   zcheck batch scrape statusr,   )r  r  rt  r  rH   r   r  r  r   r   r   r  r   r  r  s              r#   check_batch_scrape_status(V1FirecrawlApp.check_batch_scrape_statusC  s(    'rd+'')$$~hZ%@'J3&P&mmo 8$3[(&v.D K/{623q8!#.??6#:'"NN+LM!".2.?.?.RO.::cA &/J?KfKfJg-h i %`,;,@,@,B	 !KK	fb(AB*3K# !K/* +/'. 
$+{$:5%//(3$1(__[9*}=(__[9#/#/$1
2 
 
 x)DEQP"MOO$`&/2]&_ _  ) ""LL+LQC)PQ!"s=   G  4AH  9G0 	#H   G-0G==H   
H-
H((H-c                     U R                  5       nU R                  U R                   SU S3U5      nUR                  S:X  a   [	        S0 UR                  5       D6$ U R                  US5        g!   [        S5      e= f)a  
Returns information about batch scrape errors.

Args:
    id (str): The ID of the crawl job.

Returns:
    V1CrawlErrorsResponse containing:
    * errors (List[Dict[str, str]]): List of errors with fields:
      * id (str): Error ID
      * timestamp (str): When the error occurred
      * url (str): URL that caused the error
      * error (str): Error message
    * robotsBlocked (List[str]): List of URLs blocked by robots.txt

Raises:
    Exception: If the error check request fails
r&  r  r  r  zcheck batch scrape errorsNr,   r  r  s       r#   check_batch_scrape_errors(V1FirecrawlApp.check_batch_scrape_errors  s    & '')$$~5Frd'%RT[\3&P,?x}}?? x)DEP"MOOr  r+   ro   rm  rn  ro  rp  r   r+   ro   rm  ro  rp  c                   SSK n
U
R                  S[        SS9  U R                  U	S5        U R	                  5       nU(       d  U(       d  [        S5      eU(       d  U(       d  [        S5      eU(       a  U R                  U5      nU=(       d    / UUUUS	[        5        3S
.nU(       a  X,S'   U(       a  XLS'   U(       a  XS'   UR                  U	5         U R                  U R                   S3UU5      nUR                  S:X  a   UR                  5       nUS   (       a  UR                  S5      nU(       d  [        S5      e U R                  U R                   SU 3U5      nUR                  S:X  aF   UR                  5       nUS   S:X  a  [!        S!0 UD6$ US   S;   a  [        SUS    SUS    35      eOU R#                  US5        [$        R&                  " S5        M  [        SUS    35      eU R#                  US5         [!        SSS 9$ !   [        S5      e= f!   [        S5      e= f! [         a  n[        [)        U5      S5      eSnAff = f)"a  
Extract structured information from URLs.

.. deprecated::
    The extract endpoint is in maintenance mode and its use is discouraged.
    Review https://docs.firecrawl.dev/developer-guides/usage-guides/choosing-the-data-extractor
    to find a replacement.

Args:
    urls (Optional[List[str]]): URLs to extract from
    prompt (Optional[str]): Custom extraction prompt
    schema (Optional[Any]): JSON schema/Pydantic model
    system_prompt (Optional[str]): System context
    allow_external_links (Optional[bool]): Follow external links
    enable_web_search (Optional[bool]): Enable web search
    show_sources (Optional[bool]): Include source URLs
    agent (Optional[Dict[str, Any]]): Agent configuration
    **kwargs: Additional parameters to pass to the API

Returns:
    V1ExtractResponse[Any] with:
    * success (bool): Whether request succeeded
    * data (Optional[Any]): Extracted data matching schema
    * error (Optional[str]): Error message if any

Raises:
    ValueError: If prompt/schema missing or extraction fails
r   NThe extract endpoint is in maintenance mode and its use is discouraged. Review https://docs.firecrawl.dev/developer-guides/usage-guides/choosing-the-data-extractor to find a replacement.r  
stacklevelrV   #Either prompt or schema is required!Either urls or prompt is requiredr  r  r   r  r  ro   r  r+   r   r   /v1/extractr  r  r   r   )Job ID not returned from extract request./v1/extract/r   rf   rg   r   Extract job 	. Error: r   zextract-statusFailed to extract. Error:   FzInternal server error.r   r   r,   )r#  warnDeprecationWarningr  r  r{  r  r$   r  r  rt  r  rH   r   r  r  r   r  timesleepr3   )r}  r  r+   ro   rm  rn  ro  rp  r   r  r#  re   request_datar  r   job_idr  r  r  s                      r#   rV   V1FirecrawlApp.extract  s   P 	%  	 	
 	fi0'')fBCCF@AA--f5F JB"60'#KM?3
 %+"+8($)! 	F#)	*))<<.,H
 ##s*T#==?D 	?!XXd^F!'(STT *.*;*;#||nLA#+ +66#=`.=.B.B.D  +84C'8'G;'G G!,X!6:Q!Q&/,{8?T>UU^_jkr_s^t0u&v v "R !..@PQ

1# & $&@g$PQQ""8Y7 !6NOOCT#&QSS`&/2]&_ _  	*SVS))	*sP   0H4 H AH4 7H$ H4 A.H4 H!!H4 $H11H4 4
I>IIrB  c                    SSK nUR                  S[        SS9  U R                  5       n U R	                  U R
                   SU 3U5      nUR                  S:X  a   [        S0 UR                  5       D6$ U R                  US	5        g!   [        S5      e= f! [         a  n[        [        U5      S
5      eSnAff = f)a  
Retrieve the status of an extract job.

.. deprecated::
    The extract endpoint is in maintenance mode and its use is discouraged.
    Review https://docs.firecrawl.dev/developer-guides/usage-guides/choosing-the-data-extractor
    to find a replacement.

Args:
    job_id (str): The ID of the extract job.

Returns:
    ExtractResponse[Any]: The status of the extract job.

Raises:
    ValueError: If there is an error retrieving the status.
r   Nr.  r  r/  r6  r  r  zget extract statusr;  r,   )r#  r=  r>  r  r  rt  r  r   rH   r   r  r{  r3   )r}  rB  r#  re   r  r  s         r#   get_extract_status!V1FirecrawlApp.get_extract_status  s    $ 	%  	 	
 '')
	*((DLL>fX)NPWXH##s*T,?x}}?? ""8-ABT#&QSS  	*SVS))	*s/   1B B	 6B 	BB 
B=#B88B=c                   SSK n	U	R                  S[        SS9  U R                  5       n
UnU(       a  U R	                  U5      nUUUUUS[
         3S.nU(       a  X+S'   U(       a  XKS	'   U(       a  XS
'    U R                  U R                   S3X5      nUR                  S:X  a   [        S0 UR                  5       D6$ U R                  US5        g!   [        S5      e= f! [         a  n[        [        U5      S5      eSnAff = f)a  
Initiate an asynchronous extract job.

.. deprecated::
    The extract endpoint is in maintenance mode and its use is discouraged.
    Review https://docs.firecrawl.dev/developer-guides/usage-guides/choosing-the-data-extractor
    to find a replacement.

Args:
    urls (List[str]): URLs to extract information from
    prompt (Optional[str]): Custom extraction prompt
    schema (Optional[Any]): JSON schema/Pydantic model
    system_prompt (Optional[str]): System context
    allow_external_links (Optional[bool]): Follow external links
    enable_web_search (Optional[bool]): Enable web search
    show_sources (Optional[bool]): Include source URLs
    agent (Optional[Dict[str, Any]]): Agent configuration
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests

Returns:
    ExtractResponse[Any] with:
    * success (bool): Whether request succeeded
    * data (Optional[Any]): Extracted data matching schema
    * error (Optional[str]): Error message if any

Raises:
    ValueError: If job initiation fails
r   Nr.  r  r/  r  r3  r+   r   r   r4  r  r  zasync extractr;  r,   )r#  r=  r>  r  r  r  r  rt  r  r   rH   r   r  r{  r3   )r}  r  r+   ro   rm  rn  ro  rp  r   r#  re   rA  r  r  s                 r#   async_extractV1FirecrawlApp.async_extractE  s%   N 	%  	 	
 '')--f5F "60'#G9-
 %+"+8($)!
	*))T\\N+*F^H##s*T,?x}}?? ""8_=T#&QSS  	*SVS))	*s0   6/C" &C ?C" CC" "
D,DDmax_urlsshow_full_textrS  experimental_streamrK  rL  rS  rM  c                   SSK nUR                  S[        SS9  [        UUUUS9nU R	                  UUUUUS9nUR
                  (       a  UR                  (       d  [        SS	S
SS9$ UR                  n	 U R                  U	5      n
U
R                  S:X  a  U
$ U
R                  S
:X  a  U
$ U
R                  S:w  a  [        SSS
SS9$ [        R                  " S5        Mi  )a  
Generate LLMs.txt for a given URL and poll until completion.

.. deprecated::
    /v1/llmstxt is deprecated and will not be replaced.

Args:
    url (str): Target URL to generate LLMs.txt from
    max_urls (Optional[int]): Maximum URLs to process (default: 10)
    show_full_text (Optional[bool]): Include full text in output (default: False)
    cache (Optional[bool]): Whether to use cached content if available (default: True)
    experimental_stream (Optional[bool]): Enable experimental streaming

Returns:
    GenerateLLMsTextStatusResponse with:
    * Generated LLMs.txt content
    * Full version if requested
    * Generation status
    * Success/error information

Raises:
    Exception: If generation fails
r   N3/v1/llmstxt is deprecated and will not be replaced.r  r/  rQ  rR  rS  __experimental_streamrJ  Fz#Failed to start LLMs.txt generationrg   r  r   r   r   r   rf   r"  /LLMs.txt generation job terminated unexpectedly)r#  r=  r>  rO  async_generate_llms_textr   r   rj  check_generate_llms_text_statusr   r?  r@  )r}  rQ   rK  rL  rS  rM  r#  paramsr  rB  r   s              r#   generate_llms_text!V1FirecrawlApp.generate_llms_text  s    > 	A 	 	

 *'"5	
 00) 3 1 
 x{{3;	  99&AF}}+(*,.7!K# 	  JJqM r5   c                &   SSK nUR                  S[        SS9  [        UUUUS9nU R	                  5       nSU0UR                  SSS	9En	S
[         3U	S'    U R                  U R                   S3X5      n
U
R                  5       n[        SU	5        [        SU5        UR                  S5      (       a   [        S0 UD6$ U R                  US5         [        SSS9$ !   [        S5      e= f! [         a  n[        [!        U5      5      eSnAff = f)aZ  
Initiate an asynchronous LLMs.txt generation operation.

.. deprecated::
    /v1/llmstxt is deprecated and will not be replaced.

Args:
    url (str): The target URL to generate LLMs.txt from. Must be a valid HTTP/HTTPS URL.
    max_urls (Optional[int]): Maximum URLs to process (default: 10)
    show_full_text (Optional[bool]): Include full text in output (default: False)
    cache (Optional[bool]): Whether to use cached content if available (default: True)
    experimental_stream (Optional[bool]): Enable experimental streaming

Returns:
    GenerateLLMsTextResponse: A response containing:
    * success (bool): Whether the generation initiation was successful
    * id (str): The unique identifier for the generation job
    * error (str, optional): Error message if initiation failed

Raises:
    Exception: If the generation job initiation fails.
r   NrO  r  r/  rP  rQ   Tr  r  r  /v1/llmstxt	json_datar  r   r  zstart LLMs.txt generationFInternal server errorr<  r,   )r#  r=  r>  rO  r  r  r  r  rt  rH   r   r  rd  r   r  r{  r3   )r}  rQ   rK  rL  rS  rM  r#  rV  re   r[  reqr  r  s                r#   rT  'V1FirecrawlApp.async_generate_llms_text  s6   < 	A 	 	

 *'"5	
 '')CQ6;;4;#PQ	 +G95	(	%$$~[%A9VCxxzH+y)*h'||I&&S5AAA ""8-HI *)
 	
S#$QRR  	%SV$$	%s1   AC- 5
C  C- C**C- -
D7DDc                    SSK nUR                  S[        SS9  U R                  5       n U R	                  U R
                   SU 3U5      nUR                  S:X  a   UR                  5       n[        S0 UD6$ UR                  S	:X  a  [        S
5      eU R                  US5         [        SSSSS9$ ! [         a  n[        S[        U5       35      eSnAff = f! [         a  n[        [        U5      5      eSnAff = f)a  
Check the status of a LLMs.txt generation operation.

.. deprecated::
    /v1/llmstxt is deprecated and will not be replaced.

Args:
    id (str): The unique identifier of the LLMs.txt generation job to check status for.

Returns:
    GenerateLLMsTextStatusResponse: A response containing:
    * success (bool): Whether the generation was successful
    * status (str): Status of generation ("processing", "completed", "failed")
    * data (Dict[str, str], optional): Generated text with fields:
      * llmstxt (str): Generated LLMs.txt content
      * llmsfulltxt (str, optional): Full version if requested
    * error (str, optional): Error message if generation failed
    * expiresAt (str): When the generated data expires

Raises:
    Exception: If the status check fails.
r   NrO  r  r/  /v1/llmstxt/r  zFFailed to parse Firecrawl response as GenerateLLMsTextStatusResponse:   z!LLMs.txt generation job not foundz check LLMs.txt generation statusFr\  rg   r  rR  r,   )r#  r=  r>  r  r  rt  r  rH   rj  r   r3   r  r{  )r}  r   r#  re   r  r[  r  s          r#   rU  .V1FirecrawlApp.check_generate_llms_text_status'	  s   . 	A 	 	

 '')	%((DLL>bT)JGTH##s*w (I;HiHH %%, CDD""8-OP 0E\emy{|| ! w#&lmpqrmslt$uvvw  	%SV$$	%s;   1C B2 8-C 2
C<CCC 
C>%C99C>c                 Z    U(       a  SSU R                    3US.$ SSU R                    3S.$ )z
Prepare the headers for API requests.

Args:
    idempotency_key (Optional[str]): A unique key to ensure idempotency of requests.

Returns:
    Dict[str, str]: The headers including content type, authorization, and optionally idempotency key.
zapplication/jsonr  )Content-Typer  zx-idempotency-key)rd  r  )rs  )r}  r  s     r#   r  V1FirecrawlApp._prepare_headersV	  sB      2#*4<<.!9%4  /&t||n5
 	
r5   r   retriesbackoff_factorc                     [        U5       H`  n[        R                  " XUSU;   a  US   b  US   S-  S-   OSS9nUR                  S:X  a  [        R
                  " USU-  -  5        M^  Us  $    W$ )a  
Make a POST request with retries.

Args:
    url (str): The URL to send the POST request to.
    data (Dict[str, Any]): The JSON data to include in the POST request.
    headers (Dict[str, str]): The headers to include in the POST request.
    retries (int): Number of retries for the request.
    backoff_factor (float): Backoff factor for retries.

Returns:
    requests.Response: The response from the POST request.

Raises:
    requests.RequestException: If the request fails after the specified retries.
r   Nr  r)  r    r  )ranger  r  r  r?  r@  )r}  rQ   r   re   rf  rg  attemptr  s           r#   r  V1FirecrawlApp._post_requestn	  s    . W~G}}Sqz  C  rC  HL  MV  HW  HcPTU^P_bhPhklPl  im  oH##s*

>Q'\:; & r5   c                     [        U5       HG  n[        R                  " XS9nUR                  S:X  a  [        R
                  " USU-  -  5        ME  Us  $    W$ )a  
Make a GET request with retries.

Args:
    url (str): The URL to send the GET request to.
    headers (Dict[str, str]): The headers to include in the GET request.
    retries (int): Number of retries for the request.
    backoff_factor (float): Backoff factor for retries.

Returns:
    requests.Response: The response from the GET request.

Raises:
    requests.RequestException: If the request fails after the specified retries.
re   ri  r  )rj  r  r  r  r?  r@  r}  rQ   re   rf  rg  rk  r  s          r#   r  V1FirecrawlApp._get_request	  sO    * W~G||C9H##s*

>Q'\:; & r5   c                     [        U5       HG  n[        R                  " XS9nUR                  S:X  a  [        R
                  " USU-  -  5        ME  Us  $    W$ )a  
Make a DELETE request with retries.

Args:
    url (str): The URL to send the DELETE request to.
    headers (Dict[str, str]): The headers to include in the DELETE request.
    retries (int): Number of retries for the request.
    backoff_factor (float): Backoff factor for retries.

Returns:
    requests.Response: The response from the DELETE request.

Raises:
    requests.RequestException: If the request fails after the specified retries.
rn  ri  r  )rj  r  deleter  r?  r@  ro  s          r#   r  V1FirecrawlApp._delete_request	  sO    * W~Gs<H##s*

>Q'\:; & r5   c                     U R                    SU 3nU R                  XB5      nUR                  S:X  a   UR                  5       nUS   S:X  a  SU;   a|  US   nSU;   ab  [        US   5      S:X  a  OOU R                  US   U5      n UR                  5       nUR                  UR                  S/ 5      5        SU;   a  Mb  XvS'   [        S0 UD6$ [	        S	5      eUS   S
;   a#  [        US5      n[        R                  " U5        O#[	        SUS    35      eU R                  US5        GM+  !   [	        S5      e= f!   [	        S5      e= f)a  
Monitor the status of a crawl job until completion.

Args:
    id (str): The ID of the crawl job.
    headers (Dict[str, str]): The headers to include in the status check requests.
    poll_interval (int): Seconds between status checks.

Returns:
    CrawlStatusResponse: The crawl results if the job is completed successfully.

Raises:
    Exception: If the job fails or an error occurs during status checks.
r  r  r  r   rf   r   r   r   z,Crawl job completed but no data was returnedactivepausedpendingqueuedwaitingr   r  z)Crawl job failed or was stopped. Status: r  r,   )rt  r  r  rH   r   r  r  r  r
  maxr?  r@  r  )r}  r   re   r  rt  r  r  r   s           r#   r  "V1FirecrawlApp._monitor_job_status	  s|   & j5G"//AO**c1T"1"6"6"8K x(K7,*62$3";v#671< %.2.?.?F@SU\.]O`.=.B.B.D !KK(CD %3 /3F+4C{CC'(VWW *.nn"%mA"6MJJ}-#&OP[\dPeOf$ghh""?4HI? T#&QSS`&/2]&_ _s   D- D= -D:=E
r  r  c                     UR                  5       nUR                  SS5      nUR                  SS5      nU R                  UR                  X$U5      n[        R                  R                  XqS9e!    UR                  SS nUR                  5       (       a  SU 3nSUR                   3n NwS	UR                   3nS
n N! [
         a    SUR                   3nS
n  Nf = f= f)a0  
Handle errors from API responses.

Args:
    response (requests.Response): The response object from the API request.
    action (str): Description of the action that was being performed.

Raises:
    Exception: An exception with a message containing the status code and error details from the response.
r   No error message provided.details%No additional error details provided.Nr;  z#Server returned non-JSON response: zFull response status: z+Server returned empty response with status zNo additional details availablez0Server returned unreadable response with status )r  )
rH   r  r   r   r  r{  _get_error_messager  
exceptions	HTTPError)r}  r  r  r  error_messageerror_detailsresponse_textmessages           r#   r  V1FirecrawlApp._handle_error	  s    	B$MMOM)--g7STM)--i9`aM ))(*>*>Wde !!++G+GG#	B
B (ds 3 &&((&I-$YM&<X=Q=Q<R$SM&QRZRfRfQg$hM$EM B"RS[SgSgRh i ABs/   4A0 0C"38C -C  CC"CC"r  r  r  c                     US:X  a  SU SU SU 3$ US:X  a  SU SU SU 3$ US:X  a  SU S	U SU 3$ US
:X  a  SU SU SU 3$ US:X  a  SU SU SU 3$ SU SU SU SU 3$ )a  
Generate a standardized error message based on HTTP status code.

Args:
    status_code (int): The HTTP status code from the response
    action (str): Description of the action that was being performed
    error_message (str): The error message from the API response
    error_details (str): Additional error details from the API response
    
Returns:
    str: A formatted error message
i  zPayment Required: Failed to z. z - i  z!Website Not Supported: Failed to i  zRequest Timeout: Failed to z as the request timed out. i  zConflict: Failed to z due to a conflict. r;  z!Internal Server Error: Failed to zUnexpected error during z: Status code r,   r}  r  r  r  r  s        r#   r  !V1FirecrawlApp._get_error_message 
  s     #1&M?#m_]]C6vhbsS`RabbC08STaSbbefsetuuC)&1Em_TWXeWfggC6vhbsS`Rabb-fX^K=PRS`Raaderdsttr5   )r  
time_limitrK  analysis_promptrm  *_V1FirecrawlApp__experimental_stream_stepson_activity	on_sourcer  r  r  r  r  c          	         SSK n
U
R                  S[        SS9  0 nUb  X+S'   Ub  X;S'   Ub  XKS'   Ub  X[S	'   Ub  XkS
'   Ub  X{S'   [        S0 UD6nU R	                  UUUUUUS9nUR                  S5      (       a  SU;  a  U$ US   nSnSn U R                  U5      nU(       a-  SU;   a'  US   US nU H  nU" U5        M     [        US   5      nU	(       a-  SU;   a'  US   US nU H  nU	" U5        M     [        US   5      nUS   S:X  a  U$ US   S:X  a  [        SUR                  S5       35      eUS   S:w  a  O[        R                  " S5        M  SSS.$ a]  
Initiates a deep research operation on a given query and polls until completion.

.. deprecated::
    /v1/deep-research is deprecated. Use /v2/search instead.

Args:
    query (str): Research query or topic to investigate
    max_depth (Optional[int]): Maximum depth of research exploration
    time_limit (Optional[int]): Time limit in seconds for research
    max_urls (Optional[int]): Maximum number of URLs to process
    analysis_prompt (Optional[str]): Custom prompt for analysis
    system_prompt (Optional[str]): Custom system prompt
    __experimental_stream_steps (Optional[bool]): Enable experimental streaming
    on_activity (Optional[Callable]): Progress callback receiving {type, status, message, timestamp, depth}
    on_source (Optional[Callable]): Source discovery callback receiving {url, title, description}

Returns:
    DeepResearchStatusResponse containing:
    * success (bool): Whether research completed successfully
    * status (str): Current state (processing/completed/failed)
    * error (Optional[str]): Error message if failed
    * id (str): Unique identifier for the research job
    * data (Any): Research findings and analysis
    * sources (List[Dict]): List of discovered sources
    * activities (List[Dict]): Research progress log
    * summaries (List[str]): Generated research summaries

Raises:
    Exception: If research fails
r   N8/v1/deep-research is deprecated. Use /v2/search instead.r  r/  r   rX  rQ  rZ  r   __experimental_streamSteps)r  r  rK  r  rm  r   r   ra  r%  r   rf   rg   zDeep research failed. Error: r   r"  Fz)Deep research job terminated unexpectedlyr<  r,   )r#  r=  r>  rV  async_deep_researchr  check_deep_research_statusr  r   r?  r@  )r}  r(  r  r  rK  r  rm  r  r  r  r#  research_paramsr  rB  last_activity_countlast_source_countr   new_activitiesactivitynew_sourcessources                        r#   deep_researchV1FirecrawlApp.deep_research:
  s   V 	F 	 	

  *3J'!+5K()1I&&0?,-$.;N+&2<W89.AA++!+' , 
 ||I&&$h*>O$44V<F|v5!'!56I6J!K .H) !/&)&*>&?#Y&0$Y/0A0BC)Ff% *$'y(9$:!h;.!X-"?

7@S?T UVV!\1JJqM- 0 !+VWWr5   )r  r  rK  r  rm  r  c                   SSK nUR                  S[        SS9  0 n	Ub  X)S'   Ub  X9S'   Ub  XIS'   Ub  XYS	'   Ub  XiS
'   Ub  XyS'   [        S0 U	D6n	U R	                  5       n
SU0U	R                  SSS9EnS[         3US'   SU;   a?  US   nU(       a3  SU;   a-  [        US   S5      (       a  US   R                  5       US   S'    U R                  U R                   S3X5      nUR                  S:X  a   UR                  5       $ U R                  US5         SSS.$ !   [        S5      e= f! [         a  n[        [!        U5      5      eSnAff = f)  
Initiates an asynchronous deep research operation.

.. deprecated::
    /v1/deep-research is deprecated. Use /v2/search instead.

Args:
    query (str): Research query or topic to investigate
    max_depth (Optional[int]): Maximum depth of research exploration
    time_limit (Optional[int]): Time limit in seconds for research
    max_urls (Optional[int]): Maximum number of URLs to process
    analysis_prompt (Optional[str]): Custom prompt for analysis
    system_prompt (Optional[str]): Custom system prompt
    __experimental_stream_steps (Optional[bool]): Enable experimental streaming

Returns:
    Dict[str, Any]: A response containing:
    * success (bool): Whether the research initiation was successful
    * id (str): The unique identifier for the research job
    * error (str, optional): Error message if initiation failed

Raises:
    Exception: If the research initiation fails.
r   Nr  r  r/  r   rX  rQ  rZ  r   r  r(  Tr  r  r  r   ro   /v1/deep-researchr  r  zstart deep researchFr\  r<  r,   )r#  r=  r>  rV  r  r  r  hasattrro   r  rt  r  rH   r   r  r{  r3   )r}  r(  r  r  rK  r  rm  r  r#  r  re   r[  	json_optsr  r  s                  r#   r  "V1FirecrawlApp.async_deep_research
  s   D 	F 	 	

  *3J'!+5K()1I&&0?,-$.;N+&2<W89.AA'')e^';';TX\';']^	 +G95	( I%!-0IX2wy?RT\7]7]5>x5H5O5O5Q	-(2
	%))T\\N:K*LiaH##s*S#==?* ""8-BC !+BCCS#$QRR  	%SV$$	%s0   /D/ 7D D/ D,,D/ /
E9EEc                    SSK nUR                  S[        SS9  U R                  5       n U R	                  U R
                   SU 3U5      nUR                  S:X  a   UR                  5       $ UR                  S	:X  a  [        S
5      eU R                  US5         SSS.$ !   [        S5      e= f! [         a  n[        [        U5      5      eSnAff = f)  
Check the status of a deep research operation.

.. deprecated::
    /v1/deep-research is deprecated. Use /v2/search instead.

Args:
    id (str): The ID of the deep research operation.

Returns:
    DeepResearchResponse containing:

    Status:
    * success - Whether research completed successfully
    * status - Current state (processing/completed/failed)
    * error - Error message if failed

    Results:
    * id - Unique identifier for the research job
    * data - Research findings and analysis
    * sources - List of discovered sources
    * activities - Research progress log
    * summaries - Generated research summaries

Raises:
    Exception: If the status check fails.
r   Nr  r  r/  /v1/deep-research/r  r  ra  zDeep research job not foundzcheck deep research statusFr\  r<  )r#  r=  r>  r  r  rt  r  rH   r   r  r{  r3   )r}  r   r#  re   r  r  s         r#   r  )V1FirecrawlApp.check_deep_research_status
  s    8 	F 	 	

 '')	%((DLL>9KB4)PRYZH##s*S#==?* %%, =>>""8-IJ !+BCCS#$QRR
  	%SV$$	%s/   1B0 B  --B0  B--B0 0
C:CCr  method_namec           	         U(       d  g1 Sk1 Sk1 Sk1 Sk1 Sk1 Sk1 Sk1 SkS.nUR                  U[        5       5      n[        UR                  5       5      U-
  nU(       a!  [        S	U S
SR	                  U5       S35      eg)ah  
Validate additional keyword arguments before they are passed to the API.
This provides early validation before the Pydantic model validation.

Args:
    kwargs (Dict[str, Any]): Additional keyword arguments to validate
    method_name (str): Name of the method these kwargs are for

Raises:
    ValueError: If kwargs contain invalid or unsupported parameters
N>   r   r   rY   rV   ry   r  r   r   r  r  r  r  r  r  r  r  r  r  >	   r*  r-  r   r+  r`   r   r   r  r  >   r   r   r  r  r  r  r  r  r  r  r  rn  r  r  >   r   r   r   r  r  r  r  >   r   r+   ro   r  rp  rm  ro  rn  >   r   r   r   rY   rV   ry   re   r   r   r   r  r  r  r  r  r  r  r  )r  r   r  r  rV   r  r  r"  zUnsupported parameter(s) for z: z, zC. Please refer to the API documentation for the correct parameters.)r  setkeysr{  r   )r}  r  r  method_paramsallowed_paramsunknown_paramss         r#   r  V1FirecrawlApp._validate_kwargs&  s     K | } R"@(F,J%
2 '**;> V[[]+n<<[MDIIVdLeKf  gj  k  l  l r5   c                    Uc  U$ [        U[        5      (       aB  [        US5      (       a  UR                  5       $ [        US5      (       a  UR	                  5       $ [        U[
        5      (       a4  UR                  5        VVs0 s H  u  p#X R                  U5      _M     snn$ [        U[        [        45      (       a!  U Vs/ s H  o0R                  U5      PM     sn$ U$ s  snnf s  snf )zg
Utility to ensure a schema is a dict, not a Pydantic model class. Recursively checks dicts and lists.
model_json_schemaro   )
r  r   r  r  ro   r  itemsr  listtuple)r}  ro   kvs       r#   r  "V1FirecrawlApp._ensure_schema_dictY  s     >Mfd##v233//11**}}&fd##?E||~N~tqA//22~NNftUm,,9?@A,,Q/@@ O@s   C$C*c                    U(       a  [        U[        [        45      (       d  gUc
  [        5       nSSKnUR
                  " US[        S9nXd;   a  gUR                  U5         [        U[        5      (       a  SU;   a  [        US   [        5      (       a}  US   R                  S5      n[        U5      S:  aZ  US   S	:X  aQ  US
   S:X  aH  US   nX:X  a   UR                  U5        gX;   a&  U R                  X8   X#U5      UR                  U5        $ UR                  5        H-  n	U R                  XX45      (       d  M    UR                  U5        g   OH[        U[        5      (       a3  U H-  n
U R                  XX45      (       d  M    UR                  U5        g   UR                  U5        g! UR                  U5        f = f)aU  
Check if an object contains a recursive reference to a specific definition.

Args:
    obj: Object to check
    target_def_name: Name of the definition to check for recursion
    defs: Dictionary of definitions
    visited: Set of visited object keys to detect cycles
    
Returns:
    True if recursive reference is found, False otherwise
FNr   T)	sort_keysdefault$ref/   #r   $defs)r  r  r  r  rH   dumpsr3   addsplitr  discard_contains_recursive_refvalues)r}  objtarget_def_namedefsvisitedrH   obj_keyref_pathdef_namevalueitems              r#   r  &V1FirecrawlApp._contains_recursive_refk  s    *S4,77?eG**SD#>G	%#t$$S=ZFS%A%A"6{005H8})hqkS.@Xa[T[E[#+B<#6#' OOG$ $+#'#?#?P_gn#o OOG$ !ZZ\E33EDZZ# OOG$ * C&&D33D4YY# OOG$  
 OOG$ OOG$s1   #A2F/ (F/ (F/ ?F/ 2F/ F/ F/ /Gc                 x    U(       d  gUR                  5        H  u  p#U R                  X2U5      (       d  M    g   g)z
Check if $defs contain circular references.

Args:
    defs: Dictionary of definitions to check
    
Returns:
    True if circular references are found, False otherwise
FT)r  r  )r}  r  r  	def_values       r#   _check_for_circular_defs'V1FirecrawlApp._check_for_circular_defs  s8     #'::<H++IFF $0 r5   c           
         U(       a!  [        U[        [        45      (       a  US:  a  U$ Uc
  [        5       n[	        U5      nXS;   a  U$ UR                  U5         [        U[        5      (       a  SU;   a  [        US   [        5      (       a  US   R                  S5      n[        U5      S:  aN  US   S:X  aE  US   S:X  a<  US	   nXr;   a2  U R                  [        X'   5      X#US-   5      UR                  U5        $ UUR                  U5        $ 0 nUR                  5        H$  u  pU	S:X  a  M  U R                  XX4S-   5      X'   M&     UUR                  U5        $ [        U[        5      (       a6  U Vs/ s H  oR                  XX4S-   5      PM     snUR                  U5        $  UR                  U5        U$ s  snf ! UR                  U5        f = f)
a$  
Resolve $ref references in a JSON schema object.

Args:
    obj: Object to resolve references in
    defs: Dictionary of definitions
    visited: Set to track visited objects and prevent infinite recursion
    depth: Current recursion depth
    
Returns:
    Object with resolved references
rP  r  r  r  r   r  r   r  r  )r  r  r  r  r   r  r3   r  r  _resolve_refsr  r  )r}  r  r  r  depthobj_idr  r  resolvedr   r  r  s               r#   r  V1FirecrawlApp._resolve_refs  s    *S4,7752:J?eGCJF	$#t$$S=ZFS%A%A"6{005H8})hqkS.@Xa[T[E[#+B<#+#'#5#5d4>6JD[`cd[d#e OOF#  OOF# "%))+JCg~ $($6$6uGUVY$WHM #.   OOF#	 C&&WZ[WZt**4w	JWZ[ OOF#	 ' OOF#
 \ OOF#s1   BG  G ;G  G 9F?G ?G Gc                 t   ^^ U(       a  [        U[        5      (       d  U$ [        5       mUU4S jmT" U5      $ )z
Normalize a schema for OpenAI compatibility by handling recursive references.

Args:
    schema: Schema to normalize
    
Returns:
    Normalized schema
c           
      @  > [        U [        5      (       d0  [        U [        5      (       a  U  Vs/ s H  nT" U5      PM     sn$ U $ [        U 5      nUT;   a  U $ TR	                  U5        [        U 5      nSU;   a  TR                  U5        U$ SU;   a  UR                  S5      n0 nUR                  5        H0  u  pg[        U[        5      (       a  SU;  a  T" U5      XV'   M,  XuU'   M2     0 UESUR                  5        VV	s0 s H  u  pUT" U	5      _M     sn	n0En
TR                  U5        U
$ UR                  S5      S:X  a  SU;   a  UR                  S5      SL a  US	 UR                  S5      S:X  an  SU;   ah  SU;   ab  [        US   [        5      (       aG  [        US   [        5      (       a/  US    Vs/ s H  nXS   ;   d  M  UPM     nnU(       a  XS'   OUS	 OUS	 [        UR                  5       5       Hu  u  pg[        U[        5      (       a  SU;  a  T" U5      X6'   M,  [        U[        5      (       d  MC  U Vs/ s H"  n[        U[        5      (       a  T" U5      OUPM$     snX6'   Mw     TR                  U5        U$ s  snf s  sn	nf s  snf s  snf )	Nr  r  r   object
propertiesadditionalPropertiesTrequired)	r  r  r  r   r  r  popr  r  )r  r  r  
normalizedr  processed_restr   r  r  r  resultfieldvalid_requirednormalize_objectr  s                r#   r  EV1FirecrawlApp._normalize_schema_for_openai.<locals>.normalize_object  s   c4((c4((?BCst,T2sCC
 WF 
KKcJ #'!!*$!~~g.!#","2"2"4JC"5$//F%4G.>u.E+.3s+	 #5 hNgGY]YcYcYe5fYeQUQRa9I!9L6LYe5fg' v&(2
*56$>56v&(2j(
*z*5t<<z,7>>9CJ9O &I9O&+,/G&G ',9ON &I%1?:.&z2":. #:#3#3#56
eT**vU/B&6u&=JOt,,ns&tnsfjDRVAWAW'7'=]a'ans&tJO 7 OOF#w D4 6g&I 'us   JJ
;JJ)Jr  r  r  )r}  ro   r  r  s     @@r#   _normalize_schema_for_openai+V1FirecrawlApp._normalize_schema_for_openai  s3     Z55M%>	@  ''r5   c                 |   ^^ U(       a  [        U[        5      (       d  g[        5       mUU4S jmT" U5      (       + $ )z
Validate schema for OpenAI compatibility.

Args:
    schema: Schema to validate
    
Returns:
    True if schema is valid, False otherwise
Tc                   > [        U [        5      (       d  g[        U 5      nUT;   a  gTR                  U5        SU ;   a  TR	                  U5        gU R                  S5      S:X  a2  SU ;  a,  SU ;  a&  U R                  S5      SL a  TR	                  U5        gU R                  5        H  n[        U[        5      (       a(  SU;  a"  T" U5      (       a  TR	                  U5          gM@  [        U[        5      (       d  MW  U HC  n[        U[        5      (       d  M  SU;  d  M"  T" U5      (       d  M1  TR	                  U5            g   M     TR	                  U5        g)	NFr  r   r  r  patternPropertiesr  T)r  r  r   r  r  r  r  r  )r  r  r  r  has_invalid_structurer  s       r#   r  IV1FirecrawlApp._validate_schema_for_openai.<locals>.has_invalid_structureB  s'   c4((WF KK}'8+C'#3../47' eT**vU/B,U33/# 4  t,, %%dD11fD6H4T:: ' 7'+	 !& & OOF#r5   r  )r}  ro   r  r  s     @@r#   _validate_schema_for_openai*V1FirecrawlApp._validate_schema_for_openai3  s4     Z55%#	J )000r5   c                    U(       a  [        U[        5      (       d  gSSKnUR                  " U5      nSU;   =(       d    SU;   =(       d    SU;   n[	        UR                  S5      =(       d    UR                  S5      5      nU=(       d    U$ )	z
Detect if a schema contains recursive references.

Args:
    schema: Schema to analyze
    
Returns:
    True if schema has recursive patterns, False otherwise
Fr   N"$ref"#/$defs/z#/definitions/r  definitions)r  r  rH   r  r   r  )r}  ro   rH   schema_stringhas_refshas_defss         r#   _detect_recursive_schema'V1FirecrawlApp._detect_recursive_schemai  s|     Z55

6*% .-'.- 	
 

7+Hvzz-/HI#8#r5   c                 Z    U(       d  SSS.$ U R                  U5      (       a  SSS.$ SSS.$ )z
Select appropriate model based on schema complexity.

Args:
    schema: Schema to analyze
    
Returns:
    Dict with modelName and reason
zgpt-4o-mini	no_schema)	modelNamereasonzgpt-4orecursive_schema_detectedsimple_schema)r  )r}  ro   s     r#   _select_model_for_schema'V1FirecrawlApp._select_model_for_schema  s:     !.+FF((00!)5PQQ*oFFr5   c                 &   [        U[        5      (       GaZ  X!;   GaT  U R                  X   5      nU(       a  [        U[        5      (       a  UR                  S0 5      nSSKnUR
                  " U5      nUR                  S5      =(       d    SU;   =(       d    SU;   nU(       a]   U R                  X45      nUR
                  " U5      n	SU	;   =(       d    SU	;   n
U
(       d   Un[        U[        5      (       a	  SU;   a  US	 O0 U R                  X45      n[        U[        5      (       a	  SU;   a  US	 U R                  U5      nU R                  U5      (       d  [        U R                  5      eX1U'   U$ ! [         a     NNf = f! [         a     N^f = f)z
Process and validate a schema container (like extract or json_options).

Args:
    schema_container: Dict containing schema
    schema_key: Key where schema is stored (default: "schema")
    
Returns:
    Processed schema container
r  r   Nr  r  )r  r  r  r  rH   r  r  r   r  r  r{  OPENAI_SCHEMA_ERROR_MESSAGE)r}  schema_container
schema_keyro   r  rH   r  has_any_refsresolved_schemaresolved_stringhas_remaining_refss              r#   _process_schema_with_validation.V1FirecrawlApp._process_schema_with_validation  s    &--*2P--.>.JKF *VT22zz'2. $

6 2JJw' 0-0-/   *.*<*<V*J*.**_*E-5-H-iJZiLi*1%4F)&$77Gv<M$*7O!%!3!3F!A%fd3368I &w 66v>F33F;; !A!ABB+1Z(# %  % s%   %AE3 /F 3
F ?F 
FFrs  rt  NN)FNr        ?)Nr   )ro   )`r-   r.   r/   r0   r1   r  r   r3   r~  r   r	   r   r   r   r^   r   r   r   r   r   r   r   r   r   r   r   rl   r   r   r  rs   r1  r   r9  r  r?  r  rG  r  rM  r  rc   r
  r  r  r  r  r  r   r  r  r  r  r'   r   r  r   r  r"  r'  r*  r   rV   rE  rH  rj  rW  rd  rT  rU  r  r   r  Responser  r  r  r  r  r  r   r_  r  r  r  r  r  r  r  r  r  r  r  r  r  r4   r,   r5   r#   rr  rr    s   $	q  Q Qx} QX\ Q, mq04040404&*%*37%)4837(,OS(,.237 EIIM%)-1261U7U7 d7  ,g  $h  i  j	U7
 d38n-U7 #49-U7 #49-U7  (~U7 smU7 c]U7 /0U7 TNU7 $,D>U7 #+4.U7  ~U7  G$JKL!U7"  ~#U7$ l+%U7& #<0'U7( d57I=Zgiv  yG  IW  Yr  t  *  $@  A  B)U7* &..E%F+U7, c]-U7. %TN/U70 "*$1U72 *#.3U7v $(!%$("&%)&*%*8<]3]3 C=	]3
 #]3 SM]3 3-]3 c]]3 sm]3 c]]3 %_5]3 *]3~="7 =,<!5 <,Hd HGf H(GT GFd G0 .2-1#'-1#/3.2/3)-489=3726,0#+/)-.2'()-/@<@<  S	*	@<
  S	*@< C=@< &c]@< }@< 'tn@< &d^@< 'tn@< !@< !1@< %_ 456@< #+4.@<  "*$!@<" $D>#@<$ }%@<& #4.'@<( "#)@<* &d^+@<,  }-@<. "#/@<2 
3@<L .2-1#'-1#/3.2/3)-489=3726,0#+/)-.2)--z<z<  S	*	z<
  S	*z< C=z< &c]z< }z< 'tnz< &d^z< 'tnz< !z< !1z< %_ 456z< #+4.z<  "*$!z<" $D>#z<$ }%z<& #4.'z<( "#)z<* &d^+z<, "#-z<0 
1z<xQ?S Q?-B Q?f?S ?-B ?:=s =tCH~ =: 2615'+15#'372637-18<=A7;6:04#'/3-126-1-S9S9 $DI.	S9
 $DI.S9  }S9 "*#S9 C=S9 #+4.S9 "*$S9 #+4.S9 %TNS9 %_5S9 eC$89:S9 '/tnS9  &.d^!S9"  (~#S9$ C=%S9& 'tn'S9( &c])S9* "*$+S9, &c]-S90 
1S9r %)-115+/#'%*(,37[0[0 SM	[0
 %TN[0 !)[0 #4.[0 C=[0 c][0  ~[0 /0[0 '[0B W[,0,0,0,0"&!&/3!%04/3$(KO*./3 AE*.'()-.2)-1KC3iKC $w  (Q   R  S  T	KC
 $sCx.)KC tCy)KC tCy)KC $D>KC 3-KC #KC +,KC KC  (~KC 'tnKC D>KC   FGH!KC" ,'#KC$ |,%KC& $u\3E}Vcer  uC  ES  Un  p{  &{   |  }  ~'KC( ')KC*  }+KC, "#-KC. &d^/KC0 "#1KC4 
%5KCb W[,0,0,0,0"&!&/3!%04/3$(KO*./3 AE*.)-)-.2/JC3iJC $w  (Q   R  S  T	JC
 $sCx.)JC tCy)JC tCy)JC $D>JC 3-JC #JC +,JC JC  (~JC 'tnJC D>JC   FGH!JC" ,'#JC$ |,%JC& $u\3E}Vcer  uC  ES  Un  p{  &{   |  }  ~'JC( ')JC* "#+JC, "#-JC. &d^/JC2 
3JC` W[,0,0,0,0"&!&/3!%04/3$(KO*./3 AE*.)-.2)-/JC3iJC $w  (Q   R  S  T	JC
 $sCx.)JC tCy)JC tCy)JC $D>JC 3-JC #JC +,JC JC  (~JC 'tnJC D>JC   FGH!JC" ,'#JC$ |,%JC& $u\3E}Vcer  uC  ES  Un  p{  &{   |  }  ~'JC( ')JC* "#+JC, &d^-JC. "#/JC2 
3JCX<FC <F4O <F|FC F4I F> )-~P %)$(+/3805+0.2~P49%~P SM	~P
 SM~P $C=~P #+4.~P  (~~P #4.~P DcN+~P +3/~P@%* %*1B31G %*R )-O* %)$(+/3805+0.2O*49%O* SM	O*
 SMO* $C=O* #+4.O*  (~O* #4.O* DcN+O* 8I7MO*j '+-1$(26LL sm	L
 %TNL D>L "*$L <\Ld '+-1$(26A
A
 sm	A

 %TNA
 D>A
 "*$A
 <VA
F-}# -}:Z -}b .2
%c]
6:38n
: $' sCx. #s(^	
  " -5,=,=F $' #s(^ 	
 "
 -5,=,=B $' #s(^ 	
 "
 -5,=,=:2J2J #s(^2J 	2J $9	2Jh#H''#H #H !#HJuc u3 us ucf ukn u< (,(,&*-1+/:>FJDHgXgX  }	gX
 !gX smgX &c]gX $C=gX *2$gX "(DcN+;T+A"BCgX  $sCx.)94)? @AgX NjgXZ (,(,&*-1+/:>NDND  }	ND
 !ND smND &c]ND $C=ND *2$ND DHS>ND`1DS 1D5Q 1Df.ltCH~ .lC .lD .lf$0d&0dO(b41l$0G$6 r5   rr  c                       \ rS rSrSrS\S\4S jrSS jrSS	 jr	S
\S\
\\\4   /S4   SS4S jrS
\S\\\4   SS4S jrS\\\4   SS4S jrSrg)r  i  a  
A class to watch and handle crawl job events via WebSocket connection.

Attributes:
    id (str): The ID of the crawl job to watch
    app (V1FirecrawlApp): The V1FirecrawlApp instance
    data (List[Dict[str, Any]]): List of crawled documents/data
    status (str): Current status of the crawl job
    ws_url (str): WebSocket URL for the crawl job
    event_handlers (dict): Dictionary of event type to list of handler functions
r   appc                     Xl         X l        / U l        SU l        UR                  R                  SS5       SU 3U l        / / / S.U l        g )Nr   httpwsr  )doner   document)r   r  r   r   rt  replacews_urlevent_handlers)r}  r   r  s      r#   r~  V1CrawlWatcher.__init__  sQ    *,	 ,,VT:;:bTJ
r5   ru  Nc                 $  #    [         R                  " U R                  SSSU R                  R                   34/S9 ISh  vN nU R                  U5      I Sh  vN   SSS5      ISh  vN   g N. N N	! , ISh  vN  (       d  f       g= f7f)zE
Establishes WebSocket connection and starts listening for messages.
Nr  r  )max_sizeadditional_headers
websocketsconnectr  r  rs  _listenr}  	websockets     r#   r&  V1CrawlWatcher.connect  s      %%KK!0GDHH<L<L;M2N OP
 
 ,,y)))
 
 

 *
 
 
 
sY   ?BA0BA6A2A6B*A4+B2A64B6B<A?=B	Bc                    #    U  Sh  vN n[         R                  " U5      nU R                  U5      I Sh  vN   M:   N5 N
 g7f)zq
Listens for incoming WebSocket messages and handles them.

Args:
    websocket: The WebSocket connection object
NrH   loads_handle_messager}  r)  r  msgs       r#   r'  V1CrawlWatcher._listen  @      ' 	,'**W%C&&s+++	,+ '3   AA?A+AAAAAA
event_typehandlerc                 `    XR                   ;   a  U R                   U   R                  U5        gg)z
Adds an event handler function for a specific event type.

Args:
    event_type (str): Type of event to listen for ('done', 'error', or 'document')
    handler (Callable): Function to handle the event
N)r  append)r}  r4  r5  s      r#   add_event_listener!V1CrawlWatcher.add_event_listener  s.     ,,,
+227; -r5   detailc                 `    XR                   ;   a  U R                   U    H  nU" U5        M     gg)z
Dispatches an event to all registered handlers for that event type.

Args:
    event_type (str): Type of event to dispatch
    detail (Dict[str, Any]): Event details/data to pass to handlers
N)r  )r}  r4  r:  r5  s       r#   dispatch_eventV1CrawlWatcher.dispatch_event  s1     ,,,..z: ; -r5   r0  c                   #    US   S:X  a<  SU l         U R                  SU R                   U R                  U R                  S.5        gUS   S:X  a@  SU l         U R                  SU R                   U R                  US   U R                  S.5        gUS   S:X  am  US	   S
   U l         U R                  R	                  US	   R                  S	/ 5      5        U R                   H!  nU R                  SX R                  S.5        M#     gUS   S:X  aA  U R                  R                  US	   5        U R                  SUS	   U R                  S.5        gg7f)zq
Handles incoming WebSocket messages based on their type.

Args:
    msg (Dict[str, Any]): The message to handle
r   r  rf   r   r   r   r   rg   r   r   r   r   catchupr   r   r  r   r   Nr   r<  r   r   r  r  r7  r}  r0  docs      r#   r.  V1CrawlWatcher._handle_message  (     v;& %DK4;;		Y]Y`Y`(ab[G#"DKDKK]`ah]iquqxqx)yz[I%f+h/DKIIS[__VR89yy##JGG0LM ![J&IIS[)
S[,PQ '   EE)r  r   r  r   r   r  ru  N)r-   r.   r/   r0   r1   r3   rr  r~  r&  r'  r   r   r   r8  r<  r.  r4   r,   r5   r#   r  r    s    


3 

^ 

	*	,	<S 	<8T#s(^DTVZDZ;[ 	<`d 	<
  
 d38n 
  
 Rc3h RD Rr5   r  c            0       &  ^  \ rS rSrSrSS\S\4U 4S jjjr   SS\S\S	\\\4   S
\\\\	4      S\
S\S\\\	4   4S jjr SS\S
\\\	4   S	\\\4   S\
S\S\\\	4   4S jjr SS\S	\\\4   S\
S\S\\\	4   4
S jjrS\R                   S\SS4S jrS\
S\S\S\S\4
S jrS\4S jrS\4S jr  SS\S\\   S\\   SS4S jjr  SS\\   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#         S	\\\\4      S$\\\      S%\\\      S&\\   S'\\
   S(\\
   S)\\   S*\\   S+\\   S,\\   S-\\   S.\\S/      S0\\   S1\\   S2\\   S3\\\ \!\"\#\$\%\&\'\(\)4	         S\*\	   4&S4 jjr+SSSSSSS SSSSSSSSSSS5SS6.S\\   S"\\\S7         S	\\\\4      S$\\\      S%\\\      S&\\   S'\\
   S(\\
   S)\\   S*\\   S+\\   S,\\   S-\\   S.\\S/      S1\\   S2\\   S3\\\ \!\"\#\$\%\&\'\(\)4	         S8\\,   S9\\
   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\\   S"\\\S7         S	\\\\4      S$\\\      S%\\\      S&\\   S'\\
   S(\\
   S)\\   S*\\   S+\\   S,\\   S-\\   S.\\S/      S1\\   S2\\   S3\\\ \!\"\#\$\%\&\'\(\)4	         S8\\,   S<\\   S\\   S\/4*S= jjr0SSSSSSSSSSSSSSSSS5SS>.S\S?\\\      S@\\\      SA\\
   SB\\
   SC\\
   SD\\   SE\\   SF\\   SG\\   SH\\1   SI\\ \\24      SJ\\   SK\\   SL\\   SM\\
   SN\\   S9\\
   S\\   S\34(SO jjr4SSSSSSSSSSSSSSSSS5SS>.S\S?\\\      S@\\\      SA\\
   SB\\
   SC\\
   SD\\   SE\\   SF\\   SG\\   SH\\1   SI\\ \\24      SJ\\   SK\\   SL\\   SM\\
   SN\\   S9\\
   S\\   S\54(SP jjr6SQ\S\34SR jr7SSQ\S	\\\4   S9\
S\34SS jjr8SSSSSS SSST.S\SU\\   SG\\   SV\\   SW\\   SC\\
   S(\\
   S)\\   S\\9   S\:4SX jjr; SSSSSYSYSYSSZ.S\\\      S[\\   S\\\	   S]\\   SF\\   S^\\   S_\\   S8\\\\	4      S\<\	   4S` jjjr=SQ\S\-4Sa jr>SQ\S\?4Sb jr@SQ\S\?4Sc jrASQ\S\\\	4   4Sd jrBSe\S\<\	   4Sf jrC SSSSSYSYSYSSZ.S\\\      S[\\   S\\\	   S]\\   SF\\   S^\\   S_\\   S8\\\\	4      S\<\	   4Sg jjjrDSSSSh.S\Si\\
   Sj\\   Sk\\   S\E4
Sl jjrFSSSSSm.S\Si\\
   Sj\\   Sn\\   Sk\\   S\G4So jjrHSQ\S\E4Sp jrISSSSSSSSSq.Sr\SA\\
   Ss\\
   Si\\
   St\\   S]\\   Su\\   Sv\\J\\\	4   /S4      Sw\\J\\\	4   /S4      S\K4Sx jjrLSSSSSSSy.Sr\SA\\
   Ss\\
   Si\\
   St\\   S]\\   Su\\   S\\\	4   4Sz jjrMSQ\S\K4S{ jrNSSSSSSS SSS|.	Sr\SC\\
   S}\\   S~\\   S\\   S\\   S)\\   S(\\
   SH\\1   S\\ \\\	4   \O4      S\P4S jjrQSrRU =rS$ )AsyncV1FirecrawlAppi'  z
Asynchronous version of V1FirecrawlApp that implements async methods using aiohttp.
Provides non-blocking alternatives to all V1FirecrawlApp operations.
rs  rt  c                     > [         TU ]  XS9  g )Nr  superr~  )r}  rs  rt  	__class__s      r#   r~  AsyncV1FirecrawlApp.__init__-  s    :r5   NmethodrQ   re   r   rf  rg  ru  c           	      B  #    [         R                  " 5        ISh  vN n[        U5       H  n UR                  XX4S9 ISh  vN n	U	R                  S:X  a7  [
        R                  " USU-  -  5      I Sh  vN    SSS5      ISh  vN   Md  U	R                  S:  a  U R                  U	SU S35      I Sh  vN   U	R                  5       I Sh  vN sSSS5      ISh  vN   s  sSSS5      ISh  vN   $    [        S	5      e N N N N NU N? N1 N ! , ISh  vN  (       d  f       GM  = f! [         R                   a;  n
XS-
  :X  a  U
e[
        R                  " USU-  -  5      I Sh  vN     Sn
A
GMQ  Sn
A
ff = f! , ISh  vN  (       d  f       g= f7f)
a  
Generic async request method with exponential backoff retry logic.

Args:
    method (str): The HTTP method to use (e.g., "GET" or "POST").
    url (str): The URL to send the request to.
    headers (Dict[str, str]): Headers to include in the request.
    data (Optional[Dict[str, Any]]): The JSON data to include in the request body (only for POST requests).
    retries (int): Maximum number of retry attempts (default: 3).
    backoff_factor (float): Factor to calculate delay between retries (default: 0.5).
        Delay will be backoff_factor * (2 ** retry_count).

Returns:
    Dict[str, Any]: The parsed JSON response from the server.

Raises:
    aiohttp.ClientError: If the request fails after all retries.
    Exception: If max retries are exceeded or other errors occur.
N)rQ  rQ   re   rH   ri  r  i,  zmake z requestr   zMax retries exceeded)aiohttpClientSessionrj  requestr   asyncior@  r  rH   ClientErrorr   )r}  rQ  rQ   re   r   rf  rg  sessionrk  r  r  s              r#   _async_request"AsyncV1FirecrawlApp._async_request1  sp    6 ((**g >I&%  /    !#??c1")--!w,0O"PPP$      $??c1"&"4"4Xvhh?W"XXX%-]]_4      +**) 233! +  Q	  Y4  +        ** IA+-!--!w,(GHHHHI +**s3  FDFFD3D	
D30D8D
9D>D3	D
D3F)D9D
:DD
DD3!D
"D3&F(F4D5F:FF	D3DD3DDD3FD0D D0*D3-F0D33F)E=0E3
1E=6F=FFFFFFc                 F   #    U R                  SXX$U5      I Sh  vN $  N7f)a  
Make an async POST request with exponential backoff retry logic.

Args:
    url (str): The URL to send the POST request to.
    data (Dict[str, Any]): The JSON data to include in the request body.
    headers (Dict[str, str]): Headers to include in the request.
    retries (int): Maximum number of retry attempts (default: 3).
    backoff_factor (float): Factor to calculate delay between retries (default: 0.5).
        Delay will be backoff_factor * (2 ** retry_count).

Returns:
    Dict[str, Any]: The parsed JSON response from the server.

Raises:
    aiohttp.ClientError: If the request fails after all retries.
    Exception: If max retries are exceeded or other errors occur.
POSTNrY  )r}  rQ   r   re   rf  rg  s         r#   _async_post_request'AsyncV1FirecrawlApp._async_post_request^  s$     * ((tn]]]]   !!c                 F   #    U R                  SXSX45      I Sh  vN $  N7f)ac  
Make an async GET request with exponential backoff retry logic.

Args:
    url (str): The URL to send the GET request to.
    headers (Dict[str, str]): Headers to include in the request.
    retries (int): Maximum number of retry attempts (default: 3).
    backoff_factor (float): Factor to calculate delay between retries (default: 0.5).
        Delay will be backoff_factor * (2 ** retry_count).

Returns:
    Dict[str, Any]: The parsed JSON response from the server.

Raises:
    aiohttp.ClientError: If the request fails after all retries.
    Exception: If max retries are exceeded or other errors occur.
GETNr]  )r}  rQ   re   rf  rg  s        r#   _async_get_request&AsyncV1FirecrawlApp._async_get_requestu  s$     ( ((dG\\\\r`  r  r  c                 R  #     UR                  5       I Sh  vN nUR                  SS5      nUR                  SS5      nU R                  UR                  X$U5      I Sh  vN n[        R                  " U5      e Nc!   [        R                  " SUR                   35      e= f ND7f)a  
Handle errors from async API responses with detailed error messages.

Args:
    response (aiohttp.ClientResponse): The response object from the failed request
    action (str): Description of the action that was being attempted

Raises:
    aiohttp.ClientError: With a detailed error message based on the response status:
        - 402: Payment Required
        - 408: Request Timeout
        - 409: Conflict
        - 500: Internal Server Error
        - Other: Unexpected error with status code
Nr   r~  r  r  ?Failed to parse Firecrawl error response as JSON. Status code: )rH   r  rS  rW  r   _get_async_error_messager}  r  r  
error_datar  r  r  s          r#   r  !AsyncV1FirecrawlApp._handle_error  s      	{'}}.J&NN74PQM&NN96]^M 55hoov^kll!!'** /	{%%(ghphwhwgx&yzzls8   B'A= A;(A=   B' B%!B';A= =%B""B'r  r  r  c                 .   #    U R                  XX45      $ 7fa  
Generate a standardized error message based on HTTP status code for async operations.

Args:
    status_code (int): The HTTP status code from the response
    action (str): Description of the action that was being performed
    error_message (str): The error message from the API response
    error_details (str): Additional error details from the API response
    
Returns:
    str: A formatted error message
r  r  s        r#   rg  ,AsyncV1FirecrawlApp._get_async_error_message        &&{MYY   c                    #    U R                  5       nU R                  U R                   S3U5      I Sh  vN n[        S0 UD6$  N7f)z8Get current credit usage and billing period (v1, async).r  Nr,   )r  rc  rt  r9  r}  re   resps      r#   r  $AsyncV1FirecrawlApp.get_credit_usage  sO     ''),,||n12
 
 %,t,,	
   3AAAc                    #    U R                  5       nU R                  U R                   S3U5      I Sh  vN n[        S0 UD6$  N7f)z7Get current token usage and billing period (v1, async).r  Nr,   )r  rc  rt  r?  rr  s      r#   r  #AsyncV1FirecrawlApp.get_token_usage  sO     ''),,||n01
 
 $+d++	
ru  rV  r  AsyncV1CrawlWatcherc                    #    U R                  XU5      I Sh  vN nUR                  S5      (       a  SU;   a  [        US   U 5      $ [        S5      e N:7f)a  
Initiate an async crawl job and return an AsyncV1CrawlWatcher to monitor progress via WebSocket.

Args:
  url (str): Target URL to start crawling from
  params (Optional[V1CrawlParams]): See V1CrawlParams model for configuration:
    URL Discovery:
    * includePaths - Patterns of URLs to include
    * excludePaths - Patterns of URLs to exclude
    * maxDepth - Maximum crawl depth
    * maxDiscoveryDepth - Maximum depth for finding new URLs
    * limit - Maximum pages to crawl

    Link Following:
    * allowBackwardLinks - DEPRECATED: Use crawlEntireDomain instead
    * crawlEntireDomain - Follow parent directory links
    * allowExternalLinks - Follow external domain links  
    * ignoreSitemap - Skip sitemap.xml processing

    Advanced:
    * scrapeOptions - Page scraping configuration
    * webhook - Notification webhook settings
    * deduplicateSimilarURLs - Remove similar URLs
    * ignoreQueryParameters - Ignore URL parameters
    * regexOnFullURL - Apply regex to full URLs
  idempotency_key (Optional[str]): Unique key to prevent duplicate requests

Returns:
  AsyncV1CrawlWatcher: An instance to monitor the crawl job via WebSocket

Raises:
  Exception: If crawl job fails to start
Nr   r   r
  )r  r  rx  r   )r}  rQ   rV  r  r  s        r#   r  'AsyncV1FirecrawlApp.crawl_url_and_watch  sY     L  $33CQQi((T^-C&~d';TBB788	 R   AA;Ar  c                    #    U R                  XU5      I Sh  vN nUR                  S5      (       a  SU;   a  [        US   U 5      $ [        S5      e N:7f)a  
Initiate an async batch scrape job and return an AsyncV1CrawlWatcher to monitor progress.

Args:
    urls (List[str]): List of URLs to scrape
    params (Optional[V1ScrapeParams]): See V1ScrapeParams model for configuration:

      Content Options:
      * formats - Content formats to retrieve
      * includeTags - HTML tags to include
      * excludeTags - HTML tags to exclude
      * onlyMainContent - Extract main content only
      
      Request Options:
      * headers - Custom HTTP headers
      * timeout - Request timeout (ms)
      * mobile - Use mobile user agent
      * proxy - Proxy type
      
      Extraction Options:
      * extract - Content extraction config
      * jsonOptions - JSON extraction config
      * actions - Actions to perform
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests

Returns:
    AsyncV1CrawlWatcher: An instance to monitor the batch scrape job via WebSocket

Raises:
    Exception: If batch scrape job fails to start
Nr   r   r#  )r  r  rx  r   )r}  r  rV  r  batch_responses        r#   r"  /AsyncV1FirecrawlApp.batch_scrape_urls_and_watch  sY     H  $;;D/ZZi((T^-C&~d';TBB>??	 [r{  r~   )ry   re   r  r  r  r  r   r   r   r  r  r  r   r  rV   r  rY   ry   rv   r  r  r  r  r   r   r   r  r  r  r   r   r  rV   r  rY   c                  #    U R                  US5        U R                  5       nUS[         3S.nU(       a  UUS'   U(       a  UUS'   U(       a  UUS'   U(       a  UUS'   Ub  UUS	'   U(       a  UUS
'   U(       a  UUS'   U	(       a  U	R                  SSS9US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   U(       a  UUS'   Ub  UUS'   Ubm  U R	                  U5      n[        U[        5      (       a  SU;   a  U R	                  US   5      US'   [        U[        5      (       a  UOUR                  SSS9US'   Ubm  U R	                  U5      n[        U[        5      (       a  SU;   a  U R	                  US   5      US'   [        U[        5      (       a  UOUR                  SSS9US'   U(       a;  U Vs/ s H*  n[        U[        5      (       a  UOUR                  SSS9PM,     snUS'   SU;   a0  US   (       a&  SUS   ;   a  U R	                  US   S   5      US   S'   SU;   a0  US   (       a&  SUS   ;   a  U R	                  US   S   5      US   S'   SnU R                  U R                   U 3UU5      I Sh  vN nUR                  S5      (       a  SU;   a  [        S0 US   D6$ SU;   a  [        SUS    35      eUR                  S[        U5      5      n[        SU 35      es  snf  Ns7f)a1  
Scrape a single URL asynchronously.

Args:
  url (str): Target URL to scrape
  formats (Optional[List[Literal["markdown", "html", "rawHtml", "content", "links", "screenshot", "screenshot@fullPage", "extract", "json"]]]): Content types to retrieve (markdown/html/etc)
  headers (Optional[Dict[str, str]]): Custom HTTP headers
  include_tags (Optional[List[str]]): HTML tags to include
  exclude_tags (Optional[List[str]]): HTML tags to exclude
  only_main_content (Optional[bool]): Extract main content only
  wait_for (Optional[int]): Wait for a specific element to appear
  timeout (Optional[int]): Request timeout (ms)
  location (Optional[V1LocationConfig]): Location configuration
  mobile (Optional[bool]): Use mobile user agent
  skip_tls_verification (Optional[bool]): Skip TLS verification
  remove_base64_images (Optional[bool]): Remove base64 images
  block_ads (Optional[bool]): Block ads
  proxy (Optional[Literal["basic", "stealth", "auto"]]): Proxy type (basic/stealth)
  extract (Optional[V1JsonConfig]): Content extraction settings
  json_options (Optional[V1JsonConfig]): JSON extraction settings
  actions (Optional[List[Union[V1WaitAction, V1ScreenshotAction, V1ClickAction, V1WriteAction, V1PressAction, V1ScrollAction, V1ScrapeAction, V1ExecuteJavascriptAction, V1PDFAction]]]): Actions to perform
  **kwargs: Additional parameters to pass to the API

Returns:
    V1ScrapeResponse with:
    * success - Whether scrape was successful
    * markdown - Markdown content if requested
    * html - HTML content if requested
    * rawHtml - Raw HTML content if requested
    * links - Extracted links if requested
    * screenshot - Screenshot if requested
    * extract - Extracted data if requested
    * json - JSON data if requested
    * error - Error message if scrape failed

Raises:
    Exception: If scraping fails
r  r  r  ry   re   rz   r{   Nr|   r}   r   Tr  r   r   r   r   r   r   r   ro   rV   r   rY   r  r   r   r   r  r,   )r  r  r  r  r  r  r^  rt  r  r   r   r3   )r}  rQ   ry   re   r  r  r  r  r   r   r   r  r  r  r   r  rV   r  rY   r  r  r  r  r  r  error_contents                             r#   r  AsyncV1FirecrawlApp.scrape_url  s    z 	fl3((* #G9-
 '.M)$'.M)$+7M-(+7M-((/@M+,'/M)$'.M)$(0tRV(WM*%&,M(# ,3HM/0+2FM./ (1M*%%*M'" (1M*%..w7G'4((X-@$($<$<WX=N$O!2<Wd2K2KwQXQ]Q]gkz~Q]QM)$#33LAL,--(l2J)-)A)A,xBX)YX&;ElTX;Y;Y<_k_p_pz~  NR_p  `SM-( MT  (U  MT  CI*VT2J2JPVP[P[eix|P[P}(}  MT  (UM)$%-	*BxS`ajSkGk151I1I-XaJbckJl1mM)$X.M)mM.Jx[hiv[wOw595M5Mm\iNjksNt5uM-(2  11||nXJ'
 
 <<	""v'9#7hv&677 ;HW<M;NOPP %LL#h-@M;M?KLL+ (U
s    F8K9:1K2+BK9K7A4K9r  )ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  r   r  c                  #    U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS	'   U	b  U	R                  S
S
S9US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   Ub$  U Vs/ s H  nUR                  S
S
S9PM     snUS'   Ub  UR                  S
S
S9US'   UR	                  U5        [        S0 UD6nUR                  S
S
S9nUUS'   S[         3US'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   U R                  U5      nU R                  U R                   S3UU5      I Sh  vN nUR                  S5      (       a-   UR                  S5      nU R                  UUU5      I Sh  vN $ U R                  US5        gs  snf  N_!   [        S5      e= f N.7f) a  
Asynchronously scrape multiple URLs and monitor until completion.

Args:
    urls (List[str]): URLs to scrape
    formats (Optional[List[Literal]]): Content formats to retrieve
    headers (Optional[Dict[str, str]]): Custom HTTP headers
    include_tags (Optional[List[str]]): HTML tags to include
    exclude_tags (Optional[List[str]]): HTML tags to exclude
    only_main_content (Optional[bool]): Extract main content only
    wait_for (Optional[int]): Wait time in milliseconds
    timeout (Optional[int]): Request timeout in milliseconds
    location (Optional[LocationConfig]): Location configuration
    mobile (Optional[bool]): Use mobile user agent
    skip_tls_verification (Optional[bool]): Skip TLS verification
    remove_base64_images (Optional[bool]): Remove base64 encoded images
    block_ads (Optional[bool]): Block advertisements
    proxy (Optional[Literal]): Proxy type to use
    extract (Optional[JsonConfig]): Content extraction config
    json_options (Optional[JsonConfig]): JSON extraction config
    actions (Optional[List[Union]]): Actions to perform
    agent (Optional[AgentOptions]): Agent configuration
    poll_interval (Optional[int]): Seconds between status checks (default: 2)
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1BatchScrapeStatusResponse with:
    * Scraping status and progress
    * Scraped content for each URL
    * Success/error information

Raises:
    Exception: If batch scrape fails
r  Nry   re   rz   r{   r|   r}   r   Tr  r   r   r   r   r   r   ro   rV   r   rY   r   r  r  r  r  r   r   r  r  r,   )r  r  r  r  r  r   r  r  r^  rt  r  r   _async_monitor_job_statusr  )r}  r  ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  r  r  r  r  r  r   s                               r#   r  %AsyncV1FirecrawlApp.batch_scrape_urls  s    z 	f&9: '.M)$'.M)$#+7M-(#+7M-((/@M+,'/M)$'.M)$(0tRV(WM*%&,M(# ,3HM/0+2FM./ (1M*%%*M'"..w7G'4((X-@$($<$<WX=N$O!2<Wd2K2KwQXQ]Q]gkz~Q]QM)$#33LAL,--(l2J)-)A)A,xBX)YX&;ElTX;Y;Y<_k_p_pz~  NR_p  `SM-(dk'ldkZ`TPT(Udk'lM)$%*ZZDZ%QM'" 	V$ &66"''D'I"F"-gY 7H#I(>8{[dOeCe/3/G/GT]H^_gHh/iK	"8,K'K,F8WbcpWqKq373K3KKXeLfgoLp3qK&x0 ''811||n,-
 
 <<	""P\\$' 77G]SSSx)ABC (m(
P"MOOSsC   E2K;4K"C9K;K'K;#K) 4K;
K9K;)K66K;)ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  c                (  #    U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS	'   U	b  U	R                  S
S
S9US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   Ubm  U R                  U5      n[        U[        5      (       a  SU;   a  U R                  US   5      US'   [        U[        5      (       a  UOUR                  S
S
S9US'   U(       a;  U Vs/ s H*  n[        U[        5      (       a  UOUR                  S
S
S9PM,     snUS'   Ub  UR                  S
S
S9US'   Ub  UUS'   UR	                  U5        [        S 0 UD6nUR                  S
S
S9nUUS'   S[         3US'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   SU;   a0  US   (       a&  SUS   ;   a  U R                  US   S   5      US   S'   U R                  U5      nU R                  U R                   S3UU5      I Sh  vN nUR                  S5      S:X  a   [        S 0 UR                  5       D6$ U R                  US5      I Sh  vN   gs  snf  NS!   [        S5      e= f N7f)!a,  
Initiate a batch scrape job asynchronously.

Args:
    urls (List[str]): URLs to scrape
    formats (Optional[List[Literal]]): Content formats to retrieve
    headers (Optional[Dict[str, str]]): Custom HTTP headers
    include_tags (Optional[List[str]]): HTML tags to include
    exclude_tags (Optional[List[str]]): HTML tags to exclude
    only_main_content (Optional[bool]): Extract main content only
    wait_for (Optional[int]): Wait time in milliseconds
    timeout (Optional[int]): Request timeout in milliseconds
    location (Optional[LocationConfig]): Location configuration
    mobile (Optional[bool]): Use mobile user agent
    skip_tls_verification (Optional[bool]): Skip TLS verification
    remove_base64_images (Optional[bool]): Remove base64 encoded images
    block_ads (Optional[bool]): Block advertisements
    proxy (Optional[Literal]): Proxy type to use
    extract (Optional[JsonConfig]): Content extraction config
    json_options (Optional[JsonConfig]): JSON extraction config
    actions (Optional[List[Union]]): Actions to perform
    agent (Optional[AgentOptions]): Agent configuration
    zero_data_retention (Optional[bool]): Whether to delete data after 24 hours
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1BatchScrapeResponse with:
    * success - Whether job started successfully
    * id - Unique identifier for the job
    * url - Status check URL
    * error - Error message if start failed

Raises:
    Exception: If job initiation fails
r  Nry   re   rz   r{   r|   r}   r   Tr  r   r   r   r   r   r   ro   rV   r   rY   r   r  r  r  r  r  r  r  r  r  r,   )r  r  r  r  r  r   r  r  r^  rt  r  r   rH   r   r  )r}  r  ry   re   r  r  r  r  r   r   r   r  r  r  r   rV   r  rY   r   r  r  r  r  r  r  r  r  s                              r#   r  +AsyncV1FirecrawlApp.async_batch_scrape_urls.  s    | 	f&?@ '.M)$'.M)$#+7M-(#+7M-((/@M+,'/M)$'.M)$(0tRV(WM*%&,M(# ,3HM/0+2FM./ (1M*%%*M'"..w7G'4((X-@$($<$<WX=N$O!2<Wd2K2KwQXQ]Q]gkz~Q]QM)$#33LAL,--(l2J)-)A)A,xBX)YX&;ElTX;Y;Y<_k_p_pz~  NR_p  `SM-( MT  (U  MT  CI*VT2J2JPVP[P[eix|P[P}(}  MT  (UM)$%*ZZDZ%QM'"*1DM-. 	V$ &66"''D'I"F"-gY 7H#I(>8{[dOeCe/3/G/GT]H^_gHh/iK	"8,K'K,F8WbcpWqKq373K3KKXeLfgoLp3qK&x0 ''811||n,-
 
 <<&#-P,?x}}?? $$X/GHHHE (U,
P"MOOHsC   E6L81K9)DL*K>+LL  L3L4L LL)r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  c                $  #    U R                  US5        0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   OUb  UUS	'   U	b  U	US
'   U
b  U
US'   Ub  UR                  SSS9US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   UR                  U5        [        S0 UD6nUR                  SSS9nUUS'   S[         3US'   U R                  U5      nU R                  U R                   S3UU5      I Sh  vN nUR                  S5      (       a-   UR                  S5      nU R                  UUU5      I Sh  vN $ U R                  US5      I Sh  vN   g Nb!   [        S5      e= f N1 N7f)a   
Crawl a website starting from a URL.

Args:
    url (str): Target URL to start crawling from
    include_paths (Optional[List[str]]): Patterns of URLs to include
    exclude_paths (Optional[List[str]]): Patterns of URLs to exclude
    max_depth (Optional[int]): Maximum crawl depth
    max_discovery_depth (Optional[int]): Maximum depth for finding new URLs
    limit (Optional[int]): Maximum pages to crawl
    allow_backward_links (Optional[bool]): DEPRECATED: Use crawl_entire_domain instead
    crawl_entire_domain (Optional[bool]): Follow parent directory links
    allow_external_links (Optional[bool]): Follow external domain links
    ignore_sitemap (Optional[bool]): Skip sitemap.xml processing
    scrape_options (Optional[V1ScrapeOptions]): Page scraping configuration
    webhook (Optional[Union[str, V1WebhookConfig]]): Notification webhook settings
    deduplicate_similar_urls (Optional[bool]): Remove similar URLs
    ignore_query_parameters (Optional[bool]): Ignore URL parameters
    regex_on_full_url (Optional[bool]): Apply regex to full URLs
    delay (Optional[int]): Delay in seconds between scrapes
    allow_subdomains (Optional[bool]): Follow subdomains
    poll_interval (Optional[int]): Seconds between status checks (default: 2)
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1CrawlStatusResponse with:
    * Crawling status and progress
    * Crawled page contents
    * Success/error information

Raises:
    Exception: If crawl fails
r  Nr   r   r   r   r   r   r   r   r   Tr  r   r   r  r  r  r  r  rQ   r  r  r  r   r   r  r  r,   )r  r  r  r   r  r  r^  rt  r  r   r  r  )r}  rQ   r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  r  r  r  re   r  r   s                              r#   r  AsyncV1FirecrawlApp.crawl_url  s3    v 	fk2 $+8L($+8L( '0L$*0CL,-$)L!*0CL,-!-1EL-.+1EL-.%,:L)%,:,?,?\`,?,aL)&-L##/5ML12".4KL01(->L)*$)L!'.>L*+ 	F# %4|4"''D'I E"-gY 7H''811\\N)
$k7< < <<	""P\\$' 77G]SSS$$X/@AAA<P"MOOSAsH   DFE:F3E< FFF4F5F<F		FFc                  #    0 nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   OUb  UUS'   U	b  U	US	'   U
b  U
US
'   Ub  UR                  SSS9US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   UR                  U5        [        S0 UD6nUR                  SSS9nUUS'   S[         3US'   U R	                  U5      nU R                  U R                   S3UU5      I Sh  vN nUR                  S5      (       a   [        S0 UD6$ U R                  US5      I Sh  vN   g NA!   [        S5      e= f N7f)a  
Start an asynchronous crawl job.

Args:
    url (str): Target URL to start crawling from
    include_paths (Optional[List[str]]): Patterns of URLs to include
    exclude_paths (Optional[List[str]]): Patterns of URLs to exclude
    max_depth (Optional[int]): Maximum crawl depth
    max_discovery_depth (Optional[int]): Maximum depth for finding new URLs
    limit (Optional[int]): Maximum pages to crawl
    allow_backward_links (Optional[bool]): DEPRECATED: Use crawl_entire_domain instead
    crawl_entire_domain (Optional[bool]): Follow parent directory links
    allow_external_links (Optional[bool]): Follow external domain links
    ignore_sitemap (Optional[bool]): Skip sitemap.xml processing
    scrape_options (Optional[ScrapeOptions]): Page scraping configuration
    webhook (Optional[Union[str, WebhookConfig]]): Notification webhook settings
    deduplicate_similar_urls (Optional[bool]): Remove similar URLs
    ignore_query_parameters (Optional[bool]): Ignore URL parameters
    regex_on_full_url (Optional[bool]): Apply regex to full URLs
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests
    **kwargs: Additional parameters to pass to the API

Returns:
    V1CrawlResponse with:
    * success - Whether crawl started successfully
    * id - Unique identifier for the crawl job
    * url - Status check URL for the crawl
    * error - Error message if start failed

Raises:
    Exception: If crawl initiation fails
Nr   r   r   r   r   r   r   r   r   Tr  r   r   r  r  r  r  r  rQ   r  r  r  r   r  r  r,   )r  r  r   r  r  r^  rt  r  r  r   r  )r}  rQ   r  r  r  r  r   r  r  rn  r  r  r   r  r  r  r  r  r  r  r  r  r  r  re   r  s                             r#   r  #AsyncV1FirecrawlApp.async_crawl_url2  s    p  $+8L($+8L( '0L$*0CL,-$)L!*0CL,-!-1EL-.+1EL-.%,:L)%,:,?,?\`,?,aL)&-L##/5ML12".4KL01(->L)*$)L!'.>L*+ 	F# %4|4"''D'I E"-gY 7H ''811\\N)
$


 
 <<	""P&222 $$X/@AAA
P"MOOAs6   DEEE!
E	 +EEE	EEr   c           
      B  #    U R                  5       nSU 3nU R                  U R                   U 3U5      I Sh  vN nUR                  S5      S:X  a  SU;   a  US   nSU;   a  [	        US   5      S:X  a  OrUR                  S5      nU(       d  [
        R                  S5        ODU R                  Xb5      I Sh  vN nUR                  UR                  S/ 5      5        UnSU;   a  M  XTS'   [        UR                  S5      UR                  S	5      UR                  S5      UR                  S
5      UR                  S5      UR                  S5      SU;   a  SOSS9nSU;   a  UR                  S5      Ul	        SU;   a  UR                  S5      Ul
        U$  GN_ N7f)a  
Check the status and results of an asynchronous crawl job.

Args:
    id (str): Unique identifier for the crawl job

Returns:
    V1CrawlStatusResponse containing:
    Status Information:
    * status - Current state (scraping/completed/failed/cancelled)
    * completed - Number of pages crawled
    * total - Total pages to crawl
    * creditsUsed - API credits consumed
    * expiresAt - Data expiration timestamp
    
    Results:
    * data - List of crawled documents
    * next - URL for next page of results (if paginated)
    * success - Whether status check succeeded
    * error - Error message if failed

Raises:
    Exception: If status check fails
r  Nr   rf   r   r   r   r  r   r   r   r   FT)r   r   rf   r   r   r   r   )r  rc  rt  r  r  r   r   r  r
  r   r   	r}  r   re   r  r  r   r  r  r  s	            r#   r  &AsyncV1FirecrawlApp.check_crawl_status  s    2 '')t$ 33||nXJ'
 

 ??8$3$"6*+;v./14*v6H#'HI&*&=&=h&P PIKK	fb 9:"+K + '+F#(??8,//'*!ook2#6!ook2($3E
 k!(__W5HN[ 'OOF3HMI
 !Qs)   9FFA?F;F<-F+B0FFc                   #     U R                  U R                   SU 3U5      I Sh  vN nUR                  S5      S:X  a  SU;   a  US   nSU;   a  [        US   5      S:X  a  OrUR                  S5      nU(       d  [        R                  S5        ODU R                  Xb5      I Sh  vN nUR                  UR                  S/ 5      5        UnSU;   a  M  XTS'   [        S0 UD6$ [        S	5      eUR                  S5      S
;   a)  [        R                  " [        US5      5      I Sh  vN   O[        SUS    35      eGM@   GN N N7f)a  
Monitor the status of an asynchronous job until completion.

Args:
    id (str): The ID of the job to monitor
    headers (Dict[str, str]): Headers to include in status check requests
    poll_interval (int): Seconds between status checks (default: 2)

Returns:
    V1CrawlStatusResponse: The job results if completed successfully

Raises:
    Exception: If the job fails or an error occurs during status checks
r  Nr   rf   r   r   r   r  z&Job completed but no data was returnedru  r  z#Job failed or was stopped. Status: r,   )rc  rt  r  r  r   r   r  r
  r   rV  r@  r{  )r}  r   re   r  r  r   r  r  s           r#   r  -AsyncV1FirecrawlApp._async_monitor_job_status  sN      $ 7 7<<.
2$/! K
 x(K7[(&v.D K/{623q8!#.??6#:'"NN+LM!*.*A*A(*T$T	IMM&"$=>&/ !K/ +/'0?;??#$LMM*.nnmmCq$9:::"EkRZF[E\ ]^^5  %U ;s;   &EEA?E(E)-EAE*E	+EE	E)r   r  r  r  r   r   r   rV  r   r  r  c                <  #    0 n
U	(       a  U
R                  U	R                  SSS95        Ub  X*S'   Ub  X:S'   Ub  XJS'   Ub  XZS'   Ub  XjS'   Ub  XzS	'   Ub  UR                  SSS9U
S
'   [        S0 U
D6nUR                  SSS9nXS'   S[         3US'   SnU R	                  U R
                   U 3USSU R                   30S9I Sh  vN nUR                  S5      (       a  SU;   a  [        S0 UD6$ SU;   a  [        SUS    35      e[        SU 35      e NP7f)a  
Asynchronously map and discover links from a URL.

Args:
  url (str): Target URL to map
  params (Optional[V1MapParams]): See V1MapParams model:
    Discovery Options:
    * search - Filter pattern for URLs
    * ignoreSitemap - Skip sitemap.xml
    * includeSubdomains - Include subdomain links
    * sitemapOnly - Only use sitemap.xml
    
    Limits:
    * limit - Max URLs to return
    * timeout - Request timeout (ms)

Returns:
  V1MapResponse with:
  * Discovered URLs
  * Success/error status

Raises:
  Exception: If mapping fails
Tr  Nr   r   r  r  r   r   r   rQ   r  r  r  r  r  rn  r   rU   r   zFailed to map URL. Error: r,   )
r  r  r  r  r^  rt  rs  r  r  r   )r}  rQ   r   r  r  r  r   r   r   rV  r  r  r  r  r  s                  r#   r  AsyncV1FirecrawlApp.map_url  s    H 
fkk4dkKL #)x %*8').@*+#(4}%"'w$+y!%-]]Dt]%TJz" #0Z0"''D'I E"-gY 7H 11||nXJ'$~&>? 2 
 
 <<	""w(': ,8,, 8'9J8KLMM8
CDD
s   CD	D
ADFr,  r+   ro   rm  ro  rp  c                p  #    SSK n	U	R                  S[        SS9  U R                  5       n
U(       d  U(       d  [	        S5      eU(       d  U(       d  [	        S5      eU(       a  U R                  U5      nU=(       d    / UUUUS[        5        3S	.nU(       a  X+S
'   U(       a  XKS'   U(       a  XS'   U R                  U R                   S3UU
5      I Sh  vN nUR                  S5      (       a  UR                  S5      nU(       d  [        S5      e U R                  U R                   SU 3U
5      I Sh  vN nUS   S:X  a  [        S0 UD6$ US   S;   a  [        SUS    SUS    35      e[        R                  " S5      I Sh  vN   M}  [        SUR                  S5       35      e N Nw N'7f)a  
Asynchronously extract structured information from URLs.

.. deprecated::
    The extract endpoint is in maintenance mode and its use is discouraged.
    Review https://docs.firecrawl.dev/developer-guides/usage-guides/choosing-the-data-extractor
    to find a replacement.

Args:
    urls (Optional[List[str]]): URLs to extract from
    prompt (Optional[str]): Custom extraction prompt
    schema (Optional[Any]): JSON schema/Pydantic model
    system_prompt (Optional[str]): System context
    allow_external_links (Optional[bool]): Follow external links
    enable_web_search (Optional[bool]): Enable web search
    show_sources (Optional[bool]): Include source URLs
    agent (Optional[Dict[str, Any]]): Agent configuration

Returns:
  V1ExtractResponse with:
  * Structured data matching schema
  * Source information if requested
  * Success/error status

Raises:
  ValueError: If prompt/schema missing or extraction fails
r   Nr.  r  r/  r1  r2  r  r3  r+   r   r   r4  r   r   r5  r6  r   rf   r7  r8  r9  r   r:  r,   )r#  r=  r>  r  r{  r  r$   r^  rt  r  r   rc  r   rV  r@  )r}  r  r+   ro   rm  rn  ro  rp  r   r#  re   rA  r  rB  r  s                  r#   rV   AsyncV1FirecrawlApp.extracta  s    N 	%  	 	
 '')fBCCF@AA--f5F JB"60'#KM?3
 %+"+8($)!11||nK(
 
 <<	""\\$'F KLL$($;$;||nL9% 
 x(K7,;{;; *.EE#l;x3H2IS^_fSgRh$ijjmmA&&&  8g9N8OPQQ1
 's8   CF6F0A"F6:F2;AF6F4$F62F64F6c           
        #    U R                  5       nSU 3nU R                  U R                   U 3U5      I Sh  vN nUS   S:X  a  SU;   a  US   nSU;   a  [        US   5      S:X  a  OrUR	                  S5      nU(       d  [
        R                  S5        ODU R                  Xb5      I Sh  vN nUR                  UR	                  S/ 5      5        UnSU;   a  M  XTS'   [        UR	                  S5      UR	                  S	5      UR	                  S5      UR	                  S
5      UR	                  S5      UR	                  S5      S9nSU;   a  US   US'   SU;   a  US   US'   SSU;   a  S0UE$ S0UE$  GN= N7f)a  
Check the status of an asynchronous batch scrape job.

Args:
    id (str): The ID of the batch scrape job

Returns:
    V1BatchScrapeStatusResponse containing:
    Status Information:
    * status - Current state (scraping/completed/failed/cancelled)
    * completed - Number of URLs scraped
    * total - Total URLs to scrape
    * creditsUsed - API credits consumed
    * expiresAt - Data expiration timestamp
    
    Results:
    * data - List of scraped documents
    * next - URL for next page of results (if paginated)
    * success - Whether status check succeeded
    * error - Error message if failed

Raises:
    Exception: If status check fails
r&  Nr   rf   r   r   r   r  r   r   r   r  r   r   FT)	r  rc  rt  r  r  r   r   r  r   r  s	            r#   r'  -AsyncV1FirecrawlApp.check_batch_scrape_status  s    2 '')&rd+ 33||nXJ'
 

 x K/$"6*+;v./14*v6H#'HI&*&=&=h&P PIKK	fb 9:"+K + '+F#.??8,//'*!ook2#6!ook2(
 k! +G 4HW[ *62HV ; 6u

 	
<@

 	
G
 !Qs)   9E=E8A3E=/E;0-E=BE=;E=c                    #    U R                  5       nU R                  U R                   SU S3U5      I Sh  vN $  N7f)a  
Get information about errors from an asynchronous batch scrape job.

Args:
  id (str): The ID of the batch scrape job

Returns:
  V1CrawlErrorsResponse containing:
    errors (List[Dict[str, str]]): List of errors with fields:
      * id (str): Error ID
      * timestamp (str): When the error occurred
      * url (str): URL that caused the error
      * error (str): Error message
  * robotsBlocked (List[str]): List of URLs blocked by robots.txt

Raises:
  Exception: If error check fails
r&  r  Nr  rc  rt  r}  r   re   s      r#   r*  -AsyncV1FirecrawlApp.check_batch_scrape_errors  sJ     & ''),,||n-bT9
 
 	
 
   6?=?c                    #    U R                  5       nU R                  U R                   SU S3U5      I Sh  vN $  N7f)a  
Get information about errors from an asynchronous crawl job.

Args:
    id (str): The ID of the crawl job

Returns:
    V1CrawlErrorsResponse containing:
    * errors (List[Dict[str, str]]): List of errors with fields:
        - id (str): Error ID
        - timestamp (str): When the error occurred
        - url (str): URL that caused the error
        - error (str): Error message
    * robotsBlocked (List[str]): List of URLs blocked by robots.txt

Raises:
    Exception: If error check fails
r  r  Nr  r  s      r#   r   &AsyncV1FirecrawlApp.check_crawl_errors$  sI     & ''),,||nJrd'2
 
 	
 
r  c                   #    U R                  5       n[        R                  " 5        ISh  vN nUR                  U R                   SU 3US9 ISh  vN nUR                  5       I Sh  vN sSSS5      ISh  vN   sSSS5      ISh  vN   $  Nf N@ N* N N! , ISh  vN  (       d  f       O= fSSS5      ISh  vN    g! , ISh  vN  (       d  f       g= f7f)r  Nr  rn  )r  rS  rT  rr  rt  rH   )r}  r   re   rX  r  s        r#   r   AsyncV1FirecrawlApp.cancel_crawl=  s      '')((**g~~j&Ew~WW[c%]]_, XWW +**W, X +WWW +*****s   *C#BC#$C	BC	B,B-B0C	<B=C	C#BC#C	BC	C#B4	#B&$B4	0C	7C#CC#	C CC C#rB  c                    #    SSK nUR                  S[        SS9  U R                  5       n U R	                  U R
                   SU 3U5      I Sh  vN $  N! [         a  n[        [        U5      5      eSnAff = f7f)a  
Check the status of an asynchronous extraction job.

.. deprecated::
    The extract endpoint is in maintenance mode and its use is discouraged.
    Review https://docs.firecrawl.dev/developer-guides/usage-guides/choosing-the-data-extractor
    to find a replacement.

Args:
    job_id (str): The ID of the extraction job

Returns:
    V1ExtractResponse[Any] with:
    * success (bool): Whether request succeeded
    * data (Optional[Any]): Extracted data matching schema
    * error (Optional[str]): Error message if any
    * warning (Optional[str]): Warning message if any
    * sources (Optional[List[str]]): Source URLs if requested

Raises:
    ValueError: If status check fails
r   Nr.  r  r/  r6  	r#  r=  r>  r  rc  rt  r   r{  r3   )r}  rB  r#  re   r  s        r#   rE  &AsyncV1FirecrawlApp.get_extract_statusQ  s     . 	%  	 	
 '')	%00<<.VH5     	%SV$$	%:   *A>$A AA A>A 
A;"A66A;;A>c          	        #    SSK n	U	R                  S[        SS9  U R                  5       n
U(       d  U(       d  [	        S5      eU(       d  U(       d  [	        S5      eU(       a  U R                  U5      n[        U=(       d    / UUUUS[         3S	9nU(       a  X+S
'   U(       a  XKS'   U(       a  XS'    U R                  U R                   S3UU
5      I Sh  vN $  N! [         a  n[	        [        U5      5      eSnAff = f7f)a.  
Initiate an asynchronous extraction job without waiting for completion.

.. deprecated::
    The extract endpoint is in maintenance mode and its use is discouraged.
    Review https://docs.firecrawl.dev/developer-guides/usage-guides/choosing-the-data-extractor
    to find a replacement.

Args:
    urls (Optional[List[str]]): URLs to extract from
    prompt (Optional[str]): Custom extraction prompt
    schema (Optional[Any]): JSON schema/Pydantic model
    system_prompt (Optional[str]): System context
    allow_external_links (Optional[bool]): Follow external links
    enable_web_search (Optional[bool]): Enable web search
    show_sources (Optional[bool]): Include source URLs
    agent (Optional[Dict[str, Any]]): Agent configuration
    idempotency_key (Optional[str]): Unique key to prevent duplicate requests

Returns:
    V1ExtractResponse[Any] with:
    * success (bool): Whether request succeeded
    * data (Optional[Any]): Extracted data matching schema
    * error (Optional[str]): Error message if any

Raises:
    ValueError: If job initiation fails
r   Nr.  r  r/  r1  r2  r  r3  r+   r   r   r4  )r#  r=  r>  r  r{  r  r   r  r^  rt  r   r3   )r}  r  r+   ro   rm  rn  ro  rp  r   r#  re   rA  r  s                r#   rH  !AsyncV1FirecrawlApp.async_extracty  s    N 	%  	 	
 '')fBCCF@AA--f5F(3-$ 	*
 %+"+8($)!	%11<<.,   
  	%SV$$	%s<   B3D6#C  CC  DC   
D*C>>DDrK  rL  rM  rK  rL  rM  c                  #    SSK nUR                  S[        SS9  0 nUb  X&S'   Ub  X6S'   Ub  XFS'   U R                  UUUUS	9I Sh  vN nUR	                  S
5      (       a  SU;  a  U$ US   n U R                  U5      I Sh  vN n	U	S   S:X  a  U	$ U	S   S:X  a  [        SU	R	                  S5       35      eU	S   S:w  a  O [        R                  " S5      I Sh  vN   Mt  [        SSSSS9$  N Nm N7f)a  
Generate LLMs.txt for a given URL and monitor until completion.

.. deprecated::
    /v1/llmstxt is deprecated and will not be replaced.

Args:
    url (str): Target URL to generate LLMs.txt from
    max_urls (Optional[int]): Maximum URLs to process (default: 10)
    show_full_text (Optional[bool]): Include full text in output (default: False)
    experimental_stream (Optional[bool]): Enable experimental streaming

Returns:
    V1GenerateLLMsTextStatusResponse containing:
    * success (bool): Whether generation completed successfully
    * status (str): Status of generation (processing/completed/failed)
    * data (Dict[str, str], optional): Generated text with fields:
        - llmstxt (str): Generated LLMs.txt content
        - llmsfulltxt (str, optional): Full version if requested
    * error (str, optional): Error message if generation failed
    * expiresAt (str): When the generated data expires

Raises:
    Exception: If generation fails
r   NrO  r  r/  rQ  rR  rQ  r  r   r   r   rf   rg   z#LLMs.txt generation failed. Error: r   r"  FrS  r  rR  )
r#  r=  r>  rT  r  rU  r   rV  r@  rj  )
r}  rQ   rK  rL  rM  r#  rV  r  rB  r   s
             r#   rW  &AsyncV1FirecrawlApp.generate_llms_text  sQ    @ 	A 	 	

  (9%%3>"*.A*+66) 3	 7 
 
 ||I&&$h*>O$??GGFh;.!X-"EfjjQXFYEZ [\\!\1--"""  0Ev  @H  TV  W  	W-
 H #s7   AC7C1	<C7C3AC7C5C73C75C7rJ  rS  c                  #    SSK nUR                  S[        SS9  0 nUb  X'S'   Ub  X7S'   Ub  XWS'   [        UUUUS	9nU R	                  5       nS
U0UR                  SSS9En	S[         3U	S'    U R                  U R                   S3U	U5      I Sh  vN $  N! [         a  n
[        [        U
5      5      eSn
A
ff = f7f)a  
Initiate an asynchronous LLMs.txt generation job without waiting for completion.

.. deprecated::
    /v1/llmstxt is deprecated and will not be replaced.

Args:
    url (str): Target URL to generate LLMs.txt from
    max_urls (Optional[int]): Maximum URLs to process (default: 10)
    show_full_text (Optional[bool]): Include full text in output (default: False)
    cache (Optional[bool]): Whether to use cached content if available (default: True)
    experimental_stream (Optional[bool]): Enable experimental streaming

Returns:
    V1GenerateLLMsTextResponse containing:
    * success (bool): Whether job started successfully
    * id (str): Unique identifier for the job
    * error (str, optional): Error message if start failed

Raises:
    ValueError: If job initiation fails
r   NrO  r  r/  rQ  rR  rQ  rP  rQ   Tr  r  r  rZ  )r#  r=  r>  rO  r  r  r  r^  rt  r   r{  r3   )r}  rQ   rK  rL  rS  rM  r#  rV  re   r[  r  s              r#   rT  ,AsyncV1FirecrawlApp.async_generate_llms_text  s     < 	A 	 	

  (9%%3>"*.A*+)'"5	
 '')CQ6;;4;#PQ	 +G95	(	%11<<.,   
  	%SV$$	%s<   A-C 0#B BB C B 
B=$B88B==C c                    #    SSK nUR                  S[        SS9  U R                  5       n U R	                  U R
                   SU 3U5      I Sh  vN $  N! [         a  n[        [        U5      5      eSnAff = f7f)a  
Check the status of an asynchronous LLMs.txt generation job.

.. deprecated::
    /v1/llmstxt is deprecated and will not be replaced.

Args:
    id (str): The ID of the generation job

Returns:
    V1GenerateLLMsTextStatusResponse containing:
    * success (bool): Whether generation completed successfully
    * status (str): Status of generation (processing/completed/failed)
    * data (Dict[str, str], optional): Generated text with fields:
        - llmstxt (str): Generated LLMs.txt content
        - llmsfulltxt (str, optional): Full version if requested
    * error (str, optional): Error message if generation failed
    * expiresAt (str): When the generated data expires

Raises:
    ValueError: If status check fails
r   NrO  r  r/  r`  r  r}  r   r#  re   r  s        r#   rU  3AsyncV1FirecrawlApp.check_generate_llms_text_statusR  s     . 	A 	 	

 '')	%00<<.RD1     	%SV$$	%r  )r  r  rK  r  rm  /_AsyncV1FirecrawlApp__experimental_stream_stepsr  r  r(  r  r  r  r  r  c          	        #    SSK n
U
R                  S[        SS9  0 nUb  X+S'   Ub  X;S'   Ub  XKS'   Ub  X[S	'   Ub  XkS
'   Ub  X{S'   [        S0 UD6nU R	                  UUUUUUS9I Sh  vN nUR                  S5      (       a  SU;  a  U$ US   nSnSn U R                  U5      I Sh  vN nU(       a-  SU;   a'  US   US nU H  nU" U5        M     [        US   5      nU	(       a-  SU;   a'  US   US nU H  nU	" U5        M     [        US   5      nUS   S:X  a  U$ US   S:X  a  [        SUR                  S5       35      eUS   S:w  a  O [        R                  " S5      I Sh  vN   M  [        SSS9$  GN N N7fr  )r#  r=  r>  rV  r  r  r  r  r   rV  r@  r_  )r}  r(  r  r  rK  r  rm  r  r  r  r#  r  r  rB  r  r  r   r  r  r  r  s                        r#   r  !AsyncV1FirecrawlApp.deep_researchx  s    V 	F 	 	

  *3J'!+5K()1I&&0?,-$.;N+&2<W89.AA11!+' 2 
 
 ||I&&$h*>O$::6BBF|v5!'!56I6J!K .H) !/&)&*>&?#Y&0$Y/0A0BC)Ff% *$'y(9$:!h;.!X-"?

7@S?T UVV!\1--"""- 0 ,EAlmmO
  C* #s8   A(F*E=+A F+F ,C F,F-F FF)r  r  rK  r  rm  r  c                  #    SSK nUR                  S[        SS9  0 n	Ub  X)S'   Ub  X9S'   Ub  XIS'   Ub  XYS	'   Ub  XiS
'   Ub  XyS'   [        S0 U	D6n	U R	                  5       n
SU0U	R                  SSS9EnS[         3US'    U R                  U R                   S3UU
5      I Sh  vN $  N! [         a  n[        [        U5      5      eSnAff = f7f)r  r   Nr  r  r/  r   rX  rQ  rZ  r   r  r(  Tr  r  r  r  r,   )r#  r=  r>  rV  r  r  r  r^  rt  r   r{  r3   )r}  r(  r  r  rK  r  rm  r  r#  r  re   r[  r  s                r#   r  'AsyncV1FirecrawlApp.async_deep_research  s%    D 	F 	 	

  *3J'!+5K()1I&&0?,-$.;N+&2<W89.AA'')e^';';TX\';']^	 +G95	(	%11<<. 12   
  	%SV$$	%s<   BC#B. 'B,(B. +C,B. .
C8CCCc                    #    SSK nUR                  S[        SS9  U R                  5       n U R	                  U R
                   SU 3U5      I Sh  vN $  N! [         a  n[        [        U5      5      eSnAff = f7f)r  r   Nr  r  r/  r  r  r  s        r#   r  .AsyncV1FirecrawlApp.check_deep_research_status&  s     8 	F 	 	

 '')	%00<<. 22$7     	%SV$$	%r  )	r   r*  r+  r-  r`   r   r   r  rV  r*  r+  r-  r`   c       	           #    0 nU
(       aF  [        U
[        5      (       a  UR                  U
5        OUR                  U
R                  SSS95        Ub  X,S'   Ub  X<S'   Ub  XLS'   Ub  X\S'   Ub  XlS'   Ub  X|S	'   Ub  XS
'   U	b  U	R                  SSS9US'   UR                  U5        [        SSU0UD6nUR                  SSS9nS[         3US'   U R                  U R                   S3USSU R                   305      I Sh  vN $  N7f)a  
Asynchronously search for content using Firecrawl.

Args:
    query (str): Search query string
    limit (Optional[int]): Max results (default: 5)
    tbs (Optional[str]): Time filter (e.g. "qdr:d")
    filter (Optional[str]): Custom result filter
    lang (Optional[str]): Language code (default: "en")
    country (Optional[str]): Country code (default: "us") 
    location (Optional[str]): Geo-targeting
    timeout (Optional[int]): Request timeout in milliseconds
    scrape_options (Optional[ScrapeOptions]): Result scraping configuration
    params (Optional[Union[Dict[str, Any], SearchParams]]): Additional search parameters
    **kwargs: Additional keyword arguments for future compatibility

Returns:
    SearchResponse: Response containing:
        * success (bool): Whether request succeeded
        * data (List[FirecrawlDocument]): Search results
        * warning (Optional[str]): Warning message if any
        * error (Optional[str]): Error message if any

Raises:
    Exception: If search fails or response cannot be parsed
Tr  Nr   r*  r+  r-  r`   r   r   r   r(  r  r  r  r  r  r,   )r  r  r  r'  r  r^  rt  rs  )r}  r(  r   r*  r+  r-  r`   r   r   r  rV  r  r  r  r  s                  r#   r   AsyncV1FirecrawlApp.searchQ  sU    R &$''$$V,$$V[[$T[%RS %*'"?#&% &,(#$(&!'.)$(0*%'.)$%-;-@-@$]a-@-bM/* 	V$ &CEC]C"''D'I"-gY 7H--||nJ'~67
 
 	
 
s   DDD
Dr,   )ry  )Nr  r  r  r  )r  r  )Tr-   r.   r/   r0   r1   r3   r~  r   r   r   r   r   rY  r^  rc  rS  ClientResponser  rg  r9  r  r?  r  r   r  r   r   r"  r	   r   r^   r   r   r   r   r   r   r   r   r   r   r   r   r  r'   r   r  r   r  rs   rc   r
  r  r  r  r  r  r  r  r  r   rV   r'  r  r*  r   r  rE  rH  rj  rW  rd  rT  rU  r   r_  r  r  r  r'  r1  r   r4   __classcell__rO  s   @r#   rK  rK  '  so   
; ;c ; ; .2$'+4+4 +4 #s(^	+4
 4S>*+4 +4 "+4 -1cN+4^ 7:^^"&sCx.^;?S>^^.3^>B38n^2 7:]]%)#s(^]].3]>B38n],+G,B,B +C +TX +6Z# Zs Z[^ Zor Zwz Z-(= -,'; , /3-1	*9*9 ]+*9 &c]	*9 7L	*9^ 04-1	(@s)(@ ^,(@ &c]	(@ 7L	(@\ mq04040404&*%*37%)4837(,OS(,.237 EI)DMDM d7  ,g  $h  i  j	DM
 d38n-DM #49-DM #49-DM  (~DM smDM c]DM /0DM TNDM $,D>DM #+4.DM  ~DM  G$JKL!DM"  ~#DM$ l+%DM& #<0'DM( d57I=Zgiv  yG  IW  Yr  t  *  $@  A  B)DM* *#.+DMT W[,0,0,0,0"&!&/3!%04/3$(KO*./3 AE*.'()--HC3iHC $w  (Q   R  S  T	HC
 $sCx.)HC tCy)HC tCy)HC $D>HC 3-HC #HC +,HC HC  (~HC 'tnHC D>HC   FGH!HC" ,'#HC$ |,%HC& $u\3E}Vcer  uC  ES  Un  p{  &{   |  }  ~'HC( ')HC*  }+HC, "#-HC0 
%1HC^ W[,0,0,0,0"&!&/3!%04/3$(KO*./3 AE*..2)--JI3iJI $w  (Q   R  S  T	JI
 $sCx.)JI tCy)JI tCy)JI $D>JI 3-JI #JI +,JI JI  (~JI 'tnJI D>JI   FGH!JI" ,'#JI$ |,%JI& $u\3E}Vcer  uC  ES  Un  p{  &{   |  }  ~'JI( ')JI* &d^+JI, "#-JI0 
1JI` .2-1#'-1#/3.2/3)-489=3726,0#+/'()-+uBuB  S	*	uB
  S	*uB C=uB &c]uB }uB 'tnuB &d^uB 'tnuB !uB !1uB %_ 456uB #+4.uB  "*$!uB" $D>#uB$ }%uB& #4.'uB(  })uB* "#+uB. 
/uBx .2-1#'-1#/3.2/3)-489=3726,0#+/'()-+sBsB  S	*	sB
  S	*sB C=sB &c]sB }sB 'tnsB &d^sB 'tnsB !sB !1sB %_ 456sB #+4.sB  "*$!sB" $D>#sB$ }%sB& #4.'sB(  })sB* "#+sB. 
/sBj@3 @3H @D)_# )_S#X )__b )_  lA )_^ !%)--1'+#!&/3(,KEKE 	KE
 !KE %TNKE tnKE }KE #KE +,KE %KE 2?KE^ )-dR %)$(+/3805+0.2dR49%dR SM	dR
 SMdR $C=dR #+4.dR  (~dR #4.dR DcN+dR 8I7MdRLB
# B
:U B
H
# 
:O 
2
3 
3H 
2-S -T#s(^ -(&%s &%7H7M &%T )-Q% %)$(+/3805+0.2Q%49%Q% SM	Q%
 SMQ% $C=Q% #+4.Q%  (~Q% #4.Q% DcN+Q% 8I7MQ%n '+-126DWDW sm	DW
 %TNDW "*$DW <\DWT '+-1$(26>%>% sm	>%
 %TN>% D>>% "*$>% <V>%@$% $%@` $%T (,(,&*-1+/:>FJDHgngn  }	gn
 !gn smgn &c]gn $C=gn *2$gn "(DcN+;T+A"BCgn  $sCx.)94)? @Agn NjgnZ (,(,&*-1+/:>C%C%  }	C%
 !C% smC% &c]C% $C=C% *2$C% DHS>C%J)%3 )%;W )%^ $(!%$("&%)&*%*8<FJN
N
 C=	N

 #N
 SMN
 3-N
 c]N
 smN
 c]N
 %_5N
 U4S>>#ABCN
 *N
 N
r5   rK  c            
          ^  \ rS rSrSrS\S\4U 4S jjrSS jrSS	 jr	S
\
\\4   SS4S jrS\R                  S\SS4S jrS\S\S\S\S\4
S jrSrU =r$ )rx  i  zI
Async version of V1CrawlWatcher that properly handles async operations.
r   r  c                 $   > [         TU ]  X5        g r  rM  )r}  r   r  rO  s      r#   r~  AsyncV1CrawlWatcher.__init__  s    !r5   ru  Nc                 "  #    [         R                  " U R                  SSU R                  R                   34/S9 ISh  vN nU R                  U5      I Sh  vN   SSS5      ISh  vN   g N. N N	! , ISh  vN  (       d  f       g= f7f)zK
Establishes async WebSocket connection and starts listening for messages.
r  r  )r#  Nr$  r(  s     r#   r&  AsyncV1CrawlWatcher.connect  s}      %%KK!0GDHH<L<L;M2N OP
 
 ,,y)))	
 
 
 *	
 
 
 
sY   >B A/BA5A1A5B)A3*B1A53B5B;A><BBc                    #    U  Sh  vN n[         R                  " U5      nU R                  U5      I Sh  vN   M:   N5 N
 g7f)z
Listens for incoming WebSocket messages and handles them asynchronously.

Args:
    websocket: The WebSocket connection object
Nr,  r/  s       r#   r'  AsyncV1CrawlWatcher._listen  r2  r3  r0  c                   #    US   S:X  a<  SU l         U R                  SU R                   U R                  U R                  S.5        gUS   S:X  a@  SU l         U R                  SU R                   U R                  US   U R                  S.5        gUS   S:X  am  US	   S
   U l         U R                  R	                  US	   R                  S	/ 5      5        U R                   H!  nU R                  SX R                  S.5        M#     gUS   S:X  aA  U R                  R                  US	   5        U R                  SUS	   U R                  S.5        gg7f)z
Handles incoming WebSocket messages based on their type asynchronously.

Args:
    msg (Dict[str, Any]): The message to handle
r   r  rf   r?  r   rg   r@  rA  r   r   r  rB  NrC  rD  s      r#   r.  #AsyncV1CrawlWatcher._handle_message  rG  rH  r  r  c                 f  #     UR                  5       I Sh  vN nUR                  SS5      nUR                  SS5      nU R
                  R                  UR                  X$U5      I Sh  vN n[        R                  " U5      e Nm!   [        R                  " SUR                   35      e= f ND7f)z)
Handle errors from async API responses.
Nr   r~  r  r  rf  )rH   r  rS  rW  r   r  rg  rh  s          r#   r  !AsyncV1CrawlWatcher._handle_error  s     	{'}}.J&NN74PQM&NN96]^M
 99(//6bopp!!'** /	{%%(ghphwhwgx&yzz qs8   B1B B(B  *B1*B/+B1B %B,,B1r  r  r  c                 .   #    U R                  XX45      $ 7frl  rm  r  s        r#   rg  ,AsyncV1CrawlWatcher._get_async_error_message  ro  rp  )r   rI  )r-   r.   r/   r0   r1   r3   rK  r~  r&  r'  r   r   r.  rS  r  r  r   rg  r4   r  r  s   @r#   rx  rx    s    "3 "%8 "*	,Rc3h RD R,+G,B,B +C +TX + Z# Zs Z[^ Zor Zwz Z Zr5   rx  )Tr1   loggingr   r?  typingr   r   r   r   r   r   r	   r
   r   rH   r   r   r  rL   r%  rS  rV  	getLoggerr   Loggerr2   r$   r  r%   	BaseModelr'   r7   r=   rB   rO   r^   rc   rl   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r  r  r  r  r   r'  r1  r3  r9  r;  r?  rA  rG  rJ  rM  rO  rV  r]  r_  rd  rf  rj  rr  r  rK  rx  r,   r5   r#   <module>r     s[    	  X X X   	     !++K8 8
 -CLJ!X'' !
(H.. (h(( 
C8-- C:(,,gaj : *x)) *
Uh(( Uh00 $h(( $(#8%% #"++ "H&& 
H&& 
H&& 
#X'' #X''  2 2 
"($$ "(X'' (+8%% +._ . *1-wqz  ,H.. ,	$("4"4 	$+H&& +( h((  	$H.. 	$8%% H.. 
	0($$ 	0 H&&  
4h(( 
4&**GAJ &
4X'' 
4 x))  -** -H.. -x)) -8-- H$6$6 1h&8&8 18#5#5 0X%7%7 01x11 1	68-- 	6&X// &&8#5#5 &"&!3!3 &&8+=+= &&x'9'9 & x))  +h(( +X+  X+ vVYR YRvx
. x
t;OZ. OZr5   