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
impl PluginRegistry
Sourcepub fn register(
&mut self,
position: PluginPosition,
plugin: Arc<dyn StagePlugin>,
)
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.
Sourcepub fn register_pre_hook(&mut self, hook: Arc<dyn InferenceHook>)
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.
Sourcepub fn register_post_hook(&mut self, hook: Arc<dyn InferenceHook>)
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.
Sourcepub fn unregister_pre_hook(&mut self, name: &str)
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.
Sourcepub fn unregister_post_hook(&mut self, name: &str)
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.
Sourcepub async fn run_pre_hooks(
&self,
ctx: &PluginContext,
hook_timeout: Duration,
) -> Result<(), String>
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.
Sourcepub async fn run_post_hooks(&self, ctx: &PluginContext, hook_timeout: Duration)
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.
Sourcepub fn remove_all(&mut self, position: PluginPosition)
pub fn remove_all(&mut self, position: PluginPosition)
Sourcepub fn plugin_count(&self, position: PluginPosition) -> usize
pub fn plugin_count(&self, position: PluginPosition) -> usize
Sourcepub fn chain_for(&self, position: PluginPosition) -> PluginChain
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.
Sourcepub fn has_plugins(&self, position: PluginPosition) -> bool
pub fn has_plugins(&self, position: PluginPosition) -> bool
Sourcepub fn total_plugin_count(&self) -> usize
pub fn total_plugin_count(&self) -> usize
Sourcepub fn summary(&self) -> Vec<(String, usize)>
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.
Sourcepub fn pre_hook_count(&self) -> usize
pub fn pre_hook_count(&self) -> usize
Sourcepub fn post_hook_count(&self) -> usize
pub fn post_hook_count(&self) -> usize
Trait Implementations§
Source§impl Default for PluginRegistry
impl Default for PluginRegistry
Source§fn default() -> PluginRegistry
fn default() -> PluginRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for PluginRegistry
impl !UnwindSafe for PluginRegistry
impl Freeze for PluginRegistry
impl Send for PluginRegistry
impl Sync for PluginRegistry
impl Unpin for PluginRegistry
impl UnsafeUnpin for PluginRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request