§
    )`ƒik  ã                   ó°   — d Z ddlmZ ddlmZ ddlmZmZ ddlZddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ e G d„ d¦  «        ¦   «         ZdS )zÑ
TaskSupport - Configuration for experimental task support.

This module provides the TaskSupport class which encapsulates all the
infrastructure needed for task-augmented requests: store, queue, and handler.
é    )ÚAsyncIterator)Úasynccontextmanager)Ú	dataclassÚfieldN)Ú	TaskGroup)ÚTaskResultHandler)ÚServerSession)ÚInMemoryTaskStore)ÚInMemoryTaskMessageQueueÚTaskMessageQueue)Ú	TaskStorec                   óè   — e Zd ZU dZeed<   eed<    ed¬¦  «        Ze	ed<    edd¬¦  «        Z
edz  ed	<   dd„Zed
efd„¦   «         Zed
ed         fd„¦   «         Zded
dfd„Zedd„¦   «         ZdS )ÚTaskSupporta   
    Configuration for experimental task support.

    Encapsulates the task store, message queue, result handler, and task group
    for spawning background work.

    When enabled on a server, this automatically:
    - Configures response routing for each session
    - Provides default handlers for task operations
    - Manages a task group for background task execution

    Example:
        # Simple in-memory setup
        server.experimental.enable_tasks()

        # Custom store/queue for distributed systems
        server.experimental.enable_tasks(
            store=RedisTaskStore(redis_url),
            queue=RedisTaskMessageQueue(redis_url),
        )
    ÚstoreÚqueueF)ÚinitÚhandlerN)r   ÚdefaultÚ_task_groupÚreturnc                 óD   — t          | j        | j        ¦  «        | _        dS )z/Create the result handler from store and queue.N)r   r   r   r   ©Úselfs    úx/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/mcp/server/experimental/task_support.pyÚ__post_init__zTaskSupport.__post_init__3   s   € å(¨¬°T´ZÑ@Ô@ˆŒˆˆó    c                 ó<   — | j         €t          d¦  «        ‚| j         S )z‚Get the task group for spawning background work.

        Raises:
            RuntimeError: If not within a run() context
        Nz7TaskSupport not running. Ensure Server.run() is active.)r   ÚRuntimeErrorr   s    r   Ú
task_groupzTaskSupport.task_group7   s%   € ð ÔÐ#ÝÐXÑYÔYÐYØÔÐr   c                óÊ   K  — t          j        ¦   «         4 ƒd{V —†}|| _        	 dW V — d| _        n# d| _        w xY w	 ddd¦  «        ƒd{V —† dS # 1 ƒd{V —†swxY w Y   dS )a"  
        Run the task support lifecycle.

        This creates a task group for spawning background task work.
        Called automatically by Server.run().

        Usage:
            async with task_support.run():
                # Task group is now available
                ...
        N)ÚanyioÚcreate_task_groupr   )r   Útgs     r   ÚrunzTaskSupport.runB   s  è è € õ Ô*Ñ,Ô,ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(°Ø!ˆDÔð(Øà#'Ô Ð ø 4Ô Ð'Ð'Ð'Ð'Ð'ð	(ð 	(ð 	(ñ 	(ô 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(øøøð 	(ð 	(ð 	(ð 	(ð 	(ð 	(s#   œA¥2ªA²	;»AÁ
AÁAÚsessionc                 ó:   — |                      | j        ¦  «         dS )ao  
        Configure a session for task support.

        This registers the result handler as a response router so that
        responses to queued requests (elicitation, sampling) are routed
        back to the waiting resolvers.

        Called automatically by Server.run() for each new session.

        Args:
            session: The session to configure
        N)Úadd_response_routerr   )r   r%   s     r   Úconfigure_sessionzTaskSupport.configure_sessionV   s    € ð 	×#Ò# D¤LÑ1Ô1Ð1Ð1Ð1r   c                 óL   —  | t          ¦   «         t          ¦   «         ¬¦  «        S )a  
        Create in-memory task support.

        Suitable for development, testing, and single-process servers.
        For distributed systems, provide custom store and queue implementations.

        Returns:
            TaskSupport configured with in-memory store and queue
        )r   r   )r
   r   )Úclss    r   Ú	in_memoryzTaskSupport.in_memorye   s/   € ð ˆsÝ#Ñ%Ô%Ý*Ñ,Ô,ð
ñ 
ô 
ð 	
r   )r   N)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r   r   r   r   r   Úpropertyr   r   r   r$   r	   r(   Úclassmethodr+   © r   r   r   r      s*  € € € € € € ðð ð, ÐÐÑØÐÐÑØ!& ¨EÐ!2Ñ!2Ô!2€GÐÐ2Ð2Ñ2Ø$) E¨u¸dÐ$CÑ$CÔ$C€K˜TÑ!ÐCÐCÑCðAð Að Að Að ð ˜Ið  ð  ð  ñ „Xð ð ð(˜=¨Ô.ð (ð (ð (ñ Ôð(ð&2¨ð 2¸4ð 2ð 2ð 2ð 2ð ð
ð 
ð 
ñ „[ð
ð 
ð 
r   r   )r/   Úcollections.abcr   Ú
contextlibr   Údataclassesr   r   r!   Ú	anyio.abcr   Ú+mcp.server.experimental.task_result_handlerr   Úmcp.server.sessionr	   Ú2mcp.shared.experimental.tasks.in_memory_task_storer
   Ú+mcp.shared.experimental.tasks.message_queuer   r   Ú#mcp.shared.experimental.tasks.storer   r   r3   r   r   ú<module>r=      s  ððð ð *Ð )Ð )Ð )Ð )Ð )Ø *Ð *Ð *Ð *Ð *Ð *Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (à €€€Ø Ð Ð Ð Ð Ð à IÐ IÐ IÐ IÐ IÐ IØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø PÐ PÐ PÐ PÐ PÐ PØ bÐ bÐ bÐ bÐ bÐ bÐ bÐ bØ 9Ð 9Ð 9Ð 9Ð 9Ð 9ð ð\
ð \
ð \
ð \
ð \
ñ \
ô \
ñ „ð\
ð \
ð \
r   