Skip to main content

aios_spec/
context.rs

1//! 上下文窗口 — "what to send to the LLM"
2//!
3//! 脱敏后的 SanitizedEvent 按时间窗口聚合,
4//! 形成发送给 Cloud LLM 的结构化上下文。
5//! 这是 DiPECS daemon 向上的核心接口。
6
7use serde::{Deserialize, Serialize};
8
9use crate::event::{
10    ExtensionCategory, LocationType, NetworkType, RingerMode, SemanticHint, SourceTier,
11};
12use crate::sanitized::SanitizedEvent;
13
14/// 时间窗口内的脱敏上下文
15///
16/// 这是 aios-agent 发送给 Cloud LLM 的唯一数据格式。
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct StructuredContext {
19    /// 窗口唯一 ID
20    pub window_id: String,
21    /// 窗口起始时间 (epoch ms)
22    pub window_start_ms: i64,
23    /// 窗口结束时间 (epoch ms)
24    pub window_end_ms: i64,
25    /// 窗口持续的秒数
26    pub duration_secs: u32,
27    /// 窗口内的事件序列 (按时间排序, 已脱敏)
28    pub events: Vec<SanitizedEvent>,
29    /// 窗口聚合摘要 (帮助 LLM 快速理解)
30    pub summary: ContextSummary,
31}
32
33/// 窗口聚合摘要
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct ContextSummary {
36    /// 窗口内的前台 app 序列 (按时间顺序, 去重)
37    pub foreground_apps: Vec<String>,
38    /// 收到通知的 app 列表 (去重)
39    pub notified_apps: Vec<String>,
40    /// 触发的语义标签汇总 (去重)
41    pub all_semantic_hints: Vec<SemanticHint>,
42    /// 文件活动汇总 (扩展名类别 → 次数)
43    pub file_activity: Vec<(ExtensionCategory, u32)>,
44    /// 系统状态快照 (取窗口内的最新值)
45    pub latest_system_status: Option<SystemStatusSnapshot>,
46    /// 来源能力等级
47    pub source_tier: SourceTier,
48}
49
50/// 系统状态快照
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct SystemStatusSnapshot {
53    pub battery_pct: Option<u8>,
54    pub is_charging: bool,
55    pub network: NetworkType,
56    pub ringer_mode: RingerMode,
57    pub location_type: LocationType,
58    pub headphone_connected: bool,
59}