Skip to content

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

feat(channels): add capability query helpers

Steven Enamakelb1a4067cc8c5
diff --git a/crates/openhuman-core/src/channels/capabilities.rs b/crates/openhuman-core/src/channels/capabilities.rs
new file mode 100644
index 0000000000..87397c91e4
--- /dev/null
+++ b/crates/openhuman-core/src/channels/capabilities.rs
@@ -0,0 +1,39 @@
+//! Transitional per-provider capability table.
+//!
+//! TinyChannels removed its static `capabilities_for` table in favour of
+//! per-instance `ChannelCapabilities` described by the module. Until the host
+//! reads those descriptors, these four legacy flags keep their previous
+//! values, keyed by provider id.
+
+use tinychannels_bus::capabilities::provider_id;
+
+/// The four pre-v2 interaction flags the host still branches on.
+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
+pub(crate) struct HostChannelCapabilities {
+ pub remote_control: bool,
+ pub chat_approvals: bool,
+ pub history_key_ignores_thread: bool,
+}
+
+const CHAT: HostChannelCapabilities = HostChannelCapabilities {
+ remote_control: true,
+ chat_approvals: true,
+ history_key_ignores_thread: false,
+};
+
+/// Capabilities of the provider behind `channel` (`"tg:1"` resolves to telegram).
+pub(crate) fn capabilities_for(channel: &str) -> HostChannelCapabilities {
+ match provider_id(channel) {
+ "telegram" => HostChannelCapabilities {
+ history_key_ignores_thread: true,
+ ..CHAT
+ },
+ "discord" | "slack" | "mattermost" | "imessage" | "signal" | "whatsapp"
+ | "whatsapp_web" | "irc" | "dingtalk" | "qq" | "lark" | "linq" | "yuanbao" => CHAT,
+ _ => HostChannelCapabilities::default(),
+ }
+}
+
+#[cfg(test)]
+#[path = "capabilities_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/channels/capabilities_tests.rs b/crates/openhuman-core/src/channels/capabilities_tests.rs
new file mode 100644
index 0000000000..c6828ffb09
--- /dev/null
+++ b/crates/openhuman-core/src/channels/capabilities_tests.rs
@@ -0,0 +1,23 @@
+use super::*;
+
+#[test]
+fn telegram_alias_ignores_thread_in_history_key() {
+ assert!(capabilities_for("tg:123").history_key_ignores_thread);
+ assert!(capabilities_for("telegram").chat_approvals);
+}
+
+#[test]
+fn chat_providers_support_approvals_and_remote_control() {
+ for provider in ["discord", "slack", "signal", "whatsapp_web", "yuanbao"] {
+ let caps = capabilities_for(provider);
+ assert!(caps.chat_approvals && caps.remote_control, "{provider}");
+ assert!(!caps.history_key_ignores_thread, "{provider}");
+ }
+}
+
+#[test]
+fn unknown_and_oneway_providers_have_no_capabilities() {
+ for provider in ["email", "webhook", "cli", "brand-new"] {
+ assert_eq!(capabilities_for(provider), HostChannelCapabilities::default());
+ }
+}