优化: aichat 打磨收尾(切换信任保留 + save并发串行 + 后台授权守卫 + 分离窗口失效 + 气泡截图复制)

This commit is contained in:
lxy
2026-08-08 21:08:25 +08:00
parent 65c0f6b2b6
commit 6ba6daf188
14 changed files with 196 additions and 27 deletions
+11
View File
@@ -617,6 +617,8 @@ pub struct AiSession {
/// 删除语义:删了就删了,loop 后续 save 不应复活。conv_id 是 ULID 不重用,条目长期保留
/// (单条 ~40B,删除量级下可忽略)。
pub deleted_convs: HashSet<String>,
/// 每会话 save 串行锁:同会话并发 save(loop 与 IPC)串行化,防全量重写互踩吞新行
pub save_locks: HashMap<String, Arc<tokio::sync::Mutex<()>>>,
/// T2 工具命名空间存储(运行时缓存,大工具结果不进主队列)
pub namespace_store: df_ai::namespace_store::NamespaceStore,
}
@@ -630,6 +632,7 @@ impl AiSession {
pending_approvals: HashMap::new(),
per_conv: HashMap::new(),
deleted_convs: HashSet::new(),
save_locks: HashMap::new(),
namespace_store: df_ai::namespace_store::NamespaceStore::default(),
}
}
@@ -688,6 +691,14 @@ impl AiSession {
pub fn conv_read(&self, conv_id: &str) -> Option<&PerConvState> {
self.per_conv.get(conv_id)
}
/// 取或惰性创建某会话的 save 串行锁(返回 Arc 供 save 全程持有)。
pub fn save_lock(&mut self, conv_id: &str) -> Arc<tokio::sync::Mutex<()>> {
self.save_locks
.entry(conv_id.to_string())
.or_insert_with(|| Arc::new(tokio::sync::Mutex::new(())))
.clone()
}
}
#[cfg(test)]