use std::{fmt, str::FromStr};
use rho_sdk::CapabilityKind;
use thiserror::Error;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum AntigravityTool {
ViewFile,
CreateFile,
EditFile,
RunCommand,
SearchWeb,
ReadUrlContent,
}
impl AntigravityTool {
pub const ALL: &[AntigravityTool] = &[
Self::ViewFile,
Self::CreateFile,
Self::EditFile,
Self::RunCommand,
Self::SearchWeb,
Self::ReadUrlContent,
];
pub fn as_name(self) -> &'static str {
match self {
Self::ViewFile => "view_file",
Self::CreateFile => "create_file",
Self::EditFile => "edit_file",
Self::RunCommand => "run_command",
Self::SearchWeb => "search_web",
Self::ReadUrlContent => "read_url_content",
}
}
pub fn detail(self) -> &'static str {
match self {
Self::ViewFile => "Read a file.",
Self::CreateFile => "Create a file.",
Self::EditFile => "Edit a file.",
Self::RunCommand => "Run a shell command.",
Self::SearchWeb => "Search the web.",
Self::ReadUrlContent => "Fetch a URL.",
}
}
pub fn capability_kind(self) -> CapabilityKind {
match self {
Self::ViewFile => CapabilityKind::Read,
Self::CreateFile | Self::EditFile => CapabilityKind::Write,
Self::RunCommand => CapabilityKind::Process,
Self::SearchWeb | Self::ReadUrlContent => CapabilityKind::Network,
}
}
pub fn is_read_only(self) -> bool {
matches!(self.capability_kind(), CapabilityKind::Read)
}
fn accepted_names() -> String {
Self::ALL
.iter()
.map(|tool| tool.as_name())
.collect::<Vec<_>>()
.join(", ")
}
}
impl fmt::Display for AntigravityTool {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_name())
}
}
impl FromStr for AntigravityTool {
type Err = AntigravityToolError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
Self::ALL
.iter()
.copied()
.find(|tool| tool.as_name() == value)
.ok_or_else(|| AntigravityToolError {
value: value.to_string(),
expected: Self::accepted_names(),
})
}
}
#[derive(Clone, Debug, Error, PartialEq, Eq)]
#[error("unknown Antigravity tool '{value}'; expected one of: {expected}")]
pub struct AntigravityToolError {
value: String,
expected: String,
}