Skip to main content

PluginInitContext

Struct PluginInitContext 

Source
pub struct PluginInitContext<'a> {
Show 15 fields pub config_dir: &'a Path, pub state_root: &'a Path, pub tool_registry: Arc<ScopedToolRegistry>, pub advisor_registry: Arc<RwLock<AdvisorRegistry>>, pub hook_registry: Arc<HookRegistry>, pub broker: AnyBroker, pub llm_registry: Arc<LlmRegistry>, pub llm_config: Arc<LlmConfig>, pub reload_coord: Arc<ConfigReloadCoordinator>, pub sessions: Arc<SessionManager>, pub long_term_memory: Option<Arc<LongTermMemory>>, pub shutdown: CancellationToken, pub channel_adapter_registry: Arc<ChannelAdapterRegistry>, pub plugin_config: Arc<Value>, pub sandbox: Arc<SandboxRunner>,
}
Expand description

Bundle of handles a plugin’s init receives. Lifetimes tied to the boot scope; plugins that need long-lived clones must clone the Arc<...> fields explicitly.

Fields§

§config_dir: &'a Path

Resolved YAML config root. The plugin’s own config namespace lives at <config_dir>/plugins/<plugin_id>/ — use plugin_config_dir.

§state_root: &'a Path

Process-wide state root (NEXO_STATE_ROOT env or XDG default). The plugin’s own state namespace lives at <state_root>/plugins/<plugin_id>/ — use plugin_state_dir.

§tool_registry: Arc<ScopedToolRegistry>

Per-plugin scoped tool registry. Plugin registers <plugin_id>_* tools here. Names MUST match manifest.tools.expose and respect the reserved-prefix denylist; collisions are always rejected. See ScopedToolRegistry for the enforcement model.

§advisor_registry: Arc<RwLock<AdvisorRegistry>>

Advisor registry (advisory_hook). RwLock so multiple plugins can register without contention. Plugin acquires a write lock per registration: ctx.advisor_registry.write().await.register(...).

§hook_registry: Arc<HookRegistry>

Hook registry. For per-message lifecycle extensions (before_message / after_message).

§broker: AnyBroker

NATS broker handle. Plugin publishes/subscribes via broker.publish(topic, payload).await.

§llm_registry: Arc<LlmRegistry>

LLM provider builder. Plugin builds clients via llm_registry.build(&cfg.llm, &model_cfg)?.

§llm_config: Arc<LlmConfig>

LLM config the registry needs at build time (provider table with API keys, retry knobs, tenant overrides). Subprocess plugins (SubprocessNexoPlugin) pair this with llm_registry to construct LlmServices for the llm.complete JSON-RPC handler. In-tree plugins that build their own clients also use it.

§reload_coord: Arc<ConfigReloadCoordinator>

Reload coordinator. Plugin registers post-hooks via reload_coord.register_post_hook(Box::new(...)).await for hot-reload-aware behavior.

§sessions: Arc<SessionManager>

Process-shared session manager.

§long_term_memory: Option<Arc<LongTermMemory>>

Long-term memory (None when not configured by operator). Plugins that declare manifest.requires.nexo_capabilities = ["long_term_memory"] should validate this is Some and return PluginInitError::MissingNexoCapability otherwise.

§shutdown: CancellationToken

Daemon-wide shutdown signal. Plugin’s background tasks should tokio::select! on this to exit cleanly.

§channel_adapter_registry: Arc<ChannelAdapterRegistry>

Extension point for plugins shipping new channel kinds (SMS, Discord, IRC, Matrix, custom webhooks). Plugin’s init() calls ctx.channel_adapter_registry.register(Arc::new(MyAdapter), self.manifest().plugin.id.clone())?; First-registers-wins-rest-rejected — see crate::agent::channel_adapter::ChannelAdapterRegistrationError.

§plugin_config: Arc<Value>

Pre-loaded + pre-validated plugin config from <config_dir>/plugins/<plugin_id>/*.yaml. Always at least an empty mapping. Plugin treats it as read-only; typed views via serde_yaml::from_value(cfg.clone()). Validation errors short-circuit init() with InitOutcome::Failed BEFORE the plugin runs.

§sandbox: Arc<SandboxRunner>

Shared sandbox runner. Subprocess plugin adapters consume this at spawn time to wrap the child Command with bwrap argv when the plugin’s manifest declares [plugin.sandbox] enabled = true. In-tree plugins ignore the field. Built once by SubprocessRuntime at boot.

Implementations§

Source§

impl PluginInitContext<'_>

Source

pub fn plugin_config_dir(&self, plugin_id: &str) -> PathBuf

<config_dir>/plugins/<plugin_id>/. Plugin-scoped config namespace (the config loader reads this dir).

Source

pub fn plugin_state_dir(&self, plugin_id: &str) -> PathBuf

<state_root>/plugins/<plugin_id>/. Plugin-scoped state namespace (databases, caches, etc).

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for PluginInitContext<'a>

§

impl<'a> !UnwindSafe for PluginInitContext<'a>

§

impl<'a> Freeze for PluginInitContext<'a>

§

impl<'a> Send for PluginInitContext<'a>

§

impl<'a> Sync for PluginInitContext<'a>

§

impl<'a> Unpin for PluginInitContext<'a>

§

impl<'a> UnsafeUnpin for PluginInitContext<'a>

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> PolicyExt for T
where T: ?Sized,

Source§

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

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

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

Source§

fn vzip(self) -> V

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