use async_trait::async_trait;
use systemprompt_identifiers::{AgentRunId, ContextId, TaskId, UserId};
#[derive(Debug, Clone)]
pub struct AgentRunLaunch {
pub user_id: UserId,
pub task_id: TaskId,
pub context_id: ContextId,
pub request: serde_json::Value,
pub origin_kind: String,
pub origin_id: String,
}
#[derive(Debug, thiserror::Error)]
pub enum AgentRunLaunchError {
#[error("invalid run request")]
InvalidRequest(#[source] serde_json::Error),
#[error("agent run {0} not found")]
NotFound(AgentRunId),
#[error("agent run launcher unavailable")]
Unavailable(#[source] Box<dyn std::error::Error + Send + Sync>),
}
impl AgentRunLaunchError {
pub fn unavailable(source: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Unavailable(Box::new(source))
}
}
#[async_trait]
pub trait AgentRunLauncher: Send + Sync {
async fn enqueue(&self, request: AgentRunLaunch) -> Result<AgentRunId, AgentRunLaunchError>;
async fn cancel(&self, run_id: &AgentRunId) -> Result<(), AgentRunLaunchError>;
async fn run_for_task(
&self,
task_id: &TaskId,
) -> Result<Option<AgentRunId>, AgentRunLaunchError>;
}
pub type DynAgentRunLauncher = std::sync::Arc<dyn AgentRunLauncher>;