Skip to content

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

refactor(api): relocate core API types and rename BackendOAuthClient to BackendClient

Steven Enamakel6ad0bad04cd5
diff --git a/Cargo.lock b/Cargo.lock
index f4a2d12f8b..710204fb14 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4063,9 +4063,11 @@ dependencies = [
name = "openhuman-tinyhumans"
version = "0.64.4"
dependencies = [
+ "aes-gcm",
"anyhow",
"async-trait",
"axum",
+ "base64 0.22.1",
"chrono",
"log",
"openhuman",
diff --git a/crates/openhuman-tinyhumans/src/backend/product.rs b/crates/openhuman-tinyhumans/src/backend/product.rs
index d609b441ab..c37125cc67 100644
--- a/crates/openhuman-tinyhumans/src/backend/product.rs
+++ b/crates/openhuman-tinyhumans/src/backend/product.rs
@@ -13,7 +13,7 @@
//! the identity once during startup, before it builds any backend client:
//!
//! ```no_run
-//! use openhuman_core::api::{set_product_identity, ProductIdentity};
+//! use crate::backend::{set_product_identity, ProductIdentity};
//!
//! if let Some(identity) = ProductIdentity::new("opencompany") {
//! set_product_identity(identity);
diff --git a/crates/openhuman-tinyhumans/src/hosted/channel_link/managed.rs b/crates/openhuman-tinyhumans/src/hosted/channel_link/managed.rs
index c78d65c9ec..13cc01c4c6 100644
--- a/crates/openhuman-tinyhumans/src/hosted/channel_link/managed.rs
+++ b/crates/openhuman-tinyhumans/src/hosted/channel_link/managed.rs
@@ -10,7 +10,7 @@ use tinychannels_bus::controllers::{
TelegramLoginCheckResult, TelegramLoginStartResult,
};
-use openhuman_core::api::config::{app_env_from_env, is_staging_app_env};
+use openhuman_core::config::app_env::{app_env_from_env, is_staging_app_env};
use openhuman_core::config::Config;
use openhuman_core::rpc::RpcOutcome;
use openhuman_core::security::credentials;
diff --git a/crates/openhuman-tinyhumans/src/hosted/client.rs b/crates/openhuman-tinyhumans/src/hosted/client.rs
index 7b96163ba5..9c0cc09070 100644
--- a/crates/openhuman-tinyhumans/src/hosted/client.rs
+++ b/crates/openhuman-tinyhumans/src/hosted/client.rs
@@ -24,12 +24,12 @@
//! | `Envelope` / `Decode` / others | `backend request {op}: {error}` |
//! | `RouteNotExposed` | same, logged at `error` (a bug here) |
//!
-//! The non-sentinel shapes are exactly what `BackendOAuthClient::authed_json`
+//! The non-sentinel shapes are exactly what `BackendClient::authed_json`
//! produced before, so the JSON-RPC classifiers (transient status, transport
//! phrases, budget exhaustion) keep matching them.
-use openhuman_core::api::config::effective_backend_api_url;
-use openhuman_core::api::transport::{resolve_backend_transport, TransportProfile};
+use crate::backend::url::effective_backend_api_url;
+use openhuman_core::backend::transport::{resolve_backend_transport, TransportProfile};
use openhuman_core::config::Config;
use openhuman_core::core::observability::{
contains_transient_transport_phrase, is_transient_http_status_code, API_KEY_REJECTED_PREFIX,
@@ -77,7 +77,7 @@ impl HostedClient {
// The product identity (`x-sdk-name`) also rides the SDK's own
// default headers, exactly as the SDK transport does, so it holds
// even for a client this crate did not build.
- .with_default_headers(openhuman_core::api::product::product_identity_headers());
+ .with_default_headers(crate::backend::product::product_identity_headers());
match credential {
BackendCredential::Session(secret) => Self {
sdk: sdk.with_token(Some(secret.trim().to_string())),
@@ -117,7 +117,7 @@ impl HostedClient {
}
/// The backend origin with any path, query and fragment stripped — the same
-/// normalisation `BackendOAuthClient::new` applies, so a completions-style
+/// normalisation `BackendClient::new` applies, so a completions-style
/// `api_url` (`https://host/v1/chat/completions`) still reaches `/teams/...`.
fn backend_origin(api_url: &str) -> Result<String, String> {
let mut url =
@@ -138,7 +138,7 @@ fn http_client() -> reqwest::Client {
if let Ok(transport) = resolve_backend_transport() {
return transport.http_client(TransportProfile::Api);
}
- openhuman_core::api::headers::build_backend_client(TransportProfile::Api).unwrap_or_else(
+ crate::backend::headers::build_backend_client(TransportProfile::Api).unwrap_or_else(
|err| {
log::warn!("{LOG_PREFIX} failed to build backend client, using default: {err}");
reqwest::Client::new()
diff --git a/crates/openhuman-tinyhumans/src/hosted/team/ops.rs b/crates/openhuman-tinyhumans/src/hosted/team/ops.rs
index 5db6f5981e..7432b9f5b1 100644
--- a/crates/openhuman-tinyhumans/src/hosted/team/ops.rs
+++ b/crates/openhuman-tinyhumans/src/hosted/team/ops.rs
@@ -15,8 +15,8 @@ use reqwest::Method;
use serde_json::{json, Value};
use tinyhumans_sdk::api::types::{CodeRequest, CreateTeamInviteRequest};
-use openhuman_core::api::config::effective_backend_api_url;
-use openhuman_core::api::BackendOAuthClient;
+use crate::backend::url::effective_backend_api_url;
+use openhuman_core::backend::BackendClient;
use openhuman_core::config::Config;
use openhuman_core::integrations::client::budget_gate;
use openhuman_core::rpc::RpcOutcome;
@@ -87,7 +87,7 @@ pub async fn get_team(config: &Config, team_id: &str) -> Result<RpcOutcome<Value
Ok(RpcOutcome::single_log(data, "team fetched from backend"))
}
-/// `POST /teams` through the core's `BackendOAuthClient::authed_json`.
+/// `POST /teams` through the core's `BackendClient::authed_json`.
///
/// Deliberately **not** on the SDK: the SDK has no typed method for this route
/// and its generated public-route registry has no entry for it (teams were
@@ -120,11 +120,11 @@ async fn legacy_authed_value(
let credential =
openhuman_core::security::credentials::session_support::resolve_backend_credential(config)?;
let api_url = effective_backend_api_url(&config.api_url);
- let client = BackendOAuthClient::new(&api_url).map_err(|e| format!("{e:#}"))?;
+ let client = BackendClient::new(&api_url).map_err(|e| format!("{e:#}"))?;
client
.authed_json(credential, method, path, body)
.await
- .map_err(openhuman_core::api::flatten_authed_error)
+ .map_err(openhuman_core::backend::flatten_authed_error)
}
pub async fn update_team(
diff --git a/crates/openhuman-tinyhumans/src/install.rs b/crates/openhuman-tinyhumans/src/install.rs
index e40919a753..cf4a051c6c 100644
--- a/crates/openhuman-tinyhumans/src/install.rs
+++ b/crates/openhuman-tinyhumans/src/install.rs
@@ -9,8 +9,8 @@
use std::sync::{Arc, Mutex, OnceLock};
-use openhuman_core::api::transport::{install_backend_transport, installed_backend_transport};
-use openhuman_core::api::{set_product_identity, ProductIdentity};
+use openhuman_core::backend::transport::{install_backend_transport, installed_backend_transport};
+use crate::backend::{set_product_identity, ProductIdentity};
use openhuman_core::core::all::register_controller_extension;
use crate::transport::SdkBackendTransport;
diff --git a/crates/openhuman-tinyhumans/src/jev/ranker.rs b/crates/openhuman-tinyhumans/src/jev/ranker.rs
index 176b2260ec..ffadbddf8f 100644
--- a/crates/openhuman-tinyhumans/src/jev/ranker.rs
+++ b/crates/openhuman-tinyhumans/src/jev/ranker.rs
@@ -10,7 +10,7 @@ use std::{
use std::{future::Future, pin::Pin, sync::Arc, time::Duration};
use openhuman_core::agent::tinyagents::discovery::EmbeddingToolRanker;
-use openhuman_core::api::config::effective_backend_api_url;
+use crate::backend::url::effective_backend_api_url;
use openhuman_core::config::Config;
use openhuman_core::security::credentials::session_support::resolve_backend_credential;
use tinyjevclient::{Client, ClientConfig};
diff --git a/crates/openhuman-tinyhumans/src/jwt.rs b/crates/openhuman-tinyhumans/src/jwt.rs
index 1651574672..2fc65d03ce 100644
--- a/crates/openhuman-tinyhumans/src/jwt.rs
+++ b/crates/openhuman-tinyhumans/src/jwt.rs
@@ -1,7 +1,7 @@
//! JWT helpers for TinyHumans session tokens, from the SDK.
//!
//! The core carries its own copy of these three functions in
-//! `openhuman_core::api::jwt` because it needs them with no backend
+//! `openhuman_core::security::credentials::jwt` because it needs them with no backend
//! dependency; this module exposes the SDK's originals for hosts that already
//! depend on this crate.
diff --git a/crates/openhuman-tinyhumans/src/transport/error.rs b/crates/openhuman-tinyhumans/src/transport/error.rs
index 7a3725dc4d..4ef55583ce 100644
--- a/crates/openhuman-tinyhumans/src/transport/error.rs
+++ b/crates/openhuman-tinyhumans/src/transport/error.rs
@@ -3,7 +3,7 @@
//! integrations client see exactly the shapes they saw when they called the
//! SDK directly.
-use openhuman_core::api::transport::BackendTransportError;
+use openhuman_core::backend::transport::BackendTransportError;
use tinyhumans_sdk::Error as SdkError;
/// Map the SDK's error onto the core-owned transport error.
diff --git a/crates/openhuman-tinyhumans/src/transport/transport_tests.rs b/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
index 87e68731b4..7a3fa61507 100644
--- a/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
+++ b/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
@@ -2,7 +2,7 @@
//! code relies on, pinned against a mock backend.
use super::*;
-use openhuman_core::api::transport::{clear_backend_transport, resolve_backend_transport};
+use openhuman_core::backend::transport::{clear_backend_transport, resolve_backend_transport};
use serde_json::json;
use wiremock::matchers::{header, header_exists, method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
@@ -234,7 +234,7 @@ async fn backend_client_round_trips_through_the_installed_transport() {
let _guard = global_lock().lock().await;
let _t = crate::install(crate::InstallOptions::default()).unwrap();
- let client = openhuman_core::api::BackendOAuthClient::new(&server.uri()).unwrap();
+ let client = openhuman_core::backend::BackendClient::new(&server.uri()).unwrap();
let value = client
.authed_json("jwt", reqwest::Method::GET, "/announcements/latest", None)
.await