
    -:j4$                     v   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  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j5                  dg d      	 dEdeddfd       Zej5                  ddg      	 dEdee ej8                  d      f   deddfd       Zej5                  dg d      	 	 	 	 	 dFdeee    ej<                  dd       f   d!eedz   ej<                  d"      f   d#eedz   ej<                  d$d%      f   d&eee   dz   ej<                  d'd(      f   d)eedz   ej<                  d*      f   deddfd+       Zej5                  d,g d-      	 	 	 	 	 dFdee ej8                  d.      f   d!eedz   ej<                  d/      f   deee   dz   ej<                  dd0      f   d&eee   dz   ej<                  d'd1      f   d)eedz   ej<                  d2      f   deddfd3       Z ej5                  d4d5g      	 dEdee ej8                  d6      f   deddfd7       Z!ej5                  d8d9g      	 dEdee ej8                  d:      f   deddfd;       Z"ej5                  d<d=d>g      	 	 dGdee ej8                  d?      f   d@ee# ej<                  dAdBdC      f   deddfdD       Z$yc c} w c c}w )Ha  Contains commands to manage webhooks on the Hugging Face Hub.

Usage:
    # list all webhooks
    hf webhooks ls

    # show details of a single webhook
    hf webhooks info <webhook_id>

    # create a new webhook
    hf webhooks create --url https://example.com/hook --watch model:bert-base-uncased

    # create a webhook watching multiple items and domains
    hf webhooks create --url https://example.com/hook --watch org:HuggingFace --watch model:gpt2 --domain repo

    # update a webhook
    hf webhooks update <webhook_id> --url https://new-url.com/hook

    # enable / disable a webhook
    hf webhooks enable <webhook_id>
    hf webhooks disable <webhook_id>

    # delete a webhook
    hf webhooks delete <webhook_id>
    N)	Annotatedget_argsget_type_hints)WEBHOOK_DOMAIN_T)WebhookWatchedItem   )TokenOpt
get_hf_apityper_factory)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:
        typer.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typerBadParameterjoinsplitappendr   )r   itemsvalid_typesvkindr   s         ^/var/www/html/tokenscope/api/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_lsr4   _   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r6   r&   r0   webhooks       r!   webhooks_infor<   y   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*   r?   r-   r,   rA   zWebhook createdr)   )	r   r   r
   r"   valuecreate_webhookr   resultr)   )r>   r*   r?   r@   rA   r&   r0   watched_itemsdr,   r;   s              r!   webhooks_createrI      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,   rA   zWebhook updatedrC   )r
   r"   rD   update_webhookr   rF   r)   )r6   r*   r>   r@   rA   r&   r0   rG   rH   r,   r;   s              r!   webhooks_updaterM      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 enabledrC   N)r
   enable_webhookr   rF   r)   r:   s       r!   webhooks_enablerQ      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 disabledrC   N)r
   disable_webhookr   rF   r)   r:   s       r!   webhooks_disablerU      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'?)rW   r(   zWebhook deletedrC   N)r   confirmr
   delete_webhookrF   )r6   rW   r&   r0   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   _outputr   r   Enumstrr   _DOMAIN_TYPESr   listr"   webhooks_clicommandr4   Argumentr<   OptionrI   rM   rQ   rU   boolr[   )trH   s   00r!   <module>rm      sH  4  6 6  6 5 
  .);<VDE$))-n/M1/MTWX)*		/-+HQAqD+HsSc t,>'? 8 "?@    	$ 
!   #~u~~3KLLM 
   & 	 	 	 	=,1S	e	
	,1 
d
^_	a
,1 d
p	
	,1& ]d"a	
	',14 d
JK	M5,1< =,1> 
?,1,1^    	 	 	 	7"1#~u~~3UVVW"1	d
@A	C
"1 S	DI	
		"1  ]d"U	
	!"1. d
EF	H/"16 7"18 
9"1"1J #   1#~u~~3UVVW11 
11 $   2#~u~~3VWWX22 
22 #)    	1#~u~~3UVVW1	,	
	
1 1 
11u 0N ,Is   
L1
?
L6
