pub struct Shadow<P> { /* private fields */ }Expand description
Approval policy created by shadow.
Implementations§
Source§impl<P> Shadow<P>
impl<P> Shadow<P>
Sourcepub fn enforcement(self, enforcement: Enforcement) -> Self
pub fn enforcement(self, enforcement: Enforcement) -> Self
Sets whether decisions are enforced (default: observe only).
Sourcepub fn on_decision<F, Fut>(self, observer: F) -> Self
pub fn on_decision<F, Fut>(self, observer: F) -> Self
Registers an asynchronous decision observer, replacing any prior observer.
The observer runs independently on the current Tokio runtime; its output
and task panics are ignored so auditing cannot change approval. Without a
Tokio runtime the event is skipped. Dropping the policy cancels unfinished
observers; call Self::flush_decisions to drain queued events first.
§Examples
use ferrin_core::generate_text::ApprovalStatus;
use ferrin_policy::shadow;
let policy = shadow(ApprovalStatus::denied()).on_decision(|event| async move {
assert!(!event.enforced);
assert_eq!(event.effective, ApprovalStatus::approved());
});Sourcepub fn on_decision_sync(
self,
observer: impl Fn(&ParsedToolCall, Option<&ApprovalStatus>) + Send + Sync + 'static,
) -> Self
pub fn on_decision_sync( self, observer: impl Fn(&ParsedToolCall, Option<&ApprovalStatus>) + Send + Sync + 'static, ) -> Self
Registers a synchronous low-level observer, replacing any prior observer.
This Ferrin extension receives the raw optional status and blocks approval
until it returns. Unwinding observer panics are ignored. Prefer
Self::on_decision for normalized events and independent execution.
Sourcepub async fn flush_decisions(&self)
pub async fn flush_decisions(&self)
Waits for audit callbacks queued before this call took their task set.
Concurrent approval resolution can queue new events without waiting for this flush. Cancelling the flush cancels the callbacks it took ownership of.
Trait Implementations§
Source§impl<P: ApprovalPolicy> ApprovalPolicy for Shadow<P>
impl<P: ApprovalPolicy> ApprovalPolicy for Shadow<P>
Source§fn resolve<'a>(
&'a self,
call: &'a ParsedToolCall,
ctx: ApprovalContext<'a>,
) -> BoxFuture<'a, Option<ApprovalStatus>>
fn resolve<'a>( &'a self, call: &'a ParsedToolCall, ctx: ApprovalContext<'a>, ) -> BoxFuture<'a, Option<ApprovalStatus>>
call.