refactor(desktop): ChatStore structured split + IDB persistence + stream cancel
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

Split monolithic chatStore.ts (908 lines) into 4 focused stores:
- chatStore.ts: facade layer, owns messages[], backward-compatible selectors
- conversationStore.ts: conversation CRUD, agent switching, IndexedDB persistence
- streamStore.ts: streaming orchestration, chat mode, suggestions
- messageStore.ts: token tracking

Key fixes from 3-round deep audit:
- C1: Fix Rust serde camelCase vs TS snake_case mismatch (toolStart/toolEnd/iterationStart)
- C2: Fix IDB async rehydration race with persist.hasHydrated() subscribe
- C3: Add sessionKey to partialize to survive page refresh
- H3: Fix IDB migration retry on failure (don't set migrated=true in catch)
- M3: Fix ToolCallStep deduplication (toolStart creates, toolEnd updates)
- M-NEW-2: Clear sessionKey on cancelStream

Also adds:
- Rust backend stream cancellation via AtomicBool + cancel_stream command
- IndexedDB storage adapter with one-time localStorage migration
- HMR cleanup for cross-store subscriptions
This commit is contained in:
iven
2026-04-03 00:24:16 +08:00
parent da438ad868
commit 0a04b260a4
22 changed files with 1269 additions and 767 deletions

View File

@@ -65,6 +65,7 @@ pub struct AgentUpdateRequest {
// ---------------------------------------------------------------------------
/// Create a new agent
// @connected
#[tauri::command]
pub async fn agent_create(
state: State<'_, KernelState>,
@@ -103,6 +104,7 @@ pub async fn agent_create(
}
/// List all agents
// @connected
#[tauri::command]
pub async fn agent_list(
state: State<'_, KernelState>,
@@ -116,6 +118,7 @@ pub async fn agent_list(
}
/// Get agent info
// @connected
#[tauri::command]
pub async fn agent_get(
state: State<'_, KernelState>,
@@ -135,6 +138,7 @@ pub async fn agent_get(
}
/// Delete an agent
// @connected
#[tauri::command]
pub async fn agent_delete(
state: State<'_, KernelState>,
@@ -156,6 +160,7 @@ pub async fn agent_delete(
}
/// Update an agent's configuration
// @connected
#[tauri::command]
pub async fn agent_update(
state: State<'_, KernelState>,
@@ -209,6 +214,7 @@ pub async fn agent_update(
}
/// Export an agent configuration as JSON
// @reserved: 暂无前端集成
#[tauri::command]
pub async fn agent_export(
state: State<'_, KernelState>,
@@ -231,6 +237,7 @@ pub async fn agent_export(
}
/// Import an agent from JSON configuration
// @reserved: 暂无前端集成
#[tauri::command]
pub async fn agent_import(
state: State<'_, KernelState>,