pub struct PluginContext {
pub request_id: String,
pub session_id: String,
pub request_payload: Value,
pub response_payload: Option<Value>,
pub metrics: HookMetrics,
pub metadata: HashMap<String, String>,
}Expand description
Rich context passed to every pre- and post-inference hook.
Hooks receive a shared reference to this struct; they cannot modify the
pipeline payload directly — they should use the returned PluginOutput
mechanism for that. The hook context is purely informational.
Fields§
§request_id: StringUnique ID for the in-flight request.
session_id: StringSession the request belongs to.
request_payload: ValueThe raw prompt/payload as submitted to the pipeline stage.
response_payload: Option<Value>The model response, if available (only set for post-inference hooks).
metrics: HookMetricsPerformance / cost metrics for this request.
metadata: HashMap<String, String>Arbitrary metadata forwarded from the original crate::PromptRequest.
Implementations§
Source§impl PluginContext
impl PluginContext
Sourcepub fn pre_inference(
request_id: impl Into<String>,
session_id: impl Into<String>,
request_payload: Value,
metadata: HashMap<String, String>,
elapsed_ms: u64,
) -> Self
pub fn pre_inference( request_id: impl Into<String>, session_id: impl Into<String>, request_payload: Value, metadata: HashMap<String, String>, elapsed_ms: u64, ) -> Self
Sourcepub fn post_inference(
request_id: impl Into<String>,
session_id: impl Into<String>,
request_payload: Value,
response_payload: Value,
metadata: HashMap<String, String>,
elapsed_ms: u64,
prompt_tokens: Option<u64>,
completion_tokens: Option<u64>,
estimated_cost_usd: f64,
) -> Self
pub fn post_inference( request_id: impl Into<String>, session_id: impl Into<String>, request_payload: Value, response_payload: Value, metadata: HashMap<String, String>, elapsed_ms: u64, prompt_tokens: Option<u64>, completion_tokens: Option<u64>, estimated_cost_usd: f64, ) -> Self
Sourcepub fn into_plugin_input(self) -> PluginInput
pub fn into_plugin_input(self) -> PluginInput
Convert this context into a PluginInput for use with PluginChain::run.
The request_payload becomes the chain payload; response_payload
(if present) is injected into metadata under the key "response_payload_json".
§Panics
This function does not panic.
Trait Implementations§
Source§impl Clone for PluginContext
impl Clone for PluginContext
Source§fn clone(&self) -> PluginContext
fn clone(&self) -> PluginContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PluginContext
impl RefUnwindSafe for PluginContext
impl Send for PluginContext
impl Sync for PluginContext
impl Unpin for PluginContext
impl UnsafeUnpin for PluginContext
impl UnwindSafe for PluginContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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