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, PartialEq, Eq, Serialize, Deserialize)]
99pub enum ActionType {
100 PreWarmProcess,
102 PrefetchFile,
104 KeepAlive,
106 ReleaseMemory,
108 NoOp,
110}
111
112#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
114pub enum ActionUrgency {
115 Immediate,
117 IdleTime,
119 Deferred,
121}
122
123#[derive(Debug, Clone)]
133pub struct CapabilityLevel {
134 pub max_risk: RiskLevel,
135 pub allowed_actions: Vec<ActionType>,
136}
137
138#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
145pub enum DenialReason {
146 RiskExceedsConfig,
148 RiskExceedsCapability,
150 ConfidenceTooLow,
152 ActionTypeBlocked,
154 ActionUrgencyDeferred,
156 ActionCapabilityDenied,
158 TargetNotInContext,
161 BatchActionCapExceeded,
163}
164
165impl CapabilityLevel {
166 pub fn for_route(route: DecisionRoute) -> Self {
168 use ActionType::*;
169 match route {
170 DecisionRoute::RuleBased => Self {
171 max_risk: RiskLevel::Low,
172 allowed_actions: vec![NoOp, ReleaseMemory, KeepAlive],
173 },
174 DecisionRoute::LocalEvaluator => Self {
175 max_risk: RiskLevel::Low,
176 allowed_actions: vec![NoOp, PreWarmProcess, PrefetchFile, ReleaseMemory, KeepAlive],
177 },
178 DecisionRoute::CloudLlm => Self {
179 max_risk: RiskLevel::Medium,
180 allowed_actions: vec![NoOp, PreWarmProcess, PrefetchFile, KeepAlive, ReleaseMemory],
181 },
182 DecisionRoute::FallbackNoOp => Self {
183 max_risk: RiskLevel::Low,
184 allowed_actions: vec![NoOp],
185 },
186 DecisionRoute::Mock => Self {
187 max_risk: RiskLevel::Medium,
188 allowed_actions: vec![NoOp, PreWarmProcess, PrefetchFile, KeepAlive, ReleaseMemory],
189 },
190 }
191 }
192
193 pub fn allows_risk(&self, risk: RiskLevel) -> bool {
195 risk as u8 <= self.max_risk as u8
196 }
197
198 pub fn allows_action(&self, action: &ActionType) -> bool {
200 self.allowed_actions.contains(action)
201 }
202}