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(channels): add remote reset context support
Steven Enamakel9cd760b949ec
diff --git a/crates/openhuman-core/src/channels/host/remote_control.rs b/crates/openhuman-core/src/channels/host/remote_control.rsindex 6b433b3aa5..7faa519a4a 100644--- a/crates/openhuman-core/src/channels/host/remote_control.rs+++ b/crates/openhuman-core/src/channels/host/remote_control.rs@@ -1,8 +1,15 @@//! Captured host conversation and session state supplied to the channel module.-use crate::channels::context::{clear_sender_history, ChannelRuntimeContext};+use crate::channels::context::ChannelRuntimeContext;use crate::core::runtime::DispatchCtx;use crate::threads::store::{self as conversations, CreateConversationThread};+use crate::channels::Channel;++pub(crate) struct RemoteResetContext {+ pub(crate) scope: tinychannels_bus::module_remote::RemoteSessionScope,+ pub(crate) message: tinychannels_bus::ChannelMessage,+ pub(crate) history_key: String,+}/// Serves product-owned conversation state to the captured module runtime.pub(crate) async fn dispatch_callback(@@ -10,6 +17,7 @@ pub(crate) async fn dispatch_callback(ctx: &ChannelRuntimeContext,tenant: &crate::core::runtime::Tenant,cancellation: &tokio_util::sync::CancellationToken,+ reset_context: Option<&RemoteResetContext>,request: tinychannels_bus::module_remote::RemoteHostRequest,) -> tinybus::Result<tinychannels_bus::module_remote::RemoteHostResult> {use tinychannels_bus::module_remote::{@@ -56,11 +64,50 @@ pub(crate) async fn dispatch_callback(.map_err(|_| tinybus::Error::failed("conversation state unavailable"))?;Ok(Response::Completed)}- Request::ClearHistory { sender_key } => {+ Request::ClearHistory { session_scope } => {+ if cancellation.is_cancelled() {+ return Err(tinybus::Error::failed("channel session ended"));+ }+ let Some(reset) = reset_context else {+ return Err(tinybus::Error::failed(+ "remote reset has no captured ingress scope",+ ));+ };+ if session_scope != reset.scope+ || session_scope.session_key.trim().is_empty()+ || session_scope.conversation.id.trim().is_empty()+ {+ return Err(tinybus::Error::failed(+ "remote reset scope does not match captured ingress",+ ));+ }+ let account = session_scope+ .channel+ .account_id+ .as_deref()+ .ok_or_else(|| tinybus::Error::failed("remote reset account is unavailable"))?;+ let configured = ctx+ .channels_by_name+ .get(account)+ .is_some_and(|channel| {+ tinychannels_bus::provider_id(channel.name()) == session_scope.channel.id+ });+ if !configured {+ return Err(tinybus::Error::failed(+ "remote reset account is not configured",+ ));+ }+ crate::channels::runtime::dispatch::reset_durable_channel_session(+ ctx,+ &reset.message,+ &reset.scope.session_key,+ &reset.history_key,+ )+ .await+ .map_err(|_| tinybus::Error::failed("durable conversation reset failed"))?;if cancellation.is_cancelled() {return Err(tinybus::Error::failed("channel session ended"));}- clear_sender_history(&ctx.conversation_histories, &sender_key);Ok(Response::Completed)}Request::InvalidateThread { thread_id } => {diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rsindex 1c8ec97ca5..f27694fafd 100644--- a/crates/openhuman-core/src/channels/routes.rs+++ b/crates/openhuman-core/src/channels/routes.rs@@ -83,12 +83,14 @@ struct RouteCallbacks {core_context: Option<Arc<crate::core::runtime::CoreContext>>,tenant: crate::core::runtime::Tenant,cancellation: tokio_util::sync::CancellationToken,+ reset_context: Option<crate::channels::host::remote_control::RemoteResetContext>,}impl RouteCallbacks {fn new(context: ChannelRuntimeContext,cancellation: tokio_util::sync::CancellationToken,+ reset_context: Option<crate::channels::host::remote_control::RemoteResetContext>,) -> Self {let ctx = context.dispatch_ctx();Self {@@ -99,6 +101,7 @@ impl RouteCallbacks {),context,cancellation,+ reset_context,}}}@@ -128,6 +131,7 @@ impl RouteCallbacks {&self.context,&self.tenant,&self.cancellation,+ self.reset_context.as_ref(),request,) => result.map(tinychannels_bus::ChannelBackendResult::RemoteControl),}@@ -150,6 +154,8 @@ pub(crate) async fn handle_runtime_command_with_reset<F, Fut>(msg: &traits::ChannelMessage,target_channel: Option<&Arc<dyn Channel>>,sender_key: &str,+ reset_scope: Option<tinychannels_bus::module_remote::RemoteSessionScope>,+ reset_message: &traits::ChannelMessage,reset_history: F,) -> boolwhere@@ -173,7 +179,17 @@ wherelet operation = async {let lease = crate::modules::channel_runtime::ChannelRuntimeLease::open(client,- RouteCallbacks::new(ctx.clone(), super::runtime::session::channel_session()),+ RouteCallbacks::new(+ ctx.clone(),+ super::runtime::session::channel_session(),+ reset_scope.clone().map(|scope| {+ crate::channels::host::remote_control::RemoteResetContext {+ scope,+ message: reset_message.clone(),+ history_key: sender_key.to_owned(),+ }+ }),+ ),).await?;let response: Result<ChannelControlResult, _> = lease@@ -188,6 +204,7 @@ wheremodel: current.model,},history_len,+ session_scope: reset_scope,providers: provider_descriptors(),},),)@@ -271,7 +288,7 @@ pub(crate) async fn handle_runtime_command_if_needed(target_channel: Option<&Arc<dyn Channel>>,sender_key: &str,) -> bool {- handle_runtime_command_with_reset(ctx, msg, target_channel, sender_key, || async {+ handle_runtime_command_with_reset(ctx, msg, target_channel, sender_key, None, msg, || async {clear_sender_history(&ctx.conversation_histories, sender_key);Ok(())})