+
    Q(i&L                    6   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
 ^ RIHtHt ^ RIHtHtHt ^ RIt^ RIHtHt ^ RIHtHt ^ RIHt ]! ]4      t]'       d	   ^ R	IHtHt  ! R
 R]4      t]! R4      t  ! R R]PB                  ]] ,          4      t" ! R R]"R,          4      t# ! R R]"]PH                  PJ                  ,          4      t& ! R R]"]']PH                  PP                  ]PH                  PR                  ,          ,          ,          4      t*R# )zSEP-1686 client Task classes.)annotationsN)	AwaitableCallable)datetimetimezone)TYPE_CHECKINGGenericTypeVar)GetTaskResultTaskStatusNotification)MessageMessageHandler)
get_logger)CallToolResultClientc                  D   a  ] tR t^tRtR V 3R lltR V 3R lltRtV ;t# )TaskNotificationHandlerzEMessageHandler that routes task status notifications to Task objects.c                   V ^8  d   QhRR/# )   clientr    )formats   "Z/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/client/tasks.py__annotate__$TaskNotificationHandler.__annotate__   s     D Dv D    c                	Z   < \         SV `  4        \        P                  ! V4      V n        R # N)super__init__weakrefref_client_ref)selfr   	__class__s   &&r   r    TaskNotificationHandler.__init__   s    07F0Cr   c                    V ^8  d   QhRRRR/# )r   messager   returnNoner   )r   s   "r   r   r   !   s     ( (g ($ (r   c                <  <"   \        V\        P                  P                  4      '       dT   \        VP                  \
        4      '       d4   V P                  4       pV'       d   VP                  VP                  4       \        SV `%  V4      G Rj  xL
  R#  L5i)z7Dispatch messages, including task status notifications.N)

isinstancemcptypesServerNotificationrootr   r"    _handle_task_status_notificationr   dispatch)r#   r'   r   r$   s   && r   r1    TaskNotificationHandler.dispatch!   se     gsyy;;<<',,(>??))+;;GLLIgw'''s   A"B&-BBB)r"   )	__name__
__module____qualname____firstlineno____doc__r   r1   __static_attributes____classcell__r$   s   @r   r   r      s    OD D( (r   r   TaskResultTc                      ] tR t^/tRtRR R lltR R lt]R R l4       t]R	 R
 l4       t	R R lt
R R ltR R lt]P                  R R l4       tRRRR/R R lltR R ltR tRtR# )Taska  
Abstract base class for MCP background tasks (SEP-1686).

Provides a uniform API whether the server accepts background execution
or executes synchronously (graceful degradation per SEP-1686).

Subclasses:
    - ToolTask: For tool calls (result type: CallToolResult)
    - PromptTask: For prompts (future, result type: GetPromptResult)
    - ResourceTask: For resources (future, result type: ReadResourceResult)
Nc               $    V ^8  d   QhRRRRRR/# )r   r   r   task_idstrimmediate_resultzTaskResultT | Noner   )r   s   "r   r   Task.__annotate__<   s(     7 77 7 -	7r   c                t    Wn         W n        W0n        VRJV n        RV n        RV n        . V n        RV n        R# )z
Create a Task wrapper.

Args:
    client: The FastMCP client
    task_id: The task identifier
    immediate_result: If server executed synchronously, the immediate result
N)_client_task_id_immediate_result_is_immediate_status_cache_status_event_status_callbacks_cached_result)r#   r   r?   rA   s   &&&&r   r   Task.__init__<   sJ     !1-T9 4837  	 37r   c                   V ^8  d   QhRR/# r   r(   r)   r   )r   s   "r   r   rB   W   s       r   c                    V P                   '       d   R#  V P                  P                  pR#   \         d   p\        R4      ThRp?ii ; i)zValidate that client context is still active.

Raises:
    RuntimeError: If accessed outside client context (unless immediate)
NzoCannot access task results outside client context. Task futures must be used within 'async with client:' block.)rG   rD   sessionRuntimeError)r#   _es   &  r   _check_client_connectedTask._check_client_connectedW   sO     	$$A 	O 	s   . A
AA
c                   V ^8  d   QhRR/# )r   r(   r@   r   )r   s   "r   r   rB   i   s       r   c                    V P                   # )zGet the task ID.)rE   r#   s   &r   r?   Task.task_idh   s     }}r   c                   V ^8  d   QhRR/# )r   r(   boolr   )r   s   "r   r   rB   n   s     " "d "r   c                    V P                   # )zCheck if server executed the task immediately.

Returns:
    True if server executed synchronously (graceful degradation or no task support)
    False if server accepted background execution
)rG   rX   s   &r   returned_immediatelyTask.returned_immediatelym   s     !!!r   c                    V ^8  d   QhRRRR/# )r   statusr
   r(   r)   r   )r   s   "r   r   rB   w   s     K K- KD Kr   c                h   Wn         V P                  e   V P                  P                  4        V P                   F@  p V! V4      p\        P
                  ! V4      '       d   \        P                  ! V4       K@  KB  	  R#   \         d&   p\        P                  RT 2RR7        Rp?Kq  Rp?ii ; i)zProcess incoming notifications/tasks/status (internal).

Called by Client when a notification is received for this task.
Updates cache, triggers events, and invokes user callbacks.

Args:
    status: Task status from notification
NzTask callback error: T)exc_info)rH   rI   setrJ   inspectisawaitableasynciocreate_task	Exceptionloggerwarning)r#   r`   callbackresultrS   s   &&   r   _handle_status_notification Task._handle_status_notificationw   s     $ )""$ ..HK!&)&&v..''/ / /  K!6qc:TJJKs   :BB1B,,B1c                    V ^8  d   QhRRRR/# )r   rk   z1Callable[[GetTaskResult], None | Awaitable[None]]r(   r)   r   )r   s   "r   r   rB      s     0 0C0 
0r   c                <    V P                   P                  V4       R# )a  Register callback for status change notifications.

The callback will be invoked when a notifications/tasks/status is received
for this task (optional server feature per SEP-1686 lines 436-444).

Supports both sync and async callbacks (auto-detected).

Args:
    callback: Function to call with GetTaskResult when status changes.
             Can return None (sync) or Awaitable[None] (async).

Example:
    >>> task = await client.call_tool("slow_operation", {}, task=True)
    >>>
    >>> def on_update(status: GetTaskResult):
    ...     print(f"Task {status.taskId} is now {status.status}")
    >>>
    >>> task.on_status_change(on_update)
    >>> result = await task  # Callback fires when status changes
N)rJ   append)r#   rk   s   &&r   on_status_changeTask.on_status_change   s    0 	%%h/r   c                   V ^8  d   QhRR/# )r   r(   r
   r   )r   s   "r   r   rB      s     " "m "r   c           	       "   V P                  4        V P                  '       d@   \        P                  ! \        P
                  4      p\        V P                  RVVRRR7      # V P                  e   V P                  pV# V P                  P                  V P                  4      G Rj  xL
 V n        V P                  #  L5i)zGet current task status.

If server executed immediately, returns synthetic completed status.
Otherwise queries the server for current status.
	completedNi  )taskIdr`   	createdAtlastUpdatedAtttlpollInterval)rT   rG   r   nowr   utcr
   rE   rH   rD   get_task_status)r#   r|   cacheds   &  r   r`   Task.status   s      	$$&,,x||,C }}"!!  )''FM $(<<#?#?#NN!!! Os   B&C (B>)C c                   V ^8  d   QhRR/# )r   r(   r;   r   )r   s   "r   r   rB      s      k r   c                   "   R# 5i)zoWait for and return the task result.

Must be implemented by subclasses to return the appropriate result type.
Nr   rX   s   &r   rl   Task.result   s
      	s   statetimeoutg     r@c               $    V ^8  d   QhRRRRRR/# )r   r   z
str | Noner   floatr(   r
   r   )r   s   "r   r   rB      s)     =W =W"=W49=W	=Wr   c          	       "   V P                  4        V P                  '       d   V P                  4       G Rj  xL
 # V P                  f   \        P
                  ! 4       V n        \        P                  ! 4       p0 R	mpRp V P                  '       d@   V P                  P                  pVf   Wd9   d   V P                  # MWa8X  d   V P                  # \        P                  ! 4       V,
          pWr8  d*   \        RV P                   RT;'       g    R RV R24      hW',
          p \        P                  ! V P                  P                  4       \        WX4      R7      G Rj  xL
  V P                  P                  4        EK   ELL L$  \        P                   d9    T P                  P                  T P                  4      G Rj  xL 
 T n         EKU  i ; i5i)
a4  Wait for task to reach a specific state or complete.

Uses event-based waiting when notifications are available (fast),
with fallback to polling (reliable). Optimally wakes up immediately
on status changes when server sends notifications/tasks/status.

Args:
    state: Desired state ('submitted', 'working', 'completed', 'failed').
           If None, waits for any terminal state (completed/failed)
    timeout: Maximum time to wait in seconds

Returns:
    GetTaskResult: Final task status

Raises:
    TimeoutError: If desired state not reached within timeout
Ng      ?zTask z did not reach zterminal statez within s)r   >   failed	cancelledrv   )rT   rG   r`   rI   rf   EventtimerH   TimeoutErrorrE   wait_forwaitminclearrD   r~   )	r#   r   r   startterminal_statespoll_intervalcurrentelapsed	remainings	   &$$      r   r   	Task.wait   s    ( 	$$&&& %!(D		>!!!,,33=1#111 2%--- iikE)G!"DMM?/%:S:SCS9TT\]d\eefg   )IW&&&&++-s=7T   ""((*E '> '' W+/<<+G+G+V%V%V""Ws_   6GFAGA<GG&<F	 "F#F	 GF	 	=GG	
GGGGc                   V ^8  d   QhRR/# rN   r   )r   s   "r   r   rB     s     " "d "r   c                   "   V P                   '       d   R# V P                  4        V P                  P                  V P                  4      G Rj  xL
  RV n        R#  L5i)a'  Cancel this task, transitioning it to cancelled state.

Sends a tasks/cancel protocol request. The server will attempt to halt
execution and move the task to cancelled state.

Note: If server executed immediately (graceful degradation), this is a no-op
as there's no server-side task to cancel.
N)rG   rT   rD   cancel_taskrE   rH   rX   s   &r   cancelTask.cancel  sK      $$&ll&&t}}555! 	6s   AAAAc                >    V P                  4       P                  4       # )z!Allow 'await task' to get result.)rl   	__await__rX   s   &r   r   Task.__await__!  s    {{}&&((r   )rK   rD   rF   rG   rH   rJ   rI   rE   r   )r3   r4   r5   r6   r7   r   rT   propertyr?   r]   rm   rr   r`   abcabstractmethodrl   r   r   r   r8   r   r   r   r=   r=   /   s    
76"   " "K404"< 	 =W%)=W<A=W~"")r   r=   c                  B   a  ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	ToolTaski&  a  
Represents a tool call that may execute in background or immediately.

Provides a uniform API whether the server accepts background execution
or executes synchronously (graceful degradation per SEP-1686).

Usage:
    task = await client.call_tool_as_task("analyze", args)

    # Check status
    status = await task.status()

    # Wait for completion
    await task.wait()

    # Get result (waits if needed)
    result = await task.result()  # Returns CallToolResult

    # Or just await the task directly
    result = await task
c               (    V ^8  d   QhRRRRRRRR/# )r   r   r   r?   r@   	tool_namerA   zCallToolResult | Noner   )r   s   "r   r   ToolTask.__annotate__=  s2     $ $$ $ 	$
 0$r   c                4   < \         SV `  WV4       W0n        R# )z
Create a ToolTask wrapper.

Args:
    client: The FastMCP client
    task_id: The task identifier
    tool_name: Name of the tool being executed
    immediate_result: If server executed synchronously, the immediate result
N)r   r   
_tool_name)r#   r   r?   r   rA   r$   s   &&&&&r   r   ToolTask.__init__=  s      	*:;#r   c                   V ^8  d   QhRR/# )r   r(   r   r   )r   s   "r   r   r   P  s     9 9n 9r   c                6  "   V P                   e   V P                   # V P                  '       d   V P                  f   Q hV P                  pEMV P                  4        V P	                  4       G Rj  xL
  V P
                  P                  V P                  4      G Rj  xL
 p\        V\        4      '       d[   \        P                  P                  P                  V4      pV P
                  P                  V P                  VRR7      G Rj  xL
 pM\        V\        P                  P                  4      '       d2   V P
                  P                  V P                  VRR7      G Rj  xL
 pM\!        VR4      '       d   \!        VR4      '       dr   \        P                  P                  VP"                  VP$                  VP&                  R7      pV P
                  P                  V P                  VRR7      G Rj  xL
 pMTpWn         V#  EL ELr EL L L5i)zWait for and return the tool result.

If server executed immediately, returns the immediate result.
Otherwise waits for background task to complete and retrieves result.

Returns:
    CallToolResult: The parsed tool result (same as call_tool returns)
NT)raise_on_errorcontentstructured_content)r   structuredContent_meta)rK   rG   rF   rT   r   rD   get_task_resultrE   r+   dictr,   r-   r   model_validate_parse_call_tool_resultr   hasattrr   r   meta)r#   rl   
raw_result
mcp_results   &   r   rl   ToolTask.resultP  s     *&&&))555++F ((* ))+  $||;;DMMJJJ *d++ YY55DDZP
#||CCOOZ  D    J		(@(@AA#||CCOOZ  D   
 :y11g 47 7 "%!9!9 * 2 2*4*G*G(oo ": "J
 $(<<#G#GD $H $ F
 (F %I  K
sb   ,HAH0H1,HHA.HHAH'H(BH<H=HHHHH)rK   r   r   	r3   r4   r5   r6   r7   r   rl   r8   r9   r:   s   @r   r   r   &  s    ,$ $&9 9r   r   r   c                  B   a  ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	
PromptTaski  aG  
Represents a prompt call that may execute in background or immediately.

Provides a uniform API whether the server accepts background execution
or executes synchronously (graceful degradation per SEP-1686).

Usage:
    task = await client.get_prompt_as_task("analyze", args)
    result = await task  # Returns GetPromptResult
c               (    V ^8  d   QhRRRRRRRR/# )r   r   r   r?   r@   prompt_namerA   z mcp.types.GetPromptResult | Noner   )r   s   "r   r   PromptTask.__annotate__  s2     ( (( ( 	(
 ;(r   c                4   < \         SV `  WV4       W0n        R# )z
Create a PromptTask wrapper.

Args:
    client: The FastMCP client
    task_id: The task identifier
    prompt_name: Name of the prompt being executed
    immediate_result: If server executed synchronously, the immediate result
N)r   r   _prompt_name)r#   r   r?   r   rA   r$   s   &&&&&r   r   PromptTask.__init__  s      	*:;'r   c                   V ^8  d   QhRR/# )r   r(   zmcp.types.GetPromptResultr   )r   s   "r   r   r     s      7 r   c                  "   V P                   e   V P                   # V P                  '       d   V P                  f   Q hV P                  pM~V P                  4        V P	                  4       G Rj  xL
  V P
                  P                  V P                  4      G Rj  xL
 p\        P                  P                  P                  V4      pWn         V#  Lb L75i)zWait for and return the prompt result.

If server executed immediately, returns the immediate result.
Otherwise waits for background task to complete and retrieves result.

Returns:
    GetPromptResult: The prompt result with messages and description
N)rK   rG   rF   rT   r   rD   r   rE   r,   r-   GetPromptResultr   )r#   rl   r   s   &  r   rl   PromptTask.result  s      *&&&))555++F ((* ))+  $||;;DMMJJJ YY..==jIF %  Ks)   ,CA C/C0,CC6CC)rK   r   r   r   r:   s   @r   r   r     s    	( (& r   r   c                  B   a  ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	ResourceTaski  a[  
Represents a resource read that may execute in background or immediately.

Provides a uniform API whether the server accepts background execution
or executes synchronously (graceful degradation per SEP-1686).

Usage:
    task = await client.read_resource_as_task("file://data.txt")
    contents = await task  # Returns list[ReadResourceContents]
c               (    V ^8  d   QhRRRRRRRR/# )r   r   r   r?   r@   urirA   zLlist[mcp.types.TextResourceContents | mcp.types.BlobResourceContents] | Noner   )r   s   "r   r   ResourceTask.__annotate__  s2        	
r   c                4   < \         SV `  WV4       W0n        R# )z
Create a ResourceTask wrapper.

Args:
    client: The FastMCP client
    task_id: The task identifier
    uri: URI of the resource being read
    immediate_result: If server executed synchronously, the immediate result
N)r   r   _uri)r#   r   r?   r   rA   r$   s   &&&&&r   r   ResourceTask.__init__  s    & 	*:;	r   c                   V ^8  d   QhRR/# )r   r(   zElist[mcp.types.TextResourceContents | mcp.types.BlobResourceContents]r   )r   s   "r   r   r     s     6 6	N6r   c                  "   V P                   e   V P                   # V P                  '       d   V P                  f   Q hV P                  pEMV P                  4        V P	                  4       G Rj  xL
  V P
                  P                  V P                  4      G Rj  xL
 p\        V\        P                  P                  4      '       d   \        VP                  4      pM\        V\        4      '       d   RV9   d   . pVR,           F  p\        V\        4      '       d|   RV9   d;   VP                  \        P                  P                   P#                  V4      4       KZ  VP                  \        P                  P$                  P#                  V4      4       K  VP                  V4       K  	  TpM\        V\        4      '       d   TMV.pWn         V#  ELi EL?5i)zWait for and return the resource contents.

If server executed immediately, returns the immediate result.
Otherwise waits for background task to complete and retrieves result.

Returns:
    list[ReadResourceContents]: The resource contents
Ncontentsblob)rK   rG   rF   rT   r   rD   r   rE   r+   r,   r-   ReadResourceResultlistr   r   rq   BlobResourceContentsr   TextResourceContents)r#   rl   r   parsed_contentsitems   &    r   rl   ResourceTask.result  s     *&&&))555++F ((* ))+  $||;;DMMJJJ *cii&B&BCCj112J--*
2J"$&z22D!$--!T>+22 #		 > > M Md S ,22 #		 > > M Md S (..t4 3 ) (2*d'C'C* %?  Ks*   ,GAG0G1,GGD<GG)rK   r   r   r   r:   s   @r   r   r     s    	 ,6 6r   r   )+r7   
__future__r   r   rf   rd   r   r    collections.abcr   r   r   r   typingr   r   r	   	mcp.typesr,   r
   r   fastmcp.client.messagesr   r   fastmcp.utilities.loggingr   r3   ri   fastmcp.client.clientr   r   r   r;   ABCr=   r   r-   r   r   r   r   r   r   r   r   r   <module>r      s    # " 
     / ' 2 2  ; ; 0	H	<(n ($ m$t)377GK( t)nct$% cL>cii//0 >BZcii,,syy/M/MM	NOZr   