starweaver_context/
host_capabilities.rs1use std::{collections::BTreeSet, sync::Arc};
4
5use crate::DependencyStore;
6
7#[derive(Clone, Debug, Default, Eq, PartialEq)]
9pub struct ToolCapabilityGrant {
10 pub host_capabilities: BTreeSet<String>,
12 pub context_capabilities: BTreeSet<String>,
14 pub shell_environment: bool,
16}
17
18impl ToolCapabilityGrant {
19 #[must_use]
21 pub fn new() -> Self {
22 Self::default()
23 }
24
25 #[must_use]
27 pub fn with_host_capabilities(
28 mut self,
29 capabilities: impl IntoIterator<Item = impl Into<String>>,
30 ) -> Self {
31 self.host_capabilities = capabilities.into_iter().map(Into::into).collect();
32 self
33 }
34
35 #[must_use]
37 pub fn with_context_capabilities(
38 mut self,
39 capabilities: impl IntoIterator<Item = impl Into<String>>,
40 ) -> Self {
41 self.context_capabilities = capabilities.into_iter().map(Into::into).collect();
42 self
43 }
44
45 #[must_use]
47 pub const fn with_shell_environment(mut self, allowed: bool) -> Self {
48 self.shell_environment = allowed;
49 self
50 }
51}
52
53#[derive(Clone, Default)]
58pub struct HostCapabilities {
59 dependencies: DependencyStore,
60}
61
62impl HostCapabilities {
63 pub(crate) const fn new(dependencies: DependencyStore) -> Self {
64 Self { dependencies }
65 }
66
67 #[must_use]
69 pub fn get<T>(&self) -> Option<Arc<T>>
70 where
71 T: Send + Sync + 'static,
72 {
73 self.dependencies.get::<T>()
74 }
75
76 #[must_use]
78 pub fn get_named<T>(&self, name: &str) -> Option<Arc<T>>
79 where
80 T: Send + Sync + 'static,
81 {
82 self.dependencies.get_named::<T>(name)
83 }
84
85 #[must_use]
87 pub fn keys(&self) -> Vec<String> {
88 self.dependencies.keys()
89 }
90
91 #[must_use]
93 pub fn is_empty(&self) -> bool {
94 self.dependencies.is_empty()
95 }
96}
97
98impl std::fmt::Debug for HostCapabilities {
99 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100 formatter
101 .debug_struct("HostCapabilities")
102 .field("keys", &self.keys())
103 .finish()
104 }
105}