skill_web/api/
executions.rs

1//! Executions API client
2
3use std::collections::HashMap;
4
5use super::client::ApiClient;
6use super::error::ApiResult;
7use super::types::*;
8
9/// Executions API operations
10#[derive(Clone)]
11pub struct ExecutionsApi {
12    client: ApiClient,
13}
14
15impl ExecutionsApi {
16    /// Create a new executions API client
17    pub fn new(client: ApiClient) -> Self {
18        Self { client }
19    }
20
21    /// Execute a skill tool
22    pub async fn execute(&self, request: &ExecutionRequest) -> ApiResult<ExecutionResponse> {
23        self.client.post("/execute", request).await
24    }
25
26    /// Execute a skill tool with simple parameters
27    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    /// Execute a skill tool on a specific instance
45    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    /// Execute with custom timeout
64    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    /// List execution history with pagination
83    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", &params).await
89    }
90
91    /// List all execution history (no pagination)
92    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    /// Get a specific execution by ID
107    pub async fn get(&self, id: &str) -> ApiResult<ExecutionHistoryEntry> {
108        self.client.get(&format!("/executions/{}", id)).await
109    }
110
111    /// Get recent executions for a skill
112    pub async fn recent_for_skill(
113        &self,
114        skill: &str,
115        limit: usize,
116    ) -> ApiResult<Vec<ExecutionHistoryEntry>> {
117        // For now, fetch all and filter client-side
118        // TODO: Add server-side filtering
119        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    /// Clear all execution history
128    pub async fn clear_history(&self) -> ApiResult<()> {
129        self.client.delete("/executions").await?;
130        Ok(())
131    }
132}