o
    -wiM                      @  s  U d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZmZmZmZ ddlmZ ddlmZmZmZmZ dd	lmZ dd
lmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ e0e)j1hZ2de3d< 	 e0ej4hZ5de3d< 	 e0e)j6e)j7e)j8hZ9de3d< 	 e0ej:ej;hZ<de3d< 	 G dd deZ=d?ddZ>ej:dej;dej?dej4diZ@d e3d!< G d"d# d#eZAd@d&d'ZBdAd)d*ZCG d+d, d,ed-d.ZDG d/d0 d0ed1d2d3ZE	4dBdCd9d:ZF	4dBdDd=d>ZGd4S )E    )annotations)Any
CollectionFinalOptionalProtocol	TypedDict)Field)	AnnotatedSelfUnpack)GQLBaseGQLIdcomputed_fieldmodel_validatorto_json   )MongoLikeFilter)CreateFilterTriggerInputQueueJobActionInputTriggeredActionConfigUpdateFilterTriggerInput)to_input_action)
ActionType	DoNothingInputActionSavedActionSendNotificationSendWebhook)
AutomationNewAutomation)	EventType
InputEventRunMetricFilter_WrappedSavedEventFilter)AutomationScope	ScopeTypezFinal[Collection[EventType]]EXCLUDED_INPUT_EVENTSzFinal[Collection[ActionType]]EXCLUDED_INPUT_ACTIONSALWAYS_SUPPORTED_EVENTSALWAYS_SUPPORTED_ACTIONSc                   @  s   e Zd ZU ded< dS )HasIdstridN)__name__
__module____qualname____annotations__ r2   r2   U/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/automations/_utils.pyr+   >   s   
 r+   objHasId | strreturnr,   c                 C  s   t | dr| jS | S )Nr-   )hasattrr-   r4   r2   r2   r3   
extract_idB   s   r9   notification_action_inputgeneric_webhook_action_inputno_op_action_inputqueue_job_action_inputzdict[ActionType, str]ACTION_CONFIG_KEYSc                   @  sB   e Zd ZU dZdZded< dZded< dZded< dZd	ed
< dS )InputActionConfigzSA `TriggeredActionConfig` that prepares the action config for saving an automation.NzOptional[QueueJobActionInput]r=   zOptional[SendNotification]r:   zOptional[SendWebhook]r;   zOptional[DoNothing]r<   )	r.   r/   r0   __doc__r=   r1   r:   r;   r<   r2   r2   r2   r3   r?   O   s   
 r?   SavedAction | InputActiondict[str, Any]c                 C  s$   t | } tdi t| j | i S )zPrepare the `TriggeredActionConfig` input, nesting the action input inside the appropriate key.

    This is necessary to conform to the schemas for:
    - CreateFilterTriggerInput
    - UpdateFilterTriggerInput
    Nr2   )r   r?   r>   action_type
model_dumpr8   r2   r2   r3   prepare_action_config_input\   s   rE   <_WrappedSavedEventFilter | MongoLikeFilter | RunMetricFilterc                 C  s   t | tr| jn| }t|S )zPrepare the `EventFilter` input, unnesting the filter if needed and serializing to JSON.

    This is necessary to conform to the schemas for:
    - CreateFilterTriggerInput
    - UpdateFilterTriggerInput
    )
isinstancer$   filterr   )r4   filter_to_serializer2   r2   r3   prepare_event_filter_inputh   s   rJ   c                   @  sB   e Zd ZU dZded< ded< ded< ded< d	ed
< ded< dS )WriteAutomationsKwargszGKeyword arguments that can be passed to create or update an automation.r,   namedescriptionboolenabledr%   scoper"   eventr   actionN)r.   r/   r0   r@   r1   r2   r2   r2   r3   rK   |   s   
 rK   F)totalc                   @  s   e Zd ZU dZded< dZded< dZded	< d
ed< ded< ed'ddZed(ddZ	ed)ddZ
ed*ddZed+ddZed,ddZed d!d-d#d$Zed d!d-d%d&ZdS ).ValidatedCreateInputzValidated automation parameters, prepared for creating a new automation.

    Note: Users should never need to instantiate this class directly.
    r,   rL   NzOptional[str]rM   TrN   rO   z*Annotated[InputEvent, Field(exclude=True)]rQ   z+Annotated[InputAction, Field(exclude=True)]rR   r6   r&   c                 C  
   | j jjS N)rQ   rP   
scope_typeselfr2   r2   r3   rW         
zValidatedCreateInput.scope_typer   c                 C  rU   rV   )rQ   rP   r-   rX   r2   r2   r3   scope_id   rZ   zValidatedCreateInput.scope_idr!   c                 C     | j jS rV   )rQ   
event_typerX   r2   r2   r3   triggering_event_type      z*ValidatedCreateInput.triggering_event_typec                 C  s   t | jjS rV   )rJ   rQ   rH   rX   r2   r2   r3   event_filter   s   z!ValidatedCreateInput.event_filterr   c                 C  r\   rV   )rR   rC   rX   r2   r2   r3   triggered_action_type   r_   z*ValidatedCreateInput.triggered_action_typerB   c                 C  s
   t | jS rV   )rE   rR   rX   r2   r2   r3   triggered_action_config   rZ   z,ValidatedCreateInput.triggered_action_configafter)moder   c                 C  "   | j j }tv rt|d| S )Nz* events cannot be assigned to automations.)rQ   r]   r'   
ValueErrorrY   type_r2   r2   r3   _forbid_legacy_event_types      z/ValidatedCreateInput._forbid_legacy_event_typesc                 C  re   )Nz+ actions cannot be assigned to automations.)rR   rC   r(   rf   rg   r2   r2   r3   _forbid_legacy_action_types   rj   z0ValidatedCreateInput._forbid_legacy_action_types)r6   r&   )r6   r   )r6   r!   )r6   r,   )r6   r   )r6   rB   )r6   r   )r.   r/   r0   r@   r1   rM   rO   r   rW   r[   r^   r`   ra   rb   r   ri   rk   r2   r2   r2   r3   rT      s.   
 rT   forbidT)extrafrozenNNewAutomation | NonekwargsUnpack[WriteAutomationsKwargs]r   c                K  s4   | ri | j dd|n|}tdi |}t|S )zBPrepares the payload to create an automation in a GraphQL request.T)exclude_noneNr2   )rD   rT   r   model_validate)r4   rp   obj_dict	validatedr2   r2   r3   prepare_to_create   s   
rv   Automation | Noner   c                K  s`   t di i t| pi |}t|j|j|j|j|jj|jj|j	j
t|j	j|jjt|jd
S )zBPrepares the payload to update an automation in a GraphQL request.)
r-   rL   rM   rO   rW   r[   r^   r`   ra   rb   Nr2   )r   dictr   r-   rL   rM   rO   rP   rW   rQ   r]   rJ   rH   rR   rC   rE   )r4   rp   v_objr2   r2   r3   prepare_to_update   s   	
rz   )r4   r5   r6   r,   )r4   rA   r6   rB   )r4   rF   r6   r,   rV   )r4   ro   rp   rq   r6   r   )r4   rw   rp   rq   r6   r   )H
__future__r   typingr   r   r   r   r   r   pydanticr	   typing_extensionsr
   r   r   wandb._pydanticr   r   r   r   r   _filtersr   
_generatedr   r   r   r   _validatorsr   actionsr   r   r   r   r   r   automationsr   r    eventsr!   r"   r#   r$   scopesr%   r&   	frozensetUPDATE_ARTIFACT_ALIASr'   r1   	QUEUE_JOBr(   CREATE_ARTIFACTLINK_ARTIFACTADD_ARTIFACT_ALIASr)   NOTIFICATIONGENERIC_WEBHOOKr*   r+   r9   NO_OPr>   r?   rE   rJ   rK   rT   rv   rz   r2   r2   r2   r3   <module>   sf      


: