The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(relay): add relay channel ops and store
Steven Enamakelc98d8dcebe55
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rsindex 167b387ecf..7ee04ad896 100644--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs@@ -46,7 +46,7 @@ pub async fn channel_relay_inbound(let thread_id = identity.thread_id;let workspace_dir = config.workspace_dir.clone();- if store::record_inbound(&workspace_dir, ¶ms, &thread_id).await? == Recorded::Duplicate {+ if store::record_inbound(ctx, &workspace_dir, ¶ms, &thread_id).await? == Recorded::Duplicate {tracing::info!(channel = %params.channel,thread_id = %thread_id,@@ -77,6 +77,7 @@ pub async fn channel_relay_inbound("[channels::relay] relayed message accepted");crate::core::runtime::spawn_scoped(run_relay_turn(+ ctx.clone(),config,params,thread_id.clone(),@@ -97,6 +98,7 @@ pub async fn channel_relay_inbound(/// record the reply. `config` is the caller's: its tools, policy, model and/// workspace, never the process's channel runtime.pub(crate) async fn run_relay_turn(+ dispatch_ctx: crate::core::runtime::DispatchCtx,config: Config,params: RelayInboundParams,thread_id: String,@@ -132,7 +134,7 @@ pub(crate) async fn run_relay_turn(&crate::channels::SendMessage::new(reply, ¶ms.chat_id),).await;- record(&workspace_dir, ¶ms, &thread_id, &channel.sent()).await;+ record(&dispatch_ctx, &workspace_dir, ¶ms, &thread_id, &channel.sent()).await;return channel.sent();}};@@ -157,7 +159,7 @@ pub(crate) async fn run_relay_turn(&crate::channels::SendMessage::new(reply, ¶ms.chat_id),).await;- record(&workspace_dir, ¶ms, &thread_id, &channel.sent()).await;+ record(&dispatch_ctx, &workspace_dir, ¶ms, &thread_id, &channel.sent()).await;return channel.sent();}};@@ -196,6 +198,7 @@ pub(crate) async fn run_relay_turn(}};match store::prior_turns(+ &dispatch_ctx,&workspace_dir,&thread_id,¶ms.message_id,@@ -237,7 +240,7 @@ pub(crate) async fn run_relay_turn(}let replies = channel.sent();- record(&workspace_dir, ¶ms, &thread_id, &replies).await;+ record(&dispatch_ctx, &workspace_dir, ¶ms, &thread_id, &replies).await;// Idle again: deliver anything that finished while the turn ran. No// `AgentTurnCompleted` maps to this thread, so nothing else would.drop(busy);@@ -253,12 +256,13 @@ pub(crate) async fn run_relay_turn(}async fn record(+ ctx: &crate::core::runtime::DispatchCtx,workspace_dir: &std::path::Path,params: &RelayInboundParams,thread_id: &str,replies: &[String],) {- if let Err(error) = store::record_reply(workspace_dir, params, thread_id, replies).await {+ if let Err(error) = store::record_reply(ctx, workspace_dir, params, thread_id, replies).await {tracing::warn!(thread_id = %thread_id,%error,diff --git a/crates/openhuman-core/src/channels/providers/relay/store.rs b/crates/openhuman-core/src/channels/providers/relay/store.rsindex 01b46828f9..1dc0313803 100644--- a/crates/openhuman-core/src/channels/providers/relay/store.rs+++ b/crates/openhuman-core/src/channels/providers/relay/store.rs@@ -56,13 +56,14 @@ fn thread_lock(workspace_dir: &Path, thread_id: &str) -> Arc<tokio::sync::Mutex</// Create the thread if needed and append the inbound message, unless it is/// already there.pub async fn record_inbound(+ ctx: &DispatchCtx,workspace_dir: &Path,params: &RelayInboundParams,thread_id: &str,) -> Result<Recorded, String> {let now = Utc::now().to_rfc3339();conversations::ensure_thread(- DispatchCtx::ambient(),+ ctx.clone(),workspace_dir.to_path_buf(),CreateConversationThread {id: thread_id.to_string(),@@ -80,7 +81,7 @@ pub async fn record_inbound(let lock = thread_lock(workspace_dir, thread_id);let _guard = lock.lock().await;let existing = conversations::get_messages(- DispatchCtx::ambient(),+ ctx.clone(),workspace_dir.to_path_buf(),thread_id.to_string(),)@@ -89,7 +90,7 @@ pub async fn record_inbound(return Ok(Recorded::Duplicate);}conversations::append_message(- DispatchCtx::ambient(),+ ctx.clone(),workspace_dir.to_path_buf(),thread_id.to_string(),ConversationMessage {@@ -115,6 +116,7 @@ pub async fn record_inbound(/// Append the turn's reply: every text the relay sink sent, in order.pub async fn record_reply(+ ctx: &DispatchCtx,workspace_dir: &Path,params: &RelayInboundParams,thread_id: &str,@@ -124,7 +126,7 @@ pub async fn record_reply(return Ok(());}conversations::append_message(- DispatchCtx::ambient(),+ ctx.clone(),workspace_dir.to_path_buf(),thread_id.to_string(),ConversationMessage {@@ -149,6 +151,7 @@ pub async fn record_reply(/// The thread's earlier turns as the channel pipeline's per-chat history:/// user and assistant rows before `message_id`, the most recent `limit`.pub async fn prior_turns(+ ctx: &DispatchCtx,workspace_dir: &Path,thread_id: &str,message_id: &str,@@ -156,7 +159,7 @@ pub async fn prior_turns() -> Result<Vec<ChatMessage>, String> {let current = inbound_message_id(message_id);let messages = conversations::get_messages(- DispatchCtx::ambient(),+ ctx.clone(),workspace_dir.to_path_buf(),thread_id.to_string(),)