use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use ag_protocol::AgentResponse;
use async_trait::async_trait;
use tokio_util::sync::CancellationToken;
use crate::{AgentRequestKind, PermissionMode, ReasoningLevel, SessionStats, SpeedMode};
#[derive(Clone, Debug)]
pub struct OneShotRequest {
pub child_pid: Option<Arc<Mutex<Option<u32>>>>,
pub folder: PathBuf,
pub harness: String,
pub model: String,
pub permission_mode: PermissionMode,
pub prompt: String,
pub provider_call_budget: Option<crate::ProviderCallBudget>,
pub reasoning_level: ReasoningLevel,
pub request_kind: AgentRequestKind,
pub speed_mode: SpeedMode,
}
#[derive(Clone, Debug, PartialEq)]
pub struct OneShotSubmission {
pub response: AgentResponse,
pub stats: SessionStats,
}
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
#[error("{message}")]
pub struct OneShotError {
message: String,
}
impl OneShotError {
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
}
#[cfg_attr(any(test, feature = "test-utils"), mockall::automock)]
#[async_trait]
pub trait OneShotClient: Send + Sync {
fn force_shutdown(&self) {}
async fn submit(&self, request: OneShotRequest) -> Result<OneShotSubmission, OneShotError>;
async fn submit_cancellable(
&self,
request: OneShotRequest,
cancellation: CancellationToken,
) -> Result<OneShotSubmission, OneShotError> {
tokio::select! {
biased;
() = cancellation.cancelled() => Err(OneShotError::new("[Stopped] Agent run canceled")),
result = self.submit(request) => result,
}
}
async fn close(&self) {}
}
#[cfg(test)]
#[path = "one_shot_test.rs"]
mod tests;