ainl_context_compiler/
capability.rs1use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
11#[serde(rename_all = "snake_case")]
12pub enum Tier {
13 #[default]
15 Heuristic,
16 HeuristicSummarization,
18 HeuristicSummarizationEmbedding,
20}
21
22impl Tier {
23 #[must_use]
25 pub fn as_str(self) -> &'static str {
26 match self {
27 Self::Heuristic => "heuristic",
28 Self::HeuristicSummarization => "heuristic_summarization",
29 Self::HeuristicSummarizationEmbedding => "heuristic_summarization_embedding",
30 }
31 }
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
36pub struct CapabilityProbe {
37 pub summarizer: bool,
39 pub embedder: bool,
41}
42
43impl CapabilityProbe {
44 #[must_use]
46 pub fn offline() -> Self {
47 Self::default()
48 }
49
50 #[must_use]
52 pub fn active_tier(self) -> Tier {
53 match (self.summarizer, self.embedder) {
54 (true, true) => Tier::HeuristicSummarizationEmbedding,
55 (true, false) => Tier::HeuristicSummarization,
56 (false, true) => Tier::HeuristicSummarizationEmbedding,
57 (false, false) => Tier::Heuristic,
58 }
59 }
60
61 #[must_use]
63 pub fn reason(self) -> &'static str {
64 match (self.summarizer, self.embedder) {
65 (true, true) => "summarizer_and_embedder_present",
66 (true, false) => "summarizer_present",
67 (false, true) => "embedder_present",
68 (false, false) => "heuristic_only",
69 }
70 }
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn offline_is_heuristic() {
79 assert_eq!(CapabilityProbe::offline().active_tier(), Tier::Heuristic);
80 }
81
82 #[test]
83 fn summarizer_only_unlocks_tier1() {
84 let p = CapabilityProbe {
85 summarizer: true,
86 embedder: false,
87 };
88 assert_eq!(p.active_tier(), Tier::HeuristicSummarization);
89 }
90
91 #[test]
92 fn both_unlocks_tier2() {
93 let p = CapabilityProbe {
94 summarizer: true,
95 embedder: true,
96 };
97 assert_eq!(p.active_tier(), Tier::HeuristicSummarizationEmbedding);
98 }
99
100 #[test]
101 fn embedder_only_unlocks_embedding_tier() {
102 let p = CapabilityProbe {
103 summarizer: false,
104 embedder: true,
105 };
106 assert_eq!(p.active_tier(), Tier::HeuristicSummarizationEmbedding);
107 }
108}