feat: add pre-dispatch hook for agent task middleware
Generic extension point in community codebase: PreDispatchHook type registered in AppState, checked before every agent_query dispatch. Enables Pro features like budget enforcement and branch policy.
This commit is contained in:
parent
19771237c9
commit
3798bedc4d
2 changed files with 10 additions and 0 deletions
|
|
@ -9,6 +9,10 @@ pub fn agent_query(
|
|||
state: State<'_, AppState>,
|
||||
options: AgentQueryOptions,
|
||||
) -> Result<(), String> {
|
||||
// Run pre-dispatch hooks (budget enforcement, branch policy, etc.)
|
||||
for hook in &state.pre_dispatch_hooks {
|
||||
hook(&options)?;
|
||||
}
|
||||
state.sidecar_manager.query(&options)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::Arc;
|
||||
use tauri::Manager;
|
||||
|
||||
/// Pre-dispatch hook for agent task middleware (budget enforcement, branch policy, etc.)
|
||||
/// Returns Ok(()) to allow dispatch, Err(reason) to block it.
|
||||
pub type PreDispatchHook = Box<dyn Fn(&agor_core::sidecar::AgentQueryOptions) -> Result<(), String> + Send + Sync>;
|
||||
|
||||
pub(crate) struct AppState {
|
||||
pub pty_manager: Arc<PtyManager>,
|
||||
pub sidecar_manager: Arc<SidecarManager>,
|
||||
|
|
@ -40,6 +44,7 @@ pub(crate) struct AppState {
|
|||
pub remote_manager: Arc<RemoteManager>,
|
||||
pub search_db: Arc<search::SearchDb>,
|
||||
pub app_config: Arc<AppConfig>,
|
||||
pub pre_dispatch_hooks: Vec<PreDispatchHook>,
|
||||
_telemetry: telemetry::TelemetryGuard,
|
||||
}
|
||||
|
||||
|
|
@ -413,6 +418,7 @@ pub fn run() {
|
|||
remote_manager,
|
||||
search_db,
|
||||
app_config: config,
|
||||
pre_dispatch_hooks: Vec::new(),
|
||||
_telemetry: telemetry_guard,
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue