
    "j%                        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
d eD             e          Z ee          Z ej        dd eD             e          Zdee         dee
         fdZ ed          Ze                    dg d          ej        dfdededdfd            Ze                    ddg          ej        dfdee ej        d          f         dededdfd            Z e                    dg d           ddddej        dfd!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eddfd.            Z"e                    d/g d0          ddddej        dfdee ej        d1          f         d$eedz   ej!        d2          f         d!eee         dz   ej!        d"d3          f         d)eee         dz   ej!        d*d4          f         d,eedz   ej!        d5          f         dededdfd6            Z#e                    d7d8g          ej        dfdee ej        d9          f         dededdfd:            Z$e                    d;d<g          ej        dfdee ej        d=          f         dededdfd>            Z%e                    d?d@dAg          dBej        dfdee ej        dC          f         dDee& ej!        dEdFdG          f         dededdf
dH            Z'dS )Ia  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WatchedItemTypec                     i | ]}||S  r   ).0ts     f/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/huggingface_hub/cli/webhooks.py
<dictcomp>r   ;   s    /M/M/M1/M/M/M    )r   WebhookDomainc                     i | ]}||S r   r   r   ds     r   r   r   >   s    +H+H+HQAq+H+H+Hr   valuesreturnc           	      ~   g }t          t                    }| D ]}d|vr.t          j        d| dd                    |           d          |                    dd          \  }}||vr.t          j        d| dd                    |           d          |                    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         r   _parse_watchr.   A   s     E''K 	? 	?a<<$;VW ; ;!%;!7!7; ; ;   WWS!__
d{""$%ed%e%eDIIVaLbLb%e%e%efff'T===>>>>Lr   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                     t          |          }d |                                D             }t          j        |           dS )z'List all webhooks for the current user.r2   c                 p    g | ]3}|j         |j        pd |j        |j        pg d |j        pg D             d4S )z(job)c                 0    g | ]}|j          d |j         S )r   r!   )r   wis     r   
<listcomp>z*webhooks_ls.<locals>.<listcomp>.<listcomp>t   s*    KKK227..RW..KKKr   idurldisableddomainswatchedr9   )r   ws     r   r8   zwebhooks_ls.<locals>.<listcomp>n   se     	 	 	  $5#G
yBKK!)/rKKK	
 	
	 	 	r   N)r   list_webhooksr   table)r1   r2   apiresultss       r   webhooks_lsrD   `   sX     5
!
!
!C	 	 ""$$	 	 	G Igr   infozhf webhooks info abc123
webhook_idzThe ID of the webhook.c                 x    t          |          }|                    |           }t          j        |           dS )z'Show full details for a single webhook.r4   N)r   get_webhookr   dictrF   r1   r2   rB   webhooks        r   webhooks_inforL   {   s;     5
!
!
!Cooj))GHW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                 .   ||t          j        d          ||t          j        d          t          |          }t          |           }|rd |D             nd}	|                    ||||	|          }
t          j        d|
j                   dS )	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.r4   c                     g | ]	}|j         
S r   valuer   s     r   r8   z#webhooks_create.<locals>.<listcomp>       '''1qw'''r   )r;   rO   r>   r=   rQ   zWebhook createdr:   )r%   r&   r   r.   create_webhookr   resultr:   )rN   r;   rO   rP   rQ   r1   r2   rB   watched_itemsr=   rK   s              r   webhooks_creater[      s    Z 6- !NOOO
{v~ !DEEE
5
!
!
!C ''M+1;''''''tG  SX_hn ooGJ WZ000000r   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 |D             nd}	|                    | |||	|          }
t          j        d|
j                   dS )z>Update an existing webhook. Only provided options are changed.r4   Nc                     g | ]	}|j         
S r   rT   r   s     r   r8   z#webhooks_update.<locals>.<listcomp>   rV   r   )r;   r>   r=   rQ   zWebhook updatedrW   )r   r.   update_webhookr   rY   r:   )rF   r;   rN   rP   rQ   r1   r2   rB   rZ   r=   rK   s              r   webhooks_updater`      s    N 5
!
!
!C+0:L'''dM+1;''''''tG  mU\ek llGJ WZ000000r   enablezhf webhooks enable abc123z The ID of the webhook to enable.c                     t          |          }|                    |           }t          j        d|j                   dS )zEnable a disabled webhook.r4   zWebhook enabledrW   N)r   enable_webhookr   rY   r:   rJ   s        r   webhooks_enablerd      sE     5
!
!
!C  ,,GJ WZ000000r   disablezhf webhooks disable abc123z!The ID of the webhook to disable.c                     t          |          }|                    |           }t          j        d|j                   dS )zDisable an active webhook.r4   zWebhook disabledrW   N)r   disable_webhookr   rY   r:   rJ   s        r   webhooks_disablerh     sE     5
!
!
!C!!*--GJ!gj11111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          |          }|                    |            t          j        d|            dS )zDelete a webhook permanently.z)Are you sure you want to delete webhook 'z'?)rj   r4   zWebhook deletedrW   N)r   confirmr   delete_webhookrY   )rF   rj   r1   r2   rB   s        r   webhooks_deletern     sf    * KJJJJJPSTTTT
5
!
!
!Cz"""J Z00000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autorD   ArgumentrL   Optionr[   r`   rd   rh   boolrn   r   r   r   <module>r      s   4  6 6 6 6 6 6 6 6 6 6  6 6 6 6 6 6 5 5 5 5 5 5            / . . . . . . . ..);<<VDEE$)-/M/Mn/M/M/MTWXXX)**	/+H+H-+H+H+HsSSSc t,>'?    8 }"?@@@       !5 9  
   & 
!    !5 9 #~u~3KLLLLM  
	         & 	 	 	 	 4 9?-1 -1S	e	
 	
 	
	-1 
d
^___	a
-1 d
p	
 	
 	
	-1& ]d"a	
 	
 	
	'-14 d
JKKK	M5-1< =-1> ?-1@ 
A-1 -1 -1 -1`       	 	 	 	 4 99#1 #1#~u~3UVVVVW#1	d
@AAA	C
#1 S	DI	
 	
 	
		#1  ]d"U	
 	
 	
	!#1. d
EFFF	H/#16 7#18 9#1: 
;#1 #1 #1 #1L #    !5 91 1#~u~3UVVVVW11 1 
	1 1 1 1 $    !5 92 2#~u~3VWWWWX22 2 
	2 2 2 2 #)     	 4 91 1#~u~3UVVVVW1	,	
 	
 	
	
1 1 1 
1 1 1 1 1 1r   