
    qi&                        d Z ddlZddlZddlmZ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mZmZ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j?                  dg d      ej@                  ddfdedededdfd       Z!ej?                  ddg      	 dGdee ejD                  d      f   deddfd       Z#ej?                  dg d      	 	 	 	 	 dHd eee    ejH                  d!d"      f   d#eee    ejH                  d$      f   d%eee    ejH                  d&d'      f   d(eeee       ejH                  d)d*      f   d+eee    ejH                  d,      f   deddfd-       Z%ej?                  d.g d/      	 	 	 	 	 dHdee ejD                  d0      f   d#eee    ejH                  d1      f   d eeee       ejH                  d!d2      f   d(eeee       ejH                  d)d3      f   d+eee    ejH                  d4      f   deddfd5       Z&ej?                  d6d7g      	 dGdee ejD                  d8      f   deddfd9       Z'ej?                  d:d;g      	 dGdee ejD                  d<      f   deddfd=       Z(ej?                  d>d?d@g      	 	 dIdee ejD                  dA      f   dBee) ejH                  dCdDdE      f   deddfdF       Z*yc c} w c c}w )Ja  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Optionalget_argsget_type_hints)WEBHOOK_DOMAIN_T)WebhookWatchedItem   )	FormatOptOutputFormatQuietOptTokenOptapi_object_to_dict
get_hf_apiprint_list_outputtyper_factory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: , .r	   zInvalid type ')r   name)tuple_WATCHED_TYPEStyperBadParameterjoinsplitappendr   )r   itemsvalid_typesvkindr   s         N/opt/pipecat/venv/lib/python3.12/site-packages/huggingface_hub/cli/webhooks.py_parse_watchr(   E   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 -q)examplesFformatquiettokenc                     t        |      }|j                         D cg c]  }t        |       }}t        || |g dd        yc c}w )z'List all webhooks for the current user.r.   )idurldisableddomainswatchedc           
         | j                  dd      | j                  d      xs dt        | j                  dd            dj                  | j                  d      xs g       dj                  d	 | j                  d
      xs g D              gS )Nr1    r2   z(job)r3   Fr   r4   c              3   l   K   | ],  }t        |t              r|d     d|d    n
t        |       . yw)r   r   r   N)
isinstancedictstr).0ws     r'   	<genexpr>z0webhooks_ls.<locals>.<lambda>.<locals>.<genexpr>~   s:      RSjD.A1V9+Qqyk*s1vMs   24r5   )getr;   r    )items    r'   <lambda>zwebhooks_ls.<locals>.<lambda>y   s    HHT2HHUO&wU+,IIdhhy)/R0II X\X`X`ajXkXqoq 
 r)   )r,   r-   headersrow_fnN)r   list_webhooksr   r   )r,   r-   r.   apir=   resultss         r'   webhooks_lsrG   d   sO     5
!C.1.?.?.AB!!$BGB?
 Cs   Ainfozhf webhooks info abc123
webhook_idzThe ID of the webhook.c                     t        |      }|j                  |       }t        t        j                  t        |      d             y)z/Show full details for a single webhook as JSON.r0      indentN)r   get_webhookprintjsondumpsr   rI   r.   rE   webhooks       r'   webhooks_inforT      s5     5
!Cooj)G	$**'0
;<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.r2   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 cg c]  }|j                   c}nd}	|j                  ||||	|      }
t        d|
j                          t        t        j                  t        |
      d             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.r0   )r2   rW   r5   r4   rY   zWebhook created: rK   rL   )r   r   r   r(   valuecreate_webhookrO   r1   rP   rQ   r   )rV   r2   rW   rX   rY   r.   rE   watched_itemsdr4   rS   s              r'   webhooks_creater_      s    X 6-  !NOO
{v~  !DEE
5
!C 'M+1'1qww'tG  SX_hn oG	gjj\
*+	$**'0
;< (s   C 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	        d|
j
                          t	        t        j                  t        |
      d             yc c}w )z>Update an existing webhook. Only provided options are changed.r0   N)r2   r5   r4   rY   zWebhook updated: rK   rL   )	r   r(   r[   update_webhookrO   r1   rP   rQ   r   )rI   r2   rV   rX   rY   r.   rE   r]   r^   r4   rS   s              r'   webhooks_updaterc      s    L 5
!C+0L'dM+1'1qww'tG  mU\ek lG	gjj\
*+	$**'0
;< (s   Benablezhf webhooks enable abc123z The ID of the webhook to enable.c                 n    t        |      }|j                  |       }t        d|j                          y)zEnable a disabled webhook.r0   zWebhook enabled: N)r   enable_webhookrO   r1   rR   s       r'   webhooks_enablerg      s2     5
!C  ,G	gjj\
*+r)   disablezhf webhooks disable abc123z!The ID of the webhook to disable.c                 n    t        |      }|j                  |       }t        d|j                          y)zDisable an active webhook.r0   zWebhook disabled: N)r   disable_webhookrO   r1   rR   s       r'   webhooks_disablerk     s2     5
!C!!*-G	wzzl
+,r)   deletezhf webhooks delete abc123zhf webhooks delete abc123 --yesz The ID of the webhook to delete.yesz--yesz-yzSkip confirmation prompt.c                     |s:t        j                  d|  d      }|st        d       t        j                         t	        |      }|j                  |        t        d|         y)zDelete a webhook permanently.z)Are you sure you want to delete webhook 'z'?zAborted.r0   zWebhook deleted: N)r   confirmrO   Abortr   delete_webhook)rI   rm   r.   ro   rE   s        r'   webhooks_deleterr     s_    ( --"KJ<WY Z[*++-
5
!Cz"	j\
*+r)   )N)NNNNN)FN)+__doc__enumrP   typingr   r   r   r   r   huggingface_hub.constantsr   huggingface_hub.hf_apir   
_cli_utilsr
   r   r   r   r   r   r   r   r   Enumr;   r   _DOMAIN_TYPESr   listr(   webhooks_clicommandtablerG   ArgumentrT   Optionr_   rc   rg   rk   boolrr   )tr^   s   00r'   <module>r      sk  4   @ @  6 5	 	 	 .);<VDE$))-n/M1/MTWX)*		/-+HQAqD+HsSc t,>'? 8 "?@    %**  
	2 
!   =#~u~~3KLLM== 
==   & 	 	 	 	=-=S	e	
	-= 
^_	a
-= p	
	-=& m$%a	
	'-=4 JK	M5-=< =-=> 
?-=-=`    	 	 	 	7#=#~u~~3UVVW#=	@A	C
#= cI	
		#=  m$%U	
	!#=. EF	H/#=6 7#=8 
9#=#=L #   ,#~u~~3UVVW,, 
,, $   -#~u~~3VWWX-- 
-- #)    	,#~u~~3UVVW,	,	
	
, , 
,,G 0N ,Is   
M
	
M
