Struct Plugin Context

View as Markdown

Generated from cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-pii-redaction -p nemo-relay-ffi -p nemo-relay-types -p nemo-relay-plugin -p nemo-relay-worker-proto -p nemo-relay-worker.

1pub struct PluginContext<'a> { /* private fields */ }

Borrowed safe wrapper around a host plugin registration context.

Implementations

impl<'a> PluginContext<'a>

impl<'a> PluginContext<'a>

from_raw

pub unsafe fn from_raw(
    host: &'a NemoRelayNativeHostApiV1,
    raw: *mut NemoRelayNativePluginContext,
) -> Self

Creates a plugin context wrapper from raw ABI parts.

Safety

host and raw must remain valid for the lifetime of this wrapper.

host_api

pub fn host_api(&self) -> &'a NemoRelayNativeHostApiV1

Returns the host ABI table backing this registration context.

runtime

pub fn runtime(&self) -> PluginRuntime

Returns a cloneable high-level runtime handle.

register_subscriber

pub fn register_subscriber<F>(&mut self, name: &str, callback: F) -> Result<()>where
    F: Fn(&Event) + Send + Sync + 'static,

Registers a typed event subscriber callback.

register_mark_sanitize_guardrail

pub fn register_mark_sanitize_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: Fn(&Event, EventSanitizeFields) -> EventSanitizeFields + Send + Sync + 'static,

Registers a typed mark event sanitizer.

register_scope_sanitize_start_guardrail

pub fn register_scope_sanitize_start_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: Fn(&Event, EventSanitizeFields) -> EventSanitizeFields + Send + Sync + 'static,

Registers a typed scope-start event sanitizer.

register_scope_sanitize_end_guardrail

pub fn register_scope_sanitize_end_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: Fn(&Event, EventSanitizeFields) -> EventSanitizeFields + Send + Sync + 'static,

Registers a typed scope-end event sanitizer.

register_tool_sanitize_request_guardrail

pub fn register_tool_sanitize_request_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: Fn(&str, Json) -> Json + Send + Sync + 'static,

Registers a typed tool sanitize-request guardrail.

register_tool_sanitize_response_guardrail

pub fn register_tool_sanitize_response_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: Fn(&str, Json) -> Json + Send + Sync + 'static,

Registers a typed tool sanitize-response guardrail.

register_tool_conditional_execution_guardrail

pub fn register_tool_conditional_execution_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: Fn(&str, &Json) -> Result<Option<String>> + Send + Sync + 'static,

Registers a typed tool conditional-execution guardrail.

register_tool_request_intercept

pub fn register_tool_request_intercept<F>(
    &mut self,
    name: &str,
    priority: i32,
    break_chain: bool,
    callback: F,
) -> Result<()>where
    F: Fn(&str, Json) -> Result<Json> + Send + Sync + 'static,

Registers a typed tool request intercept.

register_tool_execution_intercept

pub fn register_tool_execution_intercept<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: for<'next> Fn(&str, Json, ToolNext<'next>) -> Result<ToolExecutionInterceptOutcome> + Send + Sync + 'static,

Registers a typed tool execution intercept.

The callback returns a ToolExecutionInterceptOutcome. Calling ToolNext::call continues the chain and returns only the raw downstream result JSON; Relay retains downstream pending marks.

register_llm_sanitize_request_guardrail

pub fn register_llm_sanitize_request_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: for<'ctx> Fn(LlmRequest, LlmSanitizeRequestContext<'ctx>) -> Option<LlmRequest> + Send + Sync + 'static,

Registers a typed LLM sanitize-request guardrail.

register_llm_sanitize_response_guardrail

pub fn register_llm_sanitize_response_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: for<'ctx> Fn(Json, LlmSanitizeResponseContext<'ctx>) -> Option<Json> + Send + Sync + 'static,

Registers a typed LLM sanitize-response guardrail.

register_llm_conditional_execution_guardrail

pub fn register_llm_conditional_execution_guardrail<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: Fn(&LlmRequest) -> Result<Option<String>> + Send + Sync + 'static,

Registers a typed LLM conditional-execution guardrail.

register_llm_request_intercept

pub fn register_llm_request_intercept<F>(
    &mut self,
    name: &str,
    priority: i32,
    break_chain: bool,
    callback: F,
) -> Result<()>where
    F: Fn(&str, LlmRequest, Option<AnnotatedLlmRequest>) -> Result<LlmRequestInterceptOutcome> + Send + Sync + 'static,

Registers a typed LLM request intercept.

register_llm_execution_intercept

pub fn register_llm_execution_intercept<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: for<'next> Fn(&str, LlmRequest, LlmNext<'next>) -> Result<Json> + Send + Sync + 'static,

Registers a typed LLM execution intercept.

register_llm_stream_execution_intercept

pub fn register_llm_stream_execution_intercept<F>(
    &mut self,
    name: &str,
    priority: i32,
    callback: F,
) -> Result<()>where
    F: for<'next> Fn(&str, LlmRequest, LlmStreamNext<'next>) -> Result<LlmJsonStream> + Send + Sync + 'static,

Registers a typed LLM stream execution intercept.

Native ABI v2 represents stream execution as one JSON result. The host wraps that result as a one-chunk stream.

register_subscriber_raw

pub unsafe fn register_subscriber_raw(
    &mut self,
    name: &str,
    cb: NemoRelayNativeEventSubscriberCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw event subscriber callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_mark_sanitize_guardrail_raw

pub unsafe fn register_mark_sanitize_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeEventSanitizeCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw mark event sanitizer callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_scope_sanitize_start_guardrail_raw

pub unsafe fn register_scope_sanitize_start_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeEventSanitizeCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw scope-start event sanitizer callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_scope_sanitize_end_guardrail_raw

pub unsafe fn register_scope_sanitize_end_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeEventSanitizeCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw scope-end event sanitizer callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_tool_sanitize_request_guardrail_raw

pub unsafe fn register_tool_sanitize_request_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeToolJsonCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw tool sanitize-request guardrail callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_tool_sanitize_response_guardrail_raw

pub unsafe fn register_tool_sanitize_response_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeToolJsonCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw tool sanitize-response guardrail callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_tool_conditional_execution_guardrail_raw

pub unsafe fn register_tool_conditional_execution_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeToolConditionalCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw tool conditional-execution guardrail callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_tool_request_intercept_raw

pub unsafe fn register_tool_request_intercept_raw(
    &mut self,
    name: &str,
    priority: i32,
    break_chain: bool,
    cb: NemoRelayNativeToolJsonCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw tool request intercept callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_tool_execution_intercept_raw

pub unsafe fn register_tool_execution_intercept_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeToolExecutionCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw tool execution intercept callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_llm_sanitize_request_guardrail_raw

pub unsafe fn register_llm_sanitize_request_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeLlmSanitizeRequestCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw LLM sanitize-request guardrail callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_llm_sanitize_response_guardrail_raw

pub unsafe fn register_llm_sanitize_response_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeLlmSanitizeResponseCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw LLM sanitize-response guardrail callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_llm_conditional_execution_guardrail_raw

pub unsafe fn register_llm_conditional_execution_guardrail_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeLlmConditionalCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw LLM conditional-execution guardrail callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_llm_request_intercept_raw

pub unsafe fn register_llm_request_intercept_raw(
    &mut self,
    name: &str,
    priority: i32,
    break_chain: bool,
    cb: NemoRelayNativeLlmRequestInterceptCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw LLM request intercept callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_llm_execution_intercept_raw

pub unsafe fn register_llm_execution_intercept_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeLlmExecutionCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw LLM execution intercept callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_llm_stream_execution_intercept_raw

pub unsafe fn register_llm_stream_execution_intercept_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeLlmStreamExecutionCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers a raw LLM stream execution intercept callback.

Safety

cb, user_data, and free_fn must remain valid for every host callback invocation until the host deregisters the callback or calls free_fn. free_fn must match the allocation behind user_data.

register_async_middleware_raw

pub unsafe fn register_async_middleware_raw(
    &mut self,
    kind: NemoRelayNativeAsyncMiddlewareKind,
    name: &str,
    priority: i32,
    break_chain: bool,
    cb: NemoRelayNativeAsyncMiddlewareCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers completion-based asynchronous middleware through the ABI-v3 extension table.

Plugins built against older hosts receive NemoRelayStatus::InvalidArg instead of attempting to read beyond the legacy host table.

Safety

cb, user_data, and free_fn must remain valid until the host deregisters the callback or invokes free_fn. A callback returning Pending must settle and release its completion/next references. NemoRelayNativeAsyncMiddlewareKind::LlmStreamExecutionIntercept is rejected; use Self::register_async_stream_middleware_raw instead.

register_async_stream_middleware_raw

pub unsafe fn register_async_stream_middleware_raw(
    &mut self,
    name: &str,
    priority: i32,
    cb: NemoRelayNativeAsyncStreamMiddlewareCb,
    user_data: *mut c_void,
    free_fn: NemoRelayNativeFreeFn,
) -> NemoRelayStatus

Registers an incremental completion-based LLM stream intercept.

Safety

The callback and user data must remain valid until deregistration or free_fn; callback-owned next and stream handles must each be released exactly once. Stream pushes and rejection are nonblocking: Internal with a host last-error containing backpressured means the bounded queue is full and the operation may be retried. The output stream owns the callback lifetime. next may be invoked repeatedly or concurrently until that stream settles; Relay then rejects or cancels unfinished and later calls.