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): resolve channel capabilities from live registry
Steven Enamakel2a644a944f86
diff --git a/crates/openhuman-core/src/channels/bus/delivery.rs b/crates/openhuman-core/src/channels/bus/delivery.rsindex f547d05ca7..55391d012a 100644--- a/crates/openhuman-core/src/channels/bus/delivery.rs+++ b/crates/openhuman-core/src/channels/bus/delivery.rs@@ -12,10 +12,12 @@ use tinychannels_bus::{methods, ChannelBackendRequest, ChannelBackendResult};fn request_channel(request: &ProgressiveTransportRequest) -> &str {match request {- ProgressiveTransportRequest::Send { channel, .. }+ ProgressiveTransportRequest::OutputEvent { channel, .. }+ | ProgressiveTransportRequest::Send { channel, .. }+ | ProgressiveTransportRequest::SendTyped { channel, .. }| ProgressiveTransportRequest::Edit { channel, .. }| ProgressiveTransportRequest::Delete { channel, .. }- | ProgressiveTransportRequest::Typing { channel } => channel,+ | ProgressiveTransportRequest::Typing { channel, .. } => channel,}}diff --git a/crates/openhuman-core/src/channels/host/channel_events.rs b/crates/openhuman-core/src/channels/host/channel_events.rsindex cd9b7ea42e..44436b5c23 100644--- a/crates/openhuman-core/src/channels/host/channel_events.rs+++ b/crates/openhuman-core/src/channels/host/channel_events.rs@@ -7,7 +7,7 @@ use std::path::PathBuf;use std::sync::{Arc, Mutex};use tinybus::module::ModuleClient;use tinybus::EventHandler;-use tinychannels_bus::{capabilities_for, ChannelMessage};+use tinychannels_bus::ChannelMessage;#[derive(Clone)]struct ReplyContext {@@ -74,7 +74,11 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {inbound_envelope,workspace_dir,} => {- if !capabilities_for(channel).chat_approvals {+ if !self+ .channels+ .get(channel)+ .is_some_and(|channel| channel.capabilities().chat_approvals)+ {return;}if self@@ -99,6 +103,8 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {timestamp: 0,thread_ts: thread_ts.clone(),sender_name: None,+ reply_to_id: None,+ topic_id: None,},envelope: inbound_envelope.clone(),},@@ -125,7 +131,11 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {client_id: Some(channel_name),..} => {- if !capabilities_for(channel_name).chat_approvals {+ if !self+ .channels+ .get(channel_name)+ .is_some_and(|channel| channel.capabilities().chat_approvals)+ {return;}let reply = self@@ -178,13 +188,18 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {/// Projects host turn lifecycle facts into module-owned remote status storage.pub struct ChannelTurnStateSubscriber {workspace_dir: PathBuf,+ channels: Arc<HashMap<String, Arc<dyn Channel>>>,config: Option<Arc<crate::config::Config>>,cancellation: tokio_util::sync::CancellationToken,}impl ChannelTurnStateSubscriber {- pub fn with_config(config: Arc<crate::config::Config>) -> Self {+ pub fn with_config(+ config: Arc<crate::config::Config>,+ channels: Arc<HashMap<String, Arc<dyn Channel>>>,+ ) -> Self {Self {workspace_dir: config.workspace_dir.clone(),+ channels,config: Some(config),cancellation: super::super::runtime::session::channel_session(),}@@ -193,13 +208,17 @@ impl ChannelTurnStateSubscriber {pub fn new(workspace_dir: PathBuf) -> Self {Self {workspace_dir,+ channels: Arc::new(HashMap::new()),config: None,cancellation: tokio_util::sync::CancellationToken::new(),}}async fn mark(&self, channel: &str, reply_target: &str, event_ws: &PathBuf, busy: bool) {if self.cancellation.is_cancelled()- || !capabilities_for(channel).remote_control+ || !self+ .channels+ .get(channel)+ .is_some_and(|channel| channel.capabilities().remote_control)|| *event_ws != self.workspace_dir{return;diff --git a/crates/openhuman-core/src/channels/host/channel_events_tests.rs b/crates/openhuman-core/src/channels/host/channel_events_tests.rsindex 2c3608637e..94c14a2e0c 100644--- a/crates/openhuman-core/src/channels/host/channel_events_tests.rs+++ b/crates/openhuman-core/src/channels/host/channel_events_tests.rs@@ -24,6 +24,12 @@ impl Channel for RecordingChannel {async fn listen(&self, _tx: tokio::sync::mpsc::Sender<ChannelMessage>) -> anyhow::Result<()> {Ok(())}+ fn supports_chat_approvals(&self) -> bool {+ matches!(self.name.as_str(), "telegram" | "discord" | "slack")+ }+ fn supports_remote_control(&self) -> bool {+ matches!(self.name.as_str(), "telegram" | "discord")+ }}fn recording(name: &str) -> Arc<RecordingChannel> {@@ -41,6 +47,20 @@ fn approval_subscriber(channels: &[Arc<RecordingChannel>]) -> ChannelApprovalSurChannelApprovalSurfaceSubscriber::new(Arc::new(map))}+#[cfg(feature = "e2e-test-support")]+fn turn_state_subscriber(workspace_dir: PathBuf, names: &[&str]) -> ChannelTurnStateSubscriber {+ let channels: HashMap<String, Arc<dyn Channel>> = names+ .iter()+ .map(|name| {+ let channel = recording(name);+ ((*name).to_owned(), channel as Arc<dyn Channel>)+ })+ .collect();+ let mut subscriber = ChannelTurnStateSubscriber::new(workspace_dir);+ subscriber.channels = Arc::new(channels);+ subscriber+}+fn received(channel: &str, reply_target: &str, thread_ts: Option<&str>, ws: &Path) -> DomainEvent {DomainEvent::ChannelMessageReceived {channel: channel.into(),@@ -175,7 +195,7 @@ async fn turn_state_marks_busy_for_every_remote_control_channel() {let _storage = crate::channels::module_fixture::install_memory_storage();let dir = tempdir().unwrap();let ws = dir.path().to_path_buf();- let sub = ChannelTurnStateSubscriber::new(ws.clone());+ let sub = turn_state_subscriber(ws.clone(), &["telegram", "discord"]);assert_eq!(sub.name(), "channels::turn_state");assert_eq!(sub.domains(), Some(&["channel"][..]));for channel in ["telegram", "discord"] {@@ -199,7 +219,7 @@ async fn turn_state_ignores_non_remote_channels_and_stale_workspaces() {let _storage = crate::channels::module_fixture::install_memory_storage();let dir = tempdir().unwrap();let ws = dir.path().to_path_buf();- let sub = ChannelTurnStateSubscriber::new(ws.clone());+ let sub = turn_state_subscriber(ws.clone(), &["telegram"]);let other = tempdir().unwrap().path().to_path_buf();sub.handle(&received("email", "[email protected]", None, &ws)).await;assert!(remote_status(&ws, "email", "[email protected]").await.is_none());diff --git a/crates/openhuman-core/src/channels/providers/relay/params.rs b/crates/openhuman-core/src/channels/providers/relay/params.rsindex f4d1112ddc..4ea16ce77c 100644--- a/crates/openhuman-core/src/channels/providers/relay/params.rs+++ b/crates/openhuman-core/src/channels/providers/relay/params.rs@@ -152,6 +152,8 @@ impl RelayInboundParams {.sender_name.clone().filter(|name| !name.trim().is_empty()),+ reply_to_id: None,+ topic_id: None,}}}diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rsindex d7d51fda4b..0a5ccf41a8 100644--- a/crates/openhuman-core/src/channels/routes.rs+++ b/crates/openhuman-core/src/channels/routes.rs@@ -176,6 +176,7 @@ pub(crate) async fn handle_runtime_command_if_needed((ChannelControlRequest::Route {workspace_dir: ctx.workspace_dir.to_string_lossy().into_owned(),message: Box::new(msg.clone()),+ capabilities: target_channel.map(|channel| Box::new(channel.capabilities())),route: tinychannels_bus::module_remote::RemoteRoute {provider: current.provider,model: current.model,diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rsindex 3ebb6074da..5807d7df71 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rs@@ -1,4 +1,28 @@use super::channel_has_approval_surface;+use tinychannels_bus::{Channel, ChannelMessage, SendMessage};++struct ConfiguredChannel {+ approvals: bool,+}++#[async_trait::async_trait]+impl Channel for ConfiguredChannel {+ fn name(&self) -> &str {+ "configured"+ }++ async fn send(&self, _message: &SendMessage) -> anyhow::Result<()> {+ Ok(())+ }++ async fn listen(&self, _tx: tokio::sync::mpsc::Sender<ChannelMessage>) -> anyhow::Result<()> {+ Ok(())+ }++ fn supports_chat_approvals(&self) -> bool {+ self.approvals+ }+}// Sub-issue 2 of #3098: this gate is what decides whether the dispatch// loop sets an `ApprovalChatContext` (→ gate fires for `Prompt`-class@@ -8,31 +32,10 @@ use super::channel_has_approval_surface;// path must not be scoped, or every parked call would TTL-deny.#[test]-fn chat_channels_have_an_approval_surface() {- for channel in [- "telegram",- "discord",- "slack",- "imessage",- "mattermost",- "signal",- "whatsapp",- "irc",- ] {- assert!(channel_has_approval_surface(channel), "{channel}");- }-}--#[test]-fn channels_without_a_reply_path_do_not_have_an_approval_surface() {- for channel in ["email", "cli", "webhook", "web"] {- assert!(!channel_has_approval_surface(channel), "{channel}");- }-}--#[test]-fn unknown_channel_does_not_have_approval_surface() {- assert!(!channel_has_approval_surface(""));- assert!(!channel_has_approval_surface("Telegram")); // case-sensitive on purpose- assert!(!channel_has_approval_surface("telegram-bot"));+fn configured_channel_capability_controls_approval_surface() {+ let supports_approval = ConfiguredChannel { approvals: true };+ let no_approval = ConfiguredChannel { approvals: false };+ assert!(channel_has_approval_surface(Some(&supports_approval)));+ assert!(!channel_has_approval_surface(Some(&no_approval)));+ assert!(!channel_has_approval_surface(None));}diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rsindex a657bfc7eb..b9396b2b14 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rs@@ -100,7 +100,7 @@ pub(crate) async fn admit_runtime_message(// A yes/no reply to an approval parked on this conversation decides it;// a fresh turn would cancel the parked tool call.- if channel_has_approval_surface(&msg.channel)+ if channel_has_approval_surface(target_channel.as_deref())&& try_route_approval_reply(&msg, &history_key).await{return None;diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rsindex a5216c9832..e760c1577e 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs@@ -16,8 +16,8 @@ use tinychannels_bus as traits;////// [`ApprovalChatContext`]: crate::security::approval::ApprovalChatContext/// [`ApprovalGate`]: crate::security::approval::ApprovalGate-pub(crate) fn channel_has_approval_surface(channel: &str) -> bool {- tinychannels_bus::capabilities_for(channel).chat_approvals+pub(crate) fn channel_has_approval_surface(channel: Option<&dyn crate::channels::Channel>) -> bool {+ channel.is_some_and(|channel| channel.capabilities().chat_approvals)}/// If the inbound message is a yes/no reply for a parked approval ondiff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rsindex 74c597c27a..6bc11f0fa8 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs@@ -347,7 +347,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:// "no chat context -> allow straight through" branch silently bypasses// every `Prompt`-class tool call, voiding the `supervised` autonomy tier// on the channel.- let approval = if channel_has_approval_surface(&msg.channel) {+ let approval = if channel_has_approval_surface(target_channel.as_deref()) {crate::security::approval::ApprovalTurnContext::chat(crate::security::approval::ApprovalChatContext {thread_id: history_key.clone(),diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rsindex c8061aa6a6..b284dd90f7 100644--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs@@ -34,7 +34,7 @@ pub(super) struct ModuleChannelRuntime {struct ModuleChannel {name: String,object: ModuleObjectClient,- interaction: tinychannels_bus::ChannelInteractionInfo,+ interaction: tinychannels_bus::ChannelInteractionInfoV2,relay: Option<tinychannels_bus::module_relay::RelayReservation>,relay_fronted: bool,}@@ -302,7 +302,11 @@ impl Channel for ModuleChannel {}fn proactive_target(&self) -> Option<String> {- self.interaction.proactive_target.clone()+ self.interaction+ .capabilities+ .account+ .proactive_target+ .clone()}async fn send(&self, message: &SendMessage) -> anyhow::Result<()> {@@ -378,15 +382,15 @@ impl Channel for ModuleChannel {}fn capabilities(&self) -> tinychannels_bus::ChannelCapabilities {- self.interaction.capabilities+ self.interaction.capabilities.clone()}fn supports_reactions(&self) -> bool {- self.interaction.supports_reactions+ self.interaction.capabilities.reactions}fn supports_draft_updates(&self) -> bool {- self.interaction.supports_draft_updates+ self.interaction.capabilities.streaming_reply_pipeline}async fn send_draft(&self, message: &SendMessage) -> anyhow::Result<Option<String>> {diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rsindex 4bd704df8c..517e56c136 100644--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs@@ -240,7 +240,10 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) ->// Remote-control turn state (`/status` shows "in progress") for every// channel with the `remote_control` capability.let _turn_state_handle = bus.subscribe(Arc::new(- crate::channels::host::ChannelTurnStateSubscriber::with_config(Arc::new(config.clone())),+ crate::channels::host::ChannelTurnStateSubscriber::with_config(+ Arc::new(config.clone()),+ Arc::clone(&channels_by_name),+ ),));// In-chat approvals (sub-issue 2 of #3098) for every channel with the// `chat_approvals` capability: `Prompt`-class tool calls are gated for thediff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rsindex 536d906ef8..60c78488dd 100644--- a/crates/openhuman-core/src/channels/runtime/test_support.rs+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs@@ -446,6 +446,8 @@ pub async fn run_dispatch_harness(options: DispatchHarnessOptions) -> DispatchHatimestamp: 1,thread_ts: options.thread_ts,sender_name: None,+ reply_to_id: None,+ topic_id: None,};if let Some(inbound_envelope) = options.inbound_envelope {process_channel_runtime_message(diff --git a/crates/openhuman-core/src/storage/schema.rs b/crates/openhuman-core/src/storage/schema.rsindex 50d4b0ea71..d886b80bf3 100644--- a/crates/openhuman-core/src/storage/schema.rs+++ b/crates/openhuman-core/src/storage/schema.rs@@ -17,7 +17,8 @@use std::sync::OnceLock;-use tinystoragedrivers::schema::{Item, Registry, Schema, ScopeClass};+use tinystoragedrivers::schema::{Item, Owner, Registry, Schema, ScopeClass};+use tinystoragedrivers::{CollectionSpec, IndexSpec};/// Every owner's schema that this build links.pub fn owner_schemas() -> Vec<Schema> {@@ -45,8 +46,50 @@ pub fn owner_schemas() -> Vec<Schema> {schemas.push(tinyskills_drivers::storage_schema());#[cfg(feature = "modules")]{- schemas.push(tinymcp_bus::storage::storage_schema());- schemas.push(tinychannels_bus::storage::storage_schema());+ // TinyMCP and TinyChannels v22 expose pure collection declarations;+ // their migration plans now live in the modules. Compose those specs+ // here only to provision storage and derive module grants.+ schemas.push(+ module_collection_schema(+ tinymcp_bus::storage::OWNER,+ tinymcp_bus::storage::SCHEMA_VERSION,+ tinymcp_bus::storage::collection_specs()+ .into_iter()+ .filter(|spec| !spec.name.starts_with("tsd."))+ .map(|spec| {+ let mut converted = CollectionSpec::new(spec.name);+ for index in spec.indexes {+ let unique = index.unique;+ let index = IndexSpec::new(index.name, index.fields);+ converted =+ converted.index(if unique { index.unique() } else { index });+ }+ if let Some(ttl_field) = spec.ttl_field {+ converted = converted.ttl(ttl_field);+ }+ if let Some(search) = spec.search {+ converted = converted.searchable(search.fields);+ }+ converted+ })+ .collect(),+ )+ .stream(tinymcp_bus::storage::AUDIT_STREAM, ScopeClass::Module),+ );+ schemas.push(+ module_collection_schema(+ "channels",+ tinychannels_bus::storage::schema::SCHEMA_VERSION,+ tinychannels_bus::storage::collections()+ .into_iter()+ .map(|spec| CollectionSpec::new(spec.name))+ .collect(),+ )+ .blobs(+ tinychannels_bus::storage::MEDIA_BLOB_PREFIX,+ ScopeClass::Module,+ ),+ );schemas.push(tinyconnectors_bus::storage::storage_schema());schemas.push(tinybox_bus::storage::storage_schema());schemas.push(tinyjuice_bus::storage::storage_schema());@@ -63,6 +106,22 @@ pub fn owner_schemas() -> Vec<Schema> {schemas}+/// Compose a module's current collection specs without taking ownership of its+/// migration plan. The module runs its own migrations through its storage port.+fn module_collection_schema(+ owner_name: &str,+ version: u32,+ collections: Vec<CollectionSpec>,+) -> Schema {+ let owner = Owner::new(owner_name)+ .unwrap_or_else(|_| unreachable!("module owner names are contract constants"));+ collections+ .into_iter()+ .fold(Schema::new(owner), |schema, spec| {+ schema.collection_with(version, spec, ScopeClass::Module)+ })+}+/// The registry composed from [`owner_schemas`].////// # Errorsdiff --git a/crates/openhuman-core/src/storage/schema_tests.rs b/crates/openhuman-core/src/storage/schema_tests.rsindex 0389689caa..ed16bb215d 100644--- a/crates/openhuman-core/src/storage/schema_tests.rs+++ b/crates/openhuman-core/src/storage/schema_tests.rs@@ -33,5 +33,18 @@ fn module_items_are_the_owners_module_scoped_declarations() {.iter().any(|spec| spec.name == "mcp.servers"));assert!(mcp.streams.iter().any(|name| name == "mcp.audit"));+ assert!(!mcp+ .collections+ .iter()+ .any(|spec| spec.name.starts_with("tsd.")));+ let channels = module_items("channels");+ assert!(channels+ .collections+ .iter()+ .any(|spec| spec.name == tinychannels_bus::storage::MEDIA_METADATA));+ assert!(channels+ .blobs+ .iter()+ .any(|prefix| prefix == tinychannels_bus::storage::MEDIA_BLOB_PREFIX));assert!(module_items("no-such-owner").collections.is_empty());}diff --git a/crates/openhuman-core/src/threads/store/bus.rs b/crates/openhuman-core/src/threads/store/bus.rsindex 8038030836..1a793edefe 100644--- a/crates/openhuman-core/src/threads/store/bus.rs+++ b/crates/openhuman-core/src/threads/store/bus.rs@@ -384,6 +384,8 @@ async fn persist_channel_turn(timestamp: 0,thread_ts: descriptor.thread_ts.map(ToOwned::to_owned),sender_name: None,+ reply_to_id: None,+ topic_id: None,},envelope: descriptor.inbound_envelope.cloned(),},@@ -393,12 +395,14 @@ async fn persist_channel_turn(.await.map_err(|error| error.to_string())?;let thread_id = format!("channel:{}", prepared.history_key);+ let history_key_ignores_thread = prepared.history_key_ignores_thread;let session_key = descriptor.inbound_envelope.map(|_| prepared.session_key);let title = channel_thread_title(descriptor.channel,descriptor.sender,descriptor.reply_target,descriptor.thread_ts,+ history_key_ignores_thread,);let created_at = Utc::now().to_rfc3339();@@ -485,6 +489,8 @@ fn persisted_channel_thread_id(timestamp: 0,thread_ts: thread_ts.map(ToOwned::to_owned),sender_name: None,+ reply_to_id: None,+ topic_id: None,});format!("channel:{key}")}@@ -494,13 +500,12 @@ fn channel_thread_title(sender: &str,reply_target: &str,thread_ts: Option<&str>,+ history_key_ignores_thread: bool,) -> String {match thread_ts.and_then(non_empty_trimmed) {// Providers whose thread_ts is only a reply target (Telegram topics)// share one conversation, so the title leaves it out too.- Some(thread_ts)- if !tinychannels_bus::capabilities_for(channel).history_key_ignores_thread =>- {+ Some(thread_ts) if !history_key_ignores_thread => {format!("{channel} · {sender} · {reply_target} · thread {thread_ts}")}_ => format!("{channel} · {sender} · {reply_target}"),diff --git a/crates/openhuman-core/src/threads/store/bus_tests.rs b/crates/openhuman-core/src/threads/store/bus_tests.rsindex 49f3542930..2900cad798 100644--- a/crates/openhuman-core/src/threads/store/bus_tests.rs+++ b/crates/openhuman-core/src/threads/store/bus_tests.rs@@ -169,11 +169,11 @@ fn persisted_channel_thread_id_ignores_blank_thread_ts() {#[test]fn channel_thread_title_uses_thread_suffix_only_for_non_telegram_threads() {assert_eq!(- channel_thread_title("slack", "alice", "general", Some(" 123 ")),+ channel_thread_title("slack", "alice", "general", Some(" 123 "), false),"slack · alice · general · thread 123");assert_eq!(- channel_thread_title("telegram", "alice", "chat-1", Some("123")),+ channel_thread_title("telegram", "alice", "chat-1", Some("123"), true),"telegram · alice · chat-1");}