Skip to main content

PluginCallContext

Struct PluginCallContext 

Source
pub struct PluginCallContext {
    pub request_id: Uuid,
    pub tenant_id: TenantId,
    pub user_id: UserId,
    pub plugin_instance_id: String,
    pub session_type_id: Uuid,
    pub plugin_config: Option<Value>,
    pub enabled_capabilities: Option<Vec<CapabilityValue>>,
    pub deadline: Option<Instant>,
    pub cancel: CancellationToken,
}
Expand description

Shared context attached to every plugin invocation.

Debug is implemented manually to redact plugin_config — it may contain secrets (API keys, webhook auth, credentials) that must never hit logs. Wrappers SessionPluginCtx / MessagePluginCtx derive Debug and transitively inherit this redaction.

Fields§

§request_id: Uuid

Correlation ID for this plugin invocation. Used for log correlation and distributed tracing; Chat Engine generates a fresh UUIDv4 per call (or may propagate an upstream correlation ID). Plugins should include this in every log line emitted while handling the call.

§tenant_id: TenantId

Tenant that owns the session issuing the call.

§user_id: UserId

End-user behind the call (opaque string from the auth token).

§plugin_instance_id: String

GTS plugin instance ID that is handling the call (matches the bound SessionType.plugin_instance_id).

§session_type_id: Uuid

Session type the call is scoped to.

§plugin_config: Option<Value>

Opaque plugin-specific configuration loaded from plugin_configs for this (plugin_instance_id, session_type_id) pair.

§enabled_capabilities: Option<Vec<CapabilityValue>>

Capability values selected for this call (subset of those declared by the plugin via Capability).

§deadline: Option<Instant>

Absolute monotonic deadline for this plugin call. Plugins should bound long-running work (HTTP requests, retries) to remain within this budget. None means Chat Engine did not set a deadline.

Use remaining() for a convenient countdown duration.

§cancel: CancellationToken

Cooperative cancellation signal. Cancelled by Chat Engine when:

  • the client disconnects (HTTP stream closed)
  • the deadline elapses (Chat Engine bridges deadline → cancel)
  • explicit DELETE /streaming is invoked on a session

Plugins should select! on cancel.cancelled() alongside their work and return PluginError::Transient("cancelled") (or similar) when the signal fires. cancel.is_cancelled() is also available for pre-flight checks before expensive operations.

Clones of this token share the same cancellation state. When Chat Engine cancels, all clones observe the signal simultaneously — and conversely, calling .cancel() on any clone (including one obtained by cloning the enclosing PluginCallContext) cancels every other holder, including Chat Engine’s parent token. If you fan out concurrent sub-tasks that need independent cancellation, derive child tokens with CancellationToken::child_token rather than cloning.

Implementations§

Source§

impl PluginCallContext

Source

pub fn is_cancelled(&self) -> bool

True if cancellation has been signalled.

Source

pub fn remaining(&self) -> Option<Duration>

Remaining time until the deadline.

  • None — no deadline was set; the plugin may use its own default budget.
  • Some(Duration::ZERO) — deadline has already elapsed; the plugin should abort immediately (typically returning PluginError::timeout()).
  • Some(d) where d > 0d of budget remains. Plugins typically pass this to tokio::time::timeout(...) or reqwest::Client::timeout(...).

Important: collapsing “no deadline” and “elapsed” into None would be a footgun (.unwrap_or(default) would let elapsed deadlines silently extend their budget). Callers must handle the three cases distinctly.

Trait Implementations§

Source§

impl Clone for PluginCallContext

Source§

fn clone(&self) -> PluginCallContext

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 Debug for PluginCallContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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, 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.