pub struct HookRegistry { /* private fields */ }Expand description
A registry of hooks keyed by event type.
Wraps a HashMap<HookEvent, Vec<HookCallbackMatcher>> and provides
methods to run hooks for specific events.
§Example
use starpod_hooks::{HookRegistry, HookEvent, HookCallbackMatcher, hook_fn, HookOutput};
let mut registry = HookRegistry::new();
registry.register(HookEvent::PostToolUse, vec![
HookCallbackMatcher::new(vec![
hook_fn(|_input, _id, _cancel| async move {
Ok(HookOutput::default())
}),
]).with_matcher("Bash"),
]);
assert!(registry.has_hooks(&HookEvent::PostToolUse));
assert!(!registry.has_hooks(&HookEvent::PreToolUse));Implementations§
Source§impl HookRegistry
impl HookRegistry
pub fn new() -> HookRegistry
Sourcepub fn from_map(
hooks: HashMap<HookEvent, Vec<HookCallbackMatcher>>,
) -> HookRegistry
pub fn from_map( hooks: HashMap<HookEvent, Vec<HookCallbackMatcher>>, ) -> HookRegistry
Create a registry from an existing HashMap.
Sourcepub fn with_circuit_breaker(self, config: CircuitBreakerConfig) -> HookRegistry
pub fn with_circuit_breaker(self, config: CircuitBreakerConfig) -> HookRegistry
Set a custom circuit breaker configuration.
Sourcepub fn register(&mut self, event: HookEvent, matchers: Vec<HookCallbackMatcher>)
pub fn register(&mut self, event: HookEvent, matchers: Vec<HookCallbackMatcher>)
Register matchers for a hook event.
Sourcepub fn has_hooks(&self, event: &HookEvent) -> bool
pub fn has_hooks(&self, event: &HookEvent) -> bool
Check if any hooks are registered for the given event.
Sourcepub fn get(&self, event: &HookEvent) -> Option<&Vec<HookCallbackMatcher>>
pub fn get(&self, event: &HookEvent) -> Option<&Vec<HookCallbackMatcher>>
Get the matchers for a given event.
Sourcepub fn into_map(self) -> HashMap<HookEvent, Vec<HookCallbackMatcher>>
pub fn into_map(self) -> HashMap<HookEvent, Vec<HookCallbackMatcher>>
Consume the registry and return the inner HashMap.
Sourcepub fn merge(&mut self, other: HookRegistry)
pub fn merge(&mut self, other: HookRegistry)
Merge another registry’s hooks into this one.
Sourcepub async fn run_post_tool_use(
&self,
tool_name: &str,
tool_input: &Value,
tool_response: &Value,
tool_use_id: &str,
session_id: &str,
cwd: &str,
)
pub async fn run_post_tool_use( &self, tool_name: &str, tool_input: &Value, tool_response: &Value, tool_use_id: &str, session_id: &str, cwd: &str, )
Run all matching hooks for PostToolUse.
Hooks are fire-and-forget: errors are logged but do not propagate.
Sourcepub async fn run_pre_tool_use(
&self,
tool_name: &str,
tool_input: &Value,
tool_use_id: &str,
session_id: &str,
cwd: &str,
) -> Option<HookOutput>
pub async fn run_pre_tool_use( &self, tool_name: &str, tool_input: &Value, tool_use_id: &str, session_id: &str, cwd: &str, ) -> Option<HookOutput>
Run all matching hooks for PreToolUse.
Returns the merged HookOutput from all matching hooks,
or None if no hooks matched.
Trait Implementations§
Source§impl Debug for HookRegistry
impl Debug for HookRegistry
Source§impl Default for HookRegistry
impl Default for HookRegistry
Source§fn default() -> HookRegistry
fn default() -> HookRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for HookRegistry
impl !RefUnwindSafe for HookRegistry
impl Send for HookRegistry
impl Sync for HookRegistry
impl Unpin for HookRegistry
impl UnsafeUnpin for HookRegistry
impl !UnwindSafe for HookRegistry
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.