Ë
    †Kà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y)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y)Ú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                 óN   — t        | j                  | j                  «      | _        y)z/Create the result handler from store and queue.N)r   r   r   r   ©Úselfs    úp/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/mcp/server/experimental/task_support.pyÚ__post_init__zTaskSupport.__post_init__3   s   € ä(¨¯©°T·Z±ZÓ@ˆó    c                 óH   — | j                   €t        d«      ‚| j                   S )z‚Get the task group for spawning background work.

        Raises:
            RuntimeError: If not within a run() context
        z7TaskSupport not running. Ensure Server.run() is active.)r   ÚRuntimeErrorr   s    r   Ú
task_groupzTaskSupport.task_group7   s(   € ð ×ÑÐ#ÜÐXÓYÐYØ×ÑÐr   c                óØ   K  — t        j                  «       4 ƒd{  –—† }|| _        	 d­–— d| _        ddd«      ƒd{  –—†  y7 Œ)# d| _        w xY w7 Œ# 1 ƒd{  –—†7  sw Y   yxY w­w)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   sh   è ø€ ô ×*Ñ*Ó,÷ 	(ð 	(°Ø!ˆDÔð(Üà#'Ô ÷	(÷ 	(ñ 	(ùð
 $(Õ úð	(ø÷ 	(÷ 	(ñ 	(üsX   ‚A*›AœA*ŸA¨A­A´A*¿AÁ A*Á	AÁAÁA*ÁA'ÁAÁA'Á#A*Úsessionc                 ó:   — |j                  | j                  «       y)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¡LÕ1r   c                 ó6   —  | 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   € ñ Ü#Ó%Ü*Ó,ô
ð 	
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€GÐÓ2Ù$)¨u¸dÔ$C€K˜TÑ!ÓCóAð ð ˜Iò  ó ð ð ð(˜=¨Ñ.ò (ó ð(ð&2¨ð 2¸4ó 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=      sF   ðñõ *Ý *ß (ã Ý å IÝ ,Ý Pß bÝ 9ð ÷\
ð \
ó ñ\
r   