mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
avoid passing them both around, unify on a type. this now also keys `ToolRegistry`. tests pass
43 lines
979 B
Rust
43 lines
979 B
Rust
/// Identifies a callable tool, preserving the namespace split when the model
|
|
/// provides one.
|
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
|
pub struct ToolName {
|
|
pub name: String,
|
|
pub namespace: Option<String>,
|
|
}
|
|
|
|
impl ToolName {
|
|
pub fn plain(name: impl Into<String>) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
namespace: None,
|
|
}
|
|
}
|
|
|
|
pub fn namespaced(namespace: impl Into<String>, name: impl Into<String>) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
namespace: Some(namespace.into()),
|
|
}
|
|
}
|
|
|
|
pub fn display(&self) -> String {
|
|
match &self.namespace {
|
|
Some(namespace) => format!("{namespace}{}", self.name),
|
|
None => self.name.clone(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<String> for ToolName {
|
|
fn from(name: String) -> Self {
|
|
Self::plain(name)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for ToolName {
|
|
fn from(name: &str) -> Self {
|
|
Self::plain(name)
|
|
}
|
|
}
|