LLMController

Struct LLMController 

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

The main LLM controller that manages sessions and coordinates communication

Implementations§

Source§

impl LLMController

Source

pub fn new(event_func: Option<EventFunc>) -> Self

Creates a new LLM controller

§Arguments
  • event_func - Optional callback for controller events
Source

pub async fn start(&self)

Starts the controller’s event loop. This is idempotent - calling it multiple times has no effect. Should be spawned as a tokio task.

Source

pub async fn shutdown(&self)

Gracefully shuts down the controller and all sessions. This is idempotent - calling it multiple times has no effect.

Source

pub fn is_shutdown(&self) -> bool

Returns true if the controller has been shutdown

Source

pub fn is_started(&self) -> bool

Returns true if the controller has been started

Source

pub async fn create_session( &self, config: LLMSessionConfig, ) -> Result<i64, LlmError>

Creates a new LLM session.

§Arguments
  • config - Session configuration (includes model, API key, etc.)
§Returns

The session ID of the newly created session

§Errors

Returns an error if the session fails to initialize (e.g., TLS setup failure)

Source

pub async fn get_session(&self, session_id: i64) -> Option<Arc<LLMSession>>

Retrieves a session by its ID.

§Returns

The session if found, None otherwise

Source

pub async fn session_count(&self) -> usize

Returns the number of active sessions

Source

pub async fn send_input( &self, input: ControllerInputPayload, ) -> Result<(), ControllerError>

Sends input to the controller for processing.

§Arguments
  • input - The input payload to send
§Returns

Ok(()) if the input was sent successfully, Err otherwise.

Source

pub async fn get_session_token_usage( &self, session_id: i64, ) -> Option<TokenMeter>

Get token usage for a specific session.

Source

pub async fn get_model_token_usage(&self, model: &str) -> Option<TokenMeter>

Get token usage for a specific model.

Source

pub async fn get_total_token_usage(&self) -> TokenMeter

Get total token usage across all sessions.

Source

pub fn token_usage(&self) -> &TokenUsageTracker

Get a reference to the token usage tracker for advanced queries.

Source

pub fn tool_registry(&self) -> &Arc<ToolRegistry>

Returns a reference to the tool registry.

Source

pub fn user_interaction_registry(&self) -> &Arc<UserInteractionRegistry>

Returns a reference to the user interaction registry.

Source

pub async fn respond_to_interaction( &self, tool_use_id: &str, response: AskUserQuestionsResponse, ) -> Result<(), UserInteractionError>

Respond to a pending user interaction.

This is called by the UI when the user has answered questions.

§Arguments
  • tool_use_id - ID of the tool use to respond to.
  • response - The user’s answers.
Source

pub async fn pending_interactions_for_session( &self, session_id: i64, ) -> Vec<PendingQuestionInfo>

Get all pending interactions for a session.

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

Source

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

Check if a session has pending user interactions.

Source

pub fn permission_registry(&self) -> &Arc<PermissionRegistry>

Returns a reference to the permission registry.

Source

pub async fn respond_to_permission( &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 with scope).
Source

pub async fn pending_permissions_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.

Source

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

Check if a session has pending permission requests.

Source

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

Cancel a pending permission request.

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

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