o
    ils                    @  s	  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZmZ dd	lmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)Z*ddl+Z*ddl,Z*dd
l-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3 ddl4Z5ddl6Z5ddl7Z5ddl8Z5ddl9Z5ddl:Z5ddl;Z5ddl<Z5ddl=Z5ddl>Z5ddl?Z5ddl@Z5ddlAZ5ddlBZ5ddlCZ5ddlDZ5ddlEZ5ddlFZ5ddlGZ5ddlHmIZI ddlAmJZJmKZKmLZLmMZM ddlFmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZU ddlVmWZW ddlXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb G dd dZcG dd de3ddZdG dd deZeG dd deebeaf ZfG dd deebeaf ZgeddG d d! d!ZhG d"d# d#eLZieG d$d% d%ZjeG d&d' d'ejZkG d(d) d)eZleG d*d+ d+ZmeG d,d- d-ZnG d.d/ d/ZoeddG d0d1 d1ZpeG d2d3 d3ZqG d4d5 d5ZreG d6d7 d7ZseddG d8d9 d9ZteG d:d; d;ZueG d<d= d=ZvG d>d? d?eZweG d@dA dAewZxG dBdC dCeZyeG dDdE dEZzeG dFdG dGZ{eG dHdI dIZ|eG dJdK dKZ}eG dLdM dMZ~eG dNdO dOZG dPdQ dQeZeG dRdS dSeZeG dTdU dUZeG dVdW dWZeG dXdY dYZeG dZd[ d[ZeG d\d] d]ZG d^d_ d_eZeG d`da daeZeG dbdc dcZeG ddde deZG dfdg dgZG dhdi dieeZ ZG djdk dkeZG dldm dme5jjZG dndo doe5jjZG dpdq dqe5jjZG drds dse5jjZG dtdu due5jjZG dvdw dwe5jjZG dxdy dyeZG dzd{ d{e5jjZG d|d} d}e5jjZeG d~d dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZG dd dZG dd deZdddɄZd dd΄Ze
dϡZdddՄZddd؄ZeddG ddڄ dڃZeddG dd܄ d܃ZG ddބ deZeddG dd deZeddG dd deZeddG dd deZeddG dd deZeddG dd deZeddG dd dZeddG dd dZG dd deZG dd dZe5jjZ͐dddZΐdddZG dd dejZdS (  zClient for accessing Temporal.    )annotationsN)ABCabstractmethod)Future)	dataclass)datetime	timedeltatimezone)EnumIntEnum)AnyAsyncIterator	AwaitableCallableDict	FrozenSetGenericIterableMappingOptionalSequenceTextTupleTypeUnioncastoverload)
MessageMap)ConcatenateRequiredSelf	TypedDict)ActivityCancellationDetails)DataConverterSerializationContextWithSerializationContextWorkflowSerializationContext)ConnectConfigHttpConnectProxyConfigKeepAliveConfigRetryConfigRPCErrorRPCStatusCodeServiceClient	TLSConfig   )HeaderCodecBehavior)
AnyTypeLocalReturnTypeMethodAsyncNoParamMethodAsyncSingleParamMethodSyncOrAsyncNoParamMethodSyncOrAsyncSingleParamMultiParamSpec	ParamType
ReturnTypeSelfTypec                   @  s  e Zd ZdZeddejjjg g ddde	ji dddde
jddd&d'Zdejjjg g de
jd(dd+d,Zdd/d0Zdd1d2Zedd3d4Zedd6d7Zedd9d:Zedd<d=Zedd>d?Zedd@dAZeddBdCZeddDdEZejddHdEZeddIdJZejddKdJZedddejjjejjj ddLddddddg i ddejj!jddMddndoZ"edddejjjejjj ddLddddddg i ddejj!jddMddsdoZ"edddejjjejjj ddLddddddg i ddejj!jddMddvdoZ"eejj#fg ddddejjjejjj ddLddddddg i ddejj!jddwd d|doZ"ejj#fg ddddejjjejjj ddLddddddg i ddejj!jdg g dd}d~dddoZ"edddejjjejjj ddLddddddg i ddejj!jddMdddZ$edddejjjejjj ddLddddddg i ddejj!jddMdddZ$edddejjjejjj ddLddddddg i ddejj!jddMdddZ$eejj#fg ddddejjjejjj ddLddddddg i ddejj!jddwdddZ$ejj#fg ddddejjjejjj ddLddddddg i ddejj!jddwdddZ$dddddddZ%ddddddZ&edi ddd	ddZ'edi ddd
ddZ'edi dddddZ'eejj#fg ddi dddddZ'ejj#fg ddi dddddZ'edi dddddZ(edi dddddZ(edi dddddZ(eejj#fg ddi dddddZ(ejj#fg ddi dddddZ(ejj#fg ddi dddddZ)	ddddi dddddÄZ*di dfdddƄZ+edddʄZ,edddʄZ,dddddΜdddʄZ,dg ddddi ddМddd؄Z-dddڄZ.	dddi ddۜdddބZ/i dfdddZ0di dfdddZ1g di dfdddZ2dS (   Clienta  Client for accessing Temporal.

    Most users will use :py:meth:`connect` to create a client. The
    :py:attr:`service` property provides access to a raw gRPC client. To create
    another client, like for a different namespace, :py:func:`Client` may be
    directly instantiated with a :py:attr:`service` of another.

    Clients are not thread-safe and should only be used in the event loop they
    are first connected in. If a client needs to be used from another thread
    than where it was created, make sure the event loop where it was created is
    captured, and then call :py:func:`asyncio.run_coroutine_threadsafe` with the
    client call and that event loop.

    Clients do not work across forks since runtimes do not work across forks.
    defaultNF)	namespaceapi_keydata_converterpluginsinterceptors'default_workflow_query_reject_conditiontlsretry_configkeep_alive_configrpc_metadataidentitylazyruntimehttp_connect_proxy_configheader_codec_behaviortarget_hoststrr=   r>   Optional[str]r?   "temporalio.converter.DataConverterr@   Sequence[Plugin]rA   Sequence[Interceptor]rB   0Optional[temporalio.common.QueryRejectCondition]rC   Union[bool, TLSConfig]rD   Optional[RetryConfig]rE   Optional[KeepAliveConfig]rF   Mapping[str, Union[str, bytes]]rG   rH   boolrI   $Optional[temporalio.runtime.Runtime]rJ    Optional[HttpConnectProxyConfig]rK   r0   returnr    c                  sp   t jj||||	|
||pd|||d
}dd }tj}t|D ]}|||}q||I dH }| |||||||dS )a6  Connect to a Temporal server.

        Args:
            target_host: ``host:port`` for the Temporal server. For local
                development, this is often "localhost:7233".
            namespace: Namespace to use for client calls.
            api_key: API key for Temporal. This becomes the "Authorization"
                HTTP header with "Bearer " prepended. This is only set if RPC
                metadata doesn't already have an "authorization" key.
            data_converter: Data converter to use for all data conversions
                to/from payloads.
            plugins: Set of plugins that are chained together to allow
                intercepting and modifying client creation and service connection.
                The earlier plugins wrap the later ones.

                Any plugins that also implement
                :py:class:`temporalio.worker.Plugin` will be used as worker
                plugins too so they should not be given when creating a
                worker.
            interceptors: Set of interceptors that are chained together to allow
                intercepting of client calls. The earlier interceptors wrap the
                later ones.

                Any interceptors that also implement
                :py:class:`temporalio.worker.Interceptor` will be used as worker
                interceptors too so they should not be given when creating a
                worker.
            default_workflow_query_reject_condition: The default rejection
                condition for workflow queries if not set during query. See
                :py:meth:`WorkflowHandle.query` for details on the rejection
                condition.
            tls: If false, the default, do not use TLS. If true, use system
                default TLS configuration. If TLS configuration present, that
                TLS configuration will be used.
            retry_config: Retry configuration for direct service calls (when
                opted in) or all high-level calls made by this client (which all
                opt-in to retries by default). If unset, a default retry
                configuration is used.
            keep_alive_config: Keep-alive configuration for the client
                connection. Default is to check every 30s and kill the
                connection if a response doesn't come back in 15s. Can be set to
                ``None`` to disable.
            rpc_metadata: Headers to use for all calls to the server. Keys here
                can be overriden by per-call RPC metadata keys.
            identity: Identity for this client. If unset, a default is created
                based on the version of the SDK.
            lazy: If true, the client will not connect until the first call is
                attempted or a worker is created with it. Lazy clients cannot be
                used for workers.
            runtime: The runtime for this client, or the default if unset.
            http_connect_proxy_config: Configuration for HTTP CONNECT proxy.
            header_codec_behavior: Encoding behavior for headers sent by the client.
         
rL   r>   rC   rD   rE   rF   rG   rH   rI   rJ   c                   s    fddS )Nc                   s    |  S N)connect_service_client)confignextplugin W/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/temporalio/client.py<lambda>   s    z5Client.connect.<locals>.make_lambda.<locals>.<lambda>rc   )rb   ra   rc   r`   rd   make_lambda   s   z#Client.connect.<locals>.make_lambdaN)r=   r?   rA   rB   rK   r@   )
temporalioservicer'   r-   connectreversed)clsrL   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   connect_configrf   next_functionrb   service_clientrc   rc   rd   ri   s   s6   LzClient.connect)r=   r?   r@   rA   rB   rK   rn    temporalio.service.ServiceClientc          
   	   C  s8   t |||||||d}|D ]}	|	|}q| | dS )zwCreate a Temporal client from a service client.

        See :py:meth:`connect` for details on the parameters.
        )rn   r=   r?   rA   rB   rK   r@   N)ClientConfigconfigure_client_init_from_config)
selfrn   r=   r?   r@   rA   rB   rK   r_   rb   rc   rc   rd   __init__   s   
zClient.__init__r_   rp   c                 C  s:   || _ t| | _tt| j d D ]	}|| j| _qd S )NrA   )_config_ClientImpl_implrj   listintercept_client)rs   r_   interceptorrc   rc   rd   rr      s
   
zClient._init_from_configc                 C  s   | j  }t|d |d< |S )zyConfig, as a dictionary, used to create this client.

        This makes a shallow copy of the config each call.
        rA   )ru   copyrx   rs   r_   rc   rc   rd   r_     s   
zClient.configc                 C  
   | j d S )Raw gRPC service client.rn   ru   rs   rc   rc   rd   rn        
zClient.service_client"temporalio.service.WorkflowServicec                 C     | j d jS )z!Raw gRPC workflow service client.rn   )ru   workflow_servicer   rc   rc   rd   r        zClient.workflow_service"temporalio.service.OperatorServicec                 C  r   )z!Raw gRPC operator service client.rn   )ru   operator_servicer   rc   rc   rd   r     r   zClient.operator_servicetemporalio.service.TestServicec                 C  r   )zRaw gRPC test service client.rn   )ru   test_servicer   rc   rc   rd   r      r   zClient.test_servicec                 C  r}   )z'Namespace used in calls by this client.r=   r   r   rc   rc   rd   r=   %  r   zClient.namespacec                 C  s   | j d jjS )&Identity used in calls by this client.rn   )ru   r_   rG   r   rc   rc   rd   rG   *  s   zClient.identityc                 C  r}   )z#Data converter used by this client.r?   r   r   rc   rc   rd   r?   /  r   zClient.data_converterc                 C  
   | j jjS )zHeaders for every call made by this client.

        Do not use mutate this mapping. Rather, set this property with an
        entirely new mapping to change the headers.
        rn   r_   rF   r   rc   rc   rd   rF   4     
zClient.rpc_metadatavalueNonec                 C  s   | j | || j j_dS )a%  Update the headers for this client.

        Do not mutate this mapping after set. Rather, set an entirely new
        mapping if changes are needed.

        Raises:
            TypeError: the key/value pair is not a valid gRPC ASCII or binary metadata.
                All binary metadata must be supplied as bytes, and the key must end in '-bin'.

        .. warning::
            Attempting to set an invalid binary RPC metadata value may leave the client
            in an inconsistent state (as well as raise a :py:class:`TypeError`).
        N)rn   update_rpc_metadatar_   rF   rs   r   rc   rc   rd   rF   =  s   c                 C  r   z+API key for every call made by this client.rn   r_   r>   r   rc   rc   rd   r>   Q  r   zClient.api_keyc                 C     || j j_| j | dS zUpdate the API key for this client.

        This is only set if RPCmetadata doesn't already have an "authorization"
        key.
        Nrn   r_   r>   update_api_keyr   rc   rc   rd   r>   V     
r[   )execution_timeoutrun_timeouttask_timeoutid_reuse_policyid_conflict_policyretry_policycron_schedulememosearch_attributesstatic_summarystatic_detailsstart_delaystart_signalstart_signal_argsrF   rpc_timeoutrequest_eager_startpriorityversioning_overrideworkflow(MethodAsyncNoParam[SelfType, ReturnType]id
task_queuer   Optional[timedelta]r   r   r   'temporalio.common.WorkflowIDReusePolicyr   *temporalio.common.WorkflowIDConflictPolicyr   'Optional[temporalio.common.RetryPolicy]r   r   Optional[Mapping[str, Any]]r   \Optional[Union[temporalio.common.TypedSearchAttributes, temporalio.common.SearchAttributes]]r   r   r   r   r   Sequence[Any]r   r   r   temporalio.common.Priorityr   .Optional[temporalio.common.VersioningOverride]$WorkflowHandle[SelfType, ReturnType]c                     d S r]   rc   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   rc   rc   rd   start_workflowb     zClient.start_workflow7MethodAsyncSingleParam[SelfType, ParamType, ReturnType]argr8   c                  r   r]   rc   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   rc   rc   rd   r         FCallable[Concatenate[SelfType, MultiParamSpec], Awaitable[ReturnType]]argsc                  r   r]   rc   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   rc   rc   rd   r        ")r   result_typer   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r   r   Optional[type]WorkflowHandle[Any, Any]c                  r   r]   rc   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   rc   rc   rd   r     r      )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   	callbacksworkflow_event_links
request_idstack_level)Union[str, Callable[..., Awaitable[Any]]]r   Sequence[Callback]r   5Sequence[temporalio.api.common.v1.Link.WorkflowEvent]r   r   intc              
     s*  t jj||d t jj|\}}| jtdi d|dt j	||d|d|d|d|d|	d	|
d
|d|d|d|d|d|d|di d|d|d|d|d|py|d|d|d|d|d|d|d|I dH S d|d|d|d|d|d|d|I dH S ) a{  Start a workflow and return its handle.

        Args:
            workflow: String name or class method decorated with
                ``@workflow.run`` for the workflow to start.
            arg: Single argument to the workflow.
            args: Multiple arguments to the workflow. Cannot be set if arg is.
            id: Unique identifier for the workflow execution.
            task_queue: Task queue to run the workflow on.
            result_type: For string workflows, this can set the specific result
                type hint to deserialize into.
            execution_timeout: Total workflow execution timeout including
                retries and continue as new.
            run_timeout: Timeout of a single workflow run.
            task_timeout: Timeout of a single workflow task.
            id_conflict_policy: Behavior when a workflow is currently running with the same ID.
                Default is UNSPECIFIED, which effectively means fail the start attempt.
                Set to USE_EXISTING for idempotent deduplication on workflow ID.
                Cannot be set if ``id_reuse_policy`` is set to TERMINATE_IF_RUNNING.
            id_reuse_policy: Behavior when a closed workflow with the same ID exists.
                Default is ALLOW_DUPLICATE.
            retry_policy: Retry policy for the workflow.
            cron_schedule: See https://docs.temporal.io/docs/content/what-is-a-temporal-cron-job/
            memo: Memo for the workflow.
            search_attributes: Search attributes for the workflow. The
                dictionary form of this is deprecated, use
                :py:class:`temporalio.common.TypedSearchAttributes`.
            static_summary: A single-line fixed summary for this workflow execution that may appear
                in the UI/CLI. This can be in single-line Temporal markdown format.
            static_details: General fixed details for this workflow execution that may appear in
                UI/CLI. This can be in Temporal markdown format and can span multiple lines. This is
                a fixed value on the workflow that cannot be updated. For details that can be
                updated, use :py:meth:`temporalio.workflow.get_current_details` within the workflow.
            start_delay: Amount of time to wait before starting the workflow.
                This does not work with ``cron_schedule``.
            start_signal: If present, this signal is sent as signal-with-start
                instead of traditional workflow start.
            start_signal_args: Arguments for start_signal if start_signal
                present.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
            request_eager_start: Potentially reduce the latency to start this workflow by
                encouraging the server to start it on a local worker running with
                this same client.
            priority: Priority of the workflow execution.
            versioning_override: Overrides the versioning behavior for this workflow.

        Returns:
            A workflow handle to the started workflow.

        Raises:
            temporalio.exceptions.WorkflowAlreadyStartedError: Workflow has
                already been started.
            RPCError: Workflow could not be started for some other reason.
        r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   headersr   r   r   r   ret_typerF   r   r   r   r   r   r   Nrc   )
rg   common%_warn_on_deprecated_search_attributesr   _Definitionget_name_and_result_typerw   r   StartWorkflowInput_arg_or_args) rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r   r   r   r   nameresult_type_from_type_hintrc   rc   rd   r     s   c	


r9   c                  r   r]   rc   r   rc   rc   rd   execute_workflow{  r   zClient.execute_workflowc                  r   r]   rc   r   rc   rc   rd   r     r   c                  r   r]   rc   r   rc   rc   rd   r     r   c                  r   r]   rc   r   rc   rc   rd   r     r   c                  s   | j ||fi d|d|d|d|d|d|d|	d|
d	|d
|d|d|d|d|d|d|d|d|d|d|d|d|d|ddI dH  I dH S )zStart a workflow and wait for completion.

        This is a shortcut for :py:meth:`start_workflow` +
        :py:meth:`WorkflowHandle.result`.
        r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r      N)r   resultr   rc   rc   rd   r   	  sn   *	
run_idfirst_execution_run_idr   workflow_idr   r   Optional[Type]c                C  s   t | |||||dS )a  Get a workflow handle to an existing workflow by its ID.

        Args:
            workflow_id: Workflow ID to get a handle to.
            run_id: Run ID that will be used for all calls.
            first_execution_run_id: First execution run ID used for cancellation
                and termination.
            result_type: The result type to deserialize into if known.

        Returns:
            The workflow handle.
        )r   result_run_idr   r   )WorkflowHandle)rs   r   r   r   r   rc   rc   rd   get_workflow_handleQ  s   zClient.get_workflow_handle)r   r   bUnion[MethodAsyncNoParam[SelfType, ReturnType], MethodAsyncSingleParam[SelfType, Any, ReturnType]]c                C  s"   t jj|}| j||||jdS )a  Get a typed workflow handle to an existing workflow by its ID.

        This is the same as :py:meth:`get_workflow_handle` but typed.

        Args:
            workflow: The workflow run method to use for typing the handle.
            workflow_id: Workflow ID to get a handle to.
            run_id: Run ID that will be used for all calls.
            first_execution_run_id: First execution run ID used for cancellation
                and termination.

        Returns:
            The workflow handle.
        r   )rg   r   r   must_from_run_fnr   r   )rs   r   r   r   r   defnrc   rc   rd   get_workflow_handle_forn  s   zClient.get_workflow_handle_forr   rF   r   updateGtemporalio.workflow.UpdateMethodMultiParam[[SelfType], LocalReturnType]start_workflow_operation)WithStartWorkflowOperation[SelfType, Any]r2   c                  r   r]   rc   )rs   r   r   r   rF   r   rc   rc   rd   "execute_update_with_start_workflow     	z)Client.execute_update_with_start_workflowRtemporalio.workflow.UpdateMethodMultiParam[[SelfType, ParamType], LocalReturnType]c                  r   r]   rc   )rs   r   r   r   r   rF   r   rc   rc   rd   r        Ktemporalio.workflow.UpdateMethodMultiParam[MultiParamSpec, LocalReturnType]MultiParamSpec.argsc                  r   r]   rc   )rs   r   r   r   r   rF   r   rc   rc   rd   r     r   r   r   r   rF   r   $WithStartWorkflowOperation[Any, Any]c          	        r   r]   rc   )	rs   r   r   r   r   r   r   rF   r   rc   rc   rd   r     r   Union[str, Callable]c          
        s4   | j ||||tj||||d	I dH }	|	 I dH S )a  Send an update-with-start request and wait for the update to complete.

        A WorkflowIDConflictPolicy must be set in the start_workflow_operation. If the
        specified workflow execution is not running, a new workflow execution is started
        and the update is sent in the first workflow task. Alternatively if the specified
        workflow execution is running then, if the WorkflowIDConflictPolicy is
        USE_EXISTING, the update is issued against the specified workflow, and if the
        WorkflowIDConflictPolicy is FAIL, an error is returned. This call will block until
        the update has completed, and return the update result. Note that this means that
        the call will not return successfully until the update has been delivered to a
        worker.

        Args:
            update: Update function or name on the workflow. arg: Single argument to the
                update.
            args: Multiple arguments to the update. Cannot be set if arg is.
            start_workflow_operation: a WithStartWorkflowOperation definining the
                WorkflowIDConflictPolicy and how to start the workflow in the event that a
                workflow is started.
            id: ID of the update. If not set, the default is a new UUID.
            result_type: For string updates, this can set the specific result
                type hint to deserialize into.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Raises:
            WorkflowUpdateFailedError: If the update failed.
            WorkflowUpdateRPCTimeoutOrCancelledError: This update call timed out
                or was cancelled. This doesn't mean the update itself was timed out or
                cancelled.

            RPCError: There was some issue starting the workflow or sending the update to
                the workflow.
        )r   r   wait_for_stager   r   rF   r   N)_start_update_with_startWorkflowUpdateStage	COMPLETEDr   )
rs   r   r   r   r   r   r   rF   r   handlerc   rc   rd   r     s   /r   r   %WorkflowUpdateHandle[LocalReturnType]c                  r   r]   rc   )rs   r   r   r   r   rF   r   rc   rc   rd    start_update_with_start_workflow     
z'Client.start_update_with_start_workflowc                  r   r]   rc   )rs   r   r   r   r   r   rF   r   rc   rc   rd   r        c                  r   r]   rc   )rs   r   r   r   r   r   rF   r   rc   rc   rd   r   "  r  WorkflowUpdateHandle[Any]c          
        r   r]   rc   
rs   r   r   r   r   r   r   r   rF   r   rc   rc   rd   r   2  r  c          
        s$   | j |||||||||	d	I dH S )a  Send an update-with-start request and wait for it to be accepted.

        A WorkflowIDConflictPolicy must be set in the start_workflow_operation. If the
        specified workflow execution is not running, a new workflow execution is started
        and the update is sent in the first workflow task. Alternatively if the specified
        workflow execution is running then, if the WorkflowIDConflictPolicy is
        USE_EXISTING, the update is issued against the specified workflow, and if the
        WorkflowIDConflictPolicy is FAIL, an error is returned. This call will block until
        the update has been accepted, and return a WorkflowUpdateHandle. Note that this
        means that the call will not return successfully until the update has been
        delivered to a worker.

        .. warning::
           This API is experimental

        Args:
            update: Update function or name on the workflow. arg: Single argument to the
                update.
            args: Multiple arguments to the update. Cannot be set if arg is.
            start_workflow_operation: a WithStartWorkflowOperation definining the
                WorkflowIDConflictPolicy and how to start the workflow in the event that a
                workflow is started.
            wait_for_stage: Required stage to wait until returning: either ACCEPTED or
                COMPLETED. ADMITTED is not currently supported. See
                https://docs.temporal.io/workflows#update for more details.
            id: ID of the update. If not set, the default is a new UUID.
            result_type: For string updates, this can set the specific result
                type hint to deserialize into.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Raises:
            WorkflowUpdateFailedError: If the update failed.
            WorkflowUpdateRPCTimeoutOrCancelledError: This update call timed out
                or was cancelled. This doesn't mean the update itself was timed out or
                cancelled.

            RPCError: There was some issue starting the workflow or sending the update to
                the workflow.
        )r   r   r   r   r   rF   r   N)r   r  rc   rc   rd   r   A  s   60WithStartWorkflowOperation[SelfType, ReturnType]c             
     s   |t jkr
tdjrtdd_tjj|\}
}t	||
tj
||i |p*|||	|d}d fdd}dfdd}tj|||d} j|I d H S )N!ADMITTED wait stage not supportedz+WithStartWorkflowOperation cannot be reusedT)	update_idr   r   r   r   rF   r   r   start_response@temporalio.api.workflowservice.v1.StartWorkflowExecutionResponsec              	     s*   j t jj| j| jjjd d S )N)r   r   r   )_workflow_handle
set_resultr   _start_workflow_inputr   r   r   r  rs   r   rc   rd   on_start  s   z1Client._start_update_with_start.<locals>.on_starterrorBaseExceptionc                   s    j |  d S r]   )r
  set_exception)r  )r   rc   rd   on_start_error  s   z7Client._start_update_with_start.<locals>.on_start_error)start_workflow_inputupdate_workflow_input	_on_start_on_start_errorr  r	  )r  r  )r   ADMITTED
ValueError_usedRuntimeErrorrg   r   _UpdateDefinitionr   "UpdateWithStartUpdateWorkflowInputr   r   !StartWorkflowUpdateWithStartInputr  rw   r   )rs   r   r   r   r   r   r   r   rF   r   update_namer   update_inputr  r  inputrc   r  rd   r     s6   
zClient._start_update_with_starti  )limit	page_sizenext_page_tokenrF   r   queryr#  Optional[int]r$  r%  Optional[bytes]WorkflowExecutionAsyncIteratorc             
   C  s   | j t||||||dS )ax  List workflows.

        This does not make a request until the first iteration is attempted.
        Therefore any errors will not occur until then.

        Args:
            query: A Temporal visibility list filter. See Temporal documentation
                concerning visibility list filters including behavior when left
                unset.
            limit: Maximum number of workflows to return. If unset, all
                workflows are returned. Only applies if using the
                returned :py:class:`WorkflowExecutionAsyncIterator`.
                as an async iterator.
            page_size: Maximum number of results for each page.
            next_page_token: A previously obtained next page token if doing
                pagination. Usually not needed as the iterator automatically
                starts from the beginning.
            rpc_metadata: Headers used on each RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call.

        Returns:
            An async iterator that can be used with ``async for``.
        )r&  r$  r%  rF   r   r#  )rw   list_workflowsListWorkflowsInput)rs   r&  r#  r$  r%  rF   r   rc   rc   rd   r*    s   "zClient.list_workflowsWorkflowExecutionCountc                   s   | j t|||dI dH S )a  Count workflows.

        Args:
            query: A Temporal visibility filter. See Temporal documentation
                concerning visibility list filters.
            rpc_metadata: Headers used on each RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call.

        Returns:
            Count of workflows.
        )r&  rF   r   N)rw   count_workflowsCountWorkflowsInput)rs   r&  rF   r   rc   rc   rd   r-    s   
zClient.count_workflowsactivity_idAsyncActivityHandlec                C     d S r]   rc   )rs   r   r   r/  rc   rc   rd   get_async_activity_handle  s   z Client.get_async_activity_handle
task_tokenbytesc                C  r1  r]   rc   )rs   r3  rc   rc   rd   r2       )r   r   r/  r3  c                C  sf   |dur|dus|dus|durt dt| |S |dur/|du r%t dt| t|||dS t d)a  Get an async activity handle.

        Either the workflow_id, run_id, and activity_id can be provided, or a
        singular task_token can be provided.

        Args:
            workflow_id: Workflow ID for the activity. Cannot be set if
                task_token is set.
            run_id: Run ID for the activity. Cannot be set if task_token is set.
            activity_id: ID for the activity. Cannot be set if task_token is
                set.
            task_token: Task token for the activity. Cannot be set if any of the
                id parameters are set.

        Returns:
            A handle that can be used for completion or heartbeat.
        Nz+Task token cannot be present with other IDsz?Workflow ID, run ID, and activity ID must all be given together)r   r   r/  z6Task token or workflow/run/activity ID must be present)r  r0  AsyncActivityIDReference)rs   r   r   r/  r3  rc   rc   rd   r2    s    
)trigger_immediatelybackfillr   r   r   r   rF   r   scheduleScheduler7  r8  Sequence[ScheduleBackfill]ScheduleHandlec                  s4   t j| | jt|||||||	|
dI dH S )a  Create a schedule and return its handle.

        Args:
            id: Unique identifier of the schedule.
            schedule: Schedule to create.
            trigger_immediately: If true, trigger one action immediately when
                creating the schedule.
            backfill: Set of time periods to take actions on as if that time
                passed right now.
            memo: Memo for the schedule. Memo for a scheduled workflow is part
                of the schedule action.
            search_attributes: Search attributes for the schedule. Search
                attributes for a scheduled workflow are part of the scheduled
                action. The dictionary form of this is DEPRECATED, use
                :py:class:`temporalio.common.TypedSearchAttributes`.
            static_summary: A single-line fixed summary for this workflow execution that may appear
                in the UI/CLI. This can be in single-line Temporal markdown format.
            static_details: General fixed details for this workflow execution that may appear in
                UI/CLI. This can be in Temporal markdown format and can span multiple lines. This is
                a fixed value on the workflow that cannot be updated. For details that can be
                updated, use :py:meth:`temporalio.workflow.get_current_details` within the workflow.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Returns:
            A handle to the created schedule.

        Raises:
            ScheduleAlreadyRunningError: If a schedule with this ID is already
                running.
        )r   r9  r7  r8  r   r   rF   r   N)rg   r   r   rw   create_scheduleCreateScheduleInput)rs   r   r9  r7  r8  r   r   r   r   rF   r   rc   rc   rd   r=  :  s   3
zClient.create_schedulec                 C  s
   t | |S )z'Get a schedule handle for the given ID.)r<  )rs   r   rc   rc   rd   get_schedule_handle{     
zClient.get_schedule_handle)r$  r%  rF   r   ScheduleAsyncIteratorc             	     s   | j t|||||dS )a  List schedules.

        This does not make a request until the first iteration is attempted.
        Therefore any errors will not occur until then.

        Note, this list is eventually consistent. Therefore if a schedule is
        added or deleted, it may not be available in the list immediately.

        Args:
            page_size: Maximum number of results for each page.
            query: A Temporal visibility list filter. See Temporal documentation
                concerning visibility list filters including behavior when left
                unset.
            next_page_token: A previously obtained next page token if doing
                pagination. Usually not needed as the iterator automatically
                starts from the beginning.
            rpc_metadata: Headers used on each RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call.

        Returns:
            An async iterator that can be used with ``async for``.
        )r$  r%  rF   r   r&  )rw   list_schedulesListSchedulesInput)rs   r&  r$  r%  rF   r   rc   rc   rd   rB    s    zClient.list_schedules	operation	BuildIdOpc                       | j t||||dI dH S )ax  Used to add new Build IDs or otherwise update the relative compatibility of Build Ids as
        defined on a specific task queue for the Worker Versioning feature.

        For more on this feature, see https://docs.temporal.io/workers#worker-versioning

        .. warning::
           This API is experimental

        Args:
            task_queue: The task queue to target.
            operation: The operation to perform.
            rpc_metadata: Headers used on each RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call.
        rF   r   N)rw   $update_worker_build_id_compatibility%UpdateWorkerBuildIdCompatibilityInput)rs   r   rD  rF   r   rc   rc   rd   rH       
z+Client.update_worker_build_id_compatibilitymax_setsWorkerBuildIdVersionSetsc                   rF  )aZ  Get the Build ID compatibility sets for a specific task queue.

        For more on this feature, see https://docs.temporal.io/workers#worker-versioning

        .. warning::
           This API is experimental

        Args:
            task_queue: The task queue to target.
            max_sets: The maximum number of sets to return. If not specified, all sets will be
                returned.
            rpc_metadata: Headers used on each RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call.
        rG  N)rw   !get_worker_build_id_compatibility"GetWorkerBuildIdCompatibilityInput)rs   r   rK  rF   r   rc   rc   rd   rM    rJ  z(Client.get_worker_build_id_compatibility	build_idsSequence[str]task_queuesreachability_typeOptional[TaskReachabilityType]WorkerTaskReachabilityc              	     s"   | j t|||||dI dH S )au  Determine if some Build IDs for certain Task Queues could have tasks dispatched to them.

        For more on this feature, see https://docs.temporal.io/workers#worker-versioning

        .. warning::
           This API is experimental

        Args:
            build_ids: The Build IDs to query the reachability of. At least one must be specified.
            task_queues: Task Queues to restrict the query to. If not specified, all Task Queues
                will be searched. When requesting a large number of task queues or all task queues
                associated with the given Build IDs in a namespace, all Task Queues will be listed
                in the response but some of them may not contain reachability information due to a
                server enforced limit. When reaching the limit, task queues that reachability
                information could not be retrieved for will be marked with a ``NotFetched`` entry in
                {@link BuildIdReachability.taskQueueReachability}. The caller may issue another call
                to get the reachability for those task queues.
            reachability_type: The kind of reachability this request is concerned with.
            rpc_metadata: Headers used on each RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call.
        rG  N)rw   get_worker_task_reachabilityGetWorkerTaskReachabilityInput)rs   rO  rQ  rR  rF   r   rc   rc   rd   rU    s   
z#Client.get_worker_task_reachability)"rL   rM   r=   rM   r>   rN   r?   rO   r@   rP   rA   rQ   rB   rR   rC   rS   rD   rT   rE   rU   rF   rV   rG   rN   rH   rW   rI   rX   rJ   rY   rK   r0   rZ   r    )rn   ro   r=   rM   r?   rO   r@   rP   rA   rQ   rB   rR   rK   r0   )r_   rp   )rZ   rp   rZ   ro   )rZ   r   )rZ   r   )rZ   r   rZ   rM   rZ   rO   rZ   rV   r   rV   rZ   r   rZ   rN   r   rN   rZ   r   ).r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r   )0r   r   r   r8   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r   )0r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r   )4r   rM   r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r   )<r   r   r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   r   r   r   r   r   rN   r   r   rZ   r   ).r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r9   )0r   r   r   r8   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r9   )0r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r9   )4r   rM   r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r   )4r   r   r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   r   rN   r   r   rF   rV   r   r   r   rW   r   r   r   r   rZ   r   )
r   rM   r   rN   r   rN   r   r   rZ   r   )
r   r   r   rM   r   rN   r   rN   rZ   r   )r   r   r   r   r   rN   rF   rV   r   r   rZ   r2   )r   r   r   r8   r   r   r   rN   rF   rV   r   r   rZ   r2   )r   r   r   r   r   r   r   rN   rF   rV   r   r   rZ   r2   )r   rM   r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r   )r   r   r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r   )r   r   r   r   r   r   r   rN   rF   rV   r   r   rZ   r   )r   r   r   r8   r   r   r   r   r   rN   rF   rV   r   r   rZ   r   )r   r   r   r   r   r   r   r   r   rN   rF   rV   r   r   rZ   r   )r   rM   r   r   r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r  )r   r   r   r   r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r  )r   r   r   r   r   r   r   r   r   rN   r   r   r   r  rF   rV   r   r   rZ   r  r]   )r&  rN   r#  r'  r$  r   r%  r(  rF   rV   r   r   rZ   r)  )r&  rN   rF   rV   r   r   rZ   r,  )r   rM   r   rN   r/  rM   rZ   r0  )r3  r4  rZ   r0  )
r   rN   r   rN   r/  rN   r3  r(  rZ   r0  )r   rM   r9  r:  r7  rW   r8  r;  r   r   r   r   r   rN   r   rN   rF   rV   r   r   rZ   r<  )r   rM   rZ   r<  )r&  rN   r$  r   r%  r(  rF   rV   r   r   rZ   rA  )
r   rM   rD  rE  rF   rV   r   r   rZ   r   )
r   rM   rK  r'  rF   rV   r   r   rZ   rL  )rO  rP  rQ  rP  rR  rS  rF   rV   r   r   rZ   rT  )3__name__
__module____qualname____doc__classmethodrg   	converterr#   r<   r)   r0   NO_CODECri   rt   rr   r_   propertyrn   r   r   r   r=   rG   r?   rF   setterr>   r   r   WorkflowIDReusePolicyALLOW_DUPLICATEWorkflowIDConflictPolicyUNSPECIFIEDPriorityr   
_arg_unsetr   r   r   r   r   r   r*  r-  r2  r=  r?  rB  rH  rM  rU  rc   rc   rc   rd   r;   b   s0   o
!
	!"
$& !"
$&L%"		=

E@//A.""r;   c                   @  sJ   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ed< dS )rp   z;TypedDict of config originally passed to :py:meth:`Client`.z*Required[temporalio.service.ServiceClient]rn   zRequired[str]r=   z,Required[temporalio.converter.DataConverter]r?   zRequired[Sequence[Interceptor]]rA   z:Required[Optional[temporalio.common.QueryRejectCondition]]rB   zRequired[HeaderCodecBehavior]rK   zRequired[Sequence[Plugin]]r@   Nr^  r_  r`  ra  __annotations__rc   rc   rc   rd   rp     s   
 rp   F)totalc                   @  s4   e Zd ZdZeejjjj	j
Zeejjjj	jZdS )WorkflowHistoryEventFilterTypezwType of history events to get for a workflow.

    See :py:class:`temporalio.api.enums.v1.HistoryEventFilterType`.
    N)r^  r_  r`  ra  r   rg   apienumsv1HistoryEventFilterType#HISTORY_EVENT_FILTER_TYPE_ALL_EVENT	ALL_EVENT%HISTORY_EVENT_FILTER_TYPE_CLOSE_EVENTCLOSE_EVENTrc   rc   rc   rd   rp    s    rp  c                   @  st  e Zd ZdZdddddddddZejdddZedddZ	edddZ
edddZedddZdi dd dd(d)Zi dd*dd+d,Zi dd*dd.d/Zejd0i dd1dd6d7Zddd0ejd0i dd8dd?d@Zddd0ejd0i dd8ddAdBZedi ddCddIdJZedi ddCddNdJZedi ddCddRdJZeejjfg ddi ddSddUdJZejjfg ddi ddSddWdJZei dd*ddZd[Zei dd*dd]d[Zei dd*dd_d[Zeejjfg i dd`ddad[Zejjfg i dd`ddbd[Zdi ddcddedfZedi ddgddjdkZedi ddgddmdkZedi ddgddpdkZeejjfg ddi ddqddrdkZejjfg ddi ddqddsdkZedi ddgddwdxZedi ddgddydxZedi ddgddzdxZeejjfg ddi ddqdd|dxZejjfg ddi ddqdd}dxZejjfg ddi ddqdd~dZddddddZdddddZ dS )r   zHandle for interacting with a workflow.

    This is usually created via :py:meth:`Client.get_workflow_handle` or
    returned from :py:meth:`Client.start_workflow`.
    N)r   r   r   r   start_workflow_responseclientr;   r   rM   r   rN   r   r   r   r   ry  Optional[Union[temporalio.api.workflowservice.v1.StartWorkflowExecutionResponse, temporalio.api.workflowservice.v1.SignalWithStartWorkflowExecutionResponse]]rZ   r   c                C  s4   || _ || _|| _|| _|| _|| _|| _d| _dS )zCreate workflow handle.FN)_client_id_run_id_result_run_id_first_execution_run_id_result_type_start_workflow_response)_WorkflowHandle__temporal_eagerly_started)rs   rz  r   r   r   r   r   ry  rc   rc   rd   rt   3  s   
zWorkflowHandle.__init__rO   c                 C  s    | j jtjj| j j| jdS Nr=   r   )r|  r?   with_contextrg   rc  r&   r=   r}  r   rc   rc   rd   _data_converterM  s
   
zWorkflowHandle._data_converterc                 C     | j S )zID for the workflow.r}  r   rc   rc   rd   r   U     zWorkflowHandle.idc                 C  r  )av  If present, run ID used to ensure that requested operations apply
        to this exact run.

        This is only created via :py:meth:`Client.get_workflow_handle`.
        :py:meth:`Client.start_workflow` will not set this value.

        This cannot be mutated. If a different run ID is needed,
        :py:meth:`Client.get_workflow_handle` must be used instead.
        )r~  r   rc   rc   rd   r   Z  s   zWorkflowHandle.run_idc                 C  r  )a  Run ID used for :py:meth:`result` calls if present to ensure result
        is for a workflow starting from this run.

        When this handle is created via :py:meth:`Client.get_workflow_handle`,
        this is the same as run_id. When this handle is created via
        :py:meth:`Client.start_workflow`, this value will be the resulting run
        ID.

        This cannot be mutated. If a different run ID is needed,
        :py:meth:`Client.get_workflow_handle` must be used instead.
        )r  r   rc   rc   rd   r   g  s   zWorkflowHandle.result_run_idc                 C  r  )a  Run ID used to ensure requested operations apply to a workflow ID
        started with this run ID.

        This can be set when using :py:meth:`Client.get_workflow_handle`. When
        :py:meth:`Client.start_workflow` is called without a start signal, this
        is set to the resulting run.

        This cannot be mutated. If a different first execution run ID is needed,
        :py:meth:`Client.get_workflow_handle` must be used instead.
        )r  r   rc   rc   rd   r   v  s   z%WorkflowHandle.first_execution_run_idT)follow_runsrF   r   r  rW   rF   rV   r   r   r9   c                  s  | j }	 | j|dtjd||d2 z3 dH W }|dr_|j}|r)|jr)|j} n| jr0| jgnd}| j	|j
|I dH }|sFttd  S t|dkrVtdt|  tt|d   S |dr~|j}	|rq|	jrq|	j} nt| j|	jI dH d	|d
r|j}
ttjjdg| j	|
jI dH R  d	|dr|j}ttjj|jpdg| j	|jI dH R  d	|dr|j}|r|jr|j} n,ttjjdtjjjg dd	|dr|j }|jst!d|r|j} nt"|jq6 |du rt!dq)a  Wait for result of the workflow.

        This will use :py:attr:`result_run_id` if present to base the result on.
        To use another run ID, a new handle must be created via
        :py:meth:`Client.get_workflow_handle`.

        Args:
            follow_runs: If true (default), workflow runs will be continually
                fetched, until the most recent one is found. If false, return
                the result from the first run targeted by the request if that run
                ends in a result, otherwise raise an exception.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call. Note,
                this is the timeout for each history RPC call not this overall
                function.

        Returns:
            Result of the workflow after being converted by the data converter.

        Raises:
            WorkflowFailureError: Workflow failed, was cancelled, was
                terminated, or timed out. Use the
                :py:attr:`WorkflowFailureError.cause` to see the underlying
                reason.
            Exception: Other possible failures during result fetching.
        T)wait_new_eventevent_filter_typeskip_archivalrF   r   N-workflow_execution_completed_event_attributesr/   zExpected single result, got r   *workflow_execution_failed_event_attributes)cause,workflow_execution_canceled_event_attributeszWorkflow cancelled.workflow_execution_terminated_event_attributeszWorkflow terminated-workflow_execution_timed_out_event_attributeszWorkflow timed out)typelast_heartbeat_details4workflow_execution_continued_as_new_event_attributesz4Unexpectedly missing new run ID from continue as newzNo completion event found)#r  _fetch_history_events_for_runrp  rx  HasFieldr  new_execution_run_idr  r  decode_wrapperr   r   r9   lenwarningswarnr  WorkflowFailureErrordecode_failurefailurer  rg   
exceptionsCancelledErrordetailsr  TerminatedErrorreasonr  TimeoutErrorTimeoutTypeSTART_TO_CLOSEr  r  WorkflowContinuedAsNewError)rs   r  rF   r   hist_run_ideventcomplete_attr
type_hintsresults	fail_attrcancel_attr	term_attr	time_attr	cont_attrrc   rc   rd   r     s   $












[zWorkflowHandle.resultrG  c             	     s.   | j jt| j| j| j||dI dH  dS )aL  Cancel the workflow.

        This will issue a cancellation for :py:attr:`run_id` if present. This
        call will make sure to use the run chain starting from
        :py:attr:`first_execution_run_id` if present. To create handles with
        these values, use :py:meth:`Client.get_workflow_handle`.

        .. warning::
            Handles created as a result of :py:meth:`Client.start_workflow` with
            a start signal will cancel the latest workflow with the same
            workflow ID even if it is unrelated to the started workflow.

        Args:
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Raises:
            RPCError: Workflow could not be cancelled.
        )r   r   r   rF   r   N)r|  rw   cancel_workflowCancelWorkflowInputr}  r~  r  rs   rF   r   rc   rc   rd   cancel  s   zWorkflowHandle.cancelWorkflowExecutionDescriptionc                  s&   | j jt| j| j||dI dH S )a  Get workflow details.

        This will get details for :py:attr:`run_id` if present. To use a
        different run ID, create a new handle with via
        :py:meth:`Client.get_workflow_handle`.

        .. warning::
            Handles created as a result of :py:meth:`Client.start_workflow` will
            describe the latest workflow with the same workflow ID even if it is
            unrelated to the started workflow.

        Args:
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Returns:
            Workflow details.

        Raises:
            RPCError: Workflow details could not be fetched.
        )r   r   rF   r   N)r|  rw   describe_workflowDescribeWorkflowInputr}  r~  r  rc   rc   rd   describe,  s   
zWorkflowHandle.describeFr  r  rF   r   r  rp  r  WorkflowHistoryc             	     s.   t | jdd | j||||d2 I dH dS )zGet workflow history.

        This is a shortcut for :py:meth:`fetch_history_events` that just fetches
        all events.
        c                   s   g | z3 d H W }|q6 S r]   rc   .0vrc   rc   rd   
<listcomp>`  s
    z0WorkflowHandle.fetch_history.<locals>.<listcomp>r  N)r   events)r  r   fetch_history_events)rs   r  r  rF   r   rc   rc   rd   fetch_historyQ  s   
zWorkflowHandle.fetch_historyr$  r%  r  r  r  rF   r   r$  r'  r%  r(  r  !WorkflowHistoryEventAsyncIteratorc             
   C  s   | j | j|||||||dS )aj  Get workflow history events as an async iterator.

        This does not make a request until the first iteration is attempted.
        Therefore any errors will not occur until then.

        Args:
            page_size: Maximum amount to fetch per request if any maximum.
            next_page_token: A specific page token to fetch.
            wait_new_event: Whether the event fetching request will wait for new
                events or just return right away.
            event_filter_type: Which events to obtain.
            skip_archival: Whether to skip archival.
            rpc_metadata: Headers used on each RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call.

        Returns:
            An async iterator that doesn't begin fetching until iterated on.
        r  )r  r~  )rs   r$  r%  r  r  r  rF   r   rc   rc   rd   r  k  s   z#WorkflowHandle.fetch_history_eventsc          	      C  s&   | j jt| j||||||||d	S )N)	r   r   r$  r%  r  r  r  rF   r   )r|  rw   fetch_workflow_history_eventsFetchWorkflowHistoryEventsInputr}  )	rs   r   r$  r%  r  r  r  rF   r   rc   rc   rd   r    s   z,WorkflowHandle._fetch_history_events_for_run)reject_conditionrF   r   r&  3MethodSyncOrAsyncNoParam[SelfType, LocalReturnType]r  rR   r2   c                  r   r]   rc   )rs   r&  r  rF   r   rc   rc   rd   r&       zWorkflowHandle.queryBMethodSyncOrAsyncSingleParam[SelfType, ParamType, LocalReturnType]r   r8   c                  r   r]   rc   )rs   r&  r   r  rF   r   rc   rc   rd   r&    r   cCallable[Concatenate[SelfType, MultiParamSpec], Union[Awaitable[LocalReturnType], LocalReturnType]]r   r   c                  r   r]   rc   )rs   r&  r   r  rF   r   rc   rc   rd   r&    r   )r   r   r  rF   r   r   c                  r   r]   rc   )rs   r&  r   r   r   r  rF   r   rc   rc   rd   r&       r   c                  s   |}t |r'tjj|}	|	std|j d|	js td|	j}
|	j}nt	|}
| j
jt| j| j|
tj|||pB| j
jd i |||d	I dH S )a  Query the workflow.

        This will query for :py:attr:`run_id` if present. To use a different
        run ID, create a new handle with
        :py:meth:`Client.get_workflow_handle`.

        .. warning::
            Handles created as a result of :py:meth:`Client.start_workflow` will
            query the latest workflow with the same workflow ID even if it is
            unrelated to the started workflow.

        Args:
            query: Query function or name on the workflow.
            arg: Single argument to the query.
            args: Multiple arguments to the query. Cannot be set if arg is.
            result_type: For string queries, this can set the specific result
                type hint to deserialize into.
            reject_condition: Condition for rejecting the query. If unset/None,
                defaults to the client's default (which is defaulted to None).
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Returns:
            Result of the query.

        Raises:
            WorkflowQueryRejectedError: A query reject condition was satisfied.
            RPCError: Workflow details could not be fetched.
        zQuery definition not found on z', is it decorated with @workflow.query?z&Cannot invoke dynamic query definitionrB   )	r   r   r&  r   r  r   r   rF   r   N)callablerg   r   _QueryDefinitionfrom_fnr  r`  r   r   rM   r|  rw   query_workflowQueryWorkflowInputr}  r~  r   r   ru   )rs   r&  r   r   r   r  rF   r   r   r   
query_namerc   rc   rd   r&    s6   *

signal(MethodSyncOrAsyncNoParam[SelfType, None]c                  r   r]   rc   )rs   r  rF   r   rc   rc   rd   r  ,     zWorkflowHandle.signal7MethodSyncOrAsyncSingleParam[SelfType, ParamType, None]c                  r   r]   rc   )rs   r  r   rF   r   rc   rc   rd   r  6  r  MCallable[Concatenate[SelfType, MultiParamSpec], Union[Awaitable[None], None]]c                  r   r]   rc   )rs   r  r   rF   r   rc   rc   rd   r  A  r  )r   rF   r   c                  r   r]   rc   rs   r  r   r   rF   r   rc   rc   rd   r  N  r   c                  sD   | j jt| j| jtjj	|tj
||i ||dI dH  dS )a  Send a signal to the workflow.

        This will signal for :py:attr:`run_id` if present. To use a different
        run ID, create a new handle with via
        :py:meth:`Client.get_workflow_handle`.

        .. warning::
            Handles created as a result of :py:meth:`Client.start_workflow` will
            signal the latest workflow with the same workflow ID even if it is
            unrelated to the started workflow.

        Args:
            signal: Signal function or name on the workflow.
            arg: Single argument to the signal.
            args: Multiple arguments to the signal. Cannot be set if arg is.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Raises:
            RPCError: Workflow could not be signalled.
        )r   r   r  r   r   rF   r   N)r|  rw   signal_workflowSignalWorkflowInputr}  r~  rg   r   _SignalDefinitionmust_name_from_fn_or_strr   r   r  rc   rc   rd   r  Y  s   )r  rF   r   r  c                  s2   | j jt| j| j||| j||dI dH  dS )a  Terminate the workflow.

        This will issue a termination for :py:attr:`run_id` if present. This
        call will make sure to use the run chain starting from
        :py:attr:`first_execution_run_id` if present. To create handles with
        these values, use :py:meth:`Client.get_workflow_handle`.

        .. warning::
            Handles created as a result of :py:meth:`Client.start_workflow` with
            a start signal will terminate the latest workflow with the same
            workflow ID even if it is unrelated to the started workflow.

        Args:
            args: Details to store on the termination.
            reason: Reason for the termination.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Raises:
            RPCError: Workflow could not be terminated.
        )r   r   r   r  r   rF   r   N)r|  rw   terminate_workflowTerminateWorkflowInputr}  r~  r  )rs   r  rF   r   r   rc   rc   rd   	terminate  s   zWorkflowHandle.terminater   r   r   c                  r   r]   rc   )rs   r   r   rF   r   rc   rc   rd   execute_update  r  zWorkflowHandle.execute_updater   c                  r   r]   rc   )rs   r   r   r   rF   r   rc   rc   rd   r    r  r   r   c                  r   r]   rc   )rs   r   r   r   rF   r   rc   rc   rd   r    r  r   c                  r   r]   rc   )rs   r   r   r   r   r   rF   r   rc   rc   rd   r    r  c          	   
     s2   | j |||tj||||dI dH }| I dH S )a  Send an update request to the workflow and wait for it to complete.

        This will target the workflow with :py:attr:`run_id` if present. To use a
        different run ID, create a new handle with via :py:meth:`Client.get_workflow_handle`.

        Args:
            update: Update function or name on the workflow.
            arg: Single argument to the update.
            args: Multiple arguments to the update. Cannot be set if arg is.
            id: ID of the update. If not set, the default is a new UUID.
            result_type: For string updates, this can set the specific result
                type hint to deserialize into.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Raises:
            WorkflowUpdateFailedError: If the update failed.
            WorkflowUpdateRPCTimeoutOrCancelledError: This update call timed out
                or was cancelled. This doesn't mean the update itself was timed
                out or cancelled.
            RPCError: There was some issue sending the update to the workflow.
        )r   r   r   r   rF   r   N)_start_updater   r   r   )	rs   r   r   r   r   r   rF   r   r   rc   rc   rd   r    s   "
r   r   r   c                  r   r]   rc   )rs   r   r   r   rF   r   rc   rc   rd   start_update	  r   zWorkflowHandle.start_updatec                  r   r]   rc   )rs   r   r   r   r   rF   r   rc   rc   rd   r  	  r   c                  r   r]   rc   )rs   r   r   r   r   rF   r   rc   rc   rd   r  .	  r   r  c          	        r   r]   rc   	rs   r   r   r   r   r   r   rF   r   rc   rc   rd   r  =	  r   c          	   
     s"   | j ||||||||dI dH S )a[  Send an update request to the workflow and return a handle to it.

        This will target the workflow with :py:attr:`run_id` if present. To use a
        different run ID, create a new handle with via :py:meth:`Client.get_workflow_handle`.

        Args:
            update: Update function or name on the workflow. arg: Single argument to the
                update.
            wait_for_stage: Required stage to wait until returning: either ACCEPTED or
                COMPLETED. ADMITTED is not currently supported. See
                https://docs.temporal.io/workflows#update for more details.
            args: Multiple arguments to the update. Cannot be set if arg is.
            id: ID of the update. If not set, the default is a new UUID.
            result_type: For string updates, this can set the specific result
                type hint to deserialize into.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.

        Raises:
            WorkflowUpdateRPCTimeoutOrCancelledError: This update call timed out
                or was cancelled. This doesn't mean the update itself was timed out or
                cancelled.
            RPCError: There was some issue sending the update to the workflow.
        )r   r   r   r   rF   r   N)r  r  rc   rc   rd   r  K	  s   %c                  sh   |t jkr
tdtjj|\}	}
| jj	t
| j| j| j||	tj||i |p*|
|||dI d H S )Nr  )r   r   r   r  r   r   r   r   rF   r   r   )r   r  r  rg   r   r  r   r|  rw   start_workflow_updateStartWorkflowUpdateInputr}  r~  r   r   r   )rs   r   r   r   r   r   r   rF   r   r   r   rc   rc   rd   r  {	  s(   

zWorkflowHandle._start_updateworkflow_run_idr   r  c                C  s   t | j|| j|p
| j|dS )a  Get a handle for an update. The handle can be used to wait on the
        update result.

        Users may prefer the more typesafe :py:meth:`get_update_handle_for`
        which accepts an update definition.

        Args:
            id: Update ID to get a handle to.
            workflow_run_id: Run ID to tie the handle to. If this is not set,
                the :py:attr:`run_id` will be used.
            result_type: The result type to deserialize into if known.

        Returns:
            The update handle.
        r  )WorkflowUpdateHandler|  r}  r~  )rs   r   r  r   rc   rc   rd   get_update_handle	  s   z WorkflowHandle.get_update_handle)r  @temporalio.workflow.UpdateMethodMultiParam[Any, LocalReturnType]c                C  s   | j |||jjdS )a  Get a typed handle for an update. The handle can be used to wait on
        the update result.

        This is the same as :py:meth:`get_update_handle` but typed.

        Args:
            update: The update method to use for typing the handle.
            id: Update ID to get a handle to.
            workflow_run_id: Run ID to tie the handle to. If this is not set,
                the :py:attr:`run_id` will be used.

        Returns:
            The update handle.
        r  )r  _defnr   )rs   r   r   r  rc   rc   rd   get_update_handle_for	  s   
z$WorkflowHandle.get_update_handle_for)rz  r;   r   rM   r   rN   r   rN   r   rN   r   r   ry  r{  rZ   r   rY  rX  r\  )r  rW   rF   rV   r   r   rZ   r9   rF   rV   r   r   rZ   r   )rF   rV   r   r   rZ   r  )
r  rp  r  rW   rF   rV   r   r   rZ   r  )r$  r'  r%  r(  r  rW   r  rp  r  rW   rF   rV   r   r   rZ   r  )r   rN   r$  r'  r%  r(  r  rW   r  rp  r  rW   rF   rV   r   r   rZ   r  )
r&  r  r  rR   rF   rV   r   r   rZ   r2   )r&  r  r   r8   r  rR   rF   rV   r   r   rZ   r2   )r&  r  r   r   r  rR   rF   rV   r   r   rZ   r2   )r&  rM   r   r   r   r   r   r   r  rR   rF   rV   r   r   rZ   r   )r&  r   r   r   r   r   r   r   r  rR   rF   rV   r   r   rZ   r   )r  r  rF   rV   r   r   rZ   r   )
r  r  r   r8   rF   rV   r   r   rZ   r   )
r  r  r   r   rF   rV   r   r   rZ   r   )r  rM   r   r   r   r   rF   rV   r   r   rZ   r   )r  r   r   r   r   r   rF   rV   r   r   rZ   r   )
r   r   r  rN   rF   rV   r   r   rZ   r   )
r   r   r   rN   rF   rV   r   r   rZ   r2   )r   r   r   r8   r   rN   rF   rV   r   r   rZ   r2   )r   r   r   r   r   rN   rF   rV   r   r   rZ   r2   )r   rM   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r   )r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r   )r   r   r   r   r   rN   rF   rV   r   r   rZ   r   )r   r   r   r8   r   r   r   rN   rF   rV   r   r   rZ   r   )r   r   r   r   r   r   r   rN   rF   rV   r   r   rZ   r   )r   rM   r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r  )r   r   r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   rZ   r  )r   rM   r  rN   r   r   rZ   r  )r   r  r   rM   r  rN   rZ   r   )!r^  r_  r`  ra  rt   	functoolscached_propertyr  re  r   r   r   r   r   r  r  rp  rv  r  r  r  r   r&  rg   r   rl  r  r  r  r  r  r  r  rc   rc   rc   rd   r   ,  sx    '(-
	J	
0*
/		3'#r   c                   @  s\  e Zd ZdZedddejjjdddddddi dejj	j
ddd>d&d'Zedddejjjdddddddi dejj	j
ddd?d+d'Zedddejjjdddddddi dejj	j
ddd@d/d'Zeejjfg ddddejjjdddddddi dejj	j
dd0dAd4d'Zejjfg ddddejjjdddddddi dejj	j
dd5d6dBd:d'ZdCd<d=ZdS )DWithStartWorkflowOperationzDefines a start-workflow operation used by update-with-start requests.

    Update-With-Start allows you to send an update to a workflow, while starting the
    workflow if necessary.
    Nr[   )r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rN   r   r   rF   rV   r   r   r   r   r   rZ   r   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   rc   rc   rd   rt   	  s   z#WithStartWorkflowOperation.__init__r   r   r8   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   rc   rc   rd   rt   	  s   r   r   r   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   rc   rc   rd   rt   
     )r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r   r   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   rc   rc   rd   rt   ?
  r  r   )r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r   r   r   c                C  s  t jj||d t jj|\}}|t jjjkrtdt	di d|dt j
||d|d|d|d|	d	|
d
|d|d|d|d|d|d|d|d|di d|pt|d|d|d|d|| _t | _d| _dS d|d|d|d|| _t | _d| _dS )zCreate a WithStartWorkflowOperation.

        See :py:meth:`temporalio.client.Client.start_workflow` for documentation of the
        arguments.
        r   z$WorkflowIDConflictPolicy is requiredr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   FNrc   )rg   r   r   r   r   r   ri  rj  r  !UpdateWithStartStartWorkflowInputr   r  r   r
  r  )rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r   result_type_from_run_fnrc   rc   rd   rt   `
  s   %	


r   c                   s   | j I dH S )z;Wait until workflow is running and return a WorkflowHandle.N)r
  r   rc   rc   rd   workflow_handle
  s   z*WithStartWorkflowOperation.workflow_handle)(r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   rF   rV   r   r   r   r   r   r   rZ   r   )*r   r   r   r8   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   rF   rV   r   r   r   r   r   r   rZ   r   )*r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   rF   rV   r   r   r   r   r   r   rZ   r   ).r   rM   r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   rF   rV   r   r   r   r   r   r   rZ   r   )0r   r   r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   rN   r   rN   r   r   rF   rV   r   r   r   r   r   r   r   r   rZ   r   )rZ   r   )r^  r_  r`  ra  r   rg   r   rg  rh  rk  r<   rt   rl  r  rc   rc   rc   rd   r  	  s    	!#Ir  T)frozenc                   @  s*   e Zd ZU dZded< ded< ded< dS )r6  z3Reference to an async activity by its qualified ID.rM   r   rN   r   r/  Nrm  rc   rc   rc   rd   r6  
  
   
 r6  c                   @  sz   e Zd ZdZ	d(d)ddZi ddd*ddZejjfi ddd+ddZ	g i ddd,dd Z
i ddd*d!d"Zd-d&d'ZdS ).r0  zFHandle representing an external activity for completion and heartbeat.Nrz  r;   id_or_token&Union[AsyncActivityIDReference, bytes]data_converter_overrideOptional[DataConverter]rZ   r   c                 C  s   || _ || _|| _dS )z Create an async activity handle.N)r|  _id_or_token_data_converter_override)rs   rz  r  r  rc   rc   rd   rt   
  s   
zAsyncActivityHandle.__init__rG  r  r   rF   rV   r   r   c             	     ,   | j jt| j|||| jdI dH  dS )a.  Record a heartbeat for the activity.

        Args:
            details: Details of the heartbeat.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        r  r  rF   r   r  N)r|  rw   heartbeat_async_activityHeartbeatAsyncActivityInputr  r  rs   rF   r   r  rc   rc   rd   	heartbeat
     zAsyncActivityHandle.heartbeatr   Optional[Any]c             	     s,   | j jt| j|||| jdI dH  dS )a$  Complete the activity.

        Args:
            result: Result of the activity if any.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        )r  r   rF   r   r  N)r|  rw   complete_async_activityCompleteAsyncActivityInputr  r  )rs   r   rF   r   rc   rc   rd   complete
  s   zAsyncActivityHandle.complete)r  rF   r   r  	Exceptionr  r   c             
     s.   | j jt| j||||| jdI dH  dS )ae  Fail the activity.

        Args:
            error: Error for the activity.
            last_heartbeat_details: Last heartbeat details for the activity.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        )r  r  r  rF   r   r  N)r|  rw   fail_async_activityFailAsyncActivityInputr  r  )rs   r  r  rF   r   rc   rc   rd   fail
  s   zAsyncActivityHandle.failc             	     r   )a'  Report the activity as cancelled.

        Args:
            details: Cancellation details.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        r  N)r|  rw   "report_cancellation_async_activity$ReportCancellationAsyncActivityInputr  r  r  rc   rc   rd   report_cancellation  r  z'AsyncActivityHandle.report_cancellationcontextr$   r    c                 C  sJ   | j j|}|| j ju r| S t| }|jtjurtd|| j | j|S )a  Create a new AsyncActivityHandle with a different serialization context.

        Payloads received by the activity will be decoded and deserialized using a data converter
        with :py:class:`ActivitySerializationContext` set as context. If you are using a custom data
        converter that makes use of this context then you can use this method to supply matching
        context data to the data converter used to serialize and encode the outbound payloads.
        zIf you have subclassed AsyncActivityHandle and overridden the __init__ method then you must override with_context to return an instance of your class.)r|  r?   r  r  rt   r0  	TypeErrorr  )rs   r  r?   rk   rc   rc   rd   r  *  s   z AsyncActivityHandle.with_contextr]   )rz  r;   r  r  r  r  rZ   r   )r  r   rF   rV   r   r   rZ   r   )r   r  rF   rV   r   r   rZ   r   )
r  r  r  r   rF   rV   r   r   rZ   r   )r  r$   rZ   r    )r^  r_  r`  ra  rt   r  rg   r   rl  r
  r  r  r  rc   rc   rc   rd   r0  
  s(    r0  c                   @  s4  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
ed< 	 d
ed< 	 d
ed< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< ed:dd Zed;d&d'Zd<d)d*Z	e
ejjfd=d-d.Ze
d>d2d.Ze
d?d5d.Zejjfd6d7d@d9d.Zd6S )AWorkflowExecutionz)Info for a single workflow execution run.Optional[datetime]
close_timeexecution_timer   history_lengthrM   r   r=   rN   	parent_idparent_run_idroot_idroot_run_id0temporalio.api.workflow.v1.WorkflowExecutionInforaw_infor   "temporalio.common.SearchAttributesr   r   
start_time!Optional[WorkflowExecutionStatus]statusr   'temporalio.common.TypedSearchAttributestyped_search_attributesworkflow_typerO   _context_free_data_converterrZ   c                 C  s   | j t| j| jdS )z Data converter for the workflow.r  )r&  r  r&   r=   r   r   rc   rc   rd   r?     s   z WorkflowExecution.data_converterinforc  additional_fieldsr   r    c                 K  st  | di d| dr|j jtjdnd d| dr%|j jtjdnd d|jd|jj	d|d| dr=|j
j	nd d	| drI|j
jnd d
| drU|jj	nd d| dra|jjnd d|d|jjdtj|jd|j jtjdd|jrt|jnd d|jdtj|jd|jjd||S d|jdtj|jd|jjd||S )Nr  tzinfor  r  r   r=   r  parent_executionr  r  root_executionr  r  r   r   r   r"  r   r$  r%  r&  rc   )r  r  
ToDatetimereplacer	   utcr  r  	executionr   r+  r   r,  rg   rc  decode_search_attributesr   r   r"  WorkflowExecutionStatusr   decode_typed_search_attributesr  r   )rk   r'  r=   rc  r(  rc   rc   rd   _from_raw_info  s   


 !"%&'(+,&'(+,z WorkflowExecution._from_raw_infoMapping[str, Any]c                   $    fdd j jj D I dH S )a  Workflow's memo values, converted without type hints.

        Since type hints are not used, the default converted values will come
        back. For example, if the memo was originally created with a dataclass,
        the value will be a dict. To convert using proper type hints, use
        :py:meth:`memo_value`.

        Returns:
            Mapping of all memo keys and they values without type hints.
        c                   ,   i | ]\}}| j |gI d H d qS Nr   r?   decoder  kr  r   rc   rd   
<dictcomp>  
    z*WorkflowExecution.memo.<locals>.<dictcomp>N)r  r   fieldsitemsr   rc   r   rd   r        
zWorkflowExecution.memokeyr<   c                   r   r]   rc   rs   rB  r<   rc   rc   rd   
memo_value     zWorkflowExecution.memo_value	type_hintType[ParamType]r8   c                  r   r]   rc   rs   rB  rF  rc   rc   rd   rD    rE  r1   Union[AnyType, ParamType]c                  r   r]   rc   rs   rB  r<   rF  rc   rc   rd   rD    rE  NrF  r   c                  X   | j jj|}|s|tjju rtd| |S | j	|g|r$|gndI dH d S a  Memo value for the given key, optional default, and optional type
        hint.

        Args:
            key: Key to get memo value for.
            default: Default to use if key is not present. If unset, a
                :py:class:`KeyError` is raised when the key does not exist.
            type_hint: Type hint to use when converting.

        Returns:
            Memo value, converted with the type hint if present.

        Raises:
            KeyError: Key not present and default not set.
        z#Memo does not have a value for key Nr   )
r  r   r?  getrg   r   rl  KeyErrorr?   r:  rs   rB  r<   rF  payloadrc   rc   rd   rD       rY  )
r'  r  r=   rM   rc  rO   r(  r   rZ   r    rZ   r5  rB  rM   r<   r   rZ   r   rB  rM   rF  rG  rZ   r8   rB  rM   r<   r1   rF  rG  rZ   rI  rB  rM   r<   r   rF  r   rZ   r   )r^  r_  r`  ra  rn  re  r?   rb  r4  r   r   rg   r   rl  rD  rc   rc   rc   rd   r  B  sj   
 	
7r  c                   @  sl   e Zd ZU dZded< 	 dZded< dZded< dZd	ed
< dddZdddZ	dddZ
edddZdS )r  z0Description for a single workflow execution run.Ctemporalio.api.workflowservice.v1.DescribeWorkflowExecutionResponseraw_descriptionNrN   _static_summary_static_detailsFrW   _metadata_decodedrZ   c                      | j s|  I dH  | jS )zGets the single-line fixed summary for this workflow execution that may appear in
        UI/CLI. This can be in single-line Temporal markdown format.
        N)r\  _decode_metadatarZ  r   rc   rc   rd   r        z+WorkflowExecutionDescription.static_summaryc                   r]  )zGets the general fixed details for this workflow execution that may appear in UI/CLI.
        This can be in Temporal markdown format and can span multiple lines.
        N)r\  r^  r[  r   rc   rc   rd   r     r_  z+WorkflowExecutionDescription.static_detailsr   c                   s,   t | j| jjjI dH \| _| _d| _dS )z*Internal method to decode metadata lazily.NT)_decode_user_metadatar?   rY  execution_configuser_metadatarZ  r[  r\  r   rc   rc   rd   r^    s
   
z-WorkflowExecutionDescription._decode_metadatadescriptionr=   rM   rc  rO   c                   s   t j| j||| dS )N)r=   rc  rY  )r  r4  workflow_execution_info)rc  r=   rc  rc   rc   rd   _from_raw_description$  s   z2WorkflowExecutionDescription._from_raw_descriptionr\  rZ   r   )rc  rX  r=   rM   rc  rO   rZ   r  )r^  r_  r`  ra  rn  rZ  r[  r\  r   r   r^  staticmethodre  rc   rc   rc   rd   r    s   
 


r  c                   @  s   e Zd ZdZeejjjj	j
Zeejjjj	jZeejjjj	jZeejjjj	jZeejjjj	jZeejjjj	jZeejjjj	jZdS )r2  zjStatus of a workflow execution.

    See :py:class:`temporalio.api.enums.v1.WorkflowExecutionStatus`.
    N)r^  r_  r`  ra  r   rg   rq  rr  rs  r2  !WORKFLOW_EXECUTION_STATUS_RUNNINGRUNNING#WORKFLOW_EXECUTION_STATUS_COMPLETEDr    WORKFLOW_EXECUTION_STATUS_FAILEDFAILED"WORKFLOW_EXECUTION_STATUS_CANCELEDCANCELED$WORKFLOW_EXECUTION_STATUS_TERMINATED
TERMINATED*WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEWCONTINUED_AS_NEW#WORKFLOW_EXECUTION_STATUS_TIMED_OUT	TIMED_OUTrc   rc   rc   rd   r2  2  s.    r2  c                   @  4   e Zd ZU dZded< 	 ded< 	 edd	d
ZdS )r,  z6Representation of a count from a count workflows call.r   countz0Sequence[WorkflowExecutionCountAggregationGroup]groupsrawAtemporalio.api.workflowservice.v1.CountWorkflowExecutionsResponserZ   c                 C     t | jdd | jD dS )Nc                 S     g | ]}t |qS rc   )&WorkflowExecutionCountAggregationGroup	_from_raw)r  grc   rc   rd   r  c      
z4WorkflowExecutionCount._from_raw.<locals>.<listcomp>)rv  rw  )r,  rv  rw  rx  rc   rc   rd   r}  ]  s   z WorkflowExecutionCount._from_rawN)rx  ry  rZ   r,  r^  r_  r`  ra  rn  rg  r}  rc   rc   rc   rd   r,  O     
 r,  c                   @  ru  )r|  zDAggregation group if the workflow count query had a group-by clause.r   rv  z0Sequence[temporalio.common.SearchAttributeValue]group_valuesrx  Rtemporalio.api.workflowservice.v1.CountWorkflowExecutionsResponse.AggregationGrouprZ   c                 C  rz  )Nc                 S  s   g | ]}t j|qS rc   )rg   rc  _decode_search_attribute_valuer  rc   rc   rd   r  {  s    
zDWorkflowExecutionCountAggregationGroup._from_raw.<locals>.<listcomp>)rv  r  )r|  rv  r  r  rc   rc   rd   r}  u  s   z0WorkflowExecutionCountAggregationGroup._from_rawN)rx  r  rZ   r|  r  rc   rc   rc   rd   r|  i  s   
 r|  c                   @  s   e Zd ZdZd+dd	Zed,ddZed-ddZed.ddZddd/ddZ	d0ddZ
d1ddZejdi ddd2d)d*ZdS )3r)  zAsynchronous iterator for :py:class:`WorkflowExecution` values.

    Most users should use ``async for`` on this iterator and not call any of the
    methods within. To consume the workflows as histories, call
    :py:meth:`map_histories`.
    rz  r;   r"  r+  rZ   r   c                 C  s2   || _ || _|j| _d| _d| _|j| _d| _dS )zCreate an asynchronous iterator for the given input.

        Users should not create this directly, but rather use
        :py:meth:`Client.list_workflows`.
        Nr   )	r|  _inputr%  _next_page_token_current_page_current_page_indexr#  _limit_yieldedrs   rz  r"  rc   rc   rd   rt     s   

z'WorkflowExecutionAsyncIterator.__init__r   c                 C  r  zvIndex of the entry in the current page that will be returned from
        the next :py:meth:`__anext__` call.
        r  r   rc   rc   rd   current_page_index     z1WorkflowExecutionAsyncIterator.current_page_index%Optional[Sequence[WorkflowExecution]]c                 C  r  z)Current page, if it has been fetched yet.r  r   rc   rc   rd   current_page  r  z+WorkflowExecutionAsyncIterator.current_pager(  c                 C  r  z'Token for the next page request if any.r  r   rc   rc   rd   r%    r  z.WorkflowExecutionAsyncIterator.next_page_tokenNr$  r$  r'  c                  s   |p j j} jdur j j |k r j j } jjjtjj	j
j jj| jp+d j jp0ddd j j j jdI dH } fdd|jD  _d	 _|jpQd _dS )
Fetch the next page if any.

        Args:
            page_size: Override the page size this iterator was originally
                created with.
        N    r[   )r=   r$  r%  r&  Tretrymetadatatimeoutc                   s"   g | ]}t | jj jjqS rc   )r  r4  r|  r=   r?   r  r   rc   rd   r    s    zBWorkflowExecutionAsyncIterator.fetch_next_page.<locals>.<listcomp>r   )r  r$  r  r  r|  r   list_workflow_executionsrg   rq  workflowservicers  ListWorkflowExecutionsRequestr=   r  r&  rF   r   
executionsr  r  r%  rs   r$  resprc   r   rd   fetch_next_page  s(   


z.WorkflowExecutionAsyncIterator.fetch_next_pagec                 C     | S zReturn self as the iterator.rc   r   rc   rc   rd   	__aiter__  r5  z(WorkflowExecutionAsyncIterator.__aiter__r  c                   s   | j dur| j| j krt	 | jdu r|  I dH  q| jt| jkr3| jdur1|  I dH  qt| j| j }|  jd7  _|  jd7  _|S )ZGet the next execution on this iterator, fetching next page if
        necessary.
        NTr/   )r  r  StopAsyncIterationr  r  r  r  r  rs   retrc   rc   rd   	__anext__  s    

z(WorkflowExecutionAsyncIterator.__anext__Fr  r  rp  r  rW   rF   rV   r   r   AsyncIterator[WorkflowHistory]c                C sD   | 2 z3 dH W }| j j|j|jdj||||dI dH V  q6 dS )zCreate an async iterator consuming all workflows and calling
        :py:meth:`WorkflowHandle.fetch_history` on each one.

        This is just a shortcut for ``fetch_history``, see that method for
        parameter details.
        Nr   r  )r|  r   r   r   r  )rs   r  r  rF   r   r  rc   rc   rd   map_histories  s   z,WorkflowExecutionAsyncIterator.map_histories)rz  r;   r"  r+  rZ   r   rZ   r   )rZ   r  rZ   r(  r$  r'  rZ   r   )rZ   r)  )rZ   r  )
r  rp  r  rW   rF   rV   r   r   rZ   r  )r^  r_  r`  ra  rt   re  r  r  r%  r  r  r  rp  rv  r  rc   rc   rc   rd   r)    s"    

 
r)  c                   @  sV   e Zd ZU dZded< 	 ded< 	 edddZedddZdddZ	dddZ
dS )r  z&A workflow's ID and immutable history.rM   r   z0Sequence[temporalio.api.history.v1.HistoryEvent]r  rZ   c                 C  s4   | j std| j d dstd| j d jjS )z&Run ID extracted from the first event.z	No eventsr   +workflow_execution_started_event_attributesz!First event is not workflow start)r  r  r  r  original_execution_run_idr   rc   rc   rd   r     s   zWorkflowHistory.run_idhistoryUnion[str, Dict[str, Any]]c                 C  s   t |}t| |jS )a  Construct a WorkflowHistory from an ID and a json dump of history.

        This is built to work both with Temporal UI/CLI JSON as well as
        :py:meth:`to_json` even though they are slightly different.

        Args:
            workflow_id: The workflow's ID
            history: A string or parsed-to-dict representation of workflow
                history

        Returns:
            Workflow history
        )_history_from_jsonr  r  )r   r  parsedrc   rc   rd   	from_json  s   zWorkflowHistory.from_jsonc                 C     t jjtjjjj| j	dS )z\Convert this history to JSON.

        Note, this does not include the workflow ID.
        r  )
googleprotobufjson_formatMessageToJsonrg   rq  r  rs  Historyr  r   rc   rc   rd   to_json-     zWorkflowHistory.to_jsonDict[str, Any]c                 C  r  )zlConvert this history to JSON-compatible dict.

        Note, this does not include the workflow ID.
        r  )
r  r  r  MessageToDictrg   rq  r  rs  r  r  r   rc   rc   rd   to_json_dict6  r  zWorkflowHistory.to_json_dictNrX  )r   rM   r  r  rZ   r  )rZ   r  )r^  r_  r`  ra  rn  re  r   rg  r  r  r  rc   rc   rc   rd   r    s   
 

	r  c                   @  h   e Zd ZdZddd	ZedddZed ddZed!ddZddd"ddZ	d#ddZ
d$ddZdS )%r  zAsynchronous iterator for history events of a workflow.

    Most users should use ``async for`` on this iterator and not call any of the
    methods within.
    rz  r;   r"  r  rZ   r   c                 C  $   || _ || _|j| _d| _d| _dS )zCreate an asynchronous iterator for the given input.

        Users should not create this directly, but rather use
        :py:meth:`WorkflowHandle.fetch_history_events`.
        Nr   r|  r  r%  r  r  r  r  rc   rc   rd   rt   H  s   

z*WorkflowHistoryEventAsyncIterator.__init__r   c                 C  r  r  r  r   rc   rc   rd   r  Z  r  z4WorkflowHistoryEventAsyncIterator.current_page_index:Optional[Sequence[temporalio.api.history.v1.HistoryEvent]]c                 C  r  r  r  r   rc   rc   rd   r  a  r  z.WorkflowHistoryEventAsyncIterator.current_pager(  c                 C  r  r  r  r   rc   rc   rd   r%  h  r  z1WorkflowHistoryEventAsyncIterator.next_page_tokenNr  r$  r'  c             
     s   | j jjtjjjj| j jtjj	jj
| jj| jjpdd| jjp!d| jp%d| jjtjjjj| jj| jjdd| jj| jjdI dH }t|jdksMJ t|jj| _d| _|jp[d| _dS )	r  r[   r   r   r   r  )r=   r0  maximum_page_sizer%  r  history_event_filter_typer  Tr  N) r|  r   get_workflow_execution_historyrg   rq  r  rs  "GetWorkflowExecutionHistoryRequestr=   r   r  r  r   r   r$  r  r  rr  rt  	ValueTyper  r  rF   r   r  raw_historyrx   r  r  r  r  r%  r  rc   rc   rd   r  m  s0   



z1WorkflowHistoryEventAsyncIterator.fetch_next_pagec                 C  r  r  rc   r   rc   rc   rd   r    r5  z+WorkflowHistoryEventAsyncIterator.__aiter__&temporalio.api.history.v1.HistoryEventc                   j   	 | j du r|  I dH  q| jt| j kr&| jdur$|  I dH  qt| j | j }|  jd7  _|S r  TNr/   r  r  r  r  r  r  r  rc   rc   rd   r       

z+WorkflowHistoryEventAsyncIterator.__anext__)rz  r;   r"  r  rZ   r   r  )rZ   r  r  r  )rZ   r  )rZ   r  r^  r_  r`  ra  rt   re  r  r  r%  r  r  r  rc   rc   rc   rd   r  @  s    

 r  c                   @  s   e Zd ZdZd-dd	Zi d
dd.ddZi d
dd/ddZi d
dd0ddZd
i d
dd1ddZd
i d
dd2d!d"Z	d
i d
dd1d#d$Z
ei d
dd3d'd(Zei d
dd4d*d(Zi d
dd5d,d(Zd
S )6r<  zHandle for interacting with a schedule.

    This is usually created via :py:meth:`Client.get_schedule_handle` or
    returned from :py:meth:`Client.create_schedule`.

    Attributes:
        id: ID of the schedule.
    rz  r;   r   rM   rZ   r   c                 C  s   || _ || _dS )zCreate schedule handle.N)r|  r   )rs   rz  r   rc   rc   rd   rt     s   
zScheduleHandle.__init__NrG  r8  ScheduleBackfillrF   rV   r   r   c                  s4   |st d| jjt| j|||dI dH  dS )ai  Backfill the schedule by going through the specified time periods as
        if they passed right now.

        Args:
            backfill: Backfill periods.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        zAt least one backfill required)r   	backfillsrF   r   N)r  r|  rw   backfill_scheduleBackfillScheduleInputr   )rs   rF   r   r8  rc   rc   rd   r8    s   zScheduleHandle.backfillc                  s&   | j jt| j||dI dH  dS )zDelete this schedule.

        Args:
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        r   N)r|  rw   delete_scheduleDeleteScheduleInputr   r  rc   rc   rd   delete  s   zScheduleHandle.deleteScheduleDescriptionc                  s"   | j jt| j||dI dH S )zFetch this schedule's description.

        Args:
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        r   N)r|  rw   describe_scheduleDescribeScheduleInputr   r  rc   rc   rd   r    s   
zScheduleHandle.describe)noterF   r   r  rN   c                  (   | j jt| j|||dI dH  dS )a,  Pause the schedule and set a note.

        Args:
            note: Note to set on the schedule.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        r   r  rF   r   N)r|  rw   pause_schedulePauseScheduleInputr   rs   r  rF   r   rc   rc   rd   pause     zScheduleHandle.pause)overlaprF   r   r  Optional[ScheduleOverlapPolicy]c                  r  )aZ  Trigger an action on this schedule to happen immediately.

        Args:
            overlap: If set, overrides the schedule's overlap policy.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        )r   r  rF   r   N)r|  rw   trigger_scheduleTriggerScheduleInputr   )rs   r  rF   r   rc   rc   rd   trigger  r  zScheduleHandle.triggerc                  r  )a.  Unpause the schedule and set a note.

        Args:
            note: Note to set on the schedule.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for the RPC call.
        r  N)r|  rw   unpause_scheduleUnpauseScheduleInputr   r  rc   rc   rd   unpause,  r  zScheduleHandle.unpauseupdater9Callable[[ScheduleUpdateInput], Optional[ScheduleUpdate]]c                  r   r]   rc   rs   r  rF   r   rc   rc   rd   r   D  r  zScheduleHandle.updateDCallable[[ScheduleUpdateInput], Awaitable[Optional[ScheduleUpdate]]]c                  r   r]   rc   r  rc   rc   rd   r   M  r  eCallable[[ScheduleUpdateInput], Union[Optional[ScheduleUpdate], Awaitable[Optional[ScheduleUpdate]]]]c                  r  )a4  Update a schedule using a callback to build the update from the
        description.

        The callback may be invoked multiple times in a conflict-resolution
        loop.

        Args:
            updater: Callback that returns the update. It accepts a
                :py:class:`ScheduleUpdateInput` and returns a
                :py:class:`ScheduleUpdate`. If None is returned or an error
                occurs, the update is not attempted. This may be called multiple
                times.
            rpc_metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys. This is for every call made
                within.
            rpc_timeout: Optional RPC deadline to set for the RPC call. This is
                for each call made within, not overall.
        )r   r  rF   r   N)r|  rw   update_scheduleUpdateScheduleInputr   r  rc   rc   rd   r   V  s   )rz  r;   r   rM   rZ   r   )r8  r  rF   rV   r   r   rZ   r   r  )rF   rV   r   r   rZ   r  )r  rN   rF   rV   r   r   rZ   r   )r  r  rF   rV   r   r   rZ   r   )r  r  rF   rV   r   r   rZ   r   )r  r  rF   rV   r   r   rZ   r   )r  r  rF   rV   r   r   rZ   r   )r^  r_  r`  ra  rt   r8  r  r  r  r  r  r   r   rc   rc   rc   rd   r<    sF    
	r<  c                   @  s   e Zd ZU dZejedZded< 	 ejedZ	ded< 	 ejedZ
ded< 	 ejedZded	< 	 d
Zded< 	 d
Zded< 	 d
Zded< 	 d
Zded< 	 edddZdddZd
S )ScheduleSpeczSpecification of the times scheduled actions may occur.

    The times are the union of :py:attr:`calendars`, :py:attr:`intervals`, and
    :py:attr:`cron_expressions` excluding anything in :py:attr:`skip`.
    default_factoryzSequence[ScheduleCalendarSpec]	calendarszSequence[ScheduleIntervalSpec]	intervalsrP  cron_expressionsskipNr  start_atend_atr   jitterrN   time_zone_namespec'temporalio.api.schedule.v1.ScheduleSpecrZ   c              
   C  s   t dd | jD dd | jD | jdd | jD | dr'| j jt	j
dnd | dr7| j jt	j
dnd | drB| j nd | jpGd d	S )
Nc                 S  r{  rc   ScheduleCalendarSpec_from_protor  crc   rc   rd   r    r  z,ScheduleSpec._from_proto.<locals>.<listcomp>c                 S  r{  rc   )ScheduleIntervalSpecr  r  irc   rc   rd   r    s    c                 S  r{  rc   r  r  rc   rc   rd   r        r   r)  end_timer  )r  r  r  r  r  r   r  r  )r  structured_calendarintervalcron_stringexclude_structured_calendarr  r   r-  r.  r	   r/  r  r  ToTimedeltatimezone_namer  rc   rc   rd   r    s$   zScheduleSpec._from_protoc              
   C  s   d }| j rtjj }|| j  d }| jr"tjj }|| j d }| jr3tjj	 }|
| j tjjjjdd | jD | jdd | jD dd | jD |||| jpVddS )Nc                 S     g | ]}|  qS rc   	_to_protor  calrc   rc   rd   r        z*ScheduleSpec._to_proto.<locals>.<listcomp>c                 S  r  rc   r  r  rc   rc   rd   r    r  c                 S  r  rc   r  r  rc   rc   rd   r    r  r[   )r  r  r  r  r   r  r  r  )r  r  r  timestamp_pb2	TimestampFromDatetimer   r  duration_pb2DurationFromTimedeltarg   rq  r9  rs  r  r  r  r  r  r  )rs   r   r  r  rc   rc   rd   r    s,   
zScheduleSpec._to_proto)r  r  rZ   r  )rZ   r  )r^  r_  r`  ra  dataclassesfieldrx   r  rn  r  r  r  r  r   r  r  rg  r  r  rc   rc   rc   rd   r  |  s*   
 r  c                   @  st   e Zd ZU dZded< 	 dZded< 	 dZded< 	 dd ZedddZ	edddZ
edddZdddZdS )ScheduleRangez+Inclusive range for a schedule match value.r   startr   endstepc                 C  s<   | j | jk rt| d| j | jdkrt| dd dS dS )zSet field defaults.r&  r   r'  r/   N)r&  r%  object__setattr__r'  r   rc   rc   rd   __post_init__  s
   
zScheduleRange.__post_init__ranges*Sequence[temporalio.api.schedule.v1.Range]rZ   Sequence[ScheduleRange]c                 C     t dd | D S )Nc                 s  s    | ]}t |V  qd S r]   )r$  r  r  rrc   rc   rd   	<genexpr>  s    z-ScheduleRange._from_protos.<locals>.<genexpr>tupler+  rc   rc   rd   _from_protos     zScheduleRange._from_protosrange temporalio.api.schedule.v1.Rangec                 C  s   t | j| j| jdS N)r%  r&  r'  )r$  r%  r&  r'  )r7  rc   rc   rd   r    s   zScheduleRange._from_protoc                 C  r.  )Nc                 s  s    | ]}|  V  qd S r]   r  r/  rc   rc   rd   r1    s    z+ScheduleRange._to_protos.<locals>.<genexpr>r2  r4  rc   rc   rd   
_to_protos  r6  zScheduleRange._to_protosc                 C  s   t jjjj| j| j| jdS r9  )rg   rq  r9  rs  Ranger%  r&  r'  r   rc   rc   rd   r    s   
zScheduleRange._to_protoN)r+  r,  rZ   r-  )r7  r8  rZ   r$  )r+  r-  rZ   r,  )rZ   r8  )r^  r_  r`  ra  rn  r&  r'  r*  rg  r5  r  r:  r  rc   rc   rc   rd   r$    s    
 r$  c                   @  s   e Zd ZU dZedfZded< 	 edfZded< 	 edfZded< 	 eddfZ	ded	< 	 edd
fZ
ded< 	 dZded< 	 eddfZded< 	 dZded< 	 edddZdddZdS )r  a$  Specification relative to calendar time when to run an action.

    A timestamp matches if at least one range of each field matches except for
    year. If year is missing, that means all years match. For all fields besides
    year, at least one range must be present to match anything.
    r   r-  secondminutehourr/      day_of_month   monthrc   year   day_of_weekNrN   commentr  1temporalio.api.schedule.v1.StructuredCalendarSpecrZ   c              
   C  sV   t t| jt| jt| jt| jt| jt| jt| j	| j
p(d dS )Nr<  r=  r>  r@  rB  rC  rE  rF  )r  r$  r5  r<  r=  r>  r@  rB  rC  rE  rF  r  rc   rc   rd   r  )  s   






z ScheduleCalendarSpec._from_protoc              
   C  s^   t jjjjt| jt| jt| j	t| j
t| jt| jt| j| jp,ddS )Nr[   rH  )rg   rq  r9  rs  StructuredCalendarSpecr$  r:  r<  r=  r>  r@  rB  rC  rE  rF  r   rc   rc   rd   r  8  s   







zScheduleCalendarSpec._to_proto)r  rG  rZ   r  )rZ   rG  )r^  r_  r`  ra  r$  r<  rn  r=  r>  r@  rB  rC  rE  rF  rg  r  r  rc   rc   rc   rd   r    s*   
 r  c                   @  sB   e Zd ZU dZded< 	 dZded< 	 edd
dZdddZdS )r
  zoSpecification for scheduling on an interval.

    Matches times expressed as epoch + (n * every) + offset.
    r   everyNr   offsetr  'temporalio.api.schedule.v1.IntervalSpecrZ   c                 C  s*   t | j | dr| j dS d dS )Nphase)rJ  rK  )r
  r  r  r  rM  r  rc   rc   rd   r  R  s   z ScheduleIntervalSpec._from_protoc                 C  sN   t jj }|| j d }| jrt jj }|| j tjj	j
j||dS )N)r  rM  )r  r  r  r   r!  rJ  rK  rg   rq  r9  rs  IntervalSpec)rs   r  rM  rc   rc   rd   r  [  s   zScheduleIntervalSpec._to_proto)r  rL  rZ   r
  )rZ   rL  )	r^  r_  r`  ra  rn  rK  rg  r  r  rc   rc   rc   rd   r
  E  s   
 r
  c                   @  s,   e Zd ZdZedddZedd	d
ZdS )ScheduleActionzBase class for an action a schedule can take.

    See :py:class:`ScheduleActionStartWorkflow` for the most commonly used
    implementation.
    action)temporalio.api.schedule.v1.ScheduleActionrZ   c                 C  s*   |  drt| jS td| d )Nr   zUnsupported action: rP  )r  ScheduleActionStartWorkflowr  r   r  
WhichOneof)rP  rc   rc   rd   r  l  s   
zScheduleAction._from_protorz  r;   c                   r   r]   rc   rs   rz  rc   rc   rd   r  u  rE  zScheduleAction._to_protoN)rP  rQ  rZ   rO  rz  r;   rZ   rQ  )r^  r_  r`  ra  rg  r  r   r  rc   rc   rc   rd   rO  e  s    rO  c                      s  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ed< ded< ded< ded< ded< 	 ded< ded< ded< ded< 	 ejdddZded< edAd"d#Z	e
d$d$d$d$d$ejjjd$d$ejjjd%	dBd*d+Ze
d$d$d$d$d$ejjjd$d$ejjjd%	dCd/d+Ze
d$d$d$d$d$ejjjd$d$ejjjd%	dDd2d+Ze
ejjfg d$d$d$d$d$ejjjd$d$ejjjd3
dEd5d+Ze
dFd7d+Zejjfg d$d$d$d$d$d$d$ejjji d$d$d$d$ejjjd8dG fd;d+ZdHd?d@Z  ZS )IrR  z$Schedule action to start a workflow.rM   r   z@Union[Sequence[Any], Sequence[temporalio.api.common.v1.Payload]]r   r   r   r   r   r   r   r   r   zROptional[Union[Mapping[str, Any], Mapping[str, temporalio.api.common.v1.Payload]]]r   r#  r$  r  untyped_search_attributes6Optional[Union[str, temporalio.api.common.v1.Payload]]r   r   r   r   8Optional[Mapping[str, temporalio.api.common.v1.Payload]]r   F)compareinitrW   r}  r'  3temporalio.api.workflow.v1.NewWorkflowExecutionInforZ   c                 C  s   t d| dS )Nz<unset>)r  )rR  r'  rc   rc   rd   r       z'ScheduleActionStartWorkflow._from_protoN)	r   r   r   r   r   r$  r   r   r   r   r   rN   r   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r$  r   r   r   rc   rc   rd   rt     s   z$ScheduleActionStartWorkflow.__init__r   r   r8   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r   r$  r   r   r   rc   rc   rd   rt     s   r   r   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r   r$  r   r   r   rc   rc   rd   rt     s   )
r   r   r   r   r   r   r$  r   r   r   r   c                C  r1  r]   rc   )rs   r   r   r   r   r   r   r   r   r   r   r$  r   r   r   rc   rc   rd   rt     s   r  c                C  r1  r]   rc   )rs   r   r  rc   rc   rd   rt     s   )r   r   r   r   r   r   r   r   r$  rV  r   r   r   r  r   r   =Optional[temporalio.api.workflow.v1.NewWorkflowExecutionInfo]c                  s^  t    |rd| _|jj| _|jr|jjng | _|j	| _
|jj| _|dr,|j nd| _|dr9|j nd| _|drF|j nd| _|drVtjj|jnd| _|jjra|jjnd| _tj|j| _|jjrt|jjnd| _ tj!|j| _"| jD ]}|j#j| j"v r| j"|j#j= q|dr|j$j%r|j$j%nd| _&|dr|j$j'r|j$j'nd| _(|dr|j)rtjj*+|j)| _)dS tjj*j,| _)dS d	| _|st-d
|st-dt.|rtjj/0|}|jst-d|j}n	t1|t2st3d|| _tj4||| _|| _
|| _|| _|| _|| _|	| _|
| _|| _|| _"|| _ || _&|| _(|| _)dS )zCreate a start-workflow action.

        See :py:meth:`Client.start_workflow` for details on these parameter
        values.
        Tworkflow_execution_timeoutNworkflow_run_timeoutworkflow_task_timeoutr   rb  r   FzID requiredzTask queue requiredz+Cannot schedule dynamic workflow explicitlyz%Workflow must be a string or callable)5superrt   r}  r%  r   r   r"  payloadsr   r   r   r   r  r_  r  r   r`  r   ra  r   rg   r   RetryPolicy
from_protor   r   r?  rc  r3  r   r$  headerr   r1  rV  rB  rb  summaryr   r  r   r   rk  r  r<   r  r  r   r   
isinstancerM   r  r   )rs   r   r   r   r   r   r   r   r   r   r   r$  rV  r   r   r   r  r   pairr   	__class__rc   rd   rt     s   







rz  r;   rQ  c           	        s
  d }j rtjj }|j  d }jr#tjj }|j d }jr4tjj }|j d }jrFt	j
jj }j| d }jrPj }|jt|jjd t	j
jjjt	j
jjjjt	j
jjjjdt	j
jjjjdjrt	j
jjj fddjD I d H dnd ||||j rt	j
jjj! fddj " D I d H dnd t# j$j%I d H |d	d
}fddj&" D }|rt	j'(||j)j* j+rt	j'(j+|j)j* j,rt-j,|j)j.j/|0 d t1j2koj3 |jj4I d H  |S )Nr  r   c                   s:   g | ]}t |tjjjjr|n
 |gI d H d qS r8  rh  rg   rq  r   rs  Payloadencode)r  ar?   rc   rd   r    s    z9ScheduleActionStartWorkflow._to_proto.<locals>.<listcomp>)rc  c                   s@   i | ]\}}|t |tjjjjr|n
 |gI d H d qS r8  rm  r;  rq  rc   rd   r=    s    z9ScheduleActionStartWorkflow._to_proto.<locals>.<dictcomp>r?  )r   r%  r   r"  r_  r`  ra  r   r   rb  r   r   c                   s    i | ]\}}| j vr||qS rc   )r$  r;  r   rc   rd   r=    s
    
rK   )5r   r  r  r  r   r!  r   r   r   rg   rq  r   rs  rd  apply_to_protor   r  r?   r  r&   r=   r   r9  rO  r   NewWorkflowExecutionInfoWorkflowType	taskqueue	TaskQueuer   r   Payloadsr   Memor@  _encode_user_metadatar   r   rV  rc  encode_search_attributesr   r   r$  r   _apply_headersrf  r?  r_   r0   CODECr}  payload_codec)	rs   rz  r   r   r   r   r   rP  untyped_not_in_typedrc   )r?   rs   rd   r  o  s   





	


	

(

z%ScheduleActionStartWorkflow._to_proto)r'  r[  rZ   rR  )r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r$  r#  r   rN   r   rN   r   r   rZ   r   )r   r   r   r8   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r$  r#  r   rN   r   rN   r   r   rZ   r   )r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r$  r#  r   rN   r   rN   r   r   rZ   r   )r   rM   r   r   r   r   r   rM   r   rM   r   r   r   r   r   r   r   r   r   r   r$  r#  r   rN   r   rN   r   r   rZ   r   )r   rM   r  r[  rZ   r   )$r   r   r   r   r   r   r   rN   r   rN   r   r   r   r   r   r   r   r   r   r   r$  r#  rV  r  r   rN   r   rN   r   rX  r  r^  r   r   rZ   r   rU  )r^  r_  r`  ra  rn  r"  r#  r}  rg  r  r   rg   r   TypedSearchAttributesemptyrk  r<   rt   rl  r  __classcell__rc   rc   rj  rd   rR  {  s   
 

urR  c                   @  s   e Zd ZdZeejjjj	j
Z	 eejjjj	jZ	 eejjjj	jZ	 eejjjj	jZ	 eejjjj	jZ	 eejjjj	jZdS )ScheduleOverlapPolicyziControls what happens when a workflow would be started by a schedule but
    one is already running.
    N)r^  r_  r`  ra  r   rg   rq  rr  rs  r  SCHEDULE_OVERLAP_POLICY_SKIPSKIP"SCHEDULE_OVERLAP_POLICY_BUFFER_ONE
BUFFER_ONE"SCHEDULE_OVERLAP_POLICY_BUFFER_ALL
BUFFER_ALL$SCHEDULE_OVERLAP_POLICY_CANCEL_OTHERCANCEL_OTHER'SCHEDULE_OVERLAP_POLICY_TERMINATE_OTHERTERMINATE_OTHER!SCHEDULE_OVERLAP_POLICY_ALLOW_ALL	ALLOW_ALLrc   rc   rc   rd   r    s4    r  c                   @  s:   e Zd ZU dZded< 	 ded< dZded< dd
dZdS )r  zRTime period and policy for actions taken as if the time passed right
    now.
    r   r  r   Nr  r  rZ   *temporalio.api.schedule.v1.BackfillRequestc                 C  sn   t jj }|| j t jj }|| j tjj	j
jj}| jr,tjj	j
j| j}tjjj
j|||dS )N)r   r  overlap_policy)r  r  r  r  r  r  r   rg   rq  rr  rs  r  #SCHEDULE_OVERLAP_POLICY_UNSPECIFIEDr  r  r9  BackfillRequest)rs   r   r  r  rc   rc   rd   r    s   
zScheduleBackfill._to_proto)rZ   r  )r^  r_  r`  ra  rn  r  r  rc   rc   rc   rd   r     s   
 r  c                   @  sf   e Zd ZU dZejdd dZded< 	 eddZ	d	ed
< 	 dZ
ded< 	 edddZdddZdS )SchedulePolicyzPolicies of a schedule.c                   C  s   t jS r]   )r  r  rc   rc   rc   rd   re   $      zSchedulePolicy.<lambda>r  r  r  im  )daysr   catchup_windowFrW   pause_on_failurepol+temporalio.api.schedule.v1.SchedulePoliciesrZ   c                 C  s    t tt| j| j | jdS )N)r  r  r  )r  r  r   r  r  r  r  )r  rc   rc   rd   r  4  s
   zSchedulePolicy._from_protoc                 C  s@   t jj }|| j tjjj	j
tjjj	j| j|| jdS )N)r  r  r  )r  r  r  r   r!  r  rg   rq  r9  rs  SchedulePoliciesrr  r  r  r  r  )rs   r  rc   rc   rd   r  <  s   
zSchedulePolicy._to_protoN)r  r  rZ   r  )rZ   r  )r^  r_  r`  ra  r"  r#  r  rn  r   r  r  rg  r  r  rc   rc   rc   rd   r    s   
 r  c                   @  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< 	 e	dddZ
dddZdS )ScheduleStatezState of a schedule.NrN   r  FrW   pausedlimited_actionsr   r   remaining_actionsstate(temporalio.api.schedule.v1.ScheduleStaterZ   c                 C  s   t | jpd | j| j| jdS )N)r  r  r  r  )r  notesr  r  r  )r  rc   rc   rd   r  e  s   zScheduleState._from_protoc                 C  s$   t jjjj| jp	d| j| j| jdS )Nr[   )r  r  r  r  )	rg   rq  r9  rs  r  r  r  r  r  r   rc   rc   rd   r  n  s   
zScheduleState._to_proto)r  r  rZ   r  )rZ   r  )r^  r_  r`  ra  r  rn  r  r  r  rg  r  r  rc   rc   rc   rd   r  H  s   
 r  c                   @  sj   e Zd ZU dZded< 	 ded< 	 ejedZded< 	 eje	dZ
d	ed
< 	 edddZdddZdS )r:  z.A schedule for periodically running an action.rO  rP  r  r  r  r  policyr  r  sched#temporalio.api.schedule.v1.SchedulerZ   c                 C  s0   t t| jt| jt| jt| j	dS )N)rP  r  r  r  )
r:  rO  r  rP  r  r  r  policiesr  r  )r  rc   rc   rd   r    s   



zSchedule._from_protorz  r;   c                   sT   t jj }|| jj tjj	j
j| j | j|I d H | j | j dS )N)r  rP  r  r  )r  r  r  r   r!  r  r  rg   rq  r9  rs  r:  r  r  rP  r  )rs   rz  r  rc   rc   rd   r    s   
zSchedule._to_protoN)r  r  rZ   r:  )rz  r;   rZ   r  )r^  r_  r`  ra  rn  r"  r#  r  r  r  r  rg  r  r  rc   rc   rc   rd   r:  w  s   
 r:  c                   @     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ed< 	 ed(ddZd)ddZee	j
jfd*ddZed+d dZed,d#dZe	j
jfd$d%d-d'dZd$S ).r  zDescription of a schedule.rM   r   r:  r9  ScheduleInfor'  r#  r$  r  r   rO   r?   :temporalio.api.workflowservice.v1.DescribeScheduleResponserY  descrc  rZ   c              	   C  s:   t | t|jt|jtj|j	tj
|j	||dS )N)r   r9  r'  r$  r   r?   rY  )r  r:  r  r9  r  r'  rg   rc  r3  r   r1  )r   r  rc  rc   rc   rd   r    s   

zScheduleDescription._from_protor5  c                   r6  )  Schedule's memo values, converted without type hints.

        Since type hints are not used, the default converted values will come
        back. For example, if the memo was originally created with a dataclass,
        the value will be a dict. To convert using proper type hints, use
        :py:meth:`memo_value`.

        Returns:
            Mapping of all memo keys and they values without type hints.
        c                   r7  r8  r9  r;  r   rc   rd   r=    r>  z,ScheduleDescription.memo.<locals>.<dictcomp>N)rY  r   r?  r@  r   rc   r   rd   r     rA  zScheduleDescription.memorB  r<   r   c                   r   r]   rc   rC  rc   rc   rd   rD    rE  zScheduleDescription.memo_valuerF  rG  r8   c                  r   r]   rc   rH  rc   rc   rd   rD    rE  r1   rI  c                  r   r]   rc   rJ  rc   rc   rd   rD    rE  NrK  r   c                  rL  rM  )
rY  r   r?  rN  rg   r   rl  rO  r?   r:  rP  rc   rc   rd   rD    rR  )r   rM   r  r  rc  rO   rZ   r  rS  rT  rU  rV  rW  r^  r_  r`  ra  rn  rg  r  r   r   rg   r   rl  rD  rc   rc   rc   rd   r    s<   
 
r  c                   @  sp   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ed< 	 ded< 	 edddZdS )r  zInformation about a schedule.r   num_actions!num_actions_missed_catchup_windownum_actions_skipped_overlapz!Sequence[ScheduleActionExecution]running_actionsSequence[ScheduleActionResult]recent_actionsSequence[datetime]next_action_timesr   
created_atr  last_updated_atr'  'temporalio.api.schedule.v1.ScheduleInforZ   c                 C  st   t | j| j| jdd | jD dd | jD dd | jD | j j	t
jd| dr6| j j	t
jddS d dS )Nc                 S  r{  rc   )$ScheduleActionExecutionStartWorkflowr  r/  rc   rc   rd   r  0  r  z,ScheduleInfo._from_proto.<locals>.<listcomp>c                 S  r{  rc   ScheduleActionResultr  r/  rc   rc   rd   r  4  r  c                 S     g | ]}|  jtjd qS r)  r-  r.  r	   r/  r  frc   rc   rd   r  7      r)  update_time)r  r  r  r  r  r  r  r  )r  action_countmissed_catchup_windowoverlap_skippedrunning_workflowsr  future_action_timescreate_timer-  r.  r	   r/  r  r  r\  rc   rc   rd   r  *  s&   zScheduleInfo._from_protoN)r'  r  rZ   r  r^  r_  r`  ra  rn  rg  r  rc   rc   rc   rd   r    s(   
 r  c                   @     e Zd ZdZdS )ScheduleActionExecutionz#Base class for an action execution.Nr^  r_  r`  ra  rc   rc   rc   rd   r  B      r  c                   @  s4   e Zd ZU dZded< 	 ded< 	 eddd	Zd
S )r  z(Execution of a scheduled workflow start.rM   r   r   exec*temporalio.api.common.v1.WorkflowExecutionrZ   c                 C  s   t | j| jdS )N)r   r   )r  r   r   )r  rc   rc   rd   r  R  s   z0ScheduleActionExecutionStartWorkflow._from_protoN)r  r  rZ   r  r  rc   rc   rc   rd   r  H  s   
 r  c                   @  s>   e Zd ZU dZded< 	 ded< 	 ded< 	 edd
dZdS )r  z,Information about when an action took place.r   scheduled_at
started_atr  rP  res/temporalio.api.schedule.v1.ScheduleActionResultrZ   c                 C  s6   t | j jtjd| j jtjdt| j	dS )Nr)  )r  r  rP  )
r  schedule_timer-  r.  r	   r/  actual_timer  r  start_workflow_result)r  rc   rc   rd   r  i  s   z ScheduleActionResult._from_protoN)r  r  rZ   r  r  rc   rc   rc   rd   r  \     
 r  c                   @     e Zd ZU dZded< dS )ScheduleUpdateInputzFParameter for an update callback for :py:meth:`ScheduleHandle.update`.r  rc  Nrm  rc   rc   rc   rd   r  v     
 r  c                   @  s(   e Zd ZU dZded< 	 dZded< dS )ScheduleUpdatezBResult of an update callback for :py:meth:`ScheduleHandle.update`.r:  r9  Nz1Optional[temporalio.common.TypedSearchAttributes]r   )r^  r_  r`  ra  rn  r   rc   rc   rc   rd   r  ~  s   
 r  c                   @  r  ).ScheduleListDescriptionz!Description of a listed schedule.rM   r   zOptional[ScheduleListSchedule]r9  zOptional[ScheduleListInfo]r'  r#  r$  r  r   rO   r?   ,temporalio.api.schedule.v1.ScheduleListEntry	raw_entryentryrc  rZ   c              	   C  sX   t | j| drt| jnd | drt| jnd tj	| j
tj| j
|| dS )Nr'  )r   r9  r'  r$  r   r?   r  )r  schedule_idr  ScheduleListScheduler  r'  ScheduleListInforg   rc  r3  r   r1  )r  rc  rc   rc   rd   r    s"   z#ScheduleListDescription._from_protor5  c                   r6  )r  c                   r7  r8  r9  r;  r   rc   rd   r=    r>  z0ScheduleListDescription.memo.<locals>.<dictcomp>N)r  r   r?  r@  r   rc   r   rd   r     rA  zScheduleListDescription.memorB  r<   r   c                   r   r]   rc   rC  rc   rc   rd   rD    rE  z"ScheduleListDescription.memo_valuerF  rG  r8   c                  r   r]   rc   rH  rc   rc   rd   rD    rE  r1   rI  c                  r   r]   rc   rJ  rc   rc   rd   rD    rE  NrK  r   c                  rL  rM  )
r  r   r?  rN  rg   r   rl  rO  r?   r:  rP  rc   rc   rd   rD    rR  )r  r  rc  rO   rZ   r  rS  rT  rU  rV  rW  r  rc   rc   rc   rd   r    s<   
 
r  c                   @  s>   e Zd ZU dZded< 	 ded< 	 ded< 	 edddZdS )r  zDetails for a listed schedule.ScheduleListActionrP  r  r  ScheduleListStater  r'  +temporalio.api.schedule.v1.ScheduleListInforZ   c                 C  s8   |  ds	tdtt| jjdt| jt	| dS )Nr%  zUnknown action on schedule)r   )rP  r  r  )
r  r  r  ScheduleListActionStartWorkflowr%  r   r  r  r  r  r\  rc   rc   rd   r    s   

z ScheduleListSchedule._from_protoN)r'  r  rZ   r  r  rc   rc   rc   rd   r    r  r  c                   @  r  )r  z4Base class for an action a listed schedule can take.Nr  rc   rc   rc   rd   r  !  r  r  c                   @  r  )r  z0Action to start a workflow on a listed schedule.rM   r   Nrm  rc   rc   rc   rd   r  '  r  r  c                   @  ru  )r  z$Information about a listed schedule.r  r  r  r  r'  r  rZ   c                 C  s$   t dd | jD dd | jD dS )Nc                 S  r{  rc   r  r/  rc   rc   rd   r  F  r  z0ScheduleListInfo._from_proto.<locals>.<listcomp>c                 S  r  r  r  r  rc   rc   rd   r  I  r  )r  r  )r  r  r  r\  rc   rc   rd   r  A  s   zScheduleListInfo._from_protoN)r'  r  rZ   r  r  rc   rc   rc   rd   r  /  s   
 r  c                   @  ru  )r  zState of a listed schedule.rN   r  rW   r  r'  r  rZ   c                 C  s   t | jpd | jdS )N)r  r  )r  r  r  r\  rc   rc   rd   r  ^  s   zScheduleListState._from_protoN)r'  r  rZ   r  r  rc   rc   rc   rd   r  P  r  r  c                   @  r  )%rA  zAsynchronous iterator for :py:class:`ScheduleListDescription` values.

    Most users should use ``async for`` on this iterator and not call any of the
    methods within.
    rz  r;   r"  rC  rZ   r   c                 C  r  )zCreate an asynchronous iterator for the given input.

        Users should not create this directly, but rather use
        :py:meth:`Client.list_schedules`.
        Nr   r  r  rc   rc   rd   rt   o  s
   

zScheduleAsyncIterator.__init__r   c                 C  r  r  r  r   rc   rc   rd   r    r  z(ScheduleAsyncIterator.current_page_index+Optional[Sequence[ScheduleListDescription]]c                 C  r  r  r  r   rc   rc   rd   r    r  z"ScheduleAsyncIterator.current_pager(  c                 C  r  r  r  r   rc   rc   rd   r%    r  z%ScheduleAsyncIterator.next_page_tokenNr  r$  r'  c                  s    j jjtjjjj j j|p j	j
 jpd j	jpddd j	j j	jdI dH } fdd|jD  _d	 _|jp<d _dS )
r  r  r[   )r=   r  r%  r&  Tr  Nc                   s   g | ]
}t | jjqS rc   )r  r  r|  r?   r  r   rc   rd   r    s    z9ScheduleAsyncIterator.fetch_next_page.<locals>.<listcomp>r   )r|  r   rB  rg   rq  r  rs  ListSchedulesRequestr=   r  r$  r  r&  rF   r   	schedulesr  r  r%  r  rc   r   rd   r    s"   



z%ScheduleAsyncIterator.fetch_next_pagec                 C  r  r  rc   r   rc   rc   rd   r    r5  zScheduleAsyncIterator.__aiter__r  c                   r  r  r  r  rc   rc   rd   r    r  zScheduleAsyncIterator.__anext__)rz  r;   r"  rC  rZ   r   r  )rZ   r  r  r  )rZ   rA  )rZ   r  r  rc   rc   rc   rd   rA  h  s    

rA  c                   @  s   e Zd ZdZddddd&ddZejd'ddZed(ddZ	ed(ddZ
ed)ddZi ddd*d!d"Zi dfd+d$d%ZdS ),r  z/Handle for a workflow update execution request.N)r  r   known_outcomerz  r;   r   rM   r   r  rN   r   r   r  *Optional[temporalio.api.update.v1.Outcome]c                C  s(   || _ || _|| _|| _|| _|| _dS )zCreate a workflow update handle.

        Users should not create this directly, but rather use
        :py:meth:`WorkflowHandle.start_update` or :py:meth:`WorkflowHandle.get_update_handle`.
        N)r|  r}  _workflow_id_workflow_run_idr  _known_outcome)rs   rz  r   r   r  r   r  rc   rc   rd   rt     s   
zWorkflowUpdateHandle.__init__rZ   rO   c                 C  s   | j jt| j j| jdS r  )r|  r?   r  r&   r=   r   r   rc   rc   rd   r    s   z$WorkflowUpdateHandle._data_converterc                 C  r  )zID of this Update request.r  r   rc   rc   rd   r     r  zWorkflowUpdateHandle.idc                 C  r  )z/The ID of the Workflow targeted by this Update.)r  r   rc   rc   rd   r     r  z WorkflowUpdateHandle.workflow_idc                 C  r  )zGIf specified, the specific run of the Workflow targeted by this Update.)r  r   rc   rc   rd   r    r  z$WorkflowUpdateHandle.workflow_run_idrG  rF   rV   r   r   r2   c                  s   | j ||dI dH  | jsJ | jdr#t| j| jjI dH | jjjs*dS | j	r1| j	gnd}| j
| jjj|I dH }|sDdS t|dkrTtdt|  |d S )a  Wait for and return the result of the update. The result may already be known in which case no network call
        is made. Otherwise the result will be polled for until it is returned.

        Args:
            rpc_metadata: Headers used on the RPC call. Keys here override client-level RPC metadata keys.
            rpc_timeout: Optional RPC deadline to set for each RPC call. Note: this is the timeout for each
                RPC call while polling, not a timeout for the function as a whole. If an individual RPC times out,
                it will be retried until the result is available.

        Raises:
            WorkflowUpdateFailedError: If the update failed.
            WorkflowUpdateRPCTimeoutOrCancelledError: This update call timed out
                or was cancelled. This doesn't mean the update itself was timed
                out or cancelled.
            RPCError: Update result could not be fetched for some other reason.
        rG  Nr  r/   z#Expected single update result, got r   )_poll_until_outcomer  r  WorkflowUpdateFailedErrorr  r  r  successrc  r  r:  r  r  r  )rs   rF   r   r  r  rc   rc   rd   r     s(   



zWorkflowUpdateHandle.resultr   c              
     s  | j rd S tjjjj| jjtjjjj	tjj
jj| j| jpdd| jd| jjtjjjjtjjjjjdd}	 z| jjj|d||dI d H }|drS|j| _ W d S W n- tyq } z|jtjksh|jtjkrlt | d }~w tjy } zt |d }~ww q8)	Nr[   r  )workflow_executionr  lifecycle_stage)r=   
update_refrG   wait_policyTr  outcome) r  rg   rq  r  rs  "PollWorkflowExecutionUpdateRequestr|  r=   r   	UpdateRefr   r  r   r  r   rG   
WaitPolicyrr  %UpdateWorkflowExecutionLifecycleStage3UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETEDr   poll_workflow_execution_updater  r  r+   r"  r,   DEADLINE_EXCEEDED	CANCELLED(WorkflowUpdateRPCTimeoutOrCancelledErrorasyncior  )rs   rF   r   reqr  errrc   rc   rd   r  #  sR   





z(WorkflowUpdateHandle._poll_until_outcome)rz  r;   r   rM   r   rM   r  rN   r   r   r  r  rY  rX  r\  )rF   rV   r   r   rZ   r2   r  )r^  r_  r`  ra  rt   r  r  r  re  r   r   r  r   r  rc   rc   rc   rd   r    s(    /r  c                   @  sF   e Zd ZdZeejjjj	j
Zeejjjj	jZeejjjj	jZdS )r   z[Stage to wait for workflow update to reach before returning from
    ``start_update``.
    N)r^  r_  r`  ra  r   rg   rq  rr  rs  r  2UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTEDr  2UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTEDACCEPTEDr  r   rc   rc   rc   rd   r   S  s    r   c                      0   e Zd ZdZd
 fddZeddd	Z  ZS )r  z2Error that occurs when a workflow is unsuccessful.r  r  rZ   r   c                     t  d || _dS )zCreate workflow failure error.zWorkflow execution failedNrb  rt   	__cause__rs   r  rj  rc   rd   rt   f     
zWorkflowFailureError.__init__c                 C     | j sJ | j S )zCause of the workflow failure.r
  r   rc   rc   rd   r  k     
zWorkflowFailureError.causer  r  rZ   r   rZ   r  r^  r_  r`  ra  rt   re  r  r  rc   rc   rj  rd   r  c  
    r  c                      r  )r  z7Error that occurs when a workflow was continued as new.r  rM   rZ   r   c                   r  )z&Create workflow continue as new error.zWorkflow continued as newN)rb  rt   _new_execution_run_id)rs   r  rj  rc   rd   rt   u  r  z$WorkflowContinuedAsNewError.__init__c                 C  r  )z.New execution run ID the workflow continued to)r  r   rc   rc   rd   r  z  r  z0WorkflowContinuedAsNewError.new_execution_run_id)r  rM   rZ   r   rX  )r^  r_  r`  ra  rt   re  r  r  rc   rc   rj  rd   r  r  r  r  c                      r  )WorkflowQueryRejectedErrorz,Error that occurs when a query was rejected.r"  r!  rZ   r   c                   s   t  d|  || _dS )z%Create workflow query rejected error.zQuery rejected, status: N)rb  rt   _status)rs   r"  rj  rc   rd   rt     s   
z#WorkflowQueryRejectedError.__init__c                 C  r  )z0Get workflow execution status causing rejection.)r  r   rc   rc   rd   r"    r  z!WorkflowQueryRejectedError.status)r"  r!  rZ   r   )rZ   r!  )r^  r_  r`  ra  rt   re  r"  r  rc   rc   rj  rd   r    r  r  c                      r  )WorkflowQueryFailedErrorz%Error that occurs when a query fails.messagerM   rZ   r   c                   s   t  | || _dS )z#Create workflow query failed error.N)rb  rt   _message)rs   r  rj  rc   rd   rt     r  z!WorkflowQueryFailedError.__init__c                 C  r  )zGet query failed message.)r  r   rc   rc   rd   r    r  z WorkflowQueryFailedError.message)r  rM   rZ   r   rX  )r^  r_  r`  ra  rt   re  r  r  rc   rc   rj  rd   r    r  r  c                      r  )r  z'Error that occurs when an update fails.r  r  rZ   r   c                   r  )z$Create workflow update failed error.zWorkflow update failedNr	  r  rj  rc   rd   rt     r  z"WorkflowUpdateFailedError.__init__c                 C  r  )zCause of the update failure.r  r   rc   rc   rd   r    r  zWorkflowUpdateFailedError.causer  r  r  rc   rc   rj  rd   r    r  r  c                   @  r  )RPCTimeoutOrCancelledErrorzEError that occurs on some client calls that timeout or get cancelled.Nr  rc   rc   rc   rd   r    r  r  c                      "   e Zd ZdZd fddZ  ZS )r   zError that occurs when update RPC call times out or is cancelled.

    Note, this is not related to any general concept of timing out or cancelling
    a running update, this is only related to the client call itself.
    rZ   r   c                      t  d dS )z2Create workflow update timeout or cancelled error.z*Timeout or cancellation waiting for updateNrb  rt   r   rj  rc   rd   rt        z1WorkflowUpdateRPCTimeoutOrCancelledError.__init__rf  r^  r_  r`  ra  rt   r  rc   rc   rj  rd   r     s    r   c                      s$   e Zd ZdZd	d
 fddZ  ZS )AsyncActivityCancelledErrorzLError that occurs when async activity attempted heartbeat but was cancelled.Nr  %Optional[ActivityCancellationDetails]rZ   r   c                   r  )z&Create async activity cancelled error.zActivity cancelledN)rb  rt   r  )rs   r  rj  rc   rd   rt     r  z$AsyncActivityCancelledError.__init__r]   )r  r!  rZ   r   r  rc   rc   rj  rd   r     s    r   c                      r  )ScheduleAlreadyRunningErrorz)Error when a schedule is already running.rZ   r   c                   r  )z&Create schedule already running error.zSchedule already runningNr  r   rj  rc   rd   rt     r  z$ScheduleAlreadyRunningError.__init__rf  r  rc   rc   rj  rd   r"    s    r"  c                   @  s   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ed< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded < d!ed"< ded#< d$ed%< d&ed'< d(ed)< d*ed+< ded,< d-Zd.ed/< d-S )0r   z8Input for :py:meth:`OutboundInterceptor.start_workflow`.rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   \Optional[Union[temporalio.common.SearchAttributes, temporalio.common.TypedSearchAttributes]]r   r   .Mapping[str, temporalio.api.common.v1.Payload]r   rN   r   r   r   r   r   r   rV   rF   r   rW   r   r   r   r   r   r   r   r   Nr   r   r^  r_  r`  ra  rn  r   rc   rc   rc   rd   r     s<   
 r   c                   @  s:   e Zd ZU dZded< ded< ded< ded< d	ed
< dS )r  z9Input for :py:meth:`OutboundInterceptor.cancel_workflow`.rM   r   rN   r   r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r       
 r  c                   @  2   e Zd ZU dZded< ded< ded< ded	< d
S )r  z;Input for :py:meth:`OutboundInterceptor.describe_workflow`.rM   r   rN   r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r       
 r  c                   @  sZ   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
ed< ded< ded< dS )r  zGInput for :py:meth:`OutboundInterceptor.fetch_workflow_history_events`.rM   r   rN   r   r'  r$  r(  r%  rW   r  rp  r  r  rV   rF   r   r   Nrm  rc   rc   rc   rd   r    s   
 r  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 )r+  z8Input for :py:meth:`OutboundInterceptor.list_workflows`.rN   r&  r   r$  r(  r%  rV   rF   r   r   r'  r#  Nrm  rc   rc   rc   rd   r+    s   
 r+  c                   @  *   e Zd ZU dZded< ded< ded< dS )	r.  z9Input for :py:meth:`OutboundInterceptor.count_workflows`.rN   r&  rV   rF   r   r   Nrm  rc   rc   rc   rd   r.  &  r  r.  c                   @  sZ   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ed< ded< ded< dS )r  z8Input for :py:meth:`OutboundInterceptor.query_workflow`.rM   r   rN   r   r&  r   r   rR   r  r$  r   r   r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r  /  s   
 r  c                   @  sJ   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ed< dS )r  z9Input for :py:meth:`OutboundInterceptor.signal_workflow`.rM   r   rN   r   r  r   r   r$  r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r  ?     
 r  c                   @  sJ   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ed< dS )r  z<Input for :py:meth:`OutboundInterceptor.terminate_workflow`.rM   r   rN   r   r   r   r   r  rV   rF   r   r   Nrm  rc   rc   rc   rd   r  L  r*  r  c                   @  sj   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ed< ded< ded< ded< ded< dS )r  z?Input for :py:meth:`OutboundInterceptor.start_workflow_update`.rM   r   rN   r   r   r  r   r   r   r   r   r$  r   r   r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r  Y  s   
 r  c                   @  R   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ed< ded< dS )r  zQUpdate input for :py:meth:`OutboundInterceptor.start_update_with_start_workflow`.rN   r  rM   r   r   r   r   r   r$  r   r   r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r  j  s   
 r  c                   @  s   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ed< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded < ded!< d"ed#< d$Zd%ed&< d$S )'r  zXStartWorkflow input for :py:meth:`OutboundInterceptor.start_update_with_start_workflow`.rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r#  r   r   r$  r   rN   r   r   r   r   rV   rF   r   r   r   Nr   r   r%  rc   rc   rc   rd   r  x  s0   
 r  c                   @  r'  )r  zJInput for :py:meth:`OutboundInterceptor.start_update_with_start_workflow`.r  r  r  r  RCallable[[temporalio.api.workflowservice.v1.StartWorkflowExecutionResponse], None]r  zCallable[[BaseException], None]r  Nrm  rc   rc   rc   rd   r    s   
 r  c                   @  >   e Zd ZU dZded< ded< ded< ded	< d
Zded< d
S )r  zBInput for :py:meth:`OutboundInterceptor.heartbeat_async_activity`.r  r  r   r  rV   rF   r   r   Nr  r  r^  r_  r`  ra  rn  r  rc   rc   rc   rd   r       
 r  c                   @  r-  )r	  zAInput for :py:meth:`OutboundInterceptor.complete_async_activity`.r  r  r  r   rV   rF   r   r   Nr  r  r.  rc   rc   rc   rd   r	    r/  r	  c                   @  sF   e Zd ZU dZded< ded< ded< ded	< d
ed< dZded< dS )r  z=Input for :py:meth:`OutboundInterceptor.fail_async_activity`.r  r  r  r  r   r  rV   rF   r   r   Nr  r  r.  rc   rc   rc   rd   r    s   
 r  c                   @  r-  )r  zLInput for :py:meth:`OutboundInterceptor.report_cancellation_async_activity`.r  r  r   r  rV   rF   r   r   Nr  r  r.  rc   rc   rc   rd   r    r/  r  c                   @  r+  )r>  z9Input for :py:meth:`OutboundInterceptor.create_schedule`.rM   r   r:  r9  rW   r7  r;  r8  r   r   r#  r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r>    s   
 r>  c                   @  r-  )rC  z8Input for :py:meth:`OutboundInterceptor.list_schedules`.r   r$  r(  r%  rV   rF   r   r   NrN   r&  )r^  r_  r`  ra  rn  r&  rc   rc   rc   rd   rC    r/  rC  c                   @  r'  )r  z;Input for :py:meth:`OutboundInterceptor.backfill_schedule`.rM   r   r;  r  rV   rF   r   r   Nrm  rc   rc   rc   rd   r    r(  r  c                   @  r)  )	r  z9Input for :py:meth:`OutboundInterceptor.delete_schedule`.rM   r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r    r  r  c                   @  r)  )	r  z;Input for :py:meth:`OutboundInterceptor.describe_schedule`.rM   r   rV   rF   r   r   Nrm  rc   rc   rc   rd   r    r  r  c                   @  r'  )r  z8Input for :py:meth:`OutboundInterceptor.pause_schedule`.rM   r   rN   r  rV   rF   r   r   Nrm  rc   rc   rc   rd   r    r(  r  c                   @  r'  )r  z:Input for :py:meth:`OutboundInterceptor.trigger_schedule`.rM   r   r  r  rV   rF   r   r   Nrm  rc   rc   rc   rd   r    r(  r  c                   @  r'  )r  z:Input for :py:meth:`OutboundInterceptor.unpause_schedule`.rM   r   rN   r  rV   rF   r   r   Nrm  rc   rc   rc   rd   r  "  r(  r  c                   @  r'  )r  z9Input for :py:meth:`OutboundInterceptor.update_schedule`.rM   r   r  r  rV   rF   r   r   Nrm  rc   rc   rc   rd   r  ,  s   
 r  c                   @  r'  )rI  zNInput for :py:meth:`OutboundInterceptor.update_worker_build_id_compatibility`.rM   r   rE  rD  rV   rF   r   r   Nrm  rc   rc   rc   rd   rI  9  r(  rI  c                   @  r'  )rN  zKInput for :py:meth:`OutboundInterceptor.get_worker_build_id_compatibility`.rM   r   r'  rK  rV   rF   r   r   Nrm  rc   rc   rc   rd   rN  C  r(  rN  c                   @  s:   e Zd ZU dZded< ded< ded< ded< d	ed
< dS )rV  zFInput for :py:meth:`OutboundInterceptor.get_worker_task_reachability`.rP  rO  rQ  rS  reachabilityrV   rF   r   r   Nrm  rc   rc   rc   rd   rV  M  r&  rV  c                   @  s   e Zd ZdZdddZdS )	InterceptorzVInterceptor for clients.

    This should be extended by any client interceptors.
    ra   OutboundInterceptorrZ   c                 C  s   |S )a  Method called for intercepting a client.

        Args:
            next: The underlying outbound interceptor this interceptor should
                delegate to.

        Returns:
            The new interceptor that will be called for each client call.
        rc   rs   ra   rc   rc   rd   ry   _  s   
zInterceptor.intercept_clientN)ra   r2  rZ   r2  )r^  r_  r`  ra  ry   rc   rc   rc   rd   r1  X  s    r1  c                   @  s(  e Zd ZdZdfddZdgd
dZdhddZdiddZdjddZdkddZ	dlddZ
dmd!d"Zdnd$d%Zdod'd(Zdpd+d,Zdqd.d/Zdrd1d2Zdsd4d5Zdtd7d8Zdud:d;Zdvd>d?ZdwdBdCZdxdEdFZdydHdIZdzdLdMZd{dOdPZd|dRdSZd}dUdVZd~dXdYZdd[d\Zdd_d`ZddcddZdeS )r2  zyOutboundInterceptor for intercepting client calls.

    This should be extended by any client outbound interceptors.
    ra   rZ   r   c                 C  
   || _ dS )zCreate the outbound interceptor.

        Args:
            next: The next interceptor in the chain. The default implementation
                of all calls is to delegate to the next interceptor.
        N)ra   r3  rc   rc   rd   rt   r  r   zOutboundInterceptor.__init__r"  r   r   c                      | j |I dH S )z7Called for every :py:meth:`Client.start_workflow` call.N)ra   r   rs   r"  rc   rc   rd   r   }     z"OutboundInterceptor.start_workflowr  c                      | j |I dH  dS )z7Called for every :py:meth:`WorkflowHandle.cancel` call.N)ra   r  r6  rc   rc   rd   r       z#OutboundInterceptor.cancel_workflowr  r  c                   r5  )z9Called for every :py:meth:`WorkflowHandle.describe` call.N)ra   r  r6  rc   rc   rd   r    r7  z%OutboundInterceptor.describe_workflowr  r  c                 C     | j |S )zECalled for every :py:meth:`WorkflowHandle.fetch_history_events` call.)ra   r  r6  rc   rc   rd   r    r]  z1OutboundInterceptor.fetch_workflow_history_eventsr+  r)  c                 C  r:  )z7Called for every :py:meth:`Client.list_workflows` call.)ra   r*  r6  rc   rc   rd   r*    r]  z"OutboundInterceptor.list_workflowsr.  r,  c                   r5  )z8Called for every :py:meth:`Client.count_workflows` call.N)ra   r-  r6  rc   rc   rd   r-    r7  z#OutboundInterceptor.count_workflowsr  r   c                   r5  )z6Called for every :py:meth:`WorkflowHandle.query` call.N)ra   r  r6  rc   rc   rd   r       z"OutboundInterceptor.query_workflowr  c                   r8  )z7Called for every :py:meth:`WorkflowHandle.signal` call.N)ra   r  r6  rc   rc   rd   r    r9  z#OutboundInterceptor.signal_workflowr  c                   r8  )z:Called for every :py:meth:`WorkflowHandle.terminate` call.N)ra   r  r6  rc   rc   rd   r    r9  z&OutboundInterceptor.terminate_workflowr  r  c                   r5  )zjCalled for every :py:meth:`WorkflowHandle.start_update` and :py:meth:`WorkflowHandle.execute_update` call.N)ra   r  r6  rc   rc   rd   r    r7  z)OutboundInterceptor.start_workflow_updater  c                   r5  )zCalled for every :py:meth:`Client.start_update_with_start_workflow` and :py:meth:`Client.execute_update_with_start_workflow` call.N)ra   r   r6  rc   rc   rd   r     r7  z4OutboundInterceptor.start_update_with_start_workflowr  c                   r8  )z?Called for every :py:meth:`AsyncActivityHandle.heartbeat` call.N)ra   r  r6  rc   rc   rd   r       z,OutboundInterceptor.heartbeat_async_activityr	  c                   r8  )z>Called for every :py:meth:`AsyncActivityHandle.complete` call.N)ra   r  r6  rc   rc   rd   r    r9  z+OutboundInterceptor.complete_async_activityr  c                   r8  )z:Called for every :py:meth:`AsyncActivityHandle.fail` call.N)ra   r  r6  rc   rc   rd   r    r9  z'OutboundInterceptor.fail_async_activityr  c                   r8  )zICalled for every :py:meth:`AsyncActivityHandle.report_cancellation` call.N)ra   r  r6  rc   rc   rd   r    r<  z6OutboundInterceptor.report_cancellation_async_activityr>  r<  c                   r5  )z8Called for every :py:meth:`Client.create_schedule` call.N)ra   r=  r6  rc   rc   rd   r=    r;  z#OutboundInterceptor.create_schedulerC  rA  c                 C  r:  )z7Called for every :py:meth:`Client.list_schedules` call.)ra   rB  r6  rc   rc   rd   rB       z"OutboundInterceptor.list_schedulesr  c                   r8  )z9Called for every :py:meth:`ScheduleHandle.backfill` call.N)ra   r  r6  rc   rc   rd   r    r9  z%OutboundInterceptor.backfill_scheduler  c                   r8  )z7Called for every :py:meth:`ScheduleHandle.delete` call.N)ra   r  r6  rc   rc   rd   r    r9  z#OutboundInterceptor.delete_scheduler  r  c                   r5  )z9Called for every :py:meth:`ScheduleHandle.describe` call.N)ra   r  r6  rc   rc   rd   r    r7  z%OutboundInterceptor.describe_scheduler  c                   r8  )z6Called for every :py:meth:`ScheduleHandle.pause` call.N)ra   r  r6  rc   rc   rd   r    r9  z"OutboundInterceptor.pause_scheduler  c                   r8  )z8Called for every :py:meth:`ScheduleHandle.trigger` call.N)ra   r  r6  rc   rc   rd   r    r9  z$OutboundInterceptor.trigger_scheduler  c                   r8  )z8Called for every :py:meth:`ScheduleHandle.unpause` call.N)ra   r  r6  rc   rc   rd   r    r9  z$OutboundInterceptor.unpause_scheduler  c                   r8  )z7Called for every :py:meth:`ScheduleHandle.update` call.N)ra   r  r6  rc   rc   rd   r    r9  z#OutboundInterceptor.update_schedulerI  c                   r8  )zMCalled for every :py:meth:`Client.update_worker_build_id_compatibility` call.N)ra   rH  r6  rc   rc   rd   rH    r<  z8OutboundInterceptor.update_worker_build_id_compatibilityrN  rL  c                   r5  )zJCalled for every :py:meth:`Client.get_worker_build_id_compatibility` call.N)ra   rM  r6  rc   rc   rd   rM    r7  z5OutboundInterceptor.get_worker_build_id_compatibilityrV  rT  c                   r5  )zECalled for every :py:meth:`Client.get_worker_task_reachability` call.N)ra   rU  r6  rc   rc   rd   rU    r7  z0OutboundInterceptor.get_worker_task_reachabilityN)ra   r2  rZ   r   r"  r   rZ   r   r"  r  rZ   r   r"  r  rZ   r  r"  r  rZ   r  r"  r+  rZ   r)  r"  r.  rZ   r,  r"  r  rZ   r   r"  r  rZ   r   r"  r  rZ   r   r"  r  rZ   r  r"  r  rZ   r  r"  r  rZ   r   r"  r	  rZ   r   r"  r  rZ   r   r"  r  rZ   r   r"  r>  rZ   r<  r"  rC  rZ   rA  r"  r  rZ   r   r"  r  rZ   r   r"  r  rZ   r  r"  r  rZ   r   r"  r  rZ   r   r"  r  rZ   r   r"  r  rZ   r   r"  rI  rZ   r   r"  rN  rZ   rL  r"  rV  rZ   rT  ) r^  r_  r`  ra  rt   r   r  r  r  r*  r-  r  r  r  r  r   r  r  r  r  r=  rB  r  r  r  r  r  r  r  rH  rM  rU  rc   rc   rc   rd   r2  l  s<    


























r2  c                   @  sj  e Zd ZdddZdd
dZdddZdddZdddZdddZdddZ	ddd Z
dd#d$Zdd'd(Zdd+d,Zdd/d0Zdd2d3Zdd5d6Zdd9d:Zdd?d@ZddBdCZddIdJZddLdMZddOdPZddRdSZddUdVZddYdZZdd]d^Zdd`daZddcddZddgdhZddjdkZddmdnZddpdqZ ddsdtZ!ddvdwZ"ddzd{Z#dd~dZ$dddZ%dS )rv   rz  r;   rZ   r   c                 C  s
   || _ d S r]   )r|  rT  rc   rc   rd   rt   	  r@  z_ClientImpl.__init__r"  r   r   c           	   
     s2  |j d ur| |I d H }n| |I d H }d }d}z4t|tjjjjr6| j	j
j|d|j|jdI d H }n| j	j
j|d|j|jdI d H }|j}|d}W n3 ty } z'|jtjkr}|jjr}tjjj }|jjd |r}tjj|j|j|jd d }~ww t| j	|j|j||j |d}t!|d| |S )	NFTr  eager_workflow_taskr   r  )r   r   r   ry  __temporal_eagerly_started)"r   3_build_signal_with_start_workflow_execution_request'_build_start_workflow_execution_requestrh  rg   rq  r  rs  'SignalWithStartWorkflowExecutionRequestr|  r   $signal_with_start_workflow_executionrF   r   start_workflow_executionr   r  r+   r"  r,   ALREADY_EXISTSgrpc_statusr  errordetails&WorkflowExecutionAlreadyStartedFailureUnpackr  WorkflowAlreadyStartedErrorr   r   r   r   r   setattr)	rs   r"  r  r   eagerly_startedr  r  r  r   rc   rc   rd   r     s\   



z_ClientImpl.start_workflow?temporalio.api.workflowservice.v1.StartWorkflowExecutionRequestc                   s   t jjj }| ||I d H  |j|_|jr|j|_dd |j	D  |j
 fdd|jD  |j  t jj rJd|j_d|j_d|j_|S )Nc                 S  s   g | ]}t jjjj|d qS ))workflow_event)rg   rq  r   rs  Link)r  linkrc   rc   rd   r  V  r  zG_ClientImpl._build_start_workflow_execution_request.<locals>.<listcomp>c                 3  s:    | ]}t jjjjt jjjjj|j|jd  dV  qdS ))urlrf  )nexuslinksN)rg   rq  r   rs  CallbackNexusrl  r   )r  callbackrn  rc   rd   r1  Z  s    

zF_ClientImpl._build_start_workflow_execution_request.<locals>.<genexpr>T)rg   rq  r  rs  StartWorkflowExecutionRequest*_populate_start_workflow_execution_requestr   request_eager_executionr   r   completion_callbacksextendr   rn  rm  _operation_context(_in_nexus_backing_workflow_start_contexton_conflict_optionsattach_request_idattach_completion_callbacksattach_linksrs   r"  r  rc   rr  rd   r\  J  s$   z3_ClientImpl._build_start_workflow_execution_requestItemporalio.api.workflowservice.v1.SignalWithStartWorkflowExecutionRequestc                   st   |j sJ | jjt| jj|jd}tjj	j
j|j d}|jr/|jj||jI d H  | ||I d H  |S )Nr  )signal_name)r   r|  r?   r  r&   r=   r   rg   rq  r  rs  r]  r   signal_inputrc  rw  ro  rt  rs   r"  r?   r  rc   rc   rd   r[  n  s"   

z?_ClientImpl._build_signal_with_start_workflow_execution_requestr  c                   s&   t jjj }| ||I d H  |S r]   )rg   rq  r  rs  rs  rt  r~  rc   rc   rd   9_build_update_with_start_start_workflow_execution_request  s   zE_ClientImpl._build_update_with_start_start_workflow_execution_requestr  Union[temporalio.api.workflowservice.v1.StartWorkflowExecutionRequest, temporalio.api.workflowservice.v1.SignalWithStartWorkflowExecutionRequest]<Union[StartWorkflowInput, UpdateWithStartStartWorkflowInput]c                   s  | j jt| j j|jd}| j j|_|j|_|j|j_	|j
|j
_	|jr3|jj||jI d H  |jd ur?|j|j |jd urK|j|j |jd urW|j|j | j j|_tt |_tdt|j|_tdt|j |_!|j"d ur|j"#|j" |j$|_$|j%d ur|j%& D ]\}}|j%j'| (||gI d H d  q|j)d urt*j+,|j)|j) t-||j.|j/I d H }|d ur|j0(| |j1d ur|j2|j1 |j3d ur| 4|j3|j5j'I d H  |j6d ur|j6(|j67  |j8d ur|j8(|j87  d S d S )Nr  z7temporalio.api.enums.v1.WorkflowIdReusePolicy.ValueTypez:temporalio.api.enums.v1.WorkflowIdConflictPolicy.ValueTyper   )9r|  r?   r  r&   r=   r   r   r   r%  r   r   r   r"  rc  rw  ro  r   r_  r!  r   r`  r   ra  rG   rM   uuiduuid4r   r   r   r   workflow_id_reuse_policyr   workflow_id_conflict_policyr   rt  r   r   r@  r?  CopyFromr   rg   rc  r|  r{  r   r   rb  r   workflow_start_delayr   r}  rf  r   r  r   )rs   r  r"  r?   r<  r  r  rc   rc   rd   rt    sj   








&





z6_ClientImpl._populate_start_workflow_execution_requestr  c                   sj   | j jjtjjjj| j jtjj	jj
|j|jpdd| j jtt |jp&ddd|j|jdI d H  d S )Nr[   r  )r=   r  rG   r   r   Tr  )r|  r   !request_cancel_workflow_executionrg   rq  r  rs  %RequestCancelWorkflowExecutionRequestr=   r   r  r   r   rG   rM   r  r  r   rF   r   r6  rc   rc   rd   r    s    



z_ClientImpl.cancel_workflowr  r  c              	     s|   t j| jjjtjjjj	| jj
tjjjj|j|jpdddd|j|jdI d H | jj
| jjt| jj
|jddI d H S )Nr[   r  r=   r0  Tr  r  )r=   rc  )r  re  r|  r   describe_workflow_executionrg   rq  r  rs   DescribeWorkflowExecutionRequestr=   r   r  r   r   rF   r   r?   r  r&   r6  rc   rc   rd   r    s,   


z_ClientImpl.describe_workflowr  r  c                 C     t | j|S r]   )r  r|  r6  rc   rc   rd   r    r   z)_ClientImpl.fetch_workflow_history_eventsr+  r)  c                 C  r  r]   )r)  r|  r6  rc   rc   rd   r*    r   z_ClientImpl.list_workflowsr.  r,  c                   sB   t | jjjtjjjj	| jj
|jpddd|j|jdI d H S )Nr[   )r=   r&  Tr  )r,  r}  r|  r   count_workflow_executionsrg   rq  r  rs  CountWorkflowExecutionsRequestr=   r&  rF   r   r6  rc   rc   rd   r-    s   

z_ClientImpl.count_workflowsr  r   c              
     s  | j jt| j j|jd}tjjj	j
| j jtjjj	j|j|jp"ddd}|jr3tdt|j|_|j|j_|jrJ|jjj||jI d H  |jd ur\| |j|jjjI d H  z| j jj|d|j|j dI d H }W n t!y } z|j"t#j$krt%|j& d }~ww |'drt(|j)j"rt*|j)j"d |j+jsd S |j,r|j,gnd }|-|j+j|I d H }|sd S t.|d	krt/0d
t.|  |d S )Nr  r[   r  r  z6temporalio.api.enums.v1.QueryRejectCondition.ValueTypeTr  query_rejectedr/   z"Expected single query result, got r   )1r|  r?   r  r&   r=   r   rg   rq  r  rs  QueryWorkflowRequestr   r  r   r  r   r   query_reject_conditionr&  
query_typer   
query_argsrc  rw  ro  r   r}  rf  r?  r   r  rF   r   r+   r"  r,   INVALID_ARGUMENTr  r  r  r  r  r2  query_resultr   r:  r  r  r  )rs   r"  r?   r  r  r  r  r  rc   rc   rd   r  	  sh   






z_ClientImpl.query_workflowr  c                   s   | j jt| j j|jd}tjjj	j
| j jtjjj	j|j|jp"dd|j| j jtt d}|jrB|jj||jI d H  |jd urS| |j|jjI d H  | j jj|d|j|jdI d H  d S )Nr  r[   r  )r=   r  r  rG   r   Tr  ) r|  r?   r  r&   r=   r   rg   rq  r  rs  SignalWorkflowExecutionRequestr   r  r   r  rG   rM   r  r  r   r"  rc  rw  ro  r   r}  rf  r?  r   signal_workflow_executionrF   r   r  rc   rc   rd   r  >  s0   




z_ClientImpl.signal_workflowr  c                   s   | j jt| j j|jd}tjjj	j
| j jtjjj	j|j|jp"dd|jp(d| j j|jp/dd}|jrC|jj||jI d H  | j jj|d|j|jdI d H  d S )Nr  r[   r  )r=   r  r  rG   r   Tr  )r|  r?   r  r&   r=   r   rg   rq  r  rs  !TerminateWorkflowExecutionRequestr   r  r   r  rG   r   r   r  rc  rw  ro  r   terminate_workflow_executionrF   r   r  rc   rc   rd   r  W  s,   


z_ClientImpl.terminate_workflowr  r  c              
     s  |j }| ||I d H }	 z| jjj|d|j|jdI d H }W n- ty= } z|jt	j
ks4|jt	jkr8t | d }~w tjyM } zt |d }~ww |jtjjjjjkrYnqt| j|jjj||jjj|jd}|drt|j|_ |j!t"j#kr|$ I d H  |S )NTr  )rz  r   r   r  r   r  )%r   (_build_update_workflow_execution_requestr|  r   update_workflow_executionrF   r   r+   r"  r,   r  r  r   r  r  stagerg   rq  rr  rs  r  r  r  requestmetar  r  r  r   r   r  r  r  r   r   r   r  )rs   r"  r   r  r  r  r   rc   rc   rd   r  n  sL   
z!_ClientImpl.start_workflow_updateCUnion[StartWorkflowUpdateInput, UpdateWithStartUpdateWorkflowInput]r   rM   @temporalio.api.workflowservice.v1.UpdateWorkflowExecutionRequestc              	     s   | j jt| j j|d}t|tr|j|jfnd\}}t	j
jjj| j jt	j
jjj||p.dd|p3dt	j
jjjt	j
jjj|jpEtt | j jdt	j
jjj|jddt	j
jjjt	j
jjj|jdd	}|jr{|jj jj!"|#|jI d H  |j$d ur| %|j$|jj j&j'I d H  |S )
Nr  NNr[   r  )r  rG   rl  )r  r"  r  )r=   r  r   r  r  )(r|  r?   r  r&   r=   rh  r  r   r   rg   rq  r  rs  UpdateWorkflowExecutionRequestr   r  r   RequestMetar  rM   r  r  rG   Inputr  rr  r  r  r   r   r  r"  rc  rw  ro  r   r}  rf  r?  )rs   r"  r   r?   r   r   r  rc   rc   rd   r    sV   





	
z4_ClientImpl._build_update_workflow_execution_requestr  c              
     s|  dd
 fdd}d }zz|   j j|I d H W W |r&s' | S S S  tjy: } z|}t |d }~w ty } zl|}|jt	j
t	jfv rPt |tjjj }|jjr|jjd |rtdd |jD d }|r|jtt	v r|jt	jkr|jrtjjj }|jd |rtjj jj jj|jd	}|t|jt	|j|j }|d }~ww |rs | w w w )NFr  r	  c                   s   s  |  dd S d S )NT)r  r  r"  
seen_startrc   rd   r    s   
z>_ClientImpl.start_update_with_start_workflow.<locals>.on_startr   c                 s  s@    | ]}|j tjkr|jr|jd  tjjjj	j
s|V  qdS )r   N)coder,   OKr  Isrg   rq  r  rs  MultiOperationExecutionAborted
DESCRIPTOR)r  strc   rc   rd   r1    s    
z?_ClientImpl.start_update_with_start_workflow.<locals>.<genexpr>r  r  )!!_start_workflow_update_with_startr  r  r  r  r  r   r+   r"  r,   r  r  rg   rq  rb  rs  MultiOperationExecutionFailurera  r  rd  ra   statusesr  rx   r`  rc  r  re  r   r   r   r  raw_grpc_status)rs   r"  r  r  _errmultiop_failurer"  r  rc   r  rd   r     sp   
82z,_ClientImpl.start_update_with_start_workflowstart_inputr!  r  r  r,  c                   s  |  |I d H }| j||jdI d H }tjjjj| jj	tjjjjj
|dtjjjjj
|dgd}	 | jj|I d H }|jd j}|jd j}	|| |	drU|	jnd }
|	jtjjjjjkrbnq3t| j|jjj|j|j|
|jd	}|jtjkr| I d H  |S )
N)r   rs  )update_workflow)r=   
operationsTr   r/   r  )rz  r   r   r  r  r   ) r  r  r   rg   rq  r  rs  ExecuteMultiOperationRequestr|  r=   	Operationr   execute_multi_operation	responsesr   r  r  r  r  rr  r  r  r  r  r  r  r   r   r   r   r   r  )rs   r  r!  r  	start_req
update_reqmultiop_reqmultiop_responser  update_responser  r   rc   rc   rd   r    sT   	
z-_ClientImpl._start_workflow_update_with_startr  c              	     s   |j p| jj}|jsd n||jI d H }t|jtr\| jjj	t
jjjj|jj|jjp-d|jj| jj| jj|dd|j|jdI d H }|jsM|jsM|jrZtt|j|j|jddd S | jjjt
jjjj|j| jj| jj|dd|j|jdI d H }|js|jrtt|j|j|jddd S )Nr[   r   r   r/  r=   rG   r  Tr  )cancel_requestedr  reset)r  r3  r=   rG   r  )r  r|  r?   r  encode_wrapperrh  r  r6  r   $record_activity_task_heartbeat_by_idrg   rq  r  rs  &RecordActivityTaskHeartbeatByIdRequestr   r   r/  r=   rG   rF   r   r  activity_pausedactivity_resetr   r"   record_activity_task_heartbeat"RecordActivityTaskHeartbeatRequest)rs   r"  r?   r  
resp_by_idr  rc   rc   rd   r  U  sl   


z$_ClientImpl.heartbeat_async_activityr	  c              	     s   |j p| jj}|jtjju rd n	||jgI d H }t|j	t
rK| jjjtjjjj|j	j|j	jp2d|j	j| jj| jj|dd|j|jdI d H  d S | jjjtjjjj|j	| jj| jj|dd|j|jdI d H  d S )Nr[   )r   r   r/  r=   rG   r   Tr  )r3  r=   rG   r   )r  r|  r?   r   rg   r   rl  r  rh  r  r6  r   %respond_activity_task_completed_by_idrq  r  rs  'RespondActivityTaskCompletedByIdRequestr   r   r/  r=   rG   rF   r   respond_activity_task_completed#RespondActivityTaskCompletedRequest)rs   r"  r?   r   rc   rc   rd   r    s>   


z#_ClientImpl.complete_async_activityr  c              
     s   |j p| jj}tjjj }||j	|I d H  |j
r%||j
I d H nd }t|jtrX| jjjtjjjj|jj|jjp>d|jj| jj| jj||dd|j|jdI d H  d S | jjjtjjjj|j| jj| jj||dd|j|jdI d H  d S )Nr[   )r   r   r/  r=   rG   r  r  Tr  )r3  r=   rG   r  r  )r  r|  r?   rg   rq  r  rs  Failureencode_failurer  r  r  rh  r  r6  r   "respond_activity_task_failed_by_idr  $RespondActivityTaskFailedByIdRequestr   r   r/  r=   rG   rF   r   respond_activity_task_failed RespondActivityTaskFailedRequest)rs   r"  r?   r  r  rc   rc   rd   r    sF   

	
z_ClientImpl.fail_async_activityr  c              	     s   |j p| jj}|jsd n||jI d H }t|jtrF| jjj	t
jjjj|jj|jjp-d|jj| jj| jj|dd|j|jdI d H  d S | jjjt
jjjj|j| jj| jj|dd|j|jdI d H  d S )Nr[   r  Tr  r  )r  r|  r?   r  r  rh  r  r6  r   $respond_activity_task_canceled_by_idrg   rq  r  rs  &RespondActivityTaskCanceledByIdRequestr   r   r/  r=   rG   rF   r   respond_activity_task_canceled"RespondActivityTaskCanceledRequest)rs   r"  r?   r  rc   rc   rd   r    s>   


z._ClientImpl.report_cancellation_async_activityr>  r<  c                   s  |j jjr|j jjstd|j jjs|j jjrtdd }|js%|jrPtjj j	j
|jr@tjj j	jtjjj	j|j jjdnd |jrLdd |jD nd d}zWtjjj	j jj|j|j  jI d H | jjtt |jsrd ntjjj	j fdd|j D I d H d	d
}|jrtj !|j|j  jj"j#|d|j$|j%dI d H  W n* t&y } z|j't(j)ko|j*j+o|j*j+d ,tjj-j	j.j/}|rt0  d }~ww t1 j|jS )NzGMust set limited actions to false if there are no remaining actions setzCMust set limited actions to true if there are remaining actions setr  c                 S  r  rc   r  r  brc   rc   rd   r    r  z/_ClientImpl.create_schedule.<locals>.<listcomp>)r7  backfill_requestc                   s.   i | ]\}}| j j|gI d H d qS r8  )r|  r?   ro  r;  r   rc   rd   r=  (  s
    z/_ClientImpl.create_schedule.<locals>.<dictcomp>rr  )r=   r  r9  initial_patchrG   r   r   Tr  r   )2r9  r  r  r  r  r7  r8  rg   rq  rs  SchedulePatchTriggerImmediatelyRequestrr  r  r  r  r  r  CreateScheduleRequestr|  r=   r   r  rG   rM   r  r  r   r   rz  r@  r   rc  r|  r   r=  rF   r   r+   r"  r,   r`  ra  r  r  rb  rc  r  r"  r<  )rs   r"  r  r  r  already_startedrc   r   rd   r=    s   





z_ClientImpl.create_schedulerC  rA  c                 C  r  r]   )rA  r|  r6  rc   rc   rd   rB  E  s   z_ClientImpl.list_schedulesr  c              	     sh   | j jjtjjjj| j j|j	tjj
jjdd |jD d| j jtt dd|j|jdI d H  d S )Nc                 S  r  rc   r  r  rc   rc   rd   r  N  r  z1_ClientImpl.backfill_schedule.<locals>.<listcomp>)r  r=   r  patchrG   r   Tr  )r|  r   patch_schedulerg   rq  r  rs  PatchScheduleRequestr=   r   r9  r  r  rG   rM   r  r  rF   r   r6  rc   rc   rd   r  H  s   


	z_ClientImpl.backfill_scheduler  c                   sB   | j jjtjjjj| j j|j	| j j
dd|j|jdI d H  d S )N)r=   r  rG   Tr  )r|  r   r  rg   rq  r  rs  DeleteScheduleRequestr=   r   rG   rF   r   r6  rc   rc   rd   r  X  s   
z_ClientImpl.delete_scheduler  r  c              	     sH   t |j| jjjtjjj	j
| jj|jdd|j|jdI d H | jjS )Nr=   r  Tr  )r  r  r   r|  r   r  rg   rq  r  rs  DescribeScheduleRequestr=   rF   r   r?   r6  rc   rc   rd   r  d  s   

	z_ClientImpl.describe_scheduler  c              	     b   | j jjtjjjj| j j|j	tjj
jj|jpdd| j jtt dd|j|jdI d H  d S )NzPaused via Python SDK)r  r  Tr  r|  r   r  rg   rq  r  rs  r  r=   r   r9  r  r  rG   rM   r  r  rF   r   r6  rc   rc   rd   r  u     


	z_ClientImpl.pause_scheduler  c              	     s   t jjjjj}|jrt jjjj|j}| jj	j
t jjjj| jj|jt jjjjt jjjj|dd| jjtt dd|j|jdI d H  d S )Nr  )r7  r  Tr  )rg   rq  rr  rs  r  r  r  r  r|  r   r  r  r  r=   r   r9  r  r  rG   rM   r  r  rF   r   )rs   r"  r  rc   rc   rd   r    s,   



z_ClientImpl.trigger_scheduler  c              	     r  )NzUnpaused via Python SDK)r  r  Tr  r  r6  rc   rc   rd   r    r  z_ClientImpl.unpause_scheduler  c                   s  | tt|j| jjjtj	j
jj| jj|jdd|j|jdI d H | jjd}t|r4|I d H }|s8d S t|ts?J tj	j
jj| jj|j|j| jI d H | jjtt d}|jd urq|jj  tj |j|j | jjj!|d|j|jdI d H  d S )Nr  Tr  )rc  )r=   r  r9  rG   r   )"r  r  r  r  r   r|  r   r  rg   rq  r  rs  r  r=   rF   r   r?   inspectiscoroutinerh  r  UpdateScheduleRequestr9  r  rG   rM   r  r  r   indexed_fieldsclearrc  r|  r  )rs   r"  r   r  rc   rc   rd   r    sR   

	




z_ClientImpl.update_schedulerI  c                   sB   |j  }| jj|_|j|_| jjj|d|j|jdI d H  d S )NTr  )	rD  _as_partial_protor|  r=   r   r   rH  rF   r   r~  rc   rc   rd   rH    s   

z0_ClientImpl.update_worker_build_id_compatibilityrN  rL  c                   sN   t jjjj| jj|j|jpdd}| jj	j
|d|j|jdI d H }t|S )Nr   )r=   r   rK  Tr  )rg   rq  r  rs  $GetWorkerBuildIdCompatibilityRequestr|  r=   r   rK  r   rM  rF   r   rL  r  rs   r"  r  r  rc   rc   rd   rM    s   

z-_ClientImpl.get_worker_build_id_compatibilityrV  rT  c                   sf   t jjjj| jj|j|j|j	r|j	
 nt jjjjjd}| jjj|d|j|jdI d H }t|S )N)r=   rO  rQ  r0  Tr  )rg   rq  r  rs   GetWorkerTaskReachabilityRequestr|  r=   rO  rQ  r0  r  rr  TaskReachabilityTASK_REACHABILITY_UNSPECIFIEDr   rU  rF   r   rT  r  r  rc   rc   rd   rU    s   

z(_ClientImpl.get_worker_task_reachabilitysourcerX  dest2MessageMap[Text, temporalio.api.common.v1.Payload]c                   s0   t ||| j d tjk| jjjI d H  d S )NrK   )r}  r|  r_   r0   r~  r?   r  )rs   r  r  rc   rc   rd   r}     s   z_ClientImpl._apply_headersN)rz  r;   rZ   r   r>  )r"  r   rZ   rh  )r"  r   rZ   r  )r"  r  rZ   rh  )r  r  r"  r  rZ   r   r?  r@  rA  rB  rC  rD  rE  rF  rG  )r"  r  r   rM   rZ   r  rH  )r  r  r!  r  r  r,  rZ   r  rI  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  )r  rX  r  r  rZ   r   )&r^  r_  r`  rt   r   r\  r[  r  rt  r  r  r  r*  r-  r  r  r  r  r  r   r  r  r  r  r  r=  rB  r  r  r  r  r  r  r  rH  rM  rU  r}  rc   rc   rc   rd   rv     sH    


;
$


=





5


/
1
K
<
9
"
'
&
H







-


rv   r  rX  r  r  encode_headersrW   codec+Optional[temporalio.converter.PayloadCodec]rZ   r   c                   sZ   | d u rd S |r$|d ur$|   D ]}||gI d H d }|| qtj| | d S r8  )valuesro  r  rg   r   r}  )r  r  r   r  rQ  new_payloadrc   rc   rd   r}    s   r}  r  r  !temporalio.api.history.v1.Historyc                 C  sF  t | trt| } nt| } t | tstd| d}t |t	s'td|D ]j}t |ts4tdt
d|dd t
d|d	d
 t
d|d t
d|dd t
d|d	d t
d|dd t
d|dd t
d|d	dd t
d|dd t
d|dd t
d|dd t|d	d  t|d!d" t|d#d$ q)tjjj| tjjj d%d&S )'NzJSON history not a dictionaryr  z'History does not have iterable 'events'zEvent not a dictionary/CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE;requestCancelExternalWorkflowExecutionFailedEventAttributesr  CONTINUE_AS_NEW_INITIATOR*	initiator
EVENT_TYPE	eventTypePARENT_CLOSE_POLICY3startChildWorkflowExecutionInitiatedEventAttributesparentClosePolicyRETRY_STATE
retryState/SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE4signalExternalWorkflowExecutionFailedEventAttributes+START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE0startChildWorkflowExecutionFailedEventAttributesTASK_QUEUE_KIND	taskQueuekindTIMEOUT_TYPE#workflowTaskTimedOutEventAttributestimeoutTypeWORKFLOW_ID_REUSE_POLICYworkflowIdReusePolicyWORKFLOW_TASK_FAILED_CAUSE!workflowTaskFailedEventAttributesr  "activityTaskStartedEventAttributeslastFailure'workflowExecutionStartedEventAttributescontinuedFailureT)ignore_unknown_fields)rh  rM   jsonloadsr{   deepcopydictr  rN  r   _fix_history_enum_fix_history_failurer  r  r  	ParseDictrg   rq  r  rs  r  )r  r  r  rc   rc   rd   r    s   





r  z([A-Z]+)parentr  attrsrM   c                 G  s   t d| g|ddR   t d| g|ddR   | g}|D ]5}g }|D ]'} |dkr=|  D ]}t|tr;|| q/q%| |}t|trL|| q%|sR d S |}q|D ]} t| d qWd S )Nr  timeoutFailureInfor  r  r	  r  r  )r)  r  rh  r(  appendrN  r*  )r,  r-  parentsattrnew_parentsr  childrc   rc   rd   r*  g  s<   




r*  prefixc                 G  s   |d dkr!|  D ]}t|trt| |g|dd  R   q
d S ||d }t|trNt|dkrN||d  | sL| t	d|
  ||d < d S d S t|trht|dkrht| |g|dd  R   d S t|trt|dkr|D ]}t|trt| |g|dd  R   qud S d S d S )Nr   r	  r/   z_\1)r  rh  r(  r)  rN  rM   r  
startswith_pascal_case_matchsubupperrx   )r4  r,  r-  r3  
child_itemrc   rc   rd   r)    s*   

r)  c                   @  s>   e Zd ZU dZded< 	 dddZdd	d
ZedddZdS )rL  zRepresents the sets of compatible Build ID versions associated with some Task Queue, as
    fetched by :py:meth:`Client.get_worker_build_id_compatibility`.
    zSequence[BuildIdVersionSet]version_setsrZ   BuildIdVersionSetc                 C  r}   )z4Returns the default version set for this task queue.r:  r   rc   rc   rd   default_set  r@  z$WorkerBuildIdVersionSets.default_setrM   c                 C  s   |    S )z1Returns the default Build ID for this task queue.)r>  r<   r   rc   rc   rd   default_build_id  r=  z)WorkerBuildIdVersionSets.default_build_idr  Gtemporalio.api.workflowservice.v1.GetWorkerBuildIdCompatibilityResponsec                 C  s   t dd | jD dS )Nc                 S  s   g | ]}t |jqS rc   )r;  rO  )r  mvsrc   rc   rd   r    r  z8WorkerBuildIdVersionSets._from_proto.<locals>.<listcomp>r=  )rL  major_version_sets)r  rc   rc   rd   r    s
   z$WorkerBuildIdVersionSets._from_protoN)rZ   r;  rX  )r  r@  rZ   rL  )	r^  r_  r`  ra  rn  r>  r?  rg  r  rc   rc   rc   rd   rL    s   
 

rL  c                   @  &   e Zd ZU dZded< 	 d	ddZdS )
r;  z8A set of Build IDs which are compatible with each other.rP  rO  rZ   rM   c                 C  r}   )z*Returns the default Build ID for this set.r<  )rO  r   rc   rc   rd   r<     r@  zBuildIdVersionSet.defaultNrX  )r^  r_  r`  ra  rn  r<   rc   rc   rc   rd   r;    s
   
 r;  c                   @  s   e Zd ZdZedddZdS )rE  znBase class for Build ID operations as used by
    :py:meth:`Client.update_worker_build_id_compatibility`.
    rZ   Itemporalio.api.workflowservice.v1.UpdateWorkerBuildIdCompatibilityRequestc                 C     dS )zReturns a partial request with the operation populated. Caller must populate
        non-operation fields. This is done b/c there's no good way to assign a non-primitive message
        as the operation after initializing the request.
        Nrc   r   rc   rc   rd   r    s   zBuildIdOp._as_partial_protoNrZ   rD  )r^  r_  r`  ra  r   r  rc   rc   rc   rd   rE    s    rE  c                   @  $   e Zd ZU dZded< d	ddZdS )
BuildIdOpAddNewDefaultzAdds a new Build Id into a new set, which will be used as the default set for
    the queue. This means all new workflows will start on this Build Id.
    rM   build_idrZ   rD  c                 C     t jjjj| jdS )N)#add_new_build_id_in_new_default_setrg   rq  r  rs  'UpdateWorkerBuildIdCompatibilityRequestrI  r   rc   rc   rd   r       
z(BuildIdOpAddNewDefault._as_partial_protoNrF  r^  r_  r`  ra  rn  r  rc   rc   rc   rd   rH    s   
 rH  c                   @  s>   e Zd ZU dZded< 	 ded< 	 dZded< 	 dd
dZdS )BuildIdOpAddNewCompatiblea  Adds a new Build Id into an existing compatible set. The newly added ID becomes
    the default for that compatible set, and thus new workflow tasks for workflows which have been
    executing on workers in that set will now start on this new Build Id.
    rM   rI  existing_compatible_build_idFrW   promote_setrZ   rD  c                 C  s,   t jjjjt jjjjj| j| j| jddS )N)new_build_idrQ  make_set_default)add_new_compatible_build_id)	rg   rq  r  rs  rM  AddNewCompatibleVersionrI  rQ  rR  r   rc   rc   rd   r    s   
z+BuildIdOpAddNewCompatible._as_partial_protoNrF  )r^  r_  r`  ra  rn  rR  r  rc   rc   rc   rd   rP    s   
 rP  c                   @  rC  )
BuildIdOpPromoteSetByBuildIdzPromotes a set of compatible Build Ids to become the current default set for the task queue.
    Any Build Id in the set may be used to target it.
    rM   rI  rZ   rD  c                 C  rJ  )N)promote_set_by_build_idrL  r   rc   rc   rd   r  
  rN  z.BuildIdOpPromoteSetByBuildId._as_partial_protoNrF  rO  rc   rc   rc   rd   rW     s
   
 rW  c                   @  rG  )
 BuildIdOpPromoteBuildIdWithinSetzQPromotes a Build Id within an existing set to become the default ID for that set.rM   rI  rZ   rD  c                 C  rJ  )N)promote_build_id_within_setrL  r   rc   rc   rd   r    rN  z2BuildIdOpPromoteBuildIdWithinSet._as_partial_protoNrF  rO  rc   rc   rc   rd   rY    s   
 rY  c                   @  s0   e Zd ZU dZded< 	 ded< 	 d
ddZd	S )BuildIdOpMergeSetszMerges two sets into one set, thus declaring all the Build Ids in both as compatible with one
    another. The default of the primary set is maintained as the merged set's overall default.
    rM   primary_build_idsecondary_build_idrZ   rD  c                 C  s(   t jjjjt jjjjj| j| jddS )N)primary_set_build_idsecondary_set_build_id)
merge_sets)rg   rq  r  rs  rM  	MergeSetsr\  r]  r   rc   rc   rd   r  0  s   
z$BuildIdOpMergeSets._as_partial_protoNrF  rO  rc   rc   rc   rd   r[  $  s   
 r[  c                   @  s*   e Zd ZU dZded< 	 ed
ddZd	S )rT  z=Contains information about the reachability of some Build IDsz!Mapping[str, BuildIdReachability]build_id_reachabilityr  Ctemporalio.api.workflowservice.v1.GetWorkerTaskReachabilityResponserZ   c                 C  s   t  }| jD ]6}t  }t }|jD ]}|jtjjjj	j
gkr%||j qdd |jD ||j< qt|t|d||j< qt|dS )Nc                 S  r{  rc   )TaskReachabilityTyper  r/  rc   rc   rd   r  P  r  z6WorkerTaskReachability._from_proto.<locals>.<listcomp>)task_queue_reachabilityunretrieved_task_queues)rb  )r(  rb  setre  r0  rg   rq  rr  rs  r  r  addr   BuildIdReachability	frozensetrI  rT  )r  mapping	bid_reach
tq_mappingunretrievedtq_reachrc   rc   rd   r  B  s$   


z"WorkerTaskReachability._from_protoN)r  rc  rZ   rT  r  rc   rc   rc   rd   rT  ;  s   
 rT  c                   @  s$   e Zd ZU dZded< 	 ded< dS )ri  zBContains information about the reachability of a specific Build IDz,Mapping[str, Sequence[TaskReachabilityType]]re  zFrozenSet[str]rf  Nrm  rc   rc   rc   rd   ri  \  s   
 ri  c                   @  s8   e Zd ZdZdZdZdZdZedd	d
Z	dddZ
dS )rd  z<Enumerates how a task might reach certain kinds of workflowsr/   r   r      r0  2temporalio.api.enums.v1.TaskReachability.ValueTyperZ   c                 C  sn   | t jjjjjkrtjS | t jjjjjkrtj	S | t jjjjj
kr$tjS | t jjjjjkr0tjS td|  )Nz"Cannot convert reachability type: )rg   rq  rr  rs  r  TASK_REACHABILITY_NEW_WORKFLOWSrd  NEW_WORKFLOWS$TASK_REACHABILITY_EXISTING_WORKFLOWSEXISTING_WORKFLOWS TASK_REACHABILITY_OPEN_WORKFLOWSOPEN_WORKFLOWS"TASK_REACHABILITY_CLOSED_WORKFLOWSCLOSED_WORKFLOWSr  )r0  rc   rc   rd   r  s  s"   z TaskReachabilityType._from_protoc                 C  sn   | t jkrtjjjjjS | t jkrtjjjjj	S | t j
kr$tjjjjjS | t jkr0tjjjjjS tjjjjjS r]   )rd  rs  rg   rq  rr  rs  r  rr  ru  rt  rw  rv  ry  rx  r  r   rc   rc   rd   r    s   



zTaskReachabilityType._to_protoN)r0  rq  rZ   rd  )rZ   rq  )r^  r_  r`  ra  rs  ru  rw  ry  rg  r  r  rc   rc   rc   rd   rd  k  s    rd  c                   @  s   e Zd ZdZedddddeji dddddd1ddZd2d d!Ze	d3d"d#Z
e	d4d%d&Ze	d5d'd(Ze	d6d)d*Zejd7d-d*Ze	d8d.d/Zejd9d0d/ZdS ):CloudOperationsClienta  Client for accessing Temporal Cloud Operations API.

    .. warning::
        This client and the API are experimental

    Most users will use :py:meth:`connect` to create a client. The
    :py:attr:`cloud_service` property provides access to a raw gRPC cloud
    service client.

    Clients are not thread-safe and should only be used in the event loop they
    are first connected in. If a client needs to be used from another thread
    than where it was created, make sure the event loop where it was created is
    captured, and then call :py:func:`asyncio.run_coroutine_threadsafe` with the
    client call and that event loop.

    Clients do not work across forks since runtimes do not work across forks.
    Nzsaas-api.tmprl.cloud:443TF)r>   versionrL   rC   rD   rE   rF   rG   rH   rI   rJ   r>   rN   r{  rL   rM   rC   rS   rD   rT   rE   rU   rF   rV   rG   rH   rW   rI   rX   rJ   rY   rZ   c                   sR   |rt |}||d< tjj|| |||||pd||	|
d
}ttjj|I dH S )aL  Connect to a Temporal Cloud Operations API.

        .. warning::
            This client and the API are experimental

        Args:
            api_key: API key for Temporal. This becomes the "Authorization"
                HTTP header with "Bearer " prepended. This is only set if RPC
                metadata doesn't already have an "authorization" key. This is
                essentially required for access to the cloud API.
            version: Version header for safer mutations. May or may not be
                required depending on cloud settings.
            target_host: ``host:port`` for the Temporal server. The default is
                to the common cloud endpoint.
            tls: If true, the default, use system default TLS configuration. If
                false, the default, do not use TLS. If TLS configuration
                present, that TLS configuration will be used. The default is
                usually required to access the API.
            retry_config: Retry configuration for direct service calls (when
                opted in) or all high-level calls made by this client (which all
                opt-in to retries by default). If unset, a default retry
                configuration is used.
            keep_alive_config: Keep-alive configuration for the client
                connection. Default is to check every 30s and kill the
                connection if a response doesn't come back in 15s. Can be set to
                ``None`` to disable.
            rpc_metadata: Headers to use for all calls to the server. Keys here
                can be overriden by per-call RPC metadata keys.
            identity: Identity for this client. If unset, a default is created
                based on the version of the SDK.
            lazy: If true, the client will not connect until the first call is
                attempted or a worker is created with it. Lazy clients cannot be
                used for workers.
            runtime: The runtime for this client, or the default if unset.
            http_connect_proxy_config: Configuration for HTTP CONNECT proxy.
        ztemporal-cloud-api-versionr[   r\   N)r(  rg   rh   r'   rz  r-   ri   )r>   r{  rL   rC   rD   rE   rF   rG   rH   rI   rJ   rl   rc   rc   rd   ri     s&   4zCloudOperationsClient.connectrn   ro   c                 C  r4  )zCreate a Temporal Cloud Operations client from a service client.

        .. warning::
            This client and the API are experimental

        Args:
            service_client: Existing service client to use.
        N_service_client)rs   rn   rc   rc   rd   rt     s   
zCloudOperationsClient.__init__c                 C  r  )r~   r|  r   rc   rc   rd   rn     r  z$CloudOperationsClient.service_clienttemporalio.service.CloudServicec                 C  s   | j jS )zRaw gRPC cloud service client.)r}  cloud_servicer   rc   rc   rd   r    s   z#CloudOperationsClient.cloud_servicec                 C  r   )r   )r}  r_   rG   r   rc   rc   rd   rG     r   zCloudOperationsClient.identityc                 C  r   )zHeaders for every call made by this client.

        Do not use mutate this mapping. Rather, set this property with an
        entirely new mapping to change the headers. This may include the
        ``temporal-cloud-api-version`` header if set.
        r   r   rc   rc   rd   rF     s   
z"CloudOperationsClient.rpc_metadatar   r   c                 C  r   )a  Update the headers for this client.

        Do not mutate this mapping after set. Rather, set an entirely new
        mapping if changes are needed. Currently this must be set with the
        ``temporal-cloud-api-version`` header if it is needed.
        N)rn   r_   rF   r   r   rc   rc   rd   rF      s   
	c                 C  r   r   r   r   rc   rc   rd   r>   ,  r   zCloudOperationsClient.api_keyc                 C  r   r   r   r   rc   rc   rd   r>   1  r   )r>   rN   r{  rN   rL   rM   rC   rS   rD   rT   rE   rU   rF   rV   rG   rN   rH   rW   rI   rX   rJ   rY   rZ   rz  )rn   ro   rW  )rZ   r~  rX  rZ  r[  r\  r]  )r^  r_  r`  ra  rg  r)   r<   ri   rt   re  rn   r  rG   rF   rf  r>   rc   rc   rc   rd   rz    s<    
F	rz  rc  rO   rg  rW  r  ,Optional[temporalio.api.sdk.v1.UserMetadata]c                   s   |d u r|d u rd S d }d }|d ur&t |tr$| |gI d H d }n|}|d ur=t |tr;| |gI d H d }n|}tjjjj||dS )Nr   )rg  r  )rh  rM   ro  rg   rq  sdkrs  UserMetadata)rc  rg  r  enc_summaryenc_detailsrc   rc   rd   r{  A  s   

r{  r  #Tuple[Optional[str], Optional[str]]c                   s\   |du rdS | dsdn| |jgI dH d | ds!dfS | |jgI dH d fS )zReturns (summary, details)Nr  rg  r   r  )r  r:  rg  r  )rc  r  rc   rc   rd   r`  W  s   r`  c                   @  s6   e Zd ZdZdddZeddd	ZedddZdS )Plugina  Base class for client plugins that can intercept and modify client behavior.

    Plugins allow customization of client creation and service connection processes
    through a chain of responsibility pattern. Each plugin can modify the client
    configuration or intercept service client connections.

    If the plugin is also a temporalio.worker.Plugin, it will additionally be propagated as a worker plugin.
    You should likley not also provide it to the worker as that will result in the plugin being applied twice.
    rZ   rM   c                 C  s   t | jd t | j S )zGet the name of this plugin. Can be overridden if desired to provide a more appropriate name.

        Returns:
            The fully qualified name of the plugin class (module.classname).
        .)r  r_  r`  r   rc   rc   rd   r   s  s   zPlugin.namer_   rp   c                 C  rE  )a  Hook called when creating a client to allow modification of configuration.

        This method is called during client creation and allows plugins to modify
        the client configuration before the client is fully initialized. Plugins
        can add interceptors, modify connection parameters, or change other settings.

        Args:
            config: The client configuration dictionary to potentially modify.

        Returns:
            The modified client configuration.
        Nrc   r|   rc   rc   rd   rq   {  s    zPlugin.configure_clientr'   ra   3Callable[[ConnectConfig], Awaitable[ServiceClient]]r-   c                   s   dS )a  Hook called when connecting to the Temporal service.

        This method is called during service client connection and allows plugins
        to intercept or modify the connection process. Plugins can modify connection
        parameters, add authentication, or provide custom connection logic.

        Args:
            config: The service connection configuration.

        Returns:
            The connected service client.
        Nrc   )rs   r_   ra   rc   rc   rd   r^     r  zPlugin.connect_service_clientNrX  )r_   rp   rZ   rp   )r_   r'   ra   r  rZ   r-   )r^  r_  r`  ra  r   r   rq   r^   rc   rc   rc   rd   r  h  s    

r  )
r  rX  r  r  r   rW   r  r  rZ   r   )r  r  rZ   r  )r,  r  r-  rM   rZ   r   )r4  rM   r,  r  r-  rM   rZ   r   )rc  rO   rg  rW  r  rW  rZ   r  )rc  rO   r  r  rZ   r  )ra  
__future__r   abcr  r{   r"  r  r  r%  rer  r  r   r   r   r   r   r   r	   enumr
   r   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   google.protobuf.duration_pb2r  google.protobuf.json_formatgoogle.protobuf.timestamp_pb2#google.protobuf.internal.containersr   typing_extensionsr   r   r    r!   temporalio.api.common.v1rg   temporalio.api.enums.v1temporalio.api.errordetails.v1temporalio.api.failure.v1temporalio.api.history.v1temporalio.api.schedule.v1temporalio.api.sdk.v1temporalio.api.taskqueue.v1temporalio.api.update.v1temporalio.api.workflow.v1!temporalio.api.workflowservice.v1temporalio.commontemporalio.convertertemporalio.exceptionstemporalio.nexus#temporalio.nexus._operation_contexttemporalio.runtimetemporalio.servicetemporalio.workflowtemporalio.activityr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   r0   typesr1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   rp   rp  r   r  r6  r0  r  r  r2  r,  r|  r)  r  r  r<  r  r$  r  r
  rO  rR  r  r  r  r  r:  r  r  r  r  r  r  r  r  r  r  r  r  r  rA  r  r   r  TemporalErrorr  r  r  r  r  r  r   r   r"  r   r  r  r  r+  r.  r  r  r  r  r  r  r  r  r	  r  r  r>  rC  r  r  r  r  r  r  r  rI  rN  rV  r1  r2  rv   r}  r  compiler6  r*  r)  rL  r;  rE  rH  rP  rW  rY  r[  rT  ri  rd  rz  rm  NexusCallbackro  r{  r`  r  rc   rc   rc   rd   <module>   s   L(0           9       1 Y  @/ ;h TX1=  R4(.#q4
| ] 	'
	#



						
         

H 4  