//! Request-scoped approval decisions. A review only satisfies the review gate; the host enforces permissions. use std::sync::Arc; use akode_protocol::ThreadId; use crate::ExtensionData; /// Thread-local state installed only after Guardian V2's async classifier initializes. pub struct GuardianV2Enabled; /// Guardian's choice for one approval. Synchronous results pass through unchanged. #[derive(Clone, Debug, PartialEq)] pub enum ApprovalDecision { /// Existing async evidence allows this action without synchronous review. Allow, Reviewed(akode_protocol::protocol::ReviewDecision), AskUser, } /// Runs an extension-owned review already bound to an action by the host. /// `None` requests the host user flow when automatic review exhausts its input budget /// and host policy permits it. An optional async approval resolves only when current /// cached evidence authorizes the action; it races the complete synchronous review. pub trait SynchronousApprovalReviewer: Send + Sync { fn review<'a>( &'a self, reason: akode_protocol::approvals::GuardianReviewReason, async_approval: Option>, ) -> crate::ExtensionFuture<'a, Option>; } /// Inputs to Guardian's policy choice. Conversation and scores stay thread-owned. pub struct ApprovalDecisionInput<'a> { /// Final serving value for this action. The host still requires fresh review when stale. pub serving_assessment: Option, pub approval_id: &'a str, /// Host tool invocation being approved, absent for approvals without a tool call. pub tool_call_id: Option<&'a str>, /// Host-resolved permission evidence; unavailable evidence cannot authorize cached approval. pub permissions: Option<&'a akode_guardian_context::PermissionContext>, pub action: &'a serde_json::Value, pub thread_id: ThreadId, pub thread_store: &'a ExtensionData, /// Captured configuration and evidence owned by the requesting turn. pub turn_store: &'a ExtensionData, pub category: akode_protocol::openai_models::GuardianScope, pub approval_policy: akode_protocol::protocol::AskForApproval, pub approvals_reviewer: akode_protocol::config_types::ApprovalsReviewer, pub require_guardian: bool, /// Existing retry and sensitive-action rules require a synchronous review. pub require_fresh_review: bool, pub full_access: bool, pub metrics: Option>, pub synchronous_reviewer: &'a dyn SynchronousApprovalReviewer, }