1use serde::{Deserialize, Serialize};
6
7use crate::event::ExtensionCategory;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct IntentBatch {
12 pub window_id: String,
14 pub intents: Vec<Intent>,
16 pub generated_at_ms: i64,
18 pub model: String,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
24pub enum DecisionRoute {
25 RuleBased,
26 LocalEvaluator,
27 CloudLlm,
28 FallbackNoOp,
29 Mock,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct DecisionBackendResult {
35 pub route: DecisionRoute,
36 pub intent_batch: IntentBatch,
37 pub rationale_tags: Vec<String>,
38 pub latency_us: u64,
39 pub error: Option<String>,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct Intent {
45 pub intent_id: String,
47 pub intent_type: IntentType,
49 pub confidence: f32,
51 pub risk_level: RiskLevel,
53 pub suggested_actions: Vec<SuggestedAction>,
55 pub rationale_tags: Vec<String>,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
61pub enum IntentType {
62 OpenApp(String),
64 SwitchToApp(String),
66 CheckNotification(String),
68 HandleFile(ExtensionCategory),
70 EnterContext(String),
72 Idle,
74}
75
76#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
78pub enum RiskLevel {
79 Low,
81 Medium,
83 High,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct SuggestedAction {
90 pub action_type: ActionType,
91 pub target: Option<String>,
93 pub urgency: ActionUrgency,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct AuthorizedAction {
100 pub intent_id: String,
101 pub action: SuggestedAction,
102 pub authorized_at_ms: i64,
103}
104
105#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107pub enum ActionType {
108 PreWarmProcess,
110 PrefetchFile,
112 KeepAlive,
114 ReleaseMemory,
116 NoOp,
118}
119
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
122pub enum ActionUrgency {
123 Immediate,
125 IdleTime,
127 Deferred,
129}
130
131#[derive(Debug, Clone)]
141pub struct CapabilityLevel {
142 pub max_risk: RiskLevel,
143 pub allowed_actions: Vec<ActionType>,
144}
145
146#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
153pub enum DenialReason {
154 RiskExceedsConfig,
156 RiskExceedsCapability,
158 ConfidenceTooLow,
160 ActionTypeBlocked,
162 ActionUrgencyDeferred,
164 ActionCapabilityDenied,
166 TargetNotInContext,
169 BatchActionCapExceeded,
171}
172
173impl CapabilityLevel {
174 pub fn for_route(route: DecisionRoute) -> Self {
176 use ActionType::*;
177 match route {
178 DecisionRoute::RuleBased => Self {
179 max_risk: RiskLevel::Low,
180 allowed_actions: vec![NoOp, ReleaseMemory, KeepAlive],
181 },
182 DecisionRoute::LocalEvaluator => Self {
183 max_risk: RiskLevel::Low,
184 allowed_actions: vec![NoOp, PreWarmProcess, PrefetchFile, ReleaseMemory, KeepAlive],
185 },
186 DecisionRoute::CloudLlm => Self {
187 max_risk: RiskLevel::Medium,
188 allowed_actions: vec![NoOp, PreWarmProcess, PrefetchFile, KeepAlive, ReleaseMemory],
189 },
190 DecisionRoute::FallbackNoOp => Self {
191 max_risk: RiskLevel::Low,
192 allowed_actions: vec![NoOp],
193 },
194 DecisionRoute::Mock => Self {
195 max_risk: RiskLevel::Medium,
196 allowed_actions: vec![NoOp, PreWarmProcess, PrefetchFile, KeepAlive, ReleaseMemory],
197 },
198 }
199 }
200
201 pub fn allows_risk(&self, risk: RiskLevel) -> bool {
203 risk as u8 <= self.max_risk as u8
204 }
205
206 pub fn allows_action(&self, action: &ActionType) -> bool {
208 self.allowed_actions.contains(action)
209 }
210}