a3s_code_core/capability/
value.rs1use std::fmt;
2use std::sync::Arc;
3
4use crate::cognitive_context::CognitiveContextSession;
5use crate::commands::SlashCommand;
6use crate::context::ContextProvider;
7use crate::hooks::HookBinding;
8use crate::mcp::McpBinding;
9use crate::skills::Skill;
10use crate::subagent::AgentDefinition;
11use crate::tools::Tool;
12
13use super::{CapabilityKind, FlowBinding, KnowledgeSurfaceBinding, UiBinding};
14
15#[derive(Clone)]
22pub enum CapabilityValue {
23 Tool(Arc<dyn Tool>),
24 Skill(Arc<Skill>),
25 Agent(Arc<AgentDefinition>),
26 Command(Arc<dyn SlashCommand>),
27 Hook(Arc<HookBinding>),
28 Mcp(Arc<McpBinding>),
29 Flow(Arc<FlowBinding>),
30 KnowledgeSurface(Arc<KnowledgeSurfaceBinding>),
31 Knowledge(Arc<CognitiveContextSession>),
32 Ui(Arc<UiBinding>),
33 Context(Arc<dyn ContextProvider>),
34}
35
36impl CapabilityValue {
37 pub const fn kind(&self) -> CapabilityKind {
38 match self {
39 Self::Tool(_) => CapabilityKind::Tool,
40 Self::Skill(_) => CapabilityKind::Skill,
41 Self::Agent(_) => CapabilityKind::Agent,
42 Self::Command(_) => CapabilityKind::Command,
43 Self::Hook(_) => CapabilityKind::Hook,
44 Self::Mcp(_) => CapabilityKind::Mcp,
45 Self::Flow(_) => CapabilityKind::Flow,
46 Self::KnowledgeSurface(_) => CapabilityKind::KnowledgeSurface,
47 Self::Knowledge(_) => CapabilityKind::Knowledge,
48 Self::Ui(_) => CapabilityKind::Ui,
49 Self::Context(_) => CapabilityKind::Context,
50 }
51 }
52
53 pub(crate) fn public_name(&self) -> Option<&str> {
54 match self {
55 Self::Tool(value) => Some(value.name()),
56 Self::Skill(value) => Some(&value.name),
57 Self::Agent(value) => Some(&value.name),
58 Self::Command(value) => Some(value.name()),
59 Self::Hook(value) => Some(&value.hook().id),
60 Self::Flow(value) => Some(value.public_name()),
61 Self::Mcp(value) => Some(value.server_name()),
62 Self::KnowledgeSurface(value) => Some(value.public_name()),
63 Self::Knowledge(value) => Some(value.provider_name()),
64 Self::Ui(value) => Some(value.public_name()),
65 Self::Context(value) => Some(value.name()),
66 }
67 }
68}
69
70impl fmt::Debug for CapabilityValue {
71 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
72 let mut debug = formatter.debug_struct("CapabilityValue");
73 debug.field("kind", &self.kind());
74 if let Some(public_name) = self.public_name() {
75 debug.field("public_name", &public_name);
76 }
77 debug.finish_non_exhaustive()
78 }
79}