o
    wi                     @  s  U 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
 d dlmZ d dl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/m0Z0 e*j1fZ2de3d< 	 e j4fZ5de3d< 	 e6e*j7e*j8e*j9hZ:de3d< 	 e6e 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ZAd!e3d"< G d#d$ d$eZBdAd'd(ZCdBd*d+ZDG d,d- d-e
d.d/ZEG d0d1 d1ed2d3d4ZF	5dCdDd:d;ZG	5dCdEd>d?ZHd5S )F    )annotations)
Collection)	AnnotatedAnyFinalOptionalProtocol	TypedDict)Field)SelfUnpack)GQLIdGQLInputcomputed_fieldmodel_validatorto_json   )MongoLikeFilter)CreateFilterTriggerInputQueueJobActionInputTriggeredActionConfigUpdateFilterTriggerInput)parse_input_action)
ActionType	DoNothingInputActionSavedActionSendNotificationSendWebhook)
AutomationNewAutomation)	EventType
InputEventRunMetricFilter_WrappedSavedEventFilter)AutomationScope	ScopeTypezFinal[Collection[EventType]]INVALID_INPUT_EVENTSzFinal[Collection[ActionType]]INVALID_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   L/home/ubuntu/.local/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_idC   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 )InputActionConfigz<Prepares action configuration data 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?   P   s   
 r?   SavedAction | InputActiondict[str, Any]c                 C  s$   t | } tdi t| j | i S )zNests the action input under the correct key for `TriggeredActionConfig`.

    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
t| jS t| S )zUnnests (if needed) and serializes an `EventFilter` input to JSON.

    This is necessary to conform to the schemas for:
    - `CreateFilterTriggerInput`
    - `UpdateFilterTriggerInput`
    )
isinstancer$   r   filterr8   r2   r2   r3   prepare_event_filter_inputi   s   

rI   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   rJ   |   s   
 rJ   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,   rK   NzOptional[str]rL   TrM   rN   z*Annotated[InputEvent, Field(exclude=True)]rP   z+Annotated[InputAction, Field(exclude=True)]rQ   r6   r&   c                 C  
   | j jjS N)rP   rO   
scope_typeselfr2   r2   r3   rV         
zValidatedCreateInput.scope_typer   c                 C  rT   rU   )rP   rO   r-   rW   r2   r2   r3   scope_id   rY   zValidatedCreateInput.scope_idr!   c                 C     | j jS rU   )rP   
event_typerW   r2   r2   r3   triggering_event_type      z*ValidatedCreateInput.triggering_event_typec                 C  s   t | jjS rU   )rI   rP   rH   rW   r2   r2   r3   event_filter   s   z!ValidatedCreateInput.event_filterr   c                 C  r[   rU   )rQ   rC   rW   r2   r2   r3   triggered_action_type   r^   z*ValidatedCreateInput.triggered_action_typerB   c                 C  s
   t | jS rU   )rE   rQ   rW   r2   r2   r3   triggered_action_config   rY   z,ValidatedCreateInput.triggered_action_configafter)moder   c                 C  "   | j j }tv rt|d| S )Nz* events cannot be assigned to automations.)rP   r\   r'   
ValueErrorrX   type_r2   r2   r3   _forbid_legacy_event_types      z/ValidatedCreateInput._forbid_legacy_event_typesc                 C  rd   )Nz+ actions cannot be assigned to automations.)rQ   rC   r(   re   rf   r2   r2   r3   _forbid_legacy_action_types   ri   z0ValidatedCreateInput._forbid_legacy_action_types)r6   r&   )r6   r   )r6   r!   )r6   r,   )r6   r   )r6   rB   )r6   r   )r.   r/   r0   r@   r1   rL   rN   r   rV   rZ   r]   r_   r`   ra   r   rh   rj   r2   r2   r2   r3   rS      s.   
 rS   forbidT)extrafrozenNNewAutomation | NonekwargsUnpack[WriteAutomationsKwargs]r   c                K  s0   | r
i |   |n|}tdi |}t|S )zBPrepares the payload to create an automation in a GraphQL request.Nr2   )rD   rS   r   model_validate)r4   ro   obj_dictvobjr2   r2   r3   prepare_to_create   s   	
rt   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-   rK   rL   rN   rV   rZ   r]   r_   r`   ra   Nr2   )r   dictr   r-   rK   rL   rN   rO   rV   rP   r\   rI   rH   rQ   rC   rE   )r4   ro   rs   r2   r2   r3   prepare_to_update   s   	
rw   )r4   r5   r6   r,   )r4   rA   r6   rB   )r4   rF   r6   r,   rU   )r4   rn   ro   rp   r6   r   )r4   ru   ro   rp   r6   r   )I
__future__r   collections.abcr   typingr   r   r   r   r   r	   pydanticr
   typing_extensionsr   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&   UPDATE_ARTIFACT_ALIASr'   r1   	QUEUE_JOBr(   	frozensetCREATE_ARTIFACTLINK_ARTIFACTADD_ARTIFACT_ALIASr)   NOTIFICATIONGENERIC_WEBHOOKr*   r+   r9   NO_OPr>   r?   rE   rI   rJ   rS   rt   rw   r2   r2   r2   r3   <module>   s\      


: