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: UuidCorrelation 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: TenantIdTenant that owns the session issuing the call.
user_id: UserIdEnd-user behind the call (opaque string from the auth token).
plugin_instance_id: StringGTS plugin instance ID that is handling the call (matches the bound
SessionType.plugin_instance_id).
session_type_id: UuidSession 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: CancellationTokenCooperative cancellation signal. Cancelled by Chat Engine when:
- the client disconnects (HTTP stream closed)
- the deadline elapses (Chat Engine bridges deadline → cancel)
- explicit
DELETE /streamingis 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
impl PluginCallContext
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
True if cancellation has been signalled.
Sourcepub fn remaining(&self) -> Option<Duration>
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 returningPluginError::timeout()).Some(d)whered > 0—dof budget remains. Plugins typically pass this totokio::time::timeout(...)orreqwest::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
impl Clone for PluginCallContext
Source§fn clone(&self) -> PluginCallContext
fn clone(&self) -> PluginCallContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more