use std::collections::HashMap;
use super::client::ApiClient;
use super::error::ApiResult;
use super::types::*;
#[derive(Clone)]
pub struct ExecutionsApi {
client: ApiClient,
}
impl ExecutionsApi {
pub fn new(client: ApiClient) -> Self {
Self { client }
}
pub async fn execute(&self, request: &ExecutionRequest) -> ApiResult<ExecutionResponse> {
self.client.post("/execute", request).await
}
pub async fn execute_simple(
&self,
skill: &str,
tool: &str,
args: HashMap<String, serde_json::Value>,
) -> ApiResult<ExecutionResponse> {
self.execute(&ExecutionRequest {
skill: skill.to_string(),
tool: tool.to_string(),
instance: None,
args,
stream: false,
timeout_secs: None,
})
.await
}
pub async fn execute_on_instance(
&self,
skill: &str,
tool: &str,
instance: &str,
args: HashMap<String, serde_json::Value>,
) -> ApiResult<ExecutionResponse> {
self.execute(&ExecutionRequest {
skill: skill.to_string(),
tool: tool.to_string(),
instance: Some(instance.to_string()),
args,
stream: false,
timeout_secs: None,
})
.await
}
pub async fn execute_with_timeout(
&self,
skill: &str,
tool: &str,
args: HashMap<String, serde_json::Value>,
timeout_secs: u64,
) -> ApiResult<ExecutionResponse> {
self.execute(&ExecutionRequest {
skill: skill.to_string(),
tool: tool.to_string(),
instance: None,
args,
stream: false,
timeout_secs: Some(timeout_secs),
})
.await
}
pub async fn list_history(
&self,
pagination: Option<PaginationParams>,
) -> ApiResult<PaginatedResponse<ExecutionHistoryEntry>> {
let params = pagination.unwrap_or_default();
self.client.get_with_query("/executions", ¶ms).await
}
pub async fn list_all_history(&self) -> ApiResult<Vec<ExecutionHistoryEntry>> {
let response: PaginatedResponse<ExecutionHistoryEntry> = self
.client
.get_with_query(
"/executions",
&PaginationParams {
page: 1,
per_page: 1000,
},
)
.await?;
Ok(response.items)
}
pub async fn get(&self, id: &str) -> ApiResult<ExecutionHistoryEntry> {
self.client.get(&format!("/executions/{}", id)).await
}
pub async fn recent_for_skill(
&self,
skill: &str,
limit: usize,
) -> ApiResult<Vec<ExecutionHistoryEntry>> {
let all = self.list_all_history().await?;
Ok(all
.into_iter()
.filter(|e| e.skill == skill)
.take(limit)
.collect())
}
pub async fn clear_history(&self) -> ApiResult<()> {
self.client.delete("/executions").await?;
Ok(())
}
}