feat: add editing and MCP command handling, enhance SSE streaming with usage tracking

- Implemented `Edit` and `McpAdd` commands in the command parser and handler.
- Added a new `stream` module to the runtime for handling streaming events.
- Enhanced `SseParser` to parse usage information from SSE events.
- Introduced `ToolCallAccumulator` for tracking tool calls independently.
- Updated `AppStateRest` to include `app_config` and `MiscState` to track `effort_level` and `selected_index`.
- Modified `LlmClient` to support streaming responses with usage tracking.
- Improved error handling and retry logic in the streaming API calls.
- Added tests for new features and improved markdown rendering in the chat view.
This commit is contained in:
asepharyana
2026-07-12 01:25:52 +07:00
parent fcef85a327
commit 18a41aad48
28 changed files with 838 additions and 98 deletions
+6
View File
@@ -204,6 +204,9 @@ pub struct MiscState {
pub esc_press_count: u32,
pub last_staleness_sweep_ms: i64,
pub thinking: bool,
pub effort_level: usize,
pub selected_index: usize,
pub editor: Option<super::super::mode::editor::EditorState>,
}
impl MiscState {
@@ -216,6 +219,9 @@ impl MiscState {
esc_press_count: 0,
last_staleness_sweep_ms: 0,
thinking: false,
effort_level: 1,
selected_index: 0,
editor: None,
}
}
+4
View File
@@ -8,6 +8,7 @@ use super::runtime::{SessionRuntime, TurnEvent};
use super::types::{AgentMode, Origin, Toast, TranscriptCache};
use crate::app::mcp::manager::McpManager;
use crate::app::workflow::engine::WorkflowEngine;
use crate::model::app_config::AppConfig;
use crate::model::editlog::EditLog;
use crate::model::settings::Settings;
@@ -32,6 +33,7 @@ impl ChatMessageDisplay {
pub struct AppStateRest {
pub mode: AgentMode,
pub settings: Settings,
pub app_config: AppConfig,
pub workspace_roots: Vec<PathBuf>,
pub session_id: String,
pub session_dir: PathBuf,
@@ -57,6 +59,7 @@ pub struct AppStateRest {
impl AppStateRest {
pub fn new(workspace_roots: Vec<PathBuf>, session_dir: PathBuf, memory_dir: PathBuf) -> Self {
let settings = Settings::load();
let app_config = AppConfig::load();
let download_dir = memory_dir.parent().unwrap_or(&memory_dir).join("downloads");
let worktrees_dir = memory_dir.parent().unwrap_or(&memory_dir).join("worktrees");
let dir_cache = DirCache::new();
@@ -67,6 +70,7 @@ impl AppStateRest {
AppStateRest {
mode: AgentMode::Normal,
settings,
app_config,
workspace_roots,
session_id,
session_dir: session_dir.clone(),
+7
View File
@@ -74,6 +74,13 @@ pub enum TurnEvent {
kind: String,
message: String,
},
StreamStart,
StreamToken(String),
StreamDone(crate::dto::chat::message::ChatMessage),
Usage {
tokens_in: u64,
tokens_out: u64,
},
Error(String),
Done,
}