Skip to main content

PluginRegistry

Struct PluginRegistry 

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

Global runtime registry for StagePlugin instances.

Stores plugins keyed by PluginPosition and vends fully-built PluginChains on demand. The registry is designed to be populated once at startup and then used read-only during request processing.

For dynamic plugin management (add/remove while the pipeline is running), wrap the registry in an Arc<tokio::sync::RwLock<PluginRegistry>>.

§Example

use tokio_prompt_orchestrator::plugin::{
    PluginRegistry, PluginPosition, StagePlugin, PluginInput, PluginOutput,
};
use tokio_prompt_orchestrator::PipelineStage;
use async_trait::async_trait;
use std::sync::Arc;

struct Noop;

#[async_trait]
impl StagePlugin for Noop {
    fn name(&self) -> &'static str { "noop" }
    async fn process(&self, input: PluginInput) -> PluginOutput {
        PluginOutput::passthrough(input)
    }
}

let mut registry = PluginRegistry::new();
registry.register(
    PluginPosition::Before(PipelineStage::Rag),
    Arc::new(Noop),
);

assert_eq!(registry.plugin_count(PluginPosition::Before(PipelineStage::Rag)), 1);
registry.remove_all(PluginPosition::Before(PipelineStage::Rag));
assert_eq!(registry.plugin_count(PluginPosition::Before(PipelineStage::Rag)), 0);

Implementations§

Source§

impl PluginRegistry

Source

pub fn new() -> Self

Create a new, empty registry.

§Panics

This function does not panic.

Source

pub fn register( &mut self, position: PluginPosition, plugin: Arc<dyn StagePlugin>, )

Register a plugin at the given position.

Multiple plugins registered at the same position are chained in insertion order.

§Panics

This function does not panic.

Source

pub fn register_pre_hook(&mut self, hook: Arc<dyn InferenceHook>)

Register a pre-inference hook by name.

Pre-hooks are called in registration order immediately before inference. If any hook returns Err, the pipeline aborts with that error message.

§Panics

This function does not panic.

Source

pub fn register_post_hook(&mut self, hook: Arc<dyn InferenceHook>)

Register a post-inference hook by name.

Post-hooks are called in registration order immediately after a successful inference. Errors are logged but do not abort the response.

§Panics

This function does not panic.

Source

pub fn unregister_pre_hook(&mut self, name: &str)

Unregister a plugin by name from the pre-hook list.

Removes the first matching hook. No-op if the name is not found.

§Panics

This function does not panic.

Source

pub fn unregister_post_hook(&mut self, name: &str)

Unregister a plugin by name from the post-hook list.

Removes the first matching hook. No-op if the name is not found.

§Panics

This function does not panic.

Source

pub async fn run_pre_hooks( &self, ctx: &PluginContext, hook_timeout: Duration, ) -> Result<(), String>

Run all registered pre-inference hooks in order.

Returns Ok(()) if all hooks pass. Returns Err(message) at the first hook that signals a failure; remaining hooks are not called.

Each hook is run with a per-hook timeout of hook_timeout to prevent a slow hook from blocking the pipeline indefinitely.

§Errors

Returns the error message from the first failing hook.

§Panics

This function does not panic.

Source

pub async fn run_post_hooks(&self, ctx: &PluginContext, hook_timeout: Duration)

Run all registered post-inference hooks in order.

Unlike pre-hooks, post-hook errors are logged but do not abort the caller — the response has already been produced. Each hook still receives the full PluginContext (including response_payload).

Each hook is run with a per-hook timeout of hook_timeout.

§Panics

This function does not panic.

Source

pub fn remove_all(&mut self, position: PluginPosition)

Remove all plugins registered at position.

After this call, chain_for will return an empty chain for that position.

§Panics

This function does not panic.

Source

pub fn plugin_count(&self, position: PluginPosition) -> usize

Return the number of plugins registered at position.

§Panics

This function does not panic.

Source

pub fn chain_for(&self, position: PluginPosition) -> PluginChain

Return a PluginChain for the given position.

If no plugins are registered at position, the returned chain is empty and PluginChain::run will be a no-op passthrough.

The returned chain is a clone — callers may cache it and call run concurrently without synchronisation.

§Panics

This function does not panic.

Source

pub fn has_plugins(&self, position: PluginPosition) -> bool

Return true if any plugins are registered at position.

§Panics

This function does not panic.

Source

pub fn total_plugin_count(&self) -> usize

Return the total number of plugins across all positions.

§Panics

This function does not panic.

Source

pub fn summary(&self) -> Vec<(String, usize)>

Return a Vec of (position_label, plugin_count) for every registered position, sorted by label. Useful for diagnostics and logging.

§Panics

This function does not panic.

Source

pub fn pre_hook_count(&self) -> usize

Return the number of registered pre-inference hooks.

§Panics

This function does not panic.

Source

pub fn post_hook_count(&self) -> usize

Return the number of registered post-inference hooks.

§Panics

This function does not panic.

Trait Implementations§

Source§

impl Default for PluginRegistry

Source§

fn default() -> PluginRegistry

Returns the “default value” for a type. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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