Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,5 @@ dist
.vite
# Refact binary/symlink
**/refact/bin/refact-lsp

.refact_knowledge*/
2 changes: 2 additions & 0 deletions refact-agent/engine/src/global_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub struct GlobalContext {
pub init_shadow_repos_lock: Arc<AMutex<bool>>,
pub git_operations_abort_flag: Arc<AtomicBool>,
pub app_searchable_id: String,
pub trajectory_events_tx: Option<tokio::sync::broadcast::Sender<crate::http::routers::v1::trajectories::TrajectoryEvent>>,
}

pub type SharedGlobalContext = Arc<ARwLock<GlobalContext>>; // TODO: remove this type alias, confusing
Expand Down Expand Up @@ -426,6 +427,7 @@ pub async fn create_global_context(
init_shadow_repos_lock: Arc::new(AMutex::new(false)),
git_operations_abort_flag: Arc::new(AtomicBool::new(false)),
app_searchable_id: get_app_searchable_id(&workspace_dirs),
trajectory_events_tx: Some(tokio::sync::broadcast::channel(100).0),
};
let gcx = Arc::new(ARwLock::new(cx));
crate::files_in_workspace::watcher_init(gcx.clone()).await;
Expand Down
15 changes: 12 additions & 3 deletions refact-agent/engine/src/http/routers/v1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use at_tools::handle_v1_post_tools;
use axum::Router;
use axum::routing::{get, post, delete};
use axum::routing::{get, post, put, delete};
use tower_http::cors::CorsLayer;

use crate::http::utils::telemetry_middleware;
Expand All @@ -13,7 +13,6 @@ use crate::http::routers::v1::caps::handle_v1_caps;
use crate::http::routers::v1::caps::handle_v1_ping;
use crate::http::routers::v1::chat::{handle_v1_chat, handle_v1_chat_completions};
use crate::http::routers::v1::chat_based_handlers::{handle_v1_commit_message_from_diff, handle_v1_trajectory_compress};
use crate::http::routers::v1::chat_based_handlers::handle_v1_trajectory_save;
use crate::http::routers::v1::dashboard::get_dashboard_plots;
use crate::http::routers::v1::docker::{handle_v1_docker_container_action, handle_v1_docker_container_list};
use crate::http::routers::v1::git::{handle_v1_git_commit, handle_v1_checkpoints_preview, handle_v1_checkpoints_restore};
Expand All @@ -40,6 +39,11 @@ use crate::http::routers::v1::v1_integrations::{handle_v1_integration_get, handl
use crate::http::routers::v1::file_edit_tools::handle_v1_file_edit_tool_dry_run;
use crate::http::routers::v1::code_edit::handle_v1_code_edit;
use crate::http::routers::v1::workspace::{handle_v1_get_app_searchable_id, handle_v1_set_active_group_id};
use crate::http::routers::v1::trajectories::{
handle_v1_trajectories_list, handle_v1_trajectories_get,
handle_v1_trajectories_save, handle_v1_trajectories_delete,
handle_v1_trajectories_subscribe,
};

mod ast;
pub mod at_commands;
Expand Down Expand Up @@ -71,6 +75,7 @@ mod v1_integrations;
pub mod vecdb;
mod workspace;
mod knowledge_graph;
pub mod trajectories;

pub fn make_v1_router() -> Router {
let builder = Router::new()
Expand Down Expand Up @@ -171,8 +176,12 @@ pub fn make_v1_router() -> Router {
.route("/vdb-search", post(handle_v1_vecdb_search))
.route("/vdb-status", get(handle_v1_vecdb_status))
.route("/knowledge-graph", get(handle_v1_knowledge_graph))
.route("/trajectory-save", post(handle_v1_trajectory_save))
.route("/trajectory-compress", post(handle_v1_trajectory_compress))
.route("/trajectories", get(handle_v1_trajectories_list))
.route("/trajectories/subscribe", get(handle_v1_trajectories_subscribe))
.route("/trajectories/:id", get(handle_v1_trajectories_get))
.route("/trajectories/:id", put(handle_v1_trajectories_save))
.route("/trajectories/:id", delete(handle_v1_trajectories_delete))
;

builder
Expand Down
24 changes: 0 additions & 24 deletions refact-agent/engine/src/http/routers/v1/chat_based_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,4 @@ pub async fn handle_v1_trajectory_compress(
}


pub async fn handle_v1_trajectory_save(
Extension(gcx): Extension<Arc<ARwLock<GlobalContext>>>,
body_bytes: hyper::body::Bytes,
) -> axum::response::Result<Response<Body>, ScratchError> {
let post = serde_json::from_slice::<CompressTrajectoryPost>(&body_bytes).map_err(|e| {
ScratchError::new(StatusCode::UNPROCESSABLE_ENTITY, format!("JSON problem: {}", e))
})?;

let trajectory = compress_trajectory(gcx.clone(), &post.messages)
.await.map_err(|e| ScratchError::new(StatusCode::UNPROCESSABLE_ENTITY, e))?;

let file_path = crate::memories::save_trajectory(gcx, &trajectory)
.await.map_err(|e| ScratchError::new(StatusCode::INTERNAL_SERVER_ERROR, e))?;

let response = serde_json::json!({
"trajectory": trajectory,
"file_path": file_path.to_string_lossy(),
});

Ok(Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "application/json")
.body(Body::from(serde_json::to_string(&response).unwrap()))
.unwrap())
}
Loading
Loading