
    kKj                        d 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
 ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZ ddlmZ  G d de      Zy# e$ rZ ed
      edZ[ww xY w)u  Approval — a Provider that adds human-in-the-loop approval to any server.

The LLM presents a summary of what it's about to do, and the user
approves or rejects via buttons. The result is sent back into the
conversation as a message, prompting the LLM's next turn.

Requires ``fastmcp[apps]`` (prefab-ui).

Usage::

    from fastmcp import FastMCP
    from fastmcp.apps.approval import Approval

    mcp = FastMCP("My Server")
    mcp.add_provider(Approval())
    )annotations)Literal)SetState)SendMessage)	PrefabApp)
H3ButtonCardCardContent
CardFooter
CardHeaderColumnMutedRowText)If)STATEzFApproval requires prefab-ui. Install with: pip install 'fastmcp[apps]'N)
FastMCPAppc                  `     e Zd ZdZ	 ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZdd	Zdd
Z xZS )Approvalan  A Provider that adds human-in-the-loop approval to a server.

    The LLM calls the ``request_approval`` tool with a summary and
    optional details. The user sees an approval card with Approve and
    Reject buttons. Clicking either sends a message back into the
    conversation (via ``SendMessage``), triggering the LLM's next turn.

    The message appears as if the user sent it, so the LLM sees
    something like ``'"Deploy v3.2 to production" is APPROVED'``.

    Example::

        from fastmcp import FastMCP
        from fastmcp.apps.approval import Approval

        mcp = FastMCP("My Server")
        mcp.add_provider(Approval())

    Customized::

        Approval(
            title="Deploy Gate",
            approve_text="Ship it",
            approve_variant="default",
            reject_text="Abort",
            reject_variant="destructive",
        )
    zApproval RequiredApproveRejectdefaultoutline)titleapprove_textreject_textapprove_variantreject_variantc                   t         |   |       || _        || _        || _        || _        || _        | j                          y )N)super__init___title_approve_text_reject_text_approve_variant_reject_variant_register_tools)selfnamer   r   r   r   r   	__class__s          f/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/apps/approval.pyr"   zApproval.__init__O   sE     	)' /-    c                "    d| j                   dS )Nz	Approval())r*   )r)   s    r,   __repr__zApproval.__repr__e   s    499-q))r-   c                h    | | j                         	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dfd       }y )Nc                   |xs j                   }|xs j                  }|xs j                  }	|xs j                  }
|xs j                  }d|  d| }d|  d|	 }t        d      5 }t               5  t        |       ddd       t               5  t        d      5  t        | d       |rt        |       ddd       ddd       t               5  t        t        j                        5  t        d	       ddd       t        t        j                         5  t!        d
d      5  t#        |	|t%        |      t'        dd      g       t#        ||
t%        |      t'        dd      g       ddd       ddd       ddd       ddd       t)        ddi      S # 1 sw Y   "xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   axY w# 1 sw Y   exY w# 1 sw Y   ixY w# 1 sw Y   mxY w)u`  Request human approval before proceeding with an action.

            Call this tool proactively whenever you are about to take a
            significant or irreversible action and want the user to
            confirm first. Do NOT wait for the user to ask you to seek
            approval — use your judgment about when confirmation is
            appropriate.

            The user will see an approval card with the summary, optional
            details, and Approve/Reject buttons. When they click a button,
            their decision appears as a message in the conversation (as if
            the user typed it), like:

                "Deploy v3.2 to production" — I selected: Approve

            or:

                "Deploy v3.2 to production" — I selected: Reject

            IMPORTANT: After calling this tool, you MUST stop and wait
            for the user's response. Do not continue, do not take any
            other actions, do not generate further output until you see
            the "I selected:" message. If approved, continue with the
            action. If rejected, acknowledge and ask how to proceed.

            Args:
                summary: Brief description of the action requiring approval
                    (shown prominently to the user).
                details: Optional longer explanation, context, or
                    consequences of the action.
                title: Heading for the approval card (default: "Approval Required").
                approve_text: Label for the approve button (default: "Approve").
                reject_text: Label for the reject button (default: "Reject").
                approve_variant: Button style — "default", "destructive",
                    "success", or "info".
                reject_variant: Button style for the reject button
                    (same options plus "outline").
            "u   " — I selected: zmax-w-lg mx-auto)	css_classN   )gapzfont-mediumzResponse sent.   zw-full justify-end)r6   r4   decidedT)varianton_clickF)viewstate)r#   r$   r%   r&   r'   r
   r   r   r   r   r   r   r   r   r   r8   r   r	   r   r   r   )summarydetailsr   r   r   r   r   r#   _approve_reject
_approve_v	_reject_vapprove_msg
reject_msgr;   providers                  r,   request_approvalz2Approval._register_tools.<locals>.request_approvalk   s   ` -hooF#=x'='=H!:X%:%:G(EH,E,EJ&B(*B*BIgY&8
CKWI%7yAJ 23t\vJ " !]FqMM:g %2]
  \EMM*./ +U]]N+ Q2FG" '(1$/
$;$,Y$=*" # ((2$/$<$,Y$=*" H , " 4>  %( = "\ %2M]] +* HG ,+ "\ 43s   .G:9F%G:F>$F2?F>G:G.3G
?"G.!G"/AG	6G">G.G:%F/	*G:2F;7F>>G	G:
GG.GG""G+'G..G7	3G::H)NNNNNN)r=   strr>   
str | Noner   rH   r   rH   r   rH   r   rH   r   rH   returnr   )ui)r)   rF   rE   s     @r,   r(   zApproval._register_toolsh   s    	 #' $'+&**.)-Z	Z	Z	 Z	 %	Z	
 $Z	 (Z	 'Z	 Z	 
Z	r-   )r   )r*   rG   r   rG   r   rG   r   rG   r   z4Literal['default', 'destructive', 'success', 'info']r   z?Literal['default', 'outline', 'destructive', 'success', 'info']rI   None)rI   rG   )rI   rK   )__name__
__module____qualname____doc__r"   r0   r(   __classcell__)r+   s   @r,   r   r   1   s{    >  )%#   	
  

 
,*^r-   r   )rO   
__future__r   typingr   prefab_ui.actionsr   prefab_ui.actions.mcpr   prefab_ui.appr   prefab_ui.componentsr   r	   r
   r   r   r   r   r   r   r   !prefab_ui.components.control_flowr   prefab_ui.rxr   ImportError_excfastmcp.apps.appr   r    r-   r,   <module>r]      so   " # *1'   5" (Uz U  
Ps   6A A+	A&&A+