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(core): remove unused imports across multiple modules
Steven Enamakeldff58e9d3cea
diff --git a/crates/openhuman-core/src/channels/bus/delivery.rs b/crates/openhuman-core/src/channels/bus/delivery.rsindex 0ac06c8dd5..14f2b67f5d 100644--- a/crates/openhuman-core/src/channels/bus/delivery.rs+++ b/crates/openhuman-core/src/channels/bus/delivery.rs@@ -183,11 +183,13 @@ pub(super) async fn finalize_channel_reply(}}-/// Construct the REST client + session JWT shared by every outbound-/// channel call on this turn. Returns `None` and logs if either is+/// Construct the REST client + backend credential (API key or session JWT)+/// shared by every outbound channel call on this turn. Returns `None` and logs if either is/// unavailable so the caller can bail quietly.-pub(super) async fn build_channel_client() -> Option<(crate::api::rest::BackendOAuthClient, String)>-{+pub(super) async fn build_channel_client() -> Option<(+ crate::api::rest::BackendOAuthClient,+ crate::security::credentials::session_support::BackendCredential,+)> {let config = match crate::config::rpc::load_config_with_timeout().await {Ok(c) => c,Err(e) => {@@ -196,14 +198,12 @@ pub(super) async fn build_channel_client() -> Option<(crate::api::rest::BackendO}};let api_url = crate::api::config::effective_backend_api_url(&config.api_url);- let jwt = match crate::api::jwt::get_session_token(&config) {- Ok(Some(t)) => t,- Ok(None) => {- tracing::error!("[channel-inbound] no session JWT — cannot send");- return None;- }+ let jwt = match crate::security::credentials::session_support::resolve_backend_credential(+ &config,+ ) {+ Ok(credential) => credential,Err(e) => {- tracing::error!("[channel-inbound] failed to get session token: {}", e);+ tracing::error!("[channel-inbound] no backend credential — cannot send: {}", e);return None;}};@@ -227,14 +227,12 @@ pub(super) async fn send_channel_reply(channel: &str, text: &str) {};let api_url = crate::api::config::effective_backend_api_url(&config.api_url);- let jwt = match crate::api::jwt::get_session_token(&config) {- Ok(Some(t)) => t,- Ok(None) => {- tracing::error!("[channel-inbound] no session JWT — cannot reply");- return;- }+ let jwt = match crate::security::credentials::session_support::resolve_backend_credential(+ &config,+ ) {+ Ok(credential) => credential,Err(e) => {- tracing::error!("[channel-inbound] failed to get session token: {}", e);+ tracing::error!("[channel-inbound] no backend credential — cannot reply: {}", e);return;}};diff --git a/crates/openhuman-core/src/channels/controllers/ops/messaging.rs b/crates/openhuman-core/src/channels/controllers/ops/messaging.rsindex 4f632ece1b..68fc6a606e 100644--- a/crates/openhuman-core/src/channels/controllers/ops/messaging.rs+++ b/crates/openhuman-core/src/channels/controllers/ops/messaging.rs@@ -3,7 +3,7 @@use serde_json::Value;use crate::api::config::effective_backend_api_url;-use crate::api::jwt::get_session_token;+use crate::security::credentials::session_support::resolve_backend_credential;use crate::api::rest::BackendOAuthClient;use crate::config::Config;use crate::rpc::RpcOutcome;@@ -15,8 +15,7 @@ pub async fn channel_send_message(message: Value,) -> Result<RpcOutcome<Value>, 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())?;+ let jwt = resolve_backend_credential(config)?;log::debug!("[channels] sending message to channel '{}' via {}",@@ -42,8 +41,7 @@ pub async fn channel_send_reaction(reaction: Value,) -> Result<RpcOutcome<Value>, 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())?;+ let jwt = resolve_backend_credential(config)?;log::debug!("[channels] sending reaction to channel '{}' via {}",@@ -69,8 +67,7 @@ pub async fn channel_create_thread(title: &str,) -> Result<RpcOutcome<Value>, 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())?;+ let jwt = resolve_backend_credential(config)?;log::debug!("[channels] creating thread in channel '{}' title='{}' via {}",@@ -98,8 +95,7 @@ pub async fn channel_update_thread(action: &str,) -> Result<RpcOutcome<Value>, 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())?;+ let jwt = resolve_backend_credential(config)?;log::debug!("[channels] updating thread '{}' in channel '{}' action='{}' via {}",@@ -127,8 +123,7 @@ pub async fn channel_list_threads(active: Option<bool>,) -> Result<RpcOutcome<Value>, 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())?;+ let jwt = resolve_backend_credential(config)?;log::debug!("[channels] listing threads in channel '{}' active={:?} via {}",diff --git a/crates/openhuman-core/src/core/runtime/services.rs b/crates/openhuman-core/src/core/runtime/services.rsindex 3e52caf6a8..25c78f9fa9 100644--- a/crates/openhuman-core/src/core/runtime/services.rs+++ b/crates/openhuman-core/src/core/runtime/services.rs@@ -438,7 +438,8 @@ pub fn spawn_socket_auto_connect(}};let api_url = crate::api::config::effective_backend_api_url(&config.api_url);- let initial_token = match crate::api::jwt::get_session_token(&config) {+ // The API key when one is stored, else the session token.+ let initial_token = match crate::security::credentials::session_support::backend_bearer_secret(&config) {Ok(Some(t)) => t,Ok(None) => {log::info!(diff --git a/crates/openhuman-core/src/platform/socket/ops.rs b/crates/openhuman-core/src/platform/socket/ops.rsindex 869a94d85d..8842dcffee 100644--- a/crates/openhuman-core/src/platform/socket/ops.rs+++ b/crates/openhuman-core/src/platform/socket/ops.rs@@ -53,9 +53,10 @@ pub async fn connect_with_session(manager: &SocketManager) -> Result<SocketStatelog::info!("[socket:rpc] connect_with_session — resolving credentials");let config = std::sync::Arc::new(crate::config::rpc::load_config_with_timeout().await?);let api_url = crate::api::config::effective_backend_api_url(&config.api_url);- let token = crate::api::jwt::get_session_token(&config)+ // The API key when one is stored, else the session token.+ let token = crate::security::credentials::session_support::backend_bearer_secret(&config).map_err(|e| format!("failed to read session token: {e}"))?- .ok_or("no session token stored — user must log in first")?;+ .ok_or("no session token stored — user must log in first or set an API key")?;let provider =super::token_provider::token_provider_from_config(std::sync::Arc::clone(&config));diff --git a/crates/openhuman-core/src/platform/socket/token_provider.rs b/crates/openhuman-core/src/platform/socket/token_provider.rsindex 46ed159ded..5cf62f3afa 100644--- a/crates/openhuman-core/src/platform/socket/token_provider.rs+++ b/crates/openhuman-core/src/platform/socket/token_provider.rs@@ -67,17 +67,20 @@ pub(super) fn static_token_provider(token: String) -> TokenProvider {})}-/// Build a provider that reads the latest session token from the profile store-/// on every call.+/// Build a provider that reads the latest backend credential from the profile+/// store on every call: the TinyHumans API key when one is stored, else the+/// session token. The backend's handshake accepts either as `auth.token`.////// This is the **live-refresh** path used by `handle_connect_with_session`:/// when the loop retries after a disconnect it will see any token that was/// refreshed or re-stored since the previous attempt.pub(crate) fn token_provider_from_config(config: Arc<crate::config::Config>) -> TokenProvider {Arc::new(move || {- crate::api::jwt::get_session_token(&config)+ crate::security::credentials::session_support::backend_bearer_secret(&config).map_err(|e| format!("failed to read session token: {e}"))?- .ok_or_else(|| "no session token stored — user must log in first".to_string())+ .ok_or_else(|| {+ "no session token stored — user must log in first or set an API key".to_string()+ })})}diff --git a/crates/openhuman-core/src/skills/webhooks/ops.rs b/crates/openhuman-core/src/skills/webhooks/ops.rsindex d862b8d1d3..bddc86c1e6 100644--- a/crates/openhuman-core/src/skills/webhooks/ops.rs+++ b/crates/openhuman-core/src/skills/webhooks/ops.rs@@ -1,5 +1,4 @@use crate::api::config::effective_backend_api_url;-use crate::api::jwt::get_session_token;use crate::api::BackendOAuthClient;use crate::config::Config;use crate::rpc::RpcOutcome;@@ -12,17 +11,12 @@ use reqwest::Method;use serde_json::Value;use std::collections::HashMap;-fn require_token(config: &Config) -> Result<String, String> {- get_session_token(config)?- .and_then(|v| {- let t = v.trim().to_string();- if t.is_empty() {- None- } else {- Some(t)- }- })- .ok_or_else(|| "no backend session token; run auth_store_session first".to_string())+/// The backend credential for `/webhooks/*`: the TinyHumans API key or the+/// live session JWT.+fn require_token(+ config: &Config,+) -> Result<crate::security::credentials::session_support::BackendCredential, String> {+ crate::security::credentials::session_support::resolve_backend_credential(config)}async fn get_authed_value(diff --git a/crates/openhuman-tinyhumans/src/hosted/referral/ops.rs b/crates/openhuman-tinyhumans/src/hosted/referral/ops.rsindex 0cfc079978..f6c668ab6c 100644--- a/crates/openhuman-tinyhumans/src/hosted/referral/ops.rs+++ b/crates/openhuman-tinyhumans/src/hosted/referral/ops.rs@@ -7,22 +7,16 @@ use reqwest::Method;use serde_json::{json, Map, Value};use openhuman_core::api::config::effective_backend_api_url;-use openhuman_core::api::jwt::get_session_token;use openhuman_core::api::BackendOAuthClient;use openhuman_core::config::Config;use openhuman_core::rpc::RpcOutcome;-fn require_token(config: &Config) -> Result<String, String> {- get_session_token(config)?- .and_then(|v| {- let t = v.trim().to_string();- if t.is_empty() {- None- } else {- Some(t)- }- })- .ok_or_else(|| "no backend session token; run auth_store_session first".to_string())+/// The backend credential for `/referral/*`: the TinyHumans API key (it needs+/// the `account` scope) or the live session JWT.+fn require_token(+ config: &Config,+) -> Result<openhuman_core::security::credentials::session_support::BackendCredential, String> {+ openhuman_core::security::credentials::session_support::resolve_backend_credential(config)}pub async fn get_stats(config: &Config) -> Result<RpcOutcome<Value>, String> {