Skip to content

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

refactor(threads): split thread ops into focused modules

Steven Enamakel80e6c26fba0c
diff --git a/crates/openhuman-core/src/threads/ops/edit.rs b/crates/openhuman-core/src/threads/ops/edit.rs
index 21d31f91e9..a2c41ff6e8 100644
--- a/crates/openhuman-core/src/threads/ops/edit.rs
+++ b/crates/openhuman-core/src/threads/ops/edit.rs
@@ -46,6 +46,7 @@ use tinyagents_session::transcript::{
TranscriptMeta, TruncateCut,
};
+use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
use crate::threads::store::{self as conversations, reply_run_id, run_reply_message_id};
use crate::threads::ThreadsError;
@@ -95,7 +96,7 @@ pub async fn edit_message(
// Correlate through the next assistant reply, if any — see the module
// doc's mapping section. `None` means the edited message has no reply
// yet, so there is nothing to cut on the model side.
- let cut_request_id = next_reply_request_id_after(&dir, &thread_id, &request.message_id)
+ let cut_request_id = next_reply_request_id_after(ctx, &dir, &thread_id, &request.message_id)
.await
.map_err(ThreadsError::Message)?;
diff --git a/crates/openhuman-core/src/threads/ops/purge.rs b/crates/openhuman-core/src/threads/ops/purge.rs
index 7c11d814da..c10e8b4307 100644
--- a/crates/openhuman-core/src/threads/ops/purge.rs
+++ b/crates/openhuman-core/src/threads/ops/purge.rs
@@ -1,6 +1,7 @@
//! Workspace-wide conversation purge.
use super::support::{envelope, run_to_completion, workspace_dir};
+use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
use crate::threads::store as conversations;
use crate::threads::{ApiEnvelope, EmptyRequest, PurgeConversationThreadsResponse};
diff --git a/crates/openhuman-core/src/threads/ops/support.rs b/crates/openhuman-core/src/threads/ops/support.rs
index 68993e2f0e..021c054788 100644
--- a/crates/openhuman-core/src/threads/ops/support.rs
+++ b/crates/openhuman-core/src/threads/ops/support.rs
@@ -3,6 +3,7 @@
//! store-type <-> wire-type conversions every handler needs.
use crate::config::Config;
+use crate::core::runtime::DispatchCtx;
use crate::core::runtime::context::CoreContext;
use crate::threads::store as conversations;
use crate::threads::store::{ConversationMessage, ConversationThread};
diff --git a/crates/openhuman-core/src/threads/ops/title_generation.rs b/crates/openhuman-core/src/threads/ops/title_generation.rs
index db7da1defa..4cdc760827 100644
--- a/crates/openhuman-core/src/threads/ops/title_generation.rs
+++ b/crates/openhuman-core/src/threads/ops/title_generation.rs
@@ -3,6 +3,7 @@
use super::support::{counts, envelope, thread_to_summary, update_thread_with_fallback_title};
use crate::config::Config;
+use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
use crate::inference::provider;
use crate::threads::store as conversations;
@@ -114,7 +115,7 @@ pub async fn thread_generate_title(
thread_id = %request.thread_id,
"{THREAD_TITLE_LOG_PREFIX} no assistant message yet; applying fallback title"
);
- let updated = update_thread_with_fallback_title(dir, thread, &first_user_message).await?;
+ let updated = update_thread_with_fallback_title(ctx, dir, thread, &first_user_message).await?;
return Ok(envelope(
thread_to_summary(updated),
Some(counts([("num_threads", 1)])),
@@ -135,7 +136,7 @@ pub async fn thread_generate_title(
"{THREAD_TITLE_LOG_PREFIX} provider init failed; applying fallback title"
);
let updated =
- update_thread_with_fallback_title(dir, thread, &first_user_message).await?;
+ update_thread_with_fallback_title(ctx, dir, thread, &first_user_message).await?;
return Ok(envelope(
thread_to_summary(updated),
Some(counts([("num_threads", 1)])),
@@ -167,7 +168,7 @@ pub async fn thread_generate_title(
"{THREAD_TITLE_LOG_PREFIX} title generation failed; applying fallback title"
);
let updated =
- update_thread_with_fallback_title(dir, thread, &first_user_message).await?;
+ update_thread_with_fallback_title(ctx, dir, thread, &first_user_message).await?;
return Ok(envelope(
thread_to_summary(updated),
Some(counts([("num_threads", 1)])),
@@ -183,7 +184,7 @@ pub async fn thread_generate_title(
raw_title_hash = %title_log_fingerprint(&raw_title),
"{THREAD_TITLE_LOG_PREFIX} generated empty title after sanitization; applying fallback title"
);
- let updated = update_thread_with_fallback_title(dir, thread, &first_user_message).await?;
+ let updated = update_thread_with_fallback_title(ctx, dir, thread, &first_user_message).await?;
return Ok(envelope(
thread_to_summary(updated),
Some(counts([("num_threads", 1)])),
diff --git a/crates/openhuman-core/src/threads/ops/working_dir.rs b/crates/openhuman-core/src/threads/ops/working_dir.rs
index b49c23a2b8..725784f57e 100644
--- a/crates/openhuman-core/src/threads/ops/working_dir.rs
+++ b/crates/openhuman-core/src/threads/ops/working_dir.rs
@@ -8,6 +8,7 @@
//! in another.
use super::support::{counts, envelope, thread_to_summary, workspace_dir};
+use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
use crate::security::SecurityPolicy;
use crate::threads::store as conversations;