Hook Registry • Rust AI Agent SDK

HookRegistry: Hook registry for managing hooks

HookRegistry

Defined in the hooks module.

Rust AI Agent SDK

Hook registry for managing hooks

Diagram

Allow

Deny

Event Trigger

Hook: HookRegistry

Decision

Process

Block

Fields

NameTypeDescription
hooksHashMap<HookEvent–

Methods

new

rust
fn new() -> Self

Create a new hook registry

add_hook

rust
fn add_hook(
        &mut self,
        event: HookEvent,
        func: impl Fn(&HookInput) -> HookResult + Send + Sync + 'static,
    ) -> &mut Self

Add a hook

Parameters:

NameType
eventHookEvent
funcimpl Fn(&HookInput

add_hook_with_matcher

rust
fn add_hook_with_matcher(
        &mut self,
        event: HookEvent,
        matcher: impl Into<String>,
        func: impl Fn(&HookInput) -> HookResult + Send + Sync + 'static,
    ) -> &mut Self

Add a hook with matcher

Parameters:

NameType
eventHookEvent
matcherimpl Into&lt;String&gt;
funcimpl Fn(&HookInput

add_definition

rust
fn add_definition(&mut self, hook: HookDefinition) -> &mut Self

Add a hook definition

Parameters:

NameType
hookHookDefinition

remove_hook

rust
fn remove_hook(&mut self, id: &str) -> bool

Remove a hook by ID

Parameters:

NameType
id&str

has_hooks

rust
fn has_hooks(&self, event: HookEvent) -> bool

Check if any hooks exist for an event

Parameters:

NameType
eventHookEvent

hook_count

rust
fn hook_count(&self, event: HookEvent) -> usize

Get hook count for an event

Parameters:

NameType
eventHookEvent

execute

rust
fn execute(&self, event: HookEvent, input: &HookInput) -> HookResult

Execute all hooks for an event

Parameters:

NameType
eventHookEvent
input&HookInput

execute_async

rust
async fn execute_async(&self, event: HookEvent, input: &HookInput) -> HookResult

Execute hooks asynchronously (for future async hooks)

Parameters:

NameType
eventHookEvent
input&HookInput

Source

View on GitHub

praisonai/src/hooks/mod.rs at line 359


Related Documentation