PermissionRegistry

Struct PermissionRegistry 

Source
pub struct PermissionRegistry { /* private fields */ }
Expand description

Registry for managing permission requests and session-level grants.

This registry tracks tools that are blocked waiting for permission and provides methods for the UI to query and respond to these requests. It also caches session-level grants to avoid re-asking.

Implementations§

Source§

impl PermissionRegistry

Source

pub fn new(event_tx: Sender<ControllerEvent>) -> Self

Create a new PermissionRegistry.

§Arguments
  • event_tx - Channel to send events when permissions are requested.
Source

pub async fn is_granted( &self, session_id: i64, request: &PermissionRequest, ) -> bool

Check if permission is already granted for the session.

This checks if a previous session-level grant covers this request.

§Arguments
  • session_id - Session to check.
  • request - The permission request to check.
§Returns

True if permission was previously granted for the session.

Source

pub async fn register( &self, tool_use_id: String, session_id: i64, request: PermissionRequest, turn_id: Option<TurnId>, ) -> Result<Receiver<PermissionResponse>, PermissionError>

Register a permission request and get a receiver to await on.

This is called by the AskForPermissionsTool when it starts executing. The tool will await on the returned receiver until the UI responds.

§Arguments
  • tool_use_id - Unique ID for this tool use request.
  • session_id - Session that requested the permission.
  • request - The permission request details.
  • turn_id - Optional turn ID for this request.
§Returns

A oneshot receiver that will receive the user’s response.

Source

pub async fn respond( &self, tool_use_id: &str, response: PermissionResponse, ) -> Result<(), PermissionError>

Respond to a pending permission request.

This is called by the UI when the user has granted or denied permission.

§Arguments
  • tool_use_id - ID of the tool use to respond to.
  • response - The user’s response (grant/deny).
§Returns

Ok(()) if the response was sent successfully, or an error.

Source

pub async fn cancel(&self, tool_use_id: &str) -> Result<(), PermissionError>

Cancel a pending permission request (user declined).

This is called by the UI when the user closes the permission dialog without responding.

§Arguments
  • tool_use_id - ID of the tool use to cancel.
§Returns

Ok(()) if the request was found and cancelled, or NotFound error.

Source

pub async fn pending_for_session( &self, session_id: i64, ) -> Vec<PendingPermissionInfo>

Get all pending permission requests for a session.

This is called by the UI when switching sessions to display any pending permission requests for that session.

§Arguments
  • session_id - Session ID to query.
§Returns

List of pending permission info for the session.

Source

pub async fn cancel_session(&self, session_id: i64)

Cancel all pending permission requests for a session.

This is called when a session is destroyed. It drops the senders, which will cause the awaiting tools to receive a RecvError.

§Arguments
  • session_id - Session ID to cancel.
Source

pub async fn clear_session(&self, session_id: i64)

Clear all grants for a session.

This is called when a session ends or is reset.

§Arguments
  • session_id - Session ID to clear grants for.
Source

pub async fn has_pending(&self, session_id: i64) -> bool

Check if there are any pending permission requests for a session.

§Arguments
  • session_id - Session ID to check.
§Returns

True if there are pending permission requests.

Source

pub async fn pending_count(&self) -> usize

Get the count of pending permission requests.

Source

pub async fn session_grants(&self, session_id: i64) -> HashSet<PermissionGrant>

Get all session grants for a session.

§Arguments
  • session_id - Session ID to query.
§Returns

Set of grants for the session (empty if none).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more