
    Mi{?                        S 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SSKrSSKJ	r	  SSK
r
SSKJr  SSKJr  SSKJr  SSKJr  SSKJrJr  \" 5       rS	rS
\4S jrS\4S jrS
\\\4   4S jrS
\\\4   4S jr\R>                  " S5      S 5       r \ RC                  S5      \RD                  " SSSS9\RD                  " SSS\ S3S9\RD                  " SSSS9\RD                  " SSS S9S!\S"\S#\#S$\#4S% j5       5       5       5       5       r$\ R?                  S&5      S' 5       r%\%RC                  S(5      \RL                  " S)5      \RD                  " S*S+S,S9\RD                  " S-S.\RN                  " / S/Q5      S0S1S29\RD                  " S3SS4S9S)\S5\S6\S7\#4S8 j5       5       5       5       5       r(\%RC                  S95      S: 5       r)\%RC                  S;5      \RL                  " S<5      \RD                  " S=S>SS?S9S<\S@\#4SA j5       5       5       r*g)Ba0  
Crawl4AI Cloud CLI - Commands for interacting with Crawl4AI Cloud service.

Commands:
  crwl cloud auth          - Authenticate with API key
  crwl cloud profiles upload - Upload a profile to cloud
  crwl cloud profiles list   - List cloud profiles
  crwl cloud profiles delete - Delete a cloud profile
    N)Path)Console)Panel)Table)BrowserProfiler)ShrinkLevel_format_sizezhttps://api.crawl4ai.comreturnc                      [         R                  " 5       S-  S-  n U R                  5       (       d  0 $ [        U 5       n[        R
                  " U5      =(       d    0 sSSS5        $ ! , (       d  f       g= f)z.Load global config from ~/.crawl4ai/global.yml	.crawl4ai
global.ymlN)r   homeexistsopenyaml	safe_load)config_filefs     l/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/crawl4ai/cloud/cli.pyget_global_configr   "   sR    ))++l:K		k	a~~a &B 
		s   A''
A5configc                     [         R                  " 5       S-  nUR                  SSS9  US-  n[        US5       n[        R
                  " X5        SSS5        g! , (       d  f       g= f)z,Save global config to ~/.crawl4ai/global.ymlr   T)parentsexist_okr   wN)r   r   mkdirr   r   dump)r   
config_dirr   r   s       r   save_global_configr   +   sS    {*JTD1|+K	k3	1		& 
 		s   A
A(c                  j    [        5       n U R                  S5      nU R                  S[        5      nX4$ )z&Get cloud API key and URL from config.CLOUD_API_KEYCLOUD_API_URL)r   getDEFAULT_CLOUD_API_URL)r   api_keyapi_urls      r   get_cloud_configr'   4   s2     Fjj)Gjj*?@G    c                      [        5       u  pU (       d@  [        R                  S5        [        R                  S5        [        R                  " S5        X4$ )z/Require authentication, exit if not configured.z1[red]Not authenticated with Crawl4AI Cloud.[/red]z2
Run [cyan]crwl cloud auth[/cyan] to authenticate.   )r'   consoleprintsysexit)r%   r&   s     r   require_authr/   <   s>    ')GIJKLr(   cloudc                      g)aP  Crawl4AI Cloud commands - manage cloud profiles and authentication.

Use browser profiles for authenticated crawling in the cloud.

Getting started:
  1. Get an API key at https://api.crawl4ai.com/dashboard
  2. Run: crwl cloud auth
  3. Create a local profile: crwl profiles
  4. Upload to cloud: crwl cloud profiles upload my_profile
N r2   r(   r   	cloud_cmdr3   H        	r(   authz	--api-keyz-kz%API key (will prompt if not provided))helpz	--api-urlz-uzAPI URL (default: )z--logoutTzRemove saved credentials)is_flagr6   z--statuszShow current auth statusr%   r&   logoutstatusc           	         [        5       nU(       a  UR                  S5      nUR                  S[        5      nU(       aE  [        U5      S:  a  USS S-   USS -   OSn[        R                  [        S	U S
U S3SSS95        g[        R                  [        SSSS95        gU(       a@  SU;   a$  US	 [        U5        [        R                  S5        g[        R                  S5        gU (       d3  [        R                  [        SSSS95        [        R                  " SSS9n U (       d+  [        R                  S5        [        R                  " S5        U=(       d    UR                  S[        5      n[        R                  S5         [        R                  " U S3SU 0SS9n	U	R                  S :X  a,  [        R                  S!5        [        R                  " S5        OIU	R                  S":w  a9  [        R                  S#U	R                   S$35        [        R                  " S5        XS'   U(       a  XS'   [        U5        [        R                  S&5        [        R                  S'5        g! [        R                   a9  n
[        R                  S%U
 S$35        [        R                  " S5         Sn
A
NSn
A
ff = f)(a  Authenticate with Crawl4AI Cloud.

Your API key is saved locally in ~/.crawl4ai/global.yml

To get an API key:
  1. Go to https://api.crawl4ai.com/dashboard
  2. Sign in or create an account
  3. Navigate to API Keys section
  4. Create a new key and copy it

Examples:
  crwl cloud auth                    # Interactive authentication
  crwl cloud auth --api-key sk_...   # Provide key directly
  crwl cloud auth --status           # Check current status
  crwl cloud auth --logout           # Remove saved credentials
r!   r"      N   ...z***z-[green]Authenticated[/green]

API Key: [cyan]z[/cyan]
API URL: [blue]z[/blue]zCloud Auth Statusgreentitleborder_stylez[yellow]Not authenticated[/yellow]

Run [cyan]crwl cloud auth[/cyan] to authenticate.

Get your API key at:
[blue]https://api.crawl4ai.com/dashboard[/blue]yellowz'[green]Logged out successfully.[/green]z-[yellow]Not currently authenticated.[/yellow]z[cyan]Crawl4AI Cloud Authentication[/cyan]

To get your API key:
  1. Go to [blue]https://api.crawl4ai.com/dashboard[/blue]
  2. Sign in or create an account
  3. Navigate to API Keys section
  4. Create a new key and paste it belowSetupcyanz
Enter your API keyT)
hide_inputz[red]API key is required.[/red]r*   z!
[dim]Validating API key...[/dim]/v1/profiles	X-API-Keyg      $@headerstimeouti  z[red]Invalid API key.[/red]   z[red]Error validating key: [/red][red]Connection error: z)[green]Authentication successful![/green]z8Credentials saved to [cyan]~/.crawl4ai/global.yml[/cyan])r   r#   r$   lenr+   r,   r   r   clickpromptr-   r.   httpxstatus_codeRequestError)r%   r&   r9   r:   r   current_keycurrent_urlmaskedtest_urlresponsees              r   auth_cmdr\   Y   so   ,  Fjj1jj2GHCF{CSVXCX[!_u,{23/??^cFMM%""( *""-g7 *$   	 MM%B *%  	f$'v&MMCD 	 MMIJ e7 	
 		 ,,5$G78 L&**_6KLHMM6799j% '*
 3&MM78HHQK!!S(MM78L8L7MVTUHHQK &?")vMM=>MMLN  /s&9:s    AI1 #A	I1 1J>/J99J>profilesc                      g)aK  Manage cloud browser profiles.

Upload local browser profiles to Crawl4AI Cloud for authenticated crawling.

Workflow:
  1. Create a local profile: crwl profiles
  2. Shrink it (optional): crwl shrink my_profile
  3. Upload to cloud: crwl cloud profiles upload my_profile
  4. Use in API: {"browser_config": {"profile_id": "..."}}
Nr2   r2   r(   r   profiles_cmdr_      r4   r(   uploadprofile_namez--namez-nz+Cloud profile name (defaults to local name)z--levelz-l)lightmedium
aggressiveminimalrd   z0Shrink level before upload (default: aggressive))typedefaultr6   z--no-shrinkzSkip shrinking (upload as-is)namelevel	no_shrinkc                 
   [        5       u  pE[        5       nUR                  U 5      nU(       dv  [        R	                  SU  S35        [        R	                  S5        UR                  5        H  n[        R	                  SUS    35        M      [        R                  " S5        U=(       d    U n	[        R	                  SU  35        [        R	                  SU	 35        U(       d  [        R	                  S	U S
35         UR                  U [        U5      SS9n
[        R	                  S[        U
S   5       35        U
R                  S5      (       a$  [        R	                  S[        U
S   5       35        O[        R	                  S5        [        R	                  S5        [        [        R                  " SS95      nX S3-  n [         R"                  " US5       n[        U5      R%                  5        H  nUR'                  XR(                  S9  M     SSS5        UR+                  5       R,                  n[        R	                  SUR(                   S[        U5       S35        [        R	                  S5        [#        US5       n[.        R0                  " U S 3S!U0S"U	 S3US#40SU	0S$S%9nSSS5        WR2                  S&:X  aE  [        R	                  S'U	 S(35        [        R	                  S)5        [        R                  " S5        OUR2                  S*:X  aP  UR5                  5       R                  S+S,5      n[        R	                  S-U S35        [        R                  " S5        OhUR2                  S.:w  aX  [        R	                  S/UR2                   S35        [        R	                  UR6                  5        [        R                  " S5        UR5                  5       n
U
S0   n[        R	                  S15        [        R	                  [9        S2U S3U	 S4[        U5       S5U S63	S7S8S995        U
R                  S:5      (       a9  [        R	                  S;5        U
S:    H  n[        R	                  SU 35        M     [:        R<                  " US<S=9  g! [         a$  n[        R	                  SU S35         SnAGN6SnAff = f! , (       d  f       GN= f! , (       d  f       GN2= f! [:        R<                  " US<S=9  f = f)>ar  Upload a browser profile to Crawl4AI Cloud.

The profile will be shrunk to remove caches before uploading.
Use --no-shrink to upload the profile as-is.

Examples:
  crwl cloud profiles upload my_profile
  crwl cloud profiles upload my_profile --name github-auth
  crwl cloud profiles upload my_profile --level minimal
  crwl cloud profiles upload my_profile --no-shrink
[red]Profile not found: rN   
Available profiles:  - rh   r*   z!
[cyan]Uploading profile:[/cyan] z[cyan]Cloud name:[/cyan] z
[dim][1/4] Shrinking profile (z
)...[/dim]F)dry_runz      Freed: bytes_freed
size_afterz      Size: z+[yellow]Warning: Could not shrink profile: z	[/yellow]Nz$
[dim][1/4] Skipping shrink...[/dim]z%[dim][2/4] Packaging profile...[/dim]crawl4ai_upload_)prefixz.tar.gzzw:gz)arcnamez      Created:  (r7   z&[dim][3/4] Uploading to cloud...[/dim]rbrH   rI   filezapplication/gzipg      ^@)rK   filesdatarL   i  z[red]Profile 'z ' already exists in cloud.[/red]zMUse --name to specify a different name, or delete the existing profile first.i  detailzUnknown errorz[red]Upload rejected: rM   z[red]Upload failed: idz[dim][4/4] Done![/dim]zA[green]Profile uploaded successfully![/green]

Profile ID: [cyan]z[/cyan]
Name: [blue]z[/blue]
Size: z>

[dim]Use in API:[/dim]
  {"browser_config": {"profile_id": "z"}}zUpload Completer@   rA   scan_warningsz 
[yellow]Scan warnings:[/yellow]T)ignore_errors)r/   r   get_profile_pathr+   r,   list_profilesr-   r.   shrinkr   r	   r#   	Exceptionr   tempfilemkdtemptarfiler   iterdiraddrh   statst_sizerS   postrT   jsontextr   shutilrmtree)ra   rh   ri   rj   r%   r&   profilerprofile_pathp
cloud_nameresultr[   temp_dirtar_pathtaritem
size_bytesr   rZ   error
profile_idwarnings                         r   
upload_cmdr      s>   ( $~G  H,,\:L0fEF-.'')AMMD6,- *%JMM6|nEFMM-j\:; 8zJK	V__\;u3Eu_UFMMM,vm7L*M)NOPzz,''\&:N-O,PQR 	=> MM9:H$$,>?@HL00H:4\\(F+s\*224ii0 5 ,
 ]]_,,
bj9Q8RRSTU 	>?(D!Qzz)<($g.:,g 6;MNOj)H " 3&MMN:,6VWXMMijHHQK!!S(MMO''/BEMM25'@AHHQK!!S(MM01E1E0FfMNMM(--(HHQKD\
./ 	e!!+ -%, '!*-. /66@\H $ 	
 		 ::o&&MM=>!/2WI./ 3
 	hd3K  	VMMGs)TUU	V ,+ "!\ 	hd3sW   A8R 	S1  :SA2S1 (S4GS1 
S
&SS

SS1 
S.)S1 1Tlistc                     [        5       u  p[        R                  S5         [        R                  " U S3SU 0SS9nUR
                  S:w  aX  [        R                  SUR
                   S35        [        R                  UR                  5        [        R                  " S	5        UR                  5       nUR	                  S
/ 5      nU(       d  [        R                  [        SSSS95        g[        SS9nUR                  SSS9  UR                  SSS9  UR                  SSS9  UR                  SSS9  UR                  SSS9  U H  nUR	                  S5      (       a  [        UR	                  SS5      5      OSnUR	                  S 5      (       a  UR	                  S S5      SS! OSnUR	                  S"5      (       a  UR	                  S"S5      SS! OS#n	UR                  US$   US%   SS& S'-   UUU	5        M     [        R                  U5        [        R                  S([        U5       S)35        g! [        R                    a9  n
[        R                  S*U
 S35        [        R                  " S	5         Sn
A
gSn
A
ff = f)+zVList all cloud profiles.

Shows all profiles uploaded to your Crawl4AI Cloud account.
z 
[dim]Fetching profiles...[/dim]rH   rI         >@rJ   rM   [red]Error: rN   r*   r]   zz[yellow]No cloud profiles found.[/yellow]

Upload a profile with:
  [cyan]crwl cloud profiles upload <profile_name>[/cyan]zCloud ProfilesrD   rA   N)rB   NamerF   )stylez
Profile IDdimSizeright)justifyCreatedr@   z	Last Usedbluer   r   -
created_at
   last_used_atNeverrh   r{   r=   r>   z
Total: z profile(s)rO   )r/   r+   r,   rS   r#   rT   r   r-   r.   r   r   r   
add_columnr	   add_rowrP   rU   )r%   r&   rZ   ry   r]   tabler   sizecreated	last_usedr[   s              r   list_cmdr   M  sH    $~GMM56399i|$ '*
 3&MML)=)=(>fEFMM(--(HHQK}}88J+MM%K '%   ,-v.U31'2F3A;<55;N;N<lA 67TWD78uu\7J7JaeeL#.s3PSG;<55;P;Pnc23B7V]IMM&	$e#  	e	#h-<= /s&9:s   C
H6 .EH6 6J
/I>>Jdeleteprofile_name_or_idz--yesz-yzSkip confirmationyesc           	          [        5       u  p#[        R                  S5         [        R                  " U S3SU0SS9nUR
                  S:w  a9  [        R                  SUR
                   S35        [        R                  " S	5        UR                  5       R	                  S
/ 5      nSnU H2  nUS   U :X  d$  US   U :X  d  US   R                  U 5      (       d  M0  Un  O   U(       dr  [        R                  SU  S35        [        R                  S5        U H(  n[        R                  SUS    SUS   SS  S35        M*     [        R                  " S	5        [        R                  SUS    S35        [        R                  SUS    S35        U(       d1  [        R                  " S5      (       d  [        R                  S5        g[        R                  S5        [        R                  " U SUS    3SU0SS9nUR
                  S:X  a,  [        R                  S5        [        R                  " S	5        OhUR
                  S:w  aX  [        R                  SUR
                   S35        [        R                  UR                  5        [        R                  " S	5        [        R                  SUS    S35        g! [        R                   a9  n[        R                  S U S35        [        R                  " S	5         SnAgSnAff = f)!zDelete a cloud profile.

You can specify either the profile name or ID.

Examples:
  crwl cloud profiles delete my_profile
  crwl cloud profiles delete abc123...
  crwl cloud profiles delete my_profile --yes
z
[dim]Finding profile...[/dim]rH   rI   r   rJ   rM   r   rN   r*   r]   Nrh   r{   rl   rm   rn   ru   r=   z...)z
Profile: [cyan]z[/cyan]z	ID: [dim]z[/dim]z.
Are you sure you want to delete this profile?z[yellow]Cancelled.[/yellow]z
[dim]Deleting...[/dim]z/v1/profiles/i  z=[red]Profile not found (may have been already deleted).[/red]z[green]Profile 'z' deleted successfully.[/green]rO   )r/   r+   r,   rS   r#   rT   r-   r.   r   
startswithrQ   confirmr   r   rU   )	r   r   r%   r&   rZ   r]   profiler   r[   s	            r   
delete_cmdr     s    $~G MM34:99i|$ '*
 3&MML)=)=(>fEFHHQK==?&&z26 Ay..!D'=O2OSTUYSZSeSefxSySy 
 MM45G4HOPMM12QvYKr!D'"1+dCD HHQK 	)'&/):'BC	'$-78==!RSS;< 	01<<i}WT]O4 '*
 3&MMYZHHQK!!S(MML)=)=(>fEFMM(--(HHQK((99XYZ /s&9:s&   B4K  C.K  
C5K   L/LL)+__doc__rQ   rS   osr   r-   r   r   pathlibr   r   rich.consoler   
rich.panelr   
rich.tabler   crawl4air   crawl4ai.browser_profilerr   r	   r+   r$   dictr   r   tuplestrr'   r/   groupr3   commandoptionboolr\   r_   argumentChoicer   r   r   r2   r(   r   <module>r      s     	  
         $ ?
) 3 '4 't %S/ eCHo  W	 	  6k4&MNk4(:;P:QQR&STj$-GHj$-GHeOc eOC eO eOt eO I I U O 
eOT 	 	 hh#PQi<< LM"EG mT0OPk4S k4 k4C k4D k4 Q	G R    k4\ f< <~ h$%gtT0CDI3 IT I E &  Ir(   