diff options
| author | soryu <soryu@soryu.co> | 2025-12-23 22:20:52 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2025-12-23 22:20:52 +0000 |
| commit | 72c2590571104b8d10e3f72d7a5b984d0b520c51 (patch) | |
| tree | 735aa03056a44a93b9abdf915545ad034ee2b597 /makima/src/server/handlers/chat.rs | |
| parent | f5222a7ae5ade5589436778cb01fc0abe625b3c3 (diff) | |
| download | soryu-72c2590571104b8d10e3f72d7a5b984d0b520c51.tar.gz soryu-72c2590571104b8d10e3f72d7a5b984d0b520c51.zip | |
Add conflict notification and file update WS endpoint
Diffstat (limited to 'makima/src/server/handlers/chat.rs')
| -rw-r--r-- | makima/src/server/handlers/chat.rs | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/makima/src/server/handlers/chat.rs b/makima/src/server/handlers/chat.rs index 92c4ec8..3bdbc74 100644 --- a/makima/src/server/handlers/chat.rs +++ b/makima/src/server/handlers/chat.rs @@ -17,7 +17,7 @@ use crate::llm::{ groq::{GroqClient, GroqError, Message, ToolCallResponse}, LlmModel, ToolCall, ToolResult, AVAILABLE_TOOLS, }; -use crate::server::state::SharedState; +use crate::server::state::{FileUpdateNotification, SharedState}; /// Maximum number of tool-calling rounds to prevent infinite loops const MAX_TOOL_ROUNDS: usize = 10; @@ -385,17 +385,43 @@ pub async fn chat_handler( transcript: None, summary: current_summary.clone(), body: Some(current_body.clone()), + version: None, // Internal update, skip version check }; - if let Err(e) = repository::update_file(pool, id, update_req).await { - tracing::error!("Failed to save file changes: {}", e); - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": format!("Failed to save changes: {}", e) - })), - ) - .into_response(); + match repository::update_file(pool, id, update_req).await { + Ok(Some(updated_file)) => { + // Broadcast update notification for LLM changes + let mut updated_fields = vec!["body".to_string()]; + if current_summary.is_some() { + updated_fields.push("summary".to_string()); + } + state.broadcast_file_update(FileUpdateNotification { + file_id: id, + version: updated_file.version, + updated_fields, + updated_by: "llm".to_string(), + }); + } + Ok(None) => { + // File was deleted during processing + return ( + StatusCode::NOT_FOUND, + Json(serde_json::json!({ + "error": "File not found" + })), + ) + .into_response(); + } + Err(e) => { + tracing::error!("Failed to save file changes: {}", e); + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": format!("Failed to save changes: {}", e) + })), + ) + .into_response(); + } } } |
