Skip to content

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

refactor(channels): replace Telegram-specific approval and remote-control with generic capability-ba

Steven Enamakel43f0e16db222
diff --git a/crates/openhuman-core/src/channels/providers/mod.rs b/crates/openhuman-core/src/channels/providers/mod.rs
index 048044b07f..cfa885c751 100644
--- a/crates/openhuman-core/src/channels/providers/mod.rs
+++ b/crates/openhuman-core/src/channels/providers/mod.rs
@@ -1,13 +1,13 @@
-//! OpenHuman channel glue plus portable provider exports.
+//! Portable provider exports.
//!
-//! Provider transports belong to `tinychannels`; only Telegram's OpenHuman
-//! event-bus, approval, and remote-control integration remains local.
+//! Provider transports, and the provider-independent remote control and
+//! in-chat approvals that used to be Telegram glue, belong to `tinychannels`.
pub use tinychannels::providers::email_channel;
pub use tinychannels::providers::lark;
pub use tinychannels::providers::{
- dingtalk, discord, imessage, irc, linq, mattermost, qq, signal, slack, whatsapp, yuanbao,
+ dingtalk, discord, imessage, irc, linq, mattermost, qq, signal, slack, telegram, whatsapp,
+ yuanbao,
};
-pub mod telegram;
#[cfg(feature = "whatsapp-web")]
pub use tinychannels::providers::whatsapp_web;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs
index f51fca37d5..c429d138eb 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs
@@ -1,28 +1,24 @@
-//! Gating and intercepting approval-gate replies on channels that have a
-//! registered approval surface.
+//! Gating and intercepting approval-gate replies on channels that surface
+//! approvals in chat.
use crate::channels::context::conversation_history_key;
-use crate::channels::providers::telegram::TELEGRAM_APPROVAL_CLIENT_ID;
use crate::channels::traits;
-/// Whether a channel currently has a registered approval surface — i.e.
-/// a subscriber that turns `ApprovalRequested` events into chat messages
-/// and a way for the user's reply to flow back into the
-/// [`ApprovalGate`]. When `true`, the dispatch loop scopes the agent
-/// turn in an [`ApprovalChatContext`] so the gate actually fires for
-/// `Prompt`-class tools and intercepts yes/no replies for parked
-/// approvals.
+/// Whether a channel surfaces approvals in chat: the
+/// `ChannelApprovalSurfaceSubscriber` turns `ApprovalRequested` events into
+/// chat messages and the user's reply flows back into the [`ApprovalGate`].
+/// When `true`, the dispatch loop scopes the agent turn in an
+/// [`ApprovalChatContext`] so the gate actually fires for `Prompt`-class tools,
+/// and intercepts yes/no replies for parked approvals.
///
-/// Only Telegram has a surface today (sub-issue 2 of #3098). Discord /
-/// Slack / iMessage / Mattermost remain in the legacy "no chat context
-/// → silently allow" state until each gets a per-channel surface in a
-/// follow-up PR; surfacing approvals there without a subscriber would
-/// just TTL-deny every parked call, which is worse than the status quo.
+/// Driven by the provider's `chat_approvals` capability. Channels without it
+/// (email, CLI, webhooks) keep the "no chat context → allow" behaviour, since
+/// a prompt there would only TTL-deny every parked call.
///
/// [`ApprovalChatContext`]: crate::security::approval::ApprovalChatContext
/// [`ApprovalGate`]: crate::security::approval::ApprovalGate
pub(crate) fn channel_has_approval_surface(channel: &str) -> bool {
- channel == TELEGRAM_APPROVAL_CLIENT_ID
+ tinychannels::capabilities_for(channel).chat_approvals
}
/// If the inbound message is a yes/no reply for a parked approval on
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index b9a427283d..f0892fb29f 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -435,13 +435,11 @@ pub(crate) async fn process_channel_runtime_message(
})
};
// Sub-issue 2 of #3098: scope the agent turn in an `ApprovalChatContext`
- // for channels that have a registered approval surface — currently
- // Telegram only via `TelegramApprovalSurfaceSubscriber`. Without this
- // scope the gate's "no chat context → allow straight through" branch
+ // for every channel with the `chat_approvals` capability (served by
+ // `ChannelApprovalSurfaceSubscriber`). Without this scope the gate's
+ // "no chat context → allow straight through" branch
// (`approval/gate.rs:219-231`) silently bypasses every `Prompt`-class
// tool call, voiding the `supervised` autonomy tier on the channel.
- // Discord / Slack / iMessage / Mattermost stay in the legacy bypass
- // until each gets its own approval surface in a follow-up PR.
let llm_result = tokio::time::timeout(Duration::from_secs(ctx.message_timeout_secs), async {
if channel_has_approval_surface(&msg.channel) {
let approval_ctx = crate::security::approval::ApprovalChatContext {
diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
index f30308cfee..a007f5c057 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
@@ -464,34 +464,20 @@ async fn start_channels_inner(mut config: Config) -> Result<()> {
proactive_sub.active_channel_handle(),
);
let _proactive_handle = bus.subscribe(Arc::new(proactive_sub));
- let _telegram_remote_handle = if channels_by_name.contains_key("telegram") {
- let handle = bus.subscribe(Arc::new(
- crate::channels::providers::telegram::TelegramRemoteSubscriber::new(
- config.workspace_dir.clone(),
- ),
- ));
- tracing::debug!("[telegram-remote] registered TelegramRemoteSubscriber");
- Some(handle)
- } else {
- None
- };
- // Sub-issue 2 of #3098: when Telegram is enabled, register the
- // approval-surface subscriber so `Prompt`-class tool calls actually
- // get gated for the user instead of silently allowed (the legacy
- // behavior when `ApprovalChatContext` is unset). The dispatch loop
- // pairs this by scoping each Telegram turn in an `ApprovalChatContext`
- // and intercepting `yes`/`no` replies for parked approvals.
- let _telegram_approval_surface_handle = if channels_by_name.contains_key("telegram") {
- let handle = bus.subscribe(Arc::new(
- crate::channels::providers::telegram::TelegramApprovalSurfaceSubscriber::new(
- Arc::clone(&channels_by_name),
- ),
- ));
- tracing::debug!("[telegram-approval] registered TelegramApprovalSurfaceSubscriber");
- Some(handle)
- } else {
- None
- };
+ // 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::new(config.workspace_dir.clone()),
+ ));
+ // In-chat approvals (sub-issue 2 of #3098) for every channel with the
+ // `chat_approvals` capability: `Prompt`-class tool calls are gated for the
+ // user instead of silently allowed. The dispatch loop pairs this by scoping
+ // each such turn in an `ApprovalChatContext` and intercepting `yes`/`no`
+ // replies for parked approvals.
+ let _approval_surface_handle = bus.subscribe(Arc::new(
+ crate::channels::host::ChannelApprovalSurfaceSubscriber::new(Arc::clone(&channels_by_name)),
+ ));
+ tracing::debug!("[channels] registered turn-state and approval-surface subscribers");
// Register the tree summarizer event subscriber for observability logging.
let _tree_summarizer_handle = bus.subscribe(Arc::new(
crate::memory::tree::tree_runtime::bus::TreeSummarizerEventSubscriber::new(),