pub struct Confirmer { /* private fields */ }Expand description
Tool confirmation coordinator for Bot platforms.
One Confirmer is shared across all chat sessions (wrapped in Arc).
Pending confirmations are keyed by "{chat_id}:{tool_call_id}".
Implementations§
Source§impl Confirmer
impl Confirmer
Sourcepub fn new(platform_sender: Arc<dyn PlatformSender>, timeout: Duration) -> Self
pub fn new(platform_sender: Arc<dyn PlatformSender>, timeout: Duration) -> Self
Create a new Confirmer.
Sourcepub fn with_keywords(
platform_sender: Arc<dyn PlatformSender>,
timeout: Duration,
keywords: ConfirmKeywords,
) -> Self
pub fn with_keywords( platform_sender: Arc<dyn PlatformSender>, timeout: Duration, keywords: ConfirmKeywords, ) -> Self
Create a Confirmer with custom keywords.
Sourcepub async fn request(
&self,
chat_id: &str,
info: &ToolCallInfo,
auto_approve: bool,
) -> Result<bool>
pub async fn request( &self, chat_id: &str, info: &ToolCallInfo, auto_approve: bool, ) -> Result<bool>
Request tool confirmation. Sends a prompt message to the chat and waits for the user to reply with an approve/reject keyword.
- If
auto_approveis true, returnstrueimmediately without sending. - Returns
trueif approved,falseif rejected or timed out.
Sourcepub fn check_confirmation_response(
&self,
chat_id: &str,
text: &str,
) -> Option<bool>
pub fn check_confirmation_response( &self, chat_id: &str, text: &str, ) -> Option<bool>
Check whether a user message is a confirmation reply for a pending
request in chat_id. If it matches a keyword, the pending entry is
consumed and the waiting request() is unblocked.
Returns Some(approved) if the message was a confirmation reply,
None if there was no pending confirmation or the message didn’t
match a keyword.
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Periodically clean up expired pending confirmations.
Expired entries are removed; their waiting request() calls will then
time out on their own tokio::time::timeout.