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(integrations): handle missing pricing data gracefully
Steven Enamakel499a414b4ccc
diff --git a/crates/openhuman-core/src/integrations/client/pricing.rs b/crates/openhuman-core/src/integrations/client/pricing.rsindex 7d61c9ce80..ba7f9760ba 100644--- a/crates/openhuman-core/src/integrations/client/pricing.rs+++ b/crates/openhuman-core/src/integrations/client/pricing.rs@@ -66,10 +66,10 @@ pub async fn pricing_for_config(}/// Helper: build an `Arc<IntegrationClient>` from the root config, or-/// `None` if there is no backend session JWT. A local offline credential keeps+/// `None` if there is no backend credential. A local offline credential keeps/// the core signed in but cannot authenticate hosted integration routes.///-/// Both the backend URL and the auth token come from **core defaults**:+/// Both the backend URL and the credential come from **core defaults**:////// - backend URL → [`crate::api::config::effective_backend_api_url`]/// applied to `config.api_url`. Unlike the plain@@ -79,14 +79,17 @@ pub async fn pricing_for_config(/// `BACKEND_URL` / `VITE_BACKEND_URL` env vars (and finally the hosted/// default) so backend paths don't get concatenated onto a local/// Ollama/vLLM endpoint and 404.-/// - auth token → [`crate::api::jwt::get_session_token`], i.e. the-/// app-session JWT written by `auth_store_session` — the same token-/// that billing, team, webhooks, referral, memory, etc. all use. The local-/// offline token is excluded before constructing an HTTP client.+/// - credential → [`resolve_backend_credential`], the same resolver every+/// other backend caller uses: the stored TinyHumans API key when there is+/// one (sent as `x-api-key`), else the live app-session JWT (sent as+/// `Authorization: Bearer`). The local offline token and an expired session+/// both resolve to an error, so no client is built for them.////// There are no per-feature toggles for the shared client itself —/// callers that need a kill switch (e.g. twilio, google_places,/// parallel) gate tool registration at their own level.+///+/// [`resolve_backend_credential`]: crate::security::credentials::session_support::resolve_backend_credentialpub fn build_client(config: &crate::config::Config) -> Option<Arc<IntegrationClient>> {// Use the integrations-specific resolver: when `config.api_url` is set// to a local-AI endpoint (Ollama, vLLM, …), it would still be perfect@@ -98,28 +101,32 @@ pub fn build_client(config: &crate::config::Config) -> Option<Arc<IntegrationCli// default backend in that case so integrations actually work.let backend_url = crate::api::config::effective_backend_api_url(&config.api_url);- // Primary: app-session JWT from the auth profile store.- let session_token = match crate::api::jwt::get_session_token(config) {- Ok(token) => token,- Err(e) => {- tracing::warn!("[integrations] failed to read session token: {e}");- None- }- };+ let credential =+ match crate::security::credentials::session_support::resolve_backend_credential(config) {+ Ok(credential) => Some(credential),+ Err(e) => {+ tracing::debug!("[integrations] no backend credential: {e}");+ None+ }+ };- build_client_with_session_token(config, backend_url, session_token)+ build_client_with_credential(config, backend_url, credential)}/// The credential decision is separate from profile-store lookup so callers/// can test the backend boundary without process-wide auth-store state.-fn build_client_with_session_token(+fn build_client_with_credential(config: &crate::config::Config,backend_url: String,- session_token: Option<String>,+ credential: Option<crate::security::credentials::session_support::BackendCredential>,) -> Option<Arc<IntegrationClient>> {- match session_token.as_deref().map(str::trim) {- Some(token)- if crate::security::credentials::session_support::is_local_session_token(token) =>+ use crate::security::credentials::session_support::BackendCredential;++ let credential = match credential {+ Some(BackendCredential::Session(token))+ if crate::security::credentials::session_support::is_local_session_token(+ token.trim(),+ ) =>{// Offline identity is valid for the local core, but the hosted// integrations API cannot authenticate it. Never send it as a@@ -128,27 +135,30 @@ fn build_client_with_session_token(tracing::debug!("[integrations] local offline credential has no hosted integrations client");- None- }- Some(token) if !token.is_empty() => {- tracing::debug!(- backend_url = %backend_url,- "[integrations] client built (session token resolved)"- );- Some(Arc::new(IntegrationClient::new_with_budget_config(- backend_url,- token.to_owned(),- Arc::new(config.clone()),- )))+ return None;}- _ => {- tracing::warn!(- "[integrations] no auth token available — user is not signed in \- (no app-session JWT)"- );- None+ Some(BackendCredential::Session(token)) => {+ BackendCredential::Session(token.trim().to_owned())}+ Some(BackendCredential::ApiKey(key)) => BackendCredential::ApiKey(key.trim().to_owned()),+ None => None?,+ };+ if credential.secret().is_empty() {+ tracing::warn!(+ "[integrations] no auth token available — not signed in and no API key set"+ );+ return None;}+ tracing::debug!(+ backend_url = %backend_url,+ api_key = credential.is_api_key(),+ "[integrations] client built (backend credential resolved)"+ );+ Some(Arc::new(IntegrationClient::new_with_budget_config(+ backend_url,+ credential,+ Arc::new(config.clone()),+ )))}#[cfg(test)]diff --git a/crates/openhuman-core/src/integrations/client/pricing_tests.rs b/crates/openhuman-core/src/integrations/client/pricing_tests.rsindex 5703ae92cd..b9fa7f55b4 100644--- a/crates/openhuman-core/src/integrations/client/pricing_tests.rs+++ b/crates/openhuman-core/src/integrations/client/pricing_tests.rs@@ -1,19 +1,49 @@use super::*;+use crate::security::credentials::session_support::BackendCredential;#[test]fn local_offline_token_never_constructs_a_hosted_integration_client() {let config = crate::config::Config::default();let backend_url = "https://api.example.test".to_owned();- assert!(build_client_with_session_token(+ assert!(build_client_with_credential(&config,backend_url.clone(),- Some("header.payload.local".into()),+ Some(BackendCredential::Session("header.payload.local".into())),).is_none());- assert!(build_client_with_session_token(+ assert!(build_client_with_credential(&config,backend_url,- Some("header.payload.jwt".into()),+ Some(BackendCredential::Session("header.payload.jwt".into())),).is_some());}++#[test]+fn api_key_constructs_a_client_that_authenticates_with_the_key() {+ let config = crate::config::Config::default();+ let client = build_client_with_credential(+ &config,+ "https://api.example.test".to_owned(),+ Some(BackendCredential::ApiKey(" tiny_test_abc ".into())),+ )+ .expect("an API key alone must build the integrations client");+ assert!(client.uses_api_key());+ assert_eq!(client.auth_token, "tiny_test_abc");+ let headers = client.auth_headers().unwrap();+ assert_eq!(headers.get("x-api-key").unwrap(), "tiny_test_abc");+ assert!(headers.get(reqwest::header::AUTHORIZATION).is_none());+}++#[test]+fn missing_or_blank_credential_builds_no_client() {+ let config = crate::config::Config::default();+ let url = "https://api.example.test".to_owned();+ assert!(build_client_with_credential(&config, url.clone(), None).is_none());+ assert!(build_client_with_credential(+ &config,+ url,+ Some(BackendCredential::ApiKey(" ".into()))+ )+ .is_none());+}