Skip to main content

PluginRegistry

Struct PluginRegistry 

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

Manages registered plugin instances and hook handler mappings.

Stores PluginRef wrappers by name and HookEntry (PluginRef + handler) by hook name. The executor reads scheduling decisions from PluginRef.trusted_config and dispatches through the type-erased handler.

Supports two registration patterns:

  • register::<H>() — typed registration for a single hook name (derived from H::NAME).
  • register_for_names::<H>() — typed registration for multiple hook names (the CMF pattern where one handler covers cmf.tool_pre_invoke, cmf.llm_input, etc.).

Clone is cheap-ish: the HashMaps duplicate, but their values are all Arc-counted (Arc<PluginRef>, Arc<dyn AnyHookHandler>), so the inner data is shared. Used by PluginManager’s ArcSwap snapshot pattern, where every mutating method clones the registry, mutates the clone, and atomically swaps in a new snapshot.

Implementations§

Source§

impl PluginRegistry

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn register<H: HookTypeDef>( &mut self, plugin: Arc<dyn Plugin>, config: PluginConfig, handler: Arc<dyn AnyHookHandler>, ) -> Result<(), String>

Register a typed hook handler for its primary hook name.

The handler is registered under H::NAME. The config must come from the config loader — not from the plugin. The plugin must implement the handler trait generated by define_hook!.

§Type Parameters
  • H — the hook type (implements HookTypeDef).
§Arguments
  • plugin — the plugin implementation (must also implement the handler trait).
  • config — authoritative config from the config loader.
  • handler — type-erased handler wrapping the plugin’s handler trait impl.
Source

pub fn register_for_names<H: HookTypeDef>( &mut self, plugin: Arc<dyn Plugin>, config: PluginConfig, handler: Arc<dyn AnyHookHandler>, names: &[&str], ) -> Result<(), String>

Register a typed hook handler for multiple hook names.

This is the CMF pattern — one handler trait impl covers multiple hook names (cmf.tool_pre_invoke, cmf.llm_input, etc.).

§Arguments
  • plugin — the plugin implementation.
  • config — authoritative config from the config loader.
  • handler — type-erased handler.
  • names — hook names to register under.
Source

pub fn register_for_names_with_handler( &mut self, plugin: Arc<dyn Plugin>, config: PluginConfig, handler: Arc<dyn AnyHookHandler>, names: &[&str], ) -> Result<(), String>

Register a plugin with a handler for multiple hook names.

Like register_for_names but without requiring a HookTypeDef type parameter. Used by the config-driven factory path where the hook type is not known at compile time — the factory provides the handler directly.

Source

pub fn register_multi_handler( &mut self, plugin: Arc<dyn Plugin>, config: PluginConfig, handlers: Vec<(&str, Arc<dyn AnyHookHandler>)>, ) -> Result<(), String>

Register a plugin with multiple handlers, each for a specific hook.

Used when a plugin implements multiple hook types with different payloads (e.g., ToolPreInvoke and ToolPostInvoke). Each handler is registered under its paired hook name.

The plugin is registered once in the name index. Each handler gets its own HookEntry in the hook index under the specified name.

Source

pub fn unregister(&mut self, name: &str) -> Option<Arc<PluginRef>>

Unregister a plugin by name.

Removes the PluginRef from the name index and all HookEntries from the hook index. Returns the (Arc-wrapped) PluginRef if found.

Source

pub fn get(&self, name: &str) -> Option<Arc<PluginRef>>

Look up a PluginRef by name. Returns an Arc clone so callers don’t hold borrows on internal storage — works with snapshot-based dispatch where the registry may sit behind a transient guard.

Source

pub fn entries_for_hook(&self, hook_type: &HookType) -> &[HookEntry]

Returns all HookEntries for a given hook name, sorted by priority.

Returns an empty slice if no plugins are registered for the hook.

Source

pub fn has_hooks_for(&self, hook_type: &HookType) -> bool

Whether any plugins are registered for the given hook name.

Source

pub fn plugin_count(&self) -> usize

Total number of registered plugins.

Source

pub fn plugin_names(&self) -> Vec<String>

All registered plugin names. Returns owned Strings so callers don’t hold borrows on internal storage — works with snapshot-based dispatch where the registry may sit behind a transient guard.

Source

pub fn entries_for_plugin(&self, plugin_name: &str) -> Vec<(String, HookEntry)>

Returns every (hook_name, HookEntry) pair where the entry’s plugin matches the given name. Used by external orchestrators that need to build pre-resolved dispatch lineups for a single plugin across every hook it registered to (e.g. apl-cpex deciding which entry handles step-style invocations vs field-style invocations for the same plugin). Owned tuples — no borrows held on the registry.

Trait Implementations§

Source§

impl Clone for PluginRegistry

Source§

fn clone(&self) -> PluginRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for PluginRegistry

Source§

fn default() -> Self

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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