1use serde::{Deserialize, Serialize};
8
9use crate::event::{
10 ExtensionCategory, LocationType, NetworkType, RingerMode, SemanticHint, SourceTier,
11};
12use crate::sanitized::SanitizedEvent;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct StructuredContext {
17 pub window_id: String,
18 pub window_start_ms: i64,
19 pub window_end_ms: i64,
20 pub duration_secs: u32,
21 pub events: Vec<SanitizedEvent>,
22 pub summary: ContextSummary,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct ModelInput {
33 pub current_context: StructuredContext,
34 pub behavior_profile: UserBehaviorProfile,
35 pub recent_feedback: Vec<RecentDecisionRecord>,
36}
37
38impl ModelInput {
39 pub fn current_only(current_context: StructuredContext) -> Self {
40 Self {
41 current_context,
42 behavior_profile: UserBehaviorProfile::default(),
43 recent_feedback: Vec::new(),
44 }
45 }
46}
47
48#[derive(Debug, Clone, Default, Serialize, Deserialize)]
50pub struct UserBehaviorProfile {
51 pub user_id: Option<String>,
57 pub summary: String,
58 pub observation_windows: u32,
59 pub frequent_foreground_apps: Vec<(String, u32)>,
60 pub frequent_notifying_apps: Vec<(String, u32)>,
61 pub frequent_semantic_hints: Vec<(SemanticHint, u32)>,
62 pub action_successes: Vec<(String, u32)>,
63 pub action_denials: Vec<(String, u32)>,
64 pub action_failures: Vec<(String, u32)>,
65 pub last_updated_window_id: Option<String>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct RecentDecisionRecord {
71 pub window_id: String,
72 pub window_start_ms: i64,
73 pub window_end_ms: i64,
74 pub foreground_apps: Vec<String>,
75 pub notified_apps: Vec<String>,
76 pub semantic_hints: Vec<SemanticHint>,
77 pub route: String,
78 pub model: String,
79 pub intent_count: u32,
80 pub rationale_tags: Vec<String>,
81 pub backend_error: Option<String>,
82 pub action_outcomes: Vec<ActionFeedbackRecord>,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct ActionFeedbackRecord {
87 pub action_type: String,
88 pub target: Option<String>,
89 pub terminal: String,
90 pub correctness: FeedbackCorrectness,
91 pub correctness_evidence: String,
92 pub denial_reason: Option<String>,
93 pub error: Option<String>,
94 pub outcome_summary: Option<String>,
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
98pub enum FeedbackCorrectness {
99 LikelyCorrect,
100 PredictionHit,
101 PredictionMiss,
102 PolicyRejected,
103 ExecutionFailed,
104 NeutralNoOp,
105 Unknown,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct ContextSummary {
111 pub foreground_apps: Vec<String>,
112 pub notified_apps: Vec<String>,
113 pub all_semantic_hints: Vec<SemanticHint>,
114 pub file_activity: Vec<(ExtensionCategory, u32)>,
115 pub latest_system_status: Option<SystemStatusSnapshot>,
116 pub source_tier: SourceTier,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct SystemStatusSnapshot {
122 pub battery_pct: Option<u8>,
123 pub is_charging: bool,
124 pub network: NetworkType,
125 pub ringer_mode: RingerMode,
126 pub location_type: LocationType,
127 pub headphone_connected: bool,
128}