
    RmjN                         d Z ddlZddlmZ g dZ ej        d          ZdefdZdedefd	Z	d
ededz  fdZ
d
ededz  defdZd
ededz  defdZdS )a  
Session scoping for experimental task identifiers.

Task IDs generated by `run_task()` embed an opaque, per-session marker (the
"session scope") so that the default task handlers can tell which session
created a task. The default handlers for tasks/get, tasks/result, tasks/list,
and tasks/cancel only operate on tasks created by the requesting session.

Task IDs without a session scope (explicitly provided IDs, IDs created
directly through a TaskStore, or IDs created in stateless mode) have no known
creator. They can be used with tasks/get, tasks/result, and tasks/cancel from
any session - possession of the ID is what grants access - but they are never
included in tasks/list responses.

WARNING: These APIs are experimental and may change without notice.
    Nuuid4)new_session_scopescoped_task_idsession_scope_oftask_in_session_scopetask_listable_in_session_scopezX\A(?P<scope>[0-9a-f]{32}):[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\Zreturnc                  (    t                      j        S )z(Create a new opaque session scope token.)r   hex     j/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/mcp/server/experimental/task_scope.pyr   r   &   s    77;r   session_scopec                 (    |  dt                       S )z;Generate a task ID associated with the given session scope.:r   )r   s    r   r   r   +   s    ''egg'''r   task_idc                 h    t                               |           }|r|                    d          ndS )zGReturn the session scope embedded in a task ID, or None if it has none.scopeN)_SCOPED_TASK_IDmatchgroup)r   r   s     r   r   r   0   s1    !!'**E#(25;;wd2r   c                 4    t          |           }|du p||k    S )a!  Whether a task may be used by a requestor with the given session scope.

    Used by tasks/get, tasks/result, and tasks/cancel. A task whose ID carries
    no session scope has no known creator, so possession of the ID is what
    grants access to it: it can be used from any session.
    Nr   r   r   embeddeds      r   r   r   6   s&      ((Ht8x=88r   c                 4    t          |           }|duo||k    S )a  Whether a task may be included in a tasks/list response for the given session scope.

    Used by tasks/list. Listing is stricter than access by ID: a task is only
    listed to the session that created it. Tasks with no session scope are
    never listed because they have no known creator, and requestors with no
    session scope are never shown any tasks because the server cannot tell
    them apart.
    Nr   r   s      r   r	   r	   A   s&      ((H4=H$==r   )__doc__reuuidr   __all__compiler   strr   r   r   boolr   r	   r   r   r   <module>r%      s   " 
			         "*F 3    
(# (# ( ( ( (
3c 3cDj 3 3 3 393 9sTz 9d 9 9 9 9
>C 
>d
 
>t 
> 
> 
> 
> 
> 
>r   