+
    Q(i                        R t ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RI	H
t
 ^ RIHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ]'       d   ^ RIHt ^ RI	Ht ^ RIHt ]! ]4      tRR R lltRR R lltRR R lltR# )a   Task subscription helpers for sending MCP notifications (SEP-1686).

Subscribes to Docket execution state changes and sends notifications/tasks/status
to clients when their tasks change state.

This module requires fastmcp[tasks] (pydocket). It is only imported when docket is available.
)annotations)suppress)datetimetimezone)TYPE_CHECKING)ExecutionState)TaskStatusNotificationTaskStatusNotificationParams)DEFAULT_TTL_MS)parse_task_key)DOCKET_TO_MCP_STATE)
get_logger)Docket)	Execution)ServerSessionc               0    V ^8  d   QhRRRRRRRRRR	R
R/# )   task_idstrtask_keysessionr   docketr   poll_interval_msintreturnNone )formats   "h/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/server/tasks/subscriptions.py__annotate__r      sL     2V 2V2V2V 2V 	2V
 2V 
2V    c                  "    VP                  V4      G Rj  xL
 pVf   \        P                  RV  24       R# VP                  4         Rj  xL
  pVR,          R8X  d,   \	        VV VV\        VR,          4      VR7      G Rj  xL
  KC  VR,          R8X  g   KS  \        VV VVVVR7      G Rj  xL
  Kn   L Lk L5 LDpR#   \         d)   p\        P                  RT  R	T 2R
R7        Rp?R# Rp?ii ; i5i)aG  Subscribe to Docket execution events and send MCP notifications.

Per SEP-1686 lines 436-444, servers MAY send notifications/tasks/status
when task state changes. This is an optional optimization that reduces
client polling frequency.

Args:
    task_id: Client-visible task ID (server-generated UUID)
    task_key: Internal Docket execution key (includes session, type, component)
    session: MCP ServerSession for sending notifications
    docket: Docket instance for subscribing to execution events
    poll_interval_ms: Poll interval in milliseconds to include in notifications
NzNo execution found for task typestate)r   r   r   r   r#   r   progress)r   r   r   r   	executionr   zSubscription task failed for z: T)exc_info)get_executionloggerwarning	subscribe_send_status_notificationr   _send_progress_notification	Exception)r   r   r   r   r   r%   eventes   &&&&&   r   subscribe_to_task_updatesr0      s    (V ..x88	NN9'CD %..0 	 	%V}'/##%!(w8%5   v*,1##%!'%5  ' 9	 1,  V6wir!EPTUUVs   C:C B9 C C:C CB;C4C B=C C 2B?3C ;C=C ?C C C:C7C2,C:2C77C:c               4    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#   r   r   r   r   r   r   )r   s   "r   r   r   T   sW     C6 C6C6C6 C6 	C6
 C6 C6 
C6r    c                  "   \         pVP                  VR4      p\        V4      pVR,          p	VP                  RV	 RV R24      p
VP	                  4       ;_uu_4       GRj  xL
 pVP                  V
4      G Rj  xL
 pRRR4      GRj  xL
  X'       d   VP                  R4      M1\        P                  ! \        P                  4      P                  4       pRpV\        P                  8X  d   RpM/V\        P                  8X  d   R	pMV\        P                  8X  d   R
pRVRVRVR\        P                  ! \        P                  4      P                  4       R\        RV/pV'       d   WR&   \!        \"        P$                  ! V4      R7      p\'        \(        4      ;_uu_ 4        V P+                  V4      G Rj  xL
  RRR4       R#  ELk ELU ELH  + GRj  xL 
 '       g   i     EL`; i L4  + '       g   i     R# ; i5i)a  Send notifications/tasks/status to client.

Per SEP-1686 line 454: notification SHOULD NOT include related-task metadata
(taskId is already in params).

Args:
    session: MCP ServerSession
    task_id: Client-visible task ID
    task_key: Internal task key (for metadata lookup)
    docket: Docket instance
    state: Docket execution state (enum)
    poll_interval_ms: Poll interval in milliseconds
failed
session_idfastmcp:task:::created_atNutf-8zTask completed successfullyzTask failedzTask cancelledtaskIdstatus	createdAtlastUpdatedAtttlpollIntervalstatusMessageparams)r   getr   keyredisdecoder   nowr   utc	isoformatr   	COMPLETEDFAILED	CANCELLEDr
   r   r	   model_validater   r-   send_notification)r   r   r   r   r#   r   	state_map
mcp_status	key_partsr4   created_at_keyrD   created_at_bytes
created_atstatus_messageparams_dictnotifications   &&&&&&           r   r+   r+   T   s    , $Iuh/J x(I<(JZZ-
|1WI[ QRN||~~~!&>!:: ~
  	(\\(,,'113  N(((6	.''	'&	.**	*) 	'*Zhll3==?~(K '5O$ *+::;GL
 
)		''555 
	I : ~~~J 	6 
		s   A!H
#G$H
'G<G=GH
GH
CH
/;H
*G6?G4 G6H
GH
G1	G 
G1	)G1	+	H
4G66H		H
c               4    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%   r   r   r   r   r   r   )r   s   "r   r   r      sN     ;6 ;6;6;6 ;6 	;6
 ;6 ;6 
;6r    c                D  "   VP                  4       G Rj  xL
  VP                  '       d   VP                  P                  '       g   R# \        pVP	                  VP
                  R4      p\        V4      pVR,          p	VP                  RV	 RV R24      p
VP                  4       ;_uu_4       GRj  xL
 pVP	                  V
4      G Rj  xL
 pRRR4      GRj  xL
  X'       d   VP                  R4      M1\        P                  ! \        P                  4      P                  4       pRVR	VR
VR\        P                  ! \        P                  4      P                  4       R\        RVRVP                  P                  /p\!        \"        P$                  ! V4      R7      p\'        \(        4      ;_uu_ 4        V P+                  V4      G Rj  xL
  RRR4       R#  EL EL/ EL EL  + GRj  xL 
 '       g   i     EL$; i L7  + '       g   i     R# ; i5i)a'  Send notifications/tasks/status when progress updates.

Args:
    session: MCP ServerSession
    task_id: Client-visible task ID
    task_key: Internal task key
    docket: Docket instance
    execution: Execution object with current progress
    poll_interval_ms: Poll interval in milliseconds
Nr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   )syncr$   messager   rB   r#   r   rC   rD   rE   r   rF   r   rG   rH   r
   r   r	   rL   r   r-   rM   )r   r   r   r   r%   r   rN   rO   rP   r4   rQ   rD   rR   rS   rU   rV   s   &&&&&&          r   r,   r,      s    & ..
 Y%7%7%?%?%? $Iy9J x(I<(JZZ-
|1WI[ QRN||~~~!&>!:: ~
  	(\\(,,'113  	'*Zhll3==?~(++33K *+::;GL 
)		''555 
	O  : ~~~2 	6 
		s   H G!H H 	A,H 5G$6H 9G-G'G-H G*H +CH =HH
HH $H 'G-*H -H	3G64
H	?H		H 
HH		H N)i  ) __doc__
__future__r   
contextlibr   r   r   typingr   docket.executionr   	mcp.typesr   r	   fastmcp.server.tasks.configr
   fastmcp.server.tasks.keysr   fastmcp.server.tasks.requestsr   fastmcp.utilities.loggingr   r   r   r   mcp.server.sessionr   __name__r(   r0   r+   r,   r   r    r   <module>rg      sX    #  '   + J 6 4 = 0*0	H	2VjC6L;6 ;6r    