Skip to main content

opencode_sdk/http/
tools.rs

1//! Tools, Agents, and Commands API for OpenCode.
2//!
3//! Endpoints for tool, agent, and command management.
4
5use crate::error::Result;
6use crate::http::HttpClient;
7use crate::types::tool::{Agent, Command, Tool, ToolIds};
8use reqwest::Method;
9
10/// Tools API client.
11#[derive(Clone)]
12pub struct ToolsApi {
13    http: HttpClient,
14}
15
16impl ToolsApi {
17    /// Create a new Tools API client.
18    pub fn new(http: HttpClient) -> Self {
19        Self { http }
20    }
21
22    /// Get tool IDs (experimental).
23    ///
24    /// # Errors
25    ///
26    /// Returns an error if the request fails.
27    pub async fn ids(&self) -> Result<ToolIds> {
28        self.http
29            .request_json(Method::GET, "/experimental/tool/ids", None)
30            .await
31    }
32
33    /// List tools (experimental).
34    ///
35    /// # Errors
36    ///
37    /// Returns an error if the request fails.
38    pub async fn list(&self) -> Result<Vec<Tool>> {
39        self.http
40            .request_json(Method::GET, "/experimental/tool", None)
41            .await
42    }
43
44    /// List agents.
45    ///
46    /// # Errors
47    ///
48    /// Returns an error if the request fails.
49    pub async fn agents(&self) -> Result<Vec<Agent>> {
50        self.http.request_json(Method::GET, "/agent", None).await
51    }
52
53    /// List commands.
54    ///
55    /// # Errors
56    ///
57    /// Returns an error if the request fails.
58    pub async fn commands(&self) -> Result<Vec<Command>> {
59        self.http.request_json(Method::GET, "/command", None).await
60    }
61}