use std::{collections::BTreeSet, sync::Arc};
use crate::DependencyStore;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct ToolCapabilityGrant {
pub host_capabilities: BTreeSet<String>,
pub context_capabilities: BTreeSet<String>,
pub shell_environment: bool,
}
impl ToolCapabilityGrant {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_host_capabilities(
mut self,
capabilities: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
self.host_capabilities = capabilities.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn with_context_capabilities(
mut self,
capabilities: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
self.context_capabilities = capabilities.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub const fn with_shell_environment(mut self, allowed: bool) -> Self {
self.shell_environment = allowed;
self
}
}
#[derive(Clone, Default)]
pub struct HostCapabilities {
dependencies: DependencyStore,
}
impl HostCapabilities {
pub(crate) const fn new(dependencies: DependencyStore) -> Self {
Self { dependencies }
}
#[must_use]
pub fn get<T>(&self) -> Option<Arc<T>>
where
T: Send + Sync + 'static,
{
self.dependencies.get::<T>()
}
#[must_use]
pub fn get_named<T>(&self, name: &str) -> Option<Arc<T>>
where
T: Send + Sync + 'static,
{
self.dependencies.get_named::<T>(name)
}
#[must_use]
pub fn keys(&self) -> Vec<String> {
self.dependencies.keys()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.dependencies.is_empty()
}
}
impl std::fmt::Debug for HostCapabilities {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("HostCapabilities")
.field("keys", &self.keys())
.finish()
}
}