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
fix(controllers): remove unused ops module and its submodules
Steven Enamakel61ed49411d76
diff --git a/crates/openhuman-core/src/channels/controllers/backend.rs b/crates/openhuman-core/src/channels/controllers/backend.rsindex ce26ae3ae9..a28ac0e99d 100644--- a/crates/openhuman-core/src/channels/controllers/backend.rs+++ b/crates/openhuman-core/src/channels/controllers/backend.rs@@ -39,6 +39,18 @@ impl OpenHumanChannelBackend {}}+/// The managed-bot link flows need a TinyHumans account, so the core does not+/// serve them: `openhuman-tinyhumans` registers `channels.telegram_login_*` /+/// `channels.discord_link_*` itself (`hosted::channel_link`). The contract+/// still requires these methods; nothing in the core dispatches them.+fn hosted_link_unavailable<T>(method: &str) -> anyhow::Result<T> {+ log::debug!("[channels][backend] {method} is served by openhuman-tinyhumans, not the core");+ anyhow::bail!(+ "{}channels.{method} is provided by the hosted TinyHumans layer",+ crate::core::observability::BACKEND_UNAVAILABLE_PREFIX+ )+}+fn into_anyhow<T>(result: Result<RpcOutcome<T>, String>) -> anyhow::Result<T> {result.map(|outcome| outcome.value)@@ -311,36 +323,32 @@ impl ChannelBackend for OpenHumanChannelBackend {async fn telegram_login_start(&self,- channels_config: &ChannelsConfig,+ _channels_config: &ChannelsConfig,) -> anyhow::Result<TelegramLoginStartResult> {- let config = self.config_with_channels(channels_config);- into_anyhow(ops::telegram_login_start(&config).await)+ hosted_link_unavailable("telegram_login_start")}async fn telegram_login_check(&self,- channels_config: &ChannelsConfig,- link_token: &str,+ _channels_config: &ChannelsConfig,+ _link_token: &str,) -> anyhow::Result<TelegramLoginCheckResult> {- let config = self.config_with_channels(channels_config);- into_anyhow(ops::telegram_login_check(&config, link_token).await)+ hosted_link_unavailable("telegram_login_check")}async fn discord_link_start(&self,- channels_config: &ChannelsConfig,+ _channels_config: &ChannelsConfig,) -> anyhow::Result<DiscordLinkStartResult> {- let config = self.config_with_channels(channels_config);- into_anyhow(ops::discord_link_start(&config).await)+ hosted_link_unavailable("discord_link_start")}async fn discord_link_check(&self,- channels_config: &ChannelsConfig,- link_token: &str,+ _channels_config: &ChannelsConfig,+ _link_token: &str,) -> anyhow::Result<DiscordLinkCheckResult> {- let config = self.config_with_channels(channels_config);- into_anyhow(ops::discord_link_check(&config, link_token).await)+ hosted_link_unavailable("discord_link_check")}async fn discord_list_guilds(diff --git a/crates/openhuman-core/src/channels/controllers/ops/discord.rs b/crates/openhuman-core/src/channels/controllers/ops/discord.rsindex 585cbadf1d..988919a1e7 100644--- a/crates/openhuman-core/src/channels/controllers/ops/discord.rs+++ b/crates/openhuman-core/src/channels/controllers/ops/discord.rs@@ -1,151 +1,16 @@-//! Discord managed link flow and guild/channel discovery.+//! Discord guild/channel discovery for the bot-token connection.+//!+//! The managed link flow (`channels.discord_link_*`) needs a TinyHumans+//! account and lives in `openhuman-tinyhumans` (`hosted::channel_link`).use serde_json::Value;-use crate::api::config::effective_backend_api_url;-use crate::api::jwt::get_session_token;-use crate::api::rest::BackendOAuthClient;use crate::config::Config;use crate::rpc::RpcOutcome;use crate::security::credentials;use super::super::definitions::ChannelAuthMode;use super::connect::shared::credential_provider;-use super::types::{DiscordLinkCheckResult, DiscordLinkStartResult};--// ----------------------------------------------------------------------------// Discord managed link flow-// -----------------------------------------------------------------------------/// Step 1: Create a Discord channel link token.-///-/// Returns a short-lived token the user pastes into Discord as `!start <token>`.-/// Requires an active session JWT.-pub async fn discord_link_start(- config: &Config,-) -> Result<RpcOutcome<DiscordLinkStartResult>, String> {- let api_url = effective_backend_api_url(&config.api_url);- let jwt = get_session_token(config)?- .ok_or_else(|| "session JWT required; complete login first".to_string())?;-- log::debug!("[discord-link] creating channel link token via {}", api_url);-- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;- let payload = client- .create_channel_link_token("discord", &jwt)- .await- .map_err(|e| format!("failed to create Discord link token: {e}"))?;-- let link_token = payload- .get("linkToken")- .or_else(|| payload.get("token"))- .and_then(|v| v.as_str())- .ok_or_else(|| {- format!(- "backend response missing linkToken field: {}",- serde_json::to_string(&payload).unwrap_or_default()- )- })?- .trim()- .to_string();-- if link_token.is_empty() {- return Err("backend returned empty link token".to_string());- }-- let instructions =- format!("In Discord, send this message to the OpenHuman bot: !start {link_token}");-- log::debug!(- "[discord-link] link token created, length={}",- link_token.len()- );-- Ok(RpcOutcome::new(- DiscordLinkStartResult {- link_token,- instructions,- },- vec![],- ))-}--/// Step 2: Check whether the user has completed the Discord link.-///-/// Polls `GET /auth/me` and checks whether the user profile now has a `discordId`.-/// On success, stores a `channel:discord:managed_dm` credential marker locally.-pub async fn discord_link_check(- config: &Config,- _link_token: &str,-) -> Result<RpcOutcome<DiscordLinkCheckResult>, String> {- let api_url = effective_backend_api_url(&config.api_url);- let jwt = get_session_token(config)?.ok_or_else(|| "session JWT required".to_string())?;-- log::debug!("[discord-link] checking if user profile has discordId via GET /auth/me");-- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;- let user_payload = client- .fetch_profile(&jwt)- .await- .map_err(|e| format!("failed to fetch user profile: {e}"))?;-- let discord_id = user_payload- .get("discordId")- .and_then(|v| v.as_str())- .filter(|s| !s.is_empty())- .or_else(|| {- user_payload- .get("discord_id")- .and_then(|v| v.as_str())- .filter(|s| !s.is_empty())- });-- let linked = discord_id.is_some();-- log::debug!(- "[discord-link] user profile has_discord_id={}, linked={}",- discord_id.is_some(),- linked- );-- if linked {- let provider_key = credential_provider("discord", ChannelAuthMode::ManagedDm);- let discord_user_id = discord_id.unwrap_or("").to_string();-- let mut fields_map = serde_json::Map::new();- fields_map.insert("linked".to_string(), Value::Bool(true));- if !discord_user_id.is_empty() {- fields_map.insert(- "discord_user_id".to_string(),- Value::String(discord_user_id),- );- }-- credentials::ops::store_provider_credentials(- config,- &provider_key,- None,- Some("managed".to_string()),- Some(Value::Object(fields_map)),- Some(true),- )- .await- .map_err(|e| format!("failed to store Discord managed channel credentials: {e}"))?;-- log::info!(- "[discord-link] Discord managed DM linked; credentials stored as {}",- provider_key- );- }-- Ok(RpcOutcome::new(- DiscordLinkCheckResult {- linked,- details: if linked { Some(user_payload) } else { None },- },- vec![],- ))-}// ---------------------------------------------------------------------------// Discord guild/channel discoverydiff --git a/crates/openhuman-core/src/channels/controllers/ops/mod.rs b/crates/openhuman-core/src/channels/controllers/ops/mod.rsindex 778ab47902..e8b603e60f 100644--- a/crates/openhuman-core/src/channels/controllers/ops/mod.rs+++ b/crates/openhuman-core/src/channels/controllers/ops/mod.rs@@ -3,7 +3,6 @@mod connect;mod discord;mod messaging;-mod telegram;mod types;mod yuanbao;@@ -20,15 +19,11 @@ pub use connect::{channel_status, connect_channel, connected_channel_slugs, disconnect_channel,get_default_channel, set_default_channel, test_channel,};-pub use discord::{- discord_check_permissions, discord_link_check, discord_link_start, discord_list_channels,- discord_list_guilds,-};+pub use discord::{discord_check_permissions, discord_list_channels, discord_list_guilds};pub use messaging::{channel_create_thread, channel_list_threads, channel_send_message, channel_send_reaction,channel_update_thread,};-pub use telegram::{telegram_login_check, telegram_login_start};#[cfg(test)]#[path = "../ops_tests.rs"]diff --git a/crates/openhuman-core/src/channels/controllers/ops/telegram.rs b/crates/openhuman-core/src/channels/controllers/ops/telegram.rsdeleted file mode 100644index 5a7db0da41..0000000000--- a/crates/openhuman-core/src/channels/controllers/ops/telegram.rs+++ /dev/null@@ -1,174 +0,0 @@-//! Managed Telegram login flow.--use serde_json::Value;--use crate::api::config::{app_env_from_env, effective_backend_api_url, is_staging_app_env};-use crate::api::jwt::get_session_token;-use crate::api::rest::BackendOAuthClient;-use crate::config::Config;-use crate::rpc::RpcOutcome;-use crate::security::credentials;--use super::super::definitions::ChannelAuthMode;-use super::connect::shared::credential_provider;-use super::types::{TelegramLoginCheckResult, TelegramLoginStartResult};--/// Default managed Telegram bot when `OPENHUMAN_APP_ENV` is staging and no username override is set.-const DEFAULT_TELEGRAM_BOT_USERNAME_STAGING: &str = "alphahumantest_bot";-/// Default managed Telegram bot when app env is production (or unset) and no username override is set.-const DEFAULT_TELEGRAM_BOT_USERNAME_PRODUCTION: &str = "openhumanaibot";--/// Resolve the managed Telegram bot username from env, or from staging vs production defaults using-/// `OPENHUMAN_APP_ENV` / `VITE_OPENHUMAN_APP_ENV` (via `app_env_from_env`).-fn telegram_bot_username() -> String {- if let Ok(v) = std::env::var("OPENHUMAN_TELEGRAM_BOT_USERNAME") {- return v;- }- if let Ok(v) = std::env::var("VITE_TELEGRAM_BOT_USERNAME") {- return v;- }- if is_staging_app_env(app_env_from_env().as_deref()) {- return DEFAULT_TELEGRAM_BOT_USERNAME_STAGING.to_string();- }- DEFAULT_TELEGRAM_BOT_USERNAME_PRODUCTION.to_string()-}--/// Step 1: Create a channel link token for Telegram and return the deep link URL.-///-/// Requires an active session JWT.-pub async fn telegram_login_start(- config: &Config,-) -> Result<RpcOutcome<TelegramLoginStartResult>, String> {- let api_url = effective_backend_api_url(&config.api_url);- let jwt = get_session_token(config)?- .ok_or_else(|| "session JWT required; complete login first".to_string())?;-- log::debug!(- "[telegram-login] creating channel link token via {}",- api_url- );-- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;- let payload = client- .create_channel_link_token("telegram", &jwt)- .await- .map_err(|e| format!("failed to create Telegram link token: {e}"))?;-- // Extract the link token from the backend response.- // Expected shape: { "linkToken": "..." } or { "token": "..." }- let link_token = payload- .get("linkToken")- .or_else(|| payload.get("token"))- .and_then(|v| v.as_str())- .ok_or_else(|| {- format!(- "backend response missing linkToken field: {}",- serde_json::to_string(&payload).unwrap_or_default()- )- })?- .trim()- .to_string();-- if link_token.is_empty() {- return Err("backend returned empty link token".to_string());- }-- let bot_username = telegram_bot_username();- let telegram_url = format!("https://t.me/{}?start={}", bot_username, link_token);-- log::debug!(- "[telegram-login] link token created, deep link: {}",- telegram_url- );-- Ok(RpcOutcome::new(- TelegramLoginStartResult {- link_token,- telegram_url,- bot_username,- },- vec![],- ))-}--/// Step 2: Check whether the user has completed the Telegram link (clicked /start).-///-/// Polls `GET /auth/me` and checks whether the user profile now has a `telegramId`.-/// The frontend should poll this until `linked` becomes `true`.-/// On success, stores a `channel:telegram:managed_dm` credential marker locally.-pub async fn telegram_login_check(- config: &Config,- _link_token: &str,-) -> Result<RpcOutcome<TelegramLoginCheckResult>, String> {- let api_url = effective_backend_api_url(&config.api_url);- let jwt = get_session_token(config)?.ok_or_else(|| "session JWT required".to_string())?;-- log::debug!("[telegram-login] checking if user profile has telegramId via GET /auth/me");-- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;- let user_payload = client- .fetch_profile(&jwt)- .await- .map_err(|e| format!("failed to fetch user profile: {e}"))?;-- // Check if the user now has a telegramId set.- let telegram_id = user_payload- .get("telegramId")- .and_then(|v| v.as_str())- .filter(|s| !s.is_empty())- .or_else(|| {- user_payload- .get("telegram_id")- .and_then(|v| v.as_str())- .filter(|s| !s.is_empty())- });-- let linked = telegram_id.is_some();-- log::debug!(- "[telegram-login] user profile has_telegram_id={}, linked={}",- telegram_id.is_some(),- linked- );-- if linked {- // Store a credential marker so `channel_status` reports connected.- let provider_key = credential_provider("telegram", ChannelAuthMode::ManagedDm);-- let telegram_user_id = telegram_id.unwrap_or("").to_string();-- let mut fields_map = serde_json::Map::new();- fields_map.insert("linked".to_string(), Value::Bool(true));- if !telegram_user_id.is_empty() {- fields_map.insert(- "telegram_user_id".to_string(),- Value::String(telegram_user_id),- );- }-- // Store using a placeholder token (managed mode has no user-visible token).- credentials::ops::store_provider_credentials(- config,- &provider_key,- None,- Some("managed".to_string()),- Some(Value::Object(fields_map)),- Some(true),- )- .await- .map_err(|e| format!("failed to store managed channel credentials: {e}"))?;-- log::info!(- "[telegram-login] Telegram managed DM linked; credentials stored as {}",- provider_key- );- }-- Ok(RpcOutcome::new(- TelegramLoginCheckResult {- linked,- details: if linked { Some(user_payload) } else { None },- },- vec![],- ))-}