Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(threads): add thread ops for edit, purge, titles, and working dir

Steven Enamakel554b835fb1b0
diff --git a/crates/openhuman-core/src/threads/ops/edit.rs b/crates/openhuman-core/src/threads/ops/edit.rs
index 0c2a2d85e3..21d31f91e9 100644
--- a/crates/openhuman-core/src/threads/ops/edit.rs
+++ b/crates/openhuman-core/src/threads/ops/edit.rs
@@ -118,7 +118,7 @@ pub async fn edit_message(
// Truncate the message log at the edited message itself (inclusive) —
// it and everything after it is replaced by the fresh turn below.
- super::delete_after(&thread_id, &request.message_id).await?;
+ super::delete_after(ctx, &thread_id, &request.message_id).await?;
crate::web_chat::invalidate_thread_sessions(&thread_id).await;
@@ -189,7 +189,7 @@ pub async fn regenerate(
})?;
clear_dropped_turn_states(&dir, &thread_id, &cut_request_id).await;
- super::delete_after(&thread_id, &run_reply_message_id(&cut_request_id)).await?;
+ super::delete_after(ctx, &thread_id, &run_reply_message_id(&cut_request_id)).await?;
crate::web_chat::invalidate_thread_sessions(&thread_id).await;
@@ -220,12 +220,13 @@ pub async fn regenerate(
/// it was minted for. `Ok(None)` when `after_message_id` has no reply yet
/// (or is the log's last message).
async fn next_reply_request_id_after(
+ ctx: &DispatchCtx,
dir: &std::path::Path,
thread_id: &str,
after_message_id: &str,
) -> Result<Option<String>, String> {
let messages =
- conversations::blocking::get_messages(dir.to_path_buf(), thread_id.to_string()).await?;
+ conversations::blocking::get_messages(ctx.clone(), dir.to_path_buf(), thread_id.to_string()).await?;
let Some(start) = messages.iter().position(|m| m.id == after_message_id) else {
return Ok(None);
};
diff --git a/crates/openhuman-core/src/threads/ops/purge.rs b/crates/openhuman-core/src/threads/ops/purge.rs
index 5444b656bf..7c11d814da 100644
--- a/crates/openhuman-core/src/threads/ops/purge.rs
+++ b/crates/openhuman-core/src/threads/ops/purge.rs
@@ -12,16 +12,18 @@ use std::path::PathBuf;
/// / turn-snapshot cleanup are one [`run_to_completion`] unit, so a dropped
/// caller cannot leave every thread wiped while their sub-agents keep running.
pub async fn threads_purge(
+ ctx: &DispatchCtx,
_request: EmptyRequest,
) -> Result<Outcome<ApiEnvelope<PurgeConversationThreadsResponse>>, String> {
let dir = workspace_dir().await?;
- run_to_completion("threads_purge", threads_purge_inner(dir)).await
+ run_to_completion("threads_purge", threads_purge_inner(ctx.clone(), dir)).await
}
async fn threads_purge_inner(
+ ctx: DispatchCtx,
dir: PathBuf,
) -> Result<Outcome<ApiEnvelope<PurgeConversationThreadsResponse>>, String> {
- let stats = conversations::blocking::purge_threads(dir.clone()).await?;
+ let stats = conversations::blocking::purge_threads(ctx.clone(), dir.clone()).await?;
// No parent thread survives a purge, so cancel every detached sub-agent and
// wipe every queued result. Same ordering as `thread_delete`: abort the
// in-flight runs first, then clear the delivery queue. Tombstone each
diff --git a/crates/openhuman-core/src/threads/ops/support.rs b/crates/openhuman-core/src/threads/ops/support.rs
index 931ba66b4c..68993e2f0e 100644
--- a/crates/openhuman-core/src/threads/ops/support.rs
+++ b/crates/openhuman-core/src/threads/ops/support.rs
@@ -124,6 +124,7 @@ pub(super) fn fallback_title_from_user_message(
}
pub(super) async fn update_thread_with_fallback_title(
+ ctx: &DispatchCtx,
dir: PathBuf,
thread: ConversationThread,
user_message: &str,
@@ -135,6 +136,7 @@ pub(super) async fn update_thread_with_fallback_title(
return Ok(thread);
}
conversations::blocking::update_thread_title(
+ ctx.clone(),
dir,
thread.id.clone(),
title,
diff --git a/crates/openhuman-core/src/threads/ops/title_generation.rs b/crates/openhuman-core/src/threads/ops/title_generation.rs
index 6d26b465c1..db7da1defa 100644
--- a/crates/openhuman-core/src/threads/ops/title_generation.rs
+++ b/crates/openhuman-core/src/threads/ops/title_generation.rs
@@ -44,13 +44,14 @@ pub(crate) fn is_replaceable_title(
/// Generates a durable thread title from the first user message and assistant reply.
pub async fn thread_generate_title(
+ ctx: &DispatchCtx,
request: GenerateConversationThreadTitleRequest,
) -> Result<Outcome<ApiEnvelope<ConversationThreadSummary>>, ThreadsError> {
let config = Config::load_or_init()
.await
.map_err(|e| format!("load config: {e}"))?;
let dir = config.workspace_dir.clone();
- let Some(thread) = conversations::blocking::list_threads(dir.clone())
+ let Some(thread) = conversations::blocking::list_threads(ctx.clone(), dir.clone())
.await?
.into_iter()
.find(|thread| thread.id == request.thread_id)
@@ -59,7 +60,7 @@ pub async fn thread_generate_title(
};
let messages =
- conversations::blocking::get_messages(dir.clone(), request.thread_id.clone()).await?;
+ conversations::blocking::get_messages(ctx.clone(), dir.clone(), request.thread_id.clone()).await?;
let first_user_message = messages
.iter()
.find(|message| message.sender == "user" && !message.content.trim().is_empty())
@@ -199,6 +200,7 @@ pub async fn thread_generate_title(
}
let updated = conversations::blocking::update_thread_title(
+ ctx.clone(),
dir,
request.thread_id.clone(),
title,
diff --git a/crates/openhuman-core/src/threads/ops/working_dir.rs b/crates/openhuman-core/src/threads/ops/working_dir.rs
index e88261efd2..b49c23a2b8 100644
--- a/crates/openhuman-core/src/threads/ops/working_dir.rs
+++ b/crates/openhuman-core/src/threads/ops/working_dir.rs
@@ -51,10 +51,11 @@ pub(crate) fn validate_working_dir(raw: Option<&str>) -> Result<Option<String>,
/// An unusable bound folder is an error, rather than a reason to run in the
/// global folder. This preserves the conversation's filesystem boundary.
pub(crate) async fn thread_working_dir(
+ ctx: &DispatchCtx,
workspace_dir: PathBuf,
thread_id: &str,
) -> Result<Option<PathBuf>, String> {
- let threads = conversations::blocking::list_threads(workspace_dir)
+ let threads = conversations::blocking::list_threads(ctx.clone(), workspace_dir)
.await
.map_err(|err| format!("failed to load thread working folder: {err}"))?;
let bound = threads
@@ -73,11 +74,12 @@ pub(crate) async fn thread_working_dir(
/// Binds or clears the working folder of a thread that has no messages yet.
pub async fn thread_update_working_dir(
+ ctx: &DispatchCtx,
request: UpdateConversationThreadWorkingDirRequest,
) -> Result<Outcome<ApiEnvelope<ConversationThreadSummary>>, ThreadsError> {
let dir = workspace_dir().await?;
let working_dir = validate_working_dir(Some(&request.action_dir))?;
- let Some(thread) = conversations::blocking::list_threads(dir.clone())
+ let Some(thread) = conversations::blocking::list_threads(ctx.clone(), dir.clone())
.await?
.into_iter()
.find(|thread| thread.id == request.thread_id)
@@ -92,6 +94,7 @@ pub async fn thread_update_working_dir(
);
}
let updated = conversations::blocking::update_thread_working_dir(
+ ctx.clone(),
dir,
request.thread_id.clone(),
working_dir,