异步化 DirectProject 线程订阅

把历史末项读取和订阅初始化移入 spawn_blocking,避免同步命令阻塞。
This commit is contained in:
2026-09-15 19:58:41 +08:00
committed by kdletters
parent 62d413c792
commit 75fda11b99
@@ -5278,24 +5278,27 @@ pub(crate) async fn read_agent_runtime_error_detail(
.await
.map_err(|error| format!("读取统一错误诊断后台任务失败:{error}"))?
#[tauri::command]
pub(crate) fn subscribe_direct_project_thread(
pub(crate) async fn subscribe_direct_project_thread(
project_path: String,
) -> Result<DirectThreadSubscriptionBootstrap, String> {
let root = Path::new(project_path.trim());
enforce_project_permission_policy(root, "conversation.read")?;
let (canonical_root, _) = direct_codex_canonical_project_identity(root)?;
let thread_root = canonical_root
.to_str()
.and_then(|value| value.strip_prefix("\\\\?\\"))
.map(Path::new)
.unwrap_or(canonical_root.as_path());
let thread_id = thread_root.to_string_lossy().into_owned();
let mut bootstrap = subscribe_direct_thread(&thread_id);
if bootstrap.last_completed_item_id.is_none() {
bootstrap.last_completed_item_id = read_direct_project_last_item_id_at(root)?;
}
Ok(bootstrap)
tauri::async_runtime::spawn_blocking(move || {
let root = Path::new(project_path.trim());
enforce_project_permission_policy(root, "conversation.read")?;
let (canonical_root, _) = direct_codex_canonical_project_identity(root)?;
let thread_root = canonical_root
.to_str()
.and_then(|value| value.strip_prefix("\\\\?\\"))
.map(Path::new)
.unwrap_or(canonical_root.as_path());
let thread_id = thread_root.to_string_lossy().into_owned();
let mut bootstrap = subscribe_direct_thread(&thread_id);
if bootstrap.last_completed_item_id.is_none() {
bootstrap.last_completed_item_id = read_direct_project_last_item_id_at(root)?;
}
Ok(bootstrap)
})
.await
.map_err(|error| format!("订阅 DirectProject 线程后台任务失败:{error}"))?
}
#[tauri::command]