Skip to main content

adaptive_card_core/knowledge/
format.rs

1//! Knowledge base entry format definitions.
2
3use crate::types::Host;
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum Complexity {
10    Basic,
11    Intermediate,
12    Advanced,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct KnowledgeEntry {
17    pub id: String,
18    pub title: String,
19    pub description: String,
20    pub category: String,
21    pub tags: Vec<String>,
22    #[serde(default)]
23    pub use_cases: Vec<String>,
24    pub host_targets: Vec<Host>,
25    pub complexity: Complexity,
26    pub card: Value,
27    #[serde(default)]
28    pub notes: String,
29}
30
31impl KnowledgeEntry {
32    /// Human-readable complexity label for prompt injection.
33    #[must_use]
34    pub fn complexity_str(&self) -> &'static str {
35        match self.complexity {
36            Complexity::Basic => "basic",
37            Complexity::Intermediate => "intermediate",
38            Complexity::Advanced => "advanced",
39        }
40    }
41}
42
43/// Manifest file format at `data/knowledge-base/_manifest.json`.
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct KnowledgeManifest {
46    pub version: String,
47    pub entries: Vec<ManifestEntry>,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct ManifestEntry {
52    pub id: String,
53    pub path: String,
54}
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59    use serde_json::json;
60
61    #[test]
62    fn entry_roundtrip() {
63        let entry = KnowledgeEntry {
64            id: "finance/expense".to_string(),
65            title: "Expense".to_string(),
66            description: "x".to_string(),
67            category: "finance".to_string(),
68            tags: vec!["expense".to_string()],
69            use_cases: vec![],
70            host_targets: vec![Host::Teams],
71            complexity: Complexity::Advanced,
72            card: json!({ "type": "AdaptiveCard" }),
73            notes: String::new(),
74        };
75        let json = serde_json::to_value(&entry).unwrap();
76        let back: KnowledgeEntry = serde_json::from_value(json).unwrap();
77        assert_eq!(back.id, entry.id);
78    }
79}