
    ^jf!                     Z   d Z ddlZddlmZmZmZ ddlZddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZmZ dd	lmZ  e ee
      d
         Z ej*                  deD  ci c]  } | |  c} e      Z ee      Z ej*                  deD ci c]  }|| c}e      Zdee   dee
   fdZ ed      Zej;                  dg d      	 dFdeddfd       Zej;                  ddg      	 dFdee ed      f   deddfd       Zej;                  dg d      	 	 	 	 	 dGdeee    ed d!      f   d"eedz   ed#      f   d$eedz   ed%d&      f   d'eee   dz   ed(d)      f   d*eedz   ed+      f   deddfd,       Z ej;                  d-g d.      	 	 	 	 	 dGdee ed/      f   d"eedz   ed0      f   deee   dz   ed d1      f   d'eee   dz   ed(d2      f   d*eedz   ed3      f   deddfd4       Z!ej;                  d5d6g      	 dFdee ed7      f   deddfd8       Z"ej;                  d9d:g      	 dFdee ed;      f   deddfd<       Z#ej;                  d=d>d?g      	 	 dHdee ed@      f   dAee$ edBdCdD      f   deddfdE       Z%yc c} w c c}w )Iz=Contains commands to manage webhooks on the Hugging Face Hub.    N)	Annotatedget_argsget_type_hints)WEBHOOK_DOMAIN_T)WebhookWatchedItem   )TokenOpt
get_hf_apityper_factory)ArgumentOption)outtypeWatchedItemType)r   WebhookDomainvaluesreturnc           	      T   g }t        t              }| D ]  }d|vr+t        j                  d| ddj	                  |       d      |j                  dd      \  }}||vr+t        j                  d| ddj	                  |       d      |j                  t        ||              |S )	aY  Parse 'type:name' strings into WebhookWatchedItem objects.

    Args:
        values: List of strings in the format 'type:name'
            (e.g., 'model:bert-base-uncased', 'org:HuggingFace').

    Returns:
        List of WebhookWatchedItem objects.

    Raises:
        click.BadParameter: If any value doesn't match the expected format.
    :zCExpected format 'type:name' (e.g. 'model:bert-base-uncased'), got 'z'. Valid types: z, .r   zInvalid type ')r   name)tuple_WATCHED_TYPESclickBadParameterjoinsplitappendr   )r   itemsvalid_typesvkindr   s         g/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/huggingface_hub/cli/webhooks.py_parse_watchr$   )   s     E'K 	?a<$$UVWUX Y!!%;!7 8;  WWS!_
d{"$$~dV;KDIIVaLbKccd%eff'T=>	? L    zManage webhooks on the Hub.)helpz	list | ls)zhf webhooks lszhf webhooks ls --format jsonzhf webhooks ls --format quiet)examplestokenc                 p   t        |       }|j                         D cg c]o  }|j                  |j                  xs d|j                  |j
                  xs g |j                  xs g D cg c]  }|j                   d|j                    c}dq }}}t        j                  |       yc c}w c c}}w )z'List all webhooks for the current user.r(   z(job)r   )idurldisableddomainswatchedN)r
   list_webhooksr+   r,   r-   r.   r/   r   r   r   table)r(   apiwwiresultss        r#   webhooks_lsr6   H   s     5
!C ""$	  $$55#G

yyB:;))/rK2277)1RWWI.K	
	G 	 IIg	 L	s   AB2+"B-B2-B2infozhf webhooks info abc123
webhook_idzThe ID of the webhook.c                 h    t        |      }|j                  |       }t        j                  |       y)z'Show full details for a single webhook.r*   N)r
   get_webhookr   dictr8   r(   r2   webhooks       r#   webhooks_infor>   b   s(     5
!Cooj)GHHWr%   create)zQhf webhooks create --url https://example.com/hook --watch model:bert-base-uncasedzjhf webhooks create --url https://example.com/hook --watch org:HuggingFace --watch model:gpt2 --domain repozJhf webhooks create --job-id 687f911eaea852de79c4a50a --watch user:julien-cwatchz--watchzRItem to watch, in 'type:name' format (e.g. 'model:bert-base-uncased'). Repeatable.r,   zBURL to send webhook payloads to. Mutually exclusive with --job-id.job_idz--job-idz]ID of a Job to trigger (from job.id) instead of pinging a URL. Mutually exclusive with --url.domainz--domainzNDomain to watch: 'repo' or 'discussions'. Repeatable. Defaults to all domains.secretz.Optional secret used to sign webhook payloads.c                 J   ||t        j                  d      ||t        j                  d      t        |      }t        |       }|r|D cg c]  }|j                   c}nd}	|j                  ||||	|      }
t        j                  d|
j                         yc c}w )z|Create a new webhook.

    Provide either --url (to ping a remote server) or --job-id (to trigger a Job), but not both.
    Nz+Provide either --url or --job-id, not both.z!Provide either --url or --job-id.r*   )r,   rA   r/   r.   rC   zWebhook createdr+   )	r   r   r
   r$   valuecreate_webhookr   resultr+   )r@   r,   rA   rB   rC   r(   r2   watched_itemsdr.   r=   s              r#   webhooks_createrK   r   s    X 6-  !NOO
{v~  !DEE
5
!C 'M+1'1qww'tG  SX_hn oGJJ WZZ0 (s   B update)z8hf webhooks update abc123 --url https://new-url.com/hookz:hf webhooks update abc123 --watch model:gpt2 --domain repoz,hf webhooks update abc123 --secret newsecretz The ID of the webhook to update.z$New URL to send webhook payloads to.ziNew list of items to watch, in 'type:name' format. Repeatable. Replaces the entire existing watched list.zBNew list of domains to watch: 'repo' or 'discussions'. Repeatable.z)New secret used to sign webhook payloads.c                     t        |      }|rt        |      nd}|r|D cg c]  }|j                   c}nd}	|j                  | |||	|      }
t	        j
                  d|
j                         yc c}w )z>Update an existing webhook. Only provided options are changed.r*   N)r,   r/   r.   rC   zWebhook updatedrE   )r
   r$   rF   update_webhookr   rH   r+   )r8   r,   r@   rB   rC   r(   r2   rI   rJ   r.   r=   s              r#   webhooks_updaterO      sj    L 5
!C+0L'dM+1'1qww'tG  mU\ek lGJJ WZZ0 (s   A2enablezhf webhooks enable abc123z The ID of the webhook to enable.c                     t        |      }|j                  |       }t        j                  d|j                         y)zEnable a disabled webhook.r*   zWebhook enabledrE   N)r
   enable_webhookr   rH   r+   r<   s       r#   webhooks_enablerS      s1     5
!C  ,GJJ WZZ0r%   disablezhf webhooks disable abc123z!The ID of the webhook to disable.c                     t        |      }|j                  |       }t        j                  d|j                         y)zDisable an active webhook.r*   zWebhook disabledrE   N)r
   disable_webhookr   rH   r+   r<   s       r#   webhooks_disablerW      s1     5
!C!!*-GJJ!gjj1r%   deletezhf webhooks delete abc123zhf webhooks delete abc123 --yesz The ID of the webhook to delete.yesz--yesz-yzSkip confirmation prompt.c                     t        j                  d|  d|       t        |      }|j                  |        t        j                  d|        y)zDelete a webhook permanently.z)Are you sure you want to delete webhook 'z'?)rY   r*   zWebhook deletedrE   N)r   confirmr
   delete_webhookrH   )r8   rY   r(   r2   s       r#   webhooks_deleter]      sD    ( KK;J<rJPST
5
!Cz"JJ Z0r%   )N)NNNNN)FN)&__doc__enumtypingr   r   r   r   huggingface_hub.constantsr   huggingface_hub.hf_apir   
_cli_utilsr	   r
   r   
_frameworkr   r   _outputr   r   Enumstrr   _DOMAIN_TYPESr   listr$   webhooks_clicommandr6   r>   rK   rO   rS   rW   boolr]   )trJ   s   00r#   <module>rn      s   D  6 6  6 5 
 )  .);<VDE$))-n/M1/MTWX)*		/-+HQAqD+HsSc t,>'? 8 "?@    	$ 
!   #x-EFFG 
   & 	 	 	 	=,1S	e	
	,1 
d
XY	[
,1 d
p	
	,1& ]d"a	
	',14 d
DE	G5,1< =,1> 
?,1,1^    	 	 	 	7"1#x-OPPQ"1	d
:;	=
"1 S	DI	
		"1  ]d"U	
	!"1. d
?@	B/"16 7"18 
9"1"1J #   1#x-OPPQ11 
11 $   2#x-PQQR22 
22 #)    	1#x-OPPQ1	,	
	
1 1 
11u 0N ,Is   
J#

J(
