feat: real-time file sync on write_file (upload immediately, not just at end)

This commit is contained in:
2026-04-06 20:24:37 +01:00
parent dcc6c4d28d
commit 76b964998b

View File

@@ -893,6 +893,22 @@ pub async fn run_step_loop(
let result = execute_tool(&tc.function.name, &tc.function.arguments, workdir, exec).await; let result = execute_tool(&tc.function.name, &tc.function.arguments, workdir, exec).await;
let status = if result.starts_with("Error:") { "failed" } else { "done" }; let status = if result.starts_with("Error:") { "failed" } else { "done" };
send_execution(update_tx, workflow_id, step_order, &tc.function.name, &tc.function.arguments, &result, status).await; send_execution(update_tx, workflow_id, step_order, &tc.function.name, &tc.function.arguments, &result, status).await;
// Real-time file sync: upload written file to server immediately
if tc.function.name == "write_file" && status == "done" {
if let Some(rel_path) = args.get("path").and_then(|v| v.as_str()) {
let full = std::path::Path::new(workdir).join(rel_path);
if let Ok(bytes) = tokio::fs::read(&full).await {
use base64::Engine;
let _ = update_tx.send(AgentUpdate::FileSync {
project_id: project_id.to_string(),
path: rel_path.to_string(),
data_b64: base64::engine::general_purpose::STANDARD.encode(&bytes),
}).await;
}
}
}
step_chat_history.push(ChatMessage::tool_result(&tc.id, &result)); step_chat_history.push(ChatMessage::tool_result(&tc.id, &result));
} }
} }