skill_web/api/
executions.rs1use std::collections::HashMap;
4
5use super::client::ApiClient;
6use super::error::ApiResult;
7use super::types::*;
8
9#[derive(Clone)]
11pub struct ExecutionsApi {
12 client: ApiClient,
13}
14
15impl ExecutionsApi {
16 pub fn new(client: ApiClient) -> Self {
18 Self { client }
19 }
20
21 pub async fn execute(&self, request: &ExecutionRequest) -> ApiResult<ExecutionResponse> {
23 self.client.post("/execute", request).await
24 }
25
26 pub async fn execute_simple(
28 &self,
29 skill: &str,
30 tool: &str,
31 args: HashMap<String, serde_json::Value>,
32 ) -> ApiResult<ExecutionResponse> {
33 self.execute(&ExecutionRequest {
34 skill: skill.to_string(),
35 tool: tool.to_string(),
36 instance: None,
37 args,
38 stream: false,
39 timeout_secs: None,
40 })
41 .await
42 }
43
44 pub async fn execute_on_instance(
46 &self,
47 skill: &str,
48 tool: &str,
49 instance: &str,
50 args: HashMap<String, serde_json::Value>,
51 ) -> ApiResult<ExecutionResponse> {
52 self.execute(&ExecutionRequest {
53 skill: skill.to_string(),
54 tool: tool.to_string(),
55 instance: Some(instance.to_string()),
56 args,
57 stream: false,
58 timeout_secs: None,
59 })
60 .await
61 }
62
63 pub async fn execute_with_timeout(
65 &self,
66 skill: &str,
67 tool: &str,
68 args: HashMap<String, serde_json::Value>,
69 timeout_secs: u64,
70 ) -> ApiResult<ExecutionResponse> {
71 self.execute(&ExecutionRequest {
72 skill: skill.to_string(),
73 tool: tool.to_string(),
74 instance: None,
75 args,
76 stream: false,
77 timeout_secs: Some(timeout_secs),
78 })
79 .await
80 }
81
82 pub async fn list_history(
84 &self,
85 pagination: Option<PaginationParams>,
86 ) -> ApiResult<PaginatedResponse<ExecutionHistoryEntry>> {
87 let params = pagination.unwrap_or_default();
88 self.client.get_with_query("/executions", ¶ms).await
89 }
90
91 pub async fn list_all_history(&self) -> ApiResult<Vec<ExecutionHistoryEntry>> {
93 let response: PaginatedResponse<ExecutionHistoryEntry> = self
94 .client
95 .get_with_query(
96 "/executions",
97 &PaginationParams {
98 page: 1,
99 per_page: 1000,
100 },
101 )
102 .await?;
103 Ok(response.items)
104 }
105
106 pub async fn get(&self, id: &str) -> ApiResult<ExecutionHistoryEntry> {
108 self.client.get(&format!("/executions/{}", id)).await
109 }
110
111 pub async fn recent_for_skill(
113 &self,
114 skill: &str,
115 limit: usize,
116 ) -> ApiResult<Vec<ExecutionHistoryEntry>> {
117 let all = self.list_all_history().await?;
120 Ok(all
121 .into_iter()
122 .filter(|e| e.skill == skill)
123 .take(limit)
124 .collect())
125 }
126
127 pub async fn clear_history(&self) -> ApiResult<()> {
129 self.client.delete("/executions").await?;
130 Ok(())
131 }
132}