pub struct HookContext {
pub hook_point: HookPoint,
pub component_id: ComponentId,
pub channel_id: ChannelId,
pub principal: Principal,
pub timestamp_ms: u64,
pub payload: Value,
pub metadata: HashMap<String, Value>,
pub depth: u8,
pub max_depth: u8,
}Expand description
Context passed to hook handlers.
Pre-hooks can modify payload to alter the downstream operation.
Post-hooks receive the final result in payload.
metadata carries cross-hook state from pre → post for the same operation.
Fields§
§hook_point: HookPointWhich hook point triggered this.
component_id: ComponentIdThe component targeted by this hook (from FQL match).
channel_id: ChannelIdThe channel where this is happening.
principal: PrincipalWho initiated the action.
timestamp_ms: u64Monotonic timestamp (ms since engine start).
payload: ValueHook-specific payload (varies by HookPoint).
Pre hooks: the input data (request, config, args, etc.) Post hooks: the result data (response, child_result, etc.)
metadata: HashMap<String, Value>Mutable metadata bag — hooks can store cross-hook state here. Carried from pre → post for the same operation.
depth: u8Recursion depth counter. Incremented each time hooks re-enter (e.g., hook calls orcs.exec() which triggers ToolPreExecute hooks).
max_depth: u8Maximum recursion depth (default: 4).
Implementations§
Source§impl HookContext
impl HookContext
Sourcepub fn new(
hook_point: HookPoint,
component_id: ComponentId,
channel_id: ChannelId,
principal: Principal,
timestamp_ms: u64,
payload: Value,
) -> Self
pub fn new( hook_point: HookPoint, component_id: ComponentId, channel_id: ChannelId, principal: Principal, timestamp_ms: u64, payload: Value, ) -> Self
Creates a new HookContext with all fields specified.
Sourcepub fn with_incremented_depth(&self) -> Self
pub fn with_incremented_depth(&self) -> Self
Returns a new context with depth incremented by 1.
Sourcepub fn is_depth_exceeded(&self) -> bool
pub fn is_depth_exceeded(&self) -> bool
Returns true if the current depth has reached or exceeded max_depth.
Sourcepub fn with_max_depth(self, max_depth: u8) -> Self
pub fn with_max_depth(self, max_depth: u8) -> Self
Sets the maximum recursion depth.
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Adds a metadata entry.
Trait Implementations§
Source§impl Clone for HookContext
impl Clone for HookContext
Source§fn clone(&self) -> HookContext
fn clone(&self) -> HookContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more