Skip to main content

opencode_sdk/types/
tool.rs

1//! Tool and agent types for opencode_rs.
2
3use serde::{Deserialize, Serialize};
4
5/// A tool definition.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Tool {
9    /// Tool identifier.
10    pub id: String,
11    /// Tool name.
12    pub name: String,
13    /// Tool description.
14    #[serde(default, skip_serializing_if = "Option::is_none")]
15    pub description: Option<String>,
16    /// Input schema.
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub input_schema: Option<serde_json::Value>,
19    /// Whether this tool requires approval.
20    #[serde(default)]
21    pub requires_approval: bool,
22    /// Source of the tool (builtin, mcp, etc.).
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    pub source: Option<String>,
25}
26
27/// An agent definition.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct Agent {
31    /// Agent name.
32    pub name: String,
33    /// Agent description.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub description: Option<String>,
36    /// System prompt.
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub system: Option<String>,
39    /// Allowed tools.
40    #[serde(default)]
41    pub tools: Vec<String>,
42    /// Whether this is a built-in agent.
43    #[serde(default)]
44    pub builtin: bool,
45}
46
47/// A command definition.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(rename_all = "camelCase")]
50pub struct Command {
51    /// Command name.
52    pub name: String,
53    /// Command description.
54    #[serde(default, skip_serializing_if = "Option::is_none")]
55    pub description: Option<String>,
56    /// Command shortcut key.
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    pub shortcut: Option<String>,
59}
60
61/// List of tool IDs.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(rename_all = "camelCase")]
64pub struct ToolIds {
65    /// Tool identifiers.
66    #[serde(default)]
67    pub ids: Vec<String>,
68}