+
    Q(i.                        R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	H
t
Ht ^ RIt^ RIHt ]P                  ! ]4      t]	'       d   ^ RIHt RtRtR	tR
tR R ltR R ltR R ltR# )aY  Background task elicitation support (SEP-1686).

This module provides elicitation capabilities for background tasks running
in Docket workers. Unlike regular MCP requests, background tasks don't have
an active request context, so elicitation requires special handling:

1. Set task status to "input_required" via Redis
2. Send notifications/tasks/status with elicitation metadata
3. Wait for client to send input via tasks/sendInput
4. Resume task execution with the provided input

This uses the public MCP SDK APIs where possible, with minimal use of
internal APIs for background task coordination.
)annotationsN)datetimetimezone)TYPE_CHECKINGAnycast)ServerSession)FastMCPz2fastmcp:task:{session_id}:{task_id}:elicit:requestz3fastmcp:task:{session_id}:{task_id}:elicit:responsez1fastmcp:task:{session_id}:{task_id}:elicit:statusi  c               0    V ^8  d   QhRRRRRRRRRR	R
R/# )   task_idstrsessionzServerSession | Nonemessageschemadict[str, Any]fastmcpr	   returnzmcp.types.ElicitResult )formats   "f/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/server/tasks/elicitation.py__annotate__r   *   sT     }A }A}A!}A }A 	}A
 }A }A    c                
  "   VP                   pVf   \        R4      h\        \        P                  ! 4       4      p^ RIHp V! 4       pVe   VP                  p	M\        VRR4      p	V	f   \        R4      h\        P                  WR7      p
\        P                  WR7      p\        P                  WR7      pRVRVR	V/pVP                  4       ;_uu_4       GRj  xL
 pVP                  VP                  V
4      \         P"                  ! V4      \$        R
7      G Rj  xL
  VP                  VP                  V4      R\$        R
7      G Rj  xL
  RRR4      GRj  xL
  \&        P(                  ! \*        P,                  4      P/                  4       pRRRRV RRRVRVRVR\$        R,          /RRRV RRRVRRVRVRV////p^ RIHp  V! V	VV4      G Rj  xL
  \$        p TP                  4       ;_uu_4       GRj  xL
 p\C        \D        TPG                  TP                  T4      .TR 7      4      G Rj  xL
 pT'       d   Tw  pp\         PH                  ! T4      pTP;                  TP                  T
4      TP                  T4      4      G Rj  xL
  \<        P>                  PA                  TPK                  R!R"4      TPK                  R#4      R7      uuRRR4      GRj  xL
  # RRR4      GRj  xL
   TP                  4       ;_uu_4       GRj  xL
 pTP;                  TP                  T
4      TP                  T4      TP                  T4      4      G Rj  xL
  RRR4      GRj  xL
  \<        P>                  PA                  RRR7      #  EL ELz ELN ELA  + GRj  xL 
 '       g   i     ELY; i EL  \4         d   p\6        P9                  RT T4        TP                  4       ;_uu_4       GRj  xL 
 pTP;                  TP                  T
4      TP                  T4      4      G Rj  xL 
  RRR4      GRj  xL 
  M-  + GRj  xL 
 '       g   i     M; i  \4         d     Mi ; i\<        P>                  PA                  RRR7      u Rp?# Rp?ii ; i EL ELw EL EL EL  + GRj  xL 
 '       g   i     EL; i  \4         d#   p\6        P9                  R$T T4        Rp?ELRp?ii ; i EL EL EL  + GRj  xL 
 '       g   i     EL; i  \4         d#   p\6        PM                  R%T T4        Rp?ELRp?ii ; i5i)&aI  Send an elicitation request from a background task.

This function handles the complexity of eliciting user input when running
in a Docket worker context where there's no active MCP request.

Args:
    task_id: The background task ID
    session: The MCP ServerSession for this task
    message: The message to display to the user
    schema: The JSON schema for the expected response
    fastmcp: The FastMCP server instance

Returns:
    ElicitResult containing the user's response

Raises:
    RuntimeError: If Docket is not available
    McpError: If the elicitation request fails
Nz}Background task elicitation requires Docket. Ensure 'fastmcp[tasks]' is installed and the server has task-enabled components.)get_task_context_fastmcp_state_prefixzCannot determine session_id for elicitation. This typically means elicit_for_task() was called outside a Docket worker context.
session_idr   
request_idr   r   exwaitingmethodznotifications/tasks/statusparamstaskIdstatusinput_requiredstatusMessage	createdAtlastUpdatedAtttli  _metaz$io.modelcontextprotocol/related-taskelicitation	requestIdrequestedSchema)push_notificationzSFailed to queue input_required notification for task %s, cancelling elicitation: %scancel)actioncontent)timeoutr1   acceptr2   z@BLPOP failed for task %s elicitation, falling back to cancel: %szIFailed to clean up elicitation keys for task %s (will expire via TTL): %s)'_docketRuntimeErrorr   uuiduuid4fastmcp.server.dependenciesr   r   getattrELICIT_REQUEST_KEYr   ELICIT_RESPONSE_KEYELICIT_STATUS_KEYredissetkeyjsondumpsELICIT_TTL_SECONDSr   nowr   utc	isoformat"fastmcp.server.tasks.notificationsr/   	ExceptionloggerwarningdeletemcptypesElicitResultr   r   blpoploadsgetdebug)r   r   r   r   r   docketr   r   task_contextr   request_keyresponse_key
status_keyelicit_requestr>   	timestampnotification_dictr/   emax_wait_secondsresult_keyresponse_dataresponsecleanup_errors   &&&&&                    r   elicit_for_taskrb   *   s    4 __F~_
 	
 TZZ\"J =#%L!,,
 W&=tD
e  %++z+SK&---UL"))Z)QJ 	j7&N ||~~~iiJJ{#JJ~&!  
 	
 	
 iiJJz"!  
 	
 	
 ~( X\\*446I.g&WY%,
 	2'*w%v 		5
4 EE
,=vFFF. *!
<<>>>U  ZZ-.,   F &,#m::m4 llJJ{+JJz*   yy--#<<(;$LL3 . / ">>>>H
<<>>>U,,

;'

<(

:&   "> 99!!4!@@} 	
	
 ~~~d 	G E 	a	
	||~~~llJJ{+JJz*   &~~~~~
  		yy%%Xt%DD#E2 "# ">>>6  
N	
 	

 " ">>>  
W	
 	

s  CUNU ?N"N .N"NN"UNA+UO N?O U$S  R-S 5R<9R0:R<AR<R3AR<S %R6&S *U+S 6R97S <T/ T	T/ AT T!T%T/ 0T1T/ 5"UN"N"U"N<	(N+)
N<	4N<	6	U?O R*R%%Q.P
Q.4Q:P=
;Q Q.QQ.R%Q+Q
Q+$Q+&Q.*R%+Q..Q<9R%;Q<<#R%R* U%R**U-S 0R<3R<6S 9S <S	S
S	S	S US T$T;UTU	T/ TT/ T,	T
T,	$T,	&T/ *U,T/ /U:UUUUc               0    V ^8  d   QhRRRRRRRRRR	R
R/# )r   r   r   r   r   r   r,   r   r   r	   r   Noner   )r   s   "r   r   r      sD     5 555 5  	5
 5 
5r   c           	       "    V P                  VR,          VR,          R7      G Rj  xL
 p\        VVVP                  VP                  VR7      G Rj  xL
  \        P                  RVVP                  4       R#  LS L)  \         d_   p\        P                  RY&4       \        TTRRTR7      G Rj  xL 
 pT'       g   \        P                  R	T4        Rp?R#  Rp?R# Rp?ii ; i5i)
a   Relay elicitation from a background task worker to the client.

Called by the notification subscriber when it detects an input_required
notification with elicitation metadata. Sends a standard elicitation/create
request to the client session, then uses handle_task_input() to push the
response to Redis so the blocked worker can resume.

Args:
    session: MCP ServerSession
    session_id: Session identifier
    task_id: Background task ID
    elicitation: Elicitation metadata (message, requestedSchema)
    fastmcp: FastMCP server instance
r   r.   )r   r.   N)r   r   r1   r2   r   z4Relayed elicitation response for task %s (action=%s)z+Failed to relay elicitation for task %s: %sr0   zGFailed to push cancel response for task %s (worker may block until TTL))elicithandle_task_inputr1   r2   rI   rR   rH   rJ   )r   r   r   r,   r   r]   r[   successs   &&&&&   r   relay_elicitationri      s     * ~~	*'(9: & 
 
  !==NN
 	
 	
 	BMM	

	
  DgQ)!
 
 
 NN/  sb   C,$B  A<+B  A>%B  :C,<B  >B   C))C$4B75C$C$C,$C))C,c               0    V ^8  d   QhRRRRRRRRRRR	R
/# )r   r   r   r   r1   r2   zdict[str, Any] | Noner   r	   r   boolr   )r   s   "r   r   r   "  sD     8 888 8 #	8
 8 
8r   c                ,  "   VP                   pVf   R# \        P                  WR7      p\        P                  WR7      pRVRV/pVP	                  4       ;_uu_4       GRj  xL
 p	V	P                  VP                  V4      4      G Rj  xL
 p
V
e   V
P                  R4      R8w  d    RRR4      GRj  xL
  R# V	P                  VP                  V4      \        P                  ! V4      4      G Rj  xL
  V	P                  VP                  V4      \        4      G Rj  xL
  V	P                  VP                  V4      R\        R	7      G Rj  xL
  RRR4      GRj  xL
  R
#  EL L L Ly LN L! L  + GRj  xL 
 '       g   i     R
# ; i5i)a  Handle input sent to a background task via tasks/sendInput.

This is called when a client sends input in response to an elicitation
request from a background task.

Args:
    task_id: The background task ID
    session_id: The MCP session ID
    action: The elicitation action ("accept", "decline", "cancel")
    content: The response content (for "accept" action)
    fastmcp: The FastMCP server instance

Returns:
    True if the input was successfully stored, False otherwise
NFr   r1   r2   zutf-8r!   	respondedr   T)r5   r<   r   r=   r>   rQ   r@   decodelpushrA   rB   expirerC   r?   )r   r   r1   r2   r   rS   rV   rW   r`   r>   r%   s   &&&&&      r   rg   rg   "  sU    , __F~&---UL"))Z)QJ 	&7H
 ||~~~yyJ!788>V]]73y@	 ~~ kkJJ|$JJx 
 	
 	

 ll6::l35GHHH iiJJz"!  
 	
 	
! ~, - 8 	

 	I	
! ~~~, s   A!F#E($F'$E7E+E7+F6E-7F=8E75E/6,E7"E1#.E7E3E7F!E5"F+E7-F/E71E73E75F7F	=F >
F		F		F)__doc__
__future__r   rA   loggingr7   r   r   typingr   r   r   	mcp.typesrL   r   	getLogger__name__rI   fastmcp.server.serverr	   r;   r<   r=   rC   rb   ri   rg   r   r   r   <module>ry      sm    #    ' + +  			8	$- J K G   }A@5p8r   