
    i%                     4   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mZ ddlmZ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j9                  dg d      ej:                  dfdededdfd       Zej9                  ddg      ej:                  dfdee ej>                  d      f   dededdfd       Z ej9                  dg d      ddddej:                  dfdeee    ejB                  d d!      f   d"eedz   ejB                  d#      f   d$eedz   ejB                  d%d&      f   d'eee   dz   ejB                  d(d)      f   d*eedz   ejB                  d+      f   dededdfd,       Z"ej9                  d-g d.      ddddej:                  dfdee ej>                  d/      f   d"eedz   ejB                  d0      f   deee   dz   ejB                  d d1      f   d'eee   dz   ejB                  d(d2      f   d*eedz   ejB                  d3      f   dededdfd4       Z#ej9                  d5d6g      ej:                  dfdee ej>                  d7      f   dededdfd8       Z$ej9                  d9d:g      ej:                  dfdee ej>                  d;      f   dededdfd<       Z%ej9                  d=d>d?g      d@ej:                  dfdee ej>                  dA      f   dBee& ejB                  dCdDdE      f   dededdf
dF       Z'yc c} w c c}w )Ga  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   )FormatWithAutoOptTokenOpt
get_hf_apityper_factory)OutputFormatWithAuto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         m/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/huggingface_hub/cli/webhooks.py_parse_watchr$   A   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format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/   r0   r   r   r   table)r(   r)   apiwwiresultss         r#   webhooks_lsr7   `   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r9   r(   r)   r3   webhooks        r#   webhooks_infor?   {   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-   rB   r0   r/   rD   zWebhook createdr,   )	r   r   r   r$   valuecreate_webhookr   resultr,   )rA   r-   rB   rC   rD   r(   r)   r3   watched_itemsdr/   r>   s               r#   webhooks_createrL      s    Z 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-   r0   r/   rD   zWebhook updatedrF   )r   r$   rG   update_webhookr   rI   r,   )r9   r-   rA   rC   rD   r(   r)   r3   rJ   rK   r/   r>   s               r#   webhooks_updaterP      sj    N 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 enabledrF   N)r   enable_webhookr   rI   r,   r=   s        r#   webhooks_enablerT      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 disabledrF   N)r   disable_webhookr   rI   r,   r=   s        r#   webhooks_disablerX     s1     5
!C!!*-GJJ!gjj1r%   deletezhf webhooks delete abc123zhf webhooks delete abc123 --yesFz 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'?)rZ   r+   zWebhook deletedrF   N)r   confirmr   delete_webhookrI   )r9   rZ   r(   r)   r3   s        r#   webhooks_deleter^     sD    * KK;J<rJPST
5
!Cz"JJ Z0r%   )(__doc__enumtypingr   r   r   r   huggingface_hub.constantsr   huggingface_hub.hf_apir   
_cli_utilsr	   r
   r   r   _outputr   r   r   Enumstrr   _DOMAIN_TYPESr   listr$   webhooks_clicommandautor7   Argumentr?   OptionrL   rP   rT   rX   boolr^   )trK   s   00r#   <module>rq      s  4  6 6  6 5  / .);<VDE$))-n/M1/MTWX)*		/-+HQAqD+HsSc t,>'? 8 "?@    !5 9 9 
& 
!   !5 9 9#~u~~3KLLM  
	   & 	 	 	 	 4 9 9?-1S	e	
	-1 
d
^_	a
-1 d
p	
	-1& ]d"a	
	'-14 d
JK	M5-1< =-1> ?-1@ 
A-1-1`    	 	 	 	 4 9 99#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: 
;#1#1L #   !5 9 91#~u~~3UVVW11 1 
	11 $   !5 9 92#~u~~3VWWX22 2 
	22 #)    	 4 9 91#~u~~3UVVW1	,	
	
1 1 1 
11A 0N ,Is   
N

N
