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 edit operation

Steven Enamakel4f4e1a880ca8
diff --git a/crates/openhuman-core/src/threads/ops/edit.rs b/crates/openhuman-core/src/threads/ops/edit.rs
index c2490cb53c..0c2a2d85e3 100644
--- a/crates/openhuman-core/src/threads/ops/edit.rs
+++ b/crates/openhuman-core/src/threads/ops/edit.rs
@@ -80,7 +80,10 @@ pub struct EditOrRegenerateResponse {
/// Edit a past user message: cancel the in-flight turn (if any), fork the
/// session transcript and message log to drop that message and everything
/// after it, then restart the turn with `content` in its place.
-pub async fn edit_message(request: EditMessageRequest) -> Result<Outcome<Value>, ThreadsError> {
+pub async fn edit_message(
+ ctx: &crate::core::runtime::DispatchCtx,
+ request: EditMessageRequest,
+) -> Result<Outcome<Value>, ThreadsError> {
let client_id = request.client_id.unwrap_or_else(|| "system".to_string());
let thread_id = request.thread_id;
let dir = workspace_dir().await.map_err(ThreadsError::Message)?;
@@ -120,6 +123,7 @@ pub async fn edit_message(request: EditMessageRequest) -> Result<Outcome<Value>,
crate::web_chat::invalidate_thread_sessions(&thread_id).await;
let new_request_id = crate::web_chat::start_chat(
+ ctx,
&client_id,
&thread_id,
&request.content,
@@ -144,7 +148,10 @@ pub async fn edit_message(request: EditMessageRequest) -> Result<Outcome<Value>,
/// last turn): cancel the in-flight turn (if any), fork the session
/// transcript and message log to drop the answer and everything after it,
/// then restart the turn with the same user prompt that produced it.
-pub async fn regenerate(request: RegenerateRequest) -> Result<Outcome<Value>, ThreadsError> {
+pub async fn regenerate(
+ ctx: &crate::core::runtime::DispatchCtx,
+ request: RegenerateRequest,
+) -> Result<Outcome<Value>, ThreadsError> {
let client_id = request.client_id.unwrap_or_else(|| "system".to_string());
let thread_id = request.thread_id;
let dir = workspace_dir().await.map_err(ThreadsError::Message)?;
@@ -187,6 +194,7 @@ pub async fn regenerate(request: RegenerateRequest) -> Result<Outcome<Value>, Th
crate::web_chat::invalidate_thread_sessions(&thread_id).await;
let new_request_id = crate::web_chat::start_chat(
+ ctx,
&client_id,
&thread_id,
&prompt,
diff --git a/crates/openhuman-core/src/threads/schemas/handlers.rs b/crates/openhuman-core/src/threads/schemas/handlers.rs
index 3d3136e0a9..7eab7e50af 100644
--- a/crates/openhuman-core/src/threads/schemas/handlers.rs
+++ b/crates/openhuman-core/src/threads/schemas/handlers.rs
@@ -220,14 +220,14 @@ pub(super) fn handle_edit_message(
) -> ControllerFuture {
Box::pin(async move {
let p = parse::<ops::EditMessageRequest>(params)?;
- to_json(ops::edit_message(p).await.map_err(|e| e.to_string())?)
+ to_json(ops::edit_message(&ctx, p).await.map_err(|e| e.to_string())?)
})
}
pub(super) fn handle_regenerate(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let p = parse::<ops::RegenerateRequest>(params)?;
- to_json(ops::regenerate(p).await.map_err(|e| e.to_string())?)
+ to_json(ops::regenerate(&ctx, p).await.map_err(|e| e.to_string())?)
})
}
diff --git a/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs b/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs
index 1240f38bc7..2d99b48097 100644
--- a/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs
+++ b/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs
@@ -33,6 +33,7 @@ pub(crate) async fn deliver_response_with_timing_for_test(
timing: Option<super::super::turn_timing::TurnTimingSnapshot>,
) {
super::deliver_response(
+ &crate::core::runtime::DispatchCtx::ambient(),
client_id,
thread_id,
request_id,
@@ -59,6 +60,7 @@ pub async fn deliver_response_in_workspace_for_test(
workspace_dir: Option<&std::path::Path>,
) {
super::deliver_response(
+ &crate::core::runtime::DispatchCtx::ambient(),
client_id,
thread_id,
request_id,