skill_web/api/
mod.rs

1//! API client module for communicating with the skill-http backend
2//!
3//! This module provides a type-safe HTTP client for all API operations.
4//!
5//! ## Usage
6//!
7//! ```ignore
8//! use crate::api::Api;
9//!
10//! // Create API client (uses /api prefix for Trunk proxy)
11//! let api = Api::new();
12//!
13//! // List skills
14//! let skills = api.skills.list_all().await?;
15//!
16//! // Execute a tool
17//! let result = api.executions.execute_simple("kubernetes", "get_pods", args).await?;
18//!
19//! // Search
20//! let results = api.search.query("deploy pods").await?;
21//!
22//! // Check health
23//! let healthy = api.config.is_healthy().await;
24//! ```
25
26pub mod agent;
27pub mod analytics;
28pub mod client;
29pub mod config;
30pub mod error;
31pub mod executions;
32pub mod feedback;
33pub mod search;
34pub mod services;
35pub mod skills;
36pub mod types;
37
38pub use agent::AgentApi;
39pub use analytics::AnalyticsApi;
40pub use client::ApiClient;
41pub use config::ConfigApi;
42pub use error::{ApiError, ApiResult};
43pub use executions::ExecutionsApi;
44pub use feedback::{
45    FeedbackApi, FeedbackEntry, GetFeedbackRequest, GetFeedbackResponse, SubmitFeedbackRequest,
46    SubmitFeedbackResponse,
47};
48pub use search::SearchApi;
49pub use services::ServicesApi;
50pub use skills::SkillsApi;
51pub use types::*;
52
53/// Unified API facade providing access to all API endpoints
54#[derive(Clone)]
55pub struct Api {
56    /// Skills API operations
57    pub skills: SkillsApi,
58    /// Execution API operations
59    pub executions: ExecutionsApi,
60    /// Search API operations
61    pub search: SearchApi,
62    /// Configuration API operations
63    pub config: ConfigApi,
64    /// System services API operations
65    pub services: ServicesApi,
66    /// Agent configuration API operations
67    pub agent: AgentApi,
68    /// Feedback API operations
69    pub feedback: FeedbackApi,
70    /// Analytics API operations
71    pub analytics: AnalyticsApi,
72}
73
74impl Default for Api {
75    fn default() -> Self {
76        Self::new()
77    }
78}
79
80impl Api {
81    /// Create a new API facade with the default local client
82    pub fn new() -> Self {
83        let client = ApiClient::local();
84        Self::with_client(client)
85    }
86
87    /// Create an API facade with a custom base URL
88    pub fn with_base_url(base_url: impl Into<String>) -> Self {
89        let client = ApiClient::new(base_url);
90        Self::with_client(client)
91    }
92
93    /// Create an API facade with a specific host and port
94    pub fn with_host(host: &str, port: u16) -> Self {
95        let client = ApiClient::with_host(host, port);
96        Self::with_client(client)
97    }
98
99    /// Create an API facade with an existing client
100    pub fn with_client(client: ApiClient) -> Self {
101        Self {
102            skills: SkillsApi::new(client.clone()),
103            executions: ExecutionsApi::new(client.clone()),
104            search: SearchApi::new(client.clone()),
105            config: ConfigApi::new(client.clone()),
106            services: ServicesApi::new(client.clone()),
107            agent: AgentApi::new(client.clone()),
108            feedback: FeedbackApi::new(client.clone()),
109            analytics: AnalyticsApi::new(client),
110        }
111    }
112
113    /// Check if the API server is reachable and healthy
114    pub async fn is_available(&self) -> bool {
115        self.config.is_healthy().await
116    }
117
118    /// Get version information from the server
119    pub async fn server_version(&self) -> ApiResult<String> {
120        let version = self.config.version().await?;
121        Ok(version.version)
122    }
123}
124
125/// Create a default API client (convenience function)
126pub fn api() -> Api {
127    Api::new()
128}